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

Last change on this file since 26960 was 26960, checked in by eseidel, 18 years ago

2007-10-24 Eric Seidel <[email protected]>

Reviewed by darin.

  • kjs/nodes.h: (KJS::ImmediateNumberNode::): Fix ASSERT correctness (and debug build!)
  • Property svn:eol-style set to native
File size: 46.6 KB
Line 
1// -*- c-basic-offset: 2 -*-
2/*
3 * Copyright (C) 1999-2000 Harri Porten ([email protected])
4 * Copyright (C) 2001 Peter Kelly ([email protected])
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
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 "Parser.h"
28#include "internal.h"
29#include <wtf/ListRefPtr.h>
30#include <wtf/Vector.h>
31
32#if PLATFORM(X86) && COMPILER(GCC)
33#define KJS_FAST_CALL __attribute__((regparm(3)))
34#else
35#define KJS_FAST_CALL
36#endif
37
38#if COMPILER(GCC)
39#define KJS_NO_INLINE __attribute__((noinline))
40#else
41#define KJS_NO_INLINE
42#endif
43
44namespace KJS {
45
46 class FuncDeclNode;
47 class ProgramNode;
48 class PropertyNameNode;
49 class PropertyListNode;
50 class RegExp;
51 class SourceElementsNode;
52 class SourceStream;
53 class VarDeclNode;
54
55 enum Operator { OpEqual,
56 OpEqEq,
57 OpNotEq,
58 OpStrEq,
59 OpStrNEq,
60 OpPlusEq,
61 OpMinusEq,
62 OpMultEq,
63 OpDivEq,
64 OpPlusPlus,
65 OpMinusMinus,
66 OpLess,
67 OpLessEq,
68 OpGreater,
69 OpGreaterEq,
70 OpAndEq,
71 OpXOrEq,
72 OpOrEq,
73 OpModEq,
74 OpAnd,
75 OpOr,
76 OpBitAnd,
77 OpBitXOr,
78 OpBitOr,
79 OpLShift,
80 OpRShift,
81 OpURShift,
82 OpIn,
83 OpInstanceOf
84 };
85
86 struct DeclarationStacks {
87 typedef Vector<Node*, 16> NodeStack;
88 typedef Vector<VarDeclNode*, 16> VarStack;
89 typedef Vector<FuncDeclNode*, 16> FunctionStack;
90
91 DeclarationStacks(NodeStack& n, VarStack& v, FunctionStack& f)
92 : nodeStack(n)
93 , varStack(v)
94 , functionStack(f)
95 {
96 }
97
98 NodeStack& nodeStack;
99 VarStack& varStack;
100 FunctionStack& functionStack;
101 };
102
103 class Node {
104 public:
105 Node() KJS_FAST_CALL;
106 virtual ~Node();
107
108 virtual JSValue *evaluate(ExecState *exec) KJS_FAST_CALL = 0;
109 UString toString() const KJS_FAST_CALL;
110 virtual void streamTo(SourceStream&) const KJS_FAST_CALL = 0;
111 int lineNo() const KJS_FAST_CALL { return m_line; }
112 void ref() KJS_FAST_CALL;
113 void deref() KJS_FAST_CALL;
114 unsigned refcount() KJS_FAST_CALL;
115 static void clearNewNodes() KJS_FAST_CALL;
116
117 virtual Node *nodeInsideAllParens() KJS_FAST_CALL;
118
119 virtual bool isNumber() const KJS_FAST_CALL { return false; }
120 virtual bool isImmediateValue() const KJS_FAST_CALL { return false; }
121 virtual bool isLocation() const KJS_FAST_CALL { return false; }
122 virtual bool isResolveNode() const KJS_FAST_CALL { return false; }
123 virtual bool isBracketAccessorNode() const KJS_FAST_CALL { return false; }
124 virtual bool isDotAccessorNode() const KJS_FAST_CALL { return false; }
125 virtual bool isGroupNode() const KJS_FAST_CALL { return false; }
126
127 // Used for iterative, depth-first traversal of the node tree. Does not cross function call boundaries.
128 bool mayHaveDeclarations() { return m_mayHaveDeclarations; }
129 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL { ASSERT_NOT_REACHED(); }
130
131 virtual void breakCycle() KJS_FAST_CALL { }
132
133 protected:
134 Completion createErrorCompletion(ExecState *, ErrorType, const char *msg) KJS_FAST_CALL;
135 Completion createErrorCompletion(ExecState *, ErrorType, const char *msg, const Identifier &) KJS_FAST_CALL;
136
137 JSValue *throwError(ExecState *, ErrorType, const char *msg) KJS_FAST_CALL;
138 JSValue* throwError(ExecState *, ErrorType, const char* msg, const char*) KJS_FAST_CALL;
139 JSValue *throwError(ExecState *, ErrorType, const char *msg, JSValue *, Node *) KJS_FAST_CALL;
140 JSValue *throwError(ExecState *, ErrorType, const char *msg, const Identifier &) KJS_FAST_CALL;
141 JSValue *throwError(ExecState *, ErrorType, const char *msg, JSValue *, const Identifier &) KJS_FAST_CALL;
142 JSValue *throwError(ExecState *, ErrorType, const char *msg, JSValue *, Node *, Node *) KJS_FAST_CALL;
143 JSValue *throwError(ExecState *, ErrorType, const char *msg, JSValue *, Node *, const Identifier &) KJS_FAST_CALL;
144
145 JSValue *throwUndefinedVariableError(ExecState *, const Identifier &) KJS_FAST_CALL;
146
147 void handleException(ExecState*) KJS_FAST_CALL;
148 void handleException(ExecState*, JSValue*) KJS_FAST_CALL;
149
150 Completion rethrowException(ExecState*) KJS_FAST_CALL;
151
152 int m_line : 31;
153 bool m_mayHaveDeclarations : 1;
154 private:
155 // disallow assignment
156 Node& operator=(const Node&) KJS_FAST_CALL;
157 Node(const Node &other) KJS_FAST_CALL;
158 };
159
160 class StatementNode : public Node {
161 public:
162 StatementNode() KJS_FAST_CALL;
163 void setLoc(int line0, int line1) KJS_FAST_CALL;
164 int firstLine() const KJS_FAST_CALL { return lineNo(); }
165 int lastLine() const KJS_FAST_CALL { return m_lastLine; }
166 bool hitStatement(ExecState*) KJS_FAST_CALL;
167 virtual Completion execute(ExecState *exec) KJS_FAST_CALL = 0;
168 void pushLabel(const Identifier &id) KJS_FAST_CALL { ls.push(id); }
169 protected:
170 LabelStack ls;
171 private:
172 JSValue *evaluate(ExecState*) KJS_FAST_CALL { return jsUndefined(); }
173 int m_lastLine;
174 };
175
176 class NullNode : public Node {
177 public:
178 NullNode() KJS_FAST_CALL {}
179 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
180 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
181 };
182
183 class BooleanNode : public Node {
184 public:
185 BooleanNode(bool v) KJS_FAST_CALL : value(v) {}
186 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
187 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
188 private:
189 bool value;
190 };
191
192 class NumberNode : public Node {
193 public:
194 NumberNode(double v) KJS_FAST_CALL : val(v) {}
195 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
196 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
197
198 virtual bool isNumber() const KJS_FAST_CALL { return true; }
199 double value() const KJS_FAST_CALL { return val; }
200 void setValue(double v) KJS_FAST_CALL { val = v; }
201 private:
202 double val;
203 };
204
205 class ImmediateNumberNode : public Node {
206 public:
207 ImmediateNumberNode(JSValue* v) KJS_FAST_CALL : m_value(v) {}
208 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
209 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
210
211 virtual bool isImmediateValue() const KJS_FAST_CALL { return true; }
212 double value() const KJS_FAST_CALL { return JSImmediate::toDouble(m_value); }
213 void setValue(double v) KJS_FAST_CALL { m_value = JSImmediate::fromDouble(v); ASSERT(m_value); }
214 private:
215 JSValue* m_value;
216 };
217
218 class StringNode : public Node {
219 public:
220 StringNode(const UString *v) KJS_FAST_CALL { value = *v; }
221 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
222 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
223 private:
224 UString value;
225 };
226
227 class RegExpNode : public Node {
228 public:
229 RegExpNode(const UString &p, const UString &f) KJS_FAST_CALL
230 : pattern(p), flags(f) { }
231 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
232 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
233 private:
234 UString pattern, flags;
235 };
236
237 class ThisNode : public Node {
238 public:
239 ThisNode() KJS_FAST_CALL {}
240 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
241 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
242 };
243
244 class ResolveNode : public Node {
245 public:
246 ResolveNode(const Identifier &s) KJS_FAST_CALL : ident(s) { }
247 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
248 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
249
250 virtual bool isLocation() const KJS_FAST_CALL { return true; }
251 virtual bool isResolveNode() const KJS_FAST_CALL { return true; }
252 const Identifier& identifier() const KJS_FAST_CALL { return ident; }
253
254 private:
255 Identifier ident;
256 };
257
258 class GroupNode : public Node {
259 public:
260 GroupNode(Node *g) KJS_FAST_CALL : group(g) { }
261 virtual JSValue* evaluate(ExecState*) KJS_FAST_CALL;
262 virtual Node *nodeInsideAllParens() KJS_FAST_CALL;
263 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
264 virtual bool isGroupNode() const KJS_FAST_CALL { return true; }
265 private:
266 RefPtr<Node> group;
267 };
268
269 class ElementNode : public Node {
270 public:
271 // list pointer is tail of a circular list, cracked in the ArrayNode ctor
272 ElementNode(int e, Node *n) KJS_FAST_CALL : next(this), elision(e), node(n) { Parser::noteNodeCycle(this); }
273 ElementNode(ElementNode *l, int e, Node *n) KJS_FAST_CALL
274 : next(l->next), elision(e), node(n) { l->next = this; }
275 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
276 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
277 PassRefPtr<ElementNode> releaseNext() KJS_FAST_CALL { return next.release(); }
278 virtual void breakCycle() KJS_FAST_CALL;
279 private:
280 friend class ArrayNode;
281 ListRefPtr<ElementNode> next;
282 int elision;
283 RefPtr<Node> node;
284 };
285
286 class ArrayNode : public Node {
287 public:
288 ArrayNode(int e) KJS_FAST_CALL : elision(e), opt(true) { }
289 ArrayNode(ElementNode *ele) KJS_FAST_CALL
290 : element(ele->next.release()), elision(0), opt(false) { Parser::removeNodeCycle(element.get()); }
291 ArrayNode(int eli, ElementNode *ele) KJS_FAST_CALL
292 : element(ele->next.release()), elision(eli), opt(true) { Parser::removeNodeCycle(element.get()); }
293 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
294 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
295 private:
296 RefPtr<ElementNode> element;
297 int elision;
298 bool opt;
299 };
300
301 class PropertyNameNode : public Node {
302 public:
303 PropertyNameNode(double d) KJS_FAST_CALL : numeric(d) { }
304 PropertyNameNode(const Identifier &s) KJS_FAST_CALL : str(s) { }
305 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
306 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
307 private:
308 double numeric;
309 Identifier str;
310 };
311
312 class PropertyNode : public Node {
313 public:
314 enum Type { Constant, Getter, Setter };
315 PropertyNode(PropertyNameNode *n, Node *a, Type t) KJS_FAST_CALL
316 : name(n), assign(a), type(t) { }
317 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
318 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
319 friend class PropertyListNode;
320 private:
321 RefPtr<PropertyNameNode> name;
322 RefPtr<Node> assign;
323 Type type;
324 };
325
326 class PropertyListNode : public Node {
327 public:
328 // list pointer is tail of a circular list, cracked in the ObjectLiteralNode ctor
329 PropertyListNode(PropertyNode *n) KJS_FAST_CALL
330 : node(n), next(this) { Parser::noteNodeCycle(this); }
331 PropertyListNode(PropertyNode *n, PropertyListNode *l) KJS_FAST_CALL
332 : node(n), next(l->next) { l->next = this; }
333 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
334 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
335 PassRefPtr<PropertyListNode> releaseNext() KJS_FAST_CALL { return next.release(); }
336 virtual void breakCycle() KJS_FAST_CALL;
337 private:
338 friend class ObjectLiteralNode;
339 RefPtr<PropertyNode> node;
340 ListRefPtr<PropertyListNode> next;
341 };
342
343 class ObjectLiteralNode : public Node {
344 public:
345 ObjectLiteralNode() KJS_FAST_CALL { }
346 ObjectLiteralNode(PropertyListNode *l) KJS_FAST_CALL : list(l->next.release()) { Parser::removeNodeCycle(list.get()); }
347 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
348 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
349 private:
350 RefPtr<PropertyListNode> list;
351 };
352
353 class BracketAccessorNode : public Node {
354 public:
355 BracketAccessorNode(Node *e1, Node *e2) KJS_FAST_CALL : expr1(e1), expr2(e2) {}
356 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
357 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
358
359 virtual bool isLocation() const KJS_FAST_CALL { return true; }
360 virtual bool isBracketAccessorNode() const KJS_FAST_CALL { return true; }
361 Node *base() KJS_FAST_CALL { return expr1.get(); }
362 Node *subscript() KJS_FAST_CALL { return expr2.get(); }
363
364 private:
365 RefPtr<Node> expr1;
366 RefPtr<Node> expr2;
367 };
368
369 class DotAccessorNode : public Node {
370 public:
371 DotAccessorNode(Node *e, const Identifier &s) KJS_FAST_CALL : expr(e), ident(s) { }
372 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
373 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
374
375 virtual bool isLocation() const KJS_FAST_CALL { return true; }
376 virtual bool isDotAccessorNode() const KJS_FAST_CALL { return true; }
377 Node *base() const KJS_FAST_CALL { return expr.get(); }
378 const Identifier& identifier() const KJS_FAST_CALL { return ident; }
379
380 private:
381 RefPtr<Node> expr;
382 Identifier ident;
383 };
384
385 class ArgumentListNode : public Node {
386 public:
387 // list pointer is tail of a circular list, cracked in the ArgumentsNode ctor
388 ArgumentListNode(Node *e) KJS_FAST_CALL : next(this), expr(e) { Parser::noteNodeCycle(this); }
389 ArgumentListNode(ArgumentListNode *l, Node *e) KJS_FAST_CALL
390 : next(l->next), expr(e) { l->next = this; }
391 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
392 List evaluateList(ExecState*) KJS_FAST_CALL;
393 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
394 PassRefPtr<ArgumentListNode> releaseNext() KJS_FAST_CALL { return next.release(); }
395 virtual void breakCycle() KJS_FAST_CALL;
396 private:
397 friend class ArgumentsNode;
398 ListRefPtr<ArgumentListNode> next;
399 RefPtr<Node> expr;
400 };
401
402 class ArgumentsNode : public Node {
403 public:
404 ArgumentsNode() KJS_FAST_CALL { }
405 ArgumentsNode(ArgumentListNode *l) KJS_FAST_CALL
406 : list(l->next.release()) { Parser::removeNodeCycle(list.get()); }
407 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
408 List evaluateList(ExecState *exec) KJS_FAST_CALL { return list ? list->evaluateList(exec) : List(); }
409 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
410 private:
411 RefPtr<ArgumentListNode> list;
412 };
413
414 class NewExprNode : public Node {
415 public:
416 NewExprNode(Node *e) KJS_FAST_CALL : expr(e) {}
417 NewExprNode(Node *e, ArgumentsNode *a) KJS_FAST_CALL : expr(e), args(a) {}
418 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
419 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
420 private:
421 RefPtr<Node> expr;
422 RefPtr<ArgumentsNode> args;
423 };
424
425 class FunctionCallValueNode : public Node {
426 public:
427 FunctionCallValueNode(Node *e, ArgumentsNode *a) KJS_FAST_CALL : expr(e), args(a) {}
428 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
429 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
430 private:
431 RefPtr<Node> expr;
432 RefPtr<ArgumentsNode> args;
433 };
434
435 class FunctionCallResolveNode : public Node {
436 public:
437 FunctionCallResolveNode(const Identifier& i, ArgumentsNode *a) KJS_FAST_CALL : ident(i), args(a) {}
438 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
439 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
440 private:
441 Identifier ident;
442 RefPtr<ArgumentsNode> args;
443 };
444
445 class FunctionCallBracketNode : public Node {
446 public:
447 FunctionCallBracketNode(Node *b, Node *s, ArgumentsNode *a) KJS_FAST_CALL : base(b), subscript(s), args(a) {}
448 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
449 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
450 protected:
451 RefPtr<Node> base;
452 RefPtr<Node> subscript;
453 RefPtr<ArgumentsNode> args;
454 };
455
456 class FunctionCallParenBracketNode : public FunctionCallBracketNode {
457 public:
458 FunctionCallParenBracketNode(Node *b, Node *s, ArgumentsNode *a) KJS_FAST_CALL : FunctionCallBracketNode(b, s, a) {}
459 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
460 };
461
462 class FunctionCallDotNode : public Node {
463 public:
464 FunctionCallDotNode(Node *b, const Identifier &i, ArgumentsNode *a) KJS_FAST_CALL : base(b), ident(i), args(a) {}
465 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
466 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
467 protected:
468 RefPtr<Node> base;
469 Identifier ident;
470 RefPtr<ArgumentsNode> args;
471 };
472
473 class FunctionCallParenDotNode : public FunctionCallDotNode {
474 public:
475 FunctionCallParenDotNode(Node *b, const Identifier &i, ArgumentsNode *a) KJS_FAST_CALL : FunctionCallDotNode(b, i, a) {}
476 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
477 };
478
479 class PostfixResolveNode : public Node {
480 public:
481 PostfixResolveNode(const Identifier& i, Operator o) KJS_FAST_CALL : m_ident(i), m_oper(o) {}
482 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
483 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
484 private:
485 Identifier m_ident;
486 Operator m_oper;
487 };
488
489 class PostfixBracketNode : public Node {
490 public:
491 PostfixBracketNode(Node *b, Node *s, Operator o) KJS_FAST_CALL : m_base(b), m_subscript(s), m_oper(o) {}
492 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
493 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
494 private:
495 RefPtr<Node> m_base;
496 RefPtr<Node> m_subscript;
497 Operator m_oper;
498 };
499
500 class PostfixDotNode : public Node {
501 public:
502 PostfixDotNode(Node *b, const Identifier& i, Operator o) KJS_FAST_CALL : m_base(b), m_ident(i), m_oper(o) {}
503 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
504 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
505 private:
506 RefPtr<Node> m_base;
507 Identifier m_ident;
508 Operator m_oper;
509 };
510
511 class PostfixErrorNode : public Node {
512 public:
513 PostfixErrorNode(Node* e, Operator o) KJS_FAST_CALL : m_expr(e), m_oper(o) {}
514 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
515 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
516 private:
517 RefPtr<Node> m_expr;
518 Operator m_oper;
519 };
520
521 class DeleteResolveNode : public Node {
522 public:
523 DeleteResolveNode(const Identifier& i) KJS_FAST_CALL : m_ident(i) {}
524 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
525 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
526 private:
527 Identifier m_ident;
528 };
529
530 class DeleteBracketNode : public Node {
531 public:
532 DeleteBracketNode(Node *base, Node *subscript) KJS_FAST_CALL : m_base(base), m_subscript(subscript) {}
533 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
534 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
535 private:
536 RefPtr<Node> m_base;
537 RefPtr<Node> m_subscript;
538 };
539
540 class DeleteDotNode : public Node {
541 public:
542 DeleteDotNode(Node *base, const Identifier& i) KJS_FAST_CALL : m_base(base), m_ident(i) {}
543 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
544 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
545 private:
546 RefPtr<Node> m_base;
547 Identifier m_ident;
548 };
549
550 class DeleteValueNode : public Node {
551 public:
552 DeleteValueNode(Node *e) KJS_FAST_CALL : m_expr(e) {}
553 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
554 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
555 private:
556 RefPtr<Node> m_expr;
557 };
558
559 class VoidNode : public Node {
560 public:
561 VoidNode(Node *e) KJS_FAST_CALL : expr(e) {}
562 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
563 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
564 private:
565 RefPtr<Node> expr;
566 };
567
568 class TypeOfResolveNode : public Node {
569 public:
570 TypeOfResolveNode(const Identifier& i) KJS_FAST_CALL : m_ident(i) {}
571 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
572 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
573 private:
574 Identifier m_ident;
575 };
576
577 class TypeOfValueNode : public Node {
578 public:
579 TypeOfValueNode(Node *e) KJS_FAST_CALL : m_expr(e) {}
580 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
581 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
582 private:
583 RefPtr<Node> m_expr;
584 };
585
586 class PrefixResolveNode : public Node {
587 public:
588 PrefixResolveNode(const Identifier& i, Operator o) KJS_FAST_CALL : m_ident(i), m_oper(o) {}
589 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
590 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
591 private:
592 Identifier m_ident;
593 Operator m_oper;
594 };
595
596 class PrefixBracketNode : public Node {
597 public:
598 PrefixBracketNode(Node *b, Node *s, Operator o) KJS_FAST_CALL : m_base(b), m_subscript(s), m_oper(o) {}
599 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
600 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
601 private:
602 RefPtr<Node> m_base;
603 RefPtr<Node> m_subscript;
604 Operator m_oper;
605 };
606
607 class PrefixDotNode : public Node {
608 public:
609 PrefixDotNode(Node *b, const Identifier& i, Operator o) KJS_FAST_CALL : m_base(b), m_ident(i), m_oper(o) {}
610 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
611 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
612 private:
613 RefPtr<Node> m_base;
614 Identifier m_ident;
615 Operator m_oper;
616 };
617
618 class PrefixErrorNode : public Node {
619 public:
620 PrefixErrorNode(Node* e, Operator o) KJS_FAST_CALL : m_expr(e), m_oper(o) {}
621 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
622 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
623 private:
624 RefPtr<Node> m_expr;
625 Operator m_oper;
626 };
627
628 class UnaryPlusNode : public Node {
629 public:
630 UnaryPlusNode(Node *e) KJS_FAST_CALL : expr(e) {}
631 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
632 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
633 private:
634 RefPtr<Node> expr;
635 };
636
637 class NegateNode : public Node {
638 public:
639 NegateNode(Node *e) KJS_FAST_CALL : expr(e) {}
640 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
641 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
642 private:
643 RefPtr<Node> expr;
644 };
645
646 class BitwiseNotNode : public Node {
647 public:
648 BitwiseNotNode(Node *e) KJS_FAST_CALL : expr(e) {}
649 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
650 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
651 private:
652 RefPtr<Node> expr;
653 };
654
655 class LogicalNotNode : public Node {
656 public:
657 LogicalNotNode(Node *e) KJS_FAST_CALL : expr(e) {}
658 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
659 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
660 private:
661 RefPtr<Node> expr;
662 };
663
664 class MultNode : public Node {
665 public:
666 MultNode(Node *t1, Node *t2) KJS_FAST_CALL : term1(t1), term2(t2) {}
667 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
668 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
669 private:
670 RefPtr<Node> term1;
671 RefPtr<Node> term2;
672 };
673
674 class DivNode : public Node {
675 public:
676 DivNode(Node *t1, Node *t2) KJS_FAST_CALL : term1(t1), term2(t2) {}
677 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
678 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
679 private:
680 RefPtr<Node> term1;
681 RefPtr<Node> term2;
682 };
683
684 class ModNode : public Node {
685 public:
686 ModNode(Node *t1, Node *t2) KJS_FAST_CALL : term1(t1), term2(t2) {}
687 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
688 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
689 private:
690 RefPtr<Node> term1;
691 RefPtr<Node> term2;
692 };
693
694 class AddNode : public Node {
695 public:
696 AddNode(Node *t1, Node *t2) KJS_FAST_CALL : term1(t1), term2(t2) {}
697 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
698 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
699 private:
700 RefPtr<Node> term1;
701 RefPtr<Node> term2;
702 };
703
704 class SubNode : public Node {
705 public:
706 SubNode(Node *t1, Node *t2) KJS_FAST_CALL : term1(t1), term2(t2) {}
707 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
708 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
709 private:
710 RefPtr<Node> term1;
711 RefPtr<Node> term2;
712 };
713
714 class LeftShiftNode : public Node {
715 public:
716 LeftShiftNode(Node *t1, Node *t2) KJS_FAST_CALL
717 : term1(t1), term2(t2) {}
718 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
719 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
720 private:
721 RefPtr<Node> term1;
722 RefPtr<Node> term2;
723 };
724
725 class RightShiftNode : public Node {
726 public:
727 RightShiftNode(Node *t1, Node *t2) KJS_FAST_CALL
728 : term1(t1), term2(t2) {}
729 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
730 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
731 private:
732 RefPtr<Node> term1;
733 RefPtr<Node> term2;
734 };
735
736 class UnsignedRightShiftNode : public Node {
737 public:
738 UnsignedRightShiftNode(Node *t1, Node *t2) KJS_FAST_CALL
739 : term1(t1), term2(t2) {}
740 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
741 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
742 private:
743 RefPtr<Node> term1;
744 RefPtr<Node> term2;
745 };
746
747 class LessNode : public Node {
748 public:
749 LessNode(Node *e1, Node *e2) KJS_FAST_CALL :
750 expr1(e1), expr2(e2) {}
751 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
752 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
753 private:
754 RefPtr<Node> expr1;
755 RefPtr<Node> expr2;
756 };
757
758 class GreaterNode : public Node {
759 public:
760 GreaterNode(Node *e1, Node *e2) KJS_FAST_CALL :
761 expr1(e1), expr2(e2) {}
762 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
763 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
764 private:
765 RefPtr<Node> expr1;
766 RefPtr<Node> expr2;
767 };
768
769 class LessEqNode : public Node {
770 public:
771 LessEqNode(Node *e1, Node *e2) KJS_FAST_CALL :
772 expr1(e1), expr2(e2) {}
773 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
774 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
775 private:
776 RefPtr<Node> expr1;
777 RefPtr<Node> expr2;
778 };
779
780 class GreaterEqNode : public Node {
781 public:
782 GreaterEqNode(Node *e1, Node *e2) KJS_FAST_CALL :
783 expr1(e1), expr2(e2) {}
784 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
785 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
786 private:
787 RefPtr<Node> expr1;
788 RefPtr<Node> expr2;
789 };
790
791 class InstanceOfNode : public Node {
792 public:
793 InstanceOfNode(Node *e1, Node *e2) KJS_FAST_CALL :
794 expr1(e1), expr2(e2) {}
795 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
796 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
797 private:
798 RefPtr<Node> expr1;
799 RefPtr<Node> expr2;
800 };
801
802 class InNode : public Node {
803 public:
804 InNode(Node *e1, Node *e2) KJS_FAST_CALL :
805 expr1(e1), expr2(e2) {}
806 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
807 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
808 private:
809 RefPtr<Node> expr1;
810 RefPtr<Node> expr2;
811 };
812
813 class EqualNode : public Node {
814 public:
815 EqualNode(Node *e1, Node *e2) KJS_FAST_CALL
816 : expr1(e1), expr2(e2) {}
817 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
818 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
819 private:
820 RefPtr<Node> expr1;
821 RefPtr<Node> expr2;
822 };
823
824 class NotEqualNode : public Node {
825 public:
826 NotEqualNode(Node *e1, Node *e2) KJS_FAST_CALL
827 : expr1(e1), expr2(e2) {}
828 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
829 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
830 private:
831 RefPtr<Node> expr1;
832 RefPtr<Node> expr2;
833 };
834
835 class StrictEqualNode : public Node {
836 public:
837 StrictEqualNode(Node *e1, Node *e2) KJS_FAST_CALL
838 : expr1(e1), expr2(e2) {}
839 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
840 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
841 private:
842 RefPtr<Node> expr1;
843 RefPtr<Node> expr2;
844 };
845
846 class NotStrictEqualNode : public Node {
847 public:
848 NotStrictEqualNode(Node *e1, Node *e2) KJS_FAST_CALL
849 : expr1(e1), expr2(e2) {}
850 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
851 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
852 private:
853 RefPtr<Node> expr1;
854 RefPtr<Node> expr2;
855 };
856
857 class BitAndNode : public Node {
858 public:
859 BitAndNode(Node *e1, Node *e2) KJS_FAST_CALL :
860 expr1(e1), expr2(e2) {}
861 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
862 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
863 private:
864 RefPtr<Node> expr1;
865 RefPtr<Node> expr2;
866 };
867
868 class BitOrNode : public Node {
869 public:
870 BitOrNode(Node *e1, Node *e2) KJS_FAST_CALL :
871 expr1(e1), expr2(e2) {}
872 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
873 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
874 private:
875 RefPtr<Node> expr1;
876 RefPtr<Node> expr2;
877 };
878
879 class BitXOrNode : public Node {
880 public:
881 BitXOrNode(Node *e1, Node *e2) KJS_FAST_CALL :
882 expr1(e1), expr2(e2) {}
883 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
884 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
885 private:
886 RefPtr<Node> expr1;
887 RefPtr<Node> expr2;
888 };
889
890 /**
891 * expr1 && expr2, expr1 || expr2
892 */
893 class LogicalAndNode : public Node {
894 public:
895 LogicalAndNode(Node *e1, Node *e2) KJS_FAST_CALL :
896 expr1(e1), expr2(e2) {}
897 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
898 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
899 private:
900 RefPtr<Node> expr1;
901 RefPtr<Node> expr2;
902 };
903
904 class LogicalOrNode : public Node {
905 public:
906 LogicalOrNode(Node *e1, Node *e2) KJS_FAST_CALL :
907 expr1(e1), expr2(e2) {}
908 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
909 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
910 private:
911 RefPtr<Node> expr1;
912 RefPtr<Node> expr2;
913 };
914
915 /**
916 * The ternary operator, "logical ? expr1 : expr2"
917 */
918 class ConditionalNode : public Node {
919 public:
920 ConditionalNode(Node *l, Node *e1, Node *e2) KJS_FAST_CALL :
921 logical(l), expr1(e1), expr2(e2) {}
922 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
923 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
924 private:
925 RefPtr<Node> logical;
926 RefPtr<Node> expr1;
927 RefPtr<Node> expr2;
928 };
929
930 class AssignResolveNode : public Node {
931 public:
932 AssignResolveNode(const Identifier &ident, Operator oper, Node *right) KJS_FAST_CALL
933 : m_ident(ident), m_oper(oper), m_right(right) {}
934 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
935 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
936 protected:
937 Identifier m_ident;
938 Operator m_oper;
939 RefPtr<Node> m_right;
940 };
941
942 class AssignBracketNode : public Node {
943 public:
944 AssignBracketNode(Node *base, Node *subscript, Operator oper, Node *right) KJS_FAST_CALL
945 : m_base(base), m_subscript(subscript), m_oper(oper), m_right(right) {}
946 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
947 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
948 protected:
949 RefPtr<Node> m_base;
950 RefPtr<Node> m_subscript;
951 Operator m_oper;
952 RefPtr<Node> m_right;
953 };
954
955 class AssignDotNode : public Node {
956 public:
957 AssignDotNode(Node *base, const Identifier& ident, Operator oper, Node *right) KJS_FAST_CALL
958 : m_base(base), m_ident(ident), m_oper(oper), m_right(right) {}
959 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
960 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
961 protected:
962 RefPtr<Node> m_base;
963 Identifier m_ident;
964 Operator m_oper;
965 RefPtr<Node> m_right;
966 };
967
968 class AssignErrorNode : public Node {
969 public:
970 AssignErrorNode(Node* left, Operator oper, Node* right) KJS_FAST_CALL
971 : m_left(left), m_oper(oper), m_right(right) {}
972 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
973 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
974 protected:
975 RefPtr<Node> m_left;
976 Operator m_oper;
977 RefPtr<Node> m_right;
978 };
979
980 class CommaNode : public Node {
981 public:
982 CommaNode(Node *e1, Node *e2) KJS_FAST_CALL : expr1(e1), expr2(e2) {}
983 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
984 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
985 private:
986 RefPtr<Node> expr1;
987 RefPtr<Node> expr2;
988 };
989
990 class AssignExprNode : public Node {
991 public:
992 AssignExprNode(Node *e) KJS_FAST_CALL : expr(e) {}
993 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
994 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
995 private:
996 RefPtr<Node> expr;
997 };
998
999 class VarDeclNode: public Node {
1000 public:
1001 enum Type { Variable, Constant };
1002 VarDeclNode(const Identifier &id, AssignExprNode *in, Type t) KJS_FAST_CALL;
1003 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
1004 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
1005 ALWAYS_INLINE void processDeclaration(ExecState*) KJS_FAST_CALL;
1006 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;
1007 private:
1008 JSValue* handleSlowCase(ExecState*, const ScopeChain&, JSValue*) KJS_FAST_CALL KJS_NO_INLINE;
1009 Type varType;
1010 Identifier ident;
1011 RefPtr<AssignExprNode> init;
1012 };
1013
1014 class VarDeclListNode : public Node {
1015 public:
1016 // list pointer is tail of a circular list, cracked in the ForNode/VarStatementNode ctor
1017 VarDeclListNode(VarDeclNode *v) KJS_FAST_CALL : next(this), var(v) { Parser::noteNodeCycle(this); m_mayHaveDeclarations = true; }
1018 VarDeclListNode(VarDeclListNode *l, VarDeclNode *v) KJS_FAST_CALL
1019 : next(l->next), var(v) { l->next = this; m_mayHaveDeclarations = true; }
1020 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
1021 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
1022 PassRefPtr<VarDeclListNode> releaseNext() KJS_FAST_CALL { return next.release(); }
1023 virtual void breakCycle() KJS_FAST_CALL;
1024 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;
1025 private:
1026 friend class ForNode;
1027 friend class VarStatementNode;
1028 ListRefPtr<VarDeclListNode> next;
1029 RefPtr<VarDeclNode> var;
1030 };
1031
1032 class VarStatementNode : public StatementNode {
1033 public:
1034 VarStatementNode(VarDeclListNode *l) KJS_FAST_CALL : next(l->next.release()) { Parser::removeNodeCycle(next.get()); m_mayHaveDeclarations = true; }
1035 virtual Completion execute(ExecState*) KJS_FAST_CALL;
1036 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
1037 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;
1038 private:
1039 RefPtr<VarDeclListNode> next;
1040 };
1041
1042 class BlockNode : public StatementNode {
1043 public:
1044 BlockNode(SourceElementsNode *s) KJS_FAST_CALL;
1045 virtual Completion execute(ExecState*) KJS_FAST_CALL;
1046 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
1047 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;
1048 protected:
1049 RefPtr<SourceElementsNode> source;
1050 };
1051
1052 class EmptyStatementNode : public StatementNode {
1053 public:
1054 EmptyStatementNode() KJS_FAST_CALL { } // debug
1055 virtual Completion execute(ExecState*) KJS_FAST_CALL;
1056 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
1057 };
1058
1059 class ExprStatementNode : public StatementNode {
1060 public:
1061 ExprStatementNode(Node *e) KJS_FAST_CALL : expr(e) { }
1062 virtual Completion execute(ExecState*) KJS_FAST_CALL;
1063 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
1064 private:
1065 RefPtr<Node> expr;
1066 };
1067
1068 class IfNode : public StatementNode {
1069 public:
1070 IfNode(Node *e, StatementNode *s1, StatementNode *s2) KJS_FAST_CALL
1071 : expr(e), statement1(s1), statement2(s2) { m_mayHaveDeclarations = statement1->mayHaveDeclarations() || (statement2 && statement2->mayHaveDeclarations()); }
1072 virtual Completion execute(ExecState*) KJS_FAST_CALL;
1073 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
1074 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;
1075 private:
1076 RefPtr<Node> expr;
1077 RefPtr<StatementNode> statement1;
1078 RefPtr<StatementNode> statement2;
1079 };
1080
1081 class DoWhileNode : public StatementNode {
1082 public:
1083 DoWhileNode(StatementNode *s, Node *e) KJS_FAST_CALL : statement(s), expr(e) { m_mayHaveDeclarations = true; }
1084 virtual Completion execute(ExecState*) KJS_FAST_CALL;
1085 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
1086 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;
1087 private:
1088 RefPtr<StatementNode> statement;
1089 RefPtr<Node> expr;
1090 };
1091
1092 class WhileNode : public StatementNode {
1093 public:
1094 WhileNode(Node *e, StatementNode *s) KJS_FAST_CALL : expr(e), statement(s) { m_mayHaveDeclarations = true; }
1095 virtual Completion execute(ExecState*) KJS_FAST_CALL;
1096 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
1097 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;
1098 private:
1099 RefPtr<Node> expr;
1100 RefPtr<StatementNode> statement;
1101 };
1102
1103 class ForNode : public StatementNode {
1104 public:
1105 ForNode(Node *e1, Node *e2, Node *e3, StatementNode *s) KJS_FAST_CALL :
1106 expr1(e1), expr2(e2), expr3(e3), statement(s) { m_mayHaveDeclarations = true; }
1107 ForNode(VarDeclListNode *e1, Node *e2, Node *e3, StatementNode *s) KJS_FAST_CALL :
1108 expr1(e1->next.release()), expr2(e2), expr3(e3), statement(s) { Parser::removeNodeCycle(expr1.get()); m_mayHaveDeclarations = true; }
1109 virtual Completion execute(ExecState*) KJS_FAST_CALL;
1110 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
1111 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;
1112 private:
1113 RefPtr<Node> expr1;
1114 RefPtr<Node> expr2;
1115 RefPtr<Node> expr3;
1116 RefPtr<StatementNode> statement;
1117 };
1118
1119 class ForInNode : public StatementNode {
1120 public:
1121 ForInNode(Node *l, Node *e, StatementNode *s) KJS_FAST_CALL;
1122 ForInNode(const Identifier &i, AssignExprNode *in, Node *e, StatementNode *s) KJS_FAST_CALL;
1123 virtual Completion execute(ExecState*) KJS_FAST_CALL;
1124 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
1125 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;
1126 private:
1127 Identifier ident;
1128 RefPtr<AssignExprNode> init;
1129 RefPtr<Node> lexpr;
1130 RefPtr<Node> expr;
1131 RefPtr<VarDeclNode> varDecl;
1132 RefPtr<StatementNode> statement;
1133 };
1134
1135 class ContinueNode : public StatementNode {
1136 public:
1137 ContinueNode() KJS_FAST_CALL { }
1138 ContinueNode(const Identifier &i) KJS_FAST_CALL : ident(i) { }
1139 virtual Completion execute(ExecState*) KJS_FAST_CALL;
1140 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
1141 private:
1142 Identifier ident;
1143 };
1144
1145 class BreakNode : public StatementNode {
1146 public:
1147 BreakNode() KJS_FAST_CALL { }
1148 BreakNode(const Identifier &i) KJS_FAST_CALL : ident(i) { }
1149 virtual Completion execute(ExecState*) KJS_FAST_CALL;
1150 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
1151 private:
1152 Identifier ident;
1153 };
1154
1155 class ReturnNode : public StatementNode {
1156 public:
1157 ReturnNode(Node *v) KJS_FAST_CALL : value(v) {}
1158 virtual Completion execute(ExecState*) KJS_FAST_CALL;
1159 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
1160 private:
1161 RefPtr<Node> value;
1162 };
1163
1164 class WithNode : public StatementNode {
1165 public:
1166 WithNode(Node *e, StatementNode *s) KJS_FAST_CALL : expr(e), statement(s) { m_mayHaveDeclarations = true; }
1167 virtual Completion execute(ExecState*) KJS_FAST_CALL;
1168 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
1169 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;
1170 private:
1171 RefPtr<Node> expr;
1172 RefPtr<StatementNode> statement;
1173 };
1174
1175 class LabelNode : public StatementNode {
1176 public:
1177 LabelNode(const Identifier &l, StatementNode *s) KJS_FAST_CALL : label(l), statement(s) { m_mayHaveDeclarations = true; }
1178 virtual Completion execute(ExecState*) KJS_FAST_CALL;
1179 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
1180 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;
1181 private:
1182 Identifier label;
1183 RefPtr<StatementNode> statement;
1184 };
1185
1186 class ThrowNode : public StatementNode {
1187 public:
1188 ThrowNode(Node *e) KJS_FAST_CALL : expr(e) {}
1189 virtual Completion execute(ExecState*) KJS_FAST_CALL;
1190 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
1191 private:
1192 RefPtr<Node> expr;
1193 };
1194
1195 class TryNode : public StatementNode {
1196 public:
1197 TryNode(StatementNode *b, const Identifier &e, StatementNode *c, StatementNode *f) KJS_FAST_CALL
1198 : tryBlock(b), exceptionIdent(e), catchBlock(c), finallyBlock(f) { m_mayHaveDeclarations = true; }
1199 virtual Completion execute(ExecState*) KJS_FAST_CALL;
1200 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
1201 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;
1202 private:
1203 RefPtr<StatementNode> tryBlock;
1204 Identifier exceptionIdent;
1205 RefPtr<StatementNode> catchBlock;
1206 RefPtr<StatementNode> finallyBlock;
1207 };
1208
1209 class ParameterNode : public Node {
1210 public:
1211 // list pointer is tail of a circular list, cracked in the FuncDeclNode/FuncExprNode ctor
1212 ParameterNode(const Identifier &i) KJS_FAST_CALL : id(i), next(this) { Parser::noteNodeCycle(this); }
1213 ParameterNode(ParameterNode *next, const Identifier &i) KJS_FAST_CALL
1214 : id(i), next(next->next) { next->next = this; }
1215 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
1216 Identifier ident() KJS_FAST_CALL { return id; }
1217 ParameterNode *nextParam() KJS_FAST_CALL { return next.get(); }
1218 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
1219 PassRefPtr<ParameterNode> releaseNext() KJS_FAST_CALL { return next.release(); }
1220 virtual void breakCycle() KJS_FAST_CALL;
1221 private:
1222 friend class FuncDeclNode;
1223 friend class FuncExprNode;
1224 Identifier id;
1225 ListRefPtr<ParameterNode> next;
1226 };
1227
1228 // inherited by ProgramNode
1229 class FunctionBodyNode : public BlockNode {
1230 public:
1231 FunctionBodyNode(SourceElementsNode *) KJS_FAST_CALL;
1232 int sourceId() KJS_FAST_CALL { return m_sourceId; }
1233 const UString& sourceURL() KJS_FAST_CALL { return m_sourceURL; }
1234
1235 virtual Completion execute(ExecState*) KJS_FAST_CALL;
1236
1237 void addParam(const Identifier& ident) KJS_FAST_CALL;
1238 size_t numParams() const KJS_FAST_CALL { return m_parameters.size(); }
1239 Identifier paramName(size_t pos) const KJS_FAST_CALL { return m_parameters[pos]; }
1240 UString paramString() const KJS_FAST_CALL;
1241 Vector<Identifier>& parameters() KJS_FAST_CALL { return m_parameters; }
1242 ALWAYS_INLINE void processDeclarations(ExecState*) KJS_FAST_CALL;
1243 private:
1244 UString m_sourceURL;
1245 int m_sourceId;
1246 Vector<Identifier> m_parameters;
1247
1248 void initializeDeclarationStacks();
1249 bool m_initializedDeclarationStacks;
1250 DeclarationStacks::VarStack m_varStack;
1251 DeclarationStacks::FunctionStack m_functionStack;
1252 };
1253
1254 class FuncExprNode : public Node {
1255 public:
1256 FuncExprNode(const Identifier &i, FunctionBodyNode *b, ParameterNode *p = 0) KJS_FAST_CALL
1257 : ident(i), param(p ? p->next.release() : 0), body(b) { if (p) { Parser::removeNodeCycle(param.get()); } addParams(); }
1258 virtual JSValue *evaluate(ExecState*) KJS_FAST_CALL;
1259 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
1260 private:
1261 void addParams() KJS_FAST_CALL;
1262 // Used for streamTo
1263 friend class PropertyNode;
1264 Identifier ident;
1265 RefPtr<ParameterNode> param;
1266 RefPtr<FunctionBodyNode> body;
1267 };
1268
1269 class FuncDeclNode : public StatementNode {
1270 public:
1271 FuncDeclNode(const Identifier &i, FunctionBodyNode *b) KJS_FAST_CALL
1272 : ident(i), body(b) { addParams(); m_mayHaveDeclarations = true; }
1273 FuncDeclNode(const Identifier &i, ParameterNode *p, FunctionBodyNode *b) KJS_FAST_CALL
1274 : ident(i), param(p->next.release()), body(b) { Parser::removeNodeCycle(param.get()); addParams(); m_mayHaveDeclarations = true; }
1275 virtual Completion execute(ExecState*) KJS_FAST_CALL;
1276 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
1277 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;
1278 ALWAYS_INLINE void processDeclaration(ExecState*) KJS_FAST_CALL;
1279 private:
1280 void addParams() KJS_FAST_CALL;
1281 Identifier ident;
1282 RefPtr<ParameterNode> param;
1283 RefPtr<FunctionBodyNode> body;
1284 };
1285
1286 // A linked list of source element nodes
1287 class SourceElementsNode : public StatementNode {
1288 public:
1289 static int count;
1290 // list pointer is tail of a circular list, cracked in the BlockNode (or subclass) ctor
1291 SourceElementsNode(StatementNode*) KJS_FAST_CALL;
1292 SourceElementsNode(SourceElementsNode *s1, StatementNode *s2) KJS_FAST_CALL;
1293
1294 Completion execute(ExecState*) KJS_FAST_CALL;
1295 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
1296 PassRefPtr<SourceElementsNode> releaseNext() KJS_FAST_CALL { return next.release(); }
1297 virtual void breakCycle() KJS_FAST_CALL;
1298 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;
1299 private:
1300 friend class BlockNode;
1301 friend class CaseClauseNode;
1302 RefPtr<StatementNode> node;
1303 ListRefPtr<SourceElementsNode> next;
1304 };
1305
1306 class CaseClauseNode : public Node {
1307 public:
1308 CaseClauseNode(Node *e) KJS_FAST_CALL : expr(e) { m_mayHaveDeclarations = true; }
1309 CaseClauseNode(Node *e, SourceElementsNode *s) KJS_FAST_CALL
1310 : expr(e), source(s->next.release()) { Parser::removeNodeCycle(source.get()); m_mayHaveDeclarations = true; }
1311 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
1312 Completion evalStatements(ExecState*) KJS_FAST_CALL;
1313 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
1314 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;
1315 private:
1316 RefPtr<Node> expr;
1317 RefPtr<SourceElementsNode> source;
1318 };
1319
1320 class ClauseListNode : public Node {
1321 public:
1322 // list pointer is tail of a circular list, cracked in the CaseBlockNode ctor
1323 ClauseListNode(CaseClauseNode *c) KJS_FAST_CALL : clause(c), next(this) { Parser::noteNodeCycle(this); m_mayHaveDeclarations = true; }
1324 ClauseListNode(ClauseListNode *n, CaseClauseNode *c) KJS_FAST_CALL
1325 : clause(c), next(n->next) { n->next = this; m_mayHaveDeclarations = true; }
1326 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
1327 CaseClauseNode *getClause() const KJS_FAST_CALL { return clause.get(); }
1328 ClauseListNode *getNext() const KJS_FAST_CALL { return next.get(); }
1329 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
1330 PassRefPtr<ClauseListNode> releaseNext() KJS_FAST_CALL { return next.release(); }
1331 virtual void breakCycle() KJS_FAST_CALL;
1332 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;
1333 private:
1334 friend class CaseBlockNode;
1335 RefPtr<CaseClauseNode> clause;
1336 ListRefPtr<ClauseListNode> next;
1337 };
1338
1339 class CaseBlockNode : public Node {
1340 public:
1341 CaseBlockNode(ClauseListNode *l1, CaseClauseNode *d, ClauseListNode *l2) KJS_FAST_CALL;
1342 JSValue* evaluate(ExecState*) KJS_FAST_CALL;
1343 Completion evalBlock(ExecState *exec, JSValue *input) KJS_FAST_CALL;
1344 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
1345 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;
1346 private:
1347 RefPtr<ClauseListNode> list1;
1348 RefPtr<CaseClauseNode> def;
1349 RefPtr<ClauseListNode> list2;
1350 };
1351
1352 class SwitchNode : public StatementNode {
1353 public:
1354 SwitchNode(Node *e, CaseBlockNode *b) KJS_FAST_CALL : expr(e), block(b) { m_mayHaveDeclarations = true; }
1355 virtual Completion execute(ExecState*) KJS_FAST_CALL;
1356 virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
1357 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;
1358 private:
1359 RefPtr<Node> expr;
1360 RefPtr<CaseBlockNode> block;
1361 };
1362
1363 class ProgramNode : public FunctionBodyNode {
1364 public:
1365 ProgramNode(SourceElementsNode *s) KJS_FAST_CALL;
1366 };
1367
1368} // namespace
1369
1370#endif
Note: See TracBrowser for help on using the repository browser.