summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2023-08-28 23:42:40 +0200
committerMikael Magnusson <mikma@users.sourceforge.net>2024-07-05 17:07:16 +0200
commitb28135a1bf345f4a794bde9ccae1fe2ff10565b2 (patch)
treea0912551f29d2fdda8918e61e44aac97f18018b0
parent81d627edddaae2b18a203617c1f71b06b0dfcae4 (diff)
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.
-rw-r--r--filter/config.Y1
-rw-r--r--filter/data.h2
-rw-r--r--filter/decl.m49
3 files changed, 12 insertions, 0 deletions
diff --git a/filter/config.Y b/filter/config.Y
index 5c3a1c16..e2fbb296 100644
--- a/filter/config.Y
+++ b/filter/config.Y
@@ -934,6 +934,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 bd1fa9a0..028640bb 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 */
@@ -345,6 +346,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 ea0b0995..fec1d8df 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;