New directory tree, with preprocessor/ inside interpretor/.
[Faustine.git] / interpretor / preprocessor / faust-0.9.47mr3 / compiler / signals / subsignals.cpp
1 #include <signals.hh>
2 #include <property.hh>
3
4 /**
5 * Extract the sub signals of a signal expression, that is not
6 * necesseraly all the subtrees.
7 * @param sig the signals
8 * @param vsigs a reference to the vector where the subsignals will be placed
9 * @return the number of subsignals
10 */
11
12 int getSubSignals (Tree sig, vector<Tree>& vsigs, bool visitgen)
13 {
14 vsigs.clear();
15
16 int i;
17 double r;
18 Tree c, sel, x, y, z, u, v, var, le, label, id, ff, largs, type, name, file;
19
20 if ( getUserData(sig) ) { for (int i=0; i<sig->arity(); i++) { vsigs.push_back(sig->branch(i)); }
21 return sig->arity(); }
22 else if ( isSigInt(sig, &i) ) { return 0; }
23 else if ( isSigReal(sig, &r) ) { return 0; }
24 else if ( isSigInput(sig, &i) ) { return 0; }
25 else if ( isSigOutput(sig, &i, x) ) { vsigs.push_back(x); return 1; }
26
27 else if ( isSigDelay1(sig, x) ) { vsigs.push_back(x); return 1; }
28
29 else if ( isSigFixDelay(sig, x, y) ) { vsigs.push_back(x); vsigs.push_back(y); return 2; }
30 else if ( isSigPrefix(sig, x, y) ) { vsigs.push_back(x); vsigs.push_back(y); return 2; }
31 else if ( isSigIota(sig, x) ) { vsigs.push_back(x); return 1; }
32
33 else if ( isSigBinOp(sig, &i, x, y) ) { vsigs.push_back(x); vsigs.push_back(y); return 2; }
34 else if ( isSigFFun(sig, ff, largs) ) { int n = 0; while (!isNil(largs)) { vsigs.push_back(hd(largs)); largs = tl(largs); n++; } return n; }
35 else if ( isSigFConst(sig, type, name, file) ) { return 0; }
36 else if ( isSigFVar(sig, type, name, file) ) { return 0; }
37
38 else if ( isSigTable(sig, id, x, y) ) { vsigs.push_back(x); vsigs.push_back(y); return 2; }
39 else if ( isSigWRTbl(sig, id, x, y, z) ) { vsigs.push_back(x); vsigs.push_back(y); vsigs.push_back(z); return 3; }
40 else if ( isSigRDTbl(sig, x, y) ) { vsigs.push_back(x); vsigs.push_back(y); return 2; }
41
42 else if ( isSigDocConstantTbl(sig, x, y) ) { vsigs.push_back(x); vsigs.push_back(y); return 2; }
43 else if ( isSigDocWriteTbl(sig, x, y, u, v) ) { vsigs.push_back(x); vsigs.push_back(y); vsigs.push_back(u); vsigs.push_back(v); return 4; }
44 else if ( isSigDocAccessTbl(sig, x, y) ) { vsigs.push_back(x); vsigs.push_back(y); return 2; }
45
46
47 else if ( isSigSelect2(sig, sel, x, y) ) { vsigs.push_back(sel); vsigs.push_back(x); vsigs.push_back(y); return 3; }
48 else if ( isSigSelect3(sig, sel, x, y, z) ) { vsigs.push_back(sel); vsigs.push_back(x); vsigs.push_back(y); vsigs.push_back(z); return 4; }
49
50 else if ( isSigGen(sig, x) ) { if (visitgen) { vsigs.push_back(x); return 1;} else { return 0; } }
51
52 else if ( isProj(sig, &i, x) ) { vsigs.push_back(x); return 1; }
53 else if ( isRec(sig, var, le) ) { vsigs.push_back(le); return 1; }
54
55 else if ( isSigIntCast(sig, x) ) { vsigs.push_back(x); return 1; }
56 else if ( isSigFloatCast(sig, x) ) { vsigs.push_back(x); return 1; }
57
58 else if ( isSigButton(sig, label) ) { return 0; }
59 else if ( isSigCheckbox(sig, label) ) { return 0; }
60 else if ( isSigVSlider(sig, label,c,x,y,z) ) { return 0; }
61 else if ( isSigHSlider(sig, label,c,x,y,z) ) { return 0; }
62 else if ( isSigNumEntry(sig, label,c,x,y,z) ) { return 0; }
63
64 else if ( isSigVBargraph(sig, label,x,y,z) ) { vsigs.push_back(z); return 1; }
65 else if ( isSigHBargraph(sig, label,x,y,z) ) { vsigs.push_back(z); return 1; }
66 else if ( isSigAttach(sig, x, y) ) { vsigs.push_back(x); vsigs.push_back(y); return 2; }
67 else if ( isList(sig) ) { vsigs.push_back(hd(sig)); vsigs.push_back(tl(sig)); return 2; }
68 else if ( isNil(sig) ) { return 0; }
69
70 // multirate extension
71
72 else if ( isSigVectorize(sig, x, y) ) { vsigs.push_back(x); vsigs.push_back(y); return 2; }
73 else if ( isSigSerialize(sig, x) ) { vsigs.push_back(x); return 1; }
74 else if ( isSigConcat(sig, x, y) ) { vsigs.push_back(x); vsigs.push_back(y); return 2; }
75 else if ( isSigVectorAt(sig, x, y) ) { vsigs.push_back(x); vsigs.push_back(y); return 2; }
76
77 else if ( isSigUpSample(sig, x, y) ) { vsigs.push_back(x); vsigs.push_back(y); return 2; }
78 else if ( isSigDownSample(sig, x, y) ) { vsigs.push_back(x); vsigs.push_back(y); return 2; }
79
80
81 else {
82 cerr << "ERROR in getSubSignals(), unrecognized signal : " << *sig << endl;
83 exit(1);
84 }
85 return 0;
86 }