Skip to content
Snippets Groups Projects
Commit e537844f authored by Eelco Dolstra's avatar Eelco Dolstra
Browse files

* Bottomup rewrite function.

parent 442b09ea
No related branches found
No related tags found
No related merge requests found
#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);
}
#ifndef __FIXEXPR_H
#define __FIXEXPR_H
#include <aterm2.h>
#include "util.hh"
/* Fix expressions are represented as ATerms. The maximal sharing
property of the ATerm library allows us to implement caching of
normals forms efficiently. */
typedef ATerm Expr;
/* Generic bottomup traversal over ATerms. The traversal first
recursively descends into subterms, and then applies the given term
function to the resulting term. */
struct TermFun
{
virtual ATerm operator () (ATerm e) = 0;
};
ATerm bottomupRewrite(TermFun & f, ATerm e);
#endif /* !__FIXEXPR_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment