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 {
// thus it must never be used where only a single statement
// 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); \
if (!*ok) return this->x(); \
((void)0
#define DUMMY ) // to make indentation work
#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
// the differences between Parser and PreParser:
......
......@@ -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 =
parser_->scanner()->CurrentSymbol(parser_->ast_value_factory());
DCHECK(result != NULL);
......@@ -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();
char array[100];
const char* string = DoubleToCString(double_value, ArrayVector(array));
......@@ -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());
}
Expression* ParserTraits::ThisExpression(int pos) {
Expression* ParserTraits::ThisExpression(int pos) const {
return parser_->NewUnresolved(parser_->ast_value_factory()->this_string(),
pos, pos + 4, Variable::THIS);
}
Expression* ParserTraits::NewSuperPropertyReference(AstNodeFactory* factory,
int pos) {
int pos) const {
// this_function[home_object_symbol]
VariableProxy* this_function_proxy = parser_->NewUnresolved(
parser_->ast_value_factory()->this_function_string(), pos);
......@@ -688,7 +688,7 @@ Expression* ParserTraits::NewSuperPropertyReference(AstNodeFactory* factory,
}
Expression* ParserTraits::NewSuperCallReference(AstNodeFactory* factory,
int pos) {
int pos) const {
VariableProxy* new_target_proxy = parser_->NewUnresolved(
parser_->ast_value_factory()->new_target_string(), pos);
VariableProxy* this_function_proxy = parser_->NewUnresolved(
......@@ -698,7 +698,7 @@ Expression* ParserTraits::NewSuperCallReference(AstNodeFactory* factory,
pos);
}
Expression* ParserTraits::NewTargetExpression(int pos) {
Expression* ParserTraits::NewTargetExpression(int pos) const {
static const int kNewTargetStringLength = 10;
auto proxy =
parser_->NewUnresolved(parser_->ast_value_factory()->new_target_string(),
......@@ -708,7 +708,7 @@ Expression* ParserTraits::NewTargetExpression(int pos) {
}
Expression* ParserTraits::FunctionSentExpression(AstNodeFactory* factory,
int pos) {
int pos) const {
// We desugar function.sent into %_GeneratorGetInputOrDebugPos(generator).
Zone* zone = parser_->zone();
ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(1, zone);
......@@ -722,7 +722,7 @@ Expression* ParserTraits::FunctionSentExpression(AstNodeFactory* factory,
Literal* ParserTraits::ExpressionFromLiteral(Token::Value token, int pos,
Scanner* scanner,
AstNodeFactory* factory) {
AstNodeFactory* factory) const {
switch (token) {
case Token::NULL_LITERAL:
return factory->NewNullLiteral(pos);
......@@ -748,7 +748,7 @@ Literal* ParserTraits::ExpressionFromLiteral(Token::Value token, int pos,
Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name,
int start_position,
int end_position,
InferName infer) {
InferName infer) const {
if (infer == InferName::kYes && parser_->fni_ != NULL) {
parser_->fni_->PushVariableName(name);
}
......@@ -757,7 +757,7 @@ Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name,
Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner,
AstNodeFactory* factory) {
AstNodeFactory* factory) const {
const AstRawString* symbol = GetSymbol(scanner);
if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol);
return factory->NewStringLiteral(symbol, pos);
......@@ -777,7 +777,7 @@ Expression* ParserTraits::GetIterator(Expression* iterable,
Literal* ParserTraits::GetLiteralTheHole(int position,
AstNodeFactory* factory) {
AstNodeFactory* factory) const {
return factory->NewTheHoleLiteral(kNoSourcePosition);
}
......
......@@ -416,7 +416,7 @@ class ParserTraits {
bool IsConstructor(const AstRawString* identifier) const;
bool IsDirectEvalCall(Expression* expression) {
bool IsDirectEvalCall(Expression* expression) const {
if (!expression->IsCall()) return false;
expression = expression->AsCall()->expression();
return IsIdentifier(expression) && IsEval(AsIdentifier(expression));
......@@ -515,43 +515,46 @@ class ParserTraits {
static ZoneList<Expression*>* NullExpressionList() { return nullptr; }
// Non-NULL empty string.
V8_INLINE const AstRawString* EmptyIdentifierString();
V8_INLINE const AstRawString* EmptyIdentifierString() const;
// Odd-ball literal creators.
Literal* GetLiteralTheHole(int position, AstNodeFactory* factory);
Literal* GetLiteralTheHole(int position, AstNodeFactory* factory) const;
// Producing data during the recursive descent.
const AstRawString* GetSymbol(Scanner* scanner);
const AstRawString* GetNextSymbol(Scanner* scanner);
const AstRawString* GetNumberAsSymbol(Scanner* scanner);
Expression* ThisExpression(int pos);
Expression* NewSuperPropertyReference(AstNodeFactory* factory, int pos);
Expression* NewSuperCallReference(AstNodeFactory* factory, int pos);
Expression* NewTargetExpression(int pos);
Expression* FunctionSentExpression(AstNodeFactory* factory, int pos);
const AstRawString* GetSymbol(Scanner* scanner) const;
const AstRawString* GetNextSymbol(Scanner* scanner) const;
const AstRawString* GetNumberAsSymbol(Scanner* scanner) const;
Expression* ThisExpression(int pos = kNoSourcePosition) const;
Expression* NewSuperPropertyReference(AstNodeFactory* factory, int pos) const;
Expression* NewSuperCallReference(AstNodeFactory* factory, int pos) const;
Expression* NewTargetExpression(int pos) const;
Expression* FunctionSentExpression(AstNodeFactory* factory, int pos) const;
Literal* ExpressionFromLiteral(Token::Value token, int pos, Scanner* scanner,
AstNodeFactory* factory);
AstNodeFactory* factory) const;
Expression* ExpressionFromIdentifier(const AstRawString* name,
int start_position, int end_position,
InferName = InferName::kYes);
InferName = InferName::kYes) const;
Expression* ExpressionFromString(int pos, Scanner* scanner,
AstNodeFactory* factory);
AstNodeFactory* factory) const;
Expression* GetIterator(Expression* iterable, AstNodeFactory* factory,
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);
}
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);
}
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);
}
V8_INLINE void AddParameterInitializationBlock(
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(
ZoneList<Statement*>* body, bool accept_IN,
......@@ -1188,7 +1191,7 @@ bool ParserTraits::IsFutureStrictReserved(
return parser_->scanner()->IdentifierIsFutureStrictReserved(identifier);
}
const AstRawString* ParserTraits::EmptyIdentifierString() {
const AstRawString* ParserTraits::EmptyIdentifierString() const {
return parser_->ast_value_factory()->empty_string();
}
......@@ -1326,7 +1329,7 @@ void ParserTraits::DeclareFormalParameter(
void ParserTraits::AddParameterInitializationBlock(
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) {
auto* init_block =
parser_->BuildParameterInitializationBlock(parameters, ok);
......
......@@ -41,15 +41,16 @@ namespace internal {
#define DUMMY ) // to make indentation work
#undef DUMMY
void PreParserTraits::ReportMessageAt(Scanner::Location location,
void PreParserTraits::ReportMessageAt(Scanner::Location source_location,
MessageTemplate::Template message,
const char* arg,
ParseErrorType error_type) {
pre_parser_->log_->LogMessage(location.beg_pos, location.end_pos, message,
arg, error_type);
pre_parser_->log_->LogMessage(source_location.beg_pos,
source_location.end_pos, message, arg,
error_type);
}
void PreParserTraits::ReportMessageAt(Scanner::Location location,
void PreParserTraits::ReportMessageAt(Scanner::Location source_location,
MessageTemplate::Template message,
const AstRawString* arg,
ParseErrorType error_type) {
......@@ -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()) {
case Token::ENUM:
return PreParserIdentifier::Enum();
......@@ -90,7 +91,7 @@ PreParserIdentifier PreParserTraits::GetSymbol(Scanner* scanner) {
PreParserExpression PreParserTraits::ExpressionFromString(
int pos, Scanner* scanner, PreParserFactory* factory) {
int pos, Scanner* scanner, PreParserFactory* factory) const {
if (scanner->UnescapedLiteralMatches("use strict", 10)) {
return PreParserExpression::UseStrictStringLiteral();
}
......
......@@ -745,11 +745,11 @@ class PreParserTraits {
}
// Reporting errors.
void ReportMessageAt(Scanner::Location location,
void ReportMessageAt(Scanner::Location source_location,
MessageTemplate::Template message,
const char* arg = NULL,
ParseErrorType error_type = kSyntaxError);
void ReportMessageAt(Scanner::Location location,
void ReportMessageAt(Scanner::Location source_location,
MessageTemplate::Template message,
const AstRawString* arg,
ParseErrorType error_type = kSyntaxError);
......@@ -777,7 +777,7 @@ class PreParserTraits {
static PreParserExpressionList NullExpressionList() {
return PreParserExpressionList();
}
static PreParserIdentifier EmptyIdentifierString() {
PreParserIdentifier EmptyIdentifierString() const {
return PreParserIdentifier::Default();
}
......@@ -788,13 +788,13 @@ class PreParserTraits {
}
// Producing data during the recursive descent.
PreParserIdentifier GetSymbol(Scanner* scanner);
PreParserIdentifier GetSymbol(Scanner* scanner) const;
PreParserIdentifier GetNextSymbol(Scanner* scanner) const {
return PreParserIdentifier::Default();
}
PreParserIdentifier GetNumberAsSymbol(Scanner* scanner) {
PreParserIdentifier GetNumberAsSymbol(Scanner* scanner) const {
return PreParserIdentifier::Default();
}
......@@ -834,7 +834,7 @@ class PreParserTraits {
}
PreParserExpression ExpressionFromString(int pos, Scanner* scanner,
PreParserFactory* factory);
PreParserFactory* factory) const;
PreParserExpression GetIterator(PreParserExpression iterable,
PreParserFactory* factory, int pos) {
......@@ -854,7 +854,7 @@ class PreParserTraits {
}
void AddParameterInitializationBlock(
const PreParserFormalParameters& parameters, PreParserStatementList list,
const PreParserFormalParameters& parameters, PreParserStatementList body,
bool is_async, bool* ok) const {}
void ParseAsyncArrowSingleExpressionBody(
......@@ -878,7 +878,7 @@ class PreParserTraits {
}
V8_INLINE void ParseArrowFunctionFormalParameterList(
PreParserFormalParameters* parameters, PreParserExpression expression,
PreParserFormalParameters* parameters, PreParserExpression params,
const Scanner::Location& params_loc, Scanner::Location* duplicate_loc,
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