1
0
mirror of https://gitlab.labs.nic.cz/labs/bird.git synced 2024-05-11 16:54:54 +00:00

Filter: Change linearization of branches in switch instruction

Most branching instructions (FI_CONDITION, FI_AND, FI_OR) linearize its
branches in a recursive way, while FI_SWITCH branches are linearized
from parser even before the switch instruction is allocated.

Change linearization of FI_SWITCH branches to make it similar to other
branching instructions. This also fixes an issue with constant
switch evaluation, where linearized branch is mistaken for
non-linearized during switch construction.

Thanks to Jiten Kumar Pathy for the bugreport.
This commit is contained in:
Ondrej Zajicek
2023-01-07 20:18:44 +01:00
parent d1cd5e5a63
commit e20bef69cc
4 changed files with 46 additions and 7 deletions

View File

@@ -676,16 +676,15 @@ switch_body: /* EMPTY */ { $$ = NULL; }
| switch_body switch_items ':' cmds_scoped {
/* Fill data fields */
struct f_tree *t;
struct f_line *line = f_linearize($4, 0);
for (t = $2; t; t = t->left)
t->data = line;
t->data = $4;
$$ = f_merge_items($1, $2);
}
| switch_body ELSECOL cmds_scoped {
struct f_tree *t = f_new_tree();
t->from.type = t->to.type = T_VOID;
t->right = t;
t->data = f_linearize($3, 0);
t->data = $3;
$$ = f_merge_items($1, t);
}
;
@@ -972,7 +971,7 @@ cmd:
}
| function_call ';' { $$ = f_new_inst(FI_DROP_RESULT, $1); }
| CASE term '{' switch_body '}' {
$$ = f_new_inst(FI_SWITCH, $2, build_tree($4));
$$ = f_new_inst(FI_SWITCH, $2, $4);
}
| dynamic_attr '.' EMPTY ';' { $$ = f_generate_empty($1); }