diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2023-08-28 23:42:40 +0200 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2023-08-28 23:45:05 +0200 |
commit | d72771e59723c9d55deef77d0ff5ef50e170c9e1 (patch) | |
tree | 87279bc235b5041a699ff60842bfedafccd91f4e | |
parent | b72547d31005774b27a1e4adff955689342dd98e (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.Y | 1 | ||||
-rw-r--r-- | filter/data.c | 4 | ||||
-rw-r--r-- | filter/data.h | 3 | ||||
-rw-r--r-- | filter/decl.m4 | 9 |
4 files changed, 15 insertions, 2 deletions
diff --git a/filter/config.Y b/filter/config.Y index 3bf3a2b6..7f2eb838 100644 --- a/filter/config.Y +++ b/filter/config.Y @@ -856,6 +856,7 @@ term: | dynamic_attr '.' RESET{ } */ + | EMPTY { $$ = f_new_inst(FI_CONSTANT, f_const_empty_list); } | '+' EMPTY '+' { $$ = f_new_inst(FI_CONSTANT, f_const_empty_path); } | '-' EMPTY '-' { $$ = f_new_inst(FI_CONSTANT, f_const_empty_clist); } | '-' '-' EMPTY '-' '-' { $$ = f_new_inst(FI_CONSTANT, f_const_empty_eclist); } diff --git a/filter/data.c b/filter/data.c index 1d740b0d..3d07f6e7 100644 --- a/filter/data.c +++ b/filter/data.c @@ -83,7 +83,9 @@ f_type_element_type(enum f_type t) const struct f_trie f_const_empty_trie = { .ipv4 = -1, }; -const struct f_val f_const_empty_path = { +const struct f_val f_const_empty_list = { + .type = T_EMPTY_LIST, +}, f_const_empty_path = { .type = T_PATH, .val.ad = &null_adata, }, f_const_empty_clist = { diff --git a/filter/data.h b/filter/data.h index f44e08e1..865f450d 100644 --- a/filter/data.h +++ b/filter/data.h @@ -19,6 +19,7 @@ enum f_type { /* Nothing. Simply nothing. */ T_VOID = 0, + T_EMPTY_LIST = 1, /* User visible types, which fit in int */ T_INT = 0x10, @@ -316,7 +317,7 @@ undef_value(struct f_val v) (v.val.ad == &null_adata); } -extern const struct f_val f_const_empty_path, f_const_empty_clist, f_const_empty_eclist, f_const_empty_lclist, f_const_empty_prefix_set; +extern const struct f_val f_const_empty_list, f_const_empty_path, f_const_empty_clist, f_const_empty_eclist, f_const_empty_lclist, f_const_empty_prefix_set; enum filter_return f_eval(const struct f_line *expr, struct linpool *tmp_pool, struct f_val *pres); diff --git a/filter/decl.m4 b/filter/decl.m4 index 7c863bdc..3c5b2a6f 100644 --- a/filter/decl.m4 +++ b/filter/decl.m4 @@ -518,6 +518,15 @@ f_const_promotion(struct f_inst *arg, enum f_type want) else if ((c->type == T_SET) && (!c->val.t) && (want == T_PREFIX_SET)) { *c = f_const_empty_prefix_set; return 1; + } else if ((c->type == T_EMPTY_LIST) && (want == T_CLIST)) { + *c = f_const_empty_clist; + return 1; + } else if ((c->type == T_EMPTY_LIST) && (want == T_ECLIST)) { + *c = f_const_empty_eclist; + return 1; + } else if ((c->type == T_EMPTY_LIST) && (want == T_LCLIST)) { + *c = f_const_empty_lclist; + return 1; } return 0; |