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

Side by Side Diff: runtime/vm/parser.cc

Issue 10928160: Limit the maximum number of formal parameters (32K fixed and 32K optional) (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object_test.cc ('k') | runtime/vm/raw_object.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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/parser.h" 5 #include "vm/parser.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/compiler_stats.h" 10 #include "vm/compiler_stats.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 114
115 115
116 void ParsedFunction::SetNodeSequence(SequenceNode* node_sequence) { 116 void ParsedFunction::SetNodeSequence(SequenceNode* node_sequence) {
117 ASSERT(node_sequence_ == NULL); 117 ASSERT(node_sequence_ == NULL);
118 ASSERT(node_sequence != NULL); 118 ASSERT(node_sequence != NULL);
119 node_sequence_ = node_sequence; 119 node_sequence_ = node_sequence;
120 } 120 }
121 121
122 122
123 LocalVariable* ParsedFunction::GetSavedArgumentsDescriptorVar() const { 123 LocalVariable* ParsedFunction::GetSavedArgumentsDescriptorVar() const {
124 const int num_parameters = function().NumberOfParameters(); 124 const int num_parameters = function().NumParameters();
125 LocalScope* scope = node_sequence()->scope(); 125 LocalScope* scope = node_sequence()->scope();
126 if (scope->num_variables() > num_parameters) { 126 if (scope->num_variables() > num_parameters) {
127 LocalVariable* saved_args_desc_var = scope->VariableAt(num_parameters); 127 LocalVariable* saved_args_desc_var = scope->VariableAt(num_parameters);
128 ASSERT(saved_args_desc_var != NULL); 128 ASSERT(saved_args_desc_var != NULL);
129 // The scope of the formal parameters may also contain at this position 129 // The scope of the formal parameters may also contain at this position
130 // an alias for the saved arguments descriptor variable of the enclosing 130 // an alias for the saved arguments descriptor variable of the enclosing
131 // function (check its scope owner) or an internal variable such as the 131 // function (check its scope owner) or an internal variable such as the
132 // expression temp variable or the saved entry context variable (check its 132 // expression temp variable or the saved entry context variable (check its
133 // name). 133 // name).
134 if ((saved_args_desc_var->owner() == scope) && 134 if ((saved_args_desc_var->owner() == scope) &&
135 saved_args_desc_var->name().StartsWith( 135 saved_args_desc_var->name().StartsWith(
136 String::Handle(Symbols::SavedArgDescVarPrefix()))) { 136 String::Handle(Symbols::SavedArgDescVarPrefix()))) {
137 return saved_args_desc_var; 137 return saved_args_desc_var;
138 } 138 }
139 } 139 }
140 return NULL; 140 return NULL;
141 } 141 }
142 142
143 143
144 void ParsedFunction::AllocateVariables() { 144 void ParsedFunction::AllocateVariables() {
145 LocalScope* scope = node_sequence()->scope(); 145 LocalScope* scope = node_sequence()->scope();
146 const intptr_t num_fixed_params = function().num_fixed_parameters(); 146 const intptr_t num_fixed_params = function().num_fixed_parameters();
147 const intptr_t num_opt_pos_params = 147 const intptr_t num_opt_params = function().NumOptionalParameters();
148 function().num_optional_positional_parameters();
149 const intptr_t num_opt_named_params =
150 function().num_optional_named_parameters();
151 const intptr_t num_opt_params = num_opt_pos_params + num_opt_named_params;
152 intptr_t num_params = num_fixed_params + num_opt_params; 148 intptr_t num_params = num_fixed_params + num_opt_params;
153 const bool is_native_instance_closure = 149 const bool is_native_instance_closure =
154 function().is_native() && function().IsImplicitInstanceClosureFunction(); 150 function().is_native() && function().IsImplicitInstanceClosureFunction();
155 // Compute start indices to parameters and locals, and the number of 151 // Compute start indices to parameters and locals, and the number of
156 // parameters to copy. 152 // parameters to copy.
157 if ((num_opt_params == 0) && !is_native_instance_closure) { 153 if ((num_opt_params == 0) && !is_native_instance_closure) {
158 // Parameter i will be at fp[1 + num_params - i] and local variable 154 // Parameter i will be at fp[1 + num_params - i] and local variable
159 // j will be at fp[kFirstLocalSlotIndex - j]. 155 // j will be at fp[kFirstLocalSlotIndex - j].
160 ASSERT(GetSavedArgumentsDescriptorVar() == NULL); 156 ASSERT(GetSavedArgumentsDescriptorVar() == NULL);
161 first_parameter_index_ = 1 + num_params; 157 first_parameter_index_ = 1 + num_params;
(...skipping 1767 matching lines...) Expand 10 before | Expand all | Expand 10 after
1929 &String::ZoneHandle(Symbols::PhaseParameter()), 1925 &String::ZoneHandle(Symbols::PhaseParameter()),
1930 &Type::ZoneHandle(Type::SmiType())); 1926 &Type::ZoneHandle(Type::SmiType()));
1931 1927
1932 if (func.is_const()) { 1928 if (func.is_const()) {
1933 params.SetImplicitlyFinal(); 1929 params.SetImplicitlyFinal();
1934 } 1930 }
1935 ParseFormalParameterList(allow_explicit_default_values, &params); 1931 ParseFormalParameterList(allow_explicit_default_values, &params);
1936 1932
1937 SetupDefaultsForOptionalParams(&params, default_parameter_values); 1933 SetupDefaultsForOptionalParams(&params, default_parameter_values);
1938 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); 1934 ASSERT(AbstractType::Handle(func.result_type()).IsResolved());
1939 ASSERT(func.NumberOfParameters() == params.parameters->length()); 1935 ASSERT(func.NumParameters() == params.parameters->length());
1940 1936
1941 // Now populate function scope with the formal parameters. 1937 // Now populate function scope with the formal parameters.
1942 AddFormalParamsToScope(&params, current_block_->scope); 1938 AddFormalParamsToScope(&params, current_block_->scope);
1943 1939
1944 // Initialize instance fields that have an explicit initializer expression. 1940 // Initialize instance fields that have an explicit initializer expression.
1945 // The formal parameter names must not be visible to the instance 1941 // The formal parameter names must not be visible to the instance
1946 // field initializer expressions, yet the parameters must be added to 1942 // field initializer expressions, yet the parameters must be added to
1947 // the scope so the expressions use the correct offsets for 'this' when 1943 // the scope so the expressions use the correct offsets for 'this' when
1948 // storing values. We make the formal parameters temporarily invisible 1944 // storing values. We make the formal parameters temporarily invisible
1949 // while parsing the instance field initializer expressions. 1945 // while parsing the instance field initializer expressions.
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
2194 } 2190 }
2195 } 2191 }
2196 2192
2197 // The number of parameters and their type are not yet set in local functions, 2193 // The number of parameters and their type are not yet set in local functions,
2198 // since they are not 'top-level' parsed. 2194 // since they are not 'top-level' parsed.
2199 if (func.IsLocalFunction()) { 2195 if (func.IsLocalFunction()) {
2200 AddFormalParamsToFunction(&params, func); 2196 AddFormalParamsToFunction(&params, func);
2201 } 2197 }
2202 SetupDefaultsForOptionalParams(&params, default_parameter_values); 2198 SetupDefaultsForOptionalParams(&params, default_parameter_values);
2203 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); 2199 ASSERT(AbstractType::Handle(func.result_type()).IsResolved());
2204 ASSERT(func.NumberOfParameters() == params.parameters->length()); 2200 ASSERT(func.NumParameters() == params.parameters->length());
2205 2201
2206 // Check whether the function has any field initializer formal parameters, 2202 // Check whether the function has any field initializer formal parameters,
2207 // which are not allowed in non-constructor functions. 2203 // which are not allowed in non-constructor functions.
2208 if (params.has_field_initializer) { 2204 if (params.has_field_initializer) {
2209 for (int i = 0; i < params.parameters->length(); i++) { 2205 for (int i = 0; i < params.parameters->length(); i++) {
2210 ParamDesc& param = (*params.parameters)[i]; 2206 ParamDesc& param = (*params.parameters)[i];
2211 if (param.is_field_initializer) { 2207 if (param.is_field_initializer) {
2212 ErrorMsg(param.name_pos, 2208 ErrorMsg(param.name_pos,
2213 "field initializer only allowed in constructors"); 2209 "field initializer only allowed in constructors");
2214 } 2210 }
(...skipping 2226 matching lines...) Expand 10 before | Expand all | Expand 10 after
4441 4437
4442 4438
4443 // Populate the parameter type array and parameter name array of the function 4439 // Populate the parameter type array and parameter name array of the function
4444 // with the formal parameter types and names. 4440 // with the formal parameter types and names.
4445 void Parser::AddFormalParamsToFunction(const ParamList* params, 4441 void Parser::AddFormalParamsToFunction(const ParamList* params,
4446 const Function& func) { 4442 const Function& func) {
4447 ASSERT((params != NULL) && (params->parameters != NULL)); 4443 ASSERT((params != NULL) && (params->parameters != NULL));
4448 ASSERT((params->num_optional_parameters > 0) == 4444 ASSERT((params->num_optional_parameters > 0) ==
4449 (params->has_optional_positional_parameters || 4445 (params->has_optional_positional_parameters ||
4450 params->has_optional_named_parameters)); 4446 params->has_optional_named_parameters));
4451 func.SetNumberOfParameters(params->num_fixed_parameters, 4447 if (!Utils::IsInt(16, params->num_fixed_parameters) ||
4452 params->num_optional_parameters, 4448 !Utils::IsInt(16, params->num_optional_parameters)) {
4453 params->has_optional_positional_parameters); 4449 ErrorMsg("too many formal parameters");
4450 }
4451 func.set_num_fixed_parameters(params->num_fixed_parameters);
4452 func.SetNumOptionalParameters(params->num_optional_parameters,
4453 params->has_optional_positional_parameters);
4454 const int num_parameters = params->parameters->length(); 4454 const int num_parameters = params->parameters->length();
4455 ASSERT(num_parameters == func.NumberOfParameters()); 4455 ASSERT(num_parameters == func.NumParameters());
4456 func.set_parameter_types(Array::Handle(Array::New(num_parameters, 4456 func.set_parameter_types(Array::Handle(Array::New(num_parameters,
4457 Heap::kOld))); 4457 Heap::kOld)));
4458 func.set_parameter_names(Array::Handle(Array::New(num_parameters, 4458 func.set_parameter_names(Array::Handle(Array::New(num_parameters,
4459 Heap::kOld))); 4459 Heap::kOld)));
4460 for (int i = 0; i < num_parameters; i++) { 4460 for (int i = 0; i < num_parameters; i++) {
4461 ParamDesc& param_desc = (*params->parameters)[i]; 4461 ParamDesc& param_desc = (*params->parameters)[i];
4462 ASSERT(is_top_level_ || param_desc.type->IsResolved()); 4462 ASSERT(is_top_level_ || param_desc.type->IsResolved());
4463 func.SetParameterTypeAt(i, *param_desc.type); 4463 func.SetParameterTypeAt(i, *param_desc.type);
4464 func.SetParameterNameAt(i, *param_desc.name); 4464 func.SetParameterNameAt(i, *param_desc.name);
4465 } 4465 }
(...skipping 3157 matching lines...) Expand 10 before | Expand all | Expand 10 after
7623 // enclosing functions, or a compile error would have prevented the 7623 // enclosing functions, or a compile error would have prevented the
7624 // outermost enclosing function to be executed and we would not be compiling 7624 // outermost enclosing function to be executed and we would not be compiling
7625 // this local function. 7625 // this local function.
7626 // Therefore, look for ident directly in the formal parameter lists of the 7626 // Therefore, look for ident directly in the formal parameter lists of the
7627 // enclosing functions. 7627 // enclosing functions.
7628 // There is no need to return the owner_scope, since the caller will not 7628 // There is no need to return the owner_scope, since the caller will not
7629 // create the saved_arguments_descriptor variable, which already exists. 7629 // create the saved_arguments_descriptor variable, which already exists.
7630 Function& function = Function::Handle(innermost_function().raw()); 7630 Function& function = Function::Handle(innermost_function().raw());
7631 String& param_name = String::Handle(); 7631 String& param_name = String::Handle();
7632 do { 7632 do {
7633 const int num_parameters = function.NumberOfParameters(); 7633 const int num_parameters = function.NumParameters();
7634 for (intptr_t i = 0; i < num_parameters; i++) { 7634 for (intptr_t i = 0; i < num_parameters; i++) {
7635 param_name = function.ParameterNameAt(i); 7635 param_name = function.ParameterNameAt(i);
7636 if (ident.Equals(param_name)) { 7636 if (ident.Equals(param_name)) {
7637 *owner_function = function.raw(); 7637 *owner_function = function.raw();
7638 *owner_scope = NULL; 7638 *owner_scope = NULL;
7639 *local_index = i; 7639 *local_index = i;
7640 return true; 7640 return true;
7641 } 7641 }
7642 } 7642 }
7643 function = function.parent_function(); 7643 function = function.parent_function();
7644 } while (!function.IsNull()); 7644 } while (!function.IsNull());
7645 UNREACHABLE(); 7645 UNREACHABLE();
7646 } 7646 }
7647 // Verify that local is a formal parameter of the current function or of one 7647 // Verify that local is a formal parameter of the current function or of one
7648 // of its enclosing functions. 7648 // of its enclosing functions.
7649 // Note that scopes are not yet associated to functions. 7649 // Note that scopes are not yet associated to functions.
7650 Function& function = Function::Handle(innermost_function().raw()); 7650 Function& function = Function::Handle(innermost_function().raw());
7651 LocalScope* scope = current_block_->scope; 7651 LocalScope* scope = current_block_->scope;
7652 while (scope != NULL) { 7652 while (scope != NULL) {
7653 ASSERT(!function.IsNull()); 7653 ASSERT(!function.IsNull());
7654 // Find the top scope for this function level. 7654 // Find the top scope for this function level.
7655 while ((scope->parent() != NULL) && 7655 while ((scope->parent() != NULL) &&
7656 (scope->parent()->function_level() == scope->function_level())) { 7656 (scope->parent()->function_level() == scope->function_level())) {
7657 scope = scope->parent(); 7657 scope = scope->parent();
7658 } 7658 }
7659 if (scope == local->owner()) { 7659 if (scope == local->owner()) {
7660 // Scope contains 'local' and the formal parameters of 'function'. 7660 // Scope contains 'local' and the formal parameters of 'function'.
7661 const int num_parameters = function.NumberOfParameters(); 7661 const int num_parameters = function.NumParameters();
7662 for (intptr_t i = 0; i < num_parameters; i++) { 7662 for (intptr_t i = 0; i < num_parameters; i++) {
7663 if (scope->VariableAt(i) == local) { 7663 if (scope->VariableAt(i) == local) {
7664 *owner_function = function.raw(); 7664 *owner_function = function.raw();
7665 *owner_scope = scope; 7665 *owner_scope = scope;
7666 *local_index = i; 7666 *local_index = i;
7667 return true; 7667 return true;
7668 } 7668 }
7669 } 7669 }
7670 // The variable 'local' is not a formal parameter. 7670 // The variable 'local' is not a formal parameter.
7671 return false; 7671 return false;
(...skipping 1436 matching lines...) Expand 10 before | Expand all | Expand 10 after
9108 ASSERT(owner_scope != NULL); 9108 ASSERT(owner_scope != NULL);
9109 saved_args_desc_var = 9109 saved_args_desc_var =
9110 new LocalVariable(owner_function.token_pos(), 9110 new LocalVariable(owner_function.token_pos(),
9111 saved_args_desc_name, 9111 saved_args_desc_name,
9112 Type::ZoneHandle(Type::ListInterface())); 9112 Type::ZoneHandle(Type::ListInterface()));
9113 saved_args_desc_var->set_is_final(); 9113 saved_args_desc_var->set_is_final();
9114 // The saved arguments descriptor variable must be added just after the 9114 // The saved arguments descriptor variable must be added just after the
9115 // formal parameters. This simplifies the 2-step saving of a captured 9115 // formal parameters. This simplifies the 2-step saving of a captured
9116 // arguments descriptor. 9116 // arguments descriptor.
9117 // At this time, the owner scope should only contain formal parameters. 9117 // At this time, the owner scope should only contain formal parameters.
9118 ASSERT(owner_scope->num_variables() == owner_function.NumberOfParameters()); 9118 ASSERT(owner_scope->num_variables() == owner_function.NumParameters());
9119 bool success = owner_scope->AddVariable(saved_args_desc_var); 9119 bool success = owner_scope->AddVariable(saved_args_desc_var);
9120 ASSERT(success); 9120 ASSERT(success);
9121 // Capture the saved argument descriptor variable if necessary. 9121 // Capture the saved argument descriptor variable if necessary.
9122 LocalVariable* local = LookupLocalScope(saved_args_desc_name); 9122 LocalVariable* local = LookupLocalScope(saved_args_desc_name);
9123 ASSERT(local == saved_args_desc_var); 9123 ASSERT(local == saved_args_desc_var);
9124 } 9124 }
9125 // If we currently generate code for the local function of an enclosing owner 9125 // If we currently generate code for the local function of an enclosing owner
9126 // function, the saved arguments descriptor variable must have been captured 9126 // function, the saved arguments descriptor variable must have been captured
9127 // by the above lookup. 9127 // by the above lookup.
9128 ASSERT((owner_function.raw() == innermost_function().raw()) || 9128 ASSERT((owner_function.raw() == innermost_function().raw()) ||
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
9557 void Parser::SkipQualIdent() { 9557 void Parser::SkipQualIdent() {
9558 ASSERT(IsIdentifier()); 9558 ASSERT(IsIdentifier());
9559 ConsumeToken(); 9559 ConsumeToken();
9560 if (CurrentToken() == Token::kPERIOD) { 9560 if (CurrentToken() == Token::kPERIOD) {
9561 ConsumeToken(); // Consume the kPERIOD token. 9561 ConsumeToken(); // Consume the kPERIOD token.
9562 ExpectIdentifier("identifier expected after '.'"); 9562 ExpectIdentifier("identifier expected after '.'");
9563 } 9563 }
9564 } 9564 }
9565 9565
9566 } // namespace dart 9566 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object_test.cc ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698