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);
114 class ParserArenaRefCounted
: public RefCounted
<ParserArenaRefCounted
> {
116 ParserArenaRefCounted(JSGlobalData
*);
119 virtual ~ParserArenaRefCounted()
121 ASSERT(deletionHasBegun());
125 class Node
: public ParserArenaDeletable
{
131 Return value: The register holding the production's value.
132 dst: An optional parameter specifying the most efficient
133 destination at which to store the production's value.
134 The callee must honor dst.
136 dst provides for a crude form of copy propagation. For example,
149 because the assignment node, "x =", passes r[x] as dst to the number
152 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* dst
= 0) = 0;
154 int lineNo() const { return m_line
; }
160 class ExpressionNode
: public Node
{
162 ExpressionNode(JSGlobalData
*, ResultType
= ResultType::unknownType());
164 virtual bool isNumber() const { return false; }
165 virtual bool isString() const { return false; }
166 virtual bool isNull() const { return false; }
167 virtual bool isPure(BytecodeGenerator
&) const { return false; }
168 virtual bool isLocation() const { return false; }
169 virtual bool isResolveNode() const { return false; }
170 virtual bool isBracketAccessorNode() const { return false; }
171 virtual bool isDotAccessorNode() const { return false; }
172 virtual bool isFuncExprNode() const { return false; }
173 virtual bool isCommaNode() const { return false; }
174 virtual bool isSimpleArray() const { return false; }
175 virtual bool isAdd() const { return false; }
177 virtual ExpressionNode
* stripUnaryPlus() { return this; }
179 ResultType
resultDescriptor() const { return m_resultType
; }
181 // This needs to be in public in order to compile using GCC 3.x
182 typedef enum { EvalOperator
, FunctionCall
} CallerType
;
185 ResultType m_resultType
;
188 class StatementNode
: public Node
{
190 StatementNode(JSGlobalData
*);
192 void setLoc(int line0
, int line1
);
193 int firstLine() const { return lineNo(); }
194 int lastLine() const { return m_lastLine
; }
196 virtual bool isEmptyStatement() const { return false; }
197 virtual bool isReturnNode() const { return false; }
198 virtual bool isExprStatement() const { return false; }
200 virtual bool isBlock() const { return false; }
206 class NullNode
: public ExpressionNode
{
208 NullNode(JSGlobalData
*);
211 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
213 virtual bool isNull() const { return true; }
216 class BooleanNode
: public ExpressionNode
{
218 BooleanNode(JSGlobalData
*, bool value
);
221 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
223 virtual bool isPure(BytecodeGenerator
&) const { return true; }
228 class NumberNode
: public ExpressionNode
{
230 NumberNode(JSGlobalData
*, double v
);
232 double value() const { return m_double
; }
233 void setValue(double d
) { m_double
= d
; }
236 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
238 virtual bool isNumber() const { return true; }
239 virtual bool isPure(BytecodeGenerator
&) const { return true; }
244 class StringNode
: public ExpressionNode
{
246 StringNode(JSGlobalData
*, const Identifier
& v
);
248 const Identifier
& value() { return m_value
; }
249 virtual bool isPure(BytecodeGenerator
&) const { return true; }
252 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
254 virtual bool isString() const { return true; }
259 class ThrowableExpressionData
{
261 ThrowableExpressionData()
262 : m_divot(static_cast<uint32_t>(-1))
263 , m_startOffset(static_cast<uint16_t>(-1))
264 , m_endOffset(static_cast<uint16_t>(-1))
268 ThrowableExpressionData(unsigned divot
, unsigned startOffset
, unsigned endOffset
)
270 , m_startOffset(startOffset
)
271 , m_endOffset(endOffset
)
275 void setExceptionSourceCode(unsigned divot
, unsigned startOffset
, unsigned endOffset
)
278 m_startOffset
= startOffset
;
279 m_endOffset
= endOffset
;
282 uint32_t divot() const { return m_divot
; }
283 uint16_t startOffset() const { return m_startOffset
; }
284 uint16_t endOffset() const { return m_endOffset
; }
287 RegisterID
* emitThrowError(BytecodeGenerator
&, ErrorType
, const char* msg
);
288 RegisterID
* emitThrowError(BytecodeGenerator
&, ErrorType
, const char* msg
, const Identifier
&);
292 uint16_t m_startOffset
;
293 uint16_t m_endOffset
;
296 class ThrowableSubExpressionData
: public ThrowableExpressionData
{
298 ThrowableSubExpressionData()
299 : ThrowableExpressionData()
300 , m_subexpressionDivotOffset(0)
301 , m_subexpressionEndOffset(0)
305 ThrowableSubExpressionData(unsigned divot
, unsigned startOffset
, unsigned endOffset
)
306 : ThrowableExpressionData(divot
, startOffset
, endOffset
)
307 , m_subexpressionDivotOffset(0)
308 , m_subexpressionEndOffset(0)
312 void setSubexpressionInfo(uint32_t subexpressionDivot
, uint16_t subexpressionOffset
)
314 ASSERT(subexpressionDivot
<= divot());
315 if ((divot() - subexpressionDivot
) & ~0xFFFF) // Overflow means we can't do this safely, so just point at the primary divot
317 m_subexpressionDivotOffset
= divot() - subexpressionDivot
;
318 m_subexpressionEndOffset
= subexpressionOffset
;
322 uint16_t m_subexpressionDivotOffset
;
323 uint16_t m_subexpressionEndOffset
;
326 class ThrowablePrefixedSubExpressionData
: public ThrowableExpressionData
{
328 ThrowablePrefixedSubExpressionData()
329 : ThrowableExpressionData()
330 , m_subexpressionDivotOffset(0)
331 , m_subexpressionStartOffset(0)
335 ThrowablePrefixedSubExpressionData(unsigned divot
, unsigned startOffset
, unsigned endOffset
)
336 : ThrowableExpressionData(divot
, startOffset
, endOffset
)
337 , m_subexpressionDivotOffset(0)
338 , m_subexpressionStartOffset(0)
342 void setSubexpressionInfo(uint32_t subexpressionDivot
, uint16_t subexpressionOffset
)
344 ASSERT(subexpressionDivot
>= divot());
345 if ((subexpressionDivot
- divot()) & ~0xFFFF) // Overflow means we can't do this safely, so just point at the primary divot
347 m_subexpressionDivotOffset
= subexpressionDivot
- divot();
348 m_subexpressionStartOffset
= subexpressionOffset
;
352 uint16_t m_subexpressionDivotOffset
;
353 uint16_t m_subexpressionStartOffset
;
356 class RegExpNode
: public ExpressionNode
, public ThrowableExpressionData
{
358 RegExpNode(JSGlobalData
*, const UString
& pattern
, const UString
& flags
);
361 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
367 class ThisNode
: public ExpressionNode
{
369 ThisNode(JSGlobalData
*);
372 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
375 class ResolveNode
: public ExpressionNode
{
377 ResolveNode(JSGlobalData
*, const Identifier
&, int startOffset
);
379 const Identifier
& identifier() const { return m_ident
; }
382 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
384 virtual bool isPure(BytecodeGenerator
&) const ;
385 virtual bool isLocation() const { return true; }
386 virtual bool isResolveNode() const { return true; }
389 int32_t m_startOffset
;
392 class ElementNode
: public ParserArenaDeletable
{
394 ElementNode(JSGlobalData
*, int elision
, ExpressionNode
*);
395 ElementNode(JSGlobalData
*, ElementNode
*, int elision
, ExpressionNode
*);
397 int elision() const { return m_elision
; }
398 ExpressionNode
* value() { return m_node
; }
399 ElementNode
* next() { return m_next
; }
404 ExpressionNode
* m_node
;
407 class ArrayNode
: public ExpressionNode
{
409 ArrayNode(JSGlobalData
*, int elision
);
410 ArrayNode(JSGlobalData
*, ElementNode
*);
411 ArrayNode(JSGlobalData
*, int elision
, ElementNode
*);
413 ArgumentListNode
* toArgumentList(JSGlobalData
*) const;
416 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
418 virtual bool isSimpleArray() const ;
420 ElementNode
* m_element
;
425 class PropertyNode
: public ParserArenaDeletable
{
427 enum Type
{ Constant
, Getter
, Setter
};
429 PropertyNode(JSGlobalData
*, const Identifier
& name
, ExpressionNode
* value
, Type
);
431 const Identifier
& name() const { return m_name
; }
434 friend class PropertyListNode
;
436 ExpressionNode
* m_assign
;
440 class PropertyListNode
: public Node
{
442 PropertyListNode(JSGlobalData
*, PropertyNode
*);
443 PropertyListNode(JSGlobalData
*, PropertyNode
*, PropertyListNode
*);
445 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
448 PropertyNode
* m_node
;
449 PropertyListNode
* m_next
;
452 class ObjectLiteralNode
: public ExpressionNode
{
454 ObjectLiteralNode(JSGlobalData
*);
455 ObjectLiteralNode(JSGlobalData
*, PropertyListNode
*);
458 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
460 PropertyListNode
* m_list
;
463 class BracketAccessorNode
: public ExpressionNode
, public ThrowableExpressionData
{
465 BracketAccessorNode(JSGlobalData
*, ExpressionNode
* base
, ExpressionNode
* subscript
, bool subscriptHasAssignments
);
467 ExpressionNode
* base() const { return m_base
; }
468 ExpressionNode
* subscript() const { return m_subscript
; }
471 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
473 virtual bool isLocation() const { return true; }
474 virtual bool isBracketAccessorNode() const { return true; }
476 ExpressionNode
* m_base
;
477 ExpressionNode
* m_subscript
;
478 bool m_subscriptHasAssignments
;
481 class DotAccessorNode
: public ExpressionNode
, public ThrowableExpressionData
{
483 DotAccessorNode(JSGlobalData
*, ExpressionNode
* base
, const Identifier
&);
485 ExpressionNode
* base() const { return m_base
; }
486 const Identifier
& identifier() const { return m_ident
; }
489 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
491 virtual bool isLocation() const { return true; }
492 virtual bool isDotAccessorNode() const { return true; }
494 ExpressionNode
* m_base
;
498 class ArgumentListNode
: public Node
{
500 ArgumentListNode(JSGlobalData
*, ExpressionNode
*);
501 ArgumentListNode(JSGlobalData
*, ArgumentListNode
*, ExpressionNode
*);
503 ArgumentListNode
* m_next
;
504 ExpressionNode
* m_expr
;
507 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
510 class ArgumentsNode
: public ParserArenaDeletable
{
512 ArgumentsNode(JSGlobalData
*);
513 ArgumentsNode(JSGlobalData
*, ArgumentListNode
*);
515 ArgumentListNode
* m_listNode
;
518 class NewExprNode
: public ExpressionNode
, public ThrowableExpressionData
{
520 NewExprNode(JSGlobalData
*, ExpressionNode
*);
521 NewExprNode(JSGlobalData
*, ExpressionNode
*, ArgumentsNode
*);
524 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
526 ExpressionNode
* m_expr
;
527 ArgumentsNode
* m_args
;
530 class EvalFunctionCallNode
: public ExpressionNode
, public ThrowableExpressionData
{
532 EvalFunctionCallNode(JSGlobalData
*, ArgumentsNode
*, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
535 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
537 ArgumentsNode
* m_args
;
540 class FunctionCallValueNode
: public ExpressionNode
, public ThrowableExpressionData
{
542 FunctionCallValueNode(JSGlobalData
*, ExpressionNode
*, ArgumentsNode
*, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
545 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
547 ExpressionNode
* m_expr
;
548 ArgumentsNode
* m_args
;
551 class FunctionCallResolveNode
: public ExpressionNode
, public ThrowableExpressionData
{
553 FunctionCallResolveNode(JSGlobalData
*, const Identifier
&, ArgumentsNode
*, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
556 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
559 ArgumentsNode
* m_args
;
560 size_t m_index
; // Used by LocalVarFunctionCallNode.
561 size_t m_scopeDepth
; // Used by ScopedVarFunctionCallNode and NonLocalVarFunctionCallNode
564 class FunctionCallBracketNode
: public ExpressionNode
, public ThrowableSubExpressionData
{
566 FunctionCallBracketNode(JSGlobalData
*, ExpressionNode
* base
, ExpressionNode
* subscript
, ArgumentsNode
*, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
569 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
571 ExpressionNode
* m_base
;
572 ExpressionNode
* m_subscript
;
573 ArgumentsNode
* m_args
;
576 class FunctionCallDotNode
: public ExpressionNode
, public ThrowableSubExpressionData
{
578 FunctionCallDotNode(JSGlobalData
*, ExpressionNode
* base
, const Identifier
&, ArgumentsNode
*, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
581 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
584 ExpressionNode
* m_base
;
585 const Identifier m_ident
;
586 ArgumentsNode
* m_args
;
589 class CallFunctionCallDotNode
: public FunctionCallDotNode
{
591 CallFunctionCallDotNode(JSGlobalData
*, ExpressionNode
* base
, const Identifier
&, ArgumentsNode
*, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
594 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
597 class ApplyFunctionCallDotNode
: public FunctionCallDotNode
{
599 ApplyFunctionCallDotNode(JSGlobalData
*, ExpressionNode
* base
, const Identifier
&, ArgumentsNode
*, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
602 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
605 class PrePostResolveNode
: public ExpressionNode
, public ThrowableExpressionData
{
607 PrePostResolveNode(JSGlobalData
*, const Identifier
&, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
610 const Identifier m_ident
;
613 class PostfixResolveNode
: public PrePostResolveNode
{
615 PostfixResolveNode(JSGlobalData
*, const Identifier
&, Operator
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
618 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
623 class PostfixBracketNode
: public ExpressionNode
, public ThrowableSubExpressionData
{
625 PostfixBracketNode(JSGlobalData
*, ExpressionNode
* base
, ExpressionNode
* subscript
, Operator
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
628 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
630 ExpressionNode
* m_base
;
631 ExpressionNode
* m_subscript
;
635 class PostfixDotNode
: public ExpressionNode
, public ThrowableSubExpressionData
{
637 PostfixDotNode(JSGlobalData
*, ExpressionNode
* base
, const Identifier
&, Operator
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
640 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
642 ExpressionNode
* m_base
;
647 class PostfixErrorNode
: public ExpressionNode
, public ThrowableSubExpressionData
{
649 PostfixErrorNode(JSGlobalData
*, ExpressionNode
*, Operator
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
652 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
654 ExpressionNode
* m_expr
;
658 class DeleteResolveNode
: public ExpressionNode
, public ThrowableExpressionData
{
660 DeleteResolveNode(JSGlobalData
*, const Identifier
&, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
663 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
668 class DeleteBracketNode
: public ExpressionNode
, public ThrowableExpressionData
{
670 DeleteBracketNode(JSGlobalData
*, ExpressionNode
* base
, ExpressionNode
* subscript
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
673 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
675 ExpressionNode
* m_base
;
676 ExpressionNode
* m_subscript
;
679 class DeleteDotNode
: public ExpressionNode
, public ThrowableExpressionData
{
681 DeleteDotNode(JSGlobalData
*, ExpressionNode
* base
, const Identifier
&, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
684 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
686 ExpressionNode
* m_base
;
690 class DeleteValueNode
: public ExpressionNode
{
692 DeleteValueNode(JSGlobalData
*, ExpressionNode
*);
695 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
697 ExpressionNode
* m_expr
;
700 class VoidNode
: public ExpressionNode
{
702 VoidNode(JSGlobalData
*, ExpressionNode
*);
705 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
707 ExpressionNode
* m_expr
;
710 class TypeOfResolveNode
: public ExpressionNode
{
712 TypeOfResolveNode(JSGlobalData
*, const Identifier
&);
714 const Identifier
& identifier() const { return m_ident
; }
717 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
722 class TypeOfValueNode
: public ExpressionNode
{
724 TypeOfValueNode(JSGlobalData
*, ExpressionNode
*);
727 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
729 ExpressionNode
* m_expr
;
732 class PrefixResolveNode
: public PrePostResolveNode
{
734 PrefixResolveNode(JSGlobalData
*, const Identifier
&, Operator
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
737 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
742 class PrefixBracketNode
: public ExpressionNode
, public ThrowablePrefixedSubExpressionData
{
744 PrefixBracketNode(JSGlobalData
*, ExpressionNode
* base
, ExpressionNode
* subscript
, Operator
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
747 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
749 ExpressionNode
* m_base
;
750 ExpressionNode
* m_subscript
;
754 class PrefixDotNode
: public ExpressionNode
, public ThrowablePrefixedSubExpressionData
{
756 PrefixDotNode(JSGlobalData
*, ExpressionNode
* base
, const Identifier
&, Operator
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
759 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
761 ExpressionNode
* m_base
;
766 class PrefixErrorNode
: public ExpressionNode
, public ThrowableExpressionData
{
768 PrefixErrorNode(JSGlobalData
*, ExpressionNode
*, Operator
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
771 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
773 ExpressionNode
* m_expr
;
777 class UnaryOpNode
: public ExpressionNode
{
779 UnaryOpNode(JSGlobalData
*, ResultType
, ExpressionNode
*, OpcodeID
);
782 ExpressionNode
* expr() { return m_expr
; }
785 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
787 OpcodeID
opcodeID() const { return m_opcodeID
; }
789 ExpressionNode
* m_expr
;
793 class UnaryPlusNode
: public UnaryOpNode
{
795 UnaryPlusNode(JSGlobalData
*, ExpressionNode
*);
798 virtual ExpressionNode
* stripUnaryPlus() { return expr(); }
801 class NegateNode
: public UnaryOpNode
{
803 NegateNode(JSGlobalData
*, ExpressionNode
*);
806 class BitwiseNotNode
: public UnaryOpNode
{
808 BitwiseNotNode(JSGlobalData
*, ExpressionNode
*);
811 class LogicalNotNode
: public UnaryOpNode
{
813 LogicalNotNode(JSGlobalData
*, ExpressionNode
*);
816 class BinaryOpNode
: public ExpressionNode
{
818 BinaryOpNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, OpcodeID
, bool rightHasAssignments
);
819 BinaryOpNode(JSGlobalData
*, ResultType
, ExpressionNode
* expr1
, ExpressionNode
* expr2
, OpcodeID
, bool rightHasAssignments
);
821 RegisterID
* emitStrcat(BytecodeGenerator
& generator
, RegisterID
* dst
, RegisterID
* lhs
= 0, ReadModifyResolveNode
* emitExpressionInfoForMe
= 0);
824 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
827 OpcodeID
opcodeID() const { return m_opcodeID
; }
830 ExpressionNode
* m_expr1
;
831 ExpressionNode
* m_expr2
;
835 bool m_rightHasAssignments
;
838 class ReverseBinaryOpNode
: public BinaryOpNode
{
840 ReverseBinaryOpNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, OpcodeID
, bool rightHasAssignments
);
841 ReverseBinaryOpNode(JSGlobalData
*, ResultType
, ExpressionNode
* expr1
, ExpressionNode
* expr2
, OpcodeID
, bool rightHasAssignments
);
843 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
846 class MultNode
: public BinaryOpNode
{
848 MultNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
851 class DivNode
: public BinaryOpNode
{
853 DivNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
856 class ModNode
: public BinaryOpNode
{
858 ModNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
861 class AddNode
: public BinaryOpNode
{
863 AddNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
865 virtual bool isAdd() const { return true; }
868 class SubNode
: public BinaryOpNode
{
870 SubNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
873 class LeftShiftNode
: public BinaryOpNode
{
875 LeftShiftNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
878 class RightShiftNode
: public BinaryOpNode
{
880 RightShiftNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
883 class UnsignedRightShiftNode
: public BinaryOpNode
{
885 UnsignedRightShiftNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
888 class LessNode
: public BinaryOpNode
{
890 LessNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
893 class GreaterNode
: public ReverseBinaryOpNode
{
895 GreaterNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
898 class LessEqNode
: public BinaryOpNode
{
900 LessEqNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
903 class GreaterEqNode
: public ReverseBinaryOpNode
{
905 GreaterEqNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
908 class ThrowableBinaryOpNode
: public BinaryOpNode
, public ThrowableExpressionData
{
910 ThrowableBinaryOpNode(JSGlobalData
*, ResultType
, ExpressionNode
* expr1
, ExpressionNode
* expr2
, OpcodeID
, bool rightHasAssignments
);
911 ThrowableBinaryOpNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, OpcodeID
, bool rightHasAssignments
);
914 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
917 class InstanceOfNode
: public ThrowableBinaryOpNode
{
919 InstanceOfNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
922 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
925 class InNode
: public ThrowableBinaryOpNode
{
927 InNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
930 class EqualNode
: public BinaryOpNode
{
932 EqualNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
935 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
938 class NotEqualNode
: public BinaryOpNode
{
940 NotEqualNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
943 class StrictEqualNode
: public BinaryOpNode
{
945 StrictEqualNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
948 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
951 class NotStrictEqualNode
: public BinaryOpNode
{
953 NotStrictEqualNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
956 class BitAndNode
: public BinaryOpNode
{
958 BitAndNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
961 class BitOrNode
: public BinaryOpNode
{
963 BitOrNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
966 class BitXOrNode
: public BinaryOpNode
{
968 BitXOrNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, bool rightHasAssignments
);
971 // m_expr1 && m_expr2, m_expr1 || m_expr2
972 class LogicalOpNode
: public ExpressionNode
{
974 LogicalOpNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, LogicalOperator
);
977 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
979 ExpressionNode
* m_expr1
;
980 ExpressionNode
* m_expr2
;
981 LogicalOperator m_operator
;
984 // The ternary operator, "m_logical ? m_expr1 : m_expr2"
985 class ConditionalNode
: public ExpressionNode
{
987 ConditionalNode(JSGlobalData
*, ExpressionNode
* logical
, ExpressionNode
* expr1
, ExpressionNode
* expr2
);
990 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
992 ExpressionNode
* m_logical
;
993 ExpressionNode
* m_expr1
;
994 ExpressionNode
* m_expr2
;
997 class ReadModifyResolveNode
: public ExpressionNode
, public ThrowableExpressionData
{
999 ReadModifyResolveNode(JSGlobalData
*, const Identifier
&, Operator
, ExpressionNode
* right
, bool rightHasAssignments
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
1002 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1005 ExpressionNode
* m_right
;
1006 size_t m_index
; // Used by ReadModifyLocalVarNode.
1007 Operator m_operator
;
1008 bool m_rightHasAssignments
;
1011 class AssignResolveNode
: public ExpressionNode
, public ThrowableExpressionData
{
1013 AssignResolveNode(JSGlobalData
*, const Identifier
&, ExpressionNode
* right
, bool rightHasAssignments
);
1016 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1019 ExpressionNode
* m_right
;
1020 size_t m_index
; // Used by ReadModifyLocalVarNode.
1021 bool m_rightHasAssignments
;
1024 class ReadModifyBracketNode
: public ExpressionNode
, public ThrowableSubExpressionData
{
1026 ReadModifyBracketNode(JSGlobalData
*, ExpressionNode
* base
, ExpressionNode
* subscript
, Operator
, ExpressionNode
* right
, bool subscriptHasAssignments
, bool rightHasAssignments
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
1029 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1031 ExpressionNode
* m_base
;
1032 ExpressionNode
* m_subscript
;
1033 ExpressionNode
* m_right
;
1034 Operator m_operator
: 30;
1035 bool m_subscriptHasAssignments
: 1;
1036 bool m_rightHasAssignments
: 1;
1039 class AssignBracketNode
: public ExpressionNode
, public ThrowableExpressionData
{
1041 AssignBracketNode(JSGlobalData
*, ExpressionNode
* base
, ExpressionNode
* subscript
, ExpressionNode
* right
, bool subscriptHasAssignments
, bool rightHasAssignments
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
1044 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1046 ExpressionNode
* m_base
;
1047 ExpressionNode
* m_subscript
;
1048 ExpressionNode
* m_right
;
1049 bool m_subscriptHasAssignments
: 1;
1050 bool m_rightHasAssignments
: 1;
1053 class AssignDotNode
: public ExpressionNode
, public ThrowableExpressionData
{
1055 AssignDotNode(JSGlobalData
*, ExpressionNode
* base
, const Identifier
&, ExpressionNode
* right
, bool rightHasAssignments
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
1058 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1060 ExpressionNode
* m_base
;
1062 ExpressionNode
* m_right
;
1063 bool m_rightHasAssignments
;
1066 class ReadModifyDotNode
: public ExpressionNode
, public ThrowableSubExpressionData
{
1068 ReadModifyDotNode(JSGlobalData
*, ExpressionNode
* base
, const Identifier
&, Operator
, ExpressionNode
* right
, bool rightHasAssignments
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
1071 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1073 ExpressionNode
* m_base
;
1075 ExpressionNode
* m_right
;
1076 Operator m_operator
: 31;
1077 bool m_rightHasAssignments
: 1;
1080 class AssignErrorNode
: public ExpressionNode
, public ThrowableExpressionData
{
1082 AssignErrorNode(JSGlobalData
*, ExpressionNode
* left
, Operator
, ExpressionNode
* right
, unsigned divot
, unsigned startOffset
, unsigned endOffset
);
1085 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1087 ExpressionNode
* m_left
;
1088 Operator m_operator
;
1089 ExpressionNode
* m_right
;
1092 typedef Vector
<ExpressionNode
*, 8> ExpressionVector
;
1094 class CommaNode
: public ExpressionNode
{
1096 CommaNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
);
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
&);
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 typedef Vector
<StatementNode
*> StatementVector
;
1139 class SourceElements
: public ParserArenaDeletable
{
1141 SourceElements(JSGlobalData
*);
1143 void append(StatementNode
*);
1144 void releaseContentsIntoVector(StatementVector
& destination
)
1146 ASSERT(destination
.isEmpty());
1147 m_statements
.swap(destination
);
1148 destination
.shrinkToFit();
1152 StatementVector m_statements
;
1155 class BlockNode
: public StatementNode
{
1157 BlockNode(JSGlobalData
*, SourceElements
* children
);
1159 StatementVector
& children() { return m_children
; }
1162 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1164 virtual bool isBlock() const { return true; }
1166 StatementVector m_children
;
1169 class EmptyStatementNode
: public StatementNode
{
1171 EmptyStatementNode(JSGlobalData
*);
1174 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1176 virtual bool isEmptyStatement() const { return true; }
1179 class DebuggerStatementNode
: public StatementNode
{
1181 DebuggerStatementNode(JSGlobalData
*);
1184 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1187 class ExprStatementNode
: public StatementNode
{
1189 ExprStatementNode(JSGlobalData
*, ExpressionNode
*);
1191 ExpressionNode
* expr() const { return m_expr
; }
1194 virtual bool isExprStatement() const { return true; }
1196 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1198 ExpressionNode
* m_expr
;
1201 class VarStatementNode
: public StatementNode
{
1203 VarStatementNode(JSGlobalData
*, ExpressionNode
*);
1206 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1208 ExpressionNode
* m_expr
;
1211 class IfNode
: public StatementNode
{
1213 IfNode(JSGlobalData
*, ExpressionNode
* condition
, StatementNode
* ifBlock
);
1216 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1218 ExpressionNode
* m_condition
;
1219 StatementNode
* m_ifBlock
;
1222 class IfElseNode
: public IfNode
{
1224 IfElseNode(JSGlobalData
*, ExpressionNode
* condition
, StatementNode
* ifBlock
, StatementNode
* elseBlock
);
1227 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1229 StatementNode
* m_elseBlock
;
1232 class DoWhileNode
: public StatementNode
{
1234 DoWhileNode(JSGlobalData
*, StatementNode
* statement
, ExpressionNode
*);
1237 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1239 StatementNode
* m_statement
;
1240 ExpressionNode
* m_expr
;
1243 class WhileNode
: public StatementNode
{
1245 WhileNode(JSGlobalData
*, ExpressionNode
*, StatementNode
* statement
);
1248 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1250 ExpressionNode
* m_expr
;
1251 StatementNode
* m_statement
;
1254 class ForNode
: public StatementNode
{
1256 ForNode(JSGlobalData
*, ExpressionNode
* expr1
, ExpressionNode
* expr2
, ExpressionNode
* expr3
, StatementNode
* statement
, bool expr1WasVarDecl
);
1259 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1261 ExpressionNode
* m_expr1
;
1262 ExpressionNode
* m_expr2
;
1263 ExpressionNode
* m_expr3
;
1264 StatementNode
* m_statement
;
1265 bool m_expr1WasVarDecl
;
1268 class ForInNode
: public StatementNode
, public ThrowableExpressionData
{
1270 ForInNode(JSGlobalData
*, ExpressionNode
*, ExpressionNode
*, StatementNode
*);
1271 ForInNode(JSGlobalData
*, const Identifier
&, ExpressionNode
*, ExpressionNode
*, StatementNode
*, int divot
, int startOffset
, int endOffset
);
1274 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1277 ExpressionNode
* m_init
;
1278 ExpressionNode
* m_lexpr
;
1279 ExpressionNode
* m_expr
;
1280 StatementNode
* m_statement
;
1281 bool m_identIsVarDecl
;
1284 class ContinueNode
: public StatementNode
, public ThrowableExpressionData
{
1286 ContinueNode(JSGlobalData
*);
1287 ContinueNode(JSGlobalData
*, const Identifier
&);
1290 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1295 class BreakNode
: public StatementNode
, public ThrowableExpressionData
{
1297 BreakNode(JSGlobalData
*);
1298 BreakNode(JSGlobalData
*, const Identifier
&);
1301 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1306 class ReturnNode
: public StatementNode
, public ThrowableExpressionData
{
1308 ReturnNode(JSGlobalData
*, ExpressionNode
* 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);
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
* dst
= 0);
1359 StatementNode
* m_tryBlock
;
1360 Identifier m_exceptionIdent
;
1361 StatementNode
* m_catchBlock
;
1362 StatementNode
* m_finallyBlock
;
1363 bool m_catchHasEval
;
1366 class ParameterNode
: public ParserArenaDeletable
{
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
; }
1376 ParameterNode
* m_next
;
1379 struct ScopeNodeData
{
1380 typedef DeclarationStacks::VarStack VarStack
;
1381 typedef DeclarationStacks::FunctionStack FunctionStack
;
1383 ScopeNodeData(ParserArena
&, SourceElements
*, VarStack
*, FunctionStack
*, int numConstants
);
1385 ParserArena m_arena
;
1386 VarStack m_varStack
;
1387 FunctionStack m_functionStack
;
1389 StatementVector m_children
;
1394 class ScopeNode
: public StatementNode
, public ParserArenaRefCounted
{
1396 typedef DeclarationStacks::VarStack VarStack
;
1397 typedef DeclarationStacks::FunctionStack FunctionStack
;
1399 ScopeNode(JSGlobalData
*);
1400 ScopeNode(JSGlobalData
*, const SourceCode
&, SourceElements
*, VarStack
*, FunctionStack
*, CodeFeatures
, int numConstants
);
1402 void adoptData(std::auto_ptr
<ScopeNodeData
> data
)
1404 ASSERT(!data
->m_arena
.contains(this));
1408 ScopeNodeData
* data() const { return m_data
.get(); }
1409 void destroyData() { m_data
.clear(); }
1411 const SourceCode
& source() const { return m_source
; }
1412 const UString
& sourceURL() const { return m_source
.provider()->url(); }
1413 intptr_t sourceID() const { return m_source
.provider()->asID(); }
1415 void setFeatures(CodeFeatures features
) { m_features
= features
; }
1416 CodeFeatures
features() { return m_features
; }
1418 bool usesEval() const { return m_features
& EvalFeature
; }
1419 bool usesArguments() const { return m_features
& ArgumentsFeature
; }
1420 void setUsesArguments() { m_features
|= ArgumentsFeature
; }
1421 bool usesThis() const { return m_features
& ThisFeature
; }
1422 bool needsActivation() const { return m_features
& (EvalFeature
| ClosureFeature
| WithFeature
| CatchFeature
); }
1424 VarStack
& varStack() { ASSERT(m_data
); return m_data
->m_varStack
; }
1425 FunctionStack
& functionStack() { ASSERT(m_data
); return m_data
->m_functionStack
; }
1427 StatementVector
& children() { ASSERT(m_data
); return m_data
->m_children
; }
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 virtual void mark() { }
1440 JITCode
& generatedJITCode()
1446 ExecutablePool
* getExecutablePool()
1448 return m_jitCode
.getExecutablePool();
1451 void setJITCode(const JITCode jitCode
)
1453 m_jitCode
= jitCode
;
1458 void setSource(const SourceCode
& source
) { m_source
= source
; }
1465 OwnPtr
<ScopeNodeData
> m_data
;
1466 CodeFeatures m_features
;
1467 SourceCode m_source
;
1470 class ProgramNode
: public ScopeNode
{
1472 static PassRefPtr
<ProgramNode
> create(JSGlobalData
*, SourceElements
*, VarStack
*, FunctionStack
*, const SourceCode
&, CodeFeatures
, int numConstants
);
1474 ProgramCodeBlock
& bytecode(ScopeChainNode
* scopeChain
)
1477 generateBytecode(scopeChain
);
1482 JITCode
& jitCode(ScopeChainNode
* scopeChain
)
1485 generateJITCode(scopeChain
);
1491 ProgramNode(JSGlobalData
*, SourceElements
*, VarStack
*, FunctionStack
*, const SourceCode
&, CodeFeatures
, int numConstants
);
1493 void generateBytecode(ScopeChainNode
*);
1494 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1497 void generateJITCode(ScopeChainNode
*);
1500 OwnPtr
<ProgramCodeBlock
> m_code
;
1503 class EvalNode
: public ScopeNode
{
1505 static PassRefPtr
<EvalNode
> create(JSGlobalData
*, SourceElements
*, VarStack
*, FunctionStack
*, const SourceCode
&, CodeFeatures
, int numConstants
);
1507 EvalCodeBlock
& bytecode(ScopeChainNode
* scopeChain
)
1510 generateBytecode(scopeChain
);
1514 EvalCodeBlock
& bytecodeForExceptionInfoReparse(ScopeChainNode
*, CodeBlock
*);
1516 virtual void mark();
1519 JITCode
& jitCode(ScopeChainNode
* scopeChain
)
1522 generateJITCode(scopeChain
);
1528 EvalNode(JSGlobalData
*, SourceElements
*, VarStack
*, FunctionStack
*, const SourceCode
&, CodeFeatures
, int numConstants
);
1530 void generateBytecode(ScopeChainNode
*);
1531 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1534 void generateJITCode(ScopeChainNode
*);
1537 OwnPtr
<EvalCodeBlock
> m_code
;
1540 class FunctionBodyNode
: public ScopeNode
{
1544 static PassRefPtr
<FunctionBodyNode
> createNativeThunk(JSGlobalData
*);
1546 static FunctionBodyNode
* create(JSGlobalData
*);
1547 static PassRefPtr
<FunctionBodyNode
> create(JSGlobalData
*, SourceElements
*, VarStack
*, FunctionStack
*, const SourceCode
&, CodeFeatures
, int numConstants
);
1548 virtual ~FunctionBodyNode();
1550 const Identifier
* parameters() const { return m_parameters
; }
1551 size_t parameterCount() const { return m_parameterCount
; }
1552 UString
paramString() const ;
1553 Identifier
* copyParameters();
1555 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1557 bool isGenerated() const
1562 bool isHostFunction() const;
1564 virtual void mark();
1566 void finishParsing(const SourceCode
&, ParameterNode
*);
1567 void finishParsing(Identifier
* parameters
, size_t parameterCount
);
1569 UString
toSourceString() const { return source().toString(); }
1571 CodeBlock
& bytecodeForExceptionInfoReparse(ScopeChainNode
*, CodeBlock
*);
1573 JITCode
& jitCode(ScopeChainNode
* scopeChain
)
1576 generateJITCode(scopeChain
);
1581 CodeBlock
& bytecode(ScopeChainNode
* scopeChain
)
1585 generateBytecode(scopeChain
);
1589 CodeBlock
& generatedBytecode()
1596 FunctionBodyNode(JSGlobalData
*);
1597 FunctionBodyNode(JSGlobalData
*, SourceElements
*, VarStack
*, FunctionStack
*, const SourceCode
&, CodeFeatures
, int numConstants
);
1599 void generateBytecode(ScopeChainNode
*);
1601 void generateJITCode(ScopeChainNode
*);
1603 Identifier
* m_parameters
;
1604 size_t m_parameterCount
;
1605 OwnPtr
<CodeBlock
> m_code
;
1608 class FuncExprNode
: public ExpressionNode
, public ParserArenaRefCounted
{
1610 FuncExprNode(JSGlobalData
*, const Identifier
&, FunctionBodyNode
* body
, const SourceCode
& source
, ParameterNode
* parameter
= 0);
1612 JSFunction
* makeFunction(ExecState
*, ScopeChainNode
*);
1614 FunctionBodyNode
* body() { return m_body
.get(); }
1617 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1619 virtual bool isFuncExprNode() const { return true; }
1622 RefPtr
<FunctionBodyNode
> m_body
;
1625 class FuncDeclNode
: public StatementNode
, public ParserArenaRefCounted
{
1627 FuncDeclNode(JSGlobalData
*, const Identifier
&, FunctionBodyNode
*, const SourceCode
&, ParameterNode
* = 0);
1629 JSFunction
* makeFunction(ExecState
*, ScopeChainNode
*);
1633 FunctionBodyNode
* body() { return m_body
.get(); }
1636 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1638 RefPtr
<FunctionBodyNode
> m_body
;
1641 class CaseClauseNode
: public ParserArenaDeletable
{
1643 CaseClauseNode(JSGlobalData
*, ExpressionNode
*);
1644 CaseClauseNode(JSGlobalData
*, ExpressionNode
*, SourceElements
*);
1646 ExpressionNode
* expr() const { return m_expr
; }
1647 StatementVector
& children() { return m_children
; }
1650 ExpressionNode
* m_expr
;
1651 StatementVector m_children
;
1654 class ClauseListNode
: public ParserArenaDeletable
{
1656 ClauseListNode(JSGlobalData
*, CaseClauseNode
*);
1657 ClauseListNode(JSGlobalData
*, ClauseListNode
*, CaseClauseNode
*);
1659 CaseClauseNode
* getClause() const { return m_clause
; }
1660 ClauseListNode
* getNext() const { return m_next
; }
1663 CaseClauseNode
* m_clause
;
1664 ClauseListNode
* m_next
;
1667 class CaseBlockNode
: public ParserArenaDeletable
{
1669 CaseBlockNode(JSGlobalData
*, ClauseListNode
* list1
, CaseClauseNode
* defaultClause
, ClauseListNode
* list2
);
1671 RegisterID
* emitBytecodeForBlock(BytecodeGenerator
&, RegisterID
* input
, RegisterID
* dst
= 0);
1674 SwitchInfo::SwitchType
tryOptimizedSwitch(Vector
<ExpressionNode
*, 8>& literalVector
, int32_t& min_num
, int32_t& max_num
);
1675 ClauseListNode
* m_list1
;
1676 CaseClauseNode
* m_defaultClause
;
1677 ClauseListNode
* m_list2
;
1680 class SwitchNode
: public StatementNode
{
1682 SwitchNode(JSGlobalData
*, ExpressionNode
*, CaseBlockNode
*);
1685 virtual RegisterID
* emitBytecode(BytecodeGenerator
&, RegisterID
* = 0);
1687 ExpressionNode
* m_expr
;
1688 CaseBlockNode
* m_block
;
1691 struct ElementList
{
1696 struct PropertyList
{
1697 PropertyListNode
* head
;
1698 PropertyListNode
* tail
;
1701 struct ArgumentList
{
1702 ArgumentListNode
* head
;
1703 ArgumentListNode
* tail
;
1706 struct ConstDeclList
{
1707 ConstDeclNode
* head
;
1708 ConstDeclNode
* tail
;
1711 struct ParameterList
{
1712 ParameterNode
* head
;
1713 ParameterNode
* tail
;
1717 ClauseListNode
* head
;
1718 ClauseListNode
* tail
;