diff options
Diffstat (limited to 'deps/v8/src/ast.h')
-rw-r--r-- | deps/v8/src/ast.h | 835 |
1 files changed, 341 insertions, 494 deletions
diff --git a/deps/v8/src/ast.h b/deps/v8/src/ast.h index 749e57999c..43bde6ad25 100644 --- a/deps/v8/src/ast.h +++ b/deps/v8/src/ast.h @@ -105,8 +105,7 @@ namespace internal { EXPRESSION_NODE_LIST(V) // Forward declarations -class AstConstructionVisitor; -template<class> class AstNodeFactory; +class AstNodeFactory; class AstVisitor; class Declaration; class Module; @@ -142,12 +141,10 @@ typedef ZoneList<Handle<String> > ZoneStringList; typedef ZoneList<Handle<Object> > ZoneObjectList; -#define DECLARE_NODE_TYPE(type) \ - virtual void Accept(AstVisitor* v) OVERRIDE; \ - virtual AstNode::NodeType node_type() const FINAL OVERRIDE { \ - return AstNode::k##type; \ - } \ - template<class> friend class AstNodeFactory; +#define DECLARE_NODE_TYPE(type) \ + void Accept(AstVisitor* v) OVERRIDE; \ + AstNode::NodeType node_type() const FINAL { return AstNode::k##type; } \ + friend class AstNodeFactory; enum AstPropertiesFlag { @@ -175,25 +172,24 @@ class AstProperties FINAL BASE_EMBEDDED { public: class Flags : public EnumSet<AstPropertiesFlag, int> {}; - AstProperties() : node_count_(0), feedback_slots_(0), ic_feedback_slots_(0) {} + AstProperties() : node_count_(0) {} Flags* flags() { return &flags_; } int node_count() { return node_count_; } void add_node_count(int count) { node_count_ += count; } - int feedback_slots() const { return feedback_slots_; } - void increase_feedback_slots(int count) { - feedback_slots_ += count; - } + int slots() const { return spec_.slots(); } + void increase_slots(int count) { spec_.increase_slots(count); } - int ic_feedback_slots() const { return ic_feedback_slots_; } - void increase_ic_feedback_slots(int count) { ic_feedback_slots_ += count; } + int ic_slots() const { return spec_.ic_slots(); } + void increase_ic_slots(int count) { spec_.increase_ic_slots(count); } + void SetKind(int ic_slot, Code::Kind kind) { spec_.SetKind(ic_slot, kind); } + const FeedbackVectorSpec& get_spec() const { return spec_; } private: Flags flags_; int node_count_; - int feedback_slots_; - int ic_feedback_slots_; + FeedbackVectorSpec spec_; }; @@ -238,13 +234,19 @@ class AstNode: public ZoneObject { // node types which don't actually have this. Note that this is conceptually // not really nice, but multiple inheritance would introduce yet another // vtable entry per node, something we don't want for space reasons. - virtual FeedbackVectorRequirements ComputeFeedbackRequirements() { + virtual FeedbackVectorRequirements ComputeFeedbackRequirements( + Isolate* isolate) { return FeedbackVectorRequirements(0, 0); } virtual void SetFirstFeedbackSlot(FeedbackVectorSlot slot) { UNREACHABLE(); } virtual void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) { UNREACHABLE(); } + // Each ICSlot stores a kind of IC which the participating node should know. + virtual Code::Kind FeedbackICSlotKind(int index) { + UNREACHABLE(); + return Code::NUMBER_OF_KINDS; + } private: // Hidden to prevent accidental usage. It would have to load the @@ -442,9 +444,7 @@ class BreakableStatement : public Statement { ZoneList<const AstRawString*>* labels() const { return labels_; } // Type testing & conversion. - virtual BreakableStatement* AsBreakableStatement() FINAL OVERRIDE { - return this; - } + BreakableStatement* AsBreakableStatement() FINAL { return this; } // Code generation Label* break_target() { return &break_target_; } @@ -499,7 +499,7 @@ class Block FINAL : public BreakableStatement { static int num_ids() { return parent_num_ids() + 1; } BailoutId DeclsId() const { return BailoutId(local_id(0)); } - virtual bool IsJump() const OVERRIDE { + bool IsJump() const OVERRIDE { return !statements_.is_empty() && statements_.last()->IsJump() && labels() == NULL; // Good enough as an approximation... } @@ -553,7 +553,7 @@ class VariableDeclaration FINAL : public Declaration { public: DECLARE_NODE_TYPE(VariableDeclaration) - virtual InitializationFlag initialization() const OVERRIDE { + InitializationFlag initialization() const OVERRIDE { return mode() == VAR ? kCreatedInitialized : kNeedsInitialization; } @@ -573,10 +573,10 @@ class FunctionDeclaration FINAL : public Declaration { DECLARE_NODE_TYPE(FunctionDeclaration) FunctionLiteral* fun() const { return fun_; } - virtual InitializationFlag initialization() const OVERRIDE { + InitializationFlag initialization() const OVERRIDE { return kCreatedInitialized; } - virtual bool IsInlineable() const OVERRIDE; + bool IsInlineable() const OVERRIDE; protected: FunctionDeclaration(Zone* zone, @@ -602,7 +602,7 @@ class ModuleDeclaration FINAL : public Declaration { DECLARE_NODE_TYPE(ModuleDeclaration) Module* module() const { return module_; } - virtual InitializationFlag initialization() const OVERRIDE { + InitializationFlag initialization() const OVERRIDE { return kCreatedInitialized; } @@ -626,7 +626,7 @@ class ImportDeclaration FINAL : public Declaration { DECLARE_NODE_TYPE(ImportDeclaration) Module* module() const { return module_; } - virtual InitializationFlag initialization() const OVERRIDE { + InitializationFlag initialization() const OVERRIDE { return kCreatedInitialized; } @@ -649,7 +649,7 @@ class ExportDeclaration FINAL : public Declaration { public: DECLARE_NODE_TYPE(ExportDeclaration) - virtual InitializationFlag initialization() const OVERRIDE { + InitializationFlag initialization() const OVERRIDE { return kCreatedInitialized; } @@ -760,9 +760,7 @@ class ModuleStatement FINAL : public Statement { class IterationStatement : public BreakableStatement { public: // Type testing & conversion. - virtual IterationStatement* AsIterationStatement() FINAL OVERRIDE { - return this; - } + IterationStatement* AsIterationStatement() FINAL { return this; } Statement* body() const { return body_; } @@ -801,10 +799,8 @@ class DoWhileStatement FINAL : public IterationStatement { Expression* cond() const { return cond_; } static int num_ids() { return parent_num_ids() + 2; } - virtual BailoutId ContinueId() const OVERRIDE { - return BailoutId(local_id(0)); - } - virtual BailoutId StackCheckId() const OVERRIDE { return BackEdgeId(); } + BailoutId ContinueId() const OVERRIDE { return BailoutId(local_id(0)); } + BailoutId StackCheckId() const OVERRIDE { return BackEdgeId(); } BailoutId BackEdgeId() const { return BailoutId(local_id(1)); } protected: @@ -829,32 +825,21 @@ class WhileStatement FINAL : public IterationStatement { } Expression* cond() const { return cond_; } - bool may_have_function_literal() const { - return may_have_function_literal_; - } - void set_may_have_function_literal(bool value) { - may_have_function_literal_ = value; - } static int num_ids() { return parent_num_ids() + 1; } - virtual BailoutId ContinueId() const OVERRIDE { return EntryId(); } - virtual BailoutId StackCheckId() const OVERRIDE { return BodyId(); } + BailoutId ContinueId() const OVERRIDE { return EntryId(); } + BailoutId StackCheckId() const OVERRIDE { return BodyId(); } BailoutId BodyId() const { return BailoutId(local_id(0)); } protected: WhileStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos) - : IterationStatement(zone, labels, pos), - cond_(NULL), - may_have_function_literal_(true) {} + : IterationStatement(zone, labels, pos), cond_(NULL) {} static int parent_num_ids() { return IterationStatement::num_ids(); } private: int local_id(int n) const { return base_id() + parent_num_ids() + n; } Expression* cond_; - - // True if there is a function literal subexpression in the condition. - bool may_have_function_literal_; }; @@ -876,32 +861,17 @@ class ForStatement FINAL : public IterationStatement { Expression* cond() const { return cond_; } Statement* next() const { return next_; } - bool may_have_function_literal() const { - return may_have_function_literal_; - } - void set_may_have_function_literal(bool value) { - may_have_function_literal_ = value; - } - static int num_ids() { return parent_num_ids() + 2; } - virtual BailoutId ContinueId() const OVERRIDE { - return BailoutId(local_id(0)); - } - virtual BailoutId StackCheckId() const OVERRIDE { return BodyId(); } + BailoutId ContinueId() const OVERRIDE { return BailoutId(local_id(0)); } + BailoutId StackCheckId() const OVERRIDE { return BodyId(); } BailoutId BodyId() const { return BailoutId(local_id(1)); } - bool is_fast_smi_loop() { return loop_variable_ != NULL; } - Variable* loop_variable() { return loop_variable_; } - void set_loop_variable(Variable* var) { loop_variable_ = var; } - protected: ForStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos) : IterationStatement(zone, labels, pos), init_(NULL), cond_(NULL), - next_(NULL), - may_have_function_literal_(true), - loop_variable_(NULL) {} + next_(NULL) {} static int parent_num_ids() { return IterationStatement::num_ids(); } private: @@ -910,10 +880,6 @@ class ForStatement FINAL : public IterationStatement { Statement* init_; Expression* cond_; Statement* next_; - - // True if there is a function literal subexpression in the condition. - bool may_have_function_literal_; - Variable* loop_variable_; }; @@ -952,10 +918,11 @@ class ForInStatement FINAL : public ForEachStatement { } // Type feedback information. - virtual FeedbackVectorRequirements ComputeFeedbackRequirements() OVERRIDE { + virtual FeedbackVectorRequirements ComputeFeedbackRequirements( + Isolate* isolate) OVERRIDE { return FeedbackVectorRequirements(1, 0); } - virtual void SetFirstFeedbackSlot(FeedbackVectorSlot slot) OVERRIDE { + void SetFirstFeedbackSlot(FeedbackVectorSlot slot) OVERRIDE { for_in_feedback_slot_ = slot; } @@ -973,8 +940,8 @@ class ForInStatement FINAL : public ForEachStatement { BailoutId PrepareId() const { return BailoutId(local_id(1)); } BailoutId EnumId() const { return BailoutId(local_id(2)); } BailoutId ToObjectId() const { return BailoutId(local_id(3)); } - virtual BailoutId ContinueId() const OVERRIDE { return EntryId(); } - virtual BailoutId StackCheckId() const OVERRIDE { return BodyId(); } + BailoutId ContinueId() const OVERRIDE { return EntryId(); } + BailoutId StackCheckId() const OVERRIDE { return BodyId(); } protected: ForInStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos) @@ -1033,8 +1000,8 @@ class ForOfStatement FINAL : public ForEachStatement { return assign_each_; } - virtual BailoutId ContinueId() const OVERRIDE { return EntryId(); } - virtual BailoutId StackCheckId() const OVERRIDE { return BackEdgeId(); } + BailoutId ContinueId() const OVERRIDE { return EntryId(); } + BailoutId StackCheckId() const OVERRIDE { return BackEdgeId(); } static int num_ids() { return parent_num_ids() + 1; } BailoutId BackEdgeId() const { return BailoutId(local_id(0)); } @@ -1064,7 +1031,7 @@ class ExpressionStatement FINAL : public Statement { void set_expression(Expression* e) { expression_ = e; } Expression* expression() const { return expression_; } - virtual bool IsJump() const OVERRIDE { return expression_->IsThrow(); } + bool IsJump() const OVERRIDE { return expression_->IsThrow(); } protected: ExpressionStatement(Zone* zone, Expression* expression, int pos) @@ -1077,7 +1044,7 @@ class ExpressionStatement FINAL : public Statement { class JumpStatement : public Statement { public: - virtual bool IsJump() const FINAL OVERRIDE { return true; } + bool IsJump() const FINAL { return true; } protected: explicit JumpStatement(Zone* zone, int pos) : Statement(zone, pos) {} @@ -1227,7 +1194,7 @@ class IfStatement FINAL : public Statement { Statement* then_statement() const { return then_statement_; } Statement* else_statement() const { return else_statement_; } - virtual bool IsJump() const OVERRIDE { + bool IsJump() const OVERRIDE { return HasThenStatement() && then_statement()->IsJump() && HasElseStatement() && else_statement()->IsJump(); } @@ -1276,9 +1243,9 @@ class TargetCollector FINAL : public AstNode { void AddTarget(Label* target, Zone* zone); // Virtual behaviour. TargetCollectors are never part of the AST. - virtual void Accept(AstVisitor* v) OVERRIDE { UNREACHABLE(); } - virtual NodeType node_type() const OVERRIDE { return kInvalid; } - virtual TargetCollector* AsTargetCollector() OVERRIDE { return this; } + void Accept(AstVisitor* v) OVERRIDE { UNREACHABLE(); } + NodeType node_type() const OVERRIDE { return kInvalid; } + TargetCollector* AsTargetCollector() OVERRIDE { return this; } ZoneList<Label*>* targets() { return &targets_; } @@ -1397,9 +1364,7 @@ class Literal FINAL : public Expression { public: DECLARE_NODE_TYPE(Literal) - virtual bool IsPropertyName() const OVERRIDE { - return value_->IsPropertyName(); - } + bool IsPropertyName() const OVERRIDE { return value_->IsPropertyName(); } Handle<String> AsPropertyName() { DCHECK(IsPropertyName()); @@ -1411,12 +1376,8 @@ class Literal FINAL : public Expression { return value_->AsString(); } - virtual bool ToBooleanIsTrue() const OVERRIDE { - return value()->BooleanValue(); - } - virtual bool ToBooleanIsFalse() const OVERRIDE { - return !value()->BooleanValue(); - } + bool ToBooleanIsTrue() const OVERRIDE { return value()->BooleanValue(); } + bool ToBooleanIsFalse() const OVERRIDE { return !value()->BooleanValue(); } Handle<Object> value() const { return value_->value(); } const AstValue* raw_value() const { return value_; } @@ -1526,7 +1487,7 @@ class ObjectLiteralProperty FINAL : public ZoneObject { bool is_static() const { return is_static_; } protected: - template<class> friend class AstNodeFactory; + friend class AstNodeFactory; ObjectLiteralProperty(Zone* zone, bool is_getter, FunctionLiteral* value, bool is_static); @@ -1687,7 +1648,7 @@ class VariableProxy FINAL : public Expression { public: DECLARE_NODE_TYPE(VariableProxy) - virtual bool IsValidReferenceExpression() const OVERRIDE { + bool IsValidReferenceExpression() const OVERRIDE { return !is_resolved() || var()->IsValidReference(); } @@ -1725,14 +1686,21 @@ class VariableProxy FINAL : public Expression { // Bind this proxy to the variable var. Interfaces must match. void BindTo(Variable* var); - virtual FeedbackVectorRequirements ComputeFeedbackRequirements() OVERRIDE { - return FeedbackVectorRequirements(0, FLAG_vector_ics ? 1 : 0); + bool UsesVariableFeedbackSlot() const { + return FLAG_vector_ics && (var()->IsUnallocated() || var()->IsLookupSlot()); } - virtual void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE { - variable_feedback_slot_ = slot; + + virtual FeedbackVectorRequirements ComputeFeedbackRequirements( + Isolate* isolate) OVERRIDE { + return FeedbackVectorRequirements(0, UsesVariableFeedbackSlot() ? 1 : 0); } + void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE { + variable_feedback_slot_ = slot; + } + Code::Kind FeedbackICSlotKind(int index) OVERRIDE { return Code::LOAD_IC; } FeedbackVectorICSlot VariableFeedbackSlot() { + DCHECK(!UsesVariableFeedbackSlot() || !variable_feedback_slot_.IsInvalid()); return variable_feedback_slot_; } @@ -1762,7 +1730,7 @@ class Property FINAL : public Expression { public: DECLARE_NODE_TYPE(Property) - virtual bool IsValidReferenceExpression() const OVERRIDE { return true; } + bool IsValidReferenceExpression() const OVERRIDE { return true; } Expression* obj() const { return obj_; } Expression* key() const { return key_; } @@ -1776,18 +1744,11 @@ class Property FINAL : public Expression { } // Type feedback information. - virtual bool IsMonomorphic() OVERRIDE { - return receiver_types_.length() == 1; - } - virtual SmallMapList* GetReceiverTypes() OVERRIDE { - return &receiver_types_; - } - virtual KeyedAccessStoreMode GetStoreMode() const OVERRIDE { - return STANDARD_STORE; - } - virtual IcCheckType GetKeyType() const OVERRIDE { - // PROPERTY key types currently aren't implemented for KeyedLoadICs. - return ELEMENT; + bool IsMonomorphic() OVERRIDE { return receiver_types_.length() == 1; } + SmallMapList* GetReceiverTypes() OVERRIDE { return &receiver_types_; } + KeyedAccessStoreMode GetStoreMode() const OVERRIDE { return STANDARD_STORE; } + IcCheckType GetKeyType() const OVERRIDE { + return KeyTypeField::decode(bit_field_); } bool IsUninitialized() const { return !is_for_call() && HasNoTypeInformation(); @@ -1801,6 +1762,9 @@ class Property FINAL : public Expression { void set_is_string_access(bool b) { bit_field_ = IsStringAccessField::update(bit_field_, b); } + void set_key_type(IcCheckType key_type) { + bit_field_ = KeyTypeField::update(bit_field_, key_type); + } void mark_for_call() { bit_field_ = IsForCallField::update(bit_field_, true); } @@ -1810,14 +1774,19 @@ class Property FINAL : public Expression { return obj()->IsSuperReference(); } - virtual FeedbackVectorRequirements ComputeFeedbackRequirements() OVERRIDE { + virtual FeedbackVectorRequirements ComputeFeedbackRequirements( + Isolate* isolate) OVERRIDE { return FeedbackVectorRequirements(0, FLAG_vector_ics ? 1 : 0); } - virtual void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE { + void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE { property_feedback_slot_ = slot; } + Code::Kind FeedbackICSlotKind(int index) OVERRIDE { + return key()->IsPropertyName() ? Code::LOAD_IC : Code::KEYED_LOAD_IC; + } FeedbackVectorICSlot PropertyFeedbackSlot() const { + DCHECK(!FLAG_vector_ics || !property_feedback_slot_.IsInvalid()); return property_feedback_slot_; } @@ -1838,6 +1807,7 @@ class Property FINAL : public Expression { class IsForCallField : public BitField8<bool, 0, 1> {}; class IsUninitializedField : public BitField8<bool, 1, 1> {}; class IsStringAccessField : public BitField8<bool, 2, 1> {}; + class KeyTypeField : public BitField8<IcCheckType, 3, 1> {}; uint8_t bit_field_; FeedbackVectorICSlot property_feedback_slot_; Expression* obj_; @@ -1854,24 +1824,27 @@ class Call FINAL : public Expression { ZoneList<Expression*>* arguments() const { return arguments_; } // Type feedback information. - virtual FeedbackVectorRequirements ComputeFeedbackRequirements() OVERRIDE { - return FeedbackVectorRequirements(0, 1); - } - virtual void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE { + virtual FeedbackVectorRequirements ComputeFeedbackRequirements( + Isolate* isolate) OVERRIDE; + void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE { call_feedback_slot_ = slot; } + Code::Kind FeedbackICSlotKind(int index) OVERRIDE { return Code::CALL_IC; } bool HasCallFeedbackSlot() const { return !call_feedback_slot_.IsInvalid(); } - FeedbackVectorICSlot CallFeedbackSlot() const { return call_feedback_slot_; } + FeedbackVectorICSlot CallFeedbackSlot() const { + DCHECK(!call_feedback_slot_.IsInvalid()); + return call_feedback_slot_; + } - virtual SmallMapList* GetReceiverTypes() OVERRIDE { + SmallMapList* GetReceiverTypes() OVERRIDE { if (expression()->IsProperty()) { return expression()->AsProperty()->GetReceiverTypes(); } return NULL; } - virtual bool IsMonomorphic() OVERRIDE { + bool IsMonomorphic() OVERRIDE { if (expression()->IsProperty()) { return expression()->AsProperty()->IsMonomorphic(); } @@ -1903,6 +1876,13 @@ class Call FINAL : public Expression { BailoutId ReturnId() const { return BailoutId(local_id(0)); } BailoutId EvalOrLookupId() const { return BailoutId(local_id(1)); } + bool is_uninitialized() const { + return IsUninitializedField::decode(bit_field_); + } + void set_is_uninitialized(bool b) { + bit_field_ = IsUninitializedField::update(bit_field_, b); + } + enum CallType { POSSIBLY_EVAL_CALL, GLOBAL_CALL, @@ -1927,7 +1907,8 @@ class Call FINAL : public Expression { : Expression(zone, pos), call_feedback_slot_(FeedbackVectorICSlot::Invalid()), expression_(expression), - arguments_(arguments) { + arguments_(arguments), + bit_field_(IsUninitializedField::encode(false)) { if (expression->IsProperty()) { expression->AsProperty()->mark_for_call(); } @@ -1943,6 +1924,8 @@ class Call FINAL : public Expression { Handle<JSFunction> target_; Handle<Cell> cell_; Handle<AllocationSite> allocation_site_; + class IsUninitializedField : public BitField8<bool, 0, 1> {}; + uint8_t bit_field_; }; @@ -1954,21 +1937,25 @@ class CallNew FINAL : public Expression { ZoneList<Expression*>* arguments() const { return arguments_; } // Type feedback information. - virtual FeedbackVectorRequirements ComputeFeedbackRequirements() OVERRIDE { + virtual FeedbackVectorRequirements ComputeFeedbackRequirements( + Isolate* isolate) OVERRIDE { return FeedbackVectorRequirements(FLAG_pretenuring_call_new ? 2 : 1, 0); } - virtual void SetFirstFeedbackSlot(FeedbackVectorSlot slot) OVERRIDE { + void SetFirstFeedbackSlot(FeedbackVectorSlot slot) OVERRIDE { callnew_feedback_slot_ = slot; } - FeedbackVectorSlot CallNewFeedbackSlot() { return callnew_feedback_slot_; } + FeedbackVectorSlot CallNewFeedbackSlot() { + DCHECK(!callnew_feedback_slot_.IsInvalid()); + return callnew_feedback_slot_; + } FeedbackVectorSlot AllocationSiteFeedbackSlot() { DCHECK(FLAG_pretenuring_call_new); return CallNewFeedbackSlot().next(); } void RecordTypeFeedback(TypeFeedbackOracle* oracle); - virtual bool IsMonomorphic() OVERRIDE { return is_monomorphic_; } + bool IsMonomorphic() OVERRIDE { return is_monomorphic_; } Handle<JSFunction> target() const { return target_; } Handle<AllocationSite> allocation_site() const { return allocation_site_; @@ -2016,15 +2003,21 @@ class CallRuntime FINAL : public Expression { bool is_jsruntime() const { return function_ == NULL; } // Type feedback information. - virtual FeedbackVectorRequirements ComputeFeedbackRequirements() OVERRIDE { - return FeedbackVectorRequirements( - 0, (FLAG_vector_ics && is_jsruntime()) ? 1 : 0); + bool HasCallRuntimeFeedbackSlot() const { + return FLAG_vector_ics && is_jsruntime(); } - virtual void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE { + virtual FeedbackVectorRequirements ComputeFeedbackRequirements( + Isolate* isolate) OVERRIDE { + return FeedbackVectorRequirements(0, HasCallRuntimeFeedbackSlot() ? 1 : 0); + } + void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE { callruntime_feedback_slot_ = slot; } + Code::Kind FeedbackICSlotKind(int index) OVERRIDE { return Code::LOAD_IC; } FeedbackVectorICSlot CallRuntimeFeedbackSlot() { + DCHECK(!HasCallRuntimeFeedbackSlot() || + !callruntime_feedback_slot_.IsInvalid()); return callruntime_feedback_slot_; } @@ -2089,7 +2082,7 @@ class BinaryOperation FINAL : public Expression { public: DECLARE_NODE_TYPE(BinaryOperation) - virtual bool ResultOverwriteAllowed() const OVERRIDE; + bool ResultOverwriteAllowed() const OVERRIDE; Token::Value op() const { return static_cast<Token::Value>(op_); } Expression* left() const { return left_; } @@ -2160,16 +2153,12 @@ class CountOperation FINAL : public Expression { Expression* expression() const { return expression_; } - virtual bool IsMonomorphic() OVERRIDE { - return receiver_types_.length() == 1; - } - virtual SmallMapList* GetReceiverTypes() OVERRIDE { - return &receiver_types_; - } - virtual IcCheckType GetKeyType() const OVERRIDE { + bool IsMonomorphic() OVERRIDE { return receiver_types_.length() == 1; } + SmallMapList* GetReceiverTypes() OVERRIDE { return &receiver_types_; } + IcCheckType GetKeyType() const OVERRIDE { return KeyTypeField::decode(bit_field_); } - virtual KeyedAccessStoreMode GetStoreMode() const OVERRIDE { + KeyedAccessStoreMode GetStoreMode() const OVERRIDE { return StoreModeField::decode(bit_field_); } Type* type() const { return type_; } @@ -2314,22 +2303,18 @@ class Assignment FINAL : public Expression { // Type feedback information. TypeFeedbackId AssignmentFeedbackId() { return TypeFeedbackId(local_id(1)); } - virtual bool IsMonomorphic() OVERRIDE { - return receiver_types_.length() == 1; - } + bool IsMonomorphic() OVERRIDE { return receiver_types_.length() == 1; } bool IsUninitialized() const { return IsUninitializedField::decode(bit_field_); } bool HasNoTypeInformation() { return IsUninitializedField::decode(bit_field_); } - virtual SmallMapList* GetReceiverTypes() OVERRIDE { - return &receiver_types_; - } - virtual IcCheckType GetKeyType() const OVERRIDE { + SmallMapList* GetReceiverTypes() OVERRIDE { return &receiver_types_; } + IcCheckType GetKeyType() const OVERRIDE { return KeyTypeField::decode(bit_field_); } - virtual KeyedAccessStoreMode GetStoreMode() const OVERRIDE { + KeyedAccessStoreMode GetStoreMode() const OVERRIDE { return StoreModeField::decode(bit_field_); } void set_is_uninitialized(bool b) { @@ -2347,15 +2332,6 @@ class Assignment FINAL : public Expression { int pos); static int parent_num_ids() { return Expression::num_ids(); } - template <class Visitor> - void Init(AstNodeFactory<Visitor>* factory) { - DCHECK(Token::IsAssignmentOp(op())); - if (is_compound()) { - binary_operation_ = factory->NewBinaryOperation( - binary_op(), target_, value_, position() + 1); - } - } - private: int local_id(int n) const { return base_id() + parent_num_ids() + n; } @@ -2402,15 +2378,22 @@ class Yield FINAL : public Expression { } // Type feedback information. - virtual FeedbackVectorRequirements ComputeFeedbackRequirements() OVERRIDE { - return FeedbackVectorRequirements( - 0, (FLAG_vector_ics && yield_kind() == kDelegating) ? 3 : 0); + bool HasFeedbackSlots() const { + return FLAG_vector_ics && (yield_kind() == kDelegating); + } + virtual FeedbackVectorRequirements ComputeFeedbackRequirements( + Isolate* isolate) OVERRIDE { + return FeedbackVectorRequirements(0, HasFeedbackSlots() ? 3 : 0); } - virtual void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE { + void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE { yield_first_feedback_slot_ = slot; } + Code::Kind FeedbackICSlotKind(int index) OVERRIDE { + return index == 0 ? Code::KEYED_LOAD_IC : Code::LOAD_IC; + } FeedbackVectorICSlot KeyedLoadFeedbackSlot() { + DCHECK(!HasFeedbackSlots() || !yield_first_feedback_slot_.IsInvalid()); return yield_first_feedback_slot_; } @@ -2497,6 +2480,13 @@ class FunctionLiteral FINAL : public Expression { bool is_expression() const { return IsExpression::decode(bitfield_); } bool is_anonymous() const { return IsAnonymous::decode(bitfield_); } StrictMode strict_mode() const; + bool uses_super_property() const; + bool uses_super_constructor_call() const; + + static bool NeedsHomeObject(Expression* literal) { + return literal != NULL && literal->IsFunctionLiteral() && + literal->AsFunctionLiteral()->uses_super_property(); + } int materialized_literal_count() { return materialized_literal_count_; } int expected_property_count() { return expected_property_count_; } @@ -2576,16 +2566,18 @@ class FunctionLiteral FINAL : public Expression { bool is_concise_method() { return IsConciseMethod(FunctionKindBits::decode(bitfield_)); } + bool is_default_constructor() { + return IsDefaultConstructor(FunctionKindBits::decode(bitfield_)); + } int ast_node_count() { return ast_properties_.node_count(); } AstProperties::Flags* flags() { return ast_properties_.flags(); } void set_ast_properties(AstProperties* ast_properties) { ast_properties_ = *ast_properties; } - int slot_count() { - return ast_properties_.feedback_slots(); + const FeedbackVectorSpec& feedback_vector_spec() const { + return ast_properties_.get_spec(); } - int ic_slot_count() { return ast_properties_.ic_feedback_slots(); } bool dont_optimize() { return dont_optimize_reason_ != kNoReason; } BailoutReason dont_optimize_reason() { return dont_optimize_reason_; } void set_dont_optimize_reason(BailoutReason reason) { @@ -2647,7 +2639,7 @@ class FunctionLiteral FINAL : public Expression { class HasDuplicateParameters : public BitField<ParameterFlag, 3, 1> {}; class IsFunction : public BitField<IsFunctionFlag, 4, 1> {}; class IsParenthesized : public BitField<IsParenthesizedFlag, 5, 1> {}; - class FunctionKindBits : public BitField<FunctionKind, 6, 3> {}; + class FunctionKindBits : public BitField<FunctionKind, 6, 4> {}; }; @@ -2659,6 +2651,8 @@ class ClassLiteral FINAL : public Expression { Handle<String> name() const { return raw_name_->string(); } const AstRawString* raw_name() const { return raw_name_; } + Scope* scope() const { return scope_; } + VariableProxy* class_variable_proxy() const { return class_variable_proxy_; } Expression* extends() const { return extends_; } Expression* constructor() const { return constructor_; } ZoneList<Property*>* properties() const { return properties_; } @@ -2666,11 +2660,14 @@ class ClassLiteral FINAL : public Expression { int end_position() const { return end_position_; } protected: - ClassLiteral(Zone* zone, const AstRawString* name, Expression* extends, + ClassLiteral(Zone* zone, const AstRawString* name, Scope* scope, + VariableProxy* class_variable_proxy, Expression* extends, Expression* constructor, ZoneList<Property*>* properties, int start_position, int end_position) : Expression(zone, start_position), raw_name_(name), + scope_(scope), + class_variable_proxy_(class_variable_proxy), extends_(extends), constructor_(constructor), properties_(properties), @@ -2678,6 +2675,8 @@ class ClassLiteral FINAL : public Expression { private: const AstRawString* raw_name_; + Scope* scope_; + VariableProxy* class_variable_proxy_; Expression* extends_; Expression* constructor_; ZoneList<Property*>* properties_; @@ -2722,12 +2721,14 @@ class SuperReference FINAL : public Expression { TypeFeedbackId HomeObjectFeedbackId() { return TypeFeedbackId(local_id(0)); } // Type feedback information. - virtual FeedbackVectorRequirements ComputeFeedbackRequirements() OVERRIDE { + virtual FeedbackVectorRequirements ComputeFeedbackRequirements( + Isolate* isolate) OVERRIDE { return FeedbackVectorRequirements(0, FLAG_vector_ics ? 1 : 0); } - virtual void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE { + void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE { homeobject_feedback_slot_ = slot; } + Code::Kind FeedbackICSlotKind(int index) OVERRIDE { return Code::LOAD_IC; } FeedbackVectorICSlot HomeObjectFeedbackSlot() { DCHECK(!FLAG_vector_ics || !homeobject_feedback_slot_.IsInvalid()); @@ -2796,16 +2797,16 @@ class RegExpTree : public ZoneObject { class RegExpDisjunction FINAL : public RegExpTree { public: explicit RegExpDisjunction(ZoneList<RegExpTree*>* alternatives); - virtual void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE; + void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE; virtual RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) OVERRIDE; - virtual RegExpDisjunction* AsDisjunction() OVERRIDE; - virtual Interval CaptureRegisters() OVERRIDE; - virtual bool IsDisjunction() OVERRIDE; - virtual bool IsAnchoredAtStart() OVERRIDE; - virtual bool IsAnchoredAtEnd() OVERRIDE; - virtual int min_match() OVERRIDE { return min_match_; } - virtual int max_match() OVERRIDE { return max_match_; } + RegExpDisjunction* AsDisjunction() OVERRIDE; + Interval CaptureRegisters() OVERRIDE; + bool IsDisjunction() OVERRIDE; + bool IsAnchoredAtStart() OVERRIDE; + bool IsAnchoredAtEnd() OVERRIDE; + int min_match() OVERRIDE { return min_match_; } + int max_match() OVERRIDE { return max_match_; } ZoneList<RegExpTree*>* alternatives() { return alternatives_; } private: ZoneList<RegExpTree*>* alternatives_; @@ -2817,16 +2818,16 @@ class RegExpDisjunction FINAL : public RegExpTree { class RegExpAlternative FINAL : public RegExpTree { public: explicit RegExpAlternative(ZoneList<RegExpTree*>* nodes); - virtual void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE; + void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE; virtual RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) OVERRIDE; - virtual RegExpAlternative* AsAlternative() OVERRIDE; - virtual Interval CaptureRegisters() OVERRIDE; - virtual bool IsAlternative() OVERRIDE; - virtual bool IsAnchoredAtStart() OVERRIDE; - virtual bool IsAnchoredAtEnd() OVERRIDE; - virtual int min_match() OVERRIDE { return min_match_; } - virtual int max_match() OVERRIDE { return max_match_; } + RegExpAlternative* AsAlternative() OVERRIDE; + Interval CaptureRegisters() OVERRIDE; + bool IsAlternative() OVERRIDE; + bool IsAnchoredAtStart() OVERRIDE; + bool IsAnchoredAtEnd() OVERRIDE; + int min_match() OVERRIDE { return min_match_; } + int max_match() OVERRIDE { return max_match_; } ZoneList<RegExpTree*>* nodes() { return nodes_; } private: ZoneList<RegExpTree*>* nodes_; @@ -2846,15 +2847,15 @@ class RegExpAssertion FINAL : public RegExpTree { NON_BOUNDARY }; explicit RegExpAssertion(AssertionType type) : assertion_type_(type) { } - virtual void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE; + void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE; virtual RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) OVERRIDE; - virtual RegExpAssertion* AsAssertion() OVERRIDE; - virtual bool IsAssertion() OVERRIDE; - virtual bool IsAnchoredAtStart() OVERRIDE; - virtual bool IsAnchoredAtEnd() OVERRIDE; - virtual int min_match() OVERRIDE { return 0; } - virtual int max_match() OVERRIDE { return 0; } + RegExpAssertion* AsAssertion() OVERRIDE; + bool IsAssertion() OVERRIDE; + bool IsAnchoredAtStart() OVERRIDE; + bool IsAnchoredAtEnd() OVERRIDE; + int min_match() OVERRIDE { return 0; } + int max_match() OVERRIDE { return 0; } AssertionType assertion_type() { return assertion_type_; } private: AssertionType assertion_type_; @@ -2892,15 +2893,15 @@ class RegExpCharacterClass FINAL : public RegExpTree { explicit RegExpCharacterClass(uc16 type) : set_(type), is_negated_(false) { } - virtual void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE; + void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE; virtual RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) OVERRIDE; - virtual RegExpCharacterClass* AsCharacterClass() OVERRIDE; - virtual bool IsCharacterClass() OVERRIDE; - virtual bool IsTextElement() OVERRIDE { return true; } - virtual int min_match() OVERRIDE { return 1; } - virtual int max_match() OVERRIDE { return 1; } - virtual void AppendToText(RegExpText* text, Zone* zone) OVERRIDE; + RegExpCharacterClass* AsCharacterClass() OVERRIDE; + bool IsCharacterClass() OVERRIDE; + bool IsTextElement() OVERRIDE { return true; } + int min_match() OVERRIDE { return 1; } + int max_match() OVERRIDE { return 1; } + void AppendToText(RegExpText* text, Zone* zone) OVERRIDE; CharacterSet character_set() { return set_; } // TODO(lrn): Remove need for complex version if is_standard that // recognizes a mangled standard set and just do { return set_.is_special(); } @@ -2929,15 +2930,15 @@ class RegExpCharacterClass FINAL : public RegExpTree { class RegExpAtom FINAL : public RegExpTree { public: explicit RegExpAtom(Vector<const uc16> data) : data_(data) { } - virtual void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE; + void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE; virtual RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) OVERRIDE; - virtual RegExpAtom* AsAtom() OVERRIDE; - virtual bool IsAtom() OVERRIDE; - virtual bool IsTextElement() OVERRIDE { return true; } - virtual int min_match() OVERRIDE { return data_.length(); } - virtual int max_match() OVERRIDE { return data_.length(); } - virtual void AppendToText(RegExpText* text, Zone* zone) OVERRIDE; + RegExpAtom* AsAtom() OVERRIDE; + bool IsAtom() OVERRIDE; + bool IsTextElement() OVERRIDE { return true; } + int min_match() OVERRIDE { return data_.length(); } + int max_match() OVERRIDE { return data_.length(); } + void AppendToText(RegExpText* text, Zone* zone) OVERRIDE; Vector<const uc16> data() { return data_; } int length() { return data_.length(); } private: @@ -2948,15 +2949,15 @@ class RegExpAtom FINAL : public RegExpTree { class RegExpText FINAL : public RegExpTree { public: explicit RegExpText(Zone* zone) : elements_(2, zone), length_(0) {} - virtual void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE; + void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE; virtual RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) OVERRIDE; - virtual RegExpText* AsText() OVERRIDE; - virtual bool IsText() OVERRIDE; - virtual bool IsTextElement() OVERRIDE { return true; } - virtual int min_match() OVERRIDE { return length_; } - virtual int max_match() OVERRIDE { return length_; } - virtual void AppendToText(RegExpText* text, Zone* zone) OVERRIDE; + RegExpText* AsText() OVERRIDE; + bool IsText() OVERRIDE; + bool IsTextElement() OVERRIDE { return true; } + int min_match() OVERRIDE { return length_; } + int max_match() OVERRIDE { return length_; } + void AppendToText(RegExpText* text, Zone* zone) OVERRIDE; void AddElement(TextElement elm, Zone* zone) { elements_.Add(elm, zone); length_ += elm.length(); @@ -2983,7 +2984,7 @@ class RegExpQuantifier FINAL : public RegExpTree { max_match_ = max * body->max_match(); } } - virtual void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE; + void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE; virtual RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) OVERRIDE; static RegExpNode* ToNode(int min, @@ -2993,11 +2994,11 @@ class RegExpQuantifier FINAL : public RegExpTree { RegExpCompiler* compiler, RegExpNode* on_success, bool not_at_start = false); - virtual RegExpQuantifier* AsQuantifier() OVERRIDE; - virtual Interval CaptureRegisters() OVERRIDE; - virtual bool IsQuantifier() OVERRIDE; - virtual int min_match() OVERRIDE { return min_match_; } - virtual int max_match() OVERRIDE { return max_match_; } + RegExpQuantifier* AsQuantifier() OVERRIDE; + Interval CaptureRegisters() OVERRIDE; + bool IsQuantifier() OVERRIDE; + int min_match() OVERRIDE { return min_match_; } + int max_match() OVERRIDE { return max_match_; } int min() { return min_; } int max() { return max_; } bool is_possessive() { return quantifier_type_ == POSSESSIVE; } @@ -3019,20 +3020,20 @@ class RegExpCapture FINAL : public RegExpTree { public: explicit RegExpCapture(RegExpTree* body, int index) : body_(body), index_(index) { } - virtual void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE; + void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE; virtual RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) OVERRIDE; static RegExpNode* ToNode(RegExpTree* body, int index, RegExpCompiler* compiler, RegExpNode* on_success); - virtual RegExpCapture* AsCapture() OVERRIDE; - virtual bool IsAnchoredAtStart() OVERRIDE; - virtual bool IsAnchoredAtEnd() OVERRIDE; - virtual Interval CaptureRegisters() OVERRIDE; - virtual bool IsCapture() OVERRIDE; - virtual int min_match() OVERRIDE { return body_->min_match(); } - virtual int max_match() OVERRIDE { return body_->max_match(); } + RegExpCapture* AsCapture() OVERRIDE; + bool IsAnchoredAtStart() OVERRIDE; + bool IsAnchoredAtEnd() OVERRIDE; + Interval CaptureRegisters() OVERRIDE; + bool IsCapture() OVERRIDE; + int min_match() OVERRIDE { return body_->min_match(); } + int max_match() OVERRIDE { return body_->max_match(); } RegExpTree* body() { return body_; } int index() { return index_; } static int StartRegister(int index) { return index * 2; } @@ -3055,15 +3056,15 @@ class RegExpLookahead FINAL : public RegExpTree { capture_count_(capture_count), capture_from_(capture_from) { } - virtual void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE; + void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE; virtual RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) OVERRIDE; - virtual RegExpLookahead* AsLookahead() OVERRIDE; - virtual Interval CaptureRegisters() OVERRIDE; - virtual bool IsLookahead() OVERRIDE; - virtual bool IsAnchoredAtStart() OVERRIDE; - virtual int min_match() OVERRIDE { return 0; } - virtual int max_match() OVERRIDE { return 0; } + RegExpLookahead* AsLookahead() OVERRIDE; + Interval CaptureRegisters() OVERRIDE; + bool IsLookahead() OVERRIDE; + bool IsAnchoredAtStart() OVERRIDE; + int min_match() OVERRIDE { return 0; } + int max_match() OVERRIDE { return 0; } RegExpTree* body() { return body_; } bool is_positive() { return is_positive_; } int capture_count() { return capture_count_; } @@ -3081,13 +3082,13 @@ class RegExpBackReference FINAL : public RegExpTree { public: explicit RegExpBackReference(RegExpCapture* capture) : capture_(capture) { } - virtual void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE; + void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE; virtual RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) OVERRIDE; - virtual RegExpBackReference* AsBackReference() OVERRIDE; - virtual bool IsBackReference() OVERRIDE; - virtual int min_match() OVERRIDE { return 0; } - virtual int max_match() OVERRIDE { return capture_->max_match(); } + RegExpBackReference* AsBackReference() OVERRIDE; + bool IsBackReference() OVERRIDE; + int min_match() OVERRIDE { return 0; } + int max_match() OVERRIDE { return capture_->max_match(); } int index() { return capture_->index(); } RegExpCapture* capture() { return capture_; } private: @@ -3098,17 +3099,13 @@ class RegExpBackReference FINAL : public RegExpTree { class RegExpEmpty FINAL : public RegExpTree { public: RegExpEmpty() { } - virtual void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE; + void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE; virtual RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) OVERRIDE; - virtual RegExpEmpty* AsEmpty() OVERRIDE; - virtual bool IsEmpty() OVERRIDE; - virtual int min_match() OVERRIDE { return 0; } - virtual int max_match() OVERRIDE { return 0; } - static RegExpEmpty* GetInstance() { - static RegExpEmpty* instance = ::new RegExpEmpty(); - return instance; - } + RegExpEmpty* AsEmpty() OVERRIDE; + bool IsEmpty() OVERRIDE; + int min_match() OVERRIDE { return 0; } + int max_match() OVERRIDE { return 0; } }; @@ -3146,123 +3143,49 @@ class AstVisitor BASE_EMBEDDED { }; -#define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS() \ -public: \ - virtual void Visit(AstNode* node) FINAL OVERRIDE { \ - if (!CheckStackOverflow()) node->Accept(this); \ - } \ - \ - void SetStackOverflow() { stack_overflow_ = true; } \ - void ClearStackOverflow() { stack_overflow_ = false; } \ - bool HasStackOverflow() const { return stack_overflow_; } \ - \ - bool CheckStackOverflow() { \ - if (stack_overflow_) return true; \ - StackLimitCheck check(zone_->isolate()); \ - if (!check.HasOverflowed()) return false; \ - return (stack_overflow_ = true); \ - } \ - \ -private: \ - void InitializeAstVisitor(Zone* zone) { \ - zone_ = zone; \ - stack_overflow_ = false; \ - } \ - Zone* zone() { return zone_; } \ - Isolate* isolate() { return zone_->isolate(); } \ - \ - Zone* zone_; \ +#define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS() \ + public: \ + void Visit(AstNode* node) FINAL { \ + if (!CheckStackOverflow()) node->Accept(this); \ + } \ + \ + void SetStackOverflow() { stack_overflow_ = true; } \ + void ClearStackOverflow() { stack_overflow_ = false; } \ + bool HasStackOverflow() const { return stack_overflow_; } \ + \ + bool CheckStackOverflow() { \ + if (stack_overflow_) return true; \ + StackLimitCheck check(zone_->isolate()); \ + if (!check.HasOverflowed()) return false; \ + return (stack_overflow_ = true); \ + } \ + \ + private: \ + void InitializeAstVisitor(Zone* zone) { \ + zone_ = zone; \ + stack_overflow_ = false; \ + } \ + Zone* zone() { return zone_; } \ + Isolate* isolate() { return zone_->isolate(); } \ + \ + Zone* zone_; \ bool stack_overflow_ // ---------------------------------------------------------------------------- -// Construction time visitor. - -class AstConstructionVisitor BASE_EMBEDDED { - public: - AstConstructionVisitor() - : dont_crankshaft_reason_(kNoReason), dont_turbofan_reason_(kNoReason) {} - - AstProperties* ast_properties() { return &properties_; } - BailoutReason dont_optimize_reason() { - if (dont_turbofan_reason_ != kNoReason) { - return dont_turbofan_reason_; - } else { - return dont_crankshaft_reason_; - } - } - - private: - template<class> friend class AstNodeFactory; - - // Node visitors. -#define DEF_VISIT(type) \ - void Visit##type(type* node); - AST_NODE_LIST(DEF_VISIT) -#undef DEF_VISIT - - void add_flag(AstPropertiesFlag flag) { properties_.flags()->Add(flag); } - void set_dont_crankshaft_reason(BailoutReason reason) { - dont_crankshaft_reason_ = reason; - } - void set_dont_turbofan_reason(BailoutReason reason) { - dont_turbofan_reason_ = reason; - } - - void add_slot_node(AstNode* slot_node) { - FeedbackVectorRequirements reqs = slot_node->ComputeFeedbackRequirements(); - if (reqs.slots() > 0) { - slot_node->SetFirstFeedbackSlot( - FeedbackVectorSlot(properties_.feedback_slots())); - properties_.increase_feedback_slots(reqs.slots()); - } - if (reqs.ic_slots() > 0) { - slot_node->SetFirstFeedbackICSlot( - FeedbackVectorICSlot(properties_.ic_feedback_slots())); - properties_.increase_ic_feedback_slots(reqs.ic_slots()); - } - } - - AstProperties properties_; - BailoutReason dont_crankshaft_reason_; - BailoutReason dont_turbofan_reason_; -}; - - -class AstNullVisitor BASE_EMBEDDED { - public: - // Node visitors. -#define DEF_VISIT(type) \ - void Visit##type(type* node) {} - AST_NODE_LIST(DEF_VISIT) -#undef DEF_VISIT -}; - - - -// ---------------------------------------------------------------------------- // AstNode factory -template<class Visitor> class AstNodeFactory FINAL BASE_EMBEDDED { public: explicit AstNodeFactory(AstValueFactory* ast_value_factory) : zone_(ast_value_factory->zone()), ast_value_factory_(ast_value_factory) {} - Visitor* visitor() { return &visitor_; } - -#define VISIT_AND_RETURN(NodeType, node) \ - visitor_.Visit##NodeType((node)); \ - return node; - VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy, VariableMode mode, Scope* scope, int pos) { - VariableDeclaration* decl = - new(zone_) VariableDeclaration(zone_, proxy, mode, scope, pos); - VISIT_AND_RETURN(VariableDeclaration, decl) + return new (zone_) VariableDeclaration(zone_, proxy, mode, scope, pos); } FunctionDeclaration* NewFunctionDeclaration(VariableProxy* proxy, @@ -3270,71 +3193,56 @@ class AstNodeFactory FINAL BASE_EMBEDDED { FunctionLiteral* fun, Scope* scope, int pos) { - FunctionDeclaration* decl = - new(zone_) FunctionDeclaration(zone_, proxy, mode, fun, scope, pos); - VISIT_AND_RETURN(FunctionDeclaration, decl) + return new (zone_) FunctionDeclaration(zone_, proxy, mode, fun, scope, pos); } ModuleDeclaration* NewModuleDeclaration(VariableProxy* proxy, Module* module, Scope* scope, int pos) { - ModuleDeclaration* decl = - new(zone_) ModuleDeclaration(zone_, proxy, module, scope, pos); - VISIT_AND_RETURN(ModuleDeclaration, decl) + return new (zone_) ModuleDeclaration(zone_, proxy, module, scope, pos); } ImportDeclaration* NewImportDeclaration(VariableProxy* proxy, Module* module, Scope* scope, int pos) { - ImportDeclaration* decl = - new(zone_) ImportDeclaration(zone_, proxy, module, scope, pos); - VISIT_AND_RETURN(ImportDeclaration, decl) + return new (zone_) ImportDeclaration(zone_, proxy, module, scope, pos); } ExportDeclaration* NewExportDeclaration(VariableProxy* proxy, Scope* scope, int pos) { - ExportDeclaration* decl = - new(zone_) ExportDeclaration(zone_, proxy, scope, pos); - VISIT_AND_RETURN(ExportDeclaration, decl) + return new (zone_) ExportDeclaration(zone_, proxy, scope, pos); } ModuleLiteral* NewModuleLiteral(Block* body, Interface* interface, int pos) { - ModuleLiteral* module = - new(zone_) ModuleLiteral(zone_, body, interface, pos); - VISIT_AND_RETURN(ModuleLiteral, module) + return new (zone_) ModuleLiteral(zone_, body, interface, pos); } ModuleVariable* NewModuleVariable(VariableProxy* proxy, int pos) { - ModuleVariable* module = new(zone_) ModuleVariable(zone_, proxy, pos); - VISIT_AND_RETURN(ModuleVariable, module) + return new (zone_) ModuleVariable(zone_, proxy, pos); } ModulePath* NewModulePath(Module* origin, const AstRawString* name, int pos) { - ModulePath* module = new (zone_) ModulePath(zone_, origin, name, pos); - VISIT_AND_RETURN(ModulePath, module) + return new (zone_) ModulePath(zone_, origin, name, pos); } ModuleUrl* NewModuleUrl(Handle<String> url, int pos) { - ModuleUrl* module = new(zone_) ModuleUrl(zone_, url, pos); - VISIT_AND_RETURN(ModuleUrl, module) + return new (zone_) ModuleUrl(zone_, url, pos); } Block* NewBlock(ZoneList<const AstRawString*>* labels, int capacity, bool is_initializer_block, int pos) { - Block* block = - new (zone_) Block(zone_, labels, capacity, is_initializer_block, pos); - VISIT_AND_RETURN(Block, block) + return new (zone_) + Block(zone_, labels, capacity, is_initializer_block, pos); } #define STATEMENT_WITH_LABELS(NodeType) \ NodeType* New##NodeType(ZoneList<const AstRawString*>* labels, int pos) { \ - NodeType* stmt = new (zone_) NodeType(zone_, labels, pos); \ - VISIT_AND_RETURN(NodeType, stmt); \ + return new (zone_) NodeType(zone_, labels, pos); \ } STATEMENT_WITH_LABELS(DoWhileStatement) STATEMENT_WITH_LABELS(WhileStatement) @@ -3347,12 +3255,10 @@ class AstNodeFactory FINAL BASE_EMBEDDED { int pos) { switch (visit_mode) { case ForEachStatement::ENUMERATE: { - ForInStatement* stmt = new (zone_) ForInStatement(zone_, labels, pos); - VISIT_AND_RETURN(ForInStatement, stmt); + return new (zone_) ForInStatement(zone_, labels, pos); } case ForEachStatement::ITERATE: { - ForOfStatement* stmt = new (zone_) ForOfStatement(zone_, labels, pos); - VISIT_AND_RETURN(ForOfStatement, stmt); + return new (zone_) ForOfStatement(zone_, labels, pos); } } UNREACHABLE(); @@ -3361,47 +3267,38 @@ class AstNodeFactory FINAL BASE_EMBEDDED { ModuleStatement* NewModuleStatement( VariableProxy* proxy, Block* body, int pos) { - ModuleStatement* stmt = new(zone_) ModuleStatement(zone_, proxy, body, pos); - VISIT_AND_RETURN(ModuleStatement, stmt) + return new (zone_) ModuleStatement(zone_, proxy, body, pos); } ExpressionStatement* NewExpressionStatement(Expression* expression, int pos) { - ExpressionStatement* stmt = - new(zone_) ExpressionStatement(zone_, expression, pos); - VISIT_AND_RETURN(ExpressionStatement, stmt) + return new (zone_) ExpressionStatement(zone_, expression, pos); } ContinueStatement* NewContinueStatement(IterationStatement* target, int pos) { - ContinueStatement* stmt = new(zone_) ContinueStatement(zone_, target, pos); - VISIT_AND_RETURN(ContinueStatement, stmt) + return new (zone_) ContinueStatement(zone_, target, pos); } BreakStatement* NewBreakStatement(BreakableStatement* target, int pos) { - BreakStatement* stmt = new(zone_) BreakStatement(zone_, target, pos); - VISIT_AND_RETURN(BreakStatement, stmt) + return new (zone_) BreakStatement(zone_, target, pos); } ReturnStatement* NewReturnStatement(Expression* expression, int pos) { - ReturnStatement* stmt = new(zone_) ReturnStatement(zone_, expression, pos); - VISIT_AND_RETURN(ReturnStatement, stmt) + return new (zone_) ReturnStatement(zone_, expression, pos); } WithStatement* NewWithStatement(Scope* scope, Expression* expression, Statement* statement, int pos) { - WithStatement* stmt = new(zone_) WithStatement( - zone_, scope, expression, statement, pos); - VISIT_AND_RETURN(WithStatement, stmt) + return new (zone_) WithStatement(zone_, scope, expression, statement, pos); } IfStatement* NewIfStatement(Expression* condition, Statement* then_statement, Statement* else_statement, int pos) { - IfStatement* stmt = new (zone_) + return new (zone_) IfStatement(zone_, condition, then_statement, else_statement, pos); - VISIT_AND_RETURN(IfStatement, stmt) } TryCatchStatement* NewTryCatchStatement(int index, @@ -3410,23 +3307,20 @@ class AstNodeFactory FINAL BASE_EMBEDDED { Variable* variable, Block* catch_block, int pos) { - TryCatchStatement* stmt = new(zone_) TryCatchStatement( - zone_, index, try_block, scope, variable, catch_block, pos); - VISIT_AND_RETURN(TryCatchStatement, stmt) + return new (zone_) TryCatchStatement(zone_, index, try_block, scope, + variable, catch_block, pos); } TryFinallyStatement* NewTryFinallyStatement(int index, Block* try_block, Block* finally_block, int pos) { - TryFinallyStatement* stmt = new(zone_) TryFinallyStatement( - zone_, index, try_block, finally_block, pos); - VISIT_AND_RETURN(TryFinallyStatement, stmt) + return new (zone_) + TryFinallyStatement(zone_, index, try_block, finally_block, pos); } DebuggerStatement* NewDebuggerStatement(int pos) { - DebuggerStatement* stmt = new (zone_) DebuggerStatement(zone_, pos); - VISIT_AND_RETURN(DebuggerStatement, stmt) + return new (zone_) DebuggerStatement(zone_, pos); } EmptyStatement* NewEmptyStatement(int pos) { @@ -3435,57 +3329,42 @@ class AstNodeFactory FINAL BASE_EMBEDDED { CaseClause* NewCaseClause( Expression* label, ZoneList<Statement*>* statements, int pos) { - CaseClause* clause = new (zone_) CaseClause(zone_, label, statements, pos); - VISIT_AND_RETURN(CaseClause, clause) + return new (zone_) CaseClause(zone_, label, statements, pos); } Literal* NewStringLiteral(const AstRawString* string, int pos) { - Literal* lit = - new (zone_) Literal(zone_, ast_value_factory_->NewString(string), pos); - VISIT_AND_RETURN(Literal, lit) + return new (zone_) + Literal(zone_, ast_value_factory_->NewString(string), pos); } // A JavaScript symbol (ECMA-262 edition 6). Literal* NewSymbolLiteral(const char* name, int pos) { - Literal* lit = - new (zone_) Literal(zone_, ast_value_factory_->NewSymbol(name), pos); - VISIT_AND_RETURN(Literal, lit) + return new (zone_) Literal(zone_, ast_value_factory_->NewSymbol(name), pos); } Literal* NewNumberLiteral(double number, int pos) { - Literal* lit = - new (zone_) Literal(zone_, ast_value_factory_->NewNumber(number), pos); - VISIT_AND_RETURN(Literal, lit) + return new (zone_) + Literal(zone_, ast_value_factory_->NewNumber(number), pos); } Literal* NewSmiLiteral(int number, int pos) { - Literal* lit = - new (zone_) Literal(zone_, ast_value_factory_->NewSmi(number), pos); - VISIT_AND_RETURN(Literal, lit) + return new (zone_) Literal(zone_, ast_value_factory_->NewSmi(number), pos); } Literal* NewBooleanLiteral(bool b, int pos) { - Literal* lit = - new (zone_) Literal(zone_, ast_value_factory_->NewBoolean(b), pos); - VISIT_AND_RETURN(Literal, lit) + return new (zone_) Literal(zone_, ast_value_factory_->NewBoolean(b), pos); } Literal* NewNullLiteral(int pos) { - Literal* lit = - new (zone_) Literal(zone_, ast_value_factory_->NewNull(), pos); - VISIT_AND_RETURN(Literal, lit) + return new (zone_) Literal(zone_, ast_value_factory_->NewNull(), pos); } Literal* NewUndefinedLiteral(int pos) { - Literal* lit = - new (zone_) Literal(zone_, ast_value_factory_->NewUndefined(), pos); - VISIT_AND_RETURN(Literal, lit) + return new (zone_) Literal(zone_, ast_value_factory_->NewUndefined(), pos); } Literal* NewTheHoleLiteral(int pos) { - Literal* lit = - new (zone_) Literal(zone_, ast_value_factory_->NewTheHole(), pos); - VISIT_AND_RETURN(Literal, lit) + return new (zone_) Literal(zone_, ast_value_factory_->NewTheHole(), pos); } ObjectLiteral* NewObjectLiteral( @@ -3494,10 +3373,8 @@ class AstNodeFactory FINAL BASE_EMBEDDED { int boilerplate_properties, bool has_function, int pos) { - ObjectLiteral* lit = - new (zone_) ObjectLiteral(zone_, properties, literal_index, - boilerplate_properties, has_function, pos); - VISIT_AND_RETURN(ObjectLiteral, lit) + return new (zone_) ObjectLiteral(zone_, properties, literal_index, + boilerplate_properties, has_function, pos); } ObjectLiteral::Property* NewObjectLiteralProperty(Literal* key, @@ -3513,120 +3390,104 @@ class AstNodeFactory FINAL BASE_EMBEDDED { ObjectLiteral::Property* prop = new (zone_) ObjectLiteral::Property(zone_, is_getter, value, is_static); prop->set_key(NewStringLiteral(value->raw_name(), pos)); - return prop; // Not an AST node, will not be visited. + return prop; } RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern, const AstRawString* flags, int literal_index, int pos) { - RegExpLiteral* lit = - new (zone_) RegExpLiteral(zone_, pattern, flags, literal_index, pos); - VISIT_AND_RETURN(RegExpLiteral, lit); + return new (zone_) RegExpLiteral(zone_, pattern, flags, literal_index, pos); } ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values, int literal_index, int pos) { - ArrayLiteral* lit = - new (zone_) ArrayLiteral(zone_, values, literal_index, pos); - VISIT_AND_RETURN(ArrayLiteral, lit) + return new (zone_) ArrayLiteral(zone_, values, literal_index, pos); } VariableProxy* NewVariableProxy(Variable* var, int pos = RelocInfo::kNoPosition) { - VariableProxy* proxy = new (zone_) VariableProxy(zone_, var, pos); - VISIT_AND_RETURN(VariableProxy, proxy) + return new (zone_) VariableProxy(zone_, var, pos); } VariableProxy* NewVariableProxy(const AstRawString* name, bool is_this, Interface* interface = Interface::NewValue(), int position = RelocInfo::kNoPosition) { - VariableProxy* proxy = - new (zone_) VariableProxy(zone_, name, is_this, interface, position); - VISIT_AND_RETURN(VariableProxy, proxy) + return new (zone_) VariableProxy(zone_, name, is_this, interface, position); } Property* NewProperty(Expression* obj, Expression* key, int pos) { - Property* prop = new (zone_) Property(zone_, obj, key, pos); - VISIT_AND_RETURN(Property, prop) + return new (zone_) Property(zone_, obj, key, pos); } Call* NewCall(Expression* expression, ZoneList<Expression*>* arguments, int pos) { - Call* call = new (zone_) Call(zone_, expression, arguments, pos); - VISIT_AND_RETURN(Call, call) + return new (zone_) Call(zone_, expression, arguments, pos); } CallNew* NewCallNew(Expression* expression, ZoneList<Expression*>* arguments, int pos) { - CallNew* call = new (zone_) CallNew(zone_, expression, arguments, pos); - VISIT_AND_RETURN(CallNew, call) + return new (zone_) CallNew(zone_, expression, arguments, pos); } CallRuntime* NewCallRuntime(const AstRawString* name, const Runtime::Function* function, ZoneList<Expression*>* arguments, int pos) { - CallRuntime* call = - new (zone_) CallRuntime(zone_, name, function, arguments, pos); - VISIT_AND_RETURN(CallRuntime, call) + return new (zone_) CallRuntime(zone_, name, function, arguments, pos); } UnaryOperation* NewUnaryOperation(Token::Value op, Expression* expression, int pos) { - UnaryOperation* node = - new (zone_) UnaryOperation(zone_, op, expression, pos); - VISIT_AND_RETURN(UnaryOperation, node) + return new (zone_) UnaryOperation(zone_, op, expression, pos); } BinaryOperation* NewBinaryOperation(Token::Value op, Expression* left, Expression* right, int pos) { - BinaryOperation* node = - new (zone_) BinaryOperation(zone_, op, left, right, pos); - VISIT_AND_RETURN(BinaryOperation, node) + return new (zone_) BinaryOperation(zone_, op, left, right, pos); } CountOperation* NewCountOperation(Token::Value op, bool is_prefix, Expression* expr, int pos) { - CountOperation* node = - new (zone_) CountOperation(zone_, op, is_prefix, expr, pos); - VISIT_AND_RETURN(CountOperation, node) + return new (zone_) CountOperation(zone_, op, is_prefix, expr, pos); } CompareOperation* NewCompareOperation(Token::Value op, Expression* left, Expression* right, int pos) { - CompareOperation* node = - new (zone_) CompareOperation(zone_, op, left, right, pos); - VISIT_AND_RETURN(CompareOperation, node) + return new (zone_) CompareOperation(zone_, op, left, right, pos); } Conditional* NewConditional(Expression* condition, Expression* then_expression, Expression* else_expression, int position) { - Conditional* cond = new (zone_) Conditional( - zone_, condition, then_expression, else_expression, position); - VISIT_AND_RETURN(Conditional, cond) + return new (zone_) Conditional(zone_, condition, then_expression, + else_expression, position); } Assignment* NewAssignment(Token::Value op, Expression* target, Expression* value, int pos) { + DCHECK(Token::IsAssignmentOp(op)); Assignment* assign = new (zone_) Assignment(zone_, op, target, value, pos); - assign->Init(this); - VISIT_AND_RETURN(Assignment, assign) + if (assign->is_compound()) { + DCHECK(Token::IsAssignmentOp(op)); + assign->binary_operation_ = + NewBinaryOperation(assign->binary_op(), target, value, pos + 1); + } + return assign; } Yield* NewYield(Expression *generator_object, @@ -3634,14 +3495,12 @@ class AstNodeFactory FINAL BASE_EMBEDDED { Yield::Kind yield_kind, int pos) { if (!expression) expression = NewUndefinedLiteral(pos); - Yield* yield = - new (zone_) Yield(zone_, generator_object, expression, yield_kind, pos); - VISIT_AND_RETURN(Yield, yield) + return new (zone_) + Yield(zone_, generator_object, expression, yield_kind, pos); } Throw* NewThrow(Expression* exception, int pos) { - Throw* t = new (zone_) Throw(zone_, exception, pos); - VISIT_AND_RETURN(Throw, t) + return new (zone_) Throw(zone_, exception, pos); } FunctionLiteral* NewFunctionLiteral( @@ -3653,51 +3512,39 @@ class AstNodeFactory FINAL BASE_EMBEDDED { FunctionLiteral::IsFunctionFlag is_function, FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind, int position) { - FunctionLiteral* lit = new (zone_) FunctionLiteral( + return new (zone_) FunctionLiteral( zone_, name, ast_value_factory, scope, body, materialized_literal_count, expected_property_count, handler_count, parameter_count, function_type, has_duplicate_parameters, is_function, is_parenthesized, kind, position); - // Top-level literal doesn't count for the AST's properties. - if (is_function == FunctionLiteral::kIsFunction) { - visitor_.VisitFunctionLiteral(lit); - } - return lit; } - ClassLiteral* NewClassLiteral(const AstRawString* name, Expression* extends, + ClassLiteral* NewClassLiteral(const AstRawString* name, Scope* scope, + VariableProxy* proxy, Expression* extends, Expression* constructor, ZoneList<ObjectLiteral::Property*>* properties, int start_position, int end_position) { - ClassLiteral* lit = - new (zone_) ClassLiteral(zone_, name, extends, constructor, properties, - start_position, end_position); - VISIT_AND_RETURN(ClassLiteral, lit) + return new (zone_) + ClassLiteral(zone_, name, scope, proxy, extends, constructor, + properties, start_position, end_position); } NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name, v8::Extension* extension, int pos) { - NativeFunctionLiteral* lit = - new (zone_) NativeFunctionLiteral(zone_, name, extension, pos); - VISIT_AND_RETURN(NativeFunctionLiteral, lit) + return new (zone_) NativeFunctionLiteral(zone_, name, extension, pos); } ThisFunction* NewThisFunction(int pos) { - ThisFunction* fun = new (zone_) ThisFunction(zone_, pos); - VISIT_AND_RETURN(ThisFunction, fun) + return new (zone_) ThisFunction(zone_, pos); } SuperReference* NewSuperReference(VariableProxy* this_var, int pos) { - SuperReference* super = new (zone_) SuperReference(zone_, this_var, pos); - VISIT_AND_RETURN(SuperReference, super); + return new (zone_) SuperReference(zone_, this_var, pos); } -#undef VISIT_AND_RETURN - private: Zone* zone_; - Visitor visitor_; AstValueFactory* ast_value_factory_; }; |