2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
5 * Copyright (C) 2007 Cameron Zwarich (cwzwarich@uwaterloo.ca)
6 * Copyright (C) 2007 Maks Orlovich
7 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
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.
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.
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.
32 #include "ParserArena.h"
33 #include "ResultType.h"
34 #include "SourceCode.h"
35 #include "SymbolTable.h"
36 #include <wtf/MathExtras.h>
40 class ArgumentListNode
;
41 class BytecodeGenerator
;
42 class FunctionBodyNode
;
44 class PropertyListNode
;
45 class ReadModifyResolveNode
;
50 typedef unsigned CodeFeatures
;
52 const CodeFeatures NoFeatures
= 0;
53 const CodeFeatures EvalFeature
= 1 << 0;
54 const CodeFeatures ClosureFeature
= 1 << 1;
55 const CodeFeatures AssignFeature
= 1 << 2;
56 const CodeFeatures ArgumentsFeature
= 1 << 3;
57 const CodeFeatures WithFeature
= 1 << 4;
58 const CodeFeatures CatchFeature
= 1 << 5;
59 const CodeFeatures ThisFeature
= 1 << 6;
60 const CodeFeatures StrictModeFeature
= 1 << 7;
61 const CodeFeatures ShadowsArgumentsFeature
= 1 << 8;
64 const CodeFeatures AllFeatures
= EvalFeature
| ClosureFeature
| AssignFeature
| ArgumentsFeature
| WithFeature
| CatchFeature
| ThisFeature
| StrictModeFeature
| ShadowsArgumentsFeature
;
83 enum LogicalOperator
{
88 typedef HashSet
<RefPtr
<StringImpl
>, IdentifierRepHash
> IdentifierSet
;
90 namespace DeclarationStacks
{
91 enum VarAttrs
{ IsConstant
= 1, HasInitializer
= 2 };
92 typedef Vector
<std::pair
<const Identifier
*, unsigned> > VarStack
;
93 typedef Vector
<FunctionBodyNode
*> FunctionStack
;
97 enum SwitchType
{ SwitchNone
, SwitchImmediate
, SwitchCharacter
, SwitchString
};
98 uint32_t bytecodeOffset
;
99 SwitchType switchType
;
102 class ParserArenaFreeable
{
104 // ParserArenaFreeable objects are are freed when the arena is deleted.
105 // Destructors are not called. Clients must not call delete on such objects.
106 void* operator new(size_t, JSGlobalData
*);
109 class ParserArenaDeletable
{
111 virtual ~ParserArenaDeletable() { }
113 // ParserArenaDeletable objects are deleted when the arena is deleted.
114 // Clients must not call delete directly on such objects.
115 void* operator new(size_t, JSGlobalData
*);
118 class ParserArenaRefCounted
: public RefCounted
<ParserArenaRefCounted
> {
120 ParserArenaRefCounted(JSGlobalData
*);
123 virtual ~ParserArenaRefCounted()
125 ASSERT(deletionHasBegun());
129 class Node
: public ParserArenaFreeable
{
136 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* destination
= 0) = 0;
138 int lineNo() const { return m_line
; }
144 class ExpressionNode
: public Node
{
146 ExpressionNode(JSGlobalData
*, ResultType
= ResultType::unknownType());
149 virtual bool isNumber() const { return false; }
150 virtual bool isString() const { return false; }
151 virtual bool isNull() const { return false; }
152 virtual bool isPure(BytecodeGenerator
&) const { return false; }
153 virtual bool isLocation() const { return false; }
154 virtual bool isResolveNode() const { return false; }
155 virtual bool isBracketAccessorNode() const { return false; }
156 virtual bool isDotAccessorNode() const { return false; }
157 virtual bool isFuncExprNode() const { return false; }
158 virtual bool isCommaNode() const { return false; }
159 virtual bool isSimpleArray() const { return false; }
160 virtual bool isAdd() const { return false; }
161 virtual bool isSubtract() const { return false; }
162 virtual bool hasConditionContextCodegen() const { return false; }
164 virtual void emitBytecodeInConditionContext(BytecodeGenerator
&, Label
*, Label
*, bool) { ASSERT_NOT_REACHED(); }
166 virtual ExpressionNode
* stripUnaryPlus() { return this; }
168 ResultType
resultDescriptor() const { return m_resultType
; }
171 ResultType m_resultType
;
174 class StatementNode
: public Node
{
176 StatementNode(JSGlobalData
*);
179 void setLoc(int firstLine
, int lastLine
);
180 int firstLine() const { return lineNo(); }
181 int lastLine() const { return m_lastLine
; }
183 virtual bool isEmptyStatement() const { return false; }
184 virtual bool isReturnNode() const { return false; }
185 virtual bool isExprStatement() const { return false; }
187 virtual bool isBlock() const { return false; }
193 class NullNode
: public ExpressionNode
{
195 NullNode(JSGlobalData
*);
198 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
200 virtual bool isNull() const { return true; }
203 class BooleanNode
: public ExpressionNode
{
205 BooleanNode(JSGlobalData
*, bool value
);
208 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
210 virtual bool isPure(BytecodeGenerator
&) const { return true; }
215 class NumberNode
: public ExpressionNode
{
217 NumberNode(JSGlobalData
*, double value
);
219 double value() const { return m_value
; }
220 void setValue(double value
) { m_value
= value
; }
223 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
225 virtual bool isNumber() const { return true; }
226 virtual bool isPure(BytecodeGenerator
&) const { return true; }
231 class StringNode
: public ExpressionNode
{
233 StringNode(JSGlobalData
*, const Identifier
&);
235 const Identifier
& value() { return m_value
; }
238 virtual bool isPure(BytecodeGenerator
&) const { return true; }
240 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
242 virtual bool isString() const { return true; }
244 const Identifier
& m_value
;
247 class ThrowableExpressionData
{
249 ThrowableExpressionData()
250 : m_divot(static_cast<uint32_t>(-1))
251 , m_startOffset(static_cast<uint16_t>(-1))
252 , m_endOffset(static_cast<uint16_t>(-1))
256 ThrowableExpressionData(unsigned divot
, unsigned startOffset
, unsigned endOffset
)
258 , m_startOffset(startOffset
)
259 , m_endOffset(endOffset
)
263 void setExceptionSourceCode(unsigned divot
, unsigned startOffset
, unsigned endOffset
)
266 m_startOffset
= startOffset
;
267 m_endOffset
= endOffset
;
270 uint32_t divot() const { return m_divot
; }
271 uint16_t startOffset() const { return m_startOffset
; }
272 uint16_t endOffset() const { return m_endOffset
; }
275 RegisterID
* emitThrowReferenceError(BytecodeGenerator
&, const UString
& message
);
279 uint16_t m_startOffset
;
280 uint16_t m_endOffset
;
283 class ThrowableSubExpressionData
: public ThrowableExpressionData
{
285 ThrowableSubExpressionData()
286 : m_subexpressionDivotOffset(0)
287 , m_subexpressionEndOffset(0)
291 ThrowableSubExpressionData(unsigned divot
, unsigned startOffset
, unsigned endOffset
)
292 : ThrowableExpressionData(divot
, startOffset
, endOffset
)
293 , m_subexpressionDivotOffset(0)
294 , m_subexpressionEndOffset(0)
298 void setSubexpressionInfo(uint32_t subexpressionDivot
, uint16_t subexpressionOffset
)
300 ASSERT(subexpressionDivot
<= divot());
301 if ((divot() - subexpressionDivot
) & ~0xFFFF) // Overflow means we can't do this safely, so just point at the primary divot
303 m_subexpressionDivotOffset
= divot() - subexpressionDivot
;
304 m_subexpressionEndOffset
= subexpressionOffset
;
308 uint16_t m_subexpressionDivotOffset
;
309 uint16_t m_subexpressionEndOffset
;
312 class ThrowablePrefixedSubExpressionData
: public ThrowableExpressionData
{
314 ThrowablePrefixedSubExpressionData()
315 : m_subexpressionDivotOffset(0)
316 , m_subexpressionStartOffset(0)
320 ThrowablePrefixedSubExpressionData(unsigned divot
, unsigned startOffset
, unsigned endOffset
)
321 : ThrowableExpressionData(divot
, startOffset
, endOffset
)
322 , m_subexpressionDivotOffset(0)
323 , m_subexpressionStartOffset(0)
327 void setSubexpressionInfo(uint32_t subexpressionDivot
, uint16_t subexpressionOffset
)
329 ASSERT(subexpressionDivot
>= divot());
330 if ((subexpressionDivot
- divot()) & ~0xFFFF) // Overflow means we can't do this safely, so just point at the primary divot
332 m_subexpressionDivotOffset
= subexpressionDivot
- divot();
333 m_subexpressionStartOffset
= subexpressionOffset
;
337 uint16_t m_subexpressionDivotOffset
;
338 uint16_t m_subexpressionStartOffset
;
341 class RegExpNode
: public ExpressionNode
, public ThrowableExpressionData
{
343 RegExpNode(JSGlobalData
*, const Identifier
& pattern
, const Identifier
& flags
);
346 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
348 const Identifier
& m_pattern
;
349 const Identifier
& m_flags
;
352 class ThisNode
: public ExpressionNode
{
354 ThisNode(JSGlobalData
*);
357 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
360 class ResolveNode
: public ExpressionNode
{
362 ResolveNode(JSGlobalData
*, const Identifier
&, int startOffset
);
364 const Identifier
& identifier() const { return m_ident
; }
367 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
369 virtual bool isPure(BytecodeGenerator
&) const ;
370 virtual bool isLocation() const { return true; }
371 virtual bool isResolveNode() const { return true; }
373 const Identifier
& m_ident
;
374 int32_t m_startOffset
;
377 class ElementNode
: public ParserArenaFreeable
{
379 ElementNode(JSGlobalData
*, int elision
, ExpressionNode
*);
380 ElementNode(JSGlobalData
*, ElementNode
*, int elision
, ExpressionNode
*);
382 int elision() const { return m_elision
; }
383 ExpressionNode
* value() { return m_node
; }
384 ElementNode
* next() { return m_next
; }
389 ExpressionNode
* m_node
;
392 class ArrayNode
: public ExpressionNode
{
394 ArrayNode(JSGlobalData
*, int elision
);
395 ArrayNode(JSGlobalData
*, ElementNode
*);
396 ArrayNode(JSGlobalData
*, int elision
, ElementNode
*);
398 ArgumentListNode
* toArgumentList(JSGlobalData
*) const;
401 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
403 virtual bool isSimpleArray() const ;
405 ElementNode
* m_element
;
410 class PropertyNode
: public ParserArenaFreeable
{
412 enum Type
{ Constant
= 1, Getter
= 2, Setter
= 4 };
414 PropertyNode(JSGlobalData
*, const Identifier
& name
, ExpressionNode
* value
, Type
);
415 PropertyNode(JSGlobalData
*, double name
, ExpressionNode
* value
, Type
);
417 const Identifier
& name() const { return m_name
; }
418 Type
type() const { return m_type
; }
421 friend class PropertyListNode
;
422 const Identifier
& m_name
;
423 ExpressionNode
* m_assign
;
427 class PropertyListNode
: public Node
{
429 PropertyListNode(JSGlobalData
*, PropertyNode
*);
430 PropertyListNode(JSGlobalData
*, PropertyNode
*, PropertyListNode
*);
432 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
435 PropertyNode
* m_node
;
436 PropertyListNode
* m_next
;
439 class ObjectLiteralNode
: public ExpressionNode
{
441 ObjectLiteralNode(JSGlobalData
*);
442 ObjectLiteralNode(JSGlobalData
*, PropertyListNode
*);
445 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
447 PropertyListNode
* m_list
;
450 class BracketAccessorNode
: public ExpressionNode
, public ThrowableExpressionData
{
452 BracketAccessorNode(JSGlobalData
*, ExpressionNode
* base
, ExpressionNode
* subscript
, bool subscriptHasAssignments
);
454 ExpressionNode
* base() const { return m_base
; }
455 ExpressionNode
* subscript() const { return m_subscript
; }
458 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
460 virtual bool isLocation() const { return true; }
461 virtual bool isBracketAccessorNode() const { return true; }
463 ExpressionNode
* m_base
;
464 ExpressionNode
* m_subscript
;
465 bool m_subscriptHasAssignments
;
468 class DotAccessorNode
: public ExpressionNode
, public ThrowableExpressionData
{
470 DotAccessorNode(JSGlobalData
*, ExpressionNode
* base
, const Identifier
&);
472 ExpressionNode
* base() const { return m_base
; }
473 const Identifier
& identifier() const { return m_ident
; }
476 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
478 virtual bool isLocation() const { return true; }
479 virtual bool isDotAccessorNode() const { return true; }
481 ExpressionNode
* m_base
;
482 const Identifier
& m_ident
;
485 class ArgumentListNode
: public Node
{
487 ArgumentListNode(JSGlobalData
*, ExpressionNode
*);
488 ArgumentListNode(JSGlobalData
*, ArgumentListNode
*, ExpressionNode
*);
490 ArgumentListNode
* m_next
;
491 ExpressionNode
* m_expr
;
494 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
497 class ArgumentsNode
: public ParserArenaFreeable
{
499 ArgumentsNode(JSGlobalData
*);
500 ArgumentsNode(JSGlobalData
*, ArgumentListNode
*);
502 ArgumentListNode
* m_listNode
;
505 class NewExprNode
: public ExpressionNode
, public ThrowableExpressionData
{
507 NewExprNode(JSGlobalData
*, ExpressionNode
*);
508 NewExprNode(JSGlobalData
*, ExpressionNode
*, ArgumentsNode
*);
511 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
513 ExpressionNode
* m_expr
;
514 ArgumentsNode
* m_args
;
517 class EvalFunctionCallNode
: public ExpressionNode
, public ThrowableExpressionData
{
519 EvalFunctionCallNode(JSGlobalData
*, ArgumentsNode
*, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
522 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
524 ArgumentsNode
* m_args
;
527 class FunctionCallValueNode
: public ExpressionNode
, public ThrowableExpressionData
{
529 FunctionCallValueNode(JSGlobalData
*, ExpressionNode
*, ArgumentsNode
*, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
532 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
534 ExpressionNode
* m_expr
;
535 ArgumentsNode
* m_args
;
538 class FunctionCallResolveNode
: public ExpressionNode
, public ThrowableExpressionData
{
540 FunctionCallResolveNode(JSGlobalData
*, const Identifier
&, ArgumentsNode
*, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
543 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
545 const Identifier
& m_ident
;
546 ArgumentsNode
* m_args
;
547 size_t m_index
; // Used by LocalVarFunctionCallNode.
548 size_t m_scopeDepth
; // Used by ScopedVarFunctionCallNode and NonLocalVarFunctionCallNode
551 class FunctionCallBracketNode
: public ExpressionNode
, public ThrowableSubExpressionData
{
553 FunctionCallBracketNode(JSGlobalData
*, ExpressionNode
* base
, ExpressionNode
* subscript
, ArgumentsNode
*, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
556 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
558 ExpressionNode
* m_base
;
559 ExpressionNode
* m_subscript
;
560 ArgumentsNode
* m_args
;
563 class FunctionCallDotNode
: public ExpressionNode
, public ThrowableSubExpressionData
{
565 FunctionCallDotNode(JSGlobalData
*, ExpressionNode
* base
, const Identifier
&, ArgumentsNode
*, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
568 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
571 ExpressionNode
* m_base
;
572 const Identifier
& m_ident
;
573 ArgumentsNode
* m_args
;
576 class CallFunctionCallDotNode
: public FunctionCallDotNode
{
578 CallFunctionCallDotNode(JSGlobalData
*, ExpressionNode
* base
, const Identifier
&, ArgumentsNode
*, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
581 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
584 class ApplyFunctionCallDotNode
: public FunctionCallDotNode
{
586 ApplyFunctionCallDotNode(JSGlobalData
*, ExpressionNode
* base
, const Identifier
&, ArgumentsNode
*, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
589 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
592 class PrePostResolveNode
: public ExpressionNode
, public ThrowableExpressionData
{
594 PrePostResolveNode(JSGlobalData
*, const Identifier
&, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
597 const Identifier
& m_ident
;
600 class PostfixResolveNode
: public PrePostResolveNode
{
602 PostfixResolveNode(JSGlobalData
*, const Identifier
&, Operator
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
605 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
610 class PostfixBracketNode
: public ExpressionNode
, public ThrowableSubExpressionData
{
612 PostfixBracketNode(JSGlobalData
*, ExpressionNode
* base
, ExpressionNode
* subscript
, Operator
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
615 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
617 ExpressionNode
* m_base
;
618 ExpressionNode
* m_subscript
;
622 class PostfixDotNode
: public ExpressionNode
, public ThrowableSubExpressionData
{
624 PostfixDotNode(JSGlobalData
*, ExpressionNode
* base
, const Identifier
&, Operator
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
627 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
629 ExpressionNode
* m_base
;
630 const Identifier
& m_ident
;
634 class PostfixErrorNode
: public ExpressionNode
, public ThrowableSubExpressionData
{
636 PostfixErrorNode(JSGlobalData
*, ExpressionNode
*, Operator
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
639 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
641 ExpressionNode
* m_expr
;
645 class DeleteResolveNode
: public ExpressionNode
, public ThrowableExpressionData
{
647 DeleteResolveNode(JSGlobalData
*, const Identifier
&, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
650 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
652 const Identifier
& m_ident
;
655 class DeleteBracketNode
: public ExpressionNode
, public ThrowableExpressionData
{
657 DeleteBracketNode(JSGlobalData
*, ExpressionNode
* base
, ExpressionNode
* subscript
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
660 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
662 ExpressionNode
* m_base
;
663 ExpressionNode
* m_subscript
;
666 class DeleteDotNode
: public ExpressionNode
, public ThrowableExpressionData
{
668 DeleteDotNode(JSGlobalData
*, ExpressionNode
* base
, const Identifier
&, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
671 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
673 ExpressionNode
* m_base
;
674 const Identifier
& m_ident
;
677 class DeleteValueNode
: public ExpressionNode
{
679 DeleteValueNode(JSGlobalData
*, ExpressionNode
*);
682 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
684 ExpressionNode
* m_expr
;
687 class VoidNode
: public ExpressionNode
{
689 VoidNode(JSGlobalData
*, ExpressionNode
*);
692 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
694 ExpressionNode
* m_expr
;
697 class TypeOfResolveNode
: public ExpressionNode
{
699 TypeOfResolveNode(JSGlobalData
*, const Identifier
&);
701 const Identifier
& identifier() const { return m_ident
; }
704 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
706 const Identifier
& m_ident
;
709 class TypeOfValueNode
: public ExpressionNode
{
711 TypeOfValueNode(JSGlobalData
*, ExpressionNode
*);
714 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
716 ExpressionNode
* m_expr
;
719 class PrefixResolveNode
: public PrePostResolveNode
{
721 PrefixResolveNode(JSGlobalData
*, const Identifier
&, Operator
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
724 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
729 class PrefixBracketNode
: public ExpressionNode
, public ThrowablePrefixedSubExpressionData
{
731 PrefixBracketNode(JSGlobalData
*, ExpressionNode
* base
, ExpressionNode
* subscript
, Operator
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
734 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
736 ExpressionNode
* m_base
;
737 ExpressionNode
* m_subscript
;
741 class PrefixDotNode
: public ExpressionNode
, public ThrowablePrefixedSubExpressionData
{
743 PrefixDotNode(JSGlobalData
*, ExpressionNode
* base
, const Identifier
&, Operator
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
746 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
748 ExpressionNode
* m_base
;
749 const Identifier
& m_ident
;
753 class PrefixErrorNode
: public ExpressionNode
, public ThrowableExpressionData
{
755 PrefixErrorNode(JSGlobalData
*, ExpressionNode
*, Operator
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
758 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
760 ExpressionNode
* m_expr
;
764 class UnaryOpNode
: public ExpressionNode
{
766 UnaryOpNode(JSGlobalData
*, ResultType
, ExpressionNode
*, OpcodeID
);
769 ExpressionNode
* expr() { return m_expr
; }
770 const ExpressionNode
* expr() const { return m_expr
; }
773 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
775 OpcodeID
opcodeID() const { return m_opcodeID
; }
777 ExpressionNode
* m_expr
;
781 class UnaryPlusNode
: public UnaryOpNode
{
783 UnaryPlusNode(JSGlobalData
*, ExpressionNode
*);
786 virtual ExpressionNode
* stripUnaryPlus() { return expr(); }
789 class NegateNode
: public UnaryOpNode
{
791 NegateNode(JSGlobalData
*, ExpressionNode
*);
794 class BitwiseNotNode
: public UnaryOpNode
{
796 BitwiseNotNode(JSGlobalData
*, ExpressionNode
*);
799 class LogicalNotNode
: public UnaryOpNode
{
801 LogicalNotNode(JSGlobalData
*, ExpressionNode
*);
803 void emitBytecodeInConditionContext(BytecodeGenerator
&, Label
* trueTarget
, Label
* falseTarget
, bool fallThroughMeansTrue
);
804 virtual bool hasConditionContextCodegen() const { return expr()->hasConditionContextCodegen(); }
807 class BinaryOpNode
: public ExpressionNode
{
809 BinaryOpNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, OpcodeID
, bool rightHasAssignments
);
810 BinaryOpNode(JSGlobalData
*, ResultType
, ExpressionNode
* expr1
, ExpressionNode
* expr2
, OpcodeID
, bool rightHasAssignments
);
812 RegisterID
* emitStrcat(BytecodeGenerator
& generator
, RegisterID
* destination
, RegisterID
* lhs
= 0, ReadModifyResolveNode
* emitExpressionInfoForMe
= 0);
814 ExpressionNode
* lhs() { return m_expr1
; };
815 ExpressionNode
* rhs() { return m_expr2
; };
818 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
821 OpcodeID
opcodeID() const { return m_opcodeID
; }
824 ExpressionNode
* m_expr1
;
825 ExpressionNode
* m_expr2
;
829 bool m_rightHasAssignments
;
832 class ReverseBinaryOpNode
: public BinaryOpNode
{
834 ReverseBinaryOpNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, OpcodeID
, bool rightHasAssignments
);
835 ReverseBinaryOpNode(JSGlobalData
*, ResultType
, ExpressionNode
* expr1
, ExpressionNode
* expr2
, OpcodeID
, bool rightHasAssignments
);
837 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
840 class MultNode
: public BinaryOpNode
{
842 MultNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
845 class DivNode
: public BinaryOpNode
{
847 DivNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
850 class ModNode
: public BinaryOpNode
{
852 ModNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
855 class AddNode
: public BinaryOpNode
{
857 AddNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
859 virtual bool isAdd() const { return true; }
862 class SubNode
: public BinaryOpNode
{
864 SubNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
866 virtual bool isSubtract() const { return true; }
869 class LeftShiftNode
: public BinaryOpNode
{
871 LeftShiftNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
874 class RightShiftNode
: public BinaryOpNode
{
876 RightShiftNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
879 class UnsignedRightShiftNode
: public BinaryOpNode
{
881 UnsignedRightShiftNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
884 class LessNode
: public BinaryOpNode
{
886 LessNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
889 class GreaterNode
: public ReverseBinaryOpNode
{
891 GreaterNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
894 class LessEqNode
: public BinaryOpNode
{
896 LessEqNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
899 class GreaterEqNode
: public ReverseBinaryOpNode
{
901 GreaterEqNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
904 class ThrowableBinaryOpNode
: public BinaryOpNode
, public ThrowableExpressionData
{
906 ThrowableBinaryOpNode(JSGlobalData
*, ResultType
, ExpressionNode
* expr1
, ExpressionNode
* expr2
, OpcodeID
, bool rightHasAssignments
);
907 ThrowableBinaryOpNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, OpcodeID
, bool rightHasAssignments
);
910 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
913 class InstanceOfNode
: public ThrowableBinaryOpNode
{
915 InstanceOfNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
918 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
921 class InNode
: public ThrowableBinaryOpNode
{
923 InNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
926 class EqualNode
: public BinaryOpNode
{
928 EqualNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
931 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
934 class NotEqualNode
: public BinaryOpNode
{
936 NotEqualNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
939 class StrictEqualNode
: public BinaryOpNode
{
941 StrictEqualNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
944 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
947 class NotStrictEqualNode
: public BinaryOpNode
{
949 NotStrictEqualNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
952 class BitAndNode
: public BinaryOpNode
{
954 BitAndNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
957 class BitOrNode
: public BinaryOpNode
{
959 BitOrNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
962 class BitXOrNode
: public BinaryOpNode
{
964 BitXOrNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
967 // m_expr1 && m_expr2, m_expr1 || m_expr2
968 class LogicalOpNode
: public ExpressionNode
{
970 LogicalOpNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, LogicalOperator
);
973 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
974 void emitBytecodeInConditionContext(BytecodeGenerator
&, Label
* trueTarget
, Label
* falseTarget
, bool fallThroughMeansTrue
);
975 virtual bool hasConditionContextCodegen() const { return true; }
977 ExpressionNode
* m_expr1
;
978 ExpressionNode
* m_expr2
;
979 LogicalOperator m_operator
;
982 // The ternary operator, "m_logical ? m_expr1 : m_expr2"
983 class ConditionalNode
: public ExpressionNode
{
985 ConditionalNode(JSGlobalData
*, ExpressionNode
* logical
, ExpressionNode
* expr1
, ExpressionNode
* expr2
);
988 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
990 ExpressionNode
* m_logical
;
991 ExpressionNode
* m_expr1
;
992 ExpressionNode
* m_expr2
;
995 class ReadModifyResolveNode
: public ExpressionNode
, public ThrowableExpressionData
{
997 ReadModifyResolveNode(JSGlobalData
*, const Identifier
&, Operator
, ExpressionNode
* right
, bool rightHasAssignments
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
1000 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1002 const Identifier
& m_ident
;
1003 ExpressionNode
* m_right
;
1004 size_t m_index
; // Used by ReadModifyLocalVarNode.
1005 Operator m_operator
;
1006 bool m_rightHasAssignments
;
1009 class AssignResolveNode
: public ExpressionNode
, public ThrowableExpressionData
{
1011 AssignResolveNode(JSGlobalData
*, const Identifier
&, ExpressionNode
* right
, bool rightHasAssignments
);
1014 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1016 const Identifier
& m_ident
;
1017 ExpressionNode
* m_right
;
1018 size_t m_index
; // Used by ReadModifyLocalVarNode.
1019 bool m_rightHasAssignments
;
1022 class ReadModifyBracketNode
: public ExpressionNode
, public ThrowableSubExpressionData
{
1024 ReadModifyBracketNode(JSGlobalData
*, ExpressionNode
* base
, ExpressionNode
* subscript
, Operator
, ExpressionNode
* right
, bool subscriptHasAssignments
, bool rightHasAssignments
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
1027 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1029 ExpressionNode
* m_base
;
1030 ExpressionNode
* m_subscript
;
1031 ExpressionNode
* m_right
;
1032 Operator m_operator
: 30;
1033 bool m_subscriptHasAssignments
: 1;
1034 bool m_rightHasAssignments
: 1;
1037 class AssignBracketNode
: public ExpressionNode
, public ThrowableExpressionData
{
1039 AssignBracketNode(JSGlobalData
*, ExpressionNode
* base
, ExpressionNode
* subscript
, ExpressionNode
* right
, bool subscriptHasAssignments
, bool rightHasAssignments
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
1042 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1044 ExpressionNode
* m_base
;
1045 ExpressionNode
* m_subscript
;
1046 ExpressionNode
* m_right
;
1047 bool m_subscriptHasAssignments
: 1;
1048 bool m_rightHasAssignments
: 1;
1051 class AssignDotNode
: public ExpressionNode
, public ThrowableExpressionData
{
1053 AssignDotNode(JSGlobalData
*, ExpressionNode
* base
, const Identifier
&, ExpressionNode
* right
, bool rightHasAssignments
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
1056 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1058 ExpressionNode
* m_base
;
1059 const Identifier
& m_ident
;
1060 ExpressionNode
* m_right
;
1061 bool m_rightHasAssignments
;
1064 class ReadModifyDotNode
: public ExpressionNode
, public ThrowableSubExpressionData
{
1066 ReadModifyDotNode(JSGlobalData
*, ExpressionNode
* base
, const Identifier
&, Operator
, ExpressionNode
* right
, bool rightHasAssignments
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
1069 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1071 ExpressionNode
* m_base
;
1072 const Identifier
& m_ident
;
1073 ExpressionNode
* m_right
;
1074 Operator m_operator
: 31;
1075 bool m_rightHasAssignments
: 1;
1078 class AssignErrorNode
: public ExpressionNode
, public ThrowableExpressionData
{
1080 AssignErrorNode(JSGlobalData
*, ExpressionNode
* left
, Operator
, ExpressionNode
* right
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
1083 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1085 ExpressionNode
* m_left
;
1086 Operator m_operator
;
1087 ExpressionNode
* m_right
;
1090 typedef Vector
<ExpressionNode
*, 8> ExpressionVector
;
1092 class CommaNode
: public ExpressionNode
, public ParserArenaDeletable
{
1094 CommaNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
);
1096 using ParserArenaDeletable::operator new;
1098 void append(ExpressionNode
* expr
) { m_expressions
.append(expr
); }
1101 virtual bool isCommaNode() const { return true; }
1102 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1104 ExpressionVector m_expressions
;
1107 class ConstDeclNode
: public ExpressionNode
{
1109 ConstDeclNode(JSGlobalData
*, const Identifier
&, ExpressionNode
*);
1111 bool hasInitializer() const { return m_init
; }
1112 const Identifier
& ident() { return m_ident
; }
1115 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1116 virtual RegisterID
* emitCodeSingle(BytecodeGenerator
&);
1118 const Identifier
& m_ident
;
1121 ConstDeclNode
* m_next
;
1124 ExpressionNode
* m_init
;
1127 class ConstStatementNode
: public StatementNode
{
1129 ConstStatementNode(JSGlobalData
*, ConstDeclNode
* next
);
1132 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1134 ConstDeclNode
* m_next
;
1137 class SourceElements
: public ParserArenaDeletable
{
1139 SourceElements(JSGlobalData
*);
1141 void append(StatementNode
*);
1143 StatementNode
* singleStatement() const;
1144 StatementNode
* lastStatement() const;
1146 void emitBytecode(BytecodeGenerator
&, RegisterID
* destination
);
1149 Vector
<StatementNode
*> m_statements
;
1152 class BlockNode
: public StatementNode
{
1154 BlockNode(JSGlobalData
*, SourceElements
* = 0);
1156 StatementNode
* singleStatement() const;
1157 StatementNode
* lastStatement() const;
1160 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1162 virtual bool isBlock() const { return true; }
1164 SourceElements
* m_statements
;
1167 class EmptyStatementNode
: public StatementNode
{
1169 EmptyStatementNode(JSGlobalData
*);
1172 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1174 virtual bool isEmptyStatement() const { return true; }
1177 class DebuggerStatementNode
: public StatementNode
{
1179 DebuggerStatementNode(JSGlobalData
*);
1182 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1185 class ExprStatementNode
: public StatementNode
{
1187 ExprStatementNode(JSGlobalData
*, ExpressionNode
*);
1189 ExpressionNode
* expr() const { return m_expr
; }
1192 virtual bool isExprStatement() const { return true; }
1194 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1196 ExpressionNode
* m_expr
;
1199 class VarStatementNode
: public StatementNode
{
1201 VarStatementNode(JSGlobalData
*, ExpressionNode
*);
1204 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1206 ExpressionNode
* m_expr
;
1209 class IfNode
: public StatementNode
{
1211 IfNode(JSGlobalData
*, ExpressionNode
* condition
, StatementNode
* ifBlock
);
1214 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1216 ExpressionNode
* m_condition
;
1217 StatementNode
* m_ifBlock
;
1220 class IfElseNode
: public IfNode
{
1222 IfElseNode(JSGlobalData
*, ExpressionNode
* condition
, StatementNode
* ifBlock
, StatementNode
* elseBlock
);
1225 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1227 StatementNode
* m_elseBlock
;
1230 class DoWhileNode
: public StatementNode
{
1232 DoWhileNode(JSGlobalData
*, StatementNode
* statement
, ExpressionNode
*);
1235 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1237 StatementNode
* m_statement
;
1238 ExpressionNode
* m_expr
;
1241 class WhileNode
: public StatementNode
{
1243 WhileNode(JSGlobalData
*, ExpressionNode
*, StatementNode
* statement
);
1246 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1248 ExpressionNode
* m_expr
;
1249 StatementNode
* m_statement
;
1252 class ForNode
: public StatementNode
{
1254 ForNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, ExpressionNode
* expr3
, StatementNode
* statement
, bool expr1WasVarDecl
);
1257 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1259 ExpressionNode
* m_expr1
;
1260 ExpressionNode
* m_expr2
;
1261 ExpressionNode
* m_expr3
;
1262 StatementNode
* m_statement
;
1263 bool m_expr1WasVarDecl
;
1266 class ForInNode
: public StatementNode
, public ThrowableExpressionData
{
1268 ForInNode(JSGlobalData
*, ExpressionNode
*, ExpressionNode
*, StatementNode
*);
1269 ForInNode(JSGlobalData
*, const Identifier
&, ExpressionNode
*, ExpressionNode
*, StatementNode
*, int divot
, int startOffset
, int endOffset
);
1272 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1274 const Identifier
& m_ident
;
1275 ExpressionNode
* m_init
;
1276 ExpressionNode
* m_lexpr
;
1277 ExpressionNode
* m_expr
;
1278 StatementNode
* m_statement
;
1279 bool m_identIsVarDecl
;
1282 class ContinueNode
: public StatementNode
, public ThrowableExpressionData
{
1284 ContinueNode(JSGlobalData
*);
1285 ContinueNode(JSGlobalData
*, const Identifier
&);
1288 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1290 const Identifier
& m_ident
;
1293 class BreakNode
: public StatementNode
, public ThrowableExpressionData
{
1295 BreakNode(JSGlobalData
*);
1296 BreakNode(JSGlobalData
*, const Identifier
&);
1299 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1301 const Identifier
& m_ident
;
1304 class ReturnNode
: public StatementNode
, public ThrowableExpressionData
{
1306 ReturnNode(JSGlobalData
*, ExpressionNode
* value
);
1308 ExpressionNode
* value() { return m_value
; }
1311 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1313 virtual bool isReturnNode() const { return true; }
1315 ExpressionNode
* m_value
;
1318 class WithNode
: public StatementNode
{
1320 WithNode(JSGlobalData
*, ExpressionNode
*, StatementNode
*, uint32_t divot
, uint32_t expressionLength
);
1323 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1325 ExpressionNode
* m_expr
;
1326 StatementNode
* m_statement
;
1328 uint32_t m_expressionLength
;
1331 class LabelNode
: public StatementNode
, public ThrowableExpressionData
{
1333 LabelNode(JSGlobalData
*, const Identifier
& name
, StatementNode
*);
1336 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1338 const Identifier
& m_name
;
1339 StatementNode
* m_statement
;
1342 class ThrowNode
: public StatementNode
, public ThrowableExpressionData
{
1344 ThrowNode(JSGlobalData
*, ExpressionNode
*);
1347 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1349 ExpressionNode
* m_expr
;
1352 class TryNode
: public StatementNode
{
1354 TryNode(JSGlobalData
*, StatementNode
* tryBlock
, const Identifier
& exceptionIdent
, bool catchHasEval
, StatementNode
* catchBlock
, StatementNode
* finallyBlock
);
1357 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1359 StatementNode
* m_tryBlock
;
1360 const Identifier
& m_exceptionIdent
;
1361 StatementNode
* m_catchBlock
;
1362 StatementNode
* m_finallyBlock
;
1363 bool m_catchHasEval
;
1366 class ParameterNode
: public ParserArenaFreeable
{
1368 ParameterNode(JSGlobalData
*, const Identifier
&);
1369 ParameterNode(JSGlobalData
*, ParameterNode
*, const Identifier
&);
1371 const Identifier
& ident() const { return m_ident
; }
1372 ParameterNode
* nextParam() const { return m_next
; }
1375 const Identifier
& m_ident
;
1376 ParameterNode
* m_next
;
1379 struct ScopeNodeData
{
1380 WTF_MAKE_FAST_ALLOCATED
;
1382 typedef DeclarationStacks::VarStack VarStack
;
1383 typedef DeclarationStacks::FunctionStack FunctionStack
;
1385 ScopeNodeData(ParserArena
&, SourceElements
*, VarStack
*, FunctionStack
*, IdentifierSet
&, int numConstants
);
1387 ParserArena m_arena
;
1388 VarStack m_varStack
;
1389 FunctionStack m_functionStack
;
1391 SourceElements
* m_statements
;
1392 IdentifierSet m_capturedVariables
;
1395 class ScopeNode
: public StatementNode
, public ParserArenaRefCounted
{
1397 typedef DeclarationStacks::VarStack VarStack
;
1398 typedef DeclarationStacks::FunctionStack FunctionStack
;
1400 ScopeNode(JSGlobalData
*, bool inStrictContext
);
1401 ScopeNode(JSGlobalData
*, const SourceCode
&, SourceElements
*, VarStack
*, FunctionStack
*, IdentifierSet
&, CodeFeatures
, int numConstants
);
1403 using ParserArenaRefCounted::operator new;
1405 ScopeNodeData
* data() const { return m_data
.get(); }
1406 void destroyData() { m_data
.clear(); }
1408 const SourceCode
& source() const { return m_source
; }
1409 const UString
& sourceURL() const { return m_source
.provider()->url(); }
1410 intptr_t sourceID() const { return m_source
.provider()->asID(); }
1412 void setFeatures(CodeFeatures features
) { m_features
= features
; }
1413 CodeFeatures
features() { return m_features
; }
1415 bool usesEval() const { return m_features
& EvalFeature
; }
1416 bool usesArguments() const { return (m_features
& ArgumentsFeature
) && !(m_features
& ShadowsArgumentsFeature
); }
1417 bool isStrictMode() const { return m_features
& StrictModeFeature
; }
1418 void setUsesArguments() { m_features
|= ArgumentsFeature
; }
1419 bool usesThis() const { return m_features
& ThisFeature
; }
1420 bool needsActivationForMoreThanVariables() const { ASSERT(m_data
); return m_features
& (EvalFeature
| WithFeature
| CatchFeature
); }
1421 bool needsActivation() const { ASSERT(m_data
); return (hasCapturedVariables()) || (m_features
& (EvalFeature
| WithFeature
| CatchFeature
)); }
1422 bool hasCapturedVariables() const { return !!m_data
->m_capturedVariables
.size(); }
1423 size_t capturedVariableCount() const { return m_data
->m_capturedVariables
.size(); }
1424 bool captures(const Identifier
& ident
) { return m_data
->m_capturedVariables
.contains(ident
.impl()); }
1426 VarStack
& varStack() { ASSERT(m_data
); return m_data
->m_varStack
; }
1427 FunctionStack
& functionStack() { ASSERT(m_data
); return m_data
->m_functionStack
; }
1429 int neededConstants()
1432 // We may need 2 more constants than the count given by the parser,
1433 // because of the various uses of jsUndefined() and jsNull().
1434 return m_data
->m_numConstants
+ 2;
1437 StatementNode
* singleStatement() const;
1439 void emitStatementsBytecode(BytecodeGenerator
&, RegisterID
* destination
);
1442 void setSource(const SourceCode
& source
) { m_source
= source
; }
1445 OwnPtr
<ScopeNodeData
> m_data
;
1446 CodeFeatures m_features
;
1447 SourceCode m_source
;
1450 class ProgramNode
: public ScopeNode
{
1452 static const bool isFunctionNode
= false;
1453 static PassRefPtr
<ProgramNode
> create(JSGlobalData
*, SourceElements
*, VarStack
*, FunctionStack
*, IdentifierSet
&, const SourceCode
&, CodeFeatures
, int numConstants
);
1455 static const bool scopeIsFunction
= false;
1458 ProgramNode(JSGlobalData
*, SourceElements
*, VarStack
*, FunctionStack
*, IdentifierSet
&, const SourceCode
&, CodeFeatures
, int numConstants
);
1460 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1463 class EvalNode
: public ScopeNode
{
1465 static const bool isFunctionNode
= false;
1466 static PassRefPtr
<EvalNode
> create(JSGlobalData
*, SourceElements
*, VarStack
*, FunctionStack
*, IdentifierSet
&, const SourceCode
&, CodeFeatures
, int numConstants
);
1468 static const bool scopeIsFunction
= false;
1471 EvalNode(JSGlobalData
*, SourceElements
*, VarStack
*, FunctionStack
*, IdentifierSet
&, const SourceCode
&, CodeFeatures
, int numConstants
);
1473 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1476 class FunctionParameters
: public Vector
<Identifier
>, public RefCounted
<FunctionParameters
> {
1477 WTF_MAKE_FAST_ALLOCATED
;
1479 static PassRefPtr
<FunctionParameters
> create(ParameterNode
* firstParameter
) { return adoptRef(new FunctionParameters(firstParameter
)); }
1482 FunctionParameters(ParameterNode
*);
1485 class FunctionBodyNode
: public ScopeNode
{
1487 static const bool isFunctionNode
= true;
1488 static FunctionBodyNode
* create(JSGlobalData
*, bool isStrictMode
);
1489 static PassRefPtr
<FunctionBodyNode
> create(JSGlobalData
*, SourceElements
*, VarStack
*, FunctionStack
*, IdentifierSet
&, const SourceCode
&, CodeFeatures
, int numConstants
);
1491 FunctionParameters
* parameters() const { return m_parameters
.get(); }
1492 size_t parameterCount() const { return m_parameters
->size(); }
1494 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1496 void finishParsing(const SourceCode
&, ParameterNode
*, const Identifier
&);
1497 void finishParsing(PassRefPtr
<FunctionParameters
>, const Identifier
&);
1499 const Identifier
& ident() { return m_ident
; }
1501 static const bool scopeIsFunction
= true;
1504 FunctionBodyNode(JSGlobalData
*, bool inStrictContext
);
1505 FunctionBodyNode(JSGlobalData
*, SourceElements
*, VarStack
*, FunctionStack
*, IdentifierSet
&, const SourceCode
&, CodeFeatures
, int numConstants
);
1508 RefPtr
<FunctionParameters
> m_parameters
;
1511 class FuncExprNode
: public ExpressionNode
{
1513 FuncExprNode(JSGlobalData
*, const Identifier
&, FunctionBodyNode
* body
, const SourceCode
& source
, ParameterNode
* parameter
= 0);
1515 FunctionBodyNode
* body() { return m_body
; }
1518 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1520 virtual bool isFuncExprNode() const { return true; }
1522 FunctionBodyNode
* m_body
;
1525 class FuncDeclNode
: public StatementNode
{
1527 FuncDeclNode(JSGlobalData
*, const Identifier
&, FunctionBodyNode
*, const SourceCode
&, ParameterNode
* = 0);
1529 FunctionBodyNode
* body() { return m_body
; }
1532 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1534 FunctionBodyNode
* m_body
;
1537 class CaseClauseNode
: public ParserArenaFreeable
{
1539 CaseClauseNode(JSGlobalData
*, ExpressionNode
*, SourceElements
* = 0);
1541 ExpressionNode
* expr() const { return m_expr
; }
1543 void emitBytecode(BytecodeGenerator
&, RegisterID
* destination
);
1546 ExpressionNode
* m_expr
;
1547 SourceElements
* m_statements
;
1550 class ClauseListNode
: public ParserArenaFreeable
{
1552 ClauseListNode(JSGlobalData
*, CaseClauseNode
*);
1553 ClauseListNode(JSGlobalData
*, ClauseListNode
*, CaseClauseNode
*);
1555 CaseClauseNode
* getClause() const { return m_clause
; }
1556 ClauseListNode
* getNext() const { return m_next
; }
1559 CaseClauseNode
* m_clause
;
1560 ClauseListNode
* m_next
;
1563 class CaseBlockNode
: public ParserArenaFreeable
{
1565 CaseBlockNode(JSGlobalData
*, ClauseListNode
* list1
, CaseClauseNode
* defaultClause
, ClauseListNode
* list2
);
1567 RegisterID
* emitBytecodeForBlock(BytecodeGenerator
&, RegisterID
* input
, RegisterID
* destination
);
1570 SwitchInfo::SwitchType
tryOptimizedSwitch(Vector
<ExpressionNode
*, 8>& literalVector
, int32_t& min_num
, int32_t& max_num
);
1571 ClauseListNode
* m_list1
;
1572 CaseClauseNode
* m_defaultClause
;
1573 ClauseListNode
* m_list2
;
1576 class SwitchNode
: public StatementNode
{
1578 SwitchNode(JSGlobalData
*, ExpressionNode
*, CaseBlockNode
*);
1581 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1583 ExpressionNode
* m_expr
;
1584 CaseBlockNode
* m_block
;
1587 struct ElementList
{
1592 struct PropertyList
{
1593 PropertyListNode
* head
;
1594 PropertyListNode
* tail
;
1597 struct ArgumentList
{
1598 ArgumentListNode
* head
;
1599 ArgumentListNode
* tail
;
1602 struct ConstDeclList
{
1603 ConstDeclNode
* head
;
1604 ConstDeclNode
* tail
;
1607 struct ParameterList
{
1608 ParameterNode
* head
;
1609 ParameterNode
* tail
;
1613 ClauseListNode
* head
;
1614 ClauseListNode
* tail
;