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