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.
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"
29 // The abstract syntax tree is an intermediate, light-weight
30 // representation of the parsed JavaScript code suitable for
31 // compilation to native code.
33 // Nodes are allocated in a separate zone, which allows faster
34 // allocation and constant-time deallocation of the entire syntax
38 // ----------------------------------------------------------------------------
39 // Nodes of the abstract syntax tree. Only concrete classes are
42 #define DECLARATION_NODE_LIST(V) \
43 V(VariableDeclaration) \
44 V(FunctionDeclaration) \
45 V(ImportDeclaration) \
48 #define STATEMENT_NODE_LIST(V) \
50 V(ExpressionStatement) \
53 V(ContinueStatement) \
63 V(TryCatchStatement) \
64 V(TryFinallyStatement) \
67 #define EXPRESSION_NODE_LIST(V) \
70 V(NativeFunctionLiteral) \
93 #define AST_NODE_LIST(V) \
94 DECLARATION_NODE_LIST(V) \
95 STATEMENT_NODE_LIST(V) \
96 EXPRESSION_NODE_LIST(V)
98 // Forward declarations
103 class BreakableStatement;
105 class IterationStatement;
106 class MaterializedLiteral;
108 class TypeFeedbackOracle;
110 class RegExpAlternative;
111 class RegExpAssertion;
113 class RegExpBackReference;
115 class RegExpCharacterClass;
116 class RegExpCompiler;
117 class RegExpDisjunction;
119 class RegExpLookahead;
120 class RegExpQuantifier;
123 #define DEF_FORWARD_DECLARATION(type) class type;
124 AST_NODE_LIST(DEF_FORWARD_DECLARATION)
125 #undef DEF_FORWARD_DECLARATION
128 // Typedef only introduced to avoid unreadable code.
129 // Please do appreciate the required space in "> >".
130 typedef ZoneList<Handle<String> > ZoneStringList;
131 typedef ZoneList<Handle<Object> > ZoneObjectList;
134 #define DECLARE_NODE_TYPE(type) \
135 void Accept(AstVisitor* v) override; \
136 AstNode::NodeType node_type() const final { return AstNode::k##type; } \
137 friend class AstNodeFactory;
140 enum AstPropertiesFlag {
148 class FeedbackVectorRequirements {
150 FeedbackVectorRequirements(int slots, int ic_slots)
151 : slots_(slots), ic_slots_(ic_slots) {}
153 int slots() const { return slots_; }
154 int ic_slots() const { return ic_slots_; }
162 class VariableICSlotPair final {
164 VariableICSlotPair(Variable* variable, FeedbackVectorICSlot slot)
165 : variable_(variable), slot_(slot) {}
167 : variable_(NULL), slot_(FeedbackVectorICSlot::Invalid()) {}
169 Variable* variable() const { return variable_; }
170 FeedbackVectorICSlot slot() const { return slot_; }
174 FeedbackVectorICSlot slot_;
178 typedef List<VariableICSlotPair> ICSlotCache;
181 class AstProperties final BASE_EMBEDDED {
183 class Flags : public EnumSet<AstPropertiesFlag, int> {};
185 explicit AstProperties(Zone* zone) : node_count_(0), spec_(zone) {}
187 Flags* flags() { return &flags_; }
188 int node_count() { return node_count_; }
189 void add_node_count(int count) { node_count_ += count; }
191 int slots() const { return spec_.slots(); }
192 void increase_slots(int count) { spec_.increase_slots(count); }
194 int ic_slots() const { return spec_.ic_slots(); }
195 void increase_ic_slots(int count) { spec_.increase_ic_slots(count); }
196 void SetKind(int ic_slot, Code::Kind kind) { spec_.SetKind(ic_slot, kind); }
197 const ZoneFeedbackVectorSpec* get_spec() const { return &spec_; }
202 ZoneFeedbackVectorSpec spec_;
206 class AstNode: public ZoneObject {
208 #define DECLARE_TYPE_ENUM(type) k##type,
210 AST_NODE_LIST(DECLARE_TYPE_ENUM)
213 #undef DECLARE_TYPE_ENUM
215 void* operator new(size_t size, Zone* zone) { return zone->New(size); }
217 explicit AstNode(int position): position_(position) {}
218 virtual ~AstNode() {}
220 virtual void Accept(AstVisitor* v) = 0;
221 virtual NodeType node_type() const = 0;
222 int position() const { return position_; }
224 // Type testing & conversion functions overridden by concrete subclasses.
225 #define DECLARE_NODE_FUNCTIONS(type) \
226 bool Is##type() const { return node_type() == AstNode::k##type; } \
228 return Is##type() ? reinterpret_cast<type*>(this) : NULL; \
230 const type* As##type() const { \
231 return Is##type() ? reinterpret_cast<const type*>(this) : NULL; \
233 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
234 #undef DECLARE_NODE_FUNCTIONS
236 virtual BreakableStatement* AsBreakableStatement() { return NULL; }
237 virtual IterationStatement* AsIterationStatement() { return NULL; }
238 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; }
240 // The interface for feedback slots, with default no-op implementations for
241 // node types which don't actually have this. Note that this is conceptually
242 // not really nice, but multiple inheritance would introduce yet another
243 // vtable entry per node, something we don't want for space reasons.
244 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
245 Isolate* isolate, const ICSlotCache* cache) {
246 return FeedbackVectorRequirements(0, 0);
248 virtual void SetFirstFeedbackSlot(FeedbackVectorSlot slot) { UNREACHABLE(); }
249 virtual void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot,
250 ICSlotCache* cache) {
253 // Each ICSlot stores a kind of IC which the participating node should know.
254 virtual Code::Kind FeedbackICSlotKind(int index) {
256 return Code::NUMBER_OF_KINDS;
260 // Hidden to prevent accidental usage. It would have to load the
261 // current zone from the TLS.
262 void* operator new(size_t size);
264 friend class CaseClause; // Generates AST IDs.
270 class Statement : public AstNode {
272 explicit Statement(Zone* zone, int position) : AstNode(position) {}
274 bool IsEmpty() { return AsEmptyStatement() != NULL; }
275 virtual bool IsJump() const { return false; }
279 class SmallMapList final {
282 SmallMapList(int capacity, Zone* zone) : list_(capacity, zone) {}
284 void Reserve(int capacity, Zone* zone) { list_.Reserve(capacity, zone); }
285 void Clear() { list_.Clear(); }
286 void Sort() { list_.Sort(); }
288 bool is_empty() const { return list_.is_empty(); }
289 int length() const { return list_.length(); }
291 void AddMapIfMissing(Handle<Map> map, Zone* zone) {
292 if (!Map::TryUpdate(map).ToHandle(&map)) return;
293 for (int i = 0; i < length(); ++i) {
294 if (at(i).is_identical_to(map)) return;
299 void FilterForPossibleTransitions(Map* root_map) {
300 for (int i = list_.length() - 1; i >= 0; i--) {
301 if (at(i)->FindRootMap() != root_map) {
302 list_.RemoveElement(list_.at(i));
307 void Add(Handle<Map> handle, Zone* zone) {
308 list_.Add(handle.location(), zone);
311 Handle<Map> at(int i) const {
312 return Handle<Map>(list_.at(i));
315 Handle<Map> first() const { return at(0); }
316 Handle<Map> last() const { return at(length() - 1); }
319 // The list stores pointers to Map*, that is Map**, so it's GC safe.
320 SmallPointerList<Map*> list_;
322 DISALLOW_COPY_AND_ASSIGN(SmallMapList);
326 class Expression : public AstNode {
329 // Not assigned a context yet, or else will not be visited during
332 // Evaluated for its side effects.
334 // Evaluated for its value (and side effects).
336 // Evaluated for control flow (and side effects).
340 virtual bool IsValidReferenceExpression() const { return false; }
342 // Helpers for ToBoolean conversion.
343 virtual bool ToBooleanIsTrue() const { return false; }
344 virtual bool ToBooleanIsFalse() const { return false; }
346 // Symbols that cannot be parsed as array indices are considered property
347 // names. We do not treat symbols that can be array indexes as property
348 // names because [] for string objects is handled only by keyed ICs.
349 virtual bool IsPropertyName() const { return false; }
351 // True iff the expression is a literal represented as a smi.
352 bool IsSmiLiteral() const;
354 // True iff the expression is a string literal.
355 bool IsStringLiteral() const;
357 // True iff the expression is the null literal.
358 bool IsNullLiteral() const;
360 // True if we can prove that the expression is the undefined literal.
361 bool IsUndefinedLiteral(Isolate* isolate) const;
363 // Expression type bounds
364 Bounds bounds() const { return bounds_; }
365 void set_bounds(Bounds bounds) { bounds_ = bounds; }
367 // Type feedback information for assignments and properties.
368 virtual bool IsMonomorphic() {
372 virtual SmallMapList* GetReceiverTypes() {
376 virtual KeyedAccessStoreMode GetStoreMode() const {
378 return STANDARD_STORE;
380 virtual IcCheckType GetKeyType() const {
385 // TODO(rossberg): this should move to its own AST node eventually.
386 virtual void RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle);
387 byte to_boolean_types() const {
388 return ToBooleanTypesField::decode(bit_field_);
391 void set_base_id(int id) { base_id_ = id; }
392 static int num_ids() { return parent_num_ids() + 2; }
393 BailoutId id() const { return BailoutId(local_id(0)); }
394 TypeFeedbackId test_id() const { return TypeFeedbackId(local_id(1)); }
397 Expression(Zone* zone, int pos)
399 base_id_(BailoutId::None().ToInt()),
400 bounds_(Bounds::Unbounded(zone)),
402 static int parent_num_ids() { return 0; }
403 void set_to_boolean_types(byte types) {
404 bit_field_ = ToBooleanTypesField::update(bit_field_, types);
407 int base_id() const {
408 DCHECK(!BailoutId(base_id_).IsNone());
413 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
417 class ToBooleanTypesField : public BitField16<byte, 0, 8> {};
419 // Ends with 16-bit field; deriving classes in turn begin with
420 // 16-bit fields for optimum packing efficiency.
424 class BreakableStatement : public Statement {
427 TARGET_FOR_ANONYMOUS,
428 TARGET_FOR_NAMED_ONLY
431 // The labels associated with this statement. May be NULL;
432 // if it is != NULL, guaranteed to contain at least one entry.
433 ZoneList<const AstRawString*>* labels() const { return labels_; }
435 // Type testing & conversion.
436 BreakableStatement* AsBreakableStatement() final { return this; }
439 Label* break_target() { return &break_target_; }
442 bool is_target_for_anonymous() const {
443 return breakable_type_ == TARGET_FOR_ANONYMOUS;
446 void set_base_id(int id) { base_id_ = id; }
447 static int num_ids() { return parent_num_ids() + 2; }
448 BailoutId EntryId() const { return BailoutId(local_id(0)); }
449 BailoutId ExitId() const { return BailoutId(local_id(1)); }
452 BreakableStatement(Zone* zone, ZoneList<const AstRawString*>* labels,
453 BreakableType breakable_type, int position)
454 : Statement(zone, position),
456 breakable_type_(breakable_type),
457 base_id_(BailoutId::None().ToInt()) {
458 DCHECK(labels == NULL || labels->length() > 0);
460 static int parent_num_ids() { return 0; }
462 int base_id() const {
463 DCHECK(!BailoutId(base_id_).IsNone());
468 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
470 ZoneList<const AstRawString*>* labels_;
471 BreakableType breakable_type_;
477 class Block final : public BreakableStatement {
479 DECLARE_NODE_TYPE(Block)
481 void AddStatement(Statement* statement, Zone* zone) {
482 statements_.Add(statement, zone);
485 ZoneList<Statement*>* statements() { return &statements_; }
486 bool is_initializer_block() const { return is_initializer_block_; }
488 static int num_ids() { return parent_num_ids() + 1; }
489 BailoutId DeclsId() const { return BailoutId(local_id(0)); }
491 bool IsJump() const override {
492 return !statements_.is_empty() && statements_.last()->IsJump()
493 && labels() == NULL; // Good enough as an approximation...
496 Scope* scope() const { return scope_; }
497 void set_scope(Scope* scope) { scope_ = scope; }
500 Block(Zone* zone, ZoneList<const AstRawString*>* labels, int capacity,
501 bool is_initializer_block, int pos)
502 : BreakableStatement(zone, labels, TARGET_FOR_NAMED_ONLY, pos),
503 statements_(capacity, zone),
504 is_initializer_block_(is_initializer_block),
506 static int parent_num_ids() { return BreakableStatement::num_ids(); }
509 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
511 ZoneList<Statement*> statements_;
512 bool is_initializer_block_;
517 class Declaration : public AstNode {
519 VariableProxy* proxy() const { return proxy_; }
520 VariableMode mode() const { return mode_; }
521 Scope* scope() const { return scope_; }
522 virtual InitializationFlag initialization() const = 0;
523 virtual bool IsInlineable() const;
526 Declaration(Zone* zone, VariableProxy* proxy, VariableMode mode, Scope* scope,
528 : AstNode(pos), mode_(mode), proxy_(proxy), scope_(scope) {
529 DCHECK(IsDeclaredVariableMode(mode));
534 VariableProxy* proxy_;
536 // Nested scope from which the declaration originated.
541 class VariableDeclaration final : public Declaration {
543 DECLARE_NODE_TYPE(VariableDeclaration)
545 InitializationFlag initialization() const override {
546 return mode() == VAR ? kCreatedInitialized : kNeedsInitialization;
549 bool is_class_declaration() const { return is_class_declaration_; }
551 // VariableDeclarations can be grouped into consecutive declaration
552 // groups. Each VariableDeclaration is associated with the start position of
553 // the group it belongs to. The positions are used for strong mode scope
554 // checks for classes and functions.
555 int declaration_group_start() const { return declaration_group_start_; }
558 VariableDeclaration(Zone* zone, VariableProxy* proxy, VariableMode mode,
559 Scope* scope, int pos, bool is_class_declaration = false,
560 int declaration_group_start = -1)
561 : Declaration(zone, proxy, mode, scope, pos),
562 is_class_declaration_(is_class_declaration),
563 declaration_group_start_(declaration_group_start) {}
565 bool is_class_declaration_;
566 int declaration_group_start_;
570 class FunctionDeclaration final : public Declaration {
572 DECLARE_NODE_TYPE(FunctionDeclaration)
574 FunctionLiteral* fun() const { return fun_; }
575 InitializationFlag initialization() const override {
576 return kCreatedInitialized;
578 bool IsInlineable() const override;
581 FunctionDeclaration(Zone* zone,
582 VariableProxy* proxy,
584 FunctionLiteral* fun,
587 : Declaration(zone, proxy, mode, scope, pos),
589 DCHECK(mode == VAR || mode == LET || mode == CONST);
594 FunctionLiteral* fun_;
598 class ImportDeclaration final : public Declaration {
600 DECLARE_NODE_TYPE(ImportDeclaration)
602 const AstRawString* import_name() const { return import_name_; }
603 const AstRawString* module_specifier() const { return module_specifier_; }
604 void set_module_specifier(const AstRawString* module_specifier) {
605 DCHECK(module_specifier_ == NULL);
606 module_specifier_ = module_specifier;
608 InitializationFlag initialization() const override {
609 return kNeedsInitialization;
613 ImportDeclaration(Zone* zone, VariableProxy* proxy,
614 const AstRawString* import_name,
615 const AstRawString* module_specifier, Scope* scope, int pos)
616 : Declaration(zone, proxy, IMPORT, scope, pos),
617 import_name_(import_name),
618 module_specifier_(module_specifier) {}
621 const AstRawString* import_name_;
622 const AstRawString* module_specifier_;
626 class ExportDeclaration final : public Declaration {
628 DECLARE_NODE_TYPE(ExportDeclaration)
630 InitializationFlag initialization() const override {
631 return kCreatedInitialized;
635 ExportDeclaration(Zone* zone, VariableProxy* proxy, Scope* scope, int pos)
636 : Declaration(zone, proxy, LET, scope, pos) {}
640 class Module : public AstNode {
642 ModuleDescriptor* descriptor() const { return descriptor_; }
643 Block* body() const { return body_; }
646 Module(Zone* zone, int pos)
647 : AstNode(pos), descriptor_(ModuleDescriptor::New(zone)), body_(NULL) {}
648 Module(Zone* zone, ModuleDescriptor* descriptor, int pos, Block* body = NULL)
649 : AstNode(pos), descriptor_(descriptor), body_(body) {}
652 ModuleDescriptor* descriptor_;
657 class IterationStatement : public BreakableStatement {
659 // Type testing & conversion.
660 IterationStatement* AsIterationStatement() final { return this; }
662 Statement* body() const { return body_; }
664 static int num_ids() { return parent_num_ids() + 1; }
665 BailoutId OsrEntryId() const { return BailoutId(local_id(0)); }
666 virtual BailoutId ContinueId() const = 0;
667 virtual BailoutId StackCheckId() const = 0;
670 Label* continue_target() { return &continue_target_; }
673 IterationStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
674 : BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos),
676 static int parent_num_ids() { return BreakableStatement::num_ids(); }
677 void Initialize(Statement* body) { body_ = body; }
680 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
683 Label continue_target_;
687 class DoWhileStatement final : public IterationStatement {
689 DECLARE_NODE_TYPE(DoWhileStatement)
691 void Initialize(Expression* cond, Statement* body) {
692 IterationStatement::Initialize(body);
696 Expression* cond() const { return cond_; }
698 static int num_ids() { return parent_num_ids() + 2; }
699 BailoutId ContinueId() const override { return BailoutId(local_id(0)); }
700 BailoutId StackCheckId() const override { return BackEdgeId(); }
701 BailoutId BackEdgeId() const { return BailoutId(local_id(1)); }
704 DoWhileStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
705 : IterationStatement(zone, labels, pos), cond_(NULL) {}
706 static int parent_num_ids() { return IterationStatement::num_ids(); }
709 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
715 class WhileStatement final : public IterationStatement {
717 DECLARE_NODE_TYPE(WhileStatement)
719 void Initialize(Expression* cond, Statement* body) {
720 IterationStatement::Initialize(body);
724 Expression* cond() const { return cond_; }
726 static int num_ids() { return parent_num_ids() + 1; }
727 BailoutId ContinueId() const override { return EntryId(); }
728 BailoutId StackCheckId() const override { return BodyId(); }
729 BailoutId BodyId() const { return BailoutId(local_id(0)); }
732 WhileStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
733 : IterationStatement(zone, labels, pos), cond_(NULL) {}
734 static int parent_num_ids() { return IterationStatement::num_ids(); }
737 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
743 class ForStatement final : public IterationStatement {
745 DECLARE_NODE_TYPE(ForStatement)
747 void Initialize(Statement* init,
751 IterationStatement::Initialize(body);
757 Statement* init() const { return init_; }
758 Expression* cond() const { return cond_; }
759 Statement* next() const { return next_; }
761 static int num_ids() { return parent_num_ids() + 2; }
762 BailoutId ContinueId() const override { return BailoutId(local_id(0)); }
763 BailoutId StackCheckId() const override { return BodyId(); }
764 BailoutId BodyId() const { return BailoutId(local_id(1)); }
767 ForStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
768 : IterationStatement(zone, labels, pos),
772 static int parent_num_ids() { return IterationStatement::num_ids(); }
775 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
783 class ForEachStatement : public IterationStatement {
786 ENUMERATE, // for (each in subject) body;
787 ITERATE // for (each of subject) body;
790 void Initialize(Expression* each, Expression* subject, Statement* body) {
791 IterationStatement::Initialize(body);
796 Expression* each() const { return each_; }
797 Expression* subject() const { return subject_; }
800 ForEachStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
801 : IterationStatement(zone, labels, pos), each_(NULL), subject_(NULL) {}
805 Expression* subject_;
809 class ForInStatement final : public ForEachStatement {
811 DECLARE_NODE_TYPE(ForInStatement)
813 Expression* enumerable() const {
817 // Type feedback information.
818 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
819 Isolate* isolate, const ICSlotCache* cache) override {
820 return FeedbackVectorRequirements(1, 0);
822 void SetFirstFeedbackSlot(FeedbackVectorSlot slot) override {
823 for_in_feedback_slot_ = slot;
826 FeedbackVectorSlot ForInFeedbackSlot() {
827 DCHECK(!for_in_feedback_slot_.IsInvalid());
828 return for_in_feedback_slot_;
831 enum ForInType { FAST_FOR_IN, SLOW_FOR_IN };
832 ForInType for_in_type() const { return for_in_type_; }
833 void set_for_in_type(ForInType type) { for_in_type_ = type; }
835 static int num_ids() { return parent_num_ids() + 6; }
836 BailoutId BodyId() const { return BailoutId(local_id(0)); }
837 BailoutId PrepareId() const { return BailoutId(local_id(1)); }
838 BailoutId EnumId() const { return BailoutId(local_id(2)); }
839 BailoutId ToObjectId() const { return BailoutId(local_id(3)); }
840 BailoutId FilterId() const { return BailoutId(local_id(4)); }
841 BailoutId AssignmentId() const { return BailoutId(local_id(5)); }
842 BailoutId ContinueId() const override { return EntryId(); }
843 BailoutId StackCheckId() const override { return BodyId(); }
846 ForInStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
847 : ForEachStatement(zone, labels, pos),
848 for_in_type_(SLOW_FOR_IN),
849 for_in_feedback_slot_(FeedbackVectorSlot::Invalid()) {}
850 static int parent_num_ids() { return ForEachStatement::num_ids(); }
853 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
855 ForInType for_in_type_;
856 FeedbackVectorSlot for_in_feedback_slot_;
860 class ForOfStatement final : public ForEachStatement {
862 DECLARE_NODE_TYPE(ForOfStatement)
864 void Initialize(Expression* each,
867 Expression* assign_iterator,
868 Expression* next_result,
869 Expression* result_done,
870 Expression* assign_each) {
871 ForEachStatement::Initialize(each, subject, body);
872 assign_iterator_ = assign_iterator;
873 next_result_ = next_result;
874 result_done_ = result_done;
875 assign_each_ = assign_each;
878 Expression* iterable() const {
882 // iterator = subject[Symbol.iterator]()
883 Expression* assign_iterator() const {
884 return assign_iterator_;
887 // result = iterator.next() // with type check
888 Expression* next_result() const {
893 Expression* result_done() const {
897 // each = result.value
898 Expression* assign_each() const {
902 BailoutId ContinueId() const override { return EntryId(); }
903 BailoutId StackCheckId() const override { return BackEdgeId(); }
905 static int num_ids() { return parent_num_ids() + 1; }
906 BailoutId BackEdgeId() const { return BailoutId(local_id(0)); }
909 ForOfStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
910 : ForEachStatement(zone, labels, pos),
911 assign_iterator_(NULL),
914 assign_each_(NULL) {}
915 static int parent_num_ids() { return ForEachStatement::num_ids(); }
918 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
920 Expression* assign_iterator_;
921 Expression* next_result_;
922 Expression* result_done_;
923 Expression* assign_each_;
927 class ExpressionStatement final : public Statement {
929 DECLARE_NODE_TYPE(ExpressionStatement)
931 void set_expression(Expression* e) { expression_ = e; }
932 Expression* expression() const { return expression_; }
933 bool IsJump() const override { return expression_->IsThrow(); }
936 ExpressionStatement(Zone* zone, Expression* expression, int pos)
937 : Statement(zone, pos), expression_(expression) { }
940 Expression* expression_;
944 class JumpStatement : public Statement {
946 bool IsJump() const final { return true; }
949 explicit JumpStatement(Zone* zone, int pos) : Statement(zone, pos) {}
953 class ContinueStatement final : public JumpStatement {
955 DECLARE_NODE_TYPE(ContinueStatement)
957 IterationStatement* target() const { return target_; }
960 explicit ContinueStatement(Zone* zone, IterationStatement* target, int pos)
961 : JumpStatement(zone, pos), target_(target) { }
964 IterationStatement* target_;
968 class BreakStatement final : public JumpStatement {
970 DECLARE_NODE_TYPE(BreakStatement)
972 BreakableStatement* target() const { return target_; }
975 explicit BreakStatement(Zone* zone, BreakableStatement* target, int pos)
976 : JumpStatement(zone, pos), target_(target) { }
979 BreakableStatement* target_;
983 class ReturnStatement final : public JumpStatement {
985 DECLARE_NODE_TYPE(ReturnStatement)
987 Expression* expression() const { return expression_; }
990 explicit ReturnStatement(Zone* zone, Expression* expression, int pos)
991 : JumpStatement(zone, pos), expression_(expression) { }
994 Expression* expression_;
998 class WithStatement final : public Statement {
1000 DECLARE_NODE_TYPE(WithStatement)
1002 Scope* scope() { return scope_; }
1003 Expression* expression() const { return expression_; }
1004 Statement* statement() const { return statement_; }
1006 void set_base_id(int id) { base_id_ = id; }
1007 static int num_ids() { return parent_num_ids() + 1; }
1008 BailoutId EntryId() const { return BailoutId(local_id(0)); }
1011 WithStatement(Zone* zone, Scope* scope, Expression* expression,
1012 Statement* statement, int pos)
1013 : Statement(zone, pos),
1015 expression_(expression),
1016 statement_(statement),
1017 base_id_(BailoutId::None().ToInt()) {}
1018 static int parent_num_ids() { return 0; }
1020 int base_id() const {
1021 DCHECK(!BailoutId(base_id_).IsNone());
1026 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1029 Expression* expression_;
1030 Statement* statement_;
1035 class CaseClause final : public Expression {
1037 DECLARE_NODE_TYPE(CaseClause)
1039 bool is_default() const { return label_ == NULL; }
1040 Expression* label() const {
1041 CHECK(!is_default());
1044 Label* body_target() { return &body_target_; }
1045 ZoneList<Statement*>* statements() const { return statements_; }
1047 static int num_ids() { return parent_num_ids() + 2; }
1048 BailoutId EntryId() const { return BailoutId(local_id(0)); }
1049 TypeFeedbackId CompareId() { return TypeFeedbackId(local_id(1)); }
1051 Type* compare_type() { return compare_type_; }
1052 void set_compare_type(Type* type) { compare_type_ = type; }
1055 static int parent_num_ids() { return Expression::num_ids(); }
1058 CaseClause(Zone* zone, Expression* label, ZoneList<Statement*>* statements,
1060 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1064 ZoneList<Statement*>* statements_;
1065 Type* compare_type_;
1069 class SwitchStatement final : public BreakableStatement {
1071 DECLARE_NODE_TYPE(SwitchStatement)
1073 void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) {
1078 Expression* tag() const { return tag_; }
1079 ZoneList<CaseClause*>* cases() const { return cases_; }
1082 SwitchStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
1083 : BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos),
1089 ZoneList<CaseClause*>* cases_;
1093 // If-statements always have non-null references to their then- and
1094 // else-parts. When parsing if-statements with no explicit else-part,
1095 // the parser implicitly creates an empty statement. Use the
1096 // HasThenStatement() and HasElseStatement() functions to check if a
1097 // given if-statement has a then- or an else-part containing code.
1098 class IfStatement final : public Statement {
1100 DECLARE_NODE_TYPE(IfStatement)
1102 bool HasThenStatement() const { return !then_statement()->IsEmpty(); }
1103 bool HasElseStatement() const { return !else_statement()->IsEmpty(); }
1105 Expression* condition() const { return condition_; }
1106 Statement* then_statement() const { return then_statement_; }
1107 Statement* else_statement() const { return else_statement_; }
1109 bool IsJump() const override {
1110 return HasThenStatement() && then_statement()->IsJump()
1111 && HasElseStatement() && else_statement()->IsJump();
1114 void set_base_id(int id) { base_id_ = id; }
1115 static int num_ids() { return parent_num_ids() + 3; }
1116 BailoutId IfId() const { return BailoutId(local_id(0)); }
1117 BailoutId ThenId() const { return BailoutId(local_id(1)); }
1118 BailoutId ElseId() const { return BailoutId(local_id(2)); }
1121 IfStatement(Zone* zone, Expression* condition, Statement* then_statement,
1122 Statement* else_statement, int pos)
1123 : Statement(zone, pos),
1124 condition_(condition),
1125 then_statement_(then_statement),
1126 else_statement_(else_statement),
1127 base_id_(BailoutId::None().ToInt()) {}
1128 static int parent_num_ids() { return 0; }
1130 int base_id() const {
1131 DCHECK(!BailoutId(base_id_).IsNone());
1136 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1138 Expression* condition_;
1139 Statement* then_statement_;
1140 Statement* else_statement_;
1145 class TryStatement : public Statement {
1147 int index() const { return index_; }
1148 Block* try_block() const { return try_block_; }
1151 TryStatement(Zone* zone, int index, Block* try_block, int pos)
1152 : Statement(zone, pos), index_(index), try_block_(try_block) {}
1155 // Unique (per-function) index of this handler. This is not an AST ID.
1162 class TryCatchStatement final : public TryStatement {
1164 DECLARE_NODE_TYPE(TryCatchStatement)
1166 Scope* scope() { return scope_; }
1167 Variable* variable() { return variable_; }
1168 Block* catch_block() const { return catch_block_; }
1171 TryCatchStatement(Zone* zone,
1178 : TryStatement(zone, index, try_block, pos),
1180 variable_(variable),
1181 catch_block_(catch_block) {
1186 Variable* variable_;
1187 Block* catch_block_;
1191 class TryFinallyStatement final : public TryStatement {
1193 DECLARE_NODE_TYPE(TryFinallyStatement)
1195 Block* finally_block() const { return finally_block_; }
1198 TryFinallyStatement(
1199 Zone* zone, int index, Block* try_block, Block* finally_block, int pos)
1200 : TryStatement(zone, index, try_block, pos),
1201 finally_block_(finally_block) { }
1204 Block* finally_block_;
1208 class DebuggerStatement final : public Statement {
1210 DECLARE_NODE_TYPE(DebuggerStatement)
1212 void set_base_id(int id) { base_id_ = id; }
1213 static int num_ids() { return parent_num_ids() + 1; }
1214 BailoutId DebugBreakId() const { return BailoutId(local_id(0)); }
1217 explicit DebuggerStatement(Zone* zone, int pos)
1218 : Statement(zone, pos), base_id_(BailoutId::None().ToInt()) {}
1219 static int parent_num_ids() { return 0; }
1221 int base_id() const {
1222 DCHECK(!BailoutId(base_id_).IsNone());
1227 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1233 class EmptyStatement final : public Statement {
1235 DECLARE_NODE_TYPE(EmptyStatement)
1238 explicit EmptyStatement(Zone* zone, int pos): Statement(zone, pos) {}
1242 class Literal final : public Expression {
1244 DECLARE_NODE_TYPE(Literal)
1246 bool IsPropertyName() const override { return value_->IsPropertyName(); }
1248 Handle<String> AsPropertyName() {
1249 DCHECK(IsPropertyName());
1250 return Handle<String>::cast(value());
1253 const AstRawString* AsRawPropertyName() {
1254 DCHECK(IsPropertyName());
1255 return value_->AsString();
1258 bool ToBooleanIsTrue() const override { return value()->BooleanValue(); }
1259 bool ToBooleanIsFalse() const override { return !value()->BooleanValue(); }
1261 Handle<Object> value() const { return value_->value(); }
1262 const AstValue* raw_value() const { return value_; }
1264 // Support for using Literal as a HashMap key. NOTE: Currently, this works
1265 // only for string and number literals!
1267 static bool Match(void* literal1, void* literal2);
1269 static int num_ids() { return parent_num_ids() + 1; }
1270 TypeFeedbackId LiteralFeedbackId() const {
1271 return TypeFeedbackId(local_id(0));
1275 Literal(Zone* zone, const AstValue* value, int position)
1276 : Expression(zone, position), value_(value) {}
1277 static int parent_num_ids() { return Expression::num_ids(); }
1280 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1282 const AstValue* value_;
1286 // Base class for literals that needs space in the corresponding JSFunction.
1287 class MaterializedLiteral : public Expression {
1289 virtual MaterializedLiteral* AsMaterializedLiteral() { return this; }
1291 int literal_index() { return literal_index_; }
1294 // only callable after initialization.
1295 DCHECK(depth_ >= 1);
1299 bool is_strong() const { return is_strong_; }
1302 MaterializedLiteral(Zone* zone, int literal_index, bool is_strong, int pos)
1303 : Expression(zone, pos),
1304 literal_index_(literal_index),
1306 is_strong_(is_strong),
1309 // A materialized literal is simple if the values consist of only
1310 // constants and simple object and array literals.
1311 bool is_simple() const { return is_simple_; }
1312 void set_is_simple(bool is_simple) { is_simple_ = is_simple; }
1313 friend class CompileTimeValue;
1315 void set_depth(int depth) {
1320 // Populate the constant properties/elements fixed array.
1321 void BuildConstants(Isolate* isolate);
1322 friend class ArrayLiteral;
1323 friend class ObjectLiteral;
1325 // If the expression is a literal, return the literal value;
1326 // if the expression is a materialized literal and is simple return a
1327 // compile time value as encoded by CompileTimeValue::GetValue().
1328 // Otherwise, return undefined literal as the placeholder
1329 // in the object literal boilerplate.
1330 Handle<Object> GetBoilerplateValue(Expression* expression, Isolate* isolate);
1340 // Property is used for passing information
1341 // about an object literal's properties from the parser
1342 // to the code generator.
1343 class ObjectLiteralProperty final : public ZoneObject {
1346 CONSTANT, // Property with constant value (compile time).
1347 COMPUTED, // Property with computed value (execution time).
1348 MATERIALIZED_LITERAL, // Property value is a materialized literal.
1349 GETTER, SETTER, // Property is an accessor function.
1350 PROTOTYPE // Property is __proto__.
1353 Expression* key() { return key_; }
1354 Expression* value() { return value_; }
1355 Kind kind() { return kind_; }
1357 // Type feedback information.
1358 bool IsMonomorphic() { return !receiver_type_.is_null(); }
1359 Handle<Map> GetReceiverType() { return receiver_type_; }
1361 bool IsCompileTimeValue();
1363 void set_emit_store(bool emit_store);
1366 bool is_static() const { return is_static_; }
1367 bool is_computed_name() const { return is_computed_name_; }
1369 void set_receiver_type(Handle<Map> map) { receiver_type_ = map; }
1372 friend class AstNodeFactory;
1374 ObjectLiteralProperty(Expression* key, Expression* value, Kind kind,
1375 bool is_static, bool is_computed_name);
1376 ObjectLiteralProperty(AstValueFactory* ast_value_factory, Expression* key,
1377 Expression* value, bool is_static,
1378 bool is_computed_name);
1386 bool is_computed_name_;
1387 Handle<Map> receiver_type_;
1391 // An object literal has a boilerplate object that is used
1392 // for minimizing the work when constructing it at runtime.
1393 class ObjectLiteral final : public MaterializedLiteral {
1395 typedef ObjectLiteralProperty Property;
1397 DECLARE_NODE_TYPE(ObjectLiteral)
1399 Handle<FixedArray> constant_properties() const {
1400 return constant_properties_;
1402 int properties_count() const { return constant_properties_->length() / 2; }
1403 ZoneList<Property*>* properties() const { return properties_; }
1404 bool fast_elements() const { return fast_elements_; }
1405 bool may_store_doubles() const { return may_store_doubles_; }
1406 bool has_function() const { return has_function_; }
1407 bool has_elements() const { return has_elements_; }
1409 // Decide if a property should be in the object boilerplate.
1410 static bool IsBoilerplateProperty(Property* property);
1412 // Populate the constant properties fixed array.
1413 void BuildConstantProperties(Isolate* isolate);
1415 // Mark all computed expressions that are bound to a key that
1416 // is shadowed by a later occurrence of the same key. For the
1417 // marked expressions, no store code is emitted.
1418 void CalculateEmitStore(Zone* zone);
1420 // Assemble bitfield of flags for the CreateObjectLiteral helper.
1421 int ComputeFlags(bool disable_mementos = false) const {
1422 int flags = fast_elements() ? kFastElements : kNoFlags;
1423 flags |= has_function() ? kHasFunction : kNoFlags;
1424 if (depth() == 1 && !has_elements() && !may_store_doubles()) {
1425 flags |= kShallowProperties;
1427 if (disable_mementos) {
1428 flags |= kDisableMementos;
1439 kHasFunction = 1 << 1,
1440 kShallowProperties = 1 << 2,
1441 kDisableMementos = 1 << 3,
1445 struct Accessors: public ZoneObject {
1446 Accessors() : getter(NULL), setter(NULL) {}
1451 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); }
1453 // Return an AST id for a property that is used in simulate instructions.
1454 BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 1)); }
1456 // Unlike other AST nodes, this number of bailout IDs allocated for an
1457 // ObjectLiteral can vary, so num_ids() is not a static method.
1458 int num_ids() const { return parent_num_ids() + 1 + properties()->length(); }
1461 ObjectLiteral(Zone* zone, ZoneList<Property*>* properties, int literal_index,
1462 int boilerplate_properties, bool has_function,
1463 bool is_strong, int pos)
1464 : MaterializedLiteral(zone, literal_index, is_strong, pos),
1465 properties_(properties),
1466 boilerplate_properties_(boilerplate_properties),
1467 fast_elements_(false),
1468 has_elements_(false),
1469 may_store_doubles_(false),
1470 has_function_(has_function) {}
1471 static int parent_num_ids() { return MaterializedLiteral::num_ids(); }
1474 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1475 Handle<FixedArray> constant_properties_;
1476 ZoneList<Property*>* properties_;
1477 int boilerplate_properties_;
1478 bool fast_elements_;
1480 bool may_store_doubles_;
1485 // Node for capturing a regexp literal.
1486 class RegExpLiteral final : public MaterializedLiteral {
1488 DECLARE_NODE_TYPE(RegExpLiteral)
1490 Handle<String> pattern() const { return pattern_->string(); }
1491 Handle<String> flags() const { return flags_->string(); }
1494 RegExpLiteral(Zone* zone, const AstRawString* pattern,
1495 const AstRawString* flags, int literal_index, bool is_strong,
1497 : MaterializedLiteral(zone, literal_index, is_strong, pos),
1504 const AstRawString* pattern_;
1505 const AstRawString* flags_;
1509 // An array literal has a literals object that is used
1510 // for minimizing the work when constructing it at runtime.
1511 class ArrayLiteral final : public MaterializedLiteral {
1513 DECLARE_NODE_TYPE(ArrayLiteral)
1515 Handle<FixedArray> constant_elements() const { return constant_elements_; }
1516 ElementsKind constant_elements_kind() const {
1517 DCHECK_EQ(2, constant_elements_->length());
1518 return static_cast<ElementsKind>(
1519 Smi::cast(constant_elements_->get(0))->value());
1522 ZoneList<Expression*>* values() const { return values_; }
1524 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); }
1526 // Return an AST id for an element that is used in simulate instructions.
1527 BailoutId GetIdForElement(int i) { return BailoutId(local_id(i + 1)); }
1529 // Unlike other AST nodes, this number of bailout IDs allocated for an
1530 // ArrayLiteral can vary, so num_ids() is not a static method.
1531 int num_ids() const { return parent_num_ids() + 1 + values()->length(); }
1533 // Populate the constant elements fixed array.
1534 void BuildConstantElements(Isolate* isolate);
1536 // Assemble bitfield of flags for the CreateArrayLiteral helper.
1537 int ComputeFlags(bool disable_mementos = false) const {
1538 int flags = depth() == 1 ? kShallowElements : kNoFlags;
1539 if (disable_mementos) {
1540 flags |= kDisableMementos;
1550 kShallowElements = 1,
1551 kDisableMementos = 1 << 1,
1556 ArrayLiteral(Zone* zone, ZoneList<Expression*>* values, int literal_index,
1557 bool is_strong, int pos)
1558 : MaterializedLiteral(zone, literal_index, is_strong, pos),
1560 static int parent_num_ids() { return MaterializedLiteral::num_ids(); }
1563 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1565 Handle<FixedArray> constant_elements_;
1566 ZoneList<Expression*>* values_;
1570 class VariableProxy final : public Expression {
1572 DECLARE_NODE_TYPE(VariableProxy)
1574 bool IsValidReferenceExpression() const override { return !is_this(); }
1576 bool IsArguments() const { return is_resolved() && var()->is_arguments(); }
1578 Handle<String> name() const { return raw_name()->string(); }
1579 const AstRawString* raw_name() const {
1580 return is_resolved() ? var_->raw_name() : raw_name_;
1583 Variable* var() const {
1584 DCHECK(is_resolved());
1587 void set_var(Variable* v) {
1588 DCHECK(!is_resolved());
1593 bool is_this() const { return IsThisField::decode(bit_field_); }
1595 bool is_assigned() const { return IsAssignedField::decode(bit_field_); }
1596 void set_is_assigned() {
1597 bit_field_ = IsAssignedField::update(bit_field_, true);
1600 bool is_resolved() const { return IsResolvedField::decode(bit_field_); }
1601 void set_is_resolved() {
1602 bit_field_ = IsResolvedField::update(bit_field_, true);
1605 int end_position() const { return end_position_; }
1607 // Bind this proxy to the variable var.
1608 void BindTo(Variable* var);
1610 bool UsesVariableFeedbackSlot() const {
1611 return var()->IsUnallocated() || var()->IsLookupSlot();
1614 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
1615 Isolate* isolate, const ICSlotCache* cache) override;
1617 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot,
1618 ICSlotCache* cache) override;
1619 Code::Kind FeedbackICSlotKind(int index) override { return Code::LOAD_IC; }
1620 FeedbackVectorICSlot VariableFeedbackSlot() {
1621 DCHECK(!UsesVariableFeedbackSlot() || !variable_feedback_slot_.IsInvalid());
1622 return variable_feedback_slot_;
1625 static int num_ids() { return parent_num_ids() + 1; }
1626 BailoutId BeforeId() const { return BailoutId(local_id(0)); }
1629 VariableProxy(Zone* zone, Variable* var, int start_position,
1632 VariableProxy(Zone* zone, const AstRawString* name,
1633 Variable::Kind variable_kind, int start_position,
1635 static int parent_num_ids() { return Expression::num_ids(); }
1636 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1638 class IsThisField : public BitField8<bool, 0, 1> {};
1639 class IsAssignedField : public BitField8<bool, 1, 1> {};
1640 class IsResolvedField : public BitField8<bool, 2, 1> {};
1642 // Start with 16-bit (or smaller) field, which should get packed together
1643 // with Expression's trailing 16-bit field.
1645 FeedbackVectorICSlot variable_feedback_slot_;
1647 const AstRawString* raw_name_; // if !is_resolved_
1648 Variable* var_; // if is_resolved_
1650 // Position is stored in the AstNode superclass, but VariableProxy needs to
1651 // know its end position too (for error messages). It cannot be inferred from
1652 // the variable name length because it can contain escapes.
1657 class Property final : public Expression {
1659 DECLARE_NODE_TYPE(Property)
1661 bool IsValidReferenceExpression() const override { return true; }
1663 Expression* obj() const { return obj_; }
1664 Expression* key() const { return key_; }
1666 static int num_ids() { return parent_num_ids() + 1; }
1667 BailoutId LoadId() const { return BailoutId(local_id(0)); }
1669 bool IsStringAccess() const {
1670 return IsStringAccessField::decode(bit_field_);
1673 // Type feedback information.
1674 bool IsMonomorphic() override { return receiver_types_.length() == 1; }
1675 SmallMapList* GetReceiverTypes() override { return &receiver_types_; }
1676 KeyedAccessStoreMode GetStoreMode() const override { return STANDARD_STORE; }
1677 IcCheckType GetKeyType() const override {
1678 return KeyTypeField::decode(bit_field_);
1680 bool IsUninitialized() const {
1681 return !is_for_call() && HasNoTypeInformation();
1683 bool HasNoTypeInformation() const {
1684 return GetInlineCacheState() == UNINITIALIZED;
1686 InlineCacheState GetInlineCacheState() const {
1687 return InlineCacheStateField::decode(bit_field_);
1689 void set_is_string_access(bool b) {
1690 bit_field_ = IsStringAccessField::update(bit_field_, b);
1692 void set_key_type(IcCheckType key_type) {
1693 bit_field_ = KeyTypeField::update(bit_field_, key_type);
1695 void set_inline_cache_state(InlineCacheState state) {
1696 bit_field_ = InlineCacheStateField::update(bit_field_, state);
1698 void mark_for_call() {
1699 bit_field_ = IsForCallField::update(bit_field_, true);
1701 bool is_for_call() const { return IsForCallField::decode(bit_field_); }
1703 bool IsSuperAccess() {
1704 return obj()->IsSuperReference();
1707 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
1708 Isolate* isolate, const ICSlotCache* cache) override {
1709 return FeedbackVectorRequirements(0, 1);
1711 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot,
1712 ICSlotCache* cache) override {
1713 property_feedback_slot_ = slot;
1715 Code::Kind FeedbackICSlotKind(int index) override {
1716 return key()->IsPropertyName() ? Code::LOAD_IC : Code::KEYED_LOAD_IC;
1719 FeedbackVectorICSlot PropertyFeedbackSlot() const {
1720 DCHECK(!property_feedback_slot_.IsInvalid());
1721 return property_feedback_slot_;
1725 Property(Zone* zone, Expression* obj, Expression* key, int pos)
1726 : Expression(zone, pos),
1727 bit_field_(IsForCallField::encode(false) |
1728 IsStringAccessField::encode(false) |
1729 InlineCacheStateField::encode(UNINITIALIZED)),
1730 property_feedback_slot_(FeedbackVectorICSlot::Invalid()),
1733 static int parent_num_ids() { return Expression::num_ids(); }
1736 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1738 class IsForCallField : public BitField8<bool, 0, 1> {};
1739 class IsStringAccessField : public BitField8<bool, 1, 1> {};
1740 class KeyTypeField : public BitField8<IcCheckType, 2, 1> {};
1741 class InlineCacheStateField : public BitField8<InlineCacheState, 3, 4> {};
1743 FeedbackVectorICSlot property_feedback_slot_;
1746 SmallMapList receiver_types_;
1750 class Call final : public Expression {
1752 DECLARE_NODE_TYPE(Call)
1754 Expression* expression() const { return expression_; }
1755 ZoneList<Expression*>* arguments() const { return arguments_; }
1757 // Type feedback information.
1758 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
1759 Isolate* isolate, const ICSlotCache* cache) override;
1760 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot,
1761 ICSlotCache* cache) override {
1762 ic_slot_or_slot_ = slot.ToInt();
1764 void SetFirstFeedbackSlot(FeedbackVectorSlot slot) override {
1765 ic_slot_or_slot_ = slot.ToInt();
1767 Code::Kind FeedbackICSlotKind(int index) override { return Code::CALL_IC; }
1769 FeedbackVectorSlot CallFeedbackSlot() const {
1770 DCHECK(ic_slot_or_slot_ != FeedbackVectorSlot::Invalid().ToInt());
1771 return FeedbackVectorSlot(ic_slot_or_slot_);
1774 FeedbackVectorICSlot CallFeedbackICSlot() const {
1775 DCHECK(ic_slot_or_slot_ != FeedbackVectorICSlot::Invalid().ToInt());
1776 return FeedbackVectorICSlot(ic_slot_or_slot_);
1779 SmallMapList* GetReceiverTypes() override {
1780 if (expression()->IsProperty()) {
1781 return expression()->AsProperty()->GetReceiverTypes();
1786 bool IsMonomorphic() override {
1787 if (expression()->IsProperty()) {
1788 return expression()->AsProperty()->IsMonomorphic();
1790 return !target_.is_null();
1793 bool global_call() const {
1794 VariableProxy* proxy = expression_->AsVariableProxy();
1795 return proxy != NULL && proxy->var()->IsUnallocated();
1798 bool known_global_function() const {
1799 return global_call() && !target_.is_null();
1802 Handle<JSFunction> target() { return target_; }
1804 Handle<AllocationSite> allocation_site() { return allocation_site_; }
1806 void SetKnownGlobalTarget(Handle<JSFunction> target) {
1808 set_is_uninitialized(false);
1810 void set_target(Handle<JSFunction> target) { target_ = target; }
1811 void set_allocation_site(Handle<AllocationSite> site) {
1812 allocation_site_ = site;
1815 static int num_ids() { return parent_num_ids() + 2; }
1816 BailoutId ReturnId() const { return BailoutId(local_id(0)); }
1817 BailoutId EvalOrLookupId() const { return BailoutId(local_id(1)); }
1819 bool is_uninitialized() const {
1820 return IsUninitializedField::decode(bit_field_);
1822 void set_is_uninitialized(bool b) {
1823 bit_field_ = IsUninitializedField::update(bit_field_, b);
1835 // Helpers to determine how to handle the call.
1836 CallType GetCallType(Isolate* isolate) const;
1837 bool IsUsingCallFeedbackSlot(Isolate* isolate) const;
1838 bool IsUsingCallFeedbackICSlot(Isolate* isolate) const;
1841 // Used to assert that the FullCodeGenerator records the return site.
1842 bool return_is_recorded_;
1846 Call(Zone* zone, Expression* expression, ZoneList<Expression*>* arguments,
1848 : Expression(zone, pos),
1849 ic_slot_or_slot_(FeedbackVectorICSlot::Invalid().ToInt()),
1850 expression_(expression),
1851 arguments_(arguments),
1852 bit_field_(IsUninitializedField::encode(false)) {
1853 if (expression->IsProperty()) {
1854 expression->AsProperty()->mark_for_call();
1857 static int parent_num_ids() { return Expression::num_ids(); }
1860 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1862 // We store this as an integer because we don't know if we have a slot or
1863 // an ic slot until scoping time.
1864 int ic_slot_or_slot_;
1865 Expression* expression_;
1866 ZoneList<Expression*>* arguments_;
1867 Handle<JSFunction> target_;
1868 Handle<AllocationSite> allocation_site_;
1869 class IsUninitializedField : public BitField8<bool, 0, 1> {};
1874 class CallNew final : public Expression {
1876 DECLARE_NODE_TYPE(CallNew)
1878 Expression* expression() const { return expression_; }
1879 ZoneList<Expression*>* arguments() const { return arguments_; }
1881 // Type feedback information.
1882 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
1883 Isolate* isolate, const ICSlotCache* cache) override {
1884 return FeedbackVectorRequirements(FLAG_pretenuring_call_new ? 2 : 1, 0);
1886 void SetFirstFeedbackSlot(FeedbackVectorSlot slot) override {
1887 callnew_feedback_slot_ = slot;
1890 FeedbackVectorSlot CallNewFeedbackSlot() {
1891 DCHECK(!callnew_feedback_slot_.IsInvalid());
1892 return callnew_feedback_slot_;
1894 FeedbackVectorSlot AllocationSiteFeedbackSlot() {
1895 DCHECK(FLAG_pretenuring_call_new);
1896 return CallNewFeedbackSlot().next();
1899 bool IsMonomorphic() override { return is_monomorphic_; }
1900 Handle<JSFunction> target() const { return target_; }
1901 Handle<AllocationSite> allocation_site() const {
1902 return allocation_site_;
1905 static int num_ids() { return parent_num_ids() + 1; }
1906 static int feedback_slots() { return 1; }
1907 BailoutId ReturnId() const { return BailoutId(local_id(0)); }
1909 void set_allocation_site(Handle<AllocationSite> site) {
1910 allocation_site_ = site;
1912 void set_is_monomorphic(bool monomorphic) { is_monomorphic_ = monomorphic; }
1913 void set_target(Handle<JSFunction> target) { target_ = target; }
1914 void SetKnownGlobalTarget(Handle<JSFunction> target) {
1916 is_monomorphic_ = true;
1920 CallNew(Zone* zone, Expression* expression, ZoneList<Expression*>* arguments,
1922 : Expression(zone, pos),
1923 expression_(expression),
1924 arguments_(arguments),
1925 is_monomorphic_(false),
1926 callnew_feedback_slot_(FeedbackVectorSlot::Invalid()) {}
1928 static int parent_num_ids() { return Expression::num_ids(); }
1931 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1933 Expression* expression_;
1934 ZoneList<Expression*>* arguments_;
1935 bool is_monomorphic_;
1936 Handle<JSFunction> target_;
1937 Handle<AllocationSite> allocation_site_;
1938 FeedbackVectorSlot callnew_feedback_slot_;
1942 // The CallRuntime class does not represent any official JavaScript
1943 // language construct. Instead it is used to call a C or JS function
1944 // with a set of arguments. This is used from the builtins that are
1945 // implemented in JavaScript (see "v8natives.js").
1946 class CallRuntime final : public Expression {
1948 DECLARE_NODE_TYPE(CallRuntime)
1950 Handle<String> name() const { return raw_name_->string(); }
1951 const AstRawString* raw_name() const { return raw_name_; }
1952 const Runtime::Function* function() const { return function_; }
1953 ZoneList<Expression*>* arguments() const { return arguments_; }
1954 bool is_jsruntime() const { return function_ == NULL; }
1956 // Type feedback information.
1957 bool HasCallRuntimeFeedbackSlot() const { return is_jsruntime(); }
1958 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
1959 Isolate* isolate, const ICSlotCache* cache) override {
1960 return FeedbackVectorRequirements(0, HasCallRuntimeFeedbackSlot() ? 1 : 0);
1962 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot,
1963 ICSlotCache* cache) override {
1964 callruntime_feedback_slot_ = slot;
1966 Code::Kind FeedbackICSlotKind(int index) override { return Code::LOAD_IC; }
1968 FeedbackVectorICSlot CallRuntimeFeedbackSlot() {
1969 DCHECK(!HasCallRuntimeFeedbackSlot() ||
1970 !callruntime_feedback_slot_.IsInvalid());
1971 return callruntime_feedback_slot_;
1974 static int num_ids() { return parent_num_ids(); }
1977 CallRuntime(Zone* zone, const AstRawString* name,
1978 const Runtime::Function* function,
1979 ZoneList<Expression*>* arguments, int pos)
1980 : Expression(zone, pos),
1982 function_(function),
1983 arguments_(arguments),
1984 callruntime_feedback_slot_(FeedbackVectorICSlot::Invalid()) {}
1985 static int parent_num_ids() { return Expression::num_ids(); }
1988 const AstRawString* raw_name_;
1989 const Runtime::Function* function_;
1990 ZoneList<Expression*>* arguments_;
1991 FeedbackVectorICSlot callruntime_feedback_slot_;
1995 class UnaryOperation final : public Expression {
1997 DECLARE_NODE_TYPE(UnaryOperation)
1999 Token::Value op() const { return op_; }
2000 Expression* expression() const { return expression_; }
2002 // For unary not (Token::NOT), the AST ids where true and false will
2003 // actually be materialized, respectively.
2004 static int num_ids() { return parent_num_ids() + 2; }
2005 BailoutId MaterializeTrueId() const { return BailoutId(local_id(0)); }
2006 BailoutId MaterializeFalseId() const { return BailoutId(local_id(1)); }
2008 virtual void RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle) override;
2011 UnaryOperation(Zone* zone, Token::Value op, Expression* expression, int pos)
2012 : Expression(zone, pos), op_(op), expression_(expression) {
2013 DCHECK(Token::IsUnaryOp(op));
2015 static int parent_num_ids() { return Expression::num_ids(); }
2018 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2021 Expression* expression_;
2025 class BinaryOperation final : public Expression {
2027 DECLARE_NODE_TYPE(BinaryOperation)
2029 Token::Value op() const { return static_cast<Token::Value>(op_); }
2030 Expression* left() const { return left_; }
2031 Expression* right() const { return right_; }
2032 Handle<AllocationSite> allocation_site() const { return allocation_site_; }
2033 void set_allocation_site(Handle<AllocationSite> allocation_site) {
2034 allocation_site_ = allocation_site;
2037 // The short-circuit logical operations need an AST ID for their
2038 // right-hand subexpression.
2039 static int num_ids() { return parent_num_ids() + 2; }
2040 BailoutId RightId() const { return BailoutId(local_id(0)); }
2042 TypeFeedbackId BinaryOperationFeedbackId() const {
2043 return TypeFeedbackId(local_id(1));
2045 Maybe<int> fixed_right_arg() const {
2046 return has_fixed_right_arg_ ? Just(fixed_right_arg_value_) : Nothing<int>();
2048 void set_fixed_right_arg(Maybe<int> arg) {
2049 has_fixed_right_arg_ = arg.IsJust();
2050 if (arg.IsJust()) fixed_right_arg_value_ = arg.FromJust();
2053 virtual void RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle) override;
2056 BinaryOperation(Zone* zone, Token::Value op, Expression* left,
2057 Expression* right, int pos)
2058 : Expression(zone, pos),
2059 op_(static_cast<byte>(op)),
2060 has_fixed_right_arg_(false),
2061 fixed_right_arg_value_(0),
2064 DCHECK(Token::IsBinaryOp(op));
2066 static int parent_num_ids() { return Expression::num_ids(); }
2069 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2071 const byte op_; // actually Token::Value
2072 // TODO(rossberg): the fixed arg should probably be represented as a Constant
2073 // type for the RHS. Currenty it's actually a Maybe<int>
2074 bool has_fixed_right_arg_;
2075 int fixed_right_arg_value_;
2078 Handle<AllocationSite> allocation_site_;
2082 class CountOperation final : public Expression {
2084 DECLARE_NODE_TYPE(CountOperation)
2086 bool is_prefix() const { return IsPrefixField::decode(bit_field_); }
2087 bool is_postfix() const { return !is_prefix(); }
2089 Token::Value op() const { return TokenField::decode(bit_field_); }
2090 Token::Value binary_op() {
2091 return (op() == Token::INC) ? Token::ADD : Token::SUB;
2094 Expression* expression() const { return expression_; }
2096 bool IsMonomorphic() override { return receiver_types_.length() == 1; }
2097 SmallMapList* GetReceiverTypes() override { return &receiver_types_; }
2098 IcCheckType GetKeyType() const override {
2099 return KeyTypeField::decode(bit_field_);
2101 KeyedAccessStoreMode GetStoreMode() const override {
2102 return StoreModeField::decode(bit_field_);
2104 Type* type() const { return type_; }
2105 void set_key_type(IcCheckType type) {
2106 bit_field_ = KeyTypeField::update(bit_field_, type);
2108 void set_store_mode(KeyedAccessStoreMode mode) {
2109 bit_field_ = StoreModeField::update(bit_field_, mode);
2111 void set_type(Type* type) { type_ = type; }
2113 static int num_ids() { return parent_num_ids() + 4; }
2114 BailoutId AssignmentId() const { return BailoutId(local_id(0)); }
2115 BailoutId ToNumberId() const { return BailoutId(local_id(1)); }
2116 TypeFeedbackId CountBinOpFeedbackId() const {
2117 return TypeFeedbackId(local_id(2));
2119 TypeFeedbackId CountStoreFeedbackId() const {
2120 return TypeFeedbackId(local_id(3));
2124 CountOperation(Zone* zone, Token::Value op, bool is_prefix, Expression* expr,
2126 : Expression(zone, pos),
2127 bit_field_(IsPrefixField::encode(is_prefix) |
2128 KeyTypeField::encode(ELEMENT) |
2129 StoreModeField::encode(STANDARD_STORE) |
2130 TokenField::encode(op)),
2132 expression_(expr) {}
2133 static int parent_num_ids() { return Expression::num_ids(); }
2136 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2138 class IsPrefixField : public BitField16<bool, 0, 1> {};
2139 class KeyTypeField : public BitField16<IcCheckType, 1, 1> {};
2140 class StoreModeField : public BitField16<KeyedAccessStoreMode, 2, 4> {};
2141 class TokenField : public BitField16<Token::Value, 6, 8> {};
2143 // Starts with 16-bit field, which should get packed together with
2144 // Expression's trailing 16-bit field.
2145 uint16_t bit_field_;
2147 Expression* expression_;
2148 SmallMapList receiver_types_;
2152 class CompareOperation final : public Expression {
2154 DECLARE_NODE_TYPE(CompareOperation)
2156 Token::Value op() const { return op_; }
2157 Expression* left() const { return left_; }
2158 Expression* right() const { return right_; }
2160 // Type feedback information.
2161 static int num_ids() { return parent_num_ids() + 1; }
2162 TypeFeedbackId CompareOperationFeedbackId() const {
2163 return TypeFeedbackId(local_id(0));
2165 Type* combined_type() const { return combined_type_; }
2166 void set_combined_type(Type* type) { combined_type_ = type; }
2168 // Match special cases.
2169 bool IsLiteralCompareTypeof(Expression** expr, Handle<String>* check);
2170 bool IsLiteralCompareUndefined(Expression** expr, Isolate* isolate);
2171 bool IsLiteralCompareNull(Expression** expr);
2174 CompareOperation(Zone* zone, Token::Value op, Expression* left,
2175 Expression* right, int pos)
2176 : Expression(zone, pos),
2180 combined_type_(Type::None(zone)) {
2181 DCHECK(Token::IsCompareOp(op));
2183 static int parent_num_ids() { return Expression::num_ids(); }
2186 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2192 Type* combined_type_;
2196 class Spread final : public Expression {
2198 DECLARE_NODE_TYPE(Spread)
2200 Expression* expression() const { return expression_; }
2202 static int num_ids() { return parent_num_ids(); }
2205 Spread(Zone* zone, Expression* expression, int pos)
2206 : Expression(zone, pos), expression_(expression) {}
2207 static int parent_num_ids() { return Expression::num_ids(); }
2210 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2212 Expression* expression_;
2216 class Conditional final : public Expression {
2218 DECLARE_NODE_TYPE(Conditional)
2220 Expression* condition() const { return condition_; }
2221 Expression* then_expression() const { return then_expression_; }
2222 Expression* else_expression() const { return else_expression_; }
2224 static int num_ids() { return parent_num_ids() + 2; }
2225 BailoutId ThenId() const { return BailoutId(local_id(0)); }
2226 BailoutId ElseId() const { return BailoutId(local_id(1)); }
2229 Conditional(Zone* zone, Expression* condition, Expression* then_expression,
2230 Expression* else_expression, int position)
2231 : Expression(zone, position),
2232 condition_(condition),
2233 then_expression_(then_expression),
2234 else_expression_(else_expression) {}
2235 static int parent_num_ids() { return Expression::num_ids(); }
2238 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2240 Expression* condition_;
2241 Expression* then_expression_;
2242 Expression* else_expression_;
2246 class Assignment final : public Expression {
2248 DECLARE_NODE_TYPE(Assignment)
2250 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; }
2252 Token::Value binary_op() const;
2254 Token::Value op() const { return TokenField::decode(bit_field_); }
2255 Expression* target() const { return target_; }
2256 Expression* value() const { return value_; }
2257 BinaryOperation* binary_operation() const { return binary_operation_; }
2259 // This check relies on the definition order of token in token.h.
2260 bool is_compound() const { return op() > Token::ASSIGN; }
2262 static int num_ids() { return parent_num_ids() + 2; }
2263 BailoutId AssignmentId() const { return BailoutId(local_id(0)); }
2265 // Type feedback information.
2266 TypeFeedbackId AssignmentFeedbackId() { return TypeFeedbackId(local_id(1)); }
2267 bool IsMonomorphic() override { return receiver_types_.length() == 1; }
2268 bool IsUninitialized() const {
2269 return IsUninitializedField::decode(bit_field_);
2271 bool HasNoTypeInformation() {
2272 return IsUninitializedField::decode(bit_field_);
2274 SmallMapList* GetReceiverTypes() override { return &receiver_types_; }
2275 IcCheckType GetKeyType() const override {
2276 return KeyTypeField::decode(bit_field_);
2278 KeyedAccessStoreMode GetStoreMode() const override {
2279 return StoreModeField::decode(bit_field_);
2281 void set_is_uninitialized(bool b) {
2282 bit_field_ = IsUninitializedField::update(bit_field_, b);
2284 void set_key_type(IcCheckType key_type) {
2285 bit_field_ = KeyTypeField::update(bit_field_, key_type);
2287 void set_store_mode(KeyedAccessStoreMode mode) {
2288 bit_field_ = StoreModeField::update(bit_field_, mode);
2292 Assignment(Zone* zone, Token::Value op, Expression* target, Expression* value,
2294 static int parent_num_ids() { return Expression::num_ids(); }
2297 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2299 class IsUninitializedField : public BitField16<bool, 0, 1> {};
2300 class KeyTypeField : public BitField16<IcCheckType, 1, 1> {};
2301 class StoreModeField : public BitField16<KeyedAccessStoreMode, 2, 4> {};
2302 class TokenField : public BitField16<Token::Value, 6, 8> {};
2304 // Starts with 16-bit field, which should get packed together with
2305 // Expression's trailing 16-bit field.
2306 uint16_t bit_field_;
2307 Expression* target_;
2309 BinaryOperation* binary_operation_;
2310 SmallMapList receiver_types_;
2314 class Yield final : public Expression {
2316 DECLARE_NODE_TYPE(Yield)
2319 kInitial, // The initial yield that returns the unboxed generator object.
2320 kSuspend, // A normal yield: { value: EXPRESSION, done: false }
2321 kDelegating, // A yield*.
2322 kFinal // A return: { value: EXPRESSION, done: true }
2325 Expression* generator_object() const { return generator_object_; }
2326 Expression* expression() const { return expression_; }
2327 Kind yield_kind() const { return yield_kind_; }
2329 // Delegating yield surrounds the "yield" in a "try/catch". This index
2330 // locates the catch handler in the handler table, and is equivalent to
2331 // TryCatchStatement::index().
2333 DCHECK_EQ(kDelegating, yield_kind());
2336 void set_index(int index) {
2337 DCHECK_EQ(kDelegating, yield_kind());
2341 // Type feedback information.
2342 bool HasFeedbackSlots() const { return yield_kind() == kDelegating; }
2343 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
2344 Isolate* isolate, const ICSlotCache* cache) override {
2345 return FeedbackVectorRequirements(0, HasFeedbackSlots() ? 3 : 0);
2347 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot,
2348 ICSlotCache* cache) override {
2349 yield_first_feedback_slot_ = slot;
2351 Code::Kind FeedbackICSlotKind(int index) override {
2352 return index == 0 ? Code::KEYED_LOAD_IC : Code::LOAD_IC;
2355 FeedbackVectorICSlot KeyedLoadFeedbackSlot() {
2356 DCHECK(!HasFeedbackSlots() || !yield_first_feedback_slot_.IsInvalid());
2357 return yield_first_feedback_slot_;
2360 FeedbackVectorICSlot DoneFeedbackSlot() {
2361 return KeyedLoadFeedbackSlot().next();
2364 FeedbackVectorICSlot ValueFeedbackSlot() { return DoneFeedbackSlot().next(); }
2367 Yield(Zone* zone, Expression* generator_object, Expression* expression,
2368 Kind yield_kind, int pos)
2369 : Expression(zone, pos),
2370 generator_object_(generator_object),
2371 expression_(expression),
2372 yield_kind_(yield_kind),
2374 yield_first_feedback_slot_(FeedbackVectorICSlot::Invalid()) {}
2377 Expression* generator_object_;
2378 Expression* expression_;
2381 FeedbackVectorICSlot yield_first_feedback_slot_;
2385 class Throw final : public Expression {
2387 DECLARE_NODE_TYPE(Throw)
2389 Expression* exception() const { return exception_; }
2392 Throw(Zone* zone, Expression* exception, int pos)
2393 : Expression(zone, pos), exception_(exception) {}
2396 Expression* exception_;
2400 class FunctionLiteral final : public Expression {
2403 ANONYMOUS_EXPRESSION,
2408 enum ParameterFlag {
2409 kNoDuplicateParameters = 0,
2410 kHasDuplicateParameters = 1
2413 enum IsFunctionFlag {
2418 enum EagerCompileHint { kShouldEagerCompile, kShouldLazyCompile };
2420 enum ShouldBeUsedOnceHint { kShouldBeUsedOnce, kDontKnowIfShouldBeUsedOnce };
2422 enum ArityRestriction {
2428 DECLARE_NODE_TYPE(FunctionLiteral)
2430 Handle<String> name() const { return raw_name_->string(); }
2431 const AstRawString* raw_name() const { return raw_name_; }
2432 Scope* scope() const { return scope_; }
2433 ZoneList<Statement*>* body() const { return body_; }
2434 void set_function_token_position(int pos) { function_token_position_ = pos; }
2435 int function_token_position() const { return function_token_position_; }
2436 int start_position() const;
2437 int end_position() const;
2438 int SourceSize() const { return end_position() - start_position(); }
2439 bool is_expression() const { return IsExpression::decode(bitfield_); }
2440 bool is_anonymous() const { return IsAnonymous::decode(bitfield_); }
2441 LanguageMode language_mode() const;
2442 bool uses_super_property() const;
2444 static bool NeedsHomeObject(Expression* literal) {
2445 return literal != NULL && literal->IsFunctionLiteral() &&
2446 literal->AsFunctionLiteral()->uses_super_property();
2449 int materialized_literal_count() { return materialized_literal_count_; }
2450 int expected_property_count() { return expected_property_count_; }
2451 int handler_count() { return handler_count_; }
2452 int parameter_count() { return parameter_count_; }
2454 bool AllowsLazyCompilation();
2455 bool AllowsLazyCompilationWithoutContext();
2457 void InitializeSharedInfo(Handle<Code> code);
2459 Handle<String> debug_name() const {
2460 if (raw_name_ != NULL && !raw_name_->IsEmpty()) {
2461 return raw_name_->string();
2463 return inferred_name();
2466 Handle<String> inferred_name() const {
2467 if (!inferred_name_.is_null()) {
2468 DCHECK(raw_inferred_name_ == NULL);
2469 return inferred_name_;
2471 if (raw_inferred_name_ != NULL) {
2472 return raw_inferred_name_->string();
2475 return Handle<String>();
2478 // Only one of {set_inferred_name, set_raw_inferred_name} should be called.
2479 void set_inferred_name(Handle<String> inferred_name) {
2480 DCHECK(!inferred_name.is_null());
2481 inferred_name_ = inferred_name;
2482 DCHECK(raw_inferred_name_== NULL || raw_inferred_name_->IsEmpty());
2483 raw_inferred_name_ = NULL;
2486 void set_raw_inferred_name(const AstString* raw_inferred_name) {
2487 DCHECK(raw_inferred_name != NULL);
2488 raw_inferred_name_ = raw_inferred_name;
2489 DCHECK(inferred_name_.is_null());
2490 inferred_name_ = Handle<String>();
2493 // shared_info may be null if it's not cached in full code.
2494 Handle<SharedFunctionInfo> shared_info() { return shared_info_; }
2496 bool pretenure() { return Pretenure::decode(bitfield_); }
2497 void set_pretenure() { bitfield_ |= Pretenure::encode(true); }
2499 bool has_duplicate_parameters() {
2500 return HasDuplicateParameters::decode(bitfield_);
2503 bool is_function() { return IsFunction::decode(bitfield_) == kIsFunction; }
2505 // This is used as a heuristic on when to eagerly compile a function
2506 // literal. We consider the following constructs as hints that the
2507 // function will be called immediately:
2508 // - (function() { ... })();
2509 // - var x = function() { ... }();
2510 bool should_eager_compile() const {
2511 return EagerCompileHintBit::decode(bitfield_) == kShouldEagerCompile;
2513 void set_should_eager_compile() {
2514 bitfield_ = EagerCompileHintBit::update(bitfield_, kShouldEagerCompile);
2517 // A hint that we expect this function to be called (exactly) once,
2518 // i.e. we suspect it's an initialization function.
2519 bool should_be_used_once_hint() const {
2520 return ShouldBeUsedOnceHintBit::decode(bitfield_) == kShouldBeUsedOnce;
2522 void set_should_be_used_once_hint() {
2523 bitfield_ = ShouldBeUsedOnceHintBit::update(bitfield_, kShouldBeUsedOnce);
2526 FunctionKind kind() { return FunctionKindBits::decode(bitfield_); }
2528 int ast_node_count() { return ast_properties_.node_count(); }
2529 AstProperties::Flags* flags() { return ast_properties_.flags(); }
2530 void set_ast_properties(AstProperties* ast_properties) {
2531 ast_properties_ = *ast_properties;
2533 const ZoneFeedbackVectorSpec* feedback_vector_spec() const {
2534 return ast_properties_.get_spec();
2536 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; }
2537 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; }
2538 void set_dont_optimize_reason(BailoutReason reason) {
2539 dont_optimize_reason_ = reason;
2543 FunctionLiteral(Zone* zone, const AstRawString* name,
2544 AstValueFactory* ast_value_factory, Scope* scope,
2545 ZoneList<Statement*>* body, int materialized_literal_count,
2546 int expected_property_count, int handler_count,
2547 int parameter_count, FunctionType function_type,
2548 ParameterFlag has_duplicate_parameters,
2549 IsFunctionFlag is_function,
2550 EagerCompileHint eager_compile_hint, FunctionKind kind,
2552 : Expression(zone, position),
2556 raw_inferred_name_(ast_value_factory->empty_string()),
2557 ast_properties_(zone),
2558 dont_optimize_reason_(kNoReason),
2559 materialized_literal_count_(materialized_literal_count),
2560 expected_property_count_(expected_property_count),
2561 handler_count_(handler_count),
2562 parameter_count_(parameter_count),
2563 function_token_position_(RelocInfo::kNoPosition) {
2564 bitfield_ = IsExpression::encode(function_type != DECLARATION) |
2565 IsAnonymous::encode(function_type == ANONYMOUS_EXPRESSION) |
2566 Pretenure::encode(false) |
2567 HasDuplicateParameters::encode(has_duplicate_parameters) |
2568 IsFunction::encode(is_function) |
2569 EagerCompileHintBit::encode(eager_compile_hint) |
2570 FunctionKindBits::encode(kind) |
2571 ShouldBeUsedOnceHintBit::encode(kDontKnowIfShouldBeUsedOnce);
2572 DCHECK(IsValidFunctionKind(kind));
2576 const AstRawString* raw_name_;
2577 Handle<String> name_;
2578 Handle<SharedFunctionInfo> shared_info_;
2580 ZoneList<Statement*>* body_;
2581 const AstString* raw_inferred_name_;
2582 Handle<String> inferred_name_;
2583 AstProperties ast_properties_;
2584 BailoutReason dont_optimize_reason_;
2586 int materialized_literal_count_;
2587 int expected_property_count_;
2589 int parameter_count_;
2590 int function_token_position_;
2593 class IsExpression : public BitField<bool, 0, 1> {};
2594 class IsAnonymous : public BitField<bool, 1, 1> {};
2595 class Pretenure : public BitField<bool, 2, 1> {};
2596 class HasDuplicateParameters : public BitField<ParameterFlag, 3, 1> {};
2597 class IsFunction : public BitField<IsFunctionFlag, 4, 1> {};
2598 class EagerCompileHintBit : public BitField<EagerCompileHint, 5, 1> {};
2599 class FunctionKindBits : public BitField<FunctionKind, 6, 8> {};
2600 class ShouldBeUsedOnceHintBit : public BitField<ShouldBeUsedOnceHint, 15, 1> {
2605 class ClassLiteral final : public Expression {
2607 typedef ObjectLiteralProperty Property;
2609 DECLARE_NODE_TYPE(ClassLiteral)
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_; }
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 BailoutId CreateLiteralId() const { return BailoutId(local_id(3)); }
2626 // Return an AST id for a property that is used in simulate instructions.
2627 BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 4)); }
2629 // Unlike other AST nodes, this number of bailout IDs allocated for an
2630 // ClassLiteral can vary, so num_ids() is not a static method.
2631 int num_ids() const { return parent_num_ids() + 4 + properties()->length(); }
2634 ClassLiteral(Zone* zone, const AstRawString* name, Scope* scope,
2635 VariableProxy* class_variable_proxy, Expression* extends,
2636 FunctionLiteral* constructor, ZoneList<Property*>* properties,
2637 int start_position, int end_position)
2638 : Expression(zone, start_position),
2641 class_variable_proxy_(class_variable_proxy),
2643 constructor_(constructor),
2644 properties_(properties),
2645 end_position_(end_position) {}
2646 static int parent_num_ids() { return Expression::num_ids(); }
2649 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2651 const AstRawString* raw_name_;
2653 VariableProxy* class_variable_proxy_;
2654 Expression* extends_;
2655 FunctionLiteral* constructor_;
2656 ZoneList<Property*>* properties_;
2661 class NativeFunctionLiteral final : public Expression {
2663 DECLARE_NODE_TYPE(NativeFunctionLiteral)
2665 Handle<String> name() const { return name_->string(); }
2666 v8::Extension* extension() const { return extension_; }
2669 NativeFunctionLiteral(Zone* zone, const AstRawString* name,
2670 v8::Extension* extension, int pos)
2671 : Expression(zone, pos), name_(name), extension_(extension) {}
2674 const AstRawString* name_;
2675 v8::Extension* extension_;
2679 class ThisFunction final : public Expression {
2681 DECLARE_NODE_TYPE(ThisFunction)
2684 ThisFunction(Zone* zone, int pos) : Expression(zone, pos) {}
2688 class SuperReference final : public Expression {
2690 DECLARE_NODE_TYPE(SuperReference)
2692 VariableProxy* this_var() const { return this_var_; }
2694 static int num_ids() { return parent_num_ids(); }
2696 // Type feedback information.
2697 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
2698 Isolate* isolate, const ICSlotCache* cache) override {
2699 return FeedbackVectorRequirements(0, 1);
2701 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot,
2702 ICSlotCache* cache) override {
2703 homeobject_feedback_slot_ = slot;
2705 Code::Kind FeedbackICSlotKind(int index) override { return Code::LOAD_IC; }
2707 FeedbackVectorICSlot HomeObjectFeedbackSlot() {
2708 DCHECK(!homeobject_feedback_slot_.IsInvalid());
2709 return homeobject_feedback_slot_;
2713 SuperReference(Zone* zone, VariableProxy* this_var, int pos)
2714 : Expression(zone, pos),
2715 this_var_(this_var),
2716 homeobject_feedback_slot_(FeedbackVectorICSlot::Invalid()) {
2717 DCHECK(this_var->is_this());
2719 static int parent_num_ids() { return Expression::num_ids(); }
2722 VariableProxy* this_var_;
2723 FeedbackVectorICSlot homeobject_feedback_slot_;
2727 #undef DECLARE_NODE_TYPE
2730 // ----------------------------------------------------------------------------
2731 // Regular expressions
2734 class RegExpVisitor BASE_EMBEDDED {
2736 virtual ~RegExpVisitor() { }
2737 #define MAKE_CASE(Name) \
2738 virtual void* Visit##Name(RegExp##Name*, void* data) = 0;
2739 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_CASE)
2744 class RegExpTree : public ZoneObject {
2746 static const int kInfinity = kMaxInt;
2747 virtual ~RegExpTree() {}
2748 virtual void* Accept(RegExpVisitor* visitor, void* data) = 0;
2749 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2750 RegExpNode* on_success) = 0;
2751 virtual bool IsTextElement() { return false; }
2752 virtual bool IsAnchoredAtStart() { return false; }
2753 virtual bool IsAnchoredAtEnd() { return false; }
2754 virtual int min_match() = 0;
2755 virtual int max_match() = 0;
2756 // Returns the interval of registers used for captures within this
2758 virtual Interval CaptureRegisters() { return Interval::Empty(); }
2759 virtual void AppendToText(RegExpText* text, Zone* zone);
2760 std::ostream& Print(std::ostream& os, Zone* zone); // NOLINT
2761 #define MAKE_ASTYPE(Name) \
2762 virtual RegExp##Name* As##Name(); \
2763 virtual bool Is##Name();
2764 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_ASTYPE)
2769 class RegExpDisjunction final : public RegExpTree {
2771 explicit RegExpDisjunction(ZoneList<RegExpTree*>* alternatives);
2772 void* Accept(RegExpVisitor* visitor, void* data) override;
2773 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2774 RegExpNode* on_success) override;
2775 RegExpDisjunction* AsDisjunction() override;
2776 Interval CaptureRegisters() override;
2777 bool IsDisjunction() override;
2778 bool IsAnchoredAtStart() override;
2779 bool IsAnchoredAtEnd() override;
2780 int min_match() override { return min_match_; }
2781 int max_match() override { return max_match_; }
2782 ZoneList<RegExpTree*>* alternatives() { return alternatives_; }
2784 ZoneList<RegExpTree*>* alternatives_;
2790 class RegExpAlternative final : public RegExpTree {
2792 explicit RegExpAlternative(ZoneList<RegExpTree*>* nodes);
2793 void* Accept(RegExpVisitor* visitor, void* data) override;
2794 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2795 RegExpNode* on_success) override;
2796 RegExpAlternative* AsAlternative() override;
2797 Interval CaptureRegisters() override;
2798 bool IsAlternative() override;
2799 bool IsAnchoredAtStart() override;
2800 bool IsAnchoredAtEnd() override;
2801 int min_match() override { return min_match_; }
2802 int max_match() override { return max_match_; }
2803 ZoneList<RegExpTree*>* nodes() { return nodes_; }
2805 ZoneList<RegExpTree*>* nodes_;
2811 class RegExpAssertion final : public RegExpTree {
2813 enum AssertionType {
2821 explicit RegExpAssertion(AssertionType type) : assertion_type_(type) { }
2822 void* Accept(RegExpVisitor* visitor, void* data) override;
2823 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2824 RegExpNode* on_success) override;
2825 RegExpAssertion* AsAssertion() override;
2826 bool IsAssertion() override;
2827 bool IsAnchoredAtStart() override;
2828 bool IsAnchoredAtEnd() override;
2829 int min_match() override { return 0; }
2830 int max_match() override { return 0; }
2831 AssertionType assertion_type() { return assertion_type_; }
2833 AssertionType assertion_type_;
2837 class CharacterSet final BASE_EMBEDDED {
2839 explicit CharacterSet(uc16 standard_set_type)
2841 standard_set_type_(standard_set_type) {}
2842 explicit CharacterSet(ZoneList<CharacterRange>* ranges)
2844 standard_set_type_(0) {}
2845 ZoneList<CharacterRange>* ranges(Zone* zone);
2846 uc16 standard_set_type() { return standard_set_type_; }
2847 void set_standard_set_type(uc16 special_set_type) {
2848 standard_set_type_ = special_set_type;
2850 bool is_standard() { return standard_set_type_ != 0; }
2851 void Canonicalize();
2853 ZoneList<CharacterRange>* ranges_;
2854 // If non-zero, the value represents a standard set (e.g., all whitespace
2855 // characters) without having to expand the ranges.
2856 uc16 standard_set_type_;
2860 class RegExpCharacterClass final : public RegExpTree {
2862 RegExpCharacterClass(ZoneList<CharacterRange>* ranges, bool is_negated)
2864 is_negated_(is_negated) { }
2865 explicit RegExpCharacterClass(uc16 type)
2867 is_negated_(false) { }
2868 void* Accept(RegExpVisitor* visitor, void* data) override;
2869 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2870 RegExpNode* on_success) override;
2871 RegExpCharacterClass* AsCharacterClass() override;
2872 bool IsCharacterClass() override;
2873 bool IsTextElement() override { return true; }
2874 int min_match() override { return 1; }
2875 int max_match() override { return 1; }
2876 void AppendToText(RegExpText* text, Zone* zone) override;
2877 CharacterSet character_set() { return set_; }
2878 // TODO(lrn): Remove need for complex version if is_standard that
2879 // recognizes a mangled standard set and just do { return set_.is_special(); }
2880 bool is_standard(Zone* zone);
2881 // Returns a value representing the standard character set if is_standard()
2883 // Currently used values are:
2884 // s : unicode whitespace
2885 // S : unicode non-whitespace
2886 // w : ASCII word character (digit, letter, underscore)
2887 // W : non-ASCII word character
2889 // D : non-ASCII digit
2890 // . : non-unicode non-newline
2891 // * : All characters
2892 uc16 standard_type() { return set_.standard_set_type(); }
2893 ZoneList<CharacterRange>* ranges(Zone* zone) { return set_.ranges(zone); }
2894 bool is_negated() { return is_negated_; }
2902 class RegExpAtom final : public RegExpTree {
2904 explicit RegExpAtom(Vector<const uc16> data) : data_(data) { }
2905 void* Accept(RegExpVisitor* visitor, void* data) override;
2906 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2907 RegExpNode* on_success) override;
2908 RegExpAtom* AsAtom() override;
2909 bool IsAtom() override;
2910 bool IsTextElement() override { return true; }
2911 int min_match() override { return data_.length(); }
2912 int max_match() override { return data_.length(); }
2913 void AppendToText(RegExpText* text, Zone* zone) override;
2914 Vector<const uc16> data() { return data_; }
2915 int length() { return data_.length(); }
2917 Vector<const uc16> data_;
2921 class RegExpText final : public RegExpTree {
2923 explicit RegExpText(Zone* zone) : elements_(2, zone), length_(0) {}
2924 void* Accept(RegExpVisitor* visitor, void* data) override;
2925 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2926 RegExpNode* on_success) override;
2927 RegExpText* AsText() override;
2928 bool IsText() override;
2929 bool IsTextElement() override { return true; }
2930 int min_match() override { return length_; }
2931 int max_match() override { return length_; }
2932 void AppendToText(RegExpText* text, Zone* zone) override;
2933 void AddElement(TextElement elm, Zone* zone) {
2934 elements_.Add(elm, zone);
2935 length_ += elm.length();
2937 ZoneList<TextElement>* elements() { return &elements_; }
2939 ZoneList<TextElement> elements_;
2944 class RegExpQuantifier final : public RegExpTree {
2946 enum QuantifierType { GREEDY, NON_GREEDY, POSSESSIVE };
2947 RegExpQuantifier(int min, int max, QuantifierType type, RegExpTree* body)
2951 min_match_(min * body->min_match()),
2952 quantifier_type_(type) {
2953 if (max > 0 && body->max_match() > kInfinity / max) {
2954 max_match_ = kInfinity;
2956 max_match_ = max * body->max_match();
2959 void* Accept(RegExpVisitor* visitor, void* data) override;
2960 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2961 RegExpNode* on_success) override;
2962 static RegExpNode* ToNode(int min,
2966 RegExpCompiler* compiler,
2967 RegExpNode* on_success,
2968 bool not_at_start = false);
2969 RegExpQuantifier* AsQuantifier() override;
2970 Interval CaptureRegisters() override;
2971 bool IsQuantifier() override;
2972 int min_match() override { return min_match_; }
2973 int max_match() override { return max_match_; }
2974 int min() { return min_; }
2975 int max() { return max_; }
2976 bool is_possessive() { return quantifier_type_ == POSSESSIVE; }
2977 bool is_non_greedy() { return quantifier_type_ == NON_GREEDY; }
2978 bool is_greedy() { return quantifier_type_ == GREEDY; }
2979 RegExpTree* body() { return body_; }
2987 QuantifierType quantifier_type_;
2991 class RegExpCapture final : public RegExpTree {
2993 explicit RegExpCapture(RegExpTree* body, int index)
2994 : body_(body), index_(index) { }
2995 void* Accept(RegExpVisitor* visitor, void* data) override;
2996 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2997 RegExpNode* on_success) override;
2998 static RegExpNode* ToNode(RegExpTree* body,
3000 RegExpCompiler* compiler,
3001 RegExpNode* on_success);
3002 RegExpCapture* AsCapture() override;
3003 bool IsAnchoredAtStart() override;
3004 bool IsAnchoredAtEnd() override;
3005 Interval CaptureRegisters() override;
3006 bool IsCapture() override;
3007 int min_match() override { return body_->min_match(); }
3008 int max_match() override { return body_->max_match(); }
3009 RegExpTree* body() { return body_; }
3010 int index() { return index_; }
3011 static int StartRegister(int index) { return index * 2; }
3012 static int EndRegister(int index) { return index * 2 + 1; }
3020 class RegExpLookahead final : public RegExpTree {
3022 RegExpLookahead(RegExpTree* body,
3027 is_positive_(is_positive),
3028 capture_count_(capture_count),
3029 capture_from_(capture_from) { }
3031 void* Accept(RegExpVisitor* visitor, void* data) override;
3032 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
3033 RegExpNode* on_success) override;
3034 RegExpLookahead* AsLookahead() override;
3035 Interval CaptureRegisters() override;
3036 bool IsLookahead() override;
3037 bool IsAnchoredAtStart() override;
3038 int min_match() override { return 0; }
3039 int max_match() override { return 0; }
3040 RegExpTree* body() { return body_; }
3041 bool is_positive() { return is_positive_; }
3042 int capture_count() { return capture_count_; }
3043 int capture_from() { return capture_from_; }
3053 class RegExpBackReference final : public RegExpTree {
3055 explicit RegExpBackReference(RegExpCapture* capture)
3056 : capture_(capture) { }
3057 void* Accept(RegExpVisitor* visitor, void* data) override;
3058 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
3059 RegExpNode* on_success) override;
3060 RegExpBackReference* AsBackReference() override;
3061 bool IsBackReference() override;
3062 int min_match() override { return 0; }
3063 int max_match() override { return capture_->max_match(); }
3064 int index() { return capture_->index(); }
3065 RegExpCapture* capture() { return capture_; }
3067 RegExpCapture* capture_;
3071 class RegExpEmpty final : public RegExpTree {
3074 void* Accept(RegExpVisitor* visitor, void* data) override;
3075 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
3076 RegExpNode* on_success) override;
3077 RegExpEmpty* AsEmpty() override;
3078 bool IsEmpty() override;
3079 int min_match() override { return 0; }
3080 int max_match() override { return 0; }
3084 // ----------------------------------------------------------------------------
3086 // - leaf node visitors are abstract.
3088 class AstVisitor BASE_EMBEDDED {
3091 virtual ~AstVisitor() {}
3093 // Stack overflow check and dynamic dispatch.
3094 virtual void Visit(AstNode* node) = 0;
3096 // Iteration left-to-right.
3097 virtual void VisitDeclarations(ZoneList<Declaration*>* declarations);
3098 virtual void VisitStatements(ZoneList<Statement*>* statements);
3099 virtual void VisitExpressions(ZoneList<Expression*>* expressions);
3101 // Individual AST nodes.
3102 #define DEF_VISIT(type) \
3103 virtual void Visit##type(type* node) = 0;
3104 AST_NODE_LIST(DEF_VISIT)
3109 #define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS() \
3111 void Visit(AstNode* node) final { \
3112 if (!CheckStackOverflow()) node->Accept(this); \
3115 void SetStackOverflow() { stack_overflow_ = true; } \
3116 void ClearStackOverflow() { stack_overflow_ = false; } \
3117 bool HasStackOverflow() const { return stack_overflow_; } \
3119 bool CheckStackOverflow() { \
3120 if (stack_overflow_) return true; \
3121 StackLimitCheck check(isolate_); \
3122 if (!check.HasOverflowed()) return false; \
3123 stack_overflow_ = true; \
3128 void InitializeAstVisitor(Isolate* isolate, Zone* zone) { \
3129 isolate_ = isolate; \
3131 stack_overflow_ = false; \
3133 Zone* zone() { return zone_; } \
3134 Isolate* isolate() { return isolate_; } \
3136 Isolate* isolate_; \
3138 bool stack_overflow_
3141 // ----------------------------------------------------------------------------
3144 class AstNodeFactory final BASE_EMBEDDED {
3146 explicit AstNodeFactory(AstValueFactory* ast_value_factory)
3147 : zone_(ast_value_factory->zone()),
3148 ast_value_factory_(ast_value_factory) {}
3150 VariableDeclaration* NewVariableDeclaration(
3151 VariableProxy* proxy, VariableMode mode, Scope* scope, int pos,
3152 bool is_class_declaration = false, int declaration_group_start = -1) {
3154 VariableDeclaration(zone_, proxy, mode, scope, pos,
3155 is_class_declaration, declaration_group_start);
3158 FunctionDeclaration* NewFunctionDeclaration(VariableProxy* proxy,
3160 FunctionLiteral* fun,
3163 return new (zone_) FunctionDeclaration(zone_, proxy, mode, fun, scope, pos);
3166 ImportDeclaration* NewImportDeclaration(VariableProxy* proxy,
3167 const AstRawString* import_name,
3168 const AstRawString* module_specifier,
3169 Scope* scope, int pos) {
3170 return new (zone_) ImportDeclaration(zone_, proxy, import_name,
3171 module_specifier, scope, pos);
3174 ExportDeclaration* NewExportDeclaration(VariableProxy* proxy,
3177 return new (zone_) ExportDeclaration(zone_, proxy, scope, pos);
3180 Block* NewBlock(ZoneList<const AstRawString*>* labels,
3182 bool is_initializer_block,
3185 Block(zone_, labels, capacity, is_initializer_block, pos);
3188 #define STATEMENT_WITH_LABELS(NodeType) \
3189 NodeType* New##NodeType(ZoneList<const AstRawString*>* labels, int pos) { \
3190 return new (zone_) NodeType(zone_, labels, pos); \
3192 STATEMENT_WITH_LABELS(DoWhileStatement)
3193 STATEMENT_WITH_LABELS(WhileStatement)
3194 STATEMENT_WITH_LABELS(ForStatement)
3195 STATEMENT_WITH_LABELS(SwitchStatement)
3196 #undef STATEMENT_WITH_LABELS
3198 ForEachStatement* NewForEachStatement(ForEachStatement::VisitMode visit_mode,
3199 ZoneList<const AstRawString*>* labels,
3201 switch (visit_mode) {
3202 case ForEachStatement::ENUMERATE: {
3203 return new (zone_) ForInStatement(zone_, labels, pos);
3205 case ForEachStatement::ITERATE: {
3206 return new (zone_) ForOfStatement(zone_, labels, pos);
3213 ExpressionStatement* NewExpressionStatement(Expression* expression, int pos) {
3214 return new (zone_) ExpressionStatement(zone_, expression, pos);
3217 ContinueStatement* NewContinueStatement(IterationStatement* target, int pos) {
3218 return new (zone_) ContinueStatement(zone_, target, pos);
3221 BreakStatement* NewBreakStatement(BreakableStatement* target, int pos) {
3222 return new (zone_) BreakStatement(zone_, target, pos);
3225 ReturnStatement* NewReturnStatement(Expression* expression, int pos) {
3226 return new (zone_) ReturnStatement(zone_, expression, pos);
3229 WithStatement* NewWithStatement(Scope* scope,
3230 Expression* expression,
3231 Statement* statement,
3233 return new (zone_) WithStatement(zone_, scope, expression, statement, pos);
3236 IfStatement* NewIfStatement(Expression* condition,
3237 Statement* then_statement,
3238 Statement* else_statement,
3241 IfStatement(zone_, condition, then_statement, else_statement, pos);
3244 TryCatchStatement* NewTryCatchStatement(int index,
3250 return new (zone_) TryCatchStatement(zone_, index, try_block, scope,
3251 variable, catch_block, pos);
3254 TryFinallyStatement* NewTryFinallyStatement(int index,
3256 Block* finally_block,
3259 TryFinallyStatement(zone_, index, try_block, finally_block, pos);
3262 DebuggerStatement* NewDebuggerStatement(int pos) {
3263 return new (zone_) DebuggerStatement(zone_, pos);
3266 EmptyStatement* NewEmptyStatement(int pos) {
3267 return new(zone_) EmptyStatement(zone_, pos);
3270 CaseClause* NewCaseClause(
3271 Expression* label, ZoneList<Statement*>* statements, int pos) {
3272 return new (zone_) CaseClause(zone_, label, statements, pos);
3275 Literal* NewStringLiteral(const AstRawString* string, int pos) {
3277 Literal(zone_, ast_value_factory_->NewString(string), pos);
3280 // A JavaScript symbol (ECMA-262 edition 6).
3281 Literal* NewSymbolLiteral(const char* name, int pos) {
3282 return new (zone_) Literal(zone_, ast_value_factory_->NewSymbol(name), pos);
3285 Literal* NewNumberLiteral(double number, int pos) {
3287 Literal(zone_, ast_value_factory_->NewNumber(number), pos);
3290 Literal* NewSmiLiteral(int number, int pos) {
3291 return new (zone_) Literal(zone_, ast_value_factory_->NewSmi(number), pos);
3294 Literal* NewBooleanLiteral(bool b, int pos) {
3295 return new (zone_) Literal(zone_, ast_value_factory_->NewBoolean(b), pos);
3298 Literal* NewNullLiteral(int pos) {
3299 return new (zone_) Literal(zone_, ast_value_factory_->NewNull(), pos);
3302 Literal* NewUndefinedLiteral(int pos) {
3303 return new (zone_) Literal(zone_, ast_value_factory_->NewUndefined(), pos);
3306 Literal* NewTheHoleLiteral(int pos) {
3307 return new (zone_) Literal(zone_, ast_value_factory_->NewTheHole(), pos);
3310 ObjectLiteral* NewObjectLiteral(
3311 ZoneList<ObjectLiteral::Property*>* properties,
3313 int boilerplate_properties,
3317 return new (zone_) ObjectLiteral(zone_, properties, literal_index,
3318 boilerplate_properties, has_function,
3322 ObjectLiteral::Property* NewObjectLiteralProperty(
3323 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind,
3324 bool is_static, bool is_computed_name) {
3326 ObjectLiteral::Property(key, value, kind, is_static, is_computed_name);
3329 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key,
3332 bool is_computed_name) {
3333 return new (zone_) ObjectLiteral::Property(ast_value_factory_, key, value,
3334 is_static, is_computed_name);
3337 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern,
3338 const AstRawString* flags,
3342 return new (zone_) RegExpLiteral(zone_, pattern, flags, literal_index,
3346 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values,
3350 return new (zone_) ArrayLiteral(zone_, values, literal_index, is_strong,
3354 VariableProxy* NewVariableProxy(Variable* var,
3355 int start_position = RelocInfo::kNoPosition,
3356 int end_position = RelocInfo::kNoPosition) {
3357 return new (zone_) VariableProxy(zone_, var, start_position, end_position);
3360 VariableProxy* NewVariableProxy(const AstRawString* name,
3361 Variable::Kind variable_kind,
3362 int start_position = RelocInfo::kNoPosition,
3363 int end_position = RelocInfo::kNoPosition) {
3364 DCHECK_NOT_NULL(name);
3366 VariableProxy(zone_, name, variable_kind, start_position, end_position);
3369 Property* NewProperty(Expression* obj, Expression* key, int pos) {
3370 return new (zone_) Property(zone_, obj, key, pos);
3373 Call* NewCall(Expression* expression,
3374 ZoneList<Expression*>* arguments,
3376 return new (zone_) Call(zone_, expression, arguments, pos);
3379 CallNew* NewCallNew(Expression* expression,
3380 ZoneList<Expression*>* arguments,
3382 return new (zone_) CallNew(zone_, expression, arguments, pos);
3385 CallRuntime* NewCallRuntime(const AstRawString* name,
3386 const Runtime::Function* function,
3387 ZoneList<Expression*>* arguments,
3389 return new (zone_) CallRuntime(zone_, name, function, arguments, pos);
3392 UnaryOperation* NewUnaryOperation(Token::Value op,
3393 Expression* expression,
3395 return new (zone_) UnaryOperation(zone_, op, expression, pos);
3398 BinaryOperation* NewBinaryOperation(Token::Value op,
3402 return new (zone_) BinaryOperation(zone_, op, left, right, pos);
3405 CountOperation* NewCountOperation(Token::Value op,
3409 return new (zone_) CountOperation(zone_, op, is_prefix, expr, pos);
3412 CompareOperation* NewCompareOperation(Token::Value op,
3416 return new (zone_) CompareOperation(zone_, op, left, right, pos);
3419 Spread* NewSpread(Expression* expression, int pos) {
3420 return new (zone_) Spread(zone_, expression, pos);
3423 Conditional* NewConditional(Expression* condition,
3424 Expression* then_expression,
3425 Expression* else_expression,
3427 return new (zone_) Conditional(zone_, condition, then_expression,
3428 else_expression, position);
3431 Assignment* NewAssignment(Token::Value op,
3435 DCHECK(Token::IsAssignmentOp(op));
3436 Assignment* assign = new (zone_) Assignment(zone_, op, target, value, pos);
3437 if (assign->is_compound()) {
3438 DCHECK(Token::IsAssignmentOp(op));
3439 assign->binary_operation_ =
3440 NewBinaryOperation(assign->binary_op(), target, value, pos + 1);
3445 Yield* NewYield(Expression *generator_object,
3446 Expression* expression,
3447 Yield::Kind yield_kind,
3449 if (!expression) expression = NewUndefinedLiteral(pos);
3451 Yield(zone_, generator_object, expression, yield_kind, pos);
3454 Throw* NewThrow(Expression* exception, int pos) {
3455 return new (zone_) Throw(zone_, exception, pos);
3458 FunctionLiteral* NewFunctionLiteral(
3459 const AstRawString* name, AstValueFactory* ast_value_factory,
3460 Scope* scope, ZoneList<Statement*>* body, int materialized_literal_count,
3461 int expected_property_count, int handler_count, int parameter_count,
3462 FunctionLiteral::ParameterFlag has_duplicate_parameters,
3463 FunctionLiteral::FunctionType function_type,
3464 FunctionLiteral::IsFunctionFlag is_function,
3465 FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind kind,
3467 return new (zone_) FunctionLiteral(
3468 zone_, name, ast_value_factory, scope, body, materialized_literal_count,
3469 expected_property_count, handler_count, parameter_count, function_type,
3470 has_duplicate_parameters, is_function, eager_compile_hint, kind,
3474 ClassLiteral* NewClassLiteral(const AstRawString* name, Scope* scope,
3475 VariableProxy* proxy, Expression* extends,
3476 FunctionLiteral* constructor,
3477 ZoneList<ObjectLiteral::Property*>* properties,
3478 int start_position, int end_position) {
3480 ClassLiteral(zone_, name, scope, proxy, extends, constructor,
3481 properties, start_position, end_position);
3484 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name,
3485 v8::Extension* extension,
3487 return new (zone_) NativeFunctionLiteral(zone_, name, extension, pos);
3490 ThisFunction* NewThisFunction(int pos) {
3491 return new (zone_) ThisFunction(zone_, pos);
3494 SuperReference* NewSuperReference(VariableProxy* this_var, int pos) {
3495 return new (zone_) SuperReference(zone_, this_var, pos);
3500 AstValueFactory* ast_value_factory_;
3504 } } // namespace v8::internal