Commit dc18cc1d authored by nikolaos's avatar nikolaos Committed by Commit bot

[parser] Modify some const qualifications

This patch const-qualifies some methods of ParserBase.
It also unqualifies some methods of Parser and Preparser.
The reason for the latter is that, in principle, the methods
of AstNodeFactory should be allowed to change the factory's
state, therefore should not be const and should not be used
from const-qualified parser/pre-parser methods.

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

Review-Url: https://codereview.chromium.org/2263973003
Cr-Commit-Position: refs/heads/master@{#38813}
parent 22cb3cba
......@@ -606,30 +606,30 @@ class ParserBase : public Traits {
Mode old_mode_;
};
DeclarationScope* NewScriptScope() {
DeclarationScope* NewScriptScope() const {
return new (zone()) DeclarationScope(zone());
}
DeclarationScope* NewVarblockScope() {
DeclarationScope* NewVarblockScope() const {
return new (zone()) DeclarationScope(zone(), scope(), BLOCK_SCOPE);
}
ModuleScope* NewModuleScope(DeclarationScope* parent) {
ModuleScope* NewModuleScope(DeclarationScope* parent) const {
return new (zone()) ModuleScope(zone(), parent, ast_value_factory());
}
DeclarationScope* NewEvalScope(Scope* parent) {
DeclarationScope* NewEvalScope(Scope* parent) const {
return new (zone()) DeclarationScope(zone(), parent, EVAL_SCOPE);
}
Scope* NewScope(ScopeType scope_type) {
Scope* NewScope(ScopeType scope_type) const {
return NewScopeWithParent(scope(), scope_type);
}
// This constructor should only be used when absolutely necessary. Most scopes
// should automatically use scope() as parent, and be fine with
// NewScope(ScopeType) above.
Scope* NewScopeWithParent(Scope* parent, ScopeType scope_type) {
Scope* NewScopeWithParent(Scope* parent, ScopeType scope_type) const {
// Must always use the specific constructors for the blacklisted scope
// types.
DCHECK_NE(FUNCTION_SCOPE, scope_type);
......@@ -639,7 +639,7 @@ class ParserBase : public Traits {
return new (zone()) Scope(zone(), parent, scope_type);
}
DeclarationScope* NewFunctionScope(FunctionKind kind) {
DeclarationScope* NewFunctionScope(FunctionKind kind) const {
DCHECK(ast_value_factory());
DeclarationScope* result =
new (zone()) DeclarationScope(zone(), scope(), FUNCTION_SCOPE, kind);
......@@ -653,8 +653,8 @@ class ParserBase : public Traits {
Scanner* scanner() const { return scanner_; }
AstValueFactory* ast_value_factory() const { return ast_value_factory_; }
int position() { return scanner_->location().beg_pos; }
int peek_position() { return scanner_->peek_location().beg_pos; }
int position() const { return scanner_->location().beg_pos; }
int peek_position() const { return scanner_->peek_location().beg_pos; }
bool stack_overflow() const { return stack_overflow_; }
void set_stack_overflow() { stack_overflow_ = true; }
Mode mode() const { return mode_; }
......
......@@ -577,13 +577,13 @@ const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) const {
return parser_->scanner()->NextSymbol(parser_->ast_value_factory());
}
Expression* ParserTraits::ThisExpression(int pos) const {
Expression* ParserTraits::ThisExpression(int pos) {
return parser_->NewUnresolved(parser_->ast_value_factory()->this_string(),
pos, pos + 4, Variable::THIS);
}
Expression* ParserTraits::NewSuperPropertyReference(AstNodeFactory* factory,
int pos) const {
int pos) {
// this_function[home_object_symbol]
VariableProxy* this_function_proxy = parser_->NewUnresolved(
parser_->ast_value_factory()->this_function_string(), pos);
......@@ -596,7 +596,7 @@ Expression* ParserTraits::NewSuperPropertyReference(AstNodeFactory* factory,
}
Expression* ParserTraits::NewSuperCallReference(AstNodeFactory* factory,
int pos) const {
int pos) {
VariableProxy* new_target_proxy = parser_->NewUnresolved(
parser_->ast_value_factory()->new_target_string(), pos);
VariableProxy* this_function_proxy = parser_->NewUnresolved(
......@@ -606,7 +606,7 @@ Expression* ParserTraits::NewSuperCallReference(AstNodeFactory* factory,
pos);
}
Expression* ParserTraits::NewTargetExpression(int pos) const {
Expression* ParserTraits::NewTargetExpression(int pos) {
static const int kNewTargetStringLength = 10;
auto proxy =
parser_->NewUnresolved(parser_->ast_value_factory()->new_target_string(),
......@@ -656,7 +656,7 @@ Literal* ParserTraits::ExpressionFromLiteral(Token::Value token, int pos,
Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name,
int start_position,
int end_position,
InferName infer) const {
InferName infer) {
if (infer == InferName::kYes && parser_->fni_ != NULL) {
parser_->fni_->PushVariableName(name);
}
......
......@@ -302,16 +302,16 @@ class ParserTraits {
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* ThisExpression(int pos = kNoSourcePosition);
Expression* NewSuperPropertyReference(AstNodeFactory* factory, int pos);
Expression* NewSuperCallReference(AstNodeFactory* factory, int pos);
Expression* NewTargetExpression(int pos);
Expression* FunctionSentExpression(AstNodeFactory* factory, int pos) const;
Literal* ExpressionFromLiteral(Token::Value token, int pos, Scanner* scanner,
AstNodeFactory* factory) const;
Expression* ExpressionFromIdentifier(const AstRawString* name,
int start_position, int end_position,
InferName = InferName::kYes) const;
InferName = InferName::kYes);
Expression* ExpressionFromString(int pos, Scanner* scanner,
AstNodeFactory* factory) const;
Expression* GetIterator(Expression* iterable, AstNodeFactory* factory,
......@@ -331,7 +331,7 @@ class ParserTraits {
V8_INLINE void AddParameterInitializationBlock(
const ParserFormalParameters& parameters,
ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok) const;
ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok);
void ParseAsyncArrowSingleExpressionBody(
ZoneList<Statement*>* body, bool accept_IN,
......@@ -1106,7 +1106,7 @@ void ParserTraits::DeclareFormalParameter(
void ParserTraits::AddParameterInitializationBlock(
const ParserFormalParameters& parameters,
ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok) const {
ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok) {
if (!parameters.is_simple) {
auto* init_block =
parser_->BuildParameterInitializationBlock(parameters, ok);
......
......@@ -798,21 +798,21 @@ class PreParserTraits {
return PreParserIdentifier::Default();
}
PreParserExpression ThisExpression(int pos = kNoSourcePosition) const {
PreParserExpression ThisExpression(int pos = kNoSourcePosition) {
return PreParserExpression::This();
}
PreParserExpression NewSuperPropertyReference(PreParserFactory* factory,
int pos) const {
int pos) {
return PreParserExpression::Default();
}
PreParserExpression NewSuperCallReference(PreParserFactory* factory,
int pos) const {
int pos) {
return PreParserExpression::SuperCallReference();
}
PreParserExpression NewTargetExpression(int pos) const {
PreParserExpression NewTargetExpression(int pos) {
return PreParserExpression::Default();
}
......@@ -827,9 +827,10 @@ class PreParserTraits {
return PreParserExpression::Default();
}
PreParserExpression ExpressionFromIdentifier(
PreParserIdentifier name, int start_position, int end_position,
InferName = InferName::kYes) const {
PreParserExpression ExpressionFromIdentifier(PreParserIdentifier name,
int start_position,
int end_position,
InferName = InferName::kYes) {
return PreParserExpression::FromIdentifier(name);
}
......@@ -855,7 +856,7 @@ class PreParserTraits {
void AddParameterInitializationBlock(
const PreParserFormalParameters& parameters, PreParserStatementList body,
bool is_async, bool* ok) const {}
bool is_async, bool* ok) {}
void ParseAsyncArrowSingleExpressionBody(
PreParserStatementList body, bool accept_IN,
......
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