dfilter: Improve representation of raw field references
Instead of using the abstract type "<RAW>", which might be confusing, show FT_BYTES, but display the representation with the "@" operator, so it's not even more confusing in error messages why a field might flip-flop types. Refactor the field tostr() function and some other clean ups. Before: ``` Filter: _ws.ftypes.string ==${@frame.len} dftest: _ws.ftypes.string and frame.len <RAW> are not of compatible types. _ws.ftypes.string ==${@frame.len} ^~~~~~~~~ ``` After: ``` Filter: _ws.ftypes.string ==${@frame.len} dftest: _ws.ftypes.string <FT_STRING> and @frame.len <FT_BYTES> are not of compatible types. _ws.ftypes.string ==${@frame.len} ^~~~~~~~~ ```
This commit is contained in:
parent
b83658d8a4
commit
4c2d0f16d4
|
@ -612,7 +612,7 @@ check_relation_LHS_FIELD(dfwork_t *dfw, stnode_op_t st_op,
|
|||
|
||||
if (!compatible_ftypes(ftype1, ftype2)) {
|
||||
FAIL(dfw, st_arg2, "%s and %s are not of compatible types.",
|
||||
hfinfo1->abbrev, stnode_todisplay(st_arg2));
|
||||
stnode_todisplay(st_arg1), stnode_todisplay(st_arg2));
|
||||
}
|
||||
/* Do this check even though you'd think that if
|
||||
* they're compatible, then can_func() would pass. */
|
||||
|
|
|
@ -73,21 +73,33 @@ field_tostr(const void *data, gboolean pretty _U_)
|
|||
{
|
||||
const field_t *field = data;
|
||||
ws_assert_magic(field, FIELD_MAGIC);
|
||||
char *repr, *drange_str;
|
||||
wmem_strbuf_t *repr;
|
||||
char *drange_str = NULL;
|
||||
|
||||
if (field->drange && (drange_str = drange_tostr(field->drange))) {
|
||||
repr = ws_strdup_printf("%s#[%s] <%s>",
|
||||
field->hfinfo->abbrev,
|
||||
drange_str,
|
||||
field->raw ? "RAW" : ftype_name(field->hfinfo->type));
|
||||
|
||||
repr = wmem_strbuf_new(NULL, NULL);
|
||||
|
||||
if (field->raw) {
|
||||
wmem_strbuf_append_c(repr, '@');
|
||||
}
|
||||
|
||||
wmem_strbuf_append(repr, field->hfinfo->abbrev);
|
||||
|
||||
if (field->drange) {
|
||||
drange_str = drange_tostr(field->drange);
|
||||
wmem_strbuf_append_printf(repr, "#[%s]", drange_str);
|
||||
g_free(drange_str);
|
||||
}
|
||||
|
||||
if (field->raw) {
|
||||
wmem_strbuf_append(repr, " <FT_BYTES>");
|
||||
}
|
||||
else {
|
||||
repr = ws_strdup_printf("%s <%s>", field->hfinfo->abbrev,
|
||||
field->raw ? "RAW" : ftype_name(field->hfinfo->type));
|
||||
wmem_strbuf_append_printf(repr, " <%s>",
|
||||
ftype_name(field->hfinfo->type));
|
||||
}
|
||||
|
||||
return repr;
|
||||
return wmem_strbuf_finalize(repr);
|
||||
}
|
||||
|
||||
header_field_info *
|
||||
|
|
|
@ -249,6 +249,10 @@ stnode_location(stnode_t *node)
|
|||
return &node->location;
|
||||
}
|
||||
|
||||
#define IS_OPERATOR(node) \
|
||||
(stnode_type_id(node) == STTYPE_TEST || \
|
||||
stnode_type_id(node) == STTYPE_ARITHMETIC)
|
||||
|
||||
static char *
|
||||
_node_tostr(stnode_t *node, gboolean pretty)
|
||||
{
|
||||
|
@ -262,8 +266,7 @@ _node_tostr(stnode_t *node, gboolean pretty)
|
|||
if (pretty)
|
||||
return s;
|
||||
|
||||
if (stnode_type_id(node) == STTYPE_TEST ||
|
||||
stnode_type_id(node) == STTYPE_ARITHMETIC) {
|
||||
if (IS_OPERATOR(node)) {
|
||||
repr = s;
|
||||
}
|
||||
else {
|
||||
|
@ -279,7 +282,9 @@ stnode_tostr(stnode_t *node, gboolean pretty)
|
|||
{
|
||||
ws_assert_magic(node, STNODE_MAGIC);
|
||||
|
||||
if (pretty && node->repr_token != NULL) {
|
||||
if (pretty && IS_OPERATOR(node) && node->repr_token != NULL) {
|
||||
/* Some operators can have synonyms, like "or" and "||".
|
||||
* Show the user the same representation as he typed. */
|
||||
g_free(node->repr_display);
|
||||
node->repr_display = g_strdup(node->repr_token);
|
||||
return node->repr_display;
|
||||
|
|
Loading…
Reference in New Issue