1 | // -*- c-basic-offset: 2 -*-
|
---|
2 | /*
|
---|
3 | * This file is part of the KDE libraries
|
---|
4 | * Copyright (C) 2002 Harri Porten ([email protected])
|
---|
5 | * Copyright (C) 2003 Apple Computer, Inc.
|
---|
6 | *
|
---|
7 | * This library is free software; you can redistribute it and/or
|
---|
8 | * modify it under the terms of the GNU Library General Public
|
---|
9 | * License as published by the Free Software Foundation; either
|
---|
10 | * version 2 of the License, or (at your option) any later version.
|
---|
11 | *
|
---|
12 | * This library is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
15 | * Library General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU Library General Public License
|
---|
18 | * along with this library; see the file COPYING.LIB. If not, write to
|
---|
19 | * the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
|
---|
20 | * Boston, MA 02110-1301, USA.
|
---|
21 | *
|
---|
22 | */
|
---|
23 |
|
---|
24 | #include "nodes.h"
|
---|
25 |
|
---|
26 | namespace KJS {
|
---|
27 | /**
|
---|
28 | * A simple text streaming class that helps with code indentation.
|
---|
29 | */
|
---|
30 | class SourceStream {
|
---|
31 | public:
|
---|
32 | enum Format {
|
---|
33 | Endl, Indent, Unindent
|
---|
34 | };
|
---|
35 |
|
---|
36 | UString toString() const { return str; }
|
---|
37 | SourceStream& operator<<(const Identifier &);
|
---|
38 | SourceStream& operator<<(const UString &);
|
---|
39 | SourceStream& operator<<(const char *);
|
---|
40 | SourceStream& operator<<(char);
|
---|
41 | SourceStream& operator<<(Format f);
|
---|
42 | SourceStream& operator<<(const Node *);
|
---|
43 | private:
|
---|
44 | UString str; /* TODO: buffer */
|
---|
45 | UString ind;
|
---|
46 | };
|
---|
47 | };
|
---|
48 |
|
---|
49 | using namespace KJS;
|
---|
50 |
|
---|
51 | SourceStream& SourceStream::operator<<(char c)
|
---|
52 | {
|
---|
53 | str += UString(c);
|
---|
54 | return *this;
|
---|
55 | }
|
---|
56 |
|
---|
57 | SourceStream& SourceStream::operator<<(const char *s)
|
---|
58 | {
|
---|
59 | str += UString(s);
|
---|
60 | return *this;
|
---|
61 | }
|
---|
62 |
|
---|
63 | SourceStream& SourceStream::operator<<(const UString &s)
|
---|
64 | {
|
---|
65 | str += s;
|
---|
66 | return *this;
|
---|
67 | }
|
---|
68 |
|
---|
69 | SourceStream& SourceStream::operator<<(const Identifier &s)
|
---|
70 | {
|
---|
71 | str += s.ustring();
|
---|
72 | return *this;
|
---|
73 | }
|
---|
74 |
|
---|
75 | SourceStream& SourceStream::operator<<(const Node *n)
|
---|
76 | {
|
---|
77 | if (n)
|
---|
78 | n->streamTo(*this);
|
---|
79 | return *this;
|
---|
80 | }
|
---|
81 |
|
---|
82 | SourceStream& SourceStream::operator<<(Format f)
|
---|
83 | {
|
---|
84 | switch (f) {
|
---|
85 | case Endl:
|
---|
86 | str += "\n" + ind;
|
---|
87 | break;
|
---|
88 | case Indent:
|
---|
89 | ind += " ";
|
---|
90 | break;
|
---|
91 | case Unindent:
|
---|
92 | ind = ind.substr(0, ind.size() - 2);
|
---|
93 | break;
|
---|
94 | }
|
---|
95 |
|
---|
96 | return *this;
|
---|
97 | }
|
---|
98 |
|
---|
99 | UString Node::toString() const
|
---|
100 | {
|
---|
101 | SourceStream str;
|
---|
102 | streamTo(str);
|
---|
103 |
|
---|
104 | return str.toString();
|
---|
105 | }
|
---|
106 |
|
---|
107 | void NullNode::streamTo(SourceStream &s) const { s << "null"; }
|
---|
108 |
|
---|
109 | void BooleanNode::streamTo(SourceStream &s) const
|
---|
110 | {
|
---|
111 | s << (value ? "true" : "false");
|
---|
112 | }
|
---|
113 |
|
---|
114 | void NumberNode::streamTo(SourceStream &s) const { s << UString::from(value); }
|
---|
115 |
|
---|
116 | void StringNode::streamTo(SourceStream &s) const
|
---|
117 | {
|
---|
118 | s << '"' << value << '"';
|
---|
119 | }
|
---|
120 |
|
---|
121 | void RegExpNode::streamTo(SourceStream &s) const { s << pattern; }
|
---|
122 |
|
---|
123 | void ThisNode::streamTo(SourceStream &s) const { s << "this"; }
|
---|
124 |
|
---|
125 | void ResolveNode::streamTo(SourceStream &s) const { s << ident; }
|
---|
126 |
|
---|
127 | void GroupNode::streamTo(SourceStream &s) const
|
---|
128 | {
|
---|
129 | s << "(" << group << ")";
|
---|
130 | }
|
---|
131 |
|
---|
132 | void ElementNode::streamTo(SourceStream &s) const
|
---|
133 | {
|
---|
134 | for (const ElementNode *n = this; n; n = n->list) {
|
---|
135 | for (int i = 0; i < n->elision; i++)
|
---|
136 | s << ",";
|
---|
137 | s << n->node;
|
---|
138 | }
|
---|
139 | }
|
---|
140 |
|
---|
141 | void ArrayNode::streamTo(SourceStream &s) const
|
---|
142 | {
|
---|
143 | s << "[" << element;
|
---|
144 | for (int i = 0; i < elision; i++)
|
---|
145 | s << ",";
|
---|
146 | s << "]";
|
---|
147 | }
|
---|
148 |
|
---|
149 | void ObjectLiteralNode::streamTo(SourceStream &s) const
|
---|
150 | {
|
---|
151 | if (list)
|
---|
152 | s << "{ " << list << " }";
|
---|
153 | else
|
---|
154 | s << "{ }";
|
---|
155 | }
|
---|
156 |
|
---|
157 | void PropertyValueNode::streamTo(SourceStream &s) const
|
---|
158 | {
|
---|
159 | for (const PropertyValueNode *n = this; n; n = n->list)
|
---|
160 | s << n->name << ": " << n->assign;
|
---|
161 | }
|
---|
162 |
|
---|
163 | void PropertyNode::streamTo(SourceStream &s) const
|
---|
164 | {
|
---|
165 | if (str.isNull())
|
---|
166 | s << UString::from(numeric);
|
---|
167 | else
|
---|
168 | s << str;
|
---|
169 | }
|
---|
170 |
|
---|
171 | void BracketAccessorNode::streamTo(SourceStream &s) const
|
---|
172 | {
|
---|
173 | s << expr1 << "[" << expr2 << "]";
|
---|
174 | }
|
---|
175 |
|
---|
176 | void DotAccessorNode::streamTo(SourceStream &s) const
|
---|
177 | {
|
---|
178 | s << expr << "." << ident;
|
---|
179 | }
|
---|
180 |
|
---|
181 | void ArgumentListNode::streamTo(SourceStream &s) const
|
---|
182 | {
|
---|
183 | s << expr;
|
---|
184 | for (ArgumentListNode *n = list; n; n = n->list)
|
---|
185 | s << ", " << n->expr;
|
---|
186 | }
|
---|
187 |
|
---|
188 | void ArgumentsNode::streamTo(SourceStream &s) const
|
---|
189 | {
|
---|
190 | s << "(" << list << ")";
|
---|
191 | }
|
---|
192 |
|
---|
193 | void NewExprNode::streamTo(SourceStream &s) const
|
---|
194 | {
|
---|
195 | s << "new " << expr << args;
|
---|
196 | }
|
---|
197 |
|
---|
198 | void FunctionCallValueNode::streamTo(SourceStream &s) const
|
---|
199 | {
|
---|
200 | s << expr << args;
|
---|
201 | }
|
---|
202 |
|
---|
203 | void FunctionCallResolveNode::streamTo(SourceStream &s) const
|
---|
204 | {
|
---|
205 | s << ident << args;
|
---|
206 | }
|
---|
207 |
|
---|
208 | void FunctionCallBracketNode::streamTo(SourceStream &s) const
|
---|
209 | {
|
---|
210 | s << base << "[" << subscript << "]" << args;
|
---|
211 | }
|
---|
212 |
|
---|
213 | void FunctionCallParenBracketNode::streamTo(SourceStream &s) const
|
---|
214 | {
|
---|
215 | s << "(" << base << "[" << subscript << "])" << args;
|
---|
216 | }
|
---|
217 |
|
---|
218 | void FunctionCallDotNode::streamTo(SourceStream &s) const
|
---|
219 | {
|
---|
220 | s << base << "." << ident << args;
|
---|
221 | }
|
---|
222 |
|
---|
223 | void FunctionCallParenDotNode::streamTo(SourceStream &s) const
|
---|
224 | {
|
---|
225 | s << "(" << base << "." << ident << ")" << args;
|
---|
226 | }
|
---|
227 |
|
---|
228 | void PostfixNode::streamTo(SourceStream &s) const
|
---|
229 | {
|
---|
230 | s << expr;
|
---|
231 | if (oper == OpPlusPlus)
|
---|
232 | s << "++";
|
---|
233 | else
|
---|
234 | s << "--";
|
---|
235 | }
|
---|
236 |
|
---|
237 | void DeleteNode::streamTo(SourceStream &s) const
|
---|
238 | {
|
---|
239 | s << "delete " << expr;
|
---|
240 | }
|
---|
241 |
|
---|
242 | void VoidNode::streamTo(SourceStream &s) const
|
---|
243 | {
|
---|
244 | s << "void " << expr;
|
---|
245 | }
|
---|
246 |
|
---|
247 | void TypeOfNode::streamTo(SourceStream &s) const
|
---|
248 | {
|
---|
249 | s << "typeof " << expr;
|
---|
250 | }
|
---|
251 |
|
---|
252 | void PrefixNode::streamTo(SourceStream &s) const
|
---|
253 | {
|
---|
254 | s << expr << (oper == OpPlusPlus ? "++" : "--");
|
---|
255 | }
|
---|
256 |
|
---|
257 | void UnaryPlusNode::streamTo(SourceStream &s) const
|
---|
258 | {
|
---|
259 | s << "+" << expr;
|
---|
260 | }
|
---|
261 |
|
---|
262 | void NegateNode::streamTo(SourceStream &s) const
|
---|
263 | {
|
---|
264 | s << "-" << expr;
|
---|
265 | }
|
---|
266 |
|
---|
267 | void BitwiseNotNode::streamTo(SourceStream &s) const
|
---|
268 | {
|
---|
269 | s << "~" << expr;
|
---|
270 | }
|
---|
271 |
|
---|
272 | void LogicalNotNode::streamTo(SourceStream &s) const
|
---|
273 | {
|
---|
274 | s << "!" << expr;
|
---|
275 | }
|
---|
276 |
|
---|
277 | void MultNode::streamTo(SourceStream &s) const
|
---|
278 | {
|
---|
279 | s << term1 << oper << term2;
|
---|
280 | }
|
---|
281 |
|
---|
282 | void AddNode::streamTo(SourceStream &s) const
|
---|
283 | {
|
---|
284 | s << term1 << oper << term2;
|
---|
285 | }
|
---|
286 |
|
---|
287 | void ShiftNode::streamTo(SourceStream &s) const
|
---|
288 | {
|
---|
289 | s << term1;
|
---|
290 | if (oper == OpLShift)
|
---|
291 | s << "<<";
|
---|
292 | else if (oper == OpRShift)
|
---|
293 | s << ">>";
|
---|
294 | else
|
---|
295 | s << ">>>";
|
---|
296 | s << term2;
|
---|
297 | }
|
---|
298 |
|
---|
299 | void RelationalNode::streamTo(SourceStream &s) const
|
---|
300 | {
|
---|
301 | s << expr1;
|
---|
302 | switch (oper) {
|
---|
303 | case OpLess:
|
---|
304 | s << " < ";
|
---|
305 | break;
|
---|
306 | case OpGreater:
|
---|
307 | s << " > ";
|
---|
308 | break;
|
---|
309 | case OpLessEq:
|
---|
310 | s << " <= ";
|
---|
311 | break;
|
---|
312 | case OpGreaterEq:
|
---|
313 | s << " >= ";
|
---|
314 | break;
|
---|
315 | case OpInstanceOf:
|
---|
316 | s << " instanceof ";
|
---|
317 | break;
|
---|
318 | case OpIn:
|
---|
319 | s << " in ";
|
---|
320 | break;
|
---|
321 | default:
|
---|
322 | ;
|
---|
323 | }
|
---|
324 | s << expr2;
|
---|
325 | }
|
---|
326 |
|
---|
327 | void EqualNode::streamTo(SourceStream &s) const
|
---|
328 | {
|
---|
329 | s << expr1;
|
---|
330 | switch (oper) {
|
---|
331 | case OpEqEq:
|
---|
332 | s << " == ";
|
---|
333 | break;
|
---|
334 | case OpNotEq:
|
---|
335 | s << " != ";
|
---|
336 | break;
|
---|
337 | case OpStrEq:
|
---|
338 | s << " === ";
|
---|
339 | break;
|
---|
340 | case OpStrNEq:
|
---|
341 | s << " !== ";
|
---|
342 | break;
|
---|
343 | default:
|
---|
344 | ;
|
---|
345 | }
|
---|
346 | s << expr2;
|
---|
347 | }
|
---|
348 |
|
---|
349 | void BitOperNode::streamTo(SourceStream &s) const
|
---|
350 | {
|
---|
351 | s << expr1;
|
---|
352 | if (oper == OpBitAnd)
|
---|
353 | s << " & ";
|
---|
354 | else if (oper == OpBitXOr)
|
---|
355 | s << " ^ ";
|
---|
356 | else
|
---|
357 | s << " | ";
|
---|
358 | s << expr2;
|
---|
359 | }
|
---|
360 |
|
---|
361 | void BinaryLogicalNode::streamTo(SourceStream &s) const
|
---|
362 | {
|
---|
363 | s << expr1 << (oper == OpAnd ? " && " : " || ") << expr2;
|
---|
364 | }
|
---|
365 |
|
---|
366 | void ConditionalNode::streamTo(SourceStream &s) const
|
---|
367 | {
|
---|
368 | s << logical << " ? " << expr1 << " : " << expr2;
|
---|
369 | }
|
---|
370 |
|
---|
371 | static void streamAssignmentOperatorTo(SourceStream &s, Operator oper)
|
---|
372 | {
|
---|
373 | const char *opStr;
|
---|
374 | switch (oper) {
|
---|
375 | case OpEqual:
|
---|
376 | opStr = " = ";
|
---|
377 | break;
|
---|
378 | case OpMultEq:
|
---|
379 | opStr = " *= ";
|
---|
380 | break;
|
---|
381 | case OpDivEq:
|
---|
382 | opStr = " /= ";
|
---|
383 | break;
|
---|
384 | case OpPlusEq:
|
---|
385 | opStr = " += ";
|
---|
386 | break;
|
---|
387 | case OpMinusEq:
|
---|
388 | opStr = " -= ";
|
---|
389 | break;
|
---|
390 | case OpLShift:
|
---|
391 | opStr = " <<= ";
|
---|
392 | break;
|
---|
393 | case OpRShift:
|
---|
394 | opStr = " >>= ";
|
---|
395 | break;
|
---|
396 | case OpURShift:
|
---|
397 | opStr = " >>>= ";
|
---|
398 | break;
|
---|
399 | case OpAndEq:
|
---|
400 | opStr = " &= ";
|
---|
401 | break;
|
---|
402 | case OpXOrEq:
|
---|
403 | opStr = " ^= ";
|
---|
404 | break;
|
---|
405 | case OpOrEq:
|
---|
406 | opStr = " |= ";
|
---|
407 | break;
|
---|
408 | case OpModEq:
|
---|
409 | opStr = " %= ";
|
---|
410 | break;
|
---|
411 | default:
|
---|
412 | opStr = " ?= ";
|
---|
413 | }
|
---|
414 | s << opStr;
|
---|
415 | }
|
---|
416 |
|
---|
417 | void AssignResolveNode::streamTo(SourceStream &s) const
|
---|
418 | {
|
---|
419 | s << m_ident;
|
---|
420 | streamAssignmentOperatorTo(s, m_oper);
|
---|
421 | s << m_right;
|
---|
422 | }
|
---|
423 |
|
---|
424 | void AssignBracketNode::streamTo(SourceStream &s) const
|
---|
425 | {
|
---|
426 | s << m_base << "[" << m_subscript << "]";
|
---|
427 | streamAssignmentOperatorTo(s, m_oper);
|
---|
428 | s << m_right;
|
---|
429 | }
|
---|
430 |
|
---|
431 | void AssignDotNode::streamTo(SourceStream &s) const
|
---|
432 | {
|
---|
433 | s << m_base << "." << m_ident;
|
---|
434 | streamAssignmentOperatorTo(s, m_oper);
|
---|
435 | s << m_right;
|
---|
436 | }
|
---|
437 |
|
---|
438 | void CommaNode::streamTo(SourceStream &s) const
|
---|
439 | {
|
---|
440 | s << expr1 << ", " << expr2;
|
---|
441 | }
|
---|
442 |
|
---|
443 | void StatListNode::streamTo(SourceStream &s) const
|
---|
444 | {
|
---|
445 | for (const StatListNode *n = this; n; n = n->list)
|
---|
446 | s << n->statement;
|
---|
447 | }
|
---|
448 |
|
---|
449 | void AssignExprNode::streamTo(SourceStream &s) const
|
---|
450 | {
|
---|
451 | s << " = " << expr;
|
---|
452 | }
|
---|
453 |
|
---|
454 | void VarDeclNode::streamTo(SourceStream &s) const
|
---|
455 | {
|
---|
456 | s << ident << init;
|
---|
457 | }
|
---|
458 |
|
---|
459 | void VarDeclListNode::streamTo(SourceStream &s) const
|
---|
460 | {
|
---|
461 | s << var;
|
---|
462 | for (VarDeclListNode *n = list; n; n = n->list)
|
---|
463 | s << ", " << n->var;
|
---|
464 | }
|
---|
465 |
|
---|
466 | void VarStatementNode::streamTo(SourceStream &s) const
|
---|
467 | {
|
---|
468 | s << SourceStream::Endl << "var " << list << ";";
|
---|
469 | }
|
---|
470 |
|
---|
471 | void BlockNode::streamTo(SourceStream &s) const
|
---|
472 | {
|
---|
473 | s << SourceStream::Endl << "{" << SourceStream::Indent
|
---|
474 | << source << SourceStream::Unindent << SourceStream::Endl << "}";
|
---|
475 | }
|
---|
476 |
|
---|
477 | void EmptyStatementNode::streamTo(SourceStream &s) const
|
---|
478 | {
|
---|
479 | s << SourceStream::Endl << ";";
|
---|
480 | }
|
---|
481 |
|
---|
482 | void ExprStatementNode::streamTo(SourceStream &s) const
|
---|
483 | {
|
---|
484 | s << SourceStream::Endl << expr << ";";
|
---|
485 | }
|
---|
486 |
|
---|
487 | void IfNode::streamTo(SourceStream &s) const
|
---|
488 | {
|
---|
489 | s << SourceStream::Endl << "if (" << expr << ")" << SourceStream::Indent
|
---|
490 | << statement1 << SourceStream::Unindent;
|
---|
491 | if (statement2)
|
---|
492 | s << SourceStream::Endl << "else" << SourceStream::Indent
|
---|
493 | << statement2 << SourceStream::Unindent;
|
---|
494 | }
|
---|
495 |
|
---|
496 | void DoWhileNode::streamTo(SourceStream &s) const
|
---|
497 | {
|
---|
498 | s << SourceStream::Endl << "do " << SourceStream::Indent
|
---|
499 | << statement << SourceStream::Unindent << SourceStream::Endl
|
---|
500 | << "while (" << expr << ");";
|
---|
501 | }
|
---|
502 |
|
---|
503 | void WhileNode::streamTo(SourceStream &s) const
|
---|
504 | {
|
---|
505 | s << SourceStream::Endl << "while (" << expr << ")" << SourceStream::Indent
|
---|
506 | << statement << SourceStream::Unindent;
|
---|
507 | }
|
---|
508 |
|
---|
509 | void ForNode::streamTo(SourceStream &s) const
|
---|
510 | {
|
---|
511 | s << SourceStream::Endl << "for ("
|
---|
512 | << expr1 // TODO: doesn't properly do "var i = 0"
|
---|
513 | << "; " << expr2
|
---|
514 | << "; " << expr3
|
---|
515 | << ")" << SourceStream::Indent << statement << SourceStream::Unindent;
|
---|
516 | }
|
---|
517 |
|
---|
518 | void ForInNode::streamTo(SourceStream &s) const
|
---|
519 | {
|
---|
520 | s << SourceStream::Endl << "for (";
|
---|
521 | if (varDecl)
|
---|
522 | s << "var " << varDecl;
|
---|
523 | if (init)
|
---|
524 | s << " = " << init;
|
---|
525 | s << " in " << expr << ")" << SourceStream::Indent
|
---|
526 | << statement << SourceStream::Unindent;
|
---|
527 | }
|
---|
528 |
|
---|
529 | void ContinueNode::streamTo(SourceStream &s) const
|
---|
530 | {
|
---|
531 | s << SourceStream::Endl << "continue";
|
---|
532 | if (!ident.isNull())
|
---|
533 | s << " " << ident;
|
---|
534 | s << ";";
|
---|
535 | }
|
---|
536 |
|
---|
537 | void BreakNode::streamTo(SourceStream &s) const
|
---|
538 | {
|
---|
539 | s << SourceStream::Endl << "break";
|
---|
540 | if (!ident.isNull())
|
---|
541 | s << " " << ident;
|
---|
542 | s << ";";
|
---|
543 | }
|
---|
544 |
|
---|
545 | void ReturnNode::streamTo(SourceStream &s) const
|
---|
546 | {
|
---|
547 | s << SourceStream::Endl << "return";
|
---|
548 | if (value)
|
---|
549 | s << " " << value;
|
---|
550 | s << ";";
|
---|
551 | }
|
---|
552 |
|
---|
553 | void WithNode::streamTo(SourceStream &s) const
|
---|
554 | {
|
---|
555 | s << SourceStream::Endl << "with (" << expr << ") "
|
---|
556 | << statement;
|
---|
557 | }
|
---|
558 |
|
---|
559 | void CaseClauseNode::streamTo(SourceStream &s) const
|
---|
560 | {
|
---|
561 | s << SourceStream::Endl;
|
---|
562 | if (expr)
|
---|
563 | s << "case " << expr;
|
---|
564 | else
|
---|
565 | s << "default";
|
---|
566 | s << ":" << SourceStream::Indent;
|
---|
567 | if (list)
|
---|
568 | s << list;
|
---|
569 | s << SourceStream::Unindent;
|
---|
570 | }
|
---|
571 |
|
---|
572 | void ClauseListNode::streamTo(SourceStream &s) const
|
---|
573 | {
|
---|
574 | for (const ClauseListNode *n = this; n; n = n->next())
|
---|
575 | s << n->clause();
|
---|
576 | }
|
---|
577 |
|
---|
578 | void CaseBlockNode::streamTo(SourceStream &s) const
|
---|
579 | {
|
---|
580 | for (const ClauseListNode *n = list1; n; n = n->next())
|
---|
581 | s << n->clause();
|
---|
582 | if (def)
|
---|
583 | s << def;
|
---|
584 | for (const ClauseListNode *n = list2; n; n = n->next())
|
---|
585 | s << n->clause();
|
---|
586 | }
|
---|
587 |
|
---|
588 | void SwitchNode::streamTo(SourceStream &s) const
|
---|
589 | {
|
---|
590 | s << SourceStream::Endl << "switch (" << expr << ") {"
|
---|
591 | << SourceStream::Indent << block << SourceStream::Unindent
|
---|
592 | << SourceStream::Endl << "}";
|
---|
593 | }
|
---|
594 |
|
---|
595 | void LabelNode::streamTo(SourceStream &s) const
|
---|
596 | {
|
---|
597 | s << SourceStream::Endl << label << ":" << SourceStream::Indent
|
---|
598 | << statement << SourceStream::Unindent;
|
---|
599 | }
|
---|
600 |
|
---|
601 | void ThrowNode::streamTo(SourceStream &s) const
|
---|
602 | {
|
---|
603 | s << SourceStream::Endl << "throw " << expr << ";";
|
---|
604 | }
|
---|
605 |
|
---|
606 | void CatchNode::streamTo(SourceStream &s) const
|
---|
607 | {
|
---|
608 | s << SourceStream::Endl << "catch (" << ident << ")" << block;
|
---|
609 | }
|
---|
610 |
|
---|
611 | void FinallyNode::streamTo(SourceStream &s) const
|
---|
612 | {
|
---|
613 | s << SourceStream::Endl << "finally " << block;
|
---|
614 | }
|
---|
615 |
|
---|
616 | void TryNode::streamTo(SourceStream &s) const
|
---|
617 | {
|
---|
618 | s << "try " << block
|
---|
619 | << _catch
|
---|
620 | << _final;
|
---|
621 | }
|
---|
622 |
|
---|
623 | void ParameterNode::streamTo(SourceStream &s) const
|
---|
624 | {
|
---|
625 | s << id;
|
---|
626 | for (ParameterNode *n = next; n; n = n->next)
|
---|
627 | s << ", " << n->id;
|
---|
628 | }
|
---|
629 |
|
---|
630 | void FuncDeclNode::streamTo(SourceStream &s) const {
|
---|
631 | s << "function " << ident << "(";
|
---|
632 | if (param)
|
---|
633 | s << param;
|
---|
634 | s << ")" << body;
|
---|
635 | }
|
---|
636 |
|
---|
637 | void FuncExprNode::streamTo(SourceStream &s) const
|
---|
638 | {
|
---|
639 | s << "function " << "("
|
---|
640 | << param
|
---|
641 | << ")" << body;
|
---|
642 | }
|
---|
643 |
|
---|
644 | void SourceElementsNode::streamTo(SourceStream &s) const
|
---|
645 | {
|
---|
646 | for (const SourceElementsNode *n = this; n; n = n->elements)
|
---|
647 | s << n->element;
|
---|
648 | }
|
---|
649 |
|
---|