From 25905f5d0a2a7883bd33491997556193582c6059 Mon Sep 17 00:00:00 2001 From: Paul Chaignon Date: Fri, 1 Mar 2024 17:02:06 +0100 Subject: compiler: support using int flags in field conditions Commit ed571339c6ff ("pkg/compiler: support if[expr] attributes") added support for conditional fields in structs and unions. Conditions however cannot refer to flags, as in the following example: struct { f0 flags[some_flags, int32] f1 int32 (if[value[f0] & FLAG1]) } [packed] It will fail to compile with: flags does not refer to an integer This commit adds support for that syntax. Signed-off-by: Paul Chaignon --- pkg/ast/testdata/all.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'pkg/ast/testdata') diff --git a/pkg/ast/testdata/all.txt b/pkg/ast/testdata/all.txt index d04fd4992..a274b3eff 100644 --- a/pkg/ast/testdata/all.txt +++ b/pkg/ast/testdata/all.txt @@ -16,8 +16,11 @@ expressions { f3 int8 (if[X & (A == B) & Z != C]) } +intflags = 1, 2, 3, 4 + condFields { mask int8 + flags flags[intflags, int8] # Simple expressions work. f0 int16 (if[val[mask] == SOME_CONST]) # Conditions and other attributes work together. @@ -25,5 +28,5 @@ condFields { # Test some more complex expressions. f2 int16 (out, if[val[mask] & SOME_CONST == OTHER_CONST]) f3 int16 (out, if[val[mask] & SOME_CONST & OTHER_CONST == val[mask] & CONST_X]) - f4 int16 (out, if[val[mask] & SOME_CONST]) + f4 int16 (out, if[val[flags] & SOME_CONST]) } -- cgit mrf-deployment