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 ArgumentsFeature
= 1 << 1;
55 const CodeFeatures WithFeature
= 1 << 2;
56 const CodeFeatures CatchFeature
= 1 << 3;
57 const CodeFeatures ThisFeature
= 1 << 4;
58 const CodeFeatures StrictModeFeature
= 1 << 5;
59 const CodeFeatures ShadowsArgumentsFeature
= 1 << 6;
61 const CodeFeatures AllFeatures
= EvalFeature
| ArgumentsFeature
| WithFeature
| CatchFeature
| ThisFeature
| StrictModeFeature
| ShadowsArgumentsFeature
;
80 enum LogicalOperator
{
85 typedef HashSet
<RefPtr
<StringImpl
>, IdentifierRepHash
> IdentifierSet
;
87 namespace DeclarationStacks
{
88 enum VarAttrs
{ IsConstant
= 1, HasInitializer
= 2 };
89 typedef Vector
<std::pair
<const Identifier
*, unsigned> > VarStack
;
90 typedef Vector
<FunctionBodyNode
*> FunctionStack
;
94 enum SwitchType
{ SwitchNone
, SwitchImmediate
, SwitchCharacter
, SwitchString
};
95 uint32_t bytecodeOffset
;
96 SwitchType switchType
;
99 class ParserArenaFreeable
{
101 // ParserArenaFreeable objects are are freed when the arena is deleted.
102 // Destructors are not called. Clients must not call delete on such objects.
103 void* operator new(size_t, JSGlobalData
*);
106 class ParserArenaDeletable
{
108 virtual ~ParserArenaDeletable() { }
110 // ParserArenaDeletable objects are deleted when the arena is deleted.
111 // Clients must not call delete directly on such objects.
112 void* operator new(size_t, JSGlobalData
*);
115 template <typename T
>
116 struct ParserArenaData
: ParserArenaDeletable
{
120 class ParserArenaRefCounted
: public RefCounted
<ParserArenaRefCounted
> {
122 ParserArenaRefCounted(JSGlobalData
*);
125 virtual ~ParserArenaRefCounted()
127 ASSERT(deletionHasBegun());
131 class Node
: public ParserArenaFreeable
{
138 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* destination
= 0) = 0;
140 int lineNo() const { return m_lineNumber
; }
146 class ExpressionNode
: public Node
{
148 ExpressionNode(int, ResultType
= ResultType::unknownType());
151 virtual bool isNumber() const { return false; }
152 virtual bool isString() const { return false; }
153 virtual bool isNull() const { return false; }
154 virtual bool isPure(BytecodeGenerator
&) const { return false; }
155 virtual bool isLocation() const { return false; }
156 virtual bool isResolveNode() const { return false; }
157 virtual bool isBracketAccessorNode() const { return false; }
158 virtual bool isDotAccessorNode() const { return false; }
159 virtual bool isFuncExprNode() const { return false; }
160 virtual bool isCommaNode() const { return false; }
161 virtual bool isSimpleArray() const { return false; }
162 virtual bool isAdd() const { return false; }
163 virtual bool isSubtract() const { return false; }
164 virtual bool hasConditionContextCodegen() const { return false; }
166 virtual void emitBytecodeInConditionContext(BytecodeGenerator
&, Label
*, Label
*, bool) { ASSERT_NOT_REACHED(); }
168 virtual ExpressionNode
* stripUnaryPlus() { return this; }
170 ResultType
resultDescriptor() const { return m_resultType
; }
173 ResultType m_resultType
;
176 class StatementNode
: public Node
{
181 JS_EXPORT_PRIVATE
void setLoc(int firstLine
, int lastLine
);
182 int firstLine() const { return lineNo(); }
183 int lastLine() const { return m_lastLine
; }
185 virtual bool isEmptyStatement() const { return false; }
186 virtual bool isReturnNode() const { return false; }
187 virtual bool isExprStatement() const { return false; }
189 virtual bool isBlock() const { return false; }
195 class NullNode
: public ExpressionNode
{
200 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
202 virtual bool isNull() const { return true; }
205 class BooleanNode
: public ExpressionNode
{
207 BooleanNode(int, bool value
);
210 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
212 virtual bool isPure(BytecodeGenerator
&) const { return true; }
217 class NumberNode
: public ExpressionNode
{
219 NumberNode(int, double value
);
221 double value() const { return m_value
; }
222 void setValue(double value
) { m_value
= value
; }
225 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
227 virtual bool isNumber() const { return true; }
228 virtual bool isPure(BytecodeGenerator
&) const { return true; }
233 class StringNode
: public ExpressionNode
{
235 StringNode(int, const Identifier
&);
237 const Identifier
& value() { return m_value
; }
240 virtual bool isPure(BytecodeGenerator
&) const { return true; }
242 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
244 virtual bool isString() const { return true; }
246 const Identifier
& m_value
;
249 class ThrowableExpressionData
{
251 ThrowableExpressionData()
252 : m_divot(static_cast<uint32_t>(-1))
253 , m_startOffset(static_cast<uint16_t>(-1))
254 , m_endOffset(static_cast<uint16_t>(-1))
258 ThrowableExpressionData(unsigned divot
, unsigned startOffset
, unsigned endOffset
)
260 , m_startOffset(startOffset
)
261 , m_endOffset(endOffset
)
265 void setExceptionSourceCode(unsigned divot
, unsigned startOffset
, unsigned endOffset
)
268 m_startOffset
= startOffset
;
269 m_endOffset
= endOffset
;
272 uint32_t divot() const { return m_divot
; }
273 uint16_t startOffset() const { return m_startOffset
; }
274 uint16_t endOffset() const { return m_endOffset
; }
277 RegisterID
* emitThrowReferenceError(BytecodeGenerator
&, const UString
& message
);
281 uint16_t m_startOffset
;
282 uint16_t m_endOffset
;
285 class ThrowableSubExpressionData
: public ThrowableExpressionData
{
287 ThrowableSubExpressionData()
288 : m_subexpressionDivotOffset(0)
289 , m_subexpressionEndOffset(0)
293 ThrowableSubExpressionData(unsigned divot
, unsigned startOffset
, unsigned endOffset
)
294 : ThrowableExpressionData(divot
, startOffset
, endOffset
)
295 , m_subexpressionDivotOffset(0)
296 , m_subexpressionEndOffset(0)
300 void setSubexpressionInfo(uint32_t subexpressionDivot
, uint16_t subexpressionOffset
)
302 ASSERT(subexpressionDivot
<= divot());
303 if ((divot() - subexpressionDivot
) & ~0xFFFF) // Overflow means we can't do this safely, so just point at the primary divot
305 m_subexpressionDivotOffset
= divot() - subexpressionDivot
;
306 m_subexpressionEndOffset
= subexpressionOffset
;
310 uint16_t m_subexpressionDivotOffset
;
311 uint16_t m_subexpressionEndOffset
;
314 class ThrowablePrefixedSubExpressionData
: public ThrowableExpressionData
{
316 ThrowablePrefixedSubExpressionData()
317 : m_subexpressionDivotOffset(0)
318 , m_subexpressionStartOffset(0)
322 ThrowablePrefixedSubExpressionData(unsigned divot
, unsigned startOffset
, unsigned endOffset
)
323 : ThrowableExpressionData(divot
, startOffset
, endOffset
)
324 , m_subexpressionDivotOffset(0)
325 , m_subexpressionStartOffset(0)
329 void setSubexpressionInfo(uint32_t subexpressionDivot
, uint16_t subexpressionOffset
)
331 ASSERT(subexpressionDivot
>= divot());
332 if ((subexpressionDivot
- divot()) & ~0xFFFF) // Overflow means we can't do this safely, so just point at the primary divot
334 m_subexpressionDivotOffset
= subexpressionDivot
- divot();
335 m_subexpressionStartOffset
= subexpressionOffset
;
339 uint16_t m_subexpressionDivotOffset
;
340 uint16_t m_subexpressionStartOffset
;
343 class RegExpNode
: public ExpressionNode
, public ThrowableExpressionData
{
345 RegExpNode(int, const Identifier
& pattern
, const Identifier
& flags
);
348 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
350 const Identifier
& m_pattern
;
351 const Identifier
& m_flags
;
354 class ThisNode
: public ExpressionNode
{
359 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
362 class ResolveNode
: public ExpressionNode
{
364 ResolveNode(int, const Identifier
&, int startOffset
);
366 const Identifier
& identifier() const { return m_ident
; }
369 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
371 virtual bool isPure(BytecodeGenerator
&) const ;
372 virtual bool isLocation() const { return true; }
373 virtual bool isResolveNode() const { return true; }
375 const Identifier
& m_ident
;
376 int32_t m_startOffset
;
379 class ElementNode
: public ParserArenaFreeable
{
381 ElementNode(int elision
, ExpressionNode
*);
382 ElementNode(ElementNode
*, int elision
, ExpressionNode
*);
384 int elision() const { return m_elision
; }
385 ExpressionNode
* value() { return m_node
; }
386 ElementNode
* next() { return m_next
; }
391 ExpressionNode
* m_node
;
394 class ArrayNode
: public ExpressionNode
{
396 ArrayNode(int, int elision
);
397 ArrayNode(int, ElementNode
*);
398 ArrayNode(int, int elision
, ElementNode
*);
400 ArgumentListNode
* toArgumentList(JSGlobalData
*, int) const;
403 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
405 virtual bool isSimpleArray() const ;
407 ElementNode
* m_element
;
412 class PropertyNode
: public ParserArenaFreeable
{
414 enum Type
{ Constant
= 1, Getter
= 2, Setter
= 4 };
416 PropertyNode(JSGlobalData
*, const Identifier
&, ExpressionNode
*, Type
);
417 PropertyNode(JSGlobalData
*, double, ExpressionNode
*, Type
);
419 const Identifier
& name() const { return m_name
; }
420 Type
type() const { return m_type
; }
423 friend class PropertyListNode
;
424 const Identifier
& m_name
;
425 ExpressionNode
* m_assign
;
429 class PropertyListNode
: public Node
{
431 PropertyListNode(int, PropertyNode
*);
432 PropertyListNode(int, PropertyNode
*, PropertyListNode
*);
434 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
437 PropertyNode
* m_node
;
438 PropertyListNode
* m_next
;
441 class ObjectLiteralNode
: public ExpressionNode
{
443 ObjectLiteralNode(int);
444 ObjectLiteralNode(int, PropertyListNode
*);
447 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
449 PropertyListNode
* m_list
;
452 class BracketAccessorNode
: public ExpressionNode
, public ThrowableExpressionData
{
454 BracketAccessorNode(int, ExpressionNode
* base
, ExpressionNode
* subscript
, bool subscriptHasAssignments
);
456 ExpressionNode
* base() const { return m_base
; }
457 ExpressionNode
* subscript() const { return m_subscript
; }
460 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
462 virtual bool isLocation() const { return true; }
463 virtual bool isBracketAccessorNode() const { return true; }
465 ExpressionNode
* m_base
;
466 ExpressionNode
* m_subscript
;
467 bool m_subscriptHasAssignments
;
470 class DotAccessorNode
: public ExpressionNode
, public ThrowableExpressionData
{
472 DotAccessorNode(int, ExpressionNode
* base
, const Identifier
&);
474 ExpressionNode
* base() const { return m_base
; }
475 const Identifier
& identifier() const { return m_ident
; }
478 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
480 virtual bool isLocation() const { return true; }
481 virtual bool isDotAccessorNode() const { return true; }
483 ExpressionNode
* m_base
;
484 const Identifier
& m_ident
;
487 class ArgumentListNode
: public Node
{
489 ArgumentListNode(int, ExpressionNode
*);
490 ArgumentListNode(int, ArgumentListNode
*, ExpressionNode
*);
492 ArgumentListNode
* m_next
;
493 ExpressionNode
* m_expr
;
496 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
499 class ArgumentsNode
: public ParserArenaFreeable
{
502 ArgumentsNode(ArgumentListNode
*);
504 ArgumentListNode
* m_listNode
;
507 class NewExprNode
: public ExpressionNode
, public ThrowableExpressionData
{
509 NewExprNode(int, ExpressionNode
*);
510 NewExprNode(int, ExpressionNode
*, ArgumentsNode
*);
513 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
515 ExpressionNode
* m_expr
;
516 ArgumentsNode
* m_args
;
519 class EvalFunctionCallNode
: public ExpressionNode
, public ThrowableExpressionData
{
521 EvalFunctionCallNode(int, ArgumentsNode
*, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
524 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
526 ArgumentsNode
* m_args
;
529 class FunctionCallValueNode
: public ExpressionNode
, public ThrowableExpressionData
{
531 FunctionCallValueNode(int, ExpressionNode
*, ArgumentsNode
*, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
534 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
536 ExpressionNode
* m_expr
;
537 ArgumentsNode
* m_args
;
540 class FunctionCallResolveNode
: public ExpressionNode
, public ThrowableExpressionData
{
542 FunctionCallResolveNode(int, const Identifier
&, ArgumentsNode
*, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
545 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
547 const Identifier
& m_ident
;
548 ArgumentsNode
* m_args
;
549 size_t m_index
; // Used by LocalVarFunctionCallNode.
550 size_t m_scopeDepth
; // Used by ScopedVarFunctionCallNode and NonLocalVarFunctionCallNode
553 class FunctionCallBracketNode
: public ExpressionNode
, public ThrowableSubExpressionData
{
555 FunctionCallBracketNode(int, ExpressionNode
* base
, ExpressionNode
* subscript
, ArgumentsNode
*, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
558 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
560 ExpressionNode
* m_base
;
561 ExpressionNode
* m_subscript
;
562 ArgumentsNode
* m_args
;
565 class FunctionCallDotNode
: public ExpressionNode
, public ThrowableSubExpressionData
{
567 FunctionCallDotNode(int, ExpressionNode
* base
, const Identifier
&, ArgumentsNode
*, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
570 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
573 ExpressionNode
* m_base
;
574 const Identifier
& m_ident
;
575 ArgumentsNode
* m_args
;
578 class CallFunctionCallDotNode
: public FunctionCallDotNode
{
580 CallFunctionCallDotNode(int, ExpressionNode
* base
, const Identifier
&, ArgumentsNode
*, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
583 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
586 class ApplyFunctionCallDotNode
: public FunctionCallDotNode
{
588 ApplyFunctionCallDotNode(int, ExpressionNode
* base
, const Identifier
&, ArgumentsNode
*, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
591 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
594 class PrePostResolveNode
: public ExpressionNode
, public ThrowableExpressionData
{
596 PrePostResolveNode(int, const Identifier
&, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
599 const Identifier
& m_ident
;
602 class PostfixResolveNode
: public PrePostResolveNode
{
604 PostfixResolveNode(int, const Identifier
&, Operator
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
607 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
612 class PostfixBracketNode
: public ExpressionNode
, public ThrowableSubExpressionData
{
614 PostfixBracketNode(int, ExpressionNode
* base
, ExpressionNode
* subscript
, Operator
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
617 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
619 ExpressionNode
* m_base
;
620 ExpressionNode
* m_subscript
;
624 class PostfixDotNode
: public ExpressionNode
, public ThrowableSubExpressionData
{
626 PostfixDotNode(int, ExpressionNode
* base
, const Identifier
&, Operator
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
629 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
631 ExpressionNode
* m_base
;
632 const Identifier
& m_ident
;
636 class PostfixErrorNode
: public ExpressionNode
, public ThrowableSubExpressionData
{
638 PostfixErrorNode(int, ExpressionNode
*, Operator
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
641 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
643 ExpressionNode
* m_expr
;
647 class DeleteResolveNode
: public ExpressionNode
, public ThrowableExpressionData
{
649 DeleteResolveNode(int, const Identifier
&, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
652 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
654 const Identifier
& m_ident
;
657 class DeleteBracketNode
: public ExpressionNode
, public ThrowableExpressionData
{
659 DeleteBracketNode(int, ExpressionNode
* base
, ExpressionNode
* subscript
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
662 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
664 ExpressionNode
* m_base
;
665 ExpressionNode
* m_subscript
;
668 class DeleteDotNode
: public ExpressionNode
, public ThrowableExpressionData
{
670 DeleteDotNode(int, ExpressionNode
* base
, const Identifier
&, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
673 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
675 ExpressionNode
* m_base
;
676 const Identifier
& m_ident
;
679 class DeleteValueNode
: public ExpressionNode
{
681 DeleteValueNode(int, ExpressionNode
*);
684 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
686 ExpressionNode
* m_expr
;
689 class VoidNode
: public ExpressionNode
{
691 VoidNode(int, ExpressionNode
*);
694 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
696 ExpressionNode
* m_expr
;
699 class TypeOfResolveNode
: public ExpressionNode
{
701 TypeOfResolveNode(int, const Identifier
&);
703 const Identifier
& identifier() const { return m_ident
; }
706 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
708 const Identifier
& m_ident
;
711 class TypeOfValueNode
: public ExpressionNode
{
713 TypeOfValueNode(int, ExpressionNode
*);
716 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
718 ExpressionNode
* m_expr
;
721 class PrefixResolveNode
: public PrePostResolveNode
{
723 PrefixResolveNode(int, const Identifier
&, Operator
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
726 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
731 class PrefixBracketNode
: public ExpressionNode
, public ThrowablePrefixedSubExpressionData
{
733 PrefixBracketNode(int, ExpressionNode
* base
, ExpressionNode
* subscript
, Operator
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
736 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
738 ExpressionNode
* m_base
;
739 ExpressionNode
* m_subscript
;
743 class PrefixDotNode
: public ExpressionNode
, public ThrowablePrefixedSubExpressionData
{
745 PrefixDotNode(int, ExpressionNode
* base
, const Identifier
&, Operator
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
748 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
750 ExpressionNode
* m_base
;
751 const Identifier
& m_ident
;
755 class PrefixErrorNode
: public ExpressionNode
, public ThrowableExpressionData
{
757 PrefixErrorNode(int, ExpressionNode
*, Operator
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
760 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
762 ExpressionNode
* m_expr
;
766 class UnaryOpNode
: public ExpressionNode
{
768 UnaryOpNode(int, ResultType
, ExpressionNode
*, OpcodeID
);
771 ExpressionNode
* expr() { return m_expr
; }
772 const ExpressionNode
* expr() const { return m_expr
; }
775 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
777 OpcodeID
opcodeID() const { return m_opcodeID
; }
779 ExpressionNode
* m_expr
;
783 class UnaryPlusNode
: public UnaryOpNode
{
785 UnaryPlusNode(int, ExpressionNode
*);
788 virtual ExpressionNode
* stripUnaryPlus() { return expr(); }
791 class NegateNode
: public UnaryOpNode
{
793 NegateNode(int, ExpressionNode
*);
796 class BitwiseNotNode
: public ExpressionNode
{
798 BitwiseNotNode(int, ExpressionNode
*);
801 ExpressionNode
* expr() { return m_expr
; }
802 const ExpressionNode
* expr() const { return m_expr
; }
805 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
807 ExpressionNode
* m_expr
;
810 class LogicalNotNode
: public UnaryOpNode
{
812 LogicalNotNode(int, ExpressionNode
*);
814 void emitBytecodeInConditionContext(BytecodeGenerator
&, Label
* trueTarget
, Label
* falseTarget
, bool fallThroughMeansTrue
);
815 virtual bool hasConditionContextCodegen() const { return expr()->hasConditionContextCodegen(); }
818 class BinaryOpNode
: public ExpressionNode
{
820 BinaryOpNode(int, ExpressionNode
* expr1
, ExpressionNode
* expr2
, OpcodeID
, bool rightHasAssignments
);
821 BinaryOpNode(int, ResultType
, ExpressionNode
* expr1
, ExpressionNode
* expr2
, OpcodeID
, bool rightHasAssignments
);
823 RegisterID
* emitStrcat(BytecodeGenerator
& generator
, RegisterID
* destination
, RegisterID
* lhs
= 0, ReadModifyResolveNode
* emitExpressionInfoForMe
= 0);
825 ExpressionNode
* lhs() { return m_expr1
; };
826 ExpressionNode
* rhs() { return m_expr2
; };
829 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
832 OpcodeID
opcodeID() const { return m_opcodeID
; }
835 ExpressionNode
* m_expr1
;
836 ExpressionNode
* m_expr2
;
840 bool m_rightHasAssignments
;
843 class MultNode
: public BinaryOpNode
{
845 MultNode(int, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
848 class DivNode
: public BinaryOpNode
{
850 DivNode(int, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
853 class ModNode
: public BinaryOpNode
{
855 ModNode(int, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
858 class AddNode
: public BinaryOpNode
{
860 AddNode(int, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
862 virtual bool isAdd() const { return true; }
865 class SubNode
: public BinaryOpNode
{
867 SubNode(int, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
869 virtual bool isSubtract() const { return true; }
872 class LeftShiftNode
: public BinaryOpNode
{
874 LeftShiftNode(int, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
877 class RightShiftNode
: public BinaryOpNode
{
879 RightShiftNode(int, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
882 class UnsignedRightShiftNode
: public BinaryOpNode
{
884 UnsignedRightShiftNode(int, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
887 class LessNode
: public BinaryOpNode
{
889 LessNode(int, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
892 class GreaterNode
: public BinaryOpNode
{
894 GreaterNode(int, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
897 class LessEqNode
: public BinaryOpNode
{
899 LessEqNode(int, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
902 class GreaterEqNode
: public BinaryOpNode
{
904 GreaterEqNode(int, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
907 class ThrowableBinaryOpNode
: public BinaryOpNode
, public ThrowableExpressionData
{
909 ThrowableBinaryOpNode(int, ResultType
, ExpressionNode
* expr1
, ExpressionNode
* expr2
, OpcodeID
, bool rightHasAssignments
);
910 ThrowableBinaryOpNode(int, ExpressionNode
* expr1
, ExpressionNode
* expr2
, OpcodeID
, bool rightHasAssignments
);
913 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
916 class InstanceOfNode
: public ThrowableBinaryOpNode
{
918 InstanceOfNode(int, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
921 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
924 class InNode
: public ThrowableBinaryOpNode
{
926 InNode(int, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
929 class EqualNode
: public BinaryOpNode
{
931 EqualNode(int, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
934 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
937 class NotEqualNode
: public BinaryOpNode
{
939 NotEqualNode(int, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
942 class StrictEqualNode
: public BinaryOpNode
{
944 StrictEqualNode(int, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
947 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
950 class NotStrictEqualNode
: public BinaryOpNode
{
952 NotStrictEqualNode(int, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
955 class BitAndNode
: public BinaryOpNode
{
957 BitAndNode(int, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
960 class BitOrNode
: public BinaryOpNode
{
962 BitOrNode(int, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
965 class BitXOrNode
: public BinaryOpNode
{
967 BitXOrNode(int, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
970 // m_expr1 && m_expr2, m_expr1 || m_expr2
971 class LogicalOpNode
: public ExpressionNode
{
973 LogicalOpNode(int, ExpressionNode
* expr1
, ExpressionNode
* expr2
, LogicalOperator
);
976 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
977 void emitBytecodeInConditionContext(BytecodeGenerator
&, Label
* trueTarget
, Label
* falseTarget
, bool fallThroughMeansTrue
);
978 virtual bool hasConditionContextCodegen() const { return true; }
980 ExpressionNode
* m_expr1
;
981 ExpressionNode
* m_expr2
;
982 LogicalOperator m_operator
;
985 // The ternary operator, "m_logical ? m_expr1 : m_expr2"
986 class ConditionalNode
: public ExpressionNode
{
988 ConditionalNode(int, ExpressionNode
* logical
, ExpressionNode
* expr1
, ExpressionNode
* expr2
);
991 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
993 ExpressionNode
* m_logical
;
994 ExpressionNode
* m_expr1
;
995 ExpressionNode
* m_expr2
;
998 class ReadModifyResolveNode
: public ExpressionNode
, public ThrowableExpressionData
{
1000 ReadModifyResolveNode(int, const Identifier
&, Operator
, ExpressionNode
* right
, bool rightHasAssignments
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
1003 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1005 const Identifier
& m_ident
;
1006 ExpressionNode
* m_right
;
1007 size_t m_index
; // Used by ReadModifyLocalVarNode.
1008 Operator m_operator
;
1009 bool m_rightHasAssignments
;
1012 class AssignResolveNode
: public ExpressionNode
, public ThrowableExpressionData
{
1014 AssignResolveNode(int, const Identifier
&, ExpressionNode
* right
, bool rightHasAssignments
);
1017 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1019 const Identifier
& m_ident
;
1020 ExpressionNode
* m_right
;
1021 size_t m_index
; // Used by ReadModifyLocalVarNode.
1022 bool m_rightHasAssignments
;
1025 class ReadModifyBracketNode
: public ExpressionNode
, public ThrowableSubExpressionData
{
1027 ReadModifyBracketNode(int, ExpressionNode
* base
, ExpressionNode
* subscript
, Operator
, ExpressionNode
* right
, bool subscriptHasAssignments
, bool rightHasAssignments
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
1030 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1032 ExpressionNode
* m_base
;
1033 ExpressionNode
* m_subscript
;
1034 ExpressionNode
* m_right
;
1035 Operator m_operator
: 30;
1036 bool m_subscriptHasAssignments
: 1;
1037 bool m_rightHasAssignments
: 1;
1040 class AssignBracketNode
: public ExpressionNode
, public ThrowableExpressionData
{
1042 AssignBracketNode(int, ExpressionNode
* base
, ExpressionNode
* subscript
, ExpressionNode
* right
, bool subscriptHasAssignments
, bool rightHasAssignments
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
1045 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1047 ExpressionNode
* m_base
;
1048 ExpressionNode
* m_subscript
;
1049 ExpressionNode
* m_right
;
1050 bool m_subscriptHasAssignments
: 1;
1051 bool m_rightHasAssignments
: 1;
1054 class AssignDotNode
: public ExpressionNode
, public ThrowableExpressionData
{
1056 AssignDotNode(int, ExpressionNode
* base
, const Identifier
&, ExpressionNode
* right
, bool rightHasAssignments
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
1059 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1061 ExpressionNode
* m_base
;
1062 const Identifier
& m_ident
;
1063 ExpressionNode
* m_right
;
1064 bool m_rightHasAssignments
;
1067 class ReadModifyDotNode
: public ExpressionNode
, public ThrowableSubExpressionData
{
1069 ReadModifyDotNode(int, ExpressionNode
* base
, const Identifier
&, Operator
, ExpressionNode
* right
, bool rightHasAssignments
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
1072 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1074 ExpressionNode
* m_base
;
1075 const Identifier
& m_ident
;
1076 ExpressionNode
* m_right
;
1077 Operator m_operator
: 31;
1078 bool m_rightHasAssignments
: 1;
1081 class AssignErrorNode
: public ExpressionNode
, public ThrowableExpressionData
{
1083 AssignErrorNode(int, ExpressionNode
* left
, Operator
, ExpressionNode
* right
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
1086 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1088 ExpressionNode
* m_left
;
1089 Operator m_operator
;
1090 ExpressionNode
* m_right
;
1093 typedef Vector
<ExpressionNode
*, 8> ExpressionVector
;
1095 class CommaNode
: public ExpressionNode
, public ParserArenaDeletable
{
1097 CommaNode(int, ExpressionNode
* expr1
, ExpressionNode
* expr2
);
1099 using ParserArenaDeletable::operator new;
1101 void append(ExpressionNode
* expr
) { m_expressions
.append(expr
); }
1104 virtual bool isCommaNode() const { return true; }
1105 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1107 ExpressionVector m_expressions
;
1110 class ConstDeclNode
: public ExpressionNode
{
1112 ConstDeclNode(int, const Identifier
&, ExpressionNode
*);
1114 bool hasInitializer() const { return m_init
; }
1115 const Identifier
& ident() { return m_ident
; }
1118 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1119 virtual RegisterID
* emitCodeSingle(BytecodeGenerator
&);
1121 const Identifier
& m_ident
;
1124 ConstDeclNode
* m_next
;
1127 ExpressionNode
* m_init
;
1130 class ConstStatementNode
: public StatementNode
{
1132 ConstStatementNode(int, ConstDeclNode
* next
);
1135 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1137 ConstDeclNode
* m_next
;
1140 class SourceElements
: public ParserArenaDeletable
{
1144 void append(StatementNode
*);
1146 StatementNode
* singleStatement() const;
1147 StatementNode
* lastStatement() const;
1149 void emitBytecode(BytecodeGenerator
&, RegisterID
* destination
);
1152 Vector
<StatementNode
*> m_statements
;
1155 class BlockNode
: public StatementNode
{
1157 BlockNode(int, SourceElements
* = 0);
1159 StatementNode
* singleStatement() const;
1160 StatementNode
* lastStatement() const;
1163 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1165 virtual bool isBlock() const { return true; }
1167 SourceElements
* m_statements
;
1170 class EmptyStatementNode
: public StatementNode
{
1172 EmptyStatementNode(int);
1175 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1177 virtual bool isEmptyStatement() const { return true; }
1180 class DebuggerStatementNode
: public StatementNode
{
1182 DebuggerStatementNode(int);
1185 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1188 class ExprStatementNode
: public StatementNode
{
1190 ExprStatementNode(int, ExpressionNode
*);
1192 ExpressionNode
* expr() const { return m_expr
; }
1195 virtual bool isExprStatement() const { return true; }
1197 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1199 ExpressionNode
* m_expr
;
1202 class VarStatementNode
: public StatementNode
{
1204 VarStatementNode(int, ExpressionNode
*);
1207 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1209 ExpressionNode
* m_expr
;
1212 class IfNode
: public StatementNode
{
1214 IfNode(int, ExpressionNode
* condition
, StatementNode
* ifBlock
);
1217 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1219 ExpressionNode
* m_condition
;
1220 StatementNode
* m_ifBlock
;
1223 class IfElseNode
: public IfNode
{
1225 IfElseNode(int, ExpressionNode
* condition
, StatementNode
* ifBlock
, StatementNode
* elseBlock
);
1228 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1230 StatementNode
* m_elseBlock
;
1233 class DoWhileNode
: public StatementNode
{
1235 DoWhileNode(int, StatementNode
*, ExpressionNode
*);
1238 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1240 StatementNode
* m_statement
;
1241 ExpressionNode
* m_expr
;
1244 class WhileNode
: public StatementNode
{
1246 WhileNode(int, ExpressionNode
*, StatementNode
*);
1249 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1251 ExpressionNode
* m_expr
;
1252 StatementNode
* m_statement
;
1255 class ForNode
: public StatementNode
{
1257 ForNode(int, ExpressionNode
* expr1
, ExpressionNode
* expr2
, ExpressionNode
* expr3
, StatementNode
*, bool expr1WasVarDecl
);
1260 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1262 ExpressionNode
* m_expr1
;
1263 ExpressionNode
* m_expr2
;
1264 ExpressionNode
* m_expr3
;
1265 StatementNode
* m_statement
;
1266 bool m_expr1WasVarDecl
;
1269 class ForInNode
: public StatementNode
, public ThrowableExpressionData
{
1271 ForInNode(JSGlobalData
*, int, ExpressionNode
*, ExpressionNode
*, StatementNode
*);
1272 ForInNode(JSGlobalData
*, int, const Identifier
&, ExpressionNode
*, ExpressionNode
*, StatementNode
*, int divot
, int startOffset
, int endOffset
);
1275 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1277 const Identifier
& m_ident
;
1278 ExpressionNode
* m_init
;
1279 ExpressionNode
* m_lexpr
;
1280 ExpressionNode
* m_expr
;
1281 StatementNode
* m_statement
;
1282 bool m_identIsVarDecl
;
1285 class ContinueNode
: public StatementNode
, public ThrowableExpressionData
{
1287 ContinueNode(JSGlobalData
*, int);
1288 ContinueNode(int, const Identifier
&);
1291 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1293 const Identifier
& m_ident
;
1296 class BreakNode
: public StatementNode
, public ThrowableExpressionData
{
1298 BreakNode(JSGlobalData
*, int);
1299 BreakNode(int, const Identifier
&);
1302 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1304 const Identifier
& m_ident
;
1307 class ReturnNode
: public StatementNode
, public ThrowableExpressionData
{
1309 ReturnNode(int, ExpressionNode
* value
);
1311 ExpressionNode
* value() { return m_value
; }
1314 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1316 virtual bool isReturnNode() const { return true; }
1318 ExpressionNode
* m_value
;
1321 class WithNode
: public StatementNode
{
1323 WithNode(int, ExpressionNode
*, StatementNode
*, uint32_t divot
, uint32_t expressionLength
);
1326 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1328 ExpressionNode
* m_expr
;
1329 StatementNode
* m_statement
;
1331 uint32_t m_expressionLength
;
1334 class LabelNode
: public StatementNode
, public ThrowableExpressionData
{
1336 LabelNode(int, const Identifier
& name
, StatementNode
*);
1339 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1341 const Identifier
& m_name
;
1342 StatementNode
* m_statement
;
1345 class ThrowNode
: public StatementNode
, public ThrowableExpressionData
{
1347 ThrowNode(int, ExpressionNode
*);
1350 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1352 ExpressionNode
* m_expr
;
1355 class TryNode
: public StatementNode
{
1357 TryNode(int, StatementNode
* tryBlock
, const Identifier
& exceptionIdent
, StatementNode
* catchBlock
, StatementNode
* finallyBlock
);
1360 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1362 StatementNode
* m_tryBlock
;
1363 const Identifier
& m_exceptionIdent
;
1364 StatementNode
* m_catchBlock
;
1365 StatementNode
* m_finallyBlock
;
1368 class ParameterNode
: public ParserArenaFreeable
{
1370 ParameterNode(const Identifier
&);
1371 ParameterNode(ParameterNode
*, const Identifier
&);
1373 const Identifier
& ident() const { return m_ident
; }
1374 ParameterNode
* nextParam() const { return m_next
; }
1377 const Identifier
& m_ident
;
1378 ParameterNode
* m_next
;
1381 class ScopeNode
: public StatementNode
, public ParserArenaRefCounted
{
1383 typedef DeclarationStacks::VarStack VarStack
;
1384 typedef DeclarationStacks::FunctionStack FunctionStack
;
1386 ScopeNode(JSGlobalData
*, int, bool inStrictContext
);
1387 ScopeNode(JSGlobalData
*, int, const SourceCode
&, SourceElements
*, VarStack
*, FunctionStack
*, IdentifierSet
&, CodeFeatures
, int numConstants
);
1389 using ParserArenaRefCounted::operator new;
1395 m_functionStack
.clear();
1397 m_capturedVariables
.clear();
1400 const SourceCode
& source() const { return m_source
; }
1401 const UString
& sourceURL() const { return m_source
.provider()->url(); }
1402 intptr_t sourceID() const { return m_source
.providerID(); }
1404 void setFeatures(CodeFeatures features
) { m_features
= features
; }
1405 CodeFeatures
features() { return m_features
; }
1407 bool usesEval() const { return m_features
& EvalFeature
; }
1408 bool usesArguments() const { return (m_features
& ArgumentsFeature
) && !(m_features
& ShadowsArgumentsFeature
); }
1409 bool isStrictMode() const { return m_features
& StrictModeFeature
; }
1410 void setUsesArguments() { m_features
|= ArgumentsFeature
; }
1411 bool usesThis() const { return m_features
& ThisFeature
; }
1412 bool needsActivationForMoreThanVariables() const { return m_features
& (EvalFeature
| WithFeature
| CatchFeature
); }
1413 bool needsActivation() const { return (hasCapturedVariables()) || (m_features
& (EvalFeature
| WithFeature
| CatchFeature
)); }
1414 bool hasCapturedVariables() const { return !!m_capturedVariables
.size(); }
1415 size_t capturedVariableCount() const { return m_capturedVariables
.size(); }
1416 bool captures(const Identifier
& ident
) { return m_capturedVariables
.contains(ident
.impl()); }
1418 VarStack
& varStack() { return m_varStack
; }
1419 FunctionStack
& functionStack() { return m_functionStack
; }
1421 int neededConstants()
1423 // We may need 2 more constants than the count given by the parser,
1424 // because of the various uses of jsUndefined() and jsNull().
1425 return m_numConstants
+ 2;
1428 StatementNode
* singleStatement() const;
1430 void emitStatementsBytecode(BytecodeGenerator
&, RegisterID
* destination
);
1433 void setSource(const SourceCode
& source
) { m_source
= source
; }
1434 ParserArena m_arena
;
1437 CodeFeatures m_features
;
1438 SourceCode m_source
;
1439 VarStack m_varStack
;
1440 FunctionStack m_functionStack
;
1442 SourceElements
* m_statements
;
1443 IdentifierSet m_capturedVariables
;
1446 class ProgramNode
: public ScopeNode
{
1448 static const bool isFunctionNode
= false;
1449 static PassRefPtr
<ProgramNode
> create(JSGlobalData
*, int, SourceElements
*, VarStack
*, FunctionStack
*, IdentifierSet
&, const SourceCode
&, CodeFeatures
, int numConstants
);
1451 static const bool scopeIsFunction
= false;
1454 ProgramNode(JSGlobalData
*, int, SourceElements
*, VarStack
*, FunctionStack
*, IdentifierSet
&, const SourceCode
&, CodeFeatures
, int numConstants
);
1456 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1459 class EvalNode
: public ScopeNode
{
1461 static const bool isFunctionNode
= false;
1462 static PassRefPtr
<EvalNode
> create(JSGlobalData
*, int, SourceElements
*, VarStack
*, FunctionStack
*, IdentifierSet
&, const SourceCode
&, CodeFeatures
, int numConstants
);
1464 static const bool scopeIsFunction
= false;
1467 EvalNode(JSGlobalData
*, int, SourceElements
*, VarStack
*, FunctionStack
*, IdentifierSet
&, const SourceCode
&, CodeFeatures
, int numConstants
);
1469 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1472 class FunctionParameters
: public Vector
<Identifier
>, public RefCounted
<FunctionParameters
> {
1473 WTF_MAKE_FAST_ALLOCATED
;
1475 static PassRefPtr
<FunctionParameters
> create(ParameterNode
* firstParameter
) { return adoptRef(new FunctionParameters(firstParameter
)); }
1478 FunctionParameters(ParameterNode
*);
1481 class FunctionBodyNode
: public ScopeNode
{
1483 static const bool isFunctionNode
= true;
1484 static FunctionBodyNode
* create(JSGlobalData
*, int, bool isStrictMode
);
1485 static PassRefPtr
<FunctionBodyNode
> create(JSGlobalData
*, int, SourceElements
*, VarStack
*, FunctionStack
*, IdentifierSet
&, const SourceCode
&, CodeFeatures
, int numConstants
);
1487 FunctionParameters
* parameters() const { return m_parameters
.get(); }
1488 size_t parameterCount() const { return m_parameters
->size(); }
1490 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1492 void finishParsing(const SourceCode
&, ParameterNode
*, const Identifier
&);
1493 void finishParsing(PassRefPtr
<FunctionParameters
>, const Identifier
&);
1495 const Identifier
& ident() { return m_ident
; }
1496 void setInferredName(const Identifier
& inferredName
) { ASSERT(!inferredName
.isNull()); m_inferredName
= inferredName
; }
1497 const Identifier
& inferredName() { return m_inferredName
.isEmpty() ? m_ident
: m_inferredName
; }
1499 static const bool scopeIsFunction
= true;
1502 FunctionBodyNode(JSGlobalData
*, int, bool inStrictContext
);
1503 FunctionBodyNode(JSGlobalData
*, int, SourceElements
*, VarStack
*, FunctionStack
*, IdentifierSet
&, const SourceCode
&, CodeFeatures
, int numConstants
);
1506 Identifier m_inferredName
;
1507 RefPtr
<FunctionParameters
> m_parameters
;
1510 class FuncExprNode
: public ExpressionNode
{
1512 FuncExprNode(int, const Identifier
&, FunctionBodyNode
*, const SourceCode
&, ParameterNode
* = 0);
1514 FunctionBodyNode
* body() { return m_body
; }
1517 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1519 virtual bool isFuncExprNode() const { return true; }
1521 FunctionBodyNode
* m_body
;
1524 class FuncDeclNode
: public StatementNode
{
1526 FuncDeclNode(int, const Identifier
&, FunctionBodyNode
*, const SourceCode
&, ParameterNode
* = 0);
1528 FunctionBodyNode
* body() { return m_body
; }
1531 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1533 FunctionBodyNode
* m_body
;
1536 class CaseClauseNode
: public ParserArenaFreeable
{
1538 CaseClauseNode(ExpressionNode
*, SourceElements
* = 0);
1540 ExpressionNode
* expr() const { return m_expr
; }
1542 void emitBytecode(BytecodeGenerator
&, RegisterID
* destination
);
1545 ExpressionNode
* m_expr
;
1546 SourceElements
* m_statements
;
1549 class ClauseListNode
: public ParserArenaFreeable
{
1551 ClauseListNode(CaseClauseNode
*);
1552 ClauseListNode(ClauseListNode
*, CaseClauseNode
*);
1554 CaseClauseNode
* getClause() const { return m_clause
; }
1555 ClauseListNode
* getNext() const { return m_next
; }
1558 CaseClauseNode
* m_clause
;
1559 ClauseListNode
* m_next
;
1562 class CaseBlockNode
: public ParserArenaFreeable
{
1564 CaseBlockNode(ClauseListNode
* list1
, CaseClauseNode
* defaultClause
, ClauseListNode
* list2
);
1566 RegisterID
* emitBytecodeForBlock(BytecodeGenerator
&, RegisterID
* input
, RegisterID
* destination
);
1569 SwitchInfo::SwitchType
tryOptimizedSwitch(Vector
<ExpressionNode
*, 8>& literalVector
, int32_t& min_num
, int32_t& max_num
);
1570 ClauseListNode
* m_list1
;
1571 CaseClauseNode
* m_defaultClause
;
1572 ClauseListNode
* m_list2
;
1575 class SwitchNode
: public StatementNode
{
1577 SwitchNode(int, ExpressionNode
*, CaseBlockNode
*);
1580 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1582 ExpressionNode
* m_expr
;
1583 CaseBlockNode
* m_block
;
1586 struct ElementList
{
1591 struct PropertyList
{
1592 PropertyListNode
* head
;
1593 PropertyListNode
* tail
;
1596 struct ArgumentList
{
1597 ArgumentListNode
* head
;
1598 ArgumentListNode
* tail
;
1601 struct ConstDeclList
{
1602 ConstDeclNode
* head
;
1603 ConstDeclNode
* tail
;
1606 struct ParameterList
{
1607 ParameterNode
* head
;
1608 ParameterNode
* tail
;
1612 ClauseListNode
* head
;
1613 ClauseListNode
* tail
;