Commit 8133ab4c authored by nikolaos's avatar nikolaos Committed by Commit bot

This patch continues the refactoring of the traits objects, used by the

parser and the preparser, so that they contain the same set of methods,
with the same signatures.  It mainly flags some traits methods as const.
It also contains a small cosmetic change in the definition of CHECK_OK.

R=adamk@chromium.org, marja@chromium.org
BUG=
LOG=N

Review-Url: https://codereview.chromium.org/2258123002
Cr-Commit-Position: refs/heads/master@{#38767}
parent 848b6278
...@@ -126,19 +126,15 @@ struct FormalParametersBase { ...@@ -126,19 +126,15 @@ struct FormalParametersBase {
// thus it must never be used where only a single statement // thus it must never be used where only a single statement
// is correct (e.g. an if statement branch w/o braces)! // is correct (e.g. an if statement branch w/o braces)!
#define CHECK_OK ok); \
if (!*ok) return this->EmptyExpression(); \
((void)0
#define DUMMY ) // to make indentation work
#undef DUMMY
// Used in functions where the return type is not ExpressionT.
#define CHECK_OK_CUSTOM(x) ok); \ #define CHECK_OK_CUSTOM(x) ok); \
if (!*ok) return this->x(); \ if (!*ok) return this->x(); \
((void)0 ((void)0
#define DUMMY ) // to make indentation work #define DUMMY ) // to make indentation work
#undef DUMMY #undef DUMMY
// Used in functions where the return type is ExpressionT.
#define CHECK_OK CHECK_OK_CUSTOM(EmptyExpression)
// Common base class shared between parser and pre-parser. Traits encapsulate // Common base class shared between parser and pre-parser. Traits encapsulate
// the differences between Parser and PreParser: // the differences between Parser and PreParser:
......
...@@ -649,7 +649,7 @@ void ParserTraits::ReportMessageAt(Scanner::Location source_location, ...@@ -649,7 +649,7 @@ void ParserTraits::ReportMessageAt(Scanner::Location source_location,
} }
const AstRawString* ParserTraits::GetSymbol(Scanner* scanner) { const AstRawString* ParserTraits::GetSymbol(Scanner* scanner) const {
const AstRawString* result = const AstRawString* result =
parser_->scanner()->CurrentSymbol(parser_->ast_value_factory()); parser_->scanner()->CurrentSymbol(parser_->ast_value_factory());
DCHECK(result != NULL); DCHECK(result != NULL);
...@@ -657,7 +657,7 @@ const AstRawString* ParserTraits::GetSymbol(Scanner* scanner) { ...@@ -657,7 +657,7 @@ const AstRawString* ParserTraits::GetSymbol(Scanner* scanner) {
} }
const AstRawString* ParserTraits::GetNumberAsSymbol(Scanner* scanner) { const AstRawString* ParserTraits::GetNumberAsSymbol(Scanner* scanner) const {
double double_value = parser_->scanner()->DoubleValue(); double double_value = parser_->scanner()->DoubleValue();
char array[100]; char array[100];
const char* string = DoubleToCString(double_value, ArrayVector(array)); const char* string = DoubleToCString(double_value, ArrayVector(array));
...@@ -665,17 +665,17 @@ const AstRawString* ParserTraits::GetNumberAsSymbol(Scanner* scanner) { ...@@ -665,17 +665,17 @@ const AstRawString* ParserTraits::GetNumberAsSymbol(Scanner* scanner) {
} }
const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) { const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) const {
return parser_->scanner()->NextSymbol(parser_->ast_value_factory()); return parser_->scanner()->NextSymbol(parser_->ast_value_factory());
} }
Expression* ParserTraits::ThisExpression(int pos) { Expression* ParserTraits::ThisExpression(int pos) const {
return parser_->NewUnresolved(parser_->ast_value_factory()->this_string(), return parser_->NewUnresolved(parser_->ast_value_factory()->this_string(),
pos, pos + 4, Variable::THIS); pos, pos + 4, Variable::THIS);
} }
Expression* ParserTraits::NewSuperPropertyReference(AstNodeFactory* factory, Expression* ParserTraits::NewSuperPropertyReference(AstNodeFactory* factory,
int pos) { int pos) const {
// this_function[home_object_symbol] // this_function[home_object_symbol]
VariableProxy* this_function_proxy = parser_->NewUnresolved( VariableProxy* this_function_proxy = parser_->NewUnresolved(
parser_->ast_value_factory()->this_function_string(), pos); parser_->ast_value_factory()->this_function_string(), pos);
...@@ -688,7 +688,7 @@ Expression* ParserTraits::NewSuperPropertyReference(AstNodeFactory* factory, ...@@ -688,7 +688,7 @@ Expression* ParserTraits::NewSuperPropertyReference(AstNodeFactory* factory,
} }
Expression* ParserTraits::NewSuperCallReference(AstNodeFactory* factory, Expression* ParserTraits::NewSuperCallReference(AstNodeFactory* factory,
int pos) { int pos) const {
VariableProxy* new_target_proxy = parser_->NewUnresolved( VariableProxy* new_target_proxy = parser_->NewUnresolved(
parser_->ast_value_factory()->new_target_string(), pos); parser_->ast_value_factory()->new_target_string(), pos);
VariableProxy* this_function_proxy = parser_->NewUnresolved( VariableProxy* this_function_proxy = parser_->NewUnresolved(
...@@ -698,7 +698,7 @@ Expression* ParserTraits::NewSuperCallReference(AstNodeFactory* factory, ...@@ -698,7 +698,7 @@ Expression* ParserTraits::NewSuperCallReference(AstNodeFactory* factory,
pos); pos);
} }
Expression* ParserTraits::NewTargetExpression(int pos) { Expression* ParserTraits::NewTargetExpression(int pos) const {
static const int kNewTargetStringLength = 10; static const int kNewTargetStringLength = 10;
auto proxy = auto proxy =
parser_->NewUnresolved(parser_->ast_value_factory()->new_target_string(), parser_->NewUnresolved(parser_->ast_value_factory()->new_target_string(),
...@@ -708,7 +708,7 @@ Expression* ParserTraits::NewTargetExpression(int pos) { ...@@ -708,7 +708,7 @@ Expression* ParserTraits::NewTargetExpression(int pos) {
} }
Expression* ParserTraits::FunctionSentExpression(AstNodeFactory* factory, Expression* ParserTraits::FunctionSentExpression(AstNodeFactory* factory,
int pos) { int pos) const {
// We desugar function.sent into %_GeneratorGetInputOrDebugPos(generator). // We desugar function.sent into %_GeneratorGetInputOrDebugPos(generator).
Zone* zone = parser_->zone(); Zone* zone = parser_->zone();
ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(1, zone); ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(1, zone);
...@@ -722,7 +722,7 @@ Expression* ParserTraits::FunctionSentExpression(AstNodeFactory* factory, ...@@ -722,7 +722,7 @@ Expression* ParserTraits::FunctionSentExpression(AstNodeFactory* factory,
Literal* ParserTraits::ExpressionFromLiteral(Token::Value token, int pos, Literal* ParserTraits::ExpressionFromLiteral(Token::Value token, int pos,
Scanner* scanner, Scanner* scanner,
AstNodeFactory* factory) { AstNodeFactory* factory) const {
switch (token) { switch (token) {
case Token::NULL_LITERAL: case Token::NULL_LITERAL:
return factory->NewNullLiteral(pos); return factory->NewNullLiteral(pos);
...@@ -748,7 +748,7 @@ Literal* ParserTraits::ExpressionFromLiteral(Token::Value token, int pos, ...@@ -748,7 +748,7 @@ Literal* ParserTraits::ExpressionFromLiteral(Token::Value token, int pos,
Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name, Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name,
int start_position, int start_position,
int end_position, int end_position,
InferName infer) { InferName infer) const {
if (infer == InferName::kYes && parser_->fni_ != NULL) { if (infer == InferName::kYes && parser_->fni_ != NULL) {
parser_->fni_->PushVariableName(name); parser_->fni_->PushVariableName(name);
} }
...@@ -757,7 +757,7 @@ Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name, ...@@ -757,7 +757,7 @@ Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name,
Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner, Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner,
AstNodeFactory* factory) { AstNodeFactory* factory) const {
const AstRawString* symbol = GetSymbol(scanner); const AstRawString* symbol = GetSymbol(scanner);
if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol);
return factory->NewStringLiteral(symbol, pos); return factory->NewStringLiteral(symbol, pos);
...@@ -777,7 +777,7 @@ Expression* ParserTraits::GetIterator(Expression* iterable, ...@@ -777,7 +777,7 @@ Expression* ParserTraits::GetIterator(Expression* iterable,
Literal* ParserTraits::GetLiteralTheHole(int position, Literal* ParserTraits::GetLiteralTheHole(int position,
AstNodeFactory* factory) { AstNodeFactory* factory) const {
return factory->NewTheHoleLiteral(kNoSourcePosition); return factory->NewTheHoleLiteral(kNoSourcePosition);
} }
......
...@@ -416,7 +416,7 @@ class ParserTraits { ...@@ -416,7 +416,7 @@ class ParserTraits {
bool IsConstructor(const AstRawString* identifier) const; bool IsConstructor(const AstRawString* identifier) const;
bool IsDirectEvalCall(Expression* expression) { bool IsDirectEvalCall(Expression* expression) const {
if (!expression->IsCall()) return false; if (!expression->IsCall()) return false;
expression = expression->AsCall()->expression(); expression = expression->AsCall()->expression();
return IsIdentifier(expression) && IsEval(AsIdentifier(expression)); return IsIdentifier(expression) && IsEval(AsIdentifier(expression));
...@@ -515,43 +515,46 @@ class ParserTraits { ...@@ -515,43 +515,46 @@ class ParserTraits {
static ZoneList<Expression*>* NullExpressionList() { return nullptr; } static ZoneList<Expression*>* NullExpressionList() { return nullptr; }
// Non-NULL empty string. // Non-NULL empty string.
V8_INLINE const AstRawString* EmptyIdentifierString(); V8_INLINE const AstRawString* EmptyIdentifierString() const;
// Odd-ball literal creators. // Odd-ball literal creators.
Literal* GetLiteralTheHole(int position, AstNodeFactory* factory); Literal* GetLiteralTheHole(int position, AstNodeFactory* factory) const;
// Producing data during the recursive descent. // Producing data during the recursive descent.
const AstRawString* GetSymbol(Scanner* scanner); const AstRawString* GetSymbol(Scanner* scanner) const;
const AstRawString* GetNextSymbol(Scanner* scanner); const AstRawString* GetNextSymbol(Scanner* scanner) const;
const AstRawString* GetNumberAsSymbol(Scanner* scanner); const AstRawString* GetNumberAsSymbol(Scanner* scanner) const;
Expression* ThisExpression(int pos); Expression* ThisExpression(int pos = kNoSourcePosition) const;
Expression* NewSuperPropertyReference(AstNodeFactory* factory, int pos); Expression* NewSuperPropertyReference(AstNodeFactory* factory, int pos) const;
Expression* NewSuperCallReference(AstNodeFactory* factory, int pos); Expression* NewSuperCallReference(AstNodeFactory* factory, int pos) const;
Expression* NewTargetExpression(int pos); Expression* NewTargetExpression(int pos) const;
Expression* FunctionSentExpression(AstNodeFactory* factory, int pos); Expression* FunctionSentExpression(AstNodeFactory* factory, int pos) const;
Literal* ExpressionFromLiteral(Token::Value token, int pos, Scanner* scanner, Literal* ExpressionFromLiteral(Token::Value token, int pos, Scanner* scanner,
AstNodeFactory* factory); AstNodeFactory* factory) const;
Expression* ExpressionFromIdentifier(const AstRawString* name, Expression* ExpressionFromIdentifier(const AstRawString* name,
int start_position, int end_position, int start_position, int end_position,
InferName = InferName::kYes); InferName = InferName::kYes) const;
Expression* ExpressionFromString(int pos, Scanner* scanner, Expression* ExpressionFromString(int pos, Scanner* scanner,
AstNodeFactory* factory); AstNodeFactory* factory) const;
Expression* GetIterator(Expression* iterable, AstNodeFactory* factory, Expression* GetIterator(Expression* iterable, AstNodeFactory* factory,
int pos); int pos);
ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) { ZoneList<v8::internal::Expression*>* NewExpressionList(int size,
Zone* zone) const {
return new(zone) ZoneList<v8::internal::Expression*>(size, zone); return new(zone) ZoneList<v8::internal::Expression*>(size, zone);
} }
ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) { ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size,
Zone* zone) const {
return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone);
} }
ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) { ZoneList<v8::internal::Statement*>* NewStatementList(int size,
Zone* zone) const {
return new(zone) ZoneList<v8::internal::Statement*>(size, zone); return new(zone) ZoneList<v8::internal::Statement*>(size, zone);
} }
V8_INLINE void AddParameterInitializationBlock( V8_INLINE void AddParameterInitializationBlock(
const ParserFormalParameters& parameters, const ParserFormalParameters& parameters,
ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok); ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok) const;
void ParseAsyncArrowSingleExpressionBody( void ParseAsyncArrowSingleExpressionBody(
ZoneList<Statement*>* body, bool accept_IN, ZoneList<Statement*>* body, bool accept_IN,
...@@ -1188,7 +1191,7 @@ bool ParserTraits::IsFutureStrictReserved( ...@@ -1188,7 +1191,7 @@ bool ParserTraits::IsFutureStrictReserved(
return parser_->scanner()->IdentifierIsFutureStrictReserved(identifier); return parser_->scanner()->IdentifierIsFutureStrictReserved(identifier);
} }
const AstRawString* ParserTraits::EmptyIdentifierString() { const AstRawString* ParserTraits::EmptyIdentifierString() const {
return parser_->ast_value_factory()->empty_string(); return parser_->ast_value_factory()->empty_string();
} }
...@@ -1326,7 +1329,7 @@ void ParserTraits::DeclareFormalParameter( ...@@ -1326,7 +1329,7 @@ void ParserTraits::DeclareFormalParameter(
void ParserTraits::AddParameterInitializationBlock( void ParserTraits::AddParameterInitializationBlock(
const ParserFormalParameters& parameters, const ParserFormalParameters& parameters,
ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok) { ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok) const {
if (!parameters.is_simple) { if (!parameters.is_simple) {
auto* init_block = auto* init_block =
parser_->BuildParameterInitializationBlock(parameters, ok); parser_->BuildParameterInitializationBlock(parameters, ok);
......
...@@ -41,15 +41,16 @@ namespace internal { ...@@ -41,15 +41,16 @@ namespace internal {
#define DUMMY ) // to make indentation work #define DUMMY ) // to make indentation work
#undef DUMMY #undef DUMMY
void PreParserTraits::ReportMessageAt(Scanner::Location location, void PreParserTraits::ReportMessageAt(Scanner::Location source_location,
MessageTemplate::Template message, MessageTemplate::Template message,
const char* arg, const char* arg,
ParseErrorType error_type) { ParseErrorType error_type) {
pre_parser_->log_->LogMessage(location.beg_pos, location.end_pos, message, pre_parser_->log_->LogMessage(source_location.beg_pos,
arg, error_type); source_location.end_pos, message, arg,
error_type);
} }
void PreParserTraits::ReportMessageAt(Scanner::Location location, void PreParserTraits::ReportMessageAt(Scanner::Location source_location,
MessageTemplate::Template message, MessageTemplate::Template message,
const AstRawString* arg, const AstRawString* arg,
ParseErrorType error_type) { ParseErrorType error_type) {
...@@ -57,7 +58,7 @@ void PreParserTraits::ReportMessageAt(Scanner::Location location, ...@@ -57,7 +58,7 @@ void PreParserTraits::ReportMessageAt(Scanner::Location location,
} }
PreParserIdentifier PreParserTraits::GetSymbol(Scanner* scanner) { PreParserIdentifier PreParserTraits::GetSymbol(Scanner* scanner) const {
switch (scanner->current_token()) { switch (scanner->current_token()) {
case Token::ENUM: case Token::ENUM:
return PreParserIdentifier::Enum(); return PreParserIdentifier::Enum();
...@@ -90,7 +91,7 @@ PreParserIdentifier PreParserTraits::GetSymbol(Scanner* scanner) { ...@@ -90,7 +91,7 @@ PreParserIdentifier PreParserTraits::GetSymbol(Scanner* scanner) {
PreParserExpression PreParserTraits::ExpressionFromString( PreParserExpression PreParserTraits::ExpressionFromString(
int pos, Scanner* scanner, PreParserFactory* factory) { int pos, Scanner* scanner, PreParserFactory* factory) const {
if (scanner->UnescapedLiteralMatches("use strict", 10)) { if (scanner->UnescapedLiteralMatches("use strict", 10)) {
return PreParserExpression::UseStrictStringLiteral(); return PreParserExpression::UseStrictStringLiteral();
} }
......
...@@ -745,11 +745,11 @@ class PreParserTraits { ...@@ -745,11 +745,11 @@ class PreParserTraits {
} }
// Reporting errors. // Reporting errors.
void ReportMessageAt(Scanner::Location location, void ReportMessageAt(Scanner::Location source_location,
MessageTemplate::Template message, MessageTemplate::Template message,
const char* arg = NULL, const char* arg = NULL,
ParseErrorType error_type = kSyntaxError); ParseErrorType error_type = kSyntaxError);
void ReportMessageAt(Scanner::Location location, void ReportMessageAt(Scanner::Location source_location,
MessageTemplate::Template message, MessageTemplate::Template message,
const AstRawString* arg, const AstRawString* arg,
ParseErrorType error_type = kSyntaxError); ParseErrorType error_type = kSyntaxError);
...@@ -777,7 +777,7 @@ class PreParserTraits { ...@@ -777,7 +777,7 @@ class PreParserTraits {
static PreParserExpressionList NullExpressionList() { static PreParserExpressionList NullExpressionList() {
return PreParserExpressionList(); return PreParserExpressionList();
} }
static PreParserIdentifier EmptyIdentifierString() { PreParserIdentifier EmptyIdentifierString() const {
return PreParserIdentifier::Default(); return PreParserIdentifier::Default();
} }
...@@ -788,13 +788,13 @@ class PreParserTraits { ...@@ -788,13 +788,13 @@ class PreParserTraits {
} }
// Producing data during the recursive descent. // Producing data during the recursive descent.
PreParserIdentifier GetSymbol(Scanner* scanner); PreParserIdentifier GetSymbol(Scanner* scanner) const;
PreParserIdentifier GetNextSymbol(Scanner* scanner) const { PreParserIdentifier GetNextSymbol(Scanner* scanner) const {
return PreParserIdentifier::Default(); return PreParserIdentifier::Default();
} }
PreParserIdentifier GetNumberAsSymbol(Scanner* scanner) { PreParserIdentifier GetNumberAsSymbol(Scanner* scanner) const {
return PreParserIdentifier::Default(); return PreParserIdentifier::Default();
} }
...@@ -834,7 +834,7 @@ class PreParserTraits { ...@@ -834,7 +834,7 @@ class PreParserTraits {
} }
PreParserExpression ExpressionFromString(int pos, Scanner* scanner, PreParserExpression ExpressionFromString(int pos, Scanner* scanner,
PreParserFactory* factory); PreParserFactory* factory) const;
PreParserExpression GetIterator(PreParserExpression iterable, PreParserExpression GetIterator(PreParserExpression iterable,
PreParserFactory* factory, int pos) { PreParserFactory* factory, int pos) {
...@@ -854,7 +854,7 @@ class PreParserTraits { ...@@ -854,7 +854,7 @@ class PreParserTraits {
} }
void AddParameterInitializationBlock( void AddParameterInitializationBlock(
const PreParserFormalParameters& parameters, PreParserStatementList list, const PreParserFormalParameters& parameters, PreParserStatementList body,
bool is_async, bool* ok) const {} bool is_async, bool* ok) const {}
void ParseAsyncArrowSingleExpressionBody( void ParseAsyncArrowSingleExpressionBody(
...@@ -878,7 +878,7 @@ class PreParserTraits { ...@@ -878,7 +878,7 @@ class PreParserTraits {
} }
V8_INLINE void ParseArrowFunctionFormalParameterList( V8_INLINE void ParseArrowFunctionFormalParameterList(
PreParserFormalParameters* parameters, PreParserExpression expression, PreParserFormalParameters* parameters, PreParserExpression params,
const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, const Scanner::Location& params_loc, Scanner::Location* duplicate_loc,
const Scope::Snapshot& scope_snapshot, bool* ok); const Scope::Snapshot& scope_snapshot, bool* ok);
......
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