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