| 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 2053 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2064 | 2064 |
| 2065 // Finish parsing the function type parameter. | 2065 // Finish parsing the function type parameter. |
| 2066 if (CurrentToken() == Token::kLT) { | 2066 if (CurrentToken() == Token::kLT) { |
| 2067 if (!FLAG_generic_method_syntax) { | 2067 if (!FLAG_generic_method_syntax) { |
| 2068 ReportError("generic function types not supported"); | 2068 ReportError("generic function types not supported"); |
| 2069 } | 2069 } |
| 2070 ParseTypeParameters(false); // Not parameterizing class, but function. | 2070 ParseTypeParameters(false); // Not parameterizing class, but function. |
| 2071 } | 2071 } |
| 2072 | 2072 |
| 2073 // Now that type parameters are declared, the result type can be resolved. | 2073 // Now that type parameters are declared, the result type can be resolved. |
| 2074 ResolveType(ClassFinalizer::kResolveTypeParameters, &result_type); | 2074 ResolveType(is_top_level_ ? ClassFinalizer::kResolveTypeParameters |
| 2075 : ClassFinalizer::kCanonicalize, |
| 2076 &result_type); |
| 2075 | 2077 |
| 2076 ASSERT(CurrentToken() == Token::kLPAREN); | 2078 ASSERT(CurrentToken() == Token::kLPAREN); |
| 2077 ParamList func_params; | 2079 ParamList func_params; |
| 2078 | 2080 |
| 2079 // Add implicit closure object parameter. | 2081 // Add implicit closure object parameter. |
| 2080 func_params.AddFinalParameter(TokenPos(), &Symbols::ClosureParameter(), | 2082 func_params.AddFinalParameter(TokenPos(), &Symbols::ClosureParameter(), |
| 2081 &Object::dynamic_type()); | 2083 &Object::dynamic_type()); |
| 2082 | 2084 |
| 2083 const bool no_explicit_default_values = false; | 2085 const bool no_explicit_default_values = false; |
| 2084 ParseFormalParameterList(no_explicit_default_values, false, &func_params); | 2086 ParseFormalParameterList(no_explicit_default_values, false, &func_params); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2101 // A signature type itself cannot be malformed or malbounded, only its | 2103 // A signature type itself cannot be malformed or malbounded, only its |
| 2102 // signature function's result type or parameter types may be. | 2104 // signature function's result type or parameter types may be. |
| 2103 ASSERT(!signature_type.IsMalformed()); | 2105 ASSERT(!signature_type.IsMalformed()); |
| 2104 ASSERT(!signature_type.IsMalbounded()); | 2106 ASSERT(!signature_type.IsMalbounded()); |
| 2105 // The type of the parameter is now the signature type. | 2107 // The type of the parameter is now the signature type. |
| 2106 parameter.type = &signature_type; | 2108 parameter.type = &signature_type; |
| 2107 } | 2109 } |
| 2108 } else { | 2110 } else { |
| 2109 if (!parameter.type->IsFinalized()) { | 2111 if (!parameter.type->IsFinalized()) { |
| 2110 AbstractType& type = AbstractType::ZoneHandle(Z, parameter.type->raw()); | 2112 AbstractType& type = AbstractType::ZoneHandle(Z, parameter.type->raw()); |
| 2111 ResolveType(ClassFinalizer::kResolveTypeParameters, &type); | 2113 if (is_top_level_) { |
| 2112 if (!is_top_level_) { | 2114 ResolveType(ClassFinalizer::kResolveTypeParameters, &type); |
| 2113 type = ClassFinalizer::FinalizeType( | 2115 } else { |
| 2114 Class::Handle(Z, innermost_function().origin()), type, | 2116 ResolveType(ClassFinalizer::kCanonicalize, &type); |
| 2115 ClassFinalizer::kCanonicalize); | 2117 type = ClassFinalizer::FinalizeType(current_class(), type, |
| 2118 ClassFinalizer::kCanonicalize); |
| 2116 } | 2119 } |
| 2117 parameter.type = &type; | 2120 parameter.type = &type; |
| 2118 } | 2121 } |
| 2119 } | 2122 } |
| 2120 | 2123 |
| 2121 if ((CurrentToken() == Token::kASSIGN) || (CurrentToken() == Token::kCOLON)) { | 2124 if ((CurrentToken() == Token::kASSIGN) || (CurrentToken() == Token::kCOLON)) { |
| 2122 if ((!params->has_optional_positional_parameters && | 2125 if ((!params->has_optional_positional_parameters && |
| 2123 !params->has_optional_named_parameters) || | 2126 !params->has_optional_named_parameters) || |
| 2124 !allow_explicit_default_value) { | 2127 !allow_explicit_default_value) { |
| 2125 ReportError("parameter must not specify a default value"); | 2128 ReportError("parameter must not specify a default value"); |
| (...skipping 5540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7666 if (!found_func) { | 7669 if (!found_func) { |
| 7667 ParseTypeParameters(false); // Not parameterizing class, but function. | 7670 ParseTypeParameters(false); // Not parameterizing class, but function. |
| 7668 } else { | 7671 } else { |
| 7669 TryParseTypeParameters(); | 7672 TryParseTypeParameters(); |
| 7670 } | 7673 } |
| 7671 } | 7674 } |
| 7672 | 7675 |
| 7673 if (!found_func && !result_type.IsFinalized()) { | 7676 if (!found_func && !result_type.IsFinalized()) { |
| 7674 // Now that type parameters are declared, the result type can be resolved | 7677 // Now that type parameters are declared, the result type can be resolved |
| 7675 // and finalized. | 7678 // and finalized. |
| 7676 ResolveType(ClassFinalizer::kResolveTypeParameters, &result_type); | 7679 ResolveType(ClassFinalizer::kCanonicalize, &result_type); |
| 7677 result_type = ClassFinalizer::FinalizeType(current_class(), result_type, | 7680 result_type = ClassFinalizer::FinalizeType(current_class(), result_type, |
| 7678 ClassFinalizer::kCanonicalize); | 7681 ClassFinalizer::kCanonicalize); |
| 7679 function.set_result_type(result_type); | 7682 function.set_result_type(result_type); |
| 7680 } | 7683 } |
| 7681 | 7684 |
| 7682 CheckToken(Token::kLPAREN); | 7685 CheckToken(Token::kLPAREN); |
| 7683 | 7686 |
| 7684 // The function type needs to be finalized at compile time, since the closure | 7687 // The function type needs to be finalized at compile time, since the closure |
| 7685 // may be type checked at run time when assigned to a function variable, | 7688 // may be type checked at run time when assigned to a function variable, |
| 7686 // passed as a function argument, or returned as a function result. | 7689 // passed as a function argument, or returned as a function result. |
| (...skipping 4223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11910 "type parameter '%s' cannot be parameterized", | 11913 "type parameter '%s' cannot be parameterized", |
| 11911 String::Handle(Z, type_parameter.name()).ToCString()); | 11914 String::Handle(Z, type_parameter.name()).ToCString()); |
| 11912 return; | 11915 return; |
| 11913 } | 11916 } |
| 11914 *type = type_parameter.raw(); | 11917 *type = type_parameter.raw(); |
| 11915 return; | 11918 return; |
| 11916 } | 11919 } |
| 11917 // The referenced class may not have been parsed yet. It would be wrong | 11920 // The referenced class may not have been parsed yet. It would be wrong |
| 11918 // to resolve it too early to an imported class of the same name. Only | 11921 // to resolve it too early to an imported class of the same name. Only |
| 11919 // resolve the class when a finalized type is requested. | 11922 // resolve the class when a finalized type is requested. |
| 11923 // Note that when compiling a cloned mixin function, library_ may be |
| 11924 // different than current_class's library. |
| 11920 if (finalization > ClassFinalizer::kResolveTypeParameters) { | 11925 if (finalization > ClassFinalizer::kResolveTypeParameters) { |
| 11921 resolved_type_class = library_.LookupClass(unresolved_class_name); | 11926 resolved_type_class = library_.LookupClass(unresolved_class_name); |
| 11922 } | 11927 } |
| 11923 } else { | 11928 } else { |
| 11924 // Resolve class name in the scope of the library prefix. | 11929 // Resolve class name in the scope of the library prefix. |
| 11925 const Object& prefix = | 11930 const Object& prefix = |
| 11926 Object::Handle(Z, unresolved_class.library_or_library_prefix()); | 11931 Object::Handle(Z, unresolved_class.library_or_library_prefix()); |
| 11927 ASSERT(prefix.IsLibraryPrefix()); | 11932 ASSERT(prefix.IsLibraryPrefix()); |
| 11928 resolved_type_class = | 11933 resolved_type_class = |
| 11929 LibraryPrefix::Cast(prefix).LookupClass(unresolved_class_name); | 11934 LibraryPrefix::Cast(prefix).LookupClass(unresolved_class_name); |
| (...skipping 2575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14505 const ArgumentListNode& function_args, | 14510 const ArgumentListNode& function_args, |
| 14506 const LocalVariable* temp_for_last_arg, | 14511 const LocalVariable* temp_for_last_arg, |
| 14507 bool is_super_invocation) { | 14512 bool is_super_invocation) { |
| 14508 UNREACHABLE(); | 14513 UNREACHABLE(); |
| 14509 return NULL; | 14514 return NULL; |
| 14510 } | 14515 } |
| 14511 | 14516 |
| 14512 } // namespace dart | 14517 } // namespace dart |
| 14513 | 14518 |
| 14514 #endif // DART_PRECOMPILED_RUNTIME | 14519 #endif // DART_PRECOMPILED_RUNTIME |
| OLD | NEW |