0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-09 20:58:44 +00:00

Filter: renaming pointers for consistency

The struct f_inst * is now always "what"
and the union member pointer is always "whati".
This commit is contained in:
Maria Matejka 2019-06-28 11:08:48 +02:00
parent 64bb1346c7
commit 63f49457dc
4 changed files with 35 additions and 42 deletions

View File

@ -31,9 +31,6 @@ m4_divert(-1)m4_dnl
# Final diversions # Final diversions
# 200+ completed text before it is flushed to output # 200+ completed text before it is flushed to output
# Flush the completed instruction
m4_define(FID_END, `m4_divert(-1)')
m4_dnl m4_debugmode(aceflqtx) m4_dnl m4_debugmode(aceflqtx)
m4_define(FID_ZONE, `m4_divert($1) /* $2 for INST_NAME() */') m4_define(FID_ZONE, `m4_divert($1) /* $2 for INST_NAME() */')
@ -58,8 +55,6 @@ m4_define(FID_LINE_IN, `m4_divert(107)')
m4_define(FID_INTERPRET_BODY, `m4_divert(108)') m4_define(FID_INTERPRET_BODY, `m4_divert(108)')
m4_define(FID_ALL, `FID_INTERPRET_BODY'); m4_define(FID_ALL, `FID_INTERPRET_BODY');
m4_define(FID_ALL_TARGETS, `m4_ifdef([[FID_CURDIV]], [[m4_divert(FID_CURDIV)m4_undefine([[FID_CURDIV]])]])')
m4_define(FID_HIC, `m4_ifelse(TARGET, [[H]], $1, TARGET, [[I]], $2, TARGET, [[C]], $3)') m4_define(FID_HIC, `m4_ifelse(TARGET, [[H]], $1, TARGET, [[I]], $2, TARGET, [[C]], $3)')
m4_define(INST_FLUSH, `m4_ifdef([[INST_NAME]], [[ m4_define(INST_FLUSH, `m4_ifdef([[INST_NAME]], [[
@ -84,14 +79,14 @@ FID_HIC(
[[]], [[]],
[[ [[
{ {
struct f_inst *what_ = cfg_allocz(sizeof(struct f_inst)); struct f_inst *what = cfg_allocz(sizeof(struct f_inst));
what_->fi_code = fi_code; what->fi_code = fi_code;
what_->lineno = ifs->lino; what->lineno = ifs->lino;
what_->size = 1; what->size = 1;
#define what (&(what_->i_]]INST_NAME()[[)) #define whati (&(what->i_]]INST_NAME()[[))
[[m4_undivert(103)]] [[m4_undivert(103)]]
#undef what #undef whati
return what_; return what;
} }
]]) ]])
@ -111,13 +106,13 @@ m4_undivert(104)
FID_LINEARIZE FID_LINEARIZE
case INST_NAME(): { case INST_NAME(): {
#define what (&(what_->i_]]INST_NAME()[[)) #define whati (&(what->i_]]INST_NAME()[[))
#define item (&(dest->items[pos].i_]]INST_NAME()[[)) #define item (&(dest->items[pos].i_]]INST_NAME()[[))
m4_undivert(105) m4_undivert(105)
#undef what #undef whati
#undef item #undef item
dest->items[pos].fi_code = what_->fi_code; dest->items[pos].fi_code = what->fi_code;
dest->items[pos].lineno = what_->lineno; dest->items[pos].lineno = what->lineno;
break; break;
} }
m4_undefine([[FID_LINEARIZE_BODY_EXISTS]]) m4_undefine([[FID_LINEARIZE_BODY_EXISTS]])
@ -139,7 +134,6 @@ m4_undivert(108)
#undef whati #undef whati
break; break;
FID_END
]])') ]])')
m4_define(INST, `m4_dnl m4_define(INST, `m4_dnl
@ -165,10 +159,10 @@ $1 $2;
FID_NEW_ARGS FID_NEW_ARGS
, $1 $2 , $1 $2
FID_NEW_BODY FID_NEW_BODY
what->$2 = $2; whati->$2 = $2;
m4_ifelse($3,,,[[ m4_ifelse($3,,,[[
FID_LINEARIZE_BODY FID_LINEARIZE_BODY
item->$3 = what->$2; item->$3 = whati->$2;
]]) ]])
m4_ifelse($4,,,[[ m4_ifelse($4,,,[[
FID_SAME_BODY FID_SAME_BODY
@ -186,14 +180,14 @@ FID_ALL')
m4_define(ARG_ANY, ` m4_define(ARG_ANY, `
FID_STRUCT_IN FID_STRUCT_IN
const struct f_inst * f$1; struct f_inst * f$1;
FID_NEW_ARGS FID_NEW_ARGS
, const struct f_inst * f$1 , struct f_inst * f$1
FID_NEW_BODY FID_NEW_BODY
what->f$1 = f$1; whati->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_LINEARIZE_BODY FID_LINEARIZE_BODY
pos = linearize(dest, what->f$1, pos);m4_dnl pos = linearize(dest, whati->f$1, pos);m4_dnl
FID_ALL()') FID_ALL()')
m4_define(ARG, `ARG_ANY($1) m4_define(ARG, `ARG_ANY($1)
@ -220,11 +214,11 @@ const struct f_inst * f$1;
FID_NEW_ARGS FID_NEW_ARGS
, const struct f_inst * f$1 , const struct f_inst * f$1
FID_NEW_BODY FID_NEW_BODY
what->f$1 = f$1; whati->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_LINEARIZE_BODY FID_LINEARIZE_BODY
item->fl$1 = f_linearize(what->f$1); item->fl$1 = f_linearize(whati->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
@ -307,10 +301,10 @@ FID_WR_PUT(7)
/* Linearize */ /* Linearize */
static uint static uint
linearize(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) {
FID_WR_PUT(8) FID_WR_PUT(8)
} }
pos++; pos++;

View File

@ -27,8 +27,8 @@
* m4_dnl LINE(num, unused); this argument has to be converted to its own f_line * m4_dnl LINE(num, unused); this argument has to be converted to its own f_line
* m4_dnl ECS; extended community subtype * m4_dnl ECS; extended community subtype
* m4_dnl COUNT(unused); simply a uint * m4_dnl COUNT(unused); simply a uint
* m4_dnl SYMBOL(unused); symbol handed from config * m4_dnl SYMBOL; symbol handed from config
* m4_dnl FRET(unused); filter return value * m4_dnl FRET; filter return value
* m4_dnl STATIC_ATTR; static attribute definition * m4_dnl STATIC_ATTR; static attribute definition
* m4_dnl DYNAMIC_ATTR; dynamic attribute definition * m4_dnl DYNAMIC_ATTR; dynamic attribute definition
* m4_dnl RTC; route table config * m4_dnl RTC; route table config
@ -153,7 +153,7 @@
if (tt->fi_code != FI_CONSTANT) if (tt->fi_code != FI_CONSTANT)
dyn++; dyn++;
what->count = len; whati->count = len;
FID_ALL FID_ALL
if (fstk->vcnt < whati->count) /* TODO: make this check systematic */ if (fstk->vcnt < whati->count) /* TODO: make this check systematic */
@ -262,8 +262,8 @@
/* Set to indirect value prepared in v1 */ /* Set to indirect value prepared in v1 */
INST(FI_VAR_SET, 1, 0) { INST(FI_VAR_SET, 1, 0) {
ARG_ANY(2); ARG_ANY(1);
SYMBOL(1); SYMBOL;
if ((sym->class != (SYM_VARIABLE | v1.type)) && (v1.type != T_VOID)) if ((sym->class != (SYM_VARIABLE | v1.type)) && (v1.type != T_VOID))
{ {
/* IP->Quad implicit conversion */ /* IP->Quad implicit conversion */
@ -294,17 +294,16 @@
FID_NEW_ARGS FID_NEW_ARGS
, const struct f_val val , const struct f_val val
FID_NEW_BODY FID_NEW_BODY
what->val = val; whati->val = val;
FID_LINEARIZE_BODY FID_LINEARIZE_BODY
item->val = what->val; item->val = whati->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;
FID_DUMP_BODY FID_DUMP_BODY
debug("%svalue %s\n", INDENT, val_dump(&item->val)); debug("%svalue %s\n", INDENT, val_dump(&item->val));
FID_ALL FID_ALL
res = whati->val; RESULT_VAL(whati->val);
RESULT_OK;
} }
INST(FI_CONSTANT_DEFINED, 0, 1) { INST(FI_CONSTANT_DEFINED, 0, 1) {
FID_STRUCT_IN FID_STRUCT_IN
@ -315,9 +314,9 @@
FID_NEW_ARGS FID_NEW_ARGS
, const struct symbol *sym , const struct symbol *sym
FID_NEW_BODY FID_NEW_BODY
what->sym = sym; whati->sym = sym;
FID_LINEARIZE_BODY FID_LINEARIZE_BODY
item->valp = (item->sym = what->sym)->val; item->valp = (item->sym = whati->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;
FID_DUMP_BODY FID_DUMP_BODY

View File

@ -79,7 +79,7 @@ static inline struct f_line *f_linearize(const struct f_inst *root)
void f_dump_line(const struct f_line *, uint indent); void f_dump_line(const struct f_line *, uint indent);
struct filter *f_new_where(const struct f_inst *); struct filter *f_new_where(struct f_inst *);
static inline struct f_dynamic_attr f_new_dynamic_attr(u8 type, u8 bit, enum f_type f_type, uint code) /* Type as core knows it, type as filters know it, and code of dynamic attribute */ static inline struct f_dynamic_attr f_new_dynamic_attr(u8 type, u8 bit, enum f_type f_type, uint code) /* Type as core knows it, type as filters know it, and code of dynamic attribute */
{ return (struct f_dynamic_attr) { .type = type, .bit = bit, .f_type = f_type, .ea_code = code }; } /* f_type currently unused; will be handy for static type checking */ { return (struct f_dynamic_attr) { .type = type, .bit = bit, .f_type = f_type, .ea_code = code }; } /* f_type currently unused; will be handy for static type checking */
static inline struct f_static_attr f_new_static_attr(int f_type, int code, int readonly) static inline struct f_static_attr f_new_static_attr(int f_type, int code, int readonly)

View File

@ -30,7 +30,7 @@ filter_name(const struct filter *filter)
return filter->sym->name; return filter->sym->name;
} }
struct filter *f_new_where(const struct f_inst *where) struct filter *f_new_where(struct f_inst *where)
{ {
struct f_inst acc = { struct f_inst acc = {
.fi_code = FI_PRINT_AND_DIE, .fi_code = FI_PRINT_AND_DIE,