Filter: Some people can't pronounce "postfixify" correctly. Let's try "linearize" instead.
This is just a naming change.
This commit is contained in:
parent
96d757c13f
commit
23e3b1e665
8 changed files with 36 additions and 36 deletions
|
@ -147,14 +147,14 @@ conf: definition ;
|
||||||
definition:
|
definition:
|
||||||
DEFINE CF_SYM_VOID '=' term ';' {
|
DEFINE CF_SYM_VOID '=' term ';' {
|
||||||
struct f_val *val = cfg_alloc(sizeof(struct f_val));
|
struct f_val *val = cfg_alloc(sizeof(struct f_val));
|
||||||
if (f_eval(f_postfixify($4), cfg_mem, val) > F_RETURN) cf_error("Runtime error");
|
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);
|
cf_define_symbol($2, SYM_CONSTANT | val->type, val, val);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
expr:
|
expr:
|
||||||
NUM
|
NUM
|
||||||
| '(' term ')' { $$ = f_eval_int(f_postfixify($2)); }
|
| '(' term ')' { $$ = f_eval_int(f_linearize($2)); }
|
||||||
| CF_SYM_KNOWN {
|
| CF_SYM_KNOWN {
|
||||||
if ($1->class != (SYM_CONSTANT | T_INT)) cf_error("Number constant expected");
|
if ($1->class != (SYM_CONSTANT | T_INT)) cf_error("Number constant expected");
|
||||||
$$ = SYM_VAL($1).i; }
|
$$ = SYM_VAL($1).i; }
|
||||||
|
|
|
@ -481,7 +481,7 @@ filter_def:
|
||||||
|
|
||||||
conf: filter_eval ;
|
conf: filter_eval ;
|
||||||
filter_eval:
|
filter_eval:
|
||||||
EVAL term { f_eval_int(f_postfixify($2)); }
|
EVAL term { f_eval_int(f_linearize($2)); }
|
||||||
;
|
;
|
||||||
|
|
||||||
conf: custom_attr ;
|
conf: custom_attr ;
|
||||||
|
@ -600,7 +600,7 @@ function_params:
|
||||||
|
|
||||||
function_body:
|
function_body:
|
||||||
decls '{' cmds '}' {
|
decls '{' cmds '}' {
|
||||||
$$ = f_postfixify($3);
|
$$ = f_linearize($3);
|
||||||
$$->vars = decls_count;
|
$$->vars = decls_count;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
@ -661,7 +661,7 @@ set_atom:
|
||||||
| VPN_RD { $$.type = T_RD; $$.val.ec = $1; }
|
| VPN_RD { $$.type = T_RD; $$.val.ec = $1; }
|
||||||
| ENUM { $$.type = pair_a($1); $$.val.i = pair_b($1); }
|
| ENUM { $$.type = pair_a($1); $$.val.i = pair_b($1); }
|
||||||
| '(' term ')' {
|
| '(' term ')' {
|
||||||
if (f_eval(f_postfixify($2), cfg_mem, &($$)) > F_RETURN) cf_error("Runtime error");
|
if (f_eval(f_linearize($2), cfg_mem, &($$)) > F_RETURN) cf_error("Runtime error");
|
||||||
if (!f_valid_set_type($$.type)) cf_error("Set-incompatible type");
|
if (!f_valid_set_type($$.type)) cf_error("Set-incompatible type");
|
||||||
}
|
}
|
||||||
| CF_SYM_KNOWN {
|
| CF_SYM_KNOWN {
|
||||||
|
@ -673,13 +673,13 @@ set_atom:
|
||||||
|
|
||||||
switch_atom:
|
switch_atom:
|
||||||
NUM { $$.type = T_INT; $$.val.i = $1; }
|
NUM { $$.type = T_INT; $$.val.i = $1; }
|
||||||
| '(' term ')' { $$.type = T_INT; $$.val.i = f_eval_int(f_postfixify($2)); }
|
| '(' term ')' { $$.type = T_INT; $$.val.i = f_eval_int(f_linearize($2)); }
|
||||||
| fipa { $$ = $1; }
|
| fipa { $$ = $1; }
|
||||||
| ENUM { $$.type = pair_a($1); $$.val.i = pair_b($1); }
|
| ENUM { $$.type = pair_a($1); $$.val.i = pair_b($1); }
|
||||||
;
|
;
|
||||||
|
|
||||||
cnum:
|
cnum:
|
||||||
term { $$ = f_eval_int(f_postfixify($1)); }
|
term { $$ = f_eval_int(f_linearize($1)); }
|
||||||
|
|
||||||
pair_item:
|
pair_item:
|
||||||
'(' cnum ',' cnum ')' { $$ = f_new_pair_item($2, $2, $4, $4); }
|
'(' cnum ',' cnum ')' { $$ = f_new_pair_item($2, $2, $4, $4); }
|
||||||
|
@ -766,7 +766,7 @@ switch_body: /* EMPTY */ { $$ = NULL; }
|
||||||
| switch_body switch_items ':' cmds {
|
| switch_body switch_items ':' cmds {
|
||||||
/* Fill data fields */
|
/* Fill data fields */
|
||||||
struct f_tree *t;
|
struct f_tree *t;
|
||||||
struct f_line *line = f_postfixify($4);
|
struct f_line *line = f_linearize($4);
|
||||||
for (t = $2; t; t = t->left)
|
for (t = $2; t; t = t->left)
|
||||||
t->data = line;
|
t->data = line;
|
||||||
$$ = f_merge_items($1, $2);
|
$$ = f_merge_items($1, $2);
|
||||||
|
@ -775,7 +775,7 @@ switch_body: /* EMPTY */ { $$ = NULL; }
|
||||||
struct f_tree *t = f_new_tree();
|
struct f_tree *t = f_new_tree();
|
||||||
t->from.type = t->to.type = T_VOID;
|
t->from.type = t->to.type = T_VOID;
|
||||||
t->right = t;
|
t->right = t;
|
||||||
t->data = f_postfixify($3);
|
t->data = f_linearize($3);
|
||||||
$$ = f_merge_items($1, t);
|
$$ = f_merge_items($1, t);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
|
@ -12,7 +12,7 @@ m4_divert(-1)m4_dnl
|
||||||
# 5 enum fi_code to string
|
# 5 enum fi_code to string
|
||||||
# 6 dump line item
|
# 6 dump line item
|
||||||
# 7 dump line item callers
|
# 7 dump line item callers
|
||||||
# 8 postfixify
|
# 8 linearize
|
||||||
# 9 same (filter comparator)
|
# 9 same (filter comparator)
|
||||||
# 1 union in struct f_inst
|
# 1 union in struct f_inst
|
||||||
# 3 constructors
|
# 3 constructors
|
||||||
|
@ -23,7 +23,7 @@ m4_divert(-1)m4_dnl
|
||||||
# 102 constructor arguments
|
# 102 constructor arguments
|
||||||
# 103 constructor body
|
# 103 constructor body
|
||||||
# 104 dump line item content
|
# 104 dump line item content
|
||||||
# 105 postfixify body
|
# 105 linearize body
|
||||||
# 106 comparator body
|
# 106 comparator body
|
||||||
# 107 struct f_line_item content
|
# 107 struct f_line_item content
|
||||||
# 108 interpreter body
|
# 108 interpreter body
|
||||||
|
@ -45,7 +45,7 @@ m4_define(FID_ENUM, `FID_ZONE(4, Code enum)')
|
||||||
m4_define(FID_ENUM_STR, `FID_ZONE(5, Code enum to string)')
|
m4_define(FID_ENUM_STR, `FID_ZONE(5, Code enum to string)')
|
||||||
m4_define(FID_DUMP, `FID_ZONE(6, Dump line)')
|
m4_define(FID_DUMP, `FID_ZONE(6, Dump line)')
|
||||||
m4_define(FID_DUMP_CALLER, `FID_ZONE(7, Dump line caller)')
|
m4_define(FID_DUMP_CALLER, `FID_ZONE(7, Dump line caller)')
|
||||||
m4_define(FID_POSTFIXIFY, `FID_ZONE(8, Postfixify)')
|
m4_define(FID_LINEARIZE, `FID_ZONE(8, Linearize)')
|
||||||
m4_define(FID_SAME, `FID_ZONE(9, Comparison)')
|
m4_define(FID_SAME, `FID_ZONE(9, Comparison)')
|
||||||
m4_define(FID_INTERPRET, `FID_ZONE(10, Interpret)')
|
m4_define(FID_INTERPRET, `FID_ZONE(10, Interpret)')
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ m4_define(FID_STRUCT_IN, `m4_divert(101)')
|
||||||
m4_define(FID_NEW_ARGS, `m4_divert(102)')
|
m4_define(FID_NEW_ARGS, `m4_divert(102)')
|
||||||
m4_define(FID_NEW_BODY, `m4_divert(103)')
|
m4_define(FID_NEW_BODY, `m4_divert(103)')
|
||||||
m4_define(FID_DUMP_BODY, `m4_divert(104)m4_define([[FID_DUMP_BODY_EXISTS]])')
|
m4_define(FID_DUMP_BODY, `m4_divert(104)m4_define([[FID_DUMP_BODY_EXISTS]])')
|
||||||
m4_define(FID_POSTFIXIFY_BODY, `m4_divert(105)m4_define([[FID_POSTFIXIFY_BODY_EXISTS]])')
|
m4_define(FID_LINEARIZE_BODY, `m4_divert(105)m4_define([[FID_LINEARIZE_BODY_EXISTS]])')
|
||||||
m4_define(FID_SAME_BODY, `m4_divert(106)')
|
m4_define(FID_SAME_BODY, `m4_divert(106)')
|
||||||
m4_define(FID_LINE_IN, `m4_divert(107)')
|
m4_define(FID_LINE_IN, `m4_divert(107)')
|
||||||
m4_define(FID_INTERPRET_BODY, `m4_divert(108)')
|
m4_define(FID_INTERPRET_BODY, `m4_divert(108)')
|
||||||
|
@ -112,7 +112,7 @@ m4_undivert(104)
|
||||||
}
|
}
|
||||||
FID_ALL_TARGETS
|
FID_ALL_TARGETS
|
||||||
|
|
||||||
FID_POSTFIXIFY
|
FID_LINEARIZE
|
||||||
case INST_NAME(): {
|
case INST_NAME(): {
|
||||||
#define what (&(what_->i_]]INST_NAME()[[))
|
#define what (&(what_->i_]]INST_NAME()[[))
|
||||||
#define item (&(dest->items[pos].i_]]INST_NAME()[[))
|
#define item (&(dest->items[pos].i_]]INST_NAME()[[))
|
||||||
|
@ -123,7 +123,7 @@ case INST_NAME(): {
|
||||||
dest->items[pos].lineno = what_->lineno;
|
dest->items[pos].lineno = what_->lineno;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
m4_undefine([[FID_POSTFIXIFY_BODY_EXISTS]])
|
m4_undefine([[FID_LINEARIZE_BODY_EXISTS]])
|
||||||
|
|
||||||
FID_SAME
|
FID_SAME
|
||||||
case INST_NAME():
|
case INST_NAME():
|
||||||
|
@ -170,7 +170,7 @@ FID_NEW_ARGS
|
||||||
FID_NEW_BODY
|
FID_NEW_BODY
|
||||||
what->$2 = $2;
|
what->$2 = $2;
|
||||||
m4_ifelse($3,,,[[
|
m4_ifelse($3,,,[[
|
||||||
FID_POSTFIXIFY_BODY
|
FID_LINEARIZE_BODY
|
||||||
item->$3 = what->$2;
|
item->$3 = what->$2;
|
||||||
]])
|
]])
|
||||||
m4_ifelse($4,,,[[
|
m4_ifelse($4,,,[[
|
||||||
|
@ -195,8 +195,8 @@ FID_NEW_ARGS
|
||||||
FID_NEW_BODY
|
FID_NEW_BODY
|
||||||
what->f$1 = f$1;
|
what->f$1 = f$1;
|
||||||
for (const struct f_inst *child = f$1; child; child = child->next) what_->size += child->size;
|
for (const struct f_inst *child = f$1; child; child = child->next) what_->size += child->size;
|
||||||
FID_POSTFIXIFY_BODY
|
FID_LINEARIZE_BODY
|
||||||
pos = postfixify(dest, what->f$1, pos);m4_dnl
|
pos = linearize(dest, what->f$1, pos);m4_dnl
|
||||||
FID_ALL()')
|
FID_ALL()')
|
||||||
|
|
||||||
m4_define(ARG, `ARG_ANY($1)
|
m4_define(ARG, `ARG_ANY($1)
|
||||||
|
@ -226,8 +226,8 @@ FID_NEW_BODY
|
||||||
what->f$1 = f$1;
|
what->f$1 = f$1;
|
||||||
FID_DUMP_BODY
|
FID_DUMP_BODY
|
||||||
f_dump_line(item->fl$1, indent + 1);
|
f_dump_line(item->fl$1, indent + 1);
|
||||||
FID_POSTFIXIFY_BODY
|
FID_LINEARIZE_BODY
|
||||||
item->fl$1 = f_postfixify(what->f$1);
|
item->fl$1 = f_linearize(what->f$1);
|
||||||
FID_SAME_BODY
|
FID_SAME_BODY
|
||||||
if (!f_same(f1->fl$1, f2->fl$1)) return 0;
|
if (!f_same(f1->fl$1, f2->fl$1)) return 0;
|
||||||
FID_INTERPRET_BODY
|
FID_INTERPRET_BODY
|
||||||
|
@ -310,9 +310,9 @@ FID_WR_PUT(7)
|
||||||
debug("%sFilter line %p dump done\n", INDENT, dest);
|
debug("%sFilter line %p dump done\n", INDENT, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Postfixify */
|
/* Linearize */
|
||||||
static uint
|
static uint
|
||||||
postfixify(struct f_line *dest, const struct f_inst *what_, uint pos)
|
linearize(struct f_line *dest, const struct f_inst *what_, uint pos)
|
||||||
{
|
{
|
||||||
for ( ; what_; what_ = what_->next) {
|
for ( ; what_; what_ = what_->next) {
|
||||||
switch (what_->fi_code) {
|
switch (what_->fi_code) {
|
||||||
|
@ -324,7 +324,7 @@ FID_WR_PUT(8)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct f_line *
|
struct f_line *
|
||||||
f_postfixify_concat(const struct f_inst * const inst[], uint count)
|
f_linearize_concat(const struct f_inst * const inst[], uint count)
|
||||||
{
|
{
|
||||||
uint len = 0;
|
uint len = 0;
|
||||||
for (uint i=0; i<count; i++)
|
for (uint i=0; i<count; i++)
|
||||||
|
@ -334,7 +334,7 @@ f_postfixify_concat(const struct f_inst * const inst[], uint count)
|
||||||
struct f_line *out = cfg_allocz(sizeof(struct f_line) + sizeof(struct f_line_item)*len);
|
struct f_line *out = cfg_allocz(sizeof(struct f_line) + sizeof(struct f_line_item)*len);
|
||||||
|
|
||||||
for (uint i=0; i<count; i++)
|
for (uint i=0; i<count; i++)
|
||||||
out->len = postfixify(out, inst[i], out->len);
|
out->len = linearize(out, inst[i], out->len);
|
||||||
|
|
||||||
#if DEBUGGING
|
#if DEBUGGING
|
||||||
f_dump_line(out, 0);
|
f_dump_line(out, 0);
|
||||||
|
|
|
@ -295,7 +295,7 @@
|
||||||
, const struct f_val val
|
, const struct f_val val
|
||||||
FID_NEW_BODY
|
FID_NEW_BODY
|
||||||
what->val = val;
|
what->val = val;
|
||||||
FID_POSTFIXIFY_BODY
|
FID_LINEARIZE_BODY
|
||||||
item->val = what->val;
|
item->val = what->val;
|
||||||
FID_SAME_BODY
|
FID_SAME_BODY
|
||||||
if (!val_same(&(f1->val), &(f2->val))) return 0;
|
if (!val_same(&(f1->val), &(f2->val))) return 0;
|
||||||
|
@ -316,7 +316,7 @@
|
||||||
, const struct symbol *sym
|
, const struct symbol *sym
|
||||||
FID_NEW_BODY
|
FID_NEW_BODY
|
||||||
what->sym = sym;
|
what->sym = sym;
|
||||||
FID_POSTFIXIFY_BODY
|
FID_LINEARIZE_BODY
|
||||||
item->valp = (item->sym = what->sym)->val;
|
item->valp = (item->sym = what->sym)->val;
|
||||||
FID_SAME_BODY
|
FID_SAME_BODY
|
||||||
if (strcmp(f1->sym->name, f2->sym->name) || !val_same(f1->sym->val, f2->sym->val)) return 0;
|
if (strcmp(f1->sym->name, f2->sym->name) || !val_same(f1->sym->val, f2->sym->val)) return 0;
|
||||||
|
@ -339,14 +339,14 @@
|
||||||
LINE(3,1);
|
LINE(3,1);
|
||||||
}
|
}
|
||||||
INST(FI_PRINT_AND_DIE, 0, 0) {
|
INST(FI_PRINT_AND_DIE, 0, 0) {
|
||||||
FID_POSTFIXIFY_BODY
|
FID_LINEARIZE_BODY
|
||||||
{
|
{
|
||||||
uint opos = pos;
|
uint opos = pos;
|
||||||
FID_ALL
|
FID_ALL
|
||||||
|
|
||||||
ARG_ANY(1);
|
ARG_ANY(1);
|
||||||
|
|
||||||
FID_POSTFIXIFY_BODY
|
FID_LINEARIZE_BODY
|
||||||
if (opos < pos)
|
if (opos < pos)
|
||||||
dest->items[pos].flags |= FIF_PRINTED;
|
dest->items[pos].flags |= FIF_PRINTED;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
* translates into f_new_inst_FI_code(...) and the types are checked in
|
* translates into f_new_inst_FI_code(...) and the types are checked in
|
||||||
* compile time.
|
* compile time.
|
||||||
*
|
*
|
||||||
* 2 Postfixify before interpreting
|
* 2 Linearize before interpreting
|
||||||
* The infix tree is always interpreted in the same order. Therefore we
|
* The infix tree is always interpreted in the same order. Therefore we
|
||||||
* sort the instructions one after another into struct f_line. Results
|
* sort the instructions one after another into struct f_line. Results
|
||||||
* and arguments of these instructions are implicitly put on a value
|
* and arguments of these instructions are implicitly put on a value
|
||||||
|
@ -73,9 +73,9 @@ struct f_line {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Convert the f_inst infix tree to the f_line structures */
|
/* Convert the f_inst infix tree to the f_line structures */
|
||||||
struct f_line *f_postfixify_concat(const struct f_inst * const inst[], uint count);
|
struct f_line *f_linearize_concat(const struct f_inst * const inst[], uint count);
|
||||||
static inline struct f_line *f_postfixify(const struct f_inst *root)
|
static inline struct f_line *f_linearize(const struct f_inst *root)
|
||||||
{ return f_postfixify_concat(&root, 1); }
|
{ return f_linearize_concat(&root, 1); }
|
||||||
|
|
||||||
void f_dump_line(const struct f_line *, uint indent);
|
void f_dump_line(const struct f_line *, uint indent);
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ struct filter *f_new_where(const struct f_inst *where)
|
||||||
};
|
};
|
||||||
|
|
||||||
struct filter *f = cfg_allocz(sizeof(struct filter));
|
struct filter *f = cfg_allocz(sizeof(struct filter));
|
||||||
f->root = f_postfixify(&i);
|
f->root = f_linearize(&i);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@ rtrid:
|
||||||
|
|
||||||
idval:
|
idval:
|
||||||
NUM { $$ = $1; }
|
NUM { $$ = $1; }
|
||||||
| '(' term ')' { $$ = f_eval_int(f_postfixify($2)); }
|
| '(' term ')' { $$ = f_eval_int(f_linearize($2)); }
|
||||||
| IP4 { $$ = ip4_to_u32($1); }
|
| IP4 { $$ = ip4_to_u32($1); }
|
||||||
| CF_SYM_KNOWN {
|
| CF_SYM_KNOWN {
|
||||||
if ($1->class == (SYM_CONSTANT | T_INT) || $1->class == (SYM_CONSTANT | T_QUAD))
|
if ($1->class == (SYM_CONSTANT | T_INT) || $1->class == (SYM_CONSTANT | T_QUAD))
|
||||||
|
@ -733,7 +733,7 @@ CF_CLI(DUMP PROTOCOLS,,, [[Dump protocol information]])
|
||||||
{ protos_dump_all(); cli_msg(0, ""); } ;
|
{ protos_dump_all(); cli_msg(0, ""); } ;
|
||||||
|
|
||||||
CF_CLI(EVAL, term, <expr>, [[Evaluate an expression]])
|
CF_CLI(EVAL, term, <expr>, [[Evaluate an expression]])
|
||||||
{ cmd_eval(f_postfixify($2)); } ;
|
{ cmd_eval(f_linearize($2)); } ;
|
||||||
|
|
||||||
CF_CLI_HELP(ECHO, ..., [[Control echoing of log messages]])
|
CF_CLI_HELP(ECHO, ..., [[Control echoing of log messages]])
|
||||||
CF_CLI(ECHO, echo_mask echo_size, (all | off | { debug|trace|info|remote|warning|error|auth [, ...] }) [<buffer-size>], [[Control echoing of log messages]]) {
|
CF_CLI(ECHO, echo_mask echo_size, (all | off | { debug|trace|info|remote|warning|error|auth [, ...] }) [<buffer-size>], [[Control echoing of log messages]]) {
|
||||||
|
|
|
@ -40,7 +40,7 @@ static_route_finish(void)
|
||||||
if (net_type_match(this_srt->net, NB_DEST) == !this_srt->dest)
|
if (net_type_match(this_srt->net, NB_DEST) == !this_srt->dest)
|
||||||
cf_error("Unexpected or missing nexthop/type");
|
cf_error("Unexpected or missing nexthop/type");
|
||||||
|
|
||||||
this_srt->cmds = f_postfixify(this_srt_cmds);
|
this_srt->cmds = f_linearize(this_srt_cmds);
|
||||||
}
|
}
|
||||||
|
|
||||||
CF_DECLS
|
CF_DECLS
|
||||||
|
|
Loading…
Reference in a new issue