File: boxcomplexity.cpp

package info (click to toggle)
faust 2.79.3%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 397,496 kB
  • sloc: cpp: 278,433; ansic: 116,164; javascript: 18,529; vhdl: 14,052; sh: 13,884; java: 5,900; objc: 3,852; python: 3,222; makefile: 2,655; cs: 1,672; lisp: 1,146; ruby: 954; yacc: 586; xml: 471; lex: 247; awk: 110; tcl: 26
file content (199 lines) | stat: -rw-r--r-- 5,590 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/************************************************************************
 ************************************************************************
    FAUST compiler
    Copyright (C) 2003-2018 GRAME, Centre National de Creation Musicale
    ---------------------------------------------------------------------
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation; either version 2.1 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 ************************************************************************
 ************************************************************************/
/**
 * @file boxcomplexity.cpp
 * Implement complexity computation for box diagrams.
 */

// Build graphical representation

#include "boxcomplexity.hh"
#include <ostream>
#include "exception.hh"
#include "global.hh"
#include "xtended.hh"

using namespace std;

static int computeBoxComplexity(Tree box);

/**
 * Return the complexity property of a box expression tree.
 * If no complexity property exist, it is created and computeBoxComplexity
 * is called do to the job.
 *
 * @param box an evaluated box expression tree
 * @return the complexity of box
 *
 * @see computeBoxComplexity
 */
int boxComplexity(Tree box)
{
    Tree prop = box->getProperty(gGlobal->BCOMPLEXITY);

    if (prop) {
        return tree2int(prop);
    } else {
        int v = computeBoxComplexity(box);
        box->setProperty(gGlobal->BCOMPLEXITY, tree(v));
        return v;
    }
}

/**
 * internal shortcut to simplify computeBoxComplexity code
 */
#define BC boxComplexity

/**
 * 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.
 *
 * @param box an evaluated box expression tree
 * @return the complexity of box
 */
static int computeBoxComplexity(Tree box)
{
    prim0 p0;
    prim1 p1;
    prim2 p2;
    prim3 p3;
    prim4 p4;
    prim5 p5;

    Tree t1, t2, t3, ff, label, cur, min, max, step, type, name, file, chan;

    xtended* xt = (xtended*)getUserData(box);

    // simple elements
    if (xt) {
        return 1;
    } else if (isBoxInt(box)) {
        return 1;
    } else if (isBoxReal(box)) {
        return 1;
    }

    else if (isBoxWaveform(box)) {
        return 1;
    }

    else if (isBoxCut(box)) {
        return 0;
    } else if (isBoxWire(box)) {
        return 0;
    }

    else if (isBoxPrim0(box, &p0)) {
        return 1;
    } else if (isBoxPrim1(box, &p1)) {
        return 1;
    } else if (isBoxPrim2(box, &p2)) {
        return 1;
    } else if (isBoxPrim3(box, &p3)) {
        return 1;
    } else if (isBoxPrim4(box, &p4)) {
        return 1;
    } else if (isBoxPrim5(box, &p5)) {
        return 1;
    }

    // foreign elements
    else if (isBoxFFun(box, ff)) {
        return 1;
    } else if (isBoxFConst(box, type, name, file)) {
        return 1;
    } else if (isBoxFVar(box, type, name, file)) {
        return 1;
    }
    // slots and symbolic boxes
    else if (isBoxSlot(box)) {
        return 1;
    } else if (isBoxSymbolic(box, t1, t2)) {
        return 1 + BC(t2);
    }

    // block diagram binary operator
    else if (isBoxSeq(box, t1, t2)) {
        return BC(t1) + BC(t2);
    } else if (isBoxSplit(box, t1, t2)) {
        return BC(t1) + BC(t2);
    } else if (isBoxMerge(box, t1, t2)) {
        return BC(t1) + BC(t2);
    } else if (isBoxPar(box, t1, t2)) {
        return BC(t1) + BC(t2);
    } else if (isBoxRec(box, t1, t2)) {
        return BC(t1) + BC(t2);
    }

    // user interface widgets
    else if (isBoxButton(box, label)) {
        return 1;
    } else if (isBoxCheckbox(box, label)) {
        return 1;
    } else if (isBoxVSlider(box, label, cur, min, max, step)) {
        return 1;
    } else if (isBoxHSlider(box, label, cur, min, max, step)) {
        return 1;
    } else if (isBoxHBargraph(box, label, min, max)) {
        return 1;
    } else if (isBoxVBargraph(box, label, min, max)) {
        return 1;
    } else if (isBoxSoundfile(box, label, chan)) {
        return 1;
    } else if (isBoxNumEntry(box, label, cur, min, max, step)) {
        return 1;
    }

    // user interface groups
    else if (isBoxVGroup(box, label, t1)) {
        return BC(t1);
    } else if (isBoxHGroup(box, label, t1)) {
        return BC(t1);
    } else if (isBoxTGroup(box, label, t1)) {
        return BC(t1);
    }

    // environment
    else if (isBoxEnvironment(box)) {
        return 0;
    } else if (isBoxMetadata(box, t1, t2)) {
        return BC(t1);
    }

    else if (isBoxRoute(box, t1, t2, t3)) {
        return 0;
    }

    // to complete
    else {
        stringstream error;
        error << "ERROR : boxComplexity, not an evaluated box [[ " << *box << " ]]\n";
        throw faustexception(error.str());
    }

    // Never reached
    return -1;
}