diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2003-11-16T17·46+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2003-11-16T17·46+0000 |
commit | 3e5a019a070cbaac7d1248e208c66da9fdb23313 (patch) | |
tree | dc18227825e04cabe6a4829cc76c7729792b7d78 /src/fix-ng/fix-expr.cc | |
parent | 06ae269c7c5cdda32072f3f00cf644e540ba12cd (diff) |
* Some utility functions for working with ATerms.
Diffstat (limited to 'src/fix-ng/fix-expr.cc')
-rw-r--r-- | src/fix-ng/fix-expr.cc | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/fix-ng/fix-expr.cc b/src/fix-ng/fix-expr.cc index 1ce4a55e475a..a3d24ba0e6ab 100644 --- a/src/fix-ng/fix-expr.cc +++ b/src/fix-ng/fix-expr.cc @@ -118,14 +118,15 @@ ATerm bottomupRewrite(TermFun & f, ATerm e) void queryAllAttrs(Expr e, ATermMap & attrs) { + ATMatcher m; ATermList bnds; - if (!ATmatch(e, "Attrs([<list>])", &bnds)) + if (!(atMatch(m, e) >> "Attrs" >> bnds)) throw badTerm("expected attribute set", e); while (!ATisEmpty(bnds)) { - char * s; + string s; Expr e; - if (!ATmatch(ATgetFirst(bnds), "Bind(<str>, <term>)", &s, &e)) + if (!(atMatch(m, ATgetFirst(bnds)) >> "Bind" >> s >> e)) abort(); /* can't happen */ attrs.set(s, e); bnds = ATgetNext(bnds); @@ -156,9 +157,10 @@ Expr makeAttrs(const ATermMap & attrs) Expr substitute(const ATermMap & subs, Expr e) { - char * s; + ATMatcher m; + string s; - if (ATmatch(e, "Var(<str>)", &s)) { + if (atMatch(m, e) >> "Var" >> s) { Expr sub = subs.get(s); return sub ? sub : e; } @@ -167,13 +169,13 @@ Expr substitute(const ATermMap & subs, Expr e) function. */ ATermList formals; ATerm body; - if (ATmatch(e, "Function([<list>], <term>)", &formals, &body)) { + if (atMatch(m, e) >> "Function" >> formals >> body) { ATermMap subs2(subs); ATermList fs = formals; while (!ATisEmpty(fs)) { Expr def; - if (!ATmatch(ATgetFirst(fs), "NoDefFormal(<str>)", &s) && - !ATmatch(ATgetFirst(fs), "DefFormal(<str>, <term>)", &s)) + if (!(atMatch(m, ATgetFirst(fs)) >> "NoDefFormal" >> s) && + !(atMatch(m, ATgetFirst(fs)) >> "DefFormal" >> s >> def)) abort(); subs2.remove(s); fs = ATgetNext(fs); @@ -184,12 +186,12 @@ Expr substitute(const ATermMap & subs, Expr e) /* Idem for a mutually recursive attribute set. */ ATermList bindings; - if (ATmatch(e, "Rec([<list>])", &bindings)) { + if (atMatch(m, e) >> "Rec" >> bindings) { ATermMap subs2(subs); ATermList bnds = bindings; while (!ATisEmpty(bnds)) { Expr e; - if (!ATmatch(ATgetFirst(bnds), "Bind(<str>, <term>)", &s, &e)) + if (!(atMatch(m, ATgetFirst(bnds)) >> "Bind" >> s >> e)) abort(); /* can't happen */ subs2.remove(s); bnds = ATgetNext(bnds); |