dfilter: Move a constructor to the grammar file

This commit is contained in:
João Valverde 2021-11-05 06:41:41 +00:00 committed by Wireshark GitLab Utility
parent 6823073f7e
commit 146a840ad1
3 changed files with 18 additions and 15 deletions

View File

@ -105,9 +105,6 @@ free_deprecated(GPtrArray *deprecated);
void
DfilterTrace(FILE *TraceFILE, char *zTracePrompt);
stnode_t *
dfilter_new_function(dfwork_t *dfw, const char *name);
stnode_t *
dfilter_resolve_unparsed(dfwork_t *dfw, stnode_t *node);

View File

@ -71,16 +71,6 @@ dfilter_parse_fail(dfwork_t *dfw, const char *format, ...)
dfw->syntax_error = TRUE;
}
stnode_t *
dfilter_new_function(dfwork_t *dfw, const char *name)
{
df_func_def_t *def = df_func_lookup(name);
if (!def) {
dfilter_parse_fail(dfw, "Function '%s' does not exist", name);
}
return stnode_new(STTYPE_FUNCTION, def);
}
/*
* Tries to convert an STTYPE_UNPARSED to a STTYPE_FIELD. If it's not registered as
* a field pass UNPARSED to the semantic check.

View File

@ -18,6 +18,9 @@
#pragma warning(disable:4671)
#endif
static stnode_t *
new_function(dfwork_t *dfw, df_lval_t *lval);
/* End of C code */
}
@ -284,10 +287,23 @@ set_element(N) ::= entity(X) DOTDOT entity(Y).
/* Functions */
%code {
static stnode_t *
new_function(dfwork_t *dfw, df_lval_t *lval)
{
const char *name = df_lval_value(lval);
df_func_def_t *def = df_func_lookup(name);
if (!def) {
dfilter_parse_fail(dfw, "Function '%s' does not exist", name);
}
return stnode_new(STTYPE_FUNCTION, def);
}
}
/* A function can have one or more parameters */
function(F) ::= UNPARSED(U) LPAREN function_params(P) RPAREN.
{
F = dfilter_new_function(dfw, df_lval_value(U));
F = new_function(dfw, U);
sttype_function_set_params(F, P);
df_lval_free(U);
}
@ -295,7 +311,7 @@ function(F) ::= UNPARSED(U) LPAREN function_params(P) RPAREN.
/* A function can have zero parameters. */
function(F) ::= UNPARSED(U) LPAREN RPAREN.
{
F = dfilter_new_function(dfw, df_lval_value(U));
F = new_function(dfw, U);
df_lval_free(U);
}