| 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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 } | 254 } |
| 255 | 255 |
| 256 | 256 |
| 257 // Resolve unresolved_class in the library of cls, or return null. | 257 // Resolve unresolved_class in the library of cls, or return null. |
| 258 RawClass* ClassFinalizer::ResolveClass(const Class& cls, | 258 RawClass* ClassFinalizer::ResolveClass(const Class& cls, |
| 259 const UnresolvedClass& unresolved_class, | 259 const UnresolvedClass& unresolved_class, |
| 260 Error* ambiguity_error) { | 260 Error* ambiguity_error) { |
| 261 const String& class_name = String::Handle(unresolved_class.ident()); | 261 const String& class_name = String::Handle(unresolved_class.ident()); |
| 262 Library& lib = Library::Handle(); | 262 Library& lib = Library::Handle(); |
| 263 Class& resolved_class = Class::Handle(); | 263 Class& resolved_class = Class::Handle(); |
| 264 String& ambiguity_error_msg = String::Handle(); |
| 264 if (unresolved_class.library_prefix() == LibraryPrefix::null()) { | 265 if (unresolved_class.library_prefix() == LibraryPrefix::null()) { |
| 265 lib = cls.library(); | 266 lib = cls.library(); |
| 266 ASSERT(!lib.IsNull()); | 267 ASSERT(!lib.IsNull()); |
| 267 // TODO(regis): Call lib.LookupClass(class_name, ambiguity_error) instead | 268 resolved_class = lib.LookupClass(class_name, &ambiguity_error_msg); |
| 268 // once it takes the ambiguity_error parameter. | |
| 269 | |
| 270 // First check if name is found in the local scope of the library. | |
| 271 Object& obj = Object::Handle(lib.LookupLocalObject(class_name)); | |
| 272 if (!obj.IsNull() && obj.IsClass()) { | |
| 273 return Class::Cast(obj).raw(); | |
| 274 } | |
| 275 // Now check if class_name is found in any imported libs. | |
| 276 String& first_lib_url = String::Handle(); | |
| 277 Namespace& import = Namespace::Handle(); | |
| 278 Library& import_lib = Library::Handle(); | |
| 279 for (intptr_t i = 0; i < lib.num_imports(); i++) { | |
| 280 import ^= lib.ImportAt(i); | |
| 281 obj = import.Lookup(class_name); | |
| 282 if (!obj.IsNull()) { | |
| 283 import_lib = import.library(); | |
| 284 if (!first_lib_url.IsNull()) { | |
| 285 // Found duplicate definition. | |
| 286 const Script& script = Script::Handle(cls.script()); | |
| 287 if (first_lib_url.raw() == lib.url()) { | |
| 288 *ambiguity_error = Parser::FormatErrorMsg( | |
| 289 script, unresolved_class.token_pos(), "Error", | |
| 290 "ambiguous reference to '%s', " | |
| 291 "as library '%s' is imported multiple times", | |
| 292 class_name.ToCString(), | |
| 293 first_lib_url.ToCString()); | |
| 294 } else { | |
| 295 *ambiguity_error = Parser::FormatErrorMsg( | |
| 296 script, unresolved_class.token_pos(), "Error", | |
| 297 "ambiguous reference: " | |
| 298 "'%s' is defined in library '%s' and also in '%s'", | |
| 299 class_name.ToCString(), | |
| 300 first_lib_url.ToCString(), | |
| 301 String::Handle(lib.url()).ToCString()); | |
| 302 } | |
| 303 return Class::null(); | |
| 304 } | |
| 305 first_lib_url = lib.url(); | |
| 306 if (obj.IsClass()) { | |
| 307 resolved_class = Class::Cast(obj).raw(); | |
| 308 } | |
| 309 } | |
| 310 } | |
| 311 } else { | 269 } else { |
| 312 LibraryPrefix& lib_prefix = LibraryPrefix::Handle(); | 270 LibraryPrefix& lib_prefix = LibraryPrefix::Handle(); |
| 313 lib_prefix = unresolved_class.library_prefix(); | 271 lib_prefix = unresolved_class.library_prefix(); |
| 314 ASSERT(!lib_prefix.IsNull()); | 272 ASSERT(!lib_prefix.IsNull()); |
| 315 resolved_class = lib_prefix.LookupLocalClass(class_name); | 273 resolved_class = lib_prefix.LookupClass(class_name, &ambiguity_error_msg); |
| 274 } |
| 275 if (resolved_class.IsNull() && !ambiguity_error_msg.IsNull()) { |
| 276 const Script& script = Script::Handle(cls.script()); |
| 277 *ambiguity_error = Parser::FormatErrorMsg( |
| 278 script, unresolved_class.token_pos(), "Error", |
| 279 "%s", ambiguity_error_msg.ToCString()); |
| 316 } | 280 } |
| 317 return resolved_class.raw(); | 281 return resolved_class.raw(); |
| 318 } | 282 } |
| 319 | 283 |
| 320 | 284 |
| 321 void ClassFinalizer::ResolveRedirectingFactoryTarget( | 285 void ClassFinalizer::ResolveRedirectingFactoryTarget( |
| 322 const Class& cls, | 286 const Class& cls, |
| 323 const Function& factory, | 287 const Function& factory, |
| 324 const GrowableObjectArray& visited_factories) { | 288 const GrowableObjectArray& visited_factories) { |
| 325 ASSERT(factory.IsRedirectingFactory()); | 289 ASSERT(factory.IsRedirectingFactory()); |
| (...skipping 1879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2205 expected_name ^= String::New("_offset"); | 2169 expected_name ^= String::New("_offset"); |
| 2206 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); | 2170 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); |
| 2207 field ^= fields_array.At(2); | 2171 field ^= fields_array.At(2); |
| 2208 ASSERT(field.Offset() == TypedDataView::length_offset()); | 2172 ASSERT(field.Offset() == TypedDataView::length_offset()); |
| 2209 name ^= field.name(); | 2173 name ^= field.name(); |
| 2210 ASSERT(name.Equals("length")); | 2174 ASSERT(name.Equals("length")); |
| 2211 #endif | 2175 #endif |
| 2212 } | 2176 } |
| 2213 | 2177 |
| 2214 } // namespace dart | 2178 } // namespace dart |
| OLD | NEW |