| 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 | 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 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 signature_function, | 872 signature_function, |
| 873 script_); | 873 script_); |
| 874 // Record the function signature class in the current library. | 874 // Record the function signature class in the current library. |
| 875 library_.AddClass(signature_class); | 875 library_.AddClass(signature_class); |
| 876 } else { | 876 } else { |
| 877 signature_function.set_signature_class(signature_class); | 877 signature_function.set_signature_class(signature_class); |
| 878 } | 878 } |
| 879 ASSERT(signature_function.signature_class() == signature_class.raw()); | 879 ASSERT(signature_function.signature_class() == signature_class.raw()); |
| 880 Type& signature_type = Type::ZoneHandle(signature_class.SignatureType()); | 880 Type& signature_type = Type::ZoneHandle(signature_class.SignatureType()); |
| 881 if (!is_top_level_ && !signature_type.IsFinalized()) { | 881 if (!is_top_level_ && !signature_type.IsFinalized()) { |
| 882 Error& error = Error::Handle(); | |
| 883 signature_type ^= | 882 signature_type ^= |
| 884 ClassFinalizer::FinalizeAndCanonicalizeType(signature_class, | 883 ClassFinalizer::FinalizeType(signature_class, signature_type); |
| 885 signature_type, | |
| 886 &error); | |
| 887 if (!error.IsNull()) { | |
| 888 ErrorMsg(error.ToErrorCString()); | |
| 889 } | |
| 890 } | 884 } |
| 891 // The type of the parameter is now the signature type. | 885 // The type of the parameter is now the signature type. |
| 892 parameter.type = &signature_type; | 886 parameter.type = &signature_type; |
| 893 } | 887 } |
| 894 } | 888 } |
| 895 | 889 |
| 896 if (CurrentToken() == Token::kASSIGN) { | 890 if (CurrentToken() == Token::kASSIGN) { |
| 897 if (!params->has_named_optional_parameters || | 891 if (!params->has_named_optional_parameters || |
| 898 !allow_explicit_default_value) { | 892 !allow_explicit_default_value) { |
| 899 ErrorMsg("parameter must not specify a default value"); | 893 ErrorMsg("parameter must not specify a default value"); |
| (...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1918 !ResolveIdentInLocalScope(qual_ident->ident_pos, | 1912 !ResolveIdentInLocalScope(qual_ident->ident_pos, |
| 1919 *(qual_ident->ident), | 1913 *(qual_ident->ident), |
| 1920 NULL)) { | 1914 NULL)) { |
| 1921 LibraryPrefix& lib_prefix = LibraryPrefix::ZoneHandle(); | 1915 LibraryPrefix& lib_prefix = LibraryPrefix::ZoneHandle(); |
| 1922 lib_prefix = current_class().LookupLibraryPrefix(*(qual_ident->ident)); | 1916 lib_prefix = current_class().LookupLibraryPrefix(*(qual_ident->ident)); |
| 1923 if (!lib_prefix.IsNull()) { | 1917 if (!lib_prefix.IsNull()) { |
| 1924 // We have a library prefix qualified identifier, unless the prefix is | 1918 // We have a library prefix qualified identifier, unless the prefix is |
| 1925 // shadowed by a type parameter in scope. | 1919 // shadowed by a type parameter in scope. |
| 1926 const Class& scope_class = Class::Handle(TypeParametersScopeClass()); | 1920 const Class& scope_class = Class::Handle(TypeParametersScopeClass()); |
| 1927 if (scope_class.IsNull() || | 1921 if (scope_class.IsNull() || |
| 1928 (scope_class.LookupTypeParameter(*(qual_ident->ident)) == | 1922 (scope_class.LookupTypeParameter(*(qual_ident->ident), |
| 1923 token_index_) == |
| 1929 TypeParameter::null())) { | 1924 TypeParameter::null())) { |
| 1930 ConsumeToken(); // Consume the kPERIOD token. | 1925 ConsumeToken(); // Consume the kPERIOD token. |
| 1931 qual_ident->lib_prefix = &lib_prefix; | 1926 qual_ident->lib_prefix = &lib_prefix; |
| 1932 qual_ident->ident_pos = token_index_; | 1927 qual_ident->ident_pos = token_index_; |
| 1933 qual_ident->ident = | 1928 qual_ident->ident = |
| 1934 ExpectIdentifier("identifier expected after '.'"); | 1929 ExpectIdentifier("identifier expected after '.'"); |
| 1935 } | 1930 } |
| 1936 } | 1931 } |
| 1937 } | 1932 } |
| 1938 } | 1933 } |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2329 if (member.has_factory) { | 2324 if (member.has_factory) { |
| 2330 // The factory name may be qualified. | 2325 // The factory name may be qualified. |
| 2331 QualIdent factory_name; | 2326 QualIdent factory_name; |
| 2332 ParseQualIdent(&factory_name); | 2327 ParseQualIdent(&factory_name); |
| 2333 member.name_pos = factory_name.ident_pos; | 2328 member.name_pos = factory_name.ident_pos; |
| 2334 member.name = factory_name.ident; // Unqualified identifier. | 2329 member.name = factory_name.ident; // Unqualified identifier. |
| 2335 // The class of the factory result type is specified by the factory name. | 2330 // The class of the factory result type is specified by the factory name. |
| 2336 const Object& result_type_class = Object::Handle( | 2331 const Object& result_type_class = Object::Handle( |
| 2337 LookupTypeClass(factory_name, kCanResolve)); | 2332 LookupTypeClass(factory_name, kCanResolve)); |
| 2338 // The type arguments of the result type are set during finalization. | 2333 // The type arguments of the result type are set during finalization. |
| 2339 member.type = &Type::ZoneHandle( | 2334 member.type = &Type::ZoneHandle(Type::New(result_type_class, |
| 2340 Type::New(result_type_class, TypeArguments::Handle())); | 2335 TypeArguments::Handle(), |
| 2336 factory_name.ident_pos)); |
| 2341 } else { | 2337 } else { |
| 2342 member.name_pos = token_index_; | 2338 member.name_pos = token_index_; |
| 2343 member.name = CurrentLiteral(); | 2339 member.name = CurrentLiteral(); |
| 2344 ConsumeToken(); | 2340 ConsumeToken(); |
| 2345 } | 2341 } |
| 2346 // We must be dealing with a constructor or named constructor. | 2342 // We must be dealing with a constructor or named constructor. |
| 2347 member.kind = RawFunction::kConstructor; | 2343 member.kind = RawFunction::kConstructor; |
| 2348 String& ctor_suffix = String::ZoneHandle(String::NewSymbol(".")); | 2344 String& ctor_suffix = String::ZoneHandle(String::NewSymbol(".")); |
| 2349 if (CurrentToken() == Token::kPERIOD) { | 2345 if (CurrentToken() == Token::kPERIOD) { |
| 2350 // Named constructor. | 2346 // Named constructor. |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2461 const intptr_t class_pos = token_index_; | 2457 const intptr_t class_pos = token_index_; |
| 2462 ExpectToken(Token::kCLASS); | 2458 ExpectToken(Token::kCLASS); |
| 2463 const intptr_t classname_pos = token_index_; | 2459 const intptr_t classname_pos = token_index_; |
| 2464 String& class_name = *ExpectTypeIdentifier("class name expected"); | 2460 String& class_name = *ExpectTypeIdentifier("class name expected"); |
| 2465 if (FLAG_trace_parser) { | 2461 if (FLAG_trace_parser) { |
| 2466 OS::Print("TopLevel parsing class '%s'\n", class_name.ToCString()); | 2462 OS::Print("TopLevel parsing class '%s'\n", class_name.ToCString()); |
| 2467 } | 2463 } |
| 2468 Class& cls = Class::ZoneHandle(); | 2464 Class& cls = Class::ZoneHandle(); |
| 2469 Object& obj = Object::Handle(library_.LookupObject(class_name)); | 2465 Object& obj = Object::Handle(library_.LookupObject(class_name)); |
| 2470 if (obj.IsNull()) { | 2466 if (obj.IsNull()) { |
| 2471 cls = Class::New(class_name, script_); | 2467 cls = Class::New(class_name, script_, classname_pos); |
| 2472 library_.AddClass(cls); | 2468 library_.AddClass(cls); |
| 2473 } else { | 2469 } else { |
| 2474 if (!obj.IsClass()) { | 2470 if (!obj.IsClass()) { |
| 2475 ErrorMsg(classname_pos, "'%s' is already defined", | 2471 ErrorMsg(classname_pos, "'%s' is already defined", |
| 2476 class_name.ToCString()); | 2472 class_name.ToCString()); |
| 2477 } | 2473 } |
| 2478 cls ^= obj.raw(); | 2474 cls ^= obj.raw(); |
| 2479 if (cls.is_interface()) { | 2475 if (cls.is_interface()) { |
| 2480 ErrorMsg(classname_pos, "'%s' is already defined as interface", | 2476 ErrorMsg(classname_pos, "'%s' is already defined as interface", |
| 2481 class_name.ToCString()); | 2477 class_name.ToCString()); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2620 | 2616 |
| 2621 | 2617 |
| 2622 void Parser::ParseFunctionTypeAlias(GrowableArray<const Class*>* classes) { | 2618 void Parser::ParseFunctionTypeAlias(GrowableArray<const Class*>* classes) { |
| 2623 TRACE_PARSER("ParseFunctionTypeAlias"); | 2619 TRACE_PARSER("ParseFunctionTypeAlias"); |
| 2624 ExpectToken(Token::kTYPEDEF); | 2620 ExpectToken(Token::kTYPEDEF); |
| 2625 | 2621 |
| 2626 // Allocate an interface to hold the type parameters and their 'extends' | 2622 // Allocate an interface to hold the type parameters and their 'extends' |
| 2627 // constraints. Make it the owner of the function type descriptor. | 2623 // constraints. Make it the owner of the function type descriptor. |
| 2628 const Class& alias_owner = Class::Handle( | 2624 const Class& alias_owner = Class::Handle( |
| 2629 Class::New(String::Handle(String::NewSymbol(":alias_owner")), | 2625 Class::New(String::Handle(String::NewSymbol(":alias_owner")), |
| 2630 Script::Handle())); | 2626 Script::Handle(), |
| 2627 token_index_)); |
| 2631 alias_owner.set_is_interface(); | 2628 alias_owner.set_is_interface(); |
| 2632 alias_owner.set_library(library_); | 2629 alias_owner.set_library(library_); |
| 2633 set_current_class(alias_owner); | 2630 set_current_class(alias_owner); |
| 2634 | 2631 |
| 2635 // Parse the result type of the function type. | 2632 // Parse the result type of the function type. |
| 2636 AbstractType& result_type = Type::Handle(Type::DynamicType()); | 2633 AbstractType& result_type = Type::Handle(Type::DynamicType()); |
| 2637 const intptr_t result_type_pos = token_index_; | |
| 2638 if (CurrentToken() == Token::kVOID) { | 2634 if (CurrentToken() == Token::kVOID) { |
| 2639 ConsumeToken(); | 2635 ConsumeToken(); |
| 2640 result_type = Type::VoidType(); | 2636 result_type = Type::VoidType(); |
| 2641 } else if (!IsFunctionTypeAliasName()) { | 2637 } else if (!IsFunctionTypeAliasName()) { |
| 2642 // Type annotations in typedef are never ignored, even in unchecked mode. | 2638 // Type annotations in typedef are never ignored, even in unchecked mode. |
| 2643 // Wait until we have an owner class before resolving the result type. | 2639 // Wait until we have an owner class before resolving the result type. |
| 2644 result_type = ParseType(kDoNotResolve); | 2640 result_type = ParseType(kDoNotResolve); |
| 2645 } | 2641 } |
| 2646 | 2642 |
| 2647 const intptr_t alias_name_pos = token_index_; | 2643 const intptr_t alias_name_pos = token_index_; |
| 2648 const String* alias_name = | 2644 const String* alias_name = |
| 2649 ExpectTypeIdentifier("function alias name expected"); | 2645 ExpectTypeIdentifier("function alias name expected"); |
| 2650 | 2646 |
| 2651 // Parse the type parameters of the function type. | 2647 // Parse the type parameters of the function type. |
| 2652 ParseTypeParameters(alias_owner); | 2648 ParseTypeParameters(alias_owner); |
| 2653 // At this point, the type parameters have been parsed, so we can resolve the | 2649 // At this point, the type parameters have been parsed, so we can resolve the |
| 2654 // result type. | 2650 // result type. |
| 2655 if (!result_type.IsNull()) { | 2651 if (!result_type.IsNull()) { |
| 2656 ResolveTypeFromClass(result_type_pos, | 2652 ResolveTypeFromClass(alias_owner, kCanResolve, &result_type); |
| 2657 alias_owner, | |
| 2658 kCanResolve, | |
| 2659 &result_type); | |
| 2660 } | 2653 } |
| 2661 // Parse the formal parameters of the function type. | 2654 // Parse the formal parameters of the function type. |
| 2662 if (CurrentToken() != Token::kLPAREN) { | 2655 if (CurrentToken() != Token::kLPAREN) { |
| 2663 ErrorMsg("formal parameter list expected"); | 2656 ErrorMsg("formal parameter list expected"); |
| 2664 } | 2657 } |
| 2665 ParamList func_params; | 2658 ParamList func_params; |
| 2666 const bool no_explicit_default_values = false; | 2659 const bool no_explicit_default_values = false; |
| 2667 ParseFormalParameterList(no_explicit_default_values, &func_params); | 2660 ParseFormalParameterList(no_explicit_default_values, &func_params); |
| 2668 // The field 'is_static' has no meaning for signature functions. | 2661 // The field 'is_static' has no meaning for signature functions. |
| 2669 Function& signature_function = Function::Handle( | 2662 Function& signature_function = Function::Handle( |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2720 const intptr_t interface_pos = token_index_; | 2713 const intptr_t interface_pos = token_index_; |
| 2721 ExpectToken(Token::kINTERFACE); | 2714 ExpectToken(Token::kINTERFACE); |
| 2722 const intptr_t interfacename_pos = token_index_; | 2715 const intptr_t interfacename_pos = token_index_; |
| 2723 String& interface_name = *ExpectTypeIdentifier("interface name expected"); | 2716 String& interface_name = *ExpectTypeIdentifier("interface name expected"); |
| 2724 if (FLAG_trace_parser) { | 2717 if (FLAG_trace_parser) { |
| 2725 OS::Print("TopLevel parsing interface '%s'\n", interface_name.ToCString()); | 2718 OS::Print("TopLevel parsing interface '%s'\n", interface_name.ToCString()); |
| 2726 } | 2719 } |
| 2727 Class& interface = Class::ZoneHandle(); | 2720 Class& interface = Class::ZoneHandle(); |
| 2728 Object& obj = Object::Handle(library_.LookupObject(interface_name)); | 2721 Object& obj = Object::Handle(library_.LookupObject(interface_name)); |
| 2729 if (obj.IsNull()) { | 2722 if (obj.IsNull()) { |
| 2730 interface = Class::NewInterface(interface_name, script_); | 2723 interface = Class::NewInterface(interface_name, script_, interfacename_pos); |
| 2731 library_.AddClass(interface); | 2724 library_.AddClass(interface); |
| 2732 } else { | 2725 } else { |
| 2733 if (!obj.IsClass()) { | 2726 if (!obj.IsClass()) { |
| 2734 ErrorMsg(interfacename_pos, "'%s' is already defined", | 2727 ErrorMsg(interfacename_pos, "'%s' is already defined", |
| 2735 interface_name.ToCString()); | 2728 interface_name.ToCString()); |
| 2736 } | 2729 } |
| 2737 interface ^= obj.raw(); | 2730 interface ^= obj.raw(); |
| 2738 if (!interface.is_interface()) { | 2731 if (!interface.is_interface()) { |
| 2739 ErrorMsg(interfacename_pos, | 2732 ErrorMsg(interfacename_pos, |
| 2740 "'%s' is already defined as class", | 2733 "'%s' is already defined as class", |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2755 const intptr_t interfaces_pos = token_index_; | 2748 const intptr_t interfaces_pos = token_index_; |
| 2756 interfaces = ParseInterfaceList(); | 2749 interfaces = ParseInterfaceList(); |
| 2757 AddInterfaces(interfaces_pos, interface, interfaces); | 2750 AddInterfaces(interfaces_pos, interface, interfaces); |
| 2758 } | 2751 } |
| 2759 | 2752 |
| 2760 if (CurrentToken() == Token::kDEFAULT) { | 2753 if (CurrentToken() == Token::kDEFAULT) { |
| 2761 ConsumeToken(); | 2754 ConsumeToken(); |
| 2762 if (CurrentToken() != Token::kIDENT) { | 2755 if (CurrentToken() != Token::kIDENT) { |
| 2763 ErrorMsg("class name expected"); | 2756 ErrorMsg("class name expected"); |
| 2764 } | 2757 } |
| 2765 const intptr_t factory_pos = token_index_; | |
| 2766 QualIdent factory_name; | 2758 QualIdent factory_name; |
| 2767 ParseQualIdent(&factory_name); | 2759 ParseQualIdent(&factory_name); |
| 2768 LibraryPrefix& lib_prefix = LibraryPrefix::Handle(); | 2760 LibraryPrefix& lib_prefix = LibraryPrefix::Handle(); |
| 2769 if (factory_name.lib_prefix != NULL) { | 2761 if (factory_name.lib_prefix != NULL) { |
| 2770 lib_prefix = factory_name.lib_prefix->raw(); | 2762 lib_prefix = factory_name.lib_prefix->raw(); |
| 2771 } | 2763 } |
| 2772 const UnresolvedClass& unresolved_factory_class = UnresolvedClass::Handle( | 2764 const UnresolvedClass& unresolved_factory_class = UnresolvedClass::Handle( |
| 2773 UnresolvedClass::New(factory_pos, lib_prefix, *factory_name.ident)); | 2765 UnresolvedClass::New(lib_prefix, |
| 2766 *factory_name.ident, |
| 2767 factory_name.ident_pos)); |
| 2774 const Class& factory_class = Class::Handle( | 2768 const Class& factory_class = Class::Handle( |
| 2775 Class::New(String::Handle(String::NewSymbol(":factory_signature")), | 2769 Class::New(String::Handle(String::NewSymbol(":factory_signature")), |
| 2776 script_)); | 2770 script_, |
| 2771 factory_name.ident_pos)); |
| 2777 factory_class.set_library(library_); | 2772 factory_class.set_library(library_); |
| 2778 factory_class.set_is_finalized(); | 2773 factory_class.set_is_finalized(); |
| 2779 ParseTypeParameters(factory_class); | 2774 ParseTypeParameters(factory_class); |
| 2780 unresolved_factory_class.set_factory_signature_class(factory_class); | 2775 unresolved_factory_class.set_factory_signature_class(factory_class); |
| 2781 interface.set_factory_class(unresolved_factory_class); | 2776 interface.set_factory_class(unresolved_factory_class); |
| 2782 // If a type parameter list is included in the default factory clause (it | 2777 // If a type parameter list is included in the default factory clause (it |
| 2783 // can be omitted), verify that it matches the list of type parameters of | 2778 // can be omitted), verify that it matches the list of type parameters of |
| 2784 // the interface in number and names. | 2779 // the interface in number and names. |
| 2785 const intptr_t num_default_type_params = factory_class.NumTypeParameters(); | 2780 const intptr_t num_default_type_params = factory_class.NumTypeParameters(); |
| 2786 if (num_default_type_params > 0) { | 2781 if (num_default_type_params > 0) { |
| 2787 String& interface_type_param_name = String::Handle(); | 2782 String& interface_type_param_name = String::Handle(); |
| 2788 String& factory_type_param_name = String::Handle(); | 2783 String& factory_type_param_name = String::Handle(); |
| 2789 const Array& interface_type_param_names = | 2784 const Array& interface_type_param_names = |
| 2790 Array::Handle(interface.type_parameters()); | 2785 Array::Handle(interface.type_parameters()); |
| 2791 const Array& factory_type_param_names = | 2786 const Array& factory_type_param_names = |
| 2792 Array::Handle(factory_class.type_parameters()); | 2787 Array::Handle(factory_class.type_parameters()); |
| 2793 bool mismatch = interface.NumTypeParameters() != num_default_type_params; | 2788 bool mismatch = interface.NumTypeParameters() != num_default_type_params; |
| 2794 for (intptr_t i = 0; !mismatch && (i < num_default_type_params); i++) { | 2789 for (intptr_t i = 0; !mismatch && (i < num_default_type_params); i++) { |
| 2795 interface_type_param_name ^= interface_type_param_names.At(i); | 2790 interface_type_param_name ^= interface_type_param_names.At(i); |
| 2796 factory_type_param_name ^= factory_type_param_names.At(i); | 2791 factory_type_param_name ^= factory_type_param_names.At(i); |
| 2797 if (!interface_type_param_name.Equals(factory_type_param_name)) { | 2792 if (!interface_type_param_name.Equals(factory_type_param_name)) { |
| 2798 mismatch = true; | 2793 mismatch = true; |
| 2799 } | 2794 } |
| 2800 } | 2795 } |
| 2801 if (mismatch) { | 2796 if (mismatch) { |
| 2802 const String& interface_name = String::Handle(interface.Name()); | 2797 const String& interface_name = String::Handle(interface.Name()); |
| 2803 const String& factory_name = String::Handle(factory_class.Name()); | 2798 ErrorMsg(factory_name.ident_pos, |
| 2804 ErrorMsg(factory_pos, | |
| 2805 "mismatch in number or names of type parameters between " | 2799 "mismatch in number or names of type parameters between " |
| 2806 "interface '%s' and default factory class '%s'.\n", | 2800 "interface '%s' and default factory class '%s'.\n", |
| 2807 interface_name.ToCString(), | 2801 interface_name.ToCString(), |
| 2808 factory_name.ToCString()); | 2802 factory_name.ident->ToCString()); |
| 2809 } | 2803 } |
| 2810 } | 2804 } |
| 2811 } | 2805 } |
| 2812 | 2806 |
| 2813 ExpectToken(Token::kLBRACE); | 2807 ExpectToken(Token::kLBRACE); |
| 2814 ClassDesc members(interface, interface_name, true, interface_pos); | 2808 ClassDesc members(interface, interface_name, true, interface_pos); |
| 2815 while (CurrentToken() != Token::kRBRACE) { | 2809 while (CurrentToken() != Token::kRBRACE) { |
| 2816 ParseClassMemberDefinition(&members); | 2810 ParseClassMemberDefinition(&members); |
| 2817 } | 2811 } |
| 2818 ExpectToken(Token::kRBRACE); | 2812 ExpectToken(Token::kRBRACE); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2869 ConsumeToken(); | 2863 ConsumeToken(); |
| 2870 ExpectIdentifier("name expected"); | 2864 ExpectIdentifier("name expected"); |
| 2871 } | 2865 } |
| 2872 SkipTypeArguments(); | 2866 SkipTypeArguments(); |
| 2873 } | 2867 } |
| 2874 } | 2868 } |
| 2875 | 2869 |
| 2876 | 2870 |
| 2877 void Parser::ParseTypeParameters(const Class& cls) { | 2871 void Parser::ParseTypeParameters(const Class& cls) { |
| 2878 if (CurrentToken() == Token::kLT) { | 2872 if (CurrentToken() == Token::kLT) { |
| 2879 const intptr_t type_pos = token_index_; | |
| 2880 GrowableArray<String*> type_parameters; | 2873 GrowableArray<String*> type_parameters; |
| 2881 GrowableArray<AbstractType*> type_parameter_extends; | 2874 GrowableArray<AbstractType*> type_parameter_extends; |
| 2882 do { | 2875 do { |
| 2883 ConsumeToken(); | 2876 ConsumeToken(); |
| 2884 if (CurrentToken() != Token::kIDENT) { | 2877 if (CurrentToken() != Token::kIDENT) { |
| 2885 ErrorMsg("type parameter name expected"); | 2878 ErrorMsg("type parameter name expected"); |
| 2886 } | 2879 } |
| 2887 String& type_parameter_name = *CurrentLiteral(); | 2880 String& type_parameter_name = *CurrentLiteral(); |
| 2888 ConsumeToken(); | 2881 ConsumeToken(); |
| 2889 AbstractType& type_extends = Type::ZoneHandle(Type::DynamicType()); | 2882 AbstractType& type_extends = Type::ZoneHandle(Type::DynamicType()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2903 cls.set_type_parameters(Array::Handle(NewArray<String>(type_parameters))); | 2896 cls.set_type_parameters(Array::Handle(NewArray<String>(type_parameters))); |
| 2904 const TypeArguments& extends_array = | 2897 const TypeArguments& extends_array = |
| 2905 TypeArguments::Handle(NewTypeArguments(type_parameter_extends)); | 2898 TypeArguments::Handle(NewTypeArguments(type_parameter_extends)); |
| 2906 cls.set_type_parameter_extends(extends_array); | 2899 cls.set_type_parameter_extends(extends_array); |
| 2907 // Try to resolve the upper bounds, which will at least resolve the | 2900 // Try to resolve the upper bounds, which will at least resolve the |
| 2908 // referenced type parameters. | 2901 // referenced type parameters. |
| 2909 AbstractType& type_extends = AbstractType::Handle(); | 2902 AbstractType& type_extends = AbstractType::Handle(); |
| 2910 const intptr_t num_types = extends_array.Length(); | 2903 const intptr_t num_types = extends_array.Length(); |
| 2911 for (intptr_t i = 0; i < num_types; i++) { | 2904 for (intptr_t i = 0; i < num_types; i++) { |
| 2912 type_extends = extends_array.TypeAt(i); | 2905 type_extends = extends_array.TypeAt(i); |
| 2913 ResolveTypeFromClass(type_pos, cls, kCanResolve, &type_extends); | 2906 ResolveTypeFromClass(cls, kCanResolve, &type_extends); |
| 2914 extends_array.SetTypeAt(i, type_extends); | 2907 extends_array.SetTypeAt(i, type_extends); |
| 2915 } | 2908 } |
| 2916 } | 2909 } |
| 2917 } | 2910 } |
| 2918 | 2911 |
| 2919 | 2912 |
| 2920 RawAbstractTypeArguments* Parser::ParseTypeArguments( | 2913 RawAbstractTypeArguments* Parser::ParseTypeArguments( |
| 2921 TypeResolution type_resolution) { | 2914 TypeResolution type_resolution) { |
| 2922 if (CurrentToken() == Token::kLT) { | 2915 if (CurrentToken() == Token::kLT) { |
| 2923 GrowableArray<AbstractType*> types; | 2916 GrowableArray<AbstractType*> types; |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3344 | 3337 |
| 3345 void Parser::ParseTopLevel() { | 3338 void Parser::ParseTopLevel() { |
| 3346 // Collect the classes found at the top level in this growable array. | 3339 // Collect the classes found at the top level in this growable array. |
| 3347 // They need to be registered with class finalization after parsing | 3340 // They need to be registered with class finalization after parsing |
| 3348 // has been completed. | 3341 // has been completed. |
| 3349 GrowableArray<const Class*> classes; | 3342 GrowableArray<const Class*> classes; |
| 3350 SetPosition(0); | 3343 SetPosition(0); |
| 3351 is_top_level_ = true; | 3344 is_top_level_ = true; |
| 3352 TopLevel top_level; | 3345 TopLevel top_level; |
| 3353 Class& toplevel_class = Class::ZoneHandle( | 3346 Class& toplevel_class = Class::ZoneHandle( |
| 3354 Class::New(String::ZoneHandle(String::NewSymbol("::")), script_)); | 3347 Class::New(String::ZoneHandle(String::NewSymbol("::")), |
| 3348 script_, |
| 3349 token_index_)); |
| 3355 toplevel_class.set_library(library_); | 3350 toplevel_class.set_library(library_); |
| 3356 | 3351 |
| 3357 if (is_library_source()) { | 3352 if (is_library_source()) { |
| 3358 ParseLibraryDefinition(); | 3353 ParseLibraryDefinition(); |
| 3359 } | 3354 } |
| 3360 | 3355 |
| 3361 while (true) { | 3356 while (true) { |
| 3362 set_current_class(Class::Handle()); // No current class. | 3357 set_current_class(Class::Handle()); // No current class. |
| 3363 if (CurrentToken() == Token::kCLASS) { | 3358 if (CurrentToken() == Token::kCLASS) { |
| 3364 ParseClassDefinition(&classes); | 3359 ParseClassDefinition(&classes); |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3746 LocalVariable* function_variable = NULL; | 3741 LocalVariable* function_variable = NULL; |
| 3747 Type& function_type = Type::ZoneHandle(); | 3742 Type& function_type = Type::ZoneHandle(); |
| 3748 if (variable_name != NULL) { | 3743 if (variable_name != NULL) { |
| 3749 // Since the function type depends on the signature of the closure function, | 3744 // Since the function type depends on the signature of the closure function, |
| 3750 // it cannot be determined before the formal parameter list of the closure | 3745 // it cannot be determined before the formal parameter list of the closure |
| 3751 // function is parsed. Therefore, we set the function type to a new | 3746 // function is parsed. Therefore, we set the function type to a new |
| 3752 // parameterized type to be patched after the actual type is known. | 3747 // parameterized type to be patched after the actual type is known. |
| 3753 // We temporarily use the class of the Function interface. | 3748 // We temporarily use the class of the Function interface. |
| 3754 const Class& unknown_signature_class = Class::Handle( | 3749 const Class& unknown_signature_class = Class::Handle( |
| 3755 Type::Handle(Type::FunctionInterface()).type_class()); | 3750 Type::Handle(Type::FunctionInterface()).type_class()); |
| 3756 function_type = Type::New(unknown_signature_class, TypeArguments::Handle()); | 3751 function_type = Type::New( |
| 3752 unknown_signature_class, TypeArguments::Handle(), ident_pos); |
| 3757 function_type.set_is_finalized(); // No real finalization needed. | 3753 function_type.set_is_finalized(); // No real finalization needed. |
| 3758 | 3754 |
| 3759 // Add the function variable to the scope before parsing the function in | 3755 // Add the function variable to the scope before parsing the function in |
| 3760 // order to allow self reference from inside the function. | 3756 // order to allow self reference from inside the function. |
| 3761 function_variable = new LocalVariable(ident_pos, | 3757 function_variable = new LocalVariable(ident_pos, |
| 3762 *variable_name, | 3758 *variable_name, |
| 3763 function_type); | 3759 function_type); |
| 3764 function_variable->set_is_final(); | 3760 function_variable->set_is_final(); |
| 3765 ASSERT(current_block_ != NULL); | 3761 ASSERT(current_block_ != NULL); |
| 3766 ASSERT(current_block_->scope != NULL); | 3762 ASSERT(current_block_->scope != NULL); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3805 // Patch the function type now that the signature is known. | 3801 // Patch the function type now that the signature is known. |
| 3806 // We need to create a new type for proper finalization, since the existing | 3802 // We need to create a new type for proper finalization, since the existing |
| 3807 // type is already marked as finalized. | 3803 // type is already marked as finalized. |
| 3808 Type& signature_type = Type::Handle(signature_class.SignatureType()); | 3804 Type& signature_type = Type::Handle(signature_class.SignatureType()); |
| 3809 const AbstractTypeArguments& signature_type_arguments = | 3805 const AbstractTypeArguments& signature_type_arguments = |
| 3810 AbstractTypeArguments::Handle(signature_type.arguments()); | 3806 AbstractTypeArguments::Handle(signature_type.arguments()); |
| 3811 | 3807 |
| 3812 // Since the signature type is cached by the signature class, it may have | 3808 // Since the signature type is cached by the signature class, it may have |
| 3813 // been finalized already. | 3809 // been finalized already. |
| 3814 if (!signature_type.IsFinalized()) { | 3810 if (!signature_type.IsFinalized()) { |
| 3815 Error& error = Error::Handle(); | |
| 3816 signature_type ^= | 3811 signature_type ^= |
| 3817 ClassFinalizer::FinalizeAndCanonicalizeType(signature_class, | 3812 ClassFinalizer::FinalizeType(signature_class, signature_type); |
| 3818 signature_type, | 3813 // The call to ClassFinalizer::FinalizeType may have |
| 3819 &error); | |
| 3820 if (!error.IsNull()) { | |
| 3821 ErrorMsg(error.ToErrorCString()); | |
| 3822 } | |
| 3823 // The call to ClassFinalizer::FinalizeAndCanonicalizeType may have | |
| 3824 // extended the vector of type arguments. | 3814 // extended the vector of type arguments. |
| 3825 ASSERT(signature_type_arguments.IsNull() || | 3815 ASSERT(signature_type_arguments.IsNull() || |
| 3826 (signature_type_arguments.Length() == | 3816 (signature_type_arguments.Length() == |
| 3827 signature_class.NumTypeArguments())); | 3817 signature_class.NumTypeArguments())); |
| 3828 // The signature_class should not have changed. | 3818 // The signature_class should not have changed. |
| 3829 ASSERT(signature_type.type_class() == signature_class.raw()); | 3819 ASSERT(signature_type.type_class() == signature_class.raw()); |
| 3830 } | 3820 } |
| 3831 | 3821 |
| 3832 // Now patch the function type of the variable. | 3822 // Now patch the function type of the variable. |
| 3833 function_type.set_type_class(signature_class); | 3823 function_type.set_type_class(signature_class); |
| (...skipping 2317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6151 } | 6141 } |
| 6152 | 6142 |
| 6153 | 6143 |
| 6154 // Resolve the given type and its type arguments from the given scope class | 6144 // Resolve the given type and its type arguments from the given scope class |
| 6155 // according to the given type_resolution. | 6145 // according to the given type_resolution. |
| 6156 // If the given scope class is null, use the current library, but do not try to | 6146 // If the given scope class is null, use the current library, but do not try to |
| 6157 // resolve type parameters. | 6147 // resolve type parameters. |
| 6158 // Not all involved type classes may get resolved yet, but at least the type | 6148 // Not all involved type classes may get resolved yet, but at least the type |
| 6159 // parameters of the given class will get resolved, thereby relieving the class | 6149 // parameters of the given class will get resolved, thereby relieving the class |
| 6160 // finalizer from resolving type parameters out of context. | 6150 // finalizer from resolving type parameters out of context. |
| 6161 void Parser::ResolveTypeFromClass(intptr_t type_pos, | 6151 void Parser::ResolveTypeFromClass(const Class& scope_class, |
| 6162 const Class& scope_class, | |
| 6163 TypeResolution type_resolution, | 6152 TypeResolution type_resolution, |
| 6164 AbstractType* type) { | 6153 AbstractType* type) { |
| 6165 ASSERT((type_resolution == kCanResolve) || (type_resolution == kMustResolve)); | 6154 ASSERT((type_resolution == kCanResolve) || (type_resolution == kMustResolve)); |
| 6166 ASSERT(type != NULL); | 6155 ASSERT(type != NULL); |
| 6167 // Resolve class. | 6156 // Resolve class. |
| 6168 if (!type->HasResolvedTypeClass()) { | 6157 if (!type->HasResolvedTypeClass()) { |
| 6169 const UnresolvedClass& unresolved_class = | 6158 const UnresolvedClass& unresolved_class = |
| 6170 UnresolvedClass::Handle(type->unresolved_class()); | 6159 UnresolvedClass::Handle(type->unresolved_class()); |
| 6171 const String& unresolved_class_name = | 6160 const String& unresolved_class_name = |
| 6172 String::Handle(unresolved_class.ident()); | 6161 String::Handle(unresolved_class.ident()); |
| 6173 // First resolve library prefix if any. | 6162 // First resolve library prefix if any. |
| 6174 Library& lib = Library::Handle(); | 6163 Library& lib = Library::Handle(); |
| 6175 if (unresolved_class.library_prefix() == LibraryPrefix::null()) { | 6164 if (unresolved_class.library_prefix() == LibraryPrefix::null()) { |
| 6176 if (scope_class.IsNull()) { | 6165 if (scope_class.IsNull()) { |
| 6177 lib = library_.raw(); | 6166 lib = library_.raw(); |
| 6178 } else { | 6167 } else { |
| 6179 lib = scope_class.library(); | 6168 lib = scope_class.library(); |
| 6180 // First check if the type is a type parameter of the given scope class. | 6169 // First check if the type is a type parameter of the given scope class. |
| 6181 const TypeParameter& type_parameter = TypeParameter::Handle( | 6170 const TypeParameter& type_parameter = TypeParameter::Handle( |
| 6182 scope_class.LookupTypeParameter(unresolved_class_name)); | 6171 scope_class.LookupTypeParameter(unresolved_class_name, |
| 6172 type->token_index())); |
| 6183 if (!type_parameter.IsNull()) { | 6173 if (!type_parameter.IsNull()) { |
| 6184 // A type parameter cannot be parameterized, so report an error if | 6174 // A type parameter cannot be parameterized, so report an error if |
| 6185 // type arguments have previously been parsed. | 6175 // type arguments have previously been parsed. |
| 6186 if (!AbstractTypeArguments::Handle(type->arguments()).IsNull()) { | 6176 if (!AbstractTypeArguments::Handle(type->arguments()).IsNull()) { |
| 6187 ErrorMsg(type_pos, "type parameter '%s' cannot be parameterized", | 6177 ErrorMsg(type_parameter.token_index(), |
| 6178 "type parameter '%s' cannot be parameterized", |
| 6188 String::Handle(type_parameter.Name()).ToCString()); | 6179 String::Handle(type_parameter.Name()).ToCString()); |
| 6189 } | 6180 } |
| 6190 *type = type_parameter.raw(); | 6181 *type = type_parameter.raw(); |
| 6191 return; | 6182 return; |
| 6192 } | 6183 } |
| 6193 } | 6184 } |
| 6194 } else { | 6185 } else { |
| 6195 LibraryPrefix& lib_prefix = | 6186 LibraryPrefix& lib_prefix = |
| 6196 LibraryPrefix::Handle(unresolved_class.library_prefix()); | 6187 LibraryPrefix::Handle(unresolved_class.library_prefix()); |
| 6197 lib = lib_prefix.library(); | 6188 lib = lib_prefix.library(); |
| 6198 } | 6189 } |
| 6199 if (!lib.IsNull()) { | 6190 if (!lib.IsNull()) { |
| 6200 const Class& resolved_type_class = Class::Handle( | 6191 const Class& resolved_type_class = Class::Handle( |
| 6201 lib.LookupLocalClass(unresolved_class_name)); | 6192 lib.LookupLocalClass(unresolved_class_name)); |
| 6202 if (!resolved_type_class.IsNull()) { | 6193 if (!resolved_type_class.IsNull()) { |
| 6203 Object& type_class = Object::Handle(resolved_type_class.raw()); | 6194 Object& type_class = Object::Handle(resolved_type_class.raw()); |
| 6204 ASSERT(type->IsType()); | 6195 ASSERT(type->IsType()); |
| 6205 // Replace unresolved class with resolved type class. | 6196 // Replace unresolved class with resolved type class. |
| 6206 Type& parameterized_type = Type::Handle(); | 6197 Type& parameterized_type = Type::Handle(); |
| 6207 parameterized_type ^= type->raw(); | 6198 parameterized_type ^= type->raw(); |
| 6208 parameterized_type.set_type_class(type_class); | 6199 parameterized_type.set_type_class(type_class); |
| 6209 } else if (type_resolution == kMustResolve) { | 6200 } else if (type_resolution == kMustResolve) { |
| 6210 ErrorMsg(type_pos, "type '%s' is not loaded", | 6201 ErrorMsg(type->token_index(), "type '%s' is not loaded", |
| 6211 String::Handle(type->Name()).ToCString()); | 6202 String::Handle(type->Name()).ToCString()); |
| 6212 } | 6203 } |
| 6213 } | 6204 } |
| 6214 } | 6205 } |
| 6215 // Resolve type arguments, if any. | 6206 // Resolve type arguments, if any. |
| 6216 const AbstractTypeArguments& arguments = | 6207 const AbstractTypeArguments& arguments = |
| 6217 AbstractTypeArguments::Handle(type->arguments()); | 6208 AbstractTypeArguments::Handle(type->arguments()); |
| 6218 if (!arguments.IsNull()) { | 6209 if (!arguments.IsNull()) { |
| 6219 const intptr_t num_arguments = arguments.Length(); | 6210 const intptr_t num_arguments = arguments.Length(); |
| 6220 for (intptr_t i = 0; i < num_arguments; i++) { | 6211 for (intptr_t i = 0; i < num_arguments; i++) { |
| 6221 AbstractType& type_argument = AbstractType::Handle(arguments.TypeAt(i)); | 6212 AbstractType& type_argument = AbstractType::Handle(arguments.TypeAt(i)); |
| 6222 ResolveTypeFromClass(type_pos, | 6213 ResolveTypeFromClass(scope_class, |
| 6223 scope_class, | |
| 6224 type_resolution, | 6214 type_resolution, |
| 6225 &type_argument); | 6215 &type_argument); |
| 6226 arguments.SetTypeAt(i, type_argument); | 6216 arguments.SetTypeAt(i, type_argument); |
| 6227 } | 6217 } |
| 6228 } | 6218 } |
| 6229 } | 6219 } |
| 6230 | 6220 |
| 6231 | 6221 |
| 6232 // Return class for type name. If the name cannot be resolved (yet), give an | 6222 // Return class for type name. If the name cannot be resolved (yet), give an |
| 6233 // error (if type_resolution == kMustResolve) or return the unresolved name. | 6223 // error (if type_resolution == kMustResolve) or return the unresolved name. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 6249 if (type_resolution == kMustResolve) { | 6239 if (type_resolution == kMustResolve) { |
| 6250 ErrorMsg(type_name.ident_pos, "type '%s' is not loaded", | 6240 ErrorMsg(type_name.ident_pos, "type '%s' is not loaded", |
| 6251 type_name.ident->ToCString()); | 6241 type_name.ident->ToCString()); |
| 6252 return Object::null_class(); | 6242 return Object::null_class(); |
| 6253 } | 6243 } |
| 6254 // We have an unresolved name, create an UnresolvedClass object for this case. | 6244 // We have an unresolved name, create an UnresolvedClass object for this case. |
| 6255 LibraryPrefix& lib_prefix = LibraryPrefix::Handle(); | 6245 LibraryPrefix& lib_prefix = LibraryPrefix::Handle(); |
| 6256 if (type_name.lib_prefix != NULL) { | 6246 if (type_name.lib_prefix != NULL) { |
| 6257 lib_prefix = type_name.lib_prefix->raw(); | 6247 lib_prefix = type_name.lib_prefix->raw(); |
| 6258 } | 6248 } |
| 6259 return UnresolvedClass::New(type_name.ident_pos, | 6249 return UnresolvedClass::New(lib_prefix, |
| 6260 lib_prefix, | 6250 *type_name.ident, |
| 6261 *type_name.ident); | 6251 type_name.ident_pos); |
| 6262 } | 6252 } |
| 6263 | 6253 |
| 6264 | 6254 |
| 6265 LocalVariable* Parser::LookupLocalScope(const String& ident) { | 6255 LocalVariable* Parser::LookupLocalScope(const String& ident) { |
| 6266 if (current_block_ == NULL) { | 6256 if (current_block_ == NULL) { |
| 6267 return NULL; | 6257 return NULL; |
| 6268 } | 6258 } |
| 6269 // A found name is treated as accessed and possibly marked as captured. | 6259 // A found name is treated as accessed and possibly marked as captured. |
| 6270 const bool kTestOnly = false; | 6260 const bool kTestOnly = false; |
| 6271 return current_block_->scope->LookupVariable(ident, kTestOnly); | 6261 return current_block_->scope->LookupVariable(ident, kTestOnly); |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6658 | 6648 |
| 6659 // Parses type = [ident "."] ident ["<" type { "," type } ">"]. | 6649 // Parses type = [ident "."] ident ["<" type { "," type } ">"]. |
| 6660 // Returns the class object if the type can be resolved. Otherwise, either give | 6650 // Returns the class object if the type can be resolved. Otherwise, either give |
| 6661 // an error if type resolution was required, or return the unresolved name as a | 6651 // an error if type resolution was required, or return the unresolved name as a |
| 6662 // string object. | 6652 // string object. |
| 6663 RawAbstractType* Parser::ParseType(TypeResolution type_resolution) { | 6653 RawAbstractType* Parser::ParseType(TypeResolution type_resolution) { |
| 6664 if (CurrentToken() != Token::kIDENT) { | 6654 if (CurrentToken() != Token::kIDENT) { |
| 6665 ErrorMsg("type name expected"); | 6655 ErrorMsg("type name expected"); |
| 6666 } | 6656 } |
| 6667 QualIdent type_name; | 6657 QualIdent type_name; |
| 6668 const intptr_t type_pos = token_index_; | |
| 6669 if (type_resolution == kIgnore) { | 6658 if (type_resolution == kIgnore) { |
| 6670 SkipQualIdent(); | 6659 SkipQualIdent(); |
| 6671 } else { | 6660 } else { |
| 6672 ParseQualIdent(&type_name); | 6661 ParseQualIdent(&type_name); |
| 6673 // An identifier cannot be resolved in a local scope when top level parsing. | 6662 // An identifier cannot be resolved in a local scope when top level parsing. |
| 6674 if (!is_top_level_ && | 6663 if (!is_top_level_ && |
| 6675 (type_name.lib_prefix == NULL) && | 6664 (type_name.lib_prefix == NULL) && |
| 6676 ResolveIdentInLocalScope(type_pos, *type_name.ident, NULL)) { | 6665 ResolveIdentInLocalScope(type_name.ident_pos, *type_name.ident, NULL)) { |
| 6677 ErrorMsg(type_pos, "using '%s' in this context is invalid", | 6666 ErrorMsg(type_name.ident_pos, "using '%s' in this context is invalid", |
| 6678 type_name.ident->ToCString()); | 6667 type_name.ident->ToCString()); |
| 6679 } | 6668 } |
| 6680 } | 6669 } |
| 6681 Class& scope_class = Class::Handle(); | 6670 Class& scope_class = Class::Handle(); |
| 6682 Object& type_class = Object::Handle(); | 6671 Object& type_class = Object::Handle(); |
| 6683 if (type_resolution == kIgnore) { | 6672 if (type_resolution == kIgnore) { |
| 6684 // Leave type_class as null. | 6673 // Leave type_class as null. |
| 6685 } else if (type_resolution == kDoNotResolve) { | 6674 } else if (type_resolution == kDoNotResolve) { |
| 6686 LibraryPrefix& lib_prefix = LibraryPrefix::Handle(); | 6675 LibraryPrefix& lib_prefix = LibraryPrefix::Handle(); |
| 6687 if (type_name.lib_prefix != NULL) { | 6676 if (type_name.lib_prefix != NULL) { |
| 6688 lib_prefix = type_name.lib_prefix->raw(); | 6677 lib_prefix = type_name.lib_prefix->raw(); |
| 6689 } | 6678 } |
| 6690 type_class = UnresolvedClass::New(type_pos, lib_prefix, *type_name.ident); | 6679 type_class = UnresolvedClass::New(lib_prefix, |
| 6680 *type_name.ident, |
| 6681 type_name.ident_pos); |
| 6691 } else { | 6682 } else { |
| 6692 // TODO(regis): Use ResolveTypeFromClass(). | 6683 // TODO(regis): Use ResolveTypeFromClass(). |
| 6693 ASSERT((type_resolution == kCanResolve) || | 6684 ASSERT((type_resolution == kCanResolve) || |
| 6694 (type_resolution == kMustResolve)); | 6685 (type_resolution == kMustResolve)); |
| 6695 scope_class = TypeParametersScopeClass(); | 6686 scope_class = TypeParametersScopeClass(); |
| 6696 if (!scope_class.IsNull()) { | 6687 if (!scope_class.IsNull()) { |
| 6697 if (type_name.lib_prefix == NULL) { | 6688 if (type_name.lib_prefix == NULL) { |
| 6698 // Check if ident is a type parameter in scope. | 6689 // Check if ident is a type parameter in scope. |
| 6699 TypeParameter& type_parameter = TypeParameter::Handle( | 6690 TypeParameter& type_parameter = TypeParameter::Handle( |
| 6700 scope_class.LookupTypeParameter(*type_name.ident)); | 6691 scope_class.LookupTypeParameter(*type_name.ident, |
| 6692 type_name.ident_pos)); |
| 6701 if (!type_parameter.IsNull()) { | 6693 if (!type_parameter.IsNull()) { |
| 6702 if (CurrentToken() == Token::kLT) { | 6694 if (CurrentToken() == Token::kLT) { |
| 6703 // A type parameter cannot be parameterized. | 6695 // A type parameter cannot be parameterized. |
| 6704 ErrorMsg(type_pos, "type parameter '%s' cannot be parameterized", | 6696 ErrorMsg(type_parameter.token_index(), |
| 6697 "type parameter '%s' cannot be parameterized", |
| 6705 String::Handle(type_parameter.Name()).ToCString()); | 6698 String::Handle(type_parameter.Name()).ToCString()); |
| 6706 } | 6699 } |
| 6707 if (type_resolution == kMustResolve) { | 6700 if (type_resolution == kMustResolve) { |
| 6708 Error& error = Error::Handle(); | |
| 6709 type_parameter ^= | 6701 type_parameter ^= |
| 6710 ClassFinalizer::FinalizeAndCanonicalizeType(scope_class, | 6702 ClassFinalizer::FinalizeType(current_class(), type_parameter); |
| 6711 type_parameter, | |
| 6712 &error); | |
| 6713 if (!error.IsNull()) { | |
| 6714 ErrorMsg(error.ToErrorCString()); | |
| 6715 } | |
| 6716 } | 6703 } |
| 6717 return type_parameter.raw(); | 6704 return type_parameter.raw(); |
| 6718 } | 6705 } |
| 6719 } | 6706 } |
| 6720 } | 6707 } |
| 6721 // Try to resolve the type class. | 6708 // Try to resolve the type class. |
| 6722 type_class = LookupTypeClass(type_name, type_resolution); | 6709 type_class = LookupTypeClass(type_name, type_resolution); |
| 6723 } | 6710 } |
| 6724 AbstractTypeArguments& type_arguments = | 6711 AbstractTypeArguments& type_arguments = |
| 6725 AbstractTypeArguments::Handle(ParseTypeArguments(type_resolution)); | 6712 AbstractTypeArguments::Handle(ParseTypeArguments(type_resolution)); |
| 6726 if (type_resolution == kIgnore) { | 6713 if (type_resolution == kIgnore) { |
| 6727 return Type::DynamicType(); | 6714 return Type::DynamicType(); |
| 6728 } | 6715 } |
| 6729 Type& type = Type::Handle(Type::New(type_class, type_arguments)); | 6716 Type& type = Type::Handle( |
| 6717 Type::New(type_class, type_arguments, type_name.ident_pos)); |
| 6730 if (type_resolution == kMustResolve) { | 6718 if (type_resolution == kMustResolve) { |
| 6731 ASSERT(type_class.IsClass()); // Must be resolved. | 6719 ASSERT(type_class.IsClass()); // Must be resolved. |
| 6732 Error& error = Error::Handle(); | 6720 type ^= ClassFinalizer::FinalizeType(current_class(), type); |
| 6733 type ^= ClassFinalizer::FinalizeAndCanonicalizeType(scope_class, | |
| 6734 type, | |
| 6735 &error); | |
| 6736 if (!error.IsNull()) { | |
| 6737 ErrorMsg(error.ToErrorCString()); | |
| 6738 } | |
| 6739 } | 6721 } |
| 6740 return type.raw(); | 6722 return type.raw(); |
| 6741 } | 6723 } |
| 6742 | 6724 |
| 6743 | 6725 |
| 6744 void Parser::CheckConstructorCallTypeArguments( | 6726 void Parser::CheckConstructorCallTypeArguments( |
| 6745 intptr_t pos, Function& constructor, | 6727 intptr_t pos, Function& constructor, |
| 6746 const AbstractTypeArguments& type_arguments) { | 6728 const AbstractTypeArguments& type_arguments) { |
| 6747 if (!type_arguments.IsNull()) { | 6729 if (!type_arguments.IsNull()) { |
| 6748 const Class& constructor_class = Class::Handle(constructor.owner()); | 6730 const Class& constructor_class = Class::Handle(constructor.owner()); |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7130 const intptr_t new_pos = token_index_; | 7112 const intptr_t new_pos = token_index_; |
| 7131 ASSERT((CurrentToken() == Token::kNEW) || (CurrentToken() == Token::kCONST)); | 7113 ASSERT((CurrentToken() == Token::kNEW) || (CurrentToken() == Token::kCONST)); |
| 7132 bool is_const = (CurrentToken() == Token::kCONST); | 7114 bool is_const = (CurrentToken() == Token::kCONST); |
| 7133 ConsumeToken(); | 7115 ConsumeToken(); |
| 7134 if (!IsIdentifier()) { | 7116 if (!IsIdentifier()) { |
| 7135 ErrorMsg("type name expected"); | 7117 ErrorMsg("type name expected"); |
| 7136 } | 7118 } |
| 7137 | 7119 |
| 7138 const AbstractType& type = AbstractType::Handle(ParseType(kMustResolve)); | 7120 const AbstractType& type = AbstractType::Handle(ParseType(kMustResolve)); |
| 7139 if (type.IsTypeParameter()) { | 7121 if (type.IsTypeParameter()) { |
| 7140 // TODO(regis): Use type position once supported. | 7122 ErrorMsg(type.token_index(), |
| 7141 ErrorMsg(new_pos, "type parameter '%s' cannot be instantiated", | 7123 "type parameter '%s' cannot be instantiated", |
| 7142 String::Handle(type.Name()).ToCString()); | 7124 String::Handle(type.Name()).ToCString()); |
| 7143 } | 7125 } |
| 7144 Class& type_class = Class::Handle(type.type_class()); | 7126 Class& type_class = Class::Handle(type.type_class()); |
| 7145 String& type_class_name = String::Handle(type_class.Name()); | 7127 String& type_class_name = String::Handle(type_class.Name()); |
| 7146 AbstractTypeArguments& type_arguments = | 7128 AbstractTypeArguments& type_arguments = |
| 7147 AbstractTypeArguments::ZoneHandle(type.arguments()); | 7129 AbstractTypeArguments::ZoneHandle(type.arguments()); |
| 7148 | 7130 |
| 7149 // The constructor class and its name are those of the parsed type, unless the | 7131 // The constructor class and its name are those of the parsed type, unless the |
| 7150 // parsed type is an interface and a default factory class is specified, in | 7132 // parsed type is an interface and a default factory class is specified, in |
| 7151 // which case constructor_class and constructor_class_name are modified below. | 7133 // which case constructor_class and constructor_class_name are modified below. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 7176 if (type_class.is_interface()) { | 7158 if (type_class.is_interface()) { |
| 7177 // We need to make sure that an appropriate constructor is | 7159 // We need to make sure that an appropriate constructor is |
| 7178 // declared in the interface. | 7160 // declared in the interface. |
| 7179 const String& constructor_name = | 7161 const String& constructor_name = |
| 7180 BuildConstructorName(type_class_name, named_constructor); | 7162 BuildConstructorName(type_class_name, named_constructor); |
| 7181 const String& external_constructor_name = | 7163 const String& external_constructor_name = |
| 7182 (named_constructor ? constructor_name : type_class_name); | 7164 (named_constructor ? constructor_name : type_class_name); |
| 7183 Function& constructor = Function::ZoneHandle( | 7165 Function& constructor = Function::ZoneHandle( |
| 7184 type_class.LookupConstructor(constructor_name)); | 7166 type_class.LookupConstructor(constructor_name)); |
| 7185 if (constructor.IsNull()) { | 7167 if (constructor.IsNull()) { |
| 7186 ErrorMsg(new_pos, "interface '%s' has no constructor named '%s'", | 7168 ErrorMsg(type.token_index(), |
| 7169 "interface '%s' has no constructor named '%s'", |
| 7187 type_class_name.ToCString(), | 7170 type_class_name.ToCString(), |
| 7188 external_constructor_name.ToCString()); | 7171 external_constructor_name.ToCString()); |
| 7189 } | 7172 } |
| 7190 if (!constructor.AreValidArguments(arguments_length, arguments->names())) { | 7173 if (!constructor.AreValidArguments(arguments_length, arguments->names())) { |
| 7191 ErrorMsg(new_pos, "invalid arguments passed to constructor '%s' " | 7174 ErrorMsg(type.token_index(), |
| 7175 "invalid arguments passed to constructor '%s' " |
| 7192 "for interface '%s'", | 7176 "for interface '%s'", |
| 7193 external_constructor_name.ToCString(), | 7177 external_constructor_name.ToCString(), |
| 7194 type_class_name.ToCString()); | 7178 type_class_name.ToCString()); |
| 7195 } | 7179 } |
| 7196 if (!type_class.HasFactoryClass()) { | 7180 if (!type_class.HasFactoryClass()) { |
| 7197 ErrorMsg("cannot allocate interface '%s' without factory class", | 7181 ErrorMsg("cannot allocate interface '%s' without factory class", |
| 7198 type_class_name.ToCString()); | 7182 type_class_name.ToCString()); |
| 7199 } | 7183 } |
| 7200 if (!type_class.HasResolvedFactoryClass()) { | 7184 if (!type_class.HasResolvedFactoryClass()) { |
| 7201 // This error can occur only with bootstrap classes. | 7185 // This error can occur only with bootstrap classes. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 7226 Function& constructor = Function::ZoneHandle( | 7210 Function& constructor = Function::ZoneHandle( |
| 7227 constructor_class.LookupConstructor(constructor_name)); | 7211 constructor_class.LookupConstructor(constructor_name)); |
| 7228 if (constructor.IsNull()) { | 7212 if (constructor.IsNull()) { |
| 7229 constructor = constructor_class.LookupFactory(constructor_name); | 7213 constructor = constructor_class.LookupFactory(constructor_name); |
| 7230 // A factory does not have the implicit 'phase' parameter. | 7214 // A factory does not have the implicit 'phase' parameter. |
| 7231 arguments_length -= 1; | 7215 arguments_length -= 1; |
| 7232 } | 7216 } |
| 7233 if (constructor.IsNull()) { | 7217 if (constructor.IsNull()) { |
| 7234 const String& external_constructor_name = | 7218 const String& external_constructor_name = |
| 7235 (named_constructor ? constructor_name : constructor_class_name); | 7219 (named_constructor ? constructor_name : constructor_class_name); |
| 7236 ErrorMsg(new_pos, "class '%s' has no constructor or factory named '%s'", | 7220 ErrorMsg(type.token_index(), |
| 7221 "class '%s' has no constructor or factory named '%s'", |
| 7237 String::Handle(constructor_class.Name()).ToCString(), | 7222 String::Handle(constructor_class.Name()).ToCString(), |
| 7238 external_constructor_name.ToCString()); | 7223 external_constructor_name.ToCString()); |
| 7239 } | 7224 } |
| 7240 if (!constructor.AreValidArguments(arguments_length, arguments->names())) { | 7225 if (!constructor.AreValidArguments(arguments_length, arguments->names())) { |
| 7241 const String& external_constructor_name = | 7226 const String& external_constructor_name = |
| 7242 (named_constructor ? constructor_name : constructor_class_name); | 7227 (named_constructor ? constructor_name : constructor_class_name); |
| 7243 ErrorMsg(new_pos, "invalid arguments passed to constructor '%s' " | 7228 ErrorMsg(type.token_index(), |
| 7244 "for class '%s'", | 7229 "invalid arguments passed to constructor '%s' for class '%s'", |
| 7245 external_constructor_name.ToCString(), | 7230 external_constructor_name.ToCString(), |
| 7246 String::Handle(constructor_class.Name()).ToCString()); | 7231 String::Handle(constructor_class.Name()).ToCString()); |
| 7247 } | 7232 } |
| 7248 | 7233 |
| 7249 // Now that the constructor to be called is identified, finalize the type | 7234 // Now that the constructor to be called is identified, finalize the type |
| 7250 // argument vector to be passed. | 7235 // argument vector to be passed. |
| 7251 // The type argument vector of the parsed type was finalized in ParseType. | 7236 // The type argument vector of the parsed type was finalized in ParseType. |
| 7252 // If the constructor class was changed from the interface class to the | 7237 // If the constructor class was changed from the interface class to the |
| 7253 // factory class, we need to finalize the type argument vector again, because | 7238 // factory class, we need to finalize the type argument vector again, because |
| 7254 // it may be longer due to the factory class extending a class, or/and because | 7239 // it may be longer due to the factory class extending a class, or/and because |
| (...skipping 13 matching lines...) Expand all Loading... |
| 7268 if (i < num_type_arguments) { | 7253 if (i < num_type_arguments) { |
| 7269 type_argument = type_arguments.TypeAt(i); | 7254 type_argument = type_arguments.TypeAt(i); |
| 7270 } else { | 7255 } else { |
| 7271 type_argument = Type::DynamicType(); | 7256 type_argument = Type::DynamicType(); |
| 7272 } | 7257 } |
| 7273 temp_type_arguments.SetTypeAt(i, type_argument); | 7258 temp_type_arguments.SetTypeAt(i, type_argument); |
| 7274 } | 7259 } |
| 7275 } | 7260 } |
| 7276 // TODO(regis): Temporary type should be allocated in new gen heap. | 7261 // TODO(regis): Temporary type should be allocated in new gen heap. |
| 7277 Type& temp_type = Type::Handle( | 7262 Type& temp_type = Type::Handle( |
| 7278 Type::New(constructor_class, temp_type_arguments)); | 7263 Type::New(constructor_class, temp_type_arguments, type.token_index())); |
| 7279 Error& error = Error::Handle(); | 7264 temp_type ^= ClassFinalizer::FinalizeType(current_class(), temp_type); |
| 7280 const Class& scope_class = Class::Handle(TypeParametersScopeClass()); | |
| 7281 temp_type ^= ClassFinalizer::FinalizeAndCanonicalizeType(scope_class, | |
| 7282 temp_type, | |
| 7283 &error); | |
| 7284 if (!error.IsNull()) { | |
| 7285 ErrorMsg(error.ToErrorCString()); | |
| 7286 } | |
| 7287 // The type argument vector may have been expanded with the type arguments | 7265 // The type argument vector may have been expanded with the type arguments |
| 7288 // of the super type when finalizing the temporary type. | 7266 // of the super type when finalizing the temporary type. |
| 7289 type_arguments = temp_type.arguments(); | 7267 type_arguments = temp_type.arguments(); |
| 7290 } | 7268 } |
| 7291 | 7269 |
| 7292 type_arguments ^= type_arguments.Canonicalize(); | 7270 type_arguments ^= type_arguments.Canonicalize(); |
| 7293 // Make the constructor call. | 7271 // Make the constructor call. |
| 7294 AstNode* new_object = NULL; | 7272 AstNode* new_object = NULL; |
| 7295 if (is_const) { | 7273 if (is_const) { |
| 7296 if (!constructor.is_const()) { | 7274 if (!constructor.is_const()) { |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7782 void Parser::SkipQualIdent() { | 7760 void Parser::SkipQualIdent() { |
| 7783 ASSERT(IsIdentifier()); | 7761 ASSERT(IsIdentifier()); |
| 7784 ConsumeToken(); | 7762 ConsumeToken(); |
| 7785 if (CurrentToken() == Token::kPERIOD) { | 7763 if (CurrentToken() == Token::kPERIOD) { |
| 7786 ConsumeToken(); // Consume the kPERIOD token. | 7764 ConsumeToken(); // Consume the kPERIOD token. |
| 7787 ExpectIdentifier("identifier expected after '.'"); | 7765 ExpectIdentifier("identifier expected after '.'"); |
| 7788 } | 7766 } |
| 7789 } | 7767 } |
| 7790 | 7768 |
| 7791 } // namespace dart | 7769 } // namespace dart |
| OLD | NEW |