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     virtual Value value(ExecState *exec) const;
00209     virtual void streamTo(SourceStream &s) const;
00210   private:
00211     Node *group;
00212   };
00213 
00214   class ElisionNode : public Node {
00215   public:
00216     ElisionNode(ElisionNode *e) : elision(e) { }
00217     virtual void ref();
00218     virtual bool deref();
00219     virtual ~ElisionNode();
00220     virtual Value value(ExecState *exec) const;
00221     virtual void streamTo(SourceStream &s) const;
00222   private:
00223     ElisionNode *elision;
00224   };
00225 
00226   class ElementNode : public Node {
00227   public:
00228     ElementNode(ElisionNode *e, Node *n) : list(0L), elision(e), node(n) { }
00229     ElementNode(ElementNode *l, ElisionNode *e, Node *n)
00230       : list(l), elision(e), node(n) { }
00231     virtual void ref();
00232     virtual bool deref();
00233     virtual ~ElementNode();
00234     virtual Value value(ExecState *exec) const;
00235     virtual void streamTo(SourceStream &s) const;
00236   private:
00237     ElementNode *list;
00238     ElisionNode *elision;
00239     Node *node;
00240   };
00241 
00242   class ArrayNode : public Node {
00243   public:
00244     ArrayNode(ElisionNode *e) : element(0L), elision(e), opt(true) { }
00245     ArrayNode(ElementNode *ele)
00246       : element(ele), elision(0), opt(false) { }
00247     ArrayNode(ElisionNode *eli, ElementNode *ele)
00248       : element(ele), elision(eli), opt(true) { }
00249     virtual void ref();
00250     virtual bool deref();
00251     virtual ~ArrayNode();
00252     virtual Value value(ExecState *exec) const;
00253     virtual void streamTo(SourceStream &s) const;
00254   private:
00255     ElementNode *element;
00256     ElisionNode *elision;
00257     bool opt;
00258   };
00259 
00260   class ObjectLiteralNode : public Node {
00261   public:
00262     ObjectLiteralNode(Node *l) : list(l) { }
00263     virtual void ref();
00264     virtual bool deref();
00265     virtual ~ObjectLiteralNode();
00266     virtual Value value(ExecState *exec) const;
00267     virtual void streamTo(SourceStream &s) const;
00268   private:
00269     Node *list;
00270   };
00271 
00272   class PropertyValueNode : public Node {
00273   public:
00274     PropertyValueNode(Node *n, Node *a, Node *l = 0L)
00275       : name(n), assign(a), list(l) { }
00276     virtual void ref();
00277     virtual bool deref();
00278     virtual ~PropertyValueNode();
00279     virtual Value value(ExecState *exec) const;
00280     virtual void streamTo(SourceStream &s) const;
00281   private:
00282     Node *name, *assign, *list;
00283   };
00284 
00285   class PropertyNode : public Node {
00286   public:
00287     PropertyNode(double d) : numeric(d) { }
00288     PropertyNode(const UString *s) : str(*s) { }
00289     virtual Value value(ExecState *exec) const;
00290     virtual void streamTo(SourceStream &s) const;
00291   private:
00292     double numeric;
00293     UString str;
00294   };
00295 
00296   class AccessorNode1 : public Node {
00297   public:
00298     AccessorNode1(Node *e1, Node *e2) : expr1(e1), expr2(e2) {}
00299     virtual void ref();
00300     virtual bool deref();
00301     virtual ~AccessorNode1();
00302     Reference2 evaluate(ExecState *exec) const;
00303     virtual void streamTo(SourceStream &s) const;
00304   private:
00305     Node *expr1;
00306     Node *expr2;
00307   };
00308 
00309   class AccessorNode2 : public Node {
00310   public:
00311     AccessorNode2(Node *e, const UString *s) : expr(e), ident(*s) { }
00312     virtual void ref();
00313     virtual bool deref();
00314     virtual ~AccessorNode2();
00315     Reference2 evaluate(ExecState *exec) const;
00316     virtual void streamTo(SourceStream &s) const;
00317   private:
00318     Node *expr;
00319     UString ident;
00320   };
00321 
00322   class ArgumentListNode : public Node {
00323   public:
00324     ArgumentListNode(Node *e);
00325     ArgumentListNode(ArgumentListNode *l, Node *e);
00326     virtual void ref();
00327     virtual bool deref();
00328     virtual ~ArgumentListNode();
00329     virtual Value value(ExecState *exec) const;
00330     List evaluateList(ExecState *exec) const;
00331     virtual void streamTo(SourceStream &s) const;
00332   private:
00333     ArgumentListNode *list;
00334     Node *expr;
00335   };
00336 
00337   class ArgumentsNode : public Node {
00338   public:
00339     ArgumentsNode(ArgumentListNode *l);
00340     virtual void ref();
00341     virtual bool deref();
00342     virtual ~ArgumentsNode();
00343     virtual Value value(ExecState *exec) const;
00344     List evaluateList(ExecState *exec) const;
00345     virtual void streamTo(SourceStream &s) const;
00346   private:
00347     ArgumentListNode *list;
00348   };
00349 
00350   class NewExprNode : public Node {
00351   public:
00352     NewExprNode(Node *e) : expr(e), args(0L) {}
00353     NewExprNode(Node *e, ArgumentsNode *a) : expr(e), args(a) {}
00354     virtual void ref();
00355     virtual bool deref();
00356     virtual ~NewExprNode();
00357     Value value(ExecState *exec) const;
00358     virtual void streamTo(SourceStream &s) const;
00359   private:
00360     Node *expr;
00361     ArgumentsNode *args;
00362   };
00363 
00364   class FunctionCallNode : public Node {
00365   public:
00366     FunctionCallNode(Node *e, ArgumentsNode *a) : expr(e), args(a) {}
00367     virtual void ref();
00368     virtual bool deref();
00369     virtual ~FunctionCallNode();
00370     virtual Value value(ExecState *exec) const;
00371     virtual void streamTo(SourceStream &s) const;
00372   private:
00373     Node *expr;
00374     ArgumentsNode *args;
00375   };
00376 
00377   class PostfixNode : public Node {
00378   public:
00379     PostfixNode(Node *e, Operator o) : expr(e), oper(o) {}
00380     virtual void ref();
00381     virtual bool deref();
00382     virtual ~PostfixNode();
00383     Value value(ExecState *exec) const;
00384     virtual void streamTo(SourceStream &s) const;
00385   private:
00386     Node *expr;
00387     Operator oper;
00388   };
00389 
00390   class DeleteNode : public Node {
00391   public:
00392     DeleteNode(Node *e) : expr(e) {}
00393     virtual void ref();
00394     virtual bool deref();
00395     virtual ~DeleteNode();
00396     virtual Value value(ExecState *exec) const;
00397     virtual void streamTo(SourceStream &s) const;
00398   private:
00399     Node *expr;
00400   };
00401 
00402   class VoidNode : public Node {
00403   public:
00404     VoidNode(Node *e) : expr(e) {}
00405     virtual void ref();
00406     virtual bool deref();
00407     virtual ~VoidNode();
00408     virtual Value value(ExecState *exec) const;
00409     virtual void streamTo(SourceStream &s) const;
00410   private:
00411     Node *expr;
00412   };
00413 
00414   class TypeOfNode : public Node {
00415   public:
00416     TypeOfNode(Node *e) : expr(e) {}
00417     virtual void ref();
00418     virtual bool deref();
00419     virtual ~TypeOfNode();
00420     virtual Value value(ExecState *exec) const;
00421     virtual void streamTo(SourceStream &s) const;
00422   private:
00423     Node *expr;
00424   };
00425 
00426   class PrefixNode : public Node {
00427   public:
00428     PrefixNode(Operator o, Node *e) : oper(o), expr(e) {}
00429     virtual void ref();
00430     virtual bool deref();
00431     virtual ~PrefixNode();
00432     Value value(ExecState *exec) const;
00433     virtual void streamTo(SourceStream &s) const;
00434   private:
00435     Operator oper;
00436     Node *expr;
00437   };
00438 
00439   class UnaryPlusNode : public Node {
00440   public:
00441     UnaryPlusNode(Node *e) : expr(e) {}
00442     virtual void ref();
00443     virtual bool deref();
00444     virtual ~UnaryPlusNode();
00445     virtual Value value(ExecState *exec) const;
00446     virtual void streamTo(SourceStream &s) const;
00447   private:
00448     Node *expr;
00449   };
00450 
00451   class NegateNode : public Node {
00452   public:
00453     NegateNode(Node *e) : expr(e) {}
00454     virtual void ref();
00455     virtual bool deref();
00456     virtual ~NegateNode();
00457     virtual Value value(ExecState *exec) const;
00458     virtual void streamTo(SourceStream &s) const;
00459   private:
00460     Node *expr;
00461   };
00462 
00463   class BitwiseNotNode : public Node {
00464   public:
00465     BitwiseNotNode(Node *e) : expr(e) {}
00466     virtual void ref();
00467     virtual bool deref();
00468     virtual ~BitwiseNotNode();
00469     virtual Value value(ExecState *exec) const;
00470     virtual void streamTo(SourceStream &s) const;
00471   private:
00472     Node *expr;
00473   };
00474 
00475   class LogicalNotNode : public Node {
00476   public:
00477     LogicalNotNode(Node *e) : expr(e) {}
00478     virtual void ref();
00479     virtual bool deref();
00480     virtual ~LogicalNotNode();
00481     virtual Value value(ExecState *exec) const;
00482     virtual void streamTo(SourceStream &s) const;
00483   private:
00484     Node *expr;
00485   };
00486 
00487   class MultNode : public Node {
00488   public:
00489     MultNode(Node *t1, Node *t2, char op) : term1(t1), term2(t2), oper(op) {}
00490     virtual void ref();
00491     virtual bool deref();
00492     virtual ~MultNode();
00493     virtual Value value(ExecState *exec) const;
00494     virtual void streamTo(SourceStream &s) const;
00495   private:
00496     Node *term1, *term2;
00497     char oper;
00498   };
00499 
00500   class AddNode : public Node {
00501   public:
00502     AddNode(Node *t1, Node *t2, char op) : term1(t1), term2(t2), oper(op) {}
00503     virtual void ref();
00504     virtual bool deref();
00505     virtual ~AddNode();
00506     virtual Value value(ExecState *exec) const;
00507     virtual void streamTo(SourceStream &s) const;
00508   private:
00509     Node *term1, *term2;
00510     char oper;
00511   };
00512 
00513   class ShiftNode : public Node {
00514   public:
00515     ShiftNode(Node *t1, Operator o, Node *t2)
00516       : term1(t1), term2(t2), oper(o) {}
00517     virtual void ref();
00518     virtual bool deref();
00519     virtual ~ShiftNode();
00520     virtual Value value(ExecState *exec) const;
00521     virtual void streamTo(SourceStream &s) const;
00522   private:
00523     Node *term1, *term2;
00524     Operator oper;
00525   };
00526 
00527   class RelationalNode : public Node {
00528   public:
00529     RelationalNode(Node *e1, Operator o, Node *e2) :
00530       expr1(e1), expr2(e2), oper(o) {}
00531     virtual void ref();
00532     virtual bool deref();
00533     virtual ~RelationalNode();
00534     virtual Value value(ExecState *exec) const;
00535     virtual void streamTo(SourceStream &s) const;
00536   private:
00537     Node *expr1, *expr2;
00538     Operator oper;
00539   };
00540 
00541   class EqualNode : public Node {
00542   public:
00543     EqualNode(Node *e1, Operator o, Node *e2)
00544       : expr1(e1), expr2(e2), oper(o) {}
00545     virtual void ref();
00546     virtual bool deref();
00547     virtual ~EqualNode();
00548     virtual Value value(ExecState *exec) const;
00549     virtual void streamTo(SourceStream &s) const;
00550   private:
00551     Node *expr1, *expr2;
00552     Operator oper;
00553   };
00554 
00555   class BitOperNode : public Node {
00556   public:
00557     BitOperNode(Node *e1, Operator o, Node *e2) :
00558       expr1(e1), expr2(e2), oper(o) {}
00559     virtual void ref();
00560     virtual bool deref();
00561     virtual ~BitOperNode();
00562     virtual Value value(ExecState *exec) const;
00563     virtual void streamTo(SourceStream &s) const;
00564   private:
00565     Node *expr1, *expr2;
00566     Operator oper;
00567   };
00568 
00572   class BinaryLogicalNode : public Node {
00573   public:
00574     BinaryLogicalNode(Node *e1, Operator o, Node *e2) :
00575       expr1(e1), expr2(e2), oper(o) {}
00576     virtual void ref();
00577     virtual bool deref();
00578     virtual ~BinaryLogicalNode();
00579     virtual Value value(ExecState *exec) const;
00580     virtual void streamTo(SourceStream &s) const;
00581   private:
00582     Node *expr1, *expr2;
00583     Operator oper;
00584   };
00585 
00589   class ConditionalNode : public Node {
00590   public:
00591     ConditionalNode(Node *l, Node *e1, Node *e2) :
00592       logical(l), expr1(e1), expr2(e2) {}
00593     virtual void ref();
00594     virtual bool deref();
00595     virtual ~ConditionalNode();
00596     virtual Value value(ExecState *exec) const;
00597     virtual void streamTo(SourceStream &s) const;
00598   private:
00599     Node *logical, *expr1, *expr2;
00600   };
00601 
00602   class AssignNode : public Node {
00603   public:
00604     AssignNode(Node *l, Operator o, Node *e) : left(l), oper(o), expr(e) {}
00605     virtual void ref();
00606     virtual bool deref();
00607     virtual ~AssignNode();
00608     virtual Value value(ExecState *exec) const;
00609     virtual void streamTo(SourceStream &s) const;
00610   private:
00611     Node *left;
00612     Operator oper;
00613     Node *expr;
00614   };
00615 
00616   class CommaNode : public Node {
00617   public:
00618     CommaNode(Node *e1, Node *e2) : expr1(e1), expr2(e2) {}
00619     virtual void ref();
00620     virtual bool deref();
00621     virtual ~CommaNode();
00622     virtual Value value(ExecState *exec) const;
00623     virtual void streamTo(SourceStream &s) const;
00624   private:
00625     Node *expr1, *expr2;
00626   };
00627 
00628   class StatListNode : public StatementNode {
00629   public:
00630     StatListNode(StatementNode *s) : statement(s), list(0L) { }
00631     StatListNode(StatListNode *l, StatementNode *s) : statement(s), list(l) { }
00632     virtual void ref();
00633     virtual bool deref();
00634     virtual ~StatListNode();
00635     virtual Completion execute(ExecState *exec);
00636     virtual void processVarDecls(ExecState *exec);
00637     virtual void streamTo(SourceStream &s) const;
00638   private:
00639     StatementNode *statement;
00640     StatListNode *list;
00641   };
00642 
00643   class AssignExprNode : public Node {
00644   public:
00645     AssignExprNode(Node *e) : expr(e) {}
00646     virtual void ref();
00647     virtual bool deref();
00648     virtual ~AssignExprNode();
00649     Value value(ExecState *exec) const;
00650     virtual void streamTo(SourceStream &s) const;
00651   private:
00652     Node *expr;
00653   };
00654 
00655   class VarDeclNode : public Node {
00656   public:
00657     VarDeclNode(const UString *id, AssignExprNode *in);
00658     virtual void ref();
00659     virtual bool deref();
00660     virtual ~VarDeclNode();
00661     Value value(ExecState *exec) const;
00662     virtual void processVarDecls(ExecState *exec);
00663     virtual void streamTo(SourceStream &s) const;
00664   private:
00665     UString ident;
00666     AssignExprNode *init;
00667   };
00668 
00669   class VarDeclListNode : public Node {
00670   public:
00671     VarDeclListNode(VarDeclNode *v) : list(0L), var(v) {}
00672     VarDeclListNode(Node *l, VarDeclNode *v) : list(l), var(v) {}
00673     virtual void ref();
00674     virtual bool deref();
00675     virtual ~VarDeclListNode();
00676     Value value(ExecState *exec) const;
00677     virtual void processVarDecls(ExecState *exec);
00678     virtual void streamTo(SourceStream &s) const;
00679   private:
00680     Node *list;
00681     VarDeclNode *var;
00682   };
00683 
00684   class VarStatementNode : public StatementNode {
00685   public:
00686     VarStatementNode(VarDeclListNode *l) : list(l) {}
00687     virtual void ref();
00688     virtual bool deref();
00689     virtual ~VarStatementNode();
00690     virtual Completion execute(ExecState *exec);
00691     virtual void processVarDecls(ExecState *exec);
00692     virtual void streamTo(SourceStream &s) const;
00693   private:
00694     VarDeclListNode *list;
00695   };
00696 
00697   class BlockNode : public StatementNode {
00698   public:
00699     BlockNode(SourceElementsNode *s) : source(s) {}
00700     virtual void ref();
00701     virtual bool deref();
00702     virtual ~BlockNode();
00703     virtual Completion execute(ExecState *exec);
00704     virtual void processVarDecls(ExecState *exec);
00705     virtual void streamTo(SourceStream &s) const;
00706   private:
00707     SourceElementsNode *source;
00708   };
00709 
00710   class EmptyStatementNode : public StatementNode {
00711   public:
00712     EmptyStatementNode() { } // debug
00713     virtual Completion execute(ExecState *exec);
00714     virtual void streamTo(SourceStream &s) const;
00715   };
00716 
00717   class ExprStatementNode : public StatementNode {
00718   public:
00719     ExprStatementNode(Node *e) : expr(e) { }
00720     virtual void ref();
00721     virtual bool deref();
00722     virtual ~ExprStatementNode();
00723     virtual Completion execute(ExecState *exec);
00724     virtual void streamTo(SourceStream &s) const;
00725   private:
00726     Node *expr;
00727   };
00728 
00729   class IfNode : public StatementNode {
00730   public:
00731     IfNode(Node *e, StatementNode *s1, StatementNode *s2)
00732       : expr(e), statement1(s1), statement2(s2) {}
00733     virtual void ref();
00734     virtual bool deref();
00735     virtual ~IfNode();
00736     virtual Completion execute(ExecState *exec);
00737     virtual void processVarDecls(ExecState *exec);
00738     virtual void streamTo(SourceStream &s) const;
00739   private:
00740     Node *expr;
00741     StatementNode *statement1, *statement2;
00742   };
00743 
00744   class DoWhileNode : public StatementNode {
00745   public:
00746     DoWhileNode(StatementNode *s, Node *e) : statement(s), expr(e) {}
00747     virtual void ref();
00748     virtual bool deref();
00749     virtual ~DoWhileNode();
00750     virtual Completion execute(ExecState *exec);
00751     virtual void processVarDecls(ExecState *exec);
00752     virtual void streamTo(SourceStream &s) const;
00753   private:
00754     StatementNode *statement;
00755     Node *expr;
00756   };
00757 
00758   class WhileNode : public StatementNode {
00759   public:
00760     WhileNode(Node *e, StatementNode *s) : expr(e), statement(s) {}
00761     virtual void ref();
00762     virtual bool deref();
00763     virtual ~WhileNode();
00764     virtual Completion execute(ExecState *exec);
00765     virtual void processVarDecls(ExecState *exec);
00766     virtual void streamTo(SourceStream &s) const;
00767   private:
00768     Node *expr;
00769     StatementNode *statement;
00770   };
00771 
00772   class ForNode : public StatementNode {
00773   public:
00774     ForNode(Node *e1, Node *e2, Node *e3, StatementNode *s) :
00775       expr1(e1), expr2(e2), expr3(e3), statement(s) {}
00776     virtual void ref();
00777     virtual bool deref();
00778     virtual ~ForNode();
00779     virtual Completion execute(ExecState *exec);
00780     virtual void processVarDecls(ExecState *exec);
00781     virtual void streamTo(SourceStream &s) const;
00782   private:
00783     Node *expr1, *expr2, *expr3;
00784     StatementNode *statement;
00785   };
00786 
00787   class ForInNode : public StatementNode {
00788   public:
00789     ForInNode(Node *l, Node *e, StatementNode *s);
00790     ForInNode(const UString *i, AssignExprNode *in, Node *e, StatementNode *s);
00791     virtual void ref();
00792     virtual bool deref();
00793     virtual ~ForInNode();
00794     virtual Completion execute(ExecState *exec);
00795     virtual void processVarDecls(ExecState *exec);
00796     virtual void streamTo(SourceStream &s) const;
00797   private:
00798     UString ident;
00799     AssignExprNode *init;
00800     Node *lexpr, *expr;
00801     VarDeclNode *varDecl;
00802     StatementNode *statement;
00803   };
00804 
00805   class ContinueNode : public StatementNode {
00806   public:
00807     ContinueNode() { }
00808     ContinueNode(const UString *i) : ident(*i) { }
00809     virtual Completion execute(ExecState *exec);
00810     virtual void streamTo(SourceStream &s) const;
00811   private:
00812     UString ident;
00813   };
00814 
00815   class BreakNode : public StatementNode {
00816   public:
00817     BreakNode() { }
00818     BreakNode(const UString *i) : ident(*i) { }
00819     virtual Completion execute(ExecState *exec);
00820     virtual void streamTo(SourceStream &s) const;
00821   private:
00822     UString ident;
00823   };
00824 
00825   class ReturnNode : public StatementNode {
00826   public:
00827     ReturnNode(Node *v) : value(v) {}
00828     virtual void ref();
00829     virtual bool deref();
00830     virtual ~ReturnNode();
00831     virtual Completion execute(ExecState *exec);
00832     virtual void streamTo(SourceStream &s) const;
00833   private:
00834     Node *value;
00835   };
00836 
00837   class WithNode : public StatementNode {
00838   public:
00839     WithNode(Node *e, StatementNode *s) : expr(e), statement(s) {}
00840     virtual void ref();
00841     virtual bool deref();
00842     virtual ~WithNode();
00843     virtual Completion execute(ExecState *exec);
00844     virtual void processVarDecls(ExecState *exec);
00845     virtual void streamTo(SourceStream &s) const;
00846   private:
00847     Node *expr;
00848     StatementNode *statement;
00849   };
00850 
00851   class CaseClauseNode: public Node {
00852   public:
00853     CaseClauseNode(Node *e, StatListNode *l) : expr(e), list(l) { }
00854     virtual void ref();
00855     virtual bool deref();
00856     virtual ~CaseClauseNode();
00857     Value value(ExecState *exec) const;
00858     Completion evalStatements(ExecState *exec) const;
00859     virtual void processVarDecls(ExecState *exec);
00860     virtual void streamTo(SourceStream &s) const;
00861   private:
00862     Node *expr;
00863     StatListNode *list;
00864   };
00865 
00866   class ClauseListNode : public Node {
00867   public:
00868     ClauseListNode(CaseClauseNode *c) : cl(c), nx(0L) { }
00869     virtual void ref();
00870     virtual bool deref();
00871     virtual ~ClauseListNode();
00872     ClauseListNode* append(CaseClauseNode *c);
00873     Value value(ExecState *exec) const;
00874     CaseClauseNode *clause() const { return cl; }
00875     ClauseListNode *next() const { return nx; }
00876     virtual void processVarDecls(ExecState *exec);
00877     virtual void streamTo(SourceStream &s) const;
00878   private:
00879     CaseClauseNode *cl;
00880     ClauseListNode *nx;
00881   };
00882 
00883   class CaseBlockNode: public Node {
00884   public:
00885     CaseBlockNode(ClauseListNode *l1, CaseClauseNode *d, ClauseListNode *l2)
00886       : list1(l1), def(d), list2(l2) { }
00887     virtual void ref();
00888     virtual bool deref();
00889     virtual ~CaseBlockNode();
00890     Value value(ExecState *exec) const;
00891     Completion evalBlock(ExecState *exec, const Value& input) const;
00892     virtual void processVarDecls(ExecState *exec);
00893     virtual void streamTo(SourceStream &s) const;
00894   private:
00895     ClauseListNode *list1;
00896     CaseClauseNode *def;
00897     ClauseListNode *list2;
00898   };
00899 
00900   class SwitchNode : public StatementNode {
00901   public:
00902     SwitchNode(Node *e, CaseBlockNode *b) : expr(e), block(b) { }
00903     virtual void ref();
00904     virtual bool deref();
00905     virtual ~SwitchNode();
00906     virtual Completion execute(ExecState *exec);
00907     virtual void processVarDecls(ExecState *exec);
00908     virtual void streamTo(SourceStream &s) const;
00909   private:
00910     Node *expr;
00911     CaseBlockNode *block;
00912   };
00913 
00914   class LabelNode : public StatementNode {
00915   public:
00916     LabelNode(const UString *l, StatementNode *s) : label(*l), statement(s) { }
00917     virtual void ref();
00918     virtual bool deref();
00919     virtual ~LabelNode();
00920     virtual Completion execute(ExecState *exec);
00921     virtual void processVarDecls(ExecState *exec);
00922     virtual void streamTo(SourceStream &s) const;
00923   private:
00924     UString label;
00925     StatementNode *statement;
00926   };
00927 
00928   class ThrowNode : public StatementNode {
00929   public:
00930     ThrowNode(Node *e) : expr(e) {}
00931     virtual void ref();
00932     virtual bool deref();
00933     virtual ~ThrowNode();
00934     virtual Completion execute(ExecState *exec);
00935     virtual void streamTo(SourceStream &s) const;
00936   private:
00937     Node *expr;
00938   };
00939 
00940   class CatchNode : public StatementNode {
00941   public:
00942     CatchNode(const UString *i, StatementNode *b) : ident(*i), block(b) {}
00943     virtual void ref();
00944     virtual bool deref();
00945     virtual ~CatchNode();
00946     virtual Completion execute(ExecState *exec);
00947     Completion execute(ExecState *exec, const Value &arg);
00948     virtual void processVarDecls(ExecState *exec);
00949     virtual void streamTo(SourceStream &s) const;
00950   private:
00951     UString ident;
00952     StatementNode *block;
00953   };
00954 
00955   class FinallyNode : public StatementNode {
00956   public:
00957     FinallyNode(StatementNode *b) : block(b) {}
00958     virtual void ref();
00959     virtual bool deref();
00960     virtual ~FinallyNode();
00961     virtual Completion execute(ExecState *exec);
00962     virtual void processVarDecls(ExecState *exec);
00963     virtual void streamTo(SourceStream &s) const;
00964   private:
00965     StatementNode *block;
00966   };
00967 
00968   class TryNode : public StatementNode {
00969   public:
00970     TryNode(StatementNode *b, Node *c = 0L, Node *f = 0L)
00971       : block(b), _catch((CatchNode*)c), _final((FinallyNode*)f) {}
00972     virtual void ref();
00973     virtual bool deref();
00974     virtual ~TryNode();
00975     virtual Completion execute(ExecState *exec);
00976     virtual void processVarDecls(ExecState *exec);
00977     virtual void streamTo(SourceStream &s) const;
00978   private:
00979     StatementNode *block;
00980     CatchNode *_catch;
00981     FinallyNode *_final;
00982   };
00983 
00984   class ParameterNode : public Node {
00985   public:
00986     ParameterNode(const UString *i) : id(*i), next(0L) { }
00987     ParameterNode *append(const UString *i);
00988     virtual void ref();
00989     virtual bool deref();
00990     virtual ~ParameterNode();
00991     Value value(ExecState *exec) const;
00992     UString ident() const { return id; }
00993     ParameterNode *nextParam() const { return next; }
00994     virtual void streamTo(SourceStream &s) const;
00995   private:
00996     UString id;
00997     ParameterNode *next;
00998   };
00999 
01000   // inherited by ProgramNode
01001   class FunctionBodyNode : public StatementNode {
01002   public:
01003     FunctionBodyNode(SourceElementsNode *s);
01004     virtual void ref();
01005     virtual bool deref();
01006     virtual ~FunctionBodyNode();
01007     Completion execute(ExecState *exec);
01008     virtual void processFuncDecl(ExecState *exec);
01009     virtual void processVarDecls(ExecState *exec);
01010     void streamTo(SourceStream &s) const;
01011   protected:
01012     SourceElementsNode *source;
01013   };
01014 
01015   class FuncDeclNode : public StatementNode {
01016   public:
01017     FuncDeclNode(const UString *i, ParameterNode *p, FunctionBodyNode *b)
01018       : ident(*i), param(p), body(b) { }
01019     virtual void ref();
01020     virtual bool deref();
01021     virtual ~FuncDeclNode();
01022     Completion execute(ExecState */*exec*/)
01023       { /* empty */ return Completion(); }
01024     void processFuncDecl(ExecState *exec);
01025     virtual void streamTo(SourceStream &s) const;
01026   private:
01027     UString ident;
01028     ParameterNode *param;
01029     FunctionBodyNode *body;
01030   };
01031 
01032   class FuncExprNode : public Node {
01033   public:
01034     FuncExprNode(ParameterNode *p, FunctionBodyNode *b)
01035     : param(p), body(b) { }
01036     virtual void ref();
01037     virtual bool deref();
01038     virtual ~FuncExprNode();
01039     Value value(ExecState *exec) const;
01040     virtual void streamTo(SourceStream &s) const;
01041   private:
01042     ParameterNode *param;
01043     FunctionBodyNode *body;
01044   };
01045 
01046   class SourceElementNode : public StatementNode {
01047   public:
01048     SourceElementNode(StatementNode *s) : statement(s), function(0L) { }
01049     SourceElementNode(FuncDeclNode *f) : statement(0L), function(f) { }
01050     virtual void ref();
01051     virtual bool deref();
01052     virtual ~SourceElementNode();
01053     Completion execute(ExecState *exec);
01054     virtual void processFuncDecl(ExecState *exec);
01055     virtual void processVarDecls(ExecState *exec);
01056     virtual void streamTo(SourceStream &s) const;
01057   private:
01058     StatementNode *statement;
01059     FuncDeclNode *function;
01060   };
01061 
01062   // A linked list of source element nodes
01063   class SourceElementsNode : public StatementNode {
01064   public:
01065     SourceElementsNode(SourceElementNode *s1) { element = s1; elements = 0L; }
01066     SourceElementsNode(SourceElementsNode *s1, SourceElementNode *s2)
01067       { elements = s1; element = s2; }
01068     virtual void ref();
01069     virtual bool deref();
01070     virtual ~SourceElementsNode();
01071     Completion execute(ExecState *exec);
01072     virtual void processFuncDecl(ExecState *exec);
01073     virtual void processVarDecls(ExecState *exec);
01074     virtual void streamTo(SourceStream &s) const;
01075   private:
01076     SourceElementNode *element; // 'this' element
01077     SourceElementsNode *elements; // pointer to next
01078   };
01079 
01080   class ProgramNode : public FunctionBodyNode {
01081   public:
01082     ProgramNode(SourceElementsNode *s);
01083     ~ProgramNode();
01084   private:
01085     // Disallow copy
01086     ProgramNode(const ProgramNode &other);
01087   };
01088 
01089 }; // namespace
01090 
01091 #endif
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Oct 8 12:21:15 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001