source: webkit/trunk/JavaScriptCore/kjs/nodes.h@ 1791

Last change on this file since 1791 was 1623, checked in by darin, 23 years ago

JavaScriptCore:

  • kjs/*: Roll KDE 3.0.2 changes in. Also switch to not using APPLE_CHANGES for some of the changes that we definitely want to contribute upstream.

WebCore:

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