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

Last change on this file since 12172 was 12069, checked in by darin, 19 years ago
  • Replaced tabs with spaces in source files that had less than 10 lines with tabs.
  • Set allow-tabs Subversion property in source files that have more than 10 lines with tabs.
  • 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 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 <kxmlcore/RefPtr.h>
29#include <kxmlcore/ListRefPtr.h>
30
31#include "internal.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 &s) const = 0;
82 virtual void processVarDecls(ExecState *) {}
83 int lineNo() const { return line; }
84
85 // reference counting mechanism
86 void ref() { ++m_refcount; }
87 void deref() { --m_refcount; if (!m_refcount) delete this; }
88 unsigned int refcount() { return m_refcount; }
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 protected:
99 Completion createErrorCompletion(ExecState *, ErrorType, const char *msg);
100 Completion createErrorCompletion(ExecState *, ErrorType, const char *msg, const Identifier &);
101
102 JSValue *throwError(ExecState *, ErrorType, const char *msg);
103 JSValue *throwError(ExecState *, ErrorType, const char *msg, JSValue *, Node *);
104 JSValue *throwError(ExecState *, ErrorType, const char *msg, const Identifier &);
105 JSValue *throwError(ExecState *, ErrorType, const char *msg, JSValue *, const Identifier &);
106 JSValue *throwError(ExecState *, ErrorType, const char *msg, JSValue *, Node *, Node *);
107 JSValue *throwError(ExecState *, ErrorType, const char *msg, JSValue *, Node *, const Identifier &);
108
109 JSValue *throwUndefinedVariableError(ExecState *, const Identifier &);
110
111 void setExceptionDetailsIfNeeded(ExecState *);
112
113 int line;
114 UString sourceURL;
115 unsigned int m_refcount;
116 virtual int sourceId() const { return -1; }
117
118 private:
119 // disallow assignment
120 Node& operator=(const Node&);
121 Node(const Node &other);
122 };
123
124 class StatementNode : public Node {
125 public:
126 StatementNode();
127 void setLoc(int line0, int line1, int sourceId);
128 int firstLine() const { return l0; }
129 int lastLine() const { return l1; }
130 int sourceId() const { return sid; }
131 bool hitStatement(ExecState *exec);
132 virtual Completion execute(ExecState *exec) = 0;
133 void pushLabel(const Identifier &id) { ls.push(id); }
134 virtual void processFuncDecl(ExecState *exec);
135 protected:
136 LabelStack ls;
137 private:
138 JSValue *evaluate(ExecState */*exec*/) { return jsUndefined(); }
139 int l0, l1;
140 int sid;
141 bool breakPoint;
142 };
143
144 class NullNode : public Node {
145 public:
146 NullNode() {}
147 JSValue *evaluate(ExecState *exec);
148 virtual void streamTo(SourceStream &s) const;
149 };
150
151 class BooleanNode : public Node {
152 public:
153 BooleanNode(bool v) : value(v) {}
154 JSValue *evaluate(ExecState *exec);
155 virtual void streamTo(SourceStream &s) const;
156 private:
157 bool value;
158 };
159
160 class NumberNode : public Node {
161 public:
162 NumberNode(double v) : value(v) {}
163 JSValue *evaluate(ExecState *exec);
164 virtual void streamTo(SourceStream &s) const;
165 private:
166 double value;
167 };
168
169 class StringNode : public Node {
170 public:
171 StringNode(const UString *v) { value = *v; }
172 JSValue *evaluate(ExecState *exec);
173 virtual void streamTo(SourceStream &s) const;
174 private:
175 UString value;
176 };
177
178 class RegExpNode : public Node {
179 public:
180 RegExpNode(const UString &p, const UString &f)
181 : pattern(p), flags(f) { }
182 JSValue *evaluate(ExecState *exec);
183 virtual void streamTo(SourceStream &s) const;
184 private:
185 UString pattern, flags;
186 };
187
188 class ThisNode : public Node {
189 public:
190 ThisNode() {}
191 JSValue *evaluate(ExecState *exec);
192 virtual void streamTo(SourceStream &s) const;
193 };
194
195 class ResolveNode : public Node {
196 public:
197 ResolveNode(const Identifier &s) : ident(s) { }
198 JSValue *evaluate(ExecState *exec);
199 virtual void streamTo(SourceStream &s) const;
200
201 virtual bool isLocation() const { return true; }
202 virtual bool isResolveNode() const { return true; }
203 const Identifier& identifier() const { return ident; }
204
205 private:
206 Identifier ident;
207 };
208
209 class GroupNode : public Node {
210 public:
211 GroupNode(Node *g) : group(g) { }
212 virtual JSValue *evaluate(ExecState *exec);
213 virtual Node *nodeInsideAllParens();
214 virtual void streamTo(SourceStream &s) const;
215 virtual bool isGroupNode() const { return true; }
216 private:
217 RefPtr<Node> group;
218 };
219
220 class ElementNode : public Node {
221 public:
222 // list pointer is tail of a circular list, cracked in the ArrayNode ctor
223 ElementNode(int e, Node *n) : next(this), elision(e), node(n) { }
224 ElementNode(ElementNode *l, int e, Node *n)
225 : next(l->next), elision(e), node(n) { l->next = this; }
226 JSValue *evaluate(ExecState *exec);
227 virtual void streamTo(SourceStream &s) const;
228 PassRefPtr<ElementNode> releaseNext() { return next.release(); }
229 private:
230 friend class ArrayNode;
231 ListRefPtr<ElementNode> next;
232 int elision;
233 RefPtr<Node> node;
234 };
235
236 class ArrayNode : public Node {
237 public:
238 ArrayNode(int e) : element(0), elision(e), opt(true) { }
239 ArrayNode(ElementNode *ele)
240 : element(ele->next), elision(0), opt(false) { ele->next = 0; }
241 ArrayNode(int eli, ElementNode *ele)
242 : element(ele->next), elision(eli), opt(true) { ele->next = 0; }
243 JSValue *evaluate(ExecState *exec);
244 virtual void streamTo(SourceStream &s) const;
245 private:
246 RefPtr<ElementNode> element;
247 int elision;
248 bool opt;
249 };
250
251 class PropertyNameNode : public Node {
252 public:
253 PropertyNameNode(double d) : numeric(d) { }
254 PropertyNameNode(const Identifier &s) : str(s) { }
255 JSValue *evaluate(ExecState *exec);
256 virtual void streamTo(SourceStream &s) const;
257 private:
258 double numeric;
259 Identifier str;
260 };
261
262 class PropertyNode : public Node {
263 public:
264 enum Type { Constant, Getter, Setter };
265 PropertyNode(PropertyNameNode *n, Node *a, Type t)
266 : name(n), assign(a), type(t) { }
267 JSValue *evaluate(ExecState *exec);
268 virtual void streamTo(SourceStream &s) const;
269 friend class PropertyListNode;
270 private:
271 RefPtr<PropertyNameNode> name;
272 RefPtr<Node> assign;
273 Type type;
274 };
275
276 class PropertyListNode : public Node {
277 public:
278 // list pointer is tail of a circular list, cracked in the ObjectLiteralNode ctor
279 PropertyListNode(PropertyNode *n)
280 : node(n), next(this) { }
281 PropertyListNode(PropertyNode *n, PropertyListNode *l)
282 : node(n), next(l->next) { l->next = this; }
283 JSValue *evaluate(ExecState *exec);
284 virtual void streamTo(SourceStream &s) const;
285 PassRefPtr<PropertyListNode> releaseNext() { return next.release(); }
286 private:
287 friend class ObjectLiteralNode;
288 RefPtr<PropertyNode> node;
289 ListRefPtr<PropertyListNode> next;
290 };
291
292 class ObjectLiteralNode : public Node {
293 public:
294 ObjectLiteralNode() : list(0) { }
295 ObjectLiteralNode(PropertyListNode *l) : list(l->next) { l->next = 0; }
296 JSValue *evaluate(ExecState *exec);
297 virtual void streamTo(SourceStream &s) const;
298 private:
299 RefPtr<PropertyListNode> list;
300 };
301
302 class BracketAccessorNode : public Node {
303 public:
304 BracketAccessorNode(Node *e1, Node *e2) : expr1(e1), expr2(e2) {}
305 JSValue *evaluate(ExecState *exec);
306 virtual void streamTo(SourceStream &s) const;
307
308 virtual bool isLocation() const { return true; }
309 virtual bool isBracketAccessorNode() const { return true; }
310 Node *base() { return expr1.get(); }
311 Node *subscript() { return expr2.get(); }
312
313 private:
314 RefPtr<Node> expr1;
315 RefPtr<Node> expr2;
316 };
317
318 class DotAccessorNode : public Node {
319 public:
320 DotAccessorNode(Node *e, const Identifier &s) : expr(e), ident(s) { }
321 JSValue *evaluate(ExecState *exec);
322 virtual void streamTo(SourceStream &s) const;
323
324 virtual bool isLocation() const { return true; }
325 virtual bool isDotAccessorNode() const { return true; }
326 Node *base() const { return expr.get(); }
327 const Identifier& identifier() const { return ident; }
328
329 private:
330 RefPtr<Node> expr;
331 Identifier ident;
332 };
333
334 class ArgumentListNode : public Node {
335 public:
336 // list pointer is tail of a circular list, cracked in the ArgumentsNode ctor
337 ArgumentListNode(Node *e) : next(this), expr(e) { }
338 ArgumentListNode(ArgumentListNode *l, Node *e)
339 : next(l->next), expr(e) { l->next = this; }
340 JSValue *evaluate(ExecState *exec);
341 List evaluateList(ExecState *exec);
342 virtual void streamTo(SourceStream &s) const;
343 PassRefPtr<ArgumentListNode> releaseNext() { return next.release(); }
344 private:
345 friend class ArgumentsNode;
346 ListRefPtr<ArgumentListNode> next;
347 RefPtr<Node> expr;
348 };
349
350 class ArgumentsNode : public Node {
351 public:
352 ArgumentsNode() : list(0) { }
353 ArgumentsNode(ArgumentListNode *l)
354 : list(l->next) { l->next = 0; }
355 JSValue *evaluate(ExecState *exec);
356 List evaluateList(ExecState *exec);
357 virtual void streamTo(SourceStream &s) const;
358 private:
359 RefPtr<ArgumentListNode> list;
360 };
361
362 class NewExprNode : public Node {
363 public:
364 NewExprNode(Node *e) : expr(e), args(0) {}
365 NewExprNode(Node *e, ArgumentsNode *a) : expr(e), args(a) {}
366 JSValue *evaluate(ExecState *exec);
367 virtual void streamTo(SourceStream &s) const;
368 private:
369 RefPtr<Node> expr;
370 RefPtr<ArgumentsNode> args;
371 };
372
373 class FunctionCallValueNode : public Node {
374 public:
375 FunctionCallValueNode(Node *e, ArgumentsNode *a) : expr(e), args(a) {}
376 JSValue *evaluate(ExecState *exec);
377 virtual void streamTo(SourceStream &s) const;
378 private:
379 RefPtr<Node> expr;
380 RefPtr<ArgumentsNode> args;
381 };
382
383 class FunctionCallResolveNode : public Node {
384 public:
385 FunctionCallResolveNode(const Identifier& i, ArgumentsNode *a) : ident(i), args(a) {}
386 JSValue *evaluate(ExecState *exec);
387 virtual void streamTo(SourceStream &s) const;
388 private:
389 Identifier ident;
390 RefPtr<ArgumentsNode> args;
391 };
392
393 class FunctionCallBracketNode : public Node {
394 public:
395 FunctionCallBracketNode(Node *b, Node *s, ArgumentsNode *a) : base(b), subscript(s), args(a) {}
396 JSValue *evaluate(ExecState *exec);
397 virtual void streamTo(SourceStream &s) const;
398 protected:
399 RefPtr<Node> base;
400 RefPtr<Node> subscript;
401 RefPtr<ArgumentsNode> args;
402 };
403
404 class FunctionCallParenBracketNode : public FunctionCallBracketNode {
405 public:
406 FunctionCallParenBracketNode(Node *b, Node *s, ArgumentsNode *a) : FunctionCallBracketNode(b, s, a) {}
407 virtual void streamTo(SourceStream &s) const;
408 };
409
410 class FunctionCallDotNode : public Node {
411 public:
412 FunctionCallDotNode(Node *b, const Identifier &i, ArgumentsNode *a) : base(b), ident(i), args(a) {}
413 JSValue *evaluate(ExecState *exec);
414 virtual void streamTo(SourceStream &s) const;
415 protected:
416 RefPtr<Node> base;
417 Identifier ident;
418 RefPtr<ArgumentsNode> args;
419 };
420
421 class FunctionCallParenDotNode : public FunctionCallDotNode {
422 public:
423 FunctionCallParenDotNode(Node *b, const Identifier &i, ArgumentsNode *a) : FunctionCallDotNode(b, i, a) {}
424 virtual void streamTo(SourceStream &s) const;
425 };
426
427 class PostfixResolveNode : public Node {
428 public:
429 PostfixResolveNode(const Identifier& i, Operator o) : m_ident(i), m_oper(o) {}
430 JSValue *evaluate(ExecState *exec);
431 virtual void streamTo(SourceStream &s) const;
432 private:
433 Identifier m_ident;
434 Operator m_oper;
435 };
436
437 class PostfixBracketNode : public Node {
438 public:
439 PostfixBracketNode(Node *b, Node *s, Operator o) : m_base(b), m_subscript(s), m_oper(o) {}
440 JSValue *evaluate(ExecState *exec);
441 virtual void streamTo(SourceStream &s) const;
442 private:
443 RefPtr<Node> m_base;
444 RefPtr<Node> m_subscript;
445 Operator m_oper;
446 };
447
448 class PostfixDotNode : public Node {
449 public:
450 PostfixDotNode(Node *b, const Identifier& i, Operator o) : m_base(b), m_ident(i), m_oper(o) {}
451 JSValue *evaluate(ExecState *exec);
452 virtual void streamTo(SourceStream &s) const;
453 private:
454 RefPtr<Node> m_base;
455 Identifier m_ident;
456 Operator m_oper;
457 };
458
459 class DeleteResolveNode : public Node {
460 public:
461 DeleteResolveNode(const Identifier& i) : m_ident(i) {}
462 JSValue *evaluate(ExecState *exec);
463 virtual void streamTo(SourceStream &s) const;
464 private:
465 Identifier m_ident;
466 };
467
468 class DeleteBracketNode : public Node {
469 public:
470 DeleteBracketNode(Node *base, Node *subscript) : m_base(base), m_subscript(subscript) {}
471 JSValue *evaluate(ExecState *exec);
472 virtual void streamTo(SourceStream &s) const;
473 private:
474 RefPtr<Node> m_base;
475 RefPtr<Node> m_subscript;
476 };
477
478 class DeleteDotNode : public Node {
479 public:
480 DeleteDotNode(Node *base, const Identifier& i) : m_base(base), m_ident(i) {}
481 JSValue *evaluate(ExecState *exec);
482 virtual void streamTo(SourceStream &s) const;
483 private:
484 RefPtr<Node> m_base;
485 Identifier m_ident;
486 };
487
488 class DeleteValueNode : public Node {
489 public:
490 DeleteValueNode(Node *e) : m_expr(e) {}
491 JSValue *evaluate(ExecState *exec);
492 virtual void streamTo(SourceStream &s) const;
493 private:
494 RefPtr<Node> m_expr;
495 };
496
497 class VoidNode : public Node {
498 public:
499 VoidNode(Node *e) : expr(e) {}
500 JSValue *evaluate(ExecState *exec);
501 virtual void streamTo(SourceStream &s) const;
502 private:
503 RefPtr<Node> expr;
504 };
505
506 class TypeOfResolveNode : public Node {
507 public:
508 TypeOfResolveNode(const Identifier& i) : m_ident(i) {}
509 JSValue *evaluate(ExecState *exec);
510 virtual void streamTo(SourceStream &s) const;
511 private:
512 Identifier m_ident;
513 };
514
515 class TypeOfValueNode : public Node {
516 public:
517 TypeOfValueNode(Node *e) : m_expr(e) {}
518 JSValue *evaluate(ExecState *exec);
519 virtual void streamTo(SourceStream &s) const;
520 private:
521 RefPtr<Node> m_expr;
522 };
523
524 class PrefixResolveNode : public Node {
525 public:
526 PrefixResolveNode(const Identifier& i, Operator o) : m_ident(i), m_oper(o) {}
527 JSValue *evaluate(ExecState *exec);
528 virtual void streamTo(SourceStream &s) const;
529 private:
530 Identifier m_ident;
531 Operator m_oper;
532 };
533
534 class PrefixBracketNode : public Node {
535 public:
536 PrefixBracketNode(Node *b, Node *s, Operator o) : m_base(b), m_subscript(s), m_oper(o) {}
537 JSValue *evaluate(ExecState *exec);
538 virtual void streamTo(SourceStream &s) const;
539 private:
540 RefPtr<Node> m_base;
541 RefPtr<Node> m_subscript;
542 Operator m_oper;
543 };
544
545 class PrefixDotNode : public Node {
546 public:
547 PrefixDotNode(Node *b, const Identifier& i, Operator o) : m_base(b), m_ident(i), m_oper(o) {}
548 JSValue *evaluate(ExecState *exec);
549 virtual void streamTo(SourceStream &s) const;
550 private:
551 RefPtr<Node> m_base;
552 Identifier m_ident;
553 Operator m_oper;
554 };
555
556 class UnaryPlusNode : public Node {
557 public:
558 UnaryPlusNode(Node *e) : expr(e) {}
559 JSValue *evaluate(ExecState *exec);
560 virtual void streamTo(SourceStream &s) const;
561 private:
562 RefPtr<Node> expr;
563 };
564
565 class NegateNode : public Node {
566 public:
567 NegateNode(Node *e) : expr(e) {}
568 JSValue *evaluate(ExecState *exec);
569 virtual void streamTo(SourceStream &s) const;
570 private:
571 RefPtr<Node> expr;
572 };
573
574 class BitwiseNotNode : public Node {
575 public:
576 BitwiseNotNode(Node *e) : expr(e) {}
577 JSValue *evaluate(ExecState *exec);
578 virtual void streamTo(SourceStream &s) const;
579 private:
580 RefPtr<Node> expr;
581 };
582
583 class LogicalNotNode : public Node {
584 public:
585 LogicalNotNode(Node *e) : expr(e) {}
586 JSValue *evaluate(ExecState *exec);
587 virtual void streamTo(SourceStream &s) const;
588 private:
589 RefPtr<Node> expr;
590 };
591
592 class MultNode : public Node {
593 public:
594 MultNode(Node *t1, Node *t2, char op) : term1(t1), term2(t2), oper(op) {}
595 JSValue *evaluate(ExecState *exec);
596 virtual void streamTo(SourceStream &s) const;
597 private:
598 RefPtr<Node> term1;
599 RefPtr<Node> term2;
600 char oper;
601 };
602
603 class AddNode : public Node {
604 public:
605 AddNode(Node *t1, Node *t2, char op) : term1(t1), term2(t2), oper(op) {}
606 JSValue *evaluate(ExecState *exec);
607 virtual void streamTo(SourceStream &s) const;
608 private:
609 RefPtr<Node> term1;
610 RefPtr<Node> term2;
611 char oper;
612 };
613
614 class ShiftNode : public Node {
615 public:
616 ShiftNode(Node *t1, Operator o, Node *t2)
617 : term1(t1), term2(t2), oper(o) {}
618 JSValue *evaluate(ExecState *exec);
619 virtual void streamTo(SourceStream &s) const;
620 private:
621 RefPtr<Node> term1;
622 RefPtr<Node> term2;
623 Operator oper;
624 };
625
626 class RelationalNode : public Node {
627 public:
628 RelationalNode(Node *e1, Operator o, Node *e2) :
629 expr1(e1), expr2(e2), oper(o) {}
630 JSValue *evaluate(ExecState *exec);
631 virtual void streamTo(SourceStream &s) const;
632 private:
633 RefPtr<Node> expr1;
634 RefPtr<Node> expr2;
635 Operator oper;
636 };
637
638 class EqualNode : public Node {
639 public:
640 EqualNode(Node *e1, Operator o, Node *e2)
641 : expr1(e1), expr2(e2), oper(o) {}
642 JSValue *evaluate(ExecState *exec);
643 virtual void streamTo(SourceStream &s) const;
644 private:
645 RefPtr<Node> expr1;
646 RefPtr<Node> expr2;
647 Operator oper;
648 };
649
650 class BitOperNode : public Node {
651 public:
652 BitOperNode(Node *e1, Operator o, Node *e2) :
653 expr1(e1), expr2(e2), oper(o) {}
654 JSValue *evaluate(ExecState *exec);
655 virtual void streamTo(SourceStream &s) const;
656 private:
657 RefPtr<Node> expr1;
658 RefPtr<Node> expr2;
659 Operator oper;
660 };
661
662 /**
663 * expr1 && expr2, expr1 || expr2
664 */
665 class BinaryLogicalNode : public Node {
666 public:
667 BinaryLogicalNode(Node *e1, Operator o, Node *e2) :
668 expr1(e1), expr2(e2), oper(o) {}
669 JSValue *evaluate(ExecState *exec);
670 virtual void streamTo(SourceStream &s) const;
671 private:
672 RefPtr<Node> expr1;
673 RefPtr<Node> expr2;
674 Operator oper;
675 };
676
677 /**
678 * The ternary operator, "logical ? expr1 : expr2"
679 */
680 class ConditionalNode : public Node {
681 public:
682 ConditionalNode(Node *l, Node *e1, Node *e2) :
683 logical(l), expr1(e1), expr2(e2) {}
684 JSValue *evaluate(ExecState *exec);
685 virtual void streamTo(SourceStream &s) const;
686 private:
687 RefPtr<Node> logical;
688 RefPtr<Node> expr1;
689 RefPtr<Node> expr2;
690 };
691
692 class AssignResolveNode : public Node {
693 public:
694 AssignResolveNode(const Identifier &ident, Operator oper, Node *right)
695 : m_ident(ident), m_oper(oper), m_right(right) {}
696 JSValue *evaluate(ExecState *exec);
697 virtual void streamTo(SourceStream &s) const;
698 protected:
699 Identifier m_ident;
700 Operator m_oper;
701 RefPtr<Node> m_right;
702 };
703
704 class AssignBracketNode : public Node {
705 public:
706 AssignBracketNode(Node *base, Node *subscript, Operator oper, Node *right)
707 : m_base(base), m_subscript(subscript), m_oper(oper), m_right(right) {}
708 JSValue *evaluate(ExecState *exec);
709 virtual void streamTo(SourceStream &s) const;
710 protected:
711 RefPtr<Node> m_base;
712 RefPtr<Node> m_subscript;
713 Operator m_oper;
714 RefPtr<Node> m_right;
715 };
716
717 class AssignDotNode : public Node {
718 public:
719 AssignDotNode(Node *base, const Identifier& ident, Operator oper, Node *right)
720 : m_base(base), m_ident(ident), m_oper(oper), m_right(right) {}
721 JSValue *evaluate(ExecState *exec);
722 virtual void streamTo(SourceStream &s) const;
723 protected:
724 RefPtr<Node> m_base;
725 Identifier m_ident;
726 Operator m_oper;
727 RefPtr<Node> m_right;
728 };
729
730 class CommaNode : public Node {
731 public:
732 CommaNode(Node *e1, Node *e2) : expr1(e1), expr2(e2) {}
733 JSValue *evaluate(ExecState *exec);
734 virtual void streamTo(SourceStream &s) const;
735 private:
736 RefPtr<Node> expr1;
737 RefPtr<Node> expr2;
738 };
739
740 class StatListNode : public StatementNode {
741 public:
742 // list pointer is tail of a circular list, cracked in the CaseClauseNode ctor
743 StatListNode(StatementNode *s);
744 StatListNode(StatListNode *l, StatementNode *s);
745 virtual Completion execute(ExecState *exec);
746 virtual void processVarDecls(ExecState *exec);
747 virtual void streamTo(SourceStream &s) const;
748 PassRefPtr<StatListNode> releaseNext() { return next.release(); }
749 private:
750 friend class CaseClauseNode;
751 RefPtr<StatementNode> statement;
752 ListRefPtr<StatListNode> next;
753 };
754
755 class AssignExprNode : public Node {
756 public:
757 AssignExprNode(Node *e) : expr(e) {}
758 JSValue *evaluate(ExecState *exec);
759 virtual void streamTo(SourceStream &s) const;
760 private:
761 RefPtr<Node> expr;
762 };
763
764 class VarDeclNode : public Node {
765 public:
766 enum Type { Variable, Constant };
767 VarDeclNode(const Identifier &id, AssignExprNode *in, Type t);
768 JSValue *evaluate(ExecState *exec);
769 virtual void processVarDecls(ExecState *exec);
770 virtual void streamTo(SourceStream &s) const;
771 private:
772 Type varType;
773 Identifier ident;
774 RefPtr<AssignExprNode> init;
775 };
776
777 class VarDeclListNode : public Node {
778 public:
779 // list pointer is tail of a circular list, cracked in the ForNode/VarStatementNode ctor
780 VarDeclListNode(VarDeclNode *v) : next(this), var(v) {}
781 VarDeclListNode(VarDeclListNode *l, VarDeclNode *v)
782 : next(l->next), var(v) { l->next = this; }
783 JSValue *evaluate(ExecState *exec);
784 virtual void processVarDecls(ExecState *exec);
785 virtual void streamTo(SourceStream &s) const;
786 PassRefPtr<VarDeclListNode> releaseNext() { return next.release(); }
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) { l->next = 0; }
797 virtual Completion execute(ExecState *exec);
798 virtual void processVarDecls(ExecState *exec);
799 virtual void streamTo(SourceStream &s) 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 *exec);
808 virtual void processVarDecls(ExecState *exec);
809 virtual void streamTo(SourceStream &s) const;
810 protected:
811 RefPtr<SourceElementsNode> source;
812 };
813
814 class EmptyStatementNode : public StatementNode {
815 public:
816 EmptyStatementNode() { } // debug
817 virtual Completion execute(ExecState *exec);
818 virtual void streamTo(SourceStream &s) const;
819 };
820
821 class ExprStatementNode : public StatementNode {
822 public:
823 ExprStatementNode(Node *e) : expr(e) { }
824 virtual Completion execute(ExecState *exec);
825 virtual void streamTo(SourceStream &s) 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 *exec);
835 virtual void processVarDecls(ExecState *exec);
836 virtual void streamTo(SourceStream &s) 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 *exec);
847 virtual void processVarDecls(ExecState *exec);
848 virtual void streamTo(SourceStream &s) 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 *exec);
858 virtual void processVarDecls(ExecState *exec);
859 virtual void streamTo(SourceStream &s) 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) { e1->next = 0; }
871 virtual Completion execute(ExecState *exec);
872 virtual void processVarDecls(ExecState *exec);
873 virtual void streamTo(SourceStream &s) 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 *exec);
886 virtual void processVarDecls(ExecState *exec);
887 virtual void streamTo(SourceStream &s) 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 *exec);
902 virtual void streamTo(SourceStream &s) 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 *exec);
912 virtual void streamTo(SourceStream &s) 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 *exec);
921 virtual void streamTo(SourceStream &s) 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 *exec);
930 virtual void processVarDecls(ExecState *exec);
931 virtual void streamTo(SourceStream &s) 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), next(0) { }
940 CaseClauseNode(Node *e, StatListNode *l)
941 : expr(e), next(l->next) { l->next = 0; }
942 JSValue *evaluate(ExecState *exec);
943 Completion evalStatements(ExecState *exec);
944 virtual void processVarDecls(ExecState *exec);
945 virtual void streamTo(SourceStream &s) 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) { }
955 ClauseListNode(ClauseListNode *n, CaseClauseNode *c)
956 : clause(c), next(n->next) { n->next = this; }
957 JSValue *evaluate(ExecState *exec);
958 CaseClauseNode *getClause() const { return clause.get(); }
959 ClauseListNode *getNext() const { return next.get(); }
960 virtual void processVarDecls(ExecState *exec);
961 virtual void streamTo(SourceStream &s) const;
962 PassRefPtr<ClauseListNode> releaseNext() { return next.release(); }
963 private:
964 friend class CaseBlockNode;
965 RefPtr<CaseClauseNode> clause;
966 ListRefPtr<ClauseListNode> next;
967 };
968
969 class CaseBlockNode : public Node {
970 public:
971 CaseBlockNode(ClauseListNode *l1, CaseClauseNode *d, ClauseListNode *l2);
972 JSValue *evaluate(ExecState *exec);
973 Completion evalBlock(ExecState *exec, JSValue *input);
974 virtual void processVarDecls(ExecState *exec);
975 virtual void streamTo(SourceStream &s) const;
976 private:
977 RefPtr<ClauseListNode> list1;
978 RefPtr<CaseClauseNode> def;
979 RefPtr<ClauseListNode> list2;
980 };
981
982 class SwitchNode : public StatementNode {
983 public:
984 SwitchNode(Node *e, CaseBlockNode *b) : expr(e), block(b) { }
985 virtual Completion execute(ExecState *exec);
986 virtual void processVarDecls(ExecState *exec);
987 virtual void streamTo(SourceStream &s) const;
988 private:
989 RefPtr<Node> expr;
990 RefPtr<CaseBlockNode> block;
991 };
992
993 class LabelNode : public StatementNode {
994 public:
995 LabelNode(const Identifier &l, StatementNode *s) : label(l), statement(s) { }
996 virtual Completion execute(ExecState *exec);
997 virtual void processVarDecls(ExecState *exec);
998 virtual void streamTo(SourceStream &s) const;
999 private:
1000 Identifier label;
1001 RefPtr<StatementNode> statement;
1002 };
1003
1004 class ThrowNode : public StatementNode {
1005 public:
1006 ThrowNode(Node *e) : expr(e) {}
1007 virtual Completion execute(ExecState *exec);
1008 virtual void streamTo(SourceStream &s) const;
1009 private:
1010 RefPtr<Node> expr;
1011 };
1012
1013 class TryNode : public StatementNode {
1014 public:
1015 TryNode(StatementNode *b, const Identifier &e, StatementNode *c, StatementNode *f)
1016 : tryBlock(b), exceptionIdent(e), catchBlock(c), finallyBlock(f) { }
1017 virtual Completion execute(ExecState *exec);
1018 virtual void processVarDecls(ExecState *exec);
1019 virtual void streamTo(SourceStream &s) const;
1020 private:
1021 RefPtr<StatementNode> tryBlock;
1022 Identifier exceptionIdent;
1023 RefPtr<StatementNode> catchBlock;
1024 RefPtr<StatementNode> finallyBlock;
1025 };
1026
1027 class ParameterNode : public Node {
1028 public:
1029 // list pointer is tail of a circular list, cracked in the FuncDeclNode/FuncExprNode ctor
1030 ParameterNode(const Identifier &i) : id(i), next(this) { }
1031 ParameterNode(ParameterNode *next, const Identifier &i)
1032 : id(i), next(next->next) { next->next = this; }
1033 JSValue *evaluate(ExecState *exec);
1034 Identifier ident() { return id; }
1035 ParameterNode *nextParam() { return next.get(); }
1036 virtual void streamTo(SourceStream &s) const;
1037 PassRefPtr<ParameterNode> releaseNext() { return next.release(); }
1038 private:
1039 friend class FuncDeclNode;
1040 friend class FuncExprNode;
1041 Identifier id;
1042 ListRefPtr<ParameterNode> next;
1043 };
1044
1045 // inherited by ProgramNode
1046 class FunctionBodyNode : public BlockNode {
1047 public:
1048 FunctionBodyNode(SourceElementsNode *s);
1049 void processFuncDecl(ExecState *exec);
1050 };
1051
1052 class FuncExprNode : public Node {
1053 public:
1054 FuncExprNode(const Identifier &i, FunctionBodyNode *b, ParameterNode *p = 0)
1055 : ident(i), param(p ? p->next : 0), body(b) { if (p) p->next = 0; }
1056 virtual JSValue *evaluate(ExecState *);
1057 virtual void streamTo(SourceStream &) const;
1058 private:
1059 // Used for streamTo
1060 friend class PropertyNode;
1061 Identifier ident;
1062 RefPtr<ParameterNode> param;
1063 RefPtr<FunctionBodyNode> body;
1064 };
1065
1066 class FuncDeclNode : public StatementNode {
1067 public:
1068 FuncDeclNode(const Identifier &i, FunctionBodyNode *b)
1069 : ident(i), param(0), body(b) { }
1070 FuncDeclNode(const Identifier &i, ParameterNode *p, FunctionBodyNode *b)
1071 : ident(i), param(p->next), body(b) { p->next = 0; }
1072 virtual Completion execute(ExecState *);
1073 virtual void processFuncDecl(ExecState *);
1074 virtual void streamTo(SourceStream &) const;
1075 private:
1076 Identifier ident;
1077 RefPtr<ParameterNode> param;
1078 RefPtr<FunctionBodyNode> body;
1079 };
1080
1081 // A linked list of source element nodes
1082 class SourceElementsNode : public StatementNode {
1083 public:
1084 static int count;
1085 // list pointer is tail of a circular list, cracked in the BlockNode (or subclass) ctor
1086 SourceElementsNode(StatementNode *s1);
1087 SourceElementsNode(SourceElementsNode *s1, StatementNode *s2);
1088
1089 Completion execute(ExecState *exec);
1090 void processFuncDecl(ExecState *exec);
1091 virtual void processVarDecls(ExecState *exec);
1092 virtual void streamTo(SourceStream &s) const;
1093 PassRefPtr<SourceElementsNode> releaseNext() { return next.release(); }
1094 private:
1095 friend class BlockNode;
1096 RefPtr<StatementNode> node;
1097 ListRefPtr<SourceElementsNode> next;
1098 };
1099
1100 class ProgramNode : public FunctionBodyNode {
1101 public:
1102 ProgramNode(SourceElementsNode *s);
1103 };
1104
1105} // namespace
1106
1107#endif
Note: See TracBrowser for help on using the repository browser.