forked from osmocom/wireshark
dfilter: Improve error location for expressions
Try to underline the whole expression instead of the token.
This commit is contained in:
parent
3938b406fb
commit
44511c318d
|
@ -1265,8 +1265,8 @@ check_arithmetic_expr(dfwork_t *dfw, stnode_t *st_node, ftenum_t lhs_ftype)
|
|||
}
|
||||
|
||||
if (!compatible_ftypes(ftype1, ftype2)) {
|
||||
FAIL(dfw, st_arg2, "%s and %s are not type compatible.",
|
||||
stnode_todisplay(st_arg1), stnode_todisplay(st_arg2));
|
||||
FAIL(dfw, st_node, "%s and %s are not compatible.",
|
||||
ftype_name(ftype1), ftype_name(ftype2));
|
||||
}
|
||||
|
||||
return ftype1;
|
||||
|
|
|
@ -278,6 +278,7 @@ sttype_oper_set1(stnode_t *node, stnode_op_t op, stnode_t *val1)
|
|||
oper->op = op;
|
||||
oper->val1 = val1;
|
||||
oper->val2 = NULL;
|
||||
node->location = stnode_merge_location(node, val1, (stnode_t *)NULL);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -290,6 +291,7 @@ sttype_oper_set2(stnode_t *node, stnode_op_t op, stnode_t *val1, stnode_t *val2)
|
|||
oper->op = op;
|
||||
oper->val1 = val1;
|
||||
oper->val2 = val2;
|
||||
node->location = stnode_merge_location(node, val1, val2, (stnode_t *)NULL);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -303,6 +305,7 @@ sttype_oper_set1_args(stnode_t *node, stnode_t *val1)
|
|||
ws_assert(num_operands(oper->op) == 1);
|
||||
oper->val1 = val1;
|
||||
oper->val2 = NULL;
|
||||
node->location = stnode_merge_location(node, val1, (stnode_t *)NULL);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -316,6 +319,7 @@ sttype_oper_set2_args(stnode_t *node, stnode_t *val1, stnode_t *val2)
|
|||
ws_assert(num_operands(oper->op) == 2);
|
||||
oper->val1 = val1;
|
||||
oper->val2 = val2;
|
||||
node->location = stnode_merge_location(node, val1, val2, (stnode_t *)NULL);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -250,6 +250,37 @@ stnode_location(stnode_t *node)
|
|||
return node->location;
|
||||
}
|
||||
|
||||
/* Finds the first and last location from a set and creates
|
||||
* a new location from start of first (col_start) to end of
|
||||
* last (col_start + col_len). */
|
||||
df_loc_t
|
||||
stnode_merge_location(stnode_t *st, ...)
|
||||
{
|
||||
df_loc_t first, last, loc;
|
||||
df_loc_t result;
|
||||
va_list ap;
|
||||
|
||||
first = last = stnode_location(st);
|
||||
|
||||
va_start(ap, st);
|
||||
while ((st = va_arg(ap, stnode_t *)) != NULL) {
|
||||
loc = stnode_location(st);
|
||||
if (loc.col_start >= 0) {
|
||||
if (loc.col_start < first.col_start) {
|
||||
first = loc;
|
||||
}
|
||||
else if (loc.col_start > last.col_start) {
|
||||
last = loc;
|
||||
}
|
||||
}
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
result.col_start = first.col_start;
|
||||
result.col_len = last.col_start - first.col_start + last.col_len;
|
||||
return result;
|
||||
}
|
||||
|
||||
#define IS_OPERATOR(node) \
|
||||
(stnode_type_id(node) == STTYPE_TEST || \
|
||||
stnode_type_id(node) == STTYPE_ARITHMETIC)
|
||||
|
|
|
@ -156,6 +156,9 @@ stnode_token(stnode_t *node);
|
|||
df_loc_t
|
||||
stnode_location(stnode_t *node);
|
||||
|
||||
df_loc_t
|
||||
stnode_merge_location(stnode_t *n1, ...);
|
||||
|
||||
const char *
|
||||
stnode_tostr(stnode_t *node, gboolean pretty);
|
||||
|
||||
|
|
Loading…
Reference in New Issue