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/bootstrap.h" | 9 #include "vm/bootstrap.h" |
10 #include "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
(...skipping 9098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9109 } | 9109 } |
9110 | 9110 |
9111 // Nothing found in scope of current class. | 9111 // Nothing found in scope of current class. |
9112 if (node != NULL) { | 9112 if (node != NULL) { |
9113 *node = NULL; | 9113 *node = NULL; |
9114 } | 9114 } |
9115 return false; // Not an unqualified identifier. | 9115 return false; // Not an unqualified identifier. |
9116 } | 9116 } |
9117 | 9117 |
9118 | 9118 |
9119 static RawObject* LookupNameInLibrary(Isolate* isolate, | |
9120 const Library& lib, | |
9121 const String& name) { | |
9122 Object& obj = Object::Handle(isolate); | |
9123 obj = lib.LookupLocalObject(name); | |
9124 if (!obj.IsNull()) { | |
9125 return obj.raw(); | |
9126 } | |
9127 String& accessor_name = String::Handle(isolate, Field::GetterName(name)); | |
9128 obj = lib.LookupLocalObject(accessor_name); | |
9129 if (!obj.IsNull()) { | |
9130 return obj.raw(); | |
9131 } | |
9132 accessor_name = Field::SetterName(name); | |
9133 obj = lib.LookupLocalObject(accessor_name); | |
9134 return obj.raw(); | |
9135 } | |
9136 | |
9137 | |
9138 // Resolve a name by checking the global scope of the current | |
9139 // library. If not found in the current library, then look in the scopes | |
9140 // of all libraries that are imported without a library prefix. | |
9141 RawObject* Parser::ResolveNameInCurrentLibraryScope(const String& name) { | |
9142 TRACE_PARSER("ResolveNameInCurrentLibraryScope"); | |
9143 HANDLESCOPE(isolate()); | |
9144 Object& obj = Object::Handle(isolate(), | |
9145 LookupNameInLibrary(isolate(), library_, name)); | |
9146 if (!obj.IsNull()) { | |
9147 return obj.raw(); | |
9148 } | |
9149 return library_.LookupImportedObject(name); | |
9150 } | |
9151 | |
9152 | |
9153 RawClass* Parser::ResolveClassInCurrentLibraryScope(const String& name) { | 9119 RawClass* Parser::ResolveClassInCurrentLibraryScope(const String& name) { |
9154 const Object& obj = | 9120 HANDLESCOPE(isolate()); |
9155 Object::Handle(ResolveNameInCurrentLibraryScope(name)); | 9121 const Object& obj = Object::Handle(library_.ResolveName(name)); |
9156 if (obj.IsClass()) { | 9122 if (obj.IsClass()) { |
9157 return Class::Cast(obj).raw(); | 9123 return Class::Cast(obj).raw(); |
9158 } | 9124 } |
9159 return Class::null(); | 9125 return Class::null(); |
9160 } | 9126 } |
9161 | 9127 |
9162 | 9128 |
9163 // Resolve an identifier by checking the global scope of the current | 9129 // Resolve an identifier by checking the global scope of the current |
9164 // library. If not found in the current library, then look in the scopes | 9130 // library. If not found in the current library, then look in the scopes |
9165 // of all libraries that are imported without a library prefix. | 9131 // of all libraries that are imported without a library prefix. |
9166 AstNode* Parser::ResolveIdentInCurrentLibraryScope(intptr_t ident_pos, | 9132 AstNode* Parser::ResolveIdentInCurrentLibraryScope(intptr_t ident_pos, |
9167 const String& ident) { | 9133 const String& ident) { |
9168 TRACE_PARSER("ResolveIdentInCurrentLibraryScope"); | 9134 TRACE_PARSER("ResolveIdentInCurrentLibraryScope"); |
9169 const Object& obj = | 9135 HANDLESCOPE(isolate()); |
9170 Object::Handle(ResolveNameInCurrentLibraryScope(ident)); | 9136 const Object& obj = Object::Handle(library_.ResolveName(ident)); |
9171 if (obj.IsClass()) { | 9137 if (obj.IsClass()) { |
9172 const Class& cls = Class::Cast(obj); | 9138 const Class& cls = Class::Cast(obj); |
9173 return new PrimaryNode(ident_pos, Class::ZoneHandle(cls.raw())); | 9139 return new PrimaryNode(ident_pos, Class::ZoneHandle(cls.raw())); |
9174 } else if (obj.IsField()) { | 9140 } else if (obj.IsField()) { |
9175 const Field& field = Field::Cast(obj); | 9141 const Field& field = Field::Cast(obj); |
9176 ASSERT(field.is_static()); | 9142 ASSERT(field.is_static()); |
9177 return GenerateStaticFieldLookup(field, ident_pos); | 9143 return GenerateStaticFieldLookup(field, ident_pos); |
9178 } else if (obj.IsFunction()) { | 9144 } else if (obj.IsFunction()) { |
9179 const Function& func = Function::Cast(obj); | 9145 const Function& func = Function::Cast(obj); |
9180 ASSERT(func.is_static()); | 9146 ASSERT(func.is_static()); |
9181 if (func.IsGetterFunction() || func.IsSetterFunction()) { | 9147 if (func.IsGetterFunction() || func.IsSetterFunction()) { |
9182 return new StaticGetterNode(ident_pos, | 9148 return new StaticGetterNode(ident_pos, |
9183 /* receiver */ NULL, | 9149 /* receiver */ NULL, |
9184 /* is_super_getter */ false, | 9150 /* is_super_getter */ false, |
9185 Class::ZoneHandle(func.Owner()), | 9151 Class::ZoneHandle(func.Owner()), |
9186 ident); | 9152 ident); |
9187 | 9153 |
9188 } else { | 9154 } else { |
9189 return new PrimaryNode(ident_pos, Function::ZoneHandle(func.raw())); | 9155 return new PrimaryNode(ident_pos, Function::ZoneHandle(func.raw())); |
9190 } | 9156 } |
9191 } else { | 9157 } else { |
9192 ASSERT(obj.IsNull() || obj.IsLibraryPrefix()); | 9158 ASSERT(obj.IsNull() || obj.IsLibraryPrefix()); |
9193 } | 9159 } |
9194 // Lexically unresolved primary identifiers are referenced by their name. | 9160 // Lexically unresolved primary identifiers are referenced by their name. |
9195 return new PrimaryNode(ident_pos, ident); | 9161 return new PrimaryNode(ident_pos, ident); |
9196 } | 9162 } |
9197 | 9163 |
9198 | 9164 |
9199 RawObject* Parser::ResolveNameInPrefixScope(const LibraryPrefix& prefix, | |
9200 const String& name) { | |
9201 HANDLESCOPE(isolate()); | |
9202 return prefix.LookupObject(name); | |
9203 } | |
9204 | |
9205 | |
9206 RawClass* Parser::ResolveClassInPrefixScope(const LibraryPrefix& prefix, | 9165 RawClass* Parser::ResolveClassInPrefixScope(const LibraryPrefix& prefix, |
9207 const String& name) { | 9166 const String& name) { |
9208 const Object& obj = | 9167 HANDLESCOPE(isolate()); |
9209 Object::Handle(ResolveNameInPrefixScope(prefix, name)); | 9168 const Object& obj = Object::Handle(prefix.LookupObject(name)); |
9210 if (obj.IsClass()) { | 9169 if (obj.IsClass()) { |
9211 return Class::Cast(obj).raw(); | 9170 return Class::Cast(obj).raw(); |
9212 } | 9171 } |
9213 return Class::null(); | 9172 return Class::null(); |
9214 } | 9173 } |
9215 | 9174 |
9216 | 9175 |
9217 // Do a lookup for the identifier in the scope of the specified | 9176 // Do a lookup for the identifier in the scope of the specified |
9218 // library prefix. This means trying to resolve it locally in all of the | 9177 // library prefix. This means trying to resolve it locally in all of the |
9219 // libraries present in the library prefix. | 9178 // libraries present in the library prefix. |
9220 AstNode* Parser::ResolveIdentInPrefixScope(intptr_t ident_pos, | 9179 AstNode* Parser::ResolveIdentInPrefixScope(intptr_t ident_pos, |
9221 const LibraryPrefix& prefix, | 9180 const LibraryPrefix& prefix, |
9222 const String& ident) { | 9181 const String& ident) { |
9223 TRACE_PARSER("ResolveIdentInPrefixScope"); | 9182 TRACE_PARSER("ResolveIdentInPrefixScope"); |
9224 Object& obj = Object::Handle(ResolveNameInPrefixScope(prefix, ident)); | 9183 HANDLESCOPE(isolate()); |
| 9184 Object& obj = Object::Handle(prefix.LookupObject(ident)); |
9225 if (obj.IsNull()) { | 9185 if (obj.IsNull()) { |
9226 // Unresolved prefixed primary identifier. | 9186 // Unresolved prefixed primary identifier. |
9227 String& qualified_name = String::ZoneHandle(prefix.name()); | 9187 String& qualified_name = String::ZoneHandle(prefix.name()); |
9228 qualified_name = String::Concat(qualified_name, Symbols::Dot()); | 9188 qualified_name = String::Concat(qualified_name, Symbols::Dot()); |
9229 qualified_name = String::Concat(qualified_name, ident); | 9189 qualified_name = String::Concat(qualified_name, ident); |
9230 qualified_name = Symbols::New(qualified_name); | 9190 qualified_name = Symbols::New(qualified_name); |
9231 return new PrimaryNode(ident_pos, qualified_name); | 9191 return new PrimaryNode(ident_pos, qualified_name); |
9232 } else if (obj.IsClass()) { | 9192 } else if (obj.IsClass()) { |
9233 const Class& cls = Class::Cast(obj); | 9193 const Class& cls = Class::Cast(obj); |
9234 return new PrimaryNode(ident_pos, Class::ZoneHandle(cls.raw())); | 9194 return new PrimaryNode(ident_pos, Class::ZoneHandle(cls.raw())); |
(...skipping 1579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10814 void Parser::SkipQualIdent() { | 10774 void Parser::SkipQualIdent() { |
10815 ASSERT(IsIdentifier()); | 10775 ASSERT(IsIdentifier()); |
10816 ConsumeToken(); | 10776 ConsumeToken(); |
10817 if (CurrentToken() == Token::kPERIOD) { | 10777 if (CurrentToken() == Token::kPERIOD) { |
10818 ConsumeToken(); // Consume the kPERIOD token. | 10778 ConsumeToken(); // Consume the kPERIOD token. |
10819 ExpectIdentifier("identifier expected after '.'"); | 10779 ExpectIdentifier("identifier expected after '.'"); |
10820 } | 10780 } |
10821 } | 10781 } |
10822 | 10782 |
10823 } // namespace dart | 10783 } // namespace dart |
OLD | NEW |