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

kjs

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

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
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for kjs by doxygen 1.9.4
This website is maintained by Timothy Pearson.