diff options
author | João Valverde <j@v6e.pt> | 2022-12-26 00:40:00 +0000 |
---|---|---|
committer | João Valverde <j@v6e.pt> | 2022-12-26 15:29:50 +0000 |
commit | 079ef9a165aef36f6cd46e400e548bfdb3bec8a2 (patch) | |
tree | bd22076c82009b3e43b064c2a89f3995c2bede4c /test | |
parent | 49ec151a7a220f52052caf755365d99211f83425 (diff) |
dfilter: Allow comparison relation to commute
Comparison relations should be allowed to commute but they can not
because we need type information to resolve literals to fvalues. For
that reason an expression like "1 == some.field" is invalid. Solve
that by commuting the relation if the first try did not succeed in
assigning a type to the LHS.
After the second try give up, that means we have a relation with
constants on both sides and that is not semantically valid.
Other relations like "matches" and "contains" are not symmetric and
should not commute anyway.
Before:
Filter: _ws.ftypes.int32 == 10
Syntax tree:
0 TEST_ANY_EQ:
1 FIELD(_ws.ftypes.int32 <FT_INT32>)
1 FVALUE(10 <FT_INT32>)
Instructions:
00000 READ_TREE _ws.ftypes.int32 <FT_INT32> -> reg#0
00001 IF_FALSE_GOTO 3
00002 ANY_EQ reg#0 == 10 <FT_INT32>
00003 RETURN
Filter: 10 == _ws.ftypes.int32
dftest: Left side of "==" expression must be a field or function, not 10.
10 == _ws.ftypes.int32
^~
After:
Filter: _ws.ftypes.int32 == 10
Syntax tree:
0 TEST_ANY_EQ:
1 FIELD(_ws.ftypes.int32 <FT_INT32>)
1 FVALUE(10 <FT_INT32>)
Instructions:
00000 READ_TREE _ws.ftypes.int32 <FT_INT32> -> reg#0
00001 IF_FALSE_GOTO 3
00002 ANY_EQ reg#0 == 10 <FT_INT32>
00003 RETURN
Filter: 10 == _ws.ftypes.int32
Syntax tree:
0 TEST_ANY_EQ:
1 FVALUE(10 <FT_INT32>)
1 FIELD(_ws.ftypes.int32 <FT_INT32>)
Instructions:
00000 READ_TREE _ws.ftypes.int32 <FT_INT32> -> reg#0
00001 IF_FALSE_GOTO 3
00002 ANY_EQ 10 <FT_INT32> == reg#0
00003 RETURN
Diffstat (limited to 'test')
-rw-r--r-- | test/suite_dfilter/group_syntax.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/test/suite_dfilter/group_syntax.py b/test/suite_dfilter/group_syntax.py index 5cd4d50cd4..c7746ec181 100644 --- a/test/suite_dfilter/group_syntax.py +++ b/test/suite_dfilter/group_syntax.py @@ -24,9 +24,13 @@ class case_syntax(unittest.TestCase): dfilter = "ip.proto == 6" checkDFilterCount(dfilter, 1) - def test_commute_2(self, checkDFilterFail): + def test_commute_2(self, checkDFilterCount): dfilter = "6 == ip.proto" - error = "Left side of \"==\" expression must be a field or function" + checkDFilterCount(dfilter, 1) + + def test_commute_3(self, checkDFilterFail): + dfilter = "6 == 7" + error = "Constant expression is invalid" checkDFilterFail(dfilter, error) def test_func_1(self, checkDFilterCount): |