initial import
[vuplus_webkit] / Source / JavaScriptCore / parser / Nodes.h
1 /*
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>
8  *
9  *  This library is free software; you can redistribute it and/or
10  *  modify it under the terms of the GNU Library General Public
11  *  License as published by the Free Software Foundation; either
12  *  version 2 of the License, or (at your option) any later version.
13  *
14  *  This library is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  *  Library General Public License for more details.
18  *
19  *  You should have received a copy of the GNU Library General Public License
20  *  along with this library; see the file COPYING.LIB.  If not, write to
21  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  *  Boston, MA 02110-1301, USA.
23  *
24  */
25
26 #ifndef Nodes_h
27 #define Nodes_h
28
29 #include "Error.h"
30 #include "JITCode.h"
31 #include "Opcode.h"
32 #include "ParserArena.h"
33 #include "ResultType.h"
34 #include "SourceCode.h"
35 #include "SymbolTable.h"
36 #include <wtf/MathExtras.h>
37
38 namespace JSC {
39
40     class ArgumentListNode;
41     class BytecodeGenerator;
42     class FunctionBodyNode;
43     class Label;
44     class PropertyListNode;
45     class ReadModifyResolveNode;
46     class RegisterID;
47     class ScopeChainNode;
48     class ScopeNode;
49
50     typedef unsigned CodeFeatures;
51
52     const CodeFeatures NoFeatures = 0;
53     const CodeFeatures EvalFeature = 1 << 0;
54     const CodeFeatures ClosureFeature = 1 << 1;
55     const CodeFeatures AssignFeature = 1 << 2;
56     const CodeFeatures ArgumentsFeature = 1 << 3;
57     const CodeFeatures WithFeature = 1 << 4;
58     const CodeFeatures CatchFeature = 1 << 5;
59     const CodeFeatures ThisFeature = 1 << 6;
60     const CodeFeatures StrictModeFeature = 1 << 7;
61     const CodeFeatures ShadowsArgumentsFeature = 1 << 8;
62     
63     
64     const CodeFeatures AllFeatures = EvalFeature | ClosureFeature | AssignFeature | ArgumentsFeature | WithFeature | CatchFeature | ThisFeature | StrictModeFeature | ShadowsArgumentsFeature;
65
66     enum Operator {
67         OpEqual,
68         OpPlusEq,
69         OpMinusEq,
70         OpMultEq,
71         OpDivEq,
72         OpPlusPlus,
73         OpMinusMinus,
74         OpAndEq,
75         OpXOrEq,
76         OpOrEq,
77         OpModEq,
78         OpLShift,
79         OpRShift,
80         OpURShift
81     };
82     
83     enum LogicalOperator {
84         OpLogicalAnd,
85         OpLogicalOr
86     };
87
88     typedef HashSet<RefPtr<StringImpl>, IdentifierRepHash> IdentifierSet;
89
90     namespace DeclarationStacks {
91         enum VarAttrs { IsConstant = 1, HasInitializer = 2 };
92         typedef Vector<std::pair<const Identifier*, unsigned> > VarStack;
93         typedef Vector<FunctionBodyNode*> FunctionStack;
94     }
95
96     struct SwitchInfo {
97         enum SwitchType { SwitchNone, SwitchImmediate, SwitchCharacter, SwitchString };
98         uint32_t bytecodeOffset;
99         SwitchType switchType;
100     };
101
102     class ParserArenaFreeable {
103     public:
104         // ParserArenaFreeable objects are are freed when the arena is deleted.
105         // Destructors are not called. Clients must not call delete on such objects.
106         void* operator new(size_t, JSGlobalData*);
107     };
108
109     class ParserArenaDeletable {
110     public:
111         virtual ~ParserArenaDeletable() { }
112
113         // ParserArenaDeletable objects are deleted when the arena is deleted.
114         // Clients must not call delete directly on such objects.
115         void* operator new(size_t, JSGlobalData*);
116     };
117
118     class ParserArenaRefCounted : public RefCounted<ParserArenaRefCounted> {
119     protected:
120         ParserArenaRefCounted(JSGlobalData*);
121
122     public:
123         virtual ~ParserArenaRefCounted()
124         {
125             ASSERT(deletionHasBegun());
126         }
127     };
128
129     class Node : public ParserArenaFreeable {
130     protected:
131         Node(JSGlobalData*);
132
133     public:
134         virtual ~Node() { }
135
136         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* destination = 0) = 0;
137
138         int lineNo() const { return m_line; }
139
140     protected:
141         int m_line;
142     };
143
144     class ExpressionNode : public Node {
145     protected:
146         ExpressionNode(JSGlobalData*, ResultType = ResultType::unknownType());
147
148     public:
149         virtual bool isNumber() const { return false; }
150         virtual bool isString() const { return false; }
151         virtual bool isNull() const { return false; }
152         virtual bool isPure(BytecodeGenerator&) const { return false; }        
153         virtual bool isLocation() const { return false; }
154         virtual bool isResolveNode() const { return false; }
155         virtual bool isBracketAccessorNode() const { return false; }
156         virtual bool isDotAccessorNode() const { return false; }
157         virtual bool isFuncExprNode() const { return false; }
158         virtual bool isCommaNode() const { return false; }
159         virtual bool isSimpleArray() const { return false; }
160         virtual bool isAdd() const { return false; }
161         virtual bool isSubtract() const { return false; }
162         virtual bool hasConditionContextCodegen() const { return false; }
163
164         virtual void emitBytecodeInConditionContext(BytecodeGenerator&, Label*, Label*, bool) { ASSERT_NOT_REACHED(); }
165
166         virtual ExpressionNode* stripUnaryPlus() { return this; }
167
168         ResultType resultDescriptor() const { return m_resultType; }
169
170     private:
171         ResultType m_resultType;
172     };
173
174     class StatementNode : public Node {
175     protected:
176         StatementNode(JSGlobalData*);
177
178     public:
179         void setLoc(int firstLine, int lastLine);
180         int firstLine() const { return lineNo(); }
181         int lastLine() const { return m_lastLine; }
182
183         virtual bool isEmptyStatement() const { return false; }
184         virtual bool isReturnNode() const { return false; }
185         virtual bool isExprStatement() const { return false; }
186
187         virtual bool isBlock() const { return false; }
188
189     private:
190         int m_lastLine;
191     };
192
193     class NullNode : public ExpressionNode {
194     public:
195         NullNode(JSGlobalData*);
196
197     private:
198         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
199
200         virtual bool isNull() const { return true; }
201     };
202
203     class BooleanNode : public ExpressionNode {
204     public:
205         BooleanNode(JSGlobalData*, bool value);
206
207     private:
208         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
209
210         virtual bool isPure(BytecodeGenerator&) const { return true; }
211
212         bool m_value;
213     };
214
215     class NumberNode : public ExpressionNode {
216     public:
217         NumberNode(JSGlobalData*, double value);
218
219         double value() const { return m_value; }
220         void setValue(double value) { m_value = value; }
221
222     private:
223         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
224
225         virtual bool isNumber() const { return true; }
226         virtual bool isPure(BytecodeGenerator&) const { return true; }
227
228         double m_value;
229     };
230
231     class StringNode : public ExpressionNode {
232     public:
233         StringNode(JSGlobalData*, const Identifier&);
234
235         const Identifier& value() { return m_value; }
236
237     private:
238         virtual bool isPure(BytecodeGenerator&) const { return true; }
239
240         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
241         
242         virtual bool isString() const { return true; }
243
244         const Identifier& m_value;
245     };
246     
247     class ThrowableExpressionData {
248     public:
249         ThrowableExpressionData()
250             : m_divot(static_cast<uint32_t>(-1))
251             , m_startOffset(static_cast<uint16_t>(-1))
252             , m_endOffset(static_cast<uint16_t>(-1))
253         {
254         }
255         
256         ThrowableExpressionData(unsigned divot, unsigned startOffset, unsigned endOffset)
257             : m_divot(divot)
258             , m_startOffset(startOffset)
259             , m_endOffset(endOffset)
260         {
261         }
262         
263         void setExceptionSourceCode(unsigned divot, unsigned startOffset, unsigned endOffset)
264         {
265             m_divot = divot;
266             m_startOffset = startOffset;
267             m_endOffset = endOffset;
268         }
269
270         uint32_t divot() const { return m_divot; }
271         uint16_t startOffset() const { return m_startOffset; }
272         uint16_t endOffset() const { return m_endOffset; }
273
274     protected:
275         RegisterID* emitThrowReferenceError(BytecodeGenerator&, const UString& message);
276
277     private:
278         uint32_t m_divot;
279         uint16_t m_startOffset;
280         uint16_t m_endOffset;
281     };
282
283     class ThrowableSubExpressionData : public ThrowableExpressionData {
284     public:
285         ThrowableSubExpressionData()
286             : m_subexpressionDivotOffset(0)
287             , m_subexpressionEndOffset(0)
288         {
289         }
290
291         ThrowableSubExpressionData(unsigned divot, unsigned startOffset, unsigned endOffset)
292             : ThrowableExpressionData(divot, startOffset, endOffset)
293             , m_subexpressionDivotOffset(0)
294             , m_subexpressionEndOffset(0)
295         {
296         }
297
298         void setSubexpressionInfo(uint32_t subexpressionDivot, uint16_t subexpressionOffset)
299         {
300             ASSERT(subexpressionDivot <= divot());
301             if ((divot() - subexpressionDivot) & ~0xFFFF) // Overflow means we can't do this safely, so just point at the primary divot
302                 return;
303             m_subexpressionDivotOffset = divot() - subexpressionDivot;
304             m_subexpressionEndOffset = subexpressionOffset;
305         }
306
307     protected:
308         uint16_t m_subexpressionDivotOffset;
309         uint16_t m_subexpressionEndOffset;
310     };
311     
312     class ThrowablePrefixedSubExpressionData : public ThrowableExpressionData {
313     public:
314         ThrowablePrefixedSubExpressionData()
315             : m_subexpressionDivotOffset(0)
316             , m_subexpressionStartOffset(0)
317         {
318         }
319
320         ThrowablePrefixedSubExpressionData(unsigned divot, unsigned startOffset, unsigned endOffset)
321             : ThrowableExpressionData(divot, startOffset, endOffset)
322             , m_subexpressionDivotOffset(0)
323             , m_subexpressionStartOffset(0)
324         {
325         }
326
327         void setSubexpressionInfo(uint32_t subexpressionDivot, uint16_t subexpressionOffset)
328         {
329             ASSERT(subexpressionDivot >= divot());
330             if ((subexpressionDivot - divot()) & ~0xFFFF) // Overflow means we can't do this safely, so just point at the primary divot
331                 return;
332             m_subexpressionDivotOffset = subexpressionDivot - divot();
333             m_subexpressionStartOffset = subexpressionOffset;
334         }
335
336     protected:
337         uint16_t m_subexpressionDivotOffset;
338         uint16_t m_subexpressionStartOffset;
339     };
340
341     class RegExpNode : public ExpressionNode, public ThrowableExpressionData {
342     public:
343         RegExpNode(JSGlobalData*, const Identifier& pattern, const Identifier& flags);
344
345     private:
346         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
347
348         const Identifier& m_pattern;
349         const Identifier& m_flags;
350     };
351
352     class ThisNode : public ExpressionNode {
353     public:
354         ThisNode(JSGlobalData*);
355
356     private:
357         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
358     };
359
360     class ResolveNode : public ExpressionNode {
361     public:
362         ResolveNode(JSGlobalData*, const Identifier&, int startOffset);
363
364         const Identifier& identifier() const { return m_ident; }
365
366     private:
367         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
368
369         virtual bool isPure(BytecodeGenerator&) const ;
370         virtual bool isLocation() const { return true; }
371         virtual bool isResolveNode() const { return true; }
372
373         const Identifier& m_ident;
374         int32_t m_startOffset;
375     };
376
377     class ElementNode : public ParserArenaFreeable {
378     public:
379         ElementNode(JSGlobalData*, int elision, ExpressionNode*);
380         ElementNode(JSGlobalData*, ElementNode*, int elision, ExpressionNode*);
381
382         int elision() const { return m_elision; }
383         ExpressionNode* value() { return m_node; }
384         ElementNode* next() { return m_next; }
385
386     private:
387         ElementNode* m_next;
388         int m_elision;
389         ExpressionNode* m_node;
390     };
391
392     class ArrayNode : public ExpressionNode {
393     public:
394         ArrayNode(JSGlobalData*, int elision);
395         ArrayNode(JSGlobalData*, ElementNode*);
396         ArrayNode(JSGlobalData*, int elision, ElementNode*);
397
398         ArgumentListNode* toArgumentList(JSGlobalData*) const;
399
400     private:
401         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
402
403         virtual bool isSimpleArray() const ;
404
405         ElementNode* m_element;
406         int m_elision;
407         bool m_optional;
408     };
409
410     class PropertyNode : public ParserArenaFreeable {
411     public:
412         enum Type { Constant = 1, Getter = 2, Setter = 4 };
413
414         PropertyNode(JSGlobalData*, const Identifier& name, ExpressionNode* value, Type);
415         PropertyNode(JSGlobalData*, double name, ExpressionNode* value, Type);
416
417         const Identifier& name() const { return m_name; }
418         Type type() const { return m_type; }
419
420     private:
421         friend class PropertyListNode;
422         const Identifier& m_name;
423         ExpressionNode* m_assign;
424         Type m_type;
425     };
426
427     class PropertyListNode : public Node {
428     public:
429         PropertyListNode(JSGlobalData*, PropertyNode*);
430         PropertyListNode(JSGlobalData*, PropertyNode*, PropertyListNode*);
431
432         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
433
434     private:
435         PropertyNode* m_node;
436         PropertyListNode* m_next;
437     };
438
439     class ObjectLiteralNode : public ExpressionNode {
440     public:
441         ObjectLiteralNode(JSGlobalData*);
442         ObjectLiteralNode(JSGlobalData*, PropertyListNode*);
443
444     private:
445         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
446
447         PropertyListNode* m_list;
448     };
449     
450     class BracketAccessorNode : public ExpressionNode, public ThrowableExpressionData {
451     public:
452         BracketAccessorNode(JSGlobalData*, ExpressionNode* base, ExpressionNode* subscript, bool subscriptHasAssignments);
453
454         ExpressionNode* base() const { return m_base; }
455         ExpressionNode* subscript() const { return m_subscript; }
456
457     private:
458         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
459
460         virtual bool isLocation() const { return true; }
461         virtual bool isBracketAccessorNode() const { return true; }
462
463         ExpressionNode* m_base;
464         ExpressionNode* m_subscript;
465         bool m_subscriptHasAssignments;
466     };
467
468     class DotAccessorNode : public ExpressionNode, public ThrowableExpressionData {
469     public:
470         DotAccessorNode(JSGlobalData*, ExpressionNode* base, const Identifier&);
471
472         ExpressionNode* base() const { return m_base; }
473         const Identifier& identifier() const { return m_ident; }
474
475     private:
476         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
477
478         virtual bool isLocation() const { return true; }
479         virtual bool isDotAccessorNode() const { return true; }
480
481         ExpressionNode* m_base;
482         const Identifier& m_ident;
483     };
484
485     class ArgumentListNode : public Node {
486     public:
487         ArgumentListNode(JSGlobalData*, ExpressionNode*);
488         ArgumentListNode(JSGlobalData*, ArgumentListNode*, ExpressionNode*);
489
490         ArgumentListNode* m_next;
491         ExpressionNode* m_expr;
492
493     private:
494         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
495     };
496
497     class ArgumentsNode : public ParserArenaFreeable {
498     public:
499         ArgumentsNode(JSGlobalData*);
500         ArgumentsNode(JSGlobalData*, ArgumentListNode*);
501
502         ArgumentListNode* m_listNode;
503     };
504
505     class NewExprNode : public ExpressionNode, public ThrowableExpressionData {
506     public:
507         NewExprNode(JSGlobalData*, ExpressionNode*);
508         NewExprNode(JSGlobalData*, ExpressionNode*, ArgumentsNode*);
509
510     private:
511         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
512
513         ExpressionNode* m_expr;
514         ArgumentsNode* m_args;
515     };
516
517     class EvalFunctionCallNode : public ExpressionNode, public ThrowableExpressionData {
518     public:
519         EvalFunctionCallNode(JSGlobalData*, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset);
520
521     private:
522         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
523
524         ArgumentsNode* m_args;
525     };
526
527     class FunctionCallValueNode : public ExpressionNode, public ThrowableExpressionData {
528     public:
529         FunctionCallValueNode(JSGlobalData*, ExpressionNode*, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset);
530
531     private:
532         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
533
534         ExpressionNode* m_expr;
535         ArgumentsNode* m_args;
536     };
537
538     class FunctionCallResolveNode : public ExpressionNode, public ThrowableExpressionData {
539     public:
540         FunctionCallResolveNode(JSGlobalData*, const Identifier&, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset);
541
542     private:
543         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
544
545         const Identifier& m_ident;
546         ArgumentsNode* m_args;
547         size_t m_index; // Used by LocalVarFunctionCallNode.
548         size_t m_scopeDepth; // Used by ScopedVarFunctionCallNode and NonLocalVarFunctionCallNode
549     };
550     
551     class FunctionCallBracketNode : public ExpressionNode, public ThrowableSubExpressionData {
552     public:
553         FunctionCallBracketNode(JSGlobalData*, ExpressionNode* base, ExpressionNode* subscript, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset);
554
555     private:
556         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
557
558         ExpressionNode* m_base;
559         ExpressionNode* m_subscript;
560         ArgumentsNode* m_args;
561     };
562
563     class FunctionCallDotNode : public ExpressionNode, public ThrowableSubExpressionData {
564     public:
565         FunctionCallDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset);
566
567     private:
568         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
569
570     protected:
571         ExpressionNode* m_base;
572         const Identifier& m_ident;
573         ArgumentsNode* m_args;
574     };
575
576     class CallFunctionCallDotNode : public FunctionCallDotNode {
577     public:
578         CallFunctionCallDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset);
579
580     private:
581         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
582     };
583     
584     class ApplyFunctionCallDotNode : public FunctionCallDotNode {
585     public:
586         ApplyFunctionCallDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset);
587
588     private:
589         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
590     };
591
592     class PrePostResolveNode : public ExpressionNode, public ThrowableExpressionData {
593     public:
594         PrePostResolveNode(JSGlobalData*, const Identifier&, unsigned divot, unsigned startOffset, unsigned endOffset);
595
596     protected:
597         const Identifier& m_ident;
598     };
599
600     class PostfixResolveNode : public PrePostResolveNode {
601     public:
602         PostfixResolveNode(JSGlobalData*, const Identifier&, Operator, unsigned divot, unsigned startOffset, unsigned endOffset);
603
604     private:
605         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
606
607         Operator m_operator;
608     };
609
610     class PostfixBracketNode : public ExpressionNode, public ThrowableSubExpressionData {
611     public:
612         PostfixBracketNode(JSGlobalData*, ExpressionNode* base, ExpressionNode* subscript, Operator, unsigned divot, unsigned startOffset, unsigned endOffset);
613
614     private:
615         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
616
617         ExpressionNode* m_base;
618         ExpressionNode* m_subscript;
619         Operator m_operator;
620     };
621
622     class PostfixDotNode : public ExpressionNode, public ThrowableSubExpressionData {
623     public:
624         PostfixDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, Operator, unsigned divot, unsigned startOffset, unsigned endOffset);
625
626     private:
627         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
628
629         ExpressionNode* m_base;
630         const Identifier& m_ident;
631         Operator m_operator;
632     };
633
634     class PostfixErrorNode : public ExpressionNode, public ThrowableSubExpressionData {
635     public:
636         PostfixErrorNode(JSGlobalData*, ExpressionNode*, Operator, unsigned divot, unsigned startOffset, unsigned endOffset);
637
638     private:
639         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
640
641         ExpressionNode* m_expr;
642         Operator m_operator;
643     };
644
645     class DeleteResolveNode : public ExpressionNode, public ThrowableExpressionData {
646     public:
647         DeleteResolveNode(JSGlobalData*, const Identifier&, unsigned divot, unsigned startOffset, unsigned endOffset);
648
649     private:
650         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
651
652         const Identifier& m_ident;
653     };
654
655     class DeleteBracketNode : public ExpressionNode, public ThrowableExpressionData {
656     public:
657         DeleteBracketNode(JSGlobalData*, ExpressionNode* base, ExpressionNode* subscript, unsigned divot, unsigned startOffset, unsigned endOffset);
658
659     private:
660         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
661
662         ExpressionNode* m_base;
663         ExpressionNode* m_subscript;
664     };
665
666     class DeleteDotNode : public ExpressionNode, public ThrowableExpressionData {
667     public:
668         DeleteDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, unsigned divot, unsigned startOffset, unsigned endOffset);
669
670     private:
671         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
672
673         ExpressionNode* m_base;
674         const Identifier& m_ident;
675     };
676
677     class DeleteValueNode : public ExpressionNode {
678     public:
679         DeleteValueNode(JSGlobalData*, ExpressionNode*);
680
681     private:
682         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
683
684         ExpressionNode* m_expr;
685     };
686
687     class VoidNode : public ExpressionNode {
688     public:
689         VoidNode(JSGlobalData*, ExpressionNode*);
690
691     private:
692         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
693
694         ExpressionNode* m_expr;
695     };
696
697     class TypeOfResolveNode : public ExpressionNode {
698     public:
699         TypeOfResolveNode(JSGlobalData*, const Identifier&);
700
701         const Identifier& identifier() const { return m_ident; }
702
703     private:
704         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
705
706         const Identifier& m_ident;
707     };
708
709     class TypeOfValueNode : public ExpressionNode {
710     public:
711         TypeOfValueNode(JSGlobalData*, ExpressionNode*);
712
713     private:
714         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
715
716         ExpressionNode* m_expr;
717     };
718
719     class PrefixResolveNode : public PrePostResolveNode {
720     public:
721         PrefixResolveNode(JSGlobalData*, const Identifier&, Operator, unsigned divot, unsigned startOffset, unsigned endOffset);
722
723     private:
724         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
725
726         Operator m_operator;
727     };
728
729     class PrefixBracketNode : public ExpressionNode, public ThrowablePrefixedSubExpressionData {
730     public:
731         PrefixBracketNode(JSGlobalData*, ExpressionNode* base, ExpressionNode* subscript, Operator, unsigned divot, unsigned startOffset, unsigned endOffset);
732
733     private:
734         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
735
736         ExpressionNode* m_base;
737         ExpressionNode* m_subscript;
738         Operator m_operator;
739     };
740
741     class PrefixDotNode : public ExpressionNode, public ThrowablePrefixedSubExpressionData {
742     public:
743         PrefixDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, Operator, unsigned divot, unsigned startOffset, unsigned endOffset);
744
745     private:
746         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
747
748         ExpressionNode* m_base;
749         const Identifier& m_ident;
750         Operator m_operator;
751     };
752
753     class PrefixErrorNode : public ExpressionNode, public ThrowableExpressionData {
754     public:
755         PrefixErrorNode(JSGlobalData*, ExpressionNode*, Operator, unsigned divot, unsigned startOffset, unsigned endOffset);
756
757     private:
758         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
759
760         ExpressionNode* m_expr;
761         Operator m_operator;
762     };
763
764     class UnaryOpNode : public ExpressionNode {
765     public:
766         UnaryOpNode(JSGlobalData*, ResultType, ExpressionNode*, OpcodeID);
767
768     protected:
769         ExpressionNode* expr() { return m_expr; }
770         const ExpressionNode* expr() const { return m_expr; }
771
772     private:
773         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
774
775         OpcodeID opcodeID() const { return m_opcodeID; }
776
777         ExpressionNode* m_expr;
778         OpcodeID m_opcodeID;
779     };
780
781     class UnaryPlusNode : public UnaryOpNode {
782     public:
783         UnaryPlusNode(JSGlobalData*, ExpressionNode*);
784
785     private:
786         virtual ExpressionNode* stripUnaryPlus() { return expr(); }
787     };
788
789     class NegateNode : public UnaryOpNode {
790     public:
791         NegateNode(JSGlobalData*, ExpressionNode*);
792     };
793
794     class BitwiseNotNode : public UnaryOpNode {
795     public:
796         BitwiseNotNode(JSGlobalData*, ExpressionNode*);
797     };
798
799     class LogicalNotNode : public UnaryOpNode {
800     public:
801         LogicalNotNode(JSGlobalData*, ExpressionNode*);
802     private:
803         void emitBytecodeInConditionContext(BytecodeGenerator&, Label* trueTarget, Label* falseTarget, bool fallThroughMeansTrue);
804         virtual bool hasConditionContextCodegen() const { return expr()->hasConditionContextCodegen(); }
805     };
806
807     class BinaryOpNode : public ExpressionNode {
808     public:
809         BinaryOpNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments);
810         BinaryOpNode(JSGlobalData*, ResultType, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments);
811
812         RegisterID* emitStrcat(BytecodeGenerator& generator, RegisterID* destination, RegisterID* lhs = 0, ReadModifyResolveNode* emitExpressionInfoForMe = 0);
813
814         ExpressionNode* lhs() { return m_expr1; };
815         ExpressionNode* rhs() { return m_expr2; };
816
817     private:
818         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
819
820     protected:
821         OpcodeID opcodeID() const { return m_opcodeID; }
822
823     protected:
824         ExpressionNode* m_expr1;
825         ExpressionNode* m_expr2;
826     private:
827         OpcodeID m_opcodeID;
828     protected:
829         bool m_rightHasAssignments;
830     };
831
832     class MultNode : public BinaryOpNode {
833     public:
834         MultNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
835     };
836
837     class DivNode : public BinaryOpNode {
838     public:
839         DivNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
840     };
841
842     class ModNode : public BinaryOpNode {
843     public:
844         ModNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
845     };
846
847     class AddNode : public BinaryOpNode {
848     public:
849         AddNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
850
851         virtual bool isAdd() const { return true; }
852     };
853
854     class SubNode : public BinaryOpNode {
855     public:
856         SubNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
857
858         virtual bool isSubtract() const { return true; }
859     };
860
861     class LeftShiftNode : public BinaryOpNode {
862     public:
863         LeftShiftNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
864     };
865
866     class RightShiftNode : public BinaryOpNode {
867     public:
868         RightShiftNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
869     };
870
871     class UnsignedRightShiftNode : public BinaryOpNode {
872     public:
873         UnsignedRightShiftNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
874     };
875
876     class LessNode : public BinaryOpNode {
877     public:
878         LessNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
879     };
880
881     class GreaterNode : public BinaryOpNode {
882     public:
883         GreaterNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
884     };
885
886     class LessEqNode : public BinaryOpNode {
887     public:
888         LessEqNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
889     };
890
891     class GreaterEqNode : public BinaryOpNode {
892     public:
893         GreaterEqNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
894     };
895
896     class ThrowableBinaryOpNode : public BinaryOpNode, public ThrowableExpressionData {
897     public:
898         ThrowableBinaryOpNode(JSGlobalData*, ResultType, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments);
899         ThrowableBinaryOpNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments);
900
901     private:
902         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
903     };
904     
905     class InstanceOfNode : public ThrowableBinaryOpNode {
906     public:
907         InstanceOfNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
908
909     private:
910         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
911     };
912
913     class InNode : public ThrowableBinaryOpNode {
914     public:
915         InNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
916     };
917
918     class EqualNode : public BinaryOpNode {
919     public:
920         EqualNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
921
922     private:
923         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
924     };
925
926     class NotEqualNode : public BinaryOpNode {
927     public:
928         NotEqualNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
929     };
930
931     class StrictEqualNode : public BinaryOpNode {
932     public:
933         StrictEqualNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
934
935     private:
936         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
937     };
938
939     class NotStrictEqualNode : public BinaryOpNode {
940     public:
941         NotStrictEqualNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
942     };
943
944     class BitAndNode : public BinaryOpNode {
945     public:
946         BitAndNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
947     };
948
949     class BitOrNode : public BinaryOpNode {
950     public:
951         BitOrNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
952     };
953
954     class BitXOrNode : public BinaryOpNode {
955     public:
956         BitXOrNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
957     };
958
959     // m_expr1 && m_expr2, m_expr1 || m_expr2
960     class LogicalOpNode : public ExpressionNode {
961     public:
962         LogicalOpNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, LogicalOperator);
963
964     private:
965         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
966         void emitBytecodeInConditionContext(BytecodeGenerator&, Label* trueTarget, Label* falseTarget, bool fallThroughMeansTrue);
967         virtual bool hasConditionContextCodegen() const { return true; }
968
969         ExpressionNode* m_expr1;
970         ExpressionNode* m_expr2;
971         LogicalOperator m_operator;
972     };
973
974     // The ternary operator, "m_logical ? m_expr1 : m_expr2"
975     class ConditionalNode : public ExpressionNode {
976     public:
977         ConditionalNode(JSGlobalData*, ExpressionNode* logical, ExpressionNode* expr1, ExpressionNode* expr2);
978
979     private:
980         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
981
982         ExpressionNode* m_logical;
983         ExpressionNode* m_expr1;
984         ExpressionNode* m_expr2;
985     };
986
987     class ReadModifyResolveNode : public ExpressionNode, public ThrowableExpressionData {
988     public:
989         ReadModifyResolveNode(JSGlobalData*, const Identifier&, Operator, ExpressionNode*  right, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset);
990
991     private:
992         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
993
994         const Identifier& m_ident;
995         ExpressionNode* m_right;
996         size_t m_index; // Used by ReadModifyLocalVarNode.
997         Operator m_operator;
998         bool m_rightHasAssignments;
999     };
1000
1001     class AssignResolveNode : public ExpressionNode, public ThrowableExpressionData {
1002     public:
1003         AssignResolveNode(JSGlobalData*, const Identifier&, ExpressionNode* right, bool rightHasAssignments);
1004
1005     private:
1006         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1007
1008         const Identifier& m_ident;
1009         ExpressionNode* m_right;
1010         size_t m_index; // Used by ReadModifyLocalVarNode.
1011         bool m_rightHasAssignments;
1012     };
1013
1014     class ReadModifyBracketNode : public ExpressionNode, public ThrowableSubExpressionData {
1015     public:
1016         ReadModifyBracketNode(JSGlobalData*, ExpressionNode* base, ExpressionNode* subscript, Operator, ExpressionNode* right, bool subscriptHasAssignments, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset);
1017
1018     private:
1019         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1020
1021         ExpressionNode* m_base;
1022         ExpressionNode* m_subscript;
1023         ExpressionNode* m_right;
1024         Operator m_operator : 30;
1025         bool m_subscriptHasAssignments : 1;
1026         bool m_rightHasAssignments : 1;
1027     };
1028
1029     class AssignBracketNode : public ExpressionNode, public ThrowableExpressionData {
1030     public:
1031         AssignBracketNode(JSGlobalData*, ExpressionNode* base, ExpressionNode* subscript, ExpressionNode* right, bool subscriptHasAssignments, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset);
1032
1033     private:
1034         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1035
1036         ExpressionNode* m_base;
1037         ExpressionNode* m_subscript;
1038         ExpressionNode* m_right;
1039         bool m_subscriptHasAssignments : 1;
1040         bool m_rightHasAssignments : 1;
1041     };
1042
1043     class AssignDotNode : public ExpressionNode, public ThrowableExpressionData {
1044     public:
1045         AssignDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, ExpressionNode* right, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset);
1046
1047     private:
1048         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1049
1050         ExpressionNode* m_base;
1051         const Identifier& m_ident;
1052         ExpressionNode* m_right;
1053         bool m_rightHasAssignments;
1054     };
1055
1056     class ReadModifyDotNode : public ExpressionNode, public ThrowableSubExpressionData {
1057     public:
1058         ReadModifyDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, Operator, ExpressionNode* right, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset);
1059
1060     private:
1061         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1062
1063         ExpressionNode* m_base;
1064         const Identifier& m_ident;
1065         ExpressionNode* m_right;
1066         Operator m_operator : 31;
1067         bool m_rightHasAssignments : 1;
1068     };
1069
1070     class AssignErrorNode : public ExpressionNode, public ThrowableExpressionData {
1071     public:
1072         AssignErrorNode(JSGlobalData*, ExpressionNode* left, Operator, ExpressionNode* right, unsigned divot, unsigned startOffset, unsigned endOffset);
1073
1074     private:
1075         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1076
1077         ExpressionNode* m_left;
1078         Operator m_operator;
1079         ExpressionNode* m_right;
1080     };
1081     
1082     typedef Vector<ExpressionNode*, 8> ExpressionVector;
1083
1084     class CommaNode : public ExpressionNode, public ParserArenaDeletable {
1085     public:
1086         CommaNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2);
1087
1088         using ParserArenaDeletable::operator new;
1089
1090         void append(ExpressionNode* expr) { m_expressions.append(expr); }
1091
1092     private:
1093         virtual bool isCommaNode() const { return true; }
1094         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1095
1096         ExpressionVector m_expressions;
1097     };
1098     
1099     class ConstDeclNode : public ExpressionNode {
1100     public:
1101         ConstDeclNode(JSGlobalData*, const Identifier&, ExpressionNode*);
1102
1103         bool hasInitializer() const { return m_init; }
1104         const Identifier& ident() { return m_ident; }
1105
1106     private:
1107         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1108         virtual RegisterID* emitCodeSingle(BytecodeGenerator&);
1109
1110         const Identifier& m_ident;
1111
1112     public:
1113         ConstDeclNode* m_next;
1114
1115     private:
1116         ExpressionNode* m_init;
1117     };
1118
1119     class ConstStatementNode : public StatementNode {
1120     public:
1121         ConstStatementNode(JSGlobalData*, ConstDeclNode* next);
1122
1123     private:
1124         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1125
1126         ConstDeclNode* m_next;
1127     };
1128
1129     class SourceElements : public ParserArenaDeletable {
1130     public:
1131         SourceElements(JSGlobalData*);
1132
1133         void append(StatementNode*);
1134
1135         StatementNode* singleStatement() const;
1136         StatementNode* lastStatement() const;
1137
1138         void emitBytecode(BytecodeGenerator&, RegisterID* destination);
1139
1140     private:
1141         Vector<StatementNode*> m_statements;
1142     };
1143
1144     class BlockNode : public StatementNode {
1145     public:
1146         BlockNode(JSGlobalData*, SourceElements* = 0);
1147
1148         StatementNode* singleStatement() const;
1149         StatementNode* lastStatement() const;
1150
1151     private:
1152         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1153
1154         virtual bool isBlock() const { return true; }
1155
1156         SourceElements* m_statements;
1157     };
1158
1159     class EmptyStatementNode : public StatementNode {
1160     public:
1161         EmptyStatementNode(JSGlobalData*);
1162
1163     private:
1164         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1165
1166         virtual bool isEmptyStatement() const { return true; }
1167     };
1168     
1169     class DebuggerStatementNode : public StatementNode {
1170     public:
1171         DebuggerStatementNode(JSGlobalData*);
1172         
1173     private:
1174         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1175     };
1176
1177     class ExprStatementNode : public StatementNode {
1178     public:
1179         ExprStatementNode(JSGlobalData*, ExpressionNode*);
1180
1181         ExpressionNode* expr() const { return m_expr; }
1182
1183     private:
1184         virtual bool isExprStatement() const { return true; }
1185
1186         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1187
1188         ExpressionNode* m_expr;
1189     };
1190
1191     class VarStatementNode : public StatementNode {
1192     public:
1193         VarStatementNode(JSGlobalData*, ExpressionNode*);        
1194
1195     private:
1196         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1197
1198         ExpressionNode* m_expr;
1199     };
1200
1201     class IfNode : public StatementNode {
1202     public:
1203         IfNode(JSGlobalData*, ExpressionNode* condition, StatementNode* ifBlock);
1204
1205     protected:
1206         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1207
1208         ExpressionNode* m_condition;
1209         StatementNode* m_ifBlock;
1210     };
1211
1212     class IfElseNode : public IfNode {
1213     public:
1214         IfElseNode(JSGlobalData*, ExpressionNode* condition, StatementNode* ifBlock, StatementNode* elseBlock);
1215
1216     private:
1217         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1218
1219         StatementNode* m_elseBlock;
1220     };
1221
1222     class DoWhileNode : public StatementNode {
1223     public:
1224         DoWhileNode(JSGlobalData*, StatementNode* statement, ExpressionNode*);
1225
1226     private:
1227         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1228
1229         StatementNode* m_statement;
1230         ExpressionNode* m_expr;
1231     };
1232
1233     class WhileNode : public StatementNode {
1234     public:
1235         WhileNode(JSGlobalData*, ExpressionNode*, StatementNode* statement);
1236
1237     private:
1238         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1239
1240         ExpressionNode* m_expr;
1241         StatementNode* m_statement;
1242     };
1243
1244     class ForNode : public StatementNode {
1245     public:
1246         ForNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, ExpressionNode* expr3, StatementNode* statement, bool expr1WasVarDecl);
1247
1248     private:
1249         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1250
1251         ExpressionNode* m_expr1;
1252         ExpressionNode* m_expr2;
1253         ExpressionNode* m_expr3;
1254         StatementNode* m_statement;
1255         bool m_expr1WasVarDecl;
1256     };
1257
1258     class ForInNode : public StatementNode, public ThrowableExpressionData {
1259     public:
1260         ForInNode(JSGlobalData*, ExpressionNode*, ExpressionNode*, StatementNode*);
1261         ForInNode(JSGlobalData*, const Identifier&, ExpressionNode*, ExpressionNode*, StatementNode*, int divot, int startOffset, int endOffset);
1262
1263     private:
1264         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1265
1266         const Identifier& m_ident;
1267         ExpressionNode* m_init;
1268         ExpressionNode* m_lexpr;
1269         ExpressionNode* m_expr;
1270         StatementNode* m_statement;
1271         bool m_identIsVarDecl;
1272     };
1273
1274     class ContinueNode : public StatementNode, public ThrowableExpressionData {
1275     public:
1276         ContinueNode(JSGlobalData*);
1277         ContinueNode(JSGlobalData*, const Identifier&);
1278         
1279     private:
1280         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1281
1282         const Identifier& m_ident;
1283     };
1284
1285     class BreakNode : public StatementNode, public ThrowableExpressionData {
1286     public:
1287         BreakNode(JSGlobalData*);
1288         BreakNode(JSGlobalData*, const Identifier&);
1289         
1290     private:
1291         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1292
1293         const Identifier& m_ident;
1294     };
1295
1296     class ReturnNode : public StatementNode, public ThrowableExpressionData {
1297     public:
1298         ReturnNode(JSGlobalData*, ExpressionNode* value);
1299
1300         ExpressionNode* value() { return m_value; }
1301
1302     private:
1303         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1304
1305         virtual bool isReturnNode() const { return true; }
1306
1307         ExpressionNode* m_value;
1308     };
1309
1310     class WithNode : public StatementNode {
1311     public:
1312         WithNode(JSGlobalData*, ExpressionNode*, StatementNode*, uint32_t divot, uint32_t expressionLength);
1313
1314     private:
1315         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1316
1317         ExpressionNode* m_expr;
1318         StatementNode* m_statement;
1319         uint32_t m_divot;
1320         uint32_t m_expressionLength;
1321     };
1322
1323     class LabelNode : public StatementNode, public ThrowableExpressionData {
1324     public:
1325         LabelNode(JSGlobalData*, const Identifier& name, StatementNode*);
1326
1327     private:
1328         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1329
1330         const Identifier& m_name;
1331         StatementNode* m_statement;
1332     };
1333
1334     class ThrowNode : public StatementNode, public ThrowableExpressionData {
1335     public:
1336         ThrowNode(JSGlobalData*, ExpressionNode*);
1337
1338     private:
1339         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1340
1341         ExpressionNode* m_expr;
1342     };
1343
1344     class TryNode : public StatementNode {
1345     public:
1346         TryNode(JSGlobalData*, StatementNode* tryBlock, const Identifier& exceptionIdent, bool catchHasEval, StatementNode* catchBlock, StatementNode* finallyBlock);
1347
1348     private:
1349         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1350
1351         StatementNode* m_tryBlock;
1352         const Identifier& m_exceptionIdent;
1353         StatementNode* m_catchBlock;
1354         StatementNode* m_finallyBlock;
1355         bool m_catchHasEval;
1356     };
1357
1358     class ParameterNode : public ParserArenaFreeable {
1359     public:
1360         ParameterNode(JSGlobalData*, const Identifier&);
1361         ParameterNode(JSGlobalData*, ParameterNode*, const Identifier&);
1362
1363         const Identifier& ident() const { return m_ident; }
1364         ParameterNode* nextParam() const { return m_next; }
1365
1366     private:
1367         const Identifier& m_ident;
1368         ParameterNode* m_next;
1369     };
1370
1371     struct ScopeNodeData {
1372         WTF_MAKE_FAST_ALLOCATED;
1373     public:
1374         typedef DeclarationStacks::VarStack VarStack;
1375         typedef DeclarationStacks::FunctionStack FunctionStack;
1376
1377         ScopeNodeData(ParserArena&, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, int numConstants);
1378
1379         ParserArena m_arena;
1380         VarStack m_varStack;
1381         FunctionStack m_functionStack;
1382         int m_numConstants;
1383         SourceElements* m_statements;
1384         IdentifierSet m_capturedVariables;
1385     };
1386
1387     class ScopeNode : public StatementNode, public ParserArenaRefCounted {
1388     public:
1389         typedef DeclarationStacks::VarStack VarStack;
1390         typedef DeclarationStacks::FunctionStack FunctionStack;
1391
1392         ScopeNode(JSGlobalData*, bool inStrictContext);
1393         ScopeNode(JSGlobalData*, const SourceCode&, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, CodeFeatures, int numConstants);
1394
1395         using ParserArenaRefCounted::operator new;
1396
1397         ScopeNodeData* data() const { return m_data.get(); }
1398         void destroyData() { m_data.clear(); }
1399
1400         const SourceCode& source() const { return m_source; }
1401         const UString& sourceURL() const { return m_source.provider()->url(); }
1402         intptr_t sourceID() const { return m_source.provider()->asID(); }
1403
1404         void setFeatures(CodeFeatures features) { m_features = features; }
1405         CodeFeatures features() { return m_features; }
1406
1407         bool usesEval() const { return m_features & EvalFeature; }
1408         bool usesArguments() const { return (m_features & ArgumentsFeature) && !(m_features & ShadowsArgumentsFeature); }
1409         bool isStrictMode() const { return m_features & StrictModeFeature; }
1410         void setUsesArguments() { m_features |= ArgumentsFeature; }
1411         bool usesThis() const { return m_features & ThisFeature; }
1412         bool needsActivationForMoreThanVariables() const { ASSERT(m_data); return m_features & (EvalFeature | WithFeature | CatchFeature); }
1413         bool needsActivation() const { ASSERT(m_data); return (hasCapturedVariables()) || (m_features & (EvalFeature | WithFeature | CatchFeature)); }
1414         bool hasCapturedVariables() const { return !!m_data->m_capturedVariables.size(); }
1415         size_t capturedVariableCount() const { return m_data->m_capturedVariables.size(); }
1416         bool captures(const Identifier& ident) { return m_data->m_capturedVariables.contains(ident.impl()); }
1417
1418         VarStack& varStack() { ASSERT(m_data); return m_data->m_varStack; }
1419         FunctionStack& functionStack() { ASSERT(m_data); return m_data->m_functionStack; }
1420
1421         int neededConstants()
1422         {
1423             ASSERT(m_data);
1424             // We may need 2 more constants than the count given by the parser,
1425             // because of the various uses of jsUndefined() and jsNull().
1426             return m_data->m_numConstants + 2;
1427         }
1428
1429         StatementNode* singleStatement() const;
1430
1431         void emitStatementsBytecode(BytecodeGenerator&, RegisterID* destination);
1432
1433     protected:
1434         void setSource(const SourceCode& source) { m_source = source; }
1435
1436     private:
1437         OwnPtr<ScopeNodeData> m_data;
1438         CodeFeatures m_features;
1439         SourceCode m_source;
1440     };
1441
1442     class ProgramNode : public ScopeNode {
1443     public:
1444         static const bool isFunctionNode = false;
1445         static PassRefPtr<ProgramNode> create(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants);
1446
1447         static const bool scopeIsFunction = false;
1448
1449     private:
1450         ProgramNode(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants);
1451
1452         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1453     };
1454
1455     class EvalNode : public ScopeNode {
1456     public:
1457         static const bool isFunctionNode = false;
1458         static PassRefPtr<EvalNode> create(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants);
1459
1460         static const bool scopeIsFunction = false;
1461
1462     private:
1463         EvalNode(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants);
1464
1465         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1466     };
1467
1468     class FunctionParameters : public Vector<Identifier>, public RefCounted<FunctionParameters> {
1469         WTF_MAKE_FAST_ALLOCATED;
1470     public:
1471         static PassRefPtr<FunctionParameters> create(ParameterNode* firstParameter) { return adoptRef(new FunctionParameters(firstParameter)); }
1472
1473     private:
1474         FunctionParameters(ParameterNode*);
1475     };
1476
1477     class FunctionBodyNode : public ScopeNode {
1478     public:
1479         static const bool isFunctionNode = true;
1480         static FunctionBodyNode* create(JSGlobalData*, bool isStrictMode);
1481         static PassRefPtr<FunctionBodyNode> create(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants);
1482
1483         FunctionParameters* parameters() const { return m_parameters.get(); }
1484         size_t parameterCount() const { return m_parameters->size(); }
1485
1486         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1487
1488         void finishParsing(const SourceCode&, ParameterNode*, const Identifier&);
1489         void finishParsing(PassRefPtr<FunctionParameters>, const Identifier&);
1490         
1491         const Identifier& ident() { return m_ident; }
1492
1493         static const bool scopeIsFunction = true;
1494
1495     private:
1496         FunctionBodyNode(JSGlobalData*, bool inStrictContext);
1497         FunctionBodyNode(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants);
1498
1499         Identifier m_ident;
1500         RefPtr<FunctionParameters> m_parameters;
1501     };
1502
1503     class FuncExprNode : public ExpressionNode {
1504     public:
1505         FuncExprNode(JSGlobalData*, const Identifier&, FunctionBodyNode* body, const SourceCode& source, ParameterNode* parameter = 0);
1506
1507         FunctionBodyNode* body() { return m_body; }
1508
1509     private:
1510         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1511
1512         virtual bool isFuncExprNode() const { return true; } 
1513
1514         FunctionBodyNode* m_body;
1515     };
1516
1517     class FuncDeclNode : public StatementNode {
1518     public:
1519         FuncDeclNode(JSGlobalData*, const Identifier&, FunctionBodyNode*, const SourceCode&, ParameterNode* = 0);
1520
1521         FunctionBodyNode* body() { return m_body; }
1522
1523     private:
1524         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1525
1526         FunctionBodyNode* m_body;
1527     };
1528
1529     class CaseClauseNode : public ParserArenaFreeable {
1530     public:
1531         CaseClauseNode(JSGlobalData*, ExpressionNode*, SourceElements* = 0);
1532
1533         ExpressionNode* expr() const { return m_expr; }
1534
1535         void emitBytecode(BytecodeGenerator&, RegisterID* destination);
1536
1537     private:
1538         ExpressionNode* m_expr;
1539         SourceElements* m_statements;
1540     };
1541
1542     class ClauseListNode : public ParserArenaFreeable {
1543     public:
1544         ClauseListNode(JSGlobalData*, CaseClauseNode*);
1545         ClauseListNode(JSGlobalData*, ClauseListNode*, CaseClauseNode*);
1546
1547         CaseClauseNode* getClause() const { return m_clause; }
1548         ClauseListNode* getNext() const { return m_next; }
1549
1550     private:
1551         CaseClauseNode* m_clause;
1552         ClauseListNode* m_next;
1553     };
1554
1555     class CaseBlockNode : public ParserArenaFreeable {
1556     public:
1557         CaseBlockNode(JSGlobalData*, ClauseListNode* list1, CaseClauseNode* defaultClause, ClauseListNode* list2);
1558
1559         RegisterID* emitBytecodeForBlock(BytecodeGenerator&, RegisterID* input, RegisterID* destination);
1560
1561     private:
1562         SwitchInfo::SwitchType tryOptimizedSwitch(Vector<ExpressionNode*, 8>& literalVector, int32_t& min_num, int32_t& max_num);
1563         ClauseListNode* m_list1;
1564         CaseClauseNode* m_defaultClause;
1565         ClauseListNode* m_list2;
1566     };
1567
1568     class SwitchNode : public StatementNode {
1569     public:
1570         SwitchNode(JSGlobalData*, ExpressionNode*, CaseBlockNode*);
1571
1572     private:
1573         virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1574
1575         ExpressionNode* m_expr;
1576         CaseBlockNode* m_block;
1577     };
1578
1579     struct ElementList {
1580         ElementNode* head;
1581         ElementNode* tail;
1582     };
1583
1584     struct PropertyList {
1585         PropertyListNode* head;
1586         PropertyListNode* tail;
1587     };
1588
1589     struct ArgumentList {
1590         ArgumentListNode* head;
1591         ArgumentListNode* tail;
1592     };
1593
1594     struct ConstDeclList {
1595         ConstDeclNode* head;
1596         ConstDeclNode* tail;
1597     };
1598
1599     struct ParameterList {
1600         ParameterNode* head;
1601         ParameterNode* tail;
1602     };
1603
1604     struct ClauseList {
1605         ClauseListNode* head;
1606         ClauseListNode* tail;
1607     };
1608
1609 } // namespace JSC
1610
1611 #endif // Nodes_h