FAUST compiler  0.9.9.6b8
Classes | Functions | Variables
recursive-tree.cpp File Reference
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include "tlib.hh"
Include dependency graph for recursive-tree.cpp:

Go to the source code of this file.

Classes

struct  Env
 

Functions

static Tree calcDeBruijn2Sym (Tree t)
 
static Tree substitute (Tree t, int n, Tree id)
 
static Tree calcsubstitute (Tree t, int level, Tree id)
 
static Tree liftn (Tree t, int threshold)
 
static Tree calcliftn (Tree t, int threshold)
 
Tree rec (Tree body)
 create a de Bruijn recursive tree More...
 
bool isRec (Tree t, Tree &body)
 is t a de Bruijn recursive tree More...
 
Tree ref (int level)
 create a de Bruijn recursive reference More...
 
bool isRef (Tree t, int &level)
 is t a de Bruijn recursive reference More...
 
Tree rec (Tree var, Tree body)
 create a symbolic recursive tree More...
 
bool isRec (Tree t, Tree &var, Tree &body)
 is t a symbolic recursive tree More...
 
Tree ref (Tree id)
 create a symbolic recursive reference More...
 
bool isRef (Tree t, Tree &v)
 is t a symbolic recursive reference More...
 
Tree lift (Tree t)
 
void printSignal (Tree sig, FILE *out, int prec=0)
 
Tree deBruijn2Sym (Tree t)
 
static void markOpen (Tree t)
 
static int recomputeAperture (Tree t, Env *p)
 
static int orderof (Tree t, Env *p)
 
void updateAperture (Tree t)
 

Variables

Sym DEBRUIJN = symbol ("DEBRUIJN")
 
Sym DEBRUIJNREF = symbol ("DEBRUIJNREF")
 
Sym SUBSTITUTE = symbol ("SUBSTITUTE")
 
Sym SYMREC = symbol ("SYMREC")
 
Sym SYMRECREF = symbol ("SYMRECREF")
 
Sym SYMLIFTN = symbol ("LIFTN")
 
Tree RECDEF = tree(symbol("RECDEF"))
 
Tree DEBRUIJN2SYM = tree(symbol("deBruijn2Sym"))
 

Function Documentation

static Tree calcDeBruijn2Sym ( Tree  t)
static

Definition at line 235 of file recursive-tree.cpp.

References CTree::arity(), CTree::branch(), deBruijn2Sym(), isRec(), isRef(), CTree::make(), CTree::node(), printSignal(), rec(), ref(), substitute(), tree(), and unique().

Referenced by deBruijn2Sym().

236 {
237  Tree body, var;
238  int i;
239 
240  if (isRec(t,body)) {
241 
242  var = tree(unique("W"));
243  return rec(var, deBruijn2Sym(substitute(body,1,ref(var))));
244 
245  } else if (isRef(t,var)) {
246 
247  return t;
248 
249  } else if (isRef(t,i)) {
250 
251  fprintf(stderr, "ERREUR, une reference de Bruijn touvee ! : ");
252  printSignal(t, stderr);
253  fprintf(stderr, ")\n");
254  exit(1);
255  return t;
256 
257  } else {
258 
259  //Tree br[4];
260  int a = t->arity();
261  tvec br(a);
262 
263  for (int i = 0; i < a; i++) {
264  br[i] = deBruijn2Sym(t->branch(i));
265  }
266  //return CTree::make(t->node(), a, br);
267  return CTree::make(t->node(), br);
268  }
269 }
Symbol * unique(const char *str)
Returns a new unique symbol of name strxxx.
Definition: symbol.hh:97
Tree rec(Tree body)
create a de Bruijn recursive tree
Tree deBruijn2Sym(Tree t)
Tree ref(int level)
create a de Bruijn recursive reference
vector< Tree > tvec
Definition: tree.hh:90
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
const Node & node() const
return the content of the tree
Definition: tree.hh:143
static Tree make(const Node &n, int ar, Tree br[])
return a new tree or an existing equivalent one
bool isRef(Tree t, int &level)
is t a de Bruijn recursive reference
int arity() const
return the number of branches (subtrees) of a tree
Definition: tree.hh:144
void printSignal(Tree sig, FILE *out, int prec=0)
Definition: sigprint.cpp:85
bool isRec(Tree t, Tree &body)
is t a de Bruijn recursive tree
Tree tree(const Node &n)
Definition: tree.hh:186
Tree branch(int i) const
return the ith branch (subtree) of a tree
Definition: tree.hh:145
static Tree substitute(Tree t, int n, Tree id)

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree calcliftn ( Tree  t,
int  threshold 
)
static

Definition at line 182 of file recursive-tree.cpp.

References CTree::arity(), CTree::branch(), isClosed(), isRec(), isRef(), liftn(), CTree::make(), CTree::node(), rec(), and ref().

Referenced by liftn().

183 {
184  int n;
185  Tree u;
186 
187  if (isClosed(t)) {
188 
189  return t;
190 
191  } else if (isRef(t,n)) {
192 
193  if (n < threshold) {
194  // it is a bounded reference
195  return t;
196  } else {
197  // it is a free reference
198  return ref(n+1);
199  }
200 
201  } else if (isRec(t,u)) {
202 
203  return rec(liftn(u, threshold+1));
204 
205  } else {
206  int n = t->arity();
207  //Tree br[4];
208  tvec br(n);
209  for (int i = 0; i < n; i++) {
210  br[i] = liftn(t->branch(i), threshold);
211  }
212  //return CTree::make(t->node(), n, br);
213  return CTree::make(t->node(), br);
214  }
215 
216 }
Tree rec(Tree body)
create a de Bruijn recursive tree
static Tree liftn(Tree t, int threshold)
Tree ref(int level)
create a de Bruijn recursive reference
vector< Tree > tvec
Definition: tree.hh:90
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
const Node & node() const
return the content of the tree
Definition: tree.hh:143
static Tree make(const Node &n, int ar, Tree br[])
return a new tree or an existing equivalent one
bool isClosed(Tree t)
t dont contain free de Bruijn ref
Definition: tree.hh:239
bool isRef(Tree t, int &level)
is t a de Bruijn recursive reference
int arity() const
return the number of branches (subtrees) of a tree
Definition: tree.hh:144
bool isRec(Tree t, Tree &body)
is t a de Bruijn recursive tree
Tree branch(int i) const
return the ith branch (subtree) of a tree
Definition: tree.hh:145

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree calcsubstitute ( Tree  t,
int  level,
Tree  id 
)
static

Definition at line 284 of file recursive-tree.cpp.

References CTree::aperture(), CTree::arity(), CTree::branch(), isRec(), isRef(), CTree::make(), CTree::node(), rec(), and substitute().

Referenced by substitute().

285 {
286  int l;
287  Tree body;
288 
289  if (t->aperture()<level) {
290 // fprintf(stderr, "aperture %d < level %d !!\n", t->aperture(), level);
291  return t;
292  }
293  if (isRef(t,l)) return (l == level) ? id : t;
294  if (isRec(t,body)) return rec(substitute(body, level+1, id));
295 
296  int ar = t->arity();
297  //Tree br[4];
298  tvec br(ar);
299  for (int i = 0; i < ar; i++) {
300  br[i] = substitute(t->branch(i), level, id);
301  }
302  //return CTree::make(t->node(), ar, br);
303  return CTree::make(t->node(), br);
304 }
Tree rec(Tree body)
create a de Bruijn recursive tree
vector< Tree > tvec
Definition: tree.hh:90
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
const Node & node() const
return the content of the tree
Definition: tree.hh:143
static Tree make(const Node &n, int ar, Tree br[])
return a new tree or an existing equivalent one
bool isRef(Tree t, int &level)
is t a de Bruijn recursive reference
int arity() const
return the number of branches (subtrees) of a tree
Definition: tree.hh:144
bool isRec(Tree t, Tree &body)
is t a de Bruijn recursive tree
int aperture() const
return how "open" is a tree in terms of free variables
Definition: tree.hh:148
Tree branch(int i) const
return the ith branch (subtree) of a tree
Definition: tree.hh:145
static Tree substitute(Tree t, int n, Tree id)

Here is the call graph for this function:

Here is the caller graph for this function:

Tree deBruijn2Sym ( Tree  t)

Definition at line 223 of file recursive-tree.cpp.

References calcDeBruijn2Sym(), CTree::getProperty(), isClosed(), and CTree::setProperty().

Referenced by calcDeBruijn2Sym(), mapPrepareEqSig(), and ScalarCompiler::prepare().

224 {
225  assert(isClosed(t));
226  Tree t2 = t->getProperty(DEBRUIJN2SYM);
227 
228  if (!t2) {
229  t2 = calcDeBruijn2Sym(t);
230  t->setProperty(DEBRUIJN2SYM, t2);
231  }
232  return t2;
233 }
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
bool isClosed(Tree t)
t dont contain free de Bruijn ref
Definition: tree.hh:239
void setProperty(Tree key, Tree value)
Definition: tree.hh:167
static Tree calcDeBruijn2Sym(Tree t)
Tree DEBRUIJN2SYM
Tree getProperty(Tree key)
Definition: tree.hh:173

Here is the call graph for this function:

Here is the caller graph for this function:

bool isRec ( Tree  t,
Tree body 
)

is t a de Bruijn recursive tree

Definition at line 59 of file recursive-tree.cpp.

References isTree().

Referenced by annotate(), calcDeBruijn2Sym(), calcliftn(), calcsubstitute(), computePrivatisation(), VectorCompiler::generateCodeRecursions(), ScalarCompiler::generateRecProj(), DocCompiler::generateRecProj(), getSubSignals(), infereSigOrder(), infereSigType(), ppsig::print(), printSignal(), recdraw(), recomputeAperture(), sigLabel(), sigMap(), sigMapRename(), symlistVisit(), typeAnnotation(), and sigvisitor::visit().

60 {
61  return isTree(t, DEBRUIJN, body);
62 }
bool isTree(const Tree &t, const Node &n)
Definition: tree.cpp:305
Sym DEBRUIJN

Here is the call graph for this function:

Here is the caller graph for this function:

bool isRec ( Tree  t,
Tree var,
Tree body 
)

is t a symbolic recursive tree

Definition at line 95 of file recursive-tree.cpp.

References CTree::getProperty(), and isTree().

96 {
97  if (isTree(t, SYMREC, var)) {
98  body = t->getProperty(RECDEF);
99  return true;
100  } else {
101  return false;
102  }
103 }
Sym SYMREC
Tree RECDEF
bool isTree(const Tree &t, const Node &n)
Definition: tree.cpp:305
Tree getProperty(Tree key)
Definition: tree.hh:173

Here is the call graph for this function:

bool isRef ( Tree  t,
int &  level 
)

is t a de Bruijn recursive reference

Definition at line 70 of file recursive-tree.cpp.

References isInt(), isTree(), and CTree::node().

Referenced by calcDeBruijn2Sym(), calcliftn(), calcsubstitute(), infereSigOrder(), ppsig::print(), printSignal(), recomputeAperture(), sigMapRename(), and sigvisitor::visit().

71 {
72  Tree u;
73 
74  if (isTree(t, DEBRUIJNREF, u)) {
75  return isInt(u->node(), &level);
76  } else {
77  return false;
78  }
79 }
Sym DEBRUIJNREF
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
const Node & node() const
return the content of the tree
Definition: tree.hh:143
bool isTree(const Tree &t, const Node &n)
Definition: tree.cpp:305
bool isInt(const Node &n)
Definition: node.hh:126

Here is the call graph for this function:

Here is the caller graph for this function:

bool isRef ( Tree  t,
Tree v 
)

is t a symbolic recursive reference

Definition at line 111 of file recursive-tree.cpp.

References isTree().

112 {
113  return isTree(t, SYMREC, v);
114 }
Sym SYMREC
bool isTree(const Tree &t, const Node &n)
Definition: tree.cpp:305

Here is the call graph for this function:

Tree lift ( Tree  t)

Definition at line 149 of file recursive-tree.cpp.

References liftn().

Referenced by listLift(), and realPropagate().

149 { return liftn(t, 1); }
static Tree liftn(Tree t, int threshold)

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree liftn ( Tree  t,
int  threshold 
)
static

Definition at line 169 of file recursive-tree.cpp.

References calcliftn(), CTree::getProperty(), CTree::setProperty(), and tree().

Referenced by calcliftn(), and lift().

170 {
171  Tree L = tree( Node(SYMLIFTN), tree(Node(threshold)) );
172  Tree t2 = t->getProperty(L);
173 
174  if (!t2) {
175  t2 = calcliftn(t, threshold);
176  t->setProperty(L, t2);
177  }
178  return t2;
179 
180 }
Class Node = (type x (int + double + Sym + void*))
Definition: node.hh:75
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Sym SYMLIFTN
static Tree calcliftn(Tree t, int threshold)
void setProperty(Tree key, Tree value)
Definition: tree.hh:167
Tree tree(const Node &n)
Definition: tree.hh:186
Tree getProperty(Tree key)
Definition: tree.hh:173

Here is the call graph for this function:

Here is the caller graph for this function:

static void markOpen ( Tree  t)
static

Definition at line 328 of file recursive-tree.cpp.

References CTree::aperture(), CTree::arity(), CTree::branch(), and CTree::setAperture().

Referenced by updateAperture().

329 {
330  if (t->aperture() == INT_MAX) return;
331  t->setAperture(INT_MAX);
332  int ar = t->arity();
333  for (int i = 0; i < ar; i++) {
334  markOpen(t->branch(i));
335  }
336 }
static void markOpen(Tree t)
int arity() const
return the number of branches (subtrees) of a tree
Definition: tree.hh:144
int aperture() const
return how "open" is a tree in terms of free variables
Definition: tree.hh:148
Tree branch(int i) const
return the ith branch (subtree) of a tree
Definition: tree.hh:145
void setAperture(int a)
modify the aperture of a tree
Definition: tree.hh:149

Here is the call graph for this function:

Here is the caller graph for this function:

static int orderof ( Tree  t,
Env p 
)
static

Definition at line 369 of file recursive-tree.cpp.

References Env::fNext, and Env::fTree.

Referenced by recomputeAperture().

370 {
371  if (p == NULL) return 0;
372  if (t == p->fTree) return 1;
373 
374  int pos = 1;
375  while (p != NULL) {
376  if (t == p->fTree) return pos;
377  p = p->fNext;
378  pos++;
379  }
380  return 0;
381 }
Env * fNext
Tree fTree

Here is the caller graph for this function:

void printSignal ( Tree  sig,
FILE *  out,
int  prec = 0 
)

Definition at line 85 of file sigprint.cpp.

References hd(), isList(), isProj(), isRec(), isRef(), isSigAttach(), isSigBinOp(), isSigDelay1(), isSigDocAccessTbl(), isSigDocConstantTbl(), isSigDocWriteTbl(), isSigFixDelay(), isSigFloatCast(), isSigGen(), isSigInput(), isSigInt(), isSigIntCast(), isSigOutput(), isSigPrefix(), isSigRDTbl(), isSigReal(), isSigTable(), isSigWRTbl(), print(), printSignal(), and tl().

Referenced by calcDeBruijn2Sym(), ScalarCompiler::generateCode(), main(), and printSignal().

86 {
87  int i;
88  double r;
89  Tree x, y, z, u, le, id;
90 
91  if ( isSigInt(sig, &i) ) { fprintf(out, "%d", i); }
92  else if ( isSigReal(sig, &r) ) { fprintf(out, "%f", r); }
93  else if ( isSigInput(sig, &i) ) { fprintf(out, "IN%d", i); }
94  else if ( isSigOutput(sig, &i, x) ) { fprintf(out, "OUT%d := ", i); printSignal(x, out, 0); }
95 
96  else if ( isSigBinOp(sig, &i, x, y) ) {
97  if (prec > binopprec[i]) fputs("(", out);
98  printSignal(x,out,binopprec[i]); fputs(binopname[i], out); printSignal(y, out, binopprec[i]);
99  if (prec > binopprec[i]) fputs(")", out);
100  }
101  else if ( isSigDelay1(sig, x) ) { fputs("mem(", out); printSignal(x,out,0); fputs(")", out); }
102  else if ( isSigPrefix(sig, x, y) ) { fputs("prefix(", out); printSignal(x,out,0); fputs(",", out); printSignal(y,out,0); fputs(")", out); }
103  else if ( isSigAttach(sig, x, y) ) { fputs("attach(", out); printSignal(x,out,0); fputs(",", out); printSignal(y,out,0); fputs(")", out); }
104  else if ( isSigFixDelay(sig, x, y) ) {
105  if (prec > 4) fputs("(", out);
106  printSignal(x,out,4); fputs("@", out); printSignal(y, out, 4);
107  if (prec > 4) fputs(")", out);
108  }
109 
110  else if ( isProj(sig, &i, x) ) { printSignal(x,out,prec); fprintf(out, "#%d", i); }
111  else if ( isRef(sig, i) ) { fprintf(out, "$%d", i); }
112  else if ( isRef(sig, x) ) { print(x, out); }
113  else if ( isRec(sig, le)) { fputs("\\_.", out); printSignal(le, out, prec); }
114  else if ( isRec(sig, x, le)) { fputs("\\", out); print(x,out); fputs(".", out); printSignal(le, out, prec); }
115 
116  else if ( isSigTable(sig, id, x, y) ) { fputs("table(", out); printSignal(x,out,0); fputc(',', out); printSignal(y,out,0); fputc(')', out); }
117  else if ( isSigWRTbl(sig, id, x, y, z) ){ printSignal(x,out,0); fputc('[',out); printSignal(y,out,0); fputs("] := (", out); printSignal(z,out,0); fputc(')', out); }
118  else if ( isSigRDTbl(sig, x, y) ) { printSignal(x,out,0); fputc('[', out); printSignal(y,out,0); fputc(']', out); }
119 
120  else if (isSigDocConstantTbl(sig,x,y)) { fputs("sigDocConstantTbl(", out); printSignal(x,out,0); fputc(',', out);
121  printSignal(y,out,0); fputc(')', out); }
122 
123  else if (isSigDocWriteTbl(sig,x,y,z,u)) { fputs("sigDocWriteTbl(", out); printSignal(x,out,0); fputc(',', out);
124  printSignal(y,out,0); fputc(',', out);
125  printSignal(z,out,0); fputc(',', out);
126  printSignal(u,out,0); fputc(')', out); }
127 
128  else if (isSigDocAccessTbl(sig,x,y)) { fputs("sigDocAccessTbl(", out); printSignal(x,out,0); fputc(',', out);
129  printSignal(y,out,0); fputc(')', out); }
130 
131 
132  else if ( isSigGen(sig, x) ) { printSignal(x,out,prec); }
133 
134  else if ( isSigIntCast(sig, x) ) { fputs("int(", out); printSignal(x,out,0); fputs(")", out); }
135  else if ( isSigFloatCast(sig, x) ) { fputs("float(", out); printSignal(x,out,0); fputs(")", out); }
136 
137  else if (isList(sig)) {
138  char sep = '{';
139  do {
140  fputc(sep, out);
141  printSignal(hd(sig), out, 0);
142  sep=',';
143  sig = tl(sig);
144  } while (isList(sig));
145  fputc('}', out);
146  }
147  else
148  print(sig, out);
149 }
bool isSigRDTbl(Tree s, Tree &t, Tree &i)
Definition: signals.cpp:77
bool isSigPrefix(Tree t, Tree &t0, Tree &t1)
Definition: signals.cpp:66
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
bool isSigInput(Tree t, int *i)
Definition: signals.cpp:48
bool isSigFixDelay(Tree t, Tree &t0, Tree &t1)
Definition: signals.cpp:62
Tree hd(Tree l)
Definition: list.hh:133
bool isSigGen(Tree t, Tree &x)
Definition: signals.cpp:91
bool isSigReal(Tree t, double *r)
Definition: signals.cpp:44
bool isRef(Tree t, int &level)
is t a de Bruijn recursive reference
bool isSigDocConstantTbl(Tree t, Tree &n, Tree &sig)
Definition: signals.cpp:99
bool isList(Tree l)
Definition: list.hh:138
const char * binopname[]
Definition: sigprint.cpp:71
bool isSigTable(Tree t, Tree &id, Tree &n, Tree &sig)
Definition: signals.cpp:85
void printSignal(Tree sig, FILE *out, int prec)
Definition: sigprint.cpp:85
bool isSigBinOp(Tree s, int *op, Tree &x, Tree &y)
Definition: signals.cpp:126
bool isSigAttach(Tree t, Tree &t0, Tree &t1)
Definition: signals.cpp:291
bool isSigDocAccessTbl(Tree t, Tree &tbl, Tree &ridx)
Definition: signals.cpp:107
bool isSigWRTbl(Tree u, Tree &id, Tree &t, Tree &i, Tree &s)
Definition: signals.cpp:81
bool isRec(Tree t, Tree &body)
is t a de Bruijn recursive tree
bool isSigInt(Tree t, int *i)
Definition: signals.cpp:41
int binopprec[]
Definition: sigprint.cpp:78
bool isSigDocWriteTbl(Tree t, Tree &n, Tree &sig, Tree &widx, Tree &wsig)
Definition: signals.cpp:103
bool isSigDelay1(Tree t, Tree &t0)
Definition: signals.cpp:58
bool isSigFloatCast(Tree t)
Definition: signals.cpp:187
bool isSigIntCast(Tree t)
Definition: signals.cpp:184
bool isProj(Tree t, int *i, Tree &rgroup)
Definition: signals.cpp:151
Tree tl(Tree l)
Definition: list.hh:134
bool isSigOutput(Tree t, int *i, Tree &t0)
Definition: signals.cpp:52
void print(Tree t, FILE *out)
Definition: list.cpp:154

Here is the call graph for this function:

Here is the caller graph for this function:

Tree rec ( Tree  body)

create a de Bruijn recursive tree

Definition at line 54 of file recursive-tree.cpp.

References tree().

Referenced by calcDeBruijn2Sym(), calcliftn(), calcsubstitute(), computePrivatisation(), realPropagate(), sigMap(), and sigMapRename().

55 {
56  return tree(DEBRUIJN, body);
57 }
Tree tree(const Node &n)
Definition: tree.hh:186
Sym DEBRUIJN

Here is the call graph for this function:

Here is the caller graph for this function:

Tree rec ( Tree  var,
Tree  body 
)

create a symbolic recursive tree

Definition at line 88 of file recursive-tree.cpp.

References CTree::setProperty(), and tree().

89 {
90  Tree t = tree(SYMREC, var);
91  t->setProperty(RECDEF, body);
92  return t;
93 }
Sym SYMREC
Tree RECDEF
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
void setProperty(Tree key, Tree value)
Definition: tree.hh:167
Tree tree(const Node &n)
Definition: tree.hh:186

Here is the call graph for this function:

static int recomputeAperture ( Tree  t,
Env p 
)
static

Definition at line 338 of file recursive-tree.cpp.

References CTree::aperture(), CTree::arity(), CTree::branch(), isRec(), isRef(), orderof(), and CTree::setAperture().

Referenced by updateAperture().

339 {
340  Tree var, body;
341 
342  if (t->aperture() == 0) return 0;
343 
344  if (isRef(t, var)) {
345 
346  return orderof(var, env);
347 
348  } else if (isRec(t, var, body)) {
349 
350  Env e(var,env);
351  int a = recomputeAperture(body, &e) - 1;
352  if (a<=0) { /*print(t, stderr);*/ t->setAperture(0); }
353  return a;
354 
355  } else {
356  // return max aperture of branches
357  int ma = 0;
358  int ar = t->arity();
359  for (int i = 0; i<ar; i++) {
360  int a = recomputeAperture(t->branch(i), env);
361  if (ma < a) ma = a;
362  }
363  if (ma <= 0) { /*print(t, stderr);*/ t->setAperture(0); }
364  return ma;
365  }
366 }
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
static int orderof(Tree t, Env *p)
bool isRef(Tree t, int &level)
is t a de Bruijn recursive reference
int arity() const
return the number of branches (subtrees) of a tree
Definition: tree.hh:144
bool isRec(Tree t, Tree &body)
is t a de Bruijn recursive tree
static int recomputeAperture(Tree t, Env *p)
int aperture() const
return how "open" is a tree in terms of free variables
Definition: tree.hh:148
Tree branch(int i) const
return the ith branch (subtree) of a tree
Definition: tree.hh:145
void setAperture(int a)
modify the aperture of a tree
Definition: tree.hh:149

Here is the call graph for this function:

Here is the caller graph for this function:

Tree ref ( int  level)

create a de Bruijn recursive reference

Definition at line 64 of file recursive-tree.cpp.

References tree().

Referenced by calcDeBruijn2Sym(), calcliftn(), realPropagate(), and sigMapRename().

65 {
66  assert(level > 0);
67  return tree(DEBRUIJNREF, tree(level)); // reference to enclosing recursive tree starting from 1
68 }
Sym DEBRUIJNREF
Tree tree(const Node &n)
Definition: tree.hh:186

Here is the call graph for this function:

Here is the caller graph for this function:

Tree ref ( Tree  id)

create a symbolic recursive reference

Definition at line 106 of file recursive-tree.cpp.

References tree().

107 {
108  return tree(SYMREC, id); // reference to a symbolic id
109 }
Sym SYMREC
Tree tree(const Node &n)
Definition: tree.hh:186

Here is the call graph for this function:

static Tree substitute ( Tree  t,
int  n,
Tree  id 
)
static

Definition at line 271 of file recursive-tree.cpp.

References calcsubstitute(), CTree::getProperty(), CTree::setProperty(), and tree().

Referenced by calcDeBruijn2Sym(), and calcsubstitute().

272 {
273  Tree S = tree( Node(SUBSTITUTE), tree(Node(level)), id );
274  Tree t2 = t->getProperty(S);
275 
276  if (!t2) {
277  t2 = calcsubstitute(t, level, id);
278  t->setProperty(S, t2);
279  }
280  return t2;
281 
282 }
Class Node = (type x (int + double + Sym + void*))
Definition: node.hh:75
Sym SUBSTITUTE
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
static Tree calcsubstitute(Tree t, int level, Tree id)
void setProperty(Tree key, Tree value)
Definition: tree.hh:167
Tree tree(const Node &n)
Definition: tree.hh:186
Tree getProperty(Tree key)
Definition: tree.hh:173

Here is the call graph for this function:

Here is the caller graph for this function:

void updateAperture ( Tree  t)

Definition at line 320 of file recursive-tree.cpp.

References markOpen(), and recomputeAperture().

321 {
322  markOpen(t);
323  recomputeAperture(t, NULL);
324 }
static void markOpen(Tree t)
static int recomputeAperture(Tree t, Env *p)

Here is the call graph for this function:

Variable Documentation

Sym DEBRUIJN = symbol ("DEBRUIJN")

Definition at line 39 of file recursive-tree.cpp.

Tree DEBRUIJN2SYM = tree(symbol("deBruijn2Sym"))

Definition at line 221 of file recursive-tree.cpp.

Sym DEBRUIJNREF = symbol ("DEBRUIJNREF")

Definition at line 40 of file recursive-tree.cpp.

Tree RECDEF = tree(symbol("RECDEF"))

Definition at line 85 of file recursive-tree.cpp.

Sym SUBSTITUTE = symbol ("SUBSTITUTE")

Definition at line 41 of file recursive-tree.cpp.

Sym SYMLIFTN = symbol ("LIFTN")

Definition at line 45 of file recursive-tree.cpp.

Sym SYMREC = symbol ("SYMREC")

Definition at line 43 of file recursive-tree.cpp.

Sym SYMRECREF = symbol ("SYMRECREF")

Definition at line 44 of file recursive-tree.cpp.