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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 if (unresolved_class.library_prefix() == LibraryPrefix::null()) { | 264 if (unresolved_class.library_prefix() == LibraryPrefix::null()) { |
265 lib = cls.library(); | 265 lib = cls.library(); |
266 ASSERT(!lib.IsNull()); | 266 ASSERT(!lib.IsNull()); |
267 // TODO(regis): Call lib.LookupClass(class_name, ambiguity_error) instead | 267 String& ambiguity_error_msg = String::Handle(); |
268 // once it takes the ambiguity_error parameter. | 268 resolved_class = lib.LookupClass(class_name, &ambiguity_error_msg); |
269 | 269 if (resolved_class.IsNull() && !ambiguity_error_msg.IsNull()) { |
270 // First check if name is found in the local scope of the library. | 270 const Script& script = Script::Handle(cls.script()); |
271 Object& obj = Object::Handle(lib.LookupLocalObject(class_name)); | 271 *ambiguity_error = Parser::FormatErrorMsg( |
272 if (!obj.IsNull() && obj.IsClass()) { | 272 script, unresolved_class.token_pos(), "Error", |
273 return Class::Cast(obj).raw(); | 273 "%s", ambiguity_error_msg.ToCString()); |
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 } | 274 } |
311 } else { | 275 } else { |
312 LibraryPrefix& lib_prefix = LibraryPrefix::Handle(); | 276 LibraryPrefix& lib_prefix = LibraryPrefix::Handle(); |
313 lib_prefix = unresolved_class.library_prefix(); | 277 lib_prefix = unresolved_class.library_prefix(); |
314 ASSERT(!lib_prefix.IsNull()); | 278 ASSERT(!lib_prefix.IsNull()); |
315 resolved_class = lib_prefix.LookupLocalClass(class_name); | 279 resolved_class = lib_prefix.LookupLocalClass(class_name); |
316 } | 280 } |
317 return resolved_class.raw(); | 281 return resolved_class.raw(); |
318 } | 282 } |
319 | 283 |
(...skipping 1868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2188 expected_name ^= String::New("_offset"); | 2152 expected_name ^= String::New("_offset"); |
2189 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); | 2153 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); |
2190 field ^= fields_array.At(2); | 2154 field ^= fields_array.At(2); |
2191 ASSERT(field.Offset() == TypedDataView::length_offset()); | 2155 ASSERT(field.Offset() == TypedDataView::length_offset()); |
2192 name ^= field.name(); | 2156 name ^= field.name(); |
2193 ASSERT(name.Equals("length")); | 2157 ASSERT(name.Equals("length")); |
2194 #endif | 2158 #endif |
2195 } | 2159 } |
2196 | 2160 |
2197 } // namespace dart | 2161 } // namespace dart |
OLD | NEW |