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

Side by Side Diff: src/parsing/parser.cc

Issue 2160943004: Remove ast_value_factory_ and usages from scope (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rename NewScope(...FunctionKind) to NewFunctionScope Created 4 years, 5 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 unified diff | Download patch
« no previous file with comments | « src/parsing/parser.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/parsing/parser.h" 5 #include "src/parsing/parser.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/ast-expression-rewriter.h" 9 #include "src/ast/ast-expression-rewriter.h"
10 #include "src/ast/ast-expression-visitor.h" 10 #include "src/ast/ast-expression-visitor.h"
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 bool call_super, Scope* scope, 203 bool call_super, Scope* scope,
204 int pos, int end_pos, 204 int pos, int end_pos,
205 LanguageMode language_mode) { 205 LanguageMode language_mode) {
206 int materialized_literal_count = -1; 206 int materialized_literal_count = -1;
207 int expected_property_count = -1; 207 int expected_property_count = -1;
208 int parameter_count = 0; 208 int parameter_count = 0;
209 if (name == nullptr) name = ast_value_factory()->empty_string(); 209 if (name == nullptr) name = ast_value_factory()->empty_string();
210 210
211 FunctionKind kind = call_super ? FunctionKind::kDefaultSubclassConstructor 211 FunctionKind kind = call_super ? FunctionKind::kDefaultSubclassConstructor
212 : FunctionKind::kDefaultBaseConstructor; 212 : FunctionKind::kDefaultBaseConstructor;
213 Scope* function_scope = NewScope(scope, FUNCTION_SCOPE, kind); 213 Scope* function_scope = NewFunctionScope(scope, kind);
214 SetLanguageMode(function_scope, 214 SetLanguageMode(function_scope,
215 static_cast<LanguageMode>(language_mode | STRICT)); 215 static_cast<LanguageMode>(language_mode | STRICT));
216 // Set start and end position to the same value 216 // Set start and end position to the same value
217 function_scope->set_start_position(pos); 217 function_scope->set_start_position(pos);
218 function_scope->set_end_position(pos); 218 function_scope->set_end_position(pos);
219 ZoneList<Statement*>* body = NULL; 219 ZoneList<Statement*>* body = NULL;
220 220
221 { 221 {
222 AstNodeFactory function_factory(ast_value_factory()); 222 AstNodeFactory function_factory(ast_value_factory());
223 FunctionState function_state(&function_state_, &scope_state_, 223 FunctionState function_state(&function_state_, &scope_state_,
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 if (allow_natives() || extension_ != NULL) parsing_mode = PARSE_EAGERLY; 937 if (allow_natives() || extension_ != NULL) parsing_mode = PARSE_EAGERLY;
938 938
939 FunctionLiteral* result = NULL; 939 FunctionLiteral* result = NULL;
940 { 940 {
941 // TODO(wingo): Add an outer SCRIPT_SCOPE corresponding to the native 941 // TODO(wingo): Add an outer SCRIPT_SCOPE corresponding to the native
942 // context, which will have the "this" binding for script scopes. 942 // context, which will have the "this" binding for script scopes.
943 Scope* scope = NewScope(nullptr, SCRIPT_SCOPE); 943 Scope* scope = NewScope(nullptr, SCRIPT_SCOPE);
944 info->set_script_scope(scope); 944 info->set_script_scope(scope);
945 if (!info->context().is_null() && !info->context()->IsNativeContext()) { 945 if (!info->context().is_null() && !info->context()->IsNativeContext()) {
946 scope = Scope::DeserializeScopeChain(info->isolate(), zone(), 946 scope = Scope::DeserializeScopeChain(info->isolate(), zone(),
947 *info->context(), scope); 947 *info->context(), scope,
948 ast_value_factory());
948 // The Scope is backed up by ScopeInfo (which is in the V8 heap); this 949 // The Scope is backed up by ScopeInfo (which is in the V8 heap); this
949 // means the Parser cannot operate independent of the V8 heap. Tell the 950 // means the Parser cannot operate independent of the V8 heap. Tell the
950 // string table to internalize strings and values right after they're 951 // string table to internalize strings and values right after they're
951 // created. This kind of parsing can only be done in the main thread. 952 // created. This kind of parsing can only be done in the main thread.
952 DCHECK(parsing_on_main_thread_); 953 DCHECK(parsing_on_main_thread_);
953 ast_value_factory()->Internalize(info->isolate()); 954 ast_value_factory()->Internalize(info->isolate());
954 } 955 }
955 original_scope_ = scope; 956 original_scope_ = scope;
956 if (info->is_eval()) { 957 if (info->is_eval()) {
957 if (!scope->is_script_scope() || is_strict(info->language_mode())) { 958 if (!scope->is_script_scope() || is_strict(info->language_mode())) {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 1104
1104 { 1105 {
1105 // Parse the function literal. 1106 // Parse the function literal.
1106 Scope* scope = NewScope(nullptr, SCRIPT_SCOPE); 1107 Scope* scope = NewScope(nullptr, SCRIPT_SCOPE);
1107 info->set_script_scope(scope); 1108 info->set_script_scope(scope);
1108 if (!info->context().is_null()) { 1109 if (!info->context().is_null()) {
1109 // Ok to use Isolate here, since lazy function parsing is only done in the 1110 // Ok to use Isolate here, since lazy function parsing is only done in the
1110 // main thread. 1111 // main thread.
1111 DCHECK(parsing_on_main_thread_); 1112 DCHECK(parsing_on_main_thread_);
1112 scope = Scope::DeserializeScopeChain(isolate, zone(), *info->context(), 1113 scope = Scope::DeserializeScopeChain(isolate, zone(), *info->context(),
1113 scope); 1114 scope, ast_value_factory());
1114 } 1115 }
1115 original_scope_ = scope; 1116 original_scope_ = scope;
1116 AstNodeFactory function_factory(ast_value_factory()); 1117 AstNodeFactory function_factory(ast_value_factory());
1117 FunctionState function_state(&function_state_, &scope_state_, scope, 1118 FunctionState function_state(&function_state_, &scope_state_, scope,
1118 shared_info->kind(), &function_factory); 1119 shared_info->kind(), &function_factory);
1119 DCHECK(is_sloppy(scope->language_mode()) || 1120 DCHECK(is_sloppy(scope->language_mode()) ||
1120 is_strict(info->language_mode())); 1121 is_strict(info->language_mode()));
1121 DCHECK(info->language_mode() == shared_info->language_mode()); 1122 DCHECK(info->language_mode() == shared_info->language_mode());
1122 FunctionLiteral::FunctionType function_type = 1123 FunctionLiteral::FunctionType function_type =
1123 ComputeFunctionType(shared_info); 1124 ComputeFunctionType(shared_info);
1124 bool ok = true; 1125 bool ok = true;
1125 1126
1126 if (shared_info->is_arrow()) { 1127 if (shared_info->is_arrow()) {
1127 bool is_async = allow_harmony_async_await() && shared_info->is_async(); 1128 bool is_async = allow_harmony_async_await() && shared_info->is_async();
1128 if (is_async) { 1129 if (is_async) {
1129 DCHECK(!scanner()->HasAnyLineTerminatorAfterNext()); 1130 DCHECK(!scanner()->HasAnyLineTerminatorAfterNext());
1130 if (!Check(Token::ASYNC)) { 1131 if (!Check(Token::ASYNC)) {
1131 CHECK(stack_overflow()); 1132 CHECK(stack_overflow());
1132 return nullptr; 1133 return nullptr;
1133 } 1134 }
1134 if (!(peek_any_identifier() || peek() == Token::LPAREN)) { 1135 if (!(peek_any_identifier() || peek() == Token::LPAREN)) {
1135 CHECK(stack_overflow()); 1136 CHECK(stack_overflow());
1136 return nullptr; 1137 return nullptr;
1137 } 1138 }
1138 } 1139 }
1139 1140
1140 // TODO(adamk): We should construct this scope from the ScopeInfo. 1141 // TODO(adamk): We should construct this scope from the ScopeInfo.
1141 Scope* scope = 1142 Scope* scope =
1142 NewScope(this->scope(), FUNCTION_SCOPE, FunctionKind::kArrowFunction); 1143 NewFunctionScope(this->scope(), FunctionKind::kArrowFunction);
1143 1144
1144 // These two bits only need to be explicitly set because we're 1145 // These two bits only need to be explicitly set because we're
1145 // not passing the ScopeInfo to the Scope constructor. 1146 // not passing the ScopeInfo to the Scope constructor.
1146 // TODO(adamk): Remove these calls once the above NewScope call 1147 // TODO(adamk): Remove these calls once the above NewScope call
1147 // passes the ScopeInfo. 1148 // passes the ScopeInfo.
1148 if (shared_info->scope_info()->CallsEval()) { 1149 if (shared_info->scope_info()->CallsEval()) {
1149 scope->RecordEvalCall(); 1150 scope->RecordEvalCall();
1150 } 1151 }
1151 SetLanguageMode(scope, shared_info->language_mode()); 1152 SetLanguageMode(scope, shared_info->language_mode());
1152 1153
(...skipping 3142 matching lines...) Expand 10 before | Expand all | Expand 10 after
4295 // Anonymous functions were passed either the empty symbol or a null 4296 // Anonymous functions were passed either the empty symbol or a null
4296 // handle as the function name. Remember if we were passed a non-empty 4297 // handle as the function name. Remember if we were passed a non-empty
4297 // handle to decide whether to invoke function name inference. 4298 // handle to decide whether to invoke function name inference.
4298 bool should_infer_name = function_name == NULL; 4299 bool should_infer_name = function_name == NULL;
4299 4300
4300 // We want a non-null handle as the function name. 4301 // We want a non-null handle as the function name.
4301 if (should_infer_name) { 4302 if (should_infer_name) {
4302 function_name = ast_value_factory()->empty_string(); 4303 function_name = ast_value_factory()->empty_string();
4303 } 4304 }
4304 4305
4305 Scope* scope = NewScope(this->scope(), FUNCTION_SCOPE, kind); 4306 Scope* scope = NewFunctionScope(this->scope(), kind);
4306 SetLanguageMode(scope, language_mode); 4307 SetLanguageMode(scope, language_mode);
4307 ZoneList<Statement*>* body = NULL; 4308 ZoneList<Statement*>* body = NULL;
4308 int arity = -1; 4309 int arity = -1;
4309 int materialized_literal_count = -1; 4310 int materialized_literal_count = -1;
4310 int expected_property_count = -1; 4311 int expected_property_count = -1;
4311 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); 4312 DuplicateFinder duplicate_finder(scanner()->unicode_cache());
4312 bool should_be_used_once_hint = false; 4313 bool should_be_used_once_hint = false;
4313 bool has_duplicate_parameters; 4314 bool has_duplicate_parameters;
4314 FunctionLiteral::EagerCompileHint eager_compile_hint; 4315 FunctionLiteral::EagerCompileHint eager_compile_hint;
4315 4316
(...skipping 2766 matching lines...) Expand 10 before | Expand all | Expand 10 after
7082 node->Print(Isolate::Current()); 7083 node->Print(Isolate::Current());
7083 } 7084 }
7084 #endif // DEBUG 7085 #endif // DEBUG
7085 7086
7086 #undef CHECK_OK 7087 #undef CHECK_OK
7087 #undef CHECK_OK_CUSTOM 7088 #undef CHECK_OK_CUSTOM
7088 #undef CHECK_FAILED 7089 #undef CHECK_FAILED
7089 7090
7090 } // namespace internal 7091 } // namespace internal
7091 } // namespace v8 7092 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/parser.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698