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 | 6 |
7 #include "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
9 #include "vm/ast_transformer.h" | 9 #include "vm/ast_transformer.h" |
10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
(...skipping 11328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11339 type_parameter.token_pos(), | 11339 type_parameter.token_pos(), |
11340 "type parameter '%s' cannot be parameterized", | 11340 "type parameter '%s' cannot be parameterized", |
11341 String::Handle(Z, type_parameter.name()).ToCString()); | 11341 String::Handle(Z, type_parameter.name()).ToCString()); |
11342 return; | 11342 return; |
11343 } | 11343 } |
11344 *type = type_parameter.raw(); | 11344 *type = type_parameter.raw(); |
11345 return; | 11345 return; |
11346 } | 11346 } |
11347 } | 11347 } |
11348 // The referenced class may not have been parsed yet. It would be wrong | 11348 // The referenced class may not have been parsed yet. It would be wrong |
11349 // to resolve it too early to an imported class of the same name. | 11349 // to resolve it too early to an imported class of the same name. Only |
| 11350 // resolve the class when a finalized type is requested. |
11350 if (finalization > ClassFinalizer::kResolveTypeParameters) { | 11351 if (finalization > ClassFinalizer::kResolveTypeParameters) { |
11351 // Resolve classname in the scope of the current library. | 11352 resolved_type_class = library_.LookupClass(unresolved_class_name); |
11352 resolved_type_class = ResolveClassInCurrentLibraryScope( | |
11353 unresolved_class_name); | |
11354 } | 11353 } |
11355 } else { | 11354 } else { |
11356 LibraryPrefix& lib_prefix = | 11355 // Resolve class name in the scope of the library prefix. |
| 11356 const LibraryPrefix& lib_prefix = |
11357 LibraryPrefix::Handle(Z, unresolved_class.library_prefix()); | 11357 LibraryPrefix::Handle(Z, unresolved_class.library_prefix()); |
11358 // Resolve class name in the scope of the library prefix. | 11358 resolved_type_class = lib_prefix.LookupClass(unresolved_class_name); |
11359 resolved_type_class = | |
11360 ResolveClassInPrefixScope(lib_prefix, unresolved_class_name); | |
11361 } | 11359 } |
11362 // At this point, we can only have a parameterized_type. | 11360 // At this point, we can only have a parameterized_type. |
11363 const Type& parameterized_type = Type::Cast(*type); | 11361 const Type& parameterized_type = Type::Cast(*type); |
11364 if (!resolved_type_class.IsNull()) { | 11362 if (!resolved_type_class.IsNull()) { |
11365 // Replace unresolved class with resolved type class. | 11363 // Replace unresolved class with resolved type class. |
11366 parameterized_type.set_type_class(resolved_type_class); | 11364 parameterized_type.set_type_class(resolved_type_class); |
11367 } else if (finalization >= ClassFinalizer::kCanonicalize) { | 11365 } else if (finalization >= ClassFinalizer::kCanonicalize) { |
11368 ClassFinalizer::FinalizeMalformedType( | 11366 ClassFinalizer::FinalizeMalformedType( |
11369 Error::Handle(Z), // No previous error. | 11367 Error::Handle(Z), // No previous error. |
11370 script_, | 11368 script_, |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11706 } | 11704 } |
11707 | 11705 |
11708 // Nothing found in scope of current class. | 11706 // Nothing found in scope of current class. |
11709 if (node != NULL) { | 11707 if (node != NULL) { |
11710 *node = NULL; | 11708 *node = NULL; |
11711 } | 11709 } |
11712 return false; | 11710 return false; |
11713 } | 11711 } |
11714 | 11712 |
11715 | 11713 |
11716 RawClass* Parser::ResolveClassInCurrentLibraryScope(const String& name) { | |
11717 HANDLESCOPE(I); | |
11718 const Object& obj = Object::Handle(Z, library_.ResolveName(name)); | |
11719 if (obj.IsClass()) { | |
11720 return Class::Cast(obj).raw(); | |
11721 } | |
11722 return Class::null(); | |
11723 } | |
11724 | |
11725 | |
11726 // Resolve an identifier by checking the global scope of the current | 11714 // Resolve an identifier by checking the global scope of the current |
11727 // library. If not found in the current library, then look in the scopes | 11715 // library. If not found in the current library, then look in the scopes |
11728 // of all libraries that are imported without a library prefix. | 11716 // of all libraries that are imported without a library prefix. |
11729 AstNode* Parser::ResolveIdentInCurrentLibraryScope(intptr_t ident_pos, | 11717 AstNode* Parser::ResolveIdentInCurrentLibraryScope(intptr_t ident_pos, |
11730 const String& ident) { | 11718 const String& ident) { |
11731 TRACE_PARSER("ResolveIdentInCurrentLibraryScope"); | 11719 TRACE_PARSER("ResolveIdentInCurrentLibraryScope"); |
11732 HANDLESCOPE(I); | 11720 HANDLESCOPE(I); |
11733 const Object& obj = Object::Handle(Z, library_.ResolveName(ident)); | 11721 const Object& obj = Object::Handle(Z, library_.ResolveName(ident)); |
11734 if (obj.IsClass()) { | 11722 if (obj.IsClass()) { |
11735 const Class& cls = Class::Cast(obj); | 11723 const Class& cls = Class::Cast(obj); |
(...skipping 21 matching lines...) Expand all Loading... |
11757 return new(Z) PrimaryNode(ident_pos, Function::ZoneHandle(Z, func.raw())); | 11745 return new(Z) PrimaryNode(ident_pos, Function::ZoneHandle(Z, func.raw())); |
11758 } | 11746 } |
11759 } else { | 11747 } else { |
11760 ASSERT(obj.IsNull() || obj.IsLibraryPrefix()); | 11748 ASSERT(obj.IsNull() || obj.IsLibraryPrefix()); |
11761 } | 11749 } |
11762 // Lexically unresolved primary identifiers are referenced by their name. | 11750 // Lexically unresolved primary identifiers are referenced by their name. |
11763 return new(Z) PrimaryNode(ident_pos, ident); | 11751 return new(Z) PrimaryNode(ident_pos, ident); |
11764 } | 11752 } |
11765 | 11753 |
11766 | 11754 |
11767 RawClass* Parser::ResolveClassInPrefixScope(const LibraryPrefix& prefix, | |
11768 const String& name) { | |
11769 HANDLESCOPE(I); | |
11770 const Object& obj = Object::Handle(Z, prefix.LookupObject(name)); | |
11771 if (obj.IsClass()) { | |
11772 return Class::Cast(obj).raw(); | |
11773 } | |
11774 return Class::null(); | |
11775 } | |
11776 | |
11777 | |
11778 // Do a lookup for the identifier in the scope of the specified | 11755 // Do a lookup for the identifier in the scope of the specified |
11779 // library prefix. This means trying to resolve it locally in all of the | 11756 // library prefix. This means trying to resolve it locally in all of the |
11780 // libraries present in the library prefix. | 11757 // libraries present in the library prefix. |
11781 AstNode* Parser::ResolveIdentInPrefixScope(intptr_t ident_pos, | 11758 AstNode* Parser::ResolveIdentInPrefixScope(intptr_t ident_pos, |
11782 const LibraryPrefix& prefix, | 11759 const LibraryPrefix& prefix, |
11783 const String& ident) { | 11760 const String& ident) { |
11784 TRACE_PARSER("ResolveIdentInPrefixScope"); | 11761 TRACE_PARSER("ResolveIdentInPrefixScope"); |
11785 HANDLESCOPE(I); | 11762 HANDLESCOPE(I); |
11786 if (ident.CharAt(0) == Library::kPrivateIdentifierStart) { | 11763 if (ident.CharAt(0) == Library::kPrivateIdentifierStart) { |
11787 // Private names are not exported by libraries. The name mangling | 11764 // Private names are not exported by libraries. The name mangling |
(...skipping 1717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13505 void Parser::SkipQualIdent() { | 13482 void Parser::SkipQualIdent() { |
13506 ASSERT(IsIdentifier()); | 13483 ASSERT(IsIdentifier()); |
13507 ConsumeToken(); | 13484 ConsumeToken(); |
13508 if (CurrentToken() == Token::kPERIOD) { | 13485 if (CurrentToken() == Token::kPERIOD) { |
13509 ConsumeToken(); // Consume the kPERIOD token. | 13486 ConsumeToken(); // Consume the kPERIOD token. |
13510 ExpectIdentifier("identifier expected after '.'"); | 13487 ExpectIdentifier("identifier expected after '.'"); |
13511 } | 13488 } |
13512 } | 13489 } |
13513 | 13490 |
13514 } // namespace dart | 13491 } // namespace dart |
OLD | NEW |