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