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 ************************************************************************/
32 const char * prim0name(CTree
*(*ptr
) ())
37 const char * prim1name(CTree
*(*ptr
) (CTree
*))
39 if (ptr
== sigDelay1
) return "mem";
40 if (ptr
== sigIntCast
) return "int";
41 if (ptr
== sigFloatCast
) return "float";
42 if (ptr
== sigSerialize
) return "serialize";
47 const char * prim2name(CTree
*(*ptr
) (CTree
*, CTree
*))
49 if (ptr
== sigAdd
) return "+";
50 if (ptr
== sigSub
) return "-";
51 if (ptr
== sigMul
) return "*";
52 if (ptr
== sigDiv
) return "/";
53 if (ptr
== sigRem
) return "%";
55 if (ptr
== sigAND
) return "&";
56 if (ptr
== sigOR
) return "|";
57 if (ptr
== sigXOR
) return "^";
59 if (ptr
== sigLeftShift
) return "<<";
60 if (ptr
== sigRightShift
) return ">>";
62 if (ptr
== sigLT
) return "< ";
63 if (ptr
== sigLE
) return "<=";
64 if (ptr
== sigGT
) return " >";
65 if (ptr
== sigGE
) return ">=";
66 if (ptr
== sigEQ
) return "==";
67 if (ptr
== sigNE
) return "!=";
69 if (ptr
== sigFixDelay
) return "@";
70 if (ptr
== sigPrefix
) return "prefix";
71 if (ptr
== sigAttach
) return "attach";
73 if (ptr
== sigVectorize
) return "vectorize";
74 if (ptr
== sigVectorAt
) return "[]";
75 if (ptr
== sigConcat
) return "#";
83 const char * prim3name(CTree
*(*ptr
) (CTree
*, CTree
*, CTree
*))
85 if (ptr
== sigReadOnlyTable
) return "rdtable";
86 if (ptr
== sigSelect2
) return "selecttwo";
90 const char * prim4name(CTree
*(*ptr
) (CTree
*, CTree
*, CTree
*, CTree
*))
92 if (ptr
== sigSelect3
) return "selectthree";
96 const char * prim5name(CTree
*(*ptr
) (CTree
*, CTree
*, CTree
*, CTree
*, CTree
*))
98 if (ptr
== sigWriteReadTable
) return "wrtable";
103 static void streambinop(ostream
& fout
, Tree t1
, const char* op
, Tree t2
, int curPriority
, int upPriority
)
105 if (upPriority
> curPriority
) fout
<< '(';
106 fout
<< boxpp(t1
,curPriority
) << op
<< boxpp(t2
,curPriority
);
107 if (upPriority
> curPriority
) fout
<< ')';
110 static void printRule(ostream
& fout
, Tree rule
)
112 Tree lhs
= left(rule
);
113 Tree rhs
= right(rule
);
114 char sep
= '('; while (!isNil(lhs
)) { fout
<< sep
<< boxpp(hd(lhs
)); sep
=','; lhs
=tl(lhs
); }
115 fout
<< ") => " << boxpp(rhs
) << "; ";
118 /*****************************************************************************
119 affichage d'une expression box comme en entree
120 *****************************************************************************/
122 ostream
& boxpp::print (ostream
& fout
) const
133 Tree t1
, t2
, t3
, ff
, label
, cur
, min
, max
, step
, type
, name
, file
, arg
,
134 body
, fun
, args
, abstr
, genv
, vis
, lenv
, ldef
, slot
,
139 xtended
* xt
= (xtended
*) getUserData(box
);
142 // primitive elements
143 if (xt
) fout
<< xt
->name();
144 else if (isBoxInt(box
, &i
)) fout
<< i
;
145 else if (isBoxReal(box
, &r
))
147 fout
.setf( ios_base::fixed
);
150 //fout.setf( ios_base::fixed);
153 else if (isBoxCut(box
)) fout
<< '!';
154 else if (isBoxWire(box
)) fout
<< '_';
155 else if (isBoxIdent(box
, &str
)) fout
<< str
;
156 else if (isBoxPrim0(box
, &p0
)) fout
<< prim0name(p0
);
157 else if (isBoxPrim1(box
, &p1
)) fout
<< prim1name(p1
);
158 else if (isBoxPrim2(box
, &p2
)) fout
<< prim2name(p2
);
159 else if (isBoxPrim3(box
, &p3
)) fout
<< prim3name(p3
);
160 else if (isBoxPrim4(box
, &p4
)) fout
<< prim4name(p4
);
161 else if (isBoxPrim5(box
, &p5
)) fout
<< prim5name(p5
);
163 else if (isBoxAbstr(box
,arg
,body
)) fout
<< "\\" << boxpp(arg
) << ".(" << boxpp(body
) << ")";
164 else if (isBoxAppl(box
, fun
, args
)) fout
<< boxpp(fun
) << boxpp(args
) ;
166 else if (isBoxWithLocalDef(box
, body
, ldef
)) fout
<< boxpp(body
) << " with { " << envpp(ldef
) << " }";
169 else if (isBoxFFun(box
, ff
)) fout
<< "ffunction(" << ffname(ff
) << ')';
170 else if (isBoxFConst(box
, type
, name
, file
))
171 fout
<< "fconstant(" /*<< tree2str(type) */<< tree2str(name
) << ')';
172 else if (isBoxFVar(box
, type
, name
, file
))
173 fout
<< "fvariable(" << tree2str(name
) << ')';
175 // block diagram binary operator
176 else if (isBoxSeq(box
, t1
, t2
)) streambinop(fout
, t1
, ":", t2
, 1, priority
);
177 else if (isBoxSplit(box
, t1
, t2
)) streambinop(fout
, t1
, "<:", t2
, 1, priority
);
178 else if (isBoxMerge(box
, t1
, t2
)) streambinop(fout
, t1
, ":>", t2
, 1, priority
);
179 else if (isBoxPar(box
, t1
, t2
)) streambinop(fout
, t1
,",",t2
, 2, priority
);
180 else if (isBoxRec(box
, t1
, t2
)) streambinop(fout
, t1
,"~",t2
, 4, priority
);
182 // iterative block diagram construction
183 else if (isBoxIPar(box
, t1
, t2
, t3
)) fout
<< "par(" << boxpp(t1
) << ", " << boxpp(t2
) << ") {" << boxpp(t3
) << "}";
184 else if (isBoxISeq(box
, t1
, t2
, t3
)) fout
<< "seq(" << boxpp(t1
) << ", " << boxpp(t2
) << ") {" << boxpp(t3
) << "}";
185 else if (isBoxISum(box
, t1
, t2
, t3
)) fout
<< "sum(" << boxpp(t1
) << ", " << boxpp(t2
) << ") {" << boxpp(t3
) << "}";
186 else if (isBoxIProd(box
, t1
, t2
, t3
)) fout
<< "prod(" << boxpp(t1
) << ", " << boxpp(t2
) << ") {" << boxpp(t3
) << "}";
189 else if (isBoxButton(box
, label
)) fout
<< "button(" << tree2str(label
) << ')';
190 else if (isBoxCheckbox(box
, label
)) fout
<< "checkbox(" << tree2str(label
) << ')';
191 else if (isBoxVSlider(box
, label
, cur
, min
, max
, step
)) {
193 << tree2str(label
) << ", "
194 << boxpp(cur
) << ", "
195 << boxpp(min
) << ", "
196 << boxpp(max
) << ", "
197 << boxpp(step
)<< ')';
199 else if (isBoxHSlider(box
, label
, cur
, min
, max
, step
)) {
201 << tree2str(label
) << ", "
202 << boxpp(cur
) << ", "
203 << boxpp(min
) << ", "
204 << boxpp(max
) << ", "
205 << boxpp(step
)<< ')';
207 else if (isBoxVGroup(box
, label
, t1
)) {
208 fout
<< "vgroup(" << tree2str(label
) << ", " << boxpp(t1
, 0) << ')';
210 else if (isBoxHGroup(box
, label
, t1
)) {
211 fout
<< "hgroup(" << tree2str(label
) << ", " << boxpp(t1
, 0) << ')';
213 else if (isBoxTGroup(box
, label
, t1
)) {
214 fout
<< "tgroup(" << tree2str(label
) << ", " << boxpp(t1
, 0) << ')';
216 else if (isBoxHBargraph(box
, label
, min
, max
)) {
218 << tree2str(label
) << ", "
219 << boxpp(min
) << ", "
220 << boxpp(max
) << ')';
222 else if (isBoxVBargraph(box
, label
, min
, max
)) {
224 << tree2str(label
) << ", "
225 << boxpp(min
) << ", "
226 << boxpp(max
) << ')';
228 else if (isBoxNumEntry(box
, label
, cur
, min
, max
, step
)) {
230 << tree2str(label
) << ", "
231 << boxpp(cur
) << ", "
232 << boxpp(min
) << ", "
233 << boxpp(max
) << ", "
234 << boxpp(step
)<< ')';
236 else if (isNil(box
)) {
239 else if (isList(box
)) {
245 fout
<< sep
<< boxpp(hd(l
));
253 else if (isBoxEnvironment(box
)) {
254 fout
<< "environment";
256 else if (isClosure(box
, abstr
, genv
, vis
, lenv
)) {
257 fout
<< "closure[" << boxpp(abstr
)
258 << ", genv = " << envpp(genv
)
259 << ", lenv = " << envpp(lenv
)
262 else if (isBoxComponent(box
, label
)) {
264 << tree2str(label
) << ')';
266 else if (isBoxAccess(box
, t1
, t2
)) {
267 fout
<< boxpp(t1
) << '.' << boxpp(t2
);
269 else if (isImportFile(box
, label
)) {
271 << tree2str(label
) << ')';
273 else if (isBoxSlot(box
, &id
)) {
276 else if (isBoxSymbolic(box
, slot
, body
)) {
277 fout
<< "[" << boxpp(slot
) << ">" << boxpp(body
) << "]";
280 // Pattern Matching Extensions
281 else if (isBoxCase(box
, rules
)) {
283 while (!isNil(rules
)) { printRule(fout
, hd(rules
)); rules
= tl(rules
); }
287 // more useful for debugging output
288 else if (isBoxPatternVar(box
, ident
)) {
289 fout
<< "<" << boxpp(ident
) << ">";
292 // beautify messages involving lhs patterns
293 else if (isBoxPatternVar(box
, ident
)) {
294 fout
<< boxpp(ident
);
298 else if (isBoxPatternMatcher(box
)) {
299 fout
<< "PM[" << box
<< "]";
302 else if (isBoxError(box
)) {
307 // None of the previous tests succeded, then it is not a valid box
309 cerr
<< "Error in box::print() : " << *box
<< " is not a valid box" << endl
;
317 /*****************************************************************************
318 affichage d'un environnement
319 *****************************************************************************/
321 ostream
& envpp::print (ostream
& fout
) const
323 const char* sep
= "";
328 fout
<< sep
<< boxpp(hd(hd(l
))) << "=" << boxpp(tl(hd(l
)));