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

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

Issue 2623583004: PreParser scope analysis: simplify DeclareAndInitializeVariables. (Closed)
Patch Set: Created 3 years, 11 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 | « no previous file | test/cctest/test-parsing.cc » ('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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 <cmath> 5 #include <cmath>
6 6
7 #include "src/allocation.h" 7 #include "src/allocation.h"
8 #include "src/base/logging.h" 8 #include "src/base/logging.h"
9 #include "src/conversions-inl.h" 9 #include "src/conversions-inl.h"
10 #include "src/conversions.h" 10 #include "src/conversions.h"
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 return PreParserExpression::FromIdentifier(name, proxy, zone()); 290 return PreParserExpression::FromIdentifier(name, proxy, zone());
291 } 291 }
292 292
293 void PreParser::DeclareAndInitializeVariables( 293 void PreParser::DeclareAndInitializeVariables(
294 PreParserStatement block, 294 PreParserStatement block,
295 const DeclarationDescriptor* declaration_descriptor, 295 const DeclarationDescriptor* declaration_descriptor,
296 const DeclarationParsingResult::Declaration* declaration, 296 const DeclarationParsingResult::Declaration* declaration,
297 ZoneList<const AstRawString*>* names, bool* ok) { 297 ZoneList<const AstRawString*>* names, bool* ok) {
298 if (declaration->pattern.variables_ != nullptr) { 298 if (declaration->pattern.variables_ != nullptr) {
299 DCHECK(FLAG_lazy_inner_functions); 299 DCHECK(FLAG_lazy_inner_functions);
300 /* Mimic what Parser does when declaring variables (see
301 Parser::PatternRewriter::VisitVariableProxy).
302
303 var + no initializer -> RemoveUnresolved
304 let / const + no initializer -> RemoveUnresolved
305 var + initializer -> RemoveUnresolved followed by NewUnresolved
306 let / const + initializer -> RemoveUnresolved
307 */
308 Scope* scope = declaration_descriptor->hoist_scope; 300 Scope* scope = declaration_descriptor->hoist_scope;
309 if (scope == nullptr) { 301 if (scope == nullptr) {
310 scope = this->scope(); 302 scope = this->scope();
311 } 303 }
312 if (declaration->initializer.IsEmpty() ||
313 (declaration_descriptor->mode == VariableMode::LET ||
314 declaration_descriptor->mode == VariableMode::CONST)) {
315 for (auto variable : *(declaration->pattern.variables_)) {
316 declaration_descriptor->scope->RemoveUnresolved(variable);
317 }
318 }
319 for (auto variable : *(declaration->pattern.variables_)) { 304 for (auto variable : *(declaration->pattern.variables_)) {
305 declaration_descriptor->scope->RemoveUnresolved(variable);
320 scope->DeclareVariableName(variable->raw_name(), 306 scope->DeclareVariableName(variable->raw_name(),
321 declaration_descriptor->mode); 307 declaration_descriptor->mode);
322 } 308 }
323 } 309 }
324 } 310 }
325 311
326 #undef CHECK_OK 312 #undef CHECK_OK
327 #undef CHECK_OK_CUSTOM 313 #undef CHECK_OK_CUSTOM
328 314
329 315
330 } // namespace internal 316 } // namespace internal
331 } // namespace v8 317 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698