diff options
author | Guy Harris <guy@alum.mit.edu> | 2004-02-11 21:20:52 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2004-02-11 21:20:52 +0000 |
commit | b9b4a23834e80e36c180857bf3cb7065407bd9e0 (patch) | |
tree | cade820d9fbe87bc2e2078779e17f8518573ad57 | |
parent | 87e20f806752c0d1e60d54bb7e51f5b4677693b4 (diff) |
Make an existence test of an arbitrary entity syntactically valid, but
check, in the semantics-checking phase, that we're testing a field, so
that we can give a better message than, for example, "Unexpected end of
filter string." for an existence test with a misspelled field name.
svn path=/trunk/; revision=10043
-rw-r--r-- | epan/dfilter/grammar.lemon | 6 | ||||
-rw-r--r-- | epan/dfilter/semcheck.c | 44 |
2 files changed, 45 insertions, 5 deletions
diff --git a/epan/dfilter/grammar.lemon b/epan/dfilter/grammar.lemon index 8a7e280796..8b11bc393a 100644 --- a/epan/dfilter/grammar.lemon +++ b/epan/dfilter/grammar.lemon @@ -1,4 +1,4 @@ -/* $Id: grammar.lemon,v 1.7 2003/12/06 16:35:19 gram Exp $ */ +/* $Id: grammar.lemon,v 1.8 2004/02/11 21:20:52 guy Exp $ */ %include { #ifdef HAVE_CONFIG_H @@ -143,10 +143,10 @@ logical_test(T) ::= TEST_NOT expr(E). sttype_test_set1(T, TEST_OP_NOT, E); } -logical_test(T) ::= FIELD(F). +logical_test(T) ::= entity(E). { T = stnode_new(STTYPE_TEST, NULL); - sttype_test_set1(T, TEST_OP_EXISTS, F); + sttype_test_set1(T, TEST_OP_EXISTS, E); } diff --git a/epan/dfilter/semcheck.c b/epan/dfilter/semcheck.c index 31045da3fd..db728d7ca2 100644 --- a/epan/dfilter/semcheck.c +++ b/epan/dfilter/semcheck.c @@ -1,5 +1,5 @@ /* - * $Id: semcheck.c,v 1.22 2004/01/01 16:59:20 obiot Exp $ + * $Id: semcheck.c,v 1.23 2004/02/11 21:20:52 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -269,6 +269,46 @@ is_bytes_type(enum ftenum type) return FALSE; } +/* Check the semantics of an existence test. */ +static void +check_exists(stnode_t *st_arg1) +{ +#ifdef DEBUG_dfilter + static guint i = 0; +#endif + + DebugLog((" 4 check_exists() [%u]\n", i++)); + switch (stnode_type_id(st_arg1)) { + case STTYPE_FIELD: + /* This is OK */ + break; + case STTYPE_STRING: + case STTYPE_UNPARSED: + dfilter_fail("\"%s\" is neither a field nor a protocol name.", + stnode_data(st_arg1)); + THROW(TypeError); + break; + + case STTYPE_RANGE: + /* + * XXX - why not? Shouldn't "eth[3:2]" mean + * "check whether the 'eth' field is present and + * has at least 2 bytes starting at an offset of + * 3"? + */ + dfilter_fail("You cannot test whether a range is present."); + THROW(TypeError); + break; + + case STTYPE_UNINITIALIZED: + case STTYPE_TEST: + case STTYPE_INTEGER: + case STTYPE_FVALUE: + case STTYPE_NUM_TYPES: + g_assert_not_reached(); + } +} + /* If the LHS of a relation test is a FIELD, run some checks * and possibly some modifications of syntax tree nodes. */ static void @@ -717,7 +757,7 @@ check_test(stnode_t *st_node) break; case TEST_OP_EXISTS: - /* nothing */ + check_exists(st_arg1); break; case TEST_OP_NOT: |