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>
37 #include <wtf/OwnPtr.h>
41 class ArgumentListNode;
43 class BytecodeGenerator;
47 class ProgramCodeBlock;
48 class PropertyListNode;
49 class ReadModifyResolveNode;
53 typedef unsigned CodeFeatures;
55 const CodeFeatures NoFeatures = 0;
56 const CodeFeatures EvalFeature = 1 << 0;
57 const CodeFeatures ClosureFeature = 1 << 1;
58 const CodeFeatures AssignFeature = 1 << 2;
59 const CodeFeatures ArgumentsFeature = 1 << 3;
60 const CodeFeatures WithFeature = 1 << 4;
61 const CodeFeatures CatchFeature = 1 << 5;
62 const CodeFeatures ThisFeature = 1 << 6;
63 const CodeFeatures AllFeatures = EvalFeature | ClosureFeature | AssignFeature | ArgumentsFeature | WithFeature | CatchFeature | ThisFeature;
82 enum LogicalOperator {
87 namespace DeclarationStacks {
88 enum VarAttrs { IsConstant = 1, HasInitializer = 2 };
89 typedef Vector<std::pair<Identifier, unsigned> > VarStack;
90 typedef Vector<FuncDeclNode*> FunctionStack;
94 enum SwitchType { SwitchNone, SwitchImmediate, SwitchCharacter, SwitchString };
95 uint32_t bytecodeOffset;
96 SwitchType switchType;
99 class ParserArenaDeletable {
101 ParserArenaDeletable() { }
104 virtual ~ParserArenaDeletable() { }
106 // Objects created with this version of new are deleted when the arena is deleted.
107 void* operator new(size_t, JSGlobalData*);
109 // Objects created with this version of new are not deleted when the arena is deleted.
110 // Other arrangements must be made.
111 void* operator new(size_t);
113 void operator delete(void*);
116 class ParserArenaRefCounted : public RefCountedCustomAllocated<ParserArenaRefCounted> {
118 ParserArenaRefCounted(JSGlobalData*);
121 virtual ~ParserArenaRefCounted()
123 ASSERT(deletionHasBegun());
127 class Node : public ParserArenaDeletable {
133 Return value: The register holding the production's value.
134 dst: An optional parameter specifying the most efficient
135 destination at which to store the production's value.
136 The callee must honor dst.
138 dst provides for a crude form of copy propagation. For example,
151 because the assignment node, "x =", passes r[x] as dst to the number
154 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* dst = 0) = 0;
156 int lineNo() const { return m_line; }
162 class ExpressionNode : public Node {
164 ExpressionNode(JSGlobalData*, ResultType = ResultType::unknownType());
166 virtual bool isNumber() const { return false; }
167 virtual bool isString() const { return false; }
168 virtual bool isNull() const { return false; }
169 virtual bool isPure(BytecodeGenerator&) const { return false; }
170 virtual bool isLocation() const { return false; }
171 virtual bool isResolveNode() const { return false; }
172 virtual bool isBracketAccessorNode() const { return false; }
173 virtual bool isDotAccessorNode() const { return false; }
174 virtual bool isFuncExprNode() const { return false; }
175 virtual bool isCommaNode() const { return false; }
176 virtual bool isSimpleArray() const { return false; }
177 virtual bool isAdd() const { return false; }
179 virtual ExpressionNode* stripUnaryPlus() { return this; }
181 ResultType resultDescriptor() const { return m_resultType; }
183 // This needs to be in public in order to compile using GCC 3.x
184 typedef enum { EvalOperator, FunctionCall } CallerType;
187 ResultType m_resultType;
190 class StatementNode : public Node {
192 StatementNode(JSGlobalData*);
194 void setLoc(int line0, int line1);
195 int firstLine() const { return lineNo(); }
196 int lastLine() const { return m_lastLine; }
198 virtual bool isEmptyStatement() const { return false; }
199 virtual bool isReturnNode() const { return false; }
200 virtual bool isExprStatement() const { return false; }
202 virtual bool isBlock() const { return false; }
208 class NullNode : public ExpressionNode {
210 NullNode(JSGlobalData*);
213 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
215 virtual bool isNull() const { return true; }
218 class BooleanNode : public ExpressionNode {
220 BooleanNode(JSGlobalData*, bool value);
223 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
225 virtual bool isPure(BytecodeGenerator&) const { return true; }
230 class NumberNode : public ExpressionNode {
232 NumberNode(JSGlobalData*, double v);
234 double value() const { return m_double; }
235 void setValue(double d) { m_double = d; }
238 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
240 virtual bool isNumber() const { return true; }
241 virtual bool isPure(BytecodeGenerator&) const { return true; }
246 class StringNode : public ExpressionNode {
248 StringNode(JSGlobalData*, const Identifier& v);
250 const Identifier& value() { return m_value; }
251 virtual bool isPure(BytecodeGenerator&) const { return true; }
254 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
256 virtual bool isString() const { return true; }
261 class ThrowableExpressionData {
263 ThrowableExpressionData()
264 : m_divot(static_cast<uint32_t>(-1))
265 , m_startOffset(static_cast<uint16_t>(-1))
266 , m_endOffset(static_cast<uint16_t>(-1))
270 ThrowableExpressionData(unsigned divot, unsigned startOffset, unsigned endOffset)
272 , m_startOffset(startOffset)
273 , m_endOffset(endOffset)
277 void setExceptionSourceCode(unsigned divot, unsigned startOffset, unsigned endOffset)
280 m_startOffset = startOffset;
281 m_endOffset = endOffset;
284 uint32_t divot() const { return m_divot; }
285 uint16_t startOffset() const { return m_startOffset; }
286 uint16_t endOffset() const { return m_endOffset; }
289 RegisterID* emitThrowError(BytecodeGenerator&, ErrorType, const char* msg);
290 RegisterID* emitThrowError(BytecodeGenerator&, ErrorType, const char* msg, const Identifier&);
294 uint16_t m_startOffset;
295 uint16_t m_endOffset;
298 class ThrowableSubExpressionData : public ThrowableExpressionData {
300 ThrowableSubExpressionData()
301 : ThrowableExpressionData()
302 , m_subexpressionDivotOffset(0)
303 , m_subexpressionEndOffset(0)
307 ThrowableSubExpressionData(unsigned divot, unsigned startOffset, unsigned endOffset)
308 : ThrowableExpressionData(divot, startOffset, endOffset)
309 , m_subexpressionDivotOffset(0)
310 , m_subexpressionEndOffset(0)
314 void setSubexpressionInfo(uint32_t subexpressionDivot, uint16_t subexpressionOffset)
316 ASSERT(subexpressionDivot <= divot());
317 if ((divot() - subexpressionDivot) & ~0xFFFF) // Overflow means we can't do this safely, so just point at the primary divot
319 m_subexpressionDivotOffset = divot() - subexpressionDivot;
320 m_subexpressionEndOffset = subexpressionOffset;
324 uint16_t m_subexpressionDivotOffset;
325 uint16_t m_subexpressionEndOffset;
328 class ThrowablePrefixedSubExpressionData : public ThrowableExpressionData {
330 ThrowablePrefixedSubExpressionData()
331 : ThrowableExpressionData()
332 , m_subexpressionDivotOffset(0)
333 , m_subexpressionStartOffset(0)
337 ThrowablePrefixedSubExpressionData(unsigned divot, unsigned startOffset, unsigned endOffset)
338 : ThrowableExpressionData(divot, startOffset, endOffset)
339 , m_subexpressionDivotOffset(0)
340 , m_subexpressionStartOffset(0)
344 void setSubexpressionInfo(uint32_t subexpressionDivot, uint16_t subexpressionOffset)
346 ASSERT(subexpressionDivot >= divot());
347 if ((subexpressionDivot - divot()) & ~0xFFFF) // Overflow means we can't do this safely, so just point at the primary divot
349 m_subexpressionDivotOffset = subexpressionDivot - divot();
350 m_subexpressionStartOffset = subexpressionOffset;
354 uint16_t m_subexpressionDivotOffset;
355 uint16_t m_subexpressionStartOffset;
358 class RegExpNode : public ExpressionNode, public ThrowableExpressionData {
360 RegExpNode(JSGlobalData*, const UString& pattern, const UString& flags);
363 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
369 class ThisNode : public ExpressionNode {
371 ThisNode(JSGlobalData*);
374 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
377 class ResolveNode : public ExpressionNode {
379 ResolveNode(JSGlobalData*, const Identifier&, int startOffset);
381 const Identifier& identifier() const { return m_ident; }
384 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
386 virtual bool isPure(BytecodeGenerator&) const ;
387 virtual bool isLocation() const { return true; }
388 virtual bool isResolveNode() const { return true; }
391 int32_t m_startOffset;
394 class ElementNode : public ParserArenaDeletable {
396 ElementNode(JSGlobalData*, int elision, ExpressionNode*);
397 ElementNode(JSGlobalData*, ElementNode*, int elision, ExpressionNode*);
399 int elision() const { return m_elision; }
400 ExpressionNode* value() { return m_node; }
401 ElementNode* next() { return m_next; }
406 ExpressionNode* m_node;
409 class ArrayNode : public ExpressionNode {
411 ArrayNode(JSGlobalData*, int elision);
412 ArrayNode(JSGlobalData*, ElementNode*);
413 ArrayNode(JSGlobalData*, int elision, ElementNode*);
415 ArgumentListNode* toArgumentList(JSGlobalData*) const;
418 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
420 virtual bool isSimpleArray() const ;
422 ElementNode* m_element;
427 class PropertyNode : public ParserArenaDeletable {
429 enum Type { Constant, Getter, Setter };
431 PropertyNode(JSGlobalData*, const Identifier& name, ExpressionNode* value, Type);
433 const Identifier& name() const { return m_name; }
436 friend class PropertyListNode;
438 ExpressionNode* m_assign;
442 class PropertyListNode : public Node {
444 PropertyListNode(JSGlobalData*, PropertyNode*);
445 PropertyListNode(JSGlobalData*, PropertyNode*, PropertyListNode*);
447 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
450 PropertyNode* m_node;
451 PropertyListNode* m_next;
454 class ObjectLiteralNode : public ExpressionNode {
456 ObjectLiteralNode(JSGlobalData*);
457 ObjectLiteralNode(JSGlobalData*, PropertyListNode*);
460 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
462 PropertyListNode* m_list;
465 class BracketAccessorNode : public ExpressionNode, public ThrowableExpressionData {
467 BracketAccessorNode(JSGlobalData*, ExpressionNode* base, ExpressionNode* subscript, bool subscriptHasAssignments);
469 ExpressionNode* base() const { return m_base; }
470 ExpressionNode* subscript() const { return m_subscript; }
473 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
475 virtual bool isLocation() const { return true; }
476 virtual bool isBracketAccessorNode() const { return true; }
478 ExpressionNode* m_base;
479 ExpressionNode* m_subscript;
480 bool m_subscriptHasAssignments;
483 class DotAccessorNode : public ExpressionNode, public ThrowableExpressionData {
485 DotAccessorNode(JSGlobalData*, ExpressionNode* base, const Identifier&);
487 ExpressionNode* base() const { return m_base; }
488 const Identifier& identifier() const { return m_ident; }
491 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
493 virtual bool isLocation() const { return true; }
494 virtual bool isDotAccessorNode() const { return true; }
496 ExpressionNode* m_base;
500 class ArgumentListNode : public Node {
502 ArgumentListNode(JSGlobalData*, ExpressionNode*);
503 ArgumentListNode(JSGlobalData*, ArgumentListNode*, ExpressionNode*);
505 ArgumentListNode* m_next;
506 ExpressionNode* m_expr;
509 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
512 class ArgumentsNode : public ParserArenaDeletable {
514 ArgumentsNode(JSGlobalData*);
515 ArgumentsNode(JSGlobalData*, ArgumentListNode*);
517 ArgumentListNode* m_listNode;
520 class NewExprNode : public ExpressionNode, public ThrowableExpressionData {
522 NewExprNode(JSGlobalData*, ExpressionNode*);
523 NewExprNode(JSGlobalData*, ExpressionNode*, ArgumentsNode*);
526 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
528 ExpressionNode* m_expr;
529 ArgumentsNode* m_args;
532 class EvalFunctionCallNode : public ExpressionNode, public ThrowableExpressionData {
534 EvalFunctionCallNode(JSGlobalData*, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset);
537 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
539 ArgumentsNode* m_args;
542 class FunctionCallValueNode : public ExpressionNode, public ThrowableExpressionData {
544 FunctionCallValueNode(JSGlobalData*, ExpressionNode*, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset);
547 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
549 ExpressionNode* m_expr;
550 ArgumentsNode* m_args;
553 class FunctionCallResolveNode : public ExpressionNode, public ThrowableExpressionData {
555 FunctionCallResolveNode(JSGlobalData*, const Identifier&, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset);
558 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
561 ArgumentsNode* m_args;
562 size_t m_index; // Used by LocalVarFunctionCallNode.
563 size_t m_scopeDepth; // Used by ScopedVarFunctionCallNode and NonLocalVarFunctionCallNode
566 class FunctionCallBracketNode : public ExpressionNode, public ThrowableSubExpressionData {
568 FunctionCallBracketNode(JSGlobalData*, ExpressionNode* base, ExpressionNode* subscript, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset);
571 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
573 ExpressionNode* m_base;
574 ExpressionNode* m_subscript;
575 ArgumentsNode* m_args;
578 class FunctionCallDotNode : public ExpressionNode, public ThrowableSubExpressionData {
580 FunctionCallDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset);
583 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
586 ExpressionNode* m_base;
587 const Identifier m_ident;
588 ArgumentsNode* m_args;
591 class CallFunctionCallDotNode : public FunctionCallDotNode {
593 CallFunctionCallDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset);
596 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
599 class ApplyFunctionCallDotNode : public FunctionCallDotNode {
601 ApplyFunctionCallDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset);
604 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
607 class PrePostResolveNode : public ExpressionNode, public ThrowableExpressionData {
609 PrePostResolveNode(JSGlobalData*, const Identifier&, unsigned divot, unsigned startOffset, unsigned endOffset);
612 const Identifier m_ident;
615 class PostfixResolveNode : public PrePostResolveNode {
617 PostfixResolveNode(JSGlobalData*, const Identifier&, Operator, unsigned divot, unsigned startOffset, unsigned endOffset);
620 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
625 class PostfixBracketNode : public ExpressionNode, public ThrowableSubExpressionData {
627 PostfixBracketNode(JSGlobalData*, ExpressionNode* base, ExpressionNode* subscript, Operator, unsigned divot, unsigned startOffset, unsigned endOffset);
630 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
632 ExpressionNode* m_base;
633 ExpressionNode* m_subscript;
637 class PostfixDotNode : public ExpressionNode, public ThrowableSubExpressionData {
639 PostfixDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, Operator, unsigned divot, unsigned startOffset, unsigned endOffset);
642 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
644 ExpressionNode* m_base;
649 class PostfixErrorNode : public ExpressionNode, public ThrowableSubExpressionData {
651 PostfixErrorNode(JSGlobalData*, ExpressionNode*, Operator, unsigned divot, unsigned startOffset, unsigned endOffset);
654 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
656 ExpressionNode* m_expr;
660 class DeleteResolveNode : public ExpressionNode, public ThrowableExpressionData {
662 DeleteResolveNode(JSGlobalData*, const Identifier&, unsigned divot, unsigned startOffset, unsigned endOffset);
665 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
670 class DeleteBracketNode : public ExpressionNode, public ThrowableExpressionData {
672 DeleteBracketNode(JSGlobalData*, ExpressionNode* base, ExpressionNode* subscript, unsigned divot, unsigned startOffset, unsigned endOffset);
675 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
677 ExpressionNode* m_base;
678 ExpressionNode* m_subscript;
681 class DeleteDotNode : public ExpressionNode, public ThrowableExpressionData {
683 DeleteDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, unsigned divot, unsigned startOffset, unsigned endOffset);
686 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
688 ExpressionNode* m_base;
692 class DeleteValueNode : public ExpressionNode {
694 DeleteValueNode(JSGlobalData*, ExpressionNode*);
697 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
699 ExpressionNode* m_expr;
702 class VoidNode : public ExpressionNode {
704 VoidNode(JSGlobalData*, ExpressionNode*);
707 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
709 ExpressionNode* m_expr;
712 class TypeOfResolveNode : public ExpressionNode {
714 TypeOfResolveNode(JSGlobalData*, const Identifier&);
716 const Identifier& identifier() const { return m_ident; }
719 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
724 class TypeOfValueNode : public ExpressionNode {
726 TypeOfValueNode(JSGlobalData*, ExpressionNode*);
729 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
731 ExpressionNode* m_expr;
734 class PrefixResolveNode : public PrePostResolveNode {
736 PrefixResolveNode(JSGlobalData*, const Identifier&, Operator, unsigned divot, unsigned startOffset, unsigned endOffset);
739 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
744 class PrefixBracketNode : public ExpressionNode, public ThrowablePrefixedSubExpressionData {
746 PrefixBracketNode(JSGlobalData*, ExpressionNode* base, ExpressionNode* subscript, Operator, unsigned divot, unsigned startOffset, unsigned endOffset);
749 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
751 ExpressionNode* m_base;
752 ExpressionNode* m_subscript;
756 class PrefixDotNode : public ExpressionNode, public ThrowablePrefixedSubExpressionData {
758 PrefixDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, Operator, unsigned divot, unsigned startOffset, unsigned endOffset);
761 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
763 ExpressionNode* m_base;
768 class PrefixErrorNode : public ExpressionNode, public ThrowableExpressionData {
770 PrefixErrorNode(JSGlobalData*, ExpressionNode*, Operator, unsigned divot, unsigned startOffset, unsigned endOffset);
773 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
775 ExpressionNode* m_expr;
779 class UnaryOpNode : public ExpressionNode {
781 UnaryOpNode(JSGlobalData*, ResultType, ExpressionNode*, OpcodeID);
784 ExpressionNode* expr() { return m_expr; }
787 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
789 OpcodeID opcodeID() const { return m_opcodeID; }
791 ExpressionNode* m_expr;
795 class UnaryPlusNode : public UnaryOpNode {
797 UnaryPlusNode(JSGlobalData*, ExpressionNode*);
800 virtual ExpressionNode* stripUnaryPlus() { return expr(); }
803 class NegateNode : public UnaryOpNode {
805 NegateNode(JSGlobalData*, ExpressionNode*);
808 class BitwiseNotNode : public UnaryOpNode {
810 BitwiseNotNode(JSGlobalData*, ExpressionNode*);
813 class LogicalNotNode : public UnaryOpNode {
815 LogicalNotNode(JSGlobalData*, ExpressionNode*);
818 class BinaryOpNode : public ExpressionNode {
820 BinaryOpNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments);
821 BinaryOpNode(JSGlobalData*, ResultType, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments);
823 RegisterID* emitStrcat(BytecodeGenerator& generator, RegisterID* dst, RegisterID* lhs = 0, ReadModifyResolveNode* emitExpressionInfoForMe = 0);
826 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
829 OpcodeID opcodeID() const { return m_opcodeID; }
832 ExpressionNode* m_expr1;
833 ExpressionNode* m_expr2;
837 bool m_rightHasAssignments;
840 class ReverseBinaryOpNode : public BinaryOpNode {
842 ReverseBinaryOpNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments);
843 ReverseBinaryOpNode(JSGlobalData*, ResultType, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments);
845 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
848 class MultNode : public BinaryOpNode {
850 MultNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
853 class DivNode : public BinaryOpNode {
855 DivNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
858 class ModNode : public BinaryOpNode {
860 ModNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
863 class AddNode : public BinaryOpNode {
865 AddNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
867 virtual bool isAdd() const { return true; }
870 class SubNode : public BinaryOpNode {
872 SubNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
875 class LeftShiftNode : public BinaryOpNode {
877 LeftShiftNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
880 class RightShiftNode : public BinaryOpNode {
882 RightShiftNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
885 class UnsignedRightShiftNode : public BinaryOpNode {
887 UnsignedRightShiftNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
890 class LessNode : public BinaryOpNode {
892 LessNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
895 class GreaterNode : public ReverseBinaryOpNode {
897 GreaterNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
900 class LessEqNode : public BinaryOpNode {
902 LessEqNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
905 class GreaterEqNode : public ReverseBinaryOpNode {
907 GreaterEqNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
910 class ThrowableBinaryOpNode : public BinaryOpNode, public ThrowableExpressionData {
912 ThrowableBinaryOpNode(JSGlobalData*, ResultType, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments);
913 ThrowableBinaryOpNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments);
916 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
919 class InstanceOfNode : public ThrowableBinaryOpNode {
921 InstanceOfNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
924 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
927 class InNode : public ThrowableBinaryOpNode {
929 InNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
932 class EqualNode : public BinaryOpNode {
934 EqualNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
937 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
940 class NotEqualNode : public BinaryOpNode {
942 NotEqualNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
945 class StrictEqualNode : public BinaryOpNode {
947 StrictEqualNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
950 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
953 class NotStrictEqualNode : public BinaryOpNode {
955 NotStrictEqualNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
958 class BitAndNode : public BinaryOpNode {
960 BitAndNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
963 class BitOrNode : public BinaryOpNode {
965 BitOrNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
968 class BitXOrNode : public BinaryOpNode {
970 BitXOrNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
973 // m_expr1 && m_expr2, m_expr1 || m_expr2
974 class LogicalOpNode : public ExpressionNode {
976 LogicalOpNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, LogicalOperator);
979 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
981 ExpressionNode* m_expr1;
982 ExpressionNode* m_expr2;
983 LogicalOperator m_operator;
986 // The ternary operator, "m_logical ? m_expr1 : m_expr2"
987 class ConditionalNode : public ExpressionNode {
989 ConditionalNode(JSGlobalData*, ExpressionNode* logical, ExpressionNode* expr1, ExpressionNode* expr2);
992 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
994 ExpressionNode* m_logical;
995 ExpressionNode* m_expr1;
996 ExpressionNode* m_expr2;
999 class ReadModifyResolveNode : public ExpressionNode, public ThrowableExpressionData {
1001 ReadModifyResolveNode(JSGlobalData*, const Identifier&, Operator, ExpressionNode* right, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset);
1004 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1007 ExpressionNode* m_right;
1008 size_t m_index; // Used by ReadModifyLocalVarNode.
1009 Operator m_operator;
1010 bool m_rightHasAssignments;
1013 class AssignResolveNode : public ExpressionNode, public ThrowableExpressionData {
1015 AssignResolveNode(JSGlobalData*, const Identifier&, ExpressionNode* right, bool rightHasAssignments);
1018 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1021 ExpressionNode* m_right;
1022 size_t m_index; // Used by ReadModifyLocalVarNode.
1023 bool m_rightHasAssignments;
1026 class ReadModifyBracketNode : public ExpressionNode, public ThrowableSubExpressionData {
1028 ReadModifyBracketNode(JSGlobalData*, ExpressionNode* base, ExpressionNode* subscript, Operator, ExpressionNode* right, bool subscriptHasAssignments, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset);
1031 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1033 ExpressionNode* m_base;
1034 ExpressionNode* m_subscript;
1035 ExpressionNode* m_right;
1036 Operator m_operator : 30;
1037 bool m_subscriptHasAssignments : 1;
1038 bool m_rightHasAssignments : 1;
1041 class AssignBracketNode : public ExpressionNode, public ThrowableExpressionData {
1043 AssignBracketNode(JSGlobalData*, ExpressionNode* base, ExpressionNode* subscript, ExpressionNode* right, bool subscriptHasAssignments, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset);
1046 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1048 ExpressionNode* m_base;
1049 ExpressionNode* m_subscript;
1050 ExpressionNode* m_right;
1051 bool m_subscriptHasAssignments : 1;
1052 bool m_rightHasAssignments : 1;
1055 class AssignDotNode : public ExpressionNode, public ThrowableExpressionData {
1057 AssignDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, ExpressionNode* right, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset);
1060 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1062 ExpressionNode* m_base;
1064 ExpressionNode* m_right;
1065 bool m_rightHasAssignments;
1068 class ReadModifyDotNode : public ExpressionNode, public ThrowableSubExpressionData {
1070 ReadModifyDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, Operator, ExpressionNode* right, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset);
1073 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1075 ExpressionNode* m_base;
1077 ExpressionNode* m_right;
1078 Operator m_operator : 31;
1079 bool m_rightHasAssignments : 1;
1082 class AssignErrorNode : public ExpressionNode, public ThrowableExpressionData {
1084 AssignErrorNode(JSGlobalData*, ExpressionNode* left, Operator, ExpressionNode* right, unsigned divot, unsigned startOffset, unsigned endOffset);
1087 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1089 ExpressionNode* m_left;
1090 Operator m_operator;
1091 ExpressionNode* m_right;
1094 typedef Vector<ExpressionNode*, 8> ExpressionVector;
1096 class CommaNode : public ExpressionNode {
1098 CommaNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2);
1100 void append(ExpressionNode* expr) { m_expressions.append(expr); }
1103 virtual bool isCommaNode() const { return true; }
1104 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1106 ExpressionVector m_expressions;
1109 class ConstDeclNode : public ExpressionNode {
1111 ConstDeclNode(JSGlobalData*, const Identifier&, ExpressionNode*);
1113 bool hasInitializer() const { return m_init; }
1114 const Identifier& ident() { return m_ident; }
1117 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1118 virtual RegisterID* emitCodeSingle(BytecodeGenerator&);
1123 ConstDeclNode* m_next;
1126 ExpressionNode* m_init;
1129 class ConstStatementNode : public StatementNode {
1131 ConstStatementNode(JSGlobalData*, ConstDeclNode* next);
1134 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1136 ConstDeclNode* m_next;
1139 typedef Vector<StatementNode*> StatementVector;
1141 class SourceElements : public ParserArenaDeletable {
1143 SourceElements(JSGlobalData*);
1145 void append(StatementNode*);
1146 void releaseContentsIntoVector(StatementVector& destination)
1148 ASSERT(destination.isEmpty());
1149 m_statements.swap(destination);
1150 destination.shrinkToFit();
1154 StatementVector m_statements;
1157 class BlockNode : public StatementNode {
1159 BlockNode(JSGlobalData*, SourceElements* children);
1161 StatementVector& children() { return m_children; }
1164 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1166 virtual bool isBlock() const { return true; }
1168 StatementVector m_children;
1171 class EmptyStatementNode : public StatementNode {
1173 EmptyStatementNode(JSGlobalData*);
1176 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1178 virtual bool isEmptyStatement() const { return true; }
1181 class DebuggerStatementNode : public StatementNode {
1183 DebuggerStatementNode(JSGlobalData*);
1186 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1189 class ExprStatementNode : public StatementNode {
1191 ExprStatementNode(JSGlobalData*, ExpressionNode*);
1193 ExpressionNode* expr() const { return m_expr; }
1196 virtual bool isExprStatement() const { return true; }
1198 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1200 ExpressionNode* m_expr;
1203 class VarStatementNode : public StatementNode {
1205 VarStatementNode(JSGlobalData*, ExpressionNode*);
1208 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1210 ExpressionNode* m_expr;
1213 class IfNode : public StatementNode {
1215 IfNode(JSGlobalData*, ExpressionNode* condition, StatementNode* ifBlock);
1218 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1220 ExpressionNode* m_condition;
1221 StatementNode* m_ifBlock;
1224 class IfElseNode : public IfNode {
1226 IfElseNode(JSGlobalData*, ExpressionNode* condition, StatementNode* ifBlock, StatementNode* elseBlock);
1229 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1231 StatementNode* m_elseBlock;
1234 class DoWhileNode : public StatementNode {
1236 DoWhileNode(JSGlobalData*, StatementNode* statement, ExpressionNode*);
1239 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1241 StatementNode* m_statement;
1242 ExpressionNode* m_expr;
1245 class WhileNode : public StatementNode {
1247 WhileNode(JSGlobalData*, ExpressionNode*, StatementNode* statement);
1250 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1252 ExpressionNode* m_expr;
1253 StatementNode* m_statement;
1256 class ForNode : public StatementNode {
1258 ForNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, ExpressionNode* expr3, StatementNode* statement, bool expr1WasVarDecl);
1261 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1263 ExpressionNode* m_expr1;
1264 ExpressionNode* m_expr2;
1265 ExpressionNode* m_expr3;
1266 StatementNode* m_statement;
1267 bool m_expr1WasVarDecl;
1270 class ForInNode : public StatementNode, public ThrowableExpressionData {
1272 ForInNode(JSGlobalData*, ExpressionNode*, ExpressionNode*, StatementNode*);
1273 ForInNode(JSGlobalData*, const Identifier&, ExpressionNode*, ExpressionNode*, StatementNode*, int divot, int startOffset, int endOffset);
1276 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1279 ExpressionNode* m_init;
1280 ExpressionNode* m_lexpr;
1281 ExpressionNode* m_expr;
1282 StatementNode* m_statement;
1283 bool m_identIsVarDecl;
1286 class ContinueNode : public StatementNode, public ThrowableExpressionData {
1288 ContinueNode(JSGlobalData*);
1289 ContinueNode(JSGlobalData*, const Identifier&);
1292 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1297 class BreakNode : public StatementNode, public ThrowableExpressionData {
1299 BreakNode(JSGlobalData*);
1300 BreakNode(JSGlobalData*, const Identifier&);
1303 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1308 class ReturnNode : public StatementNode, public ThrowableExpressionData {
1310 ReturnNode(JSGlobalData*, ExpressionNode* value);
1313 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1315 virtual bool isReturnNode() const { return true; }
1317 ExpressionNode* m_value;
1320 class WithNode : public StatementNode {
1322 WithNode(JSGlobalData*, ExpressionNode*, StatementNode*, uint32_t divot, uint32_t expressionLength);
1325 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1327 ExpressionNode* m_expr;
1328 StatementNode* m_statement;
1330 uint32_t m_expressionLength;
1333 class LabelNode : public StatementNode, public ThrowableExpressionData {
1335 LabelNode(JSGlobalData*, const Identifier& name, StatementNode*);
1338 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1341 StatementNode* m_statement;
1344 class ThrowNode : public StatementNode, public ThrowableExpressionData {
1346 ThrowNode(JSGlobalData*, ExpressionNode*);
1349 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1351 ExpressionNode* m_expr;
1354 class TryNode : public StatementNode {
1356 TryNode(JSGlobalData*, StatementNode* tryBlock, const Identifier& exceptionIdent, bool catchHasEval, StatementNode* catchBlock, StatementNode* finallyBlock);
1359 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* dst = 0);
1361 StatementNode* m_tryBlock;
1362 Identifier m_exceptionIdent;
1363 StatementNode* m_catchBlock;
1364 StatementNode* m_finallyBlock;
1365 bool m_catchHasEval;
1368 class ParameterNode : public ParserArenaDeletable {
1370 ParameterNode(JSGlobalData*, const Identifier&);
1371 ParameterNode(JSGlobalData*, ParameterNode*, const Identifier&);
1373 const Identifier& ident() const { return m_ident; }
1374 ParameterNode* nextParam() const { return m_next; }
1378 ParameterNode* m_next;
1381 struct ScopeNodeData {
1382 typedef DeclarationStacks::VarStack VarStack;
1383 typedef DeclarationStacks::FunctionStack FunctionStack;
1385 ScopeNodeData(ParserArena&, SourceElements*, VarStack*, FunctionStack*, int numConstants);
1387 ParserArena m_arena;
1388 VarStack m_varStack;
1389 FunctionStack m_functionStack;
1391 StatementVector m_children;
1396 class ScopeNode : public StatementNode, public ParserArenaRefCounted {
1398 typedef DeclarationStacks::VarStack VarStack;
1399 typedef DeclarationStacks::FunctionStack FunctionStack;
1401 ScopeNode(JSGlobalData*);
1402 ScopeNode(JSGlobalData*, const SourceCode&, SourceElements*, VarStack*, FunctionStack*, CodeFeatures, int numConstants);
1404 void adoptData(std::auto_ptr<ScopeNodeData> data)
1406 ASSERT(!data->m_arena.contains(this));
1410 ScopeNodeData* data() const { return m_data.get(); }
1411 void destroyData() { m_data.clear(); }
1413 const SourceCode& source() const { return m_source; }
1414 const UString& sourceURL() const { return m_source.provider()->url(); }
1415 intptr_t sourceID() const { return m_source.provider()->asID(); }
1417 void setFeatures(CodeFeatures features) { m_features = features; }
1418 CodeFeatures features() { return m_features; }
1420 bool usesEval() const { return m_features & EvalFeature; }
1421 bool usesArguments() const { return m_features & ArgumentsFeature; }
1422 void setUsesArguments() { m_features |= ArgumentsFeature; }
1423 bool usesThis() const { return m_features & ThisFeature; }
1424 bool needsActivation() const { return m_features & (EvalFeature | ClosureFeature | WithFeature | CatchFeature); }
1426 VarStack& varStack() { ASSERT(m_data); return m_data->m_varStack; }
1427 FunctionStack& functionStack() { ASSERT(m_data); return m_data->m_functionStack; }
1429 StatementVector& children() { ASSERT(m_data); return m_data->m_children; }
1431 int neededConstants()
1434 // We may need 2 more constants than the count given by the parser,
1435 // because of the various uses of jsUndefined() and jsNull().
1436 return m_data->m_numConstants + 2;
1439 virtual void mark() { }
1442 JITCode& generatedJITCode()
1448 ExecutablePool* getExecutablePool()
1450 return m_jitCode.getExecutablePool();
1453 void setJITCode(const JITCode jitCode)
1455 m_jitCode = jitCode;
1460 void setSource(const SourceCode& source) { m_source = source; }
1467 OwnPtr<ScopeNodeData> m_data;
1468 CodeFeatures m_features;
1469 SourceCode m_source;
1472 class ProgramNode : public ScopeNode {
1474 static PassRefPtr<ProgramNode> create(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, const SourceCode&, CodeFeatures, int numConstants);
1476 ProgramCodeBlock& bytecode(ScopeChainNode* scopeChain)
1479 generateBytecode(scopeChain);
1484 JITCode& jitCode(ScopeChainNode* scopeChain)
1487 generateJITCode(scopeChain);
1493 ProgramNode(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, const SourceCode&, CodeFeatures, int numConstants);
1495 void generateBytecode(ScopeChainNode*);
1496 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1499 void generateJITCode(ScopeChainNode*);
1502 OwnPtr<ProgramCodeBlock> m_code;
1505 class EvalNode : public ScopeNode {
1507 static PassRefPtr<EvalNode> create(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, const SourceCode&, CodeFeatures, int numConstants);
1509 EvalCodeBlock& bytecode(ScopeChainNode* scopeChain)
1512 generateBytecode(scopeChain);
1516 EvalCodeBlock& bytecodeForExceptionInfoReparse(ScopeChainNode*, CodeBlock*);
1518 virtual void mark();
1521 JITCode& jitCode(ScopeChainNode* scopeChain)
1524 generateJITCode(scopeChain);
1530 EvalNode(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, const SourceCode&, CodeFeatures, int numConstants);
1532 void generateBytecode(ScopeChainNode*);
1533 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1536 void generateJITCode(ScopeChainNode*);
1539 OwnPtr<EvalCodeBlock> m_code;
1542 class FunctionBodyNode : public ScopeNode {
1546 static PassRefPtr<FunctionBodyNode> createNativeThunk(JSGlobalData*);
1548 static FunctionBodyNode* create(JSGlobalData*);
1549 static PassRefPtr<FunctionBodyNode> create(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, const SourceCode&, CodeFeatures, int numConstants);
1550 virtual ~FunctionBodyNode();
1552 const Identifier* parameters() const { return m_parameters; }
1553 size_t parameterCount() const { return m_parameterCount; }
1554 UString paramString() const ;
1555 Identifier* copyParameters();
1557 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1559 bool isGenerated() const
1564 bool isHostFunction() const;
1566 virtual void mark();
1568 void finishParsing(const SourceCode&, ParameterNode*);
1569 void finishParsing(Identifier* parameters, size_t parameterCount);
1571 UString toSourceString() const { return source().toString(); }
1573 CodeBlock& bytecodeForExceptionInfoReparse(ScopeChainNode*, CodeBlock*);
1575 JITCode& jitCode(ScopeChainNode* scopeChain)
1578 generateJITCode(scopeChain);
1583 CodeBlock& bytecode(ScopeChainNode* scopeChain)
1587 generateBytecode(scopeChain);
1591 CodeBlock& generatedBytecode()
1598 FunctionBodyNode(JSGlobalData*);
1599 FunctionBodyNode(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, const SourceCode&, CodeFeatures, int numConstants);
1601 void generateBytecode(ScopeChainNode*);
1603 void generateJITCode(ScopeChainNode*);
1605 Identifier* m_parameters;
1606 size_t m_parameterCount;
1607 OwnPtr<CodeBlock> m_code;
1610 class FuncExprNode : public ExpressionNode, public ParserArenaRefCounted {
1612 FuncExprNode(JSGlobalData*, const Identifier&, FunctionBodyNode* body, const SourceCode& source, ParameterNode* parameter = 0);
1614 JSFunction* makeFunction(ExecState*, ScopeChainNode*);
1616 FunctionBodyNode* body() { return m_body.get(); }
1619 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1621 virtual bool isFuncExprNode() const { return true; }
1624 RefPtr<FunctionBodyNode> m_body;
1627 class FuncDeclNode : public StatementNode, public ParserArenaRefCounted {
1629 FuncDeclNode(JSGlobalData*, const Identifier&, FunctionBodyNode*, const SourceCode&, ParameterNode* = 0);
1631 JSFunction* makeFunction(ExecState*, ScopeChainNode*);
1635 FunctionBodyNode* body() { return m_body.get(); }
1638 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1640 RefPtr<FunctionBodyNode> m_body;
1643 class CaseClauseNode : public ParserArenaDeletable {
1645 CaseClauseNode(JSGlobalData*, ExpressionNode*);
1646 CaseClauseNode(JSGlobalData*, ExpressionNode*, SourceElements*);
1648 ExpressionNode* expr() const { return m_expr; }
1649 StatementVector& children() { return m_children; }
1652 ExpressionNode* m_expr;
1653 StatementVector m_children;
1656 class ClauseListNode : public ParserArenaDeletable {
1658 ClauseListNode(JSGlobalData*, CaseClauseNode*);
1659 ClauseListNode(JSGlobalData*, ClauseListNode*, CaseClauseNode*);
1661 CaseClauseNode* getClause() const { return m_clause; }
1662 ClauseListNode* getNext() const { return m_next; }
1665 CaseClauseNode* m_clause;
1666 ClauseListNode* m_next;
1669 class CaseBlockNode : public ParserArenaDeletable {
1671 CaseBlockNode(JSGlobalData*, ClauseListNode* list1, CaseClauseNode* defaultClause, ClauseListNode* list2);
1673 RegisterID* emitBytecodeForBlock(BytecodeGenerator&, RegisterID* input, RegisterID* dst = 0);
1676 SwitchInfo::SwitchType tryOptimizedSwitch(Vector<ExpressionNode*, 8>& literalVector, int32_t& min_num, int32_t& max_num);
1677 ClauseListNode* m_list1;
1678 CaseClauseNode* m_defaultClause;
1679 ClauseListNode* m_list2;
1682 class SwitchNode : public StatementNode {
1684 SwitchNode(JSGlobalData*, ExpressionNode*, CaseBlockNode*);
1687 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1689 ExpressionNode* m_expr;
1690 CaseBlockNode* m_block;
1693 struct ElementList {
1698 struct PropertyList {
1699 PropertyListNode* head;
1700 PropertyListNode* tail;
1703 struct ArgumentList {
1704 ArgumentListNode* head;
1705 ArgumentListNode* tail;
1708 struct ConstDeclList {
1709 ConstDeclNode* head;
1710 ConstDeclNode* tail;
1713 struct ParameterList {
1714 ParameterNode* head;
1715 ParameterNode* tail;
1719 ClauseListNode* head;
1720 ClauseListNode* tail;