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 {
147 class FeedbackVectorRequirements {
149 FeedbackVectorRequirements(int slots, int ic_slots)
150 : slots_(slots), ic_slots_(ic_slots) {}
152 int slots() const { return slots_; }
153 int ic_slots() const { return ic_slots_; }
161 class VariableICSlotPair final {
163 VariableICSlotPair(Variable* variable, FeedbackVectorICSlot slot)
164 : variable_(variable), slot_(slot) {}
166 : variable_(NULL), slot_(FeedbackVectorICSlot::Invalid()) {}
168 Variable* variable() const { return variable_; }
169 FeedbackVectorICSlot slot() const { return slot_; }
173 FeedbackVectorICSlot slot_;
177 typedef List<VariableICSlotPair> ICSlotCache;
180 class AstProperties final BASE_EMBEDDED {
182 class Flags : public EnumSet<AstPropertiesFlag, int> {};
184 explicit AstProperties(Zone* zone) : node_count_(0), spec_(zone) {}
186 Flags* flags() { return &flags_; }
187 int node_count() { return node_count_; }
188 void add_node_count(int count) { node_count_ += count; }
190 int slots() const { return spec_.slots(); }
191 void increase_slots(int count) { spec_.increase_slots(count); }
193 int ic_slots() const { return spec_.ic_slots(); }
194 void increase_ic_slots(int count) { spec_.increase_ic_slots(count); }
195 void SetKind(int ic_slot, Code::Kind kind) { spec_.SetKind(ic_slot, kind); }
196 const ZoneFeedbackVectorSpec* get_spec() const { return &spec_; }
201 ZoneFeedbackVectorSpec spec_;
205 class AstNode: public ZoneObject {
207 #define DECLARE_TYPE_ENUM(type) k##type,
209 AST_NODE_LIST(DECLARE_TYPE_ENUM)
212 #undef DECLARE_TYPE_ENUM
214 void* operator new(size_t size, Zone* zone) { return zone->New(size); }
216 explicit AstNode(int position): position_(position) {}
217 virtual ~AstNode() {}
219 virtual void Accept(AstVisitor* v) = 0;
220 virtual NodeType node_type() const = 0;
221 int position() const { return position_; }
223 // Type testing & conversion functions overridden by concrete subclasses.
224 #define DECLARE_NODE_FUNCTIONS(type) \
225 bool Is##type() const { return node_type() == AstNode::k##type; } \
227 return Is##type() ? reinterpret_cast<type*>(this) : NULL; \
229 const type* As##type() const { \
230 return Is##type() ? reinterpret_cast<const type*>(this) : NULL; \
232 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
233 #undef DECLARE_NODE_FUNCTIONS
235 virtual BreakableStatement* AsBreakableStatement() { return NULL; }
236 virtual IterationStatement* AsIterationStatement() { return NULL; }
237 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; }
239 // The interface for feedback slots, with default no-op implementations for
240 // node types which don't actually have this. Note that this is conceptually
241 // not really nice, but multiple inheritance would introduce yet another
242 // vtable entry per node, something we don't want for space reasons.
243 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
244 Isolate* isolate, const ICSlotCache* cache) {
245 return FeedbackVectorRequirements(0, 0);
247 virtual void SetFirstFeedbackSlot(FeedbackVectorSlot slot) { UNREACHABLE(); }
248 virtual void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot,
249 ICSlotCache* cache) {
252 // Each ICSlot stores a kind of IC which the participating node should know.
253 virtual Code::Kind FeedbackICSlotKind(int index) {
255 return Code::NUMBER_OF_KINDS;
259 // Hidden to prevent accidental usage. It would have to load the
260 // current zone from the TLS.
261 void* operator new(size_t size);
263 friend class CaseClause; // Generates AST IDs.
269 class Statement : public AstNode {
271 explicit Statement(Zone* zone, int position) : AstNode(position) {}
273 bool IsEmpty() { return AsEmptyStatement() != NULL; }
274 virtual bool IsJump() const { return false; }
278 class SmallMapList final {
281 SmallMapList(int capacity, Zone* zone) : list_(capacity, zone) {}
283 void Reserve(int capacity, Zone* zone) { list_.Reserve(capacity, zone); }
284 void Clear() { list_.Clear(); }
285 void Sort() { list_.Sort(); }
287 bool is_empty() const { return list_.is_empty(); }
288 int length() const { return list_.length(); }
290 void AddMapIfMissing(Handle<Map> map, Zone* zone) {
291 if (!Map::TryUpdate(map).ToHandle(&map)) return;
292 for (int i = 0; i < length(); ++i) {
293 if (at(i).is_identical_to(map)) return;
298 void FilterForPossibleTransitions(Map* root_map) {
299 for (int i = list_.length() - 1; i >= 0; i--) {
300 if (at(i)->FindRootMap() != root_map) {
301 list_.RemoveElement(list_.at(i));
306 void Add(Handle<Map> handle, Zone* zone) {
307 list_.Add(handle.location(), zone);
310 Handle<Map> at(int i) const {
311 return Handle<Map>(list_.at(i));
314 Handle<Map> first() const { return at(0); }
315 Handle<Map> last() const { return at(length() - 1); }
318 // The list stores pointers to Map*, that is Map**, so it's GC safe.
319 SmallPointerList<Map*> list_;
321 DISALLOW_COPY_AND_ASSIGN(SmallMapList);
325 class Expression : public AstNode {
328 // Not assigned a context yet, or else will not be visited during
331 // Evaluated for its side effects.
333 // Evaluated for its value (and side effects).
335 // Evaluated for control flow (and side effects).
339 virtual bool IsValidReferenceExpression() const { return false; }
341 // Helpers for ToBoolean conversion.
342 virtual bool ToBooleanIsTrue() const { return false; }
343 virtual bool ToBooleanIsFalse() const { return false; }
345 // Symbols that cannot be parsed as array indices are considered property
346 // names. We do not treat symbols that can be array indexes as property
347 // names because [] for string objects is handled only by keyed ICs.
348 virtual bool IsPropertyName() const { return false; }
350 // True iff the expression is a literal represented as a smi.
351 bool IsSmiLiteral() const;
353 // True iff the expression is a string literal.
354 bool IsStringLiteral() const;
356 // True iff the expression is the null literal.
357 bool IsNullLiteral() const;
359 // True if we can prove that the expression is the undefined literal.
360 bool IsUndefinedLiteral(Isolate* isolate) const;
362 // Expression type bounds
363 Bounds bounds() const { return bounds_; }
364 void set_bounds(Bounds bounds) { bounds_ = bounds; }
366 // Type feedback information for assignments and properties.
367 virtual bool IsMonomorphic() {
371 virtual SmallMapList* GetReceiverTypes() {
375 virtual KeyedAccessStoreMode GetStoreMode() const {
377 return STANDARD_STORE;
379 virtual IcCheckType GetKeyType() const {
384 // TODO(rossberg): this should move to its own AST node eventually.
385 virtual void RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle);
386 byte to_boolean_types() const {
387 return ToBooleanTypesField::decode(bit_field_);
390 void set_base_id(int id) { base_id_ = id; }
391 static int num_ids() { return parent_num_ids() + 2; }
392 BailoutId id() const { return BailoutId(local_id(0)); }
393 TypeFeedbackId test_id() const { return TypeFeedbackId(local_id(1)); }
396 Expression(Zone* zone, int pos)
398 base_id_(BailoutId::None().ToInt()),
399 bounds_(Bounds::Unbounded(zone)),
401 static int parent_num_ids() { return 0; }
402 void set_to_boolean_types(byte types) {
403 bit_field_ = ToBooleanTypesField::update(bit_field_, types);
406 int base_id() const {
407 DCHECK(!BailoutId(base_id_).IsNone());
412 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
416 class ToBooleanTypesField : public BitField16<byte, 0, 8> {};
418 // Ends with 16-bit field; deriving classes in turn begin with
419 // 16-bit fields for optimum packing efficiency.
423 class BreakableStatement : public Statement {
426 TARGET_FOR_ANONYMOUS,
427 TARGET_FOR_NAMED_ONLY
430 // The labels associated with this statement. May be NULL;
431 // if it is != NULL, guaranteed to contain at least one entry.
432 ZoneList<const AstRawString*>* labels() const { return labels_; }
434 // Type testing & conversion.
435 BreakableStatement* AsBreakableStatement() final { return this; }
438 Label* break_target() { return &break_target_; }
441 bool is_target_for_anonymous() const {
442 return breakable_type_ == TARGET_FOR_ANONYMOUS;
445 void set_base_id(int id) { base_id_ = id; }
446 static int num_ids() { return parent_num_ids() + 2; }
447 BailoutId EntryId() const { return BailoutId(local_id(0)); }
448 BailoutId ExitId() const { return BailoutId(local_id(1)); }
451 BreakableStatement(Zone* zone, ZoneList<const AstRawString*>* labels,
452 BreakableType breakable_type, int position)
453 : Statement(zone, position),
455 breakable_type_(breakable_type),
456 base_id_(BailoutId::None().ToInt()) {
457 DCHECK(labels == NULL || labels->length() > 0);
459 static int parent_num_ids() { return 0; }
461 int base_id() const {
462 DCHECK(!BailoutId(base_id_).IsNone());
467 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
469 ZoneList<const AstRawString*>* labels_;
470 BreakableType breakable_type_;
476 class Block final : public BreakableStatement {
478 DECLARE_NODE_TYPE(Block)
480 void AddStatement(Statement* statement, Zone* zone) {
481 statements_.Add(statement, zone);
484 ZoneList<Statement*>* statements() { return &statements_; }
485 bool is_initializer_block() const { return is_initializer_block_; }
487 static int num_ids() { return parent_num_ids() + 1; }
488 BailoutId DeclsId() const { return BailoutId(local_id(0)); }
490 bool IsJump() const override {
491 return !statements_.is_empty() && statements_.last()->IsJump()
492 && labels() == NULL; // Good enough as an approximation...
495 Scope* scope() const { return scope_; }
496 void set_scope(Scope* scope) { scope_ = scope; }
499 Block(Zone* zone, ZoneList<const AstRawString*>* labels, int capacity,
500 bool is_initializer_block, int pos)
501 : BreakableStatement(zone, labels, TARGET_FOR_NAMED_ONLY, pos),
502 statements_(capacity, zone),
503 is_initializer_block_(is_initializer_block),
505 static int parent_num_ids() { return BreakableStatement::num_ids(); }
508 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
510 ZoneList<Statement*> statements_;
511 bool is_initializer_block_;
516 class Declaration : public AstNode {
518 VariableProxy* proxy() const { return proxy_; }
519 VariableMode mode() const { return mode_; }
520 Scope* scope() const { return scope_; }
521 virtual InitializationFlag initialization() const = 0;
522 virtual bool IsInlineable() const;
525 Declaration(Zone* zone, VariableProxy* proxy, VariableMode mode, Scope* scope,
527 : AstNode(pos), mode_(mode), proxy_(proxy), scope_(scope) {
528 DCHECK(IsDeclaredVariableMode(mode));
533 VariableProxy* proxy_;
535 // Nested scope from which the declaration originated.
540 class VariableDeclaration final : public Declaration {
542 DECLARE_NODE_TYPE(VariableDeclaration)
544 InitializationFlag initialization() const override {
545 return mode() == VAR ? kCreatedInitialized : kNeedsInitialization;
548 bool is_class_declaration() const { return is_class_declaration_; }
550 // VariableDeclarations can be grouped into consecutive declaration
551 // groups. Each VariableDeclaration is associated with the start position of
552 // the group it belongs to. The positions are used for strong mode scope
553 // checks for classes and functions.
554 int declaration_group_start() const { return declaration_group_start_; }
557 VariableDeclaration(Zone* zone, VariableProxy* proxy, VariableMode mode,
558 Scope* scope, int pos, bool is_class_declaration = false,
559 int declaration_group_start = -1)
560 : Declaration(zone, proxy, mode, scope, pos),
561 is_class_declaration_(is_class_declaration),
562 declaration_group_start_(declaration_group_start) {}
564 bool is_class_declaration_;
565 int declaration_group_start_;
569 class FunctionDeclaration final : public Declaration {
571 DECLARE_NODE_TYPE(FunctionDeclaration)
573 FunctionLiteral* fun() const { return fun_; }
574 InitializationFlag initialization() const override {
575 return kCreatedInitialized;
577 bool IsInlineable() const override;
580 FunctionDeclaration(Zone* zone,
581 VariableProxy* proxy,
583 FunctionLiteral* fun,
586 : Declaration(zone, proxy, mode, scope, pos),
588 DCHECK(mode == VAR || mode == LET || mode == CONST);
593 FunctionLiteral* fun_;
597 class ImportDeclaration final : public Declaration {
599 DECLARE_NODE_TYPE(ImportDeclaration)
601 const AstRawString* import_name() const { return import_name_; }
602 const AstRawString* module_specifier() const { return module_specifier_; }
603 void set_module_specifier(const AstRawString* module_specifier) {
604 DCHECK(module_specifier_ == NULL);
605 module_specifier_ = module_specifier;
607 InitializationFlag initialization() const override {
608 return kNeedsInitialization;
612 ImportDeclaration(Zone* zone, VariableProxy* proxy,
613 const AstRawString* import_name,
614 const AstRawString* module_specifier, Scope* scope, int pos)
615 : Declaration(zone, proxy, IMPORT, scope, pos),
616 import_name_(import_name),
617 module_specifier_(module_specifier) {}
620 const AstRawString* import_name_;
621 const AstRawString* module_specifier_;
625 class ExportDeclaration final : public Declaration {
627 DECLARE_NODE_TYPE(ExportDeclaration)
629 InitializationFlag initialization() const override {
630 return kCreatedInitialized;
634 ExportDeclaration(Zone* zone, VariableProxy* proxy, Scope* scope, int pos)
635 : Declaration(zone, proxy, LET, scope, pos) {}
639 class Module : public AstNode {
641 ModuleDescriptor* descriptor() const { return descriptor_; }
642 Block* body() const { return body_; }
645 Module(Zone* zone, int pos)
646 : AstNode(pos), descriptor_(ModuleDescriptor::New(zone)), body_(NULL) {}
647 Module(Zone* zone, ModuleDescriptor* descriptor, int pos, Block* body = NULL)
648 : AstNode(pos), descriptor_(descriptor), body_(body) {}
651 ModuleDescriptor* descriptor_;
656 class IterationStatement : public BreakableStatement {
658 // Type testing & conversion.
659 IterationStatement* AsIterationStatement() final { return this; }
661 Statement* body() const { return body_; }
663 static int num_ids() { return parent_num_ids() + 1; }
664 BailoutId OsrEntryId() const { return BailoutId(local_id(0)); }
665 virtual BailoutId ContinueId() const = 0;
666 virtual BailoutId StackCheckId() const = 0;
669 Label* continue_target() { return &continue_target_; }
672 IterationStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
673 : BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos),
675 static int parent_num_ids() { return BreakableStatement::num_ids(); }
676 void Initialize(Statement* body) { body_ = body; }
679 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
682 Label continue_target_;
686 class DoWhileStatement final : public IterationStatement {
688 DECLARE_NODE_TYPE(DoWhileStatement)
690 void Initialize(Expression* cond, Statement* body) {
691 IterationStatement::Initialize(body);
695 Expression* cond() const { return cond_; }
697 static int num_ids() { return parent_num_ids() + 2; }
698 BailoutId ContinueId() const override { return BailoutId(local_id(0)); }
699 BailoutId StackCheckId() const override { return BackEdgeId(); }
700 BailoutId BackEdgeId() const { return BailoutId(local_id(1)); }
703 DoWhileStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
704 : IterationStatement(zone, labels, pos), cond_(NULL) {}
705 static int parent_num_ids() { return IterationStatement::num_ids(); }
708 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
714 class WhileStatement final : public IterationStatement {
716 DECLARE_NODE_TYPE(WhileStatement)
718 void Initialize(Expression* cond, Statement* body) {
719 IterationStatement::Initialize(body);
723 Expression* cond() const { return cond_; }
725 static int num_ids() { return parent_num_ids() + 1; }
726 BailoutId ContinueId() const override { return EntryId(); }
727 BailoutId StackCheckId() const override { return BodyId(); }
728 BailoutId BodyId() const { return BailoutId(local_id(0)); }
731 WhileStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
732 : IterationStatement(zone, labels, pos), cond_(NULL) {}
733 static int parent_num_ids() { return IterationStatement::num_ids(); }
736 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
742 class ForStatement final : public IterationStatement {
744 DECLARE_NODE_TYPE(ForStatement)
746 void Initialize(Statement* init,
750 IterationStatement::Initialize(body);
756 Statement* init() const { return init_; }
757 Expression* cond() const { return cond_; }
758 Statement* next() const { return next_; }
760 static int num_ids() { return parent_num_ids() + 2; }
761 BailoutId ContinueId() const override { return BailoutId(local_id(0)); }
762 BailoutId StackCheckId() const override { return BodyId(); }
763 BailoutId BodyId() const { return BailoutId(local_id(1)); }
766 ForStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
767 : IterationStatement(zone, labels, pos),
771 static int parent_num_ids() { return IterationStatement::num_ids(); }
774 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
782 class ForEachStatement : public IterationStatement {
785 ENUMERATE, // for (each in subject) body;
786 ITERATE // for (each of subject) body;
789 void Initialize(Expression* each, Expression* subject, Statement* body) {
790 IterationStatement::Initialize(body);
795 Expression* each() const { return each_; }
796 Expression* subject() const { return subject_; }
799 ForEachStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
800 : IterationStatement(zone, labels, pos), each_(NULL), subject_(NULL) {}
804 Expression* subject_;
808 class ForInStatement final : public ForEachStatement {
810 DECLARE_NODE_TYPE(ForInStatement)
812 Expression* enumerable() const {
816 // Type feedback information.
817 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
818 Isolate* isolate, const ICSlotCache* cache) override {
819 return FeedbackVectorRequirements(1, 0);
821 void SetFirstFeedbackSlot(FeedbackVectorSlot slot) override {
822 for_in_feedback_slot_ = slot;
825 FeedbackVectorSlot ForInFeedbackSlot() {
826 DCHECK(!for_in_feedback_slot_.IsInvalid());
827 return for_in_feedback_slot_;
830 enum ForInType { FAST_FOR_IN, SLOW_FOR_IN };
831 ForInType for_in_type() const { return for_in_type_; }
832 void set_for_in_type(ForInType type) { for_in_type_ = type; }
834 static int num_ids() { return parent_num_ids() + 6; }
835 BailoutId BodyId() const { return BailoutId(local_id(0)); }
836 BailoutId PrepareId() const { return BailoutId(local_id(1)); }
837 BailoutId EnumId() const { return BailoutId(local_id(2)); }
838 BailoutId ToObjectId() const { return BailoutId(local_id(3)); }
839 BailoutId FilterId() const { return BailoutId(local_id(4)); }
840 BailoutId AssignmentId() const { return BailoutId(local_id(5)); }
841 BailoutId ContinueId() const override { return EntryId(); }
842 BailoutId StackCheckId() const override { return BodyId(); }
845 ForInStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
846 : ForEachStatement(zone, labels, pos),
847 for_in_type_(SLOW_FOR_IN),
848 for_in_feedback_slot_(FeedbackVectorSlot::Invalid()) {}
849 static int parent_num_ids() { return ForEachStatement::num_ids(); }
852 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
854 ForInType for_in_type_;
855 FeedbackVectorSlot for_in_feedback_slot_;
859 class ForOfStatement final : public ForEachStatement {
861 DECLARE_NODE_TYPE(ForOfStatement)
863 void Initialize(Expression* each,
866 Expression* assign_iterator,
867 Expression* next_result,
868 Expression* result_done,
869 Expression* assign_each) {
870 ForEachStatement::Initialize(each, subject, body);
871 assign_iterator_ = assign_iterator;
872 next_result_ = next_result;
873 result_done_ = result_done;
874 assign_each_ = assign_each;
877 Expression* iterable() const {
881 // iterator = subject[Symbol.iterator]()
882 Expression* assign_iterator() const {
883 return assign_iterator_;
886 // result = iterator.next() // with type check
887 Expression* next_result() const {
892 Expression* result_done() const {
896 // each = result.value
897 Expression* assign_each() const {
901 BailoutId ContinueId() const override { return EntryId(); }
902 BailoutId StackCheckId() const override { return BackEdgeId(); }
904 static int num_ids() { return parent_num_ids() + 1; }
905 BailoutId BackEdgeId() const { return BailoutId(local_id(0)); }
908 ForOfStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
909 : ForEachStatement(zone, labels, pos),
910 assign_iterator_(NULL),
913 assign_each_(NULL) {}
914 static int parent_num_ids() { return ForEachStatement::num_ids(); }
917 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
919 Expression* assign_iterator_;
920 Expression* next_result_;
921 Expression* result_done_;
922 Expression* assign_each_;
926 class ExpressionStatement final : public Statement {
928 DECLARE_NODE_TYPE(ExpressionStatement)
930 void set_expression(Expression* e) { expression_ = e; }
931 Expression* expression() const { return expression_; }
932 bool IsJump() const override { return expression_->IsThrow(); }
935 ExpressionStatement(Zone* zone, Expression* expression, int pos)
936 : Statement(zone, pos), expression_(expression) { }
939 Expression* expression_;
943 class JumpStatement : public Statement {
945 bool IsJump() const final { return true; }
948 explicit JumpStatement(Zone* zone, int pos) : Statement(zone, pos) {}
952 class ContinueStatement final : public JumpStatement {
954 DECLARE_NODE_TYPE(ContinueStatement)
956 IterationStatement* target() const { return target_; }
959 explicit ContinueStatement(Zone* zone, IterationStatement* target, int pos)
960 : JumpStatement(zone, pos), target_(target) { }
963 IterationStatement* target_;
967 class BreakStatement final : public JumpStatement {
969 DECLARE_NODE_TYPE(BreakStatement)
971 BreakableStatement* target() const { return target_; }
974 explicit BreakStatement(Zone* zone, BreakableStatement* target, int pos)
975 : JumpStatement(zone, pos), target_(target) { }
978 BreakableStatement* target_;
982 class ReturnStatement final : public JumpStatement {
984 DECLARE_NODE_TYPE(ReturnStatement)
986 Expression* expression() const { return expression_; }
989 explicit ReturnStatement(Zone* zone, Expression* expression, int pos)
990 : JumpStatement(zone, pos), expression_(expression) { }
993 Expression* expression_;
997 class WithStatement final : public Statement {
999 DECLARE_NODE_TYPE(WithStatement)
1001 Scope* scope() { return scope_; }
1002 Expression* expression() const { return expression_; }
1003 Statement* statement() const { return statement_; }
1005 void set_base_id(int id) { base_id_ = id; }
1006 static int num_ids() { return parent_num_ids() + 1; }
1007 BailoutId EntryId() const { return BailoutId(local_id(0)); }
1010 WithStatement(Zone* zone, Scope* scope, Expression* expression,
1011 Statement* statement, int pos)
1012 : Statement(zone, pos),
1014 expression_(expression),
1015 statement_(statement),
1016 base_id_(BailoutId::None().ToInt()) {}
1017 static int parent_num_ids() { return 0; }
1019 int base_id() const {
1020 DCHECK(!BailoutId(base_id_).IsNone());
1025 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1028 Expression* expression_;
1029 Statement* statement_;
1034 class CaseClause final : public Expression {
1036 DECLARE_NODE_TYPE(CaseClause)
1038 bool is_default() const { return label_ == NULL; }
1039 Expression* label() const {
1040 CHECK(!is_default());
1043 Label* body_target() { return &body_target_; }
1044 ZoneList<Statement*>* statements() const { return statements_; }
1046 static int num_ids() { return parent_num_ids() + 2; }
1047 BailoutId EntryId() const { return BailoutId(local_id(0)); }
1048 TypeFeedbackId CompareId() { return TypeFeedbackId(local_id(1)); }
1050 Type* compare_type() { return compare_type_; }
1051 void set_compare_type(Type* type) { compare_type_ = type; }
1054 static int parent_num_ids() { return Expression::num_ids(); }
1057 CaseClause(Zone* zone, Expression* label, ZoneList<Statement*>* statements,
1059 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1063 ZoneList<Statement*>* statements_;
1064 Type* compare_type_;
1068 class SwitchStatement final : public BreakableStatement {
1070 DECLARE_NODE_TYPE(SwitchStatement)
1072 void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) {
1077 Expression* tag() const { return tag_; }
1078 ZoneList<CaseClause*>* cases() const { return cases_; }
1081 SwitchStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
1082 : BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos),
1088 ZoneList<CaseClause*>* cases_;
1092 // If-statements always have non-null references to their then- and
1093 // else-parts. When parsing if-statements with no explicit else-part,
1094 // the parser implicitly creates an empty statement. Use the
1095 // HasThenStatement() and HasElseStatement() functions to check if a
1096 // given if-statement has a then- or an else-part containing code.
1097 class IfStatement final : public Statement {
1099 DECLARE_NODE_TYPE(IfStatement)
1101 bool HasThenStatement() const { return !then_statement()->IsEmpty(); }
1102 bool HasElseStatement() const { return !else_statement()->IsEmpty(); }
1104 Expression* condition() const { return condition_; }
1105 Statement* then_statement() const { return then_statement_; }
1106 Statement* else_statement() const { return else_statement_; }
1108 bool IsJump() const override {
1109 return HasThenStatement() && then_statement()->IsJump()
1110 && HasElseStatement() && else_statement()->IsJump();
1113 void set_base_id(int id) { base_id_ = id; }
1114 static int num_ids() { return parent_num_ids() + 3; }
1115 BailoutId IfId() const { return BailoutId(local_id(0)); }
1116 BailoutId ThenId() const { return BailoutId(local_id(1)); }
1117 BailoutId ElseId() const { return BailoutId(local_id(2)); }
1120 IfStatement(Zone* zone, Expression* condition, Statement* then_statement,
1121 Statement* else_statement, int pos)
1122 : Statement(zone, pos),
1123 condition_(condition),
1124 then_statement_(then_statement),
1125 else_statement_(else_statement),
1126 base_id_(BailoutId::None().ToInt()) {}
1127 static int parent_num_ids() { return 0; }
1129 int base_id() const {
1130 DCHECK(!BailoutId(base_id_).IsNone());
1135 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1137 Expression* condition_;
1138 Statement* then_statement_;
1139 Statement* else_statement_;
1144 class TryStatement : public Statement {
1146 int index() const { return index_; }
1147 Block* try_block() const { return try_block_; }
1150 TryStatement(Zone* zone, int index, Block* try_block, int pos)
1151 : Statement(zone, pos), index_(index), try_block_(try_block) {}
1154 // Unique (per-function) index of this handler. This is not an AST ID.
1161 class TryCatchStatement final : public TryStatement {
1163 DECLARE_NODE_TYPE(TryCatchStatement)
1165 Scope* scope() { return scope_; }
1166 Variable* variable() { return variable_; }
1167 Block* catch_block() const { return catch_block_; }
1170 TryCatchStatement(Zone* zone,
1177 : TryStatement(zone, index, try_block, pos),
1179 variable_(variable),
1180 catch_block_(catch_block) {
1185 Variable* variable_;
1186 Block* catch_block_;
1190 class TryFinallyStatement final : public TryStatement {
1192 DECLARE_NODE_TYPE(TryFinallyStatement)
1194 Block* finally_block() const { return finally_block_; }
1197 TryFinallyStatement(
1198 Zone* zone, int index, Block* try_block, Block* finally_block, int pos)
1199 : TryStatement(zone, index, try_block, pos),
1200 finally_block_(finally_block) { }
1203 Block* finally_block_;
1207 class DebuggerStatement final : public Statement {
1209 DECLARE_NODE_TYPE(DebuggerStatement)
1211 void set_base_id(int id) { base_id_ = id; }
1212 static int num_ids() { return parent_num_ids() + 1; }
1213 BailoutId DebugBreakId() const { return BailoutId(local_id(0)); }
1216 explicit DebuggerStatement(Zone* zone, int pos)
1217 : Statement(zone, pos), base_id_(BailoutId::None().ToInt()) {}
1218 static int parent_num_ids() { return 0; }
1220 int base_id() const {
1221 DCHECK(!BailoutId(base_id_).IsNone());
1226 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1232 class EmptyStatement final : public Statement {
1234 DECLARE_NODE_TYPE(EmptyStatement)
1237 explicit EmptyStatement(Zone* zone, int pos): Statement(zone, pos) {}
1241 class Literal final : public Expression {
1243 DECLARE_NODE_TYPE(Literal)
1245 bool IsPropertyName() const override { return value_->IsPropertyName(); }
1247 Handle<String> AsPropertyName() {
1248 DCHECK(IsPropertyName());
1249 return Handle<String>::cast(value());
1252 const AstRawString* AsRawPropertyName() {
1253 DCHECK(IsPropertyName());
1254 return value_->AsString();
1257 bool ToBooleanIsTrue() const override { return value()->BooleanValue(); }
1258 bool ToBooleanIsFalse() const override { return !value()->BooleanValue(); }
1260 Handle<Object> value() const { return value_->value(); }
1261 const AstValue* raw_value() const { return value_; }
1263 // Support for using Literal as a HashMap key. NOTE: Currently, this works
1264 // only for string and number literals!
1266 static bool Match(void* literal1, void* literal2);
1268 static int num_ids() { return parent_num_ids() + 1; }
1269 TypeFeedbackId LiteralFeedbackId() const {
1270 return TypeFeedbackId(local_id(0));
1274 Literal(Zone* zone, const AstValue* value, int position)
1275 : Expression(zone, position), value_(value) {}
1276 static int parent_num_ids() { return Expression::num_ids(); }
1279 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1281 const AstValue* value_;
1285 // Base class for literals that needs space in the corresponding JSFunction.
1286 class MaterializedLiteral : public Expression {
1288 virtual MaterializedLiteral* AsMaterializedLiteral() { return this; }
1290 int literal_index() { return literal_index_; }
1293 // only callable after initialization.
1294 DCHECK(depth_ >= 1);
1298 bool is_strong() const { return is_strong_; }
1301 MaterializedLiteral(Zone* zone, int literal_index, bool is_strong, int pos)
1302 : Expression(zone, pos),
1303 literal_index_(literal_index),
1305 is_strong_(is_strong),
1308 // A materialized literal is simple if the values consist of only
1309 // constants and simple object and array literals.
1310 bool is_simple() const { return is_simple_; }
1311 void set_is_simple(bool is_simple) { is_simple_ = is_simple; }
1312 friend class CompileTimeValue;
1314 void set_depth(int depth) {
1319 // Populate the constant properties/elements fixed array.
1320 void BuildConstants(Isolate* isolate);
1321 friend class ArrayLiteral;
1322 friend class ObjectLiteral;
1324 // If the expression is a literal, return the literal value;
1325 // if the expression is a materialized literal and is simple return a
1326 // compile time value as encoded by CompileTimeValue::GetValue().
1327 // Otherwise, return undefined literal as the placeholder
1328 // in the object literal boilerplate.
1329 Handle<Object> GetBoilerplateValue(Expression* expression, Isolate* isolate);
1339 // Property is used for passing information
1340 // about an object literal's properties from the parser
1341 // to the code generator.
1342 class ObjectLiteralProperty final : public ZoneObject {
1345 CONSTANT, // Property with constant value (compile time).
1346 COMPUTED, // Property with computed value (execution time).
1347 MATERIALIZED_LITERAL, // Property value is a materialized literal.
1348 GETTER, SETTER, // Property is an accessor function.
1349 PROTOTYPE // Property is __proto__.
1352 Expression* key() { return key_; }
1353 Expression* value() { return value_; }
1354 Kind kind() { return kind_; }
1356 // Type feedback information.
1357 bool IsMonomorphic() { return !receiver_type_.is_null(); }
1358 Handle<Map> GetReceiverType() { return receiver_type_; }
1360 bool IsCompileTimeValue();
1362 void set_emit_store(bool emit_store);
1365 bool is_static() const { return is_static_; }
1366 bool is_computed_name() const { return is_computed_name_; }
1368 void set_receiver_type(Handle<Map> map) { receiver_type_ = map; }
1371 friend class AstNodeFactory;
1373 ObjectLiteralProperty(Expression* key, Expression* value, Kind kind,
1374 bool is_static, bool is_computed_name);
1375 ObjectLiteralProperty(AstValueFactory* ast_value_factory, Expression* key,
1376 Expression* value, bool is_static,
1377 bool is_computed_name);
1385 bool is_computed_name_;
1386 Handle<Map> receiver_type_;
1390 // An object literal has a boilerplate object that is used
1391 // for minimizing the work when constructing it at runtime.
1392 class ObjectLiteral final : public MaterializedLiteral {
1394 typedef ObjectLiteralProperty Property;
1396 DECLARE_NODE_TYPE(ObjectLiteral)
1398 Handle<FixedArray> constant_properties() const {
1399 return constant_properties_;
1401 int properties_count() const { return constant_properties_->length() / 2; }
1402 ZoneList<Property*>* properties() const { return properties_; }
1403 bool fast_elements() const { return fast_elements_; }
1404 bool may_store_doubles() const { return may_store_doubles_; }
1405 bool has_function() const { return has_function_; }
1406 bool has_elements() const { return has_elements_; }
1408 // Decide if a property should be in the object boilerplate.
1409 static bool IsBoilerplateProperty(Property* property);
1411 // Populate the constant properties fixed array.
1412 void BuildConstantProperties(Isolate* isolate);
1414 // Mark all computed expressions that are bound to a key that
1415 // is shadowed by a later occurrence of the same key. For the
1416 // marked expressions, no store code is emitted.
1417 void CalculateEmitStore(Zone* zone);
1419 // Assemble bitfield of flags for the CreateObjectLiteral helper.
1420 int ComputeFlags(bool disable_mementos = false) const {
1421 int flags = fast_elements() ? kFastElements : kNoFlags;
1422 flags |= has_function() ? kHasFunction : kNoFlags;
1423 if (depth() == 1 && !has_elements() && !may_store_doubles()) {
1424 flags |= kShallowProperties;
1426 if (disable_mementos) {
1427 flags |= kDisableMementos;
1438 kHasFunction = 1 << 1,
1439 kShallowProperties = 1 << 2,
1440 kDisableMementos = 1 << 3,
1444 struct Accessors: public ZoneObject {
1445 Accessors() : getter(NULL), setter(NULL) {}
1450 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); }
1452 // Return an AST id for a property that is used in simulate instructions.
1453 BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 1)); }
1455 // Unlike other AST nodes, this number of bailout IDs allocated for an
1456 // ObjectLiteral can vary, so num_ids() is not a static method.
1457 int num_ids() const { return parent_num_ids() + 1 + properties()->length(); }
1460 ObjectLiteral(Zone* zone, ZoneList<Property*>* properties, int literal_index,
1461 int boilerplate_properties, bool has_function,
1462 bool is_strong, int pos)
1463 : MaterializedLiteral(zone, literal_index, is_strong, pos),
1464 properties_(properties),
1465 boilerplate_properties_(boilerplate_properties),
1466 fast_elements_(false),
1467 has_elements_(false),
1468 may_store_doubles_(false),
1469 has_function_(has_function) {}
1470 static int parent_num_ids() { return MaterializedLiteral::num_ids(); }
1473 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1474 Handle<FixedArray> constant_properties_;
1475 ZoneList<Property*>* properties_;
1476 int boilerplate_properties_;
1477 bool fast_elements_;
1479 bool may_store_doubles_;
1484 // Node for capturing a regexp literal.
1485 class RegExpLiteral final : public MaterializedLiteral {
1487 DECLARE_NODE_TYPE(RegExpLiteral)
1489 Handle<String> pattern() const { return pattern_->string(); }
1490 Handle<String> flags() const { return flags_->string(); }
1493 RegExpLiteral(Zone* zone, const AstRawString* pattern,
1494 const AstRawString* flags, int literal_index, bool is_strong,
1496 : MaterializedLiteral(zone, literal_index, is_strong, pos),
1503 const AstRawString* pattern_;
1504 const AstRawString* flags_;
1508 // An array literal has a literals object that is used
1509 // for minimizing the work when constructing it at runtime.
1510 class ArrayLiteral final : public MaterializedLiteral {
1512 DECLARE_NODE_TYPE(ArrayLiteral)
1514 Handle<FixedArray> constant_elements() const { return constant_elements_; }
1515 ElementsKind constant_elements_kind() const {
1516 DCHECK_EQ(2, constant_elements_->length());
1517 return static_cast<ElementsKind>(
1518 Smi::cast(constant_elements_->get(0))->value());
1521 ZoneList<Expression*>* values() const { return values_; }
1523 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); }
1525 // Return an AST id for an element that is used in simulate instructions.
1526 BailoutId GetIdForElement(int i) { return BailoutId(local_id(i + 1)); }
1528 // Unlike other AST nodes, this number of bailout IDs allocated for an
1529 // ArrayLiteral can vary, so num_ids() is not a static method.
1530 int num_ids() const { return parent_num_ids() + 1 + values()->length(); }
1532 // Populate the constant elements fixed array.
1533 void BuildConstantElements(Isolate* isolate);
1535 // Assemble bitfield of flags for the CreateArrayLiteral helper.
1536 int ComputeFlags(bool disable_mementos = false) const {
1537 int flags = depth() == 1 ? kShallowElements : kNoFlags;
1538 if (disable_mementos) {
1539 flags |= kDisableMementos;
1549 kShallowElements = 1,
1550 kDisableMementos = 1 << 1,
1555 ArrayLiteral(Zone* zone, ZoneList<Expression*>* values, int literal_index,
1556 bool is_strong, int pos)
1557 : MaterializedLiteral(zone, literal_index, is_strong, pos),
1559 static int parent_num_ids() { return MaterializedLiteral::num_ids(); }
1562 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1564 Handle<FixedArray> constant_elements_;
1565 ZoneList<Expression*>* values_;
1569 class VariableProxy final : public Expression {
1571 DECLARE_NODE_TYPE(VariableProxy)
1573 bool IsValidReferenceExpression() const override { return !is_this(); }
1575 bool IsArguments() const { return is_resolved() && var()->is_arguments(); }
1577 Handle<String> name() const { return raw_name()->string(); }
1578 const AstRawString* raw_name() const {
1579 return is_resolved() ? var_->raw_name() : raw_name_;
1582 Variable* var() const {
1583 DCHECK(is_resolved());
1586 void set_var(Variable* v) {
1587 DCHECK(!is_resolved());
1592 bool is_this() const { return IsThisField::decode(bit_field_); }
1594 bool is_assigned() const { return IsAssignedField::decode(bit_field_); }
1595 void set_is_assigned() {
1596 bit_field_ = IsAssignedField::update(bit_field_, true);
1599 bool is_resolved() const { return IsResolvedField::decode(bit_field_); }
1600 void set_is_resolved() {
1601 bit_field_ = IsResolvedField::update(bit_field_, true);
1604 int end_position() const { return end_position_; }
1606 // Bind this proxy to the variable var.
1607 void BindTo(Variable* var);
1609 bool UsesVariableFeedbackSlot() const {
1610 return var()->IsUnallocated() || var()->IsLookupSlot();
1613 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
1614 Isolate* isolate, const ICSlotCache* cache) override;
1616 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot,
1617 ICSlotCache* cache) override;
1618 Code::Kind FeedbackICSlotKind(int index) override { return Code::LOAD_IC; }
1619 FeedbackVectorICSlot VariableFeedbackSlot() {
1620 DCHECK(!UsesVariableFeedbackSlot() || !variable_feedback_slot_.IsInvalid());
1621 return variable_feedback_slot_;
1624 static int num_ids() { return parent_num_ids() + 1; }
1625 BailoutId BeforeId() const { return BailoutId(local_id(0)); }
1628 VariableProxy(Zone* zone, Variable* var, int start_position,
1631 VariableProxy(Zone* zone, const AstRawString* name,
1632 Variable::Kind variable_kind, int start_position,
1634 static int parent_num_ids() { return Expression::num_ids(); }
1635 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1637 class IsThisField : public BitField8<bool, 0, 1> {};
1638 class IsAssignedField : public BitField8<bool, 1, 1> {};
1639 class IsResolvedField : public BitField8<bool, 2, 1> {};
1641 // Start with 16-bit (or smaller) field, which should get packed together
1642 // with Expression's trailing 16-bit field.
1644 FeedbackVectorICSlot variable_feedback_slot_;
1646 const AstRawString* raw_name_; // if !is_resolved_
1647 Variable* var_; // if is_resolved_
1649 // Position is stored in the AstNode superclass, but VariableProxy needs to
1650 // know its end position too (for error messages). It cannot be inferred from
1651 // the variable name length because it can contain escapes.
1656 class Property final : public Expression {
1658 DECLARE_NODE_TYPE(Property)
1660 bool IsValidReferenceExpression() const override { return true; }
1662 Expression* obj() const { return obj_; }
1663 Expression* key() const { return key_; }
1665 static int num_ids() { return parent_num_ids() + 2; }
1666 BailoutId LoadId() const { return BailoutId(local_id(0)); }
1667 TypeFeedbackId PropertyFeedbackId() { return TypeFeedbackId(local_id(1)); }
1669 bool IsStringAccess() const {
1670 return IsStringAccessField::decode(bit_field_);
1673 // Type feedback information.
1674 bool IsMonomorphic() override { return receiver_types_.length() == 1; }
1675 SmallMapList* GetReceiverTypes() override { return &receiver_types_; }
1676 KeyedAccessStoreMode GetStoreMode() const override { return STANDARD_STORE; }
1677 IcCheckType GetKeyType() const override {
1678 return KeyTypeField::decode(bit_field_);
1680 bool IsUninitialized() const {
1681 return !is_for_call() && HasNoTypeInformation();
1683 bool HasNoTypeInformation() const {
1684 return GetInlineCacheState() == UNINITIALIZED;
1686 InlineCacheState GetInlineCacheState() const {
1687 return InlineCacheStateField::decode(bit_field_);
1689 void set_is_string_access(bool b) {
1690 bit_field_ = IsStringAccessField::update(bit_field_, b);
1692 void set_key_type(IcCheckType key_type) {
1693 bit_field_ = KeyTypeField::update(bit_field_, key_type);
1695 void set_inline_cache_state(InlineCacheState state) {
1696 bit_field_ = InlineCacheStateField::update(bit_field_, state);
1698 void mark_for_call() {
1699 bit_field_ = IsForCallField::update(bit_field_, true);
1701 bool is_for_call() const { return IsForCallField::decode(bit_field_); }
1703 bool IsSuperAccess() {
1704 return obj()->IsSuperReference();
1707 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
1708 Isolate* isolate, const ICSlotCache* cache) override {
1709 return FeedbackVectorRequirements(0, 1);
1711 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot,
1712 ICSlotCache* cache) override {
1713 property_feedback_slot_ = slot;
1715 Code::Kind FeedbackICSlotKind(int index) override {
1716 return key()->IsPropertyName() ? Code::LOAD_IC : Code::KEYED_LOAD_IC;
1719 FeedbackVectorICSlot PropertyFeedbackSlot() const {
1720 DCHECK(!property_feedback_slot_.IsInvalid());
1721 return property_feedback_slot_;
1725 Property(Zone* zone, Expression* obj, Expression* key, int pos)
1726 : Expression(zone, pos),
1727 bit_field_(IsForCallField::encode(false) |
1728 IsStringAccessField::encode(false) |
1729 InlineCacheStateField::encode(UNINITIALIZED)),
1730 property_feedback_slot_(FeedbackVectorICSlot::Invalid()),
1733 static int parent_num_ids() { return Expression::num_ids(); }
1736 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1738 class IsForCallField : public BitField8<bool, 0, 1> {};
1739 class IsStringAccessField : public BitField8<bool, 1, 1> {};
1740 class KeyTypeField : public BitField8<IcCheckType, 2, 1> {};
1741 class InlineCacheStateField : public BitField8<InlineCacheState, 3, 4> {};
1743 FeedbackVectorICSlot property_feedback_slot_;
1746 SmallMapList receiver_types_;
1750 class Call final : public Expression {
1752 DECLARE_NODE_TYPE(Call)
1754 Expression* expression() const { return expression_; }
1755 ZoneList<Expression*>* arguments() const { return arguments_; }
1757 // Type feedback information.
1758 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
1759 Isolate* isolate, const ICSlotCache* cache) override;
1760 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot,
1761 ICSlotCache* cache) override {
1762 ic_slot_or_slot_ = slot.ToInt();
1764 void SetFirstFeedbackSlot(FeedbackVectorSlot slot) override {
1765 ic_slot_or_slot_ = slot.ToInt();
1767 Code::Kind FeedbackICSlotKind(int index) override { return Code::CALL_IC; }
1769 FeedbackVectorSlot CallFeedbackSlot() const {
1770 DCHECK(ic_slot_or_slot_ != FeedbackVectorSlot::Invalid().ToInt());
1771 return FeedbackVectorSlot(ic_slot_or_slot_);
1774 FeedbackVectorICSlot CallFeedbackICSlot() const {
1775 DCHECK(ic_slot_or_slot_ != FeedbackVectorICSlot::Invalid().ToInt());
1776 return FeedbackVectorICSlot(ic_slot_or_slot_);
1779 SmallMapList* GetReceiverTypes() override {
1780 if (expression()->IsProperty()) {
1781 return expression()->AsProperty()->GetReceiverTypes();
1786 bool IsMonomorphic() override {
1787 if (expression()->IsProperty()) {
1788 return expression()->AsProperty()->IsMonomorphic();
1790 return !target_.is_null();
1793 bool global_call() const {
1794 VariableProxy* proxy = expression_->AsVariableProxy();
1795 return proxy != NULL && proxy->var()->IsUnallocated();
1798 bool known_global_function() const {
1799 return global_call() && !target_.is_null();
1802 Handle<JSFunction> target() { return target_; }
1804 Handle<AllocationSite> allocation_site() { return allocation_site_; }
1806 void SetKnownGlobalTarget(Handle<JSFunction> target) {
1808 set_is_uninitialized(false);
1810 void set_target(Handle<JSFunction> target) { target_ = target; }
1811 void set_allocation_site(Handle<AllocationSite> site) {
1812 allocation_site_ = site;
1815 static int num_ids() { return parent_num_ids() + 2; }
1816 BailoutId ReturnId() const { return BailoutId(local_id(0)); }
1817 BailoutId EvalOrLookupId() const { return BailoutId(local_id(1)); }
1819 bool is_uninitialized() const {
1820 return IsUninitializedField::decode(bit_field_);
1822 void set_is_uninitialized(bool b) {
1823 bit_field_ = IsUninitializedField::update(bit_field_, b);
1835 // Helpers to determine how to handle the call.
1836 CallType GetCallType(Isolate* isolate) const;
1837 bool IsUsingCallFeedbackSlot(Isolate* isolate) const;
1838 bool IsUsingCallFeedbackICSlot(Isolate* isolate) const;
1841 // Used to assert that the FullCodeGenerator records the return site.
1842 bool return_is_recorded_;
1846 Call(Zone* zone, Expression* expression, ZoneList<Expression*>* arguments,
1848 : Expression(zone, pos),
1849 ic_slot_or_slot_(FeedbackVectorICSlot::Invalid().ToInt()),
1850 expression_(expression),
1851 arguments_(arguments),
1852 bit_field_(IsUninitializedField::encode(false)) {
1853 if (expression->IsProperty()) {
1854 expression->AsProperty()->mark_for_call();
1857 static int parent_num_ids() { return Expression::num_ids(); }
1860 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1862 // We store this as an integer because we don't know if we have a slot or
1863 // an ic slot until scoping time.
1864 int ic_slot_or_slot_;
1865 Expression* expression_;
1866 ZoneList<Expression*>* arguments_;
1867 Handle<JSFunction> target_;
1868 Handle<AllocationSite> allocation_site_;
1869 class IsUninitializedField : public BitField8<bool, 0, 1> {};
1874 class CallNew final : public Expression {
1876 DECLARE_NODE_TYPE(CallNew)
1878 Expression* expression() const { return expression_; }
1879 ZoneList<Expression*>* arguments() const { return arguments_; }
1881 // Type feedback information.
1882 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
1883 Isolate* isolate, const ICSlotCache* cache) override {
1884 return FeedbackVectorRequirements(FLAG_pretenuring_call_new ? 2 : 1, 0);
1886 void SetFirstFeedbackSlot(FeedbackVectorSlot slot) override {
1887 callnew_feedback_slot_ = slot;
1890 FeedbackVectorSlot CallNewFeedbackSlot() {
1891 DCHECK(!callnew_feedback_slot_.IsInvalid());
1892 return callnew_feedback_slot_;
1894 FeedbackVectorSlot AllocationSiteFeedbackSlot() {
1895 DCHECK(FLAG_pretenuring_call_new);
1896 return CallNewFeedbackSlot().next();
1899 bool IsMonomorphic() override { return is_monomorphic_; }
1900 Handle<JSFunction> target() const { return target_; }
1901 Handle<AllocationSite> allocation_site() const {
1902 return allocation_site_;
1905 static int num_ids() { return parent_num_ids() + 1; }
1906 static int feedback_slots() { return 1; }
1907 BailoutId ReturnId() const { return BailoutId(local_id(0)); }
1909 void set_allocation_site(Handle<AllocationSite> site) {
1910 allocation_site_ = site;
1912 void set_is_monomorphic(bool monomorphic) { is_monomorphic_ = monomorphic; }
1913 void set_target(Handle<JSFunction> target) { target_ = target; }
1914 void SetKnownGlobalTarget(Handle<JSFunction> target) {
1916 is_monomorphic_ = true;
1920 CallNew(Zone* zone, Expression* expression, ZoneList<Expression*>* arguments,
1922 : Expression(zone, pos),
1923 expression_(expression),
1924 arguments_(arguments),
1925 is_monomorphic_(false),
1926 callnew_feedback_slot_(FeedbackVectorSlot::Invalid()) {}
1928 static int parent_num_ids() { return Expression::num_ids(); }
1931 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1933 Expression* expression_;
1934 ZoneList<Expression*>* arguments_;
1935 bool is_monomorphic_;
1936 Handle<JSFunction> target_;
1937 Handle<AllocationSite> allocation_site_;
1938 FeedbackVectorSlot callnew_feedback_slot_;
1942 // The CallRuntime class does not represent any official JavaScript
1943 // language construct. Instead it is used to call a C or JS function
1944 // with a set of arguments. This is used from the builtins that are
1945 // implemented in JavaScript (see "v8natives.js").
1946 class CallRuntime final : public Expression {
1948 DECLARE_NODE_TYPE(CallRuntime)
1950 Handle<String> name() const { return raw_name_->string(); }
1951 const AstRawString* raw_name() const { return raw_name_; }
1952 const Runtime::Function* function() const { return function_; }
1953 ZoneList<Expression*>* arguments() const { return arguments_; }
1954 bool is_jsruntime() const { return function_ == NULL; }
1956 // Type feedback information.
1957 bool HasCallRuntimeFeedbackSlot() const { return is_jsruntime(); }
1958 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
1959 Isolate* isolate, const ICSlotCache* cache) override {
1960 return FeedbackVectorRequirements(0, HasCallRuntimeFeedbackSlot() ? 1 : 0);
1962 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot,
1963 ICSlotCache* cache) override {
1964 callruntime_feedback_slot_ = slot;
1966 Code::Kind FeedbackICSlotKind(int index) override { return Code::LOAD_IC; }
1968 FeedbackVectorICSlot CallRuntimeFeedbackSlot() {
1969 DCHECK(!HasCallRuntimeFeedbackSlot() ||
1970 !callruntime_feedback_slot_.IsInvalid());
1971 return callruntime_feedback_slot_;
1974 static int num_ids() { return parent_num_ids() + 1; }
1975 TypeFeedbackId CallRuntimeFeedbackId() const {
1976 return TypeFeedbackId(local_id(0));
1980 CallRuntime(Zone* zone, const AstRawString* name,
1981 const Runtime::Function* function,
1982 ZoneList<Expression*>* arguments, int pos)
1983 : Expression(zone, pos),
1985 function_(function),
1986 arguments_(arguments),
1987 callruntime_feedback_slot_(FeedbackVectorICSlot::Invalid()) {}
1988 static int parent_num_ids() { return Expression::num_ids(); }
1991 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1993 const AstRawString* raw_name_;
1994 const Runtime::Function* function_;
1995 ZoneList<Expression*>* arguments_;
1996 FeedbackVectorICSlot callruntime_feedback_slot_;
2000 class UnaryOperation final : public Expression {
2002 DECLARE_NODE_TYPE(UnaryOperation)
2004 Token::Value op() const { return op_; }
2005 Expression* expression() const { return expression_; }
2007 // For unary not (Token::NOT), the AST ids where true and false will
2008 // actually be materialized, respectively.
2009 static int num_ids() { return parent_num_ids() + 2; }
2010 BailoutId MaterializeTrueId() const { return BailoutId(local_id(0)); }
2011 BailoutId MaterializeFalseId() const { return BailoutId(local_id(1)); }
2013 virtual void RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle) override;
2016 UnaryOperation(Zone* zone, Token::Value op, Expression* expression, int pos)
2017 : Expression(zone, pos), op_(op), expression_(expression) {
2018 DCHECK(Token::IsUnaryOp(op));
2020 static int parent_num_ids() { return Expression::num_ids(); }
2023 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2026 Expression* expression_;
2030 class BinaryOperation final : public Expression {
2032 DECLARE_NODE_TYPE(BinaryOperation)
2034 Token::Value op() const { return static_cast<Token::Value>(op_); }
2035 Expression* left() const { return left_; }
2036 Expression* right() const { return right_; }
2037 Handle<AllocationSite> allocation_site() const { return allocation_site_; }
2038 void set_allocation_site(Handle<AllocationSite> allocation_site) {
2039 allocation_site_ = allocation_site;
2042 // The short-circuit logical operations need an AST ID for their
2043 // right-hand subexpression.
2044 static int num_ids() { return parent_num_ids() + 2; }
2045 BailoutId RightId() const { return BailoutId(local_id(0)); }
2047 TypeFeedbackId BinaryOperationFeedbackId() const {
2048 return TypeFeedbackId(local_id(1));
2050 Maybe<int> fixed_right_arg() const {
2051 return has_fixed_right_arg_ ? Just(fixed_right_arg_value_) : Nothing<int>();
2053 void set_fixed_right_arg(Maybe<int> arg) {
2054 has_fixed_right_arg_ = arg.IsJust();
2055 if (arg.IsJust()) fixed_right_arg_value_ = arg.FromJust();
2058 virtual void RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle) override;
2061 BinaryOperation(Zone* zone, Token::Value op, Expression* left,
2062 Expression* right, int pos)
2063 : Expression(zone, pos),
2064 op_(static_cast<byte>(op)),
2065 has_fixed_right_arg_(false),
2066 fixed_right_arg_value_(0),
2069 DCHECK(Token::IsBinaryOp(op));
2071 static int parent_num_ids() { return Expression::num_ids(); }
2074 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2076 const byte op_; // actually Token::Value
2077 // TODO(rossberg): the fixed arg should probably be represented as a Constant
2078 // type for the RHS. Currenty it's actually a Maybe<int>
2079 bool has_fixed_right_arg_;
2080 int fixed_right_arg_value_;
2083 Handle<AllocationSite> allocation_site_;
2087 class CountOperation final : public Expression {
2089 DECLARE_NODE_TYPE(CountOperation)
2091 bool is_prefix() const { return IsPrefixField::decode(bit_field_); }
2092 bool is_postfix() const { return !is_prefix(); }
2094 Token::Value op() const { return TokenField::decode(bit_field_); }
2095 Token::Value binary_op() {
2096 return (op() == Token::INC) ? Token::ADD : Token::SUB;
2099 Expression* expression() const { return expression_; }
2101 bool IsMonomorphic() override { return receiver_types_.length() == 1; }
2102 SmallMapList* GetReceiverTypes() override { return &receiver_types_; }
2103 IcCheckType GetKeyType() const override {
2104 return KeyTypeField::decode(bit_field_);
2106 KeyedAccessStoreMode GetStoreMode() const override {
2107 return StoreModeField::decode(bit_field_);
2109 Type* type() const { return type_; }
2110 void set_key_type(IcCheckType type) {
2111 bit_field_ = KeyTypeField::update(bit_field_, type);
2113 void set_store_mode(KeyedAccessStoreMode mode) {
2114 bit_field_ = StoreModeField::update(bit_field_, mode);
2116 void set_type(Type* type) { type_ = type; }
2118 static int num_ids() { return parent_num_ids() + 4; }
2119 BailoutId AssignmentId() const { return BailoutId(local_id(0)); }
2120 BailoutId ToNumberId() const { return BailoutId(local_id(1)); }
2121 TypeFeedbackId CountBinOpFeedbackId() const {
2122 return TypeFeedbackId(local_id(2));
2124 TypeFeedbackId CountStoreFeedbackId() const {
2125 return TypeFeedbackId(local_id(3));
2129 CountOperation(Zone* zone, Token::Value op, bool is_prefix, Expression* expr,
2131 : Expression(zone, pos),
2132 bit_field_(IsPrefixField::encode(is_prefix) |
2133 KeyTypeField::encode(ELEMENT) |
2134 StoreModeField::encode(STANDARD_STORE) |
2135 TokenField::encode(op)),
2137 expression_(expr) {}
2138 static int parent_num_ids() { return Expression::num_ids(); }
2141 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2143 class IsPrefixField : public BitField16<bool, 0, 1> {};
2144 class KeyTypeField : public BitField16<IcCheckType, 1, 1> {};
2145 class StoreModeField : public BitField16<KeyedAccessStoreMode, 2, 4> {};
2146 class TokenField : public BitField16<Token::Value, 6, 8> {};
2148 // Starts with 16-bit field, which should get packed together with
2149 // Expression's trailing 16-bit field.
2150 uint16_t bit_field_;
2152 Expression* expression_;
2153 SmallMapList receiver_types_;
2157 class CompareOperation final : public Expression {
2159 DECLARE_NODE_TYPE(CompareOperation)
2161 Token::Value op() const { return op_; }
2162 Expression* left() const { return left_; }
2163 Expression* right() const { return right_; }
2165 // Type feedback information.
2166 static int num_ids() { return parent_num_ids() + 1; }
2167 TypeFeedbackId CompareOperationFeedbackId() const {
2168 return TypeFeedbackId(local_id(0));
2170 Type* combined_type() const { return combined_type_; }
2171 void set_combined_type(Type* type) { combined_type_ = type; }
2173 // Match special cases.
2174 bool IsLiteralCompareTypeof(Expression** expr, Handle<String>* check);
2175 bool IsLiteralCompareUndefined(Expression** expr, Isolate* isolate);
2176 bool IsLiteralCompareNull(Expression** expr);
2179 CompareOperation(Zone* zone, Token::Value op, Expression* left,
2180 Expression* right, int pos)
2181 : Expression(zone, pos),
2185 combined_type_(Type::None(zone)) {
2186 DCHECK(Token::IsCompareOp(op));
2188 static int parent_num_ids() { return Expression::num_ids(); }
2191 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2197 Type* combined_type_;
2201 class Spread final : public Expression {
2203 DECLARE_NODE_TYPE(Spread)
2205 Expression* expression() const { return expression_; }
2207 static int num_ids() { return parent_num_ids(); }
2210 Spread(Zone* zone, Expression* expression, int pos)
2211 : Expression(zone, pos), expression_(expression) {}
2212 static int parent_num_ids() { return Expression::num_ids(); }
2215 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2217 Expression* expression_;
2221 class Conditional final : public Expression {
2223 DECLARE_NODE_TYPE(Conditional)
2225 Expression* condition() const { return condition_; }
2226 Expression* then_expression() const { return then_expression_; }
2227 Expression* else_expression() const { return else_expression_; }
2229 static int num_ids() { return parent_num_ids() + 2; }
2230 BailoutId ThenId() const { return BailoutId(local_id(0)); }
2231 BailoutId ElseId() const { return BailoutId(local_id(1)); }
2234 Conditional(Zone* zone, Expression* condition, Expression* then_expression,
2235 Expression* else_expression, int position)
2236 : Expression(zone, position),
2237 condition_(condition),
2238 then_expression_(then_expression),
2239 else_expression_(else_expression) {}
2240 static int parent_num_ids() { return Expression::num_ids(); }
2243 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2245 Expression* condition_;
2246 Expression* then_expression_;
2247 Expression* else_expression_;
2251 class Assignment final : public Expression {
2253 DECLARE_NODE_TYPE(Assignment)
2255 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; }
2257 Token::Value binary_op() const;
2259 Token::Value op() const { return TokenField::decode(bit_field_); }
2260 Expression* target() const { return target_; }
2261 Expression* value() const { return value_; }
2262 BinaryOperation* binary_operation() const { return binary_operation_; }
2264 // This check relies on the definition order of token in token.h.
2265 bool is_compound() const { return op() > Token::ASSIGN; }
2267 static int num_ids() { return parent_num_ids() + 2; }
2268 BailoutId AssignmentId() const { return BailoutId(local_id(0)); }
2270 // Type feedback information.
2271 TypeFeedbackId AssignmentFeedbackId() { return TypeFeedbackId(local_id(1)); }
2272 bool IsMonomorphic() override { return receiver_types_.length() == 1; }
2273 bool IsUninitialized() const {
2274 return IsUninitializedField::decode(bit_field_);
2276 bool HasNoTypeInformation() {
2277 return IsUninitializedField::decode(bit_field_);
2279 SmallMapList* GetReceiverTypes() override { return &receiver_types_; }
2280 IcCheckType GetKeyType() const override {
2281 return KeyTypeField::decode(bit_field_);
2283 KeyedAccessStoreMode GetStoreMode() const override {
2284 return StoreModeField::decode(bit_field_);
2286 void set_is_uninitialized(bool b) {
2287 bit_field_ = IsUninitializedField::update(bit_field_, b);
2289 void set_key_type(IcCheckType key_type) {
2290 bit_field_ = KeyTypeField::update(bit_field_, key_type);
2292 void set_store_mode(KeyedAccessStoreMode mode) {
2293 bit_field_ = StoreModeField::update(bit_field_, mode);
2297 Assignment(Zone* zone, Token::Value op, Expression* target, Expression* value,
2299 static int parent_num_ids() { return Expression::num_ids(); }
2302 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2304 class IsUninitializedField : public BitField16<bool, 0, 1> {};
2305 class KeyTypeField : public BitField16<IcCheckType, 1, 1> {};
2306 class StoreModeField : public BitField16<KeyedAccessStoreMode, 2, 4> {};
2307 class TokenField : public BitField16<Token::Value, 6, 8> {};
2309 // Starts with 16-bit field, which should get packed together with
2310 // Expression's trailing 16-bit field.
2311 uint16_t bit_field_;
2312 Expression* target_;
2314 BinaryOperation* binary_operation_;
2315 SmallMapList receiver_types_;
2319 class Yield final : public Expression {
2321 DECLARE_NODE_TYPE(Yield)
2324 kInitial, // The initial yield that returns the unboxed generator object.
2325 kSuspend, // A normal yield: { value: EXPRESSION, done: false }
2326 kDelegating, // A yield*.
2327 kFinal // A return: { value: EXPRESSION, done: true }
2330 Expression* generator_object() const { return generator_object_; }
2331 Expression* expression() const { return expression_; }
2332 Kind yield_kind() const { return yield_kind_; }
2334 // Delegating yield surrounds the "yield" in a "try/catch". This index
2335 // locates the catch handler in the handler table, and is equivalent to
2336 // TryCatchStatement::index().
2338 DCHECK_EQ(kDelegating, yield_kind());
2341 void set_index(int index) {
2342 DCHECK_EQ(kDelegating, yield_kind());
2346 // Type feedback information.
2347 bool HasFeedbackSlots() const { return yield_kind() == kDelegating; }
2348 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
2349 Isolate* isolate, const ICSlotCache* cache) override {
2350 return FeedbackVectorRequirements(0, HasFeedbackSlots() ? 3 : 0);
2352 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot,
2353 ICSlotCache* cache) override {
2354 yield_first_feedback_slot_ = slot;
2356 Code::Kind FeedbackICSlotKind(int index) override {
2357 return index == 0 ? Code::KEYED_LOAD_IC : Code::LOAD_IC;
2360 FeedbackVectorICSlot KeyedLoadFeedbackSlot() {
2361 DCHECK(!HasFeedbackSlots() || !yield_first_feedback_slot_.IsInvalid());
2362 return yield_first_feedback_slot_;
2365 FeedbackVectorICSlot DoneFeedbackSlot() {
2366 return KeyedLoadFeedbackSlot().next();
2369 FeedbackVectorICSlot ValueFeedbackSlot() { return DoneFeedbackSlot().next(); }
2372 Yield(Zone* zone, Expression* generator_object, Expression* expression,
2373 Kind yield_kind, int pos)
2374 : Expression(zone, pos),
2375 generator_object_(generator_object),
2376 expression_(expression),
2377 yield_kind_(yield_kind),
2379 yield_first_feedback_slot_(FeedbackVectorICSlot::Invalid()) {}
2382 Expression* generator_object_;
2383 Expression* expression_;
2386 FeedbackVectorICSlot yield_first_feedback_slot_;
2390 class Throw final : public Expression {
2392 DECLARE_NODE_TYPE(Throw)
2394 Expression* exception() const { return exception_; }
2397 Throw(Zone* zone, Expression* exception, int pos)
2398 : Expression(zone, pos), exception_(exception) {}
2401 Expression* exception_;
2405 class FunctionLiteral final : public Expression {
2408 ANONYMOUS_EXPRESSION,
2413 enum ParameterFlag {
2414 kNoDuplicateParameters = 0,
2415 kHasDuplicateParameters = 1
2418 enum IsFunctionFlag {
2423 enum EagerCompileHint { kShouldEagerCompile, kShouldLazyCompile };
2425 enum ShouldBeUsedOnceHint { kShouldBeUsedOnce, kDontKnowIfShouldBeUsedOnce };
2427 enum ArityRestriction {
2433 DECLARE_NODE_TYPE(FunctionLiteral)
2435 Handle<String> name() const { return raw_name_->string(); }
2436 const AstRawString* raw_name() const { return raw_name_; }
2437 Scope* scope() const { return scope_; }
2438 ZoneList<Statement*>* body() const { return body_; }
2439 void set_function_token_position(int pos) { function_token_position_ = pos; }
2440 int function_token_position() const { return function_token_position_; }
2441 int start_position() const;
2442 int end_position() const;
2443 int SourceSize() const { return end_position() - start_position(); }
2444 bool is_expression() const { return IsExpression::decode(bitfield_); }
2445 bool is_anonymous() const { return IsAnonymous::decode(bitfield_); }
2446 LanguageMode language_mode() const;
2447 bool uses_super_property() const;
2449 static bool NeedsHomeObject(Expression* literal) {
2450 return literal != NULL && literal->IsFunctionLiteral() &&
2451 literal->AsFunctionLiteral()->uses_super_property();
2454 int materialized_literal_count() { return materialized_literal_count_; }
2455 int expected_property_count() { return expected_property_count_; }
2456 int handler_count() { return handler_count_; }
2457 int parameter_count() { return parameter_count_; }
2459 bool AllowsLazyCompilation();
2460 bool AllowsLazyCompilationWithoutContext();
2462 void InitializeSharedInfo(Handle<Code> code);
2464 Handle<String> debug_name() const {
2465 if (raw_name_ != NULL && !raw_name_->IsEmpty()) {
2466 return raw_name_->string();
2468 return inferred_name();
2471 Handle<String> inferred_name() const {
2472 if (!inferred_name_.is_null()) {
2473 DCHECK(raw_inferred_name_ == NULL);
2474 return inferred_name_;
2476 if (raw_inferred_name_ != NULL) {
2477 return raw_inferred_name_->string();
2480 return Handle<String>();
2483 // Only one of {set_inferred_name, set_raw_inferred_name} should be called.
2484 void set_inferred_name(Handle<String> inferred_name) {
2485 DCHECK(!inferred_name.is_null());
2486 inferred_name_ = inferred_name;
2487 DCHECK(raw_inferred_name_== NULL || raw_inferred_name_->IsEmpty());
2488 raw_inferred_name_ = NULL;
2491 void set_raw_inferred_name(const AstString* raw_inferred_name) {
2492 DCHECK(raw_inferred_name != NULL);
2493 raw_inferred_name_ = raw_inferred_name;
2494 DCHECK(inferred_name_.is_null());
2495 inferred_name_ = Handle<String>();
2498 // shared_info may be null if it's not cached in full code.
2499 Handle<SharedFunctionInfo> shared_info() { return shared_info_; }
2501 bool pretenure() { return Pretenure::decode(bitfield_); }
2502 void set_pretenure() { bitfield_ |= Pretenure::encode(true); }
2504 bool has_duplicate_parameters() {
2505 return HasDuplicateParameters::decode(bitfield_);
2508 bool is_function() { return IsFunction::decode(bitfield_) == kIsFunction; }
2510 // This is used as a heuristic on when to eagerly compile a function
2511 // literal. We consider the following constructs as hints that the
2512 // function will be called immediately:
2513 // - (function() { ... })();
2514 // - var x = function() { ... }();
2515 bool should_eager_compile() const {
2516 return EagerCompileHintBit::decode(bitfield_) == kShouldEagerCompile;
2518 void set_should_eager_compile() {
2519 bitfield_ = EagerCompileHintBit::update(bitfield_, kShouldEagerCompile);
2522 // A hint that we expect this function to be called (exactly) once,
2523 // i.e. we suspect it's an initialization function.
2524 bool should_be_used_once_hint() const {
2525 return ShouldBeUsedOnceHintBit::decode(bitfield_) == kShouldBeUsedOnce;
2527 void set_should_be_used_once_hint() {
2528 bitfield_ = ShouldBeUsedOnceHintBit::update(bitfield_, kShouldBeUsedOnce);
2531 FunctionKind kind() { return FunctionKindBits::decode(bitfield_); }
2533 int ast_node_count() { return ast_properties_.node_count(); }
2534 AstProperties::Flags* flags() { return ast_properties_.flags(); }
2535 void set_ast_properties(AstProperties* ast_properties) {
2536 ast_properties_ = *ast_properties;
2538 const ZoneFeedbackVectorSpec* feedback_vector_spec() const {
2539 return ast_properties_.get_spec();
2541 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; }
2542 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; }
2543 void set_dont_optimize_reason(BailoutReason reason) {
2544 dont_optimize_reason_ = reason;
2548 FunctionLiteral(Zone* zone, const AstRawString* name,
2549 AstValueFactory* ast_value_factory, Scope* scope,
2550 ZoneList<Statement*>* body, int materialized_literal_count,
2551 int expected_property_count, int handler_count,
2552 int parameter_count, FunctionType function_type,
2553 ParameterFlag has_duplicate_parameters,
2554 IsFunctionFlag is_function,
2555 EagerCompileHint eager_compile_hint, FunctionKind kind,
2557 : Expression(zone, position),
2561 raw_inferred_name_(ast_value_factory->empty_string()),
2562 ast_properties_(zone),
2563 dont_optimize_reason_(kNoReason),
2564 materialized_literal_count_(materialized_literal_count),
2565 expected_property_count_(expected_property_count),
2566 handler_count_(handler_count),
2567 parameter_count_(parameter_count),
2568 function_token_position_(RelocInfo::kNoPosition) {
2569 bitfield_ = IsExpression::encode(function_type != DECLARATION) |
2570 IsAnonymous::encode(function_type == ANONYMOUS_EXPRESSION) |
2571 Pretenure::encode(false) |
2572 HasDuplicateParameters::encode(has_duplicate_parameters) |
2573 IsFunction::encode(is_function) |
2574 EagerCompileHintBit::encode(eager_compile_hint) |
2575 FunctionKindBits::encode(kind) |
2576 ShouldBeUsedOnceHintBit::encode(kDontKnowIfShouldBeUsedOnce);
2577 DCHECK(IsValidFunctionKind(kind));
2581 const AstRawString* raw_name_;
2582 Handle<String> name_;
2583 Handle<SharedFunctionInfo> shared_info_;
2585 ZoneList<Statement*>* body_;
2586 const AstString* raw_inferred_name_;
2587 Handle<String> inferred_name_;
2588 AstProperties ast_properties_;
2589 BailoutReason dont_optimize_reason_;
2591 int materialized_literal_count_;
2592 int expected_property_count_;
2594 int parameter_count_;
2595 int function_token_position_;
2598 class IsExpression : public BitField<bool, 0, 1> {};
2599 class IsAnonymous : public BitField<bool, 1, 1> {};
2600 class Pretenure : public BitField<bool, 2, 1> {};
2601 class HasDuplicateParameters : public BitField<ParameterFlag, 3, 1> {};
2602 class IsFunction : public BitField<IsFunctionFlag, 4, 1> {};
2603 class EagerCompileHintBit : public BitField<EagerCompileHint, 5, 1> {};
2604 class FunctionKindBits : public BitField<FunctionKind, 6, 8> {};
2605 class ShouldBeUsedOnceHintBit : public BitField<ShouldBeUsedOnceHint, 15, 1> {
2610 class ClassLiteral final : public Expression {
2612 typedef ObjectLiteralProperty Property;
2614 DECLARE_NODE_TYPE(ClassLiteral)
2616 Handle<String> name() const { return raw_name_->string(); }
2617 const AstRawString* raw_name() const { return raw_name_; }
2618 Scope* scope() const { return scope_; }
2619 VariableProxy* class_variable_proxy() const { return class_variable_proxy_; }
2620 Expression* extends() const { return extends_; }
2621 FunctionLiteral* constructor() const { return constructor_; }
2622 ZoneList<Property*>* properties() const { return properties_; }
2623 int start_position() const { return position(); }
2624 int end_position() const { return end_position_; }
2626 BailoutId EntryId() const { return BailoutId(local_id(0)); }
2627 BailoutId DeclsId() const { return BailoutId(local_id(1)); }
2628 BailoutId ExitId() { return BailoutId(local_id(2)); }
2629 BailoutId CreateLiteralId() const { return BailoutId(local_id(3)); }
2631 // Return an AST id for a property that is used in simulate instructions.
2632 BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 4)); }
2634 // Unlike other AST nodes, this number of bailout IDs allocated for an
2635 // ClassLiteral can vary, so num_ids() is not a static method.
2636 int num_ids() const { return parent_num_ids() + 4 + properties()->length(); }
2639 ClassLiteral(Zone* zone, const AstRawString* name, Scope* scope,
2640 VariableProxy* class_variable_proxy, Expression* extends,
2641 FunctionLiteral* constructor, ZoneList<Property*>* properties,
2642 int start_position, int end_position)
2643 : Expression(zone, start_position),
2646 class_variable_proxy_(class_variable_proxy),
2648 constructor_(constructor),
2649 properties_(properties),
2650 end_position_(end_position) {}
2651 static int parent_num_ids() { return Expression::num_ids(); }
2654 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2656 const AstRawString* raw_name_;
2658 VariableProxy* class_variable_proxy_;
2659 Expression* extends_;
2660 FunctionLiteral* constructor_;
2661 ZoneList<Property*>* properties_;
2666 class NativeFunctionLiteral final : public Expression {
2668 DECLARE_NODE_TYPE(NativeFunctionLiteral)
2670 Handle<String> name() const { return name_->string(); }
2671 v8::Extension* extension() const { return extension_; }
2674 NativeFunctionLiteral(Zone* zone, const AstRawString* name,
2675 v8::Extension* extension, int pos)
2676 : Expression(zone, pos), name_(name), extension_(extension) {}
2679 const AstRawString* name_;
2680 v8::Extension* extension_;
2684 class ThisFunction final : public Expression {
2686 DECLARE_NODE_TYPE(ThisFunction)
2689 ThisFunction(Zone* zone, int pos) : Expression(zone, pos) {}
2693 class SuperReference final : public Expression {
2695 DECLARE_NODE_TYPE(SuperReference)
2697 VariableProxy* this_var() const { return this_var_; }
2699 static int num_ids() { return parent_num_ids() + 1; }
2700 TypeFeedbackId HomeObjectFeedbackId() { return TypeFeedbackId(local_id(0)); }
2702 // Type feedback information.
2703 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
2704 Isolate* isolate, const ICSlotCache* cache) override {
2705 return FeedbackVectorRequirements(0, 1);
2707 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot,
2708 ICSlotCache* cache) override {
2709 homeobject_feedback_slot_ = slot;
2711 Code::Kind FeedbackICSlotKind(int index) override { return Code::LOAD_IC; }
2713 FeedbackVectorICSlot HomeObjectFeedbackSlot() {
2714 DCHECK(!homeobject_feedback_slot_.IsInvalid());
2715 return homeobject_feedback_slot_;
2719 SuperReference(Zone* zone, VariableProxy* this_var, int pos)
2720 : Expression(zone, pos),
2721 this_var_(this_var),
2722 homeobject_feedback_slot_(FeedbackVectorICSlot::Invalid()) {
2723 DCHECK(this_var->is_this());
2725 static int parent_num_ids() { return Expression::num_ids(); }
2728 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2730 VariableProxy* this_var_;
2731 FeedbackVectorICSlot homeobject_feedback_slot_;
2735 #undef DECLARE_NODE_TYPE
2738 // ----------------------------------------------------------------------------
2739 // Regular expressions
2742 class RegExpVisitor BASE_EMBEDDED {
2744 virtual ~RegExpVisitor() { }
2745 #define MAKE_CASE(Name) \
2746 virtual void* Visit##Name(RegExp##Name*, void* data) = 0;
2747 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_CASE)
2752 class RegExpTree : public ZoneObject {
2754 static const int kInfinity = kMaxInt;
2755 virtual ~RegExpTree() {}
2756 virtual void* Accept(RegExpVisitor* visitor, void* data) = 0;
2757 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2758 RegExpNode* on_success) = 0;
2759 virtual bool IsTextElement() { return false; }
2760 virtual bool IsAnchoredAtStart() { return false; }
2761 virtual bool IsAnchoredAtEnd() { return false; }
2762 virtual int min_match() = 0;
2763 virtual int max_match() = 0;
2764 // Returns the interval of registers used for captures within this
2766 virtual Interval CaptureRegisters() { return Interval::Empty(); }
2767 virtual void AppendToText(RegExpText* text, Zone* zone);
2768 std::ostream& Print(std::ostream& os, Zone* zone); // NOLINT
2769 #define MAKE_ASTYPE(Name) \
2770 virtual RegExp##Name* As##Name(); \
2771 virtual bool Is##Name();
2772 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_ASTYPE)
2777 class RegExpDisjunction final : public RegExpTree {
2779 explicit RegExpDisjunction(ZoneList<RegExpTree*>* alternatives);
2780 void* Accept(RegExpVisitor* visitor, void* data) override;
2781 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2782 RegExpNode* on_success) override;
2783 RegExpDisjunction* AsDisjunction() override;
2784 Interval CaptureRegisters() override;
2785 bool IsDisjunction() override;
2786 bool IsAnchoredAtStart() override;
2787 bool IsAnchoredAtEnd() override;
2788 int min_match() override { return min_match_; }
2789 int max_match() override { return max_match_; }
2790 ZoneList<RegExpTree*>* alternatives() { return alternatives_; }
2792 ZoneList<RegExpTree*>* alternatives_;
2798 class RegExpAlternative final : public RegExpTree {
2800 explicit RegExpAlternative(ZoneList<RegExpTree*>* nodes);
2801 void* Accept(RegExpVisitor* visitor, void* data) override;
2802 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2803 RegExpNode* on_success) override;
2804 RegExpAlternative* AsAlternative() override;
2805 Interval CaptureRegisters() override;
2806 bool IsAlternative() override;
2807 bool IsAnchoredAtStart() override;
2808 bool IsAnchoredAtEnd() override;
2809 int min_match() override { return min_match_; }
2810 int max_match() override { return max_match_; }
2811 ZoneList<RegExpTree*>* nodes() { return nodes_; }
2813 ZoneList<RegExpTree*>* nodes_;
2819 class RegExpAssertion final : public RegExpTree {
2821 enum AssertionType {
2829 explicit RegExpAssertion(AssertionType type) : assertion_type_(type) { }
2830 void* Accept(RegExpVisitor* visitor, void* data) override;
2831 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2832 RegExpNode* on_success) override;
2833 RegExpAssertion* AsAssertion() override;
2834 bool IsAssertion() override;
2835 bool IsAnchoredAtStart() override;
2836 bool IsAnchoredAtEnd() override;
2837 int min_match() override { return 0; }
2838 int max_match() override { return 0; }
2839 AssertionType assertion_type() { return assertion_type_; }
2841 AssertionType assertion_type_;
2845 class CharacterSet final BASE_EMBEDDED {
2847 explicit CharacterSet(uc16 standard_set_type)
2849 standard_set_type_(standard_set_type) {}
2850 explicit CharacterSet(ZoneList<CharacterRange>* ranges)
2852 standard_set_type_(0) {}
2853 ZoneList<CharacterRange>* ranges(Zone* zone);
2854 uc16 standard_set_type() { return standard_set_type_; }
2855 void set_standard_set_type(uc16 special_set_type) {
2856 standard_set_type_ = special_set_type;
2858 bool is_standard() { return standard_set_type_ != 0; }
2859 void Canonicalize();
2861 ZoneList<CharacterRange>* ranges_;
2862 // If non-zero, the value represents a standard set (e.g., all whitespace
2863 // characters) without having to expand the ranges.
2864 uc16 standard_set_type_;
2868 class RegExpCharacterClass final : public RegExpTree {
2870 RegExpCharacterClass(ZoneList<CharacterRange>* ranges, bool is_negated)
2872 is_negated_(is_negated) { }
2873 explicit RegExpCharacterClass(uc16 type)
2875 is_negated_(false) { }
2876 void* Accept(RegExpVisitor* visitor, void* data) override;
2877 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2878 RegExpNode* on_success) override;
2879 RegExpCharacterClass* AsCharacterClass() override;
2880 bool IsCharacterClass() override;
2881 bool IsTextElement() override { return true; }
2882 int min_match() override { return 1; }
2883 int max_match() override { return 1; }
2884 void AppendToText(RegExpText* text, Zone* zone) override;
2885 CharacterSet character_set() { return set_; }
2886 // TODO(lrn): Remove need for complex version if is_standard that
2887 // recognizes a mangled standard set and just do { return set_.is_special(); }
2888 bool is_standard(Zone* zone);
2889 // Returns a value representing the standard character set if is_standard()
2891 // Currently used values are:
2892 // s : unicode whitespace
2893 // S : unicode non-whitespace
2894 // w : ASCII word character (digit, letter, underscore)
2895 // W : non-ASCII word character
2897 // D : non-ASCII digit
2898 // . : non-unicode non-newline
2899 // * : All characters
2900 uc16 standard_type() { return set_.standard_set_type(); }
2901 ZoneList<CharacterRange>* ranges(Zone* zone) { return set_.ranges(zone); }
2902 bool is_negated() { return is_negated_; }
2910 class RegExpAtom final : public RegExpTree {
2912 explicit RegExpAtom(Vector<const uc16> data) : data_(data) { }
2913 void* Accept(RegExpVisitor* visitor, void* data) override;
2914 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2915 RegExpNode* on_success) override;
2916 RegExpAtom* AsAtom() override;
2917 bool IsAtom() override;
2918 bool IsTextElement() override { return true; }
2919 int min_match() override { return data_.length(); }
2920 int max_match() override { return data_.length(); }
2921 void AppendToText(RegExpText* text, Zone* zone) override;
2922 Vector<const uc16> data() { return data_; }
2923 int length() { return data_.length(); }
2925 Vector<const uc16> data_;
2929 class RegExpText final : public RegExpTree {
2931 explicit RegExpText(Zone* zone) : elements_(2, zone), length_(0) {}
2932 void* Accept(RegExpVisitor* visitor, void* data) override;
2933 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2934 RegExpNode* on_success) override;
2935 RegExpText* AsText() override;
2936 bool IsText() override;
2937 bool IsTextElement() override { return true; }
2938 int min_match() override { return length_; }
2939 int max_match() override { return length_; }
2940 void AppendToText(RegExpText* text, Zone* zone) override;
2941 void AddElement(TextElement elm, Zone* zone) {
2942 elements_.Add(elm, zone);
2943 length_ += elm.length();
2945 ZoneList<TextElement>* elements() { return &elements_; }
2947 ZoneList<TextElement> elements_;
2952 class RegExpQuantifier final : public RegExpTree {
2954 enum QuantifierType { GREEDY, NON_GREEDY, POSSESSIVE };
2955 RegExpQuantifier(int min, int max, QuantifierType type, RegExpTree* body)
2959 min_match_(min * body->min_match()),
2960 quantifier_type_(type) {
2961 if (max > 0 && body->max_match() > kInfinity / max) {
2962 max_match_ = kInfinity;
2964 max_match_ = max * body->max_match();
2967 void* Accept(RegExpVisitor* visitor, void* data) override;
2968 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2969 RegExpNode* on_success) override;
2970 static RegExpNode* ToNode(int min,
2974 RegExpCompiler* compiler,
2975 RegExpNode* on_success,
2976 bool not_at_start = false);
2977 RegExpQuantifier* AsQuantifier() override;
2978 Interval CaptureRegisters() override;
2979 bool IsQuantifier() override;
2980 int min_match() override { return min_match_; }
2981 int max_match() override { return max_match_; }
2982 int min() { return min_; }
2983 int max() { return max_; }
2984 bool is_possessive() { return quantifier_type_ == POSSESSIVE; }
2985 bool is_non_greedy() { return quantifier_type_ == NON_GREEDY; }
2986 bool is_greedy() { return quantifier_type_ == GREEDY; }
2987 RegExpTree* body() { return body_; }
2995 QuantifierType quantifier_type_;
2999 class RegExpCapture final : public RegExpTree {
3001 explicit RegExpCapture(RegExpTree* body, int index)
3002 : body_(body), index_(index) { }
3003 void* Accept(RegExpVisitor* visitor, void* data) override;
3004 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
3005 RegExpNode* on_success) override;
3006 static RegExpNode* ToNode(RegExpTree* body,
3008 RegExpCompiler* compiler,
3009 RegExpNode* on_success);
3010 RegExpCapture* AsCapture() override;
3011 bool IsAnchoredAtStart() override;
3012 bool IsAnchoredAtEnd() override;
3013 Interval CaptureRegisters() override;
3014 bool IsCapture() override;
3015 int min_match() override { return body_->min_match(); }
3016 int max_match() override { return body_->max_match(); }
3017 RegExpTree* body() { return body_; }
3018 int index() { return index_; }
3019 static int StartRegister(int index) { return index * 2; }
3020 static int EndRegister(int index) { return index * 2 + 1; }
3028 class RegExpLookahead final : public RegExpTree {
3030 RegExpLookahead(RegExpTree* body,
3035 is_positive_(is_positive),
3036 capture_count_(capture_count),
3037 capture_from_(capture_from) { }
3039 void* Accept(RegExpVisitor* visitor, void* data) override;
3040 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
3041 RegExpNode* on_success) override;
3042 RegExpLookahead* AsLookahead() override;
3043 Interval CaptureRegisters() override;
3044 bool IsLookahead() override;
3045 bool IsAnchoredAtStart() override;
3046 int min_match() override { return 0; }
3047 int max_match() override { return 0; }
3048 RegExpTree* body() { return body_; }
3049 bool is_positive() { return is_positive_; }
3050 int capture_count() { return capture_count_; }
3051 int capture_from() { return capture_from_; }
3061 class RegExpBackReference final : public RegExpTree {
3063 explicit RegExpBackReference(RegExpCapture* capture)
3064 : capture_(capture) { }
3065 void* Accept(RegExpVisitor* visitor, void* data) override;
3066 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
3067 RegExpNode* on_success) override;
3068 RegExpBackReference* AsBackReference() override;
3069 bool IsBackReference() override;
3070 int min_match() override { return 0; }
3071 int max_match() override { return capture_->max_match(); }
3072 int index() { return capture_->index(); }
3073 RegExpCapture* capture() { return capture_; }
3075 RegExpCapture* capture_;
3079 class RegExpEmpty final : public RegExpTree {
3082 void* Accept(RegExpVisitor* visitor, void* data) override;
3083 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
3084 RegExpNode* on_success) override;
3085 RegExpEmpty* AsEmpty() override;
3086 bool IsEmpty() override;
3087 int min_match() override { return 0; }
3088 int max_match() override { return 0; }
3092 // ----------------------------------------------------------------------------
3094 // - leaf node visitors are abstract.
3096 class AstVisitor BASE_EMBEDDED {
3099 virtual ~AstVisitor() {}
3101 // Stack overflow check and dynamic dispatch.
3102 virtual void Visit(AstNode* node) = 0;
3104 // Iteration left-to-right.
3105 virtual void VisitDeclarations(ZoneList<Declaration*>* declarations);
3106 virtual void VisitStatements(ZoneList<Statement*>* statements);
3107 virtual void VisitExpressions(ZoneList<Expression*>* expressions);
3109 // Individual AST nodes.
3110 #define DEF_VISIT(type) \
3111 virtual void Visit##type(type* node) = 0;
3112 AST_NODE_LIST(DEF_VISIT)
3117 #define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS() \
3119 void Visit(AstNode* node) final { \
3120 if (!CheckStackOverflow()) node->Accept(this); \
3123 void SetStackOverflow() { stack_overflow_ = true; } \
3124 void ClearStackOverflow() { stack_overflow_ = false; } \
3125 bool HasStackOverflow() const { return stack_overflow_; } \
3127 bool CheckStackOverflow() { \
3128 if (stack_overflow_) return true; \
3129 StackLimitCheck check(isolate_); \
3130 if (!check.HasOverflowed()) return false; \
3131 stack_overflow_ = true; \
3136 void InitializeAstVisitor(Isolate* isolate, Zone* zone) { \
3137 isolate_ = isolate; \
3139 stack_overflow_ = false; \
3141 Zone* zone() { return zone_; } \
3142 Isolate* isolate() { return isolate_; } \
3144 Isolate* isolate_; \
3146 bool stack_overflow_
3149 // ----------------------------------------------------------------------------
3152 class AstNodeFactory final BASE_EMBEDDED {
3154 explicit AstNodeFactory(AstValueFactory* ast_value_factory)
3155 : zone_(ast_value_factory->zone()),
3156 ast_value_factory_(ast_value_factory) {}
3158 VariableDeclaration* NewVariableDeclaration(
3159 VariableProxy* proxy, VariableMode mode, Scope* scope, int pos,
3160 bool is_class_declaration = false, int declaration_group_start = -1) {
3162 VariableDeclaration(zone_, proxy, mode, scope, pos,
3163 is_class_declaration, declaration_group_start);
3166 FunctionDeclaration* NewFunctionDeclaration(VariableProxy* proxy,
3168 FunctionLiteral* fun,
3171 return new (zone_) FunctionDeclaration(zone_, proxy, mode, fun, scope, pos);
3174 ImportDeclaration* NewImportDeclaration(VariableProxy* proxy,
3175 const AstRawString* import_name,
3176 const AstRawString* module_specifier,
3177 Scope* scope, int pos) {
3178 return new (zone_) ImportDeclaration(zone_, proxy, import_name,
3179 module_specifier, scope, pos);
3182 ExportDeclaration* NewExportDeclaration(VariableProxy* proxy,
3185 return new (zone_) ExportDeclaration(zone_, proxy, scope, pos);
3188 Block* NewBlock(ZoneList<const AstRawString*>* labels,
3190 bool is_initializer_block,
3193 Block(zone_, labels, capacity, is_initializer_block, pos);
3196 #define STATEMENT_WITH_LABELS(NodeType) \
3197 NodeType* New##NodeType(ZoneList<const AstRawString*>* labels, int pos) { \
3198 return new (zone_) NodeType(zone_, labels, pos); \
3200 STATEMENT_WITH_LABELS(DoWhileStatement)
3201 STATEMENT_WITH_LABELS(WhileStatement)
3202 STATEMENT_WITH_LABELS(ForStatement)
3203 STATEMENT_WITH_LABELS(SwitchStatement)
3204 #undef STATEMENT_WITH_LABELS
3206 ForEachStatement* NewForEachStatement(ForEachStatement::VisitMode visit_mode,
3207 ZoneList<const AstRawString*>* labels,
3209 switch (visit_mode) {
3210 case ForEachStatement::ENUMERATE: {
3211 return new (zone_) ForInStatement(zone_, labels, pos);
3213 case ForEachStatement::ITERATE: {
3214 return new (zone_) ForOfStatement(zone_, labels, pos);
3221 ExpressionStatement* NewExpressionStatement(Expression* expression, int pos) {
3222 return new (zone_) ExpressionStatement(zone_, expression, pos);
3225 ContinueStatement* NewContinueStatement(IterationStatement* target, int pos) {
3226 return new (zone_) ContinueStatement(zone_, target, pos);
3229 BreakStatement* NewBreakStatement(BreakableStatement* target, int pos) {
3230 return new (zone_) BreakStatement(zone_, target, pos);
3233 ReturnStatement* NewReturnStatement(Expression* expression, int pos) {
3234 return new (zone_) ReturnStatement(zone_, expression, pos);
3237 WithStatement* NewWithStatement(Scope* scope,
3238 Expression* expression,
3239 Statement* statement,
3241 return new (zone_) WithStatement(zone_, scope, expression, statement, pos);
3244 IfStatement* NewIfStatement(Expression* condition,
3245 Statement* then_statement,
3246 Statement* else_statement,
3249 IfStatement(zone_, condition, then_statement, else_statement, pos);
3252 TryCatchStatement* NewTryCatchStatement(int index,
3258 return new (zone_) TryCatchStatement(zone_, index, try_block, scope,
3259 variable, catch_block, pos);
3262 TryFinallyStatement* NewTryFinallyStatement(int index,
3264 Block* finally_block,
3267 TryFinallyStatement(zone_, index, try_block, finally_block, pos);
3270 DebuggerStatement* NewDebuggerStatement(int pos) {
3271 return new (zone_) DebuggerStatement(zone_, pos);
3274 EmptyStatement* NewEmptyStatement(int pos) {
3275 return new(zone_) EmptyStatement(zone_, pos);
3278 CaseClause* NewCaseClause(
3279 Expression* label, ZoneList<Statement*>* statements, int pos) {
3280 return new (zone_) CaseClause(zone_, label, statements, pos);
3283 Literal* NewStringLiteral(const AstRawString* string, int pos) {
3285 Literal(zone_, ast_value_factory_->NewString(string), pos);
3288 // A JavaScript symbol (ECMA-262 edition 6).
3289 Literal* NewSymbolLiteral(const char* name, int pos) {
3290 return new (zone_) Literal(zone_, ast_value_factory_->NewSymbol(name), pos);
3293 Literal* NewNumberLiteral(double number, int pos) {
3295 Literal(zone_, ast_value_factory_->NewNumber(number), pos);
3298 Literal* NewSmiLiteral(int number, int pos) {
3299 return new (zone_) Literal(zone_, ast_value_factory_->NewSmi(number), pos);
3302 Literal* NewBooleanLiteral(bool b, int pos) {
3303 return new (zone_) Literal(zone_, ast_value_factory_->NewBoolean(b), pos);
3306 Literal* NewNullLiteral(int pos) {
3307 return new (zone_) Literal(zone_, ast_value_factory_->NewNull(), pos);
3310 Literal* NewUndefinedLiteral(int pos) {
3311 return new (zone_) Literal(zone_, ast_value_factory_->NewUndefined(), pos);
3314 Literal* NewTheHoleLiteral(int pos) {
3315 return new (zone_) Literal(zone_, ast_value_factory_->NewTheHole(), pos);
3318 ObjectLiteral* NewObjectLiteral(
3319 ZoneList<ObjectLiteral::Property*>* properties,
3321 int boilerplate_properties,
3325 return new (zone_) ObjectLiteral(zone_, properties, literal_index,
3326 boilerplate_properties, has_function,
3330 ObjectLiteral::Property* NewObjectLiteralProperty(
3331 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind,
3332 bool is_static, bool is_computed_name) {
3334 ObjectLiteral::Property(key, value, kind, is_static, is_computed_name);
3337 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key,
3340 bool is_computed_name) {
3341 return new (zone_) ObjectLiteral::Property(ast_value_factory_, key, value,
3342 is_static, is_computed_name);
3345 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern,
3346 const AstRawString* flags,
3350 return new (zone_) RegExpLiteral(zone_, pattern, flags, literal_index,
3354 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values,
3358 return new (zone_) ArrayLiteral(zone_, values, literal_index, is_strong,
3362 VariableProxy* NewVariableProxy(Variable* var,
3363 int start_position = RelocInfo::kNoPosition,
3364 int end_position = RelocInfo::kNoPosition) {
3365 return new (zone_) VariableProxy(zone_, var, start_position, end_position);
3368 VariableProxy* NewVariableProxy(const AstRawString* name,
3369 Variable::Kind variable_kind,
3370 int start_position = RelocInfo::kNoPosition,
3371 int end_position = RelocInfo::kNoPosition) {
3372 DCHECK_NOT_NULL(name);
3374 VariableProxy(zone_, name, variable_kind, start_position, end_position);
3377 Property* NewProperty(Expression* obj, Expression* key, int pos) {
3378 return new (zone_) Property(zone_, obj, key, pos);
3381 Call* NewCall(Expression* expression,
3382 ZoneList<Expression*>* arguments,
3384 return new (zone_) Call(zone_, expression, arguments, pos);
3387 CallNew* NewCallNew(Expression* expression,
3388 ZoneList<Expression*>* arguments,
3390 return new (zone_) CallNew(zone_, expression, arguments, pos);
3393 CallRuntime* NewCallRuntime(const AstRawString* name,
3394 const Runtime::Function* function,
3395 ZoneList<Expression*>* arguments,
3397 return new (zone_) CallRuntime(zone_, name, function, arguments, pos);
3400 UnaryOperation* NewUnaryOperation(Token::Value op,
3401 Expression* expression,
3403 return new (zone_) UnaryOperation(zone_, op, expression, pos);
3406 BinaryOperation* NewBinaryOperation(Token::Value op,
3410 return new (zone_) BinaryOperation(zone_, op, left, right, pos);
3413 CountOperation* NewCountOperation(Token::Value op,
3417 return new (zone_) CountOperation(zone_, op, is_prefix, expr, pos);
3420 CompareOperation* NewCompareOperation(Token::Value op,
3424 return new (zone_) CompareOperation(zone_, op, left, right, pos);
3427 Spread* NewSpread(Expression* expression, int pos) {
3428 return new (zone_) Spread(zone_, expression, pos);
3431 Conditional* NewConditional(Expression* condition,
3432 Expression* then_expression,
3433 Expression* else_expression,
3435 return new (zone_) Conditional(zone_, condition, then_expression,
3436 else_expression, position);
3439 Assignment* NewAssignment(Token::Value op,
3443 DCHECK(Token::IsAssignmentOp(op));
3444 Assignment* assign = new (zone_) Assignment(zone_, op, target, value, pos);
3445 if (assign->is_compound()) {
3446 DCHECK(Token::IsAssignmentOp(op));
3447 assign->binary_operation_ =
3448 NewBinaryOperation(assign->binary_op(), target, value, pos + 1);
3453 Yield* NewYield(Expression *generator_object,
3454 Expression* expression,
3455 Yield::Kind yield_kind,
3457 if (!expression) expression = NewUndefinedLiteral(pos);
3459 Yield(zone_, generator_object, expression, yield_kind, pos);
3462 Throw* NewThrow(Expression* exception, int pos) {
3463 return new (zone_) Throw(zone_, exception, pos);
3466 FunctionLiteral* NewFunctionLiteral(
3467 const AstRawString* name, AstValueFactory* ast_value_factory,
3468 Scope* scope, ZoneList<Statement*>* body, int materialized_literal_count,
3469 int expected_property_count, int handler_count, int parameter_count,
3470 FunctionLiteral::ParameterFlag has_duplicate_parameters,
3471 FunctionLiteral::FunctionType function_type,
3472 FunctionLiteral::IsFunctionFlag is_function,
3473 FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind kind,
3475 return new (zone_) FunctionLiteral(
3476 zone_, name, ast_value_factory, scope, body, materialized_literal_count,
3477 expected_property_count, handler_count, parameter_count, function_type,
3478 has_duplicate_parameters, is_function, eager_compile_hint, kind,
3482 ClassLiteral* NewClassLiteral(const AstRawString* name, Scope* scope,
3483 VariableProxy* proxy, Expression* extends,
3484 FunctionLiteral* constructor,
3485 ZoneList<ObjectLiteral::Property*>* properties,
3486 int start_position, int end_position) {
3488 ClassLiteral(zone_, name, scope, proxy, extends, constructor,
3489 properties, start_position, end_position);
3492 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name,
3493 v8::Extension* extension,
3495 return new (zone_) NativeFunctionLiteral(zone_, name, extension, pos);
3498 ThisFunction* NewThisFunction(int pos) {
3499 return new (zone_) ThisFunction(zone_, pos);
3502 SuperReference* NewSuperReference(VariableProxy* this_var, int pos) {
3503 return new (zone_) SuperReference(zone_, this_var, pos);
3508 AstValueFactory* ast_value_factory_;
3512 } } // namespace v8::internal