forked from osmocom/wireshark
dfilter: Remove token value from syntax tree
Currently unused. This might still be useful to differentiate different spelling of the same token in user messages, like "==" and "eq", but currently we are not storing test tokens anyway, so just remove it, it makes everything simpler. If it's ever necessary it can be added back.
This commit is contained in:
parent
0e4851b025
commit
f5fea52982
|
@ -78,7 +78,7 @@ dfilter_new_function(dfwork_t *dfw, const char *name)
|
||||||
if (!def) {
|
if (!def) {
|
||||||
dfilter_parse_fail(dfw, "Function '%s' does not exist", name);
|
dfilter_parse_fail(dfw, "Function '%s' does not exist", name);
|
||||||
}
|
}
|
||||||
return stnode_new(STTYPE_FUNCTION, def, name);
|
return stnode_new(STTYPE_FUNCTION, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Gets a regex from a string, and sets the error message on failure. */
|
/* Gets a regex from a string, and sets the error message on failure. */
|
||||||
|
|
|
@ -110,25 +110,25 @@ expr(X) ::= logical_test(L). { X = L; }
|
||||||
/* Logical tests */
|
/* Logical tests */
|
||||||
logical_test(T) ::= expr(E) TEST_AND expr(F).
|
logical_test(T) ::= expr(E) TEST_AND expr(F).
|
||||||
{
|
{
|
||||||
T = stnode_new(STTYPE_TEST, NULL, NULL);
|
T = stnode_new(STTYPE_TEST, NULL);
|
||||||
sttype_test_set2(T, TEST_OP_AND, E, F);
|
sttype_test_set2(T, TEST_OP_AND, E, F);
|
||||||
}
|
}
|
||||||
|
|
||||||
logical_test(T) ::= expr(E) TEST_OR expr(F).
|
logical_test(T) ::= expr(E) TEST_OR expr(F).
|
||||||
{
|
{
|
||||||
T = stnode_new(STTYPE_TEST, NULL, NULL);
|
T = stnode_new(STTYPE_TEST, NULL);
|
||||||
sttype_test_set2(T, TEST_OP_OR, E, F);
|
sttype_test_set2(T, TEST_OP_OR, E, F);
|
||||||
}
|
}
|
||||||
|
|
||||||
logical_test(T) ::= TEST_NOT expr(E).
|
logical_test(T) ::= TEST_NOT expr(E).
|
||||||
{
|
{
|
||||||
T = stnode_new(STTYPE_TEST, NULL, NULL);
|
T = stnode_new(STTYPE_TEST, NULL);
|
||||||
sttype_test_set1(T, TEST_OP_NOT, E);
|
sttype_test_set1(T, TEST_OP_NOT, E);
|
||||||
}
|
}
|
||||||
|
|
||||||
logical_test(T) ::= entity(E).
|
logical_test(T) ::= entity(E).
|
||||||
{
|
{
|
||||||
T = stnode_new(STTYPE_TEST, NULL, NULL);
|
T = stnode_new(STTYPE_TEST, NULL);
|
||||||
sttype_test_set1(T, TEST_OP_EXISTS, E);
|
sttype_test_set1(T, TEST_OP_EXISTS, E);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,17 +137,17 @@ logical_test(T) ::= entity(E).
|
||||||
/* Entities, or things that can be compared/tested/checked */
|
/* Entities, or things that can be compared/tested/checked */
|
||||||
entity(E) ::= STRING(S).
|
entity(E) ::= STRING(S).
|
||||||
{
|
{
|
||||||
E = stnode_new(STTYPE_STRING, df_lval_value(S), df_lval_value(S));
|
E = stnode_new(STTYPE_STRING, df_lval_value(S));
|
||||||
df_lval_free(S);
|
df_lval_free(S);
|
||||||
}
|
}
|
||||||
entity(E) ::= CHARCONST(C).
|
entity(E) ::= CHARCONST(C).
|
||||||
{
|
{
|
||||||
E = stnode_new(STTYPE_CHARCONST, df_lval_value(C), df_lval_value(C));
|
E = stnode_new(STTYPE_CHARCONST, df_lval_value(C));
|
||||||
df_lval_free(C);
|
df_lval_free(C);
|
||||||
}
|
}
|
||||||
entity(E) ::= UNPARSED(U).
|
entity(E) ::= UNPARSED(U).
|
||||||
{
|
{
|
||||||
E = stnode_new(STTYPE_UNPARSED, df_lval_value(U), df_lval_value(U));
|
E = stnode_new(STTYPE_UNPARSED, df_lval_value(U));
|
||||||
dfilter_resolve_unparsed(dfw, E);
|
dfilter_resolve_unparsed(dfw, E);
|
||||||
df_lval_free(U);
|
df_lval_free(U);
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ entity(E) ::= function(F). { E = F; }
|
||||||
/* Ranges */
|
/* Ranges */
|
||||||
range(R) ::= entity(E) LBRACKET range_node_list(L) RBRACKET.
|
range(R) ::= entity(E) LBRACKET range_node_list(L) RBRACKET.
|
||||||
{
|
{
|
||||||
R = stnode_new(STTYPE_RANGE, NULL, NULL);
|
R = stnode_new(STTYPE_RANGE, NULL);
|
||||||
sttype_range_set(R, E, L);
|
sttype_range_set(R, E, L);
|
||||||
|
|
||||||
/* Delete the list, but not the drange_nodes that
|
/* Delete the list, but not the drange_nodes that
|
||||||
|
@ -202,7 +202,7 @@ rel_binop(O) ::= TEST_CONTAINS. { O = TEST_OP_CONTAINS; }
|
||||||
/* Relational tests */
|
/* Relational tests */
|
||||||
relation_test(T) ::= entity(E) rel_binop(O) entity(F).
|
relation_test(T) ::= entity(E) rel_binop(O) entity(F).
|
||||||
{
|
{
|
||||||
T = stnode_new(STTYPE_TEST, NULL, NULL);
|
T = stnode_new(STTYPE_TEST, NULL);
|
||||||
sttype_test_set2(T, O, E, F);
|
sttype_test_set2(T, O, E, F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,10 +220,10 @@ relation_test(T) ::= entity(E) rel_binop(O) relation_test(R).
|
||||||
sttype_test_get(F, NULL, &F, NULL);
|
sttype_test_get(F, NULL, &F, NULL);
|
||||||
} while (stnode_type_id(F) == STTYPE_TEST);
|
} while (stnode_type_id(F) == STTYPE_TEST);
|
||||||
|
|
||||||
L = stnode_new(STTYPE_TEST, NULL, NULL);
|
L = stnode_new(STTYPE_TEST, NULL);
|
||||||
sttype_test_set2(L, O, E, stnode_dup(F));
|
sttype_test_set2(L, O, E, stnode_dup(F));
|
||||||
|
|
||||||
T = stnode_new(STTYPE_TEST, NULL, NULL);
|
T = stnode_new(STTYPE_TEST, NULL);
|
||||||
sttype_test_set2(T, TEST_OP_AND, L, R);
|
sttype_test_set2(T, TEST_OP_AND, L, R);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,15 +232,15 @@ relation_test(T) ::= entity(E) TEST_MATCHES entity(F).
|
||||||
{
|
{
|
||||||
stnode_t *R = dfilter_new_regex(dfw, F);
|
stnode_t *R = dfilter_new_regex(dfw, F);
|
||||||
|
|
||||||
T = stnode_new(STTYPE_TEST, NULL, NULL);
|
T = stnode_new(STTYPE_TEST, NULL);
|
||||||
sttype_test_set2(T, TEST_OP_MATCHES, E, R);
|
sttype_test_set2(T, TEST_OP_MATCHES, E, R);
|
||||||
}
|
}
|
||||||
|
|
||||||
relation_test(T) ::= entity(E) TEST_IN LBRACE set_node_list(L) RBRACE.
|
relation_test(T) ::= entity(E) TEST_IN LBRACE set_node_list(L) RBRACE.
|
||||||
{
|
{
|
||||||
stnode_t *S;
|
stnode_t *S;
|
||||||
T = stnode_new(STTYPE_TEST, NULL, NULL);
|
T = stnode_new(STTYPE_TEST, NULL);
|
||||||
S = stnode_new(STTYPE_SET, L, NULL);
|
S = stnode_new(STTYPE_SET, L);
|
||||||
sttype_test_set2(T, TEST_OP_IN, E, S);
|
sttype_test_set2(T, TEST_OP_IN, E, S);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -973,7 +973,7 @@ check_param_entity(dfwork_t *dfw, stnode_t *st_node)
|
||||||
/* If there's an unparsed string, change it to an FT_STRING */
|
/* If there's an unparsed string, change it to an FT_STRING */
|
||||||
if (e_type == STTYPE_UNPARSED || e_type == STTYPE_CHARCONST) {
|
if (e_type == STTYPE_UNPARSED || e_type == STTYPE_CHARCONST) {
|
||||||
fvalue = dfilter_fvalue_from_unparsed(dfw, FT_STRING, st_node, TRUE, NULL);
|
fvalue = dfilter_fvalue_from_unparsed(dfw, FT_STRING, st_node, TRUE, NULL);
|
||||||
new_st = stnode_new(STTYPE_FVALUE, fvalue, st_node->token_value);
|
new_st = stnode_new(STTYPE_FVALUE, fvalue);
|
||||||
stnode_free(st_node);
|
stnode_free(st_node);
|
||||||
return new_st;
|
return new_st;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,8 +72,8 @@ sttype_lookup(sttype_id_t type_id)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
_node_clear(stnode_t *node)
|
stnode_clear(stnode_t *node)
|
||||||
{
|
{
|
||||||
ws_assert_magic(node, STNODE_MAGIC);
|
ws_assert_magic(node, STNODE_MAGIC);
|
||||||
if (node->type) {
|
if (node->type) {
|
||||||
|
@ -95,15 +95,7 @@ _node_clear(stnode_t *node)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
stnode_clear(stnode_t *node)
|
stnode_init(stnode_t *node, sttype_id_t type_id, gpointer data)
|
||||||
{
|
|
||||||
_node_clear(node);
|
|
||||||
g_free(node->token_value);
|
|
||||||
node->token_value = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
_node_init(stnode_t *node, sttype_id_t type_id, gpointer data)
|
|
||||||
{
|
{
|
||||||
sttype_t *type;
|
sttype_t *type;
|
||||||
|
|
||||||
|
@ -133,32 +125,24 @@ _node_init(stnode_t *node, sttype_id_t type_id, gpointer data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
stnode_init(stnode_t *node, sttype_id_t type_id, gpointer data, const char *token_value)
|
|
||||||
{
|
|
||||||
_node_init(node, type_id, data);
|
|
||||||
ws_assert(node->token_value == NULL);
|
|
||||||
node->token_value = g_strdup(token_value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
stnode_replace(stnode_t *node, sttype_id_t type_id, gpointer data)
|
stnode_replace(stnode_t *node, sttype_id_t type_id, gpointer data)
|
||||||
{
|
{
|
||||||
uint16_t flags = node->flags; /* Save flags. */
|
uint16_t flags = node->flags; /* Save flags. */
|
||||||
_node_clear(node);
|
stnode_clear(node);
|
||||||
_node_init(node, type_id, data);
|
stnode_init(node, type_id, data);
|
||||||
node->flags = flags;
|
node->flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
stnode_t*
|
stnode_t*
|
||||||
stnode_new(sttype_id_t type_id, gpointer data, const char *token_value)
|
stnode_new(sttype_id_t type_id, gpointer data)
|
||||||
{
|
{
|
||||||
stnode_t *node;
|
stnode_t *node;
|
||||||
|
|
||||||
node = g_new0(stnode_t, 1);
|
node = g_new0(stnode_t, 1);
|
||||||
node->magic = STNODE_MAGIC;
|
node->magic = STNODE_MAGIC;
|
||||||
|
|
||||||
stnode_init(node, type_id, data, token_value);
|
stnode_init(node, type_id, data);
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
@ -172,7 +156,6 @@ stnode_dup(const stnode_t *node)
|
||||||
new = g_new(stnode_t, 1);
|
new = g_new(stnode_t, 1);
|
||||||
new->magic = STNODE_MAGIC;
|
new->magic = STNODE_MAGIC;
|
||||||
new->flags = node->flags;
|
new->flags = node->flags;
|
||||||
new->token_value = g_strdup(node->token_value);
|
|
||||||
new->repr_display = NULL;
|
new->repr_display = NULL;
|
||||||
new->repr_debug = NULL;
|
new->repr_debug = NULL;
|
||||||
|
|
||||||
|
@ -232,15 +215,6 @@ stnode_steal_data(stnode_t *node)
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
|
||||||
stnode_token_value(stnode_t *node)
|
|
||||||
{
|
|
||||||
if (node->token_value) {
|
|
||||||
return node->token_value;
|
|
||||||
}
|
|
||||||
return "<null token value>";
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
stnode_inside_parens(stnode_t *node)
|
stnode_inside_parens(stnode_t *node)
|
||||||
{
|
{
|
||||||
|
@ -309,7 +283,6 @@ sprint_node(stnode_t *node)
|
||||||
wmem_strbuf_append_printf(buf, "\t\tinside_parens = %s\n",
|
wmem_strbuf_append_printf(buf, "\t\tinside_parens = %s\n",
|
||||||
true_or_false(stnode_inside_parens(node)));
|
true_or_false(stnode_inside_parens(node)));
|
||||||
wmem_strbuf_append(buf, "\t}\n");
|
wmem_strbuf_append(buf, "\t}\n");
|
||||||
wmem_strbuf_append_printf(buf, "\ttoken_value = \"%s\"\n", stnode_token_value(node));
|
|
||||||
wmem_strbuf_append(buf, "}\n");
|
wmem_strbuf_append(buf, "}\n");
|
||||||
return wmem_strbuf_finalize(buf);
|
return wmem_strbuf_finalize(buf);
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,6 @@ typedef struct {
|
||||||
sttype_t *type;
|
sttype_t *type;
|
||||||
uint16_t flags;
|
uint16_t flags;
|
||||||
gpointer data;
|
gpointer data;
|
||||||
char *token_value;
|
|
||||||
char *repr_display;
|
char *repr_display;
|
||||||
char *repr_debug;
|
char *repr_debug;
|
||||||
} stnode_t;
|
} stnode_t;
|
||||||
|
@ -82,7 +81,7 @@ void
|
||||||
sttype_register(sttype_t *type);
|
sttype_register(sttype_t *type);
|
||||||
|
|
||||||
stnode_t*
|
stnode_t*
|
||||||
stnode_new(sttype_id_t type_id, gpointer data, const char *token_value);
|
stnode_new(sttype_id_t type_id, gpointer data);
|
||||||
|
|
||||||
stnode_t*
|
stnode_t*
|
||||||
stnode_dup(const stnode_t *org);
|
stnode_dup(const stnode_t *org);
|
||||||
|
@ -91,7 +90,7 @@ void
|
||||||
stnode_clear(stnode_t *node);
|
stnode_clear(stnode_t *node);
|
||||||
|
|
||||||
void
|
void
|
||||||
stnode_init(stnode_t *node, sttype_id_t type_id, gpointer data, const char *token_value);
|
stnode_init(stnode_t *node, sttype_id_t type_id, gpointer data);
|
||||||
|
|
||||||
void
|
void
|
||||||
stnode_replace(stnode_t *node, sttype_id_t type_id, gpointer data);
|
stnode_replace(stnode_t *node, sttype_id_t type_id, gpointer data);
|
||||||
|
@ -111,9 +110,6 @@ stnode_data(stnode_t *node);
|
||||||
gpointer
|
gpointer
|
||||||
stnode_steal_data(stnode_t *node);
|
stnode_steal_data(stnode_t *node);
|
||||||
|
|
||||||
const char *
|
|
||||||
stnode_token_value(stnode_t *node);
|
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
stnode_tostr(stnode_t *node, gboolean pretty);
|
stnode_tostr(stnode_t *node, gboolean pretty);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue