]>
Commit | Line | Data |
---|---|---|
9dae56ea A |
1 | /* |
2 | * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) | |
3 | * Copyright (C) 2001 Peter Kelly (pmk@post.com) | |
4 | * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. | |
5 | * Copyright (C) 2007 Cameron Zwarich (cwzwarich@uwaterloo.ca) | |
6 | * Copyright (C) 2007 Maks Orlovich | |
7 | * Copyright (C) 2007 Eric Seidel <eric@webkit.org> | |
8 | * | |
9 | * This library is free software; you can redistribute it and/or | |
10 | * modify it under the terms of the GNU Library General Public | |
11 | * License as published by the Free Software Foundation; either | |
12 | * version 2 of the License, or (at your option) any later version. | |
13 | * | |
14 | * This library is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | * Library General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU Library General Public License | |
20 | * along with this library; see the file COPYING.LIB. If not, write to | |
21 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
22 | * Boston, MA 02110-1301, USA. | |
23 | * | |
24 | */ | |
25 | ||
ba379fdc A |
26 | #ifndef Nodes_h |
27 | #define Nodes_h | |
9dae56ea A |
28 | |
29 | #include "Error.h" | |
ba379fdc | 30 | #include "JITCode.h" |
9dae56ea | 31 | #include "Opcode.h" |
ba379fdc | 32 | #include "ParserArena.h" |
9dae56ea A |
33 | #include "ResultType.h" |
34 | #include "SourceCode.h" | |
35 | #include "SymbolTable.h" | |
36 | #include <wtf/MathExtras.h> | |
9dae56ea A |
37 | |
38 | namespace JSC { | |
39 | ||
ba379fdc | 40 | class ArgumentListNode; |
9dae56ea | 41 | class BytecodeGenerator; |
f9bf01c6 A |
42 | class FunctionBodyNode; |
43 | class Label; | |
9dae56ea | 44 | class PropertyListNode; |
ba379fdc | 45 | class ReadModifyResolveNode; |
9dae56ea A |
46 | class RegisterID; |
47 | class ScopeChainNode; | |
f9bf01c6 | 48 | class ScopeNode; |
9dae56ea A |
49 | |
50 | typedef unsigned CodeFeatures; | |
51 | ||
52 | const CodeFeatures NoFeatures = 0; | |
53 | const CodeFeatures EvalFeature = 1 << 0; | |
54 | const CodeFeatures ClosureFeature = 1 << 1; | |
55 | const CodeFeatures AssignFeature = 1 << 2; | |
56 | const CodeFeatures ArgumentsFeature = 1 << 3; | |
57 | const CodeFeatures WithFeature = 1 << 4; | |
58 | const CodeFeatures CatchFeature = 1 << 5; | |
59 | const CodeFeatures ThisFeature = 1 << 6; | |
14957cd0 A |
60 | const CodeFeatures StrictModeFeature = 1 << 7; |
61 | const CodeFeatures ShadowsArgumentsFeature = 1 << 8; | |
62 | ||
63 | ||
64 | const CodeFeatures AllFeatures = EvalFeature | ClosureFeature | AssignFeature | ArgumentsFeature | WithFeature | CatchFeature | ThisFeature | StrictModeFeature | ShadowsArgumentsFeature; | |
9dae56ea A |
65 | |
66 | enum Operator { | |
67 | OpEqual, | |
68 | OpPlusEq, | |
69 | OpMinusEq, | |
70 | OpMultEq, | |
71 | OpDivEq, | |
72 | OpPlusPlus, | |
73 | OpMinusMinus, | |
74 | OpAndEq, | |
75 | OpXOrEq, | |
76 | OpOrEq, | |
77 | OpModEq, | |
78 | OpLShift, | |
79 | OpRShift, | |
80 | OpURShift | |
81 | }; | |
82 | ||
83 | enum LogicalOperator { | |
84 | OpLogicalAnd, | |
85 | OpLogicalOr | |
86 | }; | |
87 | ||
14957cd0 A |
88 | typedef HashSet<RefPtr<StringImpl>, IdentifierRepHash> IdentifierSet; |
89 | ||
9dae56ea A |
90 | namespace DeclarationStacks { |
91 | enum VarAttrs { IsConstant = 1, HasInitializer = 2 }; | |
f9bf01c6 A |
92 | typedef Vector<std::pair<const Identifier*, unsigned> > VarStack; |
93 | typedef Vector<FunctionBodyNode*> FunctionStack; | |
9dae56ea A |
94 | } |
95 | ||
96 | struct SwitchInfo { | |
97 | enum SwitchType { SwitchNone, SwitchImmediate, SwitchCharacter, SwitchString }; | |
98 | uint32_t bytecodeOffset; | |
99 | SwitchType switchType; | |
100 | }; | |
101 | ||
f9bf01c6 A |
102 | class ParserArenaFreeable { |
103 | public: | |
104 | // ParserArenaFreeable objects are are freed when the arena is deleted. | |
105 | // Destructors are not called. Clients must not call delete on such objects. | |
106 | void* operator new(size_t, JSGlobalData*); | |
107 | }; | |
9dae56ea | 108 | |
f9bf01c6 | 109 | class ParserArenaDeletable { |
9dae56ea | 110 | public: |
ba379fdc | 111 | virtual ~ParserArenaDeletable() { } |
9dae56ea | 112 | |
f9bf01c6 A |
113 | // ParserArenaDeletable objects are deleted when the arena is deleted. |
114 | // Clients must not call delete directly on such objects. | |
ba379fdc | 115 | void* operator new(size_t, JSGlobalData*); |
ba379fdc | 116 | }; |
9dae56ea | 117 | |
ba379fdc A |
118 | class ParserArenaRefCounted : public RefCounted<ParserArenaRefCounted> { |
119 | protected: | |
120 | ParserArenaRefCounted(JSGlobalData*); | |
9dae56ea | 121 | |
ba379fdc A |
122 | public: |
123 | virtual ~ParserArenaRefCounted() | |
124 | { | |
125 | ASSERT(deletionHasBegun()); | |
126 | } | |
9dae56ea A |
127 | }; |
128 | ||
f9bf01c6 | 129 | class Node : public ParserArenaFreeable { |
ba379fdc A |
130 | protected: |
131 | Node(JSGlobalData*); | |
9dae56ea | 132 | |
ba379fdc | 133 | public: |
f9bf01c6 | 134 | virtual ~Node() { } |
9dae56ea | 135 | |
f9bf01c6 | 136 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* destination = 0) = 0; |
9dae56ea A |
137 | |
138 | int lineNo() const { return m_line; } | |
139 | ||
140 | protected: | |
141 | int m_line; | |
142 | }; | |
143 | ||
144 | class ExpressionNode : public Node { | |
f9bf01c6 | 145 | protected: |
ba379fdc A |
146 | ExpressionNode(JSGlobalData*, ResultType = ResultType::unknownType()); |
147 | ||
f9bf01c6 | 148 | public: |
ba379fdc A |
149 | virtual bool isNumber() const { return false; } |
150 | virtual bool isString() const { return false; } | |
151 | virtual bool isNull() const { return false; } | |
152 | virtual bool isPure(BytecodeGenerator&) const { return false; } | |
153 | virtual bool isLocation() const { return false; } | |
154 | virtual bool isResolveNode() const { return false; } | |
155 | virtual bool isBracketAccessorNode() const { return false; } | |
156 | virtual bool isDotAccessorNode() const { return false; } | |
157 | virtual bool isFuncExprNode() const { return false; } | |
158 | virtual bool isCommaNode() const { return false; } | |
159 | virtual bool isSimpleArray() const { return false; } | |
160 | virtual bool isAdd() const { return false; } | |
14957cd0 | 161 | virtual bool isSubtract() const { return false; } |
f9bf01c6 A |
162 | virtual bool hasConditionContextCodegen() const { return false; } |
163 | ||
164 | virtual void emitBytecodeInConditionContext(BytecodeGenerator&, Label*, Label*, bool) { ASSERT_NOT_REACHED(); } | |
9dae56ea A |
165 | |
166 | virtual ExpressionNode* stripUnaryPlus() { return this; } | |
167 | ||
ba379fdc | 168 | ResultType resultDescriptor() const { return m_resultType; } |
9dae56ea | 169 | |
9dae56ea | 170 | private: |
ba379fdc | 171 | ResultType m_resultType; |
9dae56ea A |
172 | }; |
173 | ||
174 | class StatementNode : public Node { | |
f9bf01c6 | 175 | protected: |
ba379fdc | 176 | StatementNode(JSGlobalData*); |
9dae56ea | 177 | |
f9bf01c6 A |
178 | public: |
179 | void setLoc(int firstLine, int lastLine); | |
ba379fdc A |
180 | int firstLine() const { return lineNo(); } |
181 | int lastLine() const { return m_lastLine; } | |
9dae56ea | 182 | |
ba379fdc A |
183 | virtual bool isEmptyStatement() const { return false; } |
184 | virtual bool isReturnNode() const { return false; } | |
185 | virtual bool isExprStatement() const { return false; } | |
186 | ||
187 | virtual bool isBlock() const { return false; } | |
9dae56ea A |
188 | |
189 | private: | |
190 | int m_lastLine; | |
191 | }; | |
192 | ||
193 | class NullNode : public ExpressionNode { | |
194 | public: | |
ba379fdc | 195 | NullNode(JSGlobalData*); |
9dae56ea | 196 | |
ba379fdc A |
197 | private: |
198 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); | |
9dae56ea | 199 | |
ba379fdc | 200 | virtual bool isNull() const { return true; } |
9dae56ea A |
201 | }; |
202 | ||
203 | class BooleanNode : public ExpressionNode { | |
204 | public: | |
ba379fdc | 205 | BooleanNode(JSGlobalData*, bool value); |
9dae56ea | 206 | |
ba379fdc A |
207 | private: |
208 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); | |
9dae56ea | 209 | |
ba379fdc | 210 | virtual bool isPure(BytecodeGenerator&) const { return true; } |
9dae56ea | 211 | |
9dae56ea A |
212 | bool m_value; |
213 | }; | |
214 | ||
215 | class NumberNode : public ExpressionNode { | |
216 | public: | |
f9bf01c6 | 217 | NumberNode(JSGlobalData*, double value); |
9dae56ea | 218 | |
f9bf01c6 A |
219 | double value() const { return m_value; } |
220 | void setValue(double value) { m_value = value; } | |
9dae56ea A |
221 | |
222 | private: | |
ba379fdc A |
223 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
224 | ||
225 | virtual bool isNumber() const { return true; } | |
226 | virtual bool isPure(BytecodeGenerator&) const { return true; } | |
227 | ||
f9bf01c6 | 228 | double m_value; |
9dae56ea A |
229 | }; |
230 | ||
231 | class StringNode : public ExpressionNode { | |
232 | public: | |
f9bf01c6 | 233 | StringNode(JSGlobalData*, const Identifier&); |
9dae56ea | 234 | |
9dae56ea | 235 | const Identifier& value() { return m_value; } |
9dae56ea A |
236 | |
237 | private: | |
f9bf01c6 A |
238 | virtual bool isPure(BytecodeGenerator&) const { return true; } |
239 | ||
ba379fdc A |
240 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
241 | ||
242 | virtual bool isString() const { return true; } | |
243 | ||
f9bf01c6 | 244 | const Identifier& m_value; |
9dae56ea A |
245 | }; |
246 | ||
247 | class ThrowableExpressionData { | |
248 | public: | |
249 | ThrowableExpressionData() | |
250 | : m_divot(static_cast<uint32_t>(-1)) | |
251 | , m_startOffset(static_cast<uint16_t>(-1)) | |
252 | , m_endOffset(static_cast<uint16_t>(-1)) | |
253 | { | |
254 | } | |
255 | ||
256 | ThrowableExpressionData(unsigned divot, unsigned startOffset, unsigned endOffset) | |
257 | : m_divot(divot) | |
258 | , m_startOffset(startOffset) | |
259 | , m_endOffset(endOffset) | |
260 | { | |
261 | } | |
262 | ||
263 | void setExceptionSourceCode(unsigned divot, unsigned startOffset, unsigned endOffset) | |
264 | { | |
265 | m_divot = divot; | |
266 | m_startOffset = startOffset; | |
267 | m_endOffset = endOffset; | |
268 | } | |
269 | ||
270 | uint32_t divot() const { return m_divot; } | |
271 | uint16_t startOffset() const { return m_startOffset; } | |
272 | uint16_t endOffset() const { return m_endOffset; } | |
273 | ||
274 | protected: | |
14957cd0 | 275 | RegisterID* emitThrowReferenceError(BytecodeGenerator&, const UString& message); |
9dae56ea A |
276 | |
277 | private: | |
278 | uint32_t m_divot; | |
279 | uint16_t m_startOffset; | |
280 | uint16_t m_endOffset; | |
281 | }; | |
282 | ||
283 | class ThrowableSubExpressionData : public ThrowableExpressionData { | |
284 | public: | |
285 | ThrowableSubExpressionData() | |
f9bf01c6 | 286 | : m_subexpressionDivotOffset(0) |
9dae56ea A |
287 | , m_subexpressionEndOffset(0) |
288 | { | |
289 | } | |
290 | ||
291 | ThrowableSubExpressionData(unsigned divot, unsigned startOffset, unsigned endOffset) | |
292 | : ThrowableExpressionData(divot, startOffset, endOffset) | |
293 | , m_subexpressionDivotOffset(0) | |
294 | , m_subexpressionEndOffset(0) | |
295 | { | |
296 | } | |
297 | ||
298 | void setSubexpressionInfo(uint32_t subexpressionDivot, uint16_t subexpressionOffset) | |
299 | { | |
300 | ASSERT(subexpressionDivot <= divot()); | |
301 | if ((divot() - subexpressionDivot) & ~0xFFFF) // Overflow means we can't do this safely, so just point at the primary divot | |
302 | return; | |
303 | m_subexpressionDivotOffset = divot() - subexpressionDivot; | |
304 | m_subexpressionEndOffset = subexpressionOffset; | |
305 | } | |
306 | ||
307 | protected: | |
308 | uint16_t m_subexpressionDivotOffset; | |
309 | uint16_t m_subexpressionEndOffset; | |
310 | }; | |
311 | ||
312 | class ThrowablePrefixedSubExpressionData : public ThrowableExpressionData { | |
313 | public: | |
314 | ThrowablePrefixedSubExpressionData() | |
f9bf01c6 | 315 | : m_subexpressionDivotOffset(0) |
9dae56ea A |
316 | , m_subexpressionStartOffset(0) |
317 | { | |
318 | } | |
319 | ||
320 | ThrowablePrefixedSubExpressionData(unsigned divot, unsigned startOffset, unsigned endOffset) | |
321 | : ThrowableExpressionData(divot, startOffset, endOffset) | |
322 | , m_subexpressionDivotOffset(0) | |
323 | , m_subexpressionStartOffset(0) | |
324 | { | |
325 | } | |
326 | ||
327 | void setSubexpressionInfo(uint32_t subexpressionDivot, uint16_t subexpressionOffset) | |
328 | { | |
329 | ASSERT(subexpressionDivot >= divot()); | |
330 | if ((subexpressionDivot - divot()) & ~0xFFFF) // Overflow means we can't do this safely, so just point at the primary divot | |
331 | return; | |
332 | m_subexpressionDivotOffset = subexpressionDivot - divot(); | |
333 | m_subexpressionStartOffset = subexpressionOffset; | |
334 | } | |
335 | ||
336 | protected: | |
337 | uint16_t m_subexpressionDivotOffset; | |
338 | uint16_t m_subexpressionStartOffset; | |
339 | }; | |
340 | ||
341 | class RegExpNode : public ExpressionNode, public ThrowableExpressionData { | |
342 | public: | |
f9bf01c6 | 343 | RegExpNode(JSGlobalData*, const Identifier& pattern, const Identifier& flags); |
9dae56ea A |
344 | |
345 | private: | |
ba379fdc A |
346 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
347 | ||
f9bf01c6 A |
348 | const Identifier& m_pattern; |
349 | const Identifier& m_flags; | |
9dae56ea A |
350 | }; |
351 | ||
352 | class ThisNode : public ExpressionNode { | |
353 | public: | |
ba379fdc | 354 | ThisNode(JSGlobalData*); |
9dae56ea | 355 | |
ba379fdc A |
356 | private: |
357 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); | |
9dae56ea A |
358 | }; |
359 | ||
360 | class ResolveNode : public ExpressionNode { | |
361 | public: | |
ba379fdc | 362 | ResolveNode(JSGlobalData*, const Identifier&, int startOffset); |
9dae56ea | 363 | |
ba379fdc | 364 | const Identifier& identifier() const { return m_ident; } |
9dae56ea A |
365 | |
366 | private: | |
ba379fdc A |
367 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
368 | ||
369 | virtual bool isPure(BytecodeGenerator&) const ; | |
370 | virtual bool isLocation() const { return true; } | |
371 | virtual bool isResolveNode() const { return true; } | |
372 | ||
f9bf01c6 | 373 | const Identifier& m_ident; |
9dae56ea A |
374 | int32_t m_startOffset; |
375 | }; | |
376 | ||
f9bf01c6 | 377 | class ElementNode : public ParserArenaFreeable { |
9dae56ea | 378 | public: |
ba379fdc A |
379 | ElementNode(JSGlobalData*, int elision, ExpressionNode*); |
380 | ElementNode(JSGlobalData*, ElementNode*, int elision, ExpressionNode*); | |
9dae56ea A |
381 | |
382 | int elision() const { return m_elision; } | |
ba379fdc A |
383 | ExpressionNode* value() { return m_node; } |
384 | ElementNode* next() { return m_next; } | |
9dae56ea A |
385 | |
386 | private: | |
ba379fdc | 387 | ElementNode* m_next; |
9dae56ea | 388 | int m_elision; |
ba379fdc | 389 | ExpressionNode* m_node; |
9dae56ea A |
390 | }; |
391 | ||
392 | class ArrayNode : public ExpressionNode { | |
393 | public: | |
ba379fdc A |
394 | ArrayNode(JSGlobalData*, int elision); |
395 | ArrayNode(JSGlobalData*, ElementNode*); | |
396 | ArrayNode(JSGlobalData*, int elision, ElementNode*); | |
9dae56ea | 397 | |
ba379fdc | 398 | ArgumentListNode* toArgumentList(JSGlobalData*) const; |
9dae56ea | 399 | |
ba379fdc A |
400 | private: |
401 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); | |
9dae56ea | 402 | |
ba379fdc | 403 | virtual bool isSimpleArray() const ; |
9dae56ea | 404 | |
ba379fdc | 405 | ElementNode* m_element; |
9dae56ea A |
406 | int m_elision; |
407 | bool m_optional; | |
408 | }; | |
409 | ||
f9bf01c6 | 410 | class PropertyNode : public ParserArenaFreeable { |
9dae56ea | 411 | public: |
14957cd0 | 412 | enum Type { Constant = 1, Getter = 2, Setter = 4 }; |
9dae56ea | 413 | |
ba379fdc | 414 | PropertyNode(JSGlobalData*, const Identifier& name, ExpressionNode* value, Type); |
f9bf01c6 | 415 | PropertyNode(JSGlobalData*, double name, ExpressionNode* value, Type); |
9dae56ea A |
416 | |
417 | const Identifier& name() const { return m_name; } | |
14957cd0 | 418 | Type type() const { return m_type; } |
9dae56ea A |
419 | |
420 | private: | |
421 | friend class PropertyListNode; | |
f9bf01c6 | 422 | const Identifier& m_name; |
ba379fdc | 423 | ExpressionNode* m_assign; |
9dae56ea A |
424 | Type m_type; |
425 | }; | |
426 | ||
427 | class PropertyListNode : public Node { | |
428 | public: | |
ba379fdc A |
429 | PropertyListNode(JSGlobalData*, PropertyNode*); |
430 | PropertyListNode(JSGlobalData*, PropertyNode*, PropertyListNode*); | |
9dae56ea | 431 | |
ba379fdc | 432 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
9dae56ea A |
433 | |
434 | private: | |
ba379fdc A |
435 | PropertyNode* m_node; |
436 | PropertyListNode* m_next; | |
9dae56ea A |
437 | }; |
438 | ||
439 | class ObjectLiteralNode : public ExpressionNode { | |
440 | public: | |
ba379fdc A |
441 | ObjectLiteralNode(JSGlobalData*); |
442 | ObjectLiteralNode(JSGlobalData*, PropertyListNode*); | |
9dae56ea A |
443 | |
444 | private: | |
ba379fdc A |
445 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
446 | ||
447 | PropertyListNode* m_list; | |
9dae56ea A |
448 | }; |
449 | ||
450 | class BracketAccessorNode : public ExpressionNode, public ThrowableExpressionData { | |
451 | public: | |
ba379fdc | 452 | BracketAccessorNode(JSGlobalData*, ExpressionNode* base, ExpressionNode* subscript, bool subscriptHasAssignments); |
9dae56ea | 453 | |
ba379fdc A |
454 | ExpressionNode* base() const { return m_base; } |
455 | ExpressionNode* subscript() const { return m_subscript; } | |
9dae56ea | 456 | |
ba379fdc A |
457 | private: |
458 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); | |
9dae56ea | 459 | |
ba379fdc A |
460 | virtual bool isLocation() const { return true; } |
461 | virtual bool isBracketAccessorNode() const { return true; } | |
9dae56ea | 462 | |
ba379fdc A |
463 | ExpressionNode* m_base; |
464 | ExpressionNode* m_subscript; | |
9dae56ea A |
465 | bool m_subscriptHasAssignments; |
466 | }; | |
467 | ||
468 | class DotAccessorNode : public ExpressionNode, public ThrowableExpressionData { | |
469 | public: | |
ba379fdc | 470 | DotAccessorNode(JSGlobalData*, ExpressionNode* base, const Identifier&); |
9dae56ea | 471 | |
ba379fdc A |
472 | ExpressionNode* base() const { return m_base; } |
473 | const Identifier& identifier() const { return m_ident; } | |
9dae56ea | 474 | |
ba379fdc A |
475 | private: |
476 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); | |
9dae56ea | 477 | |
ba379fdc A |
478 | virtual bool isLocation() const { return true; } |
479 | virtual bool isDotAccessorNode() const { return true; } | |
9dae56ea | 480 | |
ba379fdc | 481 | ExpressionNode* m_base; |
f9bf01c6 | 482 | const Identifier& m_ident; |
9dae56ea A |
483 | }; |
484 | ||
485 | class ArgumentListNode : public Node { | |
486 | public: | |
ba379fdc A |
487 | ArgumentListNode(JSGlobalData*, ExpressionNode*); |
488 | ArgumentListNode(JSGlobalData*, ArgumentListNode*, ExpressionNode*); | |
9dae56ea | 489 | |
ba379fdc A |
490 | ArgumentListNode* m_next; |
491 | ExpressionNode* m_expr; | |
9dae56ea | 492 | |
ba379fdc A |
493 | private: |
494 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); | |
9dae56ea A |
495 | }; |
496 | ||
f9bf01c6 | 497 | class ArgumentsNode : public ParserArenaFreeable { |
9dae56ea | 498 | public: |
ba379fdc A |
499 | ArgumentsNode(JSGlobalData*); |
500 | ArgumentsNode(JSGlobalData*, ArgumentListNode*); | |
9dae56ea | 501 | |
ba379fdc | 502 | ArgumentListNode* m_listNode; |
9dae56ea A |
503 | }; |
504 | ||
505 | class NewExprNode : public ExpressionNode, public ThrowableExpressionData { | |
506 | public: | |
ba379fdc A |
507 | NewExprNode(JSGlobalData*, ExpressionNode*); |
508 | NewExprNode(JSGlobalData*, ExpressionNode*, ArgumentsNode*); | |
9dae56ea A |
509 | |
510 | private: | |
ba379fdc A |
511 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
512 | ||
513 | ExpressionNode* m_expr; | |
514 | ArgumentsNode* m_args; | |
9dae56ea A |
515 | }; |
516 | ||
517 | class EvalFunctionCallNode : public ExpressionNode, public ThrowableExpressionData { | |
518 | public: | |
ba379fdc | 519 | EvalFunctionCallNode(JSGlobalData*, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset); |
9dae56ea A |
520 | |
521 | private: | |
ba379fdc A |
522 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
523 | ||
524 | ArgumentsNode* m_args; | |
9dae56ea A |
525 | }; |
526 | ||
527 | class FunctionCallValueNode : public ExpressionNode, public ThrowableExpressionData { | |
528 | public: | |
ba379fdc | 529 | FunctionCallValueNode(JSGlobalData*, ExpressionNode*, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset); |
9dae56ea A |
530 | |
531 | private: | |
ba379fdc A |
532 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
533 | ||
534 | ExpressionNode* m_expr; | |
535 | ArgumentsNode* m_args; | |
9dae56ea A |
536 | }; |
537 | ||
538 | class FunctionCallResolveNode : public ExpressionNode, public ThrowableExpressionData { | |
539 | public: | |
ba379fdc | 540 | FunctionCallResolveNode(JSGlobalData*, const Identifier&, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset); |
9dae56ea A |
541 | |
542 | private: | |
ba379fdc A |
543 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
544 | ||
f9bf01c6 | 545 | const Identifier& m_ident; |
ba379fdc | 546 | ArgumentsNode* m_args; |
9dae56ea A |
547 | size_t m_index; // Used by LocalVarFunctionCallNode. |
548 | size_t m_scopeDepth; // Used by ScopedVarFunctionCallNode and NonLocalVarFunctionCallNode | |
549 | }; | |
550 | ||
551 | class FunctionCallBracketNode : public ExpressionNode, public ThrowableSubExpressionData { | |
552 | public: | |
ba379fdc | 553 | FunctionCallBracketNode(JSGlobalData*, ExpressionNode* base, ExpressionNode* subscript, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset); |
9dae56ea A |
554 | |
555 | private: | |
ba379fdc A |
556 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
557 | ||
558 | ExpressionNode* m_base; | |
559 | ExpressionNode* m_subscript; | |
560 | ArgumentsNode* m_args; | |
9dae56ea A |
561 | }; |
562 | ||
563 | class FunctionCallDotNode : public ExpressionNode, public ThrowableSubExpressionData { | |
564 | public: | |
ba379fdc A |
565 | FunctionCallDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset); |
566 | ||
567 | private: | |
568 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); | |
9dae56ea | 569 | |
ba379fdc A |
570 | protected: |
571 | ExpressionNode* m_base; | |
f9bf01c6 | 572 | const Identifier& m_ident; |
ba379fdc A |
573 | ArgumentsNode* m_args; |
574 | }; | |
9dae56ea | 575 | |
ba379fdc A |
576 | class CallFunctionCallDotNode : public FunctionCallDotNode { |
577 | public: | |
578 | CallFunctionCallDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset); | |
9dae56ea A |
579 | |
580 | private: | |
ba379fdc A |
581 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
582 | }; | |
583 | ||
584 | class ApplyFunctionCallDotNode : public FunctionCallDotNode { | |
585 | public: | |
586 | ApplyFunctionCallDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset); | |
587 | ||
588 | private: | |
589 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); | |
9dae56ea A |
590 | }; |
591 | ||
592 | class PrePostResolveNode : public ExpressionNode, public ThrowableExpressionData { | |
593 | public: | |
ba379fdc | 594 | PrePostResolveNode(JSGlobalData*, const Identifier&, unsigned divot, unsigned startOffset, unsigned endOffset); |
9dae56ea A |
595 | |
596 | protected: | |
f9bf01c6 | 597 | const Identifier& m_ident; |
9dae56ea A |
598 | }; |
599 | ||
600 | class PostfixResolveNode : public PrePostResolveNode { | |
601 | public: | |
ba379fdc | 602 | PostfixResolveNode(JSGlobalData*, const Identifier&, Operator, unsigned divot, unsigned startOffset, unsigned endOffset); |
9dae56ea A |
603 | |
604 | private: | |
ba379fdc A |
605 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
606 | ||
9dae56ea A |
607 | Operator m_operator; |
608 | }; | |
609 | ||
610 | class PostfixBracketNode : public ExpressionNode, public ThrowableSubExpressionData { | |
611 | public: | |
ba379fdc | 612 | PostfixBracketNode(JSGlobalData*, ExpressionNode* base, ExpressionNode* subscript, Operator, unsigned divot, unsigned startOffset, unsigned endOffset); |
9dae56ea A |
613 | |
614 | private: | |
ba379fdc A |
615 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
616 | ||
617 | ExpressionNode* m_base; | |
618 | ExpressionNode* m_subscript; | |
9dae56ea A |
619 | Operator m_operator; |
620 | }; | |
621 | ||
622 | class PostfixDotNode : public ExpressionNode, public ThrowableSubExpressionData { | |
623 | public: | |
ba379fdc | 624 | PostfixDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, Operator, unsigned divot, unsigned startOffset, unsigned endOffset); |
9dae56ea A |
625 | |
626 | private: | |
ba379fdc A |
627 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
628 | ||
629 | ExpressionNode* m_base; | |
f9bf01c6 | 630 | const Identifier& m_ident; |
9dae56ea A |
631 | Operator m_operator; |
632 | }; | |
633 | ||
634 | class PostfixErrorNode : public ExpressionNode, public ThrowableSubExpressionData { | |
635 | public: | |
ba379fdc | 636 | PostfixErrorNode(JSGlobalData*, ExpressionNode*, Operator, unsigned divot, unsigned startOffset, unsigned endOffset); |
9dae56ea A |
637 | |
638 | private: | |
ba379fdc A |
639 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
640 | ||
641 | ExpressionNode* m_expr; | |
9dae56ea A |
642 | Operator m_operator; |
643 | }; | |
644 | ||
645 | class DeleteResolveNode : public ExpressionNode, public ThrowableExpressionData { | |
646 | public: | |
ba379fdc | 647 | DeleteResolveNode(JSGlobalData*, const Identifier&, unsigned divot, unsigned startOffset, unsigned endOffset); |
9dae56ea A |
648 | |
649 | private: | |
ba379fdc A |
650 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
651 | ||
f9bf01c6 | 652 | const Identifier& m_ident; |
9dae56ea A |
653 | }; |
654 | ||
655 | class DeleteBracketNode : public ExpressionNode, public ThrowableExpressionData { | |
656 | public: | |
ba379fdc | 657 | DeleteBracketNode(JSGlobalData*, ExpressionNode* base, ExpressionNode* subscript, unsigned divot, unsigned startOffset, unsigned endOffset); |
9dae56ea A |
658 | |
659 | private: | |
ba379fdc A |
660 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
661 | ||
662 | ExpressionNode* m_base; | |
663 | ExpressionNode* m_subscript; | |
9dae56ea A |
664 | }; |
665 | ||
666 | class DeleteDotNode : public ExpressionNode, public ThrowableExpressionData { | |
667 | public: | |
ba379fdc | 668 | DeleteDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, unsigned divot, unsigned startOffset, unsigned endOffset); |
9dae56ea A |
669 | |
670 | private: | |
ba379fdc A |
671 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
672 | ||
673 | ExpressionNode* m_base; | |
f9bf01c6 | 674 | const Identifier& m_ident; |
9dae56ea A |
675 | }; |
676 | ||
677 | class DeleteValueNode : public ExpressionNode { | |
678 | public: | |
ba379fdc | 679 | DeleteValueNode(JSGlobalData*, ExpressionNode*); |
9dae56ea A |
680 | |
681 | private: | |
ba379fdc A |
682 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
683 | ||
684 | ExpressionNode* m_expr; | |
9dae56ea A |
685 | }; |
686 | ||
687 | class VoidNode : public ExpressionNode { | |
688 | public: | |
ba379fdc | 689 | VoidNode(JSGlobalData*, ExpressionNode*); |
9dae56ea A |
690 | |
691 | private: | |
ba379fdc A |
692 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
693 | ||
694 | ExpressionNode* m_expr; | |
9dae56ea A |
695 | }; |
696 | ||
697 | class TypeOfResolveNode : public ExpressionNode { | |
698 | public: | |
ba379fdc | 699 | TypeOfResolveNode(JSGlobalData*, const Identifier&); |
9dae56ea | 700 | |
ba379fdc | 701 | const Identifier& identifier() const { return m_ident; } |
9dae56ea A |
702 | |
703 | private: | |
ba379fdc A |
704 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
705 | ||
f9bf01c6 | 706 | const Identifier& m_ident; |
9dae56ea A |
707 | }; |
708 | ||
709 | class TypeOfValueNode : public ExpressionNode { | |
710 | public: | |
ba379fdc | 711 | TypeOfValueNode(JSGlobalData*, ExpressionNode*); |
9dae56ea A |
712 | |
713 | private: | |
ba379fdc A |
714 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
715 | ||
716 | ExpressionNode* m_expr; | |
9dae56ea A |
717 | }; |
718 | ||
719 | class PrefixResolveNode : public PrePostResolveNode { | |
720 | public: | |
ba379fdc | 721 | PrefixResolveNode(JSGlobalData*, const Identifier&, Operator, unsigned divot, unsigned startOffset, unsigned endOffset); |
9dae56ea A |
722 | |
723 | private: | |
ba379fdc A |
724 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
725 | ||
9dae56ea A |
726 | Operator m_operator; |
727 | }; | |
728 | ||
729 | class PrefixBracketNode : public ExpressionNode, public ThrowablePrefixedSubExpressionData { | |
730 | public: | |
ba379fdc | 731 | PrefixBracketNode(JSGlobalData*, ExpressionNode* base, ExpressionNode* subscript, Operator, unsigned divot, unsigned startOffset, unsigned endOffset); |
9dae56ea A |
732 | |
733 | private: | |
ba379fdc A |
734 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
735 | ||
736 | ExpressionNode* m_base; | |
737 | ExpressionNode* m_subscript; | |
9dae56ea A |
738 | Operator m_operator; |
739 | }; | |
740 | ||
741 | class PrefixDotNode : public ExpressionNode, public ThrowablePrefixedSubExpressionData { | |
742 | public: | |
ba379fdc | 743 | PrefixDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, Operator, unsigned divot, unsigned startOffset, unsigned endOffset); |
9dae56ea A |
744 | |
745 | private: | |
ba379fdc A |
746 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
747 | ||
748 | ExpressionNode* m_base; | |
f9bf01c6 | 749 | const Identifier& m_ident; |
9dae56ea A |
750 | Operator m_operator; |
751 | }; | |
752 | ||
753 | class PrefixErrorNode : public ExpressionNode, public ThrowableExpressionData { | |
754 | public: | |
ba379fdc | 755 | PrefixErrorNode(JSGlobalData*, ExpressionNode*, Operator, unsigned divot, unsigned startOffset, unsigned endOffset); |
9dae56ea A |
756 | |
757 | private: | |
ba379fdc A |
758 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
759 | ||
760 | ExpressionNode* m_expr; | |
9dae56ea A |
761 | Operator m_operator; |
762 | }; | |
763 | ||
764 | class UnaryOpNode : public ExpressionNode { | |
765 | public: | |
ba379fdc | 766 | UnaryOpNode(JSGlobalData*, ResultType, ExpressionNode*, OpcodeID); |
9dae56ea | 767 | |
ba379fdc A |
768 | protected: |
769 | ExpressionNode* expr() { return m_expr; } | |
f9bf01c6 | 770 | const ExpressionNode* expr() const { return m_expr; } |
9dae56ea | 771 | |
ba379fdc A |
772 | private: |
773 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); | |
9dae56ea | 774 | |
ba379fdc | 775 | OpcodeID opcodeID() const { return m_opcodeID; } |
9dae56ea | 776 | |
ba379fdc A |
777 | ExpressionNode* m_expr; |
778 | OpcodeID m_opcodeID; | |
9dae56ea A |
779 | }; |
780 | ||
781 | class UnaryPlusNode : public UnaryOpNode { | |
782 | public: | |
ba379fdc | 783 | UnaryPlusNode(JSGlobalData*, ExpressionNode*); |
9dae56ea | 784 | |
ba379fdc A |
785 | private: |
786 | virtual ExpressionNode* stripUnaryPlus() { return expr(); } | |
9dae56ea A |
787 | }; |
788 | ||
789 | class NegateNode : public UnaryOpNode { | |
790 | public: | |
ba379fdc | 791 | NegateNode(JSGlobalData*, ExpressionNode*); |
9dae56ea A |
792 | }; |
793 | ||
794 | class BitwiseNotNode : public UnaryOpNode { | |
795 | public: | |
ba379fdc | 796 | BitwiseNotNode(JSGlobalData*, ExpressionNode*); |
9dae56ea A |
797 | }; |
798 | ||
799 | class LogicalNotNode : public UnaryOpNode { | |
800 | public: | |
ba379fdc | 801 | LogicalNotNode(JSGlobalData*, ExpressionNode*); |
f9bf01c6 A |
802 | private: |
803 | void emitBytecodeInConditionContext(BytecodeGenerator&, Label* trueTarget, Label* falseTarget, bool fallThroughMeansTrue); | |
804 | virtual bool hasConditionContextCodegen() const { return expr()->hasConditionContextCodegen(); } | |
9dae56ea A |
805 | }; |
806 | ||
807 | class BinaryOpNode : public ExpressionNode { | |
808 | public: | |
ba379fdc A |
809 | BinaryOpNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments); |
810 | BinaryOpNode(JSGlobalData*, ResultType, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments); | |
9dae56ea | 811 | |
f9bf01c6 | 812 | RegisterID* emitStrcat(BytecodeGenerator& generator, RegisterID* destination, RegisterID* lhs = 0, ReadModifyResolveNode* emitExpressionInfoForMe = 0); |
9dae56ea | 813 | |
14957cd0 A |
814 | ExpressionNode* lhs() { return m_expr1; }; |
815 | ExpressionNode* rhs() { return m_expr2; }; | |
816 | ||
ba379fdc A |
817 | private: |
818 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); | |
9dae56ea | 819 | |
ba379fdc A |
820 | protected: |
821 | OpcodeID opcodeID() const { return m_opcodeID; } | |
9dae56ea A |
822 | |
823 | protected: | |
ba379fdc A |
824 | ExpressionNode* m_expr1; |
825 | ExpressionNode* m_expr2; | |
826 | private: | |
827 | OpcodeID m_opcodeID; | |
828 | protected: | |
9dae56ea A |
829 | bool m_rightHasAssignments; |
830 | }; | |
831 | ||
832 | class ReverseBinaryOpNode : public BinaryOpNode { | |
833 | public: | |
ba379fdc A |
834 | ReverseBinaryOpNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments); |
835 | ReverseBinaryOpNode(JSGlobalData*, ResultType, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments); | |
9dae56ea | 836 | |
ba379fdc | 837 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
9dae56ea A |
838 | }; |
839 | ||
840 | class MultNode : public BinaryOpNode { | |
841 | public: | |
ba379fdc | 842 | MultNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
843 | }; |
844 | ||
845 | class DivNode : public BinaryOpNode { | |
846 | public: | |
ba379fdc | 847 | DivNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
848 | }; |
849 | ||
850 | class ModNode : public BinaryOpNode { | |
851 | public: | |
ba379fdc | 852 | ModNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
853 | }; |
854 | ||
855 | class AddNode : public BinaryOpNode { | |
856 | public: | |
ba379fdc | 857 | AddNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea | 858 | |
ba379fdc | 859 | virtual bool isAdd() const { return true; } |
9dae56ea A |
860 | }; |
861 | ||
862 | class SubNode : public BinaryOpNode { | |
863 | public: | |
ba379fdc | 864 | SubNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
14957cd0 A |
865 | |
866 | virtual bool isSubtract() const { return true; } | |
9dae56ea A |
867 | }; |
868 | ||
869 | class LeftShiftNode : public BinaryOpNode { | |
870 | public: | |
ba379fdc | 871 | LeftShiftNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
872 | }; |
873 | ||
874 | class RightShiftNode : public BinaryOpNode { | |
875 | public: | |
ba379fdc | 876 | RightShiftNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
877 | }; |
878 | ||
879 | class UnsignedRightShiftNode : public BinaryOpNode { | |
880 | public: | |
ba379fdc | 881 | UnsignedRightShiftNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
882 | }; |
883 | ||
884 | class LessNode : public BinaryOpNode { | |
885 | public: | |
ba379fdc | 886 | LessNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
887 | }; |
888 | ||
889 | class GreaterNode : public ReverseBinaryOpNode { | |
890 | public: | |
ba379fdc | 891 | GreaterNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
892 | }; |
893 | ||
894 | class LessEqNode : public BinaryOpNode { | |
895 | public: | |
ba379fdc | 896 | LessEqNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
897 | }; |
898 | ||
899 | class GreaterEqNode : public ReverseBinaryOpNode { | |
900 | public: | |
ba379fdc | 901 | GreaterEqNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
902 | }; |
903 | ||
904 | class ThrowableBinaryOpNode : public BinaryOpNode, public ThrowableExpressionData { | |
905 | public: | |
ba379fdc A |
906 | ThrowableBinaryOpNode(JSGlobalData*, ResultType, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments); |
907 | ThrowableBinaryOpNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments); | |
908 | ||
909 | private: | |
910 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); | |
9dae56ea A |
911 | }; |
912 | ||
913 | class InstanceOfNode : public ThrowableBinaryOpNode { | |
914 | public: | |
ba379fdc | 915 | InstanceOfNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea | 916 | |
ba379fdc A |
917 | private: |
918 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); | |
9dae56ea A |
919 | }; |
920 | ||
921 | class InNode : public ThrowableBinaryOpNode { | |
922 | public: | |
ba379fdc | 923 | InNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
924 | }; |
925 | ||
926 | class EqualNode : public BinaryOpNode { | |
927 | public: | |
ba379fdc | 928 | EqualNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea | 929 | |
ba379fdc A |
930 | private: |
931 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); | |
9dae56ea A |
932 | }; |
933 | ||
934 | class NotEqualNode : public BinaryOpNode { | |
935 | public: | |
ba379fdc | 936 | NotEqualNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
937 | }; |
938 | ||
939 | class StrictEqualNode : public BinaryOpNode { | |
940 | public: | |
ba379fdc | 941 | StrictEqualNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea | 942 | |
ba379fdc A |
943 | private: |
944 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); | |
9dae56ea A |
945 | }; |
946 | ||
947 | class NotStrictEqualNode : public BinaryOpNode { | |
948 | public: | |
ba379fdc | 949 | NotStrictEqualNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
950 | }; |
951 | ||
952 | class BitAndNode : public BinaryOpNode { | |
953 | public: | |
ba379fdc | 954 | BitAndNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
955 | }; |
956 | ||
957 | class BitOrNode : public BinaryOpNode { | |
958 | public: | |
ba379fdc | 959 | BitOrNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
960 | }; |
961 | ||
962 | class BitXOrNode : public BinaryOpNode { | |
963 | public: | |
ba379fdc | 964 | BitXOrNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
965 | }; |
966 | ||
ba379fdc | 967 | // m_expr1 && m_expr2, m_expr1 || m_expr2 |
9dae56ea A |
968 | class LogicalOpNode : public ExpressionNode { |
969 | public: | |
ba379fdc | 970 | LogicalOpNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, LogicalOperator); |
9dae56ea A |
971 | |
972 | private: | |
ba379fdc | 973 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
f9bf01c6 A |
974 | void emitBytecodeInConditionContext(BytecodeGenerator&, Label* trueTarget, Label* falseTarget, bool fallThroughMeansTrue); |
975 | virtual bool hasConditionContextCodegen() const { return true; } | |
ba379fdc A |
976 | |
977 | ExpressionNode* m_expr1; | |
978 | ExpressionNode* m_expr2; | |
9dae56ea A |
979 | LogicalOperator m_operator; |
980 | }; | |
981 | ||
ba379fdc | 982 | // The ternary operator, "m_logical ? m_expr1 : m_expr2" |
9dae56ea A |
983 | class ConditionalNode : public ExpressionNode { |
984 | public: | |
ba379fdc | 985 | ConditionalNode(JSGlobalData*, ExpressionNode* logical, ExpressionNode* expr1, ExpressionNode* expr2); |
9dae56ea A |
986 | |
987 | private: | |
ba379fdc A |
988 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
989 | ||
990 | ExpressionNode* m_logical; | |
991 | ExpressionNode* m_expr1; | |
992 | ExpressionNode* m_expr2; | |
9dae56ea A |
993 | }; |
994 | ||
995 | class ReadModifyResolveNode : public ExpressionNode, public ThrowableExpressionData { | |
996 | public: | |
ba379fdc | 997 | ReadModifyResolveNode(JSGlobalData*, const Identifier&, Operator, ExpressionNode* right, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset); |
9dae56ea A |
998 | |
999 | private: | |
ba379fdc A |
1000 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
1001 | ||
f9bf01c6 | 1002 | const Identifier& m_ident; |
ba379fdc | 1003 | ExpressionNode* m_right; |
9dae56ea | 1004 | size_t m_index; // Used by ReadModifyLocalVarNode. |
ba379fdc A |
1005 | Operator m_operator; |
1006 | bool m_rightHasAssignments; | |
9dae56ea A |
1007 | }; |
1008 | ||
1009 | class AssignResolveNode : public ExpressionNode, public ThrowableExpressionData { | |
1010 | public: | |
ba379fdc | 1011 | AssignResolveNode(JSGlobalData*, const Identifier&, ExpressionNode* right, bool rightHasAssignments); |
9dae56ea A |
1012 | |
1013 | private: | |
ba379fdc A |
1014 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
1015 | ||
f9bf01c6 | 1016 | const Identifier& m_ident; |
ba379fdc | 1017 | ExpressionNode* m_right; |
9dae56ea A |
1018 | size_t m_index; // Used by ReadModifyLocalVarNode. |
1019 | bool m_rightHasAssignments; | |
1020 | }; | |
1021 | ||
1022 | class ReadModifyBracketNode : public ExpressionNode, public ThrowableSubExpressionData { | |
1023 | public: | |
ba379fdc | 1024 | ReadModifyBracketNode(JSGlobalData*, ExpressionNode* base, ExpressionNode* subscript, Operator, ExpressionNode* right, bool subscriptHasAssignments, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset); |
9dae56ea A |
1025 | |
1026 | private: | |
ba379fdc A |
1027 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
1028 | ||
1029 | ExpressionNode* m_base; | |
1030 | ExpressionNode* m_subscript; | |
1031 | ExpressionNode* m_right; | |
9dae56ea A |
1032 | Operator m_operator : 30; |
1033 | bool m_subscriptHasAssignments : 1; | |
1034 | bool m_rightHasAssignments : 1; | |
1035 | }; | |
1036 | ||
1037 | class AssignBracketNode : public ExpressionNode, public ThrowableExpressionData { | |
1038 | public: | |
ba379fdc | 1039 | AssignBracketNode(JSGlobalData*, ExpressionNode* base, ExpressionNode* subscript, ExpressionNode* right, bool subscriptHasAssignments, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset); |
9dae56ea A |
1040 | |
1041 | private: | |
ba379fdc A |
1042 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
1043 | ||
1044 | ExpressionNode* m_base; | |
1045 | ExpressionNode* m_subscript; | |
1046 | ExpressionNode* m_right; | |
9dae56ea A |
1047 | bool m_subscriptHasAssignments : 1; |
1048 | bool m_rightHasAssignments : 1; | |
1049 | }; | |
1050 | ||
1051 | class AssignDotNode : public ExpressionNode, public ThrowableExpressionData { | |
1052 | public: | |
ba379fdc | 1053 | AssignDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, ExpressionNode* right, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset); |
9dae56ea A |
1054 | |
1055 | private: | |
ba379fdc A |
1056 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
1057 | ||
1058 | ExpressionNode* m_base; | |
f9bf01c6 | 1059 | const Identifier& m_ident; |
ba379fdc | 1060 | ExpressionNode* m_right; |
9dae56ea A |
1061 | bool m_rightHasAssignments; |
1062 | }; | |
1063 | ||
1064 | class ReadModifyDotNode : public ExpressionNode, public ThrowableSubExpressionData { | |
1065 | public: | |
ba379fdc | 1066 | ReadModifyDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, Operator, ExpressionNode* right, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset); |
9dae56ea A |
1067 | |
1068 | private: | |
ba379fdc A |
1069 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
1070 | ||
1071 | ExpressionNode* m_base; | |
f9bf01c6 | 1072 | const Identifier& m_ident; |
ba379fdc | 1073 | ExpressionNode* m_right; |
9dae56ea A |
1074 | Operator m_operator : 31; |
1075 | bool m_rightHasAssignments : 1; | |
1076 | }; | |
1077 | ||
1078 | class AssignErrorNode : public ExpressionNode, public ThrowableExpressionData { | |
1079 | public: | |
ba379fdc | 1080 | AssignErrorNode(JSGlobalData*, ExpressionNode* left, Operator, ExpressionNode* right, unsigned divot, unsigned startOffset, unsigned endOffset); |
9dae56ea A |
1081 | |
1082 | private: | |
ba379fdc A |
1083 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
1084 | ||
1085 | ExpressionNode* m_left; | |
9dae56ea | 1086 | Operator m_operator; |
ba379fdc | 1087 | ExpressionNode* m_right; |
9dae56ea | 1088 | }; |
ba379fdc A |
1089 | |
1090 | typedef Vector<ExpressionNode*, 8> ExpressionVector; | |
9dae56ea | 1091 | |
f9bf01c6 | 1092 | class CommaNode : public ExpressionNode, public ParserArenaDeletable { |
9dae56ea | 1093 | public: |
ba379fdc | 1094 | CommaNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2); |
9dae56ea | 1095 | |
f9bf01c6 A |
1096 | using ParserArenaDeletable::operator new; |
1097 | ||
ba379fdc | 1098 | void append(ExpressionNode* expr) { m_expressions.append(expr); } |
9dae56ea A |
1099 | |
1100 | private: | |
ba379fdc A |
1101 | virtual bool isCommaNode() const { return true; } |
1102 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); | |
1103 | ||
1104 | ExpressionVector m_expressions; | |
9dae56ea A |
1105 | }; |
1106 | ||
9dae56ea A |
1107 | class ConstDeclNode : public ExpressionNode { |
1108 | public: | |
ba379fdc A |
1109 | ConstDeclNode(JSGlobalData*, const Identifier&, ExpressionNode*); |
1110 | ||
1111 | bool hasInitializer() const { return m_init; } | |
1112 | const Identifier& ident() { return m_ident; } | |
9dae56ea | 1113 | |
ba379fdc A |
1114 | private: |
1115 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); | |
1116 | virtual RegisterID* emitCodeSingle(BytecodeGenerator&); | |
9dae56ea | 1117 | |
f9bf01c6 | 1118 | const Identifier& m_ident; |
9dae56ea | 1119 | |
9dae56ea | 1120 | public: |
ba379fdc | 1121 | ConstDeclNode* m_next; |
9dae56ea | 1122 | |
ba379fdc A |
1123 | private: |
1124 | ExpressionNode* m_init; | |
1125 | }; | |
9dae56ea | 1126 | |
ba379fdc A |
1127 | class ConstStatementNode : public StatementNode { |
1128 | public: | |
1129 | ConstStatementNode(JSGlobalData*, ConstDeclNode* next); | |
9dae56ea A |
1130 | |
1131 | private: | |
ba379fdc A |
1132 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
1133 | ||
1134 | ConstDeclNode* m_next; | |
9dae56ea A |
1135 | }; |
1136 | ||
ba379fdc | 1137 | class SourceElements : public ParserArenaDeletable { |
9dae56ea | 1138 | public: |
ba379fdc | 1139 | SourceElements(JSGlobalData*); |
9dae56ea | 1140 | |
ba379fdc | 1141 | void append(StatementNode*); |
f9bf01c6 A |
1142 | |
1143 | StatementNode* singleStatement() const; | |
1144 | StatementNode* lastStatement() const; | |
1145 | ||
1146 | void emitBytecode(BytecodeGenerator&, RegisterID* destination); | |
9dae56ea A |
1147 | |
1148 | private: | |
f9bf01c6 | 1149 | Vector<StatementNode*> m_statements; |
9dae56ea A |
1150 | }; |
1151 | ||
1152 | class BlockNode : public StatementNode { | |
1153 | public: | |
f9bf01c6 | 1154 | BlockNode(JSGlobalData*, SourceElements* = 0); |
9dae56ea | 1155 | |
14957cd0 | 1156 | StatementNode* singleStatement() const; |
f9bf01c6 | 1157 | StatementNode* lastStatement() const; |
9dae56ea | 1158 | |
9dae56ea | 1159 | private: |
ba379fdc A |
1160 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
1161 | ||
1162 | virtual bool isBlock() const { return true; } | |
1163 | ||
f9bf01c6 | 1164 | SourceElements* m_statements; |
9dae56ea A |
1165 | }; |
1166 | ||
1167 | class EmptyStatementNode : public StatementNode { | |
1168 | public: | |
ba379fdc | 1169 | EmptyStatementNode(JSGlobalData*); |
9dae56ea | 1170 | |
ba379fdc A |
1171 | private: |
1172 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); | |
9dae56ea | 1173 | |
ba379fdc | 1174 | virtual bool isEmptyStatement() const { return true; } |
9dae56ea A |
1175 | }; |
1176 | ||
1177 | class DebuggerStatementNode : public StatementNode { | |
1178 | public: | |
ba379fdc | 1179 | DebuggerStatementNode(JSGlobalData*); |
9dae56ea | 1180 | |
ba379fdc A |
1181 | private: |
1182 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); | |
9dae56ea A |
1183 | }; |
1184 | ||
1185 | class ExprStatementNode : public StatementNode { | |
1186 | public: | |
ba379fdc | 1187 | ExprStatementNode(JSGlobalData*, ExpressionNode*); |
9dae56ea | 1188 | |
ba379fdc | 1189 | ExpressionNode* expr() const { return m_expr; } |
9dae56ea | 1190 | |
ba379fdc A |
1191 | private: |
1192 | virtual bool isExprStatement() const { return true; } | |
9dae56ea | 1193 | |
ba379fdc | 1194 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
9dae56ea | 1195 | |
ba379fdc | 1196 | ExpressionNode* m_expr; |
9dae56ea A |
1197 | }; |
1198 | ||
1199 | class VarStatementNode : public StatementNode { | |
1200 | public: | |
ba379fdc | 1201 | VarStatementNode(JSGlobalData*, ExpressionNode*); |
9dae56ea A |
1202 | |
1203 | private: | |
ba379fdc A |
1204 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
1205 | ||
1206 | ExpressionNode* m_expr; | |
9dae56ea A |
1207 | }; |
1208 | ||
1209 | class IfNode : public StatementNode { | |
1210 | public: | |
ba379fdc | 1211 | IfNode(JSGlobalData*, ExpressionNode* condition, StatementNode* ifBlock); |
9dae56ea A |
1212 | |
1213 | protected: | |
ba379fdc A |
1214 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
1215 | ||
1216 | ExpressionNode* m_condition; | |
1217 | StatementNode* m_ifBlock; | |
9dae56ea A |
1218 | }; |
1219 | ||
1220 | class IfElseNode : public IfNode { | |
1221 | public: | |
ba379fdc | 1222 | IfElseNode(JSGlobalData*, ExpressionNode* condition, StatementNode* ifBlock, StatementNode* elseBlock); |
9dae56ea A |
1223 | |
1224 | private: | |
ba379fdc A |
1225 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
1226 | ||
1227 | StatementNode* m_elseBlock; | |
9dae56ea A |
1228 | }; |
1229 | ||
1230 | class DoWhileNode : public StatementNode { | |
1231 | public: | |
ba379fdc | 1232 | DoWhileNode(JSGlobalData*, StatementNode* statement, ExpressionNode*); |
9dae56ea A |
1233 | |
1234 | private: | |
ba379fdc A |
1235 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
1236 | ||
1237 | StatementNode* m_statement; | |
1238 | ExpressionNode* m_expr; | |
9dae56ea A |
1239 | }; |
1240 | ||
1241 | class WhileNode : public StatementNode { | |
1242 | public: | |
ba379fdc | 1243 | WhileNode(JSGlobalData*, ExpressionNode*, StatementNode* statement); |
9dae56ea A |
1244 | |
1245 | private: | |
ba379fdc A |
1246 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
1247 | ||
1248 | ExpressionNode* m_expr; | |
1249 | StatementNode* m_statement; | |
9dae56ea A |
1250 | }; |
1251 | ||
1252 | class ForNode : public StatementNode { | |
1253 | public: | |
ba379fdc | 1254 | ForNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, ExpressionNode* expr3, StatementNode* statement, bool expr1WasVarDecl); |
9dae56ea A |
1255 | |
1256 | private: | |
ba379fdc A |
1257 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
1258 | ||
1259 | ExpressionNode* m_expr1; | |
1260 | ExpressionNode* m_expr2; | |
1261 | ExpressionNode* m_expr3; | |
1262 | StatementNode* m_statement; | |
9dae56ea A |
1263 | bool m_expr1WasVarDecl; |
1264 | }; | |
1265 | ||
1266 | class ForInNode : public StatementNode, public ThrowableExpressionData { | |
1267 | public: | |
ba379fdc A |
1268 | ForInNode(JSGlobalData*, ExpressionNode*, ExpressionNode*, StatementNode*); |
1269 | ForInNode(JSGlobalData*, const Identifier&, ExpressionNode*, ExpressionNode*, StatementNode*, int divot, int startOffset, int endOffset); | |
9dae56ea A |
1270 | |
1271 | private: | |
ba379fdc A |
1272 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
1273 | ||
f9bf01c6 | 1274 | const Identifier& m_ident; |
ba379fdc A |
1275 | ExpressionNode* m_init; |
1276 | ExpressionNode* m_lexpr; | |
1277 | ExpressionNode* m_expr; | |
1278 | StatementNode* m_statement; | |
9dae56ea A |
1279 | bool m_identIsVarDecl; |
1280 | }; | |
1281 | ||
1282 | class ContinueNode : public StatementNode, public ThrowableExpressionData { | |
1283 | public: | |
ba379fdc A |
1284 | ContinueNode(JSGlobalData*); |
1285 | ContinueNode(JSGlobalData*, const Identifier&); | |
9dae56ea | 1286 | |
9dae56ea | 1287 | private: |
ba379fdc A |
1288 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
1289 | ||
f9bf01c6 | 1290 | const Identifier& m_ident; |
9dae56ea A |
1291 | }; |
1292 | ||
1293 | class BreakNode : public StatementNode, public ThrowableExpressionData { | |
1294 | public: | |
ba379fdc A |
1295 | BreakNode(JSGlobalData*); |
1296 | BreakNode(JSGlobalData*, const Identifier&); | |
9dae56ea | 1297 | |
9dae56ea | 1298 | private: |
ba379fdc A |
1299 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
1300 | ||
f9bf01c6 | 1301 | const Identifier& m_ident; |
9dae56ea A |
1302 | }; |
1303 | ||
1304 | class ReturnNode : public StatementNode, public ThrowableExpressionData { | |
1305 | public: | |
ba379fdc | 1306 | ReturnNode(JSGlobalData*, ExpressionNode* value); |
9dae56ea | 1307 | |
14957cd0 A |
1308 | ExpressionNode* value() { return m_value; } |
1309 | ||
ba379fdc A |
1310 | private: |
1311 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); | |
9dae56ea | 1312 | |
ba379fdc | 1313 | virtual bool isReturnNode() const { return true; } |
9dae56ea | 1314 | |
ba379fdc | 1315 | ExpressionNode* m_value; |
9dae56ea A |
1316 | }; |
1317 | ||
1318 | class WithNode : public StatementNode { | |
1319 | public: | |
ba379fdc | 1320 | WithNode(JSGlobalData*, ExpressionNode*, StatementNode*, uint32_t divot, uint32_t expressionLength); |
9dae56ea A |
1321 | |
1322 | private: | |
ba379fdc A |
1323 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
1324 | ||
1325 | ExpressionNode* m_expr; | |
1326 | StatementNode* m_statement; | |
9dae56ea A |
1327 | uint32_t m_divot; |
1328 | uint32_t m_expressionLength; | |
1329 | }; | |
1330 | ||
1331 | class LabelNode : public StatementNode, public ThrowableExpressionData { | |
1332 | public: | |
ba379fdc | 1333 | LabelNode(JSGlobalData*, const Identifier& name, StatementNode*); |
9dae56ea A |
1334 | |
1335 | private: | |
ba379fdc A |
1336 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
1337 | ||
f9bf01c6 | 1338 | const Identifier& m_name; |
ba379fdc | 1339 | StatementNode* m_statement; |
9dae56ea A |
1340 | }; |
1341 | ||
1342 | class ThrowNode : public StatementNode, public ThrowableExpressionData { | |
1343 | public: | |
ba379fdc | 1344 | ThrowNode(JSGlobalData*, ExpressionNode*); |
9dae56ea A |
1345 | |
1346 | private: | |
ba379fdc A |
1347 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
1348 | ||
1349 | ExpressionNode* m_expr; | |
9dae56ea A |
1350 | }; |
1351 | ||
1352 | class TryNode : public StatementNode { | |
1353 | public: | |
ba379fdc | 1354 | TryNode(JSGlobalData*, StatementNode* tryBlock, const Identifier& exceptionIdent, bool catchHasEval, StatementNode* catchBlock, StatementNode* finallyBlock); |
9dae56ea A |
1355 | |
1356 | private: | |
f9bf01c6 | 1357 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
ba379fdc A |
1358 | |
1359 | StatementNode* m_tryBlock; | |
f9bf01c6 | 1360 | const Identifier& m_exceptionIdent; |
ba379fdc A |
1361 | StatementNode* m_catchBlock; |
1362 | StatementNode* m_finallyBlock; | |
9dae56ea A |
1363 | bool m_catchHasEval; |
1364 | }; | |
1365 | ||
f9bf01c6 | 1366 | class ParameterNode : public ParserArenaFreeable { |
9dae56ea | 1367 | public: |
ba379fdc A |
1368 | ParameterNode(JSGlobalData*, const Identifier&); |
1369 | ParameterNode(JSGlobalData*, ParameterNode*, const Identifier&); | |
9dae56ea | 1370 | |
ba379fdc A |
1371 | const Identifier& ident() const { return m_ident; } |
1372 | ParameterNode* nextParam() const { return m_next; } | |
9dae56ea A |
1373 | |
1374 | private: | |
f9bf01c6 | 1375 | const Identifier& m_ident; |
ba379fdc | 1376 | ParameterNode* m_next; |
9dae56ea A |
1377 | }; |
1378 | ||
14957cd0 A |
1379 | struct ScopeNodeData { |
1380 | WTF_MAKE_FAST_ALLOCATED; | |
1381 | public: | |
9dae56ea A |
1382 | typedef DeclarationStacks::VarStack VarStack; |
1383 | typedef DeclarationStacks::FunctionStack FunctionStack; | |
1384 | ||
14957cd0 | 1385 | ScopeNodeData(ParserArena&, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, int numConstants); |
9dae56ea | 1386 | |
ba379fdc | 1387 | ParserArena m_arena; |
9dae56ea A |
1388 | VarStack m_varStack; |
1389 | FunctionStack m_functionStack; | |
1390 | int m_numConstants; | |
f9bf01c6 | 1391 | SourceElements* m_statements; |
14957cd0 | 1392 | IdentifierSet m_capturedVariables; |
9dae56ea A |
1393 | }; |
1394 | ||
ba379fdc | 1395 | class ScopeNode : public StatementNode, public ParserArenaRefCounted { |
9dae56ea A |
1396 | public: |
1397 | typedef DeclarationStacks::VarStack VarStack; | |
1398 | typedef DeclarationStacks::FunctionStack FunctionStack; | |
1399 | ||
14957cd0 A |
1400 | ScopeNode(JSGlobalData*, bool inStrictContext); |
1401 | ScopeNode(JSGlobalData*, const SourceCode&, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, CodeFeatures, int numConstants); | |
9dae56ea | 1402 | |
f9bf01c6 A |
1403 | using ParserArenaRefCounted::operator new; |
1404 | ||
9dae56ea A |
1405 | ScopeNodeData* data() const { return m_data.get(); } |
1406 | void destroyData() { m_data.clear(); } | |
1407 | ||
1408 | const SourceCode& source() const { return m_source; } | |
ba379fdc | 1409 | const UString& sourceURL() const { return m_source.provider()->url(); } |
9dae56ea A |
1410 | intptr_t sourceID() const { return m_source.provider()->asID(); } |
1411 | ||
1412 | void setFeatures(CodeFeatures features) { m_features = features; } | |
1413 | CodeFeatures features() { return m_features; } | |
1414 | ||
1415 | bool usesEval() const { return m_features & EvalFeature; } | |
14957cd0 A |
1416 | bool usesArguments() const { return (m_features & ArgumentsFeature) && !(m_features & ShadowsArgumentsFeature); } |
1417 | bool isStrictMode() const { return m_features & StrictModeFeature; } | |
9dae56ea A |
1418 | void setUsesArguments() { m_features |= ArgumentsFeature; } |
1419 | bool usesThis() const { return m_features & ThisFeature; } | |
14957cd0 A |
1420 | bool needsActivationForMoreThanVariables() const { ASSERT(m_data); return m_features & (EvalFeature | WithFeature | CatchFeature); } |
1421 | bool needsActivation() const { ASSERT(m_data); return (hasCapturedVariables()) || (m_features & (EvalFeature | WithFeature | CatchFeature)); } | |
1422 | bool hasCapturedVariables() const { return !!m_data->m_capturedVariables.size(); } | |
1423 | size_t capturedVariableCount() const { return m_data->m_capturedVariables.size(); } | |
1424 | bool captures(const Identifier& ident) { return m_data->m_capturedVariables.contains(ident.impl()); } | |
9dae56ea A |
1425 | |
1426 | VarStack& varStack() { ASSERT(m_data); return m_data->m_varStack; } | |
1427 | FunctionStack& functionStack() { ASSERT(m_data); return m_data->m_functionStack; } | |
1428 | ||
9dae56ea A |
1429 | int neededConstants() |
1430 | { | |
1431 | ASSERT(m_data); | |
1432 | // We may need 2 more constants than the count given by the parser, | |
1433 | // because of the various uses of jsUndefined() and jsNull(). | |
1434 | return m_data->m_numConstants + 2; | |
1435 | } | |
1436 | ||
f9bf01c6 | 1437 | StatementNode* singleStatement() const; |
9dae56ea | 1438 | |
f9bf01c6 | 1439 | void emitStatementsBytecode(BytecodeGenerator&, RegisterID* destination); |
ba379fdc | 1440 | |
9dae56ea A |
1441 | protected: |
1442 | void setSource(const SourceCode& source) { m_source = source; } | |
1443 | ||
1444 | private: | |
1445 | OwnPtr<ScopeNodeData> m_data; | |
1446 | CodeFeatures m_features; | |
1447 | SourceCode m_source; | |
1448 | }; | |
1449 | ||
1450 | class ProgramNode : public ScopeNode { | |
1451 | public: | |
14957cd0 A |
1452 | static const bool isFunctionNode = false; |
1453 | static PassRefPtr<ProgramNode> create(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants); | |
9dae56ea | 1454 | |
f9bf01c6 | 1455 | static const bool scopeIsFunction = false; |
ba379fdc | 1456 | |
9dae56ea | 1457 | private: |
14957cd0 | 1458 | ProgramNode(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants); |
ba379fdc | 1459 | |
ba379fdc | 1460 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
9dae56ea A |
1461 | }; |
1462 | ||
1463 | class EvalNode : public ScopeNode { | |
1464 | public: | |
14957cd0 A |
1465 | static const bool isFunctionNode = false; |
1466 | static PassRefPtr<EvalNode> create(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants); | |
9dae56ea | 1467 | |
f9bf01c6 | 1468 | static const bool scopeIsFunction = false; |
ba379fdc | 1469 | |
9dae56ea | 1470 | private: |
14957cd0 | 1471 | EvalNode(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants); |
9dae56ea | 1472 | |
ba379fdc | 1473 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
f9bf01c6 | 1474 | }; |
ba379fdc | 1475 | |
f9bf01c6 | 1476 | class FunctionParameters : public Vector<Identifier>, public RefCounted<FunctionParameters> { |
14957cd0 | 1477 | WTF_MAKE_FAST_ALLOCATED; |
f9bf01c6 A |
1478 | public: |
1479 | static PassRefPtr<FunctionParameters> create(ParameterNode* firstParameter) { return adoptRef(new FunctionParameters(firstParameter)); } | |
1480 | ||
1481 | private: | |
1482 | FunctionParameters(ParameterNode*); | |
9dae56ea A |
1483 | }; |
1484 | ||
1485 | class FunctionBodyNode : public ScopeNode { | |
9dae56ea | 1486 | public: |
14957cd0 A |
1487 | static const bool isFunctionNode = true; |
1488 | static FunctionBodyNode* create(JSGlobalData*, bool isStrictMode); | |
1489 | static PassRefPtr<FunctionBodyNode> create(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants); | |
9dae56ea | 1490 | |
f9bf01c6 A |
1491 | FunctionParameters* parameters() const { return m_parameters.get(); } |
1492 | size_t parameterCount() const { return m_parameters->size(); } | |
9dae56ea | 1493 | |
ba379fdc | 1494 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
9dae56ea | 1495 | |
f9bf01c6 A |
1496 | void finishParsing(const SourceCode&, ParameterNode*, const Identifier&); |
1497 | void finishParsing(PassRefPtr<FunctionParameters>, const Identifier&); | |
9dae56ea | 1498 | |
f9bf01c6 | 1499 | const Identifier& ident() { return m_ident; } |
9dae56ea | 1500 | |
f9bf01c6 | 1501 | static const bool scopeIsFunction = true; |
ba379fdc | 1502 | |
9dae56ea | 1503 | private: |
14957cd0 A |
1504 | FunctionBodyNode(JSGlobalData*, bool inStrictContext); |
1505 | FunctionBodyNode(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants); | |
9dae56ea | 1506 | |
f9bf01c6 A |
1507 | Identifier m_ident; |
1508 | RefPtr<FunctionParameters> m_parameters; | |
9dae56ea A |
1509 | }; |
1510 | ||
f9bf01c6 | 1511 | class FuncExprNode : public ExpressionNode { |
9dae56ea | 1512 | public: |
ba379fdc | 1513 | FuncExprNode(JSGlobalData*, const Identifier&, FunctionBodyNode* body, const SourceCode& source, ParameterNode* parameter = 0); |
9dae56ea | 1514 | |
f9bf01c6 | 1515 | FunctionBodyNode* body() { return m_body; } |
9dae56ea A |
1516 | |
1517 | private: | |
ba379fdc A |
1518 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
1519 | ||
1520 | virtual bool isFuncExprNode() const { return true; } | |
1521 | ||
f9bf01c6 | 1522 | FunctionBodyNode* m_body; |
9dae56ea A |
1523 | }; |
1524 | ||
f9bf01c6 | 1525 | class FuncDeclNode : public StatementNode { |
9dae56ea | 1526 | public: |
ba379fdc | 1527 | FuncDeclNode(JSGlobalData*, const Identifier&, FunctionBodyNode*, const SourceCode&, ParameterNode* = 0); |
9dae56ea | 1528 | |
f9bf01c6 | 1529 | FunctionBodyNode* body() { return m_body; } |
9dae56ea A |
1530 | |
1531 | private: | |
ba379fdc A |
1532 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
1533 | ||
f9bf01c6 | 1534 | FunctionBodyNode* m_body; |
9dae56ea A |
1535 | }; |
1536 | ||
f9bf01c6 | 1537 | class CaseClauseNode : public ParserArenaFreeable { |
9dae56ea | 1538 | public: |
f9bf01c6 | 1539 | CaseClauseNode(JSGlobalData*, ExpressionNode*, SourceElements* = 0); |
9dae56ea | 1540 | |
ba379fdc | 1541 | ExpressionNode* expr() const { return m_expr; } |
f9bf01c6 A |
1542 | |
1543 | void emitBytecode(BytecodeGenerator&, RegisterID* destination); | |
9dae56ea A |
1544 | |
1545 | private: | |
ba379fdc | 1546 | ExpressionNode* m_expr; |
f9bf01c6 | 1547 | SourceElements* m_statements; |
9dae56ea A |
1548 | }; |
1549 | ||
f9bf01c6 | 1550 | class ClauseListNode : public ParserArenaFreeable { |
9dae56ea | 1551 | public: |
ba379fdc A |
1552 | ClauseListNode(JSGlobalData*, CaseClauseNode*); |
1553 | ClauseListNode(JSGlobalData*, ClauseListNode*, CaseClauseNode*); | |
9dae56ea | 1554 | |
ba379fdc A |
1555 | CaseClauseNode* getClause() const { return m_clause; } |
1556 | ClauseListNode* getNext() const { return m_next; } | |
9dae56ea A |
1557 | |
1558 | private: | |
ba379fdc A |
1559 | CaseClauseNode* m_clause; |
1560 | ClauseListNode* m_next; | |
9dae56ea A |
1561 | }; |
1562 | ||
f9bf01c6 | 1563 | class CaseBlockNode : public ParserArenaFreeable { |
9dae56ea | 1564 | public: |
ba379fdc | 1565 | CaseBlockNode(JSGlobalData*, ClauseListNode* list1, CaseClauseNode* defaultClause, ClauseListNode* list2); |
9dae56ea | 1566 | |
f9bf01c6 | 1567 | RegisterID* emitBytecodeForBlock(BytecodeGenerator&, RegisterID* input, RegisterID* destination); |
9dae56ea A |
1568 | |
1569 | private: | |
1570 | SwitchInfo::SwitchType tryOptimizedSwitch(Vector<ExpressionNode*, 8>& literalVector, int32_t& min_num, int32_t& max_num); | |
ba379fdc A |
1571 | ClauseListNode* m_list1; |
1572 | CaseClauseNode* m_defaultClause; | |
1573 | ClauseListNode* m_list2; | |
9dae56ea A |
1574 | }; |
1575 | ||
1576 | class SwitchNode : public StatementNode { | |
1577 | public: | |
ba379fdc | 1578 | SwitchNode(JSGlobalData*, ExpressionNode*, CaseBlockNode*); |
9dae56ea A |
1579 | |
1580 | private: | |
ba379fdc A |
1581 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); |
1582 | ||
1583 | ExpressionNode* m_expr; | |
1584 | CaseBlockNode* m_block; | |
9dae56ea A |
1585 | }; |
1586 | ||
1587 | struct ElementList { | |
1588 | ElementNode* head; | |
1589 | ElementNode* tail; | |
1590 | }; | |
1591 | ||
1592 | struct PropertyList { | |
1593 | PropertyListNode* head; | |
1594 | PropertyListNode* tail; | |
1595 | }; | |
1596 | ||
1597 | struct ArgumentList { | |
1598 | ArgumentListNode* head; | |
1599 | ArgumentListNode* tail; | |
1600 | }; | |
1601 | ||
1602 | struct ConstDeclList { | |
1603 | ConstDeclNode* head; | |
1604 | ConstDeclNode* tail; | |
1605 | }; | |
1606 | ||
1607 | struct ParameterList { | |
1608 | ParameterNode* head; | |
1609 | ParameterNode* tail; | |
1610 | }; | |
1611 | ||
1612 | struct ClauseList { | |
1613 | ClauseListNode* head; | |
1614 | ClauseListNode* tail; | |
1615 | }; | |
1616 | ||
1617 | } // namespace JSC | |
1618 | ||
ba379fdc | 1619 | #endif // Nodes_h |