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() + 2; }
1667 BailoutId LoadId() const { return BailoutId(local_id(0)); }
1668 TypeFeedbackId PropertyFeedbackId() { return TypeFeedbackId(local_id(1)); }
1670 bool IsStringAccess() const {
1671 return IsStringAccessField::decode(bit_field_);
1674 // Type feedback information.
1675 bool IsMonomorphic() override { return receiver_types_.length() == 1; }
1676 SmallMapList* GetReceiverTypes() override { return &receiver_types_; }
1677 KeyedAccessStoreMode GetStoreMode() const override { return STANDARD_STORE; }
1678 IcCheckType GetKeyType() const override {
1679 return KeyTypeField::decode(bit_field_);
1681 bool IsUninitialized() const {
1682 return !is_for_call() && HasNoTypeInformation();
1684 bool HasNoTypeInformation() const {
1685 return GetInlineCacheState() == UNINITIALIZED;
1687 InlineCacheState GetInlineCacheState() const {
1688 return InlineCacheStateField::decode(bit_field_);
1690 void set_is_string_access(bool b) {
1691 bit_field_ = IsStringAccessField::update(bit_field_, b);
1693 void set_key_type(IcCheckType key_type) {
1694 bit_field_ = KeyTypeField::update(bit_field_, key_type);
1696 void set_inline_cache_state(InlineCacheState state) {
1697 bit_field_ = InlineCacheStateField::update(bit_field_, state);
1699 void mark_for_call() {
1700 bit_field_ = IsForCallField::update(bit_field_, true);
1702 bool is_for_call() const { return IsForCallField::decode(bit_field_); }
1704 bool IsSuperAccess() {
1705 return obj()->IsSuperReference();
1708 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
1709 Isolate* isolate, const ICSlotCache* cache) override {
1710 return FeedbackVectorRequirements(0, 1);
1712 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot,
1713 ICSlotCache* cache) override {
1714 property_feedback_slot_ = slot;
1716 Code::Kind FeedbackICSlotKind(int index) override {
1717 return key()->IsPropertyName() ? Code::LOAD_IC : Code::KEYED_LOAD_IC;
1720 FeedbackVectorICSlot PropertyFeedbackSlot() const {
1721 DCHECK(!property_feedback_slot_.IsInvalid());
1722 return property_feedback_slot_;
1726 Property(Zone* zone, Expression* obj, Expression* key, int pos)
1727 : Expression(zone, pos),
1728 bit_field_(IsForCallField::encode(false) |
1729 IsStringAccessField::encode(false) |
1730 InlineCacheStateField::encode(UNINITIALIZED)),
1731 property_feedback_slot_(FeedbackVectorICSlot::Invalid()),
1734 static int parent_num_ids() { return Expression::num_ids(); }
1737 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1739 class IsForCallField : public BitField8<bool, 0, 1> {};
1740 class IsStringAccessField : public BitField8<bool, 1, 1> {};
1741 class KeyTypeField : public BitField8<IcCheckType, 2, 1> {};
1742 class InlineCacheStateField : public BitField8<InlineCacheState, 3, 4> {};
1744 FeedbackVectorICSlot property_feedback_slot_;
1747 SmallMapList receiver_types_;
1751 class Call final : public Expression {
1753 DECLARE_NODE_TYPE(Call)
1755 Expression* expression() const { return expression_; }
1756 ZoneList<Expression*>* arguments() const { return arguments_; }
1758 // Type feedback information.
1759 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
1760 Isolate* isolate, const ICSlotCache* cache) override;
1761 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot,
1762 ICSlotCache* cache) override {
1763 ic_slot_or_slot_ = slot.ToInt();
1765 void SetFirstFeedbackSlot(FeedbackVectorSlot slot) override {
1766 ic_slot_or_slot_ = slot.ToInt();
1768 Code::Kind FeedbackICSlotKind(int index) override { return Code::CALL_IC; }
1770 FeedbackVectorSlot CallFeedbackSlot() const {
1771 DCHECK(ic_slot_or_slot_ != FeedbackVectorSlot::Invalid().ToInt());
1772 return FeedbackVectorSlot(ic_slot_or_slot_);
1775 FeedbackVectorICSlot CallFeedbackICSlot() const {
1776 DCHECK(ic_slot_or_slot_ != FeedbackVectorICSlot::Invalid().ToInt());
1777 return FeedbackVectorICSlot(ic_slot_or_slot_);
1780 SmallMapList* GetReceiverTypes() override {
1781 if (expression()->IsProperty()) {
1782 return expression()->AsProperty()->GetReceiverTypes();
1787 bool IsMonomorphic() override {
1788 if (expression()->IsProperty()) {
1789 return expression()->AsProperty()->IsMonomorphic();
1791 return !target_.is_null();
1794 bool global_call() const {
1795 VariableProxy* proxy = expression_->AsVariableProxy();
1796 return proxy != NULL && proxy->var()->IsUnallocated();
1799 bool known_global_function() const {
1800 return global_call() && !target_.is_null();
1803 Handle<JSFunction> target() { return target_; }
1805 Handle<AllocationSite> allocation_site() { return allocation_site_; }
1807 void SetKnownGlobalTarget(Handle<JSFunction> target) {
1809 set_is_uninitialized(false);
1811 void set_target(Handle<JSFunction> target) { target_ = target; }
1812 void set_allocation_site(Handle<AllocationSite> site) {
1813 allocation_site_ = site;
1816 static int num_ids() { return parent_num_ids() + 2; }
1817 BailoutId ReturnId() const { return BailoutId(local_id(0)); }
1818 BailoutId EvalOrLookupId() const { return BailoutId(local_id(1)); }
1820 bool is_uninitialized() const {
1821 return IsUninitializedField::decode(bit_field_);
1823 void set_is_uninitialized(bool b) {
1824 bit_field_ = IsUninitializedField::update(bit_field_, b);
1836 // Helpers to determine how to handle the call.
1837 CallType GetCallType(Isolate* isolate) const;
1838 bool IsUsingCallFeedbackSlot(Isolate* isolate) const;
1839 bool IsUsingCallFeedbackICSlot(Isolate* isolate) const;
1842 // Used to assert that the FullCodeGenerator records the return site.
1843 bool return_is_recorded_;
1847 Call(Zone* zone, Expression* expression, ZoneList<Expression*>* arguments,
1849 : Expression(zone, pos),
1850 ic_slot_or_slot_(FeedbackVectorICSlot::Invalid().ToInt()),
1851 expression_(expression),
1852 arguments_(arguments),
1853 bit_field_(IsUninitializedField::encode(false)) {
1854 if (expression->IsProperty()) {
1855 expression->AsProperty()->mark_for_call();
1858 static int parent_num_ids() { return Expression::num_ids(); }
1861 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1863 // We store this as an integer because we don't know if we have a slot or
1864 // an ic slot until scoping time.
1865 int ic_slot_or_slot_;
1866 Expression* expression_;
1867 ZoneList<Expression*>* arguments_;
1868 Handle<JSFunction> target_;
1869 Handle<AllocationSite> allocation_site_;
1870 class IsUninitializedField : public BitField8<bool, 0, 1> {};
1875 class CallNew final : public Expression {
1877 DECLARE_NODE_TYPE(CallNew)
1879 Expression* expression() const { return expression_; }
1880 ZoneList<Expression*>* arguments() const { return arguments_; }
1882 // Type feedback information.
1883 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
1884 Isolate* isolate, const ICSlotCache* cache) override {
1885 return FeedbackVectorRequirements(FLAG_pretenuring_call_new ? 2 : 1, 0);
1887 void SetFirstFeedbackSlot(FeedbackVectorSlot slot) override {
1888 callnew_feedback_slot_ = slot;
1891 FeedbackVectorSlot CallNewFeedbackSlot() {
1892 DCHECK(!callnew_feedback_slot_.IsInvalid());
1893 return callnew_feedback_slot_;
1895 FeedbackVectorSlot AllocationSiteFeedbackSlot() {
1896 DCHECK(FLAG_pretenuring_call_new);
1897 return CallNewFeedbackSlot().next();
1900 bool IsMonomorphic() override { return is_monomorphic_; }
1901 Handle<JSFunction> target() const { return target_; }
1902 Handle<AllocationSite> allocation_site() const {
1903 return allocation_site_;
1906 static int num_ids() { return parent_num_ids() + 1; }
1907 static int feedback_slots() { return 1; }
1908 BailoutId ReturnId() const { return BailoutId(local_id(0)); }
1910 void set_allocation_site(Handle<AllocationSite> site) {
1911 allocation_site_ = site;
1913 void set_is_monomorphic(bool monomorphic) { is_monomorphic_ = monomorphic; }
1914 void set_target(Handle<JSFunction> target) { target_ = target; }
1915 void SetKnownGlobalTarget(Handle<JSFunction> target) {
1917 is_monomorphic_ = true;
1921 CallNew(Zone* zone, Expression* expression, ZoneList<Expression*>* arguments,
1923 : Expression(zone, pos),
1924 expression_(expression),
1925 arguments_(arguments),
1926 is_monomorphic_(false),
1927 callnew_feedback_slot_(FeedbackVectorSlot::Invalid()) {}
1929 static int parent_num_ids() { return Expression::num_ids(); }
1932 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1934 Expression* expression_;
1935 ZoneList<Expression*>* arguments_;
1936 bool is_monomorphic_;
1937 Handle<JSFunction> target_;
1938 Handle<AllocationSite> allocation_site_;
1939 FeedbackVectorSlot callnew_feedback_slot_;
1943 // The CallRuntime class does not represent any official JavaScript
1944 // language construct. Instead it is used to call a C or JS function
1945 // with a set of arguments. This is used from the builtins that are
1946 // implemented in JavaScript (see "v8natives.js").
1947 class CallRuntime final : public Expression {
1949 DECLARE_NODE_TYPE(CallRuntime)
1951 Handle<String> name() const { return raw_name_->string(); }
1952 const AstRawString* raw_name() const { return raw_name_; }
1953 const Runtime::Function* function() const { return function_; }
1954 ZoneList<Expression*>* arguments() const { return arguments_; }
1955 bool is_jsruntime() const { return function_ == NULL; }
1957 // Type feedback information.
1958 bool HasCallRuntimeFeedbackSlot() const { return is_jsruntime(); }
1959 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
1960 Isolate* isolate, const ICSlotCache* cache) override {
1961 return FeedbackVectorRequirements(0, HasCallRuntimeFeedbackSlot() ? 1 : 0);
1963 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot,
1964 ICSlotCache* cache) override {
1965 callruntime_feedback_slot_ = slot;
1967 Code::Kind FeedbackICSlotKind(int index) override { return Code::LOAD_IC; }
1969 FeedbackVectorICSlot CallRuntimeFeedbackSlot() {
1970 DCHECK(!HasCallRuntimeFeedbackSlot() ||
1971 !callruntime_feedback_slot_.IsInvalid());
1972 return callruntime_feedback_slot_;
1975 static int num_ids() { return parent_num_ids() + 1; }
1976 TypeFeedbackId CallRuntimeFeedbackId() const {
1977 return TypeFeedbackId(local_id(0));
1981 CallRuntime(Zone* zone, const AstRawString* name,
1982 const Runtime::Function* function,
1983 ZoneList<Expression*>* arguments, int pos)
1984 : Expression(zone, pos),
1986 function_(function),
1987 arguments_(arguments),
1988 callruntime_feedback_slot_(FeedbackVectorICSlot::Invalid()) {}
1989 static int parent_num_ids() { return Expression::num_ids(); }
1992 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1994 const AstRawString* raw_name_;
1995 const Runtime::Function* function_;
1996 ZoneList<Expression*>* arguments_;
1997 FeedbackVectorICSlot callruntime_feedback_slot_;
2001 class UnaryOperation final : public Expression {
2003 DECLARE_NODE_TYPE(UnaryOperation)
2005 Token::Value op() const { return op_; }
2006 Expression* expression() const { return expression_; }
2008 // For unary not (Token::NOT), the AST ids where true and false will
2009 // actually be materialized, respectively.
2010 static int num_ids() { return parent_num_ids() + 2; }
2011 BailoutId MaterializeTrueId() const { return BailoutId(local_id(0)); }
2012 BailoutId MaterializeFalseId() const { return BailoutId(local_id(1)); }
2014 virtual void RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle) override;
2017 UnaryOperation(Zone* zone, Token::Value op, Expression* expression, int pos)
2018 : Expression(zone, pos), op_(op), expression_(expression) {
2019 DCHECK(Token::IsUnaryOp(op));
2021 static int parent_num_ids() { return Expression::num_ids(); }
2024 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2027 Expression* expression_;
2031 class BinaryOperation final : public Expression {
2033 DECLARE_NODE_TYPE(BinaryOperation)
2035 Token::Value op() const { return static_cast<Token::Value>(op_); }
2036 Expression* left() const { return left_; }
2037 Expression* right() const { return right_; }
2038 Handle<AllocationSite> allocation_site() const { return allocation_site_; }
2039 void set_allocation_site(Handle<AllocationSite> allocation_site) {
2040 allocation_site_ = allocation_site;
2043 // The short-circuit logical operations need an AST ID for their
2044 // right-hand subexpression.
2045 static int num_ids() { return parent_num_ids() + 2; }
2046 BailoutId RightId() const { return BailoutId(local_id(0)); }
2048 TypeFeedbackId BinaryOperationFeedbackId() const {
2049 return TypeFeedbackId(local_id(1));
2051 Maybe<int> fixed_right_arg() const {
2052 return has_fixed_right_arg_ ? Just(fixed_right_arg_value_) : Nothing<int>();
2054 void set_fixed_right_arg(Maybe<int> arg) {
2055 has_fixed_right_arg_ = arg.IsJust();
2056 if (arg.IsJust()) fixed_right_arg_value_ = arg.FromJust();
2059 virtual void RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle) override;
2062 BinaryOperation(Zone* zone, Token::Value op, Expression* left,
2063 Expression* right, int pos)
2064 : Expression(zone, pos),
2065 op_(static_cast<byte>(op)),
2066 has_fixed_right_arg_(false),
2067 fixed_right_arg_value_(0),
2070 DCHECK(Token::IsBinaryOp(op));
2072 static int parent_num_ids() { return Expression::num_ids(); }
2075 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2077 const byte op_; // actually Token::Value
2078 // TODO(rossberg): the fixed arg should probably be represented as a Constant
2079 // type for the RHS. Currenty it's actually a Maybe<int>
2080 bool has_fixed_right_arg_;
2081 int fixed_right_arg_value_;
2084 Handle<AllocationSite> allocation_site_;
2088 class CountOperation final : public Expression {
2090 DECLARE_NODE_TYPE(CountOperation)
2092 bool is_prefix() const { return IsPrefixField::decode(bit_field_); }
2093 bool is_postfix() const { return !is_prefix(); }
2095 Token::Value op() const { return TokenField::decode(bit_field_); }
2096 Token::Value binary_op() {
2097 return (op() == Token::INC) ? Token::ADD : Token::SUB;
2100 Expression* expression() const { return expression_; }
2102 bool IsMonomorphic() override { return receiver_types_.length() == 1; }
2103 SmallMapList* GetReceiverTypes() override { return &receiver_types_; }
2104 IcCheckType GetKeyType() const override {
2105 return KeyTypeField::decode(bit_field_);
2107 KeyedAccessStoreMode GetStoreMode() const override {
2108 return StoreModeField::decode(bit_field_);
2110 Type* type() const { return type_; }
2111 void set_key_type(IcCheckType type) {
2112 bit_field_ = KeyTypeField::update(bit_field_, type);
2114 void set_store_mode(KeyedAccessStoreMode mode) {
2115 bit_field_ = StoreModeField::update(bit_field_, mode);
2117 void set_type(Type* type) { type_ = type; }
2119 static int num_ids() { return parent_num_ids() + 4; }
2120 BailoutId AssignmentId() const { return BailoutId(local_id(0)); }
2121 BailoutId ToNumberId() const { return BailoutId(local_id(1)); }
2122 TypeFeedbackId CountBinOpFeedbackId() const {
2123 return TypeFeedbackId(local_id(2));
2125 TypeFeedbackId CountStoreFeedbackId() const {
2126 return TypeFeedbackId(local_id(3));
2130 CountOperation(Zone* zone, Token::Value op, bool is_prefix, Expression* expr,
2132 : Expression(zone, pos),
2133 bit_field_(IsPrefixField::encode(is_prefix) |
2134 KeyTypeField::encode(ELEMENT) |
2135 StoreModeField::encode(STANDARD_STORE) |
2136 TokenField::encode(op)),
2138 expression_(expr) {}
2139 static int parent_num_ids() { return Expression::num_ids(); }
2142 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2144 class IsPrefixField : public BitField16<bool, 0, 1> {};
2145 class KeyTypeField : public BitField16<IcCheckType, 1, 1> {};
2146 class StoreModeField : public BitField16<KeyedAccessStoreMode, 2, 4> {};
2147 class TokenField : public BitField16<Token::Value, 6, 8> {};
2149 // Starts with 16-bit field, which should get packed together with
2150 // Expression's trailing 16-bit field.
2151 uint16_t bit_field_;
2153 Expression* expression_;
2154 SmallMapList receiver_types_;
2158 class CompareOperation final : public Expression {
2160 DECLARE_NODE_TYPE(CompareOperation)
2162 Token::Value op() const { return op_; }
2163 Expression* left() const { return left_; }
2164 Expression* right() const { return right_; }
2166 // Type feedback information.
2167 static int num_ids() { return parent_num_ids() + 1; }
2168 TypeFeedbackId CompareOperationFeedbackId() const {
2169 return TypeFeedbackId(local_id(0));
2171 Type* combined_type() const { return combined_type_; }
2172 void set_combined_type(Type* type) { combined_type_ = type; }
2174 // Match special cases.
2175 bool IsLiteralCompareTypeof(Expression** expr, Handle<String>* check);
2176 bool IsLiteralCompareUndefined(Expression** expr, Isolate* isolate);
2177 bool IsLiteralCompareNull(Expression** expr);
2180 CompareOperation(Zone* zone, Token::Value op, Expression* left,
2181 Expression* right, int pos)
2182 : Expression(zone, pos),
2186 combined_type_(Type::None(zone)) {
2187 DCHECK(Token::IsCompareOp(op));
2189 static int parent_num_ids() { return Expression::num_ids(); }
2192 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2198 Type* combined_type_;
2202 class Spread final : public Expression {
2204 DECLARE_NODE_TYPE(Spread)
2206 Expression* expression() const { return expression_; }
2208 static int num_ids() { return parent_num_ids(); }
2211 Spread(Zone* zone, Expression* expression, int pos)
2212 : Expression(zone, pos), expression_(expression) {}
2213 static int parent_num_ids() { return Expression::num_ids(); }
2216 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2218 Expression* expression_;
2222 class Conditional final : public Expression {
2224 DECLARE_NODE_TYPE(Conditional)
2226 Expression* condition() const { return condition_; }
2227 Expression* then_expression() const { return then_expression_; }
2228 Expression* else_expression() const { return else_expression_; }
2230 static int num_ids() { return parent_num_ids() + 2; }
2231 BailoutId ThenId() const { return BailoutId(local_id(0)); }
2232 BailoutId ElseId() const { return BailoutId(local_id(1)); }
2235 Conditional(Zone* zone, Expression* condition, Expression* then_expression,
2236 Expression* else_expression, int position)
2237 : Expression(zone, position),
2238 condition_(condition),
2239 then_expression_(then_expression),
2240 else_expression_(else_expression) {}
2241 static int parent_num_ids() { return Expression::num_ids(); }
2244 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2246 Expression* condition_;
2247 Expression* then_expression_;
2248 Expression* else_expression_;
2252 class Assignment final : public Expression {
2254 DECLARE_NODE_TYPE(Assignment)
2256 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; }
2258 Token::Value binary_op() const;
2260 Token::Value op() const { return TokenField::decode(bit_field_); }
2261 Expression* target() const { return target_; }
2262 Expression* value() const { return value_; }
2263 BinaryOperation* binary_operation() const { return binary_operation_; }
2265 // This check relies on the definition order of token in token.h.
2266 bool is_compound() const { return op() > Token::ASSIGN; }
2268 static int num_ids() { return parent_num_ids() + 2; }
2269 BailoutId AssignmentId() const { return BailoutId(local_id(0)); }
2271 // Type feedback information.
2272 TypeFeedbackId AssignmentFeedbackId() { return TypeFeedbackId(local_id(1)); }
2273 bool IsMonomorphic() override { return receiver_types_.length() == 1; }
2274 bool IsUninitialized() const {
2275 return IsUninitializedField::decode(bit_field_);
2277 bool HasNoTypeInformation() {
2278 return IsUninitializedField::decode(bit_field_);
2280 SmallMapList* GetReceiverTypes() override { return &receiver_types_; }
2281 IcCheckType GetKeyType() const override {
2282 return KeyTypeField::decode(bit_field_);
2284 KeyedAccessStoreMode GetStoreMode() const override {
2285 return StoreModeField::decode(bit_field_);
2287 void set_is_uninitialized(bool b) {
2288 bit_field_ = IsUninitializedField::update(bit_field_, b);
2290 void set_key_type(IcCheckType key_type) {
2291 bit_field_ = KeyTypeField::update(bit_field_, key_type);
2293 void set_store_mode(KeyedAccessStoreMode mode) {
2294 bit_field_ = StoreModeField::update(bit_field_, mode);
2298 Assignment(Zone* zone, Token::Value op, Expression* target, Expression* value,
2300 static int parent_num_ids() { return Expression::num_ids(); }
2303 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2305 class IsUninitializedField : public BitField16<bool, 0, 1> {};
2306 class KeyTypeField : public BitField16<IcCheckType, 1, 1> {};
2307 class StoreModeField : public BitField16<KeyedAccessStoreMode, 2, 4> {};
2308 class TokenField : public BitField16<Token::Value, 6, 8> {};
2310 // Starts with 16-bit field, which should get packed together with
2311 // Expression's trailing 16-bit field.
2312 uint16_t bit_field_;
2313 Expression* target_;
2315 BinaryOperation* binary_operation_;
2316 SmallMapList receiver_types_;
2320 class Yield final : public Expression {
2322 DECLARE_NODE_TYPE(Yield)
2325 kInitial, // The initial yield that returns the unboxed generator object.
2326 kSuspend, // A normal yield: { value: EXPRESSION, done: false }
2327 kDelegating, // A yield*.
2328 kFinal // A return: { value: EXPRESSION, done: true }
2331 Expression* generator_object() const { return generator_object_; }
2332 Expression* expression() const { return expression_; }
2333 Kind yield_kind() const { return yield_kind_; }
2335 // Delegating yield surrounds the "yield" in a "try/catch". This index
2336 // locates the catch handler in the handler table, and is equivalent to
2337 // TryCatchStatement::index().
2339 DCHECK_EQ(kDelegating, yield_kind());
2342 void set_index(int index) {
2343 DCHECK_EQ(kDelegating, yield_kind());
2347 // Type feedback information.
2348 bool HasFeedbackSlots() const { return yield_kind() == kDelegating; }
2349 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
2350 Isolate* isolate, const ICSlotCache* cache) override {
2351 return FeedbackVectorRequirements(0, HasFeedbackSlots() ? 3 : 0);
2353 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot,
2354 ICSlotCache* cache) override {
2355 yield_first_feedback_slot_ = slot;
2357 Code::Kind FeedbackICSlotKind(int index) override {
2358 return index == 0 ? Code::KEYED_LOAD_IC : Code::LOAD_IC;
2361 FeedbackVectorICSlot KeyedLoadFeedbackSlot() {
2362 DCHECK(!HasFeedbackSlots() || !yield_first_feedback_slot_.IsInvalid());
2363 return yield_first_feedback_slot_;
2366 FeedbackVectorICSlot DoneFeedbackSlot() {
2367 return KeyedLoadFeedbackSlot().next();
2370 FeedbackVectorICSlot ValueFeedbackSlot() { return DoneFeedbackSlot().next(); }
2373 Yield(Zone* zone, Expression* generator_object, Expression* expression,
2374 Kind yield_kind, int pos)
2375 : Expression(zone, pos),
2376 generator_object_(generator_object),
2377 expression_(expression),
2378 yield_kind_(yield_kind),
2380 yield_first_feedback_slot_(FeedbackVectorICSlot::Invalid()) {}
2383 Expression* generator_object_;
2384 Expression* expression_;
2387 FeedbackVectorICSlot yield_first_feedback_slot_;
2391 class Throw final : public Expression {
2393 DECLARE_NODE_TYPE(Throw)
2395 Expression* exception() const { return exception_; }
2398 Throw(Zone* zone, Expression* exception, int pos)
2399 : Expression(zone, pos), exception_(exception) {}
2402 Expression* exception_;
2406 class FunctionLiteral final : public Expression {
2409 ANONYMOUS_EXPRESSION,
2414 enum ParameterFlag {
2415 kNoDuplicateParameters = 0,
2416 kHasDuplicateParameters = 1
2419 enum IsFunctionFlag {
2424 enum EagerCompileHint { kShouldEagerCompile, kShouldLazyCompile };
2426 enum ShouldBeUsedOnceHint { kShouldBeUsedOnce, kDontKnowIfShouldBeUsedOnce };
2428 enum ArityRestriction {
2434 DECLARE_NODE_TYPE(FunctionLiteral)
2436 Handle<String> name() const { return raw_name_->string(); }
2437 const AstRawString* raw_name() const { return raw_name_; }
2438 Scope* scope() const { return scope_; }
2439 ZoneList<Statement*>* body() const { return body_; }
2440 void set_function_token_position(int pos) { function_token_position_ = pos; }
2441 int function_token_position() const { return function_token_position_; }
2442 int start_position() const;
2443 int end_position() const;
2444 int SourceSize() const { return end_position() - start_position(); }
2445 bool is_expression() const { return IsExpression::decode(bitfield_); }
2446 bool is_anonymous() const { return IsAnonymous::decode(bitfield_); }
2447 LanguageMode language_mode() const;
2448 bool uses_super_property() const;
2450 static bool NeedsHomeObject(Expression* literal) {
2451 return literal != NULL && literal->IsFunctionLiteral() &&
2452 literal->AsFunctionLiteral()->uses_super_property();
2455 int materialized_literal_count() { return materialized_literal_count_; }
2456 int expected_property_count() { return expected_property_count_; }
2457 int handler_count() { return handler_count_; }
2458 int parameter_count() { return parameter_count_; }
2460 bool AllowsLazyCompilation();
2461 bool AllowsLazyCompilationWithoutContext();
2463 void InitializeSharedInfo(Handle<Code> code);
2465 Handle<String> debug_name() const {
2466 if (raw_name_ != NULL && !raw_name_->IsEmpty()) {
2467 return raw_name_->string();
2469 return inferred_name();
2472 Handle<String> inferred_name() const {
2473 if (!inferred_name_.is_null()) {
2474 DCHECK(raw_inferred_name_ == NULL);
2475 return inferred_name_;
2477 if (raw_inferred_name_ != NULL) {
2478 return raw_inferred_name_->string();
2481 return Handle<String>();
2484 // Only one of {set_inferred_name, set_raw_inferred_name} should be called.
2485 void set_inferred_name(Handle<String> inferred_name) {
2486 DCHECK(!inferred_name.is_null());
2487 inferred_name_ = inferred_name;
2488 DCHECK(raw_inferred_name_== NULL || raw_inferred_name_->IsEmpty());
2489 raw_inferred_name_ = NULL;
2492 void set_raw_inferred_name(const AstString* raw_inferred_name) {
2493 DCHECK(raw_inferred_name != NULL);
2494 raw_inferred_name_ = raw_inferred_name;
2495 DCHECK(inferred_name_.is_null());
2496 inferred_name_ = Handle<String>();
2499 // shared_info may be null if it's not cached in full code.
2500 Handle<SharedFunctionInfo> shared_info() { return shared_info_; }
2502 bool pretenure() { return Pretenure::decode(bitfield_); }
2503 void set_pretenure() { bitfield_ |= Pretenure::encode(true); }
2505 bool has_duplicate_parameters() {
2506 return HasDuplicateParameters::decode(bitfield_);
2509 bool is_function() { return IsFunction::decode(bitfield_) == kIsFunction; }
2511 // This is used as a heuristic on when to eagerly compile a function
2512 // literal. We consider the following constructs as hints that the
2513 // function will be called immediately:
2514 // - (function() { ... })();
2515 // - var x = function() { ... }();
2516 bool should_eager_compile() const {
2517 return EagerCompileHintBit::decode(bitfield_) == kShouldEagerCompile;
2519 void set_should_eager_compile() {
2520 bitfield_ = EagerCompileHintBit::update(bitfield_, kShouldEagerCompile);
2523 // A hint that we expect this function to be called (exactly) once,
2524 // i.e. we suspect it's an initialization function.
2525 bool should_be_used_once_hint() const {
2526 return ShouldBeUsedOnceHintBit::decode(bitfield_) == kShouldBeUsedOnce;
2528 void set_should_be_used_once_hint() {
2529 bitfield_ = ShouldBeUsedOnceHintBit::update(bitfield_, kShouldBeUsedOnce);
2532 FunctionKind kind() { return FunctionKindBits::decode(bitfield_); }
2534 int ast_node_count() { return ast_properties_.node_count(); }
2535 AstProperties::Flags* flags() { return ast_properties_.flags(); }
2536 void set_ast_properties(AstProperties* ast_properties) {
2537 ast_properties_ = *ast_properties;
2539 const ZoneFeedbackVectorSpec* feedback_vector_spec() const {
2540 return ast_properties_.get_spec();
2542 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; }
2543 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; }
2544 void set_dont_optimize_reason(BailoutReason reason) {
2545 dont_optimize_reason_ = reason;
2549 FunctionLiteral(Zone* zone, const AstRawString* name,
2550 AstValueFactory* ast_value_factory, Scope* scope,
2551 ZoneList<Statement*>* body, int materialized_literal_count,
2552 int expected_property_count, int handler_count,
2553 int parameter_count, FunctionType function_type,
2554 ParameterFlag has_duplicate_parameters,
2555 IsFunctionFlag is_function,
2556 EagerCompileHint eager_compile_hint, FunctionKind kind,
2558 : Expression(zone, position),
2562 raw_inferred_name_(ast_value_factory->empty_string()),
2563 ast_properties_(zone),
2564 dont_optimize_reason_(kNoReason),
2565 materialized_literal_count_(materialized_literal_count),
2566 expected_property_count_(expected_property_count),
2567 handler_count_(handler_count),
2568 parameter_count_(parameter_count),
2569 function_token_position_(RelocInfo::kNoPosition) {
2570 bitfield_ = IsExpression::encode(function_type != DECLARATION) |
2571 IsAnonymous::encode(function_type == ANONYMOUS_EXPRESSION) |
2572 Pretenure::encode(false) |
2573 HasDuplicateParameters::encode(has_duplicate_parameters) |
2574 IsFunction::encode(is_function) |
2575 EagerCompileHintBit::encode(eager_compile_hint) |
2576 FunctionKindBits::encode(kind) |
2577 ShouldBeUsedOnceHintBit::encode(kDontKnowIfShouldBeUsedOnce);
2578 DCHECK(IsValidFunctionKind(kind));
2582 const AstRawString* raw_name_;
2583 Handle<String> name_;
2584 Handle<SharedFunctionInfo> shared_info_;
2586 ZoneList<Statement*>* body_;
2587 const AstString* raw_inferred_name_;
2588 Handle<String> inferred_name_;
2589 AstProperties ast_properties_;
2590 BailoutReason dont_optimize_reason_;
2592 int materialized_literal_count_;
2593 int expected_property_count_;
2595 int parameter_count_;
2596 int function_token_position_;
2599 class IsExpression : public BitField<bool, 0, 1> {};
2600 class IsAnonymous : public BitField<bool, 1, 1> {};
2601 class Pretenure : public BitField<bool, 2, 1> {};
2602 class HasDuplicateParameters : public BitField<ParameterFlag, 3, 1> {};
2603 class IsFunction : public BitField<IsFunctionFlag, 4, 1> {};
2604 class EagerCompileHintBit : public BitField<EagerCompileHint, 5, 1> {};
2605 class FunctionKindBits : public BitField<FunctionKind, 6, 8> {};
2606 class ShouldBeUsedOnceHintBit : public BitField<ShouldBeUsedOnceHint, 15, 1> {
2611 class ClassLiteral final : public Expression {
2613 typedef ObjectLiteralProperty Property;
2615 DECLARE_NODE_TYPE(ClassLiteral)
2617 Handle<String> name() const { return raw_name_->string(); }
2618 const AstRawString* raw_name() const { return raw_name_; }
2619 Scope* scope() const { return scope_; }
2620 VariableProxy* class_variable_proxy() const { return class_variable_proxy_; }
2621 Expression* extends() const { return extends_; }
2622 FunctionLiteral* constructor() const { return constructor_; }
2623 ZoneList<Property*>* properties() const { return properties_; }
2624 int start_position() const { return position(); }
2625 int end_position() const { return end_position_; }
2627 BailoutId EntryId() const { return BailoutId(local_id(0)); }
2628 BailoutId DeclsId() const { return BailoutId(local_id(1)); }
2629 BailoutId ExitId() { return BailoutId(local_id(2)); }
2630 BailoutId CreateLiteralId() const { return BailoutId(local_id(3)); }
2632 // Return an AST id for a property that is used in simulate instructions.
2633 BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 4)); }
2635 // Unlike other AST nodes, this number of bailout IDs allocated for an
2636 // ClassLiteral can vary, so num_ids() is not a static method.
2637 int num_ids() const { return parent_num_ids() + 4 + properties()->length(); }
2640 ClassLiteral(Zone* zone, const AstRawString* name, Scope* scope,
2641 VariableProxy* class_variable_proxy, Expression* extends,
2642 FunctionLiteral* constructor, ZoneList<Property*>* properties,
2643 int start_position, int end_position)
2644 : Expression(zone, start_position),
2647 class_variable_proxy_(class_variable_proxy),
2649 constructor_(constructor),
2650 properties_(properties),
2651 end_position_(end_position) {}
2652 static int parent_num_ids() { return Expression::num_ids(); }
2655 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2657 const AstRawString* raw_name_;
2659 VariableProxy* class_variable_proxy_;
2660 Expression* extends_;
2661 FunctionLiteral* constructor_;
2662 ZoneList<Property*>* properties_;
2667 class NativeFunctionLiteral final : public Expression {
2669 DECLARE_NODE_TYPE(NativeFunctionLiteral)
2671 Handle<String> name() const { return name_->string(); }
2672 v8::Extension* extension() const { return extension_; }
2675 NativeFunctionLiteral(Zone* zone, const AstRawString* name,
2676 v8::Extension* extension, int pos)
2677 : Expression(zone, pos), name_(name), extension_(extension) {}
2680 const AstRawString* name_;
2681 v8::Extension* extension_;
2685 class ThisFunction final : public Expression {
2687 DECLARE_NODE_TYPE(ThisFunction)
2690 ThisFunction(Zone* zone, int pos) : Expression(zone, pos) {}
2694 class SuperReference final : public Expression {
2696 DECLARE_NODE_TYPE(SuperReference)
2698 VariableProxy* this_var() const { return this_var_; }
2700 static int num_ids() { return parent_num_ids() + 1; }
2701 TypeFeedbackId HomeObjectFeedbackId() { return TypeFeedbackId(local_id(0)); }
2703 // Type feedback information.
2704 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
2705 Isolate* isolate, const ICSlotCache* cache) override {
2706 return FeedbackVectorRequirements(0, 1);
2708 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot,
2709 ICSlotCache* cache) override {
2710 homeobject_feedback_slot_ = slot;
2712 Code::Kind FeedbackICSlotKind(int index) override { return Code::LOAD_IC; }
2714 FeedbackVectorICSlot HomeObjectFeedbackSlot() {
2715 DCHECK(!homeobject_feedback_slot_.IsInvalid());
2716 return homeobject_feedback_slot_;
2720 SuperReference(Zone* zone, VariableProxy* this_var, int pos)
2721 : Expression(zone, pos),
2722 this_var_(this_var),
2723 homeobject_feedback_slot_(FeedbackVectorICSlot::Invalid()) {
2724 DCHECK(this_var->is_this());
2726 static int parent_num_ids() { return Expression::num_ids(); }
2729 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2731 VariableProxy* this_var_;
2732 FeedbackVectorICSlot homeobject_feedback_slot_;
2736 #undef DECLARE_NODE_TYPE
2739 // ----------------------------------------------------------------------------
2740 // Regular expressions
2743 class RegExpVisitor BASE_EMBEDDED {
2745 virtual ~RegExpVisitor() { }
2746 #define MAKE_CASE(Name) \
2747 virtual void* Visit##Name(RegExp##Name*, void* data) = 0;
2748 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_CASE)
2753 class RegExpTree : public ZoneObject {
2755 static const int kInfinity = kMaxInt;
2756 virtual ~RegExpTree() {}
2757 virtual void* Accept(RegExpVisitor* visitor, void* data) = 0;
2758 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2759 RegExpNode* on_success) = 0;
2760 virtual bool IsTextElement() { return false; }
2761 virtual bool IsAnchoredAtStart() { return false; }
2762 virtual bool IsAnchoredAtEnd() { return false; }
2763 virtual int min_match() = 0;
2764 virtual int max_match() = 0;
2765 // Returns the interval of registers used for captures within this
2767 virtual Interval CaptureRegisters() { return Interval::Empty(); }
2768 virtual void AppendToText(RegExpText* text, Zone* zone);
2769 std::ostream& Print(std::ostream& os, Zone* zone); // NOLINT
2770 #define MAKE_ASTYPE(Name) \
2771 virtual RegExp##Name* As##Name(); \
2772 virtual bool Is##Name();
2773 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_ASTYPE)
2778 class RegExpDisjunction final : public RegExpTree {
2780 explicit RegExpDisjunction(ZoneList<RegExpTree*>* alternatives);
2781 void* Accept(RegExpVisitor* visitor, void* data) override;
2782 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2783 RegExpNode* on_success) override;
2784 RegExpDisjunction* AsDisjunction() override;
2785 Interval CaptureRegisters() override;
2786 bool IsDisjunction() override;
2787 bool IsAnchoredAtStart() override;
2788 bool IsAnchoredAtEnd() override;
2789 int min_match() override { return min_match_; }
2790 int max_match() override { return max_match_; }
2791 ZoneList<RegExpTree*>* alternatives() { return alternatives_; }
2793 ZoneList<RegExpTree*>* alternatives_;
2799 class RegExpAlternative final : public RegExpTree {
2801 explicit RegExpAlternative(ZoneList<RegExpTree*>* nodes);
2802 void* Accept(RegExpVisitor* visitor, void* data) override;
2803 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2804 RegExpNode* on_success) override;
2805 RegExpAlternative* AsAlternative() override;
2806 Interval CaptureRegisters() override;
2807 bool IsAlternative() override;
2808 bool IsAnchoredAtStart() override;
2809 bool IsAnchoredAtEnd() override;
2810 int min_match() override { return min_match_; }
2811 int max_match() override { return max_match_; }
2812 ZoneList<RegExpTree*>* nodes() { return nodes_; }
2814 ZoneList<RegExpTree*>* nodes_;
2820 class RegExpAssertion final : public RegExpTree {
2822 enum AssertionType {
2830 explicit RegExpAssertion(AssertionType type) : assertion_type_(type) { }
2831 void* Accept(RegExpVisitor* visitor, void* data) override;
2832 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2833 RegExpNode* on_success) override;
2834 RegExpAssertion* AsAssertion() override;
2835 bool IsAssertion() override;
2836 bool IsAnchoredAtStart() override;
2837 bool IsAnchoredAtEnd() override;
2838 int min_match() override { return 0; }
2839 int max_match() override { return 0; }
2840 AssertionType assertion_type() { return assertion_type_; }
2842 AssertionType assertion_type_;
2846 class CharacterSet final BASE_EMBEDDED {
2848 explicit CharacterSet(uc16 standard_set_type)
2850 standard_set_type_(standard_set_type) {}
2851 explicit CharacterSet(ZoneList<CharacterRange>* ranges)
2853 standard_set_type_(0) {}
2854 ZoneList<CharacterRange>* ranges(Zone* zone);
2855 uc16 standard_set_type() { return standard_set_type_; }
2856 void set_standard_set_type(uc16 special_set_type) {
2857 standard_set_type_ = special_set_type;
2859 bool is_standard() { return standard_set_type_ != 0; }
2860 void Canonicalize();
2862 ZoneList<CharacterRange>* ranges_;
2863 // If non-zero, the value represents a standard set (e.g., all whitespace
2864 // characters) without having to expand the ranges.
2865 uc16 standard_set_type_;
2869 class RegExpCharacterClass final : public RegExpTree {
2871 RegExpCharacterClass(ZoneList<CharacterRange>* ranges, bool is_negated)
2873 is_negated_(is_negated) { }
2874 explicit RegExpCharacterClass(uc16 type)
2876 is_negated_(false) { }
2877 void* Accept(RegExpVisitor* visitor, void* data) override;
2878 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2879 RegExpNode* on_success) override;
2880 RegExpCharacterClass* AsCharacterClass() override;
2881 bool IsCharacterClass() override;
2882 bool IsTextElement() override { return true; }
2883 int min_match() override { return 1; }
2884 int max_match() override { return 1; }
2885 void AppendToText(RegExpText* text, Zone* zone) override;
2886 CharacterSet character_set() { return set_; }
2887 // TODO(lrn): Remove need for complex version if is_standard that
2888 // recognizes a mangled standard set and just do { return set_.is_special(); }
2889 bool is_standard(Zone* zone);
2890 // Returns a value representing the standard character set if is_standard()
2892 // Currently used values are:
2893 // s : unicode whitespace
2894 // S : unicode non-whitespace
2895 // w : ASCII word character (digit, letter, underscore)
2896 // W : non-ASCII word character
2898 // D : non-ASCII digit
2899 // . : non-unicode non-newline
2900 // * : All characters
2901 uc16 standard_type() { return set_.standard_set_type(); }
2902 ZoneList<CharacterRange>* ranges(Zone* zone) { return set_.ranges(zone); }
2903 bool is_negated() { return is_negated_; }
2911 class RegExpAtom final : public RegExpTree {
2913 explicit RegExpAtom(Vector<const uc16> data) : data_(data) { }
2914 void* Accept(RegExpVisitor* visitor, void* data) override;
2915 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2916 RegExpNode* on_success) override;
2917 RegExpAtom* AsAtom() override;
2918 bool IsAtom() override;
2919 bool IsTextElement() override { return true; }
2920 int min_match() override { return data_.length(); }
2921 int max_match() override { return data_.length(); }
2922 void AppendToText(RegExpText* text, Zone* zone) override;
2923 Vector<const uc16> data() { return data_; }
2924 int length() { return data_.length(); }
2926 Vector<const uc16> data_;
2930 class RegExpText final : public RegExpTree {
2932 explicit RegExpText(Zone* zone) : elements_(2, zone), length_(0) {}
2933 void* Accept(RegExpVisitor* visitor, void* data) override;
2934 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2935 RegExpNode* on_success) override;
2936 RegExpText* AsText() override;
2937 bool IsText() override;
2938 bool IsTextElement() override { return true; }
2939 int min_match() override { return length_; }
2940 int max_match() override { return length_; }
2941 void AppendToText(RegExpText* text, Zone* zone) override;
2942 void AddElement(TextElement elm, Zone* zone) {
2943 elements_.Add(elm, zone);
2944 length_ += elm.length();
2946 ZoneList<TextElement>* elements() { return &elements_; }
2948 ZoneList<TextElement> elements_;
2953 class RegExpQuantifier final : public RegExpTree {
2955 enum QuantifierType { GREEDY, NON_GREEDY, POSSESSIVE };
2956 RegExpQuantifier(int min, int max, QuantifierType type, RegExpTree* body)
2960 min_match_(min * body->min_match()),
2961 quantifier_type_(type) {
2962 if (max > 0 && body->max_match() > kInfinity / max) {
2963 max_match_ = kInfinity;
2965 max_match_ = max * body->max_match();
2968 void* Accept(RegExpVisitor* visitor, void* data) override;
2969 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2970 RegExpNode* on_success) override;
2971 static RegExpNode* ToNode(int min,
2975 RegExpCompiler* compiler,
2976 RegExpNode* on_success,
2977 bool not_at_start = false);
2978 RegExpQuantifier* AsQuantifier() override;
2979 Interval CaptureRegisters() override;
2980 bool IsQuantifier() override;
2981 int min_match() override { return min_match_; }
2982 int max_match() override { return max_match_; }
2983 int min() { return min_; }
2984 int max() { return max_; }
2985 bool is_possessive() { return quantifier_type_ == POSSESSIVE; }
2986 bool is_non_greedy() { return quantifier_type_ == NON_GREEDY; }
2987 bool is_greedy() { return quantifier_type_ == GREEDY; }
2988 RegExpTree* body() { return body_; }
2996 QuantifierType quantifier_type_;
3000 class RegExpCapture final : public RegExpTree {
3002 explicit RegExpCapture(RegExpTree* body, int index)
3003 : body_(body), index_(index) { }
3004 void* Accept(RegExpVisitor* visitor, void* data) override;
3005 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
3006 RegExpNode* on_success) override;
3007 static RegExpNode* ToNode(RegExpTree* body,
3009 RegExpCompiler* compiler,
3010 RegExpNode* on_success);
3011 RegExpCapture* AsCapture() override;
3012 bool IsAnchoredAtStart() override;
3013 bool IsAnchoredAtEnd() override;
3014 Interval CaptureRegisters() override;
3015 bool IsCapture() override;
3016 int min_match() override { return body_->min_match(); }
3017 int max_match() override { return body_->max_match(); }
3018 RegExpTree* body() { return body_; }
3019 int index() { return index_; }
3020 static int StartRegister(int index) { return index * 2; }
3021 static int EndRegister(int index) { return index * 2 + 1; }
3029 class RegExpLookahead final : public RegExpTree {
3031 RegExpLookahead(RegExpTree* body,
3036 is_positive_(is_positive),
3037 capture_count_(capture_count),
3038 capture_from_(capture_from) { }
3040 void* Accept(RegExpVisitor* visitor, void* data) override;
3041 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
3042 RegExpNode* on_success) override;
3043 RegExpLookahead* AsLookahead() override;
3044 Interval CaptureRegisters() override;
3045 bool IsLookahead() override;
3046 bool IsAnchoredAtStart() override;
3047 int min_match() override { return 0; }
3048 int max_match() override { return 0; }
3049 RegExpTree* body() { return body_; }
3050 bool is_positive() { return is_positive_; }
3051 int capture_count() { return capture_count_; }
3052 int capture_from() { return capture_from_; }
3062 class RegExpBackReference final : public RegExpTree {
3064 explicit RegExpBackReference(RegExpCapture* capture)
3065 : capture_(capture) { }
3066 void* Accept(RegExpVisitor* visitor, void* data) override;
3067 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
3068 RegExpNode* on_success) override;
3069 RegExpBackReference* AsBackReference() override;
3070 bool IsBackReference() override;
3071 int min_match() override { return 0; }
3072 int max_match() override { return capture_->max_match(); }
3073 int index() { return capture_->index(); }
3074 RegExpCapture* capture() { return capture_; }
3076 RegExpCapture* capture_;
3080 class RegExpEmpty final : public RegExpTree {
3083 void* Accept(RegExpVisitor* visitor, void* data) override;
3084 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
3085 RegExpNode* on_success) override;
3086 RegExpEmpty* AsEmpty() override;
3087 bool IsEmpty() override;
3088 int min_match() override { return 0; }
3089 int max_match() override { return 0; }
3093 // ----------------------------------------------------------------------------
3095 // - leaf node visitors are abstract.
3097 class AstVisitor BASE_EMBEDDED {
3100 virtual ~AstVisitor() {}
3102 // Stack overflow check and dynamic dispatch.
3103 virtual void Visit(AstNode* node) = 0;
3105 // Iteration left-to-right.
3106 virtual void VisitDeclarations(ZoneList<Declaration*>* declarations);
3107 virtual void VisitStatements(ZoneList<Statement*>* statements);
3108 virtual void VisitExpressions(ZoneList<Expression*>* expressions);
3110 // Individual AST nodes.
3111 #define DEF_VISIT(type) \
3112 virtual void Visit##type(type* node) = 0;
3113 AST_NODE_LIST(DEF_VISIT)
3118 #define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS() \
3120 void Visit(AstNode* node) final { \
3121 if (!CheckStackOverflow()) node->Accept(this); \
3124 void SetStackOverflow() { stack_overflow_ = true; } \
3125 void ClearStackOverflow() { stack_overflow_ = false; } \
3126 bool HasStackOverflow() const { return stack_overflow_; } \
3128 bool CheckStackOverflow() { \
3129 if (stack_overflow_) return true; \
3130 StackLimitCheck check(isolate_); \
3131 if (!check.HasOverflowed()) return false; \
3132 stack_overflow_ = true; \
3137 void InitializeAstVisitor(Isolate* isolate, Zone* zone) { \
3138 isolate_ = isolate; \
3140 stack_overflow_ = false; \
3142 Zone* zone() { return zone_; } \
3143 Isolate* isolate() { return isolate_; } \
3145 Isolate* isolate_; \
3147 bool stack_overflow_
3150 // ----------------------------------------------------------------------------
3153 class AstNodeFactory final BASE_EMBEDDED {
3155 explicit AstNodeFactory(AstValueFactory* ast_value_factory)
3156 : zone_(ast_value_factory->zone()),
3157 ast_value_factory_(ast_value_factory) {}
3159 VariableDeclaration* NewVariableDeclaration(
3160 VariableProxy* proxy, VariableMode mode, Scope* scope, int pos,
3161 bool is_class_declaration = false, int declaration_group_start = -1) {
3163 VariableDeclaration(zone_, proxy, mode, scope, pos,
3164 is_class_declaration, declaration_group_start);
3167 FunctionDeclaration* NewFunctionDeclaration(VariableProxy* proxy,
3169 FunctionLiteral* fun,
3172 return new (zone_) FunctionDeclaration(zone_, proxy, mode, fun, scope, pos);
3175 ImportDeclaration* NewImportDeclaration(VariableProxy* proxy,
3176 const AstRawString* import_name,
3177 const AstRawString* module_specifier,
3178 Scope* scope, int pos) {
3179 return new (zone_) ImportDeclaration(zone_, proxy, import_name,
3180 module_specifier, scope, pos);
3183 ExportDeclaration* NewExportDeclaration(VariableProxy* proxy,
3186 return new (zone_) ExportDeclaration(zone_, proxy, scope, pos);
3189 Block* NewBlock(ZoneList<const AstRawString*>* labels,
3191 bool is_initializer_block,
3194 Block(zone_, labels, capacity, is_initializer_block, pos);
3197 #define STATEMENT_WITH_LABELS(NodeType) \
3198 NodeType* New##NodeType(ZoneList<const AstRawString*>* labels, int pos) { \
3199 return new (zone_) NodeType(zone_, labels, pos); \
3201 STATEMENT_WITH_LABELS(DoWhileStatement)
3202 STATEMENT_WITH_LABELS(WhileStatement)
3203 STATEMENT_WITH_LABELS(ForStatement)
3204 STATEMENT_WITH_LABELS(SwitchStatement)
3205 #undef STATEMENT_WITH_LABELS
3207 ForEachStatement* NewForEachStatement(ForEachStatement::VisitMode visit_mode,
3208 ZoneList<const AstRawString*>* labels,
3210 switch (visit_mode) {
3211 case ForEachStatement::ENUMERATE: {
3212 return new (zone_) ForInStatement(zone_, labels, pos);
3214 case ForEachStatement::ITERATE: {
3215 return new (zone_) ForOfStatement(zone_, labels, pos);
3222 ExpressionStatement* NewExpressionStatement(Expression* expression, int pos) {
3223 return new (zone_) ExpressionStatement(zone_, expression, pos);
3226 ContinueStatement* NewContinueStatement(IterationStatement* target, int pos) {
3227 return new (zone_) ContinueStatement(zone_, target, pos);
3230 BreakStatement* NewBreakStatement(BreakableStatement* target, int pos) {
3231 return new (zone_) BreakStatement(zone_, target, pos);
3234 ReturnStatement* NewReturnStatement(Expression* expression, int pos) {
3235 return new (zone_) ReturnStatement(zone_, expression, pos);
3238 WithStatement* NewWithStatement(Scope* scope,
3239 Expression* expression,
3240 Statement* statement,
3242 return new (zone_) WithStatement(zone_, scope, expression, statement, pos);
3245 IfStatement* NewIfStatement(Expression* condition,
3246 Statement* then_statement,
3247 Statement* else_statement,
3250 IfStatement(zone_, condition, then_statement, else_statement, pos);
3253 TryCatchStatement* NewTryCatchStatement(int index,
3259 return new (zone_) TryCatchStatement(zone_, index, try_block, scope,
3260 variable, catch_block, pos);
3263 TryFinallyStatement* NewTryFinallyStatement(int index,
3265 Block* finally_block,
3268 TryFinallyStatement(zone_, index, try_block, finally_block, pos);
3271 DebuggerStatement* NewDebuggerStatement(int pos) {
3272 return new (zone_) DebuggerStatement(zone_, pos);
3275 EmptyStatement* NewEmptyStatement(int pos) {
3276 return new(zone_) EmptyStatement(zone_, pos);
3279 CaseClause* NewCaseClause(
3280 Expression* label, ZoneList<Statement*>* statements, int pos) {
3281 return new (zone_) CaseClause(zone_, label, statements, pos);
3284 Literal* NewStringLiteral(const AstRawString* string, int pos) {
3286 Literal(zone_, ast_value_factory_->NewString(string), pos);
3289 // A JavaScript symbol (ECMA-262 edition 6).
3290 Literal* NewSymbolLiteral(const char* name, int pos) {
3291 return new (zone_) Literal(zone_, ast_value_factory_->NewSymbol(name), pos);
3294 Literal* NewNumberLiteral(double number, int pos) {
3296 Literal(zone_, ast_value_factory_->NewNumber(number), pos);
3299 Literal* NewSmiLiteral(int number, int pos) {
3300 return new (zone_) Literal(zone_, ast_value_factory_->NewSmi(number), pos);
3303 Literal* NewBooleanLiteral(bool b, int pos) {
3304 return new (zone_) Literal(zone_, ast_value_factory_->NewBoolean(b), pos);
3307 Literal* NewNullLiteral(int pos) {
3308 return new (zone_) Literal(zone_, ast_value_factory_->NewNull(), pos);
3311 Literal* NewUndefinedLiteral(int pos) {
3312 return new (zone_) Literal(zone_, ast_value_factory_->NewUndefined(), pos);
3315 Literal* NewTheHoleLiteral(int pos) {
3316 return new (zone_) Literal(zone_, ast_value_factory_->NewTheHole(), pos);
3319 ObjectLiteral* NewObjectLiteral(
3320 ZoneList<ObjectLiteral::Property*>* properties,
3322 int boilerplate_properties,
3326 return new (zone_) ObjectLiteral(zone_, properties, literal_index,
3327 boilerplate_properties, has_function,
3331 ObjectLiteral::Property* NewObjectLiteralProperty(
3332 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind,
3333 bool is_static, bool is_computed_name) {
3335 ObjectLiteral::Property(key, value, kind, is_static, is_computed_name);
3338 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key,
3341 bool is_computed_name) {
3342 return new (zone_) ObjectLiteral::Property(ast_value_factory_, key, value,
3343 is_static, is_computed_name);
3346 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern,
3347 const AstRawString* flags,
3351 return new (zone_) RegExpLiteral(zone_, pattern, flags, literal_index,
3355 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values,
3359 return new (zone_) ArrayLiteral(zone_, values, literal_index, is_strong,
3363 VariableProxy* NewVariableProxy(Variable* var,
3364 int start_position = RelocInfo::kNoPosition,
3365 int end_position = RelocInfo::kNoPosition) {
3366 return new (zone_) VariableProxy(zone_, var, start_position, end_position);
3369 VariableProxy* NewVariableProxy(const AstRawString* name,
3370 Variable::Kind variable_kind,
3371 int start_position = RelocInfo::kNoPosition,
3372 int end_position = RelocInfo::kNoPosition) {
3373 DCHECK_NOT_NULL(name);
3375 VariableProxy(zone_, name, variable_kind, start_position, end_position);
3378 Property* NewProperty(Expression* obj, Expression* key, int pos) {
3379 return new (zone_) Property(zone_, obj, key, pos);
3382 Call* NewCall(Expression* expression,
3383 ZoneList<Expression*>* arguments,
3385 return new (zone_) Call(zone_, expression, arguments, pos);
3388 CallNew* NewCallNew(Expression* expression,
3389 ZoneList<Expression*>* arguments,
3391 return new (zone_) CallNew(zone_, expression, arguments, pos);
3394 CallRuntime* NewCallRuntime(const AstRawString* name,
3395 const Runtime::Function* function,
3396 ZoneList<Expression*>* arguments,
3398 return new (zone_) CallRuntime(zone_, name, function, arguments, pos);
3401 UnaryOperation* NewUnaryOperation(Token::Value op,
3402 Expression* expression,
3404 return new (zone_) UnaryOperation(zone_, op, expression, pos);
3407 BinaryOperation* NewBinaryOperation(Token::Value op,
3411 return new (zone_) BinaryOperation(zone_, op, left, right, pos);
3414 CountOperation* NewCountOperation(Token::Value op,
3418 return new (zone_) CountOperation(zone_, op, is_prefix, expr, pos);
3421 CompareOperation* NewCompareOperation(Token::Value op,
3425 return new (zone_) CompareOperation(zone_, op, left, right, pos);
3428 Spread* NewSpread(Expression* expression, int pos) {
3429 return new (zone_) Spread(zone_, expression, pos);
3432 Conditional* NewConditional(Expression* condition,
3433 Expression* then_expression,
3434 Expression* else_expression,
3436 return new (zone_) Conditional(zone_, condition, then_expression,
3437 else_expression, position);
3440 Assignment* NewAssignment(Token::Value op,
3444 DCHECK(Token::IsAssignmentOp(op));
3445 Assignment* assign = new (zone_) Assignment(zone_, op, target, value, pos);
3446 if (assign->is_compound()) {
3447 DCHECK(Token::IsAssignmentOp(op));
3448 assign->binary_operation_ =
3449 NewBinaryOperation(assign->binary_op(), target, value, pos + 1);
3454 Yield* NewYield(Expression *generator_object,
3455 Expression* expression,
3456 Yield::Kind yield_kind,
3458 if (!expression) expression = NewUndefinedLiteral(pos);
3460 Yield(zone_, generator_object, expression, yield_kind, pos);
3463 Throw* NewThrow(Expression* exception, int pos) {
3464 return new (zone_) Throw(zone_, exception, pos);
3467 FunctionLiteral* NewFunctionLiteral(
3468 const AstRawString* name, AstValueFactory* ast_value_factory,
3469 Scope* scope, ZoneList<Statement*>* body, int materialized_literal_count,
3470 int expected_property_count, int handler_count, int parameter_count,
3471 FunctionLiteral::ParameterFlag has_duplicate_parameters,
3472 FunctionLiteral::FunctionType function_type,
3473 FunctionLiteral::IsFunctionFlag is_function,
3474 FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind kind,
3476 return new (zone_) FunctionLiteral(
3477 zone_, name, ast_value_factory, scope, body, materialized_literal_count,
3478 expected_property_count, handler_count, parameter_count, function_type,
3479 has_duplicate_parameters, is_function, eager_compile_hint, kind,
3483 ClassLiteral* NewClassLiteral(const AstRawString* name, Scope* scope,
3484 VariableProxy* proxy, Expression* extends,
3485 FunctionLiteral* constructor,
3486 ZoneList<ObjectLiteral::Property*>* properties,
3487 int start_position, int end_position) {
3489 ClassLiteral(zone_, name, scope, proxy, extends, constructor,
3490 properties, start_position, end_position);
3493 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name,
3494 v8::Extension* extension,
3496 return new (zone_) NativeFunctionLiteral(zone_, name, extension, pos);
3499 ThisFunction* NewThisFunction(int pos) {
3500 return new (zone_) ThisFunction(zone_, pos);
3503 SuperReference* NewSuperReference(VariableProxy* this_var, int pos) {
3504 return new (zone_) SuperReference(zone_, this_var, pos);
3509 AstValueFactory* ast_value_factory_;
3513 } } // namespace v8::internal