FAUST compiler  0.9.9.6b8
Macros | Functions | Variables
boxcomplexity.cpp File Reference

Implement complexity computation for box diagrams. More...

#include <ostream>
#include "xtended.hh"
#include "boxcomplexity.h"
Include dependency graph for boxcomplexity.cpp:

Go to the source code of this file.

Macros

#define BC   boxComplexity
 internal shortcut to simplify computeBoxComplexity code More...
 

Functions

static int computeBoxComplexity (Tree box)
 Compute the complexity of a box expression. More...
 
int boxComplexity (Tree box)
 Return the complexity propety of a box expression tree. More...
 

Variables

Tree BCOMPLEXITY = tree ("BCOMPLEXITY")
 property Key used to store box complexity More...
 

Detailed Description

Implement complexity computation for box diagrams.

Definition in file boxcomplexity.cpp.

Macro Definition Documentation

#define BC   boxComplexity

internal shortcut to simplify computeBoxComplexity code

Definition at line 73 of file boxcomplexity.cpp.

Referenced by computeBoxComplexity().

Function Documentation

int boxComplexity ( Tree  box)

Return the complexity propety of a box expression tree.

Return the complexity propety of a box expression tree. If no complexity property exist, it is created an computeBoxComplexity is called do to the job.

Parameters
boxan evaluated box expression tree
Returns
the complexity of box
See also
computeBoxComplexity

Definition at line 56 of file boxcomplexity.cpp.

References BCOMPLEXITY, computeBoxComplexity(), CTree::getProperty(), CTree::setProperty(), tree(), and tree2int().

Referenced by drawSchema(), and generateDiagramSchema().

57 {
58  Tree prop = box->getProperty(BCOMPLEXITY);
59 
60  if (prop) {
61  return tree2int(prop);
62 
63  } else {
64  int v = computeBoxComplexity(box);
65  box->setProperty(BCOMPLEXITY,tree(v));
66  return v;
67  }
68 }
static int computeBoxComplexity(Tree box)
Compute the complexity of a box expression.
int tree2int(Tree t)
if t has a node of type int, return it otherwise error
Definition: tree.cpp:230
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree BCOMPLEXITY
property Key used to store box complexity
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:

int computeBoxComplexity ( Tree  box)
static

Compute the complexity of a box expression.

Compute the complexity of a box expression tree according to the complexity of its subexpressions. Basically it counts the number of boxes to be drawn. The box-diagram expression is supposed to be evaluated. It will exit with an error if it is not the case.

Parameters
boxan evaluated box expression tree
Returns
the complexity of box

Definition at line 87 of file boxcomplexity.cpp.

References BC, getUserData(), isBoxButton(), isBoxCheckbox(), isBoxCut(), isBoxFConst(), isBoxFFun(), isBoxFVar(), isBoxHBargraph(), isBoxHGroup(), isBoxHSlider(), isBoxInt(), isBoxMerge(), isBoxNumEntry(), isBoxPar(), isBoxPrim0(), isBoxPrim1(), isBoxPrim2(), isBoxPrim3(), isBoxPrim4(), isBoxPrim5(), isBoxReal(), isBoxRec(), isBoxSeq(), isBoxSlot(), isBoxSplit(), isBoxSymbolic(), isBoxTGroup(), isBoxVBargraph(), isBoxVGroup(), isBoxVSlider(), isBoxWaveform(), isBoxWire(), max(), min(), and name().

Referenced by boxComplexity().

88 {
89  int i;
90  double r;
91  prim0 p0;
92  prim1 p1;
93  prim2 p2;
94  prim3 p3;
95  prim4 p4;
96  prim5 p5;
97 
98  Tree t1, t2, ff, label, cur, min, max, step, type, name, file;
99 
100  xtended* xt = (xtended*) getUserData(box);
101 
102 
103  // simple elements
104  if (xt) return 1;
105  else if (isBoxInt(box, &i)) return 1;
106  else if (isBoxReal(box, &r)) return 1;
107 
108  else if (isBoxWaveform(box)) return 1;
109 
110  else if (isBoxCut(box)) return 0;
111  else if (isBoxWire(box)) return 0;
112 
113  else if (isBoxPrim0(box, &p0)) return 1;
114  else if (isBoxPrim1(box, &p1)) return 1;
115  else if (isBoxPrim2(box, &p2)) return 1;
116  else if (isBoxPrim3(box, &p3)) return 1;
117  else if (isBoxPrim4(box, &p4)) return 1;
118  else if (isBoxPrim5(box, &p5)) return 1;
119 
120  // foreign elements
121  else if (isBoxFFun(box, ff)) return 1;
122  else if (isBoxFConst(box, type, name, file))
123  return 1;
124  else if (isBoxFVar(box, type, name, file))
125  return 1;
126  // slots and symbolic boxes
127  else if (isBoxSlot(box, &i)) return 1;
128  else if (isBoxSymbolic(box,t1,t2)) return 1 + BC(t2);
129 
130  // block diagram binary operator
131  else if (isBoxSeq(box, t1, t2)) return BC(t1) + BC(t2);
132  else if (isBoxSplit(box, t1, t2)) return BC(t1) + BC(t2);
133  else if (isBoxMerge(box, t1, t2)) return BC(t1) + BC(t2);
134  else if (isBoxPar(box, t1, t2)) return BC(t1) + BC(t2);
135  else if (isBoxRec(box, t1, t2)) return BC(t1) + BC(t2);
136 
137  // user interface widgets
138  else if (isBoxButton(box, label)) return 1;
139  else if (isBoxCheckbox(box, label)) return 1;
140  else if (isBoxVSlider(box, label, cur, min, max, step)) return 1;
141  else if (isBoxHSlider(box, label, cur, min, max, step)) return 1;
142  else if (isBoxHBargraph(box, label, min, max)) return 1;
143  else if (isBoxVBargraph(box, label, min, max)) return 1;
144  else if (isBoxNumEntry(box, label, cur, min, max, step))return 1;
145 
146  // user interface groups
147  else if (isBoxVGroup(box, label, t1)) return BC(t1);
148  else if (isBoxHGroup(box, label, t1)) return BC(t1);
149  else if (isBoxTGroup(box, label, t1)) return BC(t1);
150 
151  //a completer
152  else {
153  //fout << tree2str(box);
154  cerr << "ERROR in boxComplexity : not an evaluated box [[ " << *box << " ]]";
155  exit(-1);
156  }
157 
158  return -1;
159 }
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 isBoxWire(Tree t)
Definition: boxes.cpp:109
bool isBoxSeq(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:136
bool isBoxInt(Tree t)
Definition: boxes.cpp:78
bool isBoxSplit(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:148
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
bool isBoxPrim0(Tree s)
Definition: boxes.cpp:310
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
Tree(* prim3)(Tree x, Tree y, Tree z)
Definition: boxes.hh:211
Tree(* prim5)(Tree v, Tree w, Tree x, Tree y, Tree z)
Definition: boxes.hh:213
bool isBoxSymbolic(Tree t)
Definition: boxes.cpp:126
bool isBoxTGroup(Tree s)
Definition: boxes.cpp:449
bool isBoxButton(Tree s)
Definition: boxes.cpp:366
bool isBoxReal(Tree t)
Definition: boxes.cpp:79
Tree(* prim1)(Tree x)
Definition: boxes.hh:209
bool isBoxPar(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:140
bool isBoxHSlider(Tree s)
Definition: boxes.cpp:379
bool isBoxVBargraph(Tree s)
Definition: boxes.cpp:461
bool isBoxWaveform(Tree s)
Definition: boxes.cpp:97
bool isBoxCheckbox(Tree s)
Definition: boxes.cpp:372
#define BC
internal shortcut to simplify computeBoxComplexity code
bool isBoxVGroup(Tree s)
Definition: boxes.cpp:443
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
bool isBoxNumEntry(Tree s)
Definition: boxes.cpp:418
bool isBoxSlot(Tree t)
Definition: boxes.cpp:119
void * getUserData(Symbol *sym)
Returns user data.
Definition: symbol.hh:100
bool isBoxPrim3(Tree s)
Definition: boxes.cpp:325
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
Tree(* prim0)()
Definition: boxes.hh:208

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

Tree BCOMPLEXITY = tree ("BCOMPLEXITY")

property Key used to store box complexity

Definition at line 41 of file boxcomplexity.cpp.

Referenced by boxComplexity().