kjs Library API Documentation

nodes.h

00001 // -*- c-basic-offset: 2 -*-
00002 /*
00003  *  This file is part of the KDE libraries
00004  *  Copyright (C) 1999-2000, 2003 Harri Porten (porten@kde.org)
00005  *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
00006  *  Copyright (C) 2003 Apple Computer, Inc.
00007  *
00008  *  This library is free software; you can redistribute it and/or
00009  *  modify it under the terms of the GNU Library General Public
00010  *  License as published by the Free Software Foundation; either
00011  *  version 2 of the License, or (at your option) any later version.
00012  *
00013  *  This library is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  *  Library General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Library General Public License
00019  *  along with this library; see the file COPYING.LIB.  If not, write to
00020  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00021  *  Boston, MA 02111-1307, USA.
00022  *
00023  */
00024 
00025 #ifndef _NODES_H_
00026 #define _NODES_H_
00027 
00028 #include "internal.h"
00029 //#include "debugger.h"
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     // reusing Value Type here, declare new enum if required
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* /*exec*/) {}
00099     int lineNo() const { return line; }
00100 
00101   public:
00102     // reference counting mechanism
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, Value v, Node *expr) const;
00117     Value throwError(ExecState *exec, ErrorType e, const char *msg, Identifier label) const;
00118     int line;
00119     unsigned int refcount;
00120     virtual int sourceId() const { return -1; }
00121   private:
00122 #ifdef KJS_DEBUG_MEM
00123     // List of all nodes, for debugging purposes. Don't remove!
00124     static std::list<Node *> *s_nodes;
00125 #endif
00126     // disallow assignment
00127     Node& operator=(const Node&);
00128     Node(const Node &other);
00129   };
00130 
00131   class StatementNode : public Node {
00132   public:
00133     StatementNode();
00134     virtual ~StatementNode();
00135     void setLoc(int line0, int line1, SourceCode *src);
00136     int firstLine() const { return l0; }
00137     int lastLine() const { return l1; }
00138     int sourceId() const { return sourceCode->sid; }
00139     SourceCode *code() const { return sourceCode; }
00140     bool hitStatement(ExecState *exec);
00141     bool abortStatement(ExecState *exec);
00142     virtual Completion execute(ExecState *exec) = 0;
00143     void pushLabel(const Identifier &id) { ls.push(id); }
00144     virtual void processFuncDecl(ExecState *exec);
00145   protected:
00146     LabelStack ls;
00147   private:
00148     Reference evaluateReference(ExecState* /*exec*/) const { return Reference(0,Identifier::null()); }
00149     int l0, l1;
00150     SourceCode *sourceCode;
00151     bool breakPoint;
00152   };
00153 
00154   class NullNode : public Node {
00155   public:
00156     NullNode() {}
00157     virtual Value evaluate(ExecState *exec) const;
00158     virtual bool toBoolean(ExecState *exec) const;
00159     virtual double toNumber(ExecState *exec) const;
00160     virtual UString toString(ExecState *exec) const;
00161     virtual void streamTo(SourceStream &s) const;
00162   };
00163 
00164   class BooleanNode : public Node {
00165   public:
00166     BooleanNode(bool v) : val(v) {}
00167     virtual Type type() const { return BooleanType; }
00168     virtual Value evaluate(ExecState *exec) const;
00169     virtual bool toBoolean(ExecState *exec) const;
00170     virtual double toNumber(ExecState *exec) const;
00171     virtual UString toString(ExecState *exec) const;
00172     virtual void streamTo(SourceStream &s) const;
00173   private:
00174     bool val;
00175   };
00176 
00177   class NumberNode : public Node {
00178   public:
00179     NumberNode(double v) : val(v) { }
00180     virtual Type type() const { return NumberType; }
00181     virtual Value evaluate(ExecState *exec) const;
00182     virtual bool toBoolean(ExecState *exec) const;
00183     virtual double toNumber(ExecState *exec) const;
00184     virtual UString toString(ExecState *exec) const;
00185     virtual void streamTo(SourceStream &s) const;
00186   private:
00187     double val;
00188   };
00189 
00190   class StringNode : public Node {
00191   public:
00192     StringNode(const UString *v) : val(*v) { }
00193     virtual Type type() const { return StringType; }
00194     virtual Value evaluate(ExecState *exec) const;
00195     virtual bool toBoolean(ExecState *exec) const;
00196     virtual double toNumber(ExecState *exec) const;
00197     virtual UString toString(ExecState *exec) const;
00198     virtual void streamTo(SourceStream &s) const;
00199   private:
00200     UString val;
00201   };
00202 
00203   class RegExpNode : public Node {
00204   public:
00205     RegExpNode(const UString &p, const UString &f)
00206       : pattern(p), flags(f) { }
00207     virtual Value evaluate(ExecState *exec) const;
00208     virtual bool toBoolean(ExecState *exec) const;
00209     virtual void streamTo(SourceStream &s) const;
00210   private:
00211     UString pattern, flags;
00212   };
00213 
00214   class ThisNode : public Node {
00215   public:
00216     ThisNode() {}
00217     virtual Value evaluate(ExecState *exec) const;
00218     virtual void streamTo(SourceStream &s) const;
00219   };
00220 
00221   class ResolveNode : public Node {
00222   public:
00223     ResolveNode(const Identifier &s) : ident(s) { }
00224     Reference evaluateReference(ExecState *exec) const;
00225     virtual Value evaluate(ExecState *exec) const;
00226     virtual void streamTo(SourceStream &s) const;
00227   private:
00228     Identifier ident;
00229   };
00230 
00231   class GroupNode : public Node {
00232   public:
00233     GroupNode(Node *g) : group(g) { }
00234     virtual void ref();
00235     virtual bool deref();
00236     Reference evaluateReference(ExecState *exec) const;
00237     virtual Value evaluate(ExecState *exec) const;
00238     virtual void streamTo(SourceStream &s) const;
00239   private:
00240     Node *group;
00241   };
00242 
00243   class ElementNode : public Node {
00244   public:
00245     // list is circular during construction. cracked in ArrayNode ctor
00246     ElementNode(int e, Node *n) : list(this), elision(e), node(n) { }
00247     ElementNode(ElementNode *l, int e, Node *n)
00248       : list(l->list), elision(e), node(n) { l->list = this; }
00249     virtual void ref();
00250     virtual bool deref();
00251     virtual Value evaluate(ExecState *exec) const;
00252     virtual void streamTo(SourceStream &s) const;
00253   private:
00254     friend class ArrayNode;
00255     ElementNode *list;
00256     int elision;
00257     Node *node;
00258   };
00259 
00260   class ArrayNode : public Node {
00261   public:
00262     ArrayNode(int e) : element(0L), elision(e), opt(true) { }
00263     ArrayNode(ElementNode *ele)
00264       : element(ele->list), elision(0), opt(false) { ele->list = 0; }
00265     ArrayNode(int eli, ElementNode *ele)
00266       : element(ele->list), elision(eli), opt(true) { ele->list = 0; }
00267     virtual void ref();
00268     virtual bool deref();
00269     virtual Value evaluate(ExecState *exec) const;
00270     virtual void streamTo(SourceStream &s) const;
00271   private:
00272     ElementNode *element;
00273     int elision;
00274     bool opt;
00275   };
00276 
00277   class PropertyValueNode : public Node {
00278   public:
00279     // list is circular during construction, cut in ObjectLiteralNode ctor
00280     PropertyValueNode(PropertyNode *n, Node *a)
00281       : name(n), assign(a), list(this) { }
00282     PropertyValueNode(PropertyNode *n, Node *a, PropertyValueNode *l)
00283       : name(n), assign(a), list(l->list) { l->list = this; }
00284     virtual void ref();
00285     virtual bool deref();
00286     virtual Value evaluate(ExecState *exec) const;
00287     virtual void streamTo(SourceStream &s) const;
00288   private:
00289     friend class ObjectLiteralNode;
00290     PropertyNode *name;
00291     Node *assign;
00292     PropertyValueNode *list;
00293   };
00294 
00295   class PropertyNode : public Node {
00296   public:
00297     PropertyNode(double d) : numeric(d) { }
00298     PropertyNode(const Identifier &s) : str(s) { }
00299     virtual Value evaluate(ExecState *exec) const;
00300     virtual void streamTo(SourceStream &s) const;
00301   private:
00302     double numeric;
00303     Identifier str;
00304   };
00305 
00306   class ObjectLiteralNode : public Node {
00307   public:
00308     // empty literal
00309     ObjectLiteralNode() : list(0) { }
00310     // l points to last list element, get and detach pointer to first one
00311     ObjectLiteralNode(PropertyValueNode *l) : list(l->list) { l->list = 0; }
00312     virtual void ref();
00313     virtual bool deref();
00314     virtual Value evaluate(ExecState *exec) const;
00315     virtual void streamTo(SourceStream &s) const;
00316   private:
00317     PropertyValueNode *list;
00318   };
00319 
00320   class AccessorNode1 : public Node {
00321   public:
00322     AccessorNode1(Node *e1, Node *e2) : expr1(e1), expr2(e2) {}
00323     virtual void ref();
00324     virtual bool deref();
00325     Reference evaluateReference(ExecState *exec) const;
00326     virtual void streamTo(SourceStream &s) const;
00327   private:
00328     Node *expr1;
00329     Node *expr2;
00330   };
00331 
00332   class AccessorNode2 : public Node {
00333   public:
00334     AccessorNode2(Node *e, const Identifier &s) : expr(e), ident(s) { }
00335     virtual void ref();
00336     virtual bool deref();
00337     Reference evaluateReference(ExecState *exec) const;
00338     virtual void streamTo(SourceStream &s) const;
00339   private:
00340     Node *expr;
00341     Identifier ident;
00342   };
00343 
00344   class ArgumentListNode : public Node {
00345   public:
00346     // list is circular during construction. cracked in ArgumentsNode ctor
00347     ArgumentListNode(Node *e) : list(this), expr(e) {}
00348     ArgumentListNode(ArgumentListNode *l, Node *e)
00349       : list(l->list), expr(e) { l->list = this; }
00350     virtual void ref();
00351     virtual bool deref();
00352     virtual Value evaluate(ExecState *exec) const;
00353     List evaluateList(ExecState *exec) const;
00354     virtual void streamTo(SourceStream &s) const;
00355   private:
00356     friend class ArgumentsNode;
00357     ArgumentListNode *list;
00358     Node *expr;
00359   };
00360 
00361   class ArgumentsNode : public Node {
00362   public:
00363     ArgumentsNode() : list(0) {}
00364     ArgumentsNode(ArgumentListNode *l) : list(l->list) { l->list = 0; }
00365     virtual void ref();
00366     virtual bool deref();
00367     virtual Value evaluate(ExecState *exec) const;
00368     List evaluateList(ExecState *exec) const;
00369     virtual void streamTo(SourceStream &s) const;
00370   private:
00371     ArgumentListNode *list;
00372   };
00373 
00374   class NewExprNode : public Node {
00375   public:
00376     NewExprNode(Node *e) : expr(e), args(0L) {}
00377     NewExprNode(Node *e, ArgumentsNode *a) : expr(e), args(a) {}
00378     virtual void ref();
00379     virtual bool deref();
00380     virtual Value evaluate(ExecState *exec) const;
00381     virtual void streamTo(SourceStream &s) const;
00382   private:
00383     Node *expr;
00384     ArgumentsNode *args;
00385   };
00386 
00387   class FunctionCallNode : public Node {
00388   public:
00389     FunctionCallNode(Node *e, ArgumentsNode *a) : expr(e), args(a) {}
00390     virtual void ref();
00391     virtual bool deref();
00392     virtual Value evaluate(ExecState *exec) const;
00393     virtual void streamTo(SourceStream &s) const;
00394   private:
00395     Node *expr;
00396     ArgumentsNode *args;
00397   };
00398 
00399   class PostfixNode : public Node {
00400   public:
00401     PostfixNode(Node *e, Operator o) : expr(e), oper(o) {}
00402     virtual void ref();
00403     virtual bool deref();
00404     virtual Value evaluate(ExecState *exec) const;
00405     virtual void streamTo(SourceStream &s) const;
00406   private:
00407     Node *expr;
00408     Operator oper;
00409   };
00410 
00411   class DeleteNode : public Node {
00412   public:
00413     DeleteNode(Node *e) : expr(e) {}
00414     virtual void ref();
00415     virtual bool deref();
00416     virtual Value evaluate(ExecState *exec) const;
00417     virtual void streamTo(SourceStream &s) const;
00418   private:
00419     Node *expr;
00420   };
00421 
00422   class VoidNode : public Node {
00423   public:
00424     VoidNode(Node *e) : expr(e) {}
00425     virtual void ref();
00426     virtual bool deref();
00427     virtual Value evaluate(ExecState *exec) const;
00428     virtual void streamTo(SourceStream &s) const;
00429   private:
00430     Node *expr;
00431   };
00432 
00433   class TypeOfNode : public Node {
00434   public:
00435     TypeOfNode(Node *e) : expr(e) {}
00436     virtual void ref();
00437     virtual bool deref();
00438     virtual Value evaluate(ExecState *exec) const;
00439     virtual void streamTo(SourceStream &s) const;
00440   private:
00441     Node *expr;
00442   };
00443 
00444   class PrefixNode : public Node {
00445   public:
00446     PrefixNode(Operator o, Node *e) : oper(o), expr(e) {}
00447     virtual void ref();
00448     virtual bool deref();
00449     virtual Value evaluate(ExecState *exec) const;
00450     virtual void streamTo(SourceStream &s) const;
00451   private:
00452     Operator oper;
00453     Node *expr;
00454   };
00455 
00456   class UnaryPlusNode : public Node {
00457   public:
00458     UnaryPlusNode(Node *e) : expr(e) {}
00459     virtual void ref();
00460     virtual bool deref();
00461     virtual Value evaluate(ExecState *exec) const;
00462     virtual double toNumber(ExecState *exec) const;
00463     virtual void streamTo(SourceStream &s) const;
00464   private:
00465     Node *expr;
00466   };
00467 
00468   class NegateNode : public Node {
00469   public:
00470     NegateNode(Node *e) : expr(e) {}
00471     virtual void ref();
00472     virtual bool deref();
00473     virtual Value evaluate(ExecState *exec) const;
00474     virtual double toNumber(ExecState *exec) const;
00475     virtual void streamTo(SourceStream &s) const;
00476   private:
00477     Node *expr;
00478   };
00479 
00480   class BitwiseNotNode : public Node {
00481   public:
00482     BitwiseNotNode(Node *e) : expr(e) {}
00483     virtual void ref();
00484     virtual bool deref();
00485     virtual Value evaluate(ExecState *exec) const;
00486     virtual void streamTo(SourceStream &s) const;
00487   private:
00488     Node *expr;
00489   };
00490 
00491   class LogicalNotNode : public Node {
00492   public:
00493     LogicalNotNode(Node *e) : expr(e) {}
00494     virtual void ref();
00495     virtual bool deref();
00496     virtual Value evaluate(ExecState *exec) const;
00497     virtual bool toBoolean(ExecState *exec) const;
00498     virtual void streamTo(SourceStream &s) const;
00499   private:
00500     Node *expr;
00501   };
00502 
00503   class MultNode : public Node {
00504   public:
00505     MultNode(Node *t1, Node *t2, char op) : term1(t1), term2(t2), oper(op) {}
00506     virtual void ref();
00507     virtual bool deref();
00508     virtual Value evaluate(ExecState *exec) const;
00509     virtual void streamTo(SourceStream &s) const;
00510   private:
00511     Node *term1, *term2;
00512     char oper;
00513   };
00514 
00515   class AddNode : public Node {
00516   public:
00517     AddNode(Node *t1, Node *t2, char op) : term1(t1), term2(t2), oper(op) {}
00518 
00519     static Node* create(Node *t1, Node *t2, char op);
00520 
00521     virtual void ref();
00522     virtual bool deref();
00523     virtual Value evaluate(ExecState *exec) const;
00524     virtual void streamTo(SourceStream &s) const;
00525   private:
00526     Node *term1, *term2;
00527     char oper;
00528   };
00529 
00530   class AppendStringNode : public Node {
00531   public:
00532     AppendStringNode(Node *t, const UString &s) : term(t), str(s) { }
00533     virtual void ref();
00534     virtual bool deref();
00535     virtual Value evaluate(ExecState *exec) const;
00536     virtual void streamTo(SourceStream &s) const;
00537   private:
00538     Node *term;
00539     UString str;
00540   };
00541 
00542   class ShiftNode : public Node {
00543   public:
00544     ShiftNode(Node *t1, Operator o, Node *t2)
00545       : term1(t1), term2(t2), oper(o) {}
00546     virtual void ref();
00547     virtual bool deref();
00548     virtual Value evaluate(ExecState *exec) const;
00549     virtual void streamTo(SourceStream &s) const;
00550   private:
00551     Node *term1, *term2;
00552     Operator oper;
00553   };
00554 
00555   class RelationalNode : public Node {
00556   public:
00557     RelationalNode(Node *e1, Operator o, Node *e2) :
00558       expr1(e1), expr2(e2), oper(o) {}
00559     virtual void ref();
00560     virtual bool deref();
00561     virtual Value evaluate(ExecState *exec) const;
00562     virtual void streamTo(SourceStream &s) const;
00563   private:
00564     Node *expr1, *expr2;
00565     Operator oper;
00566   };
00567 
00568   class EqualNode : public Node {
00569   public:
00570     EqualNode(Node *e1, Operator o, Node *e2)
00571       : expr1(e1), expr2(e2), oper(o) {}
00572     virtual void ref();
00573     virtual bool deref();
00574     virtual Value evaluate(ExecState *exec) const;
00575     virtual void streamTo(SourceStream &s) const;
00576   private:
00577     Node *expr1, *expr2;
00578     Operator oper;
00579   };
00580 
00581   class BitOperNode : public Node {
00582   public:
00583     BitOperNode(Node *e1, Operator o, Node *e2) :
00584       expr1(e1), expr2(e2), oper(o) {}
00585     virtual void ref();
00586     virtual bool deref();
00587     virtual Value evaluate(ExecState *exec) const;
00588     virtual void streamTo(SourceStream &s) const;
00589   private:
00590     Node *expr1, *expr2;
00591     Operator oper;
00592   };
00593 
00597   class BinaryLogicalNode : public Node {
00598   public:
00599     BinaryLogicalNode(Node *e1, Operator o, Node *e2) :
00600       expr1(e1), expr2(e2), oper(o) {}
00601     virtual void ref();
00602     virtual bool deref();
00603     virtual Value evaluate(ExecState *exec) const;
00604     virtual void streamTo(SourceStream &s) const;
00605   private:
00606     Node *expr1, *expr2;
00607     Operator oper;
00608   };
00609 
00613   class ConditionalNode : public Node {
00614   public:
00615     ConditionalNode(Node *l, Node *e1, Node *e2) :
00616       logical(l), expr1(e1), expr2(e2) {}
00617     virtual void ref();
00618     virtual bool deref();
00619     virtual Value evaluate(ExecState *exec) const;
00620     virtual void streamTo(SourceStream &s) const;
00621   private:
00622     Node *logical, *expr1, *expr2;
00623   };
00624 
00625   class AssignNode : public Node {
00626   public:
00627     AssignNode(Node *l, Operator o, Node *e) : left(l), oper(o), expr(e) {}
00628     virtual void ref();
00629     virtual bool deref();
00630     virtual Value evaluate(ExecState *exec) const;
00631     virtual void streamTo(SourceStream &s) const;
00632   private:
00633     Node *left;
00634     Operator oper;
00635     Node *expr;
00636   };
00637 
00638   class CommaNode : public Node {
00639   public:
00640     CommaNode(Node *e1, Node *e2) : expr1(e1), expr2(e2) {}
00641     virtual void ref();
00642     virtual bool deref();
00643     virtual Value evaluate(ExecState *exec) const;
00644     virtual void streamTo(SourceStream &s) const;
00645   private:
00646     Node *expr1, *expr2;
00647   };
00648 
00649   class StatListNode : public StatementNode {
00650   public:
00651     // list is circular during construction. cracked in CaseClauseNode ctor
00652     StatListNode(StatementNode *s);
00653     StatListNode(StatListNode *l, StatementNode *s);
00654     virtual void ref();
00655     virtual bool deref();
00656     virtual Completion execute(ExecState *exec);
00657     virtual void processVarDecls(ExecState *exec);
00658     virtual void streamTo(SourceStream &s) const;
00659   private:
00660     friend class CaseClauseNode;
00661     StatementNode *statement;
00662     StatListNode *list;
00663   };
00664 
00665   class AssignExprNode : public Node {
00666   public:
00667     AssignExprNode(Node *e) : expr(e) {}
00668     virtual void ref();
00669     virtual bool deref();
00670     virtual Value evaluate(ExecState *exec) const;
00671     virtual void streamTo(SourceStream &s) const;
00672   private:
00673     Node *expr;
00674   };
00675 
00676   class VarDeclNode : public Node {
00677   public:
00678     VarDeclNode(const Identifier &id, AssignExprNode *in);
00679     virtual void ref();
00680     virtual bool deref();
00681     virtual Value evaluate(ExecState *exec) const;
00682     virtual void processVarDecls(ExecState *exec);
00683     virtual void streamTo(SourceStream &s) const;
00684   private:
00685     Identifier ident;
00686     AssignExprNode *init;
00687   };
00688 
00689   class VarDeclListNode : public Node {
00690   public:
00691     // list is circular until cracked in VarStatementNode/ForNode ctor
00692     VarDeclListNode(VarDeclNode *v) : list(this), var(v) {}
00693     VarDeclListNode(VarDeclListNode *l, VarDeclNode *v)
00694       : list(l->list), var(v) { l->list = this; }
00695     virtual void ref();
00696     virtual bool deref();
00697     virtual Value evaluate(ExecState *exec) const;
00698     virtual void processVarDecls(ExecState *exec);
00699     virtual void streamTo(SourceStream &s) const;
00700   private:
00701     friend class ForNode;
00702     friend class VarStatementNode;
00703     VarDeclListNode *list;
00704     VarDeclNode *var;
00705   };
00706 
00707   class VarStatementNode : public StatementNode {
00708   public:
00709     VarStatementNode(VarDeclListNode *l) : list(l->list) { l->list = 0; }
00710     virtual void ref();
00711     virtual bool deref();
00712     virtual Completion execute(ExecState *exec);
00713     virtual void processVarDecls(ExecState *exec);
00714     virtual void streamTo(SourceStream &s) const;
00715   private:
00716     VarDeclListNode *list;
00717   };
00718 
00719   class BlockNode : public StatementNode {
00720   public:
00721     BlockNode(SourceElementsNode *s);
00722     virtual void ref();
00723     virtual bool deref();
00724     virtual Completion execute(ExecState *exec);
00725     virtual void processVarDecls(ExecState *exec);
00726     virtual void streamTo(SourceStream &s) const;
00727   protected:
00728     SourceElementsNode *source;
00729   };
00730 
00731   class EmptyStatementNode : public StatementNode {
00732   public:
00733     EmptyStatementNode() { } // debug
00734     virtual Completion execute(ExecState *exec);
00735     virtual void streamTo(SourceStream &s) const;
00736   };
00737 
00738   class ExprStatementNode : public StatementNode {
00739   public:
00740     ExprStatementNode(Node *e) : expr(e) { }
00741     virtual void ref();
00742     virtual bool deref();
00743     virtual Completion execute(ExecState *exec);
00744     virtual void streamTo(SourceStream &s) const;
00745   private:
00746     Node *expr;
00747   };
00748 
00749   class IfNode : public StatementNode {
00750   public:
00751     IfNode(Node *e, StatementNode *s1, StatementNode *s2)
00752       : expr(e), statement1(s1), statement2(s2) {}
00753     virtual void ref();
00754     virtual bool deref();
00755     virtual Completion execute(ExecState *exec);
00756     virtual void processVarDecls(ExecState *exec);
00757     virtual void streamTo(SourceStream &s) const;
00758   private:
00759     Node *expr;
00760     StatementNode *statement1, *statement2;
00761   };
00762 
00763   class DoWhileNode : public StatementNode {
00764   public:
00765     DoWhileNode(StatementNode *s, Node *e) : statement(s), expr(e) {}
00766     virtual void ref();
00767     virtual bool deref();
00768     virtual Completion execute(ExecState *exec);
00769     virtual void processVarDecls(ExecState *exec);
00770     virtual void streamTo(SourceStream &s) const;
00771   private:
00772     StatementNode *statement;
00773     Node *expr;
00774   };
00775 
00776   class WhileNode : public StatementNode {
00777   public:
00778     WhileNode(Node *e, StatementNode *s) : expr(e), statement(s) {}
00779     virtual void ref();
00780     virtual bool deref();
00781     virtual Completion execute(ExecState *exec);
00782     virtual void processVarDecls(ExecState *exec);
00783     virtual void streamTo(SourceStream &s) const;
00784   private:
00785     Node *expr;
00786     StatementNode *statement;
00787   };
00788 
00789   class ForNode : public StatementNode {
00790   public:
00791     ForNode(Node *e1, Node *e2, Node *e3, StatementNode *s) :
00792       expr1(e1), expr2(e2), expr3(e3), statement(s) {}
00793     ForNode(VarDeclListNode *e1, Node *e2, Node *e3, StatementNode *s) :
00794       expr1(e1->list), expr2(e2), expr3(e3), statement(s) { e1->list = 0; }
00795     virtual void ref();
00796     virtual bool deref();
00797     virtual Completion execute(ExecState *exec);
00798     virtual void processVarDecls(ExecState *exec);
00799     virtual void streamTo(SourceStream &s) const;
00800   private:
00801     Node *expr1, *expr2, *expr3;
00802     StatementNode *statement;
00803   };
00804 
00805   class ForInNode : public StatementNode {
00806   public:
00807     ForInNode(Node *l, Node *e, StatementNode *s);
00808     ForInNode(const Identifier &i, AssignExprNode *in, Node *e, StatementNode *s);
00809     virtual void ref();
00810     virtual bool deref();
00811     virtual Completion execute(ExecState *exec);
00812     virtual void processVarDecls(ExecState *exec);
00813     virtual void streamTo(SourceStream &s) const;
00814   private:
00815     Identifier ident;
00816     AssignExprNode *init;
00817     Node *lexpr, *expr;
00818     VarDeclNode *varDecl;
00819     StatementNode *statement;
00820   };
00821 
00822   class ContinueNode : public StatementNode {
00823   public:
00824     ContinueNode() { }
00825     ContinueNode(const Identifier &i) : ident(i) { }
00826     virtual Completion execute(ExecState *exec);
00827     virtual void streamTo(SourceStream &s) const;
00828   private:
00829     Identifier ident;
00830   };
00831 
00832   class BreakNode : public StatementNode {
00833   public:
00834     BreakNode() { }
00835     BreakNode(const Identifier &i) : ident(i) { }
00836     virtual Completion execute(ExecState *exec);
00837     virtual void streamTo(SourceStream &s) const;
00838   private:
00839     Identifier ident;
00840   };
00841 
00842   class ReturnNode : public StatementNode {
00843   public:
00844     ReturnNode(Node *v) : value(v) {}
00845     virtual void ref();
00846     virtual bool deref();
00847     virtual Completion execute(ExecState *exec);
00848     virtual void streamTo(SourceStream &s) const;
00849   private:
00850     Node *value;
00851   };
00852 
00853   class WithNode : public StatementNode {
00854   public:
00855     WithNode(Node *e, StatementNode *s) : expr(e), statement(s) {}
00856     virtual void ref();
00857     virtual bool deref();
00858     virtual Completion execute(ExecState *exec);
00859     virtual void processVarDecls(ExecState *exec);
00860     virtual void streamTo(SourceStream &s) const;
00861   private:
00862     Node *expr;
00863     StatementNode *statement;
00864   };
00865 
00866   class CaseClauseNode: public Node {
00867   public:
00868     CaseClauseNode(Node *e) : expr(e), list(0) { }
00869     CaseClauseNode(Node *e, StatListNode *l)
00870       : expr(e), list(l->list) { l->list = 0; }
00871     virtual void ref();
00872     virtual bool deref();
00873     virtual Value evaluate(ExecState *exec) const;
00874     Completion evalStatements(ExecState *exec) const;
00875     virtual void processVarDecls(ExecState *exec);
00876     virtual void streamTo(SourceStream &s) const;
00877   private:
00878     Node *expr;
00879     StatListNode *list;
00880   };
00881 
00882   class ClauseListNode : public Node {
00883   public:
00884     // list is circular during construction. cracked in CaseBlockNode ctor
00885     ClauseListNode(CaseClauseNode *c) : cl(c), nx(this) { }
00886     ClauseListNode(ClauseListNode *n, CaseClauseNode *c)
00887       : cl(c), nx(n->nx) { n->nx = this; }
00888     virtual void ref();
00889     virtual bool deref();
00890     virtual Value evaluate(ExecState *exec) const;
00891     CaseClauseNode *clause() const { return cl; }
00892     ClauseListNode *next() const { return nx; }
00893     virtual void processVarDecls(ExecState *exec);
00894     virtual void streamTo(SourceStream &s) const;
00895   private:
00896     friend class CaseBlockNode;
00897     CaseClauseNode *cl;
00898     ClauseListNode *nx;
00899   };
00900 
00901   class CaseBlockNode: public Node {
00902   public:
00903     CaseBlockNode(ClauseListNode *l1, CaseClauseNode *d, ClauseListNode *l2);
00904     virtual void ref();
00905     virtual bool deref();
00906     virtual Value evaluate(ExecState *exec) const;
00907     Completion evalBlock(ExecState *exec, const Value& input) const;
00908     virtual void processVarDecls(ExecState *exec);
00909     virtual void streamTo(SourceStream &s) const;
00910   private:
00911     ClauseListNode *list1;
00912     CaseClauseNode *def;
00913     ClauseListNode *list2;
00914   };
00915 
00916   class SwitchNode : public StatementNode {
00917   public:
00918     SwitchNode(Node *e, CaseBlockNode *b) : expr(e), block(b) { }
00919     virtual void ref();
00920     virtual bool deref();
00921     virtual Completion execute(ExecState *exec);
00922     virtual void processVarDecls(ExecState *exec);
00923     virtual void streamTo(SourceStream &s) const;
00924   private:
00925     Node *expr;
00926     CaseBlockNode *block;
00927   };
00928 
00929   class LabelNode : public StatementNode {
00930   public:
00931     LabelNode(const Identifier &l, StatementNode *s) : label(l), statement(s) { }
00932     virtual void ref();
00933     virtual bool deref();
00934     virtual Completion execute(ExecState *exec);
00935     virtual void processVarDecls(ExecState *exec);
00936     virtual void streamTo(SourceStream &s) const;
00937   private:
00938     Identifier label;
00939     StatementNode *statement;
00940   };
00941 
00942   class ThrowNode : public StatementNode {
00943   public:
00944     ThrowNode(Node *e) : expr(e) {}
00945     virtual void ref();
00946     virtual bool deref();
00947     virtual Completion execute(ExecState *exec);
00948     virtual void streamTo(SourceStream &s) const;
00949   private:
00950     Node *expr;
00951   };
00952 
00953   class CatchNode : public StatementNode {
00954   public:
00955     CatchNode(const Identifier &i, StatementNode *b) : ident(i), block(b) {}
00956     virtual void ref();
00957     virtual bool deref();
00958     virtual Completion execute(ExecState *exec);
00959     Completion execute(ExecState *exec, const Value &arg);
00960     virtual void processVarDecls(ExecState *exec);
00961     virtual void streamTo(SourceStream &s) const;
00962   private:
00963     Identifier ident;
00964     StatementNode *block;
00965   };
00966 
00967   class FinallyNode : public StatementNode {
00968   public:
00969     FinallyNode(StatementNode *b) : block(b) {}
00970     virtual void ref();
00971     virtual bool deref();
00972     virtual Completion execute(ExecState *exec);
00973     virtual void processVarDecls(ExecState *exec);
00974     virtual void streamTo(SourceStream &s) const;
00975   private:
00976     StatementNode *block;
00977   };
00978 
00979   class TryNode : public StatementNode {
00980   public:
00981     TryNode(StatementNode *b, CatchNode *c)
00982       : block(b), _catch(c), _final(0) {}
00983     TryNode(StatementNode *b, FinallyNode *f)
00984       : block(b), _catch(0), _final(f) {}
00985     TryNode(StatementNode *b, CatchNode *c, FinallyNode *f)
00986       : block(b), _catch(c), _final(f) {}
00987     virtual void ref();
00988     virtual bool deref();
00989     virtual Completion execute(ExecState *exec);
00990     virtual void processVarDecls(ExecState *exec);
00991     virtual void streamTo(SourceStream &s) const;
00992   private:
00993     StatementNode *block;
00994     CatchNode *_catch;
00995     FinallyNode *_final;
00996   };
00997 
00998   class ParameterNode : public Node {
00999   public:
01000     // list is circular during construction. cracked in FuncDecl/ExprNode ctor.
01001     ParameterNode(const Identifier &i) : id(i), next(this) { }
01002     ParameterNode(ParameterNode *list, const Identifier &i)
01003       : id(i), next(list->next) { list->next = this; }
01004     virtual void ref();
01005     virtual bool deref();
01006     virtual Value evaluate(ExecState *exec) const;
01007     Identifier ident() const { return id; }
01008     ParameterNode *nextParam() const { return next; }
01009     virtual void streamTo(SourceStream &s) const;
01010   private:
01011     friend class FuncDeclNode;
01012     friend class FuncExprNode;
01013     Identifier id;
01014     ParameterNode *next;
01015   };
01016 
01017   class FunctionBodyNode : public BlockNode {
01018   public:
01019     FunctionBodyNode(SourceElementsNode *s);
01020     virtual void processFuncDecl(ExecState *exec);
01021     virtual Completion execute(ExecState *exec);
01022     void setProgram(bool _program) { program = _program; }
01023     bool isProgram() const { return program; }
01024   private:
01025     bool program;
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* /*exec*/)
01037       { /* empty */ 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   // A linked list of source element nodes
01062   class SourceElementsNode : public StatementNode {
01063   public:
01064     // list is circular until cracked in BlockNode (or subclass) ctor
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; // 'this' element
01076     SourceElementsNode *elements; // pointer to next
01077   };
01078 
01079 } // namespace
01080 
01081 #endif
KDE Logo
This file is part of the documentation for kjs Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Apr 22 14:23:47 2004 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2003