FAUST compiler  0.9.9.6b8
Public Member Functions | Protected Attributes | List of all members
boxpp Class Reference

#include <ppbox.hh>

Collaboration diagram for boxpp:
Collaboration graph
[legend]

Public Member Functions

 boxpp (Tree b, int p=0)
 
virtual ostream & print (ostream &fout) const
 

Protected Attributes

Tree box
 
int priority
 

Detailed Description

Definition at line 58 of file ppbox.hh.

Constructor & Destructor Documentation

boxpp::boxpp ( Tree  b,
int  p = 0 
)
inline

Definition at line 65 of file ppbox.hh.

Referenced by print().

65 : box(b), priority(p) {}
Tree box
Definition: ppbox.hh:62
int priority
Definition: ppbox.hh:63

Here is the caller graph for this function:

Member Function Documentation

ostream & boxpp::print ( ostream &  fout) const
virtual

Definition at line 144 of file ppbox.cpp.

References CTree::arity(), box, boxpp(), CTree::branch(), ffargtype(), ffarity(), ffincfile(), fflibfile(), ffrestype(), ffsignature(), getUserData(), gFloatSize, hd(), isBoxAbstr(), isBoxAccess(), isBoxAppl(), isBoxButton(), isBoxCase(), isBoxCheckbox(), isBoxComponent(), isBoxCut(), isBoxEnvironment(), isBoxError(), isBoxFConst(), isBoxFFun(), isBoxFVar(), isBoxHBargraph(), isBoxHGroup(), isBoxHSlider(), isBoxIdent(), isBoxInputs(), isBoxInt(), isBoxIPar(), isBoxIProd(), isBoxISeq(), isBoxISum(), isBoxMerge(), isBoxNumEntry(), isBoxOutputs(), isBoxPar(), isBoxPatternMatcher(), isBoxPatternVar(), isBoxPrim0(), isBoxPrim1(), isBoxPrim2(), isBoxPrim3(), isBoxPrim4(), isBoxPrim5(), isBoxReal(), isBoxRec(), isBoxSeq(), isBoxSlot(), isBoxSplit(), isBoxSymbolic(), isBoxTGroup(), isBoxVBargraph(), isBoxVGroup(), isBoxVSlider(), isBoxWaveform(), isBoxWire(), isBoxWithLocalDef(), isClosure(), isImportFile(), isList(), isNil(), max(), min(), xtended::name(), name(), nth(), prim0name(), prim1name(), prim2name(), prim3name(), prim4name(), prim5name(), printRule(), priority, streambinop(), T(), tl(), tree2int(), tree2quotedstr(), tree2str(), and type2str().

Referenced by operator<<().

145 {
146  int i, id;
147  double r;
148  prim0 p0;
149  prim1 p1;
150  prim2 p2;
151  prim3 p3;
152  prim4 p4;
153  prim5 p5;
154 
155  Tree t1, t2, t3, ff, label, cur, min, max, step, type, name, file, arg,
156  body, fun, args, abstr, genv, vis, lenv, ldef, slot,
157  ident, rules, filename;
158 
159  const char* str;
160 
161  xtended* xt = (xtended*) getUserData(box);
162 
163  // primitive elements
164  if (xt) fout << xt->name();
165  else if (isBoxInt(box, &i)) fout << i;
166  else if (isBoxReal(box, &r)) fout << T(r);
167  else if (isBoxCut(box)) fout << '!';
168  else if (isBoxWire(box)) fout << '_';
169  else if (isBoxIdent(box, &str)) fout << str;
170  else if (isBoxPrim0(box, &p0)) fout << prim0name(p0);
171  else if (isBoxPrim1(box, &p1)) fout << prim1name(p1);
172  else if (isBoxPrim2(box, &p2)) fout << prim2name(p2);
173  else if (isBoxPrim3(box, &p3)) fout << prim3name(p3);
174  else if (isBoxPrim4(box, &p4)) fout << prim4name(p4);
175  else if (isBoxPrim5(box, &p5)) fout << prim5name(p5);
176 
177  else if (isBoxAbstr(box,arg,body)) fout << "\\" << boxpp(arg) << ".(" << boxpp(body) << ")";
178  else if (isBoxAppl(box, fun, args)) fout << boxpp(fun) << boxpp(args) ;
179 
180  else if (isBoxWithLocalDef(box, body, ldef)) fout << boxpp(body) << " with { " << envpp(ldef) << " }";
181 
182  // foreign elements
183  else if (isBoxFFun(box, ff)) {
184  fout << "ffunction(" << type2str(ffrestype(ff));
185  Tree namelist = nth(ffsignature(ff),1);
186  char sep = ' ';
187  for (int i = 0; i < gFloatSize; i++) {
188  fout << sep << tree2str(nth(namelist,i));
189  sep = '|';
190  }
191  sep = '(';
192  for (int i = 0; i < ffarity(ff); i++) {
193  fout << sep << type2str(ffargtype(ff, i));
194  sep = ',';
195  }
196  fout << ')';
197  fout << ',' << ffincfile(ff) << ',' << fflibfile(ff) << ')';
198  } else if (isBoxFConst(box, type, name, file))
199  fout << "fconstant(" << type2str(tree2int(type)) << ' ' << tree2str(name) << ", " << tree2str(file) << ')';
200  else if (isBoxFVar(box, type, name, file))
201  fout << "fvariable(" << type2str(tree2int(type)) << ' ' << tree2str(name) << ", " << tree2str(file) << ')';
202 
203  // block diagram binary operator
204  else if (isBoxSeq(box, t1, t2)) streambinop(fout, t1, " : ", t2, 1, priority);
205  else if (isBoxSplit(box, t1, t2)) streambinop(fout, t1, "<:", t2, 1, priority);
206  else if (isBoxMerge(box, t1, t2)) streambinop(fout, t1, ":>", t2, 1, priority);
207  else if (isBoxPar(box, t1, t2)) streambinop(fout, t1,",",t2, 2, priority);
208  else if (isBoxRec(box, t1, t2)) streambinop(fout, t1,"~",t2, 4, priority);
209 
210  // iterative block diagram construction
211  else if (isBoxIPar(box, t1, t2, t3)) fout << "par(" << boxpp(t1) << ", " << boxpp(t2) << ") {" << boxpp(t3) << "}";
212  else if (isBoxISeq(box, t1, t2, t3)) fout << "seq(" << boxpp(t1) << ", " << boxpp(t2) << ") {" << boxpp(t3) << "}";
213  else if (isBoxISum(box, t1, t2, t3)) fout << "sum(" << boxpp(t1) << ", " << boxpp(t2) << ") {" << boxpp(t3) << "}";
214  else if (isBoxIProd(box, t1, t2, t3)) fout << "prod(" << boxpp(t1) << ", " << boxpp(t2) << ") {" << boxpp(t3) << "}";
215 
216  else if (isBoxInputs(box, t1)) fout << "inputs(" << boxpp(t1) << ")";
217  else if (isBoxOutputs(box, t1)) fout << "outputs(" << boxpp(t1) << ")";
218 
219  // user interface
220  else if (isBoxButton(box, label)) fout << "button(" << tree2quotedstr(label) << ')';
221  else if (isBoxCheckbox(box, label)) fout << "checkbox(" << tree2quotedstr(label) << ')';
222  else if (isBoxVSlider(box, label, cur, min, max, step)) {
223  fout << "vslider("
224  << tree2quotedstr(label) << ", "
225  << boxpp(cur) << ", "
226  << boxpp(min) << ", "
227  << boxpp(max) << ", "
228  << boxpp(step)<< ')';
229  }
230  else if (isBoxHSlider(box, label, cur, min, max, step)) {
231  fout << "hslider("
232  << tree2quotedstr(label) << ", "
233  << boxpp(cur) << ", "
234  << boxpp(min) << ", "
235  << boxpp(max) << ", "
236  << boxpp(step)<< ')';
237  }
238  else if (isBoxVGroup(box, label, t1)) {
239  fout << "vgroup(" << tree2quotedstr(label) << ", " << boxpp(t1, 0) << ')';
240  }
241  else if (isBoxHGroup(box, label, t1)) {
242  fout << "hgroup(" << tree2quotedstr(label) << ", " << boxpp(t1, 0) << ')';
243  }
244  else if (isBoxTGroup(box, label, t1)) {
245  fout << "tgroup(" << tree2quotedstr(label) << ", " << boxpp(t1, 0) << ')';
246  }
247  else if (isBoxHBargraph(box, label, min, max)) {
248  fout << "hbargraph("
249  << tree2quotedstr(label) << ", "
250  << boxpp(min) << ", "
251  << boxpp(max) << ')';
252  }
253  else if (isBoxVBargraph(box, label, min, max)) {
254  fout << "vbargraph("
255  << tree2quotedstr(label) << ", "
256  << boxpp(min) << ", "
257  << boxpp(max) << ')';
258  }
259  else if (isBoxNumEntry(box, label, cur, min, max, step)) {
260  fout << "nentry("
261  << tree2quotedstr(label) << ", "
262  << boxpp(cur) << ", "
263  << boxpp(min) << ", "
264  << boxpp(max) << ", "
265  << boxpp(step)<< ')';
266  }
267  else if (isNil(box)) {
268  fout << "()" ;
269  }
270  else if (isList(box)) {
271 
272  Tree l = box;
273  char sep = '(';
274 
275  do {
276  fout << sep << boxpp(hd(l));
277  sep = ',';
278  l = tl(l);
279  } while (isList(l));
280 
281  fout << ')';
282 
283  } else if (isBoxWaveform(box)) {
284 
285  fout << "waveform";
286  char sep = '{';
287  for (size_t i=0; i<box->arity(); i++) {
288  fout << sep << boxpp(box->branch(i));
289  sep = ',';
290  }
291  fout << '}';
292 
293  /*
294  size_t n = box->arity();
295 
296  if (n < 6) {
297  // small waveform, print all data
298  fout << "waveform";
299  char sep = '{';
300  for (size_t i=0; i<n; i++) {
301  fout << sep << boxpp(box->branch(i));
302  sep = ',';
303  }
304  fout << '}';
305  } else {
306  // large waveform print only first and last values
307  fout << "waveform{" << box->branch(0) << ", ..<" << n-2 << ">..," << box->branch(n-1) << "}";
308  }
309  */
310 
311  } else if (isBoxEnvironment(box)) {
312  fout << "environment";
313 
314  } else if (isClosure(box, abstr, genv, vis, lenv)) {
315  fout << "closure[" << boxpp(abstr)
316  << ", genv = " << envpp(genv)
317  << ", lenv = " << envpp(lenv)
318  << "]";
319  }
320  else if (isBoxComponent(box, label)) {
321  fout << "component("
322  << tree2quotedstr(label) << ')';
323  }
324  else if (isBoxAccess(box, t1, t2)) {
325  fout << boxpp(t1) << '.' << boxpp(t2);
326  }
327  else if (isImportFile(box, label)) {
328  fout << "import("
329  << tree2quotedstr(label) << ')';
330  }
331  else if (isBoxSlot(box, &id)) {
332  //fout << "#" << id;
333  fout << "x" << id;
334  }
335  else if (isBoxSymbolic(box, slot, body)) {
336  fout << "\\(" << boxpp(slot) << ").(" << boxpp(body) << ")";
337  }
338 
339  // Pattern Matching Extensions
340  else if (isBoxCase(box, rules)) {
341  fout << "case {";
342  while (!isNil(rules)) {
343  printRule(fout, hd(rules));
344  rules = tl(rules);
345  }
346  fout << "}";
347  }
348 #if 1
349  // more useful for debugging output
350  else if (isBoxPatternVar(box, ident)) {
351  fout << "<" << boxpp(ident) << ">";
352  }
353 #else
354  // beautify messages involving lhs patterns
355  else if (isBoxPatternVar(box, ident)) {
356  fout << boxpp(ident);
357  }
358 #endif
359 
360  else if (isBoxPatternMatcher(box)) {
361  fout << "PM[" << box << "]";
362  }
363 
364  else if (isBoxError(box)) {
365  fout << "ERROR";
366  }
367 
368  //else if (isImportFile(box, filename)) {
369  // printf("filename %s\n", tree2str(filename));
370  // fout << tree2quotedstr(filename);
371  //}
372 
373  // None of the previous tests succeded, then it is not a valid box
374  else {
375  cerr << "Error in box::print() : " << *box << " is not a valid box" << endl;
376  exit(1);
377  }
378 
379  return fout;
380 }
bool isBoxPrim1(Tree s)
Definition: boxes.cpp:315
bool isBoxPrim5(Tree s)
Definition: boxes.cpp:335
Tree(* prim2)(Tree x, Tree y)
Definition: boxes.hh:210
bool isBoxIPar(Tree t, Tree &x, Tree &y, Tree &z)
Definition: boxes.cpp:169
bool isBoxWire(Tree t)
Definition: boxes.cpp:109
bool isImportFile(Tree s, Tree &filename)
Definition: boxes.cpp:301
Tree box
Definition: ppbox.hh:62
const char * prim3name(CTree *(*ptr)(CTree *, CTree *, CTree *))
Definition: ppbox.cpp:76
bool isBoxSeq(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:136
bool isBoxWithLocalDef(Tree t, Tree &body, Tree &ldef)
Definition: boxes.cpp:265
bool isBoxInt(Tree t)
Definition: boxes.cpp:78
const char * prim2name(CTree *(*ptr)(CTree *, CTree *))
Definition: ppbox.cpp:47
bool isBoxIdent(Tree t)
Definition: boxes.cpp:58
bool isBoxOutputs(Tree t, Tree &x)
Definition: boxes.cpp:186
bool isBoxIProd(Tree t, Tree &x, Tree &y, Tree &z)
Definition: boxes.cpp:172
bool isBoxPatternMatcher(Tree s)
Definition: boxes.cpp:630
int tree2int(Tree t)
if t has a node of type int, return it otherwise error
Definition: tree.cpp:230
bool isBoxSplit(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:148
bool isBoxComponent(Tree s, Tree &filename)
Definition: boxes.cpp:290
Tree(* prim4)(Tree w, Tree x, Tree y, Tree z)
Definition: boxes.hh:212
bool isBoxFFun(Tree s)
Definition: boxes.cpp:344
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
bool isBoxCut(Tree t)
Definition: boxes.cpp:105
int ffarity(Tree t)
Definition: prim2.cpp:67
bool isBoxAppl(Tree t)
Definition: boxes.cpp:203
Tree hd(Tree l)
Definition: list.hh:133
int gFloatSize
Definition: main.cpp:153
bool isBoxAccess(Tree t, Tree &exp, Tree &id)
Definition: boxes.cpp:256
bool isBoxPrim0(Tree s)
Definition: boxes.cpp:310
const char * name()
Definition: xtended.hh:25
bool isBoxPrim4(Tree s)
Definition: boxes.cpp:330
bool isBoxHGroup(Tree s)
Definition: boxes.cpp:437
bool isBoxHBargraph(Tree s)
Definition: boxes.cpp:455
bool isBoxRec(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:144
double max(double x, double y)
Definition: interval.hh:60
int priority
Definition: ppbox.hh:63
Tree ffsignature(Tree ff)
Definition: prim2.cpp:40
bool isBoxAbstr(Tree t)
Definition: boxes.cpp:202
Tree(* prim3)(Tree x, Tree y, Tree z)
Definition: boxes.hh:211
bool isNil(Tree l)
Definition: list.hh:137
Tree(* prim5)(Tree v, Tree w, Tree x, Tree y, Tree z)
Definition: boxes.hh:213
const char * ffincfile(Tree ff)
Definition: prim2.cpp:45
static string type2str(int type)
Definition: ppbox.cpp:126
bool isBoxSymbolic(Tree t)
Definition: boxes.cpp:126
bool isBoxTGroup(Tree s)
Definition: boxes.cpp:449
bool isBoxISum(Tree t, Tree &x, Tree &y, Tree &z)
Definition: boxes.cpp:171
bool isBoxEnvironment(Tree s)
Definition: boxes.cpp:285
int ffrestype(Tree t)
Definition: prim2.cpp:55
bool isBoxButton(Tree s)
Definition: boxes.cpp:366
bool isBoxReal(Tree t)
Definition: boxes.cpp:79
bool isBoxCase(Tree s)
Definition: boxes.cpp:617
Tree(* prim1)(Tree x)
Definition: boxes.hh:209
static string tree2quotedstr(Tree t)
Definition: ppbox.cpp:121
bool isList(Tree l)
Definition: list.hh:138
bool isBoxPar(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:140
bool isBoxHSlider(Tree s)
Definition: boxes.cpp:379
string T(char *c)
Definition: Text.cpp:158
static void printRule(ostream &fout, Tree rule)
Definition: ppbox.cpp:103
bool isBoxVBargraph(Tree s)
Definition: boxes.cpp:461
bool isBoxWaveform(Tree s)
Definition: boxes.cpp:97
bool isClosure(Tree t, Tree &abstr, Tree &genv, Tree &vis, Tree &lenv)
Definition: boxes.cpp:239
bool isBoxCheckbox(Tree s)
Definition: boxes.cpp:372
boxpp(Tree b, int p=0)
Definition: ppbox.hh:65
static void streambinop(ostream &fout, Tree t1, const char *op, Tree t2, int curPriority, int upPriority)
Definition: ppbox.cpp:96
bool isBoxVGroup(Tree s)
Definition: boxes.cpp:443
int arity() const
return the number of branches (subtrees) of a tree
Definition: tree.hh:144
bool isBoxFVar(Tree s)
Definition: boxes.cpp:356
const char * name(Symbol *sym)
Returns the name of a symbol.
Definition: symbol.hh:98
bool isBoxVSlider(Tree s)
Definition: boxes.cpp:399
const char * fflibfile(Tree ff)
Definition: prim2.cpp:50
bool isBoxNumEntry(Tree s)
Definition: boxes.cpp:418
bool isBoxSlot(Tree t)
Definition: boxes.cpp:119
bool isBoxInputs(Tree t, Tree &x)
Definition: boxes.cpp:185
void * getUserData(Symbol *sym)
Returns user data.
Definition: symbol.hh:100
bool isBoxPrim3(Tree s)
Definition: boxes.cpp:325
bool isBoxISeq(Tree t, Tree &x, Tree &y, Tree &z)
Definition: boxes.cpp:170
bool isBoxPatternVar(Tree s, Tree &id)
Definition: boxes.cpp:622
int ffargtype(Tree t, int i)
Definition: prim2.cpp:72
const char * prim5name(CTree *(*ptr)(CTree *, CTree *, CTree *, CTree *, CTree *))
Definition: ppbox.cpp:89
Definition: ppbox.hh:75
bool isBoxError(Tree t)
Definition: boxes.cpp:249
const char * prim1name(CTree *(*ptr)(CTree *))
Definition: ppbox.cpp:39
bool isBoxMerge(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:152
bool isBoxFConst(Tree s)
Definition: boxes.cpp:350
double min(double x, double y)
Definition: interval.hh:59
bool isBoxPrim2(Tree s)
Definition: boxes.cpp:320
const char * prim0name(CTree *(*ptr)())
Definition: ppbox.cpp:34
Tree tl(Tree l)
Definition: list.hh:134
const char * tree2str(Tree t)
if t has a node of type symbol, return its name otherwise error
Definition: tree.cpp:278
Tree branch(int i) const
return the ith branch (subtree) of a tree
Definition: tree.hh:145
Tree nth(Tree l, int i)
Definition: list.cpp:182
const char * prim4name(CTree *(*ptr)(CTree *, CTree *, CTree *, CTree *))
Definition: ppbox.cpp:83
Tree(* prim0)()
Definition: boxes.hh:208

Here is the caller graph for this function:

Member Data Documentation

Tree boxpp::box
protected

Definition at line 62 of file ppbox.hh.

Referenced by print().

int boxpp::priority
protected

Definition at line 63 of file ppbox.hh.

Referenced by print().


The documentation for this class was generated from the following files: