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

Side by Side Diff: src/parsing/parser-base.h

Issue 2172723003: [cleanup] Remove some leftover strong mode code from the parser (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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.cc ('k') | src/parsing/preparser.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 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 #ifndef V8_PARSING_PARSER_BASE_H 5 #ifndef V8_PARSING_PARSER_BASE_H
6 #define V8_PARSING_PARSER_BASE_H 6 #define V8_PARSING_PARSER_BASE_H
7 7
8 #include "src/ast/scopes.h" 8 #include "src/ast/scopes.h"
9 #include "src/bailout-reason.h" 9 #include "src/bailout-reason.h"
10 #include "src/base/hashmap.h" 10 #include "src/base/hashmap.h"
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 return next_materialized_literal_index_; 383 return next_materialized_literal_index_;
384 } 384 }
385 385
386 void SkipMaterializedLiterals(int count) { 386 void SkipMaterializedLiterals(int count) {
387 next_materialized_literal_index_ += count; 387 next_materialized_literal_index_ += count;
388 } 388 }
389 389
390 void AddProperty() { expected_property_count_++; } 390 void AddProperty() { expected_property_count_++; }
391 int expected_property_count() { return expected_property_count_; } 391 int expected_property_count() { return expected_property_count_; }
392 392
393 Scanner::Location this_location() const { return this_location_; }
394 Scanner::Location super_location() const { return super_location_; }
395 Scanner::Location return_location() const { return return_location_; }
396 void set_this_location(Scanner::Location location) {
397 this_location_ = location;
398 }
399 void set_super_location(Scanner::Location location) {
400 super_location_ = location;
401 }
402 void set_return_location(Scanner::Location location) {
403 return_location_ = location;
404 }
405
406 bool is_generator() const { return IsGeneratorFunction(kind_); } 393 bool is_generator() const { return IsGeneratorFunction(kind_); }
407 bool is_async_function() const { return IsAsyncFunction(kind_); } 394 bool is_async_function() const { return IsAsyncFunction(kind_); }
408 bool is_resumable() const { return is_generator() || is_async_function(); } 395 bool is_resumable() const { return is_generator() || is_async_function(); }
409 396
410 FunctionKind kind() const { return kind_; } 397 FunctionKind kind() const { return kind_; }
411 FunctionState* outer() const { return outer_function_state_; } 398 FunctionState* outer() const { return outer_function_state_; }
412 399
413 void set_generator_object_variable( 400 void set_generator_object_variable(
414 typename Traits::Type::GeneratorVariable* variable) { 401 typename Traits::Type::GeneratorVariable* variable) {
415 DCHECK(variable != NULL); 402 DCHECK(variable != NULL);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 } 467 }
481 468
482 // Used to assign an index to each literal that needs materialization in 469 // Used to assign an index to each literal that needs materialization in
483 // the function. Includes regexp literals, and boilerplate for object and 470 // the function. Includes regexp literals, and boilerplate for object and
484 // array literals. 471 // array literals.
485 int next_materialized_literal_index_; 472 int next_materialized_literal_index_;
486 473
487 // Properties count estimation. 474 // Properties count estimation.
488 int expected_property_count_; 475 int expected_property_count_;
489 476
490 // Location of most recent use of 'this' (invalid if none).
491 Scanner::Location this_location_;
492
493 // Location of most recent 'return' statement (invalid if none).
494 Scanner::Location return_location_;
495
496 // Location of call to the "super" constructor (invalid if none).
497 Scanner::Location super_location_;
498
499 FunctionKind kind_; 477 FunctionKind kind_;
500 // For generators, this variable may hold the generator object. It variable 478 // For generators, this variable may hold the generator object. It variable
501 // is used by yield expressions and return statements. It is not necessary 479 // is used by yield expressions and return statements. It is not necessary
502 // for generator functions to have this variable set. 480 // for generator functions to have this variable set.
503 Variable* generator_object_variable_; 481 Variable* generator_object_variable_;
504 482
505 FunctionState** function_state_stack_; 483 FunctionState** function_state_stack_;
506 FunctionState* outer_function_state_; 484 FunctionState* outer_function_state_;
507 485
508 ZoneList<DestructuringAssignment> destructuring_assignments_to_rewrite_; 486 ZoneList<DestructuringAssignment> destructuring_assignments_to_rewrite_;
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 bool allow_harmony_trailing_commas_; 1223 bool allow_harmony_trailing_commas_;
1246 }; 1224 };
1247 1225
1248 template <class Traits> 1226 template <class Traits>
1249 ParserBase<Traits>::FunctionState::FunctionState( 1227 ParserBase<Traits>::FunctionState::FunctionState(
1250 FunctionState** function_state_stack, ScopeState** scope_stack, 1228 FunctionState** function_state_stack, ScopeState** scope_stack,
1251 Scope* scope, FunctionKind kind) 1229 Scope* scope, FunctionKind kind)
1252 : ScopeState(scope_stack, scope), 1230 : ScopeState(scope_stack, scope),
1253 next_materialized_literal_index_(0), 1231 next_materialized_literal_index_(0),
1254 expected_property_count_(0), 1232 expected_property_count_(0),
1255 this_location_(Scanner::Location::invalid()),
1256 return_location_(Scanner::Location::invalid()),
1257 super_location_(Scanner::Location::invalid()),
1258 kind_(kind), 1233 kind_(kind),
1259 generator_object_variable_(NULL), 1234 generator_object_variable_(NULL),
1260 function_state_stack_(function_state_stack), 1235 function_state_stack_(function_state_stack),
1261 outer_function_state_(*function_state_stack), 1236 outer_function_state_(*function_state_stack),
1262 destructuring_assignments_to_rewrite_(16, scope->zone()), 1237 destructuring_assignments_to_rewrite_(16, scope->zone()),
1263 tail_call_expressions_(scope->zone()), 1238 tail_call_expressions_(scope->zone()),
1264 return_expr_context_(ReturnExprContext::kInsideValidBlock), 1239 return_expr_context_(ReturnExprContext::kInsideValidBlock),
1265 non_patterns_to_rewrite_(0, scope->zone()), 1240 non_patterns_to_rewrite_(0, scope->zone()),
1266 reported_errors_(16, scope->zone()), 1241 reported_errors_(16, scope->zone()),
1267 next_function_is_parenthesized_(false), 1242 next_function_is_parenthesized_(false),
(...skipping 1826 matching lines...) Expand 10 before | Expand all | Expand 10 after
3094 IsClassConstructor(kind)) { 3069 IsClassConstructor(kind)) {
3095 if (peek() == Token::PERIOD || peek() == Token::LBRACK) { 3070 if (peek() == Token::PERIOD || peek() == Token::LBRACK) {
3096 scope->RecordSuperPropertyUsage(); 3071 scope->RecordSuperPropertyUsage();
3097 return this->NewSuperPropertyReference(this->scope(), factory(), pos); 3072 return this->NewSuperPropertyReference(this->scope(), factory(), pos);
3098 } 3073 }
3099 // new super() is never allowed. 3074 // new super() is never allowed.
3100 // super() is only allowed in derived constructor 3075 // super() is only allowed in derived constructor
3101 if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) { 3076 if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) {
3102 // TODO(rossberg): This might not be the correct FunctionState for the 3077 // TODO(rossberg): This might not be the correct FunctionState for the
3103 // method here. 3078 // method here.
3104 function_state_->set_super_location(scanner()->location());
3105 return this->NewSuperCallReference(this->scope(), factory(), pos); 3079 return this->NewSuperCallReference(this->scope(), factory(), pos);
3106 } 3080 }
3107 } 3081 }
3108 3082
3109 ReportMessageAt(scanner()->location(), MessageTemplate::kUnexpectedSuper); 3083 ReportMessageAt(scanner()->location(), MessageTemplate::kUnexpectedSuper);
3110 *ok = false; 3084 *ok = false;
3111 return this->EmptyExpression(); 3085 return this->EmptyExpression();
3112 } 3086 }
3113 3087
3114 template <class Traits> 3088 template <class Traits>
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
3368 // If next token is not `=>`, it's a syntax error anyways. 3342 // If next token is not `=>`, it's a syntax error anyways.
3369 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); 3343 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW);
3370 *ok = false; 3344 *ok = false;
3371 return this->EmptyExpression(); 3345 return this->EmptyExpression();
3372 } 3346 }
3373 3347
3374 typename Traits::Type::StatementList body; 3348 typename Traits::Type::StatementList body;
3375 int num_parameters = formal_parameters.scope->num_parameters(); 3349 int num_parameters = formal_parameters.scope->num_parameters();
3376 int materialized_literal_count = -1; 3350 int materialized_literal_count = -1;
3377 int expected_property_count = -1; 3351 int expected_property_count = -1;
3378 Scanner::Location super_loc;
3379 3352
3380 FunctionKind arrow_kind = is_async ? kAsyncArrowFunction : kArrowFunction; 3353 FunctionKind arrow_kind = is_async ? kAsyncArrowFunction : kArrowFunction;
3381 { 3354 {
3382 FunctionState function_state(&function_state_, &scope_state_, 3355 FunctionState function_state(&function_state_, &scope_state_,
3383 formal_parameters.scope, arrow_kind); 3356 formal_parameters.scope, arrow_kind);
3384 3357
3385 function_state.SkipMaterializedLiterals( 3358 function_state.SkipMaterializedLiterals(
3386 formal_parameters.materialized_literals_count); 3359 formal_parameters.materialized_literals_count);
3387 3360
3388 this->ReindexLiterals(formal_parameters); 3361 this->ReindexLiterals(formal_parameters);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
3432 body->Add(factory()->NewReturnStatement(expression, pos), zone()); 3405 body->Add(factory()->NewReturnStatement(expression, pos), zone());
3433 if (allow_tailcalls() && !is_sloppy(language_mode())) { 3406 if (allow_tailcalls() && !is_sloppy(language_mode())) {
3434 // ES6 14.6.1 Static Semantics: IsInTailPosition 3407 // ES6 14.6.1 Static Semantics: IsInTailPosition
3435 this->MarkTailPosition(expression); 3408 this->MarkTailPosition(expression);
3436 } 3409 }
3437 } 3410 }
3438 materialized_literal_count = function_state.materialized_literal_count(); 3411 materialized_literal_count = function_state.materialized_literal_count();
3439 expected_property_count = function_state.expected_property_count(); 3412 expected_property_count = function_state.expected_property_count();
3440 this->MarkCollectedTailCallExpressions(); 3413 this->MarkCollectedTailCallExpressions();
3441 } 3414 }
3442 super_loc = function_state.super_location();
3443 3415
3444 formal_parameters.scope->set_end_position(scanner()->location().end_pos); 3416 formal_parameters.scope->set_end_position(scanner()->location().end_pos);
3445 3417
3446 // Arrow function formal parameters are parsed as StrictFormalParameterList, 3418 // Arrow function formal parameters are parsed as StrictFormalParameterList,
3447 // which is not the same as "parameters of a strict function"; it only means 3419 // which is not the same as "parameters of a strict function"; it only means
3448 // that duplicates are not allowed. Of course, the arrow function may 3420 // that duplicates are not allowed. Of course, the arrow function may
3449 // itself be strict as well. 3421 // itself be strict as well.
3450 const bool allow_duplicate_parameters = false; 3422 const bool allow_duplicate_parameters = false;
3451 this->ValidateFormalParameters(&formals_classifier, language_mode(), 3423 this->ValidateFormalParameters(&formals_classifier, language_mode(),
3452 allow_duplicate_parameters, CHECK_OK); 3424 allow_duplicate_parameters, CHECK_OK);
(...skipping 11 matching lines...) Expand all
3464 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( 3436 FunctionLiteralT function_literal = factory()->NewFunctionLiteral(
3465 this->EmptyIdentifierString(), formal_parameters.scope, body, 3437 this->EmptyIdentifierString(), formal_parameters.scope, body,
3466 materialized_literal_count, expected_property_count, num_parameters, 3438 materialized_literal_count, expected_property_count, num_parameters,
3467 FunctionLiteral::kNoDuplicateParameters, 3439 FunctionLiteral::kNoDuplicateParameters,
3468 FunctionLiteral::kAnonymousExpression, 3440 FunctionLiteral::kAnonymousExpression,
3469 FunctionLiteral::kShouldLazyCompile, arrow_kind, 3441 FunctionLiteral::kShouldLazyCompile, arrow_kind,
3470 formal_parameters.scope->start_position()); 3442 formal_parameters.scope->start_position());
3471 3443
3472 function_literal->set_function_token_position( 3444 function_literal->set_function_token_position(
3473 formal_parameters.scope->start_position()); 3445 formal_parameters.scope->start_position());
3474 if (super_loc.IsValid()) function_state_->set_super_location(super_loc);
3475 3446
3476 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); 3447 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal);
3477 3448
3478 return function_literal; 3449 return function_literal;
3479 } 3450 }
3480 3451
3481 3452
3482 template <typename Traits> 3453 template <typename Traits>
3483 typename ParserBase<Traits>::ExpressionT 3454 typename ParserBase<Traits>::ExpressionT
3484 ParserBase<Traits>::ParseTemplateLiteral(ExpressionT tag, int start, 3455 ParserBase<Traits>::ParseTemplateLiteral(ExpressionT tag, int start,
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
3689 has_seen_constructor_ = true; 3660 has_seen_constructor_ = true;
3690 return; 3661 return;
3691 } 3662 }
3692 } 3663 }
3693 3664
3694 3665
3695 } // namespace internal 3666 } // namespace internal
3696 } // namespace v8 3667 } // namespace v8
3697 3668
3698 #endif // V8_PARSING_PARSER_BASE_H 3669 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW
« no previous file with comments | « src/parsing/parser.cc ('k') | src/parsing/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698