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

Side by Side Diff: src/parser.cc

Issue 1259013003: [es6] Refactor FormalParameter (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Comments Created 5 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 unified diff | Download patch
« no previous file with comments | « src/parser.h ('k') | src/preparser.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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/ast-literal-reindexer.h" 9 #include "src/ast-literal-reindexer.h"
10 #include "src/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 DCHECK(!info->script().is_null() || info->source_stream() != NULL); 910 DCHECK(!info->script().is_null() || info->source_stream() != NULL);
911 set_allow_lazy(info->allow_lazy_parsing()); 911 set_allow_lazy(info->allow_lazy_parsing());
912 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); 912 set_allow_natives(FLAG_allow_natives_syntax || info->is_native());
913 set_allow_harmony_modules(!info->is_native() && FLAG_harmony_modules); 913 set_allow_harmony_modules(!info->is_native() && FLAG_harmony_modules);
914 set_allow_harmony_arrow_functions(FLAG_harmony_arrow_functions); 914 set_allow_harmony_arrow_functions(FLAG_harmony_arrow_functions);
915 set_allow_harmony_sloppy(FLAG_harmony_sloppy); 915 set_allow_harmony_sloppy(FLAG_harmony_sloppy);
916 set_allow_harmony_sloppy_let(FLAG_harmony_sloppy_let); 916 set_allow_harmony_sloppy_let(FLAG_harmony_sloppy_let);
917 set_allow_harmony_unicode(FLAG_harmony_unicode); 917 set_allow_harmony_unicode(FLAG_harmony_unicode);
918 set_allow_harmony_computed_property_names( 918 set_allow_harmony_computed_property_names(
919 FLAG_harmony_computed_property_names); 919 FLAG_harmony_computed_property_names);
920 set_allow_harmony_rest_params(FLAG_harmony_rest_parameters); 920 set_allow_harmony_rest_parameters(FLAG_harmony_rest_parameters);
921 set_allow_harmony_spreadcalls(FLAG_harmony_spreadcalls); 921 set_allow_harmony_spreadcalls(FLAG_harmony_spreadcalls);
922 set_allow_harmony_destructuring(FLAG_harmony_destructuring); 922 set_allow_harmony_destructuring(FLAG_harmony_destructuring);
923 set_allow_harmony_spread_arrays(FLAG_harmony_spread_arrays); 923 set_allow_harmony_spread_arrays(FLAG_harmony_spread_arrays);
924 set_allow_harmony_new_target(FLAG_harmony_new_target); 924 set_allow_harmony_new_target(FLAG_harmony_new_target);
925 set_allow_strong_mode(FLAG_strong_mode); 925 set_allow_strong_mode(FLAG_strong_mode);
926 set_allow_legacy_const(FLAG_legacy_const); 926 set_allow_legacy_const(FLAG_legacy_const);
927 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; 927 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount;
928 ++feature) { 928 ++feature) {
929 use_counts_[feature] = 0; 929 use_counts_[feature] = 0;
930 } 930 }
(...skipping 2916 matching lines...) Expand 10 before | Expand all | Expand 10 after
3847 3847
3848 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { 3848 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) {
3849 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); 3849 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot)));
3850 } 3850 }
3851 3851
3852 3852
3853 void ParserTraits::ParseArrowFunctionFormalParameters( 3853 void ParserTraits::ParseArrowFunctionFormalParameters(
3854 ParserFormalParameters* parameters, Expression* expr, 3854 ParserFormalParameters* parameters, Expression* expr,
3855 const Scanner::Location& params_loc, 3855 const Scanner::Location& params_loc,
3856 Scanner::Location* duplicate_loc, bool* ok) { 3856 Scanner::Location* duplicate_loc, bool* ok) {
3857 if (parameters->scope->num_parameters() >= Code::kMaxArguments) { 3857 if (parameters->arity >= Code::kMaxArguments) {
3858 ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList); 3858 ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList);
3859 *ok = false; 3859 *ok = false;
3860 return; 3860 return;
3861 } 3861 }
3862 3862
3863 // ArrowFunctionFormals :: 3863 // ArrowFunctionFormals ::
3864 // Binary(Token::COMMA, NonTailArrowFunctionFormals, Tail) 3864 // Binary(Token::COMMA, NonTailArrowFunctionFormals, Tail)
3865 // Tail 3865 // Tail
3866 // NonTailArrowFunctionFormals :: 3866 // NonTailArrowFunctionFormals ::
3867 // Binary(Token::COMMA, NonTailArrowFunctionFormals, VariableProxy) 3867 // Binary(Token::COMMA, NonTailArrowFunctionFormals, VariableProxy)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
3901 3901
3902 if (expr->IsVariableProxy()) { 3902 if (expr->IsVariableProxy()) {
3903 // When the formal parameter was originally seen, it was parsed as a 3903 // When the formal parameter was originally seen, it was parsed as a
3904 // VariableProxy and recorded as unresolved in the scope. Here we undo that 3904 // VariableProxy and recorded as unresolved in the scope. Here we undo that
3905 // parse-time side-effect for parameters that are single-names (not 3905 // parse-time side-effect for parameters that are single-names (not
3906 // patterns; for patterns that happens uniformly in 3906 // patterns; for patterns that happens uniformly in
3907 // PatternRewriter::VisitVariableProxy). 3907 // PatternRewriter::VisitVariableProxy).
3908 parser_->scope_->RemoveUnresolved(expr->AsVariableProxy()); 3908 parser_->scope_->RemoveUnresolved(expr->AsVariableProxy());
3909 } 3909 }
3910 3910
3911 ++parameters->arity;
3911 ExpressionClassifier classifier; 3912 ExpressionClassifier classifier;
3912 DeclareFormalParameter(parameters, expr, is_rest, &classifier); 3913 DeclareFormalParameter(parameters, expr, is_rest, &classifier);
3913 if (!duplicate_loc->IsValid()) { 3914 if (!duplicate_loc->IsValid()) {
3914 *duplicate_loc = classifier.duplicate_formal_parameter_error().location; 3915 *duplicate_loc = classifier.duplicate_formal_parameter_error().location;
3915 } 3916 }
3916 } 3917 }
3917 3918
3918 3919
3919 void ParserTraits::ReindexLiterals(const ParserFormalParameters& parameters) { 3920 void ParserTraits::ReindexLiterals(const ParserFormalParameters& parameters) {
3920 if (parser_->function_state_->materialized_literal_count() > 0) { 3921 if (parser_->function_state_->materialized_literal_count() > 0) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
3989 Scope* declaration_scope = scope_->DeclarationScope(); 3990 Scope* declaration_scope = scope_->DeclarationScope();
3990 Scope* original_declaration_scope = original_scope_->DeclarationScope(); 3991 Scope* original_declaration_scope = original_scope_->DeclarationScope();
3991 Scope* scope = function_type == FunctionLiteral::DECLARATION && 3992 Scope* scope = function_type == FunctionLiteral::DECLARATION &&
3992 is_sloppy(language_mode) && !allow_harmony_sloppy() && 3993 is_sloppy(language_mode) && !allow_harmony_sloppy() &&
3993 (original_scope_ == original_declaration_scope || 3994 (original_scope_ == original_declaration_scope ||
3994 declaration_scope != original_declaration_scope) 3995 declaration_scope != original_declaration_scope)
3995 ? NewScope(declaration_scope, FUNCTION_SCOPE, kind) 3996 ? NewScope(declaration_scope, FUNCTION_SCOPE, kind)
3996 : NewScope(scope_, FUNCTION_SCOPE, kind); 3997 : NewScope(scope_, FUNCTION_SCOPE, kind);
3997 scope->SetLanguageMode(language_mode); 3998 scope->SetLanguageMode(language_mode);
3998 ZoneList<Statement*>* body = NULL; 3999 ZoneList<Statement*>* body = NULL;
3999 int arity = 0; 4000 int arity = -1;
4000 int materialized_literal_count = -1; 4001 int materialized_literal_count = -1;
4001 int expected_property_count = -1; 4002 int expected_property_count = -1;
4002 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); 4003 DuplicateFinder duplicate_finder(scanner()->unicode_cache());
4003 ExpressionClassifier formals_classifier(&duplicate_finder); 4004 ExpressionClassifier formals_classifier(&duplicate_finder);
4004 FunctionLiteral::EagerCompileHint eager_compile_hint = 4005 FunctionLiteral::EagerCompileHint eager_compile_hint =
4005 parenthesized_function_ ? FunctionLiteral::kShouldEagerCompile 4006 parenthesized_function_ ? FunctionLiteral::kShouldEagerCompile
4006 : FunctionLiteral::kShouldLazyCompile; 4007 : FunctionLiteral::kShouldLazyCompile;
4007 bool should_be_used_once_hint = false; 4008 bool should_be_used_once_hint = false;
4008 // Parse function. 4009 // Parse function.
4009 { 4010 {
(...skipping 13 matching lines...) Expand all
4023 // expressions. This also marks the FunctionState as a generator. 4024 // expressions. This also marks the FunctionState as a generator.
4024 Variable* temp = scope_->NewTemporary( 4025 Variable* temp = scope_->NewTemporary(
4025 ast_value_factory()->dot_generator_object_string()); 4026 ast_value_factory()->dot_generator_object_string());
4026 function_state.set_generator_object_variable(temp); 4027 function_state.set_generator_object_variable(temp);
4027 } 4028 }
4028 4029
4029 Expect(Token::LPAREN, CHECK_OK); 4030 Expect(Token::LPAREN, CHECK_OK);
4030 int start_position = scanner()->location().beg_pos; 4031 int start_position = scanner()->location().beg_pos;
4031 scope_->set_start_position(start_position); 4032 scope_->set_start_position(start_position);
4032 ParserFormalParameters formals(scope); 4033 ParserFormalParameters formals(scope);
4033 arity = ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK); 4034 ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK);
4035 arity = formals.arity;
4036 DCHECK(arity == formals.params.length());
4034 Expect(Token::RPAREN, CHECK_OK); 4037 Expect(Token::RPAREN, CHECK_OK);
4035 int formals_end_position = scanner()->location().end_pos; 4038 int formals_end_position = scanner()->location().end_pos;
4036 4039
4037 CheckArityRestrictions(arity, arity_restriction, 4040 CheckArityRestrictions(arity, arity_restriction,
4038 formals.has_rest, start_position, 4041 formals.has_rest, start_position,
4039 formals_end_position, CHECK_OK); 4042 formals_end_position, CHECK_OK);
4040 Expect(Token::LBRACE, CHECK_OK); 4043 Expect(Token::LBRACE, CHECK_OK);
4041 4044
4042 // Determine if the function can be parsed lazily. Lazy parsing is different 4045 // Determine if the function can be parsed lazily. Lazy parsing is different
4043 // from lazy compilation; we need to parse more eagerly than we compile. 4046 // from lazy compilation; we need to parse more eagerly than we compile.
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
4287 return if_statement; 4290 return if_statement;
4288 } 4291 }
4289 4292
4290 4293
4291 Block* Parser::BuildParameterInitializationBlock( 4294 Block* Parser::BuildParameterInitializationBlock(
4292 const ParserFormalParameters& parameters, bool* ok) { 4295 const ParserFormalParameters& parameters, bool* ok) {
4293 DCHECK(!parameters.is_simple); 4296 DCHECK(!parameters.is_simple);
4294 DCHECK(scope_->is_function_scope()); 4297 DCHECK(scope_->is_function_scope());
4295 Block* init_block = 4298 Block* init_block =
4296 factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition); 4299 factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition);
4297 for (auto parameter : parameters.params) { 4300 for (int i = 0; i < parameters.params.length(); ++i) {
4301 auto parameter = parameters.params[i];
4298 if (parameter.pattern == nullptr) continue; 4302 if (parameter.pattern == nullptr) continue;
4299 DeclarationDescriptor descriptor; 4303 DeclarationDescriptor descriptor;
4300 descriptor.declaration_kind = DeclarationDescriptor::PARAMETER; 4304 descriptor.declaration_kind = DeclarationDescriptor::PARAMETER;
4301 descriptor.parser = this; 4305 descriptor.parser = this;
4302 descriptor.declaration_scope = scope_; 4306 descriptor.declaration_scope = scope_;
4303 descriptor.scope = scope_; 4307 descriptor.scope = scope_;
4304 descriptor.mode = LET; 4308 descriptor.mode = LET;
4305 descriptor.is_const = false; 4309 descriptor.is_const = false;
4306 descriptor.needs_init = true; 4310 descriptor.needs_init = true;
4307 descriptor.declaration_pos = parameter.pattern->position(); 4311 descriptor.declaration_pos = parameter.pattern->position();
4308 descriptor.initialization_pos = parameter.pattern->position(); 4312 descriptor.initialization_pos = parameter.pattern->position();
4309 descriptor.init_op = Token::INIT_LET; 4313 descriptor.init_op = Token::INIT_LET;
4310 DeclarationParsingResult::Declaration decl( 4314 DeclarationParsingResult::Declaration decl(
4311 parameter.pattern, parameter.pattern->position(), 4315 parameter.pattern, parameter.pattern->position(),
4312 factory()->NewVariableProxy(parameter.var)); 4316 factory()->NewVariableProxy(parameters.scope->parameter(i)));
4313 PatternRewriter::DeclareAndInitializeVariables(init_block, &descriptor, 4317 PatternRewriter::DeclareAndInitializeVariables(init_block, &descriptor,
4314 &decl, nullptr, CHECK_OK); 4318 &decl, nullptr, CHECK_OK);
4315 } 4319 }
4316 return init_block; 4320 return init_block;
4317 } 4321 }
4318 4322
4319 4323
4320 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( 4324 ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
4321 const AstRawString* function_name, int pos, 4325 const AstRawString* function_name, int pos,
4322 const ParserFormalParameters& parameters, FunctionKind kind, 4326 const ParserFormalParameters& parameters, FunctionKind kind,
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
4470 NULL, stack_limit_); 4474 NULL, stack_limit_);
4471 reusable_preparser_->set_allow_lazy(true); 4475 reusable_preparser_->set_allow_lazy(true);
4472 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); 4476 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name());
4473 SET_ALLOW(natives); 4477 SET_ALLOW(natives);
4474 SET_ALLOW(harmony_modules); 4478 SET_ALLOW(harmony_modules);
4475 SET_ALLOW(harmony_arrow_functions); 4479 SET_ALLOW(harmony_arrow_functions);
4476 SET_ALLOW(harmony_sloppy); 4480 SET_ALLOW(harmony_sloppy);
4477 SET_ALLOW(harmony_sloppy_let); 4481 SET_ALLOW(harmony_sloppy_let);
4478 SET_ALLOW(harmony_unicode); 4482 SET_ALLOW(harmony_unicode);
4479 SET_ALLOW(harmony_computed_property_names); 4483 SET_ALLOW(harmony_computed_property_names);
4480 SET_ALLOW(harmony_rest_params); 4484 SET_ALLOW(harmony_rest_parameters);
4481 SET_ALLOW(harmony_spreadcalls); 4485 SET_ALLOW(harmony_spreadcalls);
4482 SET_ALLOW(harmony_destructuring); 4486 SET_ALLOW(harmony_destructuring);
4483 SET_ALLOW(harmony_spread_arrays); 4487 SET_ALLOW(harmony_spread_arrays);
4484 SET_ALLOW(harmony_new_target); 4488 SET_ALLOW(harmony_new_target);
4485 SET_ALLOW(strong_mode); 4489 SET_ALLOW(strong_mode);
4486 #undef SET_ALLOW 4490 #undef SET_ALLOW
4487 } 4491 }
4488 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( 4492 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction(
4489 language_mode(), function_state_->kind(), logger, bookmark); 4493 language_mode(), function_state_->kind(), logger, bookmark);
4490 if (pre_parse_timer_ != NULL) { 4494 if (pre_parse_timer_ != NULL) {
(...skipping 1505 matching lines...) Expand 10 before | Expand all | Expand 10 after
5996 Expression* Parser::SpreadCallNew(Expression* function, 6000 Expression* Parser::SpreadCallNew(Expression* function,
5997 ZoneList<v8::internal::Expression*>* args, 6001 ZoneList<v8::internal::Expression*>* args,
5998 int pos) { 6002 int pos) {
5999 args->InsertAt(0, function, zone()); 6003 args->InsertAt(0, function, zone());
6000 6004
6001 return factory()->NewCallRuntime( 6005 return factory()->NewCallRuntime(
6002 ast_value_factory()->reflect_construct_string(), NULL, args, pos); 6006 ast_value_factory()->reflect_construct_string(), NULL, args, pos);
6003 } 6007 }
6004 } // namespace internal 6008 } // namespace internal
6005 } // namespace v8 6009 } // namespace v8
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698