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

Last change on this file since 13598 was 13593, checked in by eseidel, 19 years ago

2006-03-30 Eric Seidel <[email protected]>

Reviewed by ggaren.

  • kjs/nodes.h: Some various small style fixes.
  • Property allow-tabs set to x
  • Property svn:eol-style set to native
File size: 32.8 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, 2004, 2005, 2006 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 Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 *
23 */
24
25#ifndef NODES_H_
26#define NODES_H_
27
28#include "Parser.h"
29#include "internal.h"
30#include <kxmlcore/ListRefPtr.h>
31#include <kxmlcore/RefPtr.h>
32
33namespace KJS {
34
35 class ProgramNode;
36 class PropertyNameNode;
37 class PropertyListNode;
38 class Reference;
39 class RegExp;
40 class SourceElementsNode;
41 class SourceStream;
42
43 enum Operator { OpEqual,
44 OpEqEq,
45 OpNotEq,
46 OpStrEq,
47 OpStrNEq,
48 OpPlusEq,
49 OpMinusEq,
50 OpMultEq,
51 OpDivEq,
52 OpPlusPlus,
53 OpMinusMinus,
54 OpLess,
55 OpLessEq,
56 OpGreater,
57 OpGreaterEq,
58 OpAndEq,
59 OpXOrEq,
60 OpOrEq,
61 OpModEq,
62 OpAnd,
63 OpOr,
64 OpBitAnd,
65 OpBitXOr,
66 OpBitOr,
67 OpLShift,
68 OpRShift,
69 OpURShift,
70 OpIn,
71 OpInstanceOf
72 };
73
74 class Node {
75 public:
76 Node();
77 virtual ~Node();
78
79 virtual JSValue *evaluate(ExecState *exec) = 0;
80 UString toString() const;
81 virtual void streamTo(SourceStream&) const = 0;
82 virtual void processVarDecls(ExecState*) {}
83 int lineNo() const { return m_line; }
84
85 void ref();
86 void deref();
87 unsigned refcount();
88 static void clearNewNodes();
89
90 virtual Node *nodeInsideAllParens();
91
92 virtual bool isLocation() const { return false; }
93 virtual bool isResolveNode() const { return false; }
94 virtual bool isBracketAccessorNode() const { return false; }
95 virtual bool isDotAccessorNode() const { return false; }
96 virtual bool isGroupNode() const { return false; }
97
98 virtual void breakCycle() { }
99
100 protected:
101 Completion createErrorCompletion(ExecState *, ErrorType, const char *msg);
102 Completion createErrorCompletion(ExecState *, ErrorType, const char *msg, const Identifier &);
103
104 JSValue *throwError(ExecState *, ErrorType, const char *msg);
105 JSValue *throwError(ExecState *, ErrorType, const char *msg, JSValue *, Node *);
106 JSValue *throwError(ExecState *, ErrorType, const char *msg, const Identifier &);
107 JSValue *throwError(ExecState *, ErrorType, const char *msg, JSValue *, const Identifier &);
108 JSValue *throwError(ExecState *, ErrorType, const char *msg, JSValue *, Node *, Node *);
109 JSValue *throwError(ExecState *, ErrorType, const char *msg, JSValue *, Node *, const Identifier &);
110
111 JSValue *throwUndefinedVariableError(ExecState *, const Identifier &);
112
113 void setExceptionDetailsIfNeeded(ExecState*);
114
115 int m_line;
116 private:
117 // disallow assignment
118 Node& operator=(const Node&);
119 Node(const Node &other);
120 };
121
122 class StatementNode : public Node {
123 public:
124 StatementNode();
125 void setLoc(int line0, int line1);
126 int firstLine() const { return lineNo(); }
127 int lastLine() const { return m_lastLine; }
128 bool hitStatement(ExecState*);
129 virtual Completion execute(ExecState *exec) = 0;
130 void pushLabel(const Identifier &id) { ls.push(id); }
131 virtual void processFuncDecl(ExecState*);
132 protected:
133 LabelStack ls;
134 private:
135 JSValue *evaluate(ExecState*) { return jsUndefined(); }
136 int m_lastLine;
137 };
138
139 class NullNode : public Node {
140 public:
141 NullNode() {}
142 JSValue* evaluate(ExecState*);
143 virtual void streamTo(SourceStream&) const;
144 };
145
146 class BooleanNode : public Node {
147 public:
148 BooleanNode(bool v) : value(v) {}
149 JSValue* evaluate(ExecState*);
150 virtual void streamTo(SourceStream&) const;
151 private:
152 bool value;
153 };
154
155 class NumberNode : public Node {
156 public:
157 NumberNode(double v) : value(v) {}
158 JSValue* evaluate(ExecState*);
159 virtual void streamTo(SourceStream&) const;
160 private:
161 double value;
162 };
163
164 class StringNode : public Node {
165 public:
166 StringNode(const UString *v) { value = *v; }
167 JSValue* evaluate(ExecState*);
168 virtual void streamTo(SourceStream&) 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 JSValue* evaluate(ExecState*);
178 virtual void streamTo(SourceStream&) const;
179 private:
180 UString pattern, flags;
181 };
182
183 class ThisNode : public Node {
184 public:
185 ThisNode() {}
186 JSValue* evaluate(ExecState*);
187 virtual void streamTo(SourceStream&) const;
188 };
189
190 class ResolveNode : public Node {
191 public:
192 ResolveNode(const Identifier &s) : ident(s) { }
193 JSValue* evaluate(ExecState*);
194 virtual void streamTo(SourceStream&) const;
195
196 virtual bool isLocation() const { return true; }
197 virtual bool isResolveNode() const { return true; }
198 const Identifier& identifier() const { return ident; }
199
200 private:
201 Identifier ident;
202 };
203
204 class GroupNode : public Node {
205 public:
206 GroupNode(Node *g) : group(g) { }
207 virtual JSValue* evaluate(ExecState*);
208 virtual Node *nodeInsideAllParens();
209 virtual void streamTo(SourceStream&) const;
210 virtual bool isGroupNode() const { return true; }
211 private:
212 RefPtr<Node> group;
213 };
214
215 class ElementNode : public Node {
216 public:
217 // list pointer is tail of a circular list, cracked in the ArrayNode ctor
218 ElementNode(int e, Node *n) : next(this), elision(e), node(n) { Parser::noteNodeCycle(this); }
219 ElementNode(ElementNode *l, int e, Node *n)
220 : next(l->next), elision(e), node(n) { l->next = this; }
221 JSValue* evaluate(ExecState*);
222 virtual void streamTo(SourceStream&) const;
223 PassRefPtr<ElementNode> releaseNext() { return next.release(); }
224 virtual void breakCycle();
225 private:
226 friend class ArrayNode;
227 ListRefPtr<ElementNode> next;
228 int elision;
229 RefPtr<Node> node;
230 };
231
232 class ArrayNode : public Node {
233 public:
234 ArrayNode(int e) : elision(e), opt(true) { }
235 ArrayNode(ElementNode *ele)
236 : element(ele->next), elision(0), opt(false) { Parser::removeNodeCycle(element.get()); ele->next = 0; }
237 ArrayNode(int eli, ElementNode *ele)
238 : element(ele->next), elision(eli), opt(true) { Parser::removeNodeCycle(element.get()); ele->next = 0; }
239 JSValue* evaluate(ExecState*);
240 virtual void streamTo(SourceStream&) const;
241 private:
242 RefPtr<ElementNode> element;
243 int elision;
244 bool opt;
245 };
246
247 class PropertyNameNode : public Node {
248 public:
249 PropertyNameNode(double d) : numeric(d) { }
250 PropertyNameNode(const Identifier &s) : str(s) { }
251 JSValue* evaluate(ExecState*);
252 virtual void streamTo(SourceStream&) const;
253 private:
254 double numeric;
255 Identifier str;
256 };
257
258 class PropertyNode : public Node {
259 public:
260 enum Type { Constant, Getter, Setter };
261 PropertyNode(PropertyNameNode *n, Node *a, Type t)
262 : name(n), assign(a), type(t) { }
263 JSValue* evaluate(ExecState*);
264 virtual void streamTo(SourceStream&) const;
265 friend class PropertyListNode;
266 private:
267 RefPtr<PropertyNameNode> name;
268 RefPtr<Node> assign;
269 Type type;
270 };
271
272 class PropertyListNode : public Node {
273 public:
274 // list pointer is tail of a circular list, cracked in the ObjectLiteralNode ctor
275 PropertyListNode(PropertyNode *n)
276 : node(n), next(this) { Parser::noteNodeCycle(this); }
277 PropertyListNode(PropertyNode *n, PropertyListNode *l)
278 : node(n), next(l->next) { l->next = this; }
279 JSValue* evaluate(ExecState*);
280 virtual void streamTo(SourceStream&) const;
281 PassRefPtr<PropertyListNode> releaseNext() { return next.release(); }
282 virtual void breakCycle();
283 private:
284 friend class ObjectLiteralNode;
285 RefPtr<PropertyNode> node;
286 ListRefPtr<PropertyListNode> next;
287 };
288
289 class ObjectLiteralNode : public Node {
290 public:
291 ObjectLiteralNode() { }
292 ObjectLiteralNode(PropertyListNode *l) : list(l->next) { Parser::removeNodeCycle(list.get()); l->next = 0; }
293 JSValue* evaluate(ExecState*);
294 virtual void streamTo(SourceStream&) const;
295 private:
296 RefPtr<PropertyListNode> list;
297 };
298
299 class BracketAccessorNode : public Node {
300 public:
301 BracketAccessorNode(Node *e1, Node *e2) : expr1(e1), expr2(e2) {}
302 JSValue* evaluate(ExecState*);
303 virtual void streamTo(SourceStream&) const;
304
305 virtual bool isLocation() const { return true; }
306 virtual bool isBracketAccessorNode() const { return true; }
307 Node *base() { return expr1.get(); }
308 Node *subscript() { return expr2.get(); }
309
310 private:
311 RefPtr<Node> expr1;
312 RefPtr<Node> expr2;
313 };
314
315 class DotAccessorNode : public Node {
316 public:
317 DotAccessorNode(Node *e, const Identifier &s) : expr(e), ident(s) { }
318 JSValue* evaluate(ExecState*);
319 virtual void streamTo(SourceStream&) const;
320
321 virtual bool isLocation() const { return true; }
322 virtual bool isDotAccessorNode() const { return true; }
323 Node *base() const { return expr.get(); }
324 const Identifier& identifier() const { return ident; }
325
326 private:
327 RefPtr<Node> expr;
328 Identifier ident;
329 };
330
331 class ArgumentListNode : public Node {
332 public:
333 // list pointer is tail of a circular list, cracked in the ArgumentsNode ctor
334 ArgumentListNode(Node *e) : next(this), expr(e) { Parser::noteNodeCycle(this); }
335 ArgumentListNode(ArgumentListNode *l, Node *e)
336 : next(l->next), expr(e) { l->next = this; }
337 JSValue* evaluate(ExecState*);
338 List evaluateList(ExecState*);
339 virtual void streamTo(SourceStream&) const;
340 PassRefPtr<ArgumentListNode> releaseNext() { return next.release(); }
341 virtual void breakCycle();
342 private:
343 friend class ArgumentsNode;
344 ListRefPtr<ArgumentListNode> next;
345 RefPtr<Node> expr;
346 };
347
348 class ArgumentsNode : public Node {
349 public:
350 ArgumentsNode() { }
351 ArgumentsNode(ArgumentListNode *l)
352 : list(l->next) { Parser::removeNodeCycle(list.get()); l->next = 0; }
353 JSValue* evaluate(ExecState*);
354 List evaluateList(ExecState *exec) { return list ? list->evaluateList(exec) : List(); }
355 virtual void streamTo(SourceStream&) const;
356 private:
357 RefPtr<ArgumentListNode> list;
358 };
359
360 class NewExprNode : public Node {
361 public:
362 NewExprNode(Node *e) : expr(e) {}
363 NewExprNode(Node *e, ArgumentsNode *a) : expr(e), args(a) {}
364 JSValue* evaluate(ExecState*);
365 virtual void streamTo(SourceStream&) const;
366 private:
367 RefPtr<Node> expr;
368 RefPtr<ArgumentsNode> args;
369 };
370
371 class FunctionCallValueNode : public Node {
372 public:
373 FunctionCallValueNode(Node *e, ArgumentsNode *a) : expr(e), args(a) {}
374 JSValue* evaluate(ExecState*);
375 virtual void streamTo(SourceStream&) const;
376 private:
377 RefPtr<Node> expr;
378 RefPtr<ArgumentsNode> args;
379 };
380
381 class FunctionCallResolveNode : public Node {
382 public:
383 FunctionCallResolveNode(const Identifier& i, ArgumentsNode *a) : ident(i), args(a) {}
384 JSValue* evaluate(ExecState*);
385 virtual void streamTo(SourceStream&) const;
386 private:
387 Identifier ident;
388 RefPtr<ArgumentsNode> args;
389 };
390
391 class FunctionCallBracketNode : public Node {
392 public:
393 FunctionCallBracketNode(Node *b, Node *s, ArgumentsNode *a) : base(b), subscript(s), args(a) {}
394 JSValue* evaluate(ExecState*);
395 virtual void streamTo(SourceStream&) const;
396 protected:
397 RefPtr<Node> base;
398 RefPtr<Node> subscript;
399 RefPtr<ArgumentsNode> args;
400 };
401
402 class FunctionCallParenBracketNode : public FunctionCallBracketNode {
403 public:
404 FunctionCallParenBracketNode(Node *b, Node *s, ArgumentsNode *a) : FunctionCallBracketNode(b, s, a) {}
405 virtual void streamTo(SourceStream&) const;
406 };
407
408 class FunctionCallDotNode : public Node {
409 public:
410 FunctionCallDotNode(Node *b, const Identifier &i, ArgumentsNode *a) : base(b), ident(i), args(a) {}
411 JSValue* evaluate(ExecState*);
412 virtual void streamTo(SourceStream&) const;
413 protected:
414 RefPtr<Node> base;
415 Identifier ident;
416 RefPtr<ArgumentsNode> args;
417 };
418
419 class FunctionCallParenDotNode : public FunctionCallDotNode {
420 public:
421 FunctionCallParenDotNode(Node *b, const Identifier &i, ArgumentsNode *a) : FunctionCallDotNode(b, i, a) {}
422 virtual void streamTo(SourceStream&) const;
423 };
424
425 class PostfixResolveNode : public Node {
426 public:
427 PostfixResolveNode(const Identifier& i, Operator o) : m_ident(i), m_oper(o) {}
428 JSValue* evaluate(ExecState*);
429 virtual void streamTo(SourceStream&) const;
430 private:
431 Identifier m_ident;
432 Operator m_oper;
433 };
434
435 class PostfixBracketNode : public Node {
436 public:
437 PostfixBracketNode(Node *b, Node *s, Operator o) : m_base(b), m_subscript(s), m_oper(o) {}
438 JSValue* evaluate(ExecState*);
439 virtual void streamTo(SourceStream&) const;
440 private:
441 RefPtr<Node> m_base;
442 RefPtr<Node> m_subscript;
443 Operator m_oper;
444 };
445
446 class PostfixDotNode : public Node {
447 public:
448 PostfixDotNode(Node *b, const Identifier& i, Operator o) : m_base(b), m_ident(i), m_oper(o) {}
449 JSValue* evaluate(ExecState*);
450 virtual void streamTo(SourceStream&) const;
451 private:
452 RefPtr<Node> m_base;
453 Identifier m_ident;
454 Operator m_oper;
455 };
456
457 class DeleteResolveNode : public Node {
458 public:
459 DeleteResolveNode(const Identifier& i) : m_ident(i) {}
460 JSValue* evaluate(ExecState*);
461 virtual void streamTo(SourceStream&) const;
462 private:
463 Identifier m_ident;
464 };
465
466 class DeleteBracketNode : public Node {
467 public:
468 DeleteBracketNode(Node *base, Node *subscript) : m_base(base), m_subscript(subscript) {}
469 JSValue* evaluate(ExecState*);
470 virtual void streamTo(SourceStream&) const;
471 private:
472 RefPtr<Node> m_base;
473 RefPtr<Node> m_subscript;
474 };
475
476 class DeleteDotNode : public Node {
477 public:
478 DeleteDotNode(Node *base, const Identifier& i) : m_base(base), m_ident(i) {}
479 JSValue* evaluate(ExecState*);
480 virtual void streamTo(SourceStream&) const;
481 private:
482 RefPtr<Node> m_base;
483 Identifier m_ident;
484 };
485
486 class DeleteValueNode : public Node {
487 public:
488 DeleteValueNode(Node *e) : m_expr(e) {}
489 JSValue* evaluate(ExecState*);
490 virtual void streamTo(SourceStream&) const;
491 private:
492 RefPtr<Node> m_expr;
493 };
494
495 class VoidNode : public Node {
496 public:
497 VoidNode(Node *e) : expr(e) {}
498 JSValue* evaluate(ExecState*);
499 virtual void streamTo(SourceStream&) const;
500 private:
501 RefPtr<Node> expr;
502 };
503
504 class TypeOfResolveNode : public Node {
505 public:
506 TypeOfResolveNode(const Identifier& i) : m_ident(i) {}
507 JSValue* evaluate(ExecState*);
508 virtual void streamTo(SourceStream&) const;
509 private:
510 Identifier m_ident;
511 };
512
513 class TypeOfValueNode : public Node {
514 public:
515 TypeOfValueNode(Node *e) : m_expr(e) {}
516 JSValue* evaluate(ExecState*);
517 virtual void streamTo(SourceStream&) const;
518 private:
519 RefPtr<Node> m_expr;
520 };
521
522 class PrefixResolveNode : public Node {
523 public:
524 PrefixResolveNode(const Identifier& i, Operator o) : m_ident(i), m_oper(o) {}
525 JSValue* evaluate(ExecState*);
526 virtual void streamTo(SourceStream&) const;
527 private:
528 Identifier m_ident;
529 Operator m_oper;
530 };
531
532 class PrefixBracketNode : public Node {
533 public:
534 PrefixBracketNode(Node *b, Node *s, Operator o) : m_base(b), m_subscript(s), m_oper(o) {}
535 JSValue* evaluate(ExecState*);
536 virtual void streamTo(SourceStream&) const;
537 private:
538 RefPtr<Node> m_base;
539 RefPtr<Node> m_subscript;
540 Operator m_oper;
541 };
542
543 class PrefixDotNode : public Node {
544 public:
545 PrefixDotNode(Node *b, const Identifier& i, Operator o) : m_base(b), m_ident(i), m_oper(o) {}
546 JSValue* evaluate(ExecState*);
547 virtual void streamTo(SourceStream&) const;
548 private:
549 RefPtr<Node> m_base;
550 Identifier m_ident;
551 Operator m_oper;
552 };
553
554 class UnaryPlusNode : public Node {
555 public:
556 UnaryPlusNode(Node *e) : expr(e) {}
557 JSValue* evaluate(ExecState*);
558 virtual void streamTo(SourceStream&) const;
559 private:
560 RefPtr<Node> expr;
561 };
562
563 class NegateNode : public Node {
564 public:
565 NegateNode(Node *e) : expr(e) {}
566 JSValue* evaluate(ExecState*);
567 virtual void streamTo(SourceStream&) const;
568 private:
569 RefPtr<Node> expr;
570 };
571
572 class BitwiseNotNode : public Node {
573 public:
574 BitwiseNotNode(Node *e) : expr(e) {}
575 JSValue* evaluate(ExecState*);
576 virtual void streamTo(SourceStream&) const;
577 private:
578 RefPtr<Node> expr;
579 };
580
581 class LogicalNotNode : public Node {
582 public:
583 LogicalNotNode(Node *e) : expr(e) {}
584 JSValue* evaluate(ExecState*);
585 virtual void streamTo(SourceStream&) const;
586 private:
587 RefPtr<Node> expr;
588 };
589
590 class MultNode : public Node {
591 public:
592 MultNode(Node *t1, Node *t2, char op) : term1(t1), term2(t2), oper(op) {}
593 JSValue* evaluate(ExecState*);
594 virtual void streamTo(SourceStream&) const;
595 private:
596 RefPtr<Node> term1;
597 RefPtr<Node> term2;
598 char oper;
599 };
600
601 class AddNode : public Node {
602 public:
603 AddNode(Node *t1, Node *t2, char op) : term1(t1), term2(t2), oper(op) {}
604 JSValue* evaluate(ExecState*);
605 virtual void streamTo(SourceStream&) const;
606 private:
607 RefPtr<Node> term1;
608 RefPtr<Node> term2;
609 char oper;
610 };
611
612 class ShiftNode : public Node {
613 public:
614 ShiftNode(Node *t1, Operator o, Node *t2)
615 : term1(t1), term2(t2), oper(o) {}
616 JSValue* evaluate(ExecState*);
617 virtual void streamTo(SourceStream&) const;
618 private:
619 RefPtr<Node> term1;
620 RefPtr<Node> term2;
621 Operator oper;
622 };
623
624 class RelationalNode : public Node {
625 public:
626 RelationalNode(Node *e1, Operator o, Node *e2) :
627 expr1(e1), expr2(e2), oper(o) {}
628 JSValue* evaluate(ExecState*);
629 virtual void streamTo(SourceStream&) const;
630 private:
631 RefPtr<Node> expr1;
632 RefPtr<Node> expr2;
633 Operator oper;
634 };
635
636 class EqualNode : public Node {
637 public:
638 EqualNode(Node *e1, Operator o, Node *e2)
639 : expr1(e1), expr2(e2), oper(o) {}
640 JSValue* evaluate(ExecState*);
641 virtual void streamTo(SourceStream&) const;
642 private:
643 RefPtr<Node> expr1;
644 RefPtr<Node> expr2;
645 Operator oper;
646 };
647
648 class BitOperNode : public Node {
649 public:
650 BitOperNode(Node *e1, Operator o, Node *e2) :
651 expr1(e1), expr2(e2), oper(o) {}
652 JSValue* evaluate(ExecState*);
653 virtual void streamTo(SourceStream&) const;
654 private:
655 RefPtr<Node> expr1;
656 RefPtr<Node> expr2;
657 Operator oper;
658 };
659
660 /**
661 * expr1 && expr2, expr1 || expr2
662 */
663 class BinaryLogicalNode : public Node {
664 public:
665 BinaryLogicalNode(Node *e1, Operator o, Node *e2) :
666 expr1(e1), expr2(e2), oper(o) {}
667 JSValue* evaluate(ExecState*);
668 virtual void streamTo(SourceStream&) const;
669 private:
670 RefPtr<Node> expr1;
671 RefPtr<Node> expr2;
672 Operator oper;
673 };
674
675 /**
676 * The ternary operator, "logical ? expr1 : expr2"
677 */
678 class ConditionalNode : public Node {
679 public:
680 ConditionalNode(Node *l, Node *e1, Node *e2) :
681 logical(l), expr1(e1), expr2(e2) {}
682 JSValue* evaluate(ExecState*);
683 virtual void streamTo(SourceStream&) const;
684 private:
685 RefPtr<Node> logical;
686 RefPtr<Node> expr1;
687 RefPtr<Node> expr2;
688 };
689
690 class AssignResolveNode : public Node {
691 public:
692 AssignResolveNode(const Identifier &ident, Operator oper, Node *right)
693 : m_ident(ident), m_oper(oper), m_right(right) {}
694 JSValue* evaluate(ExecState*);
695 virtual void streamTo(SourceStream&) const;
696 protected:
697 Identifier m_ident;
698 Operator m_oper;
699 RefPtr<Node> m_right;
700 };
701
702 class AssignBracketNode : public Node {
703 public:
704 AssignBracketNode(Node *base, Node *subscript, Operator oper, Node *right)
705 : m_base(base), m_subscript(subscript), m_oper(oper), m_right(right) {}
706 JSValue* evaluate(ExecState*);
707 virtual void streamTo(SourceStream&) const;
708 protected:
709 RefPtr<Node> m_base;
710 RefPtr<Node> m_subscript;
711 Operator m_oper;
712 RefPtr<Node> m_right;
713 };
714
715 class AssignDotNode : public Node {
716 public:
717 AssignDotNode(Node *base, const Identifier& ident, Operator oper, Node *right)
718 : m_base(base), m_ident(ident), m_oper(oper), m_right(right) {}
719 JSValue* evaluate(ExecState*);
720 virtual void streamTo(SourceStream&) const;
721 protected:
722 RefPtr<Node> m_base;
723 Identifier m_ident;
724 Operator m_oper;
725 RefPtr<Node> m_right;
726 };
727
728 class CommaNode : public Node {
729 public:
730 CommaNode(Node *e1, Node *e2) : expr1(e1), expr2(e2) {}
731 JSValue* evaluate(ExecState*);
732 virtual void streamTo(SourceStream&) const;
733 private:
734 RefPtr<Node> expr1;
735 RefPtr<Node> expr2;
736 };
737
738 class StatListNode : public StatementNode {
739 public:
740 // list pointer is tail of a circular list, cracked in the CaseClauseNode ctor
741 StatListNode(StatementNode *s);
742 StatListNode(StatListNode *l, StatementNode *s);
743 virtual Completion execute(ExecState*);
744 virtual void processVarDecls(ExecState*);
745 virtual void streamTo(SourceStream&) const;
746 PassRefPtr<StatListNode> releaseNext() { return next.release(); }
747 virtual void breakCycle();
748 private:
749 friend class CaseClauseNode;
750 RefPtr<StatementNode> statement;
751 ListRefPtr<StatListNode> next;
752 };
753
754 class AssignExprNode : public Node {
755 public:
756 AssignExprNode(Node *e) : expr(e) {}
757 JSValue* evaluate(ExecState*);
758 virtual void streamTo(SourceStream&) const;
759 private:
760 RefPtr<Node> expr;
761 };
762
763 class VarDeclNode : public Node {
764 public:
765 enum Type { Variable, Constant };
766 VarDeclNode(const Identifier &id, AssignExprNode *in, Type t);
767 JSValue* evaluate(ExecState*);
768 virtual void processVarDecls(ExecState*);
769 virtual void streamTo(SourceStream&) const;
770 private:
771 Type varType;
772 Identifier ident;
773 RefPtr<AssignExprNode> init;
774 };
775
776 class VarDeclListNode : public Node {
777 public:
778 // list pointer is tail of a circular list, cracked in the ForNode/VarStatementNode ctor
779 VarDeclListNode(VarDeclNode *v) : next(this), var(v) { Parser::noteNodeCycle(this); }
780 VarDeclListNode(VarDeclListNode *l, VarDeclNode *v)
781 : next(l->next), var(v) { l->next = this; }
782 JSValue* evaluate(ExecState*);
783 virtual void processVarDecls(ExecState*);
784 virtual void streamTo(SourceStream&) const;
785 PassRefPtr<VarDeclListNode> releaseNext() { return next.release(); }
786 virtual void breakCycle();
787 private:
788 friend class ForNode;
789 friend class VarStatementNode;
790 ListRefPtr<VarDeclListNode> next;
791 RefPtr<VarDeclNode> var;
792 };
793
794 class VarStatementNode : public StatementNode {
795 public:
796 VarStatementNode(VarDeclListNode *l) : next(l->next) { Parser::removeNodeCycle(next.get()); l->next = 0; }
797 virtual Completion execute(ExecState*);
798 virtual void processVarDecls(ExecState*);
799 virtual void streamTo(SourceStream&) const;
800 private:
801 RefPtr<VarDeclListNode> next;
802 };
803
804 class BlockNode : public StatementNode {
805 public:
806 BlockNode(SourceElementsNode *s);
807 virtual Completion execute(ExecState*);
808 virtual void processVarDecls(ExecState*);
809 virtual void streamTo(SourceStream&) const;
810 protected:
811 RefPtr<SourceElementsNode> source;
812 };
813
814 class EmptyStatementNode : public StatementNode {
815 public:
816 EmptyStatementNode() { } // debug
817 virtual Completion execute(ExecState*);
818 virtual void streamTo(SourceStream&) const;
819 };
820
821 class ExprStatementNode : public StatementNode {
822 public:
823 ExprStatementNode(Node *e) : expr(e) { }
824 virtual Completion execute(ExecState*);
825 virtual void streamTo(SourceStream&) const;
826 private:
827 RefPtr<Node> expr;
828 };
829
830 class IfNode : public StatementNode {
831 public:
832 IfNode(Node *e, StatementNode *s1, StatementNode *s2)
833 : expr(e), statement1(s1), statement2(s2) {}
834 virtual Completion execute(ExecState*);
835 virtual void processVarDecls(ExecState*);
836 virtual void streamTo(SourceStream&) const;
837 private:
838 RefPtr<Node> expr;
839 RefPtr<StatementNode> statement1;
840 RefPtr<StatementNode> statement2;
841 };
842
843 class DoWhileNode : public StatementNode {
844 public:
845 DoWhileNode(StatementNode *s, Node *e) : statement(s), expr(e) {}
846 virtual Completion execute(ExecState*);
847 virtual void processVarDecls(ExecState*);
848 virtual void streamTo(SourceStream&) const;
849 private:
850 RefPtr<StatementNode> statement;
851 RefPtr<Node> expr;
852 };
853
854 class WhileNode : public StatementNode {
855 public:
856 WhileNode(Node *e, StatementNode *s) : expr(e), statement(s) {}
857 virtual Completion execute(ExecState*);
858 virtual void processVarDecls(ExecState*);
859 virtual void streamTo(SourceStream&) const;
860 private:
861 RefPtr<Node> expr;
862 RefPtr<StatementNode> statement;
863 };
864
865 class ForNode : public StatementNode {
866 public:
867 ForNode(Node *e1, Node *e2, Node *e3, StatementNode *s) :
868 expr1(e1), expr2(e2), expr3(e3), statement(s) {}
869 ForNode(VarDeclListNode *e1, Node *e2, Node *e3, StatementNode *s) :
870 expr1(e1->next), expr2(e2), expr3(e3), statement(s) { Parser::removeNodeCycle(expr1.get()); e1->next = 0; }
871 virtual Completion execute(ExecState*);
872 virtual void processVarDecls(ExecState*);
873 virtual void streamTo(SourceStream&) const;
874 private:
875 RefPtr<Node> expr1;
876 RefPtr<Node> expr2;
877 RefPtr<Node> expr3;
878 RefPtr<StatementNode> statement;
879 };
880
881 class ForInNode : public StatementNode {
882 public:
883 ForInNode(Node *l, Node *e, StatementNode *s);
884 ForInNode(const Identifier &i, AssignExprNode *in, Node *e, StatementNode *s);
885 virtual Completion execute(ExecState*);
886 virtual void processVarDecls(ExecState*);
887 virtual void streamTo(SourceStream&) const;
888 private:
889 Identifier ident;
890 RefPtr<AssignExprNode> init;
891 RefPtr<Node> lexpr;
892 RefPtr<Node> expr;
893 RefPtr<VarDeclNode> varDecl;
894 RefPtr<StatementNode> statement;
895 };
896
897 class ContinueNode : public StatementNode {
898 public:
899 ContinueNode() { }
900 ContinueNode(const Identifier &i) : ident(i) { }
901 virtual Completion execute(ExecState*);
902 virtual void streamTo(SourceStream&) const;
903 private:
904 Identifier ident;
905 };
906
907 class BreakNode : public StatementNode {
908 public:
909 BreakNode() { }
910 BreakNode(const Identifier &i) : ident(i) { }
911 virtual Completion execute(ExecState*);
912 virtual void streamTo(SourceStream&) const;
913 private:
914 Identifier ident;
915 };
916
917 class ReturnNode : public StatementNode {
918 public:
919 ReturnNode(Node *v) : value(v) {}
920 virtual Completion execute(ExecState*);
921 virtual void streamTo(SourceStream&) const;
922 private:
923 RefPtr<Node> value;
924 };
925
926 class WithNode : public StatementNode {
927 public:
928 WithNode(Node *e, StatementNode *s) : expr(e), statement(s) {}
929 virtual Completion execute(ExecState*);
930 virtual void processVarDecls(ExecState*);
931 virtual void streamTo(SourceStream&) const;
932 private:
933 RefPtr<Node> expr;
934 RefPtr<StatementNode> statement;
935 };
936
937 class CaseClauseNode : public Node {
938 public:
939 CaseClauseNode(Node *e) : expr(e) { }
940 CaseClauseNode(Node *e, StatListNode *l)
941 : expr(e), next(l->next) { Parser::removeNodeCycle(next.get()); l->next = 0; }
942 JSValue* evaluate(ExecState*);
943 Completion evalStatements(ExecState*);
944 virtual void processVarDecls(ExecState*);
945 virtual void streamTo(SourceStream&) const;
946 private:
947 RefPtr<Node> expr;
948 RefPtr<StatListNode> next;
949 };
950
951 class ClauseListNode : public Node {
952 public:
953 // list pointer is tail of a circular list, cracked in the CaseBlockNode ctor
954 ClauseListNode(CaseClauseNode *c) : clause(c), next(this) { Parser::noteNodeCycle(this); }
955 ClauseListNode(ClauseListNode *n, CaseClauseNode *c)
956 : clause(c), next(n->next) { n->next = this; }
957 JSValue* evaluate(ExecState*);
958 CaseClauseNode *getClause() const { return clause.get(); }
959 ClauseListNode *getNext() const { return next.get(); }
960 virtual void processVarDecls(ExecState*);
961 virtual void streamTo(SourceStream&) const;
962 PassRefPtr<ClauseListNode> releaseNext() { return next.release(); }
963 virtual void breakCycle();
964 private:
965 friend class CaseBlockNode;
966 RefPtr<CaseClauseNode> clause;
967 ListRefPtr<ClauseListNode> next;
968 };
969
970 class CaseBlockNode : public Node {
971 public:
972 CaseBlockNode(ClauseListNode *l1, CaseClauseNode *d, ClauseListNode *l2);
973 JSValue* evaluate(ExecState*);
974 Completion evalBlock(ExecState *exec, JSValue *input);
975 virtual void processVarDecls(ExecState*);
976 virtual void streamTo(SourceStream&) const;
977 private:
978 RefPtr<ClauseListNode> list1;
979 RefPtr<CaseClauseNode> def;
980 RefPtr<ClauseListNode> list2;
981 };
982
983 class SwitchNode : public StatementNode {
984 public:
985 SwitchNode(Node *e, CaseBlockNode *b) : expr(e), block(b) { }
986 virtual Completion execute(ExecState*);
987 virtual void processVarDecls(ExecState*);
988 virtual void streamTo(SourceStream&) const;
989 private:
990 RefPtr<Node> expr;
991 RefPtr<CaseBlockNode> block;
992 };
993
994 class LabelNode : public StatementNode {
995 public:
996 LabelNode(const Identifier &l, StatementNode *s) : label(l), statement(s) { }
997 virtual Completion execute(ExecState*);
998 virtual void processVarDecls(ExecState*);
999 virtual void streamTo(SourceStream&) const;
1000 private:
1001 Identifier label;
1002 RefPtr<StatementNode> statement;
1003 };
1004
1005 class ThrowNode : public StatementNode {
1006 public:
1007 ThrowNode(Node *e) : expr(e) {}
1008 virtual Completion execute(ExecState*);
1009 virtual void streamTo(SourceStream&) const;
1010 private:
1011 RefPtr<Node> expr;
1012 };
1013
1014 class TryNode : public StatementNode {
1015 public:
1016 TryNode(StatementNode *b, const Identifier &e, StatementNode *c, StatementNode *f)
1017 : tryBlock(b), exceptionIdent(e), catchBlock(c), finallyBlock(f) { }
1018 virtual Completion execute(ExecState*);
1019 virtual void processVarDecls(ExecState*);
1020 virtual void streamTo(SourceStream&) const;
1021 private:
1022 RefPtr<StatementNode> tryBlock;
1023 Identifier exceptionIdent;
1024 RefPtr<StatementNode> catchBlock;
1025 RefPtr<StatementNode> finallyBlock;
1026 };
1027
1028 class ParameterNode : public Node {
1029 public:
1030 // list pointer is tail of a circular list, cracked in the FuncDeclNode/FuncExprNode ctor
1031 ParameterNode(const Identifier &i) : id(i), next(this) { Parser::noteNodeCycle(this); }
1032 ParameterNode(ParameterNode *next, const Identifier &i)
1033 : id(i), next(next->next) { next->next = this; }
1034 JSValue* evaluate(ExecState*);
1035 Identifier ident() { return id; }
1036 ParameterNode *nextParam() { return next.get(); }
1037 virtual void streamTo(SourceStream&) const;
1038 PassRefPtr<ParameterNode> releaseNext() { return next.release(); }
1039 virtual void breakCycle();
1040 private:
1041 friend class FuncDeclNode;
1042 friend class FuncExprNode;
1043 Identifier id;
1044 ListRefPtr<ParameterNode> next;
1045 };
1046
1047 // inherited by ProgramNode
1048 class FunctionBodyNode : public BlockNode {
1049 public:
1050 FunctionBodyNode(SourceElementsNode *);
1051 virtual void processFuncDecl(ExecState*);
1052 int sourceId() { return m_sourceId; }
1053 const UString& sourceURL() { return m_sourceURL; }
1054 private:
1055 UString m_sourceURL;
1056 int m_sourceId;
1057 };
1058
1059 class FuncExprNode : public Node {
1060 public:
1061 FuncExprNode(const Identifier &i, FunctionBodyNode *b, ParameterNode *p = 0)
1062 : ident(i), param(p ? p->next : 0), body(b) { if (p) { Parser::removeNodeCycle(param.get()); p->next = 0; } }
1063 virtual JSValue *evaluate(ExecState*);
1064 virtual void streamTo(SourceStream&) const;
1065 private:
1066 // Used for streamTo
1067 friend class PropertyNode;
1068 Identifier ident;
1069 RefPtr<ParameterNode> param;
1070 RefPtr<FunctionBodyNode> body;
1071 };
1072
1073 class FuncDeclNode : public StatementNode {
1074 public:
1075 FuncDeclNode(const Identifier &i, FunctionBodyNode *b)
1076 : ident(i), body(b) { }
1077 FuncDeclNode(const Identifier &i, ParameterNode *p, FunctionBodyNode *b)
1078 : ident(i), param(p->next), body(b) { Parser::removeNodeCycle(param.get()); p->next = 0; }
1079 virtual Completion execute(ExecState*);
1080 virtual void processFuncDecl(ExecState*);
1081 virtual void streamTo(SourceStream&) const;
1082 private:
1083 Identifier ident;
1084 RefPtr<ParameterNode> param;
1085 RefPtr<FunctionBodyNode> body;
1086 };
1087
1088 // A linked list of source element nodes
1089 class SourceElementsNode : public StatementNode {
1090 public:
1091 static int count;
1092 // list pointer is tail of a circular list, cracked in the BlockNode (or subclass) ctor
1093 SourceElementsNode(StatementNode*);
1094 SourceElementsNode(SourceElementsNode *s1, StatementNode *s2);
1095
1096 Completion execute(ExecState*);
1097 void processFuncDecl(ExecState*);
1098 virtual void processVarDecls(ExecState*);
1099 virtual void streamTo(SourceStream&) const;
1100 PassRefPtr<SourceElementsNode> releaseNext() { return next.release(); }
1101 virtual void breakCycle();
1102 private:
1103 friend class BlockNode;
1104 RefPtr<StatementNode> node;
1105 ListRefPtr<SourceElementsNode> next;
1106 };
1107
1108 class ProgramNode : public FunctionBodyNode {
1109 public:
1110 ProgramNode(SourceElementsNode *s);
1111 };
1112
1113} // namespace
1114
1115#endif
Note: See TracBrowser for help on using the repository browser.