00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _NODES_H_
00026 #define _NODES_H_
00027
00028 #include "internal.h"
00029
00030 #ifndef NDEBUG
00031 #include <list>
00032 #include <assert.h>
00033 #endif
00034
00035 namespace KJS {
00036
00037 class RegExp;
00038 class SourceElementsNode;
00039 class ObjectLiteralNode;
00040 class PropertyNode;
00041 class SourceStream;
00042 class PropertyValueNode;
00043 class PropertyNode;
00044
00045 enum Operator { OpEqual,
00046 OpEqEq,
00047 OpNotEq,
00048 OpStrEq,
00049 OpStrNEq,
00050 OpPlusEq,
00051 OpMinusEq,
00052 OpMultEq,
00053 OpDivEq,
00054 OpPlusPlus,
00055 OpMinusMinus,
00056 OpLess,
00057 OpLessEq,
00058 OpGreater,
00059 OpGreaterEq,
00060 OpAndEq,
00061 OpXOrEq,
00062 OpOrEq,
00063 OpModEq,
00064 OpAnd,
00065 OpOr,
00066 OpBitAnd,
00067 OpBitXOr,
00068 OpBitOr,
00069 OpLShift,
00070 OpRShift,
00071 OpURShift,
00072 OpIn,
00073 OpInstanceOf
00074 };
00075
00076 class Node {
00077 public:
00078 Node();
00079 virtual ~Node();
00080
00081
00082 virtual Type type() const { return UnspecifiedType; }
00083
00087 virtual Reference evaluateReference(ExecState *exec) const;
00091 virtual Value evaluate(ExecState *exec) const;
00092 virtual bool toBoolean(ExecState *exec) const;
00093 virtual double toNumber(ExecState *exec) const;
00094 virtual UString toString(ExecState *exec) const;
00095
00096 UString toCode() const;
00097 virtual void streamTo(SourceStream &s) const = 0;
00098 virtual void processVarDecls(ExecState* ) {}
00099 int lineNo() const { return line; }
00100
00101 public:
00102
00103 virtual void ref() { refcount++; }
00104 #ifdef KJS_DEBUG_MEM
00105 virtual bool deref() { assert( refcount > 0 ); return (!--refcount); }
00106 #else
00107 virtual bool deref() { return (!--refcount); }
00108 #endif
00109
00110
00111 #ifdef KJS_DEBUG_MEM
00112 static void finalCheck();
00113 #endif
00114 protected:
00115 Value throwError(ExecState *exec, ErrorType e, const char *msg) const;
00116 Value throwError(ExecState *exec, ErrorType e, const char *msg,
00117 const Value &v, const Node *expr) const;
00118 Value throwError(ExecState *exec, ErrorType e, const char *msg, Identifier label) const;
00119 void setExceptionDetailsIfNeeded(ExecState *exec) const;
00120 int line;
00121 unsigned int refcount;
00122 virtual int sourceId() const { return -1; }
00123 private:
00124 #ifdef KJS_DEBUG_MEM
00125
00126 static std::list<Node *> *s_nodes;
00127 #endif
00128
00129 Node& operator=(const Node&);
00130 Node(const Node &other);
00131 };
00132
00133 class StatementNode : public Node {
00134 public:
00135 StatementNode();
00136 virtual ~StatementNode();
00137 void setLoc(int line0, int line1, SourceCode *src);
00138 int firstLine() const { return l0; }
00139 int lastLine() const { return l1; }
00140 int sourceId() const { return sourceCode->sid; }
00141 SourceCode *code() const { return sourceCode; }
00142 bool hitStatement(ExecState *exec);
00143 bool abortStatement(ExecState *exec);
00144 virtual Completion execute(ExecState *exec) = 0;
00145 void pushLabel(const Identifier &id) { ls.push(id); }
00146 virtual void processFuncDecl(ExecState *exec);
00147 protected:
00148 LabelStack ls;
00149 private:
00150 Reference evaluateReference(ExecState* ) const { return Reference(0,Identifier::null()); }
00151 int l0, l1;
00152 SourceCode *sourceCode;
00153 bool breakPoint;
00154 };
00155
00156 class NullNode : public Node {
00157 public:
00158 NullNode() {}
00159 virtual Value evaluate(ExecState *exec) const;
00160 virtual bool toBoolean(ExecState *exec) const;
00161 virtual double toNumber(ExecState *exec) const;
00162 virtual UString toString(ExecState *exec) const;
00163 virtual void streamTo(SourceStream &s) const;
00164 };
00165
00166 class BooleanNode : public Node {
00167 public:
00168 BooleanNode(bool v) : val(v) {}
00169 virtual Type type() const { return BooleanType; }
00170 virtual Value evaluate(ExecState *exec) const;
00171 virtual bool toBoolean(ExecState *exec) const;
00172 virtual double toNumber(ExecState *exec) const;
00173 virtual UString toString(ExecState *exec) const;
00174 virtual void streamTo(SourceStream &s) const;
00175 private:
00176 bool val;
00177 };
00178
00179 class NumberNode : public Node {
00180 public:
00181 NumberNode(double v) : val(v) { }
00182 virtual Type type() const { return NumberType; }
00183 virtual Value evaluate(ExecState *exec) const;
00184 virtual bool toBoolean(ExecState *exec) const;
00185 virtual double toNumber(ExecState *exec) const;
00186 virtual UString toString(ExecState *exec) const;
00187 virtual void streamTo(SourceStream &s) const;
00188 private:
00189 double val;
00190 };
00191
00192 class StringNode : public Node {
00193 public:
00194 StringNode(const UString *v) : val(*v) { }
00195 virtual Type type() const { return StringType; }
00196 virtual Value evaluate(ExecState *exec) const;
00197 virtual bool toBoolean(ExecState *exec) const;
00198 virtual double toNumber(ExecState *exec) const;
00199 virtual UString toString(ExecState *exec) const;
00200 virtual void streamTo(SourceStream &s) const;
00201 private:
00202 UString val;
00203 };
00204
00205 class RegExpNode : public Node {
00206 public:
00207 RegExpNode(const UString &p, const UString &f)
00208 : pattern(p), flags(f) { }
00209 virtual Value evaluate(ExecState *exec) const;
00210 virtual bool toBoolean(ExecState *exec) const;
00211 virtual void streamTo(SourceStream &s) const;
00212 private:
00213 UString pattern, flags;
00214 };
00215
00216 class ThisNode : public Node {
00217 public:
00218 ThisNode() {}
00219 virtual Value evaluate(ExecState *exec) const;
00220 virtual void streamTo(SourceStream &s) const;
00221 };
00222
00223 class ResolveNode : public Node {
00224 public:
00225 ResolveNode(const Identifier &s) : ident(s) { }
00226 Reference evaluateReference(ExecState *exec) const;
00227 virtual Value evaluate(ExecState *exec) const;
00228 virtual void streamTo(SourceStream &s) const;
00229 private:
00230 Identifier ident;
00231 };
00232
00233 class GroupNode : public Node {
00234 public:
00235 GroupNode(Node *g) : group(g) { }
00236 virtual void ref();
00237 virtual bool deref();
00238 Reference evaluateReference(ExecState *exec) const;
00239 virtual Value evaluate(ExecState *exec) const;
00240 virtual void streamTo(SourceStream &s) const;
00241 private:
00242 Node *group;
00243 };
00244
00245 class ElementNode : public Node {
00246 public:
00247
00248 ElementNode(int e, Node *n) : list(this), elision(e), node(n) { }
00249 ElementNode(ElementNode *l, int e, Node *n)
00250 : list(l->list), elision(e), node(n) { l->list = this; }
00251 virtual void ref();
00252 virtual bool deref();
00253 virtual Value evaluate(ExecState *exec) const;
00254 virtual void streamTo(SourceStream &s) const;
00255 private:
00256 friend class ArrayNode;
00257 ElementNode *list;
00258 int elision;
00259 Node *node;
00260 };
00261
00262 class ArrayNode : public Node {
00263 public:
00264 ArrayNode(int e) : element(0L), elision(e), opt(true) { }
00265 ArrayNode(ElementNode *ele)
00266 : element(ele->list), elision(0), opt(false) { ele->list = 0; }
00267 ArrayNode(int eli, ElementNode *ele)
00268 : element(ele->list), elision(eli), opt(true) { ele->list = 0; }
00269 virtual void ref();
00270 virtual bool deref();
00271 virtual Value evaluate(ExecState *exec) const;
00272 virtual void streamTo(SourceStream &s) const;
00273 private:
00274 ElementNode *element;
00275 int elision;
00276 bool opt;
00277 };
00278
00279 class PropertyValueNode : public Node {
00280 public:
00281
00282 PropertyValueNode(PropertyNode *n, Node *a)
00283 : name(n), assign(a), list(this) { }
00284 PropertyValueNode(PropertyNode *n, Node *a, PropertyValueNode *l)
00285 : name(n), assign(a), list(l->list) { l->list = this; }
00286 virtual void ref();
00287 virtual bool deref();
00288 virtual Value evaluate(ExecState *exec) const;
00289 virtual void streamTo(SourceStream &s) const;
00290 private:
00291 friend class ObjectLiteralNode;
00292 PropertyNode *name;
00293 Node *assign;
00294 PropertyValueNode *list;
00295 };
00296
00297 class PropertyNode : public Node {
00298 public:
00299 PropertyNode(double d) : numeric(d) { }
00300 PropertyNode(const Identifier &s) : str(s) { }
00301 virtual Value evaluate(ExecState *exec) const;
00302 virtual void streamTo(SourceStream &s) const;
00303 private:
00304 double numeric;
00305 Identifier str;
00306 };
00307
00308 class ObjectLiteralNode : public Node {
00309 public:
00310
00311 ObjectLiteralNode() : list(0) { }
00312
00313 ObjectLiteralNode(PropertyValueNode *l) : list(l->list) { l->list = 0; }
00314 virtual void ref();
00315 virtual bool deref();
00316 virtual Value evaluate(ExecState *exec) const;
00317 virtual void streamTo(SourceStream &s) const;
00318 private:
00319 PropertyValueNode *list;
00320 };
00321
00322 class AccessorNode1 : public Node {
00323 public:
00324 AccessorNode1(Node *e1, Node *e2) : expr1(e1), expr2(e2) {}
00325 virtual void ref();
00326 virtual bool deref();
00327 Reference evaluateReference(ExecState *exec) const;
00328 virtual void streamTo(SourceStream &s) const;
00329 private:
00330 Node *expr1;
00331 Node *expr2;
00332 };
00333
00334 class AccessorNode2 : public Node {
00335 public:
00336 AccessorNode2(Node *e, const Identifier &s) : expr(e), ident(s) { }
00337 virtual void ref();
00338 virtual bool deref();
00339 Reference evaluateReference(ExecState *exec) const;
00340 virtual void streamTo(SourceStream &s) const;
00341 private:
00342 Node *expr;
00343 Identifier ident;
00344 };
00345
00346 class ArgumentListNode : public Node {
00347 public:
00348
00349 ArgumentListNode(Node *e) : list(this), expr(e) {}
00350 ArgumentListNode(ArgumentListNode *l, Node *e)
00351 : list(l->list), expr(e) { l->list = this; }
00352 virtual void ref();
00353 virtual bool deref();
00354 virtual Value evaluate(ExecState *exec) const;
00355 List evaluateList(ExecState *exec) const;
00356 virtual void streamTo(SourceStream &s) const;
00357 private:
00358 friend class ArgumentsNode;
00359 ArgumentListNode *list;
00360 Node *expr;
00361 };
00362
00363 class ArgumentsNode : public Node {
00364 public:
00365 ArgumentsNode() : list(0) {}
00366 ArgumentsNode(ArgumentListNode *l) : list(l->list) { l->list = 0; }
00367 virtual void ref();
00368 virtual bool deref();
00369 virtual Value evaluate(ExecState *exec) const;
00370 List evaluateList(ExecState *exec) const;
00371 virtual void streamTo(SourceStream &s) const;
00372 private:
00373 ArgumentListNode *list;
00374 };
00375
00376 class NewExprNode : public Node {
00377 public:
00378 NewExprNode(Node *e) : expr(e), args(0L) {}
00379 NewExprNode(Node *e, ArgumentsNode *a) : expr(e), args(a) {}
00380 virtual void ref();
00381 virtual bool deref();
00382 virtual Value evaluate(ExecState *exec) const;
00383 virtual void streamTo(SourceStream &s) const;
00384 private:
00385 Node *expr;
00386 ArgumentsNode *args;
00387 };
00388
00389 class FunctionCallNode : public Node {
00390 public:
00391 FunctionCallNode(Node *e, ArgumentsNode *a) : expr(e), args(a) {}
00392 virtual void ref();
00393 virtual bool deref();
00394 virtual Value evaluate(ExecState *exec) const;
00395 virtual void streamTo(SourceStream &s) const;
00396 private:
00397 Node *expr;
00398 ArgumentsNode *args;
00399 };
00400
00401 class PostfixNode : public Node {
00402 public:
00403 PostfixNode(Node *e, Operator o) : expr(e), oper(o) {}
00404 virtual void ref();
00405 virtual bool deref();
00406 virtual Value evaluate(ExecState *exec) const;
00407 virtual void streamTo(SourceStream &s) const;
00408 private:
00409 Node *expr;
00410 Operator oper;
00411 };
00412
00413 class DeleteNode : public Node {
00414 public:
00415 DeleteNode(Node *e) : expr(e) {}
00416 virtual void ref();
00417 virtual bool deref();
00418 virtual Value evaluate(ExecState *exec) const;
00419 virtual void streamTo(SourceStream &s) const;
00420 private:
00421 Node *expr;
00422 };
00423
00424 class VoidNode : public Node {
00425 public:
00426 VoidNode(Node *e) : expr(e) {}
00427 virtual void ref();
00428 virtual bool deref();
00429 virtual Value evaluate(ExecState *exec) const;
00430 virtual void streamTo(SourceStream &s) const;
00431 private:
00432 Node *expr;
00433 };
00434
00435 class TypeOfNode : public Node {
00436 public:
00437 TypeOfNode(Node *e) : expr(e) {}
00438 virtual void ref();
00439 virtual bool deref();
00440 virtual Value evaluate(ExecState *exec) const;
00441 virtual void streamTo(SourceStream &s) const;
00442 private:
00443 Node *expr;
00444 };
00445
00446 class PrefixNode : public Node {
00447 public:
00448 PrefixNode(Operator o, Node *e) : oper(o), expr(e) {}
00449 virtual void ref();
00450 virtual bool deref();
00451 virtual Value evaluate(ExecState *exec) const;
00452 virtual void streamTo(SourceStream &s) const;
00453 private:
00454 Operator oper;
00455 Node *expr;
00456 };
00457
00458 class UnaryPlusNode : public Node {
00459 public:
00460 UnaryPlusNode(Node *e) : expr(e) {}
00461 virtual void ref();
00462 virtual bool deref();
00463 virtual Value evaluate(ExecState *exec) const;
00464 virtual double toNumber(ExecState *exec) const;
00465 virtual void streamTo(SourceStream &s) const;
00466 private:
00467 Node *expr;
00468 };
00469
00470 class NegateNode : public Node {
00471 public:
00472 NegateNode(Node *e) : expr(e) {}
00473 virtual void ref();
00474 virtual bool deref();
00475 virtual Value evaluate(ExecState *exec) const;
00476 virtual double toNumber(ExecState *exec) const;
00477 virtual void streamTo(SourceStream &s) const;
00478 private:
00479 Node *expr;
00480 };
00481
00482 class BitwiseNotNode : public Node {
00483 public:
00484 BitwiseNotNode(Node *e) : expr(e) {}
00485 virtual void ref();
00486 virtual bool deref();
00487 virtual Value evaluate(ExecState *exec) const;
00488 virtual void streamTo(SourceStream &s) const;
00489 private:
00490 Node *expr;
00491 };
00492
00493 class LogicalNotNode : public Node {
00494 public:
00495 LogicalNotNode(Node *e) : expr(e) {}
00496 virtual void ref();
00497 virtual bool deref();
00498 virtual Value evaluate(ExecState *exec) const;
00499 virtual bool toBoolean(ExecState *exec) const;
00500 virtual void streamTo(SourceStream &s) const;
00501 private:
00502 Node *expr;
00503 };
00504
00505 class MultNode : public Node {
00506 public:
00507 MultNode(Node *t1, Node *t2, char op) : term1(t1), term2(t2), oper(op) {}
00508 virtual void ref();
00509 virtual bool deref();
00510 virtual Value evaluate(ExecState *exec) const;
00511 virtual void streamTo(SourceStream &s) const;
00512 private:
00513 Node *term1, *term2;
00514 char oper;
00515 };
00516
00517 class AddNode : public Node {
00518 public:
00519 AddNode(Node *t1, Node *t2, char op) : term1(t1), term2(t2), oper(op) {}
00520
00521 static Node* create(Node *t1, Node *t2, char op);
00522
00523 virtual void ref();
00524 virtual bool deref();
00525 virtual Value evaluate(ExecState *exec) const;
00526 virtual void streamTo(SourceStream &s) const;
00527 private:
00528 Node *term1, *term2;
00529 char oper;
00530 };
00531
00532 class AppendStringNode : public Node {
00533 public:
00534 AppendStringNode(Node *t, const UString &s) : term(t), str(s) { }
00535 virtual void ref();
00536 virtual bool deref();
00537 virtual Value evaluate(ExecState *exec) const;
00538 virtual void streamTo(SourceStream &s) const;
00539 private:
00540 Node *term;
00541 UString str;
00542 };
00543
00544 class ShiftNode : public Node {
00545 public:
00546 ShiftNode(Node *t1, Operator o, Node *t2)
00547 : term1(t1), term2(t2), oper(o) {}
00548 virtual void ref();
00549 virtual bool deref();
00550 virtual Value evaluate(ExecState *exec) const;
00551 virtual void streamTo(SourceStream &s) const;
00552 private:
00553 Node *term1, *term2;
00554 Operator oper;
00555 };
00556
00557 class RelationalNode : public Node {
00558 public:
00559 RelationalNode(Node *e1, Operator o, Node *e2) :
00560 expr1(e1), expr2(e2), oper(o) {}
00561 virtual void ref();
00562 virtual bool deref();
00563 virtual Value evaluate(ExecState *exec) const;
00564 virtual void streamTo(SourceStream &s) const;
00565 private:
00566 Node *expr1, *expr2;
00567 Operator oper;
00568 };
00569
00570 class EqualNode : public Node {
00571 public:
00572 EqualNode(Node *e1, Operator o, Node *e2)
00573 : expr1(e1), expr2(e2), oper(o) {}
00574 virtual void ref();
00575 virtual bool deref();
00576 virtual Value evaluate(ExecState *exec) const;
00577 virtual void streamTo(SourceStream &s) const;
00578 private:
00579 Node *expr1, *expr2;
00580 Operator oper;
00581 };
00582
00583 class BitOperNode : public Node {
00584 public:
00585 BitOperNode(Node *e1, Operator o, Node *e2) :
00586 expr1(e1), expr2(e2), oper(o) {}
00587 virtual void ref();
00588 virtual bool deref();
00589 virtual Value evaluate(ExecState *exec) const;
00590 virtual void streamTo(SourceStream &s) const;
00591 private:
00592 Node *expr1, *expr2;
00593 Operator oper;
00594 };
00595
00599 class BinaryLogicalNode : public Node {
00600 public:
00601 BinaryLogicalNode(Node *e1, Operator o, Node *e2) :
00602 expr1(e1), expr2(e2), oper(o) {}
00603 virtual void ref();
00604 virtual bool deref();
00605 virtual Value evaluate(ExecState *exec) const;
00606 virtual void streamTo(SourceStream &s) const;
00607 private:
00608 Node *expr1, *expr2;
00609 Operator oper;
00610 };
00611
00615 class ConditionalNode : public Node {
00616 public:
00617 ConditionalNode(Node *l, Node *e1, Node *e2) :
00618 logical(l), expr1(e1), expr2(e2) {}
00619 virtual void ref();
00620 virtual bool deref();
00621 virtual Value evaluate(ExecState *exec) const;
00622 virtual void streamTo(SourceStream &s) const;
00623 private:
00624 Node *logical, *expr1, *expr2;
00625 };
00626
00627 class AssignNode : public Node {
00628 public:
00629 AssignNode(Node *l, Operator o, Node *e) : left(l), oper(o), expr(e) {}
00630 virtual void ref();
00631 virtual bool deref();
00632 virtual Value evaluate(ExecState *exec) const;
00633 virtual void streamTo(SourceStream &s) const;
00634 private:
00635 Node *left;
00636 Operator oper;
00637 Node *expr;
00638 };
00639
00640 class CommaNode : public Node {
00641 public:
00642 CommaNode(Node *e1, Node *e2) : expr1(e1), expr2(e2) {}
00643 virtual void ref();
00644 virtual bool deref();
00645 virtual Value evaluate(ExecState *exec) const;
00646 virtual void streamTo(SourceStream &s) const;
00647 private:
00648 Node *expr1, *expr2;
00649 };
00650
00651 class StatListNode : public StatementNode {
00652 public:
00653
00654 StatListNode(StatementNode *s);
00655 StatListNode(StatListNode *l, StatementNode *s);
00656 virtual void ref();
00657 virtual bool deref();
00658 virtual Completion execute(ExecState *exec);
00659 virtual void processVarDecls(ExecState *exec);
00660 virtual void streamTo(SourceStream &s) const;
00661 private:
00662 friend class CaseClauseNode;
00663 StatementNode *statement;
00664 StatListNode *list;
00665 };
00666
00667 class AssignExprNode : public Node {
00668 public:
00669 AssignExprNode(Node *e) : expr(e) {}
00670 virtual void ref();
00671 virtual bool deref();
00672 virtual Value evaluate(ExecState *exec) const;
00673 virtual void streamTo(SourceStream &s) const;
00674 private:
00675 Node *expr;
00676 };
00677
00678 class VarDeclNode : public Node {
00679 public:
00680 enum Type { Variable, Constant };
00681 VarDeclNode(const Identifier &id, AssignExprNode *in, Type t);
00682 virtual void ref();
00683 virtual bool deref();
00684 virtual Value evaluate(ExecState *exec) const;
00685 virtual void processVarDecls(ExecState *exec);
00686 virtual void streamTo(SourceStream &s) const;
00687 private:
00688 Type varType;
00689 Identifier ident;
00690 AssignExprNode *init;
00691 };
00692
00693 class VarDeclListNode : public Node {
00694 public:
00695
00696 VarDeclListNode(VarDeclNode *v) : list(this), var(v) {}
00697 VarDeclListNode(VarDeclListNode *l, VarDeclNode *v)
00698 : list(l->list), var(v) { l->list = this; }
00699 virtual void ref();
00700 virtual bool deref();
00701 virtual Value evaluate(ExecState *exec) const;
00702 virtual void processVarDecls(ExecState *exec);
00703 virtual void streamTo(SourceStream &s) const;
00704 private:
00705 friend class ForNode;
00706 friend class VarStatementNode;
00707 VarDeclListNode *list;
00708 VarDeclNode *var;
00709 };
00710
00711 class VarStatementNode : public StatementNode {
00712 public:
00713 VarStatementNode(VarDeclListNode *l) : list(l->list) { l->list = 0; }
00714 virtual void ref();
00715 virtual bool deref();
00716 virtual Completion execute(ExecState *exec);
00717 virtual void processVarDecls(ExecState *exec);
00718 virtual void streamTo(SourceStream &s) const;
00719 private:
00720 VarDeclListNode *list;
00721 };
00722
00723 class BlockNode : public StatementNode {
00724 public:
00725 BlockNode(SourceElementsNode *s);
00726 virtual void ref();
00727 virtual bool deref();
00728 virtual Completion execute(ExecState *exec);
00729 virtual void processVarDecls(ExecState *exec);
00730 virtual void streamTo(SourceStream &s) const;
00731 protected:
00732 SourceElementsNode *source;
00733 };
00734
00735 class EmptyStatementNode : public StatementNode {
00736 public:
00737 EmptyStatementNode() { }
00738 virtual Completion execute(ExecState *exec);
00739 virtual void streamTo(SourceStream &s) const;
00740 };
00741
00742 class ExprStatementNode : public StatementNode {
00743 public:
00744 ExprStatementNode(Node *e) : expr(e) { }
00745 virtual void ref();
00746 virtual bool deref();
00747 virtual Completion execute(ExecState *exec);
00748 virtual void streamTo(SourceStream &s) const;
00749 private:
00750 Node *expr;
00751 };
00752
00753 class IfNode : public StatementNode {
00754 public:
00755 IfNode(Node *e, StatementNode *s1, StatementNode *s2)
00756 : expr(e), statement1(s1), statement2(s2) {}
00757 virtual void ref();
00758 virtual bool deref();
00759 virtual Completion execute(ExecState *exec);
00760 virtual void processVarDecls(ExecState *exec);
00761 virtual void streamTo(SourceStream &s) const;
00762 private:
00763 Node *expr;
00764 StatementNode *statement1, *statement2;
00765 };
00766
00767 class DoWhileNode : public StatementNode {
00768 public:
00769 DoWhileNode(StatementNode *s, Node *e) : statement(s), expr(e) {}
00770 virtual void ref();
00771 virtual bool deref();
00772 virtual Completion execute(ExecState *exec);
00773 virtual void processVarDecls(ExecState *exec);
00774 virtual void streamTo(SourceStream &s) const;
00775 private:
00776 StatementNode *statement;
00777 Node *expr;
00778 };
00779
00780 class WhileNode : public StatementNode {
00781 public:
00782 WhileNode(Node *e, StatementNode *s) : expr(e), statement(s) {}
00783 virtual void ref();
00784 virtual bool deref();
00785 virtual Completion execute(ExecState *exec);
00786 virtual void processVarDecls(ExecState *exec);
00787 virtual void streamTo(SourceStream &s) const;
00788 private:
00789 Node *expr;
00790 StatementNode *statement;
00791 };
00792
00793 class ForNode : public StatementNode {
00794 public:
00795 ForNode(Node *e1, Node *e2, Node *e3, StatementNode *s) :
00796 expr1(e1), expr2(e2), expr3(e3), statement(s) {}
00797 ForNode(VarDeclListNode *e1, Node *e2, Node *e3, StatementNode *s) :
00798 expr1(e1->list), expr2(e2), expr3(e3), statement(s) { e1->list = 0; }
00799 virtual void ref();
00800 virtual bool deref();
00801 virtual Completion execute(ExecState *exec);
00802 virtual void processVarDecls(ExecState *exec);
00803 virtual void streamTo(SourceStream &s) const;
00804 private:
00805 Node *expr1, *expr2, *expr3;
00806 StatementNode *statement;
00807 };
00808
00809 class ForInNode : public StatementNode {
00810 public:
00811 ForInNode(Node *l, Node *e, StatementNode *s);
00812 ForInNode(const Identifier &i, AssignExprNode *in, Node *e, StatementNode *s);
00813 virtual void ref();
00814 virtual bool deref();
00815 virtual Completion execute(ExecState *exec);
00816 virtual void processVarDecls(ExecState *exec);
00817 virtual void streamTo(SourceStream &s) const;
00818 private:
00819 Identifier ident;
00820 AssignExprNode *init;
00821 Node *lexpr, *expr;
00822 VarDeclNode *varDecl;
00823 StatementNode *statement;
00824 };
00825
00826 class ContinueNode : public StatementNode {
00827 public:
00828 ContinueNode() { }
00829 ContinueNode(const Identifier &i) : ident(i) { }
00830 virtual Completion execute(ExecState *exec);
00831 virtual void streamTo(SourceStream &s) const;
00832 private:
00833 Identifier ident;
00834 };
00835
00836 class BreakNode : public StatementNode {
00837 public:
00838 BreakNode() { }
00839 BreakNode(const Identifier &i) : ident(i) { }
00840 virtual Completion execute(ExecState *exec);
00841 virtual void streamTo(SourceStream &s) const;
00842 private:
00843 Identifier ident;
00844 };
00845
00846 class ReturnNode : public StatementNode {
00847 public:
00848 ReturnNode(Node *v) : value(v) {}
00849 virtual void ref();
00850 virtual bool deref();
00851 virtual Completion execute(ExecState *exec);
00852 virtual void streamTo(SourceStream &s) const;
00853 private:
00854 Node *value;
00855 };
00856
00857 class WithNode : public StatementNode {
00858 public:
00859 WithNode(Node *e, StatementNode *s) : expr(e), statement(s) {}
00860 virtual void ref();
00861 virtual bool deref();
00862 virtual Completion execute(ExecState *exec);
00863 virtual void processVarDecls(ExecState *exec);
00864 virtual void streamTo(SourceStream &s) const;
00865 private:
00866 Node *expr;
00867 StatementNode *statement;
00868 };
00869
00870 class CaseClauseNode : public Node {
00871 public:
00872 CaseClauseNode(Node *e) : expr(e), list(0) { }
00873 CaseClauseNode(Node *e, StatListNode *l)
00874 : expr(e), list(l->list) { l->list = 0; }
00875 virtual void ref();
00876 virtual bool deref();
00877 virtual Value evaluate(ExecState *exec) const;
00878 Completion evalStatements(ExecState *exec) const;
00879 virtual void processVarDecls(ExecState *exec);
00880 virtual void streamTo(SourceStream &s) const;
00881 private:
00882 Node *expr;
00883 StatListNode *list;
00884 };
00885
00886 class ClauseListNode : public Node {
00887 public:
00888
00889 ClauseListNode(CaseClauseNode *c) : cl(c), nx(this) { }
00890 ClauseListNode(ClauseListNode *n, CaseClauseNode *c)
00891 : cl(c), nx(n->nx) { n->nx = this; }
00892 virtual void ref();
00893 virtual bool deref();
00894 virtual Value evaluate(ExecState *exec) const;
00895 CaseClauseNode *clause() const { return cl; }
00896 ClauseListNode *next() const { return nx; }
00897 virtual void processVarDecls(ExecState *exec);
00898 virtual void streamTo(SourceStream &s) const;
00899 private:
00900 friend class CaseBlockNode;
00901 CaseClauseNode *cl;
00902 ClauseListNode *nx;
00903 };
00904
00905 class CaseBlockNode: public Node {
00906 public:
00907 CaseBlockNode(ClauseListNode *l1, CaseClauseNode *d, ClauseListNode *l2);
00908 virtual void ref();
00909 virtual bool deref();
00910 virtual Value evaluate(ExecState *exec) const;
00911 Completion evalBlock(ExecState *exec, const Value& input) const;
00912 virtual void processVarDecls(ExecState *exec);
00913 virtual void streamTo(SourceStream &s) const;
00914 private:
00915 ClauseListNode *list1;
00916 CaseClauseNode *def;
00917 ClauseListNode *list2;
00918 };
00919
00920 class SwitchNode : public StatementNode {
00921 public:
00922 SwitchNode(Node *e, CaseBlockNode *b) : expr(e), block(b) { }
00923 virtual void ref();
00924 virtual bool deref();
00925 virtual Completion execute(ExecState *exec);
00926 virtual void processVarDecls(ExecState *exec);
00927 virtual void streamTo(SourceStream &s) const;
00928 private:
00929 Node *expr;
00930 CaseBlockNode *block;
00931 };
00932
00933 class LabelNode : public StatementNode {
00934 public:
00935 LabelNode(const Identifier &l, StatementNode *s) : label(l), statement(s) { }
00936 virtual void ref();
00937 virtual bool deref();
00938 virtual Completion execute(ExecState *exec);
00939 virtual void processVarDecls(ExecState *exec);
00940 virtual void streamTo(SourceStream &s) const;
00941 private:
00942 Identifier label;
00943 StatementNode *statement;
00944 };
00945
00946 class ThrowNode : public StatementNode {
00947 public:
00948 ThrowNode(Node *e) : expr(e) {}
00949 virtual void ref();
00950 virtual bool deref();
00951 virtual Completion execute(ExecState *exec);
00952 virtual void streamTo(SourceStream &s) const;
00953 private:
00954 Node *expr;
00955 };
00956
00957 class CatchNode : public StatementNode {
00958 public:
00959 CatchNode(const Identifier &i, StatementNode *b) : ident(i), block(b) {}
00960 virtual void ref();
00961 virtual bool deref();
00962 virtual Completion execute(ExecState *exec);
00963 Completion execute(ExecState *exec, const Value &arg);
00964 virtual void processVarDecls(ExecState *exec);
00965 virtual void streamTo(SourceStream &s) const;
00966 private:
00967 Identifier ident;
00968 StatementNode *block;
00969 };
00970
00971 class FinallyNode : public StatementNode {
00972 public:
00973 FinallyNode(StatementNode *b) : block(b) {}
00974 virtual void ref();
00975 virtual bool deref();
00976 virtual Completion execute(ExecState *exec);
00977 virtual void processVarDecls(ExecState *exec);
00978 virtual void streamTo(SourceStream &s) const;
00979 private:
00980 StatementNode *block;
00981 };
00982
00983 class TryNode : public StatementNode {
00984 public:
00985 TryNode(StatementNode *b, CatchNode *c)
00986 : block(b), _catch(c), _final(0) {}
00987 TryNode(StatementNode *b, FinallyNode *f)
00988 : block(b), _catch(0), _final(f) {}
00989 TryNode(StatementNode *b, CatchNode *c, FinallyNode *f)
00990 : block(b), _catch(c), _final(f) {}
00991 virtual void ref();
00992 virtual bool deref();
00993 virtual Completion execute(ExecState *exec);
00994 virtual void processVarDecls(ExecState *exec);
00995 virtual void streamTo(SourceStream &s) const;
00996 private:
00997 StatementNode *block;
00998 CatchNode *_catch;
00999 FinallyNode *_final;
01000 };
01001
01002 class ParameterNode : public Node {
01003 public:
01004
01005 ParameterNode(const Identifier &i) : id(i), next(this) { }
01006 ParameterNode(ParameterNode *list, const Identifier &i)
01007 : id(i), next(list->next) { list->next = this; }
01008 virtual void ref();
01009 virtual bool deref();
01010 virtual Value evaluate(ExecState *exec) const;
01011 Identifier ident() const { return id; }
01012 ParameterNode *nextParam() const { return next; }
01013 virtual void streamTo(SourceStream &s) const;
01014 private:
01015 friend class FuncDeclNode;
01016 friend class FuncExprNode;
01017 Identifier id;
01018 ParameterNode *next;
01019 };
01020
01021
01022 class FunctionBodyNode : public BlockNode {
01023 public:
01024 FunctionBodyNode(SourceElementsNode *s);
01025 virtual void processFuncDecl(ExecState *exec);
01026 };
01027
01028 class FuncDeclNode : public StatementNode {
01029 public:
01030 FuncDeclNode(const Identifier &i, FunctionBodyNode *b)
01031 : ident(i), param(0), body(b) { }
01032 FuncDeclNode(const Identifier &i, ParameterNode *p, FunctionBodyNode *b)
01033 : ident(i), param(p->next), body(b) { p->next = 0; }
01034 virtual void ref();
01035 virtual bool deref();
01036 Completion execute(ExecState* )
01037 { return Completion(); }
01038 void processFuncDecl(ExecState *exec);
01039 virtual void streamTo(SourceStream &s) const;
01040 private:
01041 Identifier ident;
01042 ParameterNode *param;
01043 FunctionBodyNode *body;
01044 };
01045
01046 class FuncExprNode : public Node {
01047 public:
01048 FuncExprNode(FunctionBodyNode *b)
01049 : param(0), body(b) { }
01050 FuncExprNode(ParameterNode *p, FunctionBodyNode *b)
01051 : param(p->next), body(b) { p->next = 0; }
01052 virtual void ref();
01053 virtual bool deref();
01054 virtual Value evaluate(ExecState *exec) const;
01055 virtual void streamTo(SourceStream &s) const;
01056 private:
01057 ParameterNode *param;
01058 FunctionBodyNode *body;
01059 };
01060
01061
01062 class SourceElementsNode : public StatementNode {
01063 public:
01064
01065 SourceElementsNode(StatementNode *s1);
01066 SourceElementsNode(SourceElementsNode *s1, StatementNode *s2);
01067 virtual void ref();
01068 virtual bool deref();
01069 Completion execute(ExecState *exec);
01070 virtual void processFuncDecl(ExecState *exec);
01071 virtual void processVarDecls(ExecState *exec);
01072 virtual void streamTo(SourceStream &s) const;
01073 private:
01074 friend class BlockNode;
01075 StatementNode *element;
01076 SourceElementsNode *elements;
01077 };
01078
01079 }
01080
01081 #endif