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

Side by Side Diff: src/parser.cc

Issue 1078093002: Factor formal argument parsing into ParserBase (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Created 5 years, 8 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
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/bailout-reason.h" 9 #include "src/bailout-reason.h"
10 #include "src/base/platform/platform.h" 10 #include "src/base/platform/platform.h"
(...skipping 3843 matching lines...) Expand 10 before | Expand all | Expand 10 after
3854 scope_->ForceContextAllocation(); 3854 scope_->ForceContextAllocation();
3855 3855
3856 // Calling a generator returns a generator object. That object is stored 3856 // Calling a generator returns a generator object. That object is stored
3857 // in a temporary variable, a definition that is used by "yield" 3857 // in a temporary variable, a definition that is used by "yield"
3858 // expressions. This also marks the FunctionState as a generator. 3858 // expressions. This also marks the FunctionState as a generator.
3859 Variable* temp = scope_->DeclarationScope()->NewTemporary( 3859 Variable* temp = scope_->DeclarationScope()->NewTemporary(
3860 ast_value_factory()->dot_generator_object_string()); 3860 ast_value_factory()->dot_generator_object_string());
3861 function_state.set_generator_object_variable(temp); 3861 function_state.set_generator_object_variable(temp);
3862 } 3862 }
3863 3863
3864 // FormalParameterList ::
3865 // '(' (Identifier)*[','] ')'
3866 Expect(Token::LPAREN, CHECK_OK);
3867 scope->set_start_position(scanner()->location().beg_pos);
3868
3869 // We don't yet know if the function will be strict, so we cannot yet 3864 // We don't yet know if the function will be strict, so we cannot yet
3870 // produce errors for parameter names or duplicates. However, we remember 3865 // produce errors for parameter names or duplicates. However, we remember
3871 // the locations of these errors if they occur and produce the errors later. 3866 // the locations of these errors if they occur and produce the errors later.
3872 Scanner::Location eval_args_error_loc = Scanner::Location::invalid(); 3867 Scanner::Location eval_args_error_loc = Scanner::Location::invalid();
3873 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); 3868 Scanner::Location dupe_error_loc = Scanner::Location::invalid();
3874 Scanner::Location reserved_error_loc = Scanner::Location::invalid(); 3869 Scanner::Location reserved_error_loc = Scanner::Location::invalid();
3875 3870
3876 bool is_rest = false; 3871 bool has_rest = false;
3877 bool done = arity_restriction == FunctionLiteral::GETTER_ARITY || 3872 Expect(Token::LPAREN, CHECK_OK);
3878 (peek() == Token::RPAREN && 3873 int start_position = scanner()->location().beg_pos;
3879 arity_restriction != FunctionLiteral::SETTER_ARITY); 3874 ZoneList<const AstRawString*>* params =
3880 while (!done) { 3875 ParseFormalParameterList(&eval_args_error_loc, &dupe_error_loc,
3881 bool is_strict_reserved = false; 3876 &reserved_error_loc, &has_rest, CHECK_OK);
3882 is_rest = peek() == Token::ELLIPSIS && allow_harmony_rest_params(); 3877 Expect(Token::RPAREN, CHECK_OK);
3883 if (is_rest) { 3878 int formals_end_position = scanner()->location().end_pos;
3884 Consume(Token::ELLIPSIS);
3885 }
3886 3879
3887 const AstRawString* param_name = 3880 CheckArityRestrictions(params->length(), arity_restriction, start_position,
3888 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); 3881 formals_end_position, CHECK_OK);
3889 3882
3890 // Store locations for possible future error reports. 3883 scope->set_start_position(start_position);
3891 if (!eval_args_error_loc.IsValid() && IsEvalOrArguments(param_name)) {
3892 eval_args_error_loc = scanner()->location();
3893 }
3894 if (!reserved_error_loc.IsValid() && is_strict_reserved) {
3895 reserved_error_loc = scanner()->location();
3896 }
3897 if (!dupe_error_loc.IsValid() &&
3898 scope_->IsDeclaredParameter(param_name)) {
3899 duplicate_parameters = FunctionLiteral::kHasDuplicateParameters;
3900 dupe_error_loc = scanner()->location();
3901 }
3902 3884
3885 num_parameters = params->length();
3886 if (dupe_error_loc.IsValid()) {
3887 duplicate_parameters = FunctionLiteral::kHasDuplicateParameters;
3888 }
3889
3890 for (int i = 0; i < params->length(); i++) {
3891 const AstRawString* param_name = params->at(i);
3892 int is_rest = has_rest && i == params->length() - 1;
3903 Variable* var = scope_->DeclareParameter(param_name, VAR, is_rest); 3893 Variable* var = scope_->DeclareParameter(param_name, VAR, is_rest);
3904 if (is_sloppy(scope->language_mode())) { 3894 if (is_sloppy(scope->language_mode())) {
3905 // TODO(sigurds) Mark every parameter as maybe assigned. This is a 3895 // TODO(sigurds) Mark every parameter as maybe assigned. This is a
3906 // conservative approximation necessary to account for parameters 3896 // conservative approximation necessary to account for parameters
3907 // that are assigned via the arguments array. 3897 // that are assigned via the arguments array.
3908 var->set_maybe_assigned(); 3898 var->set_maybe_assigned();
3909 } 3899 }
3910
3911 num_parameters++;
3912 if (num_parameters > Code::kMaxArguments) {
3913 ReportMessage("too_many_parameters");
3914 *ok = false;
3915 return NULL;
3916 }
3917 if (arity_restriction == FunctionLiteral::SETTER_ARITY) break;
3918 done = (peek() == Token::RPAREN);
3919 if (!done) {
3920 if (is_rest) {
3921 ReportMessageAt(scanner()->peek_location(), "param_after_rest");
3922 *ok = false;
3923 return NULL;
3924 }
3925 Expect(Token::COMMA, CHECK_OK);
3926 }
3927 } 3900 }
3928 Expect(Token::RPAREN, CHECK_OK);
3929 3901
3930 Expect(Token::LBRACE, CHECK_OK); 3902 Expect(Token::LBRACE, CHECK_OK);
3931 3903
3932 // If we have a named function expression, we add a local variable 3904 // If we have a named function expression, we add a local variable
3933 // declaration to the body of the function with the name of the 3905 // declaration to the body of the function with the name of the
3934 // function and let it refer to the function itself (closure). 3906 // function and let it refer to the function itself (closure).
3935 // NOTE: We create a proxy and resolve it here so that in the 3907 // NOTE: We create a proxy and resolve it here so that in the
3936 // future we can change the AST to only refer to VariableProxies 3908 // future we can change the AST to only refer to VariableProxies
3937 // instead of Variables and Proxis as is the case now. 3909 // instead of Variables and Proxis as is the case now.
3938 Variable* fvar = NULL; 3910 Variable* fvar = NULL;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
4000 materialized_literal_count = function_state.materialized_literal_count(); 3972 materialized_literal_count = function_state.materialized_literal_count();
4001 expected_property_count = function_state.expected_property_count(); 3973 expected_property_count = function_state.expected_property_count();
4002 handler_count = function_state.handler_count(); 3974 handler_count = function_state.handler_count();
4003 } 3975 }
4004 3976
4005 // Validate name and parameter names. We can do this only after parsing the 3977 // Validate name and parameter names. We can do this only after parsing the
4006 // function, since the function can declare itself strict. 3978 // function, since the function can declare itself strict.
4007 CheckFunctionName(language_mode(), kind, function_name, 3979 CheckFunctionName(language_mode(), kind, function_name,
4008 name_is_strict_reserved, function_name_location, 3980 name_is_strict_reserved, function_name_location,
4009 CHECK_OK); 3981 CHECK_OK);
4010 const bool use_strict_params = is_rest || IsConciseMethod(kind); 3982 const bool use_strict_params = has_rest || IsConciseMethod(kind);
4011 CheckFunctionParameterNames(language_mode(), use_strict_params, 3983 CheckFunctionParameterNames(language_mode(), use_strict_params,
4012 eval_args_error_loc, dupe_error_loc, 3984 eval_args_error_loc, dupe_error_loc,
4013 reserved_error_loc, CHECK_OK); 3985 reserved_error_loc, CHECK_OK);
4014 3986
4015 if (is_strict(language_mode())) { 3987 if (is_strict(language_mode())) {
4016 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), 3988 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(),
4017 CHECK_OK); 3989 CHECK_OK);
4018 } 3990 }
4019 if (is_strict(language_mode())) { 3991 if (is_strict(language_mode())) {
4020 CheckConflictingVarDeclarations(scope, CHECK_OK); 3992 CheckConflictingVarDeclarations(scope, CHECK_OK);
(...skipping 1714 matching lines...) Expand 10 before | Expand all | Expand 10 after
5735 5707
5736 Expression* Parser::SpreadCallNew(Expression* function, 5708 Expression* Parser::SpreadCallNew(Expression* function,
5737 ZoneList<v8::internal::Expression*>* args, 5709 ZoneList<v8::internal::Expression*>* args,
5738 int pos) { 5710 int pos) {
5739 args->InsertAt(0, function, zone()); 5711 args->InsertAt(0, function, zone());
5740 5712
5741 return factory()->NewCallRuntime( 5713 return factory()->NewCallRuntime(
5742 ast_value_factory()->reflect_construct_string(), NULL, args, pos); 5714 ast_value_factory()->reflect_construct_string(), NULL, args, pos);
5743 } 5715 }
5744 } } // namespace v8::internal 5716 } } // namespace v8::internal
OLDNEW
« src/messages.js ('K') | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698