kjs Library: nodes.h Source File (kjs Library)

| # kjs Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# 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,
    00117                      const Value &v, const Node *expr) const;
    00118     Value throwError(ExecState *exec, ErrorType e, const char *msg, Identifier label) const;
    00119     int line;
    00120     unsigned int refcount;
    00121     virtual int sourceId() const { return -1; }
    00122   private:
    00123 #ifdef KJS_DEBUG_MEM
    00124     // List of all nodes, for debugging purposes. Don't remove!
    00125     static std::list<Node *> *s_nodes;
    00126 #endif
    00127     // disallow assignment
    00128     Node& operator=(const Node&);
    00129     Node(const Node &other);
    00130   };
    00131
    00132   class StatementNode : public Node {
    00133   public:
    00134     StatementNode();
    00135     virtual ~StatementNode();
    00136     void setLoc(int line0, int line1, SourceCode *src);
    00137     int firstLine() const { return l0; }
    00138     int lastLine() const { return l1; }
    00139     int sourceId() const { return sourceCode->sid; }
    00140     SourceCode *code() const { return sourceCode; }
    00141     bool hitStatement(ExecState *exec);
    00142     bool abortStatement(ExecState *exec);
    00143     virtual Completion execute(ExecState *exec) = 0;
    00144     void pushLabel(const Identifier &id) { ls.push(id); }
    00145     virtual void processFuncDecl(ExecState *exec);
    00146   protected:
    00147     LabelStack ls;
    00148   private:
    00149     Reference evaluateReference(ExecState* /*exec*/) const { return Reference(0,Identifier::null()); }
    00150     int l0, l1;
    00151     SourceCode *sourceCode;
    00152     bool breakPoint;
    00153   };
    00154
    00155   class NullNode : public Node {
    00156   public:
    00157     NullNode() {}
    00158     virtual Value evaluate(ExecState *exec) const;
    00159     virtual bool toBoolean(ExecState *exec) const;
    00160     virtual double toNumber(ExecState *exec) const;
    00161     virtual UString toString(ExecState *exec) const;
    00162     virtual void streamTo(SourceStream &s) const;
    00163   };
    00164
    00165   class BooleanNode : public Node {
    00166   public:
    00167     BooleanNode(bool v) : val(v) {}
    00168     virtual Type type() const { return BooleanType; }
    00169     virtual Value evaluate(ExecState *exec) const;
    00170     virtual bool toBoolean(ExecState *exec) const;
    00171     virtual double toNumber(ExecState *exec) const;
    00172     virtual UString toString(ExecState *exec) const;
    00173     virtual void streamTo(SourceStream &s) const;
    00174   private:
    00175     bool val;
    00176   };
    00177
    00178   class NumberNode : public Node {
    00179   public:
    00180     NumberNode(double v) : val(v) { }
    00181     virtual Type type() const { return NumberType; }
    00182     virtual Value evaluate(ExecState *exec) const;
    00183     virtual bool toBoolean(ExecState *exec) const;
    00184     virtual double toNumber(ExecState *exec) const;
    00185     virtual UString toString(ExecState *exec) const;
    00186     virtual void streamTo(SourceStream &s) const;
    00187   private:
    00188     double val;
    00189   };
    00190
    00191   class StringNode : public Node {
    00192   public:
    00193     StringNode(const UString *v) : val(*v) { }
    00194     virtual Type type() const { return StringType; }
    00195     virtual Value evaluate(ExecState *exec) const;
    00196     virtual bool toBoolean(ExecState *exec) const;
    00197     virtual double toNumber(ExecState *exec) const;
    00198     virtual UString toString(ExecState *exec) const;
    00199     virtual void streamTo(SourceStream &s) const;
    00200   private:
    00201     UString val;
    00202   };
    00203
    00204   class RegExpNode : public Node {
    00205   public:
    00206     RegExpNode(const UString &p, const UString &f)
    00207       : pattern(p), flags(f) { }
    00208     virtual Value evaluate(ExecState *exec) const;
    00209     virtual bool toBoolean(ExecState *exec) const;
    00210     virtual void streamTo(SourceStream &s) const;
    00211   private:
    00212     UString pattern, flags;
    00213   };
    00214
    00215   class ThisNode : public Node {
    00216   public:
    00217     ThisNode() {}
    00218     virtual Value evaluate(ExecState *exec) const;
    00219     virtual void streamTo(SourceStream &s) const;
    00220   };
    00221
    00222   class ResolveNode : public Node {
    00223   public:
    00224     ResolveNode(const Identifier &s) : ident(s) { }
    00225     Reference evaluateReference(ExecState *exec) const;
    00226     virtual Value evaluate(ExecState *exec) const;
    00227     virtual void streamTo(SourceStream &s) const;
    00228   private:
    00229     Identifier ident;
    00230   };
    00231
    00232   class GroupNode : public Node {
    00233   public:
    00234     GroupNode(Node *g) : group(g) { }
    00235     virtual void ref();
    00236     virtual bool deref();
    00237     Reference evaluateReference(ExecState *exec) const;
    00238     virtual Value evaluate(ExecState *exec) const;
    00239     virtual void streamTo(SourceStream &s) const;
    00240   private:
    00241     Node *group;
    00242   };
    00243
    00244   class ElementNode : public Node {
    00245   public:
    00246     // list is circular during construction. cracked in ArrayNode ctor
    00247     ElementNode(int e, Node *n) : list(this), elision(e), node(n) { }
    00248     ElementNode(ElementNode *l, int e, Node *n)
    00249       : list(l->list), elision(e), node(n) { l->list = this; }
    00250     virtual void ref();
    00251     virtual bool deref();
    00252     virtual Value evaluate(ExecState *exec) const;
    00253     virtual void streamTo(SourceStream &s) const;
    00254   private:
    00255     friend class ArrayNode;
    00256     ElementNode *list;
    00257     int elision;
    00258     Node *node;
    00259   };
    00260
    00261   class ArrayNode : public Node {
    00262   public:
    00263     ArrayNode(int e) : element(0L), elision(e), opt(true) { }
    00264     ArrayNode(ElementNode *ele)
    00265       : element(ele->list), elision(0), opt(false) { ele->list = 0; }
    00266     ArrayNode(int eli, ElementNode *ele)
    00267       : element(ele->list), elision(eli), opt(true) { ele->list = 0; }
    00268     virtual void ref();
    00269     virtual bool deref();
    00270     virtual Value evaluate(ExecState *exec) const;
    00271     virtual void streamTo(SourceStream &s) const;
    00272   private:
    00273     ElementNode *element;
    00274     int elision;
    00275     bool opt;
    00276   };
    00277
    00278   class PropertyValueNode : public Node {
    00279   public:
    00280     // list is circular during construction, cut in ObjectLiteralNode ctor
    00281     PropertyValueNode(PropertyNode *n, Node *a)
    00282       : name(n), assign(a), list(this) { }
    00283     PropertyValueNode(PropertyNode *n, Node *a, PropertyValueNode *l)
    00284       : name(n), assign(a), list(l->list) { l->list = this; }
    00285     virtual void ref();
    00286     virtual bool deref();
    00287     virtual Value evaluate(ExecState *exec) const;
    00288     virtual void streamTo(SourceStream &s) const;
    00289   private:
    00290     friend class ObjectLiteralNode;
    00291     PropertyNode *name;
    00292     Node *assign;
    00293     PropertyValueNode *list;
    00294   };
    00295
    00296   class PropertyNode : public Node {
    00297   public:
    00298     PropertyNode(double d) : numeric(d) { }
    00299     PropertyNode(const Identifier &s) : str(s) { }
    00300     virtual Value evaluate(ExecState *exec) const;
    00301     virtual void streamTo(SourceStream &s) const;
    00302   private:
    00303     double numeric;
    00304     Identifier str;
    00305   };
    00306
    00307   class ObjectLiteralNode : public Node {
    00308   public:
    00309     // empty literal
    00310     ObjectLiteralNode() : list(0) { }
    00311     // l points to last list element, get and detach pointer to first one
    00312     ObjectLiteralNode(PropertyValueNode *l) : list(l->list) { l->list = 0; }
    00313     virtual void ref();
    00314     virtual bool deref();
    00315     virtual Value evaluate(ExecState *exec) const;
    00316     virtual void streamTo(SourceStream &s) const;
    00317   private:
    00318     PropertyValueNode *list;
    00319   };
    00320
    00321   class AccessorNode1 : public Node {
    00322   public:
    00323     AccessorNode1(Node *e1, Node *e2) : expr1(e1), expr2(e2) {}
    00324     virtual void ref();
    00325     virtual bool deref();
    00326     Reference evaluateReference(ExecState *exec) const;
    00327     virtual void streamTo(SourceStream &s) const;
    00328   private:
    00329     Node *expr1;
    00330     Node *expr2;
    00331   };
    00332
    00333   class AccessorNode2 : public Node {
    00334   public:
    00335     AccessorNode2(Node *e, const Identifier &s) : expr(e), ident(s) { }
    00336     virtual void ref();
    00337     virtual bool deref();
    00338     Reference evaluateReference(ExecState *exec) const;
    00339     virtual void streamTo(SourceStream &s) const;
    00340   private:
    00341     Node *expr;
    00342     Identifier ident;
    00343   };
    00344
    00345   class ArgumentListNode : public Node {
    00346   public:
    00347     // list is circular during construction. cracked in ArgumentsNode ctor
    00348     ArgumentListNode(Node *e) : list(this), expr(e) {}
    00349     ArgumentListNode(ArgumentListNode *l, Node *e)
    00350       : list(l->list), expr(e) { l->list = this; }
    00351     virtual void ref();
    00352     virtual bool deref();
    00353     virtual Value evaluate(ExecState *exec) const;
    00354     List evaluateList(ExecState *exec) const;
    00355     virtual void streamTo(SourceStream &s) const;
    00356   private:
    00357     friend class ArgumentsNode;
    00358     ArgumentListNode *list;
    00359     Node *expr;
    00360   };
    00361
    00362   class ArgumentsNode : public Node {
    00363   public:
    00364     ArgumentsNode() : list(0) {}
    00365     ArgumentsNode(ArgumentListNode *l) : list(l->list) { l->list = 0; }
    00366     virtual void ref();
    00367     virtual bool deref();
    00368     virtual Value evaluate(ExecState *exec) const;
    00369     List evaluateList(ExecState *exec) const;
    00370     virtual void streamTo(SourceStream &s) const;
    00371   private:
    00372     ArgumentListNode *list;
    00373   };
    00374
    00375   class NewExprNode : public Node {
    00376   public:
    00377     NewExprNode(Node *e) : expr(e), args(0L) {}
    00378     NewExprNode(Node *e, ArgumentsNode *a) : expr(e), args(a) {}
    00379     virtual void ref();
    00380     virtual bool deref();
    00381     virtual Value evaluate(ExecState *exec) const;
    00382     virtual void streamTo(SourceStream &s) const;
    00383   private:
    00384     Node *expr;
    00385     ArgumentsNode *args;
    00386   };
    00387
    00388   class FunctionCallNode : public Node {
    00389   public:
    00390     FunctionCallNode(Node *e, ArgumentsNode *a) : expr(e), args(a) {}
    00391     virtual void ref();
    00392     virtual bool deref();
    00393     virtual Value evaluate(ExecState *exec) const;
    00394     virtual void streamTo(SourceStream &s) const;
    00395   private:
    00396     Node *expr;
    00397     ArgumentsNode *args;
    00398   };
    00399
    00400   class PostfixNode : public Node {
    00401   public:
    00402     PostfixNode(Node *e, Operator o) : expr(e), oper(o) {}
    00403     virtual void ref();
    00404     virtual bool deref();
    00405     virtual Value evaluate(ExecState *exec) const;
    00406     virtual void streamTo(SourceStream &s) const;
    00407   private:
    00408     Node *expr;
    00409     Operator oper;
    00410   };
    00411
    00412   class DeleteNode : public Node {
    00413   public:
    00414     DeleteNode(Node *e) : expr(e) {}
    00415     virtual void ref();
    00416     virtual bool deref();
    00417     virtual Value evaluate(ExecState *exec) const;
    00418     virtual void streamTo(SourceStream &s) const;
    00419   private:
    00420     Node *expr;
    00421   };
    00422
    00423   class VoidNode : public Node {
    00424   public:
    00425     VoidNode(Node *e) : expr(e) {}
    00426     virtual void ref();
    00427     virtual bool deref();
    00428     virtual Value evaluate(ExecState *exec) const;
    00429     virtual void streamTo(SourceStream &s) const;
    00430   private:
    00431     Node *expr;
    00432   };
    00433
    00434   class TypeOfNode : public Node {
    00435   public:
    00436     TypeOfNode(Node *e) : expr(e) {}
    00437     virtual void ref();
    00438     virtual bool deref();
    00439     virtual Value evaluate(ExecState *exec) const;
    00440     virtual void streamTo(SourceStream &s) const;
    00441   private:
    00442     Node *expr;
    00443   };
    00444
    00445   class PrefixNode : public Node {
    00446   public:
    00447     PrefixNode(Operator o, Node *e) : oper(o), expr(e) {}
    00448     virtual void ref();
    00449     virtual bool deref();
    00450     virtual Value evaluate(ExecState *exec) const;
    00451     virtual void streamTo(SourceStream &s) const;
    00452   private:
    00453     Operator oper;
    00454     Node *expr;
    00455   };
    00456
    00457   class UnaryPlusNode : public Node {
    00458   public:
    00459     UnaryPlusNode(Node *e) : expr(e) {}
    00460     virtual void ref();
    00461     virtual bool deref();
    00462     virtual Value evaluate(ExecState *exec) const;
    00463     virtual double toNumber(ExecState *exec) const;
    00464     virtual void streamTo(SourceStream &s) const;
    00465   private:
    00466     Node *expr;
    00467   };
    00468
    00469   class NegateNode : public Node {
    00470   public:
    00471     NegateNode(Node *e) : expr(e) {}
    00472     virtual void ref();
    00473     virtual bool deref();
    00474     virtual Value evaluate(ExecState *exec) const;
    00475     virtual double toNumber(ExecState *exec) const;
    00476     virtual void streamTo(SourceStream &s) const;
    00477   private:
    00478     Node *expr;
    00479   };
    00480
    00481   class BitwiseNotNode : public Node {
    00482   public:
    00483     BitwiseNotNode(Node *e) : expr(e) {}
    00484     virtual void ref();
    00485     virtual bool deref();
    00486     virtual Value evaluate(ExecState *exec) const;
    00487     virtual void streamTo(SourceStream &s) const;
    00488   private:
    00489     Node *expr;
    00490   };
    00491
    00492   class LogicalNotNode : public Node {
    00493   public:
    00494     LogicalNotNode(Node *e) : expr(e) {}
    00495     virtual void ref();
    00496     virtual bool deref();
    00497     virtual Value evaluate(ExecState *exec) const;
    00498     virtual bool toBoolean(ExecState *exec) const;
    00499     virtual void streamTo(SourceStream &s) const;
    00500   private:
    00501     Node *expr;
    00502   };
    00503
    00504   class MultNode : public Node {
    00505   public:
    00506     MultNode(Node *t1, Node *t2, char op) : term1(t1), term2(t2), oper(op) {}
    00507     virtual void ref();
    00508     virtual bool deref();
    00509     virtual Value evaluate(ExecState *exec) const;
    00510     virtual void streamTo(SourceStream &s) const;
    00511   private:
    00512     Node *term1, *term2;
    00513     char oper;
    00514   };
    00515
    00516   class AddNode : public Node {
    00517   public:
    00518     AddNode(Node *t1, Node *t2, char op) : term1(t1), term2(t2), oper(op) {}
    00519
    00520     static Node* create(Node *t1, Node *t2, char op);
    00521
    00522     virtual void ref();
    00523     virtual bool deref();
    00524     virtual Value evaluate(ExecState *exec) const;
    00525     virtual void streamTo(SourceStream &s) const;
    00526   private:
    00527     Node *term1, *term2;
    00528     char oper;
    00529   };
    00530
    00531   class AppendStringNode : public Node {
    00532   public:
    00533     AppendStringNode(Node *t, const UString &s) : term(t), str(s) { }
    00534     virtual void ref();
    00535     virtual bool deref();
    00536     virtual Value evaluate(ExecState *exec) const;
    00537     virtual void streamTo(SourceStream &s) const;
    00538   private:
    00539     Node *term;
    00540     UString str;
    00541   };
    00542
    00543   class ShiftNode : public Node {
    00544   public:
    00545     ShiftNode(Node *t1, Operator o, Node *t2)
    00546       : term1(t1), term2(t2), oper(o) {}
    00547     virtual void ref();
    00548     virtual bool deref();
    00549     virtual Value evaluate(ExecState *exec) const;
    00550     virtual void streamTo(SourceStream &s) const;
    00551   private:
    00552     Node *term1, *term2;
    00553     Operator oper;
    00554   };
    00555
    00556   class RelationalNode : public Node {
    00557   public:
    00558     RelationalNode(Node *e1, Operator o, Node *e2) :
    00559       expr1(e1), expr2(e2), oper(o) {}
    00560     virtual void ref();
    00561     virtual bool deref();
    00562     virtual Value evaluate(ExecState *exec) const;
    00563     virtual void streamTo(SourceStream &s) const;
    00564   private:
    00565     Node *expr1, *expr2;
    00566     Operator oper;
    00567   };
    00568
    00569   class EqualNode : public Node {
    00570   public:
    00571     EqualNode(Node *e1, Operator o, Node *e2)
    00572       : expr1(e1), expr2(e2), oper(o) {}
    00573     virtual void ref();
    00574     virtual bool deref();
    00575     virtual Value evaluate(ExecState *exec) const;
    00576     virtual void streamTo(SourceStream &s) const;
    00577   private:
    00578     Node *expr1, *expr2;
    00579     Operator oper;
    00580   };
    00581
    00582   class BitOperNode : public Node {
    00583   public:
    00584     BitOperNode(Node *e1, Operator o, Node *e2) :
    00585       expr1(e1), expr2(e2), oper(o) {}
    00586     virtual void ref();
    00587     virtual bool deref();
    00588     virtual Value evaluate(ExecState *exec) const;
    00589     virtual void streamTo(SourceStream &s) const;
    00590   private:
    00591     Node *expr1, *expr2;
    00592     Operator oper;
    00593   };
    00594
    00598   class BinaryLogicalNode : public Node {
    00599   public:
    00600     BinaryLogicalNode(Node *e1, Operator o, Node *e2) :
    00601       expr1(e1), expr2(e2), oper(o) {}
    00602     virtual void ref();
    00603     virtual bool deref();
    00604     virtual Value evaluate(ExecState *exec) const;
    00605     virtual void streamTo(SourceStream &s) const;
    00606   private:
    00607     Node *expr1, *expr2;
    00608     Operator oper;
    00609   };
    00610
    00614   class ConditionalNode : public Node {
    00615   public:
    00616     ConditionalNode(Node *l, Node *e1, Node *e2) :
    00617       logical(l), expr1(e1), expr2(e2) {}
    00618     virtual void ref();
    00619     virtual bool deref();
    00620     virtual Value evaluate(ExecState *exec) const;
    00621     virtual void streamTo(SourceStream &s) const;
    00622   private:
    00623     Node *logical, *expr1, *expr2;
    00624   };
    00625
    00626   class AssignNode : public Node {
    00627   public:
    00628     AssignNode(Node *l, Operator o, Node *e) : left(l), oper(o), expr(e) {}
    00629     virtual void ref();
    00630     virtual bool deref();
    00631     virtual Value evaluate(ExecState *exec) const;
    00632     virtual void streamTo(SourceStream &s) const;
    00633   private:
    00634     Node *left;
    00635     Operator oper;
    00636     Node *expr;
    00637   };
    00638
    00639   class CommaNode : public Node {
    00640   public:
    00641     CommaNode(Node *e1, Node *e2) : expr1(e1), expr2(e2) {}
    00642     virtual void ref();
    00643     virtual bool deref();
    00644     virtual Value evaluate(ExecState *exec) const;
    00645     virtual void streamTo(SourceStream &s) const;
    00646   private:
    00647     Node *expr1, *expr2;
    00648   };
    00649
    00650   class StatListNode : public StatementNode {
    00651   public:
    00652     // list is circular during construction. cracked in CaseClauseNode ctor
    00653     StatListNode(StatementNode *s);
    00654     StatListNode(StatListNode *l, StatementNode *s);
    00655     virtual void ref();
    00656     virtual bool deref();
    00657     virtual Completion execute(ExecState *exec);
    00658     virtual void processVarDecls(ExecState *exec);
    00659     virtual void streamTo(SourceStream &s) const;
    00660   private:
    00661     friend class CaseClauseNode;
    00662     StatementNode *statement;
    00663     StatListNode *list;
    00664   };
    00665
    00666   class AssignExprNode : public Node {
    00667   public:
    00668     AssignExprNode(Node *e) : expr(e) {}
    00669     virtual void ref();
    00670     virtual bool deref();
    00671     virtual Value evaluate(ExecState *exec) const;
    00672     virtual void streamTo(SourceStream &s) const;
    00673   private:
    00674     Node *expr;
    00675   };
    00676
    00677   class VarDeclNode : public Node {
    00678   public:
    00679     VarDeclNode(const Identifier &id, AssignExprNode *in);
    00680     virtual void ref();
    00681     virtual bool deref();
    00682     virtual Value evaluate(ExecState *exec) const;
    00683     virtual void processVarDecls(ExecState *exec);
    00684     virtual void streamTo(SourceStream &s) const;
    00685   private:
    00686     Identifier ident;
    00687     AssignExprNode *init;
    00688   };
    00689
    00690   class VarDeclListNode : public Node {
    00691   public:
    00692     // list is circular until cracked in VarStatementNode/ForNode ctor
    00693     VarDeclListNode(VarDeclNode *v) : list(this), var(v) {}
    00694     VarDeclListNode(VarDeclListNode *l, VarDeclNode *v)
    00695       : list(l->list), var(v) { l->list = this; }
    00696     virtual void ref();
    00697     virtual bool deref();
    00698     virtual Value evaluate(ExecState *exec) const;
    00699     virtual void processVarDecls(ExecState *exec);
    00700     virtual void streamTo(SourceStream &s) const;
    00701   private:
    00702     friend class ForNode;
    00703     friend class VarStatementNode;
    00704     VarDeclListNode *list;
    00705     VarDeclNode *var;
    00706   };
    00707
    00708   class VarStatementNode : public StatementNode {
    00709   public:
    00710     enum Type { Variable, Constant };
    00711     VarStatementNode(Type t, VarDeclListNode *l)
    00712       : varType(t), list(l->list) { l->list = 0; }
    00713     virtual void ref();
    00714     virtual bool deref();
    00715     virtual Completion execute(ExecState *exec);
    00716     virtual void processVarDecls(ExecState *exec);
    00717     virtual void streamTo(SourceStream &s) const;
    00718   private:
    00719     Type varType;
    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() { } // debug
    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     // list is circular during construction. cracked in CaseBlockNode ctor
    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     // list is circular during construction. cracked in FuncDecl/ExprNode ctor.
    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   // inherited by ProgramNode
    01022   class FunctionBodyNode : public BlockNode {
    01023   public:
    01024     FunctionBodyNode(SourceElementsNode *s);
    01025     virtual void processFuncDecl(ExecState *exec);
    01026     virtual Completion execute(ExecState *exec);
    01027     void setProgram(bool _program) { program = _program; }
    01028     bool isProgram() const { return program; }
    01029   private:
    01030     bool program;
    01031   };
    01032
    01033   class FuncDeclNode : public StatementNode {
    01034   public:
    01035     FuncDeclNode(const Identifier &i, FunctionBodyNode *b)
    01036       : ident(i), param(0), body(b) { }
    01037     FuncDeclNode(const Identifier &i, ParameterNode *p, FunctionBodyNode *b)
    01038       : ident(i), param(p->next), body(b) { p->next = 0; }
    01039     virtual void ref();
    01040     virtual bool deref();
    01041     Completion execute(ExecState* /*exec*/)
    01042       { /* empty */ return Completion(); }
    01043     void processFuncDecl(ExecState *exec);
    01044     virtual void streamTo(SourceStream &s) const;
    01045   private:
    01046     Identifier ident;
    01047     ParameterNode *param;
    01048     FunctionBodyNode *body;
    01049   };
    01050
    01051   class FuncExprNode : public Node {
    01052   public:
    01053     FuncExprNode(FunctionBodyNode *b)
    01054       : param(0), body(b) { }
    01055     FuncExprNode(ParameterNode *p, FunctionBodyNode *b)
    01056       : param(p->next), body(b) { p->next = 0; }
    01057     virtual void ref();
    01058     virtual bool deref();
    01059     virtual Value evaluate(ExecState *exec) const;
    01060     virtual void streamTo(SourceStream &s) const;
    01061   private:
    01062     ParameterNode *param;
    01063     FunctionBodyNode *body;
    01064   };
    01065
    01066   // A linked list of source element nodes
    01067   class SourceElementsNode : public StatementNode {
    01068   public:
    01069     // list is circular until cracked in BlockNode (or subclass) ctor
    01070     SourceElementsNode(StatementNode *s1);
    01071     SourceElementsNode(SourceElementsNode *s1, StatementNode *s2);
    01072     virtual void ref();
    01073     virtual bool deref();
    01074     Completion execute(ExecState *exec);
    01075     virtual void processFuncDecl(ExecState *exec);
    01076     virtual void processVarDecls(ExecState *exec);
    01077     virtual void streamTo(SourceStream &s) const;
    01078   private:
    01079     friend class BlockNode;
    01080     StatementNode *element; // 'this' element
    01081     SourceElementsNode *elements; // pointer to next
    01082   };
    01083
    01084 } // namespace
    01085
    01086 #endif

This file is part of the documentation for kjs Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:23:07 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003