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

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

Issue 2941643002: Check for a passed-in type argument vector in the prolog of generic functions. (Closed)
Patch Set: Fix lookup in dart:_internal Created 3 years, 6 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 (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 #include "vm/flags.h" 6 #include "vm/flags.h"
7 7
8 #ifndef DART_PRECOMPILED_RUNTIME 8 #ifndef DART_PRECOMPILED_RUNTIME
9 9
10 #include "lib/invocation_mirror.h" 10 #include "lib/invocation_mirror.h"
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 deferred_prefixes_->Add(&LibraryPrefix::ZoneHandle(Z, prefix.raw())); 303 deferred_prefixes_->Add(&LibraryPrefix::ZoneHandle(Z, prefix.raw()));
304 } 304 }
305 305
306 306
307 void ParsedFunction::AllocateVariables() { 307 void ParsedFunction::AllocateVariables() {
308 ASSERT(!function().IsIrregexpFunction()); 308 ASSERT(!function().IsIrregexpFunction());
309 LocalScope* scope = node_sequence()->scope(); 309 LocalScope* scope = node_sequence()->scope();
310 const intptr_t num_fixed_params = function().num_fixed_parameters(); 310 const intptr_t num_fixed_params = function().num_fixed_parameters();
311 const intptr_t num_opt_params = function().NumOptionalParameters(); 311 const intptr_t num_opt_params = function().NumOptionalParameters();
312 const intptr_t num_params = num_fixed_params + num_opt_params; 312 const intptr_t num_params = num_fixed_params + num_opt_params;
313 const intptr_t type_args_slot = function().IsGeneric() ? 1 : 0;
314
313 // Compute start indices to parameters and locals, and the number of 315 // Compute start indices to parameters and locals, and the number of
314 // parameters to copy. 316 // parameters to copy.
315 if (num_opt_params == 0) { 317 if (num_opt_params == 0) {
316 // Parameter i will be at fp[kParamEndSlotFromFp + num_params - i] and 318 // Parameter i will be at fp[kParamEndSlotFromFp + num_params - i] and
317 // local variable j will be at fp[kFirstLocalSlotFromFp - j]. 319 // local variable j will be at fp[kFirstLocalSlotFromFp - j].
318 first_parameter_index_ = kParamEndSlotFromFp + num_params; 320 first_parameter_index_ = kParamEndSlotFromFp + num_params;
319 first_stack_local_index_ = kFirstLocalSlotFromFp; 321 first_stack_local_index_ = kFirstLocalSlotFromFp;
320 num_copied_params_ = 0; 322 num_copied_params_ = 0;
321 } else { 323 } else {
322 // Parameter i will be at fp[kFirstLocalSlotFromFp - i] and local variable 324 // Parameter i will be at fp[kFirstLocalSlotFromFp - i] and local variable
323 // j will be at fp[kFirstLocalSlotFromFp - num_params - j]. 325 // j will be at fp[kFirstLocalSlotFromFp - num_params - j].
324 first_parameter_index_ = kFirstLocalSlotFromFp; 326 first_parameter_index_ = kFirstLocalSlotFromFp;
325 first_stack_local_index_ = first_parameter_index_ - num_params; 327 first_stack_local_index_ = first_parameter_index_ - num_params;
326 num_copied_params_ = num_params; 328 num_copied_params_ = num_params;
327 } 329 }
328 330
329 // Allocate parameters and local variables, either in the local frame or 331 // Allocate parameters and local variables, either in the local frame or
330 // in the context(s). 332 // in the context(s).
331 bool found_captured_variables = false; 333 bool found_captured_variables = false;
332 int next_free_frame_index = scope->AllocateVariables( 334 int next_free_frame_index = scope->AllocateVariables(
333 first_parameter_index_, num_params, first_stack_local_index_, NULL, 335 first_parameter_index_, num_params, type_args_slot,
334 &found_captured_variables); 336 first_stack_local_index_, NULL, &found_captured_variables);
335 337
336 // Frame indices are relative to the frame pointer and are decreasing. 338 // Frame indices are relative to the frame pointer and are decreasing.
337 ASSERT(next_free_frame_index <= first_stack_local_index_); 339 ASSERT(next_free_frame_index <= first_stack_local_index_);
338 num_stack_locals_ = first_stack_local_index_ - next_free_frame_index; 340 num_stack_locals_ = first_stack_local_index_ - next_free_frame_index;
339 } 341 }
340 342
341 343
342 struct CatchParamDesc { 344 struct CatchParamDesc {
343 CatchParamDesc() 345 CatchParamDesc()
344 : token_pos(TokenPosition::kNoSource), 346 : token_pos(TokenPosition::kNoSource),
(...skipping 1451 matching lines...) Expand 10 before | Expand all | Expand 10 after
1796 params.num_optional_parameters++; 1798 params.num_optional_parameters++;
1797 params.has_optional_named_parameters = true; 1799 params.has_optional_named_parameters = true;
1798 } 1800 }
1799 ASSERT(desc.NamedCount() == params.num_optional_parameters); 1801 ASSERT(desc.NamedCount() == params.num_optional_parameters);
1800 1802
1801 SetupDefaultsForOptionalParams(params); 1803 SetupDefaultsForOptionalParams(params);
1802 1804
1803 // Build local scope for function and populate with the formal parameters. 1805 // Build local scope for function and populate with the formal parameters.
1804 OpenFunctionBlock(func); 1806 OpenFunctionBlock(func);
1805 AddFormalParamsToScope(&params, current_block_->scope); 1807 AddFormalParamsToScope(&params, current_block_->scope);
1808
1809 if (desc.TypeArgsLen() > 0) {
1810 ASSERT(func.IsGeneric() && !func.HasGenericParent());
1811 // Insert function type arguments variable to scope.
1812 LocalVariable* type_args_var = new (Z) LocalVariable(
1813 TokenPosition::kNoSource, TokenPosition::kNoSource,
1814 Symbols::FunctionTypeArgumentsVar(), Object::dynamic_type());
1815 current_block_->scope->AddVariable(type_args_var);
1816 ASSERT(FunctionLevel() == 0);
1817 parsed_function_->set_function_type_arguments(type_args_var);
1818 }
1806 } 1819 }
1807 1820
1808 1821
1809 SequenceNode* Parser::ParseNoSuchMethodDispatcher(const Function& func) { 1822 SequenceNode* Parser::ParseNoSuchMethodDispatcher(const Function& func) {
1810 TRACE_PARSER("ParseNoSuchMethodDispatcher"); 1823 TRACE_PARSER("ParseNoSuchMethodDispatcher");
1811 ASSERT(FLAG_lazy_dispatchers); 1824 ASSERT(FLAG_lazy_dispatchers);
1812 ASSERT(func.IsNoSuchMethodDispatcher()); 1825 ASSERT(func.IsNoSuchMethodDispatcher());
1813 TokenPosition token_pos = func.token_pos(); 1826 TokenPosition token_pos = func.token_pos();
1814 ASSERT(func.token_pos() == TokenPosition::kMinSource); 1827 ASSERT(func.token_pos() == TokenPosition::kMinSource);
1815 ASSERT(current_class().raw() == func.Owner()); 1828 ASSERT(current_class().raw() == func.Owner());
1816 1829
1817 ArgumentsDescriptor desc(Array::Handle(Z, func.saved_args_desc())); 1830 ArgumentsDescriptor desc(Array::Handle(Z, func.saved_args_desc()));
1818 ASSERT(desc.Count() > 0); 1831 ASSERT(desc.Count() > 0);
1819 1832
1820 // Set up scope for this function. 1833 // Set up scope for this function.
1821 BuildDispatcherScope(func, desc); 1834 BuildDispatcherScope(func, desc);
1822 1835
1823 // Receiver is local 0. 1836 // Receiver is local 0.
1824 LocalScope* scope = current_block_->scope; 1837 LocalScope* scope = current_block_->scope;
1825 ArgumentListNode* func_args = new ArgumentListNode(token_pos); 1838 ArgumentListNode* func_args = new ArgumentListNode(
1839 token_pos, parsed_function_->function_type_arguments(),
1840 desc.TypeArgsLen());
1826 for (intptr_t i = 0; i < desc.Count(); ++i) { 1841 for (intptr_t i = 0; i < desc.Count(); ++i) {
1827 func_args->Add(new LoadLocalNode(token_pos, scope->VariableAt(i))); 1842 func_args->Add(new LoadLocalNode(token_pos, scope->VariableAt(i)));
1828 } 1843 }
1829 1844
1830 if (desc.NamedCount() > 0) { 1845 if (desc.NamedCount() > 0) {
1831 const Array& arg_names = 1846 const Array& arg_names =
1832 Array::ZoneHandle(Z, Array::New(desc.NamedCount(), Heap::kOld)); 1847 Array::ZoneHandle(Z, Array::New(desc.NamedCount(), Heap::kOld));
1833 for (intptr_t i = 0; i < arg_names.Length(); ++i) { 1848 for (intptr_t i = 0; i < arg_names.Length(); ++i) {
1834 arg_names.SetAt(i, String::Handle(Z, desc.NameAt(i))); 1849 arg_names.SetAt(i, String::Handle(Z, desc.NameAt(i)));
1835 } 1850 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1891 if (owner.raw() == closure_cls.raw() && name.Equals(Symbols::Call())) { 1906 if (owner.raw() == closure_cls.raw() && name.Equals(Symbols::Call())) {
1892 function_object = receiver; 1907 function_object = receiver;
1893 } else { 1908 } else {
1894 const String& getter_name = 1909 const String& getter_name =
1895 String::ZoneHandle(Z, Field::GetterSymbol(name)); 1910 String::ZoneHandle(Z, Field::GetterSymbol(name));
1896 function_object = 1911 function_object =
1897 new (Z) InstanceCallNode(token_pos, receiver, getter_name, no_args); 1912 new (Z) InstanceCallNode(token_pos, receiver, getter_name, no_args);
1898 } 1913 }
1899 1914
1900 // Pass arguments 1..n to the closure call. 1915 // Pass arguments 1..n to the closure call.
1901 ArgumentListNode* args = new (Z) ArgumentListNode(token_pos); 1916 ArgumentListNode* args = new (Z)
1917 ArgumentListNode(token_pos, parsed_function_->function_type_arguments(),
1918 desc.TypeArgsLen());
1902 const Array& names = 1919 const Array& names =
1903 Array::Handle(Z, Array::New(desc.NamedCount(), Heap::kOld)); 1920 Array::Handle(Z, Array::New(desc.NamedCount(), Heap::kOld));
1921
1904 // Positional parameters. 1922 // Positional parameters.
1905 intptr_t i = 1; 1923 intptr_t i = 1;
1906 for (; i < desc.PositionalCount(); ++i) { 1924 for (; i < desc.PositionalCount(); ++i) {
1907 args->Add(new LoadLocalNode(token_pos, scope->VariableAt(i))); 1925 args->Add(new LoadLocalNode(token_pos, scope->VariableAt(i)));
1908 } 1926 }
1909 // Named parameters. 1927 // Named parameters.
1910 for (; i < desc.Count(); i++) { 1928 for (; i < desc.Count(); i++) {
1911 args->Add(new (Z) LoadLocalNode(token_pos, scope->VariableAt(i))); 1929 args->Add(new (Z) LoadLocalNode(token_pos, scope->VariableAt(i)));
1912 intptr_t index = i - desc.PositionalCount(); 1930 intptr_t index = i - desc.PositionalCount();
1913 names.SetAt(index, String::Handle(Z, desc.NameAt(index))); 1931 names.SetAt(index, String::Handle(Z, desc.NameAt(index)));
(...skipping 3777 matching lines...) Expand 10 before | Expand all | Expand 10 after
5691 } 5709 }
5692 types.Add(&AbstractType::ZoneHandle(Z, type.raw())); 5710 types.Add(&AbstractType::ZoneHandle(Z, type.raw()));
5693 } while (CurrentToken() == Token::kCOMMA); 5711 } while (CurrentToken() == Token::kCOMMA);
5694 Token::Kind token = CurrentToken(); 5712 Token::Kind token = CurrentToken();
5695 if ((token == Token::kGT) || (token == Token::kSHR)) { 5713 if ((token == Token::kGT) || (token == Token::kSHR)) {
5696 ConsumeRightAngleBracket(); 5714 ConsumeRightAngleBracket();
5697 } else { 5715 } else {
5698 ReportError("right angle bracket expected"); 5716 ReportError("right angle bracket expected");
5699 } 5717 }
5700 if (finalization != ClassFinalizer::kIgnore) { 5718 if (finalization != ClassFinalizer::kIgnore) {
5701 return NewTypeArguments(types); 5719 TypeArguments& type_args = TypeArguments::Handle(NewTypeArguments(types));
5720 if (finalization == ClassFinalizer::kCanonicalize) {
5721 type_args = type_args.Canonicalize();
5722 }
5723 return type_args.raw();
5702 } 5724 }
5703 } 5725 }
5704 return TypeArguments::null(); 5726 return TypeArguments::null();
5705 } 5727 }
5706 5728
5707 5729
5708 // Parse interface list and add to class cls. 5730 // Parse interface list and add to class cls.
5709 void Parser::ParseInterfaceList(const Class& cls) { 5731 void Parser::ParseInterfaceList(const Class& cls) {
5710 TRACE_PARSER("ParseInterfaceList"); 5732 TRACE_PARSER("ParseInterfaceList");
5711 ASSERT(CurrentToken() == Token::kIMPLEMENTS); 5733 ASSERT(CurrentToken() == Token::kIMPLEMENTS);
(...skipping 6846 matching lines...) Expand 10 before | Expand all | Expand 10 after
12558 } 12580 }
12559 *type = type_parameter.raw(); 12581 *type = type_parameter.raw();
12560 return; 12582 return;
12561 } 12583 }
12562 } 12584 }
12563 } 12585 }
12564 // Resolve type arguments, if any. 12586 // Resolve type arguments, if any.
12565 if (type->arguments() != TypeArguments::null()) { 12587 if (type->arguments() != TypeArguments::null()) {
12566 const TypeArguments& arguments = 12588 const TypeArguments& arguments =
12567 TypeArguments::Handle(Z, type->arguments()); 12589 TypeArguments::Handle(Z, type->arguments());
12568 const intptr_t num_arguments = arguments.Length(); 12590 // Already resolved if canonical.
12569 AbstractType& type_argument = AbstractType::Handle(Z); 12591 if (!arguments.IsCanonical()) {
12570 for (intptr_t i = 0; i < num_arguments; i++) { 12592 const intptr_t num_arguments = arguments.Length();
12571 type_argument = arguments.TypeAt(i); 12593 AbstractType& type_argument = AbstractType::Handle(Z);
12572 ResolveType(&type_argument); 12594 for (intptr_t i = 0; i < num_arguments; i++) {
12573 arguments.SetTypeAt(i, type_argument); 12595 type_argument = arguments.TypeAt(i);
12596 ResolveType(&type_argument);
12597 arguments.SetTypeAt(i, type_argument);
12598 }
12574 } 12599 }
12575 } 12600 }
12576 if (type->IsFunctionType()) { 12601 if (type->IsFunctionType()) {
12577 const Function& signature = 12602 const Function& signature =
12578 Function::Handle(Z, Type::Cast(*type).signature()); 12603 Function::Handle(Z, Type::Cast(*type).signature());
12579 Type& signature_type = Type::Handle(Z, signature.SignatureType()); 12604 Type& signature_type = Type::Handle(Z, signature.SignatureType());
12580 if (signature_type.raw() != type->raw()) { 12605 if (signature_type.raw() != type->raw()) {
12581 ResolveType(&signature_type); 12606 ResolveType(&signature_type);
12582 } else { 12607 } else {
12583 ResolveSignature(signature); 12608 ResolveSignature(signature);
(...skipping 2729 matching lines...) Expand 10 before | Expand all | Expand 10 after
15313 TokenPosition* start, 15338 TokenPosition* start,
15314 TokenPosition* end) { 15339 TokenPosition* end) {
15315 UNREACHABLE(); 15340 UNREACHABLE();
15316 return false; 15341 return false;
15317 } 15342 }
15318 15343
15319 15344
15320 } // namespace dart 15345 } // namespace dart
15321 15346
15322 #endif // DART_PRECOMPILED_RUNTIME 15347 #endif // DART_PRECOMPILED_RUNTIME
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698