Commit 4faa0ae8 authored by Andy Wingo's avatar Andy Wingo

Remove AstConstructionVisitor/AstNullVisitor

R=svenpanne@chromium.org
BUG=

Review URL: https://codereview.chromium.org/679943004

Cr-Commit-Position: refs/heads/master@{#25357}
parent 27cc3c68
......@@ -1001,110 +1001,6 @@ CaseClause::CaseClause(Zone* zone, Expression* label,
compare_type_(Type::None(zone)) {}
#define REGULAR_NODE(NodeType) \
void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \
}
#define REGULAR_NODE_WITH_FEEDBACK_SLOTS(NodeType) \
void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \
}
#define DONT_OPTIMIZE_NODE(NodeType) \
void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \
}
#define DONT_OPTIMIZE_NODE_WITH_FEEDBACK_SLOTS(NodeType) \
void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \
}
#define DONT_TURBOFAN_NODE(NodeType) \
void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \
}
#define DONT_TURBOFAN_NODE_WITH_FEEDBACK_SLOTS(NodeType) \
void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \
}
#define DONT_SELFOPTIMIZE_NODE(NodeType) \
void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \
}
#define DONT_SELFOPTIMIZE_NODE_WITH_FEEDBACK_SLOTS(NodeType) \
void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \
}
#define DONT_CACHE_NODE(NodeType) \
void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \
}
REGULAR_NODE(VariableDeclaration)
REGULAR_NODE(FunctionDeclaration)
REGULAR_NODE(Block)
REGULAR_NODE(ExpressionStatement)
REGULAR_NODE(EmptyStatement)
REGULAR_NODE(IfStatement)
REGULAR_NODE(ContinueStatement)
REGULAR_NODE(BreakStatement)
REGULAR_NODE(ReturnStatement)
REGULAR_NODE(SwitchStatement)
REGULAR_NODE(CaseClause)
REGULAR_NODE(Conditional)
REGULAR_NODE(Literal)
REGULAR_NODE(ArrayLiteral)
REGULAR_NODE(ObjectLiteral)
REGULAR_NODE(RegExpLiteral)
REGULAR_NODE(FunctionLiteral)
REGULAR_NODE(Assignment)
REGULAR_NODE(Throw)
REGULAR_NODE(UnaryOperation)
REGULAR_NODE(CountOperation)
REGULAR_NODE(BinaryOperation)
REGULAR_NODE(CompareOperation)
REGULAR_NODE(ThisFunction)
REGULAR_NODE_WITH_FEEDBACK_SLOTS(Call)
REGULAR_NODE_WITH_FEEDBACK_SLOTS(CallNew)
REGULAR_NODE_WITH_FEEDBACK_SLOTS(Property)
// In theory, for VariableProxy we'd have to add:
// if (node->var()->IsLookupSlot())
// set_dont_optimize_reason(kReferenceToAVariableWhichRequiresDynamicLookup);
// But node->var() is usually not bound yet at VariableProxy creation time, and
// LOOKUP variables only result from constructs that cannot be inlined anyway.
REGULAR_NODE_WITH_FEEDBACK_SLOTS(VariableProxy)
// We currently do not optimize any modules.
DONT_OPTIMIZE_NODE(ModuleDeclaration)
DONT_OPTIMIZE_NODE(ImportDeclaration)
DONT_OPTIMIZE_NODE(ExportDeclaration)
DONT_OPTIMIZE_NODE(ModuleVariable)
DONT_OPTIMIZE_NODE(ModulePath)
DONT_OPTIMIZE_NODE(ModuleUrl)
DONT_OPTIMIZE_NODE(ModuleStatement)
DONT_OPTIMIZE_NODE(WithStatement)
DONT_OPTIMIZE_NODE(DebuggerStatement)
DONT_OPTIMIZE_NODE(NativeFunctionLiteral)
DONT_OPTIMIZE_NODE_WITH_FEEDBACK_SLOTS(Yield)
// TODO(turbofan): Remove the dont_turbofan_reason once this list is empty.
// This list must be kept in sync with Pipeline::GenerateCode.
DONT_TURBOFAN_NODE(ForOfStatement)
DONT_TURBOFAN_NODE(TryCatchStatement)
DONT_TURBOFAN_NODE(TryFinallyStatement)
DONT_TURBOFAN_NODE(ClassLiteral)
DONT_TURBOFAN_NODE_WITH_FEEDBACK_SLOTS(SuperReference)
DONT_SELFOPTIMIZE_NODE(DoWhileStatement)
DONT_SELFOPTIMIZE_NODE(WhileStatement)
DONT_SELFOPTIMIZE_NODE(ForStatement)
DONT_SELFOPTIMIZE_NODE_WITH_FEEDBACK_SLOTS(ForInStatement)
DONT_CACHE_NODE(ModuleLiteral)
void AstConstructionVisitor::VisitCallRuntime(CallRuntime* node) {
}
#undef REGULAR_NODE
#undef DONT_OPTIMIZE_NODE
#undef DONT_SELFOPTIMIZE_NODE
#undef DONT_CACHE_NODE
uint32_t Literal::Hash() {
return raw_value()->IsString()
? raw_value()->AsString()->hash()
......
This diff is collapsed.
......@@ -287,8 +287,7 @@ FunctionLiteral* Parser::DefaultConstructor(bool call_super, Scope* scope,
ZoneList<Statement*>* body = NULL;
{
AstNodeFactory<AstConstructionVisitor> function_factory(
ast_value_factory());
AstNodeFactory function_factory(ast_value_factory());
FunctionState function_state(&function_state_, &scope_, function_scope,
&function_factory);
......@@ -460,7 +459,7 @@ Expression* ParserTraits::MarkExpressionAsAssigned(Expression* expression) {
bool ParserTraits::ShortcutNumericLiteralBinaryExpression(
Expression** x, Expression* y, Token::Value op, int pos,
AstNodeFactory<AstConstructionVisitor>* factory) {
AstNodeFactory* factory) {
if ((*x)->AsLiteral() && (*x)->AsLiteral()->raw_value()->IsNumber() &&
y->AsLiteral() && y->AsLiteral()->raw_value()->IsNumber()) {
double x_val = (*x)->AsLiteral()->raw_value()->AsNumber();
......@@ -518,9 +517,9 @@ bool ParserTraits::ShortcutNumericLiteralBinaryExpression(
}
Expression* ParserTraits::BuildUnaryExpression(
Expression* expression, Token::Value op, int pos,
AstNodeFactory<AstConstructionVisitor>* factory) {
Expression* ParserTraits::BuildUnaryExpression(Expression* expression,
Token::Value op, int pos,
AstNodeFactory* factory) {
DCHECK(expression != NULL);
if (expression->IsLiteral()) {
const AstValue* literal = expression->AsLiteral()->raw_value();
......@@ -674,13 +673,13 @@ const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) {
}
Expression* ParserTraits::ThisExpression(
Scope* scope, AstNodeFactory<AstConstructionVisitor>* factory, int pos) {
Expression* ParserTraits::ThisExpression(Scope* scope, AstNodeFactory* factory,
int pos) {
return factory->NewVariableProxy(scope->receiver(), pos);
}
Expression* ParserTraits::SuperReference(
Scope* scope, AstNodeFactory<AstConstructionVisitor>* factory, int pos) {
Expression* ParserTraits::SuperReference(Scope* scope, AstNodeFactory* factory,
int pos) {
return factory->NewSuperReference(
ThisExpression(scope, factory, pos)->AsVariableProxy(),
pos);
......@@ -689,22 +688,20 @@ Expression* ParserTraits::SuperReference(
Expression* ParserTraits::ClassExpression(
const AstRawString* name, Expression* extends, Expression* constructor,
ZoneList<ObjectLiteral::Property*>* properties, int start_position,
int end_position, AstNodeFactory<AstConstructionVisitor>* factory) {
int end_position, AstNodeFactory* factory) {
return factory->NewClassLiteral(name, extends, constructor, properties,
start_position, end_position);
}
Expression* ParserTraits::DefaultConstructor(bool call_super, Scope* scope,
int pos, int end_pos) {
return parser_->DefaultConstructor(call_super, scope, pos, end_pos);
}
Literal* ParserTraits::ExpressionFromLiteral(
Token::Value token, int pos,
Scanner* scanner,
AstNodeFactory<AstConstructionVisitor>* factory) {
Literal* ParserTraits::ExpressionFromLiteral(Token::Value token, int pos,
Scanner* scanner,
AstNodeFactory* factory) {
switch (token) {
case Token::NULL_LITERAL:
return factory->NewNullLiteral(pos);
......@@ -723,9 +720,9 @@ Literal* ParserTraits::ExpressionFromLiteral(
}
Expression* ParserTraits::ExpressionFromIdentifier(
const AstRawString* name, int pos, Scope* scope,
AstNodeFactory<AstConstructionVisitor>* factory) {
Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name,
int pos, Scope* scope,
AstNodeFactory* factory) {
if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name);
// The name may refer to a module instance object, so its type is unknown.
#ifdef DEBUG
......@@ -737,17 +734,16 @@ Expression* ParserTraits::ExpressionFromIdentifier(
}
Expression* ParserTraits::ExpressionFromString(
int pos, Scanner* scanner,
AstNodeFactory<AstConstructionVisitor>* factory) {
Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner,
AstNodeFactory* factory) {
const AstRawString* symbol = GetSymbol(scanner);
if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol);
return factory->NewStringLiteral(symbol, pos);
}
Expression* ParserTraits::GetIterator(
Expression* iterable, AstNodeFactory<AstConstructionVisitor>* factory) {
Expression* ParserTraits::GetIterator(Expression* iterable,
AstNodeFactory* factory) {
Expression* iterator_symbol_literal =
factory->NewSymbolLiteral("iterator_symbol", RelocInfo::kNoPosition);
int pos = iterable->position();
......@@ -759,8 +755,8 @@ Expression* ParserTraits::GetIterator(
}
Literal* ParserTraits::GetLiteralTheHole(
int position, AstNodeFactory<AstConstructionVisitor>* factory) {
Literal* ParserTraits::GetLiteralTheHole(int position,
AstNodeFactory* factory) {
return factory->NewTheHoleLiteral(RelocInfo::kNoPosition);
}
......@@ -924,8 +920,7 @@ FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, Scope** scope,
ParsingModeScope parsing_mode(this, mode);
// Enters 'scope'.
AstNodeFactory<AstConstructionVisitor> function_factory(
ast_value_factory());
AstNodeFactory function_factory(ast_value_factory());
FunctionState function_state(&function_state_, &scope_, *scope,
&function_factory);
......@@ -1036,8 +1031,7 @@ FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) {
zone());
}
original_scope_ = scope;
AstNodeFactory<AstConstructionVisitor> function_factory(
ast_value_factory());
AstNodeFactory function_factory(ast_value_factory());
FunctionState function_state(&function_state_, &scope_, scope,
&function_factory);
DCHECK(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT);
......@@ -3549,8 +3543,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
: FunctionLiteral::kNotParenthesized;
// Parse function body.
{
AstNodeFactory<AstConstructionVisitor> function_factory(
ast_value_factory());
AstNodeFactory function_factory(ast_value_factory());
FunctionState function_state(&function_state_, &scope_, scope,
&function_factory);
scope_->SetScopeName(function_name);
......
......@@ -373,7 +373,7 @@ class ParserTraits {
typedef ZoneList<v8::internal::Statement*>* StatementList;
// For constructing objects returned by the traversing functions.
typedef AstNodeFactory<AstConstructionVisitor> Factory;
typedef AstNodeFactory Factory;
};
explicit ParserTraits(Parser* parser) : parser_(parser) {}
......@@ -451,9 +451,9 @@ class ParserTraits {
// Returns true if we have a binary expression between two numeric
// literals. In that case, *x will be changed to an expression which is the
// computed value.
bool ShortcutNumericLiteralBinaryExpression(
Expression** x, Expression* y, Token::Value op, int pos,
AstNodeFactory<AstConstructionVisitor>* factory);
bool ShortcutNumericLiteralBinaryExpression(Expression** x, Expression* y,
Token::Value op, int pos,
AstNodeFactory* factory);
// Rewrites the following types of unary expressions:
// not <literal> -> true / false
......@@ -466,9 +466,8 @@ class ParserTraits {
// + foo -> foo * 1
// - foo -> foo * (-1)
// ~ foo -> foo ^(~0)
Expression* BuildUnaryExpression(
Expression* expression, Token::Value op, int pos,
AstNodeFactory<AstConstructionVisitor>* factory);
Expression* BuildUnaryExpression(Expression* expression, Token::Value op,
int pos, AstNodeFactory* factory);
// Generate AST node that throws a ReferenceError with the given type.
Expression* NewThrowReferenceError(const char* type, int pos);
......@@ -528,38 +527,32 @@ class ParserTraits {
V8_INLINE const AstRawString* EmptyIdentifierString();
// Odd-ball literal creators.
Literal* GetLiteralTheHole(int position,
AstNodeFactory<AstConstructionVisitor>* factory);
Literal* GetLiteralTheHole(int position, AstNodeFactory* factory);
// Producing data during the recursive descent.
const AstRawString* GetSymbol(Scanner* scanner);
const AstRawString* GetNextSymbol(Scanner* scanner);
const AstRawString* GetNumberAsSymbol(Scanner* scanner);
Expression* ThisExpression(Scope* scope,
AstNodeFactory<AstConstructionVisitor>* factory,
Expression* ThisExpression(Scope* scope, AstNodeFactory* factory,
int pos = RelocInfo::kNoPosition);
Expression* SuperReference(Scope* scope,
AstNodeFactory<AstConstructionVisitor>* factory,
Expression* SuperReference(Scope* scope, AstNodeFactory* factory,
int pos = RelocInfo::kNoPosition);
Expression* ClassExpression(const AstRawString* name, Expression* extends,
Expression* constructor,
ZoneList<ObjectLiteral::Property*>* properties,
int start_position, int end_position,
AstNodeFactory<AstConstructionVisitor>* factory);
AstNodeFactory* factory);
Expression* DefaultConstructor(bool call_super, Scope* scope, int pos,
int end_pos);
Literal* ExpressionFromLiteral(
Token::Value token, int pos, Scanner* scanner,
AstNodeFactory<AstConstructionVisitor>* factory);
Expression* ExpressionFromIdentifier(
const AstRawString* name, int pos, Scope* scope,
AstNodeFactory<AstConstructionVisitor>* factory);
Expression* ExpressionFromString(
int pos, Scanner* scanner,
AstNodeFactory<AstConstructionVisitor>* factory);
Expression* GetIterator(Expression* iterable,
AstNodeFactory<AstConstructionVisitor>* factory);
Literal* ExpressionFromLiteral(Token::Value token, int pos, Scanner* scanner,
AstNodeFactory* factory);
Expression* ExpressionFromIdentifier(const AstRawString* name, int pos,
Scope* scope, AstNodeFactory* factory);
Expression* ExpressionFromString(int pos, Scanner* scanner,
AstNodeFactory* factory);
Expression* GetIterator(Expression* iterable, AstNodeFactory* factory);
ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) {
return new(zone) ZoneList<v8::internal::Expression*>(size, zone);
}
......
......@@ -29,9 +29,7 @@ class Processor: public AstVisitor {
void Process(ZoneList<Statement*>* statements);
bool result_assigned() const { return result_assigned_; }
AstNodeFactory<AstNullVisitor>* factory() {
return &factory_;
}
AstNodeFactory* factory() { return &factory_; }
private:
Variable* result_;
......@@ -49,7 +47,7 @@ class Processor: public AstVisitor {
bool is_set_;
bool in_try_;
AstNodeFactory<AstNullVisitor> factory_;
AstNodeFactory factory_;
Expression* SetResult(Expression* value) {
result_assigned_ = true;
......
......@@ -277,7 +277,7 @@ bool Scope::Analyze(CompilationInfo* info) {
// Allocate the variables.
{
AstNodeFactory<AstNullVisitor> ast_node_factory(info->ast_value_factory());
AstNodeFactory ast_node_factory(info->ast_value_factory());
if (!top->AllocateVariables(info, &ast_node_factory)) return false;
}
......@@ -424,7 +424,7 @@ Variable* Scope::LookupLocal(const AstRawString* name) {
Variable* Scope::LookupFunctionVar(const AstRawString* name,
AstNodeFactory<AstNullVisitor>* factory) {
AstNodeFactory* factory) {
if (function_ != NULL && function_->proxy()->raw_name() == name) {
return function_->proxy()->var();
} else if (!scope_info_.is_null()) {
......@@ -643,8 +643,7 @@ void Scope::CollectStackAndContextLocals(ZoneList<Variable*>* stack_locals,
}
bool Scope::AllocateVariables(CompilationInfo* info,
AstNodeFactory<AstNullVisitor>* factory) {
bool Scope::AllocateVariables(CompilationInfo* info, AstNodeFactory* factory) {
// 1) Propagate scope information.
bool outer_scope_calls_sloppy_eval = false;
if (outer_scope_ != NULL) {
......@@ -981,7 +980,7 @@ Variable* Scope::NonLocal(const AstRawString* name, VariableMode mode) {
Variable* Scope::LookupRecursive(VariableProxy* proxy,
BindingKind* binding_kind,
AstNodeFactory<AstNullVisitor>* factory) {
AstNodeFactory* factory) {
DCHECK(binding_kind != NULL);
if (already_resolved() && is_with_scope()) {
// Short-cut: if the scope is deserialized from a scope info, variable
......@@ -1043,9 +1042,8 @@ Variable* Scope::LookupRecursive(VariableProxy* proxy,
}
bool Scope::ResolveVariable(CompilationInfo* info,
VariableProxy* proxy,
AstNodeFactory<AstNullVisitor>* factory) {
bool Scope::ResolveVariable(CompilationInfo* info, VariableProxy* proxy,
AstNodeFactory* factory) {
DCHECK(info->script_scope()->is_script_scope());
// If the proxy is already resolved there's nothing to do
......@@ -1152,9 +1150,8 @@ bool Scope::ResolveVariable(CompilationInfo* info,
}
bool Scope::ResolveVariablesRecursively(
CompilationInfo* info,
AstNodeFactory<AstNullVisitor>* factory) {
bool Scope::ResolveVariablesRecursively(CompilationInfo* info,
AstNodeFactory* factory) {
DCHECK(info->script_scope()->is_script_scope());
// Resolve unresolved variables for this scope.
......
......@@ -108,7 +108,7 @@ class Scope: public ZoneObject {
// the name of named function literal is kept in an intermediate scope
// in between this scope and the next outer scope.)
Variable* LookupFunctionVar(const AstRawString* name,
AstNodeFactory<AstNullVisitor>* factory);
AstNodeFactory* factory);
// Lookup a variable in this scope or outer scopes.
// Returns the variable or NULL if not found.
......@@ -141,8 +141,7 @@ class Scope: public ZoneObject {
Variable* DeclareDynamicGlobal(const AstRawString* name);
// Create a new unresolved variable.
template<class Visitor>
VariableProxy* NewUnresolved(AstNodeFactory<Visitor>* factory,
VariableProxy* NewUnresolved(AstNodeFactory* factory,
const AstRawString* name,
Interface* interface = Interface::NewValue(),
int position = RelocInfo::kNoPosition) {
......@@ -594,16 +593,14 @@ class Scope: public ZoneObject {
// Lookup a variable reference given by name recursively starting with this
// scope. If the code is executed because of a call to 'eval', the context
// parameter should be set to the calling context of 'eval'.
Variable* LookupRecursive(VariableProxy* proxy,
BindingKind* binding_kind,
AstNodeFactory<AstNullVisitor>* factory);
Variable* LookupRecursive(VariableProxy* proxy, BindingKind* binding_kind,
AstNodeFactory* factory);
MUST_USE_RESULT
bool ResolveVariable(CompilationInfo* info,
VariableProxy* proxy,
AstNodeFactory<AstNullVisitor>* factory);
bool ResolveVariable(CompilationInfo* info, VariableProxy* proxy,
AstNodeFactory* factory);
MUST_USE_RESULT
bool ResolveVariablesRecursively(CompilationInfo* info,
AstNodeFactory<AstNullVisitor>* factory);
AstNodeFactory* factory);
// Scope analysis.
void PropagateScopeInfo(bool outer_scope_calls_sloppy_eval);
......@@ -632,8 +629,7 @@ class Scope: public ZoneObject {
// parameter is the context in which eval was called. In all other
// cases the context parameter is an empty handle.
MUST_USE_RESULT
bool AllocateVariables(CompilationInfo* info,
AstNodeFactory<AstNullVisitor>* factory);
bool AllocateVariables(CompilationInfo* info, AstNodeFactory* factory);
private:
// Construct a scope based on the scope info.
......
......@@ -41,7 +41,7 @@ TEST(List) {
Isolate* isolate = CcTest::i_isolate();
Zone zone(isolate);
AstValueFactory value_factory(&zone, 0);
AstNodeFactory<AstNullVisitor> factory(&value_factory);
AstNodeFactory factory(&value_factory);
AstNode* node = factory.NewEmptyStatement(RelocInfo::kNoPosition);
list->Add(node);
CHECK_EQ(1, list->length());
......
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