source: webkit/trunk/JavaScriptCore/kjs/nodes.h@ 10456

Last change on this file since 10456 was 10416, checked in by ggaren, 20 years ago

-rolled in fix for http://bugzilla.opendarwin.org/show_bug.cgi?id=4698
kjs does not allow named functions in function expressions

Fix by Arthur Langereis.

Reviewed by darin.

  • kjs/grammar.y:
  • kjs/nodes.cpp: (FuncExprNode::evaluate):
  • kjs/nodes.h: (KJS::FuncExprNode::FuncExprNode):

Test cases added:

  • layout-tests/fast/js/named-function-expression-expected.txt: Added.
  • layout-tests/fast/js/named-function-expression.html: Added.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 30.9 KB
Line 
1// -*- c-basic-offset: 2 -*-
2/*
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999-2000 Harri Porten ([email protected])
5 * Copyright (C) 2001 Peter Kelly ([email protected])
6 * Copyright (C) 2003 Apple Computer, Inc.
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 *
23 */
24
25#ifndef _NODES_H_
26#define _NODES_H_
27
28#include "fast_malloc.h"
29#include "shared_ptr.h"
30
31#include "internal.h"
32//#include "debugger.h"
33#ifndef NDEBUG
34#ifndef __osf__
35#include <list>
36#endif
37#endif
38
39namespace KJS {
40
41 class RegExp;
42 class SourceElementsNode;
43 class ProgramNode;
44 class SourceStream;
45 class PropertyValueNode;
46 class PropertyNode;
47
48 enum Operator { OpEqual,
49 OpEqEq,
50 OpNotEq,
51 OpStrEq,
52 OpStrNEq,
53 OpPlusEq,
54 OpMinusEq,
55 OpMultEq,
56 OpDivEq,
57 OpPlusPlus,
58 OpMinusMinus,
59 OpLess,
60 OpLessEq,
61 OpGreater,
62 OpGreaterEq,
63 OpAndEq,
64 OpXOrEq,
65 OpOrEq,
66 OpModEq,
67 OpAnd,
68 OpOr,
69 OpBitAnd,
70 OpBitXOr,
71 OpBitOr,
72 OpLShift,
73 OpRShift,
74 OpURShift,
75 OpIn,
76 OpInstanceOf
77 };
78
79 class Node {
80 public:
81 Node();
82 virtual ~Node();
83
84 KJS_FAST_ALLOCATED;
85
86 virtual ValueImp *evaluate(ExecState *exec) = 0;
87 virtual Reference evaluateReference(ExecState *exec);
88 UString toString() const;
89 virtual void streamTo(SourceStream &s) const = 0;
90 virtual void processVarDecls(ExecState */*exec*/) {}
91 int lineNo() const { return line; }
92
93 public:
94 // reference counting mechanism
95 void ref() { ++m_refcount; }
96 void deref() { --m_refcount; if (!m_refcount) delete this; }
97 unsigned int refcount() { return m_refcount; }
98
99 protected:
100 ValueImp *throwError(ExecState *exec, ErrorType e, const char *msg);
101 ValueImp *throwError(ExecState *exec, ErrorType e, const char *msg, ValueImp *v, Node *expr);
102 ValueImp *throwError(ExecState *exec, ErrorType e, const char *msg, Identifier label);
103 ValueImp *throwError(ExecState *exec, ErrorType e, const char *msg, ValueImp *v, Identifier ident);
104 ValueImp *throwError(ExecState *exec, ErrorType e, const char *msg, ValueImp *v, Node *e1, Node *e2);
105 ValueImp *throwError(ExecState *exec, ErrorType e, const char *msg, ValueImp *v, Node *expr, Identifier ident);
106
107 void setExceptionDetailsIfNeeded(ExecState *exec);
108 int line;
109 UString sourceURL;
110 unsigned int m_refcount;
111 virtual int sourceId() const { return -1; }
112 private:
113 // disallow assignment
114 Node& operator=(const Node&);
115 Node(const Node &other);
116 };
117
118 class StatementNode : public Node {
119 public:
120 StatementNode();
121 void setLoc(int line0, int line1, int sourceId);
122 int firstLine() const { return l0; }
123 int lastLine() const { return l1; }
124 int sourceId() const { return sid; }
125 bool hitStatement(ExecState *exec);
126 bool abortStatement(ExecState *exec);
127 virtual Completion execute(ExecState *exec) = 0;
128 void pushLabel(const Identifier &id) { ls.push(id); }
129 virtual void processFuncDecl(ExecState *exec);
130 protected:
131 LabelStack ls;
132 private:
133 ValueImp *evaluate(ExecState */*exec*/) { return Undefined(); }
134 int l0, l1;
135 int sid;
136 bool breakPoint;
137 };
138
139 class NullNode : public Node {
140 public:
141 NullNode() {}
142 ValueImp *evaluate(ExecState *exec);
143 virtual void streamTo(SourceStream &s) const;
144 };
145
146 class BooleanNode : public Node {
147 public:
148 BooleanNode(bool v) : value(v) {}
149 ValueImp *evaluate(ExecState *exec);
150 virtual void streamTo(SourceStream &s) const;
151 private:
152 bool value;
153 };
154
155 class NumberNode : public Node {
156 public:
157 NumberNode(double v) : value(v) {}
158 ValueImp *evaluate(ExecState *exec);
159 virtual void streamTo(SourceStream &s) const;
160 private:
161 double value;
162 };
163
164 class StringNode : public Node {
165 public:
166 StringNode(const UString *v) { value = *v; }
167 ValueImp *evaluate(ExecState *exec);
168 virtual void streamTo(SourceStream &s) const;
169 private:
170 UString value;
171 };
172
173 class RegExpNode : public Node {
174 public:
175 RegExpNode(const UString &p, const UString &f)
176 : pattern(p), flags(f) { }
177 ValueImp *evaluate(ExecState *exec);
178 virtual void streamTo(SourceStream &s) const;
179 private:
180 UString pattern, flags;
181 };
182
183 class ThisNode : public Node {
184 public:
185 ThisNode() {}
186 ValueImp *evaluate(ExecState *exec);
187 virtual void streamTo(SourceStream &s) const;
188 };
189
190 class ResolveNode : public Node {
191 public:
192 ResolveNode(const Identifier &s) : ident(s) { }
193 ValueImp *evaluate(ExecState *exec);
194 virtual Reference evaluateReference(ExecState *exec);
195 virtual void streamTo(SourceStream &s) const;
196 private:
197 Identifier ident;
198 };
199
200 class GroupNode : public Node {
201 public:
202 GroupNode(Node *g) : group(g) { }
203 virtual ValueImp *evaluate(ExecState *exec);
204 virtual Reference evaluateReference(ExecState *exec);
205 virtual void streamTo(SourceStream &s) const;
206 private:
207 KXMLCore::SharedPtr<Node> group;
208 };
209
210 class ElementNode : public Node {
211 public:
212 // list pointer is tail of a circular list, cracked in the ArrayNode ctor
213 ElementNode(int e, Node *n) : list(this), elision(e), node(n) { }
214 ElementNode(ElementNode *l, int e, Node *n)
215 : list(l->list), elision(e), node(n) { l->list = this; }
216 ValueImp *evaluate(ExecState *exec);
217 virtual void streamTo(SourceStream &s) const;
218 private:
219 friend class ArrayNode;
220 KXMLCore::SharedPtr<ElementNode> list;
221 int elision;
222 KXMLCore::SharedPtr<Node> node;
223 };
224
225 class ArrayNode : public Node {
226 public:
227 ArrayNode(int e) : element(0), elision(e), opt(true) { }
228 ArrayNode(ElementNode *ele)
229 : element(ele->list), elision(0), opt(false) { ele->list = 0; }
230 ArrayNode(int eli, ElementNode *ele)
231 : element(ele->list), elision(eli), opt(true) { ele->list = 0; }
232 ValueImp *evaluate(ExecState *exec);
233 virtual void streamTo(SourceStream &s) const;
234 private:
235 KXMLCore::SharedPtr<ElementNode> element;
236 int elision;
237 bool opt;
238 };
239
240 class PropertyValueNode : public Node {
241 public:
242 // list pointer is tail of a circular list, cracked in the ObjectLiteralNode ctor
243 PropertyValueNode(PropertyNode *n, Node *a)
244 : name(n), assign(a), list(this) { }
245 PropertyValueNode(PropertyNode *n, Node *a, PropertyValueNode *l)
246 : name(n), assign(a), list(l->list) { l->list = this; }
247 ValueImp *evaluate(ExecState *exec);
248 virtual void streamTo(SourceStream &s) const;
249 private:
250 friend class ObjectLiteralNode;
251 KXMLCore::SharedPtr<PropertyNode> name;
252 KXMLCore::SharedPtr<Node> assign;
253 KXMLCore::SharedPtr<PropertyValueNode> list;
254 };
255
256 class ObjectLiteralNode : public Node {
257 public:
258 ObjectLiteralNode() : list(0) { }
259 ObjectLiteralNode(PropertyValueNode *l) : list(l->list) { l->list = 0; }
260 ValueImp *evaluate(ExecState *exec);
261 virtual void streamTo(SourceStream &s) const;
262 private:
263 KXMLCore::SharedPtr<PropertyValueNode> list;
264 };
265
266 class PropertyNode : public Node {
267 public:
268 PropertyNode(double d) : numeric(d) { }
269 PropertyNode(const Identifier &s) : str(s) { }
270 ValueImp *evaluate(ExecState *exec);
271 virtual void streamTo(SourceStream &s) const;
272 private:
273 double numeric;
274 Identifier str;
275 };
276
277 class BracketAccessorNode : public Node {
278 public:
279 BracketAccessorNode(Node *e1, Node *e2) : expr1(e1), expr2(e2) {}
280 ValueImp *evaluate(ExecState *exec);
281 virtual Reference evaluateReference(ExecState *exec);
282 virtual void streamTo(SourceStream &s) const;
283 private:
284 KXMLCore::SharedPtr<Node> expr1;
285 KXMLCore::SharedPtr<Node> expr2;
286 };
287
288 class DotAccessorNode : public Node {
289 public:
290 DotAccessorNode(Node *e, const Identifier &s) : expr(e), ident(s) { }
291 ValueImp *evaluate(ExecState *exec);
292 virtual Reference evaluateReference(ExecState *exec);
293 virtual void streamTo(SourceStream &s) const;
294 private:
295 KXMLCore::SharedPtr<Node> expr;
296 Identifier ident;
297 };
298
299 class ArgumentListNode : public Node {
300 public:
301 // list pointer is tail of a circular list, cracked in the ArgumentsNode ctor
302 ArgumentListNode(Node *e) : list(this), expr(e) { }
303 ArgumentListNode(ArgumentListNode *l, Node *e)
304 : list(l->list), expr(e) { l->list = this; }
305 ValueImp *evaluate(ExecState *exec);
306 List evaluateList(ExecState *exec);
307 virtual void streamTo(SourceStream &s) const;
308 private:
309 friend class ArgumentsNode;
310 KXMLCore::SharedPtr<ArgumentListNode> list;
311 KXMLCore::SharedPtr<Node> expr;
312 };
313
314 class ArgumentsNode : public Node {
315 public:
316 ArgumentsNode() : list(0) { }
317 ArgumentsNode(ArgumentListNode *l)
318 : list(l->list) { l->list = 0; }
319 ValueImp *evaluate(ExecState *exec);
320 List evaluateList(ExecState *exec);
321 virtual void streamTo(SourceStream &s) const;
322 private:
323 KXMLCore::SharedPtr<ArgumentListNode> list;
324 };
325
326 class NewExprNode : public Node {
327 public:
328 NewExprNode(Node *e) : expr(e), args(0) {}
329 NewExprNode(Node *e, ArgumentsNode *a) : expr(e), args(a) {}
330 ValueImp *evaluate(ExecState *exec);
331 virtual void streamTo(SourceStream &s) const;
332 private:
333 KXMLCore::SharedPtr<Node> expr;
334 KXMLCore::SharedPtr<ArgumentsNode> args;
335 };
336
337 class FunctionCallValueNode : public Node {
338 public:
339 FunctionCallValueNode(Node *e, ArgumentsNode *a) : expr(e), args(a) {}
340 ValueImp *evaluate(ExecState *exec);
341 virtual void streamTo(SourceStream &s) const;
342 private:
343 KXMLCore::SharedPtr<Node> expr;
344 KXMLCore::SharedPtr<ArgumentsNode> args;
345 };
346
347 class FunctionCallResolveNode : public Node {
348 public:
349 FunctionCallResolveNode(const Identifier& i, ArgumentsNode *a) : ident(i), args(a) {}
350 ValueImp *evaluate(ExecState *exec);
351 virtual void streamTo(SourceStream &s) const;
352 private:
353 Identifier ident;
354 KXMLCore::SharedPtr<ArgumentsNode> args;
355 };
356
357 class FunctionCallBracketNode : public Node {
358 public:
359 FunctionCallBracketNode(Node *b, Node *s, ArgumentsNode *a) : base(b), subscript(s), args(a) {}
360 ValueImp *evaluate(ExecState *exec);
361 virtual void streamTo(SourceStream &s) const;
362 protected:
363 KXMLCore::SharedPtr<Node> base;
364 KXMLCore::SharedPtr<Node> subscript;
365 KXMLCore::SharedPtr<ArgumentsNode> args;
366 };
367
368 class FunctionCallParenBracketNode : public FunctionCallBracketNode {
369 public:
370 FunctionCallParenBracketNode(Node *b, Node *s, ArgumentsNode *a) : FunctionCallBracketNode(b, s, a) {}
371 virtual void streamTo(SourceStream &s) const;
372 };
373
374 class FunctionCallDotNode : public Node {
375 public:
376 FunctionCallDotNode(Node *b, const Identifier &i, ArgumentsNode *a) : base(b), ident(i), args(a) {}
377 ValueImp *evaluate(ExecState *exec);
378 virtual void streamTo(SourceStream &s) const;
379 protected:
380 KXMLCore::SharedPtr<Node> base;
381 Identifier ident;
382 KXMLCore::SharedPtr<ArgumentsNode> args;
383 };
384
385 class FunctionCallParenDotNode : public FunctionCallDotNode {
386 public:
387 FunctionCallParenDotNode(Node *b, const Identifier &i, ArgumentsNode *a) : FunctionCallDotNode(b, i, a) {}
388 virtual void streamTo(SourceStream &s) const;
389 };
390
391 class PostfixNode : public Node {
392 public:
393 PostfixNode(Node *e, Operator o) : expr(e), oper(o) {}
394 ValueImp *evaluate(ExecState *exec);
395 virtual void streamTo(SourceStream &s) const;
396 private:
397 KXMLCore::SharedPtr<Node> expr;
398 Operator oper;
399 };
400
401 class DeleteNode : public Node {
402 public:
403 DeleteNode(Node *e) : expr(e) {}
404 ValueImp *evaluate(ExecState *exec);
405 virtual void streamTo(SourceStream &s) const;
406 private:
407 KXMLCore::SharedPtr<Node> expr;
408 };
409
410 class VoidNode : public Node {
411 public:
412 VoidNode(Node *e) : expr(e) {}
413 ValueImp *evaluate(ExecState *exec);
414 virtual void streamTo(SourceStream &s) const;
415 private:
416 KXMLCore::SharedPtr<Node> expr;
417 };
418
419 class TypeOfNode : public Node {
420 public:
421 TypeOfNode(Node *e) : expr(e) {}
422 ValueImp *evaluate(ExecState *exec);
423 virtual void streamTo(SourceStream &s) const;
424 private:
425 KXMLCore::SharedPtr<Node> expr;
426 };
427
428 class PrefixNode : public Node {
429 public:
430 PrefixNode(Operator o, Node *e) : oper(o), expr(e) {}
431 ValueImp *evaluate(ExecState *exec);
432 virtual void streamTo(SourceStream &s) const;
433 private:
434 Operator oper;
435 KXMLCore::SharedPtr<Node> expr;
436 };
437
438 class UnaryPlusNode : public Node {
439 public:
440 UnaryPlusNode(Node *e) : expr(e) {}
441 ValueImp *evaluate(ExecState *exec);
442 virtual void streamTo(SourceStream &s) const;
443 private:
444 KXMLCore::SharedPtr<Node> expr;
445 };
446
447 class NegateNode : public Node {
448 public:
449 NegateNode(Node *e) : expr(e) {}
450 ValueImp *evaluate(ExecState *exec);
451 virtual void streamTo(SourceStream &s) const;
452 private:
453 KXMLCore::SharedPtr<Node> expr;
454 };
455
456 class BitwiseNotNode : public Node {
457 public:
458 BitwiseNotNode(Node *e) : expr(e) {}
459 ValueImp *evaluate(ExecState *exec);
460 virtual void streamTo(SourceStream &s) const;
461 private:
462 KXMLCore::SharedPtr<Node> expr;
463 };
464
465 class LogicalNotNode : public Node {
466 public:
467 LogicalNotNode(Node *e) : expr(e) {}
468 ValueImp *evaluate(ExecState *exec);
469 virtual void streamTo(SourceStream &s) const;
470 private:
471 KXMLCore::SharedPtr<Node> expr;
472 };
473
474 class MultNode : public Node {
475 public:
476 MultNode(Node *t1, Node *t2, char op) : term1(t1), term2(t2), oper(op) {}
477 ValueImp *evaluate(ExecState *exec);
478 virtual void streamTo(SourceStream &s) const;
479 private:
480 KXMLCore::SharedPtr<Node> term1;
481 KXMLCore::SharedPtr<Node> term2;
482 char oper;
483 };
484
485 class AddNode : public Node {
486 public:
487 AddNode(Node *t1, Node *t2, char op) : term1(t1), term2(t2), oper(op) {}
488 ValueImp *evaluate(ExecState *exec);
489 virtual void streamTo(SourceStream &s) const;
490 private:
491 KXMLCore::SharedPtr<Node> term1;
492 KXMLCore::SharedPtr<Node> term2;
493 char oper;
494 };
495
496 class ShiftNode : public Node {
497 public:
498 ShiftNode(Node *t1, Operator o, Node *t2)
499 : term1(t1), term2(t2), oper(o) {}
500 ValueImp *evaluate(ExecState *exec);
501 virtual void streamTo(SourceStream &s) const;
502 private:
503 KXMLCore::SharedPtr<Node> term1;
504 KXMLCore::SharedPtr<Node> term2;
505 Operator oper;
506 };
507
508 class RelationalNode : public Node {
509 public:
510 RelationalNode(Node *e1, Operator o, Node *e2) :
511 expr1(e1), expr2(e2), oper(o) {}
512 ValueImp *evaluate(ExecState *exec);
513 virtual void streamTo(SourceStream &s) const;
514 private:
515 KXMLCore::SharedPtr<Node> expr1;
516 KXMLCore::SharedPtr<Node> expr2;
517 Operator oper;
518 };
519
520 class EqualNode : public Node {
521 public:
522 EqualNode(Node *e1, Operator o, Node *e2)
523 : expr1(e1), expr2(e2), oper(o) {}
524 ValueImp *evaluate(ExecState *exec);
525 virtual void streamTo(SourceStream &s) const;
526 private:
527 KXMLCore::SharedPtr<Node> expr1;
528 KXMLCore::SharedPtr<Node> expr2;
529 Operator oper;
530 };
531
532 class BitOperNode : public Node {
533 public:
534 BitOperNode(Node *e1, Operator o, Node *e2) :
535 expr1(e1), expr2(e2), oper(o) {}
536 ValueImp *evaluate(ExecState *exec);
537 virtual void streamTo(SourceStream &s) const;
538 private:
539 KXMLCore::SharedPtr<Node> expr1;
540 KXMLCore::SharedPtr<Node> expr2;
541 Operator oper;
542 };
543
544 /**
545 * expr1 && expr2, expr1 || expr2
546 */
547 class BinaryLogicalNode : public Node {
548 public:
549 BinaryLogicalNode(Node *e1, Operator o, Node *e2) :
550 expr1(e1), expr2(e2), oper(o) {}
551 ValueImp *evaluate(ExecState *exec);
552 virtual void streamTo(SourceStream &s) const;
553 private:
554 KXMLCore::SharedPtr<Node> expr1;
555 KXMLCore::SharedPtr<Node> expr2;
556 Operator oper;
557 };
558
559 /**
560 * The ternary operator, "logical ? expr1 : expr2"
561 */
562 class ConditionalNode : public Node {
563 public:
564 ConditionalNode(Node *l, Node *e1, Node *e2) :
565 logical(l), expr1(e1), expr2(e2) {}
566 ValueImp *evaluate(ExecState *exec);
567 virtual void streamTo(SourceStream &s) const;
568 private:
569 KXMLCore::SharedPtr<Node> logical;
570 KXMLCore::SharedPtr<Node> expr1;
571 KXMLCore::SharedPtr<Node> expr2;
572 };
573
574 class AssignResolveNode : public Node {
575 public:
576 AssignResolveNode(const Identifier &ident, Operator oper, Node *right)
577 : m_ident(ident), m_oper(oper), m_right(right) {}
578 ValueImp *evaluate(ExecState *exec);
579 virtual void streamTo(SourceStream &s) const;
580 protected:
581 Identifier m_ident;
582 Operator m_oper;
583 KXMLCore::SharedPtr<Node> m_right;
584 };
585
586 class AssignBracketNode : public Node {
587 public:
588 AssignBracketNode(Node *base, Node *subscript, Operator oper, Node *right)
589 : m_base(base), m_subscript(subscript), m_oper(oper), m_right(right) {}
590 ValueImp *evaluate(ExecState *exec);
591 virtual void streamTo(SourceStream &s) const;
592 protected:
593 KXMLCore::SharedPtr<Node> m_base;
594 KXMLCore::SharedPtr<Node> m_subscript;
595 Operator m_oper;
596 KXMLCore::SharedPtr<Node> m_right;
597 };
598
599 class AssignDotNode : public Node {
600 public:
601 AssignDotNode(Node *base, const Identifier& ident, Operator oper, Node *right)
602 : m_base(base), m_ident(ident), m_oper(oper), m_right(right) {}
603 ValueImp *evaluate(ExecState *exec);
604 virtual void streamTo(SourceStream &s) const;
605 protected:
606 KXMLCore::SharedPtr<Node> m_base;
607 Identifier m_ident;
608 Operator m_oper;
609 KXMLCore::SharedPtr<Node> m_right;
610 };
611
612 class CommaNode : public Node {
613 public:
614 CommaNode(Node *e1, Node *e2) : expr1(e1), expr2(e2) {}
615 ValueImp *evaluate(ExecState *exec);
616 virtual void streamTo(SourceStream &s) const;
617 private:
618 KXMLCore::SharedPtr<Node> expr1;
619 KXMLCore::SharedPtr<Node> expr2;
620 };
621
622 class StatListNode : public StatementNode {
623 public:
624 // list pointer is tail of a circular list, cracked in the CaseClauseNode ctor
625 StatListNode(StatementNode *s);
626 StatListNode(StatListNode *l, StatementNode *s);
627 virtual Completion execute(ExecState *exec);
628 virtual void processVarDecls(ExecState *exec);
629 virtual void streamTo(SourceStream &s) const;
630 private:
631 friend class CaseClauseNode;
632 KXMLCore::SharedPtr<StatementNode> statement;
633 KXMLCore::SharedPtr<StatListNode> list;
634 };
635
636 class AssignExprNode : public Node {
637 public:
638 AssignExprNode(Node *e) : expr(e) {}
639 ValueImp *evaluate(ExecState *exec);
640 virtual void streamTo(SourceStream &s) const;
641 private:
642 KXMLCore::SharedPtr<Node> expr;
643 };
644
645 class VarDeclNode : public Node {
646 public:
647 enum Type { Variable, Constant };
648 VarDeclNode(const Identifier &id, AssignExprNode *in, Type t);
649 ValueImp *evaluate(ExecState *exec);
650 virtual void processVarDecls(ExecState *exec);
651 virtual void streamTo(SourceStream &s) const;
652 private:
653 Type varType;
654 Identifier ident;
655 KXMLCore::SharedPtr<AssignExprNode> init;
656 };
657
658 class VarDeclListNode : public Node {
659 public:
660 // list pointer is tail of a circular list, cracked in the ForNode/VarStatementNode ctor
661 VarDeclListNode(VarDeclNode *v) : list(this), var(v) {}
662 VarDeclListNode(VarDeclListNode *l, VarDeclNode *v)
663 : list(l->list), var(v) { l->list = this; }
664 ValueImp *evaluate(ExecState *exec);
665 virtual void processVarDecls(ExecState *exec);
666 virtual void streamTo(SourceStream &s) const;
667 private:
668 friend class ForNode;
669 friend class VarStatementNode;
670 KXMLCore::SharedPtr<VarDeclListNode> list;
671 KXMLCore::SharedPtr<VarDeclNode> var;
672 };
673
674 class VarStatementNode : public StatementNode {
675 public:
676 VarStatementNode(VarDeclListNode *l) : list(l->list) { l->list = 0; }
677 virtual Completion execute(ExecState *exec);
678 virtual void processVarDecls(ExecState *exec);
679 virtual void streamTo(SourceStream &s) const;
680 private:
681 KXMLCore::SharedPtr<VarDeclListNode> list;
682 };
683
684 class BlockNode : public StatementNode {
685 public:
686 BlockNode(SourceElementsNode *s);
687 virtual Completion execute(ExecState *exec);
688 virtual void processVarDecls(ExecState *exec);
689 virtual void streamTo(SourceStream &s) const;
690 protected:
691 KXMLCore::SharedPtr<SourceElementsNode> source;
692 };
693
694 class EmptyStatementNode : public StatementNode {
695 public:
696 EmptyStatementNode() { } // debug
697 virtual Completion execute(ExecState *exec);
698 virtual void streamTo(SourceStream &s) const;
699 };
700
701 class ExprStatementNode : public StatementNode {
702 public:
703 ExprStatementNode(Node *e) : expr(e) { }
704 virtual Completion execute(ExecState *exec);
705 virtual void streamTo(SourceStream &s) const;
706 private:
707 KXMLCore::SharedPtr<Node> expr;
708 };
709
710 class IfNode : public StatementNode {
711 public:
712 IfNode(Node *e, StatementNode *s1, StatementNode *s2)
713 : expr(e), statement1(s1), statement2(s2) {}
714 virtual Completion execute(ExecState *exec);
715 virtual void processVarDecls(ExecState *exec);
716 virtual void streamTo(SourceStream &s) const;
717 private:
718 KXMLCore::SharedPtr<Node> expr;
719 KXMLCore::SharedPtr<StatementNode> statement1;
720 KXMLCore::SharedPtr<StatementNode> statement2;
721 };
722
723 class DoWhileNode : public StatementNode {
724 public:
725 DoWhileNode(StatementNode *s, Node *e) : statement(s), expr(e) {}
726 virtual Completion execute(ExecState *exec);
727 virtual void processVarDecls(ExecState *exec);
728 virtual void streamTo(SourceStream &s) const;
729 private:
730 KXMLCore::SharedPtr<StatementNode> statement;
731 KXMLCore::SharedPtr<Node> expr;
732 };
733
734 class WhileNode : public StatementNode {
735 public:
736 WhileNode(Node *e, StatementNode *s) : expr(e), statement(s) {}
737 virtual Completion execute(ExecState *exec);
738 virtual void processVarDecls(ExecState *exec);
739 virtual void streamTo(SourceStream &s) const;
740 private:
741 KXMLCore::SharedPtr<Node> expr;
742 KXMLCore::SharedPtr<StatementNode> statement;
743 };
744
745 class ForNode : public StatementNode {
746 public:
747 ForNode(Node *e1, Node *e2, Node *e3, StatementNode *s) :
748 expr1(e1), expr2(e2), expr3(e3), statement(s) {}
749 ForNode(VarDeclListNode *e1, Node *e2, Node *e3, StatementNode *s) :
750 expr1(e1->list), expr2(e2), expr3(e3), statement(s) { e1->list = 0; }
751 virtual Completion execute(ExecState *exec);
752 virtual void processVarDecls(ExecState *exec);
753 virtual void streamTo(SourceStream &s) const;
754 private:
755 KXMLCore::SharedPtr<Node> expr1;
756 KXMLCore::SharedPtr<Node> expr2;
757 KXMLCore::SharedPtr<Node> expr3;
758 KXMLCore::SharedPtr<StatementNode> statement;
759 };
760
761 class ForInNode : public StatementNode {
762 public:
763 ForInNode(Node *l, Node *e, StatementNode *s);
764 ForInNode(const Identifier &i, AssignExprNode *in, Node *e, StatementNode *s);
765 virtual Completion execute(ExecState *exec);
766 virtual void processVarDecls(ExecState *exec);
767 virtual void streamTo(SourceStream &s) const;
768 private:
769 Identifier ident;
770 KXMLCore::SharedPtr<AssignExprNode> init;
771 KXMLCore::SharedPtr<Node> lexpr;
772 KXMLCore::SharedPtr<Node> expr;
773 KXMLCore::SharedPtr<VarDeclNode> varDecl;
774 KXMLCore::SharedPtr<StatementNode> statement;
775 };
776
777 class ContinueNode : public StatementNode {
778 public:
779 ContinueNode() { }
780 ContinueNode(const Identifier &i) : ident(i) { }
781 virtual Completion execute(ExecState *exec);
782 virtual void streamTo(SourceStream &s) const;
783 private:
784 Identifier ident;
785 };
786
787 class BreakNode : public StatementNode {
788 public:
789 BreakNode() { }
790 BreakNode(const Identifier &i) : ident(i) { }
791 virtual Completion execute(ExecState *exec);
792 virtual void streamTo(SourceStream &s) const;
793 private:
794 Identifier ident;
795 };
796
797 class ReturnNode : public StatementNode {
798 public:
799 ReturnNode(Node *v) : value(v) {}
800 virtual Completion execute(ExecState *exec);
801 virtual void streamTo(SourceStream &s) const;
802 private:
803 KXMLCore::SharedPtr<Node> value;
804 };
805
806 class WithNode : public StatementNode {
807 public:
808 WithNode(Node *e, StatementNode *s) : expr(e), statement(s) {}
809 virtual Completion execute(ExecState *exec);
810 virtual void processVarDecls(ExecState *exec);
811 virtual void streamTo(SourceStream &s) const;
812 private:
813 KXMLCore::SharedPtr<Node> expr;
814 KXMLCore::SharedPtr<StatementNode> statement;
815 };
816
817 class CaseClauseNode : public Node {
818 public:
819 CaseClauseNode(Node *e) : expr(e), list(0) { }
820 CaseClauseNode(Node *e, StatListNode *l)
821 : expr(e), list(l->list) { l->list = 0; }
822 ValueImp *evaluate(ExecState *exec);
823 Completion evalStatements(ExecState *exec);
824 virtual void processVarDecls(ExecState *exec);
825 virtual void streamTo(SourceStream &s) const;
826 private:
827 KXMLCore::SharedPtr<Node> expr;
828 KXMLCore::SharedPtr<StatListNode> list;
829 };
830
831 class ClauseListNode : public Node {
832 public:
833 // list pointer is tail of a circular list, cracked in the CaseBlockNode ctor
834 ClauseListNode(CaseClauseNode *c) : cl(c), nx(this) { }
835 ClauseListNode(ClauseListNode *n, CaseClauseNode *c)
836 : cl(c), nx(n->nx) { n->nx = this; }
837 ValueImp *evaluate(ExecState *exec);
838 CaseClauseNode *clause() const { return cl.get(); }
839 ClauseListNode *next() const { return nx.get(); }
840 virtual void processVarDecls(ExecState *exec);
841 virtual void streamTo(SourceStream &s) const;
842 private:
843 friend class CaseBlockNode;
844 KXMLCore::SharedPtr<CaseClauseNode> cl;
845 KXMLCore::SharedPtr<ClauseListNode> nx;
846 };
847
848 class CaseBlockNode : public Node {
849 public:
850 CaseBlockNode(ClauseListNode *l1, CaseClauseNode *d, ClauseListNode *l2);
851 ValueImp *evaluate(ExecState *exec);
852 Completion evalBlock(ExecState *exec, ValueImp *input);
853 virtual void processVarDecls(ExecState *exec);
854 virtual void streamTo(SourceStream &s) const;
855 private:
856 KXMLCore::SharedPtr<ClauseListNode> list1;
857 KXMLCore::SharedPtr<CaseClauseNode> def;
858 KXMLCore::SharedPtr<ClauseListNode> list2;
859 };
860
861 class SwitchNode : public StatementNode {
862 public:
863 SwitchNode(Node *e, CaseBlockNode *b) : expr(e), block(b) { }
864 virtual Completion execute(ExecState *exec);
865 virtual void processVarDecls(ExecState *exec);
866 virtual void streamTo(SourceStream &s) const;
867 private:
868 KXMLCore::SharedPtr<Node> expr;
869 KXMLCore::SharedPtr<CaseBlockNode> block;
870 };
871
872 class LabelNode : public StatementNode {
873 public:
874 LabelNode(const Identifier &l, StatementNode *s) : label(l), statement(s) { }
875 virtual Completion execute(ExecState *exec);
876 virtual void processVarDecls(ExecState *exec);
877 virtual void streamTo(SourceStream &s) const;
878 private:
879 Identifier label;
880 KXMLCore::SharedPtr<StatementNode> statement;
881 };
882
883 class ThrowNode : public StatementNode {
884 public:
885 ThrowNode(Node *e) : expr(e) {}
886 virtual Completion execute(ExecState *exec);
887 virtual void streamTo(SourceStream &s) const;
888 private:
889 KXMLCore::SharedPtr<Node> expr;
890 };
891
892 class CatchNode : public StatementNode {
893 public:
894 CatchNode(const Identifier &i, StatementNode *b) : ident(i), block(b) {}
895 virtual Completion execute(ExecState *exec);
896 Completion execute(ExecState *exec, ValueImp *arg);
897 virtual void processVarDecls(ExecState *exec);
898 virtual void streamTo(SourceStream &s) const;
899 private:
900 Identifier ident;
901 KXMLCore::SharedPtr<StatementNode> block;
902 };
903
904 class FinallyNode : public StatementNode {
905 public:
906 FinallyNode(StatementNode *b) : block(b) {}
907 virtual Completion execute(ExecState *exec);
908 virtual void processVarDecls(ExecState *exec);
909 virtual void streamTo(SourceStream &s) const;
910 private:
911 KXMLCore::SharedPtr<StatementNode> block;
912 };
913
914 class TryNode : public StatementNode {
915 public:
916 TryNode(StatementNode *b, CatchNode *c)
917 : block(b), _catch(c), _final(0) {}
918 TryNode(StatementNode *b, FinallyNode *f)
919 : block(b), _catch(0), _final(f) {}
920 TryNode(StatementNode *b, CatchNode *c, FinallyNode *f)
921 : block(b), _catch(c), _final(f) {}
922 virtual Completion execute(ExecState *exec);
923 virtual void processVarDecls(ExecState *exec);
924 virtual void streamTo(SourceStream &s) const;
925 private:
926 KXMLCore::SharedPtr<StatementNode> block;
927 KXMLCore::SharedPtr<CatchNode> _catch;
928 KXMLCore::SharedPtr<FinallyNode> _final;
929 };
930
931 class ParameterNode : public Node {
932 public:
933 // list pointer is tail of a circular list, cracked in the FuncDeclNode/FuncExprNode ctor
934 ParameterNode(const Identifier &i) : id(i), next(this) { }
935 ParameterNode(ParameterNode *list, const Identifier &i)
936 : id(i), next(list->next) { list->next = this; }
937 ValueImp *evaluate(ExecState *exec);
938 Identifier ident() { return id; }
939 ParameterNode *nextParam() { return next.get(); }
940 virtual void streamTo(SourceStream &s) const;
941 private:
942 friend class FuncDeclNode;
943 friend class FuncExprNode;
944 Identifier id;
945 KXMLCore::SharedPtr<ParameterNode> next;
946 };
947
948 // inherited by ProgramNode
949 class FunctionBodyNode : public BlockNode {
950 public:
951 FunctionBodyNode(SourceElementsNode *s);
952 void processFuncDecl(ExecState *exec);
953 };
954
955 class FuncDeclNode : public StatementNode {
956 public:
957 FuncDeclNode(const Identifier &i, FunctionBodyNode *b)
958 : ident(i), param(0), body(b) { }
959 FuncDeclNode(const Identifier &i, ParameterNode *p, FunctionBodyNode *b)
960 : ident(i), param(p->next), body(b) { p->next = 0; }
961 Completion execute(ExecState */*exec*/)
962 { /* empty */ return Completion(); }
963 void processFuncDecl(ExecState *exec);
964 virtual void streamTo(SourceStream &s) const;
965 private:
966 Identifier ident;
967 KXMLCore::SharedPtr<ParameterNode> param;
968 KXMLCore::SharedPtr<FunctionBodyNode> body;
969 };
970
971 class FuncExprNode : public Node {
972 public:
973 FuncExprNode(const Identifier &i, FunctionBodyNode *b)
974 : ident(i), param(0), body(b) { }
975 FuncExprNode(const Identifier &i, ParameterNode *p, FunctionBodyNode *b)
976 : ident(i), param(p->next), body(b) { p->next = 0; }
977 ValueImp *evaluate(ExecState *exec);
978 virtual void streamTo(SourceStream &s) const;
979 private:
980 Identifier ident;
981 KXMLCore::SharedPtr<ParameterNode> param;
982 KXMLCore::SharedPtr<FunctionBodyNode> body;
983 };
984
985 // A linked list of source element nodes
986 class SourceElementsNode : public StatementNode {
987 public:
988 // list pointer is tail of a circular list, cracked in the BlockNode (or subclass) ctor
989 SourceElementsNode(StatementNode *s1);
990 SourceElementsNode(SourceElementsNode *s1, StatementNode *s2);
991
992 Completion execute(ExecState *exec);
993 void processFuncDecl(ExecState *exec);
994 virtual void processVarDecls(ExecState *exec);
995 virtual void streamTo(SourceStream &s) const;
996 private:
997 friend class BlockNode;
998 KXMLCore::SharedPtr<StatementNode> element; // 'this' element
999 KXMLCore::SharedPtr<SourceElementsNode> elements; // pointer to next
1000 };
1001
1002 class ProgramNode : public FunctionBodyNode {
1003 public:
1004 ProgramNode(SourceElementsNode *s);
1005 };
1006
1007} // namespace
1008
1009#endif
Note: See TracBrowser for help on using the repository browser.