mirror of
https://github.com/NixOS/nix
synced 2025-07-01 16:41:47 +02:00
* Bottomup rewrite function.
This commit is contained in:
parent
442b09ea33
commit
e537844f4e
2 changed files with 60 additions and 0 deletions
33
src/fix-ng/fix-expr.cc
Normal file
33
src/fix-ng/fix-expr.cc
Normal file
|
@ -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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue