OLD | NEW |
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 1785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1796 params.num_optional_parameters++; | 1796 params.num_optional_parameters++; |
1797 params.has_optional_named_parameters = true; | 1797 params.has_optional_named_parameters = true; |
1798 } | 1798 } |
1799 ASSERT(desc.NamedCount() == params.num_optional_parameters); | 1799 ASSERT(desc.NamedCount() == params.num_optional_parameters); |
1800 | 1800 |
1801 SetupDefaultsForOptionalParams(params); | 1801 SetupDefaultsForOptionalParams(params); |
1802 | 1802 |
1803 // Build local scope for function and populate with the formal parameters. | 1803 // Build local scope for function and populate with the formal parameters. |
1804 OpenFunctionBlock(func); | 1804 OpenFunctionBlock(func); |
1805 AddFormalParamsToScope(¶ms, current_block_->scope); | 1805 AddFormalParamsToScope(¶ms, current_block_->scope); |
| 1806 |
| 1807 if (desc.TypeArgsLen() > 0) { |
| 1808 ASSERT(func.IsGeneric() && !func.HasGenericParent()); |
| 1809 // Insert function type arguments variable to scope. |
| 1810 LocalVariable* type_args_var = new (Z) LocalVariable( |
| 1811 TokenPosition::kNoSource, TokenPosition::kNoSource, |
| 1812 Symbols::FunctionTypeArgumentsVar(), Object::dynamic_type()); |
| 1813 current_block_->scope->AddVariable(type_args_var); |
| 1814 ASSERT(FunctionLevel() == 0); |
| 1815 parsed_function_->set_function_type_arguments(type_args_var); |
| 1816 } |
1806 } | 1817 } |
1807 | 1818 |
1808 | 1819 |
1809 SequenceNode* Parser::ParseNoSuchMethodDispatcher(const Function& func) { | 1820 SequenceNode* Parser::ParseNoSuchMethodDispatcher(const Function& func) { |
1810 TRACE_PARSER("ParseNoSuchMethodDispatcher"); | 1821 TRACE_PARSER("ParseNoSuchMethodDispatcher"); |
1811 ASSERT(FLAG_lazy_dispatchers); | 1822 ASSERT(FLAG_lazy_dispatchers); |
1812 ASSERT(func.IsNoSuchMethodDispatcher()); | 1823 ASSERT(func.IsNoSuchMethodDispatcher()); |
1813 TokenPosition token_pos = func.token_pos(); | 1824 TokenPosition token_pos = func.token_pos(); |
1814 ASSERT(func.token_pos() == TokenPosition::kMinSource); | 1825 ASSERT(func.token_pos() == TokenPosition::kMinSource); |
1815 ASSERT(current_class().raw() == func.Owner()); | 1826 ASSERT(current_class().raw() == func.Owner()); |
1816 | 1827 |
1817 ArgumentsDescriptor desc(Array::Handle(Z, func.saved_args_desc())); | 1828 ArgumentsDescriptor desc(Array::Handle(Z, func.saved_args_desc())); |
1818 ASSERT(desc.Count() > 0); | 1829 ASSERT(desc.Count() > 0); |
1819 | 1830 |
1820 // Set up scope for this function. | 1831 // Set up scope for this function. |
1821 BuildDispatcherScope(func, desc); | 1832 BuildDispatcherScope(func, desc); |
1822 | 1833 |
1823 // Receiver is local 0. | 1834 // Receiver is local 0. |
1824 LocalScope* scope = current_block_->scope; | 1835 LocalScope* scope = current_block_->scope; |
1825 ArgumentListNode* func_args = new ArgumentListNode(token_pos); | 1836 ArgumentListNode* func_args = new ArgumentListNode( |
| 1837 token_pos, parsed_function_->function_type_arguments(), |
| 1838 desc.TypeArgsLen()); |
1826 for (intptr_t i = 0; i < desc.Count(); ++i) { | 1839 for (intptr_t i = 0; i < desc.Count(); ++i) { |
1827 func_args->Add(new LoadLocalNode(token_pos, scope->VariableAt(i))); | 1840 func_args->Add(new LoadLocalNode(token_pos, scope->VariableAt(i))); |
1828 } | 1841 } |
1829 | 1842 |
1830 if (desc.NamedCount() > 0) { | 1843 if (desc.NamedCount() > 0) { |
1831 const Array& arg_names = | 1844 const Array& arg_names = |
1832 Array::ZoneHandle(Z, Array::New(desc.NamedCount(), Heap::kOld)); | 1845 Array::ZoneHandle(Z, Array::New(desc.NamedCount(), Heap::kOld)); |
1833 for (intptr_t i = 0; i < arg_names.Length(); ++i) { | 1846 for (intptr_t i = 0; i < arg_names.Length(); ++i) { |
1834 arg_names.SetAt(i, String::Handle(Z, desc.NameAt(i))); | 1847 arg_names.SetAt(i, String::Handle(Z, desc.NameAt(i))); |
1835 } | 1848 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1891 if (owner.raw() == closure_cls.raw() && name.Equals(Symbols::Call())) { | 1904 if (owner.raw() == closure_cls.raw() && name.Equals(Symbols::Call())) { |
1892 function_object = receiver; | 1905 function_object = receiver; |
1893 } else { | 1906 } else { |
1894 const String& getter_name = | 1907 const String& getter_name = |
1895 String::ZoneHandle(Z, Field::GetterSymbol(name)); | 1908 String::ZoneHandle(Z, Field::GetterSymbol(name)); |
1896 function_object = | 1909 function_object = |
1897 new (Z) InstanceCallNode(token_pos, receiver, getter_name, no_args); | 1910 new (Z) InstanceCallNode(token_pos, receiver, getter_name, no_args); |
1898 } | 1911 } |
1899 | 1912 |
1900 // Pass arguments 1..n to the closure call. | 1913 // Pass arguments 1..n to the closure call. |
1901 ArgumentListNode* args = new (Z) ArgumentListNode(token_pos); | 1914 ArgumentListNode* args = new (Z) |
| 1915 ArgumentListNode(token_pos, parsed_function_->function_type_arguments(), |
| 1916 desc.TypeArgsLen()); |
1902 const Array& names = | 1917 const Array& names = |
1903 Array::Handle(Z, Array::New(desc.NamedCount(), Heap::kOld)); | 1918 Array::Handle(Z, Array::New(desc.NamedCount(), Heap::kOld)); |
| 1919 |
1904 // Positional parameters. | 1920 // Positional parameters. |
1905 intptr_t i = 1; | 1921 intptr_t i = 1; |
1906 for (; i < desc.PositionalCount(); ++i) { | 1922 for (; i < desc.PositionalCount(); ++i) { |
1907 args->Add(new LoadLocalNode(token_pos, scope->VariableAt(i))); | 1923 args->Add(new LoadLocalNode(token_pos, scope->VariableAt(i))); |
1908 } | 1924 } |
1909 // Named parameters. | 1925 // Named parameters. |
1910 for (; i < desc.Count(); i++) { | 1926 for (; i < desc.Count(); i++) { |
1911 args->Add(new (Z) LoadLocalNode(token_pos, scope->VariableAt(i))); | 1927 args->Add(new (Z) LoadLocalNode(token_pos, scope->VariableAt(i))); |
1912 intptr_t index = i - desc.PositionalCount(); | 1928 intptr_t index = i - desc.PositionalCount(); |
1913 names.SetAt(index, String::Handle(Z, desc.NameAt(index))); | 1929 names.SetAt(index, String::Handle(Z, desc.NameAt(index))); |
(...skipping 3777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5691 } | 5707 } |
5692 types.Add(&AbstractType::ZoneHandle(Z, type.raw())); | 5708 types.Add(&AbstractType::ZoneHandle(Z, type.raw())); |
5693 } while (CurrentToken() == Token::kCOMMA); | 5709 } while (CurrentToken() == Token::kCOMMA); |
5694 Token::Kind token = CurrentToken(); | 5710 Token::Kind token = CurrentToken(); |
5695 if ((token == Token::kGT) || (token == Token::kSHR)) { | 5711 if ((token == Token::kGT) || (token == Token::kSHR)) { |
5696 ConsumeRightAngleBracket(); | 5712 ConsumeRightAngleBracket(); |
5697 } else { | 5713 } else { |
5698 ReportError("right angle bracket expected"); | 5714 ReportError("right angle bracket expected"); |
5699 } | 5715 } |
5700 if (finalization != ClassFinalizer::kIgnore) { | 5716 if (finalization != ClassFinalizer::kIgnore) { |
5701 return NewTypeArguments(types); | 5717 TypeArguments& type_args = TypeArguments::Handle(NewTypeArguments(types)); |
| 5718 if (finalization == ClassFinalizer::kCanonicalize) { |
| 5719 type_args = type_args.Canonicalize(); |
| 5720 } |
| 5721 return type_args.raw(); |
5702 } | 5722 } |
5703 } | 5723 } |
5704 return TypeArguments::null(); | 5724 return TypeArguments::null(); |
5705 } | 5725 } |
5706 | 5726 |
5707 | 5727 |
5708 // Parse interface list and add to class cls. | 5728 // Parse interface list and add to class cls. |
5709 void Parser::ParseInterfaceList(const Class& cls) { | 5729 void Parser::ParseInterfaceList(const Class& cls) { |
5710 TRACE_PARSER("ParseInterfaceList"); | 5730 TRACE_PARSER("ParseInterfaceList"); |
5711 ASSERT(CurrentToken() == Token::kIMPLEMENTS); | 5731 ASSERT(CurrentToken() == Token::kIMPLEMENTS); |
(...skipping 6846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12558 } | 12578 } |
12559 *type = type_parameter.raw(); | 12579 *type = type_parameter.raw(); |
12560 return; | 12580 return; |
12561 } | 12581 } |
12562 } | 12582 } |
12563 } | 12583 } |
12564 // Resolve type arguments, if any. | 12584 // Resolve type arguments, if any. |
12565 if (type->arguments() != TypeArguments::null()) { | 12585 if (type->arguments() != TypeArguments::null()) { |
12566 const TypeArguments& arguments = | 12586 const TypeArguments& arguments = |
12567 TypeArguments::Handle(Z, type->arguments()); | 12587 TypeArguments::Handle(Z, type->arguments()); |
12568 const intptr_t num_arguments = arguments.Length(); | 12588 // Already resolved if canonical. |
12569 AbstractType& type_argument = AbstractType::Handle(Z); | 12589 if (!arguments.IsCanonical()) { |
12570 for (intptr_t i = 0; i < num_arguments; i++) { | 12590 const intptr_t num_arguments = arguments.Length(); |
12571 type_argument = arguments.TypeAt(i); | 12591 AbstractType& type_argument = AbstractType::Handle(Z); |
12572 ResolveType(&type_argument); | 12592 for (intptr_t i = 0; i < num_arguments; i++) { |
12573 arguments.SetTypeAt(i, type_argument); | 12593 type_argument = arguments.TypeAt(i); |
| 12594 ResolveType(&type_argument); |
| 12595 arguments.SetTypeAt(i, type_argument); |
| 12596 } |
12574 } | 12597 } |
12575 } | 12598 } |
12576 if (type->IsFunctionType()) { | 12599 if (type->IsFunctionType()) { |
12577 const Function& signature = | 12600 const Function& signature = |
12578 Function::Handle(Z, Type::Cast(*type).signature()); | 12601 Function::Handle(Z, Type::Cast(*type).signature()); |
12579 Type& signature_type = Type::Handle(Z, signature.SignatureType()); | 12602 Type& signature_type = Type::Handle(Z, signature.SignatureType()); |
12580 if (signature_type.raw() != type->raw()) { | 12603 if (signature_type.raw() != type->raw()) { |
12581 ResolveType(&signature_type); | 12604 ResolveType(&signature_type); |
12582 } else { | 12605 } else { |
12583 ResolveSignature(signature); | 12606 ResolveSignature(signature); |
(...skipping 2729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15313 TokenPosition* start, | 15336 TokenPosition* start, |
15314 TokenPosition* end) { | 15337 TokenPosition* end) { |
15315 UNREACHABLE(); | 15338 UNREACHABLE(); |
15316 return false; | 15339 return false; |
15317 } | 15340 } |
15318 | 15341 |
15319 | 15342 |
15320 } // namespace dart | 15343 } // namespace dart |
15321 | 15344 |
15322 #endif // DART_PRECOMPILED_RUNTIME | 15345 #endif // DART_PRECOMPILED_RUNTIME |
OLD | NEW |