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 9084 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9095 } | 9095 } |
9096 | 9096 |
9097 // Nothing found in scope of current class. | 9097 // Nothing found in scope of current class. |
9098 if (node != NULL) { | 9098 if (node != NULL) { |
9099 *node = NULL; | 9099 *node = NULL; |
9100 } | 9100 } |
9101 return false; // Not an unqualified identifier. | 9101 return false; // Not an unqualified identifier. |
9102 } | 9102 } |
9103 | 9103 |
9104 | 9104 |
9105 static RawObject* LookupNameInLibrary(Isolate* isolate, | |
9106 const Library& lib, | |
9107 const String& name) { | |
9108 Object& obj = Object::Handle(isolate); | |
9109 obj = lib.LookupLocalObject(name); | |
9110 if (!obj.IsNull()) { | |
9111 return obj.raw(); | |
9112 } | |
9113 String& accessor_name = String::Handle(isolate, Field::GetterName(name)); | |
9114 obj = lib.LookupLocalObject(accessor_name); | |
9115 if (!obj.IsNull()) { | |
9116 return obj.raw(); | |
9117 } | |
9118 accessor_name = Field::SetterName(name); | |
9119 obj = lib.LookupLocalObject(accessor_name); | |
9120 return obj.raw(); | |
9121 } | |
9122 | |
9123 | |
9124 // Resolve a name by checking the global scope of the current | |
9125 // library. If not found in the current library, then look in the scopes | |
9126 // of all libraries that are imported without a library prefix. | |
9127 RawObject* Parser::ResolveNameInCurrentLibraryScope(const String& name) { | |
9128 TRACE_PARSER("ResolveNameInCurrentLibraryScope"); | |
9129 HANDLESCOPE(isolate()); | |
9130 Object& obj = Object::Handle(isolate(), | |
9131 LookupNameInLibrary(isolate(), library_, name)); | |
9132 if (!obj.IsNull()) { | |
9133 return obj.raw(); | |
9134 } | |
9135 return library_.LookupImportedObject(name); | |
9136 } | |
9137 | |
9138 | |
9139 RawClass* Parser::ResolveClassInCurrentLibraryScope(const String& name) { | 9105 RawClass* Parser::ResolveClassInCurrentLibraryScope(const String& name) { |
9140 const Object& obj = | 9106 HANDLESCOPE(isolate()); |
9141 Object::Handle(ResolveNameInCurrentLibraryScope(name)); | 9107 const Object& obj = Object::Handle(library_.ResolveName(name)); |
9142 if (obj.IsClass()) { | 9108 if (obj.IsClass()) { |
9143 return Class::Cast(obj).raw(); | 9109 return Class::Cast(obj).raw(); |
9144 } | 9110 } |
9145 return Class::null(); | 9111 return Class::null(); |
9146 } | 9112 } |
9147 | 9113 |
9148 | 9114 |
9149 // Resolve an identifier by checking the global scope of the current | 9115 // Resolve an identifier by checking the global scope of the current |
9150 // library. If not found in the current library, then look in the scopes | 9116 // library. If not found in the current library, then look in the scopes |
9151 // of all libraries that are imported without a library prefix. | 9117 // of all libraries that are imported without a library prefix. |
9152 AstNode* Parser::ResolveIdentInCurrentLibraryScope(intptr_t ident_pos, | 9118 AstNode* Parser::ResolveIdentInCurrentLibraryScope(intptr_t ident_pos, |
9153 const String& ident) { | 9119 const String& ident) { |
9154 TRACE_PARSER("ResolveIdentInCurrentLibraryScope"); | 9120 TRACE_PARSER("ResolveIdentInCurrentLibraryScope"); |
9155 const Object& obj = | 9121 HANDLESCOPE(isolate()); |
9156 Object::Handle(ResolveNameInCurrentLibraryScope(ident)); | 9122 const Object& obj = Object::Handle(library_.ResolveName(ident)); |
9157 if (obj.IsClass()) { | 9123 if (obj.IsClass()) { |
9158 const Class& cls = Class::Cast(obj); | 9124 const Class& cls = Class::Cast(obj); |
9159 return new PrimaryNode(ident_pos, Class::ZoneHandle(cls.raw())); | 9125 return new PrimaryNode(ident_pos, Class::ZoneHandle(cls.raw())); |
9160 } else if (obj.IsField()) { | 9126 } else if (obj.IsField()) { |
9161 const Field& field = Field::Cast(obj); | 9127 const Field& field = Field::Cast(obj); |
9162 ASSERT(field.is_static()); | 9128 ASSERT(field.is_static()); |
9163 return GenerateStaticFieldLookup(field, ident_pos); | 9129 return GenerateStaticFieldLookup(field, ident_pos); |
9164 } else if (obj.IsFunction()) { | 9130 } else if (obj.IsFunction()) { |
9165 const Function& func = Function::Cast(obj); | 9131 const Function& func = Function::Cast(obj); |
9166 ASSERT(func.is_static()); | 9132 ASSERT(func.is_static()); |
9167 if (func.IsGetterFunction() || func.IsSetterFunction()) { | 9133 if (func.IsGetterFunction() || func.IsSetterFunction()) { |
9168 return new StaticGetterNode(ident_pos, | 9134 return new StaticGetterNode(ident_pos, |
9169 /* receiver */ NULL, | 9135 /* receiver */ NULL, |
9170 /* is_super_getter */ false, | 9136 /* is_super_getter */ false, |
9171 Class::ZoneHandle(func.Owner()), | 9137 Class::ZoneHandle(func.Owner()), |
9172 ident); | 9138 ident); |
9173 | 9139 |
9174 } else { | 9140 } else { |
9175 return new PrimaryNode(ident_pos, Function::ZoneHandle(func.raw())); | 9141 return new PrimaryNode(ident_pos, Function::ZoneHandle(func.raw())); |
9176 } | 9142 } |
9177 } else { | 9143 } else { |
9178 ASSERT(obj.IsNull() || obj.IsLibraryPrefix()); | 9144 ASSERT(obj.IsNull() || obj.IsLibraryPrefix()); |
9179 } | 9145 } |
9180 // Lexically unresolved primary identifiers are referenced by their name. | 9146 // Lexically unresolved primary identifiers are referenced by their name. |
9181 return new PrimaryNode(ident_pos, ident); | 9147 return new PrimaryNode(ident_pos, ident); |
9182 } | 9148 } |
9183 | 9149 |
9184 | 9150 |
9185 RawObject* Parser::ResolveNameInPrefixScope(const LibraryPrefix& prefix, | |
9186 const String& name) { | |
9187 HANDLESCOPE(isolate()); | |
9188 return prefix.LookupObject(name); | |
9189 } | |
9190 | |
9191 | |
9192 RawClass* Parser::ResolveClassInPrefixScope(const LibraryPrefix& prefix, | 9151 RawClass* Parser::ResolveClassInPrefixScope(const LibraryPrefix& prefix, |
9193 const String& name) { | 9152 const String& name) { |
9194 const Object& obj = | 9153 HANDLESCOPE(isolate()); |
9195 Object::Handle(ResolveNameInPrefixScope(prefix, name)); | 9154 const Object& obj = Object::Handle(prefix.LookupObject(name)); |
9196 if (obj.IsClass()) { | 9155 if (obj.IsClass()) { |
9197 return Class::Cast(obj).raw(); | 9156 return Class::Cast(obj).raw(); |
9198 } | 9157 } |
9199 return Class::null(); | 9158 return Class::null(); |
9200 } | 9159 } |
9201 | 9160 |
9202 | 9161 |
9203 // Do a lookup for the identifier in the scope of the specified | 9162 // Do a lookup for the identifier in the scope of the specified |
9204 // library prefix. This means trying to resolve it locally in all of the | 9163 // library prefix. This means trying to resolve it locally in all of the |
9205 // libraries present in the library prefix. | 9164 // libraries present in the library prefix. |
9206 AstNode* Parser::ResolveIdentInPrefixScope(intptr_t ident_pos, | 9165 AstNode* Parser::ResolveIdentInPrefixScope(intptr_t ident_pos, |
9207 const LibraryPrefix& prefix, | 9166 const LibraryPrefix& prefix, |
9208 const String& ident) { | 9167 const String& ident) { |
9209 TRACE_PARSER("ResolveIdentInPrefixScope"); | 9168 TRACE_PARSER("ResolveIdentInPrefixScope"); |
9210 Object& obj = Object::Handle(ResolveNameInPrefixScope(prefix, ident)); | 9169 HANDLESCOPE(isolate()); |
| 9170 Object& obj = Object::Handle(prefix.LookupObject(ident)); |
9211 if (obj.IsNull()) { | 9171 if (obj.IsNull()) { |
9212 // Unresolved prefixed primary identifier. | 9172 // Unresolved prefixed primary identifier. |
9213 String& qualified_name = String::ZoneHandle(prefix.name()); | 9173 String& qualified_name = String::ZoneHandle(prefix.name()); |
9214 qualified_name = String::Concat(qualified_name, Symbols::Dot()); | 9174 qualified_name = String::Concat(qualified_name, Symbols::Dot()); |
9215 qualified_name = String::Concat(qualified_name, ident); | 9175 qualified_name = String::Concat(qualified_name, ident); |
9216 qualified_name = Symbols::New(qualified_name); | 9176 qualified_name = Symbols::New(qualified_name); |
9217 return new PrimaryNode(ident_pos, qualified_name); | 9177 return new PrimaryNode(ident_pos, qualified_name); |
9218 } else if (obj.IsClass()) { | 9178 } else if (obj.IsClass()) { |
9219 const Class& cls = Class::Cast(obj); | 9179 const Class& cls = Class::Cast(obj); |
9220 return new PrimaryNode(ident_pos, Class::ZoneHandle(cls.raw())); | 9180 return new PrimaryNode(ident_pos, Class::ZoneHandle(cls.raw())); |
(...skipping 1579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10800 void Parser::SkipQualIdent() { | 10760 void Parser::SkipQualIdent() { |
10801 ASSERT(IsIdentifier()); | 10761 ASSERT(IsIdentifier()); |
10802 ConsumeToken(); | 10762 ConsumeToken(); |
10803 if (CurrentToken() == Token::kPERIOD) { | 10763 if (CurrentToken() == Token::kPERIOD) { |
10804 ConsumeToken(); // Consume the kPERIOD token. | 10764 ConsumeToken(); // Consume the kPERIOD token. |
10805 ExpectIdentifier("identifier expected after '.'"); | 10765 ExpectIdentifier("identifier expected after '.'"); |
10806 } | 10766 } |
10807 } | 10767 } |
10808 | 10768 |
10809 } // namespace dart | 10769 } // namespace dart |
OLD | NEW |