From: Phil Sutter Date: Tue, 29 Jul 2025 15:52:35 +0000 (+0200) Subject: expression: Introduce is_symbol_value_expr() macro X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=26ed87de43142dac3c85390ae27e50a156581e94;p=thirdparty%2Fnftables.git expression: Introduce is_symbol_value_expr() macro Annotate and combine the 'etype' and 'symtype' checks done in bison parser for readability and because JSON parser will start doing the same in a follow-up patch. Signed-off-by: Phil Sutter Reviewed-by: Pablo Neira Ayuso --- diff --git a/include/expression.h b/include/expression.h index 5b60c1b0..e483b7e7 100644 --- a/include/expression.h +++ b/include/expression.h @@ -470,6 +470,8 @@ extern struct expr *verdict_expr_alloc(const struct location *loc, extern struct expr *symbol_expr_alloc(const struct location *loc, enum symbol_types type, struct scope *scope, const char *identifier); +#define is_symbol_value_expr(expr) \ + ((expr)->etype == EXPR_SYMBOL && (expr)->symtype == SYMBOL_VALUE) const char *expr_name(const struct expr *e); diff --git a/src/parser_bison.y b/src/parser_bison.y index aacfa291..0b1ea699 100644 --- a/src/parser_bison.y +++ b/src/parser_bison.y @@ -4496,10 +4496,8 @@ prefix_rhs_expr : basic_rhs_expr SLASH NUM range_rhs_expr : basic_rhs_expr DASH basic_rhs_expr { - if ($1->etype == EXPR_SYMBOL && - $1->symtype == SYMBOL_VALUE && - $3->etype == EXPR_SYMBOL && - $3->symtype == SYMBOL_VALUE) { + if (is_symbol_value_expr($1) && + is_symbol_value_expr($3)) { $$ = symbol_range_expr_alloc(&@$, $1->symtype, $1->scope, $1->identifier, $3->identifier); expr_free($1); expr_free($3);