46275b3fda66f8712864539eb4b344722e54e380
1 /************************************************************************
2 ************************************************************************
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.
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.
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 ************************************************************************/
28 #include "recursivness.hh"
30 ostream
& ppsig::printinfix (ostream
& fout
, const string
& opname
, int priority
, Tree x
, Tree y
) const
32 if (fPriority
> priority
) fout
<< "(";
33 fout
<< ppsig(x
,fEnv
,priority
) << opname
<< ppsig(y
,fEnv
,priority
);
34 if (fPriority
> priority
) fout
<< ")";
38 ostream
& ppsig::printfun (ostream
& fout
, const string
& funame
, Tree x
) const
40 return fout
<< funame
<< '(' << ppsig(x
,fEnv
) << ')';
43 ostream
& ppsig::printfun (ostream
& fout
, const string
& funame
, Tree x
, Tree y
) const
45 return fout
<< funame
<< '(' << ppsig(x
,fEnv
) << ',' << ppsig(y
,fEnv
) << ')';
48 ostream
& ppsig::printfun (ostream
& fout
, const string
& funame
, Tree x
, Tree y
, Tree z
) const
50 return fout
<< funame
<< '(' << ppsig(x
,fEnv
) << ',' << ppsig(y
,fEnv
) << ',' << ppsig(z
,fEnv
) << ')';
53 ostream
& ppsig::printfun (ostream
& fout
, const string
& funame
, Tree x
, Tree y
, Tree z
, Tree zz
) const
55 return fout
<< funame
<< '(' << ppsig(x
,fEnv
) << ',' << ppsig(y
,fEnv
) << ',' << ppsig(z
,fEnv
) << ',' << ppsig(zz
,fEnv
) << ')';
58 ostream
& ppsig::printfun (ostream
& fout
, const string
& funame
, Tree x
, Tree y
, Tree z
, Tree z2
, Tree z3
) const
60 return fout
<< funame
<< '(' << ppsig(x
,fEnv
) << ',' << ppsig(y
,fEnv
) << ',' << ppsig(z
,fEnv
) << ',' << ppsig(z2
,fEnv
) << ',' << ppsig(z3
,fEnv
) << ')';
63 ostream
& ppsig::printui (ostream
& fout
, const string
& funame
, Tree label
) const
65 fout
<< funame
<< '(';
66 printlabel(fout
, label
);
70 ostream
& ppsig::printui (ostream
& fout
, const string
& funame
, Tree label
, Tree lo
, Tree hi
, Tree step
) const
72 fout
<< funame
<< '(';
73 printlabel(fout
, label
);
75 << ',' << ppsig(lo
,fEnv
)
76 << ',' << ppsig(hi
,fEnv
)
77 << ',' << ppsig(step
,fEnv
)
81 ostream
& ppsig::printui (ostream
& fout
, const string
& funame
, Tree label
, Tree cur
, Tree lo
, Tree hi
, Tree step
) const
83 fout
<< funame
<< '(';
84 printlabel(fout
, label
);
86 << ',' << ppsig(cur
,fEnv
)
87 << ',' << ppsig(lo
,fEnv
)
88 << ',' << ppsig(hi
,fEnv
)
89 << ',' << ppsig(step
,fEnv
)
93 ostream
& ppsig::printout (ostream
& fout
, int i
, Tree x
) const
95 if (fPriority
> 0) fout
<< "(";
96 fout
<< "OUT" << i
<< " = " << ppsig(x
, fEnv
, 0);
97 if (fPriority
> 0) fout
<< ")";
101 ostream
& ppsig::printlabel (ostream
& fout
, Tree pathname
) const
103 fout
<< *hd(pathname
);
104 pathname
= tl(pathname
);
105 while (!isNil(pathname
)) {
106 fout
<< '/' << *tl(hd(pathname
));
107 pathname
= tl(pathname
);
112 ostream
& ppsig::printlist (ostream
& fout
, Tree largs
) const
116 while (!isNil(largs
)) {
117 fout
<< sep
<< ppsig(hd(largs
), fEnv
);
125 ostream
& ppsig::printff (ostream
& fout
, Tree ff
, Tree largs
) const
127 fout
<< ffname(ff
); printlist(fout
, largs
);
131 ostream
& ppsig::printFixDelay (ostream
& fout
, Tree exp
, Tree delay
) const
135 if (isSigInt(delay
, &d
) && (d
==1)) {
136 fout
<< ppsig(exp
,fEnv
,8) << "'";
138 printinfix(fout
, "@", 8, exp
, delay
);
143 // else if ( isSigFixDelay(sig, x, y) ) { printinfix(fout, "@", 8, x, y); }
145 ostream
& ppsig::printrec (ostream
& fout
, Tree var
, Tree lexp
, bool hide
) const
147 if (isElement(var
, fEnv
) ) {
152 fout
<< "letrec(" << *var
<< " = " << ppsig(lexp
, addElement(var
, fEnv
)) << ")";
157 ostream
& ppsig::printrec (ostream
& fout
, Tree lexp
, bool hide
) const
159 fout
<< "debruijn(" << ppsig(lexp
,fEnv
) << ")";
163 ostream
& ppsig::printextended (ostream
& fout
, Tree sig
) const
166 xtended
* p
= (xtended
*) getUserData(sig
);
168 fout
<< p
->name() << '(';
169 for (int i
= 0; i
< sig
->arity(); i
++) {
170 fout
<< sep
<< ppsig(sig
->branch(i
), fEnv
);
178 ostream
& ppsig::print (ostream
& fout
) const
182 Tree c
, sel
, x
, y
, z
, u
, var
, le
, label
, id
, ff
, largs
, type
, name
, file
;
184 if ( isList(sig
) ) { printlist(fout
, sig
); }
185 else if ( isProj(sig
, &i
, x
) ) { fout
<< "proj" << i
<< '(' << ppsig(x
, fEnv
) << ')'; }
186 else if ( isRec(sig
, var
, le
) ) { printrec(fout
, var
, le
, fHideRecursion
/*&& (getRecursivness(sig)==0)*/ ); }
189 else if ( isRec(sig
, le
) ) { printrec(fout
, le
, fHideRecursion
); }
190 else if ( isRef(sig
, i
) ) { fout
<< "REF[" << i
<< "]"; }
192 else if ( getUserData(sig
) ) { printextended(fout
, sig
); }
193 else if ( isSigInt(sig
, &i
) ) { fout
<< i
; }
194 else if ( isSigReal(sig
, &r
) ) { fout
<< r
; }
195 else if ( isSigInput(sig
, &i
) ) { fout
<< "IN[" << i
<< "]"; }
196 else if ( isSigOutput(sig
, &i
, x
) ) { printout(fout
, i
, x
) ; }
198 else if ( isSigDelay1(sig
, x
) ) { fout
<< ppsig(x
, fEnv
, 9) << "'"; }
199 //else if ( isSigFixDelay(sig, x, y) ) { printinfix(fout, "@", 8, x, y); }
200 else if ( isSigFixDelay(sig
, x
, y
) ) { printFixDelay(fout
, x
, y
); }
201 else if ( isSigPrefix(sig
, x
, y
) ) { printfun(fout
, "prefix", x
, y
); }
202 else if ( isSigIota(sig
, x
) ) { printfun(fout
, "iota", x
); }
203 else if ( isSigBinOp(sig
, &i
, x
, y
) ) { printinfix(fout
, gBinOpTable
[i
]->fName
, gBinOpTable
[i
]->fPriority
, x
, y
); }
204 else if ( isSigFFun(sig
, ff
, largs
) ) { printff(fout
, ff
, largs
); }
205 else if ( isSigFConst(sig
, type
, name
, file
) ) { fout
<< tree2str(name
); }
206 else if ( isSigFVar(sig
, type
, name
, file
) ) { fout
<< tree2str(name
); }
208 else if ( isSigTable(sig
, id
, x
, y
) ) { printfun(fout
, "TABLE", x
, y
); }
209 else if ( isSigWRTbl(sig
, id
, x
, y
, z
) ) { printfun(fout
, "write", x
, y
, z
); }
210 else if ( isSigRDTbl(sig
, x
, y
) ) { printfun(fout
, "read", x
, y
); }
211 else if ( isSigGen(sig
, x
) ) { fout
<< ppsig(x
, fEnv
, fPriority
); }
213 else if ( isSigDocConstantTbl(sig
, x
, y
) ) { printfun(fout
, "docConstantTbl", x
, y
); }
214 else if ( isSigDocWriteTbl(sig
, x
, y
, z
, u
) ) { printfun(fout
, "docWriteTbl", x
, y
, z
, u
); }
215 else if ( isSigDocAccessTbl(sig
, x
, y
) ) { printfun(fout
, "docAccessTbl", x
, y
); }
217 else if ( isSigSelect2(sig
, sel
, x
, y
) ) { printfun(fout
, "select2", sel
, x
, y
); }
218 else if ( isSigSelect3(sig
, sel
, x
, y
, z
) ) { printfun(fout
, "select3", sel
, x
, y
, z
); }
220 else if ( isSigIntCast(sig
, x
) ) { printfun(fout
, "int", x
); }
221 else if ( isSigFloatCast(sig
, x
) ) { printfun(fout
, "float", x
); }
223 else if ( isSigButton(sig
, label
) ) { printui(fout
, "button", label
); }
224 else if ( isSigCheckbox(sig
, label
) ) { printui(fout
, "checkbox", label
); }
225 else if ( isSigVSlider(sig
, label
,c
,x
,y
,z
) ) { printui(fout
, "vslider", label
, c
, x
, y
, z
); }
226 else if ( isSigHSlider(sig
, label
,c
,x
,y
,z
) ) { printui(fout
, "hslider", label
, c
, x
, y
, z
); }
227 else if ( isSigNumEntry(sig
, label
,c
,x
,y
,z
) ) { printui(fout
, "nentry", label
, c
, x
, y
, z
); }
228 else if ( isSigVBargraph(sig
, label
,x
,y
,z
) ) { printui(fout
, "vbargraph", label
, x
, y
, z
); }
229 else if ( isSigHBargraph(sig
, label
,x
,y
,z
) ) { printui(fout
, "hbargraph", label
, x
, y
, z
); }
230 else if ( isSigAttach(sig
, x
, y
) ) { printfun(fout
, "attach", x
, y
); }
232 else if ( isSigVectorize(sig
,x
,y
)) { printfun(fout
, "vectorize", x
, y
); }
233 else if ( isSigSerialize(sig
,x
)) { printfun(fout
, "serialize", x
); }
234 else if ( isSigVectorAt(sig
,x
,y
)) { printfun(fout
, "vectorAt", x
, y
); }
235 else if ( isSigConcat(sig
,x
,y
)) { printfun(fout
, "concat", x
, y
); }
237 else if ( isSigUpSample(sig
,x
,y
)) { printfun(fout
, "up", x
, y
); }
238 else if ( isSigDownSample(sig
,x
,y
)) { printfun(fout
, "down", x
, y
); }
241 cerr
<< "NOT A SIGNAL : " << *sig
<< endl
;