diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2003-10-30T16·11+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2003-10-30T16·11+0000 |
commit | e537844f4ebc53df13f52722fb16bbeb1f4cbd18 (patch) | |
tree | 798eeaa266774cb7dde8fb00f3cb0ed0de53c475 /src/fix-ng/fix-expr.cc | |
parent | 442b09ea33dcf516a6f5244ed2c362682e1347b0 (diff) |
* Bottomup rewrite function.
Diffstat (limited to 'src/fix-ng/fix-expr.cc')
-rw-r--r-- | src/fix-ng/fix-expr.cc | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/fix-ng/fix-expr.cc b/src/fix-ng/fix-expr.cc new file mode 100644 index 000000000000..00795da4c427 --- /dev/null +++ b/src/fix-ng/fix-expr.cc @@ -0,0 +1,33 @@ +#include "fix-expr.hh" +#include "expr.hh" + + +ATerm bottomupRewrite(TermFun & f, ATerm e) +{ + e = f(e); + + if (ATgetType(e) == AT_APPL) { + AFun fun = ATgetAFun(e); + int arity = ATgetArity(fun); + ATermList args = ATempty; + + for (int i = arity - 1; i >= 0; i--) + args = ATinsert(args, bottomupRewrite(f, ATgetArgument(e, i))); + + return (ATerm) ATmakeApplList(fun, args); + } + + if (ATgetType(e) == AT_LIST) { + ATermList in = (ATermList) e; + ATermList out = ATempty; + + while (!ATisEmpty(in)) { + out = ATinsert(out, bottomupRewrite(f, ATgetFirst(in))); + in = ATgetNext(in); + } + + return (ATerm) ATreverse(out); + } + + throw badTerm("cannot rewrite", e); +} |