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

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

top level:

  • Tests/WebFoundation-Misc/ifnsurlextensions-test.m: (TestURLCommon): Add tests for the new WebNSURLExtras methods.
  • Tests/libiftest/IFCheckLeaks.c: (IFCheckLeaksAtExit): Remove workaround for CFPreferences race condition; it's now in WebFoundation.

JavaScriptCore:

Speed improvements. 19% faster on cvs-js-performance, 1% on cvs-static-urls.

Use global string objects for length and other common property names rather
than constantly making and destroying them. Use integer versions of get() and
other related calls rather than always making a string.

Also get rid of many unneeded constructors, destructors, copy constructors, and
assignment operators. And make some functions non-virtual.

  • kjs/internal.h:
  • kjs/internal.cpp: (NumberImp::toUInt32): Implement. (ReferenceImp::ReferenceImp): Special case for numeric property names. (ReferenceImp::getPropertyName): Moved guts here from ValueImp. Handle numeric case. (ReferenceImp::getValue): Moved guts here from ValueImp. Handle numeric case. (ReferenceImp::putValue): Moved guts here from ValueImp. Handle numeric case. (ReferenceImp::deleteValue): Added. Handle numeric case.
  • kjs/array_object.h:
  • kjs/array_object.cpp: All-new array implementation that stores the elements in a C++ array rather than in a property map. (ArrayInstanceImp::ArrayInstanceImp): Allocate the C++ array. (ArrayInstanceImp::~ArrayInstanceImp): Delete the C++ array. (ArrayInstanceImp::get): Implement both the old version and the new overload that takes an unsigned index for speed. (ArrayInstanceImp::put): Implement both the old version and the new overload that takes an unsigned index for speed. (ArrayInstanceImp::hasProperty): Implement both the old version and the new overload that takes an unsigned index for speed. (ArrayInstanceImp::deleteProperty): Implement both the old version and the new overload that takes an unsigned index for speed. (ArrayInstanceImp::setLength): Added. Used by the above to resize the array. (ArrayInstanceImp::mark): Mark the elements of the array too. (ArrayPrototypeImp::ArrayPrototypeImp): Pass the length to the array instance constructor.
  • kjs/bool_object.cpp:
  • kjs/date_object.cpp:
  • kjs/error_object.cpp:
  • kjs/function.cpp:
  • kjs/function_object.cpp:
  • kjs/math_object.cpp:
  • kjs/nodes.cpp:
  • kjs/nodes.h:
  • kjs/number_object.cpp:
  • kjs/object_object.cpp:
  • kjs/regexp_object.cpp:
  • kjs/string_object.cpp:
  • kjs/nodes2string.cpp: (SourceStream::operator<<): Add a special case for char now that you can't create a UString from a char implicitly.
  • kjs/object.h:
  • kjs/object.cpp: (ObjectImp::get): Call through to the string version if the numeric version is not implemented. (ObjectImp::put): Call through to the string version if the numeric version is not implemented. (ObjectImp::hasProperty): Call through to the string version if the numeric version is not implemented. (ObjectImp::deleteProperty): Call through to the string version if the numeric version is not implemented.
  • kjs/types.h:
  • kjs/types.cpp: (Reference::Reference): Added constructors for the numeric property name case.
  • kjs/ustring.h: Made the constructor that turns a character into a string be explicit so we don't get numbers that turn themselves into strings.
  • kjs/ustring.cpp: (UString::UString): Detect the empty string case, and use a shared empty string. (UString::find): Add an overload for single character finds. (UString::rfind): Add an overload for single character finds. (KJS::operator==): Fix bug where it would call strlen(0) if the first string was not null. Also handle non-ASCII characters consistently with the rest of the code by casting to unsigned char just in case.
  • kjs/value.h: Make ValueImp and all subclasses non-copyable and non-assignable.
  • kjs/value.cpp: (ValueImp::toUInt32): New interface, mainly useful so we can detect array indices and not turn them into strings and back. (ValueImp::toInteger): Use the new toUInt32. Probably can use more improvement. (ValueImp::toInt32): Use the new toUInt32. Probably can use more improvement. (ValueImp::toUInt16): Use the new toUInt32. Probably can use more improvement. (ValueImp::getBase): Remove handling of the Reference case. That's in ReferenceImp now. (ValueImp::getPropertyName): Remove handling of the Reference case. That's in ReferenceImp now. (ValueImp::getValue): Remove handling of the Reference case. That's in ReferenceImp now. (ValueImp::putValue): Remove handling of the Reference case. That's in ReferenceImp now. (ValueImp::deleteValue): Added. Used so we can do delete the same way we do put.

WebFoundation:

  • CacheLoader.subproj/WebHTTPResourceLoader.m: (-[WebHTTPProtocolHandler createWFLoadRequest]): Fix handling of paths with queries and some other subtle path and port number handling issues by using _web_hostWithPort and _web_pathWithQuery.
  • Misc.subproj/WebNSURLExtras.h:
  • Misc.subproj/WebNSURLExtras.m: (-[NSURL _web_hostWithPort]): Added. (-[NSURL _web_pathWithQuery]): Added.
  • CacheLoader.subproj/WebResourceLoad.m: (initLoader): Get some random preference before creating threads. This makes it impossible to run into the CFPreferences race condition.

WebCore:

  • force-clean-timestamp: Need a full build because of KJS changes.
  • khtml/ecma/kjs_window.h: Need to store an Object, not an ObjectImp, because there's no way to copy an ObjectImp. KJS changes caught this mistake.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 26.9 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 void setLoc(int line0, int line1, int sourceId);
115 int firstLine() const { return l0; }
116 int lastLine() const { return l1; }
117 int sourceId() const { return sid; }
118 bool hitStatement(ExecState *exec);
119 bool abortStatement(ExecState *exec);
120 virtual Completion execute(ExecState *exec) = 0;
121 void pushLabel(const UString *id) {
122 if (id) ls.push(*id);
123 }
124 protected:
125 LabelStack ls;
126 private:
127 Value evaluate(ExecState */*exec*/) { return Undefined(); }
128 int l0, l1;
129 int sid;
130 bool breakPoint;
131 };
132
133 class NullNode : public Node {
134 public:
135 NullNode() {}
136 Value evaluate(ExecState *exec);
137 virtual void streamTo(SourceStream &s) const;
138 };
139
140 class BooleanNode : public Node {
141 public:
142 BooleanNode(bool v) : value(v) {}
143 Value evaluate(ExecState *exec);
144 virtual void streamTo(SourceStream &s) const;
145 private:
146 bool value;
147 };
148
149 class NumberNode : public Node {
150 public:
151 NumberNode(double v) : value(v) { }
152 Value evaluate(ExecState *exec);
153 virtual void streamTo(SourceStream &s) const;
154 private:
155 double value;
156 };
157
158 class StringNode : public Node {
159 public:
160 StringNode(const UString *v) { value = *v; }
161 Value evaluate(ExecState *exec);
162 virtual void streamTo(SourceStream &s) const;
163 private:
164 UString value;
165 };
166
167 class RegExpNode : public Node {
168 public:
169 RegExpNode(const UString &p, const UString &f)
170 : pattern(p), flags(f) { }
171 Value evaluate(ExecState *exec);
172 virtual void streamTo(SourceStream &s) const;
173 private:
174 UString pattern, flags;
175 };
176
177 class ThisNode : public Node {
178 public:
179 ThisNode() {}
180 Value evaluate(ExecState *exec);
181 virtual void streamTo(SourceStream &s) const;
182 };
183
184 class ResolveNode : public Node {
185 public:
186 ResolveNode(const UString *s) : ident(*s) { }
187 Value evaluate(ExecState *exec);
188 virtual void streamTo(SourceStream &s) const;
189 private:
190 UString ident;
191 };
192
193 class GroupNode : public Node {
194 public:
195 GroupNode(Node *g) : group(g) { }
196 virtual void ref();
197 virtual bool deref();
198 Value evaluate(ExecState *exec);
199 virtual void streamTo(SourceStream &s) const { group->streamTo(s); }
200 private:
201 Node *group;
202 };
203
204 class ElisionNode : public Node {
205 public:
206 ElisionNode(ElisionNode *e) : elision(e) { }
207 virtual void ref();
208 virtual bool deref();
209 Value evaluate(ExecState *exec);
210 virtual void streamTo(SourceStream &s) const;
211 private:
212 ElisionNode *elision;
213 };
214
215 class ElementNode : public Node {
216 public:
217 ElementNode(ElisionNode *e, Node *n) : list(0L), elision(e), node(n) { }
218 ElementNode(ElementNode *l, ElisionNode *e, Node *n)
219 : list(l), elision(e), node(n) { }
220 virtual void ref();
221 virtual bool deref();
222 Value evaluate(ExecState *exec);
223 virtual void streamTo(SourceStream &s) const;
224 private:
225 ElementNode *list;
226 ElisionNode *elision;
227 Node *node;
228 };
229
230 class ArrayNode : public Node {
231 public:
232 ArrayNode(ElisionNode *e) : element(0L), elision(e), opt(true) { }
233 ArrayNode(ElementNode *ele)
234 : element(ele), elision(0), opt(false) { }
235 ArrayNode(ElisionNode *eli, ElementNode *ele)
236 : element(ele), elision(eli), opt(true) { }
237 virtual void ref();
238 virtual bool deref();
239 Value evaluate(ExecState *exec);
240 virtual void streamTo(SourceStream &s) const;
241 private:
242 ElementNode *element;
243 ElisionNode *elision;
244 bool opt;
245 };
246
247 class ObjectLiteralNode : public Node {
248 public:
249 ObjectLiteralNode(Node *l) : list(l) { }
250 virtual void ref();
251 virtual bool deref();
252 Value evaluate(ExecState *exec);
253 virtual void streamTo(SourceStream &s) const;
254 private:
255 Node *list;
256 };
257
258 class PropertyValueNode : public Node {
259 public:
260 PropertyValueNode(Node *n, Node *a, Node *l = 0L)
261 : name(n), assign(a), list(l) { }
262 virtual void ref();
263 virtual bool deref();
264 Value evaluate(ExecState *exec);
265 virtual void streamTo(SourceStream &s) const;
266 private:
267 Node *name, *assign, *list;
268 };
269
270 class PropertyNode : public Node {
271 public:
272 PropertyNode(double d) : numeric(d) { }
273 PropertyNode(const UString *s) : str(*s) { }
274 Value evaluate(ExecState *exec);
275 virtual void streamTo(SourceStream &s) const;
276 private:
277 double numeric;
278 UString str;
279 };
280
281 class AccessorNode1 : public Node {
282 public:
283 AccessorNode1(Node *e1, Node *e2) : expr1(e1), expr2(e2) {}
284 virtual void ref();
285 virtual bool deref();
286 Value evaluate(ExecState *exec);
287 virtual void streamTo(SourceStream &s) const;
288 private:
289 Node *expr1;
290 Node *expr2;
291 };
292
293 class AccessorNode2 : public Node {
294 public:
295 AccessorNode2(Node *e, const UString *s) : expr(e), ident(*s) { }
296 virtual void ref();
297 virtual bool deref();
298 Value evaluate(ExecState *exec);
299 virtual void streamTo(SourceStream &s) const;
300 private:
301 Node *expr;
302 UString ident;
303 };
304
305 class ArgumentListNode : public Node {
306 public:
307 ArgumentListNode(Node *e);
308 ArgumentListNode(ArgumentListNode *l, Node *e);
309 virtual void ref();
310 virtual bool deref();
311 Value evaluate(ExecState *exec);
312 List evaluateList(ExecState *exec);
313 virtual void streamTo(SourceStream &s) const;
314 private:
315 ArgumentListNode *list;
316 Node *expr;
317 };
318
319 class ArgumentsNode : public Node {
320 public:
321 ArgumentsNode(ArgumentListNode *l);
322 virtual void ref();
323 virtual bool deref();
324 Value evaluate(ExecState *exec);
325 List evaluateList(ExecState *exec);
326 virtual void streamTo(SourceStream &s) const;
327 private:
328 ArgumentListNode *list;
329 };
330
331 class NewExprNode : public Node {
332 public:
333 NewExprNode(Node *e) : expr(e), args(0L) {}
334 NewExprNode(Node *e, ArgumentsNode *a) : expr(e), args(a) {}
335 virtual void ref();
336 virtual bool deref();
337 Value evaluate(ExecState *exec);
338 virtual void streamTo(SourceStream &s) const;
339 private:
340 Node *expr;
341 ArgumentsNode *args;
342 };
343
344 class FunctionCallNode : public Node {
345 public:
346 FunctionCallNode(Node *e, ArgumentsNode *a) : expr(e), args(a) {}
347 virtual void ref();
348 virtual bool deref();
349 Value evaluate(ExecState *exec);
350 virtual void streamTo(SourceStream &s) const;
351 private:
352 Node *expr;
353 ArgumentsNode *args;
354 };
355
356 class PostfixNode : public Node {
357 public:
358 PostfixNode(Node *e, Operator o) : expr(e), oper(o) {}
359 virtual void ref();
360 virtual bool deref();
361 Value evaluate(ExecState *exec);
362 virtual void streamTo(SourceStream &s) const;
363 private:
364 Node *expr;
365 Operator oper;
366 };
367
368 class DeleteNode : public Node {
369 public:
370 DeleteNode(Node *e) : expr(e) {}
371 virtual void ref();
372 virtual bool deref();
373 Value evaluate(ExecState *exec);
374 virtual void streamTo(SourceStream &s) const;
375 private:
376 Node *expr;
377 };
378
379 class VoidNode : public Node {
380 public:
381 VoidNode(Node *e) : expr(e) {}
382 virtual void ref();
383 virtual bool deref();
384 Value evaluate(ExecState *exec);
385 virtual void streamTo(SourceStream &s) const;
386 private:
387 Node *expr;
388 };
389
390 class TypeOfNode : public Node {
391 public:
392 TypeOfNode(Node *e) : expr(e) {}
393 virtual void ref();
394 virtual bool deref();
395 Value evaluate(ExecState *exec);
396 virtual void streamTo(SourceStream &s) const;
397 private:
398 Node *expr;
399 };
400
401 class PrefixNode : public Node {
402 public:
403 PrefixNode(Operator o, Node *e) : oper(o), expr(e) {}
404 virtual void ref();
405 virtual bool deref();
406 Value evaluate(ExecState *exec);
407 virtual void streamTo(SourceStream &s) const;
408 private:
409 Operator oper;
410 Node *expr;
411 };
412
413 class UnaryPlusNode : public Node {
414 public:
415 UnaryPlusNode(Node *e) : expr(e) {}
416 virtual void ref();
417 virtual bool deref();
418 Value evaluate(ExecState *exec);
419 virtual void streamTo(SourceStream &s) const;
420 private:
421 Node *expr;
422 };
423
424 class NegateNode : public Node {
425 public:
426 NegateNode(Node *e) : expr(e) {}
427 virtual void ref();
428 virtual bool deref();
429 Value evaluate(ExecState *exec);
430 virtual void streamTo(SourceStream &s) const;
431 private:
432 Node *expr;
433 };
434
435 class BitwiseNotNode : public Node {
436 public:
437 BitwiseNotNode(Node *e) : expr(e) {}
438 virtual void ref();
439 virtual bool deref();
440 Value evaluate(ExecState *exec);
441 virtual void streamTo(SourceStream &s) const;
442 private:
443 Node *expr;
444 };
445
446 class LogicalNotNode : public Node {
447 public:
448 LogicalNotNode(Node *e) : expr(e) {}
449 virtual void ref();
450 virtual bool deref();
451 Value evaluate(ExecState *exec);
452 virtual void streamTo(SourceStream &s) const;
453 private:
454 Node *expr;
455 };
456
457 class MultNode : public Node {
458 public:
459 MultNode(Node *t1, Node *t2, char op) : term1(t1), term2(t2), oper(op) {}
460 virtual void ref();
461 virtual bool deref();
462 Value evaluate(ExecState *exec);
463 virtual void streamTo(SourceStream &s) const;
464 private:
465 Node *term1, *term2;
466 char oper;
467 };
468
469 class AddNode : public Node {
470 public:
471 AddNode(Node *t1, Node *t2, char op) : term1(t1), term2(t2), oper(op) {}
472 virtual void ref();
473 virtual bool deref();
474 Value evaluate(ExecState *exec);
475 virtual void streamTo(SourceStream &s) const;
476 private:
477 Node *term1, *term2;
478 char oper;
479 };
480
481 class ShiftNode : public Node {
482 public:
483 ShiftNode(Node *t1, Operator o, Node *t2)
484 : term1(t1), term2(t2), oper(o) {}
485 virtual void ref();
486 virtual bool deref();
487 Value evaluate(ExecState *exec);
488 virtual void streamTo(SourceStream &s) const;
489 private:
490 Node *term1, *term2;
491 Operator oper;
492 };
493
494 class RelationalNode : public Node {
495 public:
496 RelationalNode(Node *e1, Operator o, Node *e2) :
497 expr1(e1), expr2(e2), oper(o) {}
498 virtual void ref();
499 virtual bool deref();
500 Value evaluate(ExecState *exec);
501 virtual void streamTo(SourceStream &s) const;
502 private:
503 Node *expr1, *expr2;
504 Operator oper;
505 };
506
507 class EqualNode : public Node {
508 public:
509 EqualNode(Node *e1, Operator o, Node *e2)
510 : expr1(e1), expr2(e2), oper(o) {}
511 virtual void ref();
512 virtual bool deref();
513 Value evaluate(ExecState *exec);
514 virtual void streamTo(SourceStream &s) const;
515 private:
516 Node *expr1, *expr2;
517 Operator oper;
518 };
519
520 class BitOperNode : public Node {
521 public:
522 BitOperNode(Node *e1, Operator o, Node *e2) :
523 expr1(e1), expr2(e2), oper(o) {}
524 virtual void ref();
525 virtual bool deref();
526 Value evaluate(ExecState *exec);
527 virtual void streamTo(SourceStream &s) const;
528 private:
529 Node *expr1, *expr2;
530 Operator oper;
531 };
532
533 /**
534 * expr1 && expr2, expr1 || expr2
535 */
536 class BinaryLogicalNode : public Node {
537 public:
538 BinaryLogicalNode(Node *e1, Operator o, Node *e2) :
539 expr1(e1), expr2(e2), oper(o) {}
540 virtual void ref();
541 virtual bool deref();
542 Value evaluate(ExecState *exec);
543 virtual void streamTo(SourceStream &s) const;
544 private:
545 Node *expr1, *expr2;
546 Operator oper;
547 };
548
549 /**
550 * The ternary operator, "logical ? expr1 : expr2"
551 */
552 class ConditionalNode : public Node {
553 public:
554 ConditionalNode(Node *l, Node *e1, Node *e2) :
555 logical(l), expr1(e1), expr2(e2) {}
556 virtual void ref();
557 virtual bool deref();
558 Value evaluate(ExecState *exec);
559 virtual void streamTo(SourceStream &s) const;
560 private:
561 Node *logical, *expr1, *expr2;
562 };
563
564 class AssignNode : public Node {
565 public:
566 AssignNode(Node *l, Operator o, Node *e) : left(l), oper(o), expr(e) {}
567 virtual void ref();
568 virtual bool deref();
569 Value evaluate(ExecState *exec);
570 virtual void streamTo(SourceStream &s) const;
571 private:
572 Node *left;
573 Operator oper;
574 Node *expr;
575 };
576
577 class CommaNode : public Node {
578 public:
579 CommaNode(Node *e1, Node *e2) : expr1(e1), expr2(e2) {}
580 virtual void ref();
581 virtual bool deref();
582 Value evaluate(ExecState *exec);
583 virtual void streamTo(SourceStream &s) const;
584 private:
585 Node *expr1, *expr2;
586 };
587
588 class StatListNode : public StatementNode {
589 public:
590 StatListNode(StatementNode *s) : statement(s), list(0L) { }
591 StatListNode(StatListNode *l, StatementNode *s) : statement(s), list(l) { }
592 virtual void ref();
593 virtual bool deref();
594 virtual Completion execute(ExecState *exec);
595 virtual void processVarDecls(ExecState *exec);
596 virtual void streamTo(SourceStream &s) const;
597 private:
598 StatementNode *statement;
599 StatListNode *list;
600 };
601
602 class AssignExprNode : public Node {
603 public:
604 AssignExprNode(Node *e) : expr(e) {}
605 virtual void ref();
606 virtual bool deref();
607 Value evaluate(ExecState *exec);
608 virtual void streamTo(SourceStream &s) const;
609 private:
610 Node *expr;
611 };
612
613 class VarDeclNode : public Node {
614 public:
615 VarDeclNode(const UString *id, AssignExprNode *in);
616 virtual void ref();
617 virtual bool deref();
618 Value evaluate(ExecState *exec);
619 virtual void processVarDecls(ExecState *exec);
620 virtual void streamTo(SourceStream &s) const;
621 private:
622 UString ident;
623 AssignExprNode *init;
624 };
625
626 class VarDeclListNode : public Node {
627 public:
628 VarDeclListNode(VarDeclNode *v) : list(0L), var(v) {}
629 VarDeclListNode(Node *l, VarDeclNode *v) : list(l), var(v) {}
630 virtual void ref();
631 virtual bool deref();
632 Value evaluate(ExecState *exec);
633 virtual void processVarDecls(ExecState *exec);
634 virtual void streamTo(SourceStream &s) const;
635 private:
636 Node *list;
637 VarDeclNode *var;
638 };
639
640 class VarStatementNode : public StatementNode {
641 public:
642 VarStatementNode(VarDeclListNode *l) : list(l) {}
643 virtual void ref();
644 virtual bool deref();
645 virtual Completion execute(ExecState *exec);
646 virtual void processVarDecls(ExecState *exec);
647 virtual void streamTo(SourceStream &s) const;
648 private:
649 VarDeclListNode *list;
650 };
651
652 class BlockNode : public StatementNode {
653 public:
654 BlockNode(SourceElementsNode *s) : source(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 SourceElementsNode *source;
662 };
663
664 class EmptyStatementNode : public StatementNode {
665 public:
666 EmptyStatementNode() { } // debug
667 virtual Completion execute(ExecState *exec);
668 virtual void streamTo(SourceStream &s) const;
669 };
670
671 class ExprStatementNode : public StatementNode {
672 public:
673 ExprStatementNode(Node *e) : expr(e) { }
674 virtual void ref();
675 virtual bool deref();
676 virtual Completion execute(ExecState *exec);
677 virtual void streamTo(SourceStream &s) const;
678 private:
679 Node *expr;
680 };
681
682 class IfNode : public StatementNode {
683 public:
684 IfNode(Node *e, StatementNode *s1, StatementNode *s2)
685 : expr(e), statement1(s1), statement2(s2) {}
686 virtual void ref();
687 virtual bool deref();
688 virtual Completion execute(ExecState *exec);
689 virtual void processVarDecls(ExecState *exec);
690 virtual void streamTo(SourceStream &s) const;
691 private:
692 Node *expr;
693 StatementNode *statement1, *statement2;
694 };
695
696 class DoWhileNode : public StatementNode {
697 public:
698 DoWhileNode(StatementNode *s, Node *e) : statement(s), expr(e) {}
699 virtual void ref();
700 virtual bool deref();
701 virtual Completion execute(ExecState *exec);
702 virtual void processVarDecls(ExecState *exec);
703 virtual void streamTo(SourceStream &s) const;
704 private:
705 StatementNode *statement;
706 Node *expr;
707 };
708
709 class WhileNode : public StatementNode {
710 public:
711 WhileNode(Node *e, StatementNode *s) : expr(e), statement(s) {}
712 virtual void ref();
713 virtual bool deref();
714 virtual Completion execute(ExecState *exec);
715 virtual void processVarDecls(ExecState *exec);
716 virtual void streamTo(SourceStream &s) const;
717 private:
718 Node *expr;
719 StatementNode *statement;
720 };
721
722 class ForNode : public StatementNode {
723 public:
724 ForNode(Node *e1, Node *e2, Node *e3, StatementNode *s) :
725 expr1(e1), expr2(e2), expr3(e3), statement(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 private:
732 Node *expr1, *expr2, *expr3;
733 StatementNode *statement;
734 };
735
736 class ForInNode : public StatementNode {
737 public:
738 ForInNode(Node *l, Node *e, StatementNode *s);
739 ForInNode(const UString *i, AssignExprNode *in, Node *e, StatementNode *s);
740 virtual void ref();
741 virtual bool deref();
742 virtual Completion execute(ExecState *exec);
743 virtual void processVarDecls(ExecState *exec);
744 virtual void streamTo(SourceStream &s) const;
745 private:
746 UString ident;
747 AssignExprNode *init;
748 Node *lexpr, *expr;
749 VarDeclNode *varDecl;
750 StatementNode *statement;
751 };
752
753 class ContinueNode : public StatementNode {
754 public:
755 ContinueNode() { }
756 ContinueNode(const UString *i) : ident(*i) { }
757 virtual Completion execute(ExecState *exec);
758 virtual void streamTo(SourceStream &s) const;
759 private:
760 UString ident;
761 };
762
763 class BreakNode : public StatementNode {
764 public:
765 BreakNode() { }
766 BreakNode(const UString *i) : ident(*i) { }
767 virtual Completion execute(ExecState *exec);
768 virtual void streamTo(SourceStream &s) const;
769 private:
770 UString ident;
771 };
772
773 class ReturnNode : public StatementNode {
774 public:
775 ReturnNode(Node *v) : value(v) {}
776 virtual void ref();
777 virtual bool deref();
778 virtual Completion execute(ExecState *exec);
779 virtual void streamTo(SourceStream &s) const;
780 private:
781 Node *value;
782 };
783
784 class WithNode : public StatementNode {
785 public:
786 WithNode(Node *e, StatementNode *s) : expr(e), statement(s) {}
787 virtual void ref();
788 virtual bool deref();
789 virtual Completion execute(ExecState *exec);
790 virtual void processVarDecls(ExecState *exec);
791 virtual void streamTo(SourceStream &s) const;
792 private:
793 Node *expr;
794 StatementNode *statement;
795 };
796
797 class CaseClauseNode: public Node {
798 public:
799 CaseClauseNode(Node *e, StatListNode *l) : expr(e), list(l) { }
800 virtual void ref();
801 virtual bool deref();
802 Value evaluate(ExecState *exec);
803 Completion evalStatements(ExecState *exec);
804 virtual void processVarDecls(ExecState *exec);
805 virtual void streamTo(SourceStream &s) const;
806 private:
807 Node *expr;
808 StatListNode *list;
809 };
810
811 class ClauseListNode : public Node {
812 public:
813 ClauseListNode(CaseClauseNode *c) : cl(c), nx(0L) { }
814 virtual void ref();
815 virtual bool deref();
816 ClauseListNode* append(CaseClauseNode *c);
817 Value evaluate(ExecState *exec);
818 CaseClauseNode *clause() const { return cl; }
819 ClauseListNode *next() const { return nx; }
820 virtual void processVarDecls(ExecState *exec);
821 virtual void streamTo(SourceStream &s) const;
822 private:
823 CaseClauseNode *cl;
824 ClauseListNode *nx;
825 };
826
827 class CaseBlockNode: public Node {
828 public:
829 CaseBlockNode(ClauseListNode *l1, CaseClauseNode *d, ClauseListNode *l2)
830 : list1(l1), def(d), list2(l2) { }
831 virtual void ref();
832 virtual bool deref();
833 Value evaluate(ExecState *exec);
834 Completion evalBlock(ExecState *exec, const Value& input);
835 virtual void processVarDecls(ExecState *exec);
836 virtual void streamTo(SourceStream &s) const;
837 private:
838 ClauseListNode *list1;
839 CaseClauseNode *def;
840 ClauseListNode *list2;
841 };
842
843 class SwitchNode : public StatementNode {
844 public:
845 SwitchNode(Node *e, CaseBlockNode *b) : expr(e), block(b) { }
846 virtual void ref();
847 virtual bool deref();
848 virtual Completion execute(ExecState *exec);
849 virtual void processVarDecls(ExecState *exec);
850 virtual void streamTo(SourceStream &s) const;
851 private:
852 Node *expr;
853 CaseBlockNode *block;
854 };
855
856 class LabelNode : public StatementNode {
857 public:
858 LabelNode(const UString *l, StatementNode *s) : label(*l), 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 UString label;
866 StatementNode *statement;
867 };
868
869 class ThrowNode : public StatementNode {
870 public:
871 ThrowNode(Node *e) : expr(e) {}
872 virtual void ref();
873 virtual bool deref();
874 virtual Completion execute(ExecState *exec);
875 virtual void streamTo(SourceStream &s) const;
876 private:
877 Node *expr;
878 };
879
880 class CatchNode : public StatementNode {
881 public:
882 CatchNode(const UString *i, StatementNode *b) : ident(*i), block(b) {}
883 virtual void ref();
884 virtual bool deref();
885 virtual Completion execute(ExecState *exec);
886 Completion execute(ExecState *exec, const Value &arg);
887 virtual void processVarDecls(ExecState *exec);
888 virtual void streamTo(SourceStream &s) const;
889 private:
890 UString ident;
891 StatementNode *block;
892 };
893
894 class FinallyNode : public StatementNode {
895 public:
896 FinallyNode(StatementNode *b) : block(b) {}
897 virtual void ref();
898 virtual bool deref();
899 virtual Completion execute(ExecState *exec);
900 virtual void processVarDecls(ExecState *exec);
901 virtual void streamTo(SourceStream &s) const;
902 private:
903 StatementNode *block;
904 };
905
906 class TryNode : public StatementNode {
907 public:
908 TryNode(StatementNode *b, Node *c = 0L, Node *f = 0L)
909 : block(b), _catch((CatchNode*)c), _final((FinallyNode*)f) {}
910 virtual void ref();
911 virtual bool deref();
912 virtual Completion execute(ExecState *exec);
913 virtual void processVarDecls(ExecState *exec);
914 virtual void streamTo(SourceStream &s) const;
915 private:
916 StatementNode *block;
917 CatchNode *_catch;
918 FinallyNode *_final;
919 };
920
921 class ParameterNode : public Node {
922 public:
923 ParameterNode(const UString *i) : id(*i), next(0L) { }
924 ParameterNode *append(const UString *i);
925 virtual void ref();
926 virtual bool deref();
927 Value evaluate(ExecState *exec);
928 UString ident() { return id; }
929 ParameterNode *nextParam() { return next; }
930 virtual void streamTo(SourceStream &s) const;
931 private:
932 UString id;
933 ParameterNode *next;
934 };
935
936 // inherited by ProgramNode
937 class FunctionBodyNode : public StatementNode {
938 public:
939 FunctionBodyNode(SourceElementsNode *s);
940 virtual void ref();
941 virtual bool deref();
942 Completion execute(ExecState *exec);
943 virtual void processFuncDecl(ExecState *exec);
944 virtual void processVarDecls(ExecState *exec);
945 void streamTo(SourceStream &s) const;
946 protected:
947 SourceElementsNode *source;
948 };
949
950 class FuncDeclNode : public StatementNode {
951 public:
952 FuncDeclNode(const UString *i, ParameterNode *p, FunctionBodyNode *b)
953 : ident(*i), param(p), body(b) { }
954 virtual void ref();
955 virtual bool deref();
956 Completion execute(ExecState */*exec*/)
957 { /* empty */ return Completion(); }
958 void processFuncDecl(ExecState *exec);
959 virtual void streamTo(SourceStream &s) const;
960 private:
961 UString ident;
962 ParameterNode *param;
963 FunctionBodyNode *body;
964 };
965
966 class FuncExprNode : public Node {
967 public:
968 FuncExprNode(ParameterNode *p, FunctionBodyNode *b)
969 : param(p), body(b) { }
970 virtual void ref();
971 virtual bool deref();
972 Value evaluate(ExecState *exec);
973 virtual void streamTo(SourceStream &s) const;
974 private:
975 ParameterNode *param;
976 FunctionBodyNode *body;
977 };
978
979 class SourceElementNode : public StatementNode {
980 public:
981 SourceElementNode(StatementNode *s) : statement(s), function(0L) { }
982 SourceElementNode(FuncDeclNode *f) : statement(0L), function(f) { }
983 virtual void ref();
984 virtual bool deref();
985 Completion execute(ExecState *exec);
986 virtual void processFuncDecl(ExecState *exec);
987 virtual void processVarDecls(ExecState *exec);
988 virtual void streamTo(SourceStream &s) const;
989 private:
990 StatementNode *statement;
991 FuncDeclNode *function;
992 };
993
994 // A linked list of source element nodes
995 class SourceElementsNode : public StatementNode {
996 public:
997 SourceElementsNode(SourceElementNode *s1) { element = s1; elements = 0L; }
998 SourceElementsNode(SourceElementsNode *s1, SourceElementNode *s2)
999 { elements = s1; element = s2; }
1000 virtual void ref();
1001 virtual bool deref();
1002 Completion execute(ExecState *exec);
1003 virtual void processFuncDecl(ExecState *exec);
1004 virtual void processVarDecls(ExecState *exec);
1005 virtual void streamTo(SourceStream &s) const;
1006 private:
1007 SourceElementNode *element; // 'this' element
1008 SourceElementsNode *elements; // pointer to next
1009 };
1010
1011 class ProgramNode : public FunctionBodyNode {
1012 public:
1013 ProgramNode(SourceElementsNode *s);
1014 };
1015
1016}; // namespace
1017
1018#endif
Note: See TracBrowser for help on using the repository browser.