Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: runtime/vm/class_finalizer.cc

Issue 8247014: Changes to handle unresolved qualified identifiers. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 } 278 }
279 279
280 280
281 RawType* ClassFinalizer::ResolveType(const Class& cls, const Type& type) { 281 RawType* ClassFinalizer::ResolveType(const Class& cls, const Type& type) {
282 if (type.IsResolved()) { 282 if (type.IsResolved()) {
283 return type.raw(); 283 return type.raw();
284 } 284 }
285 285
286 // Resolve the type class. 286 // Resolve the type class.
287 if (!type.HasResolvedTypeClass()) { 287 if (!type.HasResolvedTypeClass()) {
288 const String& type_class_name = 288 const UnresolvedClass& unresolved_class =
289 String::Handle(type.unresolved_type_class()); 289 UnresolvedClass::Handle(type.unresolved_class());
290 const String& type_class_name = String::Handle(unresolved_class.ident());
290 291
291 // The type class name may be a type parameter of cls that was not resolved 292 // The type class name may be a type parameter of cls that was not resolved
292 // by the parser because it appeared as part of the declaration 293 // by the parser because it appeared as part of the declaration
293 // as T1 in B<T1, T2 extends A<T1>> or 294 // as T1 in B<T1, T2 extends A<T1>> or
294 // as T2 in B<T1 extends A<T2>, T2>>. 295 // as T2 in B<T1 extends A<T2>, T2>>.
295 const TypeParameter& type_parameter = TypeParameter::Handle( 296 const TypeParameter& type_parameter = TypeParameter::Handle(
296 cls.LookupTypeParameter(type_class_name)); 297 cls.LookupTypeParameter(type_class_name));
297 if (!type_parameter.IsNull()) { 298 if (!type_parameter.IsNull()) {
298 // No need to check for proper instance scoping, since another type 299 // No need to check for proper instance scoping, since another type
299 // parameter must be involved for the type to still be unresolved. 300 // parameter must be involved for the type to still be unresolved.
300 // The scope checking was performed for the other type parameter already. 301 // The scope checking was performed for the other type parameter already.
301 302
302 // A type parameter cannot be parameterized, so report an error if type 303 // A type parameter cannot be parameterized, so report an error if type
303 // arguments have previously been parsed. 304 // arguments have previously been parsed.
304 if (type.arguments() != TypeArguments::null()) { 305 if (type.arguments() != TypeArguments::null()) {
305 ReportError("type parameter '%s' cannot be parameterized", 306 ReportError("type parameter '%s' cannot be parameterized",
306 type_class_name.ToCString()); 307 type_class_name.ToCString());
307 } 308 }
308 return type_parameter.raw(); 309 return type_parameter.raw();
309 } 310 }
310 311
311 // Lookup the type class. 312 // Lookup the type class.
312 Class& type_class = Class::Handle(); 313 Class& type_class = Class::Handle();
313 const Library& lib = Library::Handle(cls.library()); 314 Library& lib = Library::Handle();
315 if (unresolved_class.qualifier() == String::null()) {
316 lib ^= cls.library();
regis 2011/10/13 17:23:03 No downcast necessary. lib = instead of lib ^=
siva 2011/10/13 20:06:39 Done.
317 } else {
318 const String& qualifier = String::Handle(unresolved_class.qualifier());
319 LibraryPrefix& lib_prefix = LibraryPrefix::Handle();
320 lib_prefix = cls.LookupLibraryPrefix(qualifier);
321 if (lib_prefix.IsNull()) {
322 const Script& script = Script::Handle(cls.script());
323 ReportError(script, unresolved_class.token_index(),
324 "cannot resolve name '%s'\n",
325 String::Handle(unresolved_class.Name()).ToCString());
326 }
327 lib ^= lib_prefix.library();
regis 2011/10/13 17:23:03 ditto
siva 2011/10/13 20:06:39 Done.
328 }
314 ASSERT(!lib.IsNull()); 329 ASSERT(!lib.IsNull());
315 type_class = lib.LookupClass(type_class_name); 330 type_class = lib.LookupClass(type_class_name);
316 if (type_class.IsNull()) { 331 if (type_class.IsNull()) {
317 ReportError("cannot resolve class name '%s' from '%s'\n", 332 const Script& script = Script::Handle(cls.script());
318 type_class_name.ToCString(), 333 ReportError(script, unresolved_class.token_index(),
334 "cannot resolve class name '%s' from '%s'\n",
335 String::Handle(unresolved_class.Name()).ToCString(),
319 String::Handle(cls.Name()).ToCString()); 336 String::Handle(cls.Name()).ToCString());
320 } 337 }
321 // Replace unresolved type class with resolved type class. 338 // Replace unresolved class with resolved type class.
322 ASSERT(type.IsParameterizedType()); 339 ASSERT(type.IsParameterizedType());
323 ParameterizedType& parameterized_type = ParameterizedType::Handle(); 340 ParameterizedType& parameterized_type = ParameterizedType::Handle();
324 parameterized_type ^= type.raw(); 341 parameterized_type ^= type.raw();
325 parameterized_type.set_type_class(Object::Handle(type_class.raw())); 342 parameterized_type.set_type_class(Object::Handle(type_class.raw()));
326 } 343 }
327 344
328 // Resolve type arguments, if any. 345 // Resolve type arguments, if any.
329 const TypeArguments& arguments = TypeArguments::Handle(type.arguments()); 346 const TypeArguments& arguments = TypeArguments::Handle(type.arguments());
330 if (!arguments.IsNull()) { 347 if (!arguments.IsNull()) {
331 intptr_t num_arguments = arguments.Length(); 348 intptr_t num_arguments = arguments.Length();
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 const Array& fields_array = Array::Handle(cls.fields()); 924 const Array& fields_array = Array::Handle(cls.fields());
908 Field& field = Field::Handle(); 925 Field& field = Field::Handle();
909 len = fields_array.Length(); 926 len = fields_array.Length();
910 for (intptr_t i = 0; i < len; i++) { 927 for (intptr_t i = 0; i < len; i++) {
911 field ^= fields_array.At(i); 928 field ^= fields_array.At(i);
912 OS::Print(" %s\n", field.ToCString()); 929 OS::Print(" %s\n", field.ToCString());
913 } 930 }
914 } 931 }
915 932
916 933
934 void ClassFinalizer::ReportError(const Script& script,
935 intptr_t token_index,
936 const char* format, ...) {
937 static const int kBufferLength = 1024;
938 Isolate* isolate = Isolate::Current();
939 ASSERT(isolate != NULL);
940 Zone* zone = isolate->current_zone();
941 ASSERT(zone != NULL);
942 char* msg_buffer = reinterpret_cast<char*>(zone->Allocate(kBufferLength + 1));
943
944 const String& script_url = String::CheckedHandle(script.url());
945 const int buf_size = 256;
946 static char text_buffer[buf_size];
947 intptr_t line, column;
948 script.GetTokenLocation(token_index, &line, &column);
949 va_list args;
950 va_start(args, format);
951 OS::VSNPrint(text_buffer, buf_size, format, args);
952 va_end(args);
953
954 intptr_t msg_len = OS::SNPrint(msg_buffer, kBufferLength,
955 "'%s': line %d pos %d: %s\n",
956 script_url.ToCString(),
957 line, column, text_buffer);
958 const String& text = String::Handle(script.GetLine(line));
959 ASSERT(!text.IsNull());
960 if (text.Length() < buf_size) {
961 OS::SNPrint(msg_buffer + msg_len, (kBufferLength - msg_len), "%s\n%*s\n",
962 text.ToCString(), column, "^");
963 }
964 isolate->long_jump_base()->Jump(1, msg_buffer);
965 UNREACHABLE();
966 }
967
968
917 void ClassFinalizer::ReportError(const char* format, ...) { 969 void ClassFinalizer::ReportError(const char* format, ...) {
918 static const int kBufferLength = 1024; 970 static const int kBufferLength = 1024;
919 Isolate* isolate = Isolate::Current(); 971 Isolate* isolate = Isolate::Current();
920 ASSERT(isolate != NULL); 972 ASSERT(isolate != NULL);
921 Zone* zone = isolate->current_zone(); 973 Zone* zone = isolate->current_zone();
922 ASSERT(zone != NULL); 974 ASSERT(zone != NULL);
923 char* msg_buffer = reinterpret_cast<char*>(zone->Allocate(kBufferLength + 1)); 975 char* msg_buffer = reinterpret_cast<char*>(zone->Allocate(kBufferLength + 1));
924 ASSERT(msg_buffer != NULL); 976 ASSERT(msg_buffer != NULL);
925 va_list args; 977 va_list args;
926 va_start(args, format); 978 va_start(args, format);
927 OS::VSNPrint(msg_buffer, kBufferLength, format, args); 979 OS::VSNPrint(msg_buffer, kBufferLength, format, args);
928 va_end(args); 980 va_end(args);
929 isolate->long_jump_base()->Jump(1, msg_buffer); 981 isolate->long_jump_base()->Jump(1, msg_buffer);
930 UNREACHABLE(); 982 UNREACHABLE();
931 } 983 }
932 984
933 } // namespace dart 985 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698