• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kjs
 

kjs

  • kjs
nodes.h
1 // -*- c-basic-offset: 2 -*-
2 /*
3  * This file is part of the KDE libraries
4  * Copyright (C) 1999-2000, 2003 Harri Porten (porten@kde.org)
5  * Copyright (C) 2001 Peter Kelly (pmk@post.com)
6  * Copyright (C) 2003 Apple Computer, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public License
19  * along with this library; see the file COPYING.LIB. If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  *
23  */
24 
25 #ifndef _NODES_H_
26 #define _NODES_H_
27 
28 #include "internal.h"
29 //#include "debugger.h"
30 #ifndef NDEBUG
31 #include <list>
32 #include <assert.h>
33 #endif
34 
35 namespace KJS {
36 
37  class RegExp;
38  class SourceElementsNode;
39  class ObjectLiteralNode;
40  class PropertyNode;
41  class SourceStream;
42  class PropertyValueNode;
43  class PropertyNode;
44 
45  enum Operator { OpEqual,
46  OpEqEq,
47  OpNotEq,
48  OpStrEq,
49  OpStrNEq,
50  OpPlusEq,
51  OpMinusEq,
52  OpMultEq,
53  OpDivEq,
54  OpPlusPlus,
55  OpMinusMinus,
56  OpLess,
57  OpLessEq,
58  OpGreater,
59  OpGreaterEq,
60  OpAndEq,
61  OpXOrEq,
62  OpOrEq,
63  OpModEq,
64  OpAnd,
65  OpOr,
66  OpBitAnd,
67  OpBitXOr,
68  OpBitOr,
69  OpLShift,
70  OpRShift,
71  OpURShift,
72  OpIn,
73  OpInstanceOf
74  };
75 
76  class Node {
77  public:
78  Node();
79  virtual ~Node();
80 
81  // reusing Value Type here, declare new enum if required
82  virtual Type type() const { return UnspecifiedType; }
83 
87  virtual Reference evaluateReference(ExecState *exec) const;
91  virtual Value evaluate(ExecState *exec) const;
92  virtual bool toBoolean(ExecState *exec) const;
93  virtual double toNumber(ExecState *exec) const;
94  virtual UString toString(ExecState *exec) const;
95 
96  UString toCode() const;
97  virtual void streamTo(SourceStream &s) const = 0;
98  virtual void processVarDecls(ExecState* /*exec*/) {}
99  int lineNo() const { return line; }
100 
101  public:
102  // reference counting mechanism
103  virtual void ref() { refcount++; }
104 #ifdef KJS_DEBUG_MEM
105  virtual bool deref() { assert( refcount > 0 ); return (!--refcount); }
106 #else
107  virtual bool deref() { return (!--refcount); }
108 #endif
109 
110 
111 #ifdef KJS_DEBUG_MEM
112  static void finalCheck();
113 #endif
114  protected:
115  Value throwError(ExecState *exec, ErrorType e, const char *msg) const;
116  Value throwError(ExecState *exec, ErrorType e, const char *msg,
117  const Value &v, const Node *expr) const;
118  Value throwError(ExecState *exec, ErrorType e, const char *msg, Identifier label) const;
119  void setExceptionDetailsIfNeeded(ExecState *exec) const;
120  int line;
121  unsigned int refcount;
122  virtual int sourceId() const { return -1; }
123  private:
124 #ifdef KJS_DEBUG_MEM
125  // List of all nodes, for debugging purposes. Don't remove!
126  static std::list<Node *> *s_nodes;
127 #endif
128  // disallow assignment
129  Node& operator=(const Node&);
130  Node(const Node &other);
131  };
132 
133  class StatementNode : public Node {
134  public:
135  StatementNode();
136  virtual ~StatementNode();
137  void setLoc(int line0, int line1, SourceCode *src);
138  int firstLine() const { return l0; }
139  int lastLine() const { return l1; }
140  int sourceId() const { return sourceCode->sid; }
141  SourceCode *code() const { return sourceCode; }
142  bool hitStatement(ExecState *exec);
143  bool abortStatement(ExecState *exec);
144  virtual Completion execute(ExecState *exec) = 0;
145  void pushLabel(const Identifier &id) { ls.push(id); }
146  virtual void processFuncDecl(ExecState *exec);
147  protected:
148  LabelStack ls;
149  private:
150  Reference evaluateReference(ExecState* /*exec*/) const { return Reference(0,Identifier::null()); }
151  int l0, l1;
152  SourceCode *sourceCode;
153  bool breakPoint;
154  };
155 
156  class NullNode : public Node {
157  public:
158  NullNode() {}
159  virtual Value evaluate(ExecState *exec) const;
160  virtual bool toBoolean(ExecState *exec) const;
161  virtual double toNumber(ExecState *exec) const;
162  virtual UString toString(ExecState *exec) const;
163  virtual void streamTo(SourceStream &s) const;
164  };
165 
166  class BooleanNode : public Node {
167  public:
168  BooleanNode(bool v) : val(v) {}
169  virtual Type type() const { return BooleanType; }
170  virtual Value evaluate(ExecState *exec) const;
171  virtual bool toBoolean(ExecState *exec) const;
172  virtual double toNumber(ExecState *exec) const;
173  virtual UString toString(ExecState *exec) const;
174  virtual void streamTo(SourceStream &s) const;
175  private:
176  bool val;
177  };
178 
179  class NumberNode : public Node {
180  public:
181  NumberNode(double v) : val(v) { }
182  virtual Type type() const { return NumberType; }
183  virtual Value evaluate(ExecState *exec) const;
184  virtual bool toBoolean(ExecState *exec) const;
185  virtual double toNumber(ExecState *exec) const;
186  virtual UString toString(ExecState *exec) const;
187  virtual void streamTo(SourceStream &s) const;
188  private:
189  double val;
190  };
191 
192  class StringNode : public Node {
193  public:
194  StringNode(const UString *v) : val(*v) { }
195  virtual Type type() const { return StringType; }
196  virtual Value evaluate(ExecState *exec) const;
197  virtual bool toBoolean(ExecState *exec) const;
198  virtual double toNumber(ExecState *exec) const;
199  virtual UString toString(ExecState *exec) const;
200  virtual void streamTo(SourceStream &s) const;
201  private:
202  UString val;
203  };
204 
205  class RegExpNode : public Node {
206  public:
207  RegExpNode(const UString &p, const UString &f)
208  : pattern(p), flags(f) { }
209  virtual Value evaluate(ExecState *exec) const;
210  virtual bool toBoolean(ExecState *exec) const;
211  virtual void streamTo(SourceStream &s) const;
212  private:
213  UString pattern, flags;
214  };
215 
216  class ThisNode : public Node {
217  public:
218  ThisNode() {}
219  virtual Value evaluate(ExecState *exec) const;
220  virtual void streamTo(SourceStream &s) const;
221  };
222 
223  class ResolveNode : public Node {
224  public:
225  ResolveNode(const Identifier &s) : ident(s) { }
226  Reference evaluateReference(ExecState *exec) const;
227  virtual Value evaluate(ExecState *exec) const;
228  virtual void streamTo(SourceStream &s) const;
229  private:
230  Identifier ident;
231  };
232 
233  class GroupNode : public Node {
234  public:
235  GroupNode(Node *g) : group(g) { }
236  virtual void ref();
237  virtual bool deref();
238  Reference evaluateReference(ExecState *exec) const;
239  virtual Value evaluate(ExecState *exec) const;
240  virtual void streamTo(SourceStream &s) const;
241  private:
242  Node *group;
243  };
244 
245  class ElementNode : public Node {
246  public:
247  // list is circular during construction. cracked in ArrayNode ctor
248  ElementNode(int e, Node *n) : list(this), elision(e), node(n) { }
249  ElementNode(ElementNode *l, int e, Node *n)
250  : list(l->list), elision(e), node(n) { l->list = this; }
251  virtual void ref();
252  virtual bool deref();
253  virtual Value evaluate(ExecState *exec) const;
254  virtual void streamTo(SourceStream &s) const;
255  private:
256  friend class ArrayNode;
257  ElementNode *list;
258  int elision;
259  Node *node;
260  };
261 
262  class ArrayNode : public Node {
263  public:
264  ArrayNode(int e) : element(0L), elision(e), opt(true) { }
265  ArrayNode(ElementNode *ele)
266  : element(ele->list), elision(0), opt(false) { ele->list = 0; }
267  ArrayNode(int eli, ElementNode *ele)
268  : element(ele->list), elision(eli), opt(true) { ele->list = 0; }
269  virtual void ref();
270  virtual bool deref();
271  virtual Value evaluate(ExecState *exec) const;
272  virtual void streamTo(SourceStream &s) const;
273  private:
274  ElementNode *element;
275  int elision;
276  bool opt;
277  };
278 
279  class PropertyValueNode : public Node {
280  public:
281  // list is circular during construction, cut in ObjectLiteralNode ctor
282  PropertyValueNode(PropertyNode *n, Node *a)
283  : name(n), assign(a), list(this) { }
284  PropertyValueNode(PropertyNode *n, Node *a, PropertyValueNode *l)
285  : name(n), assign(a), list(l->list) { l->list = this; }
286  virtual void ref();
287  virtual bool deref();
288  virtual Value evaluate(ExecState *exec) const;
289  virtual void streamTo(SourceStream &s) const;
290  private:
291  friend class ObjectLiteralNode;
292  PropertyNode *name;
293  Node *assign;
294  PropertyValueNode *list;
295  };
296 
297  class PropertyNode : public Node {
298  public:
299  PropertyNode(double d) : numeric(d) { }
300  PropertyNode(const Identifier &s) : str(s) { }
301  virtual Value evaluate(ExecState *exec) const;
302  virtual void streamTo(SourceStream &s) const;
303  private:
304  double numeric;
305  Identifier str;
306  };
307 
308  class ObjectLiteralNode : public Node {
309  public:
310  // empty literal
311  ObjectLiteralNode() : list(0) { }
312  // l points to last list element, get and detach pointer to first one
313  ObjectLiteralNode(PropertyValueNode *l) : list(l->list) { l->list = 0; }
314  virtual void ref();
315  virtual bool deref();
316  virtual Value evaluate(ExecState *exec) const;
317  virtual void streamTo(SourceStream &s) const;
318  private:
319  PropertyValueNode *list;
320  };
321 
322  class AccessorNode1 : public Node {
323  public:
324  AccessorNode1(Node *e1, Node *e2) : expr1(e1), expr2(e2) {}
325  virtual void ref();
326  virtual bool deref();
327  Reference evaluateReference(ExecState *exec) const;
328  virtual void streamTo(SourceStream &s) const;
329  private:
330  Node *expr1;
331  Node *expr2;
332  };
333 
334  class AccessorNode2 : public Node {
335  public:
336  AccessorNode2(Node *e, const Identifier &s) : expr(e), ident(s) { }
337  virtual void ref();
338  virtual bool deref();
339  Reference evaluateReference(ExecState *exec) const;
340  virtual void streamTo(SourceStream &s) const;
341  private:
342  Node *expr;
343  Identifier ident;
344  };
345 
346  class ArgumentListNode : public Node {
347  public:
348  // list is circular during construction. cracked in ArgumentsNode ctor
349  ArgumentListNode(Node *e) : list(this), expr(e) {}
350  ArgumentListNode(ArgumentListNode *l, Node *e)
351  : list(l->list), expr(e) { l->list = this; }
352  virtual void ref();
353  virtual bool deref();
354  virtual Value evaluate(ExecState *exec) const;
355  List evaluateList(ExecState *exec) const;
356  virtual void streamTo(SourceStream &s) const;
357  private:
358  friend class ArgumentsNode;
359  ArgumentListNode *list;
360  Node *expr;
361  };
362 
363  class ArgumentsNode : public Node {
364  public:
365  ArgumentsNode() : list(0) {}
366  ArgumentsNode(ArgumentListNode *l) : list(l->list) { l->list = 0; }
367  virtual void ref();
368  virtual bool deref();
369  virtual Value evaluate(ExecState *exec) const;
370  List evaluateList(ExecState *exec) const;
371  virtual void streamTo(SourceStream &s) const;
372  private:
373  ArgumentListNode *list;
374  };
375 
376  class NewExprNode : public Node {
377  public:
378  NewExprNode(Node *e) : expr(e), args(0L) {}
379  NewExprNode(Node *e, ArgumentsNode *a) : expr(e), args(a) {}
380  virtual void ref();
381  virtual bool deref();
382  virtual Value evaluate(ExecState *exec) const;
383  virtual void streamTo(SourceStream &s) const;
384  private:
385  Node *expr;
386  ArgumentsNode *args;
387  };
388 
389  class FunctionCallNode : public Node {
390  public:
391  FunctionCallNode(Node *e, ArgumentsNode *a) : expr(e), args(a) {}
392  virtual void ref();
393  virtual bool deref();
394  virtual Value evaluate(ExecState *exec) const;
395  virtual void streamTo(SourceStream &s) const;
396  private:
397  Node *expr;
398  ArgumentsNode *args;
399  };
400 
401  class PostfixNode : public Node {
402  public:
403  PostfixNode(Node *e, Operator o) : expr(e), oper(o) {}
404  virtual void ref();
405  virtual bool deref();
406  virtual Value evaluate(ExecState *exec) const;
407  virtual void streamTo(SourceStream &s) const;
408  private:
409  Node *expr;
410  Operator oper;
411  };
412 
413  class DeleteNode : public Node {
414  public:
415  DeleteNode(Node *e) : expr(e) {}
416  virtual void ref();
417  virtual bool deref();
418  virtual Value evaluate(ExecState *exec) const;
419  virtual void streamTo(SourceStream &s) const;
420  private:
421  Node *expr;
422  };
423 
424  class VoidNode : public Node {
425  public:
426  VoidNode(Node *e) : expr(e) {}
427  virtual void ref();
428  virtual bool deref();
429  virtual Value evaluate(ExecState *exec) const;
430  virtual void streamTo(SourceStream &s) const;
431  private:
432  Node *expr;
433  };
434 
435  class TypeOfNode : public Node {
436  public:
437  TypeOfNode(Node *e) : expr(e) {}
438  virtual void ref();
439  virtual bool deref();
440  virtual Value evaluate(ExecState *exec) const;
441  virtual void streamTo(SourceStream &s) const;
442  private:
443  Node *expr;
444  };
445 
446  class PrefixNode : public Node {
447  public:
448  PrefixNode(Operator o, Node *e) : oper(o), expr(e) {}
449  virtual void ref();
450  virtual bool deref();
451  virtual Value evaluate(ExecState *exec) const;
452  virtual void streamTo(SourceStream &s) const;
453  private:
454  Operator oper;
455  Node *expr;
456  };
457 
458  class UnaryPlusNode : public Node {
459  public:
460  UnaryPlusNode(Node *e) : expr(e) {}
461  virtual void ref();
462  virtual bool deref();
463  virtual Value evaluate(ExecState *exec) const;
464  virtual double toNumber(ExecState *exec) const;
465  virtual void streamTo(SourceStream &s) const;
466  private:
467  Node *expr;
468  };
469 
470  class NegateNode : public Node {
471  public:
472  NegateNode(Node *e) : expr(e) {}
473  virtual void ref();
474  virtual bool deref();
475  virtual Value evaluate(ExecState *exec) const;
476  virtual double toNumber(ExecState *exec) const;
477  virtual void streamTo(SourceStream &s) const;
478  private:
479  Node *expr;
480  };
481 
482  class BitwiseNotNode : public Node {
483  public:
484  BitwiseNotNode(Node *e) : expr(e) {}
485  virtual void ref();
486  virtual bool deref();
487  virtual Value evaluate(ExecState *exec) const;
488  virtual void streamTo(SourceStream &s) const;
489  private:
490  Node *expr;
491  };
492 
493  class LogicalNotNode : public Node {
494  public:
495  LogicalNotNode(Node *e) : expr(e) {}
496  virtual void ref();
497  virtual bool deref();
498  virtual Value evaluate(ExecState *exec) const;
499  virtual bool toBoolean(ExecState *exec) const;
500  virtual void streamTo(SourceStream &s) const;
501  private:
502  Node *expr;
503  };
504 
505  class MultNode : public Node {
506  public:
507  MultNode(Node *t1, Node *t2, char op) : term1(t1), term2(t2), oper(op) {}
508  virtual void ref();
509  virtual bool deref();
510  virtual Value evaluate(ExecState *exec) const;
511  virtual void streamTo(SourceStream &s) const;
512  private:
513  Node *term1, *term2;
514  char oper;
515  };
516 
517  class AddNode : public Node {
518  public:
519  AddNode(Node *t1, Node *t2, char op) : term1(t1), term2(t2), oper(op) {}
520 
521  static Node* create(Node *t1, Node *t2, char op);
522 
523  virtual void ref();
524  virtual bool deref();
525  virtual Value evaluate(ExecState *exec) const;
526  virtual void streamTo(SourceStream &s) const;
527  private:
528  Node *term1, *term2;
529  char oper;
530  };
531 
532  class AppendStringNode : public Node {
533  public:
534  AppendStringNode(Node *t, const UString &s) : term(t), str(s) { }
535  virtual void ref();
536  virtual bool deref();
537  virtual Value evaluate(ExecState *exec) const;
538  virtual void streamTo(SourceStream &s) const;
539  private:
540  Node *term;
541  UString str;
542  };
543 
544  class ShiftNode : public Node {
545  public:
546  ShiftNode(Node *t1, Operator o, Node *t2)
547  : term1(t1), term2(t2), oper(o) {}
548  virtual void ref();
549  virtual bool deref();
550  virtual Value evaluate(ExecState *exec) const;
551  virtual void streamTo(SourceStream &s) const;
552  private:
553  Node *term1, *term2;
554  Operator oper;
555  };
556 
557  class RelationalNode : public Node {
558  public:
559  RelationalNode(Node *e1, Operator o, Node *e2) :
560  expr1(e1), expr2(e2), oper(o) {}
561  virtual void ref();
562  virtual bool deref();
563  virtual Value evaluate(ExecState *exec) const;
564  virtual void streamTo(SourceStream &s) const;
565  private:
566  Node *expr1, *expr2;
567  Operator oper;
568  };
569 
570  class EqualNode : public Node {
571  public:
572  EqualNode(Node *e1, Operator o, Node *e2)
573  : expr1(e1), expr2(e2), oper(o) {}
574  virtual void ref();
575  virtual bool deref();
576  virtual Value evaluate(ExecState *exec) const;
577  virtual void streamTo(SourceStream &s) const;
578  private:
579  Node *expr1, *expr2;
580  Operator oper;
581  };
582 
583  class BitOperNode : public Node {
584  public:
585  BitOperNode(Node *e1, Operator o, Node *e2) :
586  expr1(e1), expr2(e2), oper(o) {}
587  virtual void ref();
588  virtual bool deref();
589  virtual Value evaluate(ExecState *exec) const;
590  virtual void streamTo(SourceStream &s) const;
591  private:
592  Node *expr1, *expr2;
593  Operator oper;
594  };
595 
599  class BinaryLogicalNode : public Node {
600  public:
601  BinaryLogicalNode(Node *e1, Operator o, Node *e2) :
602  expr1(e1), expr2(e2), oper(o) {}
603  virtual void ref();
604  virtual bool deref();
605  virtual Value evaluate(ExecState *exec) const;
606  virtual void streamTo(SourceStream &s) const;
607  private:
608  Node *expr1, *expr2;
609  Operator oper;
610  };
611 
615  class ConditionalNode : public Node {
616  public:
617  ConditionalNode(Node *l, Node *e1, Node *e2) :
618  logical(l), expr1(e1), expr2(e2) {}
619  virtual void ref();
620  virtual bool deref();
621  virtual Value evaluate(ExecState *exec) const;
622  virtual void streamTo(SourceStream &s) const;
623  private:
624  Node *logical, *expr1, *expr2;
625  };
626 
627  class AssignNode : public Node {
628  public:
629  AssignNode(Node *l, Operator o, Node *e) : left(l), oper(o), expr(e) {}
630  virtual void ref();
631  virtual bool deref();
632  virtual Value evaluate(ExecState *exec) const;
633  virtual void streamTo(SourceStream &s) const;
634  private:
635  Node *left;
636  Operator oper;
637  Node *expr;
638  };
639 
640  class CommaNode : public Node {
641  public:
642  CommaNode(Node *e1, Node *e2) : expr1(e1), expr2(e2) {}
643  virtual void ref();
644  virtual bool deref();
645  virtual Value evaluate(ExecState *exec) const;
646  virtual void streamTo(SourceStream &s) const;
647  private:
648  Node *expr1, *expr2;
649  };
650 
651  class StatListNode : public StatementNode {
652  public:
653  // list is circular during construction. cracked in CaseClauseNode ctor
654  StatListNode(StatementNode *s);
655  StatListNode(StatListNode *l, StatementNode *s);
656  virtual void ref();
657  virtual bool deref();
658  virtual Completion execute(ExecState *exec);
659  virtual void processVarDecls(ExecState *exec);
660  virtual void streamTo(SourceStream &s) const;
661  private:
662  friend class CaseClauseNode;
663  StatementNode *statement;
664  StatListNode *list;
665  };
666 
667  class AssignExprNode : public Node {
668  public:
669  AssignExprNode(Node *e) : expr(e) {}
670  virtual void ref();
671  virtual bool deref();
672  virtual Value evaluate(ExecState *exec) const;
673  virtual void streamTo(SourceStream &s) const;
674  private:
675  Node *expr;
676  };
677 
678  class VarDeclNode : public Node {
679  public:
680  enum Type { Variable, Constant };
681  VarDeclNode(const Identifier &id, AssignExprNode *in, Type t);
682  virtual void ref();
683  virtual bool deref();
684  virtual Value evaluate(ExecState *exec) const;
685  virtual void processVarDecls(ExecState *exec);
686  virtual void streamTo(SourceStream &s) const;
687  private:
688  Type varType;
689  Identifier ident;
690  AssignExprNode *init;
691  };
692 
693  class VarDeclListNode : public Node {
694  public:
695  // list pointer is tail of a circular list, cracked in the ForNode/VarStatementNode ctor
696  VarDeclListNode(VarDeclNode *v) : list(this), var(v) {}
697  VarDeclListNode(VarDeclListNode *l, VarDeclNode *v)
698  : list(l->list), var(v) { l->list = this; }
699  virtual void ref();
700  virtual bool deref();
701  virtual Value evaluate(ExecState *exec) const;
702  virtual void processVarDecls(ExecState *exec);
703  virtual void streamTo(SourceStream &s) const;
704  private:
705  friend class ForNode;
706  friend class VarStatementNode;
707  VarDeclListNode *list;
708  VarDeclNode *var;
709  };
710 
711  class VarStatementNode : public StatementNode {
712  public:
713  VarStatementNode(VarDeclListNode *l) : list(l->list) { l->list = 0; }
714  virtual void ref();
715  virtual bool deref();
716  virtual Completion execute(ExecState *exec);
717  virtual void processVarDecls(ExecState *exec);
718  virtual void streamTo(SourceStream &s) const;
719  private:
720  VarDeclListNode *list;
721  };
722 
723  class BlockNode : public StatementNode {
724  public:
725  BlockNode(SourceElementsNode *s);
726  virtual void ref();
727  virtual bool deref();
728  virtual Completion execute(ExecState *exec);
729  virtual void processVarDecls(ExecState *exec);
730  virtual void streamTo(SourceStream &s) const;
731  protected:
732  SourceElementsNode *source;
733  };
734 
735  class EmptyStatementNode : public StatementNode {
736  public:
737  EmptyStatementNode() { } // debug
738  virtual Completion execute(ExecState *exec);
739  virtual void streamTo(SourceStream &s) const;
740  };
741 
742  class ExprStatementNode : public StatementNode {
743  public:
744  ExprStatementNode(Node *e) : expr(e) { }
745  virtual void ref();
746  virtual bool deref();
747  virtual Completion execute(ExecState *exec);
748  virtual void streamTo(SourceStream &s) const;
749  private:
750  Node *expr;
751  };
752 
753  class IfNode : public StatementNode {
754  public:
755  IfNode(Node *e, StatementNode *s1, StatementNode *s2)
756  : expr(e), statement1(s1), statement2(s2) {}
757  virtual void ref();
758  virtual bool deref();
759  virtual Completion execute(ExecState *exec);
760  virtual void processVarDecls(ExecState *exec);
761  virtual void streamTo(SourceStream &s) const;
762  private:
763  Node *expr;
764  StatementNode *statement1, *statement2;
765  };
766 
767  class DoWhileNode : public StatementNode {
768  public:
769  DoWhileNode(StatementNode *s, Node *e) : statement(s), expr(e) {}
770  virtual void ref();
771  virtual bool deref();
772  virtual Completion execute(ExecState *exec);
773  virtual void processVarDecls(ExecState *exec);
774  virtual void streamTo(SourceStream &s) const;
775  private:
776  StatementNode *statement;
777  Node *expr;
778  };
779 
780  class WhileNode : public StatementNode {
781  public:
782  WhileNode(Node *e, StatementNode *s) : expr(e), statement(s) {}
783  virtual void ref();
784  virtual bool deref();
785  virtual Completion execute(ExecState *exec);
786  virtual void processVarDecls(ExecState *exec);
787  virtual void streamTo(SourceStream &s) const;
788  private:
789  Node *expr;
790  StatementNode *statement;
791  };
792 
793  class ForNode : public StatementNode {
794  public:
795  ForNode(Node *e1, Node *e2, Node *e3, StatementNode *s) :
796  expr1(e1), expr2(e2), expr3(e3), statement(s) {}
797  ForNode(VarDeclListNode *e1, Node *e2, Node *e3, StatementNode *s) :
798  expr1(e1->list), expr2(e2), expr3(e3), statement(s) { e1->list = 0; }
799  virtual void ref();
800  virtual bool deref();
801  virtual Completion execute(ExecState *exec);
802  virtual void processVarDecls(ExecState *exec);
803  virtual void streamTo(SourceStream &s) const;
804  private:
805  Node *expr1, *expr2, *expr3;
806  StatementNode *statement;
807  };
808 
809  class ForInNode : public StatementNode {
810  public:
811  ForInNode(Node *l, Node *e, StatementNode *s);
812  ForInNode(const Identifier &i, AssignExprNode *in, Node *e, StatementNode *s);
813  virtual void ref();
814  virtual bool deref();
815  virtual Completion execute(ExecState *exec);
816  virtual void processVarDecls(ExecState *exec);
817  virtual void streamTo(SourceStream &s) const;
818  private:
819  Identifier ident;
820  AssignExprNode *init;
821  Node *lexpr, *expr;
822  VarDeclNode *varDecl;
823  StatementNode *statement;
824  };
825 
826  class ContinueNode : public StatementNode {
827  public:
828  ContinueNode() { }
829  ContinueNode(const Identifier &i) : ident(i) { }
830  virtual Completion execute(ExecState *exec);
831  virtual void streamTo(SourceStream &s) const;
832  private:
833  Identifier ident;
834  };
835 
836  class BreakNode : public StatementNode {
837  public:
838  BreakNode() { }
839  BreakNode(const Identifier &i) : ident(i) { }
840  virtual Completion execute(ExecState *exec);
841  virtual void streamTo(SourceStream &s) const;
842  private:
843  Identifier ident;
844  };
845 
846  class ReturnNode : public StatementNode {
847  public:
848  ReturnNode(Node *v) : value(v) {}
849  virtual void ref();
850  virtual bool deref();
851  virtual Completion execute(ExecState *exec);
852  virtual void streamTo(SourceStream &s) const;
853  private:
854  Node *value;
855  };
856 
857  class WithNode : public StatementNode {
858  public:
859  WithNode(Node *e, StatementNode *s) : expr(e), statement(s) {}
860  virtual void ref();
861  virtual bool deref();
862  virtual Completion execute(ExecState *exec);
863  virtual void processVarDecls(ExecState *exec);
864  virtual void streamTo(SourceStream &s) const;
865  private:
866  Node *expr;
867  StatementNode *statement;
868  };
869 
870  class CaseClauseNode : public Node {
871  public:
872  CaseClauseNode(Node *e) : expr(e), list(0) { }
873  CaseClauseNode(Node *e, StatListNode *l)
874  : expr(e), list(l->list) { l->list = 0; }
875  virtual void ref();
876  virtual bool deref();
877  virtual Value evaluate(ExecState *exec) const;
878  Completion evalStatements(ExecState *exec) const;
879  virtual void processVarDecls(ExecState *exec);
880  virtual void streamTo(SourceStream &s) const;
881  private:
882  Node *expr;
883  StatListNode *list;
884  };
885 
886  class ClauseListNode : public Node {
887  public:
888  // list is circular during construction. cracked in CaseBlockNode ctor
889  ClauseListNode(CaseClauseNode *c) : cl(c), nx(this) { }
890  ClauseListNode(ClauseListNode *n, CaseClauseNode *c)
891  : cl(c), nx(n->nx) { n->nx = this; }
892  virtual void ref();
893  virtual bool deref();
894  virtual Value evaluate(ExecState *exec) const;
895  CaseClauseNode *clause() const { return cl; }
896  ClauseListNode *next() const { return nx; }
897  virtual void processVarDecls(ExecState *exec);
898  virtual void streamTo(SourceStream &s) const;
899  private:
900  friend class CaseBlockNode;
901  CaseClauseNode *cl;
902  ClauseListNode *nx;
903  };
904 
905  class CaseBlockNode: public Node {
906  public:
907  CaseBlockNode(ClauseListNode *l1, CaseClauseNode *d, ClauseListNode *l2);
908  virtual void ref();
909  virtual bool deref();
910  virtual Value evaluate(ExecState *exec) const;
911  Completion evalBlock(ExecState *exec, const Value& input) const;
912  virtual void processVarDecls(ExecState *exec);
913  virtual void streamTo(SourceStream &s) const;
914  private:
915  ClauseListNode *list1;
916  CaseClauseNode *def;
917  ClauseListNode *list2;
918  };
919 
920  class SwitchNode : public StatementNode {
921  public:
922  SwitchNode(Node *e, CaseBlockNode *b) : expr(e), block(b) { }
923  virtual void ref();
924  virtual bool deref();
925  virtual Completion execute(ExecState *exec);
926  virtual void processVarDecls(ExecState *exec);
927  virtual void streamTo(SourceStream &s) const;
928  private:
929  Node *expr;
930  CaseBlockNode *block;
931  };
932 
933  class LabelNode : public StatementNode {
934  public:
935  LabelNode(const Identifier &l, StatementNode *s) : label(l), statement(s) { }
936  virtual void ref();
937  virtual bool deref();
938  virtual Completion execute(ExecState *exec);
939  virtual void processVarDecls(ExecState *exec);
940  virtual void streamTo(SourceStream &s) const;
941  private:
942  Identifier label;
943  StatementNode *statement;
944  };
945 
946  class ThrowNode : public StatementNode {
947  public:
948  ThrowNode(Node *e) : expr(e) {}
949  virtual void ref();
950  virtual bool deref();
951  virtual Completion execute(ExecState *exec);
952  virtual void streamTo(SourceStream &s) const;
953  private:
954  Node *expr;
955  };
956 
957  class CatchNode : public StatementNode {
958  public:
959  CatchNode(const Identifier &i, StatementNode *b) : ident(i), block(b) {}
960  virtual void ref();
961  virtual bool deref();
962  virtual Completion execute(ExecState *exec);
963  Completion execute(ExecState *exec, const Value &arg);
964  virtual void processVarDecls(ExecState *exec);
965  virtual void streamTo(SourceStream &s) const;
966  private:
967  Identifier ident;
968  StatementNode *block;
969  };
970 
971  class FinallyNode : public StatementNode {
972  public:
973  FinallyNode(StatementNode *b) : block(b) {}
974  virtual void ref();
975  virtual bool deref();
976  virtual Completion execute(ExecState *exec);
977  virtual void processVarDecls(ExecState *exec);
978  virtual void streamTo(SourceStream &s) const;
979  private:
980  StatementNode *block;
981  };
982 
983  class TryNode : public StatementNode {
984  public:
985  TryNode(StatementNode *b, CatchNode *c)
986  : block(b), _catch(c), _final(0) {}
987  TryNode(StatementNode *b, FinallyNode *f)
988  : block(b), _catch(0), _final(f) {}
989  TryNode(StatementNode *b, CatchNode *c, FinallyNode *f)
990  : block(b), _catch(c), _final(f) {}
991  virtual void ref();
992  virtual bool deref();
993  virtual Completion execute(ExecState *exec);
994  virtual void processVarDecls(ExecState *exec);
995  virtual void streamTo(SourceStream &s) const;
996  private:
997  StatementNode *block;
998  CatchNode *_catch;
999  FinallyNode *_final;
1000  };
1001 
1002  class ParameterNode : public Node {
1003  public:
1004  // list is circular during construction. cracked in FuncDecl/ExprNode ctor.
1005  ParameterNode(const Identifier &i) : id(i), next(this) { }
1006  ParameterNode(ParameterNode *list, const Identifier &i)
1007  : id(i), next(list->next) { list->next = this; }
1008  virtual void ref();
1009  virtual bool deref();
1010  virtual Value evaluate(ExecState *exec) const;
1011  Identifier ident() const { return id; }
1012  ParameterNode *nextParam() const { return next; }
1013  virtual void streamTo(SourceStream &s) const;
1014  private:
1015  friend class FuncDeclNode;
1016  friend class FuncExprNode;
1017  Identifier id;
1018  ParameterNode *next;
1019  };
1020 
1021  // inherited by ProgramNode
1022  class FunctionBodyNode : public BlockNode {
1023  public:
1024  FunctionBodyNode(SourceElementsNode *s);
1025  virtual void processFuncDecl(ExecState *exec);
1026  };
1027 
1028  class FuncDeclNode : public StatementNode {
1029  public:
1030  FuncDeclNode(const Identifier &i, FunctionBodyNode *b)
1031  : ident(i), param(0), body(b) { }
1032  FuncDeclNode(const Identifier &i, ParameterNode *p, FunctionBodyNode *b)
1033  : ident(i), param(p->next), body(b) { p->next = 0; }
1034  virtual void ref();
1035  virtual bool deref();
1036  Completion execute(ExecState* /*exec*/)
1037  { /* empty */ return Completion(); }
1038  void processFuncDecl(ExecState *exec);
1039  virtual void streamTo(SourceStream &s) const;
1040  private:
1041  Identifier ident;
1042  ParameterNode *param;
1043  FunctionBodyNode *body;
1044  };
1045 
1046  class FuncExprNode : public Node {
1047  public:
1048  FuncExprNode(const Identifier &i, FunctionBodyNode *b)
1049  : ident(i), param(0), body(b) { }
1050  FuncExprNode(const Identifier &i, ParameterNode *p, FunctionBodyNode *b)
1051  : ident(i), param(p->next), body(b) { p->next = 0; }
1052  virtual void ref();
1053  virtual bool deref();
1054  virtual Value evaluate(ExecState *exec) const;
1055  virtual void streamTo(SourceStream &s) const;
1056  private:
1057  Identifier ident;
1058  ParameterNode *param;
1059  FunctionBodyNode *body;
1060  };
1061 
1062  // A linked list of source element nodes
1063  class SourceElementsNode : public StatementNode {
1064  public:
1065  // list is circular until cracked in BlockNode (or subclass) ctor
1066  SourceElementsNode(StatementNode *s1);
1067  SourceElementsNode(SourceElementsNode *s1, StatementNode *s2);
1068  virtual void ref();
1069  virtual bool deref();
1070  Completion execute(ExecState *exec);
1071  virtual void processFuncDecl(ExecState *exec);
1072  virtual void processVarDecls(ExecState *exec);
1073  virtual void streamTo(SourceStream &s) const;
1074  private:
1075  friend class BlockNode;
1076  StatementNode *element; // 'this' element
1077  SourceElementsNode *elements; // pointer to next
1078  };
1079 
1080 } // namespace
1081 
1082 #endif

kjs

Skip menu "kjs"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kjs

Skip menu "kjs"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kjs by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |