From d2171eba4784761b9493325a4316c32079fdc685 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Mon, 21 May 2012 23:17:33 -0300 Subject: [PATCH] b2/: add "ignore" keyword for substitution rules This allows us to decide in the project-specific rules how to indicate DNP/NC/DNS/... parts. In the original BOOM, F1 == NC was hard-coded. --- b2/SUBST | 4 +++- b2/boom.c | 5 ++++- b2/lang.y | 7 +++++-- b2/subex.c | 14 ++++++++------ b2/subex.h | 3 ++- b2/subst.c | 11 +++++++++++ b2/subst.h | 12 +++++++----- 7 files changed, 40 insertions(+), 16 deletions(-) diff --git a/b2/SUBST b/b2/SUBST index 039ada9..595a855 100644 --- a/b2/SUBST +++ b/b2/SUBST @@ -1,10 +1,12 @@ +FN=DNP { ignore } + REF=R[0-9]* { T=R VAL=(#R) { R=$1 } TOL <= 5% FN=*% { TOL<=$$ } break REF -// end break again +// end break again ignore } /* diff --git a/b2/boom.c b/b2/boom.c index 83ea06e..55d7a2e 100644 --- a/b2/boom.c +++ b/b2/boom.c @@ -48,7 +48,10 @@ static void do_substitutions(void) const struct param *var; const struct part **parts, **p; - out = substitute(substitutions, vars); + if (!substitute(substitutions, vars, &out)) { + fprintf(stderr, "ignore\n"); + return; + } if (select_parts) { parts = select_parametric(out, &hierarchy); if (!parts) { diff --git a/b2/lang.y b/b2/lang.y index 9d7d022..64d5ee4 100644 --- a/b2/lang.y +++ b/b2/lang.y @@ -613,9 +613,12 @@ block: } | WORD { - if (strcmp($1, "end")) + if (!strcmp($1, "end")) + $$ = subst_end(); + else if (!strcmp($1, "ignore")) + $$ = subst_ignore(); + else yyerrorf("unknown keyword \"%s\"", $1); - $$ = subst_end(); } ; diff --git a/b2/subex.c b/b2/subex.c index 97b8342..fe058d0 100644 --- a/b2/subex.c +++ b/b2/subex.c @@ -30,9 +30,9 @@ static const char *fn = NULL, *f[FIELDS]; -/* Jump target that can never be reached. */ +/* Jump targets that can never be reached. */ static struct subst jump_end; - +static struct subst jump_ignore; static char *canonicalize(const char *s, char unit) @@ -206,6 +206,8 @@ static const struct subst *recurse_sub(const struct subst *sub, break; case st_end: return &jump_end; + case st_ignore: + return &jump_ignore; case st_break: sub = sub->u.jump->next; continue; @@ -221,9 +223,9 @@ static const struct subst *recurse_sub(const struct subst *sub, } -struct param *substitute(const struct subst *sub, const struct param *in) +int substitute(const struct subst *sub, const struct param *in, + struct param **out) { - struct param *out = NULL; int i; char tmp[4]; @@ -234,6 +236,6 @@ struct param *substitute(const struct subst *sub, const struct param *in) f[i] = unique(tmp); } } - recurse_sub(sub, in, NULL, NULL, NULL, &out); - return out; + *out = NULL; + return recurse_sub(sub, in, NULL, NULL, NULL, out) != &jump_ignore; } diff --git a/b2/subex.h b/b2/subex.h index e280bdc..a664ae0 100644 --- a/b2/subex.h +++ b/b2/subex.h @@ -17,6 +17,7 @@ #include "subst.h" -struct param *substitute(const struct subst *sub, const struct param *in); +int substitute(const struct subst *sub, const struct param *in, + struct param **out); #endif /* !SUBEX_H */ diff --git a/b2/subst.c b/b2/subst.c index 6cf2058..e0c3718 100644 --- a/b2/subst.c +++ b/b2/subst.c @@ -245,6 +245,12 @@ struct subst *subst_end(void) } +struct subst *subst_ignore(void) +{ + return alloc_subst(st_ignore); +} + + struct subst *subst_break(const char *block) { struct subst *sub; @@ -357,6 +363,8 @@ static void recurse_fin(struct subst *sub, const struct parent *parent) break; case st_end: break; + case st_ignore: + break; case st_break: case st_again: sub->u.jump = resolve_jump(sub->u.tmp, parent); @@ -425,6 +433,9 @@ static void recurse_dump(FILE *file, const struct subst *sub, int level) case st_end: fprintf(file, "end\n"); break; + case st_ignore: + fprintf(file, "ignore\n"); + break; case st_break: fprintf(file, "break %s\n", sub->u.jump->u.match.src); break; diff --git a/b2/subst.h b/b2/subst.h index bb68445..22d872c 100644 --- a/b2/subst.h +++ b/b2/subst.h @@ -37,11 +37,12 @@ struct chunk { }; enum subst_type { - st_match, - st_assign, - st_end, - st_break, - st_again, + st_match, /* try to match a variable */ + st_assign, /* assign to a variable */ + st_end, /* end the substitutions, accepting the part */ + st_ignore, /* ignore the part */ + st_break, /* jump to an outer block */ + st_again, /* repeat an outer block */ }; struct subst { @@ -73,6 +74,7 @@ struct subst { struct subst *subst_match(const char *src, const char *re); struct subst *subst_assign(const char *dst, enum relop op, const char *pat); struct subst *subst_end(void); +struct subst *subst_ignore(void); struct subst *subst_break(const char *block); struct subst *subst_again(const char *block);