OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/class_finalizer.h" | 5 #include "vm/class_finalizer.h" |
6 | 6 |
7 #include "vm/flags.h" | 7 #include "vm/flags.h" |
8 #include "vm/heap.h" | 8 #include "vm/heap.h" |
9 #include "vm/isolate.h" | 9 #include "vm/isolate.h" |
10 #include "vm/longjump.h" | 10 #include "vm/longjump.h" |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 OS::Exit(255); | 246 OS::Exit(255); |
247 } | 247 } |
248 if (FLAG_trace_class_finalization) { | 248 if (FLAG_trace_class_finalization) { |
249 OS::Print("VerifyBootstrapClasses END.\n"); | 249 OS::Print("VerifyBootstrapClasses END.\n"); |
250 } | 250 } |
251 Isolate::Current()->heap()->Verify(); | 251 Isolate::Current()->heap()->Verify(); |
252 } | 252 } |
253 | 253 |
254 | 254 |
255 // Resolve unresolved_class in the library of cls, or return null. | 255 // Resolve unresolved_class in the library of cls, or return null. |
256 RawClass* ClassFinalizer::ResolveClass(const Class& cls, | 256 RawClass* ClassFinalizer::ResolveClass( |
257 const UnresolvedClass& unresolved_class, | 257 const Class& cls, |
258 Error* ambiguity_error) { | 258 const UnresolvedClass& unresolved_class) { |
259 const String& class_name = String::Handle(unresolved_class.ident()); | 259 const String& class_name = String::Handle(unresolved_class.ident()); |
260 Library& lib = Library::Handle(); | 260 Library& lib = Library::Handle(); |
261 Class& resolved_class = Class::Handle(); | 261 Class& resolved_class = Class::Handle(); |
262 String& ambiguity_error_msg = String::Handle(); | |
263 if (unresolved_class.library_prefix() == LibraryPrefix::null()) { | 262 if (unresolved_class.library_prefix() == LibraryPrefix::null()) { |
264 lib = cls.library(); | 263 lib = cls.library(); |
265 ASSERT(!lib.IsNull()); | 264 ASSERT(!lib.IsNull()); |
266 resolved_class = lib.LookupClass(class_name, &ambiguity_error_msg); | 265 resolved_class = lib.LookupClass(class_name); |
267 } else { | 266 } else { |
268 LibraryPrefix& lib_prefix = LibraryPrefix::Handle(); | 267 LibraryPrefix& lib_prefix = LibraryPrefix::Handle(); |
269 lib_prefix = unresolved_class.library_prefix(); | 268 lib_prefix = unresolved_class.library_prefix(); |
270 ASSERT(!lib_prefix.IsNull()); | 269 ASSERT(!lib_prefix.IsNull()); |
271 resolved_class = lib_prefix.LookupClass(class_name, &ambiguity_error_msg); | 270 resolved_class = lib_prefix.LookupClass(class_name); |
272 } | |
273 if (resolved_class.IsNull() && !ambiguity_error_msg.IsNull()) { | |
274 const Script& script = Script::Handle(cls.script()); | |
275 *ambiguity_error = Parser::FormatErrorMsg( | |
276 script, unresolved_class.token_pos(), "Error", | |
277 "%s", ambiguity_error_msg.ToCString()); | |
278 } | 271 } |
279 return resolved_class.raw(); | 272 return resolved_class.raw(); |
280 } | 273 } |
281 | 274 |
282 | 275 |
283 | 276 |
284 void ClassFinalizer::ResolveRedirectingFactory(const Class& cls, | 277 void ClassFinalizer::ResolveRedirectingFactory(const Class& cls, |
285 const Function& factory) { | 278 const Function& factory) { |
286 const Function& target = Function::Handle(factory.RedirectionTarget()); | 279 const Function& target = Function::Handle(factory.RedirectionTarget()); |
287 if (target.IsNull()) { | 280 if (target.IsNull()) { |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 if (!type.HasResolvedTypeClass()) { | 453 if (!type.HasResolvedTypeClass()) { |
461 // Type parameters are always resolved in the parser in the correct | 454 // Type parameters are always resolved in the parser in the correct |
462 // non-static scope or factory scope. That resolution scope is unknown here. | 455 // non-static scope or factory scope. That resolution scope is unknown here. |
463 // Being able to resolve a type parameter from class cls here would indicate | 456 // Being able to resolve a type parameter from class cls here would indicate |
464 // that the type parameter appeared in a static scope. Leaving the type as | 457 // that the type parameter appeared in a static scope. Leaving the type as |
465 // unresolved is the correct thing to do. | 458 // unresolved is the correct thing to do. |
466 | 459 |
467 // Lookup the type class. | 460 // Lookup the type class. |
468 const UnresolvedClass& unresolved_class = | 461 const UnresolvedClass& unresolved_class = |
469 UnresolvedClass::Handle(type.unresolved_class()); | 462 UnresolvedClass::Handle(type.unresolved_class()); |
470 Error& ambiguous_error = Error::Handle(); | |
471 const Class& type_class = | 463 const Class& type_class = |
472 Class::Handle(ResolveClass(cls, unresolved_class, &ambiguous_error)); | 464 Class::Handle(ResolveClass(cls, unresolved_class)); |
473 | 465 |
474 // Replace unresolved class with resolved type class. | 466 // Replace unresolved class with resolved type class. |
475 const Type& parameterized_type = Type::Cast(type); | 467 const Type& parameterized_type = Type::Cast(type); |
476 if (type_class.IsNull()) { | 468 if (type_class.IsNull()) { |
477 if ((finalization == kCanonicalizeWellFormed) || | 469 if ((finalization == kCanonicalizeWellFormed) || |
478 FLAG_error_on_bad_type) { | 470 FLAG_error_on_bad_type) { |
479 // The type class could not be resolved. The type is malformed. | 471 // The type class could not be resolved. The type is malformed. |
480 FinalizeMalformedType( | 472 FinalizeMalformedType( |
481 ambiguous_error, // May be null. | 473 Error::Handle(), // No previous error. |
482 cls, | 474 cls, |
483 parameterized_type, | 475 parameterized_type, |
484 "cannot resolve class '%s' from '%s'", | 476 "cannot resolve class '%s' from '%s'", |
485 String::Handle(unresolved_class.Name()).ToCString(), | 477 String::Handle(unresolved_class.Name()).ToCString(), |
486 String::Handle(cls.Name()).ToCString()); | 478 String::Handle(cls.Name()).ToCString()); |
487 } else { | 479 } else { |
488 // Map the malformed type to dynamic and ignore type arguments. | 480 // Map the malformed type to dynamic and ignore type arguments. |
489 parameterized_type.set_type_class(Class::Handle( | 481 parameterized_type.set_type_class(Class::Handle( |
490 Object::dynamic_class())); | 482 Object::dynamic_class())); |
491 parameterized_type.set_arguments( | 483 parameterized_type.set_arguments( |
(...skipping 1835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2327 expected_name ^= String::New("_offset"); | 2319 expected_name ^= String::New("_offset"); |
2328 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); | 2320 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); |
2329 field ^= fields_array.At(2); | 2321 field ^= fields_array.At(2); |
2330 ASSERT(field.Offset() == TypedDataView::length_offset()); | 2322 ASSERT(field.Offset() == TypedDataView::length_offset()); |
2331 name ^= field.name(); | 2323 name ^= field.name(); |
2332 ASSERT(name.Equals("length")); | 2324 ASSERT(name.Equals("length")); |
2333 #endif | 2325 #endif |
2334 } | 2326 } |
2335 | 2327 |
2336 } // namespace dart | 2328 } // namespace dart |
OLD | NEW |