Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1876)

Unified Diff: src/parsing/parser-base.h

Issue 2209573002: Separate Scope into DeclarationScope and Scope (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/parsing/parser-base.h
diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h
index 10c36aa917582687057a5d836ffad0f9ea1f441c..418c35a4de72963d644aa5fbd6a5e45071082a09 100644
--- a/src/parsing/parser-base.h
+++ b/src/parsing/parser-base.h
@@ -111,8 +111,8 @@ inline bool IsGeneratorMethod(MethodKind kind) {
inline bool IsAsyncMethod(MethodKind kind) { return kind & MethodKind::Async; }
struct FormalParametersBase {
- explicit FormalParametersBase(Scope* scope) : scope(scope) {}
- Scope* scope;
+ explicit FormalParametersBase(DeclarationScope* scope) : scope(scope) {}
+ DeclarationScope* scope;
bool has_rest = false;
bool is_simple = true;
int materialized_literals_count = 0;
@@ -325,7 +325,7 @@ class ParserBase : public Traits {
Scope* NewScope(ScopeState* outer_state) {
Scope* parent = outer_state->scope();
Zone* zone = outer_state->zone();
- return new (zone) Scope(zone, parent, BLOCK_SCOPE, kNormalFunction);
+ return new (zone) Scope(zone, parent, BLOCK_SCOPE);
}
};
@@ -619,8 +619,24 @@ class ParserBase : public Traits {
Mode old_mode_;
};
- Scope* NewScriptScope() {
- return new (zone()) Scope(zone(), nullptr, SCRIPT_SCOPE, kNormalFunction);
+ DeclarationScope* NewScriptScope() {
+ return new (zone()) DeclarationScope(zone(), nullptr, SCRIPT_SCOPE);
+ }
+
+ DeclarationScope* NewVarblockScope() {
+ return new (zone()) DeclarationScope(zone(), scope(), BLOCK_SCOPE);
+ }
+
+ DeclarationScope* NewModuleScope(Scope* parent) {
+ DeclarationScope* result =
+ new (zone()) DeclarationScope(zone(), parent, MODULE_SCOPE);
+ // TODO(verwaest): Move into the DeclarationScope constructor.
+ result->DeclareThis(ast_value_factory());
+ return result;
+ }
+
+ DeclarationScope* NewEvalScope(Scope* parent) {
+ return new (zone()) DeclarationScope(zone(), parent, EVAL_SCOPE);
}
Scope* NewScope(ScopeType scope_type) {
@@ -635,16 +651,16 @@ class ParserBase : public Traits {
// types.
DCHECK_NE(FUNCTION_SCOPE, scope_type);
DCHECK_NE(SCRIPT_SCOPE, scope_type);
+ DCHECK_NE(MODULE_SCOPE, scope_type);
DCHECK_NOT_NULL(parent);
- Scope* result =
- new (zone()) Scope(zone(), parent, scope_type, kNormalFunction);
- if (scope_type == MODULE_SCOPE) result->DeclareThis(ast_value_factory());
- return result;
+ return new (zone()) Scope(zone(), parent, scope_type);
}
- Scope* NewFunctionScope(FunctionKind kind) {
+ DeclarationScope* NewFunctionScope(FunctionKind kind) {
DCHECK(ast_value_factory());
- Scope* result = new (zone()) Scope(zone(), scope(), FUNCTION_SCOPE, kind);
+ DeclarationScope* result =
+ new (zone()) DeclarationScope(zone(), scope(), FUNCTION_SCOPE, kind);
+ // TODO(verwaest): Move into the DeclarationScope constructor.
if (!IsArrowFunction(kind)) {
result->DeclareThis(ast_value_factory());
result->DeclareDefaultFunctionVariables(ast_value_factory());
@@ -1155,7 +1171,7 @@ class ParserBase : public Traits {
if (is_sloppy(scope->language_mode())) {
// For sloppy scopes we also have to record the call at function level,
// in case it includes declarations that will be hoisted.
- scope->DeclarationScope()->RecordEvalCall();
+ scope->GetDeclarationScope()->RecordEvalCall();
}
}
}
@@ -1219,7 +1235,9 @@ class ParserBase : public Traits {
bool has_seen_constructor_;
};
- ModuleDescriptor* module() const { return scope()->module(); }
+ ModuleDescriptor* module() const {
+ return scope()->AsDeclarationScope()->module();
+ }
Scope* scope() const { return scope_state_->scope(); }
ScopeState* scope_state_; // Scope stack.
@@ -2321,7 +2339,7 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN,
ValidateFormalParameterInitializer(&arrow_formals_classifier, ok);
Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos);
- Scope* scope =
+ DeclarationScope* scope =
this->NewFunctionScope(is_async ? FunctionKind::kAsyncArrowFunction
: FunctionKind::kArrowFunction);
// Because the arrow's parameters were parsed in the outer scope, any
@@ -3086,7 +3104,7 @@ ParserBase<Traits>::ParseSuperExpression(bool is_new, bool* ok) {
Expect(Token::SUPER, CHECK_OK);
int pos = position();
- Scope* scope = this->scope()->ReceiverScope();
+ DeclarationScope* scope = this->scope()->GetReceiverScope();
FunctionKind kind = scope->function_kind();
if (IsConciseMethod(kind) || IsAccessorFunction(kind) ||
IsClassConstructor(kind)) {
@@ -3128,7 +3146,7 @@ ParserBase<Traits>::ParseNewTargetExpression(bool* ok) {
int pos = position();
ExpectMetaProperty(CStrVector("target"), "new.target", pos, CHECK_OK);
- if (!scope()->ReceiverScope()->is_function_scope()) {
+ if (!scope()->GetReceiverScope()->is_function_scope()) {
ReportMessageAt(scanner()->location(),
MessageTemplate::kUnexpectedNewTarget);
*ok = false;

Powered by Google App Engine
This is Rietveld 408576698