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