]>
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) | |
ed1e77d3 | 4 | * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2013, 2015 Apple Inc. All rights reserved. |
9dae56ea A |
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" |
93a37866 | 33 | #include "ParserTokens.h" |
9dae56ea A |
34 | #include "ResultType.h" |
35 | #include "SourceCode.h" | |
36 | #include "SymbolTable.h" | |
37 | #include <wtf/MathExtras.h> | |
9dae56ea A |
38 | |
39 | namespace JSC { | |
40 | ||
ba379fdc | 41 | class ArgumentListNode; |
9dae56ea | 42 | class BytecodeGenerator; |
f9bf01c6 A |
43 | class FunctionBodyNode; |
44 | class Label; | |
9dae56ea | 45 | class PropertyListNode; |
ba379fdc | 46 | class ReadModifyResolveNode; |
9dae56ea | 47 | class RegisterID; |
93a37866 | 48 | class JSScope; |
f9bf01c6 | 49 | class ScopeNode; |
9dae56ea | 50 | |
9dae56ea A |
51 | enum Operator { |
52 | OpEqual, | |
53 | OpPlusEq, | |
54 | OpMinusEq, | |
55 | OpMultEq, | |
56 | OpDivEq, | |
57 | OpPlusPlus, | |
58 | OpMinusMinus, | |
59 | OpAndEq, | |
60 | OpXOrEq, | |
61 | OpOrEq, | |
62 | OpModEq, | |
63 | OpLShift, | |
64 | OpRShift, | |
65 | OpURShift | |
66 | }; | |
67 | ||
68 | enum LogicalOperator { | |
69 | OpLogicalAnd, | |
70 | OpLogicalOr | |
71 | }; | |
72 | ||
93a37866 A |
73 | enum FallThroughMode { |
74 | FallThroughMeansTrue = 0, | |
75 | FallThroughMeansFalse = 1 | |
76 | }; | |
77 | inline FallThroughMode invert(FallThroughMode fallThroughMode) { return static_cast<FallThroughMode>(!fallThroughMode); } | |
78 | ||
ed1e77d3 | 79 | typedef HashSet<RefPtr<UniquedStringImpl>, IdentifierRepHash> IdentifierSet; |
14957cd0 | 80 | |
9dae56ea A |
81 | namespace DeclarationStacks { |
82 | enum VarAttrs { IsConstant = 1, HasInitializer = 2 }; | |
81345200 | 83 | typedef Vector<std::pair<Identifier, unsigned>> VarStack; |
f9bf01c6 | 84 | typedef Vector<FunctionBodyNode*> FunctionStack; |
9dae56ea A |
85 | } |
86 | ||
87 | struct SwitchInfo { | |
88 | enum SwitchType { SwitchNone, SwitchImmediate, SwitchCharacter, SwitchString }; | |
89 | uint32_t bytecodeOffset; | |
90 | SwitchType switchType; | |
91 | }; | |
92 | ||
f9bf01c6 A |
93 | class ParserArenaFreeable { |
94 | public: | |
95 | // ParserArenaFreeable objects are are freed when the arena is deleted. | |
96 | // Destructors are not called. Clients must not call delete on such objects. | |
ed1e77d3 | 97 | void* operator new(size_t, ParserArena&); |
f9bf01c6 | 98 | }; |
9dae56ea | 99 | |
f9bf01c6 | 100 | class ParserArenaDeletable { |
9dae56ea | 101 | public: |
ba379fdc | 102 | virtual ~ParserArenaDeletable() { } |
9dae56ea | 103 | |
f9bf01c6 A |
104 | // ParserArenaDeletable objects are deleted when the arena is deleted. |
105 | // Clients must not call delete directly on such objects. | |
ed1e77d3 | 106 | void* operator new(size_t, ParserArena&); |
ba379fdc | 107 | }; |
9dae56ea | 108 | |
ed1e77d3 | 109 | class ParserArenaRoot { |
81345200 | 110 | WTF_MAKE_FAST_ALLOCATED; |
ba379fdc | 111 | protected: |
ed1e77d3 | 112 | ParserArenaRoot(ParserArena&); |
9dae56ea | 113 | |
ba379fdc | 114 | public: |
ed1e77d3 A |
115 | ParserArena& parserArena() { return m_arena; } |
116 | virtual ~ParserArenaRoot() { } | |
117 | ||
118 | protected: | |
119 | ParserArena m_arena; | |
9dae56ea A |
120 | }; |
121 | ||
f9bf01c6 | 122 | class Node : public ParserArenaFreeable { |
ba379fdc | 123 | protected: |
93a37866 | 124 | Node(const JSTokenLocation&); |
9dae56ea | 125 | |
ba379fdc | 126 | public: |
f9bf01c6 | 127 | virtual ~Node() { } |
9dae56ea | 128 | |
ed1e77d3 | 129 | int firstLine() const { return m_position.line; } |
81345200 | 130 | int startOffset() const { return m_position.offset; } |
ed1e77d3 | 131 | int endOffset() const { return m_endOffset; } |
81345200 A |
132 | int lineStartOffset() const { return m_position.lineStartOffset; } |
133 | const JSTextPosition& position() const { return m_position; } | |
ed1e77d3 A |
134 | void setEndOffset(int offset) { m_endOffset = offset; } |
135 | void setStartOffset(int offset) { m_position.offset = offset; } | |
9dae56ea A |
136 | |
137 | protected: | |
81345200 | 138 | JSTextPosition m_position; |
ed1e77d3 | 139 | int m_endOffset; |
9dae56ea A |
140 | }; |
141 | ||
142 | class ExpressionNode : public Node { | |
f9bf01c6 | 143 | protected: |
93a37866 | 144 | ExpressionNode(const JSTokenLocation&, ResultType = ResultType::unknownType()); |
ba379fdc | 145 | |
f9bf01c6 | 146 | public: |
93a37866 A |
147 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* destination = 0) = 0; |
148 | ||
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; } | |
93a37866 | 153 | virtual bool isConstant() const { return false; } |
ba379fdc | 154 | virtual bool isLocation() const { return false; } |
81345200 | 155 | virtual bool isAssignmentLocation() const { return isLocation(); } |
ba379fdc A |
156 | virtual bool isResolveNode() const { return false; } |
157 | virtual bool isBracketAccessorNode() const { return false; } | |
158 | virtual bool isDotAccessorNode() const { return false; } | |
ed1e77d3 | 159 | virtual bool isDestructuringNode() const { return false; } |
ba379fdc A |
160 | virtual bool isFuncExprNode() const { return false; } |
161 | virtual bool isCommaNode() const { return false; } | |
162 | virtual bool isSimpleArray() const { return false; } | |
163 | virtual bool isAdd() const { return false; } | |
14957cd0 | 164 | virtual bool isSubtract() const { return false; } |
93a37866 | 165 | virtual bool isBoolean() const { return false; } |
81345200 | 166 | virtual bool isSpreadExpression() const { return false; } |
ed1e77d3 | 167 | virtual bool isSuperNode() const { return false; } |
f9bf01c6 | 168 | |
93a37866 | 169 | virtual void emitBytecodeInConditionContext(BytecodeGenerator&, Label*, Label*, FallThroughMode); |
9dae56ea A |
170 | |
171 | virtual ExpressionNode* stripUnaryPlus() { return this; } | |
172 | ||
ba379fdc | 173 | ResultType resultDescriptor() const { return m_resultType; } |
9dae56ea | 174 | |
9dae56ea | 175 | private: |
ba379fdc | 176 | ResultType m_resultType; |
9dae56ea A |
177 | }; |
178 | ||
179 | class StatementNode : public Node { | |
f9bf01c6 | 180 | protected: |
93a37866 | 181 | StatementNode(const JSTokenLocation&); |
9dae56ea | 182 | |
f9bf01c6 | 183 | public: |
93a37866 A |
184 | virtual void emitBytecode(BytecodeGenerator&, RegisterID* destination = 0) = 0; |
185 | ||
186 | void setLoc(unsigned firstLine, unsigned lastLine, int startOffset, int lineStartOffset); | |
93a37866 | 187 | unsigned lastLine() const { return m_lastLine; } |
9dae56ea | 188 | |
ed1e77d3 A |
189 | StatementNode* next() { return m_next; } |
190 | void setNext(StatementNode* next) { m_next = next; } | |
191 | ||
ba379fdc A |
192 | virtual bool isEmptyStatement() const { return false; } |
193 | virtual bool isReturnNode() const { return false; } | |
194 | virtual bool isExprStatement() const { return false; } | |
93a37866 A |
195 | virtual bool isBreak() const { return false; } |
196 | virtual bool isContinue() const { return false; } | |
ba379fdc | 197 | virtual bool isBlock() const { return false; } |
ed1e77d3 | 198 | virtual bool isFuncDeclNode() const { return false; } |
9dae56ea | 199 | |
81345200 | 200 | protected: |
ed1e77d3 | 201 | StatementNode* m_next; |
9dae56ea A |
202 | int m_lastLine; |
203 | }; | |
204 | ||
93a37866 | 205 | class ConstantNode : public ExpressionNode { |
9dae56ea | 206 | public: |
93a37866 | 207 | ConstantNode(const JSTokenLocation&, ResultType); |
81345200 A |
208 | virtual bool isPure(BytecodeGenerator&) const override { return true; } |
209 | virtual bool isConstant() const override { return true; } | |
93a37866 | 210 | virtual JSValue jsValue(BytecodeGenerator&) const = 0; |
ba379fdc | 211 | private: |
81345200 A |
212 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
213 | virtual void emitBytecodeInConditionContext(BytecodeGenerator&, Label* trueTarget, Label* falseTarget, FallThroughMode) override; | |
93a37866 A |
214 | }; |
215 | ||
216 | class NullNode : public ConstantNode { | |
217 | public: | |
218 | NullNode(const JSTokenLocation&); | |
9dae56ea | 219 | |
93a37866 | 220 | private: |
81345200 A |
221 | virtual bool isNull() const override { return true; } |
222 | virtual JSValue jsValue(BytecodeGenerator&) const override { return jsNull(); } | |
9dae56ea A |
223 | }; |
224 | ||
93a37866 | 225 | class BooleanNode : public ConstantNode { |
9dae56ea | 226 | public: |
93a37866 A |
227 | BooleanNode(const JSTokenLocation&, bool value); |
228 | bool value() { return m_value; } | |
9dae56ea | 229 | |
ba379fdc | 230 | private: |
81345200 A |
231 | virtual bool isBoolean() const override { return true; } |
232 | virtual JSValue jsValue(BytecodeGenerator&) const override { return jsBoolean(m_value); } | |
9dae56ea | 233 | |
9dae56ea A |
234 | bool m_value; |
235 | }; | |
236 | ||
93a37866 | 237 | class NumberNode : public ConstantNode { |
9dae56ea | 238 | public: |
93a37866 | 239 | NumberNode(const JSTokenLocation&, double value); |
ed1e77d3 A |
240 | double value() const { return m_value; } |
241 | virtual bool isIntegerNode() const = 0; | |
242 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override final; | |
9dae56ea A |
243 | |
244 | private: | |
ed1e77d3 | 245 | virtual bool isNumber() const override final { return true; } |
81345200 | 246 | virtual JSValue jsValue(BytecodeGenerator&) const override { return jsNumber(m_value); } |
ba379fdc | 247 | |
f9bf01c6 | 248 | double m_value; |
9dae56ea A |
249 | }; |
250 | ||
ed1e77d3 A |
251 | class DoubleNode : public NumberNode { |
252 | public: | |
253 | DoubleNode(const JSTokenLocation&, double value); | |
254 | ||
255 | private: | |
256 | virtual bool isIntegerNode() const override { return false; } | |
257 | }; | |
258 | ||
259 | // An integer node represent a number represented as an integer (e.g. 42 instead of 42., 42.0, 42e0) | |
260 | class IntegerNode : public DoubleNode { | |
261 | public: | |
262 | IntegerNode(const JSTokenLocation&, double value); | |
263 | virtual bool isIntegerNode() const override final { return true; } | |
264 | }; | |
265 | ||
93a37866 | 266 | class StringNode : public ConstantNode { |
9dae56ea | 267 | public: |
93a37866 | 268 | StringNode(const JSTokenLocation&, const Identifier&); |
9dae56ea | 269 | const Identifier& value() { return m_value; } |
9dae56ea A |
270 | |
271 | private: | |
81345200 A |
272 | virtual bool isString() const override { return true; } |
273 | virtual JSValue jsValue(BytecodeGenerator&) const override; | |
ba379fdc | 274 | |
f9bf01c6 | 275 | const Identifier& m_value; |
9dae56ea | 276 | }; |
ed1e77d3 | 277 | |
9dae56ea A |
278 | class ThrowableExpressionData { |
279 | public: | |
280 | ThrowableExpressionData() | |
81345200 A |
281 | : m_divot(-1, -1, -1) |
282 | , m_divotStart(-1, -1, -1) | |
283 | , m_divotEnd(-1, -1, -1) | |
9dae56ea A |
284 | { |
285 | } | |
286 | ||
81345200 | 287 | ThrowableExpressionData(const JSTextPosition& divot, const JSTextPosition& start, const JSTextPosition& end) |
9dae56ea | 288 | : m_divot(divot) |
81345200 A |
289 | , m_divotStart(start) |
290 | , m_divotEnd(end) | |
9dae56ea | 291 | { |
81345200 A |
292 | ASSERT(m_divot.offset >= m_divot.lineStartOffset); |
293 | ASSERT(m_divotStart.offset >= m_divotStart.lineStartOffset); | |
294 | ASSERT(m_divotEnd.offset >= m_divotEnd.lineStartOffset); | |
9dae56ea | 295 | } |
81345200 A |
296 | |
297 | void setExceptionSourceCode(const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd) | |
9dae56ea | 298 | { |
81345200 A |
299 | ASSERT(divot.offset >= divot.lineStartOffset); |
300 | ASSERT(divotStart.offset >= divotStart.lineStartOffset); | |
301 | ASSERT(divotEnd.offset >= divotEnd.lineStartOffset); | |
9dae56ea | 302 | m_divot = divot; |
81345200 A |
303 | m_divotStart = divotStart; |
304 | m_divotEnd = divotEnd; | |
9dae56ea A |
305 | } |
306 | ||
81345200 A |
307 | const JSTextPosition& divot() const { return m_divot; } |
308 | const JSTextPosition& divotStart() const { return m_divotStart; } | |
309 | const JSTextPosition& divotEnd() const { return m_divotEnd; } | |
9dae56ea A |
310 | |
311 | protected: | |
93a37866 | 312 | RegisterID* emitThrowReferenceError(BytecodeGenerator&, const String& message); |
9dae56ea A |
313 | |
314 | private: | |
81345200 A |
315 | JSTextPosition m_divot; |
316 | JSTextPosition m_divotStart; | |
317 | JSTextPosition m_divotEnd; | |
9dae56ea A |
318 | }; |
319 | ||
320 | class ThrowableSubExpressionData : public ThrowableExpressionData { | |
321 | public: | |
322 | ThrowableSubExpressionData() | |
f9bf01c6 | 323 | : m_subexpressionDivotOffset(0) |
9dae56ea | 324 | , m_subexpressionEndOffset(0) |
93a37866 A |
325 | , m_subexpressionLineOffset(0) |
326 | , m_subexpressionLineStartOffset(0) | |
9dae56ea A |
327 | { |
328 | } | |
329 | ||
81345200 A |
330 | ThrowableSubExpressionData(const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd) |
331 | : ThrowableExpressionData(divot, divotStart, divotEnd) | |
9dae56ea A |
332 | , m_subexpressionDivotOffset(0) |
333 | , m_subexpressionEndOffset(0) | |
93a37866 A |
334 | , m_subexpressionLineOffset(0) |
335 | , m_subexpressionLineStartOffset(0) | |
9dae56ea A |
336 | { |
337 | } | |
338 | ||
81345200 | 339 | void setSubexpressionInfo(const JSTextPosition& subexpressionDivot, int subexpressionOffset) |
9dae56ea | 340 | { |
81345200 | 341 | ASSERT(subexpressionDivot.offset <= divot().offset); |
93a37866 A |
342 | // Overflow means we can't do this safely, so just point at the primary divot, |
343 | // divotLine, or divotLineStart. | |
81345200 A |
344 | if ((divot() - subexpressionDivot.offset) & ~0xFFFF) |
345 | return; | |
346 | if ((divot().line - subexpressionDivot.line) & ~0xFFFF) | |
93a37866 | 347 | return; |
81345200 | 348 | if ((divot().lineStartOffset - subexpressionDivot.lineStartOffset) & ~0xFFFF) |
93a37866 | 349 | return; |
81345200 | 350 | if ((divotEnd() - subexpressionOffset) & ~0xFFFF) |
9dae56ea | 351 | return; |
81345200 A |
352 | m_subexpressionDivotOffset = divot() - subexpressionDivot.offset; |
353 | m_subexpressionEndOffset = divotEnd() - subexpressionOffset; | |
354 | m_subexpressionLineOffset = divot().line - subexpressionDivot.line; | |
355 | m_subexpressionLineStartOffset = divot().lineStartOffset - subexpressionDivot.lineStartOffset; | |
9dae56ea A |
356 | } |
357 | ||
81345200 A |
358 | JSTextPosition subexpressionDivot() |
359 | { | |
360 | int newLine = divot().line - m_subexpressionLineOffset; | |
361 | int newOffset = divot().offset - m_subexpressionDivotOffset; | |
362 | int newLineStartOffset = divot().lineStartOffset - m_subexpressionLineStartOffset; | |
363 | return JSTextPosition(newLine, newOffset, newLineStartOffset); | |
364 | } | |
365 | JSTextPosition subexpressionStart() { return divotStart(); } | |
366 | JSTextPosition subexpressionEnd() { return divotEnd() - static_cast<int>(m_subexpressionEndOffset); } | |
93a37866 | 367 | |
9dae56ea A |
368 | protected: |
369 | uint16_t m_subexpressionDivotOffset; | |
370 | uint16_t m_subexpressionEndOffset; | |
93a37866 A |
371 | uint16_t m_subexpressionLineOffset; |
372 | uint16_t m_subexpressionLineStartOffset; | |
9dae56ea A |
373 | }; |
374 | ||
375 | class ThrowablePrefixedSubExpressionData : public ThrowableExpressionData { | |
376 | public: | |
377 | ThrowablePrefixedSubExpressionData() | |
f9bf01c6 | 378 | : m_subexpressionDivotOffset(0) |
9dae56ea | 379 | , m_subexpressionStartOffset(0) |
93a37866 A |
380 | , m_subexpressionLineOffset(0) |
381 | , m_subexpressionLineStartOffset(0) | |
9dae56ea A |
382 | { |
383 | } | |
384 | ||
81345200 A |
385 | ThrowablePrefixedSubExpressionData(const JSTextPosition& divot, const JSTextPosition& start, const JSTextPosition& end) |
386 | : ThrowableExpressionData(divot, start, end) | |
9dae56ea A |
387 | , m_subexpressionDivotOffset(0) |
388 | , m_subexpressionStartOffset(0) | |
93a37866 A |
389 | , m_subexpressionLineOffset(0) |
390 | , m_subexpressionLineStartOffset(0) | |
9dae56ea A |
391 | { |
392 | } | |
393 | ||
81345200 | 394 | void setSubexpressionInfo(const JSTextPosition& subexpressionDivot, int subexpressionOffset) |
9dae56ea | 395 | { |
81345200 | 396 | ASSERT(subexpressionDivot.offset >= divot().offset); |
93a37866 A |
397 | // Overflow means we can't do this safely, so just point at the primary divot, |
398 | // divotLine, or divotLineStart. | |
81345200 A |
399 | if ((subexpressionDivot.offset - divot()) & ~0xFFFF) |
400 | return; | |
401 | if ((subexpressionDivot.line - divot().line) & ~0xFFFF) | |
93a37866 | 402 | return; |
81345200 | 403 | if ((subexpressionDivot.lineStartOffset - divot().lineStartOffset) & ~0xFFFF) |
93a37866 | 404 | return; |
81345200 | 405 | if ((subexpressionOffset - divotStart()) & ~0xFFFF) |
9dae56ea | 406 | return; |
81345200 A |
407 | m_subexpressionDivotOffset = subexpressionDivot.offset - divot(); |
408 | m_subexpressionStartOffset = subexpressionOffset - divotStart(); | |
409 | m_subexpressionLineOffset = subexpressionDivot.line - divot().line; | |
410 | m_subexpressionLineStartOffset = subexpressionDivot.lineStartOffset - divot().lineStartOffset; | |
9dae56ea A |
411 | } |
412 | ||
81345200 A |
413 | JSTextPosition subexpressionDivot() |
414 | { | |
415 | int newLine = divot().line + m_subexpressionLineOffset; | |
416 | int newOffset = divot().offset + m_subexpressionDivotOffset; | |
417 | int newLineStartOffset = divot().lineStartOffset + m_subexpressionLineStartOffset; | |
418 | return JSTextPosition(newLine, newOffset, newLineStartOffset); | |
419 | } | |
420 | JSTextPosition subexpressionStart() { return divotStart() + static_cast<int>(m_subexpressionStartOffset); } | |
421 | JSTextPosition subexpressionEnd() { return divotEnd(); } | |
93a37866 | 422 | |
9dae56ea A |
423 | protected: |
424 | uint16_t m_subexpressionDivotOffset; | |
425 | uint16_t m_subexpressionStartOffset; | |
93a37866 A |
426 | uint16_t m_subexpressionLineOffset; |
427 | uint16_t m_subexpressionLineStartOffset; | |
9dae56ea A |
428 | }; |
429 | ||
ed1e77d3 A |
430 | #if ENABLE(ES6_TEMPLATE_LITERAL_SYNTAX) |
431 | class TemplateExpressionListNode : public ParserArenaFreeable { | |
432 | public: | |
433 | TemplateExpressionListNode(ExpressionNode*); | |
434 | TemplateExpressionListNode(TemplateExpressionListNode*, ExpressionNode*); | |
435 | ||
436 | ExpressionNode* value() { return m_node; } | |
437 | TemplateExpressionListNode* next() { return m_next; } | |
438 | ||
439 | private: | |
440 | TemplateExpressionListNode* m_next { nullptr }; | |
441 | ExpressionNode* m_node { nullptr }; | |
442 | }; | |
443 | ||
444 | class TemplateStringNode : public ExpressionNode { | |
445 | public: | |
446 | TemplateStringNode(const JSTokenLocation&, const Identifier& cooked, const Identifier& raw); | |
447 | ||
448 | const Identifier& cooked() { return m_cooked; } | |
449 | const Identifier& raw() { return m_raw; } | |
450 | ||
451 | private: | |
452 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; | |
453 | ||
454 | const Identifier& m_cooked; | |
455 | const Identifier& m_raw; | |
456 | }; | |
457 | ||
458 | class TemplateStringListNode : public ParserArenaFreeable { | |
459 | public: | |
460 | TemplateStringListNode(TemplateStringNode*); | |
461 | TemplateStringListNode(TemplateStringListNode*, TemplateStringNode*); | |
462 | ||
463 | TemplateStringNode* value() { return m_node; } | |
464 | TemplateStringListNode* next() { return m_next; } | |
465 | ||
466 | private: | |
467 | TemplateStringListNode* m_next { nullptr }; | |
468 | TemplateStringNode* m_node { nullptr }; | |
469 | }; | |
470 | ||
471 | class TemplateLiteralNode : public ExpressionNode { | |
472 | public: | |
473 | TemplateLiteralNode(const JSTokenLocation&, TemplateStringListNode*); | |
474 | TemplateLiteralNode(const JSTokenLocation&, TemplateStringListNode*, TemplateExpressionListNode*); | |
475 | ||
476 | TemplateStringListNode* templateStrings() const { return m_templateStrings; } | |
477 | TemplateExpressionListNode* templateExpressions() const { return m_templateExpressions; } | |
478 | ||
479 | private: | |
480 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; | |
481 | ||
482 | TemplateStringListNode* m_templateStrings; | |
483 | TemplateExpressionListNode* m_templateExpressions; | |
484 | }; | |
485 | ||
486 | class TaggedTemplateNode : public ExpressionNode, public ThrowableExpressionData { | |
487 | public: | |
488 | TaggedTemplateNode(const JSTokenLocation&, ExpressionNode*, TemplateLiteralNode*); | |
489 | ||
490 | TemplateLiteralNode* templateLiteral() const { return m_templateLiteral; } | |
491 | ||
492 | private: | |
493 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; | |
494 | ||
495 | ExpressionNode* m_tag; | |
496 | TemplateLiteralNode* m_templateLiteral; | |
497 | }; | |
498 | #endif | |
499 | ||
9dae56ea A |
500 | class RegExpNode : public ExpressionNode, public ThrowableExpressionData { |
501 | public: | |
93a37866 | 502 | RegExpNode(const JSTokenLocation&, const Identifier& pattern, const Identifier& flags); |
9dae56ea A |
503 | |
504 | private: | |
81345200 | 505 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc | 506 | |
f9bf01c6 A |
507 | const Identifier& m_pattern; |
508 | const Identifier& m_flags; | |
9dae56ea A |
509 | }; |
510 | ||
511 | class ThisNode : public ExpressionNode { | |
512 | public: | |
ed1e77d3 | 513 | ThisNode(const JSTokenLocation&, ThisTDZMode); |
9dae56ea | 514 | |
ba379fdc | 515 | private: |
81345200 | 516 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ed1e77d3 A |
517 | |
518 | bool m_shouldAlwaysEmitTDZCheck; | |
519 | }; | |
520 | ||
521 | class SuperNode final : public ExpressionNode { | |
522 | public: | |
523 | SuperNode(const JSTokenLocation&); | |
524 | ||
525 | private: | |
526 | virtual bool isSuperNode() const override { return true; } | |
527 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; | |
9dae56ea A |
528 | }; |
529 | ||
530 | class ResolveNode : public ExpressionNode { | |
531 | public: | |
81345200 | 532 | ResolveNode(const JSTokenLocation&, const Identifier&, const JSTextPosition& start); |
9dae56ea | 533 | |
ba379fdc | 534 | const Identifier& identifier() const { return m_ident; } |
9dae56ea A |
535 | |
536 | private: | |
81345200 | 537 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc | 538 | |
81345200 A |
539 | virtual bool isPure(BytecodeGenerator&) const override; |
540 | virtual bool isLocation() const override { return true; } | |
541 | virtual bool isResolveNode() const override { return true; } | |
ba379fdc | 542 | |
f9bf01c6 | 543 | const Identifier& m_ident; |
81345200 | 544 | JSTextPosition m_start; |
9dae56ea A |
545 | }; |
546 | ||
f9bf01c6 | 547 | class ElementNode : public ParserArenaFreeable { |
9dae56ea | 548 | public: |
6fe7ccc8 A |
549 | ElementNode(int elision, ExpressionNode*); |
550 | ElementNode(ElementNode*, int elision, ExpressionNode*); | |
9dae56ea A |
551 | |
552 | int elision() const { return m_elision; } | |
ba379fdc A |
553 | ExpressionNode* value() { return m_node; } |
554 | ElementNode* next() { return m_next; } | |
9dae56ea A |
555 | |
556 | private: | |
ba379fdc | 557 | ElementNode* m_next; |
9dae56ea | 558 | int m_elision; |
ba379fdc | 559 | ExpressionNode* m_node; |
9dae56ea A |
560 | }; |
561 | ||
562 | class ArrayNode : public ExpressionNode { | |
563 | public: | |
93a37866 A |
564 | ArrayNode(const JSTokenLocation&, int elision); |
565 | ArrayNode(const JSTokenLocation&, ElementNode*); | |
566 | ArrayNode(const JSTokenLocation&, int elision, ElementNode*); | |
9dae56ea | 567 | |
ed1e77d3 | 568 | ArgumentListNode* toArgumentList(ParserArena&, int, int) const; |
9dae56ea | 569 | |
81345200 | 570 | ElementNode* elements() const { ASSERT(isSimpleArray()); return m_element; } |
ba379fdc | 571 | private: |
81345200 | 572 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
9dae56ea | 573 | |
81345200 | 574 | virtual bool isSimpleArray() const override; |
9dae56ea | 575 | |
ba379fdc | 576 | ElementNode* m_element; |
9dae56ea A |
577 | int m_elision; |
578 | bool m_optional; | |
579 | }; | |
580 | ||
f9bf01c6 | 581 | class PropertyNode : public ParserArenaFreeable { |
9dae56ea | 582 | public: |
ed1e77d3 A |
583 | enum Type { Constant = 1, Getter = 2, Setter = 4, Computed = 8, Shorthand = 16 }; |
584 | enum PutType { Unknown, KnownDirect }; | |
585 | ||
586 | PropertyNode(const Identifier&, ExpressionNode*, Type, PutType, SuperBinding); | |
587 | PropertyNode(ExpressionNode* propertyName, ExpressionNode*, Type, PutType); | |
9dae56ea | 588 | |
81345200 A |
589 | ExpressionNode* expressionName() const { return m_expression; } |
590 | const Identifier* name() const { return m_name; } | |
9dae56ea | 591 | |
ed1e77d3 A |
592 | Type type() const { return static_cast<Type>(m_type); } |
593 | bool needsSuperBinding() const { return m_needsSuperBinding; } | |
594 | PutType putType() const { return static_cast<PutType>(m_putType); } | |
9dae56ea A |
595 | |
596 | private: | |
597 | friend class PropertyListNode; | |
81345200 A |
598 | const Identifier* m_name; |
599 | ExpressionNode* m_expression; | |
ba379fdc | 600 | ExpressionNode* m_assign; |
ed1e77d3 A |
601 | unsigned m_type : 5; |
602 | unsigned m_needsSuperBinding : 1; | |
603 | unsigned m_putType : 1; | |
9dae56ea A |
604 | }; |
605 | ||
93a37866 | 606 | class PropertyListNode : public ExpressionNode { |
9dae56ea | 607 | public: |
93a37866 A |
608 | PropertyListNode(const JSTokenLocation&, PropertyNode*); |
609 | PropertyListNode(const JSTokenLocation&, PropertyNode*, PropertyListNode*); | |
9dae56ea | 610 | |
ed1e77d3 | 611 | private: |
81345200 | 612 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ed1e77d3 | 613 | void emitPutConstantProperty(BytecodeGenerator&, RegisterID*, PropertyNode&); |
9dae56ea | 614 | |
ba379fdc A |
615 | PropertyNode* m_node; |
616 | PropertyListNode* m_next; | |
9dae56ea A |
617 | }; |
618 | ||
619 | class ObjectLiteralNode : public ExpressionNode { | |
620 | public: | |
93a37866 A |
621 | ObjectLiteralNode(const JSTokenLocation&); |
622 | ObjectLiteralNode(const JSTokenLocation&, PropertyListNode*); | |
9dae56ea A |
623 | |
624 | private: | |
81345200 | 625 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc A |
626 | |
627 | PropertyListNode* m_list; | |
9dae56ea A |
628 | }; |
629 | ||
630 | class BracketAccessorNode : public ExpressionNode, public ThrowableExpressionData { | |
631 | public: | |
93a37866 | 632 | BracketAccessorNode(const JSTokenLocation&, ExpressionNode* base, ExpressionNode* subscript, bool subscriptHasAssignments); |
9dae56ea | 633 | |
ba379fdc A |
634 | ExpressionNode* base() const { return m_base; } |
635 | ExpressionNode* subscript() const { return m_subscript; } | |
9dae56ea | 636 | |
93a37866 A |
637 | bool subscriptHasAssignments() const { return m_subscriptHasAssignments; } |
638 | ||
ba379fdc | 639 | private: |
81345200 | 640 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
9dae56ea | 641 | |
81345200 A |
642 | virtual bool isLocation() const override { return true; } |
643 | virtual bool isBracketAccessorNode() const override { return true; } | |
9dae56ea | 644 | |
ba379fdc A |
645 | ExpressionNode* m_base; |
646 | ExpressionNode* m_subscript; | |
9dae56ea A |
647 | bool m_subscriptHasAssignments; |
648 | }; | |
649 | ||
650 | class DotAccessorNode : public ExpressionNode, public ThrowableExpressionData { | |
651 | public: | |
93a37866 | 652 | DotAccessorNode(const JSTokenLocation&, ExpressionNode* base, const Identifier&); |
9dae56ea | 653 | |
ba379fdc A |
654 | ExpressionNode* base() const { return m_base; } |
655 | const Identifier& identifier() const { return m_ident; } | |
9dae56ea | 656 | |
ba379fdc | 657 | private: |
81345200 | 658 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
9dae56ea | 659 | |
81345200 A |
660 | virtual bool isLocation() const override { return true; } |
661 | virtual bool isDotAccessorNode() const override { return true; } | |
9dae56ea | 662 | |
ba379fdc | 663 | ExpressionNode* m_base; |
f9bf01c6 | 664 | const Identifier& m_ident; |
9dae56ea A |
665 | }; |
666 | ||
81345200 A |
667 | class SpreadExpressionNode : public ExpressionNode, public ThrowableExpressionData { |
668 | public: | |
669 | SpreadExpressionNode(const JSTokenLocation&, ExpressionNode*); | |
670 | ||
671 | ExpressionNode* expression() const { return m_expression; } | |
672 | ||
673 | private: | |
674 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; | |
675 | ||
676 | virtual bool isSpreadExpression() const override { return true; } | |
677 | ExpressionNode* m_expression; | |
678 | }; | |
679 | ||
93a37866 | 680 | class ArgumentListNode : public ExpressionNode { |
9dae56ea | 681 | public: |
93a37866 A |
682 | ArgumentListNode(const JSTokenLocation&, ExpressionNode*); |
683 | ArgumentListNode(const JSTokenLocation&, ArgumentListNode*, ExpressionNode*); | |
9dae56ea | 684 | |
ba379fdc A |
685 | ArgumentListNode* m_next; |
686 | ExpressionNode* m_expr; | |
9dae56ea | 687 | |
ba379fdc | 688 | private: |
81345200 | 689 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
9dae56ea A |
690 | }; |
691 | ||
f9bf01c6 | 692 | class ArgumentsNode : public ParserArenaFreeable { |
9dae56ea | 693 | public: |
6fe7ccc8 A |
694 | ArgumentsNode(); |
695 | ArgumentsNode(ArgumentListNode*); | |
9dae56ea | 696 | |
ba379fdc | 697 | ArgumentListNode* m_listNode; |
9dae56ea A |
698 | }; |
699 | ||
700 | class NewExprNode : public ExpressionNode, public ThrowableExpressionData { | |
701 | public: | |
93a37866 A |
702 | NewExprNode(const JSTokenLocation&, ExpressionNode*); |
703 | NewExprNode(const JSTokenLocation&, ExpressionNode*, ArgumentsNode*); | |
9dae56ea A |
704 | |
705 | private: | |
81345200 | 706 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc A |
707 | |
708 | ExpressionNode* m_expr; | |
709 | ArgumentsNode* m_args; | |
9dae56ea A |
710 | }; |
711 | ||
712 | class EvalFunctionCallNode : public ExpressionNode, public ThrowableExpressionData { | |
713 | public: | |
81345200 | 714 | EvalFunctionCallNode(const JSTokenLocation&, ArgumentsNode*, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd); |
9dae56ea A |
715 | |
716 | private: | |
81345200 | 717 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc A |
718 | |
719 | ArgumentsNode* m_args; | |
9dae56ea A |
720 | }; |
721 | ||
722 | class FunctionCallValueNode : public ExpressionNode, public ThrowableExpressionData { | |
723 | public: | |
81345200 | 724 | FunctionCallValueNode(const JSTokenLocation&, ExpressionNode*, ArgumentsNode*, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd); |
9dae56ea A |
725 | |
726 | private: | |
81345200 | 727 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc A |
728 | |
729 | ExpressionNode* m_expr; | |
730 | ArgumentsNode* m_args; | |
9dae56ea A |
731 | }; |
732 | ||
733 | class FunctionCallResolveNode : public ExpressionNode, public ThrowableExpressionData { | |
734 | public: | |
81345200 | 735 | FunctionCallResolveNode(const JSTokenLocation&, const Identifier&, ArgumentsNode*, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd); |
9dae56ea A |
736 | |
737 | private: | |
81345200 | 738 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc | 739 | |
f9bf01c6 | 740 | const Identifier& m_ident; |
ba379fdc | 741 | ArgumentsNode* m_args; |
9dae56ea A |
742 | }; |
743 | ||
744 | class FunctionCallBracketNode : public ExpressionNode, public ThrowableSubExpressionData { | |
745 | public: | |
ed1e77d3 | 746 | FunctionCallBracketNode(const JSTokenLocation&, ExpressionNode* base, ExpressionNode* subscript, bool subscriptHasAssignments, ArgumentsNode*, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd); |
9dae56ea A |
747 | |
748 | private: | |
81345200 | 749 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc A |
750 | |
751 | ExpressionNode* m_base; | |
752 | ExpressionNode* m_subscript; | |
753 | ArgumentsNode* m_args; | |
ed1e77d3 | 754 | bool m_subscriptHasAssignments; |
9dae56ea A |
755 | }; |
756 | ||
757 | class FunctionCallDotNode : public ExpressionNode, public ThrowableSubExpressionData { | |
758 | public: | |
81345200 | 759 | FunctionCallDotNode(const JSTokenLocation&, ExpressionNode* base, const Identifier&, ArgumentsNode*, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd); |
ba379fdc A |
760 | |
761 | private: | |
81345200 | 762 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
9dae56ea | 763 | |
ba379fdc A |
764 | protected: |
765 | ExpressionNode* m_base; | |
f9bf01c6 | 766 | const Identifier& m_ident; |
ba379fdc A |
767 | ArgumentsNode* m_args; |
768 | }; | |
9dae56ea | 769 | |
ed1e77d3 A |
770 | class BytecodeIntrinsicNode : public ExpressionNode, public ThrowableExpressionData { |
771 | public: | |
772 | typedef RegisterID* (BytecodeIntrinsicNode::* EmitterType)(BytecodeGenerator&, RegisterID*); | |
773 | ||
774 | BytecodeIntrinsicNode(const JSTokenLocation&, EmitterType, const Identifier&, ArgumentsNode*, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd); | |
775 | ||
776 | const Identifier& identifier() const { return m_ident; } | |
777 | ||
778 | #define JSC_DECLARE_BYTECODE_INTRINSIC_FUNCTIONS(name) RegisterID* emit_intrinsic_##name(BytecodeGenerator&, RegisterID*); | |
779 | JSC_COMMON_BYTECODE_INTRINSICS_EACH_NAME(JSC_DECLARE_BYTECODE_INTRINSIC_FUNCTIONS) | |
780 | #undef JSC_DECLARE_BYTECODE_INTRINSIC_FUNCTIONS | |
781 | ||
782 | private: | |
783 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; | |
784 | ||
785 | EmitterType m_emitter; | |
786 | const Identifier& m_ident; | |
787 | ArgumentsNode* m_args; | |
788 | }; | |
789 | ||
ba379fdc A |
790 | class CallFunctionCallDotNode : public FunctionCallDotNode { |
791 | public: | |
81345200 | 792 | CallFunctionCallDotNode(const JSTokenLocation&, ExpressionNode* base, const Identifier&, ArgumentsNode*, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd); |
9dae56ea A |
793 | |
794 | private: | |
81345200 | 795 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc A |
796 | }; |
797 | ||
798 | class ApplyFunctionCallDotNode : public FunctionCallDotNode { | |
799 | public: | |
81345200 | 800 | ApplyFunctionCallDotNode(const JSTokenLocation&, ExpressionNode* base, const Identifier&, ArgumentsNode*, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd); |
ba379fdc A |
801 | |
802 | private: | |
81345200 | 803 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
9dae56ea A |
804 | }; |
805 | ||
9dae56ea A |
806 | class DeleteResolveNode : public ExpressionNode, public ThrowableExpressionData { |
807 | public: | |
81345200 | 808 | DeleteResolveNode(const JSTokenLocation&, const Identifier&, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd); |
9dae56ea A |
809 | |
810 | private: | |
81345200 | 811 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc | 812 | |
f9bf01c6 | 813 | const Identifier& m_ident; |
9dae56ea A |
814 | }; |
815 | ||
816 | class DeleteBracketNode : public ExpressionNode, public ThrowableExpressionData { | |
817 | public: | |
81345200 | 818 | DeleteBracketNode(const JSTokenLocation&, ExpressionNode* base, ExpressionNode* subscript, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd); |
9dae56ea A |
819 | |
820 | private: | |
81345200 | 821 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc A |
822 | |
823 | ExpressionNode* m_base; | |
824 | ExpressionNode* m_subscript; | |
9dae56ea A |
825 | }; |
826 | ||
827 | class DeleteDotNode : public ExpressionNode, public ThrowableExpressionData { | |
828 | public: | |
81345200 | 829 | DeleteDotNode(const JSTokenLocation&, ExpressionNode* base, const Identifier&, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd); |
9dae56ea A |
830 | |
831 | private: | |
81345200 | 832 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc A |
833 | |
834 | ExpressionNode* m_base; | |
f9bf01c6 | 835 | const Identifier& m_ident; |
9dae56ea A |
836 | }; |
837 | ||
838 | class DeleteValueNode : public ExpressionNode { | |
839 | public: | |
93a37866 | 840 | DeleteValueNode(const JSTokenLocation&, ExpressionNode*); |
9dae56ea A |
841 | |
842 | private: | |
81345200 | 843 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc A |
844 | |
845 | ExpressionNode* m_expr; | |
9dae56ea A |
846 | }; |
847 | ||
848 | class VoidNode : public ExpressionNode { | |
849 | public: | |
93a37866 | 850 | VoidNode(const JSTokenLocation&, ExpressionNode*); |
9dae56ea A |
851 | |
852 | private: | |
81345200 | 853 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc A |
854 | |
855 | ExpressionNode* m_expr; | |
9dae56ea A |
856 | }; |
857 | ||
858 | class TypeOfResolveNode : public ExpressionNode { | |
859 | public: | |
93a37866 | 860 | TypeOfResolveNode(const JSTokenLocation&, const Identifier&); |
9dae56ea | 861 | |
ba379fdc | 862 | const Identifier& identifier() const { return m_ident; } |
9dae56ea A |
863 | |
864 | private: | |
81345200 | 865 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc | 866 | |
f9bf01c6 | 867 | const Identifier& m_ident; |
9dae56ea A |
868 | }; |
869 | ||
870 | class TypeOfValueNode : public ExpressionNode { | |
871 | public: | |
93a37866 | 872 | TypeOfValueNode(const JSTokenLocation&, ExpressionNode*); |
9dae56ea A |
873 | |
874 | private: | |
81345200 | 875 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc A |
876 | |
877 | ExpressionNode* m_expr; | |
9dae56ea A |
878 | }; |
879 | ||
93a37866 | 880 | class PrefixNode : public ExpressionNode, public ThrowablePrefixedSubExpressionData { |
9dae56ea | 881 | public: |
81345200 | 882 | PrefixNode(const JSTokenLocation&, ExpressionNode*, Operator, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd); |
9dae56ea | 883 | |
93a37866 | 884 | protected: |
81345200 | 885 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
93a37866 A |
886 | virtual RegisterID* emitResolve(BytecodeGenerator&, RegisterID* = 0); |
887 | virtual RegisterID* emitBracket(BytecodeGenerator&, RegisterID* = 0); | |
888 | virtual RegisterID* emitDot(BytecodeGenerator&, RegisterID* = 0); | |
ba379fdc | 889 | |
93a37866 | 890 | ExpressionNode* m_expr; |
9dae56ea A |
891 | Operator m_operator; |
892 | }; | |
893 | ||
93a37866 | 894 | class PostfixNode : public PrefixNode { |
9dae56ea | 895 | public: |
81345200 | 896 | PostfixNode(const JSTokenLocation&, ExpressionNode*, Operator, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd); |
9dae56ea A |
897 | |
898 | private: | |
81345200 A |
899 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
900 | virtual RegisterID* emitResolve(BytecodeGenerator&, RegisterID* = 0) override; | |
901 | virtual RegisterID* emitBracket(BytecodeGenerator&, RegisterID* = 0) override; | |
902 | virtual RegisterID* emitDot(BytecodeGenerator&, RegisterID* = 0) override; | |
9dae56ea A |
903 | }; |
904 | ||
905 | class UnaryOpNode : public ExpressionNode { | |
906 | public: | |
93a37866 | 907 | UnaryOpNode(const JSTokenLocation&, ResultType, ExpressionNode*, OpcodeID); |
9dae56ea | 908 | |
ba379fdc A |
909 | protected: |
910 | ExpressionNode* expr() { return m_expr; } | |
f9bf01c6 | 911 | const ExpressionNode* expr() const { return m_expr; } |
9dae56ea | 912 | |
ba379fdc | 913 | private: |
81345200 | 914 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
9dae56ea | 915 | |
ba379fdc | 916 | OpcodeID opcodeID() const { return m_opcodeID; } |
9dae56ea | 917 | |
ba379fdc A |
918 | ExpressionNode* m_expr; |
919 | OpcodeID m_opcodeID; | |
9dae56ea A |
920 | }; |
921 | ||
922 | class UnaryPlusNode : public UnaryOpNode { | |
923 | public: | |
93a37866 | 924 | UnaryPlusNode(const JSTokenLocation&, ExpressionNode*); |
9dae56ea | 925 | |
ba379fdc | 926 | private: |
81345200 | 927 | virtual ExpressionNode* stripUnaryPlus() override { return expr(); } |
9dae56ea A |
928 | }; |
929 | ||
930 | class NegateNode : public UnaryOpNode { | |
931 | public: | |
93a37866 | 932 | NegateNode(const JSTokenLocation&, ExpressionNode*); |
9dae56ea A |
933 | }; |
934 | ||
6fe7ccc8 | 935 | class BitwiseNotNode : public ExpressionNode { |
9dae56ea | 936 | public: |
93a37866 | 937 | BitwiseNotNode(const JSTokenLocation&, ExpressionNode*); |
6fe7ccc8 A |
938 | |
939 | protected: | |
940 | ExpressionNode* expr() { return m_expr; } | |
941 | const ExpressionNode* expr() const { return m_expr; } | |
942 | ||
943 | private: | |
81345200 | 944 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
9dae56ea | 945 | |
6fe7ccc8 A |
946 | ExpressionNode* m_expr; |
947 | }; | |
948 | ||
9dae56ea A |
949 | class LogicalNotNode : public UnaryOpNode { |
950 | public: | |
93a37866 | 951 | LogicalNotNode(const JSTokenLocation&, ExpressionNode*); |
f9bf01c6 | 952 | private: |
81345200 | 953 | virtual void emitBytecodeInConditionContext(BytecodeGenerator&, Label* trueTarget, Label* falseTarget, FallThroughMode) override; |
9dae56ea A |
954 | }; |
955 | ||
956 | class BinaryOpNode : public ExpressionNode { | |
957 | public: | |
93a37866 A |
958 | BinaryOpNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments); |
959 | BinaryOpNode(const JSTokenLocation&, ResultType, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments); | |
9dae56ea | 960 | |
f9bf01c6 | 961 | RegisterID* emitStrcat(BytecodeGenerator& generator, RegisterID* destination, RegisterID* lhs = 0, ReadModifyResolveNode* emitExpressionInfoForMe = 0); |
81345200 | 962 | virtual void emitBytecodeInConditionContext(BytecodeGenerator&, Label* trueTarget, Label* falseTarget, FallThroughMode) override; |
9dae56ea | 963 | |
14957cd0 A |
964 | ExpressionNode* lhs() { return m_expr1; }; |
965 | ExpressionNode* rhs() { return m_expr2; }; | |
966 | ||
ba379fdc | 967 | private: |
93a37866 | 968 | void tryFoldToBranch(BytecodeGenerator&, TriState& branchCondition, ExpressionNode*& branchExpression); |
81345200 | 969 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
9dae56ea | 970 | |
ba379fdc A |
971 | protected: |
972 | OpcodeID opcodeID() const { return m_opcodeID; } | |
9dae56ea A |
973 | |
974 | protected: | |
ba379fdc A |
975 | ExpressionNode* m_expr1; |
976 | ExpressionNode* m_expr2; | |
977 | private: | |
978 | OpcodeID m_opcodeID; | |
979 | protected: | |
9dae56ea A |
980 | bool m_rightHasAssignments; |
981 | }; | |
982 | ||
9dae56ea A |
983 | class MultNode : public BinaryOpNode { |
984 | public: | |
93a37866 | 985 | MultNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
986 | }; |
987 | ||
988 | class DivNode : public BinaryOpNode { | |
989 | public: | |
93a37866 | 990 | DivNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
991 | }; |
992 | ||
993 | class ModNode : public BinaryOpNode { | |
994 | public: | |
93a37866 | 995 | ModNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
996 | }; |
997 | ||
998 | class AddNode : public BinaryOpNode { | |
999 | public: | |
93a37866 | 1000 | AddNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea | 1001 | |
81345200 | 1002 | virtual bool isAdd() const override { return true; } |
9dae56ea A |
1003 | }; |
1004 | ||
1005 | class SubNode : public BinaryOpNode { | |
1006 | public: | |
93a37866 | 1007 | SubNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
14957cd0 | 1008 | |
81345200 | 1009 | virtual bool isSubtract() const override { return true; } |
9dae56ea A |
1010 | }; |
1011 | ||
1012 | class LeftShiftNode : public BinaryOpNode { | |
1013 | public: | |
93a37866 | 1014 | LeftShiftNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
1015 | }; |
1016 | ||
1017 | class RightShiftNode : public BinaryOpNode { | |
1018 | public: | |
93a37866 | 1019 | RightShiftNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
1020 | }; |
1021 | ||
1022 | class UnsignedRightShiftNode : public BinaryOpNode { | |
1023 | public: | |
93a37866 | 1024 | UnsignedRightShiftNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
1025 | }; |
1026 | ||
1027 | class LessNode : public BinaryOpNode { | |
1028 | public: | |
93a37866 | 1029 | LessNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
1030 | }; |
1031 | ||
6fe7ccc8 | 1032 | class GreaterNode : public BinaryOpNode { |
9dae56ea | 1033 | public: |
93a37866 | 1034 | GreaterNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
1035 | }; |
1036 | ||
1037 | class LessEqNode : public BinaryOpNode { | |
1038 | public: | |
93a37866 | 1039 | LessEqNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
1040 | }; |
1041 | ||
6fe7ccc8 | 1042 | class GreaterEqNode : public BinaryOpNode { |
9dae56ea | 1043 | public: |
93a37866 | 1044 | GreaterEqNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
1045 | }; |
1046 | ||
1047 | class ThrowableBinaryOpNode : public BinaryOpNode, public ThrowableExpressionData { | |
1048 | public: | |
93a37866 A |
1049 | ThrowableBinaryOpNode(const JSTokenLocation&, ResultType, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments); |
1050 | ThrowableBinaryOpNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments); | |
ba379fdc A |
1051 | |
1052 | private: | |
81345200 | 1053 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
9dae56ea A |
1054 | }; |
1055 | ||
1056 | class InstanceOfNode : public ThrowableBinaryOpNode { | |
1057 | public: | |
93a37866 | 1058 | InstanceOfNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea | 1059 | |
ba379fdc | 1060 | private: |
81345200 | 1061 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
9dae56ea A |
1062 | }; |
1063 | ||
1064 | class InNode : public ThrowableBinaryOpNode { | |
1065 | public: | |
93a37866 | 1066 | InNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
1067 | }; |
1068 | ||
1069 | class EqualNode : public BinaryOpNode { | |
1070 | public: | |
93a37866 | 1071 | EqualNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea | 1072 | |
ba379fdc | 1073 | private: |
81345200 | 1074 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
9dae56ea A |
1075 | }; |
1076 | ||
1077 | class NotEqualNode : public BinaryOpNode { | |
1078 | public: | |
93a37866 | 1079 | NotEqualNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
1080 | }; |
1081 | ||
1082 | class StrictEqualNode : public BinaryOpNode { | |
1083 | public: | |
93a37866 | 1084 | StrictEqualNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea | 1085 | |
ba379fdc | 1086 | private: |
81345200 | 1087 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
9dae56ea A |
1088 | }; |
1089 | ||
1090 | class NotStrictEqualNode : public BinaryOpNode { | |
1091 | public: | |
93a37866 | 1092 | NotStrictEqualNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
1093 | }; |
1094 | ||
1095 | class BitAndNode : public BinaryOpNode { | |
1096 | public: | |
93a37866 | 1097 | BitAndNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
1098 | }; |
1099 | ||
1100 | class BitOrNode : public BinaryOpNode { | |
1101 | public: | |
93a37866 | 1102 | BitOrNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
1103 | }; |
1104 | ||
1105 | class BitXOrNode : public BinaryOpNode { | |
1106 | public: | |
93a37866 | 1107 | BitXOrNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments); |
9dae56ea A |
1108 | }; |
1109 | ||
ba379fdc | 1110 | // m_expr1 && m_expr2, m_expr1 || m_expr2 |
9dae56ea A |
1111 | class LogicalOpNode : public ExpressionNode { |
1112 | public: | |
93a37866 | 1113 | LogicalOpNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, LogicalOperator); |
9dae56ea A |
1114 | |
1115 | private: | |
81345200 A |
1116 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
1117 | virtual void emitBytecodeInConditionContext(BytecodeGenerator&, Label* trueTarget, Label* falseTarget, FallThroughMode) override; | |
ba379fdc A |
1118 | |
1119 | ExpressionNode* m_expr1; | |
1120 | ExpressionNode* m_expr2; | |
9dae56ea A |
1121 | LogicalOperator m_operator; |
1122 | }; | |
1123 | ||
ba379fdc | 1124 | // The ternary operator, "m_logical ? m_expr1 : m_expr2" |
9dae56ea A |
1125 | class ConditionalNode : public ExpressionNode { |
1126 | public: | |
93a37866 | 1127 | ConditionalNode(const JSTokenLocation&, ExpressionNode* logical, ExpressionNode* expr1, ExpressionNode* expr2); |
9dae56ea A |
1128 | |
1129 | private: | |
81345200 | 1130 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc A |
1131 | |
1132 | ExpressionNode* m_logical; | |
1133 | ExpressionNode* m_expr1; | |
1134 | ExpressionNode* m_expr2; | |
9dae56ea A |
1135 | }; |
1136 | ||
1137 | class ReadModifyResolveNode : public ExpressionNode, public ThrowableExpressionData { | |
1138 | public: | |
81345200 | 1139 | ReadModifyResolveNode(const JSTokenLocation&, const Identifier&, Operator, ExpressionNode* right, bool rightHasAssignments, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd); |
9dae56ea A |
1140 | |
1141 | private: | |
81345200 | 1142 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc | 1143 | |
f9bf01c6 | 1144 | const Identifier& m_ident; |
ba379fdc | 1145 | ExpressionNode* m_right; |
ba379fdc A |
1146 | Operator m_operator; |
1147 | bool m_rightHasAssignments; | |
9dae56ea A |
1148 | }; |
1149 | ||
1150 | class AssignResolveNode : public ExpressionNode, public ThrowableExpressionData { | |
1151 | public: | |
93a37866 | 1152 | AssignResolveNode(const JSTokenLocation&, const Identifier&, ExpressionNode* right); |
9dae56ea A |
1153 | |
1154 | private: | |
81345200 | 1155 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc | 1156 | |
f9bf01c6 | 1157 | const Identifier& m_ident; |
ba379fdc | 1158 | ExpressionNode* m_right; |
9dae56ea A |
1159 | }; |
1160 | ||
1161 | class ReadModifyBracketNode : public ExpressionNode, public ThrowableSubExpressionData { | |
1162 | public: | |
81345200 | 1163 | ReadModifyBracketNode(const JSTokenLocation&, ExpressionNode* base, ExpressionNode* subscript, Operator, ExpressionNode* right, bool subscriptHasAssignments, bool rightHasAssignments, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd); |
9dae56ea A |
1164 | |
1165 | private: | |
81345200 | 1166 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc A |
1167 | |
1168 | ExpressionNode* m_base; | |
1169 | ExpressionNode* m_subscript; | |
1170 | ExpressionNode* m_right; | |
81345200 | 1171 | unsigned m_operator : 30; |
9dae56ea A |
1172 | bool m_subscriptHasAssignments : 1; |
1173 | bool m_rightHasAssignments : 1; | |
1174 | }; | |
1175 | ||
1176 | class AssignBracketNode : public ExpressionNode, public ThrowableExpressionData { | |
1177 | public: | |
81345200 | 1178 | AssignBracketNode(const JSTokenLocation&, ExpressionNode* base, ExpressionNode* subscript, ExpressionNode* right, bool subscriptHasAssignments, bool rightHasAssignments, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd); |
9dae56ea A |
1179 | |
1180 | private: | |
81345200 | 1181 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc A |
1182 | |
1183 | ExpressionNode* m_base; | |
1184 | ExpressionNode* m_subscript; | |
1185 | ExpressionNode* m_right; | |
9dae56ea A |
1186 | bool m_subscriptHasAssignments : 1; |
1187 | bool m_rightHasAssignments : 1; | |
1188 | }; | |
1189 | ||
1190 | class AssignDotNode : public ExpressionNode, public ThrowableExpressionData { | |
1191 | public: | |
81345200 | 1192 | AssignDotNode(const JSTokenLocation&, ExpressionNode* base, const Identifier&, ExpressionNode* right, bool rightHasAssignments, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd); |
9dae56ea A |
1193 | |
1194 | private: | |
81345200 | 1195 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc A |
1196 | |
1197 | ExpressionNode* m_base; | |
f9bf01c6 | 1198 | const Identifier& m_ident; |
ba379fdc | 1199 | ExpressionNode* m_right; |
9dae56ea A |
1200 | bool m_rightHasAssignments; |
1201 | }; | |
1202 | ||
1203 | class ReadModifyDotNode : public ExpressionNode, public ThrowableSubExpressionData { | |
1204 | public: | |
81345200 | 1205 | ReadModifyDotNode(const JSTokenLocation&, ExpressionNode* base, const Identifier&, Operator, ExpressionNode* right, bool rightHasAssignments, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd); |
9dae56ea A |
1206 | |
1207 | private: | |
81345200 | 1208 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc A |
1209 | |
1210 | ExpressionNode* m_base; | |
f9bf01c6 | 1211 | const Identifier& m_ident; |
ba379fdc | 1212 | ExpressionNode* m_right; |
81345200 | 1213 | unsigned m_operator : 31; |
9dae56ea A |
1214 | bool m_rightHasAssignments : 1; |
1215 | }; | |
1216 | ||
1217 | class AssignErrorNode : public ExpressionNode, public ThrowableExpressionData { | |
1218 | public: | |
81345200 | 1219 | AssignErrorNode(const JSTokenLocation&, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd); |
9dae56ea A |
1220 | |
1221 | private: | |
81345200 | 1222 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
9dae56ea | 1223 | }; |
ba379fdc | 1224 | |
ed1e77d3 | 1225 | class CommaNode final : public ExpressionNode { |
9dae56ea | 1226 | public: |
ed1e77d3 | 1227 | CommaNode(const JSTokenLocation&, ExpressionNode*); |
9dae56ea | 1228 | |
ed1e77d3 A |
1229 | void setNext(CommaNode* next) { m_next = next; } |
1230 | CommaNode* next() { return m_next; } | |
9dae56ea A |
1231 | |
1232 | private: | |
81345200 A |
1233 | virtual bool isCommaNode() const override { return true; } |
1234 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; | |
ba379fdc | 1235 | |
ed1e77d3 A |
1236 | ExpressionNode* m_expr; |
1237 | CommaNode* m_next; | |
9dae56ea A |
1238 | }; |
1239 | ||
9dae56ea A |
1240 | class ConstDeclNode : public ExpressionNode { |
1241 | public: | |
93a37866 | 1242 | ConstDeclNode(const JSTokenLocation&, const Identifier&, ExpressionNode*); |
ba379fdc A |
1243 | |
1244 | bool hasInitializer() const { return m_init; } | |
1245 | const Identifier& ident() { return m_ident; } | |
9dae56ea | 1246 | |
ba379fdc | 1247 | private: |
81345200 | 1248 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc | 1249 | virtual RegisterID* emitCodeSingle(BytecodeGenerator&); |
9dae56ea | 1250 | |
f9bf01c6 | 1251 | const Identifier& m_ident; |
9dae56ea | 1252 | |
9dae56ea | 1253 | public: |
ba379fdc | 1254 | ConstDeclNode* m_next; |
9dae56ea | 1255 | |
ba379fdc A |
1256 | private: |
1257 | ExpressionNode* m_init; | |
1258 | }; | |
9dae56ea | 1259 | |
ba379fdc A |
1260 | class ConstStatementNode : public StatementNode { |
1261 | public: | |
93a37866 | 1262 | ConstStatementNode(const JSTokenLocation&, ConstDeclNode* next); |
9dae56ea A |
1263 | |
1264 | private: | |
81345200 | 1265 | virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc A |
1266 | |
1267 | ConstDeclNode* m_next; | |
9dae56ea A |
1268 | }; |
1269 | ||
ed1e77d3 | 1270 | class SourceElements final : public ParserArenaFreeable { |
9dae56ea | 1271 | public: |
6fe7ccc8 | 1272 | SourceElements(); |
9dae56ea | 1273 | |
ba379fdc | 1274 | void append(StatementNode*); |
f9bf01c6 A |
1275 | |
1276 | StatementNode* singleStatement() const; | |
1277 | StatementNode* lastStatement() const; | |
1278 | ||
1279 | void emitBytecode(BytecodeGenerator&, RegisterID* destination); | |
9dae56ea A |
1280 | |
1281 | private: | |
ed1e77d3 A |
1282 | StatementNode* m_head; |
1283 | StatementNode* m_tail; | |
9dae56ea A |
1284 | }; |
1285 | ||
1286 | class BlockNode : public StatementNode { | |
1287 | public: | |
93a37866 | 1288 | BlockNode(const JSTokenLocation&, SourceElements* = 0); |
9dae56ea | 1289 | |
14957cd0 | 1290 | StatementNode* singleStatement() const; |
f9bf01c6 | 1291 | StatementNode* lastStatement() const; |
9dae56ea | 1292 | |
9dae56ea | 1293 | private: |
81345200 | 1294 | virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc | 1295 | |
81345200 | 1296 | virtual bool isBlock() const override { return true; } |
ba379fdc | 1297 | |
f9bf01c6 | 1298 | SourceElements* m_statements; |
9dae56ea A |
1299 | }; |
1300 | ||
1301 | class EmptyStatementNode : public StatementNode { | |
1302 | public: | |
93a37866 | 1303 | EmptyStatementNode(const JSTokenLocation&); |
9dae56ea | 1304 | |
ba379fdc | 1305 | private: |
81345200 | 1306 | virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
9dae56ea | 1307 | |
81345200 | 1308 | virtual bool isEmptyStatement() const override { return true; } |
9dae56ea A |
1309 | }; |
1310 | ||
1311 | class DebuggerStatementNode : public StatementNode { | |
1312 | public: | |
93a37866 | 1313 | DebuggerStatementNode(const JSTokenLocation&); |
9dae56ea | 1314 | |
ba379fdc | 1315 | private: |
81345200 | 1316 | virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
9dae56ea A |
1317 | }; |
1318 | ||
1319 | class ExprStatementNode : public StatementNode { | |
1320 | public: | |
93a37866 | 1321 | ExprStatementNode(const JSTokenLocation&, ExpressionNode*); |
9dae56ea | 1322 | |
ba379fdc | 1323 | ExpressionNode* expr() const { return m_expr; } |
9dae56ea | 1324 | |
ba379fdc | 1325 | private: |
81345200 | 1326 | virtual bool isExprStatement() const override { return true; } |
9dae56ea | 1327 | |
81345200 | 1328 | virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
9dae56ea | 1329 | |
ba379fdc | 1330 | ExpressionNode* m_expr; |
9dae56ea A |
1331 | }; |
1332 | ||
1333 | class VarStatementNode : public StatementNode { | |
1334 | public: | |
93a37866 | 1335 | VarStatementNode(const JSTokenLocation&, ExpressionNode*); |
9dae56ea | 1336 | private: |
81345200 | 1337 | virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc A |
1338 | |
1339 | ExpressionNode* m_expr; | |
9dae56ea A |
1340 | }; |
1341 | ||
ed1e77d3 A |
1342 | class EmptyVarExpression : public ExpressionNode { |
1343 | public: | |
1344 | EmptyVarExpression(const JSTokenLocation&, const Identifier&); | |
1345 | ||
1346 | private: | |
1347 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; | |
1348 | ||
1349 | const Identifier& m_ident; | |
1350 | }; | |
1351 | ||
1352 | ||
93a37866 | 1353 | class IfElseNode : public StatementNode { |
9dae56ea | 1354 | public: |
93a37866 | 1355 | IfElseNode(const JSTokenLocation&, ExpressionNode* condition, StatementNode* ifBlock, StatementNode* elseBlock); |
9dae56ea | 1356 | |
93a37866 | 1357 | private: |
81345200 | 1358 | virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
93a37866 A |
1359 | bool tryFoldBreakAndContinue(BytecodeGenerator&, StatementNode* ifBlock, |
1360 | Label*& trueTarget, FallThroughMode&); | |
ba379fdc A |
1361 | |
1362 | ExpressionNode* m_condition; | |
1363 | StatementNode* m_ifBlock; | |
ba379fdc | 1364 | StatementNode* m_elseBlock; |
9dae56ea A |
1365 | }; |
1366 | ||
1367 | class DoWhileNode : public StatementNode { | |
1368 | public: | |
93a37866 | 1369 | DoWhileNode(const JSTokenLocation&, StatementNode*, ExpressionNode*); |
9dae56ea A |
1370 | |
1371 | private: | |
81345200 | 1372 | virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc A |
1373 | |
1374 | StatementNode* m_statement; | |
1375 | ExpressionNode* m_expr; | |
9dae56ea A |
1376 | }; |
1377 | ||
1378 | class WhileNode : public StatementNode { | |
1379 | public: | |
93a37866 | 1380 | WhileNode(const JSTokenLocation&, ExpressionNode*, StatementNode*); |
9dae56ea A |
1381 | |
1382 | private: | |
81345200 | 1383 | virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc A |
1384 | |
1385 | ExpressionNode* m_expr; | |
1386 | StatementNode* m_statement; | |
9dae56ea A |
1387 | }; |
1388 | ||
1389 | class ForNode : public StatementNode { | |
1390 | public: | |
93a37866 | 1391 | ForNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, ExpressionNode* expr3, StatementNode*); |
9dae56ea A |
1392 | |
1393 | private: | |
81345200 | 1394 | virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc A |
1395 | |
1396 | ExpressionNode* m_expr1; | |
1397 | ExpressionNode* m_expr2; | |
1398 | ExpressionNode* m_expr3; | |
1399 | StatementNode* m_statement; | |
9dae56ea | 1400 | }; |
81345200 | 1401 | |
ed1e77d3 | 1402 | class DestructuringPatternNode; |
81345200 A |
1403 | |
1404 | class EnumerationNode : public StatementNode, public ThrowableExpressionData { | |
9dae56ea | 1405 | public: |
81345200 | 1406 | EnumerationNode(const JSTokenLocation&, ExpressionNode*, ExpressionNode*, StatementNode*); |
81345200 A |
1407 | |
1408 | protected: | |
ba379fdc A |
1409 | ExpressionNode* m_lexpr; |
1410 | ExpressionNode* m_expr; | |
1411 | StatementNode* m_statement; | |
9dae56ea | 1412 | }; |
81345200 A |
1413 | |
1414 | class ForInNode : public EnumerationNode { | |
1415 | public: | |
1416 | ForInNode(const JSTokenLocation&, ExpressionNode*, ExpressionNode*, StatementNode*); | |
81345200 A |
1417 | |
1418 | private: | |
ed1e77d3 A |
1419 | RegisterID* tryGetBoundLocal(BytecodeGenerator&); |
1420 | void emitLoopHeader(BytecodeGenerator&, RegisterID* propertyName); | |
1421 | void emitMultiLoopBytecode(BytecodeGenerator&, RegisterID* dst); | |
1422 | ||
81345200 A |
1423 | virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
1424 | }; | |
1425 | ||
1426 | class ForOfNode : public EnumerationNode { | |
1427 | public: | |
1428 | ForOfNode(const JSTokenLocation&, ExpressionNode*, ExpressionNode*, StatementNode*); | |
81345200 A |
1429 | |
1430 | private: | |
1431 | virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; | |
1432 | }; | |
9dae56ea A |
1433 | |
1434 | class ContinueNode : public StatementNode, public ThrowableExpressionData { | |
1435 | public: | |
93a37866 A |
1436 | ContinueNode(const JSTokenLocation&, const Identifier&); |
1437 | Label* trivialTarget(BytecodeGenerator&); | |
9dae56ea | 1438 | |
9dae56ea | 1439 | private: |
81345200 A |
1440 | virtual bool isContinue() const override { return true; } |
1441 | virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; | |
ba379fdc | 1442 | |
f9bf01c6 | 1443 | const Identifier& m_ident; |
9dae56ea A |
1444 | }; |
1445 | ||
1446 | class BreakNode : public StatementNode, public ThrowableExpressionData { | |
1447 | public: | |
93a37866 A |
1448 | BreakNode(const JSTokenLocation&, const Identifier&); |
1449 | Label* trivialTarget(BytecodeGenerator&); | |
9dae56ea | 1450 | |
9dae56ea | 1451 | private: |
81345200 A |
1452 | virtual bool isBreak() const override { return true; } |
1453 | virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; | |
ba379fdc | 1454 | |
f9bf01c6 | 1455 | const Identifier& m_ident; |
9dae56ea A |
1456 | }; |
1457 | ||
1458 | class ReturnNode : public StatementNode, public ThrowableExpressionData { | |
1459 | public: | |
93a37866 | 1460 | ReturnNode(const JSTokenLocation&, ExpressionNode* value); |
9dae56ea | 1461 | |
14957cd0 A |
1462 | ExpressionNode* value() { return m_value; } |
1463 | ||
ba379fdc | 1464 | private: |
81345200 | 1465 | virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
9dae56ea | 1466 | |
81345200 | 1467 | virtual bool isReturnNode() const override { return true; } |
9dae56ea | 1468 | |
ba379fdc | 1469 | ExpressionNode* m_value; |
9dae56ea A |
1470 | }; |
1471 | ||
1472 | class WithNode : public StatementNode { | |
1473 | public: | |
81345200 | 1474 | WithNode(const JSTokenLocation&, ExpressionNode*, StatementNode*, const JSTextPosition& divot, uint32_t expressionLength); |
9dae56ea A |
1475 | |
1476 | private: | |
81345200 | 1477 | virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc A |
1478 | |
1479 | ExpressionNode* m_expr; | |
1480 | StatementNode* m_statement; | |
81345200 | 1481 | JSTextPosition m_divot; |
9dae56ea A |
1482 | uint32_t m_expressionLength; |
1483 | }; | |
1484 | ||
1485 | class LabelNode : public StatementNode, public ThrowableExpressionData { | |
1486 | public: | |
93a37866 | 1487 | LabelNode(const JSTokenLocation&, const Identifier& name, StatementNode*); |
9dae56ea A |
1488 | |
1489 | private: | |
81345200 | 1490 | virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc | 1491 | |
f9bf01c6 | 1492 | const Identifier& m_name; |
ba379fdc | 1493 | StatementNode* m_statement; |
9dae56ea A |
1494 | }; |
1495 | ||
1496 | class ThrowNode : public StatementNode, public ThrowableExpressionData { | |
1497 | public: | |
93a37866 | 1498 | ThrowNode(const JSTokenLocation&, ExpressionNode*); |
9dae56ea A |
1499 | |
1500 | private: | |
81345200 | 1501 | virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc A |
1502 | |
1503 | ExpressionNode* m_expr; | |
9dae56ea A |
1504 | }; |
1505 | ||
1506 | class TryNode : public StatementNode { | |
1507 | public: | |
93a37866 | 1508 | TryNode(const JSTokenLocation&, StatementNode* tryBlock, const Identifier& exceptionIdent, StatementNode* catchBlock, StatementNode* finallyBlock); |
9dae56ea A |
1509 | |
1510 | private: | |
81345200 | 1511 | virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc A |
1512 | |
1513 | StatementNode* m_tryBlock; | |
ed1e77d3 | 1514 | const Identifier& m_thrownValueIdent; |
ba379fdc A |
1515 | StatementNode* m_catchBlock; |
1516 | StatementNode* m_finallyBlock; | |
9dae56ea A |
1517 | }; |
1518 | ||
81345200 | 1519 | class ParameterNode : public ParserArenaDeletable { |
9dae56ea | 1520 | public: |
ed1e77d3 A |
1521 | ParameterNode(PassRefPtr<DestructuringPatternNode>); |
1522 | ParameterNode(ParameterNode*, PassRefPtr<DestructuringPatternNode>); | |
9dae56ea | 1523 | |
ed1e77d3 | 1524 | DestructuringPatternNode* pattern() const { return m_pattern.get(); } |
ba379fdc | 1525 | ParameterNode* nextParam() const { return m_next; } |
9dae56ea A |
1526 | |
1527 | private: | |
ed1e77d3 | 1528 | RefPtr<DestructuringPatternNode> m_pattern; |
ba379fdc | 1529 | ParameterNode* m_next; |
9dae56ea A |
1530 | }; |
1531 | ||
ed1e77d3 | 1532 | class ScopeNode : public StatementNode, public ParserArenaRoot { |
9dae56ea A |
1533 | public: |
1534 | typedef DeclarationStacks::VarStack VarStack; | |
1535 | typedef DeclarationStacks::FunctionStack FunctionStack; | |
1536 | ||
ed1e77d3 A |
1537 | ScopeNode(ParserArena&, const JSTokenLocation& start, const JSTokenLocation& end, bool inStrictContext); |
1538 | ScopeNode(ParserArena&, const JSTokenLocation& start, const JSTokenLocation& end, const SourceCode&, SourceElements*, VarStack&, FunctionStack&, IdentifierSet&, CodeFeatures, int numConstants); | |
9dae56ea | 1539 | |
ed1e77d3 | 1540 | using ParserArenaRoot::operator new; |
9dae56ea A |
1541 | |
1542 | const SourceCode& source() const { return m_source; } | |
93a37866 | 1543 | const String& sourceURL() const { return m_source.provider()->url(); } |
6fe7ccc8 | 1544 | intptr_t sourceID() const { return m_source.providerID(); } |
9dae56ea | 1545 | |
93a37866 A |
1546 | int startLine() const { return m_startLineNumber; } |
1547 | int startStartOffset() const { return m_startStartOffset; } | |
1548 | int startLineStartOffset() const { return m_startLineStartOffset; } | |
1549 | ||
9dae56ea A |
1550 | void setFeatures(CodeFeatures features) { m_features = features; } |
1551 | CodeFeatures features() { return m_features; } | |
1552 | ||
1553 | bool usesEval() const { return m_features & EvalFeature; } | |
14957cd0 | 1554 | bool usesArguments() const { return (m_features & ArgumentsFeature) && !(m_features & ShadowsArgumentsFeature); } |
81345200 | 1555 | bool modifiesParameter() const { return m_features & ModifiedParameterFeature; } |
ed1e77d3 | 1556 | bool modifiesArguments() const { return m_features & (EvalFeature | ModifiedArgumentsFeature); } |
14957cd0 | 1557 | bool isStrictMode() const { return m_features & StrictModeFeature; } |
9dae56ea A |
1558 | void setUsesArguments() { m_features |= ArgumentsFeature; } |
1559 | bool usesThis() const { return m_features & ThisFeature; } | |
6fe7ccc8 A |
1560 | bool needsActivationForMoreThanVariables() const { return m_features & (EvalFeature | WithFeature | CatchFeature); } |
1561 | bool needsActivation() const { return (hasCapturedVariables()) || (m_features & (EvalFeature | WithFeature | CatchFeature)); } | |
1562 | bool hasCapturedVariables() const { return !!m_capturedVariables.size(); } | |
1563 | size_t capturedVariableCount() const { return m_capturedVariables.size(); } | |
81345200 | 1564 | const IdentifierSet& capturedVariables() const { return m_capturedVariables; } |
ed1e77d3 A |
1565 | bool captures(UniquedStringImpl* uid) { return m_capturedVariables.contains(uid); } |
1566 | bool captures(const Identifier& ident) { return captures(ident.impl()); } | |
9dae56ea | 1567 | |
6fe7ccc8 A |
1568 | VarStack& varStack() { return m_varStack; } |
1569 | FunctionStack& functionStack() { return m_functionStack; } | |
9dae56ea | 1570 | |
9dae56ea A |
1571 | int neededConstants() |
1572 | { | |
9dae56ea A |
1573 | // We may need 2 more constants than the count given by the parser, |
1574 | // because of the various uses of jsUndefined() and jsNull(). | |
6fe7ccc8 | 1575 | return m_numConstants + 2; |
9dae56ea A |
1576 | } |
1577 | ||
f9bf01c6 | 1578 | StatementNode* singleStatement() const; |
9dae56ea | 1579 | |
f9bf01c6 | 1580 | void emitStatementsBytecode(BytecodeGenerator&, RegisterID* destination); |
81345200 | 1581 | |
ed1e77d3 | 1582 | void setClosedVariables(Vector<RefPtr<UniquedStringImpl>>&&) { } |
ba379fdc | 1583 | |
9dae56ea | 1584 | protected: |
93a37866 A |
1585 | int m_startLineNumber; |
1586 | unsigned m_startStartOffset; | |
1587 | unsigned m_startLineStartOffset; | |
1588 | ||
9dae56ea | 1589 | private: |
9dae56ea A |
1590 | CodeFeatures m_features; |
1591 | SourceCode m_source; | |
6fe7ccc8 A |
1592 | VarStack m_varStack; |
1593 | FunctionStack m_functionStack; | |
1594 | int m_numConstants; | |
1595 | SourceElements* m_statements; | |
1596 | IdentifierSet m_capturedVariables; | |
9dae56ea A |
1597 | }; |
1598 | ||
1599 | class ProgramNode : public ScopeNode { | |
1600 | public: | |
ed1e77d3 | 1601 | ProgramNode(ParserArena&, const JSTokenLocation& start, const JSTokenLocation& end, unsigned startColumn, unsigned endColumn, SourceElements*, VarStack&, FunctionStack&, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants); |
93a37866 | 1602 | |
81345200 A |
1603 | unsigned startColumn() const { return m_startColumn; } |
1604 | unsigned endColumn() const { return m_endColumn; } | |
9dae56ea | 1605 | |
f9bf01c6 | 1606 | static const bool scopeIsFunction = false; |
ba379fdc | 1607 | |
ed1e77d3 A |
1608 | void setClosedVariables(Vector<RefPtr<UniquedStringImpl>>&&); |
1609 | const Vector<RefPtr<UniquedStringImpl>>& closedVariables() const { return m_closedVariables; } | |
93a37866 | 1610 | |
ed1e77d3 | 1611 | private: |
81345200 | 1612 | virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ed1e77d3 | 1613 | Vector<RefPtr<UniquedStringImpl>> m_closedVariables; |
93a37866 | 1614 | unsigned m_startColumn; |
81345200 | 1615 | unsigned m_endColumn; |
9dae56ea A |
1616 | }; |
1617 | ||
1618 | class EvalNode : public ScopeNode { | |
1619 | public: | |
ed1e77d3 | 1620 | EvalNode(ParserArena&, const JSTokenLocation& start, const JSTokenLocation& end, unsigned startColumn, unsigned endColumn, SourceElements*, VarStack&, FunctionStack&, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants); |
93a37866 | 1621 | |
81345200 A |
1622 | ALWAYS_INLINE unsigned startColumn() const { return 0; } |
1623 | unsigned endColumn() const { return m_endColumn; } | |
9dae56ea | 1624 | |
f9bf01c6 | 1625 | static const bool scopeIsFunction = false; |
ba379fdc | 1626 | |
9dae56ea | 1627 | private: |
81345200 | 1628 | virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
9dae56ea | 1629 | |
81345200 | 1630 | unsigned m_endColumn; |
f9bf01c6 | 1631 | }; |
ba379fdc | 1632 | |
93a37866 | 1633 | class FunctionParameters : public RefCounted<FunctionParameters> { |
14957cd0 | 1634 | WTF_MAKE_FAST_ALLOCATED; |
81345200 | 1635 | WTF_MAKE_NONCOPYABLE(FunctionParameters); |
f9bf01c6 | 1636 | public: |
ed1e77d3 | 1637 | static Ref<FunctionParameters> create(ParameterNode*); |
93a37866 A |
1638 | ~FunctionParameters(); |
1639 | ||
1640 | unsigned size() const { return m_size; } | |
ed1e77d3 | 1641 | DestructuringPatternNode* at(unsigned index) { ASSERT(index < m_size); return patterns()[index]; } |
f9bf01c6 A |
1642 | |
1643 | private: | |
93a37866 A |
1644 | FunctionParameters(ParameterNode*, unsigned size); |
1645 | ||
ed1e77d3 | 1646 | DestructuringPatternNode** patterns() { return &m_storage; } |
93a37866 A |
1647 | |
1648 | unsigned m_size; | |
ed1e77d3 | 1649 | DestructuringPatternNode* m_storage; |
9dae56ea A |
1650 | }; |
1651 | ||
ed1e77d3 | 1652 | class FunctionBodyNode final : public StatementNode, public ParserArenaDeletable { |
9dae56ea | 1653 | public: |
ed1e77d3 A |
1654 | using ParserArenaDeletable::operator new; |
1655 | ||
1656 | FunctionBodyNode( | |
1657 | ParserArena&, const JSTokenLocation& start, const JSTokenLocation& end, | |
1658 | unsigned startColumn, unsigned endColumn, int functionKeywordStart, | |
1659 | int functionNameStart, int parametersStart, bool isInStrictContext, | |
1660 | ConstructorKind); | |
9dae56ea | 1661 | |
f9bf01c6 | 1662 | FunctionParameters* parameters() const { return m_parameters.get(); } |
9dae56ea | 1663 | |
81345200 | 1664 | virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
9dae56ea | 1665 | |
81345200 | 1666 | void finishParsing(const SourceCode&, ParameterNode*, const Identifier&, FunctionMode); |
9dae56ea | 1667 | |
81345200 | 1668 | void overrideName(const Identifier& ident) { m_ident = ident; } |
f9bf01c6 | 1669 | const Identifier& ident() { return m_ident; } |
6fe7ccc8 A |
1670 | void setInferredName(const Identifier& inferredName) { ASSERT(!inferredName.isNull()); m_inferredName = inferredName; } |
1671 | const Identifier& inferredName() { return m_inferredName.isEmpty() ? m_ident : m_inferredName; } | |
9dae56ea | 1672 | |
81345200 | 1673 | FunctionMode functionMode() { return m_functionMode; } |
93a37866 | 1674 | |
81345200 | 1675 | int functionNameStart() const { return m_functionNameStart; } |
ed1e77d3 A |
1676 | int functionKeywordStart() const { return m_functionKeywordStart; } |
1677 | int parametersStart() const { return m_parametersStart; } | |
93a37866 | 1678 | unsigned startColumn() const { return m_startColumn; } |
81345200 A |
1679 | unsigned endColumn() const { return m_endColumn; } |
1680 | ||
1681 | void setEndPosition(JSTextPosition); | |
93a37866 | 1682 | |
ed1e77d3 | 1683 | const SourceCode& source() const { return m_source; } |
ba379fdc | 1684 | |
ed1e77d3 A |
1685 | int startStartOffset() const { return m_startStartOffset; } |
1686 | bool isInStrictContext() const { return m_isInStrictContext; } | |
1687 | ConstructorKind constructorKind() { return static_cast<ConstructorKind>(m_constructorKind); } | |
9dae56ea | 1688 | |
ed1e77d3 | 1689 | protected: |
f9bf01c6 | 1690 | Identifier m_ident; |
6fe7ccc8 | 1691 | Identifier m_inferredName; |
81345200 | 1692 | FunctionMode m_functionMode; |
f9bf01c6 | 1693 | RefPtr<FunctionParameters> m_parameters; |
ed1e77d3 A |
1694 | unsigned m_startColumn; |
1695 | unsigned m_endColumn; | |
1696 | int m_functionKeywordStart; | |
81345200 | 1697 | int m_functionNameStart; |
ed1e77d3 A |
1698 | int m_parametersStart; |
1699 | SourceCode m_source; | |
1700 | int m_startStartOffset; | |
1701 | unsigned m_isInStrictContext : 1; | |
1702 | unsigned m_constructorKind : 2; | |
1703 | }; | |
1704 | ||
1705 | class FunctionNode final : public ScopeNode { | |
1706 | public: | |
1707 | FunctionNode(ParserArena&, const JSTokenLocation& start, const JSTokenLocation& end, unsigned startColumn, unsigned endColumn, SourceElements*, VarStack&, FunctionStack&, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants); | |
1708 | ||
1709 | FunctionParameters* parameters() const { return m_parameters.get(); } | |
1710 | ||
1711 | virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; | |
1712 | ||
1713 | void finishParsing(PassRefPtr<FunctionParameters>, const Identifier&, FunctionMode); | |
1714 | ||
1715 | const Identifier& ident() { return m_ident; } | |
1716 | ||
1717 | FunctionMode functionMode() { return m_functionMode; } | |
1718 | ||
1719 | unsigned startColumn() const { return m_startColumn; } | |
1720 | unsigned endColumn() const { return m_endColumn; } | |
1721 | ||
1722 | static const bool scopeIsFunction = true; | |
1723 | ||
1724 | private: | |
1725 | Identifier m_ident; | |
1726 | FunctionMode m_functionMode; | |
1727 | RefPtr<FunctionParameters> m_parameters; | |
93a37866 | 1728 | unsigned m_startColumn; |
81345200 | 1729 | unsigned m_endColumn; |
9dae56ea A |
1730 | }; |
1731 | ||
f9bf01c6 | 1732 | class FuncExprNode : public ExpressionNode { |
9dae56ea | 1733 | public: |
93a37866 | 1734 | FuncExprNode(const JSTokenLocation&, const Identifier&, FunctionBodyNode*, const SourceCode&, ParameterNode* = 0); |
9dae56ea | 1735 | |
f9bf01c6 | 1736 | FunctionBodyNode* body() { return m_body; } |
9dae56ea A |
1737 | |
1738 | private: | |
81345200 | 1739 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc | 1740 | |
81345200 | 1741 | virtual bool isFuncExprNode() const override { return true; } |
ba379fdc | 1742 | |
f9bf01c6 | 1743 | FunctionBodyNode* m_body; |
9dae56ea A |
1744 | }; |
1745 | ||
ed1e77d3 A |
1746 | #if ENABLE(ES6_CLASS_SYNTAX) |
1747 | class ClassExprNode final : public ExpressionNode { | |
1748 | public: | |
1749 | ClassExprNode(const JSTokenLocation&, const Identifier&, ExpressionNode* constructorExpresssion, | |
1750 | ExpressionNode* parentClass, PropertyListNode* instanceMethods, PropertyListNode* staticMethods); | |
1751 | ||
1752 | const Identifier& name() { return m_name; } | |
1753 | ||
1754 | private: | |
1755 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; | |
1756 | ||
1757 | const Identifier& m_name; | |
1758 | ExpressionNode* m_constructorExpression; | |
1759 | ExpressionNode* m_classHeritage; | |
1760 | PropertyListNode* m_instanceMethods; | |
1761 | PropertyListNode* m_staticMethods; | |
1762 | }; | |
1763 | #endif | |
1764 | ||
1765 | class DestructuringPatternNode : public RefCounted<DestructuringPatternNode> { | |
1766 | WTF_MAKE_NONCOPYABLE(DestructuringPatternNode); | |
81345200 A |
1767 | WTF_MAKE_FAST_ALLOCATED; |
1768 | ||
1769 | public: | |
1770 | virtual void collectBoundIdentifiers(Vector<Identifier>&) const = 0; | |
1771 | virtual void bindValue(BytecodeGenerator&, RegisterID* source) const = 0; | |
1772 | virtual void toString(StringBuilder&) const = 0; | |
1773 | ||
1774 | virtual bool isBindingNode() const { return false; } | |
1775 | virtual RegisterID* emitDirectBinding(BytecodeGenerator&, RegisterID*, ExpressionNode*) { return 0; } | |
1776 | ||
ed1e77d3 | 1777 | virtual ~DestructuringPatternNode() = 0; |
81345200 A |
1778 | |
1779 | protected: | |
ed1e77d3 | 1780 | DestructuringPatternNode(); |
81345200 A |
1781 | }; |
1782 | ||
ed1e77d3 | 1783 | class ArrayPatternNode : public DestructuringPatternNode, public ThrowableExpressionData { |
81345200 | 1784 | public: |
ed1e77d3 A |
1785 | enum class BindingType { |
1786 | Elision, | |
1787 | Element, | |
1788 | RestElement | |
1789 | }; | |
1790 | ||
1791 | static Ref<ArrayPatternNode> create(); | |
1792 | void appendIndex(BindingType bindingType, const JSTokenLocation&, DestructuringPatternNode* node, ExpressionNode* defaultValue) | |
81345200 | 1793 | { |
ed1e77d3 | 1794 | m_targetPatterns.append({ bindingType, node, defaultValue }); |
81345200 A |
1795 | } |
1796 | ||
1797 | private: | |
ed1e77d3 A |
1798 | struct Entry { |
1799 | BindingType bindingType; | |
1800 | RefPtr<DestructuringPatternNode> pattern; | |
1801 | ExpressionNode* defaultValue; | |
1802 | }; | |
1803 | ArrayPatternNode(); | |
81345200 A |
1804 | virtual void collectBoundIdentifiers(Vector<Identifier>&) const override; |
1805 | virtual void bindValue(BytecodeGenerator&, RegisterID*) const override; | |
1806 | virtual RegisterID* emitDirectBinding(BytecodeGenerator&, RegisterID* dst, ExpressionNode*) override; | |
1807 | virtual void toString(StringBuilder&) const override; | |
1808 | ||
ed1e77d3 | 1809 | Vector<Entry> m_targetPatterns; |
81345200 A |
1810 | }; |
1811 | ||
ed1e77d3 | 1812 | class ObjectPatternNode : public DestructuringPatternNode { |
81345200 | 1813 | public: |
ed1e77d3 A |
1814 | static Ref<ObjectPatternNode> create(); |
1815 | void appendEntry(const JSTokenLocation&, const Identifier& identifier, bool wasString, DestructuringPatternNode* pattern, ExpressionNode* defaultValue) | |
81345200 | 1816 | { |
ed1e77d3 | 1817 | m_targetPatterns.append(Entry{ identifier, wasString, pattern, defaultValue }); |
81345200 A |
1818 | } |
1819 | ||
1820 | private: | |
ed1e77d3 | 1821 | ObjectPatternNode(); |
81345200 A |
1822 | virtual void collectBoundIdentifiers(Vector<Identifier>&) const override; |
1823 | virtual void bindValue(BytecodeGenerator&, RegisterID*) const override; | |
1824 | virtual void toString(StringBuilder&) const override; | |
1825 | struct Entry { | |
81345200 A |
1826 | Identifier propertyName; |
1827 | bool wasString; | |
ed1e77d3 A |
1828 | RefPtr<DestructuringPatternNode> pattern; |
1829 | ExpressionNode* defaultValue; | |
81345200 A |
1830 | }; |
1831 | Vector<Entry> m_targetPatterns; | |
1832 | }; | |
1833 | ||
ed1e77d3 | 1834 | class BindingNode : public DestructuringPatternNode { |
81345200 | 1835 | public: |
ed1e77d3 | 1836 | static Ref<BindingNode> create(const Identifier& boundProperty, const JSTextPosition& start, const JSTextPosition& end); |
81345200 A |
1837 | const Identifier& boundProperty() const { return m_boundProperty; } |
1838 | ||
1839 | const JSTextPosition& divotStart() const { return m_divotStart; } | |
1840 | const JSTextPosition& divotEnd() const { return m_divotEnd; } | |
1841 | ||
1842 | private: | |
ed1e77d3 | 1843 | BindingNode(const Identifier& boundProperty, const JSTextPosition& start, const JSTextPosition& end); |
81345200 A |
1844 | |
1845 | virtual void collectBoundIdentifiers(Vector<Identifier>&) const override; | |
1846 | virtual void bindValue(BytecodeGenerator&, RegisterID*) const override; | |
1847 | virtual void toString(StringBuilder&) const override; | |
1848 | ||
1849 | virtual bool isBindingNode() const override { return true; } | |
1850 | ||
1851 | JSTextPosition m_divotStart; | |
1852 | JSTextPosition m_divotEnd; | |
1853 | Identifier m_boundProperty; | |
1854 | }; | |
1855 | ||
ed1e77d3 | 1856 | class DestructuringAssignmentNode : public ExpressionNode, public ParserArenaDeletable { |
81345200 | 1857 | public: |
ed1e77d3 A |
1858 | DestructuringAssignmentNode(const JSTokenLocation&, PassRefPtr<DestructuringPatternNode>, ExpressionNode*); |
1859 | DestructuringPatternNode* bindings() { return m_bindings.get(); } | |
81345200 A |
1860 | |
1861 | using ParserArenaDeletable::operator new; | |
1862 | ||
1863 | private: | |
1864 | virtual bool isAssignmentLocation() const override { return true; } | |
ed1e77d3 | 1865 | virtual bool isDestructuringNode() const override { return true; } |
81345200 A |
1866 | virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
1867 | ||
ed1e77d3 | 1868 | RefPtr<DestructuringPatternNode> m_bindings; |
81345200 A |
1869 | ExpressionNode* m_initializer; |
1870 | }; | |
1871 | ||
f9bf01c6 | 1872 | class FuncDeclNode : public StatementNode { |
9dae56ea | 1873 | public: |
93a37866 | 1874 | FuncDeclNode(const JSTokenLocation&, const Identifier&, FunctionBodyNode*, const SourceCode&, ParameterNode* = 0); |
9dae56ea | 1875 | |
ed1e77d3 | 1876 | virtual bool isFuncDeclNode() const override { return true; } |
f9bf01c6 | 1877 | FunctionBodyNode* body() { return m_body; } |
9dae56ea A |
1878 | |
1879 | private: | |
81345200 | 1880 | virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc | 1881 | |
f9bf01c6 | 1882 | FunctionBodyNode* m_body; |
9dae56ea A |
1883 | }; |
1884 | ||
ed1e77d3 A |
1885 | #if ENABLE(ES6_CLASS_SYNTAX) |
1886 | class ClassDeclNode final : public StatementNode { | |
1887 | public: | |
1888 | ClassDeclNode(const JSTokenLocation&, ExpressionNode* classExpression); | |
1889 | ||
1890 | private: | |
1891 | virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; | |
1892 | ||
1893 | ExpressionNode* m_classDeclaration; | |
1894 | }; | |
1895 | #endif | |
1896 | ||
f9bf01c6 | 1897 | class CaseClauseNode : public ParserArenaFreeable { |
9dae56ea | 1898 | public: |
6fe7ccc8 | 1899 | CaseClauseNode(ExpressionNode*, SourceElements* = 0); |
9dae56ea | 1900 | |
ba379fdc | 1901 | ExpressionNode* expr() const { return m_expr; } |
f9bf01c6 A |
1902 | |
1903 | void emitBytecode(BytecodeGenerator&, RegisterID* destination); | |
ed1e77d3 | 1904 | void setStartOffset(int offset) { m_startOffset = offset; } |
9dae56ea A |
1905 | |
1906 | private: | |
ba379fdc | 1907 | ExpressionNode* m_expr; |
f9bf01c6 | 1908 | SourceElements* m_statements; |
ed1e77d3 | 1909 | int m_startOffset; |
9dae56ea A |
1910 | }; |
1911 | ||
f9bf01c6 | 1912 | class ClauseListNode : public ParserArenaFreeable { |
9dae56ea | 1913 | public: |
6fe7ccc8 A |
1914 | ClauseListNode(CaseClauseNode*); |
1915 | ClauseListNode(ClauseListNode*, CaseClauseNode*); | |
9dae56ea | 1916 | |
ba379fdc A |
1917 | CaseClauseNode* getClause() const { return m_clause; } |
1918 | ClauseListNode* getNext() const { return m_next; } | |
9dae56ea A |
1919 | |
1920 | private: | |
ba379fdc A |
1921 | CaseClauseNode* m_clause; |
1922 | ClauseListNode* m_next; | |
9dae56ea A |
1923 | }; |
1924 | ||
f9bf01c6 | 1925 | class CaseBlockNode : public ParserArenaFreeable { |
9dae56ea | 1926 | public: |
6fe7ccc8 | 1927 | CaseBlockNode(ClauseListNode* list1, CaseClauseNode* defaultClause, ClauseListNode* list2); |
9dae56ea | 1928 | |
93a37866 | 1929 | void emitBytecodeForBlock(BytecodeGenerator&, RegisterID* input, RegisterID* destination); |
9dae56ea A |
1930 | |
1931 | private: | |
93a37866 | 1932 | SwitchInfo::SwitchType tryTableSwitch(Vector<ExpressionNode*, 8>& literalVector, int32_t& min_num, int32_t& max_num); |
81345200 | 1933 | static const size_t s_tableSwitchMinimum = 3; |
ba379fdc A |
1934 | ClauseListNode* m_list1; |
1935 | CaseClauseNode* m_defaultClause; | |
1936 | ClauseListNode* m_list2; | |
9dae56ea A |
1937 | }; |
1938 | ||
1939 | class SwitchNode : public StatementNode { | |
1940 | public: | |
93a37866 | 1941 | SwitchNode(const JSTokenLocation&, ExpressionNode*, CaseBlockNode*); |
9dae56ea A |
1942 | |
1943 | private: | |
81345200 | 1944 | virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; |
ba379fdc A |
1945 | |
1946 | ExpressionNode* m_expr; | |
1947 | CaseBlockNode* m_block; | |
9dae56ea A |
1948 | }; |
1949 | ||
1950 | struct ElementList { | |
1951 | ElementNode* head; | |
1952 | ElementNode* tail; | |
1953 | }; | |
1954 | ||
1955 | struct PropertyList { | |
1956 | PropertyListNode* head; | |
1957 | PropertyListNode* tail; | |
1958 | }; | |
1959 | ||
1960 | struct ArgumentList { | |
1961 | ArgumentListNode* head; | |
1962 | ArgumentListNode* tail; | |
1963 | }; | |
1964 | ||
1965 | struct ConstDeclList { | |
1966 | ConstDeclNode* head; | |
1967 | ConstDeclNode* tail; | |
1968 | }; | |
1969 | ||
1970 | struct ParameterList { | |
1971 | ParameterNode* head; | |
1972 | ParameterNode* tail; | |
1973 | }; | |
1974 | ||
1975 | struct ClauseList { | |
1976 | ClauseListNode* head; | |
1977 | ClauseListNode* tail; | |
1978 | }; | |
1979 | ||
1980 | } // namespace JSC | |
1981 | ||
ba379fdc | 1982 | #endif // Nodes_h |