Commit ebf166df authored by verwaest's avatar verwaest Committed by Commit bot

Templatize AstVisitor with its subclass

This replaces the vtable on AstNode with a NodeType tag. The visitors replace double dispatch with a single switch over the NodeType.

For now, visitors with subclasses still have virtual methods themselves. We should probably specialize them later as well.

The uint8_t NodeType allows us to better pack memory, saving 8-16 bytes on many AST nodes (with additional packing that I'll do in a follow-up CL)

BUG=

Review-Url: https://codereview.chromium.org/2142233003
Cr-Commit-Position: refs/heads/master@{#37788}
parent d4341d1f
This diff is collapsed.
...@@ -17,19 +17,21 @@ namespace internal { ...@@ -17,19 +17,21 @@ namespace internal {
// A rewriting Visitor over a CompilationInfo's AST that invokes // A rewriting Visitor over a CompilationInfo's AST that invokes
// VisitExpression on each expression node. // VisitExpression on each expression node.
class AstExpressionRewriter : public AstVisitor { // This AstVistor is not final, and provides the AstVisitor methods as virtual
// methods so they can be specialized by subclasses.
class AstExpressionRewriter : public AstVisitor<AstExpressionRewriter> {
public: public:
explicit AstExpressionRewriter(Isolate* isolate) : AstVisitor() { explicit AstExpressionRewriter(Isolate* isolate) {
InitializeAstRewriter(isolate); InitializeAstRewriter(isolate);
} }
explicit AstExpressionRewriter(uintptr_t stack_limit) : AstVisitor() { explicit AstExpressionRewriter(uintptr_t stack_limit) {
InitializeAstRewriter(stack_limit); InitializeAstRewriter(stack_limit);
} }
~AstExpressionRewriter() override {} virtual ~AstExpressionRewriter() {}
void VisitDeclarations(ZoneList<Declaration*>* declarations) override; virtual void VisitDeclarations(ZoneList<Declaration*>* declarations);
void VisitStatements(ZoneList<Statement*>* statements) override; virtual void VisitStatements(ZoneList<Statement*>* statements);
void VisitExpressions(ZoneList<Expression*>* expressions) override; virtual void VisitExpressions(ZoneList<Expression*>* expressions);
virtual void VisitObjectLiteralProperty(ObjectLiteralProperty* property); virtual void VisitObjectLiteralProperty(ObjectLiteralProperty* property);
...@@ -39,7 +41,7 @@ class AstExpressionRewriter : public AstVisitor { ...@@ -39,7 +41,7 @@ class AstExpressionRewriter : public AstVisitor {
private: private:
DEFINE_AST_REWRITER_SUBCLASS_MEMBERS(); DEFINE_AST_REWRITER_SUBCLASS_MEMBERS();
#define DECLARE_VISIT(type) void Visit##type(type* node) override; #define DECLARE_VISIT(type) virtual void Visit##type(type* node);
AST_NODE_LIST(DECLARE_VISIT) AST_NODE_LIST(DECLARE_VISIT)
#undef DECLARE_VISIT #undef DECLARE_VISIT
......
...@@ -321,9 +321,6 @@ void AstLiteralReindexer::VisitFunctionLiteral(FunctionLiteral* node) { ...@@ -321,9 +321,6 @@ void AstLiteralReindexer::VisitFunctionLiteral(FunctionLiteral* node) {
// We don't recurse into the declarations or body of the function literal: // We don't recurse into the declarations or body of the function literal:
} }
void AstLiteralReindexer::Reindex(Expression* pattern) { Visit(pattern); }
void AstLiteralReindexer::Reindex(Expression* pattern) {
pattern->Accept(this);
}
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -11,20 +11,20 @@ ...@@ -11,20 +11,20 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
class AstLiteralReindexer final : public AstVisitor { class AstLiteralReindexer final : public AstVisitor<AstLiteralReindexer> {
public: public:
AstLiteralReindexer() : AstVisitor(), next_index_(0) {} AstLiteralReindexer() : next_index_(0) {}
int count() const { return next_index_; } int count() const { return next_index_; }
void Reindex(Expression* pattern); void Reindex(Expression* pattern);
private: private:
#define DEFINE_VISIT(type) void Visit##type(type* node) override; #define DEFINE_VISIT(type) void Visit##type(type* node);
AST_NODE_LIST(DEFINE_VISIT) AST_NODE_LIST(DEFINE_VISIT)
#undef DEFINE_VISIT #undef DEFINE_VISIT
void VisitStatements(ZoneList<Statement*>* statements) override; void VisitStatements(ZoneList<Statement*>* statements);
void VisitDeclarations(ZoneList<Declaration*>* declarations) override; void VisitDeclarations(ZoneList<Declaration*>* declarations);
void VisitArguments(ZoneList<Expression*>* arguments); void VisitArguments(ZoneList<Expression*>* arguments);
void VisitObjectLiteralProperty(ObjectLiteralProperty* property); void VisitObjectLiteralProperty(ObjectLiteralProperty* property);
...@@ -32,10 +32,9 @@ class AstLiteralReindexer final : public AstVisitor { ...@@ -32,10 +32,9 @@ class AstLiteralReindexer final : public AstVisitor {
literal->literal_index_ = next_index_++; literal->literal_index_ = next_index_++;
} }
void Visit(AstNode* node) override { node->Accept(this); }
int next_index_; int next_index_;
DEFINE_AST_VISITOR_MEMBERS_WITHOUT_STACKOVERFLOW()
DISALLOW_COPY_AND_ASSIGN(AstLiteralReindexer); DISALLOW_COPY_AND_ASSIGN(AstLiteralReindexer);
}; };
} // namespace internal } // namespace internal
......
...@@ -10,11 +10,10 @@ ...@@ -10,11 +10,10 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
class AstNumberingVisitor final : public AstVisitor { class AstNumberingVisitor final : public AstVisitor<AstNumberingVisitor> {
public: public:
AstNumberingVisitor(Isolate* isolate, Zone* zone) AstNumberingVisitor(Isolate* isolate, Zone* zone)
: AstVisitor(), : isolate_(isolate),
isolate_(isolate),
zone_(zone), zone_(zone),
next_id_(BailoutId::FirstUsable().ToInt()), next_id_(BailoutId::FirstUsable().ToInt()),
yield_count_(0), yield_count_(0),
...@@ -29,7 +28,7 @@ class AstNumberingVisitor final : public AstVisitor { ...@@ -29,7 +28,7 @@ class AstNumberingVisitor final : public AstVisitor {
private: private:
// AST node visitor interface. // AST node visitor interface.
#define DEFINE_VISIT(type) void Visit##type(type* node) override; #define DEFINE_VISIT(type) void Visit##type(type* node);
AST_NODE_LIST(DEFINE_VISIT) AST_NODE_LIST(DEFINE_VISIT)
#undef DEFINE_VISIT #undef DEFINE_VISIT
...@@ -37,8 +36,8 @@ class AstNumberingVisitor final : public AstVisitor { ...@@ -37,8 +36,8 @@ class AstNumberingVisitor final : public AstVisitor {
void VisitPropertyReference(Property* node); void VisitPropertyReference(Property* node);
void VisitReference(Expression* expr); void VisitReference(Expression* expr);
void VisitStatements(ZoneList<Statement*>* statements) override; void VisitStatements(ZoneList<Statement*>* statements);
void VisitDeclarations(ZoneList<Declaration*>* declarations) override; void VisitDeclarations(ZoneList<Declaration*>* declarations);
void VisitArguments(ZoneList<Expression*>* arguments); void VisitArguments(ZoneList<Expression*>* arguments);
void VisitObjectLiteralProperty(ObjectLiteralProperty* property); void VisitObjectLiteralProperty(ObjectLiteralProperty* property);
......
...@@ -22,15 +22,6 @@ ...@@ -22,15 +22,6 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
// ----------------------------------------------------------------------------
// All the Accept member functions for each syntax tree node type.
#define DECL_ACCEPT(type) \
void type::Accept(AstVisitor* v) { v->Visit##type(this); }
AST_NODE_LIST(DECL_ACCEPT)
#undef DECL_ACCEPT
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Implementation of other node functionality. // Implementation of other node functionality.
...@@ -182,7 +173,7 @@ bool Statement::IsJump() const { ...@@ -182,7 +173,7 @@ bool Statement::IsJump() const {
VariableProxy::VariableProxy(Zone* zone, Variable* var, int start_position, VariableProxy::VariableProxy(Zone* zone, Variable* var, int start_position,
int end_position) int end_position)
: Expression(zone, start_position), : Expression(zone, start_position, kVariableProxy),
bit_field_(IsThisField::encode(var->is_this()) | bit_field_(IsThisField::encode(var->is_this()) |
IsAssignedField::encode(false) | IsAssignedField::encode(false) |
IsResolvedField::encode(false)), IsResolvedField::encode(false)),
...@@ -191,18 +182,16 @@ VariableProxy::VariableProxy(Zone* zone, Variable* var, int start_position, ...@@ -191,18 +182,16 @@ VariableProxy::VariableProxy(Zone* zone, Variable* var, int start_position,
BindTo(var); BindTo(var);
} }
VariableProxy::VariableProxy(Zone* zone, const AstRawString* name, VariableProxy::VariableProxy(Zone* zone, const AstRawString* name,
Variable::Kind variable_kind, int start_position, Variable::Kind variable_kind, int start_position,
int end_position) int end_position)
: Expression(zone, start_position), : Expression(zone, start_position, kVariableProxy),
bit_field_(IsThisField::encode(variable_kind == Variable::THIS) | bit_field_(IsThisField::encode(variable_kind == Variable::THIS) |
IsAssignedField::encode(false) | IsAssignedField::encode(false) |
IsResolvedField::encode(false)), IsResolvedField::encode(false)),
raw_name_(name), raw_name_(name),
end_position_(end_position) {} end_position_(end_position) {}
void VariableProxy::BindTo(Variable* var) { void VariableProxy::BindTo(Variable* var) {
DCHECK((is_this() && var->is_this()) || raw_name() == var->raw_name()); DCHECK((is_this() && var->is_this()) || raw_name() == var->raw_name());
set_var(var); set_var(var);
...@@ -255,10 +244,9 @@ void ForInStatement::AssignFeedbackVectorSlots(Isolate* isolate, ...@@ -255,10 +244,9 @@ void ForInStatement::AssignFeedbackVectorSlots(Isolate* isolate,
for_in_feedback_slot_ = spec->AddGeneralSlot(); for_in_feedback_slot_ = spec->AddGeneralSlot();
} }
Assignment::Assignment(Zone* zone, Token::Value op, Expression* target, Assignment::Assignment(Zone* zone, Token::Value op, Expression* target,
Expression* value, int pos) Expression* value, int pos)
: Expression(zone, pos), : Expression(zone, pos, kAssignment),
bit_field_( bit_field_(
IsUninitializedField::encode(false) | KeyTypeField::encode(ELEMENT) | IsUninitializedField::encode(false) | KeyTypeField::encode(ELEMENT) |
StoreModeField::encode(STANDARD_STORE) | TokenField::encode(op)), StoreModeField::encode(STANDARD_STORE) | TokenField::encode(op)),
...@@ -266,7 +254,6 @@ Assignment::Assignment(Zone* zone, Token::Value op, Expression* target, ...@@ -266,7 +254,6 @@ Assignment::Assignment(Zone* zone, Token::Value op, Expression* target,
value_(value), value_(value),
binary_operation_(NULL) {} binary_operation_(NULL) {}
void Assignment::AssignFeedbackVectorSlots(Isolate* isolate, void Assignment::AssignFeedbackVectorSlots(Isolate* isolate,
FeedbackVectorSpec* spec, FeedbackVectorSpec* spec,
FeedbackVectorSlotCache* cache) { FeedbackVectorSlotCache* cache) {
...@@ -930,36 +917,6 @@ Call::CallType Call::GetCallType(Isolate* isolate) const { ...@@ -930,36 +917,6 @@ Call::CallType Call::GetCallType(Isolate* isolate) const {
} }
// ----------------------------------------------------------------------------
// Implementation of AstVisitor
void AstVisitor::VisitDeclarations(ZoneList<Declaration*>* declarations) {
for (int i = 0; i < declarations->length(); i++) {
Visit(declarations->at(i));
}
}
void AstVisitor::VisitStatements(ZoneList<Statement*>* statements) {
for (int i = 0; i < statements->length(); i++) {
Statement* stmt = statements->at(i);
Visit(stmt);
if (stmt->IsJump()) break;
}
}
void AstVisitor::VisitExpressions(ZoneList<Expression*>* expressions) {
for (int i = 0; i < expressions->length(); i++) {
// The variable statement visiting code may pass NULL expressions
// to this code. Maybe this should be handled by introducing an
// undefined expression or literal? Revisit this code if this
// changes
Expression* expression = expressions->at(i);
if (expression != NULL) Visit(expression);
}
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Implementation of AstTraversalVisitor // Implementation of AstTraversalVisitor
...@@ -1263,7 +1220,7 @@ void AstTraversalVisitor::VisitRewritableExpression( ...@@ -1263,7 +1220,7 @@ void AstTraversalVisitor::VisitRewritableExpression(
CaseClause::CaseClause(Zone* zone, Expression* label, CaseClause::CaseClause(Zone* zone, Expression* label,
ZoneList<Statement*>* statements, int pos) ZoneList<Statement*>* statements, int pos)
: Expression(zone, pos), : Expression(zone, pos, kCaseClause),
label_(label), label_(label),
statements_(statements), statements_(statements),
compare_type_(Type::None()) {} compare_type_(Type::None()) {}
......
This diff is collapsed.
...@@ -12,10 +12,10 @@ ...@@ -12,10 +12,10 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
class CallPrinter : public AstVisitor { class CallPrinter final : public AstVisitor<CallPrinter> {
public: public:
explicit CallPrinter(Isolate* isolate, bool is_builtin); explicit CallPrinter(Isolate* isolate, bool is_builtin);
virtual ~CallPrinter(); ~CallPrinter();
// The following routine prints the node with position |position| into a // The following routine prints the node with position |position| into a
// string. The result string is alive as long as the CallPrinter is alive. // string. The result string is alive as long as the CallPrinter is alive.
...@@ -26,7 +26,7 @@ class CallPrinter : public AstVisitor { ...@@ -26,7 +26,7 @@ class CallPrinter : public AstVisitor {
void Find(AstNode* node, bool print = false); void Find(AstNode* node, bool print = false);
// Individual nodes // Individual nodes
#define DECLARE_VISIT(type) void Visit##type(type* node) override; #define DECLARE_VISIT(type) void Visit##type(type* node);
AST_NODE_LIST(DECLARE_VISIT) AST_NODE_LIST(DECLARE_VISIT)
#undef DECLARE_VISIT #undef DECLARE_VISIT
...@@ -53,14 +53,13 @@ class CallPrinter : public AstVisitor { ...@@ -53,14 +53,13 @@ class CallPrinter : public AstVisitor {
#ifdef DEBUG #ifdef DEBUG
// Prints the AST structure class AstPrinter final : public AstVisitor<AstPrinter> {
class AstPrinter : public AstVisitor {
public: public:
explicit AstPrinter(Isolate* isolate); explicit AstPrinter(Isolate* isolate);
virtual ~AstPrinter(); ~AstPrinter();
// The following routines print a node into a string. // The following routines print a node into a string.
// The result string is alive as long as the PrettyPrinter is alive. // The result string is alive as long as the AstPrinter is alive.
const char* Print(AstNode* node); const char* Print(AstNode* node);
const char* PrintProgram(FunctionLiteral* program); const char* PrintProgram(FunctionLiteral* program);
...@@ -70,7 +69,7 @@ class AstPrinter : public AstVisitor { ...@@ -70,7 +69,7 @@ class AstPrinter : public AstVisitor {
static void PrintOut(Isolate* isolate, AstNode* node); static void PrintOut(Isolate* isolate, AstNode* node);
// Individual nodes // Individual nodes
#define DECLARE_VISIT(type) void Visit##type(type* node) override; #define DECLARE_VISIT(type) void Visit##type(type* node);
AST_NODE_LIST(DECLARE_VISIT) AST_NODE_LIST(DECLARE_VISIT)
#undef DECLARE_VISIT #undef DECLARE_VISIT
......
...@@ -1112,7 +1112,7 @@ void AstGraphBuilder::VisitForValues(ZoneList<Expression*>* exprs) { ...@@ -1112,7 +1112,7 @@ void AstGraphBuilder::VisitForValues(ZoneList<Expression*>* exprs) {
void AstGraphBuilder::VisitForValue(Expression* expr) { void AstGraphBuilder::VisitForValue(Expression* expr) {
AstValueContext for_value(this); AstValueContext for_value(this);
if (!CheckStackOverflow()) { if (!CheckStackOverflow()) {
expr->Accept(this); AstVisitor<AstGraphBuilder>::Visit(expr);
} else { } else {
ast_context()->ProduceValue(expr, jsgraph()->UndefinedConstant()); ast_context()->ProduceValue(expr, jsgraph()->UndefinedConstant());
} }
...@@ -1122,7 +1122,7 @@ void AstGraphBuilder::VisitForValue(Expression* expr) { ...@@ -1122,7 +1122,7 @@ void AstGraphBuilder::VisitForValue(Expression* expr) {
void AstGraphBuilder::VisitForEffect(Expression* expr) { void AstGraphBuilder::VisitForEffect(Expression* expr) {
AstEffectContext for_effect(this); AstEffectContext for_effect(this);
if (!CheckStackOverflow()) { if (!CheckStackOverflow()) {
expr->Accept(this); AstVisitor<AstGraphBuilder>::Visit(expr);
} else { } else {
ast_context()->ProduceValue(expr, jsgraph()->UndefinedConstant()); ast_context()->ProduceValue(expr, jsgraph()->UndefinedConstant());
} }
...@@ -1132,7 +1132,7 @@ void AstGraphBuilder::VisitForEffect(Expression* expr) { ...@@ -1132,7 +1132,7 @@ void AstGraphBuilder::VisitForEffect(Expression* expr) {
void AstGraphBuilder::VisitForTest(Expression* expr) { void AstGraphBuilder::VisitForTest(Expression* expr) {
AstTestContext for_condition(this, expr->test_id()); AstTestContext for_condition(this, expr->test_id());
if (!CheckStackOverflow()) { if (!CheckStackOverflow()) {
expr->Accept(this); AstVisitor<AstGraphBuilder>::Visit(expr);
} else { } else {
ast_context()->ProduceValue(expr, jsgraph()->UndefinedConstant()); ast_context()->ProduceValue(expr, jsgraph()->UndefinedConstant());
} }
...@@ -1142,7 +1142,7 @@ void AstGraphBuilder::VisitForTest(Expression* expr) { ...@@ -1142,7 +1142,7 @@ void AstGraphBuilder::VisitForTest(Expression* expr) {
void AstGraphBuilder::Visit(Expression* expr) { void AstGraphBuilder::Visit(Expression* expr) {
// Reuses enclosing AstContext. // Reuses enclosing AstContext.
if (!CheckStackOverflow()) { if (!CheckStackOverflow()) {
expr->Accept(this); AstVisitor<AstGraphBuilder>::Visit(expr);
} else { } else {
ast_context()->ProduceValue(expr, jsgraph()->UndefinedConstant()); ast_context()->ProduceValue(expr, jsgraph()->UndefinedConstant());
} }
...@@ -2982,7 +2982,7 @@ void AstGraphBuilder::VisitCaseClause(CaseClause* expr) { ...@@ -2982,7 +2982,7 @@ void AstGraphBuilder::VisitCaseClause(CaseClause* expr) {
void AstGraphBuilder::VisitDeclarations(ZoneList<Declaration*>* declarations) { void AstGraphBuilder::VisitDeclarations(ZoneList<Declaration*>* declarations) {
DCHECK(globals()->empty()); DCHECK(globals()->empty());
AstVisitor::VisitDeclarations(declarations); AstVisitor<AstGraphBuilder>::VisitDeclarations(declarations);
if (globals()->empty()) return; if (globals()->empty()) return;
int array_index = 0; int array_index = 0;
Handle<TypeFeedbackVector> feedback_vector( Handle<TypeFeedbackVector> feedback_vector(
......
...@@ -32,11 +32,14 @@ class TypeHintAnalysis; ...@@ -32,11 +32,14 @@ class TypeHintAnalysis;
// underlying AST. The produced graph can either be compiled into a // underlying AST. The produced graph can either be compiled into a
// stand-alone function or be wired into another graph for the purposes // stand-alone function or be wired into another graph for the purposes
// of function inlining. // of function inlining.
class AstGraphBuilder : public AstVisitor { // This AstVistor is not final, and provides the AstVisitor methods as virtual
// methods so they can be specialized by subclasses.
class AstGraphBuilder : public AstVisitor<AstGraphBuilder> {
public: public:
AstGraphBuilder(Zone* local_zone, CompilationInfo* info, JSGraph* jsgraph, AstGraphBuilder(Zone* local_zone, CompilationInfo* info, JSGraph* jsgraph,
LoopAssignmentAnalysis* loop_assignment = nullptr, LoopAssignmentAnalysis* loop_assignment = nullptr,
TypeHintAnalysis* type_hint_analysis = nullptr); TypeHintAnalysis* type_hint_analysis = nullptr);
virtual ~AstGraphBuilder() {}
// Creates a graph by visiting the entire AST. // Creates a graph by visiting the entire AST.
bool CreateGraph(bool stack_check = true); bool CreateGraph(bool stack_check = true);
...@@ -51,13 +54,13 @@ class AstGraphBuilder : public AstVisitor { ...@@ -51,13 +54,13 @@ class AstGraphBuilder : public AstVisitor {
} }
protected: protected:
#define DECLARE_VISIT(type) void Visit##type(type* node) override; #define DECLARE_VISIT(type) virtual void Visit##type(type* node);
// Visiting functions for AST nodes make this an AstVisitor. // Visiting functions for AST nodes make this an AstVisitor.
AST_NODE_LIST(DECLARE_VISIT) AST_NODE_LIST(DECLARE_VISIT)
#undef DECLARE_VISIT #undef DECLARE_VISIT
// Visiting function for declarations list is overridden. // Visiting function for declarations list is overridden.
void VisitDeclarations(ZoneList<Declaration*>* declarations) override; void VisitDeclarations(ZoneList<Declaration*>* declarations);
private: private:
class AstContext; class AstContext;
......
...@@ -40,13 +40,14 @@ class LoopAssignmentAnalysis : public ZoneObject { ...@@ -40,13 +40,14 @@ class LoopAssignmentAnalysis : public ZoneObject {
// The class that performs loop assignment analysis by walking the AST. // The class that performs loop assignment analysis by walking the AST.
class AstLoopAssignmentAnalyzer : public AstVisitor { class AstLoopAssignmentAnalyzer final
: public AstVisitor<AstLoopAssignmentAnalyzer> {
public: public:
AstLoopAssignmentAnalyzer(Zone* zone, CompilationInfo* info); AstLoopAssignmentAnalyzer(Zone* zone, CompilationInfo* info);
LoopAssignmentAnalysis* Analyze(); LoopAssignmentAnalysis* Analyze();
#define DECLARE_VISIT(type) void Visit##type(type* node) override; #define DECLARE_VISIT(type) void Visit##type(type* node);
AST_NODE_LIST(DECLARE_VISIT) AST_NODE_LIST(DECLARE_VISIT)
#undef DECLARE_VISIT #undef DECLARE_VISIT
......
...@@ -12141,7 +12141,7 @@ void HOptimizedGraphBuilder::VisitSuperCallReference(SuperCallReference* expr) { ...@@ -12141,7 +12141,7 @@ void HOptimizedGraphBuilder::VisitSuperCallReference(SuperCallReference* expr) {
void HOptimizedGraphBuilder::VisitDeclarations( void HOptimizedGraphBuilder::VisitDeclarations(
ZoneList<Declaration*>* declarations) { ZoneList<Declaration*>* declarations) {
DCHECK(globals_.is_empty()); DCHECK(globals_.is_empty());
AstVisitor::VisitDeclarations(declarations); AstVisitor<HOptimizedGraphBuilder>::VisitDeclarations(declarations);
if (!globals_.is_empty()) { if (!globals_.is_empty()) {
Handle<FixedArray> array = Handle<FixedArray> array =
isolate()->factory()->NewFixedArray(globals_.length(), TENURED); isolate()->factory()->NewFixedArray(globals_.length(), TENURED);
......
...@@ -2062,8 +2062,10 @@ inline HContext* HGraphBuilder::New<HContext>() { ...@@ -2062,8 +2062,10 @@ inline HContext* HGraphBuilder::New<HContext>() {
return HContext::New(zone()); return HContext::New(zone());
} }
// This AstVistor is not final, and provides the AstVisitor methods as virtual
class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor { // methods so they can be specialized by subclasses.
class HOptimizedGraphBuilder : public HGraphBuilder,
public AstVisitor<HOptimizedGraphBuilder> {
public: public:
// A class encapsulating (lazily-allocated) break and continue blocks for // A class encapsulating (lazily-allocated) break and continue blocks for
// a breakable statement. Separated from BreakAndContinueScope so that it // a breakable statement. Separated from BreakAndContinueScope so that it
...@@ -2143,7 +2145,7 @@ class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor { ...@@ -2143,7 +2145,7 @@ class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor {
FunctionState* function_state() const { return function_state_; } FunctionState* function_state() const { return function_state_; }
void VisitDeclarations(ZoneList<Declaration*>* declarations) override; void VisitDeclarations(ZoneList<Declaration*>* declarations);
AstTypeBounds* bounds() { return &bounds_; } AstTypeBounds* bounds() { return &bounds_; }
...@@ -2351,7 +2353,7 @@ class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor { ...@@ -2351,7 +2353,7 @@ class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor {
HBasicBlock* false_block); HBasicBlock* false_block);
// Visit a list of expressions from left to right, each in a value context. // Visit a list of expressions from left to right, each in a value context.
void VisitExpressions(ZoneList<Expression*>* exprs) override; void VisitExpressions(ZoneList<Expression*>* exprs);
void VisitExpressions(ZoneList<Expression*>* exprs, void VisitExpressions(ZoneList<Expression*>* exprs,
ArgumentsAllowedFlag flag); ArgumentsAllowedFlag flag);
...@@ -2361,9 +2363,9 @@ class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor { ...@@ -2361,9 +2363,9 @@ class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor {
void PushArgumentsFromEnvironment(int count); void PushArgumentsFromEnvironment(int count);
void SetUpScope(Scope* scope); void SetUpScope(Scope* scope);
void VisitStatements(ZoneList<Statement*>* statements) override; void VisitStatements(ZoneList<Statement*>* statements);
#define DECLARE_VISIT(type) void Visit##type(type* node) override; #define DECLARE_VISIT(type) virtual void Visit##type(type* node);
AST_NODE_LIST(DECLARE_VISIT) AST_NODE_LIST(DECLARE_VISIT)
#undef DECLARE_VISIT #undef DECLARE_VISIT
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
class AstTyper: public AstVisitor { class AstTyper final : public AstVisitor<AstTyper> {
public: public:
AstTyper(Isolate* isolate, Zone* zone, Handle<JSFunction> closure, AstTyper(Isolate* isolate, Zone* zone, Handle<JSFunction> closure,
Scope* scope, BailoutId osr_ast_id, FunctionLiteral* root, Scope* scope, BailoutId osr_ast_id, FunctionLiteral* root,
...@@ -71,10 +71,10 @@ class AstTyper: public AstVisitor { ...@@ -71,10 +71,10 @@ class AstTyper: public AstVisitor {
var->IsParameter() ? parameter_index(var->index()) : kNoVar; var->IsParameter() ? parameter_index(var->index()) : kNoVar;
} }
void VisitDeclarations(ZoneList<Declaration*>* declarations) override; void VisitDeclarations(ZoneList<Declaration*>* declarations);
void VisitStatements(ZoneList<Statement*>* statements) override; void VisitStatements(ZoneList<Statement*>* statements);
#define DECLARE_VISIT(type) void Visit##type(type* node) override; #define DECLARE_VISIT(type) void Visit##type(type* node);
AST_NODE_LIST(DECLARE_VISIT) AST_NODE_LIST(DECLARE_VISIT)
#undef DECLARE_VISIT #undef DECLARE_VISIT
......
...@@ -390,7 +390,7 @@ void FullCodeGenerator::VisitDeclarations( ...@@ -390,7 +390,7 @@ void FullCodeGenerator::VisitDeclarations(
ZoneList<Handle<Object> > inner_globals(10, zone()); ZoneList<Handle<Object> > inner_globals(10, zone());
globals_ = &inner_globals; globals_ = &inner_globals;
AstVisitor::VisitDeclarations(declarations); AstVisitor<FullCodeGenerator>::VisitDeclarations(declarations);
if (!globals_->is_empty()) { if (!globals_->is_empty()) {
// Invoke the platform-dependent code generator to do the actual // Invoke the platform-dependent code generator to do the actual
......
...@@ -27,7 +27,7 @@ class JumpPatchSite; ...@@ -27,7 +27,7 @@ class JumpPatchSite;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Full code generator. // Full code generator.
class FullCodeGenerator: public AstVisitor { class FullCodeGenerator final : public AstVisitor<FullCodeGenerator> {
public: public:
FullCodeGenerator(MacroAssembler* masm, CompilationInfo* info) FullCodeGenerator(MacroAssembler* masm, CompilationInfo* info)
: masm_(masm), : masm_(masm),
...@@ -387,7 +387,7 @@ class FullCodeGenerator: public AstVisitor { ...@@ -387,7 +387,7 @@ class FullCodeGenerator: public AstVisitor {
void VisitInDuplicateContext(Expression* expr); void VisitInDuplicateContext(Expression* expr);
void VisitDeclarations(ZoneList<Declaration*>* declarations) override; void VisitDeclarations(ZoneList<Declaration*>* declarations);
void DeclareGlobals(Handle<FixedArray> pairs); void DeclareGlobals(Handle<FixedArray> pairs);
int DeclareGlobalsFlags(); int DeclareGlobalsFlags();
...@@ -737,7 +737,7 @@ class FullCodeGenerator: public AstVisitor { ...@@ -737,7 +737,7 @@ class FullCodeGenerator: public AstVisitor {
void PushCalleeAndWithBaseObject(Call* expr); void PushCalleeAndWithBaseObject(Call* expr);
// AST node visit functions. // AST node visit functions.
#define DECLARE_VISIT(type) void Visit##type(type* node) override; #define DECLARE_VISIT(type) void Visit##type(type* node);
AST_NODE_LIST(DECLARE_VISIT) AST_NODE_LIST(DECLARE_VISIT)
#undef DECLARE_VISIT #undef DECLARE_VISIT
......
...@@ -19,19 +19,19 @@ namespace interpreter { ...@@ -19,19 +19,19 @@ namespace interpreter {
class LoopBuilder; class LoopBuilder;
class BytecodeGenerator final : public AstVisitor { class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> {
public: public:
explicit BytecodeGenerator(CompilationInfo* info); explicit BytecodeGenerator(CompilationInfo* info);
Handle<BytecodeArray> MakeBytecode(); Handle<BytecodeArray> MakeBytecode();
#define DECLARE_VISIT(type) void Visit##type(type* node) override; #define DECLARE_VISIT(type) void Visit##type(type* node);
AST_NODE_LIST(DECLARE_VISIT) AST_NODE_LIST(DECLARE_VISIT)
#undef DECLARE_VISIT #undef DECLARE_VISIT
// Visiting function for declarations list and statements are overridden. // Visiting function for declarations list and statements are overridden.
void VisitDeclarations(ZoneList<Declaration*>* declarations) override; void VisitDeclarations(ZoneList<Declaration*>* declarations);
void VisitStatements(ZoneList<Statement*>* statments) override; void VisitStatements(ZoneList<Statement*>* statments);
private: private:
class ContextScope; class ContextScope;
......
...@@ -3062,7 +3062,7 @@ ParserBase<Traits>::ParseSuperExpression(bool is_new, ...@@ -3062,7 +3062,7 @@ ParserBase<Traits>::ParseSuperExpression(bool is_new,
IsClassConstructor(kind)) { IsClassConstructor(kind)) {
if (peek() == Token::PERIOD || peek() == Token::LBRACK) { if (peek() == Token::PERIOD || peek() == Token::LBRACK) {
scope->RecordSuperPropertyUsage(); scope->RecordSuperPropertyUsage();
return this->SuperPropertyReference(scope_, factory(), pos); return this->NewSuperPropertyReference(scope_, factory(), pos);
} }
// new super() is never allowed. // new super() is never allowed.
// super() is only allowed in derived constructor // super() is only allowed in derived constructor
...@@ -3070,7 +3070,7 @@ ParserBase<Traits>::ParseSuperExpression(bool is_new, ...@@ -3070,7 +3070,7 @@ ParserBase<Traits>::ParseSuperExpression(bool is_new,
// TODO(rossberg): This might not be the correct FunctionState for the // TODO(rossberg): This might not be the correct FunctionState for the
// method here. // method here.
function_state_->set_super_location(scanner()->location()); function_state_->set_super_location(scanner()->location());
return this->SuperCallReference(scope_, factory(), pos); return this->NewSuperCallReference(scope_, factory(), pos);
} }
} }
......
...@@ -634,8 +634,7 @@ Expression* ParserTraits::ThisExpression(Scope* scope, AstNodeFactory* factory, ...@@ -634,8 +634,7 @@ Expression* ParserTraits::ThisExpression(Scope* scope, AstNodeFactory* factory,
Variable::THIS, pos, pos + 4); Variable::THIS, pos, pos + 4);
} }
Expression* ParserTraits::NewSuperPropertyReference(Scope* scope,
Expression* ParserTraits::SuperPropertyReference(Scope* scope,
AstNodeFactory* factory, AstNodeFactory* factory,
int pos) { int pos) {
// this_function[home_object_symbol] // this_function[home_object_symbol]
...@@ -650,9 +649,9 @@ Expression* ParserTraits::SuperPropertyReference(Scope* scope, ...@@ -650,9 +649,9 @@ Expression* ParserTraits::SuperPropertyReference(Scope* scope,
ThisExpression(scope, factory, pos)->AsVariableProxy(), home_object, pos); ThisExpression(scope, factory, pos)->AsVariableProxy(), home_object, pos);
} }
Expression* ParserTraits::NewSuperCallReference(Scope* scope,
Expression* ParserTraits::SuperCallReference(Scope* scope, AstNodeFactory* factory,
AstNodeFactory* factory, int pos) { int pos) {
VariableProxy* new_target_proxy = scope->NewUnresolved( VariableProxy* new_target_proxy = scope->NewUnresolved(
factory, parser_->ast_value_factory()->new_target_string(), factory, parser_->ast_value_factory()->new_target_string(),
Variable::NORMAL, pos); Variable::NORMAL, pos);
......
...@@ -507,9 +507,9 @@ class ParserTraits { ...@@ -507,9 +507,9 @@ class ParserTraits {
Expression* ThisExpression(Scope* scope, AstNodeFactory* factory, Expression* ThisExpression(Scope* scope, AstNodeFactory* factory,
int pos = kNoSourcePosition); int pos = kNoSourcePosition);
Expression* SuperPropertyReference(Scope* scope, AstNodeFactory* factory, Expression* NewSuperPropertyReference(Scope* scope, AstNodeFactory* factory,
int pos); int pos);
Expression* SuperCallReference(Scope* scope, AstNodeFactory* factory, Expression* NewSuperCallReference(Scope* scope, AstNodeFactory* factory,
int pos); int pos);
Expression* NewTargetExpression(Scope* scope, AstNodeFactory* factory, Expression* NewTargetExpression(Scope* scope, AstNodeFactory* factory,
int pos); int pos);
...@@ -840,7 +840,7 @@ class Parser : public ParserBase<ParserTraits> { ...@@ -840,7 +840,7 @@ class Parser : public ParserBase<ParserTraits> {
Scanner::Location bindings_loc; Scanner::Location bindings_loc;
}; };
class PatternRewriter : private AstVisitor { class PatternRewriter final : private AstVisitor<PatternRewriter> {
public: public:
static void DeclareAndInitializeVariables( static void DeclareAndInitializeVariables(
Block* block, const DeclarationDescriptor* declaration_descriptor, Block* block, const DeclarationDescriptor* declaration_descriptor,
...@@ -858,11 +858,10 @@ class Parser : public ParserBase<ParserTraits> { ...@@ -858,11 +858,10 @@ class Parser : public ParserBase<ParserTraits> {
private: private:
PatternRewriter() {} PatternRewriter() {}
#define DECLARE_VISIT(type) void Visit##type(v8::internal::type* node) override; #define DECLARE_VISIT(type) void Visit##type(v8::internal::type* node);
// Visiting functions for AST nodes make this an AstVisitor. // Visiting functions for AST nodes make this an AstVisitor.
AST_NODE_LIST(DECLARE_VISIT) AST_NODE_LIST(DECLARE_VISIT)
#undef DECLARE_VISIT #undef DECLARE_VISIT
void Visit(AstNode* node) override;
enum PatternContext { enum PatternContext {
BINDING, BINDING,
...@@ -878,7 +877,7 @@ class Parser : public ParserBase<ParserTraits> { ...@@ -878,7 +877,7 @@ class Parser : public ParserBase<ParserTraits> {
Expression* old_value = current_value_; Expression* old_value = current_value_;
current_value_ = value; current_value_ = value;
recursion_level_++; recursion_level_++;
pattern->Accept(this); Visit(pattern);
recursion_level_--; recursion_level_--;
current_value_ = old_value; current_value_ = old_value;
} }
...@@ -917,6 +916,8 @@ class Parser : public ParserBase<ParserTraits> { ...@@ -917,6 +916,8 @@ class Parser : public ParserBase<ParserTraits> {
Expression* current_value_; Expression* current_value_;
int recursion_level_; int recursion_level_;
bool* ok_; bool* ok_;
DEFINE_AST_VISITOR_MEMBERS_WITHOUT_STACKOVERFLOW()
}; };
Block* ParseVariableDeclarations(VariableDeclarationContext var_context, Block* ParseVariableDeclarations(VariableDeclarationContext var_context,
......
...@@ -328,7 +328,7 @@ void Parser::PatternRewriter::VisitRewritableExpression( ...@@ -328,7 +328,7 @@ void Parser::PatternRewriter::VisitRewritableExpression(
// perform BindingPattern rewriting // perform BindingPattern rewriting
DCHECK(!node->is_rewritten()); DCHECK(!node->is_rewritten());
node->Rewrite(node->expression()); node->Rewrite(node->expression());
return node->expression()->Accept(this); return Visit(node->expression());
} }
if (node->is_rewritten()) return; if (node->is_rewritten()) return;
...@@ -730,8 +730,6 @@ void Parser::PatternRewriter::VisitProperty(v8::internal::Property* node) { ...@@ -730,8 +730,6 @@ void Parser::PatternRewriter::VisitProperty(v8::internal::Property* node) {
// =============== UNREACHABLE ============================= // =============== UNREACHABLE =============================
void Parser::PatternRewriter::Visit(AstNode* node) { UNREACHABLE(); }
#define NOT_A_PATTERN(Node) \ #define NOT_A_PATTERN(Node) \
void Parser::PatternRewriter::Visit##Node(v8::internal::Node*) { \ void Parser::PatternRewriter::Visit##Node(v8::internal::Node*) { \
UNREACHABLE(); \ UNREACHABLE(); \
......
...@@ -802,13 +802,12 @@ class PreParserTraits { ...@@ -802,13 +802,12 @@ class PreParserTraits {
return PreParserExpression::This(); return PreParserExpression::This();
} }
static PreParserExpression SuperPropertyReference(Scope* scope, static PreParserExpression NewSuperPropertyReference(
PreParserFactory* factory, Scope* scope, PreParserFactory* factory, int pos) {
int pos) {
return PreParserExpression::Default(); return PreParserExpression::Default();
} }
static PreParserExpression SuperCallReference(Scope* scope, static PreParserExpression NewSuperCallReference(Scope* scope,
PreParserFactory* factory, PreParserFactory* factory,
int pos) { int pos) {
return PreParserExpression::SuperCallReference(); return PreParserExpression::SuperCallReference();
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
class Processor: public AstVisitor { class Processor final : public AstVisitor<Processor> {
public: public:
Processor(Isolate* isolate, Scope* scope, Variable* result, Processor(Isolate* isolate, Scope* scope, Variable* result,
AstValueFactory* ast_value_factory) AstValueFactory* ast_value_factory)
...@@ -37,8 +37,6 @@ class Processor: public AstVisitor { ...@@ -37,8 +37,6 @@ class Processor: public AstVisitor {
InitializeAstVisitor(parser->stack_limit()); InitializeAstVisitor(parser->stack_limit());
} }
~Processor() override {}
void Process(ZoneList<Statement*>* statements); void Process(ZoneList<Statement*>* statements);
bool result_assigned() const { return result_assigned_; } bool result_assigned() const { return result_assigned_; }
...@@ -81,7 +79,7 @@ class Processor: public AstVisitor { ...@@ -81,7 +79,7 @@ class Processor: public AstVisitor {
AstNodeFactory factory_; AstNodeFactory factory_;
// Node visitors. // Node visitors.
#define DEF_VISIT(type) void Visit##type(type* node) override; #define DEF_VISIT(type) void Visit##type(type* node);
AST_NODE_LIST(DEF_VISIT) AST_NODE_LIST(DEF_VISIT)
#undef DEF_VISIT #undef DEF_VISIT
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment