[RFC PATCH 18/20] allow typed definitions
Asbjørn Sloth Tønnesen
ast at 2e8.dk
Mon Dec 30 17:56:44 CET 2019
---
conf/confbase.Y | 5 +++++
filter/config.Y | 18 +++++++++++++++---
2 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/conf/confbase.Y b/conf/confbase.Y
index eda5b9c1..ca8ec19a 100644
--- a/conf/confbase.Y
+++ b/conf/confbase.Y
@@ -150,6 +150,11 @@ definition:
if (f_eval(f_linearize($4), cfg_mem, val) > F_RETURN) cf_error("Runtime error");
cf_define_symbol($2, SYM_CONSTANT | val->type, val, val);
}
+ | DEFINE symbol ':' net_type '=' term ';' {
+ struct f_val *val = cfg_alloc(sizeof(struct f_val));
+ if (f_eval(f_linearize($6), cfg_mem, val) > F_RETURN) cf_error("Runtime error");
+ cf_define_typed_symbol($2, SYM_CONSTANT | val->type, val, val, $4);
+ }
;
expr:
diff --git a/filter/config.Y b/filter/config.Y
index a7d1dd9b..653d2265 100644
--- a/filter/config.Y
+++ b/filter/config.Y
@@ -462,12 +462,19 @@ CF_KEYWORDS(FUNCTION, PRINT, PRINTN, UNSET, RETURN,
%type <v> set_atom switch_atom fipa
%type <px> fprefix
%type <t> get_cf_position
+%type <s> filter_symbol function_symbol
CF_GRAMMAR
+filter_symbol:
+ symbol { $$ = cf_define_symbol($1, SYM_FILTER, filter, NULL); }
+ | symbol ':' net_type {
+ $$ = cf_define_typed_symbol($1, SYM_FILTER, filter, NULL, $3);
+ };
+
conf: filter_def ;
filter_def:
- FILTER symbol { $2 = cf_define_symbol($2, SYM_FILTER, filter, NULL); cf_push_scope( $2 ); }
+ FILTER filter_symbol { cf_push_scope( $2 ); }
filter_body {
struct filter *f = cfg_alloc(sizeof(struct filter));
*f = (struct filter) { .sym = $2, .root = $4 };
@@ -605,10 +612,15 @@ function_body:
}
;
+function_symbol:
+ symbol { $$ = cf_define_symbol($1, SYM_FUNCTION, function, NULL); }
+ | symbol ':' net_type {
+ $$ = cf_define_typed_symbol($1, SYM_FUNCTION, function, NULL, $3);
+ };
+
conf: function_def ;
function_def:
- FUNCTION symbol { DBG( "Beginning of function %s\n", $2->name );
- $2 = cf_define_symbol($2, SYM_FUNCTION, function, NULL);
+ FUNCTION function_symbol { DBG( "Beginning of function %s\n", $2->name );
cf_push_scope($2);
} function_args function_body {
DBG("Definition of function %s with %u args and %u local vars.\n", $2->name, $4, $5->vars);
--
2.24.0
More information about the Bird-users
mailing list