diff options
author | Maria Matejka <mq@ucw.cz> | 2023-06-16 17:35:37 +0200 |
---|---|---|
committer | Ondrej Zajicek <santiago@crfreenet.org> | 2023-09-12 16:19:33 +0200 |
commit | fc9d471b36b91429e5d86aa794716683a5281449 (patch) | |
tree | ffe1298e55f99f0d6198aa6836213006e6a0dd89 /conf/conf.h | |
parent | 39f8f46d81203ebd6b976da56e83930f972dccab (diff) |
Filter: Methods rework
Methods can now be called as x.m(y), as long as x can have its type
inferred in config time. If used as a command, it modifies the object,
if used as a value, it keeps the original object intact.
Also functions add(x,y), delete(x,y), filter(x,y) and prepend(x,y) now
spit a warning and are considered deprecated.
It's also possible to call a method on a constant, see filter/test.conf
for examples like bgp_path = +empty+.prepend(1).
Inside instruction definitions (filter/f-inst.c), a METHOD_CONSTRUCTOR()
call is added, which registers the instruction as a method for the type
of its first argument. Each type has its own method symbol table and
filter parser switches between them based on the inferred type of the
object calling the method.
Also FI_CLIST_(ADD|DELETE|FILTER) instructions have been split to allow
for this method dispatch. With type inference, it's now possible.
Diffstat (limited to 'conf/conf.h')
-rw-r--r-- | conf/conf.h | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/conf/conf.h b/conf/conf.h index b7c97ce5..1413cb58 100644 --- a/conf/conf.h +++ b/conf/conf.h @@ -126,6 +126,7 @@ struct symbol { struct f_val *val; /* For SYM_CONSTANT */ uint offset; /* For SYM_VARIABLE */ const struct keyword *keyword; /* For SYM_KEYWORD */ + const struct f_method *method; /* For SYM_METHOD */ }; char name[0]; @@ -144,13 +145,9 @@ struct sym_scope { byte readonly:1; /* Do not add new symbols */ }; -enum keyword_scope { - CFK_KEYWORDS, - CFK_METHODS, - CFK__MAX -}; - extern struct sym_scope *global_root_scope; +extern pool *global_root_scope_pool; +extern linpool *global_root_scope_linpool; struct bytestring { size_t length; @@ -168,6 +165,7 @@ struct bytestring { #define SYM_TABLE 5 #define SYM_ATTRIBUTE 6 #define SYM_KEYWORD 7 +#define SYM_METHOD 8 #define SYM_VARIABLE 0x100 /* 0x100-0x1ff are variable types */ #define SYM_VARIABLE_RANGE SYM_VARIABLE ... (SYM_VARIABLE | 0xff) @@ -215,6 +213,9 @@ struct symbol *cf_localize_symbol(struct config *conf, struct symbol *sym); static inline int cf_symbol_is_local(struct config *conf, struct symbol *sym) { return (sym->scope == conf->current_scope) && !conf->current_scope->soft_scopes; } +/* internal */ +struct symbol *cf_new_symbol(struct sym_scope *scope, pool *p, struct linpool *lp, const byte *c); + /** * cf_define_symbol - define meaning of a symbol * @sym: symbol to be defined |