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 13466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13477 TypeArguments::Handle(Z, list_type_arguments.Canonicalize())); | 13477 TypeArguments::Handle(Z, list_type_arguments.Canonicalize())); |
13478 Error& bound_error = Error::Handle(Z); | 13478 Error& bound_error = Error::Handle(Z); |
13479 for (int i = 0; i < element_list.length(); i++) { | 13479 for (int i = 0; i < element_list.length(); i++) { |
13480 AstNode* elem = element_list[i]; | 13480 AstNode* elem = element_list[i]; |
13481 // Arguments have been evaluated to a literal value already. | 13481 // Arguments have been evaluated to a literal value already. |
13482 ASSERT(elem->IsLiteralNode()); | 13482 ASSERT(elem->IsLiteralNode()); |
13483 ASSERT(!is_top_level_); // We cannot check unresolved types. | 13483 ASSERT(!is_top_level_); // We cannot check unresolved types. |
13484 if (I->type_checks() && !element_type.IsDynamicType() && | 13484 if (I->type_checks() && !element_type.IsDynamicType() && |
13485 (!elem->AsLiteralNode()->literal().IsNull() && | 13485 (!elem->AsLiteralNode()->literal().IsNull() && |
13486 !elem->AsLiteralNode()->literal().IsInstanceOf( | 13486 !elem->AsLiteralNode()->literal().IsInstanceOf( |
13487 element_type, Object::null_type_arguments(), &bound_error))) { | 13487 element_type, Object::null_type_arguments(), |
| 13488 Object::null_type_arguments(), &bound_error))) { |
13488 // If the failure is due to a bound error, display it instead. | 13489 // If the failure is due to a bound error, display it instead. |
13489 if (!bound_error.IsNull()) { | 13490 if (!bound_error.IsNull()) { |
13490 ReportError(bound_error); | 13491 ReportError(bound_error); |
13491 } else { | 13492 } else { |
13492 ReportError( | 13493 ReportError( |
13493 elem->AsLiteralNode()->token_pos(), | 13494 elem->AsLiteralNode()->token_pos(), |
13494 "list literal element at index %d must be " | 13495 "list literal element at index %d must be " |
13495 "a constant of type '%s'", | 13496 "a constant of type '%s'", |
13496 i, String::Handle(Z, element_type.UserVisibleName()).ToCString()); | 13497 i, String::Handle(Z, element_type.UserVisibleName()).ToCString()); |
13497 } | 13498 } |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13701 if ((i % 2) == 0) { | 13702 if ((i % 2) == 0) { |
13702 // Check key type. | 13703 // Check key type. |
13703 arg_type = key_type.raw(); | 13704 arg_type = key_type.raw(); |
13704 } else { | 13705 } else { |
13705 // Check value type. | 13706 // Check value type. |
13706 arg_type = value_type.raw(); | 13707 arg_type = value_type.raw(); |
13707 } | 13708 } |
13708 if (!arg_type.IsDynamicType() && | 13709 if (!arg_type.IsDynamicType() && |
13709 (!arg->AsLiteralNode()->literal().IsNull() && | 13710 (!arg->AsLiteralNode()->literal().IsNull() && |
13710 !arg->AsLiteralNode()->literal().IsInstanceOf( | 13711 !arg->AsLiteralNode()->literal().IsInstanceOf( |
13711 arg_type, Object::null_type_arguments(), &bound_error))) { | 13712 arg_type, Object::null_type_arguments(), |
| 13713 Object::null_type_arguments(), &bound_error))) { |
13712 // If the failure is due to a bound error, display it. | 13714 // If the failure is due to a bound error, display it. |
13713 if (!bound_error.IsNull()) { | 13715 if (!bound_error.IsNull()) { |
13714 ReportError(bound_error); | 13716 ReportError(bound_error); |
13715 } else { | 13717 } else { |
13716 ReportError( | 13718 ReportError( |
13717 arg->AsLiteralNode()->token_pos(), | 13719 arg->AsLiteralNode()->token_pos(), |
13718 "map literal %s at index %d must be " | 13720 "map literal %s at index %d must be " |
13719 "a constant of type '%s'", | 13721 "a constant of type '%s'", |
13720 ((i % 2) == 0) ? "key" : "value", i >> 1, | 13722 ((i % 2) == 0) ? "key" : "value", i >> 1, |
13721 String::Handle(Z, arg_type.UserVisibleName()).ToCString()); | 13723 String::Handle(Z, arg_type.UserVisibleName()).ToCString()); |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13981 BuildConstructorName(T, type_class_name, named_constructor); | 13983 BuildConstructorName(T, type_class_name, named_constructor); |
13982 *constructor = type_class.LookupConstructor(constructor_name); | 13984 *constructor = type_class.LookupConstructor(constructor_name); |
13983 if (constructor->IsNull()) { | 13985 if (constructor->IsNull()) { |
13984 *constructor = type_class.LookupFactory(constructor_name); | 13986 *constructor = type_class.LookupFactory(constructor_name); |
13985 ASSERT(!constructor->IsNull()); | 13987 ASSERT(!constructor->IsNull()); |
13986 if (constructor->IsRedirectingFactory()) { | 13988 if (constructor->IsRedirectingFactory()) { |
13987 ClassFinalizer::ResolveRedirectingFactory(type_class, *constructor); | 13989 ClassFinalizer::ResolveRedirectingFactory(type_class, *constructor); |
13988 type = constructor->RedirectionType(); | 13990 type = constructor->RedirectionType(); |
13989 ASSERT(!type.IsMalformedOrMalbounded()); | 13991 ASSERT(!type.IsMalformedOrMalbounded()); |
13990 if (!type.IsInstantiated()) { | 13992 if (!type.IsInstantiated()) { |
| 13993 ASSERT(type.IsInstantiated(kFunctions)); // No generic constructors. |
13991 Error& error = Error::Handle(Z); | 13994 Error& error = Error::Handle(Z); |
13992 type ^= type.InstantiateFrom(*type_arguments, &error, | 13995 type ^= type.InstantiateFrom(*type_arguments, |
| 13996 Object::null_type_arguments(), &error, |
13993 NULL, // instantiation_trail | 13997 NULL, // instantiation_trail |
13994 NULL, // bound_trail | 13998 NULL, // bound_trail |
13995 Heap::kOld); | 13999 Heap::kOld); |
13996 ASSERT(error.IsNull()); | 14000 ASSERT(error.IsNull()); |
13997 } | 14001 } |
13998 *type_arguments = type.arguments(); | 14002 *type_arguments = type.arguments(); |
13999 *constructor = constructor->RedirectionTarget(); | 14003 *constructor = constructor->RedirectionTarget(); |
14000 } | 14004 } |
14001 } | 14005 } |
14002 } | 14006 } |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14145 } | 14149 } |
14146 return ThrowNoSuchMethodError( | 14150 return ThrowNoSuchMethodError( |
14147 call_pos, type_class, external_constructor_name, arguments, | 14151 call_pos, type_class, external_constructor_name, arguments, |
14148 InvocationMirror::kConstructor, InvocationMirror::kMethod, | 14152 InvocationMirror::kConstructor, InvocationMirror::kMethod, |
14149 NULL); // No existing function. | 14153 NULL); // No existing function. |
14150 } else if (constructor.IsRedirectingFactory()) { | 14154 } else if (constructor.IsRedirectingFactory()) { |
14151 ClassFinalizer::ResolveRedirectingFactory(type_class, constructor); | 14155 ClassFinalizer::ResolveRedirectingFactory(type_class, constructor); |
14152 Type& redirect_type = Type::ZoneHandle(Z, constructor.RedirectionType()); | 14156 Type& redirect_type = Type::ZoneHandle(Z, constructor.RedirectionType()); |
14153 if (!redirect_type.IsMalformedOrMalbounded() && | 14157 if (!redirect_type.IsMalformedOrMalbounded() && |
14154 !redirect_type.IsInstantiated()) { | 14158 !redirect_type.IsInstantiated()) { |
| 14159 // No generic constructors allowed. |
| 14160 ASSERT(redirect_type.IsInstantiated(kFunctions)); |
14155 // The type arguments of the redirection type are instantiated from the | 14161 // The type arguments of the redirection type are instantiated from the |
14156 // type arguments of the parsed type of the 'new' or 'const' expression. | 14162 // type arguments of the parsed type of the 'new' or 'const' expression. |
14157 Error& error = Error::Handle(Z); | 14163 Error& error = Error::Handle(Z); |
14158 redirect_type ^= | 14164 redirect_type ^= redirect_type.InstantiateFrom( |
14159 redirect_type.InstantiateFrom(type_arguments, &error, | 14165 type_arguments, Object::null_type_arguments(), &error, |
14160 NULL, // instantiation_trail | 14166 NULL, // instantiation_trail |
14161 NULL, // bound_trail | 14167 NULL, // bound_trail |
14162 Heap::kOld); | 14168 Heap::kOld); |
14163 if (!error.IsNull()) { | 14169 if (!error.IsNull()) { |
14164 redirect_type = ClassFinalizer::NewFinalizedMalformedType( | 14170 redirect_type = ClassFinalizer::NewFinalizedMalformedType( |
14165 error, script_, call_pos, | 14171 error, script_, call_pos, |
14166 "redirecting factory type '%s' cannot be instantiated", | 14172 "redirecting factory type '%s' cannot be instantiated", |
14167 String::Handle(Z, redirect_type.UserVisibleName()).ToCString()); | 14173 String::Handle(Z, redirect_type.UserVisibleName()).ToCString()); |
14168 } | 14174 } |
14169 } | 14175 } |
14170 if (!redirect_type.HasResolvedTypeClass()) { | 14176 if (!redirect_type.HasResolvedTypeClass()) { |
14171 // If the redirection type is unresolved, we convert the allocation | 14177 // If the redirection type is unresolved, we convert the allocation |
14172 // into throwing a type error. | 14178 // into throwing a type error. |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14315 } | 14321 } |
14316 const_instance ^= constructor_result.raw(); | 14322 const_instance ^= constructor_result.raw(); |
14317 CacheConstantValue(new_pos, const_instance); | 14323 CacheConstantValue(new_pos, const_instance); |
14318 } | 14324 } |
14319 new_object = new (Z) LiteralNode(new_pos, const_instance); | 14325 new_object = new (Z) LiteralNode(new_pos, const_instance); |
14320 if (!type_bound.IsNull()) { | 14326 if (!type_bound.IsNull()) { |
14321 ASSERT(!type_bound.IsMalformed()); | 14327 ASSERT(!type_bound.IsMalformed()); |
14322 Error& bound_error = Error::Handle(Z); | 14328 Error& bound_error = Error::Handle(Z); |
14323 ASSERT(!is_top_level_); // We cannot check unresolved types. | 14329 ASSERT(!is_top_level_); // We cannot check unresolved types. |
14324 if (!const_instance.IsInstanceOf( | 14330 if (!const_instance.IsInstanceOf( |
14325 type_bound, Object::null_type_arguments(), &bound_error)) { | 14331 type_bound, Object::null_type_arguments(), |
| 14332 Object::null_type_arguments(), &bound_error)) { |
14326 type_bound = ClassFinalizer::NewFinalizedMalformedType( | 14333 type_bound = ClassFinalizer::NewFinalizedMalformedType( |
14327 bound_error, script_, new_pos, | 14334 bound_error, script_, new_pos, |
14328 "const factory result is not an instance of '%s'", | 14335 "const factory result is not an instance of '%s'", |
14329 String::Handle(Z, type_bound.UserVisibleName()).ToCString()); | 14336 String::Handle(Z, type_bound.UserVisibleName()).ToCString()); |
14330 new_object = ThrowTypeError(new_pos, type_bound); | 14337 new_object = ThrowTypeError(new_pos, type_bound); |
14331 } | 14338 } |
14332 type_bound = AbstractType::null(); | 14339 type_bound = AbstractType::null(); |
14333 } | 14340 } |
14334 } else { | 14341 } else { |
14335 CheckConstructorCallTypeArguments(new_pos, constructor, type_arguments); | 14342 CheckConstructorCallTypeArguments(new_pos, constructor, type_arguments); |
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15207 const ArgumentListNode& function_args, | 15214 const ArgumentListNode& function_args, |
15208 const LocalVariable* temp_for_last_arg, | 15215 const LocalVariable* temp_for_last_arg, |
15209 bool is_super_invocation) { | 15216 bool is_super_invocation) { |
15210 UNREACHABLE(); | 15217 UNREACHABLE(); |
15211 return NULL; | 15218 return NULL; |
15212 } | 15219 } |
15213 | 15220 |
15214 } // namespace dart | 15221 } // namespace dart |
15215 | 15222 |
15216 #endif // DART_PRECOMPILED_RUNTIME | 15223 #endif // DART_PRECOMPILED_RUNTIME |
OLD | NEW |