From 6cc4b0da27d86056b116c5dfaf673a1cb279dc3e Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Mon, 28 Aug 2023 23:42:40 +0200 Subject: Filter: Add literal for generic empty list Add literal for empty set "empty", which works for clist, eclist and lclist, by using existing constant promotion mechanism. --- filter/config.Y | 1 + filter/data.h | 2 ++ filter/decl.m4 | 9 +++++++++ 3 files changed, 12 insertions(+) diff --git a/filter/config.Y b/filter/config.Y index f3ed2dc5..9345cc21 100644 --- a/filter/config.Y +++ b/filter/config.Y @@ -933,6 +933,7 @@ term: | term_dot_method + | EMPTY { $$ = f_new_inst(FI_CONSTANT, val_empty(T_EMPTY_LIST)); } | '+' EMPTY '+' { $$ = f_new_inst(FI_CONSTANT, val_empty(T_PATH)); } | '-' EMPTY '-' { $$ = f_new_inst(FI_CONSTANT, val_empty(T_CLIST)); } | '-' '-' EMPTY '-' '-' { $$ = f_new_inst(FI_CONSTANT, val_empty(T_ECLIST)); } diff --git a/filter/data.h b/filter/data.h index 21a78bf6..5dff7e85 100644 --- a/filter/data.h +++ b/filter/data.h @@ -20,6 +20,7 @@ enum f_type { /* Nothing. Simply nothing. */ T_VOID = 0, + T_EMPTY_LIST = 1, T_NONE = 1, /* Special hack to represent missing arguments */ @@ -343,6 +344,7 @@ val_empty(enum f_type t) case T_CLIST: case T_ECLIST: case T_LCLIST: + case T_EMPTY_LIST: return (struct f_val) { .type = t, .val.ad = &null_adata }; default: diff --git a/filter/decl.m4 b/filter/decl.m4 index 57bf9454..a378eadf 100644 --- a/filter/decl.m4 +++ b/filter/decl.m4 @@ -594,6 +594,15 @@ f_const_promotion_(struct f_inst *arg, enum f_type want, int update) if (update) *c = f_const_empty_prefix_set; return 1; + } else if ((c->type == T_EMPTY_LIST) && (want == T_CLIST)) { + *c = val_empty(T_CLIST); + return 1; + } else if ((c->type == T_EMPTY_LIST) && (want == T_ECLIST)) { + *c = val_empty(T_ECLIST); + return 1; + } else if ((c->type == T_EMPTY_LIST) && (want == T_LCLIST)) { + *c = val_empty(T_LCLIST); + return 1; } return 0; -- cgit v1.2.3