dfilter: Rename test syntax tree node

Test node also includes arithmetic operations so rename it
to a generic "operator" node.
This commit is contained in:
João Valverde 2022-06-27 06:37:45 +01:00
parent b10db887ce
commit fc5c81328e
10 changed files with 600 additions and 600 deletions

View File

@ -27,7 +27,7 @@ set(DFILTER_HEADER_FILES
sttype-pointer.h
sttype-set.h
sttype-slice.h
sttype-test.h
sttype-op.h
syntax-tree.h
)
@ -45,7 +45,7 @@ set(DFILTER_NONGENERATED_FILES
sttype-set.c
sttype-slice.c
sttype-string.c
sttype-test.c
sttype-op.c
syntax-tree.c
)
source_group(dfilter FILES ${DFILTER_NONGENERATED_FILES})

View File

@ -14,7 +14,7 @@
#include "syntax-tree.h"
#include "sttype-field.h"
#include "sttype-slice.h"
#include "sttype-test.h"
#include "sttype-op.h"
#include "sttype-set.h"
#include "sttype-function.h"
#include "ftypes/ftypes.h"
@ -30,9 +30,9 @@ static dfvm_value_t *
gen_entity(dfwork_t *dfw, stnode_t *st_arg, GSList **jumps_ptr);
static dfvm_opcode_t
select_opcode(dfvm_opcode_t op, test_match_t how)
select_opcode(dfvm_opcode_t op, stmatch_t how)
{
if (how == ST_MATCH_DEF)
if (how == STNODE_MATCH_DEF)
return op;
switch (op) {
@ -46,7 +46,7 @@ select_opcode(dfvm_opcode_t op, test_match_t how)
case ALL_CONTAINS:
case ALL_MATCHES:
case ALL_IN_RANGE:
return how == ST_MATCH_ALL ? op : op + 1;
return how == STNODE_MATCH_ALL ? op : op + 1;
case ANY_EQ:
case ANY_NE:
case ANY_GT:
@ -57,7 +57,7 @@ select_opcode(dfvm_opcode_t op, test_match_t how)
case ANY_CONTAINS:
case ANY_MATCHES:
case ANY_IN_RANGE:
return how == ST_MATCH_ANY ? op : op - 1;
return how == STNODE_MATCH_ANY ? op : op - 1;
case IF_TRUE_GOTO:
case IF_FALSE_GOTO:
case CHECK_EXISTS:
@ -349,7 +349,7 @@ gen_relation_insn(dfwork_t *dfw, dfvm_opcode_t op,
}
static void
gen_relation(dfwork_t *dfw, dfvm_opcode_t op, test_match_t how,
gen_relation(dfwork_t *dfw, dfvm_opcode_t op, stmatch_t how,
stnode_t *st_arg1, stnode_t *st_arg2)
{
GSList *jumps = NULL;
@ -384,7 +384,7 @@ fixup_jumps(gpointer data, gpointer user_data)
/* Generate the code for the in operator. It behaves much like an OR-ed
* series of == tests, but without the redundant existence checks. */
static void
gen_relation_in(dfwork_t *dfw, test_match_t how,
gen_relation_in(dfwork_t *dfw, stmatch_t how,
stnode_t *st_arg1, stnode_t *st_arg2)
{
dfvm_insn_t *insn;
@ -452,31 +452,31 @@ static dfvm_value_t *
gen_arithmetic(dfwork_t *dfw, stnode_t *st_arg, GSList **jumps_ptr)
{
stnode_t *left, *right;
test_op_t st_op;
stnode_op_t st_op;
dfvm_value_t *reg_val, *val1, *val2 = NULL;
dfvm_opcode_t op;
sttype_test_get(st_arg, &st_op, &left, &right);
sttype_oper_get(st_arg, &st_op, &left, &right);
if (st_op == OP_UNARY_MINUS) {
if (st_op == STNODE_OP_UNARY_MINUS) {
op = MK_MINUS;
}
else if (st_op == OP_ADD) {
else if (st_op == STNODE_OP_ADD) {
op = DFVM_ADD;
}
else if (st_op == OP_SUBTRACT) {
else if (st_op == STNODE_OP_SUBTRACT) {
op = DFVM_SUBTRACT;
}
else if (st_op == OP_MULTIPLY) {
else if (st_op == STNODE_OP_MULTIPLY) {
op = DFVM_MULTIPLY;
}
else if (st_op == OP_DIVIDE) {
else if (st_op == STNODE_OP_DIVIDE) {
op = DFVM_DIVIDE;
}
else if (st_op == OP_MODULO) {
else if (st_op == STNODE_OP_MODULO) {
op = DFVM_MODULO;
}
else if (st_op == OP_BITWISE_AND) {
else if (st_op == STNODE_OP_BITWISE_AND) {
op = MK_BITWISE_AND;
}
else {
@ -603,28 +603,28 @@ gen_notzero(dfwork_t *dfw, stnode_t *st_node)
static void
gen_test(dfwork_t *dfw, stnode_t *st_node)
{
test_op_t st_op;
test_match_t st_how;
stnode_op_t st_op;
stmatch_t st_how;
stnode_t *st_arg1, *st_arg2;
dfvm_insn_t *insn;
dfvm_value_t *jmp;
sttype_test_get(st_node, &st_op, &st_arg1, &st_arg2);
sttype_oper_get(st_node, &st_op, &st_arg1, &st_arg2);
st_how = sttype_test_get_match(st_node);
switch (st_op) {
case TEST_OP_UNINITIALIZED:
case STNODE_OP_UNINITIALIZED:
ws_assert_not_reached();
break;
case TEST_OP_NOT:
case STNODE_OP_NOT:
gencode(dfw, st_arg1);
insn = dfvm_insn_new(NOT);
dfw_append_insn(dfw, insn);
break;
case TEST_OP_AND:
case STNODE_OP_AND:
gencode(dfw, st_arg1);
insn = dfvm_insn_new(IF_FALSE_GOTO);
@ -636,7 +636,7 @@ gen_test(dfwork_t *dfw, stnode_t *st_node)
jmp->value.numeric = dfw->next_insn_id;
break;
case TEST_OP_OR:
case STNODE_OP_OR:
gencode(dfw, st_arg1);
insn = dfvm_insn_new(IF_TRUE_GOTO);
@ -648,57 +648,57 @@ gen_test(dfwork_t *dfw, stnode_t *st_node)
jmp->value.numeric = dfw->next_insn_id;
break;
case TEST_OP_ALL_EQ:
case STNODE_OP_ALL_EQ:
gen_relation(dfw, ALL_EQ, st_how, st_arg1, st_arg2);
break;
case TEST_OP_ANY_EQ:
case STNODE_OP_ANY_EQ:
gen_relation(dfw, ANY_EQ, st_how, st_arg1, st_arg2);
break;
case TEST_OP_ALL_NE:
case STNODE_OP_ALL_NE:
gen_relation(dfw, ALL_NE, st_how, st_arg1, st_arg2);
break;
case TEST_OP_ANY_NE:
case STNODE_OP_ANY_NE:
gen_relation(dfw, ANY_NE, st_how, st_arg1, st_arg2);
break;
case TEST_OP_GT:
case STNODE_OP_GT:
gen_relation(dfw, ANY_GT, st_how, st_arg1, st_arg2);
break;
case TEST_OP_GE:
case STNODE_OP_GE:
gen_relation(dfw, ANY_GE, st_how, st_arg1, st_arg2);
break;
case TEST_OP_LT:
case STNODE_OP_LT:
gen_relation(dfw, ANY_LT, st_how, st_arg1, st_arg2);
break;
case TEST_OP_LE:
case STNODE_OP_LE:
gen_relation(dfw, ANY_LE, st_how, st_arg1, st_arg2);
break;
case TEST_OP_CONTAINS:
case STNODE_OP_CONTAINS:
gen_relation(dfw, ANY_CONTAINS, st_how, st_arg1, st_arg2);
break;
case TEST_OP_MATCHES:
case STNODE_OP_MATCHES:
gen_relation(dfw, ANY_MATCHES, st_how, st_arg1, st_arg2);
break;
case TEST_OP_IN:
case STNODE_OP_IN:
gen_relation_in(dfw, st_how, st_arg1, st_arg2);
break;
case OP_BITWISE_AND:
case OP_UNARY_MINUS:
case OP_ADD:
case OP_SUBTRACT:
case OP_MULTIPLY:
case OP_DIVIDE:
case OP_MODULO:
case STNODE_OP_BITWISE_AND:
case STNODE_OP_UNARY_MINUS:
case STNODE_OP_ADD:
case STNODE_OP_SUBTRACT:
case STNODE_OP_MULTIPLY:
case STNODE_OP_DIVIDE:
case STNODE_OP_MODULO:
ws_assert_not_reached();
break;
}

View File

@ -8,7 +8,7 @@
#include "syntax-tree.h"
#include "sttype-field.h"
#include "sttype-slice.h"
#include "sttype-test.h"
#include "sttype-op.h"
#include "sttype-function.h"
#include "sttype-set.h"
#include "drange.h"
@ -99,19 +99,19 @@ expr(X) ::= arithmetic_expr(E). { X = E; }
expr(X) ::= expr(Y) TEST_AND(T) expr(Z).
{
X = T;
sttype_test_set2(X, TEST_OP_AND, Y, Z);
sttype_oper_set2(X, STNODE_OP_AND, Y, Z);
}
expr(X) ::= expr(Y) TEST_OR(T) expr(Z).
{
X = T;
sttype_test_set2(X, TEST_OP_OR, Y, Z);
sttype_oper_set2(X, STNODE_OP_OR, Y, Z);
}
expr(X) ::= TEST_NOT(T) expr(Y).
{
X = T;
sttype_test_set1(X, TEST_OP_NOT, Y);
sttype_oper_set1(X, STNODE_OP_NOT, Y);
}
/* Any expression inside parens is simply that expression */
@ -213,43 +213,43 @@ arithmetic_expr(T) ::= PLUS entity(N). [UNARY_PLUS]
arithmetic_expr(T) ::= MINUS(M) entity(N). [UNARY_MINUS]
{
T = M;
sttype_test_set1(T, OP_UNARY_MINUS, N);
sttype_oper_set1(T, STNODE_OP_UNARY_MINUS, N);
}
arithmetic_expr(T) ::= arithmetic_expr(F) BITWISE_AND(O) arithmetic_expr(M).
{
T = O;
sttype_test_set2(T, OP_BITWISE_AND, F, M);
sttype_oper_set2(T, STNODE_OP_BITWISE_AND, F, M);
}
arithmetic_expr(T) ::= arithmetic_expr(F) PLUS(O) arithmetic_expr(M).
{
T = O;
sttype_test_set2(T, OP_ADD, F, M);
sttype_oper_set2(T, STNODE_OP_ADD, F, M);
}
arithmetic_expr(T) ::= arithmetic_expr(F) MINUS(O) arithmetic_expr(M).
{
T = O;
sttype_test_set2(T, OP_SUBTRACT, F, M);
sttype_oper_set2(T, STNODE_OP_SUBTRACT, F, M);
}
arithmetic_expr(T) ::= arithmetic_expr(F) STAR(O) arithmetic_expr(M).
{
T = O;
sttype_test_set2(T, OP_MULTIPLY, F, M);
sttype_oper_set2(T, STNODE_OP_MULTIPLY, F, M);
}
arithmetic_expr(T) ::= arithmetic_expr(F) RSLASH(O) arithmetic_expr(M).
{
T = O;
sttype_test_set2(T, OP_DIVIDE, F, M);
sttype_oper_set2(T, STNODE_OP_DIVIDE, F, M);
}
arithmetic_expr(T) ::= arithmetic_expr(F) PERCENT(O) arithmetic_expr(M).
{
T = O;
sttype_test_set2(T, OP_MODULO, F, M);
sttype_oper_set2(T, STNODE_OP_MODULO, F, M);
}
arithmetic_expr(T) ::= LBRACE arithmetic_expr(F) RBRACE.
@ -258,40 +258,40 @@ arithmetic_expr(T) ::= LBRACE arithmetic_expr(F) RBRACE.
}
/* Relational tests */
cmp_op(O) ::= TEST_ALL_EQ(L). { O = L; sttype_test_set_op(O, TEST_OP_ALL_EQ); }
cmp_op(O) ::= TEST_ANY_EQ(L). { O = L; sttype_test_set_op(O, TEST_OP_ANY_EQ); }
cmp_op(O) ::= TEST_ALL_NE(L). { O = L; sttype_test_set_op(O, TEST_OP_ALL_NE); }
cmp_op(O) ::= TEST_ANY_NE(L). { O = L; sttype_test_set_op(O, TEST_OP_ANY_NE); }
cmp_op(O) ::= TEST_GT(L). { O = L; sttype_test_set_op(O, TEST_OP_GT); }
cmp_op(O) ::= TEST_GE(L). { O = L; sttype_test_set_op(O, TEST_OP_GE); }
cmp_op(O) ::= TEST_LT(L). { O = L; sttype_test_set_op(O, TEST_OP_LT); }
cmp_op(O) ::= TEST_LE(L). { O = L; sttype_test_set_op(O, TEST_OP_LE); }
cmp_op(O) ::= TEST_ALL_EQ(L). { O = L; sttype_oper_set_op(O, STNODE_OP_ALL_EQ); }
cmp_op(O) ::= TEST_ANY_EQ(L). { O = L; sttype_oper_set_op(O, STNODE_OP_ANY_EQ); }
cmp_op(O) ::= TEST_ALL_NE(L). { O = L; sttype_oper_set_op(O, STNODE_OP_ALL_NE); }
cmp_op(O) ::= TEST_ANY_NE(L). { O = L; sttype_oper_set_op(O, STNODE_OP_ANY_NE); }
cmp_op(O) ::= TEST_GT(L). { O = L; sttype_oper_set_op(O, STNODE_OP_GT); }
cmp_op(O) ::= TEST_GE(L). { O = L; sttype_oper_set_op(O, STNODE_OP_GE); }
cmp_op(O) ::= TEST_LT(L). { O = L; sttype_oper_set_op(O, STNODE_OP_LT); }
cmp_op(O) ::= TEST_LE(L). { O = L; sttype_oper_set_op(O, STNODE_OP_LE); }
comparison_test(T) ::= arithmetic_expr(E) cmp_op(O) arithmetic_expr(F).
{
T = O;
sttype_test_set2_args(O, E, F);
sttype_oper_set2_args(O, E, F);
}
/* 'a == b == c' or 'a < b <= c <= d < e' */
comparison_test(T) ::= arithmetic_expr(E) cmp_op(O) comparison_test(R).
{
stnode_t *L, *F;
/* for now generate it like E O F TEST_OP_AND F P G, later it could be optimized
/* for now generate it like E O F STNODE_OP_AND F P G, later it could be optimized
or semantically checked (to make a <= b >= c or a == b != c invalid)?
*/
F = R;
do {
ws_assert(F != NULL && stnode_type_id(F) == STTYPE_TEST);
sttype_test_get(F, NULL, &F, NULL);
sttype_oper_get(F, NULL, &F, NULL);
} while (stnode_type_id(F) == STTYPE_TEST);
L = O;
sttype_test_set2_args(L, E, stnode_dup(F));
sttype_oper_set2_args(L, E, stnode_dup(F));
T = stnode_new(STTYPE_TEST, NULL, NULL, NULL);
sttype_test_set2(T, TEST_OP_AND, L, R);
sttype_oper_set2(T, STNODE_OP_AND, L, R);
}
relation_test(T) ::= comparison_test(C). { T = C; }
@ -299,26 +299,26 @@ relation_test(T) ::= comparison_test(C). { T = C; }
relation_test(T) ::= entity(E) TEST_CONTAINS(L) entity(F).
{
T = L;
sttype_test_set2(T, TEST_OP_CONTAINS, E, F);
sttype_oper_set2(T, STNODE_OP_CONTAINS, E, F);
}
relation_test(T) ::= entity(E) TEST_MATCHES(L) entity(F).
{
T = L;
sttype_test_set2(T, TEST_OP_MATCHES, E, F);
sttype_oper_set2(T, STNODE_OP_MATCHES, E, F);
}
relation_test(T) ::= entity(E) TEST_IN(O) set(S).
{
T = O;
sttype_test_set2(T, TEST_OP_IN, E, S);
sttype_oper_set2(T, STNODE_OP_IN, E, S);
}
relation_test(T) ::= entity(E) TEST_NOT(P) TEST_IN(O) set(S).
{
T = P;
sttype_test_set2(O, TEST_OP_IN, E, S);
sttype_test_set1(T, TEST_OP_NOT, O);
sttype_oper_set2(O, STNODE_OP_IN, E, S);
sttype_oper_set1(T, STNODE_OP_NOT, O);
}
relation(R) ::= relation_test(T). { R = T; }
@ -326,13 +326,13 @@ relation(R) ::= relation_test(T). { R = T; }
relation(R) ::= ANY relation_test(T).
{
R = T;
sttype_test_set_match(R, ST_MATCH_ANY);
sttype_test_set_match(R, STNODE_MATCH_ANY);
}
relation(R) ::= ALL relation_test(T).
{
R = T;
sttype_test_set_match(R, ST_MATCH_ALL);
sttype_test_set_match(R, STNODE_MATCH_ALL);
}
set(S) ::= LBRACE set_list(L) RBRACE.
@ -358,7 +358,7 @@ set_entity(N) ::= entity(E).
set_entity(N) ::= MINUS(M) entity(E).
{
N = M;
sttype_test_set1(N, OP_UNARY_MINUS, E);
sttype_oper_set1(N, STNODE_OP_UNARY_MINUS, E);
}
set_entity(N) ::= PLUS entity(E).

View File

@ -17,7 +17,7 @@
#include "syntax-tree.h"
#include "sttype-field.h"
#include "sttype-slice.h"
#include "sttype-test.h"
#include "sttype-op.h"
#include "sttype-set.h"
#include "sttype-function.h"
#include "sttype-pointer.h"
@ -592,7 +592,7 @@ dfilter_fvalue_from_charconst(dfwork_t *dfw, ftenum_t ftype, stnode_t *st)
/* If the LHS of a relation test is a FIELD, run some checks
* and possibly some modifications of syntax tree nodes. */
static void
check_relation_LHS_FIELD(dfwork_t *dfw, test_op_t st_op,
check_relation_LHS_FIELD(dfwork_t *dfw, stnode_op_t st_op,
FtypeCanFunc can_func, gboolean allow_partial_value,
stnode_t *st_node,
stnode_t *st_arg1, stnode_t *st_arg2)
@ -680,7 +680,7 @@ check_relation_LHS_FIELD(dfwork_t *dfw, test_op_t st_op,
}
}
else if (type2 == STTYPE_PCRE) {
ws_assert(st_op == TEST_OP_MATCHES);
ws_assert(st_op == STNODE_OP_MATCHES);
}
else if (type2 == STTYPE_ARITHMETIC) {
ftype2 = check_arithmetic_expr(dfw, st_arg2, ftype1);
@ -701,7 +701,7 @@ check_relation_LHS_FIELD(dfwork_t *dfw, test_op_t st_op,
}
static void
check_relation_LHS_SLICE(dfwork_t *dfw, test_op_t st_op,
check_relation_LHS_SLICE(dfwork_t *dfw, stnode_op_t st_op,
FtypeCanFunc can_func _U_,
gboolean allow_partial_value,
stnode_t *st_node _U_,
@ -761,7 +761,7 @@ check_relation_LHS_SLICE(dfwork_t *dfw, test_op_t st_op,
}
}
else if (type2 == STTYPE_PCRE) {
ws_assert(st_op == TEST_OP_MATCHES);
ws_assert(st_op == STNODE_OP_MATCHES);
}
else if (type2 == STTYPE_ARITHMETIC) {
ftype2 = check_arithmetic_expr(dfw, st_arg2, FT_BYTES);
@ -784,7 +784,7 @@ check_relation_LHS_SLICE(dfwork_t *dfw, test_op_t st_op,
/* If the LHS of a relation test is a FUNCTION, run some checks
* and possibly some modifications of syntax tree nodes. */
static void
check_relation_LHS_FUNCTION(dfwork_t *dfw, test_op_t st_op,
check_relation_LHS_FUNCTION(dfwork_t *dfw, stnode_op_t st_op,
FtypeCanFunc can_func, gboolean allow_partial_value,
stnode_t *st_node,
stnode_t *st_arg1, stnode_t *st_arg2)
@ -860,7 +860,7 @@ check_relation_LHS_FUNCTION(dfwork_t *dfw, test_op_t st_op,
}
}
else if (type2 == STTYPE_PCRE) {
ws_assert(st_op == TEST_OP_MATCHES);
ws_assert(st_op == STNODE_OP_MATCHES);
}
else if (type2 == STTYPE_ARITHMETIC) {
ftype2 = check_arithmetic_expr(dfw, st_arg2, ftype1);
@ -881,7 +881,7 @@ check_relation_LHS_FUNCTION(dfwork_t *dfw, test_op_t st_op,
}
static void
check_relation_LHS_ARITHMETIC(dfwork_t *dfw, test_op_t st_op _U_,
check_relation_LHS_ARITHMETIC(dfwork_t *dfw, stnode_op_t st_op _U_,
FtypeCanFunc can_func _U_, gboolean allow_partial_value,
stnode_t *st_node, stnode_t *st_arg1, stnode_t *st_arg2)
{
@ -892,7 +892,7 @@ check_relation_LHS_ARITHMETIC(dfwork_t *dfw, test_op_t st_op _U_,
check_arithmetic_expr(dfw, st_arg1, FT_NONE);
sttype_test_get(st_arg1, NULL, &entity, NULL);
sttype_oper_get(st_arg1, NULL, &entity, NULL);
entity_type = stnode_type_id(entity);
if (IS_FIELD_ENTITY(entity_type)) {
@ -914,7 +914,7 @@ check_relation_LHS_ARITHMETIC(dfwork_t *dfw, test_op_t st_op _U_,
/* Check the semantics of any relational test. */
static void
check_relation(dfwork_t *dfw, test_op_t st_op,
check_relation(dfwork_t *dfw, stnode_op_t st_op,
FtypeCanFunc can_func, gboolean allow_partial_value,
stnode_t *st_node, stnode_t *st_arg1, stnode_t *st_arg2)
{
@ -953,15 +953,15 @@ check_relation_contains(dfwork_t *dfw, stnode_t *st_node,
switch (stnode_type_id(st_arg1)) {
case STTYPE_FIELD:
case STTYPE_REFERENCE:
check_relation_LHS_FIELD(dfw, TEST_OP_CONTAINS, ftype_can_contains,
check_relation_LHS_FIELD(dfw, STNODE_OP_CONTAINS, ftype_can_contains,
TRUE, st_node, st_arg1, st_arg2);
break;
case STTYPE_FUNCTION:
check_relation_LHS_FUNCTION(dfw, TEST_OP_CONTAINS, ftype_can_contains,
check_relation_LHS_FUNCTION(dfw, STNODE_OP_CONTAINS, ftype_can_contains,
TRUE, st_node, st_arg1, st_arg2);
break;
case STTYPE_SLICE:
check_relation_LHS_SLICE(dfw, TEST_OP_CONTAINS, ftype_can_contains,
check_relation_LHS_SLICE(dfw, STNODE_OP_CONTAINS, ftype_can_contains,
TRUE, st_node, st_arg1, st_arg2);
break;
default:
@ -1000,15 +1000,15 @@ check_relation_matches(dfwork_t *dfw, stnode_t *st_node,
switch (stnode_type_id(st_arg1)) {
case STTYPE_FIELD:
case STTYPE_REFERENCE:
check_relation_LHS_FIELD(dfw, TEST_OP_MATCHES, ftype_can_matches,
check_relation_LHS_FIELD(dfw, STNODE_OP_MATCHES, ftype_can_matches,
TRUE, st_node, st_arg1, st_arg2);
break;
case STTYPE_FUNCTION:
check_relation_LHS_FUNCTION(dfw, TEST_OP_MATCHES, ftype_can_matches,
check_relation_LHS_FUNCTION(dfw, STNODE_OP_MATCHES, ftype_can_matches,
TRUE, st_node, st_arg1, st_arg2);
break;
case STTYPE_SLICE:
check_relation_LHS_SLICE(dfw, TEST_OP_MATCHES, ftype_can_matches,
check_relation_LHS_SLICE(dfw, STNODE_OP_MATCHES, ftype_can_matches,
TRUE, st_node, st_arg1, st_arg2);
break;
default:
@ -1050,12 +1050,12 @@ check_relation_in(dfwork_t *dfw, stnode_t *st_node _U_,
ws_assert(nodelist);
node_right = nodelist->data;
if (node_right) {
check_relation_LHS_FIELD(dfw, TEST_OP_GE, ftype_can_cmp,
check_relation_LHS_FIELD(dfw, STNODE_OP_GE, ftype_can_cmp,
FALSE, st_node, st_arg1, node_left);
check_relation_LHS_FIELD(dfw, TEST_OP_LE, ftype_can_cmp,
check_relation_LHS_FIELD(dfw, STNODE_OP_LE, ftype_can_cmp,
FALSE, st_node, st_arg1, node_right);
} else {
check_relation_LHS_FIELD(dfw, TEST_OP_ANY_EQ, ftype_can_eq,
check_relation_LHS_FIELD(dfw, STNODE_OP_ANY_EQ, ftype_can_eq,
FALSE, st_node, st_arg1, node_left);
}
nodelist = g_slist_next(nodelist);
@ -1066,47 +1066,47 @@ check_relation_in(dfwork_t *dfw, stnode_t *st_node _U_,
static void
check_test(dfwork_t *dfw, stnode_t *st_node)
{
test_op_t st_op;
stnode_op_t st_op;
stnode_t *st_arg1, *st_arg2;
LOG_NODE(st_node);
sttype_test_get(st_node, &st_op, &st_arg1, &st_arg2);
sttype_oper_get(st_node, &st_op, &st_arg1, &st_arg2);
switch (st_op) {
case TEST_OP_UNINITIALIZED:
case STNODE_OP_UNINITIALIZED:
ws_assert_not_reached();
break;
case TEST_OP_NOT:
case STNODE_OP_NOT:
semcheck(dfw, st_arg1);
break;
case TEST_OP_AND:
case TEST_OP_OR:
case STNODE_OP_AND:
case STNODE_OP_OR:
semcheck(dfw, st_arg1);
semcheck(dfw, st_arg2);
break;
case TEST_OP_ALL_EQ:
case TEST_OP_ANY_EQ:
case TEST_OP_ALL_NE:
case TEST_OP_ANY_NE:
case STNODE_OP_ALL_EQ:
case STNODE_OP_ANY_EQ:
case STNODE_OP_ALL_NE:
case STNODE_OP_ANY_NE:
check_relation(dfw, st_op, ftype_can_eq, FALSE, st_node, st_arg1, st_arg2);
break;
case TEST_OP_GT:
case TEST_OP_GE:
case TEST_OP_LT:
case TEST_OP_LE:
case STNODE_OP_GT:
case STNODE_OP_GE:
case STNODE_OP_LT:
case STNODE_OP_LE:
check_relation(dfw, st_op, ftype_can_cmp, FALSE, st_node, st_arg1, st_arg2);
break;
case TEST_OP_CONTAINS:
case STNODE_OP_CONTAINS:
check_relation_contains(dfw, st_node, st_arg1, st_arg2);
break;
case TEST_OP_MATCHES:
case STNODE_OP_MATCHES:
check_relation_matches(dfw, st_node, st_arg1, st_arg2);
break;
case TEST_OP_IN:
case STNODE_OP_IN:
check_relation_in(dfw, st_node, st_arg1, st_arg2);
break;
@ -1162,7 +1162,7 @@ check_arithmetic_entity(dfwork_t *dfw, stnode_t *st_arg, ftenum_t lhs_ftype)
ftenum_t
check_arithmetic_expr(dfwork_t *dfw, stnode_t *st_node, ftenum_t lhs_ftype)
{
test_op_t st_op;
stnode_op_t st_op;
stnode_t *st_arg1, *st_arg2;
ftenum_t ftype1, ftype2;
FtypeCanFunc can_func = NULL;
@ -1173,14 +1173,14 @@ check_arithmetic_expr(dfwork_t *dfw, stnode_t *st_node, ftenum_t lhs_ftype)
return check_arithmetic_entity(dfw, st_node, lhs_ftype);
}
sttype_test_get(st_node, &st_op, &st_arg1, &st_arg2);
sttype_oper_get(st_node, &st_op, &st_arg1, &st_arg2);
/* On the LHS we require a field-like value as the first term. */
if (lhs_ftype == FT_NONE && node_is_constant(st_arg1)) {
FAIL(dfw, st_arg1, "Constant arithmetic expression on the LHS is invalid.");
}
if (st_op == OP_UNARY_MINUS) {
if (st_op == STNODE_OP_UNARY_MINUS) {
ftype1 = check_arithmetic_entity(dfw, st_arg1, lhs_ftype);
if (stnode_type_id(st_arg1) == STTYPE_FVALUE) {
/* Pre-compute constant unary minus result */
@ -1202,22 +1202,22 @@ check_arithmetic_expr(dfwork_t *dfw, stnode_t *st_node, ftenum_t lhs_ftype)
ftype2 = check_arithmetic_expr(dfw, st_arg2, ftype1);
switch (st_op) {
case OP_ADD:
case STNODE_OP_ADD:
can_func = ftype_can_add;
break;
case OP_SUBTRACT:
case STNODE_OP_SUBTRACT:
can_func = ftype_can_subtract;
break;
case OP_MULTIPLY:
case STNODE_OP_MULTIPLY:
can_func = ftype_can_multiply;
break;
case OP_DIVIDE:
case STNODE_OP_DIVIDE:
can_func = ftype_can_divide;
break;
case OP_MODULO:
case STNODE_OP_MODULO:
can_func = ftype_can_modulo;
break;
case OP_BITWISE_AND:
case STNODE_OP_BITWISE_AND:
can_func = ftype_can_bitwise_and;
break;
default:

402
epan/dfilter/sttype-op.c Normal file
View File

@ -0,0 +1,402 @@
/*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 2001 Gerald Combs
*
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "syntax-tree.h"
#include "sttype-op.h"
typedef struct {
guint32 magic;
stnode_op_t op;
stmatch_t how;
stnode_t *val1;
stnode_t *val2;
} oper_t;
#define OPER_MAGIC 0xab9009ba
static gpointer
oper_new(gpointer junk)
{
oper_t *oper;
ws_assert(junk == NULL);
oper = g_new(oper_t, 1);
oper->magic = OPER_MAGIC;
oper->op = STNODE_OP_UNINITIALIZED;
oper->how = STNODE_MATCH_DEF;
oper->val1 = NULL;
oper->val2 = NULL;
return oper;
}
static gpointer
oper_dup(gconstpointer data)
{
const oper_t *org = data;
oper_t *oper;
oper = oper_new(NULL);
oper->op = org->op;
oper->how = org->how;
oper->val1 = stnode_dup(org->val1);
oper->val2 = stnode_dup(org->val1);
return oper;
}
static void
oper_free(gpointer value)
{
oper_t *oper = value;
ws_assert_magic(oper, OPER_MAGIC);
if (oper->val1)
stnode_free(oper->val1);
if (oper->val2)
stnode_free(oper->val2);
g_free(oper);
}
static char *
oper_todisplay(const oper_t *oper)
{
const char *s = "<notset>";
switch(oper->op) {
case STNODE_OP_NOT:
s = "!";
break;
case STNODE_OP_AND:
s = "&&";
break;
case STNODE_OP_OR:
s = "||";
break;
case STNODE_OP_ALL_EQ:
s = "===";
break;
case STNODE_OP_ANY_EQ:
s = "==";
break;
case STNODE_OP_ALL_NE:
s = "!=";
break;
case STNODE_OP_ANY_NE:
s = "~=";
break;
case STNODE_OP_GT:
s = ">";
break;
case STNODE_OP_GE:
s = ">=";
break;
case STNODE_OP_LT:
s = "<";
break;
case STNODE_OP_LE:
s = "<=";
break;
case STNODE_OP_BITWISE_AND:
s = "&";
break;
case STNODE_OP_ADD:
s = "+";
break;
case STNODE_OP_UNARY_MINUS:
case STNODE_OP_SUBTRACT:
s = "-";
break;
case STNODE_OP_MULTIPLY:
s = "*";
break;
case STNODE_OP_DIVIDE:
s = "/";
break;
case STNODE_OP_MODULO:
s = "%";
break;
case STNODE_OP_CONTAINS:
s = "contains";
break;
case STNODE_OP_MATCHES:
s = "matches";
break;
case STNODE_OP_IN:
s = "in";
break;
case STNODE_OP_UNINITIALIZED:
s = "<uninitialized>";
break;
}
return g_strdup(s);
}
static char *
oper_todebug(const oper_t *oper)
{
const char *s = "<notset>";
switch(oper->op) {
case STNODE_OP_NOT:
s = "TEST_NOT";
break;
case STNODE_OP_AND:
s = "TEST_AND";
break;
case STNODE_OP_OR:
s = "TEST_OR";
break;
case STNODE_OP_ALL_EQ:
s = "TEST_ALL_EQ";
break;
case STNODE_OP_ANY_EQ:
s = "TEST_ANY_EQ";
break;
case STNODE_OP_ALL_NE:
s = "TEST_ALL_NE";
break;
case STNODE_OP_ANY_NE:
s = "TEST_ANY_NE";
break;
case STNODE_OP_GT:
s = "TEST_GT";
break;
case STNODE_OP_GE:
s = "TEST_GE";
break;
case STNODE_OP_LT:
s = "TEST_LT";
break;
case STNODE_OP_LE:
s = "TEST_LE";
break;
case STNODE_OP_BITWISE_AND:
s = "STNODE_OP_BITWISE_AND";
break;
case STNODE_OP_UNARY_MINUS:
s = "STNODE_OP_UNARY_MINUS";
break;
case STNODE_OP_ADD:
s = "STNODE_OP_ADD";
break;
case STNODE_OP_SUBTRACT:
s = "STNODE_OP_SUBTRACT";
break;
case STNODE_OP_MULTIPLY:
s = "STNODE_OP_MULTIPLY";
break;
case STNODE_OP_DIVIDE:
s = "STNODE_OP_DIVIDE";
break;
case STNODE_OP_MODULO:
s = "STNODE_OP_MODULO";
break;
case STNODE_OP_CONTAINS:
s = "TEST_CONTAINS";
break;
case STNODE_OP_MATCHES:
s = "TEST_MATCHES";
break;
case STNODE_OP_IN:
s = "TEST_IN";
break;
case STNODE_OP_UNINITIALIZED:
s = "<uninitialized>";
break;
}
if (oper->how == STNODE_MATCH_ALL)
return g_strdup_printf("ALL %s", s);
if (oper->how == STNODE_MATCH_ANY)
return g_strdup_printf("ANY %s", s);
return g_strdup(s);
}
static char *
oper_tostr(const void *value, gboolean pretty)
{
const oper_t *oper = value;
ws_assert_magic(oper, OPER_MAGIC);
if (pretty)
return oper_todisplay(oper);
return oper_todebug(oper);
}
static int
num_operands(stnode_op_t op)
{
switch(op) {
case STNODE_OP_UNINITIALIZED:
break;
case STNODE_OP_NOT:
case STNODE_OP_UNARY_MINUS:
return 1;
case STNODE_OP_AND:
case STNODE_OP_OR:
case STNODE_OP_ALL_EQ:
case STNODE_OP_ANY_EQ:
case STNODE_OP_ALL_NE:
case STNODE_OP_ANY_NE:
case STNODE_OP_GT:
case STNODE_OP_GE:
case STNODE_OP_LT:
case STNODE_OP_LE:
case STNODE_OP_BITWISE_AND:
case STNODE_OP_ADD:
case STNODE_OP_SUBTRACT:
case STNODE_OP_MULTIPLY:
case STNODE_OP_DIVIDE:
case STNODE_OP_MODULO:
case STNODE_OP_CONTAINS:
case STNODE_OP_MATCHES:
case STNODE_OP_IN:
return 2;
}
ws_assert_not_reached();
return -1;
}
void
sttype_oper_set1(stnode_t *node, stnode_op_t op, stnode_t *val1)
{
oper_t *oper = stnode_data(node);
ws_assert_magic(oper, OPER_MAGIC);
ws_assert(num_operands(op) == 1);
oper->op = op;
oper->val1 = val1;
oper->val2 = NULL;
}
void
sttype_oper_set2(stnode_t *node, stnode_op_t op, stnode_t *val1, stnode_t *val2)
{
oper_t *oper = stnode_data(node);
ws_assert_magic(oper, OPER_MAGIC);
ws_assert(num_operands(op) == 2);
oper->op = op;
oper->val1 = val1;
oper->val2 = val2;
}
void
sttype_oper_set1_args(stnode_t *node, stnode_t *val1)
{
oper_t *oper;
oper = (oper_t*)stnode_data(node);
ws_assert_magic(oper, OPER_MAGIC);
ws_assert(num_operands(oper->op) == 1);
oper->val1 = val1;
oper->val2 = NULL;
}
void
sttype_oper_set2_args(stnode_t *node, stnode_t *val1, stnode_t *val2)
{
oper_t *oper;
oper = (oper_t*)stnode_data(node);
ws_assert_magic(oper, OPER_MAGIC);
ws_assert(num_operands(oper->op) == 2);
oper->val1 = val1;
oper->val2 = val2;
}
void
sttype_oper_set_op(stnode_t *node, stnode_op_t op)
{
oper_t *oper = stnode_data(node);
ws_assert_magic(oper, OPER_MAGIC);
ws_assert(oper->op == STNODE_OP_UNINITIALIZED);
oper->op = op;
}
stnode_op_t
sttype_oper_get_op(stnode_t *node)
{
ws_assert_magic(node, OPER_MAGIC);
return ((oper_t *)node)->op;
}
void
sttype_oper_get(stnode_t *node, stnode_op_t *p_op, stnode_t **p_val1, stnode_t **p_val2)
{
oper_t *oper = stnode_data(node);
ws_assert_magic(oper, OPER_MAGIC);
if (p_op)
*p_op = oper->op;
if (p_val1)
*p_val1 = oper->val1;
if (p_val2)
*p_val2 = oper->val2;
}
void
sttype_test_set_match(stnode_t *node, stmatch_t how)
{
oper_t *oper = stnode_data(node);
ws_assert_magic(oper, OPER_MAGIC);
oper->how = how;
}
stmatch_t
sttype_test_get_match(stnode_t *node)
{
oper_t *oper = stnode_data(node);
ws_assert_magic(oper, OPER_MAGIC);
return oper->how;
}
void
sttype_register_opers(void)
{
static sttype_t test_type = {
STTYPE_TEST,
"TEST",
oper_new,
oper_free,
oper_dup,
oper_tostr
};
static sttype_t arithmetic_type = {
STTYPE_ARITHMETIC,
"ARITHMETIC",
oper_new,
oper_free,
oper_dup,
oper_tostr
};
sttype_register(&test_type);
sttype_register(&arithmetic_type);
}
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 8
* tab-width: 8
* indent-tabs-mode: t
* End:
*
* vi: set shiftwidth=8 tabstop=8 noexpandtab:
* :indentSize=8:tabSize=8:noTabs=false:
*/

41
epan/dfilter/sttype-op.h Normal file
View File

@ -0,0 +1,41 @@
/** @file
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 2001 Gerald Combs
*
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef STTYPE_TEST_H
#define STTYPE_TEST_H
void
sttype_oper_set1(stnode_t *node, stnode_op_t op, stnode_t *val1);
void
sttype_oper_set2(stnode_t *node, stnode_op_t op, stnode_t *val1, stnode_t *val2);
void
sttype_oper_set1_args(stnode_t *node, stnode_t *val1);
void
sttype_oper_set2_args(stnode_t *node, stnode_t *val1, stnode_t *val2);
void
sttype_oper_set_op(stnode_t *node, stnode_op_t op);
stnode_op_t
sttype_oper_get_op(stnode_t *node);
void
sttype_oper_get(stnode_t *node, stnode_op_t *p_op, stnode_t **p_val1, stnode_t **p_val2);
void
sttype_test_set_match(stnode_t *node, stmatch_t how);
stmatch_t
sttype_test_get_match(stnode_t *node);
#endif

View File

@ -1,402 +0,0 @@
/*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 2001 Gerald Combs
*
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "syntax-tree.h"
#include "sttype-test.h"
typedef struct {
guint32 magic;
test_op_t op;
test_match_t how;
stnode_t *val1;
stnode_t *val2;
} test_t;
#define TEST_MAGIC 0xab9009ba
static gpointer
test_new(gpointer junk)
{
test_t *test;
ws_assert(junk == NULL);
test = g_new(test_t, 1);
test->magic = TEST_MAGIC;
test->op = TEST_OP_UNINITIALIZED;
test->how = ST_MATCH_DEF;
test->val1 = NULL;
test->val2 = NULL;
return test;
}
static gpointer
test_dup(gconstpointer data)
{
const test_t *org = data;
test_t *test;
test = test_new(NULL);
test->op = org->op;
test->how = org->how;
test->val1 = stnode_dup(org->val1);
test->val2 = stnode_dup(org->val1);
return test;
}
static void
test_free(gpointer value)
{
test_t *test = value;
ws_assert_magic(test, TEST_MAGIC);
if (test->val1)
stnode_free(test->val1);
if (test->val2)
stnode_free(test->val2);
g_free(test);
}
static char *
test_todisplay(const test_t *test)
{
const char *s = "<notset>";
switch(test->op) {
case TEST_OP_NOT:
s = "!";
break;
case TEST_OP_AND:
s = "&&";
break;
case TEST_OP_OR:
s = "||";
break;
case TEST_OP_ALL_EQ:
s = "===";
break;
case TEST_OP_ANY_EQ:
s = "==";
break;
case TEST_OP_ALL_NE:
s = "!=";
break;
case TEST_OP_ANY_NE:
s = "~=";
break;
case TEST_OP_GT:
s = ">";
break;
case TEST_OP_GE:
s = ">=";
break;
case TEST_OP_LT:
s = "<";
break;
case TEST_OP_LE:
s = "<=";
break;
case OP_BITWISE_AND:
s = "&";
break;
case OP_ADD:
s = "+";
break;
case OP_UNARY_MINUS:
case OP_SUBTRACT:
s = "-";
break;
case OP_MULTIPLY:
s = "*";
break;
case OP_DIVIDE:
s = "/";
break;
case OP_MODULO:
s = "%";
break;
case TEST_OP_CONTAINS:
s = "contains";
break;
case TEST_OP_MATCHES:
s = "matches";
break;
case TEST_OP_IN:
s = "in";
break;
case TEST_OP_UNINITIALIZED:
s = "<uninitialized>";
break;
}
return g_strdup(s);
}
static char *
test_todebug(const test_t *test)
{
const char *s = "<notset>";
switch(test->op) {
case TEST_OP_NOT:
s = "TEST_NOT";
break;
case TEST_OP_AND:
s = "TEST_AND";
break;
case TEST_OP_OR:
s = "TEST_OR";
break;
case TEST_OP_ALL_EQ:
s = "TEST_ALL_EQ";
break;
case TEST_OP_ANY_EQ:
s = "TEST_ANY_EQ";
break;
case TEST_OP_ALL_NE:
s = "TEST_ALL_NE";
break;
case TEST_OP_ANY_NE:
s = "TEST_ANY_NE";
break;
case TEST_OP_GT:
s = "TEST_GT";
break;
case TEST_OP_GE:
s = "TEST_GE";
break;
case TEST_OP_LT:
s = "TEST_LT";
break;
case TEST_OP_LE:
s = "TEST_LE";
break;
case OP_BITWISE_AND:
s = "OP_BITWISE_AND";
break;
case OP_UNARY_MINUS:
s = "OP_UNARY_MINUS";
break;
case OP_ADD:
s = "OP_ADD";
break;
case OP_SUBTRACT:
s = "OP_SUBTRACT";
break;
case OP_MULTIPLY:
s = "OP_MULTIPLY";
break;
case OP_DIVIDE:
s = "OP_DIVIDE";
break;
case OP_MODULO:
s = "OP_MODULO";
break;
case TEST_OP_CONTAINS:
s = "TEST_CONTAINS";
break;
case TEST_OP_MATCHES:
s = "TEST_MATCHES";
break;
case TEST_OP_IN:
s = "TEST_IN";
break;
case TEST_OP_UNINITIALIZED:
s = "<uninitialized>";
break;
}
if (test->how == ST_MATCH_ALL)
return g_strdup_printf("ALL %s", s);
if (test->how == ST_MATCH_ANY)
return g_strdup_printf("ANY %s", s);
return g_strdup(s);
}
static char *
test_tostr(const void *value, gboolean pretty)
{
const test_t *test = value;
ws_assert_magic(test, TEST_MAGIC);
if (pretty)
return test_todisplay(test);
return test_todebug(test);
}
static int
num_operands(test_op_t op)
{
switch(op) {
case TEST_OP_UNINITIALIZED:
break;
case TEST_OP_NOT:
case OP_UNARY_MINUS:
return 1;
case TEST_OP_AND:
case TEST_OP_OR:
case TEST_OP_ALL_EQ:
case TEST_OP_ANY_EQ:
case TEST_OP_ALL_NE:
case TEST_OP_ANY_NE:
case TEST_OP_GT:
case TEST_OP_GE:
case TEST_OP_LT:
case TEST_OP_LE:
case OP_BITWISE_AND:
case OP_ADD:
case OP_SUBTRACT:
case OP_MULTIPLY:
case OP_DIVIDE:
case OP_MODULO:
case TEST_OP_CONTAINS:
case TEST_OP_MATCHES:
case TEST_OP_IN:
return 2;
}
ws_assert_not_reached();
return -1;
}
void
sttype_test_set1(stnode_t *node, test_op_t op, stnode_t *val1)
{
test_t *test = stnode_data(node);
ws_assert_magic(test, TEST_MAGIC);
ws_assert(num_operands(op) == 1);
test->op = op;
test->val1 = val1;
test->val2 = NULL;
}
void
sttype_test_set2(stnode_t *node, test_op_t op, stnode_t *val1, stnode_t *val2)
{
test_t *test = stnode_data(node);
ws_assert_magic(test, TEST_MAGIC);
ws_assert(num_operands(op) == 2);
test->op = op;
test->val1 = val1;
test->val2 = val2;
}
void
sttype_test_set1_args(stnode_t *node, stnode_t *val1)
{
test_t *test;
test = (test_t*)stnode_data(node);
ws_assert_magic(test, TEST_MAGIC);
ws_assert(num_operands(test->op) == 1);
test->val1 = val1;
test->val2 = NULL;
}
void
sttype_test_set2_args(stnode_t *node, stnode_t *val1, stnode_t *val2)
{
test_t *test;
test = (test_t*)stnode_data(node);
ws_assert_magic(test, TEST_MAGIC);
ws_assert(num_operands(test->op) == 2);
test->val1 = val1;
test->val2 = val2;
}
void
sttype_test_set_op(stnode_t *node, test_op_t op)
{
test_t *test = stnode_data(node);
ws_assert_magic(test, TEST_MAGIC);
ws_assert(test->op == TEST_OP_UNINITIALIZED);
test->op = op;
}
test_op_t
sttype_test_get_op(stnode_t *node)
{
ws_assert_magic(node, TEST_MAGIC);
return ((test_t *)node)->op;
}
void
sttype_test_get(stnode_t *node, test_op_t *p_op, stnode_t **p_val1, stnode_t **p_val2)
{
test_t *test = stnode_data(node);
ws_assert_magic(test, TEST_MAGIC);
if (p_op)
*p_op = test->op;
if (p_val1)
*p_val1 = test->val1;
if (p_val2)
*p_val2 = test->val2;
}
void
sttype_test_set_match(stnode_t *node, test_match_t how)
{
test_t *test = stnode_data(node);
ws_assert_magic(test, TEST_MAGIC);
test->how = how;
}
test_match_t
sttype_test_get_match(stnode_t *node)
{
test_t *test = stnode_data(node);
ws_assert_magic(test, TEST_MAGIC);
return test->how;
}
void
sttype_register_test(void)
{
static sttype_t test_type = {
STTYPE_TEST,
"TEST",
test_new,
test_free,
test_dup,
test_tostr
};
static sttype_t arithmetic_type = {
STTYPE_ARITHMETIC,
"ARITHMETIC",
test_new,
test_free,
test_dup,
test_tostr
};
sttype_register(&test_type);
sttype_register(&arithmetic_type);
}
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 8
* tab-width: 8
* indent-tabs-mode: t
* End:
*
* vi: set shiftwidth=8 tabstop=8 noexpandtab:
* :indentSize=8:tabSize=8:noTabs=false:
*/

View File

@ -1,41 +0,0 @@
/** @file
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 2001 Gerald Combs
*
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef STTYPE_TEST_H
#define STTYPE_TEST_H
void
sttype_test_set1(stnode_t *node, test_op_t op, stnode_t *val1);
void
sttype_test_set2(stnode_t *node, test_op_t op, stnode_t *val1, stnode_t *val2);
void
sttype_test_set1_args(stnode_t *node, stnode_t *val1);
void
sttype_test_set2_args(stnode_t *node, stnode_t *val1, stnode_t *val2);
void
sttype_test_set_op(stnode_t *node, test_op_t op);
test_op_t
sttype_test_get_op(stnode_t *node);
void
sttype_test_get(stnode_t *node, test_op_t *p_op, stnode_t **p_val1, stnode_t **p_val2);
void
sttype_test_set_match(stnode_t *node, test_match_t how);
test_match_t
sttype_test_get_match(stnode_t *node);
#endif

View File

@ -14,7 +14,7 @@
#include <wsutil/wmem/wmem.h>
#include <wsutil/str_util.h>
#include <wsutil/glib-compat.h>
#include "sttype-test.h"
#include "sttype-op.h"
#include "sttype-function.h"
#include "dfilter-int.h"
@ -34,7 +34,7 @@ sttype_init(void)
sttype_register_set();
sttype_register_slice();
sttype_register_string();
sttype_register_test();
sttype_register_opers();
}
void
@ -349,11 +349,11 @@ log_test_full(enum ws_log_level level,
return;
}
test_op_t st_op;
stnode_op_t st_op;
stnode_t *st_lhs = NULL, *st_rhs = NULL;
char *lhs = NULL, *rhs = NULL;
sttype_test_get(node, &st_op, &st_lhs, &st_rhs);
sttype_oper_get(node, &st_op, &st_lhs, &st_rhs);
if (st_lhs)
lhs = sprint_node(st_lhs);
@ -390,7 +390,7 @@ visit_tree(wmem_strbuf_t *buf, stnode_t *node, int level)
if (stnode_type_id(node) == STTYPE_TEST ||
stnode_type_id(node) == STTYPE_ARITHMETIC) {
wmem_strbuf_append_printf(buf, "%s:\n", stnode_todebug(node));
sttype_test_get(node, NULL, &left, &right);
sttype_oper_get(node, NULL, &left, &right);
if (left && right) {
indent(buf, level + 1);
visit_tree(buf, left, level + 1);

View File

@ -37,37 +37,6 @@ typedef enum {
STTYPE_NUM_TYPES
} sttype_id_t;
typedef enum {
TEST_OP_UNINITIALIZED,
TEST_OP_NOT,
TEST_OP_AND,
TEST_OP_OR,
TEST_OP_ALL_EQ,
TEST_OP_ANY_EQ,
TEST_OP_ALL_NE,
TEST_OP_ANY_NE,
TEST_OP_GT,
TEST_OP_GE,
TEST_OP_LT,
TEST_OP_LE,
OP_BITWISE_AND,
OP_UNARY_MINUS,
OP_ADD,
OP_SUBTRACT,
OP_MULTIPLY,
OP_DIVIDE,
OP_MODULO,
TEST_OP_CONTAINS,
TEST_OP_MATCHES,
TEST_OP_IN
} test_op_t;
typedef enum {
ST_MATCH_DEF,
ST_MATCH_ANY,
ST_MATCH_ALL,
} test_match_t;
typedef gpointer (*STTypeNewFunc)(gpointer);
typedef gpointer (*STTypeDupFunc)(gconstpointer);
typedef void (*STTypeFreeFunc)(gpointer);
@ -100,6 +69,37 @@ typedef struct {
stloc_t location;
} stnode_t;
typedef enum {
STNODE_OP_UNINITIALIZED,
STNODE_OP_NOT,
STNODE_OP_AND,
STNODE_OP_OR,
STNODE_OP_ALL_EQ,
STNODE_OP_ANY_EQ,
STNODE_OP_ALL_NE,
STNODE_OP_ANY_NE,
STNODE_OP_GT,
STNODE_OP_GE,
STNODE_OP_LT,
STNODE_OP_LE,
STNODE_OP_CONTAINS,
STNODE_OP_MATCHES,
STNODE_OP_IN,
STNODE_OP_BITWISE_AND,
STNODE_OP_UNARY_MINUS,
STNODE_OP_ADD,
STNODE_OP_SUBTRACT,
STNODE_OP_MULTIPLY,
STNODE_OP_DIVIDE,
STNODE_OP_MODULO,
} stnode_op_t;
typedef enum {
STNODE_MATCH_DEF,
STNODE_MATCH_ANY,
STNODE_MATCH_ALL,
} stmatch_t;
/* These are the sttype_t registration function prototypes. */
void sttype_register_field(void);
void sttype_register_function(void);
@ -107,7 +107,7 @@ void sttype_register_pointer(void);
void sttype_register_set(void);
void sttype_register_slice(void);
void sttype_register_string(void);
void sttype_register_test(void);
void sttype_register_opers(void);
void
sttype_init(void);