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()
......
......@@ -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,12 @@ 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) \
virtual void Accept(AstVisitor* v) OVERRIDE; \
virtual AstNode::NodeType node_type() const FINAL OVERRIDE { \
return AstNode::k##type; \
} \
friend class AstNodeFactory;
enum AstPropertiesFlag {
......@@ -1498,7 +1497,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);
......@@ -2329,15 +2328,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; }
......@@ -3163,58 +3153,20 @@ private: \
bool stack_overflow_
// ----------------------------------------------------------------------------
// Construction time visitor.
class AstConstructionVisitor BASE_EMBEDDED {
public:
AstConstructionVisitor() {}
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
};
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,
......@@ -3222,71 +3174,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)
......@@ -3299,12 +3236,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();
......@@ -3313,47 +3248,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,
......@@ -3362,23 +3288,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) {
......@@ -3387,57 +3310,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(
......@@ -3446,10 +3354,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,
......@@ -3465,120 +3371,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,
......@@ -3586,14 +3476,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(
......@@ -3605,51 +3493,37 @@ 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,
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, 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_;
};
......
......@@ -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