| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 13 matching lines...) Expand all Loading... |
| 24 DEFINE_FLAG(bool, enable_asserts, false, "Enable assert statements."); | 24 DEFINE_FLAG(bool, enable_asserts, false, "Enable assert statements."); |
| 25 DEFINE_FLAG(bool, enable_type_checks, false, "Enable type checks."); | 25 DEFINE_FLAG(bool, enable_type_checks, false, "Enable type checks."); |
| 26 DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations."); | 26 DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations."); |
| 27 DEFINE_FLAG(bool, warning_as_error, false, "Treat warnings as errors."); | 27 DEFINE_FLAG(bool, warning_as_error, false, "Treat warnings as errors."); |
| 28 DEFINE_FLAG(bool, silent_warnings, false, "Silence warnings."); | 28 DEFINE_FLAG(bool, silent_warnings, false, "Silence warnings."); |
| 29 | 29 |
| 30 // All references to Dart names are listed here. | 30 // All references to Dart names are listed here. |
| 31 static const char* kAssertionErrorName = "AssertionError"; | 31 static const char* kAssertionErrorName = "AssertionError"; |
| 32 static const char* kFallThroughErrorName = "FallThroughError"; | 32 static const char* kFallThroughErrorName = "FallThroughError"; |
| 33 static const char* kThrowNewName = "_throwNew"; | 33 static const char* kThrowNewName = "_throwNew"; |
| 34 static const char* kLiteralFactoryClassName = "_LiteralFactory"; | 34 static const char* kListLiteralFactoryClassName = "_ListLiteralFactory"; |
| 35 static const char* kLiteralFactoryListFromLiteralName = "List.fromLiteral"; | 35 static const char* kListLiteralFactoryName = "List.fromLiteral"; |
| 36 static const char* kLiteralFactoryMapFromLiteralName = "Map.fromLiteral"; | 36 static const char* kMapLiteralFactoryClassName = "_MapLiteralFactory"; |
| 37 static const char* kMapLiteralFactoryName = "Map.fromLiteral"; |
| 37 static const char* kImmutableMapName = "ImmutableMap"; | 38 static const char* kImmutableMapName = "ImmutableMap"; |
| 38 static const char* kImmutableMapConstructorName = "ImmutableMap._create"; | 39 static const char* kImmutableMapConstructorName = "ImmutableMap._create"; |
| 39 static const char* kStringClassName = "StringBase"; | 40 static const char* kStringClassName = "StringBase"; |
| 40 static const char* kInterpolateName = "_interpolate"; | 41 static const char* kInterpolateName = "_interpolate"; |
| 41 static const char* kThisName = "this"; | 42 static const char* kThisName = "this"; |
| 42 static const char* kPhaseParameterName = ":phase"; | 43 static const char* kPhaseParameterName = ":phase"; |
| 43 static const char* kGetIteratorName = "iterator"; | 44 static const char* kGetIteratorName = "iterator"; |
| 44 | 45 |
| 45 #if defined(DEBUG) | 46 #if defined(DEBUG) |
| 46 | 47 |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 CompilerStats::parser_timer.Start(); | 560 CompilerStats::parser_timer.Start(); |
| 560 } | 561 } |
| 561 SequenceNode* node_sequence = NULL; | 562 SequenceNode* node_sequence = NULL; |
| 562 Array& default_parameter_values = Array::Handle(); | 563 Array& default_parameter_values = Array::Handle(); |
| 563 switch (func.kind()) { | 564 switch (func.kind()) { |
| 564 case RawFunction::kFunction: | 565 case RawFunction::kFunction: |
| 565 case RawFunction::kClosureFunction: | 566 case RawFunction::kClosureFunction: |
| 566 case RawFunction::kGetterFunction: | 567 case RawFunction::kGetterFunction: |
| 567 case RawFunction::kSetterFunction: | 568 case RawFunction::kSetterFunction: |
| 568 case RawFunction::kConstructor: | 569 case RawFunction::kConstructor: |
| 569 ASSERT(!func.IsFactory() || (func.signature_class() != Class::null())); | |
| 570 node_sequence = parser.ParseFunc(func, default_parameter_values); | 570 node_sequence = parser.ParseFunc(func, default_parameter_values); |
| 571 break; | 571 break; |
| 572 case RawFunction::kImplicitGetter: | 572 case RawFunction::kImplicitGetter: |
| 573 ASSERT(!func.is_static()); | 573 ASSERT(!func.is_static()); |
| 574 node_sequence = parser.ParseInstanceGetter(func); | 574 node_sequence = parser.ParseInstanceGetter(func); |
| 575 break; | 575 break; |
| 576 case RawFunction::kImplicitSetter: | 576 case RawFunction::kImplicitSetter: |
| 577 ASSERT(!func.is_static()); | 577 ASSERT(!func.is_static()); |
| 578 node_sequence = parser.ParseInstanceSetter(func); | 578 node_sequence = parser.ParseInstanceSetter(func); |
| 579 break; | 579 break; |
| (...skipping 1739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2319 member.type = &AbstractType::ZoneHandle(ParseType(kCanResolve)); | 2319 member.type = &AbstractType::ZoneHandle(ParseType(kCanResolve)); |
| 2320 } | 2320 } |
| 2321 } | 2321 } |
| 2322 } | 2322 } |
| 2323 // Optionally parse a (possibly named) constructor name or factory. | 2323 // Optionally parse a (possibly named) constructor name or factory. |
| 2324 if ((CurrentToken() == Token::kIDENT) && | 2324 if ((CurrentToken() == Token::kIDENT) && |
| 2325 (CurrentLiteral()->Equals(members->class_name()) || member.has_factory)) { | 2325 (CurrentLiteral()->Equals(members->class_name()) || member.has_factory)) { |
| 2326 member.name = CurrentLiteral(); | 2326 member.name = CurrentLiteral(); |
| 2327 member.name_pos = this->token_index_; | 2327 member.name_pos = this->token_index_; |
| 2328 ConsumeToken(); | 2328 ConsumeToken(); |
| 2329 // Resolution of the factory result type is always postponed until class | |
| 2330 // finalization, so that the list of type parameters in the factory | |
| 2331 // signature can be checked at the same time. | |
| 2332 if (member.has_factory) { | 2329 if (member.has_factory) { |
| 2333 String& qualifier = String::Handle(); | 2330 String& qualifier = String::Handle(); |
| 2334 if (CurrentToken() == Token::kPERIOD) { | 2331 if (CurrentToken() == Token::kPERIOD) { |
| 2335 LibraryPrefix& lib_prefix = LibraryPrefix::ZoneHandle(); | 2332 LibraryPrefix& lib_prefix = LibraryPrefix::ZoneHandle(); |
| 2336 lib_prefix = current_class().LookupLibraryPrefix(*member.name); | 2333 lib_prefix = current_class().LookupLibraryPrefix(*member.name); |
| 2337 if (!lib_prefix.IsNull()) { | 2334 if (!lib_prefix.IsNull()) { |
| 2338 // We have a library prefix qualified identifier. | 2335 // We have a library prefix qualified identifier. |
| 2339 ConsumeToken(); // Consume the kPERIOD token. | 2336 ConsumeToken(); // Consume the kPERIOD token. |
| 2340 qualifier ^= member.name->raw(); | 2337 qualifier ^= member.name->raw(); |
| 2341 member.name = ExpectIdentifier("identifier expected"); | 2338 member.name = ExpectIdentifier("identifier expected"); |
| 2342 } | 2339 } |
| 2343 } | 2340 } |
| 2341 // TODO(regis): Remove support for type parameters on factories. |
| 2342 // Once done, stop postponing resolution of the factory result type until |
| 2343 // class finalization. |
| 2344 const UnresolvedClass& unresolved_factory_class = | 2344 const UnresolvedClass& unresolved_factory_class = |
| 2345 UnresolvedClass::Handle(UnresolvedClass::New(member.name_pos, | 2345 UnresolvedClass::Handle(UnresolvedClass::New(member.name_pos, |
| 2346 qualifier, | 2346 qualifier, |
| 2347 *(member.name))); | 2347 *(member.name))); |
| 2348 const Class& signature_class = Class::Handle( | 2348 const Class& signature_class = Class::Handle( |
| 2349 Class::New(String::Handle(String::NewSymbol(":factory_signature")), | 2349 Class::New(String::Handle(String::NewSymbol(":factory_signature")), |
| 2350 script_)); | 2350 script_)); |
| 2351 signature_class.set_is_finalized(); | 2351 signature_class.set_is_finalized(); |
| 2352 signature_class.set_library(library_); | 2352 signature_class.set_library(library_); |
| 2353 unresolved_factory_class.set_factory_signature_class(signature_class); | 2353 unresolved_factory_class.set_factory_signature_class(signature_class); |
| 2354 // The type arguments of the result type are set during finalization. | 2354 // The type arguments of the result type are set during finalization. |
| 2355 const TypeArguments& args = TypeArguments::Handle(); | 2355 const TypeArguments& args = TypeArguments::Handle(); |
| 2356 member.type = &Type::ZoneHandle( | 2356 member.type = &Type::ZoneHandle( |
| 2357 Type::NewParameterizedType(unresolved_factory_class, args)); | 2357 Type::NewParameterizedType(unresolved_factory_class, args)); |
| 2358 ParseTypeParameters(signature_class); | 2358 ParseTypeParameters(signature_class); |
| 2359 if (signature_class.NumTypeParameters() > 0) { |
| 2360 Warning("factory method '%s' should not declare type parameters.\n", |
| 2361 member.name->ToCString()); |
| 2362 } else { |
| 2363 // Remove factory signature class, since no type parameters declared. |
| 2364 unresolved_factory_class.set_factory_signature_class(Class::Handle()); |
| 2365 } |
| 2359 } | 2366 } |
| 2360 // We must be dealing with a constructor or named constructor. | 2367 // We must be dealing with a constructor or named constructor. |
| 2361 member.kind = RawFunction::kConstructor; | 2368 member.kind = RawFunction::kConstructor; |
| 2362 String& ctor_suffix = String::ZoneHandle(String::NewSymbol(".")); | 2369 String& ctor_suffix = String::ZoneHandle(String::NewSymbol(".")); |
| 2363 if (CurrentToken() == Token::kPERIOD) { | 2370 if (CurrentToken() == Token::kPERIOD) { |
| 2364 // Named constructor. | 2371 // Named constructor. |
| 2365 ConsumeToken(); | 2372 ConsumeToken(); |
| 2366 const String* name = ExpectIdentifier("identifier expected"); | 2373 const String* name = ExpectIdentifier("identifier expected"); |
| 2367 ctor_suffix = String::Concat(ctor_suffix, *name); | 2374 ctor_suffix = String::Concat(ctor_suffix, *name); |
| 2368 } | 2375 } |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2739 set_current_class(interface); | 2746 set_current_class(interface); |
| 2740 ParseTypeParameters(interface); | 2747 ParseTypeParameters(interface); |
| 2741 | 2748 |
| 2742 if (CurrentToken() == Token::kEXTENDS) { | 2749 if (CurrentToken() == Token::kEXTENDS) { |
| 2743 Array& interfaces = Array::Handle(); | 2750 Array& interfaces = Array::Handle(); |
| 2744 const intptr_t interfaces_pos = token_index_; | 2751 const intptr_t interfaces_pos = token_index_; |
| 2745 interfaces = ParseInterfaceList(); | 2752 interfaces = ParseInterfaceList(); |
| 2746 AddInterfaces(interfaces_pos, interface, interfaces); | 2753 AddInterfaces(interfaces_pos, interface, interfaces); |
| 2747 } | 2754 } |
| 2748 | 2755 |
| 2749 if (CurrentToken() == Token::kFACTORY) { | 2756 // TODO(regis): Remove support for "factory" keyword. |
| 2757 if ((CurrentToken() == Token::kDEFAULT) || |
| 2758 (CurrentToken() == Token::kFACTORY)) { |
| 2759 if (CurrentToken() == Token::kFACTORY) { |
| 2760 Warning("'factory' is obsolete, use 'default' instead."); |
| 2761 } |
| 2750 ConsumeToken(); | 2762 ConsumeToken(); |
| 2751 const intptr_t factory_pos = token_index_; | 2763 const intptr_t factory_pos = token_index_; |
| 2752 QualIdent factory_name; | 2764 QualIdent factory_name; |
| 2753 ParseQualIdent(&factory_name); | 2765 ParseQualIdent(&factory_name); |
| 2754 if (factory_name.is_local_scope_ident) { | 2766 if (factory_name.is_local_scope_ident) { |
| 2755 ErrorMsg(factory_pos, | 2767 ErrorMsg(factory_pos, |
| 2756 "using '%s' in this context is invalid", | 2768 "using '%s' in this context is invalid", |
| 2757 factory_name.ident->ToCString()); | 2769 factory_name.ident->ToCString()); |
| 2758 } | 2770 } |
| 2759 String& qualifier = String::Handle(); | 2771 String& qualifier = String::Handle(); |
| 2760 if (factory_name.qualifier != NULL) { | 2772 if (factory_name.qualifier != NULL) { |
| 2761 qualifier ^= factory_name.qualifier->raw(); | 2773 qualifier ^= factory_name.qualifier->raw(); |
| 2762 } | 2774 } |
| 2763 const UnresolvedClass& unresolved_factory_class = UnresolvedClass::Handle( | 2775 const UnresolvedClass& unresolved_factory_class = UnresolvedClass::Handle( |
| 2764 UnresolvedClass::New(factory_pos, qualifier, *(factory_name.ident))); | 2776 UnresolvedClass::New(factory_pos, qualifier, *(factory_name.ident))); |
| 2765 const Class& signature_class = Class::Handle( | 2777 const Class& factory_class = Class::Handle( |
| 2766 Class::New(String::Handle(String::NewSymbol(":factory_signature")), | 2778 Class::New(String::Handle(String::NewSymbol(":factory_signature")), |
| 2767 script_)); | 2779 script_)); |
| 2768 signature_class.set_library(library_); | 2780 factory_class.set_library(library_); |
| 2769 signature_class.set_is_finalized(); | 2781 factory_class.set_is_finalized(); |
| 2770 ParseTypeParameters(signature_class); | 2782 ParseTypeParameters(factory_class); |
| 2771 unresolved_factory_class.set_factory_signature_class(signature_class); | 2783 unresolved_factory_class.set_factory_signature_class(factory_class); |
| 2772 interface.set_factory_class(unresolved_factory_class); | 2784 interface.set_factory_class(unresolved_factory_class); |
| 2785 // Verify that the type parameters of the factory class and of the interface |
| 2786 // have identical names. |
| 2787 const intptr_t num_type_params = factory_class.NumTypeParameters(); |
| 2788 bool mismatch = interface.NumTypeParameters() != num_type_params; |
| 2789 if (mismatch && (num_type_params == 0)) { |
| 2790 // TODO(regis): For now, and until the core lib is fixed, we accept a |
| 2791 // factory clause with a class missing its list of type parameters. |
| 2792 // See bug 5408808. |
| 2793 const String& interface_name = String::Handle(interface.Name()); |
| 2794 const String& factory_name = String::Handle(factory_class.Name()); |
| 2795 Warning(factory_pos, |
| 2796 "class '%s' in default clause of interface '%s' is " |
| 2797 "missing its type parameter list.\n", |
| 2798 factory_name.ToCString(), |
| 2799 interface_name.ToCString()); |
| 2800 } else { |
| 2801 String& interface_type_param_name = String::Handle(); |
| 2802 String& factory_type_param_name = String::Handle(); |
| 2803 const Array& interface_type_param_names = |
| 2804 Array::Handle(interface.type_parameters()); |
| 2805 const Array& factory_type_param_names = |
| 2806 Array::Handle(factory_class.type_parameters()); |
| 2807 for (intptr_t i = 0; !mismatch && (i < num_type_params); i++) { |
| 2808 interface_type_param_name ^= interface_type_param_names.At(i); |
| 2809 factory_type_param_name ^= factory_type_param_names.At(i); |
| 2810 if (!interface_type_param_name.Equals(factory_type_param_name)) { |
| 2811 mismatch = true; |
| 2812 } |
| 2813 } |
| 2814 if (mismatch) { |
| 2815 const String& interface_name = String::Handle(interface.Name()); |
| 2816 const String& factory_name = String::Handle(factory_class.Name()); |
| 2817 ErrorMsg(factory_pos, |
| 2818 "mismatch in number or names of type parameters between " |
| 2819 "interface '%s' and default factory class '%s'.\n", |
| 2820 interface_name.ToCString(), |
| 2821 factory_name.ToCString()); |
| 2822 } |
| 2823 } |
| 2773 } | 2824 } |
| 2774 | 2825 |
| 2775 ExpectToken(Token::kLBRACE); | 2826 ExpectToken(Token::kLBRACE); |
| 2776 ClassDesc members(interface, interface_name, true, interface_pos); | 2827 ClassDesc members(interface, interface_name, true, interface_pos); |
| 2777 while (CurrentToken() != Token::kRBRACE) { | 2828 while (CurrentToken() != Token::kRBRACE) { |
| 2778 ParseClassMemberDefinition(&members); | 2829 ParseClassMemberDefinition(&members); |
| 2779 } | 2830 } |
| 2780 ExpectToken(Token::kRBRACE); | 2831 ExpectToken(Token::kRBRACE); |
| 2781 | 2832 |
| 2782 interface.SetFields(Array::Handle(NewArray<Field>(members.fields()))); | 2833 interface.SetFields(Array::Handle(NewArray<Field>(members.fields()))); |
| (...skipping 3372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6155 RawClass* Parser::TypeParametersScopeClass() { | 6206 RawClass* Parser::TypeParametersScopeClass() { |
| 6156 // Type parameters cannot be referred to from a static function, except from | 6207 // Type parameters cannot be referred to from a static function, except from |
| 6157 // a constructor or from a factory. | 6208 // a constructor or from a factory. |
| 6158 // A constructor is considered as non-static by the compiler. | 6209 // A constructor is considered as non-static by the compiler. |
| 6159 if (is_top_level_) { | 6210 if (is_top_level_) { |
| 6160 if ((current_member_ != NULL) && current_member_->has_factory) { | 6211 if ((current_member_ != NULL) && current_member_->has_factory) { |
| 6161 const AbstractType& factory_result_type = *current_member_->type; | 6212 const AbstractType& factory_result_type = *current_member_->type; |
| 6162 ASSERT(!factory_result_type.IsNull()); | 6213 ASSERT(!factory_result_type.IsNull()); |
| 6163 const UnresolvedClass& unresolved_factory_class = | 6214 const UnresolvedClass& unresolved_factory_class = |
| 6164 UnresolvedClass::Handle(factory_result_type.unresolved_class()); | 6215 UnresolvedClass::Handle(factory_result_type.unresolved_class()); |
| 6165 // TODO(regis): For now, and until the core lib is fixed, we accept a | 6216 // TODO(regis): Remove support for type parameters declared by factory |
| 6166 // factory method with missing list of type parameters and use the | 6217 // methods. |
| 6167 // list of the enclosing class. | 6218 if (unresolved_factory_class.factory_signature_class() != Class::null()) { |
| 6168 // See bug 5408808. | 6219 return unresolved_factory_class.factory_signature_class(); |
| 6169 // Therefore, we temporarily return the current class instead of the | |
| 6170 // factory signature class if the latter one does not declare any type | |
| 6171 // parameters. | |
| 6172 const Class& factory_signature_class = | |
| 6173 Class::Handle(unresolved_factory_class.factory_signature_class()); | |
| 6174 if (factory_signature_class.NumTypeParameters() == 0) { | |
| 6175 return current_class().raw(); | |
| 6176 } else { | |
| 6177 return factory_signature_class.raw(); | |
| 6178 } | 6220 } |
| 6221 return current_class().raw(); |
| 6179 } | 6222 } |
| 6180 if ((current_member_ == NULL) || !current_member_->has_static) { | 6223 if ((current_member_ == NULL) || !current_member_->has_static) { |
| 6181 return current_class().raw(); | 6224 return current_class().raw(); |
| 6182 } | 6225 } |
| 6183 } else { | 6226 } else { |
| 6184 if (!current_function().IsNull()) { | 6227 if (!current_function().IsNull()) { |
| 6185 Function& outer_function = Function::Handle(current_function().raw()); | 6228 Function& outer_function = Function::Handle(current_function().raw()); |
| 6186 while (outer_function.IsLocalFunction()) { | 6229 while (outer_function.IsLocalFunction()) { |
| 6187 outer_function = outer_function.parent_function(); | 6230 outer_function = outer_function.parent_function(); |
| 6188 } | 6231 } |
| 6189 if (outer_function.IsFactory()) { | 6232 if (outer_function.IsFactory()) { |
| 6190 return outer_function.signature_class(); | 6233 // TODO(regis): Remove support for type parameters declared by factory |
| 6234 // methods. |
| 6235 if (outer_function.signature_class() != Class::null()) { |
| 6236 return outer_function.signature_class(); |
| 6237 } |
| 6238 return current_class().raw(); |
| 6191 } | 6239 } |
| 6192 if (!outer_function.is_static()) { | 6240 if (!outer_function.is_static()) { |
| 6193 return current_class().raw(); | 6241 return current_class().raw(); |
| 6194 } | 6242 } |
| 6195 } | 6243 } |
| 6196 } | 6244 } |
| 6197 return Class::null(); | 6245 return Class::null(); |
| 6198 } | 6246 } |
| 6199 | 6247 |
| 6200 | 6248 |
| 6201 bool Parser::IsInstantiatorRequired() const { | 6249 bool Parser::IsInstantiatorRequired() const { |
| 6202 ASSERT(!current_function().IsNull()); | 6250 ASSERT(!current_function().IsNull()); |
| 6203 Function& outer_function = Function::Handle(current_function().raw()); | 6251 Function& outer_function = Function::Handle(current_function().raw()); |
| 6204 while (outer_function.IsLocalFunction()) { | 6252 while (outer_function.IsLocalFunction()) { |
| 6205 outer_function = outer_function.parent_function(); | 6253 outer_function = outer_function.parent_function(); |
| 6206 } | 6254 } |
| 6207 if (outer_function.IsFactory()) { | 6255 if (outer_function.IsFactory()) { |
| 6208 const Class& signature_class = | 6256 // TODO(regis): Remove support for type parameters on factories. |
| 6209 Class::Handle(outer_function.signature_class()); | 6257 Class& signature_class = Class::Handle(outer_function.signature_class()); |
| 6258 if (signature_class.IsNull()) { |
| 6259 return current_class().NumTypeParameters() > 0; |
| 6260 } |
| 6210 return signature_class.NumTypeParameters() > 0; | 6261 return signature_class.NumTypeParameters() > 0; |
| 6211 } | 6262 } |
| 6212 if (!outer_function.is_static()) { | 6263 if (!outer_function.is_static()) { |
| 6213 return current_class().NumTypeParameters() > 0; | 6264 return current_class().NumTypeParameters() > 0; |
| 6214 } | 6265 } |
| 6215 return false; | 6266 return false; |
| 6216 } | 6267 } |
| 6217 | 6268 |
| 6218 | 6269 |
| 6219 void Parser::RunStaticFieldInitializer(const Field& field) { | 6270 void Parser::RunStaticFieldInitializer(const Field& field) { |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6612 } | 6663 } |
| 6613 } | 6664 } |
| 6614 return type.raw(); | 6665 return type.raw(); |
| 6615 } | 6666 } |
| 6616 | 6667 |
| 6617 | 6668 |
| 6618 void Parser::CheckConstructorCallTypeArguments( | 6669 void Parser::CheckConstructorCallTypeArguments( |
| 6619 intptr_t pos, Function& constructor, | 6670 intptr_t pos, Function& constructor, |
| 6620 const AbstractTypeArguments& type_arguments) { | 6671 const AbstractTypeArguments& type_arguments) { |
| 6621 if (!type_arguments.IsNull()) { | 6672 if (!type_arguments.IsNull()) { |
| 6673 // TODO(regis): Remove support for type parameters on factories. |
| 6622 Class& signature_class = Class::Handle(); | 6674 Class& signature_class = Class::Handle(); |
| 6623 if (constructor.IsFactory()) { | 6675 if (constructor.IsFactory() && |
| 6676 (constructor.signature_class() != Class::null())) { |
| 6624 signature_class = constructor.signature_class(); | 6677 signature_class = constructor.signature_class(); |
| 6625 } else { | 6678 } else { |
| 6626 signature_class = constructor.owner(); | 6679 signature_class = constructor.owner(); |
| 6627 } | 6680 } |
| 6628 ASSERT(!signature_class.IsNull()); | 6681 ASSERT(!signature_class.IsNull()); |
| 6629 ASSERT(signature_class.is_finalized()); | 6682 ASSERT(signature_class.is_finalized()); |
| 6630 // Do not report the expected vs. actual number of type arguments, because | 6683 // Do not report the expected vs. actual number of type arguments, because |
| 6631 // the type argument vector is flattened and raw types are allowed. | 6684 // the type argument vector is flattened and raw types are allowed. |
| 6632 if (type_arguments.Length() != signature_class.NumTypeArguments()) { | 6685 if (type_arguments.Length() != signature_class.NumTypeArguments()) { |
| 6633 ErrorMsg(pos, "wrong number of type arguments passed to constructor"); | 6686 ErrorMsg(pos, "wrong number of type arguments passed to constructor"); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6728 i, | 6781 i, |
| 6729 String::Handle(element_type.Name()).ToCString()); | 6782 String::Handle(element_type.Name()).ToCString()); |
| 6730 } | 6783 } |
| 6731 const_list.SetAt(i, elem->AsLiteralNode()->literal()); | 6784 const_list.SetAt(i, elem->AsLiteralNode()->literal()); |
| 6732 } | 6785 } |
| 6733 const_list ^= const_list.Canonicalize(); | 6786 const_list ^= const_list.Canonicalize(); |
| 6734 const_list.MakeImmutable(); | 6787 const_list.MakeImmutable(); |
| 6735 return new LiteralNode(literal_pos, const_list); | 6788 return new LiteralNode(literal_pos, const_list); |
| 6736 } else { | 6789 } else { |
| 6737 // Factory call at runtime. | 6790 // Factory call at runtime. |
| 6738 String& literal_factory_class_name = String::Handle( | 6791 String& list_literal_factory_class_name = String::Handle( |
| 6739 String::NewSymbol(kLiteralFactoryClassName)); | 6792 String::NewSymbol(kListLiteralFactoryClassName)); |
| 6740 const Class& literal_factory_class = | 6793 const Class& list_literal_factory_class = |
| 6741 Class::Handle(LookupCoreClass(literal_factory_class_name)); | 6794 Class::Handle(LookupCoreClass(list_literal_factory_class_name)); |
| 6742 ASSERT(!literal_factory_class.IsNull()); | 6795 ASSERT(!list_literal_factory_class.IsNull()); |
| 6743 const String& literal_list_factory_name = | 6796 const String& list_literal_factory_name = |
| 6744 String::Handle(String::NewSymbol(kLiteralFactoryListFromLiteralName)); | 6797 String::Handle(String::NewSymbol(kListLiteralFactoryName)); |
| 6745 const Function& literal_list_factory = Function::ZoneHandle( | 6798 const Function& list_literal_factory = Function::ZoneHandle( |
| 6746 literal_factory_class.LookupFactory(literal_list_factory_name)); | 6799 list_literal_factory_class.LookupFactory(list_literal_factory_name)); |
| 6747 ASSERT(!literal_list_factory.IsNull()); | 6800 ASSERT(!list_literal_factory.IsNull()); |
| 6748 if (!type_arguments.IsNull() && | 6801 if (!type_arguments.IsNull() && |
| 6749 !type_arguments.IsInstantiated() && | 6802 !type_arguments.IsInstantiated() && |
| 6750 (current_block_->scope->function_level() > 0)) { | 6803 (current_block_->scope->function_level() > 0)) { |
| 6751 // Make sure that the instantiator is captured. | 6804 // Make sure that the instantiator is captured. |
| 6752 CaptureReceiver(); | 6805 CaptureReceiver(); |
| 6753 } | 6806 } |
| 6754 ArgumentListNode* factory_param = new ArgumentListNode(literal_pos); | 6807 ArgumentListNode* factory_param = new ArgumentListNode(literal_pos); |
| 6755 factory_param->Add(list); | 6808 factory_param->Add(list); |
| 6756 AbstractTypeArguments& canonical_type_arguments = | 6809 AbstractTypeArguments& canonical_type_arguments = |
| 6757 AbstractTypeArguments::ZoneHandle(type_arguments.Canonicalize()); | 6810 AbstractTypeArguments::ZoneHandle(type_arguments.Canonicalize()); |
| 6758 return new ConstructorCallNode(literal_pos, | 6811 return new ConstructorCallNode(literal_pos, |
| 6759 canonical_type_arguments, | 6812 canonical_type_arguments, |
| 6760 literal_list_factory, | 6813 list_literal_factory, |
| 6761 factory_param); | 6814 factory_param); |
| 6762 } | 6815 } |
| 6763 } | 6816 } |
| 6764 | 6817 |
| 6765 | 6818 |
| 6766 static void AddKeyValuePair(ArrayNode* pairs, | 6819 static void AddKeyValuePair(ArrayNode* pairs, |
| 6767 bool is_const, | 6820 bool is_const, |
| 6768 AstNode* key, | 6821 AstNode* key, |
| 6769 AstNode* value) { | 6822 AstNode* value) { |
| 6770 if (is_const) { | 6823 if (is_const) { |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6931 map_type_arguments, | 6984 map_type_arguments, |
| 6932 map_constr, | 6985 map_constr, |
| 6933 constr_args)); | 6986 constr_args)); |
| 6934 if (const_instance.IsUnhandledException()) { | 6987 if (const_instance.IsUnhandledException()) { |
| 6935 return CreateEvalConstConstructorThrow(literal_pos, const_instance); | 6988 return CreateEvalConstConstructorThrow(literal_pos, const_instance); |
| 6936 } else { | 6989 } else { |
| 6937 return new LiteralNode(literal_pos, const_instance); | 6990 return new LiteralNode(literal_pos, const_instance); |
| 6938 } | 6991 } |
| 6939 } else { | 6992 } else { |
| 6940 // Factory call at runtime. | 6993 // Factory call at runtime. |
| 6941 String& literal_factory_class_name = String::Handle( | 6994 String& map_literal_factory_class_name = String::Handle( |
| 6942 String::NewSymbol(kLiteralFactoryClassName)); | 6995 String::NewSymbol(kMapLiteralFactoryClassName)); |
| 6943 const Class& literal_factory_class = | 6996 const Class& map_literal_factory_class = |
| 6944 Class::Handle(LookupCoreClass(literal_factory_class_name)); | 6997 Class::Handle(LookupCoreClass(map_literal_factory_class_name)); |
| 6945 ASSERT(!literal_factory_class.IsNull()); | 6998 ASSERT(!map_literal_factory_class.IsNull()); |
| 6946 const String& literal_map_factory_name = | 6999 const String& map_literal_factory_name = |
| 6947 String::Handle(String::NewSymbol(kLiteralFactoryMapFromLiteralName)); | 7000 String::Handle(String::NewSymbol(kMapLiteralFactoryName)); |
| 6948 const Function& literal_map_factory = Function::ZoneHandle( | 7001 const Function& map_literal_factory = Function::ZoneHandle( |
| 6949 literal_factory_class.LookupFactory(literal_map_factory_name)); | 7002 map_literal_factory_class.LookupFactory(map_literal_factory_name)); |
| 6950 ASSERT(!literal_map_factory.IsNull()); | 7003 ASSERT(!map_literal_factory.IsNull()); |
| 6951 if (!map_type_arguments.IsNull() && | 7004 if (!map_type_arguments.IsNull() && |
| 6952 !map_type_arguments.IsInstantiated() && | 7005 !map_type_arguments.IsInstantiated() && |
| 6953 (current_block_->scope->function_level() > 0)) { | 7006 (current_block_->scope->function_level() > 0)) { |
| 6954 // Make sure that the instantiator is captured. | 7007 // Make sure that the instantiator is captured. |
| 6955 CaptureReceiver(); | 7008 CaptureReceiver(); |
| 6956 } | 7009 } |
| 6957 ArgumentListNode* factory_param = new ArgumentListNode(literal_pos); | 7010 ArgumentListNode* factory_param = new ArgumentListNode(literal_pos); |
| 6958 factory_param->Add(kv_pairs); | 7011 factory_param->Add(kv_pairs); |
| 6959 return new ConstructorCallNode(literal_pos, | 7012 return new ConstructorCallNode(literal_pos, |
| 6960 map_type_arguments, | 7013 map_type_arguments, |
| 6961 literal_map_factory, | 7014 map_literal_factory, |
| 6962 factory_param); | 7015 factory_param); |
| 6963 } | 7016 } |
| 6964 } | 7017 } |
| 6965 | 7018 |
| 6966 | 7019 |
| 6967 AstNode* Parser::ParseCompoundLiteral() { | 7020 AstNode* Parser::ParseCompoundLiteral() { |
| 6968 bool is_const = false; | 7021 bool is_const = false; |
| 6969 if (CurrentToken() == Token::kCONST) { | 7022 if (CurrentToken() == Token::kCONST) { |
| 6970 is_const = true; | 7023 is_const = true; |
| 6971 ConsumeToken(); | 7024 ConsumeToken(); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7139 if (!constructor.AreValidArguments(arguments_length, arguments->names())) { | 7192 if (!constructor.AreValidArguments(arguments_length, arguments->names())) { |
| 7140 ErrorMsg(new_pos, "invalid arguments passed to constructor '%s' " | 7193 ErrorMsg(new_pos, "invalid arguments passed to constructor '%s' " |
| 7141 "for class '%s'", | 7194 "for class '%s'", |
| 7142 external_constructor_name.ToCString(), | 7195 external_constructor_name.ToCString(), |
| 7143 String::Handle(type_class.Name()).ToCString()); | 7196 String::Handle(type_class.Name()).ToCString()); |
| 7144 } | 7197 } |
| 7145 | 7198 |
| 7146 // Now that the constructor to be called is identified, finalize the type | 7199 // Now that the constructor to be called is identified, finalize the type |
| 7147 // argument vector to be passed. | 7200 // argument vector to be passed. |
| 7148 { | 7201 { |
| 7202 // TODO(regis): Remove support for type parameters on factories. |
| 7149 Class& signature_class = Class::Handle(); | 7203 Class& signature_class = Class::Handle(); |
| 7150 if (constructor.IsFactory()) { | 7204 if (constructor.IsFactory() && |
| 7205 (constructor.signature_class() != Class::null())) { |
| 7151 signature_class = constructor.signature_class(); | 7206 signature_class = constructor.signature_class(); |
| 7152 } else { | 7207 } else { |
| 7153 signature_class = constructor.owner(); | 7208 signature_class = constructor.owner(); |
| 7154 ASSERT(signature_class.raw() == type_class.raw()); | 7209 ASSERT(signature_class.raw() == type_class.raw()); |
| 7155 } | 7210 } |
| 7156 // TODO(regis): Temporary type should be allocated in new gen heap. | 7211 // TODO(regis): Temporary type should be allocated in new gen heap. |
| 7157 Type& type = Type::Handle( | 7212 Type& type = Type::Handle( |
| 7158 Type::NewParameterizedType(signature_class, type_arguments)); | 7213 Type::NewParameterizedType(signature_class, type_arguments)); |
| 7159 String& errmsg = String::Handle(); | 7214 String& errmsg = String::Handle(); |
| 7160 type ^= ClassFinalizer::FinalizeAndCanonicalizeType(signature_class, | 7215 type ^= ClassFinalizer::FinalizeAndCanonicalizeType(signature_class, |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7632 } | 7687 } |
| 7633 | 7688 |
| 7634 | 7689 |
| 7635 void Parser::SkipNestedExpr() { | 7690 void Parser::SkipNestedExpr() { |
| 7636 const bool saved_mode = SetAllowFunctionLiterals(true); | 7691 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 7637 SkipExpr(); | 7692 SkipExpr(); |
| 7638 SetAllowFunctionLiterals(saved_mode); | 7693 SetAllowFunctionLiterals(saved_mode); |
| 7639 } | 7694 } |
| 7640 | 7695 |
| 7641 } // namespace dart | 7696 } // namespace dart |
| OLD | NEW |