deps: update v8 to 4.3.61.21
[platform/upstream/nodejs.git] / deps / v8 / src / ast.h
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef V8_AST_H_
6 #define V8_AST_H_
7
8 #include "src/v8.h"
9
10 #include "src/assembler.h"
11 #include "src/ast-value-factory.h"
12 #include "src/bailout-reason.h"
13 #include "src/factory.h"
14 #include "src/isolate.h"
15 #include "src/jsregexp.h"
16 #include "src/list-inl.h"
17 #include "src/modules.h"
18 #include "src/runtime/runtime.h"
19 #include "src/small-pointer-list.h"
20 #include "src/smart-pointers.h"
21 #include "src/token.h"
22 #include "src/types.h"
23 #include "src/utils.h"
24 #include "src/variables.h"
25
26 namespace v8 {
27 namespace internal {
28
29 // The abstract syntax tree is an intermediate, light-weight
30 // representation of the parsed JavaScript code suitable for
31 // compilation to native code.
32
33 // Nodes are allocated in a separate zone, which allows faster
34 // allocation and constant-time deallocation of the entire syntax
35 // tree.
36
37
38 // ----------------------------------------------------------------------------
39 // Nodes of the abstract syntax tree. Only concrete classes are
40 // enumerated here.
41
42 #define DECLARATION_NODE_LIST(V) \
43   V(VariableDeclaration)         \
44   V(FunctionDeclaration)         \
45   V(ModuleDeclaration)           \
46   V(ImportDeclaration)           \
47   V(ExportDeclaration)
48
49 #define MODULE_NODE_LIST(V)                     \
50   V(ModuleLiteral)                              \
51   V(ModulePath)                                 \
52   V(ModuleUrl)
53
54 #define STATEMENT_NODE_LIST(V)                  \
55   V(Block)                                      \
56   V(ModuleStatement)                            \
57   V(ExpressionStatement)                        \
58   V(EmptyStatement)                             \
59   V(IfStatement)                                \
60   V(ContinueStatement)                          \
61   V(BreakStatement)                             \
62   V(ReturnStatement)                            \
63   V(WithStatement)                              \
64   V(SwitchStatement)                            \
65   V(DoWhileStatement)                           \
66   V(WhileStatement)                             \
67   V(ForStatement)                               \
68   V(ForInStatement)                             \
69   V(ForOfStatement)                             \
70   V(TryCatchStatement)                          \
71   V(TryFinallyStatement)                        \
72   V(DebuggerStatement)
73
74 #define EXPRESSION_NODE_LIST(V) \
75   V(FunctionLiteral)            \
76   V(ClassLiteral)               \
77   V(NativeFunctionLiteral)      \
78   V(Conditional)                \
79   V(VariableProxy)              \
80   V(Literal)                    \
81   V(RegExpLiteral)              \
82   V(ObjectLiteral)              \
83   V(ArrayLiteral)               \
84   V(Assignment)                 \
85   V(Yield)                      \
86   V(Throw)                      \
87   V(Property)                   \
88   V(Call)                       \
89   V(CallNew)                    \
90   V(CallRuntime)                \
91   V(UnaryOperation)             \
92   V(CountOperation)             \
93   V(BinaryOperation)            \
94   V(CompareOperation)           \
95   V(ThisFunction)               \
96   V(SuperReference)             \
97   V(CaseClause)
98
99 #define AST_NODE_LIST(V)                        \
100   DECLARATION_NODE_LIST(V)                      \
101   MODULE_NODE_LIST(V)                           \
102   STATEMENT_NODE_LIST(V)                        \
103   EXPRESSION_NODE_LIST(V)
104
105 // Forward declarations
106 class AstNodeFactory;
107 class AstVisitor;
108 class Declaration;
109 class Module;
110 class BreakableStatement;
111 class Expression;
112 class IterationStatement;
113 class MaterializedLiteral;
114 class Statement;
115 class TypeFeedbackOracle;
116
117 class RegExpAlternative;
118 class RegExpAssertion;
119 class RegExpAtom;
120 class RegExpBackReference;
121 class RegExpCapture;
122 class RegExpCharacterClass;
123 class RegExpCompiler;
124 class RegExpDisjunction;
125 class RegExpEmpty;
126 class RegExpLookahead;
127 class RegExpQuantifier;
128 class RegExpText;
129
130 #define DEF_FORWARD_DECLARATION(type) class type;
131 AST_NODE_LIST(DEF_FORWARD_DECLARATION)
132 #undef DEF_FORWARD_DECLARATION
133
134
135 // Typedef only introduced to avoid unreadable code.
136 // Please do appreciate the required space in "> >".
137 typedef ZoneList<Handle<String> > ZoneStringList;
138 typedef ZoneList<Handle<Object> > ZoneObjectList;
139
140
141 #define DECLARE_NODE_TYPE(type)                                          \
142   void Accept(AstVisitor* v) OVERRIDE;                                   \
143   AstNode::NodeType node_type() const FINAL { return AstNode::k##type; } \
144   friend class AstNodeFactory;
145
146
147 enum AstPropertiesFlag {
148   kDontSelfOptimize,
149   kDontSoftInline,
150   kDontCache
151 };
152
153
154 class FeedbackVectorRequirements {
155  public:
156   FeedbackVectorRequirements(int slots, int ic_slots)
157       : slots_(slots), ic_slots_(ic_slots) {}
158
159   int slots() const { return slots_; }
160   int ic_slots() const { return ic_slots_; }
161
162  private:
163   int slots_;
164   int ic_slots_;
165 };
166
167
168 class VariableICSlotPair FINAL {
169  public:
170   VariableICSlotPair(Variable* variable, FeedbackVectorICSlot slot)
171       : variable_(variable), slot_(slot) {}
172   VariableICSlotPair()
173       : variable_(NULL), slot_(FeedbackVectorICSlot::Invalid()) {}
174
175   Variable* variable() const { return variable_; }
176   FeedbackVectorICSlot slot() const { return slot_; }
177
178  private:
179   Variable* variable_;
180   FeedbackVectorICSlot slot_;
181 };
182
183
184 typedef List<VariableICSlotPair> ICSlotCache;
185
186
187 class AstProperties FINAL BASE_EMBEDDED {
188  public:
189   class Flags : public EnumSet<AstPropertiesFlag, int> {};
190
191   explicit AstProperties(Zone* zone) : node_count_(0), spec_(zone) {}
192
193   Flags* flags() { return &flags_; }
194   int node_count() { return node_count_; }
195   void add_node_count(int count) { node_count_ += count; }
196
197   int slots() const { return spec_.slots(); }
198   void increase_slots(int count) { spec_.increase_slots(count); }
199
200   int ic_slots() const { return spec_.ic_slots(); }
201   void increase_ic_slots(int count) { spec_.increase_ic_slots(count); }
202   void SetKind(int ic_slot, Code::Kind kind) { spec_.SetKind(ic_slot, kind); }
203   const ZoneFeedbackVectorSpec* get_spec() const { return &spec_; }
204
205  private:
206   Flags flags_;
207   int node_count_;
208   ZoneFeedbackVectorSpec spec_;
209 };
210
211
212 class AstNode: public ZoneObject {
213  public:
214 #define DECLARE_TYPE_ENUM(type) k##type,
215   enum NodeType {
216     AST_NODE_LIST(DECLARE_TYPE_ENUM)
217     kInvalid = -1
218   };
219 #undef DECLARE_TYPE_ENUM
220
221   void* operator new(size_t size, Zone* zone) { return zone->New(size); }
222
223   explicit AstNode(int position): position_(position) {}
224   virtual ~AstNode() {}
225
226   virtual void Accept(AstVisitor* v) = 0;
227   virtual NodeType node_type() const = 0;
228   int position() const { return position_; }
229
230   // Type testing & conversion functions overridden by concrete subclasses.
231 #define DECLARE_NODE_FUNCTIONS(type) \
232   bool Is##type() const { return node_type() == AstNode::k##type; } \
233   type* As##type() { \
234     return Is##type() ? reinterpret_cast<type*>(this) : NULL; \
235   } \
236   const type* As##type() const { \
237     return Is##type() ? reinterpret_cast<const type*>(this) : NULL; \
238   }
239   AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
240 #undef DECLARE_NODE_FUNCTIONS
241
242   virtual BreakableStatement* AsBreakableStatement() { return NULL; }
243   virtual IterationStatement* AsIterationStatement() { return NULL; }
244   virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; }
245
246   // The interface for feedback slots, with default no-op implementations for
247   // node types which don't actually have this. Note that this is conceptually
248   // not really nice, but multiple inheritance would introduce yet another
249   // vtable entry per node, something we don't want for space reasons.
250   virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
251       Isolate* isolate, const ICSlotCache* cache) {
252     return FeedbackVectorRequirements(0, 0);
253   }
254   virtual void SetFirstFeedbackSlot(FeedbackVectorSlot slot) { UNREACHABLE(); }
255   virtual void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot,
256                                       ICSlotCache* cache) {
257     UNREACHABLE();
258   }
259   // Each ICSlot stores a kind of IC which the participating node should know.
260   virtual Code::Kind FeedbackICSlotKind(int index) {
261     UNREACHABLE();
262     return Code::NUMBER_OF_KINDS;
263   }
264
265  private:
266   // Hidden to prevent accidental usage. It would have to load the
267   // current zone from the TLS.
268   void* operator new(size_t size);
269
270   friend class CaseClause;  // Generates AST IDs.
271
272   int position_;
273 };
274
275
276 class Statement : public AstNode {
277  public:
278   explicit Statement(Zone* zone, int position) : AstNode(position) {}
279
280   bool IsEmpty() { return AsEmptyStatement() != NULL; }
281   virtual bool IsJump() const { return false; }
282 };
283
284
285 class SmallMapList FINAL {
286  public:
287   SmallMapList() {}
288   SmallMapList(int capacity, Zone* zone) : list_(capacity, zone) {}
289
290   void Reserve(int capacity, Zone* zone) { list_.Reserve(capacity, zone); }
291   void Clear() { list_.Clear(); }
292   void Sort() { list_.Sort(); }
293
294   bool is_empty() const { return list_.is_empty(); }
295   int length() const { return list_.length(); }
296
297   void AddMapIfMissing(Handle<Map> map, Zone* zone) {
298     if (!Map::TryUpdate(map).ToHandle(&map)) return;
299     for (int i = 0; i < length(); ++i) {
300       if (at(i).is_identical_to(map)) return;
301     }
302     Add(map, zone);
303   }
304
305   void FilterForPossibleTransitions(Map* root_map) {
306     for (int i = list_.length() - 1; i >= 0; i--) {
307       if (at(i)->FindRootMap() != root_map) {
308         list_.RemoveElement(list_.at(i));
309       }
310     }
311   }
312
313   void Add(Handle<Map> handle, Zone* zone) {
314     list_.Add(handle.location(), zone);
315   }
316
317   Handle<Map> at(int i) const {
318     return Handle<Map>(list_.at(i));
319   }
320
321   Handle<Map> first() const { return at(0); }
322   Handle<Map> last() const { return at(length() - 1); }
323
324  private:
325   // The list stores pointers to Map*, that is Map**, so it's GC safe.
326   SmallPointerList<Map*> list_;
327
328   DISALLOW_COPY_AND_ASSIGN(SmallMapList);
329 };
330
331
332 class Expression : public AstNode {
333  public:
334   enum Context {
335     // Not assigned a context yet, or else will not be visited during
336     // code generation.
337     kUninitialized,
338     // Evaluated for its side effects.
339     kEffect,
340     // Evaluated for its value (and side effects).
341     kValue,
342     // Evaluated for control flow (and side effects).
343     kTest
344   };
345
346   virtual bool IsValidReferenceExpression() const { return false; }
347
348   // Helpers for ToBoolean conversion.
349   virtual bool ToBooleanIsTrue() const { return false; }
350   virtual bool ToBooleanIsFalse() const { return false; }
351
352   // Symbols that cannot be parsed as array indices are considered property
353   // names.  We do not treat symbols that can be array indexes as property
354   // names because [] for string objects is handled only by keyed ICs.
355   virtual bool IsPropertyName() const { return false; }
356
357   // True iff the expression is a literal represented as a smi.
358   bool IsSmiLiteral() const;
359
360   // True iff the expression is a string literal.
361   bool IsStringLiteral() const;
362
363   // True iff the expression is the null literal.
364   bool IsNullLiteral() const;
365
366   // True if we can prove that the expression is the undefined literal.
367   bool IsUndefinedLiteral(Isolate* isolate) const;
368
369   // Expression type bounds
370   Bounds bounds() const { return bounds_; }
371   void set_bounds(Bounds bounds) { bounds_ = bounds; }
372
373   // Whether the expression is parenthesized
374   bool is_parenthesized() const {
375     return IsParenthesizedField::decode(bit_field_);
376   }
377   bool is_multi_parenthesized() const {
378     return IsMultiParenthesizedField::decode(bit_field_);
379   }
380   void increase_parenthesization_level() {
381     bit_field_ =
382         IsMultiParenthesizedField::update(bit_field_, is_parenthesized());
383     bit_field_ = IsParenthesizedField::update(bit_field_, true);
384   }
385
386   // Type feedback information for assignments and properties.
387   virtual bool IsMonomorphic() {
388     UNREACHABLE();
389     return false;
390   }
391   virtual SmallMapList* GetReceiverTypes() {
392     UNREACHABLE();
393     return NULL;
394   }
395   virtual KeyedAccessStoreMode GetStoreMode() const {
396     UNREACHABLE();
397     return STANDARD_STORE;
398   }
399   virtual IcCheckType GetKeyType() const {
400     UNREACHABLE();
401     return ELEMENT;
402   }
403
404   // TODO(rossberg): this should move to its own AST node eventually.
405   virtual void RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle);
406   byte to_boolean_types() const {
407     return ToBooleanTypesField::decode(bit_field_);
408   }
409
410   void set_base_id(int id) { base_id_ = id; }
411   static int num_ids() { return parent_num_ids() + 2; }
412   BailoutId id() const { return BailoutId(local_id(0)); }
413   TypeFeedbackId test_id() const { return TypeFeedbackId(local_id(1)); }
414
415  protected:
416   Expression(Zone* zone, int pos)
417       : AstNode(pos),
418         base_id_(BailoutId::None().ToInt()),
419         bounds_(Bounds::Unbounded(zone)),
420         bit_field_(0) {}
421   static int parent_num_ids() { return 0; }
422   void set_to_boolean_types(byte types) {
423     bit_field_ = ToBooleanTypesField::update(bit_field_, types);
424   }
425
426   int base_id() const {
427     DCHECK(!BailoutId(base_id_).IsNone());
428     return base_id_;
429   }
430
431  private:
432   int local_id(int n) const { return base_id() + parent_num_ids() + n; }
433
434   int base_id_;
435   Bounds bounds_;
436   class ToBooleanTypesField : public BitField16<byte, 0, 8> {};
437   class IsParenthesizedField : public BitField16<bool, 8, 1> {};
438   class IsMultiParenthesizedField : public BitField16<bool, 9, 1> {};
439   uint16_t bit_field_;
440   // Ends with 16-bit field; deriving classes in turn begin with
441   // 16-bit fields for optimum packing efficiency.
442 };
443
444
445 class BreakableStatement : public Statement {
446  public:
447   enum BreakableType {
448     TARGET_FOR_ANONYMOUS,
449     TARGET_FOR_NAMED_ONLY
450   };
451
452   // The labels associated with this statement. May be NULL;
453   // if it is != NULL, guaranteed to contain at least one entry.
454   ZoneList<const AstRawString*>* labels() const { return labels_; }
455
456   // Type testing & conversion.
457   BreakableStatement* AsBreakableStatement() FINAL { return this; }
458
459   // Code generation
460   Label* break_target() { return &break_target_; }
461
462   // Testers.
463   bool is_target_for_anonymous() const {
464     return breakable_type_ == TARGET_FOR_ANONYMOUS;
465   }
466
467   void set_base_id(int id) { base_id_ = id; }
468   static int num_ids() { return parent_num_ids() + 2; }
469   BailoutId EntryId() const { return BailoutId(local_id(0)); }
470   BailoutId ExitId() const { return BailoutId(local_id(1)); }
471
472  protected:
473   BreakableStatement(Zone* zone, ZoneList<const AstRawString*>* labels,
474                      BreakableType breakable_type, int position)
475       : Statement(zone, position),
476         labels_(labels),
477         breakable_type_(breakable_type),
478         base_id_(BailoutId::None().ToInt()) {
479     DCHECK(labels == NULL || labels->length() > 0);
480   }
481   static int parent_num_ids() { return 0; }
482
483   int base_id() const {
484     DCHECK(!BailoutId(base_id_).IsNone());
485     return base_id_;
486   }
487
488  private:
489   int local_id(int n) const { return base_id() + parent_num_ids() + n; }
490
491   ZoneList<const AstRawString*>* labels_;
492   BreakableType breakable_type_;
493   Label break_target_;
494   int base_id_;
495 };
496
497
498 class Block FINAL : public BreakableStatement {
499  public:
500   DECLARE_NODE_TYPE(Block)
501
502   void AddStatement(Statement* statement, Zone* zone) {
503     statements_.Add(statement, zone);
504   }
505
506   ZoneList<Statement*>* statements() { return &statements_; }
507   bool is_initializer_block() const { return is_initializer_block_; }
508
509   static int num_ids() { return parent_num_ids() + 1; }
510   BailoutId DeclsId() const { return BailoutId(local_id(0)); }
511
512   bool IsJump() const OVERRIDE {
513     return !statements_.is_empty() && statements_.last()->IsJump()
514         && labels() == NULL;  // Good enough as an approximation...
515   }
516
517   Scope* scope() const { return scope_; }
518   void set_scope(Scope* scope) { scope_ = scope; }
519
520  protected:
521   Block(Zone* zone, ZoneList<const AstRawString*>* labels, int capacity,
522         bool is_initializer_block, int pos)
523       : BreakableStatement(zone, labels, TARGET_FOR_NAMED_ONLY, pos),
524         statements_(capacity, zone),
525         is_initializer_block_(is_initializer_block),
526         scope_(NULL) {}
527   static int parent_num_ids() { return BreakableStatement::num_ids(); }
528
529  private:
530   int local_id(int n) const { return base_id() + parent_num_ids() + n; }
531
532   ZoneList<Statement*> statements_;
533   bool is_initializer_block_;
534   Scope* scope_;
535 };
536
537
538 class Declaration : public AstNode {
539  public:
540   VariableProxy* proxy() const { return proxy_; }
541   VariableMode mode() const { return mode_; }
542   Scope* scope() const { return scope_; }
543   virtual InitializationFlag initialization() const = 0;
544   virtual bool IsInlineable() const;
545
546  protected:
547   Declaration(Zone* zone, VariableProxy* proxy, VariableMode mode, Scope* scope,
548               int pos)
549       : AstNode(pos), mode_(mode), proxy_(proxy), scope_(scope) {
550     DCHECK(IsDeclaredVariableMode(mode));
551   }
552
553  private:
554   VariableMode mode_;
555   VariableProxy* proxy_;
556
557   // Nested scope from which the declaration originated.
558   Scope* scope_;
559 };
560
561
562 class VariableDeclaration FINAL : public Declaration {
563  public:
564   DECLARE_NODE_TYPE(VariableDeclaration)
565
566   InitializationFlag initialization() const OVERRIDE {
567     return mode() == VAR ? kCreatedInitialized : kNeedsInitialization;
568   }
569
570  protected:
571   VariableDeclaration(Zone* zone,
572                       VariableProxy* proxy,
573                       VariableMode mode,
574                       Scope* scope,
575                       int pos)
576       : Declaration(zone, proxy, mode, scope, pos) {
577   }
578 };
579
580
581 class FunctionDeclaration FINAL : public Declaration {
582  public:
583   DECLARE_NODE_TYPE(FunctionDeclaration)
584
585   FunctionLiteral* fun() const { return fun_; }
586   InitializationFlag initialization() const OVERRIDE {
587     return kCreatedInitialized;
588   }
589   bool IsInlineable() const OVERRIDE;
590
591  protected:
592   FunctionDeclaration(Zone* zone,
593                       VariableProxy* proxy,
594                       VariableMode mode,
595                       FunctionLiteral* fun,
596                       Scope* scope,
597                       int pos)
598       : Declaration(zone, proxy, mode, scope, pos),
599         fun_(fun) {
600     DCHECK(mode == VAR || mode == LET || mode == CONST);
601     DCHECK(fun != NULL);
602   }
603
604  private:
605   FunctionLiteral* fun_;
606 };
607
608
609 class ModuleDeclaration FINAL : public Declaration {
610  public:
611   DECLARE_NODE_TYPE(ModuleDeclaration)
612
613   Module* module() const { return module_; }
614   InitializationFlag initialization() const OVERRIDE {
615     return kCreatedInitialized;
616   }
617
618  protected:
619   ModuleDeclaration(Zone* zone, VariableProxy* proxy, Module* module,
620                     Scope* scope, int pos)
621       : Declaration(zone, proxy, CONST, scope, pos), module_(module) {}
622
623  private:
624   Module* module_;
625 };
626
627
628 class ImportDeclaration FINAL : public Declaration {
629  public:
630   DECLARE_NODE_TYPE(ImportDeclaration)
631
632   const AstRawString* import_name() const { return import_name_; }
633   const AstRawString* module_specifier() const { return module_specifier_; }
634   void set_module_specifier(const AstRawString* module_specifier) {
635     DCHECK(module_specifier_ == NULL);
636     module_specifier_ = module_specifier;
637   }
638   InitializationFlag initialization() const OVERRIDE {
639     return kNeedsInitialization;
640   }
641
642  protected:
643   ImportDeclaration(Zone* zone, VariableProxy* proxy,
644                     const AstRawString* import_name,
645                     const AstRawString* module_specifier, Scope* scope, int pos)
646       : Declaration(zone, proxy, IMPORT, scope, pos),
647         import_name_(import_name),
648         module_specifier_(module_specifier) {}
649
650  private:
651   const AstRawString* import_name_;
652   const AstRawString* module_specifier_;
653 };
654
655
656 class ExportDeclaration FINAL : public Declaration {
657  public:
658   DECLARE_NODE_TYPE(ExportDeclaration)
659
660   InitializationFlag initialization() const OVERRIDE {
661     return kCreatedInitialized;
662   }
663
664  protected:
665   ExportDeclaration(Zone* zone, VariableProxy* proxy, Scope* scope, int pos)
666       : Declaration(zone, proxy, LET, scope, pos) {}
667 };
668
669
670 class Module : public AstNode {
671  public:
672   ModuleDescriptor* descriptor() const { return descriptor_; }
673   Block* body() const { return body_; }
674
675  protected:
676   Module(Zone* zone, int pos)
677       : AstNode(pos), descriptor_(ModuleDescriptor::New(zone)), body_(NULL) {}
678   Module(Zone* zone, ModuleDescriptor* descriptor, int pos, Block* body = NULL)
679       : AstNode(pos), descriptor_(descriptor), body_(body) {}
680
681  private:
682   ModuleDescriptor* descriptor_;
683   Block* body_;
684 };
685
686
687 class ModuleLiteral FINAL : public Module {
688  public:
689   DECLARE_NODE_TYPE(ModuleLiteral)
690
691  protected:
692   ModuleLiteral(Zone* zone, Block* body, ModuleDescriptor* descriptor, int pos)
693       : Module(zone, descriptor, pos, body) {}
694 };
695
696
697 class ModulePath FINAL : public Module {
698  public:
699   DECLARE_NODE_TYPE(ModulePath)
700
701   Module* module() const { return module_; }
702   Handle<String> name() const { return name_->string(); }
703
704  protected:
705   ModulePath(Zone* zone, Module* module, const AstRawString* name, int pos)
706       : Module(zone, pos), module_(module), name_(name) {}
707
708  private:
709   Module* module_;
710   const AstRawString* name_;
711 };
712
713
714 class ModuleUrl FINAL : public Module {
715  public:
716   DECLARE_NODE_TYPE(ModuleUrl)
717
718   Handle<String> url() const { return url_; }
719
720  protected:
721   ModuleUrl(Zone* zone, Handle<String> url, int pos)
722       : Module(zone, pos), url_(url) {
723   }
724
725  private:
726   Handle<String> url_;
727 };
728
729
730 class ModuleStatement FINAL : public Statement {
731  public:
732   DECLARE_NODE_TYPE(ModuleStatement)
733
734   Block* body() const { return body_; }
735
736  protected:
737   ModuleStatement(Zone* zone, Block* body, int pos)
738       : Statement(zone, pos), body_(body) {}
739
740  private:
741   Block* body_;
742 };
743
744
745 class IterationStatement : public BreakableStatement {
746  public:
747   // Type testing & conversion.
748   IterationStatement* AsIterationStatement() FINAL { return this; }
749
750   Statement* body() const { return body_; }
751
752   static int num_ids() { return parent_num_ids() + 1; }
753   BailoutId OsrEntryId() const { return BailoutId(local_id(0)); }
754   virtual BailoutId ContinueId() const = 0;
755   virtual BailoutId StackCheckId() const = 0;
756
757   // Code generation
758   Label* continue_target()  { return &continue_target_; }
759
760  protected:
761   IterationStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
762       : BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos),
763         body_(NULL) {}
764   static int parent_num_ids() { return BreakableStatement::num_ids(); }
765   void Initialize(Statement* body) { body_ = body; }
766
767  private:
768   int local_id(int n) const { return base_id() + parent_num_ids() + n; }
769
770   Statement* body_;
771   Label continue_target_;
772 };
773
774
775 class DoWhileStatement FINAL : public IterationStatement {
776  public:
777   DECLARE_NODE_TYPE(DoWhileStatement)
778
779   void Initialize(Expression* cond, Statement* body) {
780     IterationStatement::Initialize(body);
781     cond_ = cond;
782   }
783
784   Expression* cond() const { return cond_; }
785
786   static int num_ids() { return parent_num_ids() + 2; }
787   BailoutId ContinueId() const OVERRIDE { return BailoutId(local_id(0)); }
788   BailoutId StackCheckId() const OVERRIDE { return BackEdgeId(); }
789   BailoutId BackEdgeId() const { return BailoutId(local_id(1)); }
790
791  protected:
792   DoWhileStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
793       : IterationStatement(zone, labels, pos), cond_(NULL) {}
794   static int parent_num_ids() { return IterationStatement::num_ids(); }
795
796  private:
797   int local_id(int n) const { return base_id() + parent_num_ids() + n; }
798
799   Expression* cond_;
800 };
801
802
803 class WhileStatement FINAL : public IterationStatement {
804  public:
805   DECLARE_NODE_TYPE(WhileStatement)
806
807   void Initialize(Expression* cond, Statement* body) {
808     IterationStatement::Initialize(body);
809     cond_ = cond;
810   }
811
812   Expression* cond() const { return cond_; }
813
814   static int num_ids() { return parent_num_ids() + 1; }
815   BailoutId ContinueId() const OVERRIDE { return EntryId(); }
816   BailoutId StackCheckId() const OVERRIDE { return BodyId(); }
817   BailoutId BodyId() const { return BailoutId(local_id(0)); }
818
819  protected:
820   WhileStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
821       : IterationStatement(zone, labels, pos), cond_(NULL) {}
822   static int parent_num_ids() { return IterationStatement::num_ids(); }
823
824  private:
825   int local_id(int n) const { return base_id() + parent_num_ids() + n; }
826
827   Expression* cond_;
828 };
829
830
831 class ForStatement FINAL : public IterationStatement {
832  public:
833   DECLARE_NODE_TYPE(ForStatement)
834
835   void Initialize(Statement* init,
836                   Expression* cond,
837                   Statement* next,
838                   Statement* body) {
839     IterationStatement::Initialize(body);
840     init_ = init;
841     cond_ = cond;
842     next_ = next;
843   }
844
845   Statement* init() const { return init_; }
846   Expression* cond() const { return cond_; }
847   Statement* next() const { return next_; }
848
849   static int num_ids() { return parent_num_ids() + 2; }
850   BailoutId ContinueId() const OVERRIDE { return BailoutId(local_id(0)); }
851   BailoutId StackCheckId() const OVERRIDE { return BodyId(); }
852   BailoutId BodyId() const { return BailoutId(local_id(1)); }
853
854  protected:
855   ForStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
856       : IterationStatement(zone, labels, pos),
857         init_(NULL),
858         cond_(NULL),
859         next_(NULL) {}
860   static int parent_num_ids() { return IterationStatement::num_ids(); }
861
862  private:
863   int local_id(int n) const { return base_id() + parent_num_ids() + n; }
864
865   Statement* init_;
866   Expression* cond_;
867   Statement* next_;
868 };
869
870
871 class ForEachStatement : public IterationStatement {
872  public:
873   enum VisitMode {
874     ENUMERATE,   // for (each in subject) body;
875     ITERATE      // for (each of subject) body;
876   };
877
878   void Initialize(Expression* each, Expression* subject, Statement* body) {
879     IterationStatement::Initialize(body);
880     each_ = each;
881     subject_ = subject;
882   }
883
884   Expression* each() const { return each_; }
885   Expression* subject() const { return subject_; }
886
887  protected:
888   ForEachStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
889       : IterationStatement(zone, labels, pos), each_(NULL), subject_(NULL) {}
890
891  private:
892   Expression* each_;
893   Expression* subject_;
894 };
895
896
897 class ForInStatement FINAL : public ForEachStatement {
898  public:
899   DECLARE_NODE_TYPE(ForInStatement)
900
901   Expression* enumerable() const {
902     return subject();
903   }
904
905   // Type feedback information.
906   virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
907       Isolate* isolate, const ICSlotCache* cache) OVERRIDE {
908     return FeedbackVectorRequirements(1, 0);
909   }
910   void SetFirstFeedbackSlot(FeedbackVectorSlot slot) OVERRIDE {
911     for_in_feedback_slot_ = slot;
912   }
913
914   FeedbackVectorSlot ForInFeedbackSlot() {
915     DCHECK(!for_in_feedback_slot_.IsInvalid());
916     return for_in_feedback_slot_;
917   }
918
919   enum ForInType { FAST_FOR_IN, SLOW_FOR_IN };
920   ForInType for_in_type() const { return for_in_type_; }
921   void set_for_in_type(ForInType type) { for_in_type_ = type; }
922
923   static int num_ids() { return parent_num_ids() + 5; }
924   BailoutId BodyId() const { return BailoutId(local_id(0)); }
925   BailoutId PrepareId() const { return BailoutId(local_id(1)); }
926   BailoutId EnumId() const { return BailoutId(local_id(2)); }
927   BailoutId ToObjectId() const { return BailoutId(local_id(3)); }
928   BailoutId AssignmentId() const { return BailoutId(local_id(4)); }
929   BailoutId ContinueId() const OVERRIDE { return EntryId(); }
930   BailoutId StackCheckId() const OVERRIDE { return BodyId(); }
931
932  protected:
933   ForInStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
934       : ForEachStatement(zone, labels, pos),
935         for_in_type_(SLOW_FOR_IN),
936         for_in_feedback_slot_(FeedbackVectorSlot::Invalid()) {}
937   static int parent_num_ids() { return ForEachStatement::num_ids(); }
938
939  private:
940   int local_id(int n) const { return base_id() + parent_num_ids() + n; }
941
942   ForInType for_in_type_;
943   FeedbackVectorSlot for_in_feedback_slot_;
944 };
945
946
947 class ForOfStatement FINAL : public ForEachStatement {
948  public:
949   DECLARE_NODE_TYPE(ForOfStatement)
950
951   void Initialize(Expression* each,
952                   Expression* subject,
953                   Statement* body,
954                   Expression* assign_iterator,
955                   Expression* next_result,
956                   Expression* result_done,
957                   Expression* assign_each) {
958     ForEachStatement::Initialize(each, subject, body);
959     assign_iterator_ = assign_iterator;
960     next_result_ = next_result;
961     result_done_ = result_done;
962     assign_each_ = assign_each;
963   }
964
965   Expression* iterable() const {
966     return subject();
967   }
968
969   // iterator = subject[Symbol.iterator]()
970   Expression* assign_iterator() const {
971     return assign_iterator_;
972   }
973
974   // result = iterator.next()  // with type check
975   Expression* next_result() const {
976     return next_result_;
977   }
978
979   // result.done
980   Expression* result_done() const {
981     return result_done_;
982   }
983
984   // each = result.value
985   Expression* assign_each() const {
986     return assign_each_;
987   }
988
989   BailoutId ContinueId() const OVERRIDE { return EntryId(); }
990   BailoutId StackCheckId() const OVERRIDE { return BackEdgeId(); }
991
992   static int num_ids() { return parent_num_ids() + 1; }
993   BailoutId BackEdgeId() const { return BailoutId(local_id(0)); }
994
995  protected:
996   ForOfStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
997       : ForEachStatement(zone, labels, pos),
998         assign_iterator_(NULL),
999         next_result_(NULL),
1000         result_done_(NULL),
1001         assign_each_(NULL) {}
1002   static int parent_num_ids() { return ForEachStatement::num_ids(); }
1003
1004  private:
1005   int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1006
1007   Expression* assign_iterator_;
1008   Expression* next_result_;
1009   Expression* result_done_;
1010   Expression* assign_each_;
1011 };
1012
1013
1014 class ExpressionStatement FINAL : public Statement {
1015  public:
1016   DECLARE_NODE_TYPE(ExpressionStatement)
1017
1018   void set_expression(Expression* e) { expression_ = e; }
1019   Expression* expression() const { return expression_; }
1020   bool IsJump() const OVERRIDE { return expression_->IsThrow(); }
1021
1022  protected:
1023   ExpressionStatement(Zone* zone, Expression* expression, int pos)
1024       : Statement(zone, pos), expression_(expression) { }
1025
1026  private:
1027   Expression* expression_;
1028 };
1029
1030
1031 class JumpStatement : public Statement {
1032  public:
1033   bool IsJump() const FINAL { return true; }
1034
1035  protected:
1036   explicit JumpStatement(Zone* zone, int pos) : Statement(zone, pos) {}
1037 };
1038
1039
1040 class ContinueStatement FINAL : public JumpStatement {
1041  public:
1042   DECLARE_NODE_TYPE(ContinueStatement)
1043
1044   IterationStatement* target() const { return target_; }
1045
1046  protected:
1047   explicit ContinueStatement(Zone* zone, IterationStatement* target, int pos)
1048       : JumpStatement(zone, pos), target_(target) { }
1049
1050  private:
1051   IterationStatement* target_;
1052 };
1053
1054
1055 class BreakStatement FINAL : public JumpStatement {
1056  public:
1057   DECLARE_NODE_TYPE(BreakStatement)
1058
1059   BreakableStatement* target() const { return target_; }
1060
1061  protected:
1062   explicit BreakStatement(Zone* zone, BreakableStatement* target, int pos)
1063       : JumpStatement(zone, pos), target_(target) { }
1064
1065  private:
1066   BreakableStatement* target_;
1067 };
1068
1069
1070 class ReturnStatement FINAL : public JumpStatement {
1071  public:
1072   DECLARE_NODE_TYPE(ReturnStatement)
1073
1074   Expression* expression() const { return expression_; }
1075
1076  protected:
1077   explicit ReturnStatement(Zone* zone, Expression* expression, int pos)
1078       : JumpStatement(zone, pos), expression_(expression) { }
1079
1080  private:
1081   Expression* expression_;
1082 };
1083
1084
1085 class WithStatement FINAL : public Statement {
1086  public:
1087   DECLARE_NODE_TYPE(WithStatement)
1088
1089   Scope* scope() { return scope_; }
1090   Expression* expression() const { return expression_; }
1091   Statement* statement() const { return statement_; }
1092
1093   void set_base_id(int id) { base_id_ = id; }
1094   static int num_ids() { return parent_num_ids() + 1; }
1095   BailoutId EntryId() const { return BailoutId(local_id(0)); }
1096
1097  protected:
1098   WithStatement(Zone* zone, Scope* scope, Expression* expression,
1099                 Statement* statement, int pos)
1100       : Statement(zone, pos),
1101         scope_(scope),
1102         expression_(expression),
1103         statement_(statement),
1104         base_id_(BailoutId::None().ToInt()) {}
1105   static int parent_num_ids() { return 0; }
1106
1107   int base_id() const {
1108     DCHECK(!BailoutId(base_id_).IsNone());
1109     return base_id_;
1110   }
1111
1112  private:
1113   int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1114
1115   Scope* scope_;
1116   Expression* expression_;
1117   Statement* statement_;
1118   int base_id_;
1119 };
1120
1121
1122 class CaseClause FINAL : public Expression {
1123  public:
1124   DECLARE_NODE_TYPE(CaseClause)
1125
1126   bool is_default() const { return label_ == NULL; }
1127   Expression* label() const {
1128     CHECK(!is_default());
1129     return label_;
1130   }
1131   Label* body_target() { return &body_target_; }
1132   ZoneList<Statement*>* statements() const { return statements_; }
1133
1134   static int num_ids() { return parent_num_ids() + 2; }
1135   BailoutId EntryId() const { return BailoutId(local_id(0)); }
1136   TypeFeedbackId CompareId() { return TypeFeedbackId(local_id(1)); }
1137
1138   Type* compare_type() { return compare_type_; }
1139   void set_compare_type(Type* type) { compare_type_ = type; }
1140
1141  protected:
1142   static int parent_num_ids() { return Expression::num_ids(); }
1143
1144  private:
1145   CaseClause(Zone* zone, Expression* label, ZoneList<Statement*>* statements,
1146              int pos);
1147   int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1148
1149   Expression* label_;
1150   Label body_target_;
1151   ZoneList<Statement*>* statements_;
1152   Type* compare_type_;
1153 };
1154
1155
1156 class SwitchStatement FINAL : public BreakableStatement {
1157  public:
1158   DECLARE_NODE_TYPE(SwitchStatement)
1159
1160   void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) {
1161     tag_ = tag;
1162     cases_ = cases;
1163   }
1164
1165   Expression* tag() const { return tag_; }
1166   ZoneList<CaseClause*>* cases() const { return cases_; }
1167
1168  protected:
1169   SwitchStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
1170       : BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos),
1171         tag_(NULL),
1172         cases_(NULL) {}
1173
1174  private:
1175   Expression* tag_;
1176   ZoneList<CaseClause*>* cases_;
1177 };
1178
1179
1180 // If-statements always have non-null references to their then- and
1181 // else-parts. When parsing if-statements with no explicit else-part,
1182 // the parser implicitly creates an empty statement. Use the
1183 // HasThenStatement() and HasElseStatement() functions to check if a
1184 // given if-statement has a then- or an else-part containing code.
1185 class IfStatement FINAL : public Statement {
1186  public:
1187   DECLARE_NODE_TYPE(IfStatement)
1188
1189   bool HasThenStatement() const { return !then_statement()->IsEmpty(); }
1190   bool HasElseStatement() const { return !else_statement()->IsEmpty(); }
1191
1192   Expression* condition() const { return condition_; }
1193   Statement* then_statement() const { return then_statement_; }
1194   Statement* else_statement() const { return else_statement_; }
1195
1196   bool IsJump() const OVERRIDE {
1197     return HasThenStatement() && then_statement()->IsJump()
1198         && HasElseStatement() && else_statement()->IsJump();
1199   }
1200
1201   void set_base_id(int id) { base_id_ = id; }
1202   static int num_ids() { return parent_num_ids() + 3; }
1203   BailoutId IfId() const { return BailoutId(local_id(0)); }
1204   BailoutId ThenId() const { return BailoutId(local_id(1)); }
1205   BailoutId ElseId() const { return BailoutId(local_id(2)); }
1206
1207  protected:
1208   IfStatement(Zone* zone, Expression* condition, Statement* then_statement,
1209               Statement* else_statement, int pos)
1210       : Statement(zone, pos),
1211         condition_(condition),
1212         then_statement_(then_statement),
1213         else_statement_(else_statement),
1214         base_id_(BailoutId::None().ToInt()) {}
1215   static int parent_num_ids() { return 0; }
1216
1217   int base_id() const {
1218     DCHECK(!BailoutId(base_id_).IsNone());
1219     return base_id_;
1220   }
1221
1222  private:
1223   int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1224
1225   Expression* condition_;
1226   Statement* then_statement_;
1227   Statement* else_statement_;
1228   int base_id_;
1229 };
1230
1231
1232 class TryStatement : public Statement {
1233  public:
1234   int index() const { return index_; }
1235   Block* try_block() const { return try_block_; }
1236
1237  protected:
1238   TryStatement(Zone* zone, int index, Block* try_block, int pos)
1239       : Statement(zone, pos), index_(index), try_block_(try_block) {}
1240
1241  private:
1242   // Unique (per-function) index of this handler.  This is not an AST ID.
1243   int index_;
1244
1245   Block* try_block_;
1246 };
1247
1248
1249 class TryCatchStatement FINAL : public TryStatement {
1250  public:
1251   DECLARE_NODE_TYPE(TryCatchStatement)
1252
1253   Scope* scope() { return scope_; }
1254   Variable* variable() { return variable_; }
1255   Block* catch_block() const { return catch_block_; }
1256
1257  protected:
1258   TryCatchStatement(Zone* zone,
1259                     int index,
1260                     Block* try_block,
1261                     Scope* scope,
1262                     Variable* variable,
1263                     Block* catch_block,
1264                     int pos)
1265       : TryStatement(zone, index, try_block, pos),
1266         scope_(scope),
1267         variable_(variable),
1268         catch_block_(catch_block) {
1269   }
1270
1271  private:
1272   Scope* scope_;
1273   Variable* variable_;
1274   Block* catch_block_;
1275 };
1276
1277
1278 class TryFinallyStatement FINAL : public TryStatement {
1279  public:
1280   DECLARE_NODE_TYPE(TryFinallyStatement)
1281
1282   Block* finally_block() const { return finally_block_; }
1283
1284  protected:
1285   TryFinallyStatement(
1286       Zone* zone, int index, Block* try_block, Block* finally_block, int pos)
1287       : TryStatement(zone, index, try_block, pos),
1288         finally_block_(finally_block) { }
1289
1290  private:
1291   Block* finally_block_;
1292 };
1293
1294
1295 class DebuggerStatement FINAL : public Statement {
1296  public:
1297   DECLARE_NODE_TYPE(DebuggerStatement)
1298
1299   void set_base_id(int id) { base_id_ = id; }
1300   static int num_ids() { return parent_num_ids() + 1; }
1301   BailoutId DebugBreakId() const { return BailoutId(local_id(0)); }
1302
1303  protected:
1304   explicit DebuggerStatement(Zone* zone, int pos)
1305       : Statement(zone, pos), base_id_(BailoutId::None().ToInt()) {}
1306   static int parent_num_ids() { return 0; }
1307
1308   int base_id() const {
1309     DCHECK(!BailoutId(base_id_).IsNone());
1310     return base_id_;
1311   }
1312
1313  private:
1314   int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1315
1316   int base_id_;
1317 };
1318
1319
1320 class EmptyStatement FINAL : public Statement {
1321  public:
1322   DECLARE_NODE_TYPE(EmptyStatement)
1323
1324  protected:
1325   explicit EmptyStatement(Zone* zone, int pos): Statement(zone, pos) {}
1326 };
1327
1328
1329 class Literal FINAL : public Expression {
1330  public:
1331   DECLARE_NODE_TYPE(Literal)
1332
1333   bool IsPropertyName() const OVERRIDE { return value_->IsPropertyName(); }
1334
1335   Handle<String> AsPropertyName() {
1336     DCHECK(IsPropertyName());
1337     return Handle<String>::cast(value());
1338   }
1339
1340   const AstRawString* AsRawPropertyName() {
1341     DCHECK(IsPropertyName());
1342     return value_->AsString();
1343   }
1344
1345   bool ToBooleanIsTrue() const OVERRIDE { return value()->BooleanValue(); }
1346   bool ToBooleanIsFalse() const OVERRIDE { return !value()->BooleanValue(); }
1347
1348   Handle<Object> value() const { return value_->value(); }
1349   const AstValue* raw_value() const { return value_; }
1350
1351   // Support for using Literal as a HashMap key. NOTE: Currently, this works
1352   // only for string and number literals!
1353   uint32_t Hash();
1354   static bool Match(void* literal1, void* literal2);
1355
1356   static int num_ids() { return parent_num_ids() + 1; }
1357   TypeFeedbackId LiteralFeedbackId() const {
1358     return TypeFeedbackId(local_id(0));
1359   }
1360
1361  protected:
1362   Literal(Zone* zone, const AstValue* value, int position)
1363       : Expression(zone, position), value_(value) {}
1364   static int parent_num_ids() { return Expression::num_ids(); }
1365
1366  private:
1367   int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1368
1369   const AstValue* value_;
1370 };
1371
1372
1373 // Base class for literals that needs space in the corresponding JSFunction.
1374 class MaterializedLiteral : public Expression {
1375  public:
1376   virtual MaterializedLiteral* AsMaterializedLiteral() { return this; }
1377
1378   int literal_index() { return literal_index_; }
1379
1380   int depth() const {
1381     // only callable after initialization.
1382     DCHECK(depth_ >= 1);
1383     return depth_;
1384   }
1385
1386  protected:
1387   MaterializedLiteral(Zone* zone, int literal_index, int pos)
1388       : Expression(zone, pos),
1389         literal_index_(literal_index),
1390         is_simple_(false),
1391         depth_(0) {}
1392
1393   // A materialized literal is simple if the values consist of only
1394   // constants and simple object and array literals.
1395   bool is_simple() const { return is_simple_; }
1396   void set_is_simple(bool is_simple) { is_simple_ = is_simple; }
1397   friend class CompileTimeValue;
1398
1399   void set_depth(int depth) {
1400     DCHECK(depth >= 1);
1401     depth_ = depth;
1402   }
1403
1404   // Populate the constant properties/elements fixed array.
1405   void BuildConstants(Isolate* isolate);
1406   friend class ArrayLiteral;
1407   friend class ObjectLiteral;
1408
1409   // If the expression is a literal, return the literal value;
1410   // if the expression is a materialized literal and is simple return a
1411   // compile time value as encoded by CompileTimeValue::GetValue().
1412   // Otherwise, return undefined literal as the placeholder
1413   // in the object literal boilerplate.
1414   Handle<Object> GetBoilerplateValue(Expression* expression, Isolate* isolate);
1415
1416  private:
1417   int literal_index_;
1418   bool is_simple_;
1419   int depth_;
1420 };
1421
1422
1423 // Property is used for passing information
1424 // about an object literal's properties from the parser
1425 // to the code generator.
1426 class ObjectLiteralProperty FINAL : public ZoneObject {
1427  public:
1428   enum Kind {
1429     CONSTANT,              // Property with constant value (compile time).
1430     COMPUTED,              // Property with computed value (execution time).
1431     MATERIALIZED_LITERAL,  // Property value is a materialized literal.
1432     GETTER, SETTER,        // Property is an accessor function.
1433     PROTOTYPE              // Property is __proto__.
1434   };
1435
1436   Expression* key() { return key_; }
1437   Expression* value() { return value_; }
1438   Kind kind() { return kind_; }
1439
1440   // Type feedback information.
1441   bool IsMonomorphic() { return !receiver_type_.is_null(); }
1442   Handle<Map> GetReceiverType() { return receiver_type_; }
1443
1444   bool IsCompileTimeValue();
1445
1446   void set_emit_store(bool emit_store);
1447   bool emit_store();
1448
1449   bool is_static() const { return is_static_; }
1450   bool is_computed_name() const { return is_computed_name_; }
1451
1452   void set_receiver_type(Handle<Map> map) { receiver_type_ = map; }
1453
1454  protected:
1455   friend class AstNodeFactory;
1456
1457   ObjectLiteralProperty(Expression* key, Expression* value, Kind kind,
1458                         bool is_static, bool is_computed_name);
1459   ObjectLiteralProperty(AstValueFactory* ast_value_factory, Expression* key,
1460                         Expression* value, bool is_static,
1461                         bool is_computed_name);
1462
1463  private:
1464   Expression* key_;
1465   Expression* value_;
1466   Kind kind_;
1467   bool emit_store_;
1468   bool is_static_;
1469   bool is_computed_name_;
1470   Handle<Map> receiver_type_;
1471 };
1472
1473
1474 // An object literal has a boilerplate object that is used
1475 // for minimizing the work when constructing it at runtime.
1476 class ObjectLiteral FINAL : public MaterializedLiteral {
1477  public:
1478   typedef ObjectLiteralProperty Property;
1479
1480   DECLARE_NODE_TYPE(ObjectLiteral)
1481
1482   Handle<FixedArray> constant_properties() const {
1483     return constant_properties_;
1484   }
1485   int properties_count() const { return constant_properties_->length() / 2; }
1486   ZoneList<Property*>* properties() const { return properties_; }
1487   bool fast_elements() const { return fast_elements_; }
1488   bool may_store_doubles() const { return may_store_doubles_; }
1489   bool has_function() const { return has_function_; }
1490   bool has_elements() const { return has_elements_; }
1491
1492   // Decide if a property should be in the object boilerplate.
1493   static bool IsBoilerplateProperty(Property* property);
1494
1495   // Populate the constant properties fixed array.
1496   void BuildConstantProperties(Isolate* isolate);
1497
1498   // Mark all computed expressions that are bound to a key that
1499   // is shadowed by a later occurrence of the same key. For the
1500   // marked expressions, no store code is emitted.
1501   void CalculateEmitStore(Zone* zone);
1502
1503   // Assemble bitfield of flags for the CreateObjectLiteral helper.
1504   int ComputeFlags(bool disable_mementos = false) const {
1505     int flags = fast_elements() ? kFastElements : kNoFlags;
1506     flags |= has_function() ? kHasFunction : kNoFlags;
1507     if (disable_mementos) {
1508       flags |= kDisableMementos;
1509     }
1510     return flags;
1511   }
1512
1513   enum Flags {
1514     kNoFlags = 0,
1515     kFastElements = 1,
1516     kHasFunction = 1 << 1,
1517     kDisableMementos = 1 << 2
1518   };
1519
1520   struct Accessors: public ZoneObject {
1521     Accessors() : getter(NULL), setter(NULL) {}
1522     Expression* getter;
1523     Expression* setter;
1524   };
1525
1526   BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); }
1527
1528   // Return an AST id for a property that is used in simulate instructions.
1529   BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 1)); }
1530
1531   // Unlike other AST nodes, this number of bailout IDs allocated for an
1532   // ObjectLiteral can vary, so num_ids() is not a static method.
1533   int num_ids() const { return parent_num_ids() + 1 + properties()->length(); }
1534
1535  protected:
1536   ObjectLiteral(Zone* zone, ZoneList<Property*>* properties, int literal_index,
1537                 int boilerplate_properties, bool has_function, int pos)
1538       : MaterializedLiteral(zone, literal_index, pos),
1539         properties_(properties),
1540         boilerplate_properties_(boilerplate_properties),
1541         fast_elements_(false),
1542         has_elements_(false),
1543         may_store_doubles_(false),
1544         has_function_(has_function) {}
1545   static int parent_num_ids() { return MaterializedLiteral::num_ids(); }
1546
1547  private:
1548   int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1549   Handle<FixedArray> constant_properties_;
1550   ZoneList<Property*>* properties_;
1551   int boilerplate_properties_;
1552   bool fast_elements_;
1553   bool has_elements_;
1554   bool may_store_doubles_;
1555   bool has_function_;
1556 };
1557
1558
1559 // Node for capturing a regexp literal.
1560 class RegExpLiteral FINAL : public MaterializedLiteral {
1561  public:
1562   DECLARE_NODE_TYPE(RegExpLiteral)
1563
1564   Handle<String> pattern() const { return pattern_->string(); }
1565   Handle<String> flags() const { return flags_->string(); }
1566
1567  protected:
1568   RegExpLiteral(Zone* zone, const AstRawString* pattern,
1569                 const AstRawString* flags, int literal_index, int pos)
1570       : MaterializedLiteral(zone, literal_index, pos),
1571         pattern_(pattern),
1572         flags_(flags) {
1573     set_depth(1);
1574   }
1575
1576  private:
1577   const AstRawString* pattern_;
1578   const AstRawString* flags_;
1579 };
1580
1581
1582 // An array literal has a literals object that is used
1583 // for minimizing the work when constructing it at runtime.
1584 class ArrayLiteral FINAL : public MaterializedLiteral {
1585  public:
1586   DECLARE_NODE_TYPE(ArrayLiteral)
1587
1588   Handle<FixedArray> constant_elements() const { return constant_elements_; }
1589   ElementsKind constant_elements_kind() const {
1590     DCHECK_EQ(2, constant_elements_->length());
1591     return static_cast<ElementsKind>(
1592         Smi::cast(constant_elements_->get(0))->value());
1593   }
1594
1595   ZoneList<Expression*>* values() const { return values_; }
1596
1597   BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); }
1598
1599   // Return an AST id for an element that is used in simulate instructions.
1600   BailoutId GetIdForElement(int i) { return BailoutId(local_id(i + 1)); }
1601
1602   // Unlike other AST nodes, this number of bailout IDs allocated for an
1603   // ArrayLiteral can vary, so num_ids() is not a static method.
1604   int num_ids() const { return parent_num_ids() + 1 + values()->length(); }
1605
1606   // Populate the constant elements fixed array.
1607   void BuildConstantElements(Isolate* isolate);
1608
1609   // Assemble bitfield of flags for the CreateArrayLiteral helper.
1610   int ComputeFlags(bool disable_mementos = false) const {
1611     int flags = depth() == 1 ? kShallowElements : kNoFlags;
1612     if (disable_mementos) {
1613       flags |= kDisableMementos;
1614     }
1615     return flags;
1616   }
1617
1618   enum Flags {
1619     kNoFlags = 0,
1620     kShallowElements = 1,
1621     kDisableMementos = 1 << 1
1622   };
1623
1624  protected:
1625   ArrayLiteral(Zone* zone, ZoneList<Expression*>* values, int literal_index,
1626                int pos)
1627       : MaterializedLiteral(zone, literal_index, pos), values_(values) {}
1628   static int parent_num_ids() { return MaterializedLiteral::num_ids(); }
1629
1630  private:
1631   int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1632
1633   Handle<FixedArray> constant_elements_;
1634   ZoneList<Expression*>* values_;
1635 };
1636
1637
1638 class VariableProxy FINAL : public Expression {
1639  public:
1640   DECLARE_NODE_TYPE(VariableProxy)
1641
1642   bool IsValidReferenceExpression() const OVERRIDE { return !is_this(); }
1643
1644   bool IsArguments() const { return is_resolved() && var()->is_arguments(); }
1645
1646   Handle<String> name() const { return raw_name()->string(); }
1647   const AstRawString* raw_name() const {
1648     return is_resolved() ? var_->raw_name() : raw_name_;
1649   }
1650
1651   Variable* var() const {
1652     DCHECK(is_resolved());
1653     return var_;
1654   }
1655   void set_var(Variable* v) {
1656     DCHECK(!is_resolved());
1657     DCHECK_NOT_NULL(v);
1658     var_ = v;
1659   }
1660
1661   bool is_this() const { return IsThisField::decode(bit_field_); }
1662
1663   bool is_assigned() const { return IsAssignedField::decode(bit_field_); }
1664   void set_is_assigned() {
1665     bit_field_ = IsAssignedField::update(bit_field_, true);
1666   }
1667
1668   bool is_resolved() const { return IsResolvedField::decode(bit_field_); }
1669   void set_is_resolved() {
1670     bit_field_ = IsResolvedField::update(bit_field_, true);
1671   }
1672
1673   int end_position() const { return end_position_; }
1674
1675   // Bind this proxy to the variable var.
1676   void BindTo(Variable* var);
1677
1678   bool UsesVariableFeedbackSlot() const {
1679     return FLAG_vector_ics && (var()->IsUnallocated() || var()->IsLookupSlot());
1680   }
1681
1682   virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
1683       Isolate* isolate, const ICSlotCache* cache) OVERRIDE;
1684
1685   void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot,
1686                               ICSlotCache* cache) OVERRIDE;
1687   Code::Kind FeedbackICSlotKind(int index) OVERRIDE { return Code::LOAD_IC; }
1688   FeedbackVectorICSlot VariableFeedbackSlot() {
1689     DCHECK(!UsesVariableFeedbackSlot() || !variable_feedback_slot_.IsInvalid());
1690     return variable_feedback_slot_;
1691   }
1692
1693  protected:
1694   VariableProxy(Zone* zone, Variable* var, int start_position,
1695                 int end_position);
1696
1697   VariableProxy(Zone* zone, const AstRawString* name,
1698                 Variable::Kind variable_kind, int start_position,
1699                 int end_position);
1700
1701   class IsThisField : public BitField8<bool, 0, 1> {};
1702   class IsAssignedField : public BitField8<bool, 1, 1> {};
1703   class IsResolvedField : public BitField8<bool, 2, 1> {};
1704
1705   // Start with 16-bit (or smaller) field, which should get packed together
1706   // with Expression's trailing 16-bit field.
1707   uint8_t bit_field_;
1708   FeedbackVectorICSlot variable_feedback_slot_;
1709   union {
1710     const AstRawString* raw_name_;  // if !is_resolved_
1711     Variable* var_;                 // if is_resolved_
1712   };
1713   // Position is stored in the AstNode superclass, but VariableProxy needs to
1714   // know its end position too (for error messages). It cannot be inferred from
1715   // the variable name length because it can contain escapes.
1716   int end_position_;
1717 };
1718
1719
1720 class Property FINAL : public Expression {
1721  public:
1722   DECLARE_NODE_TYPE(Property)
1723
1724   bool IsValidReferenceExpression() const OVERRIDE { return true; }
1725
1726   Expression* obj() const { return obj_; }
1727   Expression* key() const { return key_; }
1728
1729   static int num_ids() { return parent_num_ids() + 2; }
1730   BailoutId LoadId() const { return BailoutId(local_id(0)); }
1731   TypeFeedbackId PropertyFeedbackId() { return TypeFeedbackId(local_id(1)); }
1732
1733   bool IsStringAccess() const {
1734     return IsStringAccessField::decode(bit_field_);
1735   }
1736
1737   // Type feedback information.
1738   bool IsMonomorphic() OVERRIDE { return receiver_types_.length() == 1; }
1739   SmallMapList* GetReceiverTypes() OVERRIDE { return &receiver_types_; }
1740   KeyedAccessStoreMode GetStoreMode() const OVERRIDE { return STANDARD_STORE; }
1741   IcCheckType GetKeyType() const OVERRIDE {
1742     return KeyTypeField::decode(bit_field_);
1743   }
1744   bool IsUninitialized() const {
1745     return !is_for_call() && HasNoTypeInformation();
1746   }
1747   bool HasNoTypeInformation() const {
1748     return IsUninitializedField::decode(bit_field_);
1749   }
1750   void set_is_uninitialized(bool b) {
1751     bit_field_ = IsUninitializedField::update(bit_field_, b);
1752   }
1753   void set_is_string_access(bool b) {
1754     bit_field_ = IsStringAccessField::update(bit_field_, b);
1755   }
1756   void set_key_type(IcCheckType key_type) {
1757     bit_field_ = KeyTypeField::update(bit_field_, key_type);
1758   }
1759   void mark_for_call() {
1760     bit_field_ = IsForCallField::update(bit_field_, true);
1761   }
1762   bool is_for_call() const { return IsForCallField::decode(bit_field_); }
1763
1764   bool IsSuperAccess() {
1765     return obj()->IsSuperReference();
1766   }
1767
1768   virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
1769       Isolate* isolate, const ICSlotCache* cache) OVERRIDE {
1770     return FeedbackVectorRequirements(0, FLAG_vector_ics ? 1 : 0);
1771   }
1772   void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot,
1773                               ICSlotCache* cache) OVERRIDE {
1774     property_feedback_slot_ = slot;
1775   }
1776   Code::Kind FeedbackICSlotKind(int index) OVERRIDE {
1777     return key()->IsPropertyName() ? Code::LOAD_IC : Code::KEYED_LOAD_IC;
1778   }
1779
1780   FeedbackVectorICSlot PropertyFeedbackSlot() const {
1781     DCHECK(!FLAG_vector_ics || !property_feedback_slot_.IsInvalid());
1782     return property_feedback_slot_;
1783   }
1784
1785  protected:
1786   Property(Zone* zone, Expression* obj, Expression* key, int pos)
1787       : Expression(zone, pos),
1788         bit_field_(IsForCallField::encode(false) |
1789                    IsUninitializedField::encode(false) |
1790                    IsStringAccessField::encode(false)),
1791         property_feedback_slot_(FeedbackVectorICSlot::Invalid()),
1792         obj_(obj),
1793         key_(key) {}
1794   static int parent_num_ids() { return Expression::num_ids(); }
1795
1796  private:
1797   int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1798
1799   class IsForCallField : public BitField8<bool, 0, 1> {};
1800   class IsUninitializedField : public BitField8<bool, 1, 1> {};
1801   class IsStringAccessField : public BitField8<bool, 2, 1> {};
1802   class KeyTypeField : public BitField8<IcCheckType, 3, 1> {};
1803   uint8_t bit_field_;
1804   FeedbackVectorICSlot property_feedback_slot_;
1805   Expression* obj_;
1806   Expression* key_;
1807   SmallMapList receiver_types_;
1808 };
1809
1810
1811 class Call FINAL : public Expression {
1812  public:
1813   DECLARE_NODE_TYPE(Call)
1814
1815   Expression* expression() const { return expression_; }
1816   ZoneList<Expression*>* arguments() const { return arguments_; }
1817
1818   // Type feedback information.
1819   virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
1820       Isolate* isolate, const ICSlotCache* cache) OVERRIDE;
1821   void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot,
1822                               ICSlotCache* cache) OVERRIDE {
1823     ic_slot_or_slot_ = slot.ToInt();
1824   }
1825   void SetFirstFeedbackSlot(FeedbackVectorSlot slot) OVERRIDE {
1826     ic_slot_or_slot_ = slot.ToInt();
1827   }
1828   Code::Kind FeedbackICSlotKind(int index) OVERRIDE { return Code::CALL_IC; }
1829
1830   FeedbackVectorSlot CallFeedbackSlot() const {
1831     DCHECK(ic_slot_or_slot_ != FeedbackVectorSlot::Invalid().ToInt());
1832     return FeedbackVectorSlot(ic_slot_or_slot_);
1833   }
1834
1835   FeedbackVectorICSlot CallFeedbackICSlot() const {
1836     DCHECK(ic_slot_or_slot_ != FeedbackVectorICSlot::Invalid().ToInt());
1837     return FeedbackVectorICSlot(ic_slot_or_slot_);
1838   }
1839
1840   SmallMapList* GetReceiverTypes() OVERRIDE {
1841     if (expression()->IsProperty()) {
1842       return expression()->AsProperty()->GetReceiverTypes();
1843     }
1844     return NULL;
1845   }
1846
1847   bool IsMonomorphic() OVERRIDE {
1848     if (expression()->IsProperty()) {
1849       return expression()->AsProperty()->IsMonomorphic();
1850     }
1851     return !target_.is_null();
1852   }
1853
1854   bool global_call() const {
1855     VariableProxy* proxy = expression_->AsVariableProxy();
1856     return proxy != NULL && proxy->var()->IsUnallocated();
1857   }
1858
1859   bool known_global_function() const {
1860     return global_call() && !target_.is_null();
1861   }
1862
1863   Handle<JSFunction> target() { return target_; }
1864
1865   Handle<AllocationSite> allocation_site() { return allocation_site_; }
1866
1867   void SetKnownGlobalTarget(Handle<JSFunction> target) {
1868     target_ = target;
1869     set_is_uninitialized(false);
1870   }
1871   void set_target(Handle<JSFunction> target) { target_ = target; }
1872   void set_allocation_site(Handle<AllocationSite> site) {
1873     allocation_site_ = site;
1874   }
1875
1876   static int num_ids() { return parent_num_ids() + 2; }
1877   BailoutId ReturnId() const { return BailoutId(local_id(0)); }
1878   BailoutId EvalOrLookupId() const { return BailoutId(local_id(1)); }
1879
1880   bool is_uninitialized() const {
1881     return IsUninitializedField::decode(bit_field_);
1882   }
1883   void set_is_uninitialized(bool b) {
1884     bit_field_ = IsUninitializedField::update(bit_field_, b);
1885   }
1886
1887   enum CallType {
1888     POSSIBLY_EVAL_CALL,
1889     GLOBAL_CALL,
1890     LOOKUP_SLOT_CALL,
1891     PROPERTY_CALL,
1892     SUPER_CALL,
1893     OTHER_CALL
1894   };
1895
1896   // Helpers to determine how to handle the call.
1897   CallType GetCallType(Isolate* isolate) const;
1898   bool IsUsingCallFeedbackSlot(Isolate* isolate) const;
1899   bool IsUsingCallFeedbackICSlot(Isolate* isolate) const;
1900
1901 #ifdef DEBUG
1902   // Used to assert that the FullCodeGenerator records the return site.
1903   bool return_is_recorded_;
1904 #endif
1905
1906  protected:
1907   Call(Zone* zone, Expression* expression, ZoneList<Expression*>* arguments,
1908        int pos)
1909       : Expression(zone, pos),
1910         ic_slot_or_slot_(FeedbackVectorICSlot::Invalid().ToInt()),
1911         expression_(expression),
1912         arguments_(arguments),
1913         bit_field_(IsUninitializedField::encode(false)) {
1914     if (expression->IsProperty()) {
1915       expression->AsProperty()->mark_for_call();
1916     }
1917   }
1918   static int parent_num_ids() { return Expression::num_ids(); }
1919
1920  private:
1921   int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1922
1923   // We store this as an integer because we don't know if we have a slot or
1924   // an ic slot until scoping time.
1925   int ic_slot_or_slot_;
1926   Expression* expression_;
1927   ZoneList<Expression*>* arguments_;
1928   Handle<JSFunction> target_;
1929   Handle<AllocationSite> allocation_site_;
1930   class IsUninitializedField : public BitField8<bool, 0, 1> {};
1931   uint8_t bit_field_;
1932 };
1933
1934
1935 class CallNew FINAL : public Expression {
1936  public:
1937   DECLARE_NODE_TYPE(CallNew)
1938
1939   Expression* expression() const { return expression_; }
1940   ZoneList<Expression*>* arguments() const { return arguments_; }
1941
1942   // Type feedback information.
1943   virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
1944       Isolate* isolate, const ICSlotCache* cache) OVERRIDE {
1945     return FeedbackVectorRequirements(FLAG_pretenuring_call_new ? 2 : 1, 0);
1946   }
1947   void SetFirstFeedbackSlot(FeedbackVectorSlot slot) OVERRIDE {
1948     callnew_feedback_slot_ = slot;
1949   }
1950
1951   FeedbackVectorSlot CallNewFeedbackSlot() {
1952     DCHECK(!callnew_feedback_slot_.IsInvalid());
1953     return callnew_feedback_slot_;
1954   }
1955   FeedbackVectorSlot AllocationSiteFeedbackSlot() {
1956     DCHECK(FLAG_pretenuring_call_new);
1957     return CallNewFeedbackSlot().next();
1958   }
1959
1960   bool IsMonomorphic() OVERRIDE { return is_monomorphic_; }
1961   Handle<JSFunction> target() const { return target_; }
1962   Handle<AllocationSite> allocation_site() const {
1963     return allocation_site_;
1964   }
1965
1966   static int num_ids() { return parent_num_ids() + 1; }
1967   static int feedback_slots() { return 1; }
1968   BailoutId ReturnId() const { return BailoutId(local_id(0)); }
1969
1970   void set_allocation_site(Handle<AllocationSite> site) {
1971     allocation_site_ = site;
1972   }
1973   void set_is_monomorphic(bool monomorphic) { is_monomorphic_ = monomorphic; }
1974   void set_target(Handle<JSFunction> target) { target_ = target; }
1975   void SetKnownGlobalTarget(Handle<JSFunction> target) {
1976     target_ = target;
1977     is_monomorphic_ = true;
1978   }
1979
1980  protected:
1981   CallNew(Zone* zone, Expression* expression, ZoneList<Expression*>* arguments,
1982           int pos)
1983       : Expression(zone, pos),
1984         expression_(expression),
1985         arguments_(arguments),
1986         is_monomorphic_(false),
1987         callnew_feedback_slot_(FeedbackVectorSlot::Invalid()) {}
1988
1989   static int parent_num_ids() { return Expression::num_ids(); }
1990
1991  private:
1992   int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1993
1994   Expression* expression_;
1995   ZoneList<Expression*>* arguments_;
1996   bool is_monomorphic_;
1997   Handle<JSFunction> target_;
1998   Handle<AllocationSite> allocation_site_;
1999   FeedbackVectorSlot callnew_feedback_slot_;
2000 };
2001
2002
2003 // The CallRuntime class does not represent any official JavaScript
2004 // language construct. Instead it is used to call a C or JS function
2005 // with a set of arguments. This is used from the builtins that are
2006 // implemented in JavaScript (see "v8natives.js").
2007 class CallRuntime FINAL : public Expression {
2008  public:
2009   DECLARE_NODE_TYPE(CallRuntime)
2010
2011   Handle<String> name() const { return raw_name_->string(); }
2012   const AstRawString* raw_name() const { return raw_name_; }
2013   const Runtime::Function* function() const { return function_; }
2014   ZoneList<Expression*>* arguments() const { return arguments_; }
2015   bool is_jsruntime() const { return function_ == NULL; }
2016
2017   // Type feedback information.
2018   bool HasCallRuntimeFeedbackSlot() const {
2019     return FLAG_vector_ics && is_jsruntime();
2020   }
2021   virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
2022       Isolate* isolate, const ICSlotCache* cache) OVERRIDE {
2023     return FeedbackVectorRequirements(0, HasCallRuntimeFeedbackSlot() ? 1 : 0);
2024   }
2025   void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot,
2026                               ICSlotCache* cache) OVERRIDE {
2027     callruntime_feedback_slot_ = slot;
2028   }
2029   Code::Kind FeedbackICSlotKind(int index) OVERRIDE { return Code::LOAD_IC; }
2030
2031   FeedbackVectorICSlot CallRuntimeFeedbackSlot() {
2032     DCHECK(!HasCallRuntimeFeedbackSlot() ||
2033            !callruntime_feedback_slot_.IsInvalid());
2034     return callruntime_feedback_slot_;
2035   }
2036
2037   static int num_ids() { return parent_num_ids() + 1; }
2038   TypeFeedbackId CallRuntimeFeedbackId() const {
2039     return TypeFeedbackId(local_id(0));
2040   }
2041
2042  protected:
2043   CallRuntime(Zone* zone, const AstRawString* name,
2044               const Runtime::Function* function,
2045               ZoneList<Expression*>* arguments, int pos)
2046       : Expression(zone, pos),
2047         raw_name_(name),
2048         function_(function),
2049         arguments_(arguments),
2050         callruntime_feedback_slot_(FeedbackVectorICSlot::Invalid()) {}
2051   static int parent_num_ids() { return Expression::num_ids(); }
2052
2053  private:
2054   int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2055
2056   const AstRawString* raw_name_;
2057   const Runtime::Function* function_;
2058   ZoneList<Expression*>* arguments_;
2059   FeedbackVectorICSlot callruntime_feedback_slot_;
2060 };
2061
2062
2063 class UnaryOperation FINAL : public Expression {
2064  public:
2065   DECLARE_NODE_TYPE(UnaryOperation)
2066
2067   Token::Value op() const { return op_; }
2068   Expression* expression() const { return expression_; }
2069
2070   // For unary not (Token::NOT), the AST ids where true and false will
2071   // actually be materialized, respectively.
2072   static int num_ids() { return parent_num_ids() + 2; }
2073   BailoutId MaterializeTrueId() const { return BailoutId(local_id(0)); }
2074   BailoutId MaterializeFalseId() const { return BailoutId(local_id(1)); }
2075
2076   virtual void RecordToBooleanTypeFeedback(
2077       TypeFeedbackOracle* oracle) OVERRIDE;
2078
2079  protected:
2080   UnaryOperation(Zone* zone, Token::Value op, Expression* expression, int pos)
2081       : Expression(zone, pos), op_(op), expression_(expression) {
2082     DCHECK(Token::IsUnaryOp(op));
2083   }
2084   static int parent_num_ids() { return Expression::num_ids(); }
2085
2086  private:
2087   int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2088
2089   Token::Value op_;
2090   Expression* expression_;
2091 };
2092
2093
2094 class BinaryOperation FINAL : public Expression {
2095  public:
2096   DECLARE_NODE_TYPE(BinaryOperation)
2097
2098   Token::Value op() const { return static_cast<Token::Value>(op_); }
2099   Expression* left() const { return left_; }
2100   Expression* right() const { return right_; }
2101   Handle<AllocationSite> allocation_site() const { return allocation_site_; }
2102   void set_allocation_site(Handle<AllocationSite> allocation_site) {
2103     allocation_site_ = allocation_site;
2104   }
2105
2106   // The short-circuit logical operations need an AST ID for their
2107   // right-hand subexpression.
2108   static int num_ids() { return parent_num_ids() + 2; }
2109   BailoutId RightId() const { return BailoutId(local_id(0)); }
2110
2111   TypeFeedbackId BinaryOperationFeedbackId() const {
2112     return TypeFeedbackId(local_id(1));
2113   }
2114   Maybe<int> fixed_right_arg() const {
2115     return has_fixed_right_arg_ ? Just(fixed_right_arg_value_) : Nothing<int>();
2116   }
2117   void set_fixed_right_arg(Maybe<int> arg) {
2118     has_fixed_right_arg_ = arg.IsJust();
2119     if (arg.IsJust()) fixed_right_arg_value_ = arg.FromJust();
2120   }
2121
2122   virtual void RecordToBooleanTypeFeedback(
2123       TypeFeedbackOracle* oracle) OVERRIDE;
2124
2125  protected:
2126   BinaryOperation(Zone* zone, Token::Value op, Expression* left,
2127                   Expression* right, int pos)
2128       : Expression(zone, pos),
2129         op_(static_cast<byte>(op)),
2130         has_fixed_right_arg_(false),
2131         fixed_right_arg_value_(0),
2132         left_(left),
2133         right_(right) {
2134     DCHECK(Token::IsBinaryOp(op));
2135   }
2136   static int parent_num_ids() { return Expression::num_ids(); }
2137
2138  private:
2139   int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2140
2141   const byte op_;  // actually Token::Value
2142   // TODO(rossberg): the fixed arg should probably be represented as a Constant
2143   // type for the RHS. Currenty it's actually a Maybe<int>
2144   bool has_fixed_right_arg_;
2145   int fixed_right_arg_value_;
2146   Expression* left_;
2147   Expression* right_;
2148   Handle<AllocationSite> allocation_site_;
2149 };
2150
2151
2152 class CountOperation FINAL : public Expression {
2153  public:
2154   DECLARE_NODE_TYPE(CountOperation)
2155
2156   bool is_prefix() const { return IsPrefixField::decode(bit_field_); }
2157   bool is_postfix() const { return !is_prefix(); }
2158
2159   Token::Value op() const { return TokenField::decode(bit_field_); }
2160   Token::Value binary_op() {
2161     return (op() == Token::INC) ? Token::ADD : Token::SUB;
2162   }
2163
2164   Expression* expression() const { return expression_; }
2165
2166   bool IsMonomorphic() OVERRIDE { return receiver_types_.length() == 1; }
2167   SmallMapList* GetReceiverTypes() OVERRIDE { return &receiver_types_; }
2168   IcCheckType GetKeyType() const OVERRIDE {
2169     return KeyTypeField::decode(bit_field_);
2170   }
2171   KeyedAccessStoreMode GetStoreMode() const OVERRIDE {
2172     return StoreModeField::decode(bit_field_);
2173   }
2174   Type* type() const { return type_; }
2175   void set_key_type(IcCheckType type) {
2176     bit_field_ = KeyTypeField::update(bit_field_, type);
2177   }
2178   void set_store_mode(KeyedAccessStoreMode mode) {
2179     bit_field_ = StoreModeField::update(bit_field_, mode);
2180   }
2181   void set_type(Type* type) { type_ = type; }
2182
2183   static int num_ids() { return parent_num_ids() + 4; }
2184   BailoutId AssignmentId() const { return BailoutId(local_id(0)); }
2185   BailoutId ToNumberId() const { return BailoutId(local_id(1)); }
2186   TypeFeedbackId CountBinOpFeedbackId() const {
2187     return TypeFeedbackId(local_id(2));
2188   }
2189   TypeFeedbackId CountStoreFeedbackId() const {
2190     return TypeFeedbackId(local_id(3));
2191   }
2192
2193  protected:
2194   CountOperation(Zone* zone, Token::Value op, bool is_prefix, Expression* expr,
2195                  int pos)
2196       : Expression(zone, pos),
2197         bit_field_(IsPrefixField::encode(is_prefix) |
2198                    KeyTypeField::encode(ELEMENT) |
2199                    StoreModeField::encode(STANDARD_STORE) |
2200                    TokenField::encode(op)),
2201         type_(NULL),
2202         expression_(expr) {}
2203   static int parent_num_ids() { return Expression::num_ids(); }
2204
2205  private:
2206   int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2207
2208   class IsPrefixField : public BitField16<bool, 0, 1> {};
2209   class KeyTypeField : public BitField16<IcCheckType, 1, 1> {};
2210   class StoreModeField : public BitField16<KeyedAccessStoreMode, 2, 4> {};
2211   class TokenField : public BitField16<Token::Value, 6, 8> {};
2212
2213   // Starts with 16-bit field, which should get packed together with
2214   // Expression's trailing 16-bit field.
2215   uint16_t bit_field_;
2216   Type* type_;
2217   Expression* expression_;
2218   SmallMapList receiver_types_;
2219 };
2220
2221
2222 class CompareOperation FINAL : public Expression {
2223  public:
2224   DECLARE_NODE_TYPE(CompareOperation)
2225
2226   Token::Value op() const { return op_; }
2227   Expression* left() const { return left_; }
2228   Expression* right() const { return right_; }
2229
2230   // Type feedback information.
2231   static int num_ids() { return parent_num_ids() + 1; }
2232   TypeFeedbackId CompareOperationFeedbackId() const {
2233     return TypeFeedbackId(local_id(0));
2234   }
2235   Type* combined_type() const { return combined_type_; }
2236   void set_combined_type(Type* type) { combined_type_ = type; }
2237
2238   // Match special cases.
2239   bool IsLiteralCompareTypeof(Expression** expr, Handle<String>* check);
2240   bool IsLiteralCompareUndefined(Expression** expr, Isolate* isolate);
2241   bool IsLiteralCompareNull(Expression** expr);
2242
2243  protected:
2244   CompareOperation(Zone* zone, Token::Value op, Expression* left,
2245                    Expression* right, int pos)
2246       : Expression(zone, pos),
2247         op_(op),
2248         left_(left),
2249         right_(right),
2250         combined_type_(Type::None(zone)) {
2251     DCHECK(Token::IsCompareOp(op));
2252   }
2253   static int parent_num_ids() { return Expression::num_ids(); }
2254
2255  private:
2256   int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2257
2258   Token::Value op_;
2259   Expression* left_;
2260   Expression* right_;
2261
2262   Type* combined_type_;
2263 };
2264
2265
2266 class Conditional FINAL : public Expression {
2267  public:
2268   DECLARE_NODE_TYPE(Conditional)
2269
2270   Expression* condition() const { return condition_; }
2271   Expression* then_expression() const { return then_expression_; }
2272   Expression* else_expression() const { return else_expression_; }
2273
2274   static int num_ids() { return parent_num_ids() + 2; }
2275   BailoutId ThenId() const { return BailoutId(local_id(0)); }
2276   BailoutId ElseId() const { return BailoutId(local_id(1)); }
2277
2278  protected:
2279   Conditional(Zone* zone, Expression* condition, Expression* then_expression,
2280               Expression* else_expression, int position)
2281       : Expression(zone, position),
2282         condition_(condition),
2283         then_expression_(then_expression),
2284         else_expression_(else_expression) {}
2285   static int parent_num_ids() { return Expression::num_ids(); }
2286
2287  private:
2288   int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2289
2290   Expression* condition_;
2291   Expression* then_expression_;
2292   Expression* else_expression_;
2293 };
2294
2295
2296 class Assignment FINAL : public Expression {
2297  public:
2298   DECLARE_NODE_TYPE(Assignment)
2299
2300   Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; }
2301
2302   Token::Value binary_op() const;
2303
2304   Token::Value op() const { return TokenField::decode(bit_field_); }
2305   Expression* target() const { return target_; }
2306   Expression* value() const { return value_; }
2307   BinaryOperation* binary_operation() const { return binary_operation_; }
2308
2309   // This check relies on the definition order of token in token.h.
2310   bool is_compound() const { return op() > Token::ASSIGN; }
2311
2312   static int num_ids() { return parent_num_ids() + 2; }
2313   BailoutId AssignmentId() const { return BailoutId(local_id(0)); }
2314
2315   // Type feedback information.
2316   TypeFeedbackId AssignmentFeedbackId() { return TypeFeedbackId(local_id(1)); }
2317   bool IsMonomorphic() OVERRIDE { return receiver_types_.length() == 1; }
2318   bool IsUninitialized() const {
2319     return IsUninitializedField::decode(bit_field_);
2320   }
2321   bool HasNoTypeInformation() {
2322     return IsUninitializedField::decode(bit_field_);
2323   }
2324   SmallMapList* GetReceiverTypes() OVERRIDE { return &receiver_types_; }
2325   IcCheckType GetKeyType() const OVERRIDE {
2326     return KeyTypeField::decode(bit_field_);
2327   }
2328   KeyedAccessStoreMode GetStoreMode() const OVERRIDE {
2329     return StoreModeField::decode(bit_field_);
2330   }
2331   void set_is_uninitialized(bool b) {
2332     bit_field_ = IsUninitializedField::update(bit_field_, b);
2333   }
2334   void set_key_type(IcCheckType key_type) {
2335     bit_field_ = KeyTypeField::update(bit_field_, key_type);
2336   }
2337   void set_store_mode(KeyedAccessStoreMode mode) {
2338     bit_field_ = StoreModeField::update(bit_field_, mode);
2339   }
2340
2341  protected:
2342   Assignment(Zone* zone, Token::Value op, Expression* target, Expression* value,
2343              int pos);
2344   static int parent_num_ids() { return Expression::num_ids(); }
2345
2346  private:
2347   int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2348
2349   class IsUninitializedField : public BitField16<bool, 0, 1> {};
2350   class KeyTypeField : public BitField16<IcCheckType, 1, 1> {};
2351   class StoreModeField : public BitField16<KeyedAccessStoreMode, 2, 4> {};
2352   class TokenField : public BitField16<Token::Value, 6, 8> {};
2353
2354   // Starts with 16-bit field, which should get packed together with
2355   // Expression's trailing 16-bit field.
2356   uint16_t bit_field_;
2357   Expression* target_;
2358   Expression* value_;
2359   BinaryOperation* binary_operation_;
2360   SmallMapList receiver_types_;
2361 };
2362
2363
2364 class Yield FINAL : public Expression {
2365  public:
2366   DECLARE_NODE_TYPE(Yield)
2367
2368   enum Kind {
2369     kInitial,  // The initial yield that returns the unboxed generator object.
2370     kSuspend,  // A normal yield: { value: EXPRESSION, done: false }
2371     kDelegating,  // A yield*.
2372     kFinal        // A return: { value: EXPRESSION, done: true }
2373   };
2374
2375   Expression* generator_object() const { return generator_object_; }
2376   Expression* expression() const { return expression_; }
2377   Kind yield_kind() const { return yield_kind_; }
2378
2379   // Delegating yield surrounds the "yield" in a "try/catch".  This index
2380   // locates the catch handler in the handler table, and is equivalent to
2381   // TryCatchStatement::index().
2382   int index() const {
2383     DCHECK_EQ(kDelegating, yield_kind());
2384     return index_;
2385   }
2386   void set_index(int index) {
2387     DCHECK_EQ(kDelegating, yield_kind());
2388     index_ = index;
2389   }
2390
2391   // Type feedback information.
2392   bool HasFeedbackSlots() const {
2393     return FLAG_vector_ics && (yield_kind() == kDelegating);
2394   }
2395   virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
2396       Isolate* isolate, const ICSlotCache* cache) OVERRIDE {
2397     return FeedbackVectorRequirements(0, HasFeedbackSlots() ? 3 : 0);
2398   }
2399   void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot,
2400                               ICSlotCache* cache) OVERRIDE {
2401     yield_first_feedback_slot_ = slot;
2402   }
2403   Code::Kind FeedbackICSlotKind(int index) OVERRIDE {
2404     return index == 0 ? Code::KEYED_LOAD_IC : Code::LOAD_IC;
2405   }
2406
2407   FeedbackVectorICSlot KeyedLoadFeedbackSlot() {
2408     DCHECK(!HasFeedbackSlots() || !yield_first_feedback_slot_.IsInvalid());
2409     return yield_first_feedback_slot_;
2410   }
2411
2412   FeedbackVectorICSlot DoneFeedbackSlot() {
2413     return KeyedLoadFeedbackSlot().next();
2414   }
2415
2416   FeedbackVectorICSlot ValueFeedbackSlot() { return DoneFeedbackSlot().next(); }
2417
2418  protected:
2419   Yield(Zone* zone, Expression* generator_object, Expression* expression,
2420         Kind yield_kind, int pos)
2421       : Expression(zone, pos),
2422         generator_object_(generator_object),
2423         expression_(expression),
2424         yield_kind_(yield_kind),
2425         index_(-1),
2426         yield_first_feedback_slot_(FeedbackVectorICSlot::Invalid()) {}
2427
2428  private:
2429   Expression* generator_object_;
2430   Expression* expression_;
2431   Kind yield_kind_;
2432   int index_;
2433   FeedbackVectorICSlot yield_first_feedback_slot_;
2434 };
2435
2436
2437 class Throw FINAL : public Expression {
2438  public:
2439   DECLARE_NODE_TYPE(Throw)
2440
2441   Expression* exception() const { return exception_; }
2442
2443  protected:
2444   Throw(Zone* zone, Expression* exception, int pos)
2445       : Expression(zone, pos), exception_(exception) {}
2446
2447  private:
2448   Expression* exception_;
2449 };
2450
2451
2452 class FunctionLiteral FINAL : public Expression {
2453  public:
2454   enum FunctionType {
2455     ANONYMOUS_EXPRESSION,
2456     NAMED_EXPRESSION,
2457     DECLARATION
2458   };
2459
2460   enum ParameterFlag {
2461     kNoDuplicateParameters = 0,
2462     kHasDuplicateParameters = 1
2463   };
2464
2465   enum IsFunctionFlag {
2466     kGlobalOrEval,
2467     kIsFunction
2468   };
2469
2470   enum IsParenthesizedFlag {
2471     kIsParenthesized,
2472     kNotParenthesized
2473   };
2474
2475   enum ArityRestriction {
2476     NORMAL_ARITY,
2477     GETTER_ARITY,
2478     SETTER_ARITY
2479   };
2480
2481   DECLARE_NODE_TYPE(FunctionLiteral)
2482
2483   Handle<String> name() const { return raw_name_->string(); }
2484   const AstRawString* raw_name() const { return raw_name_; }
2485   Scope* scope() const { return scope_; }
2486   ZoneList<Statement*>* body() const { return body_; }
2487   void set_function_token_position(int pos) { function_token_position_ = pos; }
2488   int function_token_position() const { return function_token_position_; }
2489   int start_position() const;
2490   int end_position() const;
2491   int SourceSize() const { return end_position() - start_position(); }
2492   bool is_expression() const { return IsExpression::decode(bitfield_); }
2493   bool is_anonymous() const { return IsAnonymous::decode(bitfield_); }
2494   LanguageMode language_mode() const;
2495   bool uses_super_property() const;
2496
2497   static bool NeedsHomeObject(Expression* literal) {
2498     return literal != NULL && literal->IsFunctionLiteral() &&
2499            literal->AsFunctionLiteral()->uses_super_property();
2500   }
2501
2502   int materialized_literal_count() { return materialized_literal_count_; }
2503   int expected_property_count() { return expected_property_count_; }
2504   int handler_count() { return handler_count_; }
2505   int parameter_count() { return parameter_count_; }
2506
2507   bool AllowsLazyCompilation();
2508   bool AllowsLazyCompilationWithoutContext();
2509
2510   void InitializeSharedInfo(Handle<Code> code);
2511
2512   Handle<String> debug_name() const {
2513     if (raw_name_ != NULL && !raw_name_->IsEmpty()) {
2514       return raw_name_->string();
2515     }
2516     return inferred_name();
2517   }
2518
2519   Handle<String> inferred_name() const {
2520     if (!inferred_name_.is_null()) {
2521       DCHECK(raw_inferred_name_ == NULL);
2522       return inferred_name_;
2523     }
2524     if (raw_inferred_name_ != NULL) {
2525       return raw_inferred_name_->string();
2526     }
2527     UNREACHABLE();
2528     return Handle<String>();
2529   }
2530
2531   // Only one of {set_inferred_name, set_raw_inferred_name} should be called.
2532   void set_inferred_name(Handle<String> inferred_name) {
2533     DCHECK(!inferred_name.is_null());
2534     inferred_name_ = inferred_name;
2535     DCHECK(raw_inferred_name_== NULL || raw_inferred_name_->IsEmpty());
2536     raw_inferred_name_ = NULL;
2537   }
2538
2539   void set_raw_inferred_name(const AstString* raw_inferred_name) {
2540     DCHECK(raw_inferred_name != NULL);
2541     raw_inferred_name_ = raw_inferred_name;
2542     DCHECK(inferred_name_.is_null());
2543     inferred_name_ = Handle<String>();
2544   }
2545
2546   // shared_info may be null if it's not cached in full code.
2547   Handle<SharedFunctionInfo> shared_info() { return shared_info_; }
2548
2549   bool pretenure() { return Pretenure::decode(bitfield_); }
2550   void set_pretenure() { bitfield_ |= Pretenure::encode(true); }
2551
2552   bool has_duplicate_parameters() {
2553     return HasDuplicateParameters::decode(bitfield_);
2554   }
2555
2556   bool is_function() { return IsFunction::decode(bitfield_) == kIsFunction; }
2557
2558   // This is used as a heuristic on when to eagerly compile a function
2559   // literal. We consider the following constructs as hints that the
2560   // function will be called immediately:
2561   // - (function() { ... })();
2562   // - var x = function() { ... }();
2563   bool is_parenthesized() {
2564     return IsParenthesized::decode(bitfield_) == kIsParenthesized;
2565   }
2566   void set_parenthesized() {
2567     bitfield_ = IsParenthesized::update(bitfield_, kIsParenthesized);
2568   }
2569
2570   FunctionKind kind() { return FunctionKindBits::decode(bitfield_); }
2571
2572   int ast_node_count() { return ast_properties_.node_count(); }
2573   AstProperties::Flags* flags() { return ast_properties_.flags(); }
2574   void set_ast_properties(AstProperties* ast_properties) {
2575     ast_properties_ = *ast_properties;
2576   }
2577   const ZoneFeedbackVectorSpec* feedback_vector_spec() const {
2578     return ast_properties_.get_spec();
2579   }
2580   bool dont_optimize() { return dont_optimize_reason_ != kNoReason; }
2581   BailoutReason dont_optimize_reason() { return dont_optimize_reason_; }
2582   void set_dont_optimize_reason(BailoutReason reason) {
2583     dont_optimize_reason_ = reason;
2584   }
2585
2586  protected:
2587   FunctionLiteral(Zone* zone, const AstRawString* name,
2588                   AstValueFactory* ast_value_factory, Scope* scope,
2589                   ZoneList<Statement*>* body, int materialized_literal_count,
2590                   int expected_property_count, int handler_count,
2591                   int parameter_count, FunctionType function_type,
2592                   ParameterFlag has_duplicate_parameters,
2593                   IsFunctionFlag is_function,
2594                   IsParenthesizedFlag is_parenthesized, FunctionKind kind,
2595                   int position)
2596       : Expression(zone, position),
2597         raw_name_(name),
2598         scope_(scope),
2599         body_(body),
2600         raw_inferred_name_(ast_value_factory->empty_string()),
2601         ast_properties_(zone),
2602         dont_optimize_reason_(kNoReason),
2603         materialized_literal_count_(materialized_literal_count),
2604         expected_property_count_(expected_property_count),
2605         handler_count_(handler_count),
2606         parameter_count_(parameter_count),
2607         function_token_position_(RelocInfo::kNoPosition) {
2608     bitfield_ = IsExpression::encode(function_type != DECLARATION) |
2609                 IsAnonymous::encode(function_type == ANONYMOUS_EXPRESSION) |
2610                 Pretenure::encode(false) |
2611                 HasDuplicateParameters::encode(has_duplicate_parameters) |
2612                 IsFunction::encode(is_function) |
2613                 IsParenthesized::encode(is_parenthesized) |
2614                 FunctionKindBits::encode(kind);
2615     DCHECK(IsValidFunctionKind(kind));
2616   }
2617
2618  private:
2619   const AstRawString* raw_name_;
2620   Handle<String> name_;
2621   Handle<SharedFunctionInfo> shared_info_;
2622   Scope* scope_;
2623   ZoneList<Statement*>* body_;
2624   const AstString* raw_inferred_name_;
2625   Handle<String> inferred_name_;
2626   AstProperties ast_properties_;
2627   BailoutReason dont_optimize_reason_;
2628
2629   int materialized_literal_count_;
2630   int expected_property_count_;
2631   int handler_count_;
2632   int parameter_count_;
2633   int function_token_position_;
2634
2635   unsigned bitfield_;
2636   class IsExpression : public BitField<bool, 0, 1> {};
2637   class IsAnonymous : public BitField<bool, 1, 1> {};
2638   class Pretenure : public BitField<bool, 2, 1> {};
2639   class HasDuplicateParameters : public BitField<ParameterFlag, 3, 1> {};
2640   class IsFunction : public BitField<IsFunctionFlag, 4, 1> {};
2641   class IsParenthesized : public BitField<IsParenthesizedFlag, 5, 1> {};
2642   class FunctionKindBits : public BitField<FunctionKind, 6, 8> {};
2643 };
2644
2645
2646 class ClassLiteral FINAL : public Expression {
2647  public:
2648   typedef ObjectLiteralProperty Property;
2649
2650   DECLARE_NODE_TYPE(ClassLiteral)
2651
2652   Handle<String> name() const { return raw_name_->string(); }
2653   const AstRawString* raw_name() const { return raw_name_; }
2654   Scope* scope() const { return scope_; }
2655   VariableProxy* class_variable_proxy() const { return class_variable_proxy_; }
2656   Expression* extends() const { return extends_; }
2657   FunctionLiteral* constructor() const { return constructor_; }
2658   ZoneList<Property*>* properties() const { return properties_; }
2659   int start_position() const { return position(); }
2660   int end_position() const { return end_position_; }
2661
2662   BailoutId EntryId() const { return BailoutId(local_id(0)); }
2663   BailoutId DeclsId() const { return BailoutId(local_id(1)); }
2664   BailoutId ExitId() { return BailoutId(local_id(2)); }
2665
2666   // Return an AST id for a property that is used in simulate instructions.
2667   BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 3)); }
2668
2669   // Unlike other AST nodes, this number of bailout IDs allocated for an
2670   // ClassLiteral can vary, so num_ids() is not a static method.
2671   int num_ids() const { return parent_num_ids() + 3 + properties()->length(); }
2672
2673  protected:
2674   ClassLiteral(Zone* zone, const AstRawString* name, Scope* scope,
2675                VariableProxy* class_variable_proxy, Expression* extends,
2676                FunctionLiteral* constructor, ZoneList<Property*>* properties,
2677                int start_position, int end_position)
2678       : Expression(zone, start_position),
2679         raw_name_(name),
2680         scope_(scope),
2681         class_variable_proxy_(class_variable_proxy),
2682         extends_(extends),
2683         constructor_(constructor),
2684         properties_(properties),
2685         end_position_(end_position) {}
2686   static int parent_num_ids() { return Expression::num_ids(); }
2687
2688  private:
2689   int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2690
2691   const AstRawString* raw_name_;
2692   Scope* scope_;
2693   VariableProxy* class_variable_proxy_;
2694   Expression* extends_;
2695   FunctionLiteral* constructor_;
2696   ZoneList<Property*>* properties_;
2697   int end_position_;
2698 };
2699
2700
2701 class NativeFunctionLiteral FINAL : public Expression {
2702  public:
2703   DECLARE_NODE_TYPE(NativeFunctionLiteral)
2704
2705   Handle<String> name() const { return name_->string(); }
2706   v8::Extension* extension() const { return extension_; }
2707
2708  protected:
2709   NativeFunctionLiteral(Zone* zone, const AstRawString* name,
2710                         v8::Extension* extension, int pos)
2711       : Expression(zone, pos), name_(name), extension_(extension) {}
2712
2713  private:
2714   const AstRawString* name_;
2715   v8::Extension* extension_;
2716 };
2717
2718
2719 class ThisFunction FINAL : public Expression {
2720  public:
2721   DECLARE_NODE_TYPE(ThisFunction)
2722
2723  protected:
2724   ThisFunction(Zone* zone, int pos) : Expression(zone, pos) {}
2725 };
2726
2727
2728 class SuperReference FINAL : public Expression {
2729  public:
2730   DECLARE_NODE_TYPE(SuperReference)
2731
2732   VariableProxy* this_var() const { return this_var_; }
2733
2734   static int num_ids() { return parent_num_ids() + 1; }
2735   TypeFeedbackId HomeObjectFeedbackId() { return TypeFeedbackId(local_id(0)); }
2736
2737   // Type feedback information.
2738   virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
2739       Isolate* isolate, const ICSlotCache* cache) OVERRIDE {
2740     return FeedbackVectorRequirements(0, FLAG_vector_ics ? 1 : 0);
2741   }
2742   void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot,
2743                               ICSlotCache* cache) OVERRIDE {
2744     homeobject_feedback_slot_ = slot;
2745   }
2746   Code::Kind FeedbackICSlotKind(int index) OVERRIDE { return Code::LOAD_IC; }
2747
2748   FeedbackVectorICSlot HomeObjectFeedbackSlot() {
2749     DCHECK(!FLAG_vector_ics || !homeobject_feedback_slot_.IsInvalid());
2750     return homeobject_feedback_slot_;
2751   }
2752
2753  protected:
2754   SuperReference(Zone* zone, VariableProxy* this_var, int pos)
2755       : Expression(zone, pos),
2756         this_var_(this_var),
2757         homeobject_feedback_slot_(FeedbackVectorICSlot::Invalid()) {
2758     DCHECK(this_var->is_this());
2759   }
2760   static int parent_num_ids() { return Expression::num_ids(); }
2761
2762  private:
2763   int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2764
2765   VariableProxy* this_var_;
2766   FeedbackVectorICSlot homeobject_feedback_slot_;
2767 };
2768
2769
2770 #undef DECLARE_NODE_TYPE
2771
2772
2773 // ----------------------------------------------------------------------------
2774 // Regular expressions
2775
2776
2777 class RegExpVisitor BASE_EMBEDDED {
2778  public:
2779   virtual ~RegExpVisitor() { }
2780 #define MAKE_CASE(Name)                                              \
2781   virtual void* Visit##Name(RegExp##Name*, void* data) = 0;
2782   FOR_EACH_REG_EXP_TREE_TYPE(MAKE_CASE)
2783 #undef MAKE_CASE
2784 };
2785
2786
2787 class RegExpTree : public ZoneObject {
2788  public:
2789   static const int kInfinity = kMaxInt;
2790   virtual ~RegExpTree() {}
2791   virtual void* Accept(RegExpVisitor* visitor, void* data) = 0;
2792   virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2793                              RegExpNode* on_success) = 0;
2794   virtual bool IsTextElement() { return false; }
2795   virtual bool IsAnchoredAtStart() { return false; }
2796   virtual bool IsAnchoredAtEnd() { return false; }
2797   virtual int min_match() = 0;
2798   virtual int max_match() = 0;
2799   // Returns the interval of registers used for captures within this
2800   // expression.
2801   virtual Interval CaptureRegisters() { return Interval::Empty(); }
2802   virtual void AppendToText(RegExpText* text, Zone* zone);
2803   std::ostream& Print(std::ostream& os, Zone* zone);  // NOLINT
2804 #define MAKE_ASTYPE(Name)                                                  \
2805   virtual RegExp##Name* As##Name();                                        \
2806   virtual bool Is##Name();
2807   FOR_EACH_REG_EXP_TREE_TYPE(MAKE_ASTYPE)
2808 #undef MAKE_ASTYPE
2809 };
2810
2811
2812 class RegExpDisjunction FINAL : public RegExpTree {
2813  public:
2814   explicit RegExpDisjunction(ZoneList<RegExpTree*>* alternatives);
2815   void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
2816   virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2817                              RegExpNode* on_success) OVERRIDE;
2818   RegExpDisjunction* AsDisjunction() OVERRIDE;
2819   Interval CaptureRegisters() OVERRIDE;
2820   bool IsDisjunction() OVERRIDE;
2821   bool IsAnchoredAtStart() OVERRIDE;
2822   bool IsAnchoredAtEnd() OVERRIDE;
2823   int min_match() OVERRIDE { return min_match_; }
2824   int max_match() OVERRIDE { return max_match_; }
2825   ZoneList<RegExpTree*>* alternatives() { return alternatives_; }
2826  private:
2827   ZoneList<RegExpTree*>* alternatives_;
2828   int min_match_;
2829   int max_match_;
2830 };
2831
2832
2833 class RegExpAlternative FINAL : public RegExpTree {
2834  public:
2835   explicit RegExpAlternative(ZoneList<RegExpTree*>* nodes);
2836   void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
2837   virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2838                              RegExpNode* on_success) OVERRIDE;
2839   RegExpAlternative* AsAlternative() OVERRIDE;
2840   Interval CaptureRegisters() OVERRIDE;
2841   bool IsAlternative() OVERRIDE;
2842   bool IsAnchoredAtStart() OVERRIDE;
2843   bool IsAnchoredAtEnd() OVERRIDE;
2844   int min_match() OVERRIDE { return min_match_; }
2845   int max_match() OVERRIDE { return max_match_; }
2846   ZoneList<RegExpTree*>* nodes() { return nodes_; }
2847  private:
2848   ZoneList<RegExpTree*>* nodes_;
2849   int min_match_;
2850   int max_match_;
2851 };
2852
2853
2854 class RegExpAssertion FINAL : public RegExpTree {
2855  public:
2856   enum AssertionType {
2857     START_OF_LINE,
2858     START_OF_INPUT,
2859     END_OF_LINE,
2860     END_OF_INPUT,
2861     BOUNDARY,
2862     NON_BOUNDARY
2863   };
2864   explicit RegExpAssertion(AssertionType type) : assertion_type_(type) { }
2865   void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
2866   virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2867                              RegExpNode* on_success) OVERRIDE;
2868   RegExpAssertion* AsAssertion() OVERRIDE;
2869   bool IsAssertion() OVERRIDE;
2870   bool IsAnchoredAtStart() OVERRIDE;
2871   bool IsAnchoredAtEnd() OVERRIDE;
2872   int min_match() OVERRIDE { return 0; }
2873   int max_match() OVERRIDE { return 0; }
2874   AssertionType assertion_type() { return assertion_type_; }
2875  private:
2876   AssertionType assertion_type_;
2877 };
2878
2879
2880 class CharacterSet FINAL BASE_EMBEDDED {
2881  public:
2882   explicit CharacterSet(uc16 standard_set_type)
2883       : ranges_(NULL),
2884         standard_set_type_(standard_set_type) {}
2885   explicit CharacterSet(ZoneList<CharacterRange>* ranges)
2886       : ranges_(ranges),
2887         standard_set_type_(0) {}
2888   ZoneList<CharacterRange>* ranges(Zone* zone);
2889   uc16 standard_set_type() { return standard_set_type_; }
2890   void set_standard_set_type(uc16 special_set_type) {
2891     standard_set_type_ = special_set_type;
2892   }
2893   bool is_standard() { return standard_set_type_ != 0; }
2894   void Canonicalize();
2895  private:
2896   ZoneList<CharacterRange>* ranges_;
2897   // If non-zero, the value represents a standard set (e.g., all whitespace
2898   // characters) without having to expand the ranges.
2899   uc16 standard_set_type_;
2900 };
2901
2902
2903 class RegExpCharacterClass FINAL : public RegExpTree {
2904  public:
2905   RegExpCharacterClass(ZoneList<CharacterRange>* ranges, bool is_negated)
2906       : set_(ranges),
2907         is_negated_(is_negated) { }
2908   explicit RegExpCharacterClass(uc16 type)
2909       : set_(type),
2910         is_negated_(false) { }
2911   void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
2912   virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2913                              RegExpNode* on_success) OVERRIDE;
2914   RegExpCharacterClass* AsCharacterClass() OVERRIDE;
2915   bool IsCharacterClass() OVERRIDE;
2916   bool IsTextElement() OVERRIDE { return true; }
2917   int min_match() OVERRIDE { return 1; }
2918   int max_match() OVERRIDE { return 1; }
2919   void AppendToText(RegExpText* text, Zone* zone) OVERRIDE;
2920   CharacterSet character_set() { return set_; }
2921   // TODO(lrn): Remove need for complex version if is_standard that
2922   // recognizes a mangled standard set and just do { return set_.is_special(); }
2923   bool is_standard(Zone* zone);
2924   // Returns a value representing the standard character set if is_standard()
2925   // returns true.
2926   // Currently used values are:
2927   // s : unicode whitespace
2928   // S : unicode non-whitespace
2929   // w : ASCII word character (digit, letter, underscore)
2930   // W : non-ASCII word character
2931   // d : ASCII digit
2932   // D : non-ASCII digit
2933   // . : non-unicode non-newline
2934   // * : All characters
2935   uc16 standard_type() { return set_.standard_set_type(); }
2936   ZoneList<CharacterRange>* ranges(Zone* zone) { return set_.ranges(zone); }
2937   bool is_negated() { return is_negated_; }
2938
2939  private:
2940   CharacterSet set_;
2941   bool is_negated_;
2942 };
2943
2944
2945 class RegExpAtom FINAL : public RegExpTree {
2946  public:
2947   explicit RegExpAtom(Vector<const uc16> data) : data_(data) { }
2948   void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
2949   virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2950                              RegExpNode* on_success) OVERRIDE;
2951   RegExpAtom* AsAtom() OVERRIDE;
2952   bool IsAtom() OVERRIDE;
2953   bool IsTextElement() OVERRIDE { return true; }
2954   int min_match() OVERRIDE { return data_.length(); }
2955   int max_match() OVERRIDE { return data_.length(); }
2956   void AppendToText(RegExpText* text, Zone* zone) OVERRIDE;
2957   Vector<const uc16> data() { return data_; }
2958   int length() { return data_.length(); }
2959  private:
2960   Vector<const uc16> data_;
2961 };
2962
2963
2964 class RegExpText FINAL : public RegExpTree {
2965  public:
2966   explicit RegExpText(Zone* zone) : elements_(2, zone), length_(0) {}
2967   void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
2968   virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2969                              RegExpNode* on_success) OVERRIDE;
2970   RegExpText* AsText() OVERRIDE;
2971   bool IsText() OVERRIDE;
2972   bool IsTextElement() OVERRIDE { return true; }
2973   int min_match() OVERRIDE { return length_; }
2974   int max_match() OVERRIDE { return length_; }
2975   void AppendToText(RegExpText* text, Zone* zone) OVERRIDE;
2976   void AddElement(TextElement elm, Zone* zone)  {
2977     elements_.Add(elm, zone);
2978     length_ += elm.length();
2979   }
2980   ZoneList<TextElement>* elements() { return &elements_; }
2981  private:
2982   ZoneList<TextElement> elements_;
2983   int length_;
2984 };
2985
2986
2987 class RegExpQuantifier FINAL : public RegExpTree {
2988  public:
2989   enum QuantifierType { GREEDY, NON_GREEDY, POSSESSIVE };
2990   RegExpQuantifier(int min, int max, QuantifierType type, RegExpTree* body)
2991       : body_(body),
2992         min_(min),
2993         max_(max),
2994         min_match_(min * body->min_match()),
2995         quantifier_type_(type) {
2996     if (max > 0 && body->max_match() > kInfinity / max) {
2997       max_match_ = kInfinity;
2998     } else {
2999       max_match_ = max * body->max_match();
3000     }
3001   }
3002   void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
3003   virtual RegExpNode* ToNode(RegExpCompiler* compiler,
3004                              RegExpNode* on_success) OVERRIDE;
3005   static RegExpNode* ToNode(int min,
3006                             int max,
3007                             bool is_greedy,
3008                             RegExpTree* body,
3009                             RegExpCompiler* compiler,
3010                             RegExpNode* on_success,
3011                             bool not_at_start = false);
3012   RegExpQuantifier* AsQuantifier() OVERRIDE;
3013   Interval CaptureRegisters() OVERRIDE;
3014   bool IsQuantifier() OVERRIDE;
3015   int min_match() OVERRIDE { return min_match_; }
3016   int max_match() OVERRIDE { return max_match_; }
3017   int min() { return min_; }
3018   int max() { return max_; }
3019   bool is_possessive() { return quantifier_type_ == POSSESSIVE; }
3020   bool is_non_greedy() { return quantifier_type_ == NON_GREEDY; }
3021   bool is_greedy() { return quantifier_type_ == GREEDY; }
3022   RegExpTree* body() { return body_; }
3023
3024  private:
3025   RegExpTree* body_;
3026   int min_;
3027   int max_;
3028   int min_match_;
3029   int max_match_;
3030   QuantifierType quantifier_type_;
3031 };
3032
3033
3034 class RegExpCapture FINAL : public RegExpTree {
3035  public:
3036   explicit RegExpCapture(RegExpTree* body, int index)
3037       : body_(body), index_(index) { }
3038   void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
3039   virtual RegExpNode* ToNode(RegExpCompiler* compiler,
3040                              RegExpNode* on_success) OVERRIDE;
3041   static RegExpNode* ToNode(RegExpTree* body,
3042                             int index,
3043                             RegExpCompiler* compiler,
3044                             RegExpNode* on_success);
3045   RegExpCapture* AsCapture() OVERRIDE;
3046   bool IsAnchoredAtStart() OVERRIDE;
3047   bool IsAnchoredAtEnd() OVERRIDE;
3048   Interval CaptureRegisters() OVERRIDE;
3049   bool IsCapture() OVERRIDE;
3050   int min_match() OVERRIDE { return body_->min_match(); }
3051   int max_match() OVERRIDE { return body_->max_match(); }
3052   RegExpTree* body() { return body_; }
3053   int index() { return index_; }
3054   static int StartRegister(int index) { return index * 2; }
3055   static int EndRegister(int index) { return index * 2 + 1; }
3056
3057  private:
3058   RegExpTree* body_;
3059   int index_;
3060 };
3061
3062
3063 class RegExpLookahead FINAL : public RegExpTree {
3064  public:
3065   RegExpLookahead(RegExpTree* body,
3066                   bool is_positive,
3067                   int capture_count,
3068                   int capture_from)
3069       : body_(body),
3070         is_positive_(is_positive),
3071         capture_count_(capture_count),
3072         capture_from_(capture_from) { }
3073
3074   void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
3075   virtual RegExpNode* ToNode(RegExpCompiler* compiler,
3076                              RegExpNode* on_success) OVERRIDE;
3077   RegExpLookahead* AsLookahead() OVERRIDE;
3078   Interval CaptureRegisters() OVERRIDE;
3079   bool IsLookahead() OVERRIDE;
3080   bool IsAnchoredAtStart() OVERRIDE;
3081   int min_match() OVERRIDE { return 0; }
3082   int max_match() OVERRIDE { return 0; }
3083   RegExpTree* body() { return body_; }
3084   bool is_positive() { return is_positive_; }
3085   int capture_count() { return capture_count_; }
3086   int capture_from() { return capture_from_; }
3087
3088  private:
3089   RegExpTree* body_;
3090   bool is_positive_;
3091   int capture_count_;
3092   int capture_from_;
3093 };
3094
3095
3096 class RegExpBackReference FINAL : public RegExpTree {
3097  public:
3098   explicit RegExpBackReference(RegExpCapture* capture)
3099       : capture_(capture) { }
3100   void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
3101   virtual RegExpNode* ToNode(RegExpCompiler* compiler,
3102                              RegExpNode* on_success) OVERRIDE;
3103   RegExpBackReference* AsBackReference() OVERRIDE;
3104   bool IsBackReference() OVERRIDE;
3105   int min_match() OVERRIDE { return 0; }
3106   int max_match() OVERRIDE { return capture_->max_match(); }
3107   int index() { return capture_->index(); }
3108   RegExpCapture* capture() { return capture_; }
3109  private:
3110   RegExpCapture* capture_;
3111 };
3112
3113
3114 class RegExpEmpty FINAL : public RegExpTree {
3115  public:
3116   RegExpEmpty() { }
3117   void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
3118   virtual RegExpNode* ToNode(RegExpCompiler* compiler,
3119                              RegExpNode* on_success) OVERRIDE;
3120   RegExpEmpty* AsEmpty() OVERRIDE;
3121   bool IsEmpty() OVERRIDE;
3122   int min_match() OVERRIDE { return 0; }
3123   int max_match() OVERRIDE { return 0; }
3124 };
3125
3126
3127 // ----------------------------------------------------------------------------
3128 // Basic visitor
3129 // - leaf node visitors are abstract.
3130
3131 class AstVisitor BASE_EMBEDDED {
3132  public:
3133   AstVisitor() {}
3134   virtual ~AstVisitor() {}
3135
3136   // Stack overflow check and dynamic dispatch.
3137   virtual void Visit(AstNode* node) = 0;
3138
3139   // Iteration left-to-right.
3140   virtual void VisitDeclarations(ZoneList<Declaration*>* declarations);
3141   virtual void VisitStatements(ZoneList<Statement*>* statements);
3142   virtual void VisitExpressions(ZoneList<Expression*>* expressions);
3143
3144   // Individual AST nodes.
3145 #define DEF_VISIT(type)                         \
3146   virtual void Visit##type(type* node) = 0;
3147   AST_NODE_LIST(DEF_VISIT)
3148 #undef DEF_VISIT
3149 };
3150
3151
3152 #define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS()               \
3153  public:                                                    \
3154   void Visit(AstNode* node) FINAL {                         \
3155     if (!CheckStackOverflow()) node->Accept(this);          \
3156   }                                                         \
3157                                                             \
3158   void SetStackOverflow() { stack_overflow_ = true; }       \
3159   void ClearStackOverflow() { stack_overflow_ = false; }    \
3160   bool HasStackOverflow() const { return stack_overflow_; } \
3161                                                             \
3162   bool CheckStackOverflow() {                               \
3163     if (stack_overflow_) return true;                       \
3164     StackLimitCheck check(isolate_);                        \
3165     if (!check.HasOverflowed()) return false;               \
3166     stack_overflow_ = true;                                 \
3167     return true;                                            \
3168   }                                                         \
3169                                                             \
3170  private:                                                   \
3171   void InitializeAstVisitor(Isolate* isolate, Zone* zone) { \
3172     isolate_ = isolate;                                     \
3173     zone_ = zone;                                           \
3174     stack_overflow_ = false;                                \
3175   }                                                         \
3176   Zone* zone() { return zone_; }                            \
3177   Isolate* isolate() { return isolate_; }                   \
3178                                                             \
3179   Isolate* isolate_;                                        \
3180   Zone* zone_;                                              \
3181   bool stack_overflow_
3182
3183
3184 // ----------------------------------------------------------------------------
3185 // AstNode factory
3186
3187 class AstNodeFactory FINAL BASE_EMBEDDED {
3188  public:
3189   explicit AstNodeFactory(AstValueFactory* ast_value_factory)
3190       : zone_(ast_value_factory->zone()),
3191         ast_value_factory_(ast_value_factory) {}
3192
3193   VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy,
3194                                               VariableMode mode,
3195                                               Scope* scope,
3196                                               int pos) {
3197     return new (zone_) VariableDeclaration(zone_, proxy, mode, scope, pos);
3198   }
3199
3200   FunctionDeclaration* NewFunctionDeclaration(VariableProxy* proxy,
3201                                               VariableMode mode,
3202                                               FunctionLiteral* fun,
3203                                               Scope* scope,
3204                                               int pos) {
3205     return new (zone_) FunctionDeclaration(zone_, proxy, mode, fun, scope, pos);
3206   }
3207
3208   ModuleDeclaration* NewModuleDeclaration(VariableProxy* proxy,
3209                                           Module* module,
3210                                           Scope* scope,
3211                                           int pos) {
3212     return new (zone_) ModuleDeclaration(zone_, proxy, module, scope, pos);
3213   }
3214
3215   ImportDeclaration* NewImportDeclaration(VariableProxy* proxy,
3216                                           const AstRawString* import_name,
3217                                           const AstRawString* module_specifier,
3218                                           Scope* scope, int pos) {
3219     return new (zone_) ImportDeclaration(zone_, proxy, import_name,
3220                                          module_specifier, scope, pos);
3221   }
3222
3223   ExportDeclaration* NewExportDeclaration(VariableProxy* proxy,
3224                                           Scope* scope,
3225                                           int pos) {
3226     return new (zone_) ExportDeclaration(zone_, proxy, scope, pos);
3227   }
3228
3229   ModuleLiteral* NewModuleLiteral(Block* body, ModuleDescriptor* descriptor,
3230                                   int pos) {
3231     return new (zone_) ModuleLiteral(zone_, body, descriptor, pos);
3232   }
3233
3234   ModulePath* NewModulePath(Module* origin, const AstRawString* name, int pos) {
3235     return new (zone_) ModulePath(zone_, origin, name, pos);
3236   }
3237
3238   ModuleUrl* NewModuleUrl(Handle<String> url, int pos) {
3239     return new (zone_) ModuleUrl(zone_, url, pos);
3240   }
3241
3242   Block* NewBlock(ZoneList<const AstRawString*>* labels,
3243                   int capacity,
3244                   bool is_initializer_block,
3245                   int pos) {
3246     return new (zone_)
3247         Block(zone_, labels, capacity, is_initializer_block, pos);
3248   }
3249
3250 #define STATEMENT_WITH_LABELS(NodeType)                                     \
3251   NodeType* New##NodeType(ZoneList<const AstRawString*>* labels, int pos) { \
3252     return new (zone_) NodeType(zone_, labels, pos);                        \
3253   }
3254   STATEMENT_WITH_LABELS(DoWhileStatement)
3255   STATEMENT_WITH_LABELS(WhileStatement)
3256   STATEMENT_WITH_LABELS(ForStatement)
3257   STATEMENT_WITH_LABELS(SwitchStatement)
3258 #undef STATEMENT_WITH_LABELS
3259
3260   ForEachStatement* NewForEachStatement(ForEachStatement::VisitMode visit_mode,
3261                                         ZoneList<const AstRawString*>* labels,
3262                                         int pos) {
3263     switch (visit_mode) {
3264       case ForEachStatement::ENUMERATE: {
3265         return new (zone_) ForInStatement(zone_, labels, pos);
3266       }
3267       case ForEachStatement::ITERATE: {
3268         return new (zone_) ForOfStatement(zone_, labels, pos);
3269       }
3270     }
3271     UNREACHABLE();
3272     return NULL;
3273   }
3274
3275   ModuleStatement* NewModuleStatement(Block* body, int pos) {
3276     return new (zone_) ModuleStatement(zone_, body, pos);
3277   }
3278
3279   ExpressionStatement* NewExpressionStatement(Expression* expression, int pos) {
3280     return new (zone_) ExpressionStatement(zone_, expression, pos);
3281   }
3282
3283   ContinueStatement* NewContinueStatement(IterationStatement* target, int pos) {
3284     return new (zone_) ContinueStatement(zone_, target, pos);
3285   }
3286
3287   BreakStatement* NewBreakStatement(BreakableStatement* target, int pos) {
3288     return new (zone_) BreakStatement(zone_, target, pos);
3289   }
3290
3291   ReturnStatement* NewReturnStatement(Expression* expression, int pos) {
3292     return new (zone_) ReturnStatement(zone_, expression, pos);
3293   }
3294
3295   WithStatement* NewWithStatement(Scope* scope,
3296                                   Expression* expression,
3297                                   Statement* statement,
3298                                   int pos) {
3299     return new (zone_) WithStatement(zone_, scope, expression, statement, pos);
3300   }
3301
3302   IfStatement* NewIfStatement(Expression* condition,
3303                               Statement* then_statement,
3304                               Statement* else_statement,
3305                               int pos) {
3306     return new (zone_)
3307         IfStatement(zone_, condition, then_statement, else_statement, pos);
3308   }
3309
3310   TryCatchStatement* NewTryCatchStatement(int index,
3311                                           Block* try_block,
3312                                           Scope* scope,
3313                                           Variable* variable,
3314                                           Block* catch_block,
3315                                           int pos) {
3316     return new (zone_) TryCatchStatement(zone_, index, try_block, scope,
3317                                          variable, catch_block, pos);
3318   }
3319
3320   TryFinallyStatement* NewTryFinallyStatement(int index,
3321                                               Block* try_block,
3322                                               Block* finally_block,
3323                                               int pos) {
3324     return new (zone_)
3325         TryFinallyStatement(zone_, index, try_block, finally_block, pos);
3326   }
3327
3328   DebuggerStatement* NewDebuggerStatement(int pos) {
3329     return new (zone_) DebuggerStatement(zone_, pos);
3330   }
3331
3332   EmptyStatement* NewEmptyStatement(int pos) {
3333     return new(zone_) EmptyStatement(zone_, pos);
3334   }
3335
3336   CaseClause* NewCaseClause(
3337       Expression* label, ZoneList<Statement*>* statements, int pos) {
3338     return new (zone_) CaseClause(zone_, label, statements, pos);
3339   }
3340
3341   Literal* NewStringLiteral(const AstRawString* string, int pos) {
3342     return new (zone_)
3343         Literal(zone_, ast_value_factory_->NewString(string), pos);
3344   }
3345
3346   // A JavaScript symbol (ECMA-262 edition 6).
3347   Literal* NewSymbolLiteral(const char* name, int pos) {
3348     return new (zone_) Literal(zone_, ast_value_factory_->NewSymbol(name), pos);
3349   }
3350
3351   Literal* NewNumberLiteral(double number, int pos) {
3352     return new (zone_)
3353         Literal(zone_, ast_value_factory_->NewNumber(number), pos);
3354   }
3355
3356   Literal* NewSmiLiteral(int number, int pos) {
3357     return new (zone_) Literal(zone_, ast_value_factory_->NewSmi(number), pos);
3358   }
3359
3360   Literal* NewBooleanLiteral(bool b, int pos) {
3361     return new (zone_) Literal(zone_, ast_value_factory_->NewBoolean(b), pos);
3362   }
3363
3364   Literal* NewNullLiteral(int pos) {
3365     return new (zone_) Literal(zone_, ast_value_factory_->NewNull(), pos);
3366   }
3367
3368   Literal* NewUndefinedLiteral(int pos) {
3369     return new (zone_) Literal(zone_, ast_value_factory_->NewUndefined(), pos);
3370   }
3371
3372   Literal* NewTheHoleLiteral(int pos) {
3373     return new (zone_) Literal(zone_, ast_value_factory_->NewTheHole(), pos);
3374   }
3375
3376   ObjectLiteral* NewObjectLiteral(
3377       ZoneList<ObjectLiteral::Property*>* properties,
3378       int literal_index,
3379       int boilerplate_properties,
3380       bool has_function,
3381       int pos) {
3382     return new (zone_) ObjectLiteral(zone_, properties, literal_index,
3383                                      boilerplate_properties, has_function, pos);
3384   }
3385
3386   ObjectLiteral::Property* NewObjectLiteralProperty(
3387       Expression* key, Expression* value, ObjectLiteralProperty::Kind kind,
3388       bool is_static, bool is_computed_name) {
3389     return new (zone_)
3390         ObjectLiteral::Property(key, value, kind, is_static, is_computed_name);
3391   }
3392
3393   ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key,
3394                                                     Expression* value,
3395                                                     bool is_static,
3396                                                     bool is_computed_name) {
3397     return new (zone_) ObjectLiteral::Property(ast_value_factory_, key, value,
3398                                                is_static, is_computed_name);
3399   }
3400
3401   RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern,
3402                                   const AstRawString* flags,
3403                                   int literal_index,
3404                                   int pos) {
3405     return new (zone_) RegExpLiteral(zone_, pattern, flags, literal_index, pos);
3406   }
3407
3408   ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values,
3409                                 int literal_index,
3410                                 int pos) {
3411     return new (zone_) ArrayLiteral(zone_, values, literal_index, pos);
3412   }
3413
3414   VariableProxy* NewVariableProxy(Variable* var,
3415                                   int start_position = RelocInfo::kNoPosition,
3416                                   int end_position = RelocInfo::kNoPosition) {
3417     return new (zone_) VariableProxy(zone_, var, start_position, end_position);
3418   }
3419
3420   VariableProxy* NewVariableProxy(const AstRawString* name,
3421                                   Variable::Kind variable_kind,
3422                                   int start_position = RelocInfo::kNoPosition,
3423                                   int end_position = RelocInfo::kNoPosition) {
3424     return new (zone_)
3425         VariableProxy(zone_, name, variable_kind, start_position, end_position);
3426   }
3427
3428   Property* NewProperty(Expression* obj, Expression* key, int pos) {
3429     return new (zone_) Property(zone_, obj, key, pos);
3430   }
3431
3432   Call* NewCall(Expression* expression,
3433                 ZoneList<Expression*>* arguments,
3434                 int pos) {
3435     return new (zone_) Call(zone_, expression, arguments, pos);
3436   }
3437
3438   CallNew* NewCallNew(Expression* expression,
3439                       ZoneList<Expression*>* arguments,
3440                       int pos) {
3441     return new (zone_) CallNew(zone_, expression, arguments, pos);
3442   }
3443
3444   CallRuntime* NewCallRuntime(const AstRawString* name,
3445                               const Runtime::Function* function,
3446                               ZoneList<Expression*>* arguments,
3447                               int pos) {
3448     return new (zone_) CallRuntime(zone_, name, function, arguments, pos);
3449   }
3450
3451   UnaryOperation* NewUnaryOperation(Token::Value op,
3452                                     Expression* expression,
3453                                     int pos) {
3454     return new (zone_) UnaryOperation(zone_, op, expression, pos);
3455   }
3456
3457   BinaryOperation* NewBinaryOperation(Token::Value op,
3458                                       Expression* left,
3459                                       Expression* right,
3460                                       int pos) {
3461     return new (zone_) BinaryOperation(zone_, op, left, right, pos);
3462   }
3463
3464   CountOperation* NewCountOperation(Token::Value op,
3465                                     bool is_prefix,
3466                                     Expression* expr,
3467                                     int pos) {
3468     return new (zone_) CountOperation(zone_, op, is_prefix, expr, pos);
3469   }
3470
3471   CompareOperation* NewCompareOperation(Token::Value op,
3472                                         Expression* left,
3473                                         Expression* right,
3474                                         int pos) {
3475     return new (zone_) CompareOperation(zone_, op, left, right, pos);
3476   }
3477
3478   Conditional* NewConditional(Expression* condition,
3479                               Expression* then_expression,
3480                               Expression* else_expression,
3481                               int position) {
3482     return new (zone_) Conditional(zone_, condition, then_expression,
3483                                    else_expression, position);
3484   }
3485
3486   Assignment* NewAssignment(Token::Value op,
3487                             Expression* target,
3488                             Expression* value,
3489                             int pos) {
3490     DCHECK(Token::IsAssignmentOp(op));
3491     Assignment* assign = new (zone_) Assignment(zone_, op, target, value, pos);
3492     if (assign->is_compound()) {
3493       DCHECK(Token::IsAssignmentOp(op));
3494       assign->binary_operation_ =
3495           NewBinaryOperation(assign->binary_op(), target, value, pos + 1);
3496     }
3497     return assign;
3498   }
3499
3500   Yield* NewYield(Expression *generator_object,
3501                   Expression* expression,
3502                   Yield::Kind yield_kind,
3503                   int pos) {
3504     if (!expression) expression = NewUndefinedLiteral(pos);
3505     return new (zone_)
3506         Yield(zone_, generator_object, expression, yield_kind, pos);
3507   }
3508
3509   Throw* NewThrow(Expression* exception, int pos) {
3510     return new (zone_) Throw(zone_, exception, pos);
3511   }
3512
3513   FunctionLiteral* NewFunctionLiteral(
3514       const AstRawString* name, AstValueFactory* ast_value_factory,
3515       Scope* scope, ZoneList<Statement*>* body, int materialized_literal_count,
3516       int expected_property_count, int handler_count, int parameter_count,
3517       FunctionLiteral::ParameterFlag has_duplicate_parameters,
3518       FunctionLiteral::FunctionType function_type,
3519       FunctionLiteral::IsFunctionFlag is_function,
3520       FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind,
3521       int position) {
3522     return new (zone_) FunctionLiteral(
3523         zone_, name, ast_value_factory, scope, body, materialized_literal_count,
3524         expected_property_count, handler_count, parameter_count, function_type,
3525         has_duplicate_parameters, is_function, is_parenthesized, kind,
3526         position);
3527   }
3528
3529   ClassLiteral* NewClassLiteral(const AstRawString* name, Scope* scope,
3530                                 VariableProxy* proxy, Expression* extends,
3531                                 FunctionLiteral* constructor,
3532                                 ZoneList<ObjectLiteral::Property*>* properties,
3533                                 int start_position, int end_position) {
3534     return new (zone_)
3535         ClassLiteral(zone_, name, scope, proxy, extends, constructor,
3536                      properties, start_position, end_position);
3537   }
3538
3539   NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name,
3540                                                   v8::Extension* extension,
3541                                                   int pos) {
3542     return new (zone_) NativeFunctionLiteral(zone_, name, extension, pos);
3543   }
3544
3545   ThisFunction* NewThisFunction(int pos) {
3546     return new (zone_) ThisFunction(zone_, pos);
3547   }
3548
3549   SuperReference* NewSuperReference(VariableProxy* this_var, int pos) {
3550     return new (zone_) SuperReference(zone_, this_var, pos);
3551   }
3552
3553  private:
3554   Zone* zone_;
3555   AstValueFactory* ast_value_factory_;
3556 };
3557
3558
3559 } }  // namespace v8::internal
3560
3561 #endif  // V8_AST_H_