FAUST compiler  0.9.9.6b8
boxcomplexity.cpp
Go to the documentation of this file.
1 /************************************************************************
2  ************************************************************************
3  FAUST compiler
4  Copyright (C) 2003-2004 GRAME, Centre National de Creation Musicale
5  ---------------------------------------------------------------------
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  ************************************************************************
20  ************************************************************************/
29 // construction des representations graphiques
30 
31 
32 #include <ostream>
33 #include "xtended.hh"
34 #include "boxcomplexity.h"
35 
36 using namespace std;
37 
41 Tree BCOMPLEXITY = tree ("BCOMPLEXITY");
42 
43 static int computeBoxComplexity (Tree box);
44 
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 }
69 
73 #define BC boxComplexity
74 
75 
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
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
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
Tree BCOMPLEXITY
property Key used to store box complexity
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
int boxComplexity(Tree box)
Return the complexity propety of a box expression tree.
bool isBoxPar(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:140
bool isBoxHSlider(Tree s)
Definition: boxes.cpp:379
void setProperty(Tree key, Tree value)
Definition: tree.hh:167
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
Tree tree(const Node &n)
Definition: tree.hh:186
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
Tree getProperty(Tree key)
Definition: tree.hh:173
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