Chromium Code Reviews| Index: runtime/vm/parser.cc |
| =================================================================== |
| --- runtime/vm/parser.cc (revision 12740) |
| +++ runtime/vm/parser.cc (working copy) |
| @@ -4087,15 +4087,17 @@ |
| } |
| } |
| // Add the import to the library. |
| + const Namespace& import = Namespace::Handle( |
| + Namespace::New(library, Array::Handle(), Array::Handle())); |
| if (prefix.IsNull() || (prefix.Length() == 0)) { |
| - library_.AddImport(library); |
| + library_.AddImport(import); |
| } else { |
| LibraryPrefix& library_prefix = LibraryPrefix::Handle(); |
| library_prefix = library_.LookupLocalLibraryPrefix(prefix); |
| if (!library_prefix.IsNull()) { |
| - library_prefix.AddLibrary(library); |
| + library_prefix.AddImport(import); |
| } else { |
| - library_prefix = LibraryPrefix::New(prefix, library); |
| + library_prefix = LibraryPrefix::New(prefix, import); |
| library_.AddObject(library_prefix, prefix); |
| } |
| } |
| @@ -4137,6 +4139,18 @@ |
| } |
| +void Parser::ParseIdentList(GrowableObjectArray* names) { |
| + while (IsIdentifier()) { |
| + names->Add(*CurrentLiteral()); |
| + ConsumeToken(); // Identifier. |
| + if (CurrentToken() != Token::kCOMMA) { |
| + return; |
| + } |
| + ConsumeToken(); // Comma. |
| + } |
| +} |
| + |
| + |
| void Parser::ParseLibraryImportExport() { |
| if (IsLiteral("import")) { |
| const intptr_t import_pos = TokenPos(); |
| @@ -4154,10 +4168,31 @@ |
| ConsumeToken(); |
| prefix = ExpectIdentifier("prefix expected")->raw(); |
| } |
| - if (IsLiteral("show")) { |
| - ErrorMsg("show combinator not yet supported"); |
| - } else if (IsLiteral("hide")) { |
| - ErrorMsg("hide combinator not yet supported"); |
| + |
| + Array& show_names = Array::Handle(); |
| + Array& hide_names = Array::Handle(); |
| + if (IsLiteral("show") || IsLiteral("hide")) { |
| + GrowableObjectArray& show_list = |
| + GrowableObjectArray::Handle(GrowableObjectArray::New()); |
| + GrowableObjectArray& hide_list = |
| + GrowableObjectArray::Handle(GrowableObjectArray::New()); |
| + for (;;) { |
| + if (IsLiteral("show")) { |
| + ConsumeToken(); |
| + ParseIdentList(&show_list); |
|
siva
2012/09/24 18:28:51
From this code it appears that one can add private
hausner
2012/09/24 20:25:43
Private names are not contained in the export name
|
| + } else if (IsLiteral("hide")) { |
| + ConsumeToken(); |
| + ParseIdentList(&hide_list); |
| + } else { |
| + break; |
| + } |
| + } |
|
siva
2012/09/24 18:28:51
Another question there is no check to ensure that
hausner
2012/09/24 20:25:43
I added a note to the spec asking for clarificatio
|
| + if (show_list.Length() > 0) { |
| + show_names = Array::MakeArray(show_list); |
| + } |
| + if (hide_list.Length() > 0) { |
| + hide_names = Array::MakeArray(hide_list); |
| + } |
| } |
| ExpectSemicolon(); |
| @@ -4179,15 +4214,17 @@ |
| } |
| } |
| // Add the import to the library. |
| + const Namespace& import = |
| + Namespace::Handle(Namespace::New(library, show_names, hide_names)); |
| if (prefix.IsNull() || (prefix.Length() == 0)) { |
| - library_.AddImport(library); |
| + library_.AddImport(import); |
| } else { |
| LibraryPrefix& library_prefix = LibraryPrefix::Handle(); |
| library_prefix = library_.LookupLocalLibraryPrefix(prefix); |
| if (!library_prefix.IsNull()) { |
| - library_prefix.AddLibrary(library); |
| + library_prefix.AddImport(import); |
| } else { |
| - library_prefix = LibraryPrefix::New(prefix, library); |
| + library_prefix = LibraryPrefix::New(prefix, import); |
| library_.AddObject(library_prefix, prefix); |
| } |
| } |
| @@ -4226,7 +4263,7 @@ |
| if (!library_.ImportsCorelib()) { |
| Library& core_lib = Library::Handle(Library::CoreLibrary()); |
| ASSERT(!core_lib.IsNull()); |
| - library_.AddImport(core_lib); |
| + library_.AddImportAll(core_lib); |
| } |
| return; |
| } |
| @@ -4254,7 +4291,7 @@ |
| if (!library_.ImportsCorelib()) { |
| Library& core_lib = Library::Handle(Library::CoreLibrary()); |
| ASSERT(!core_lib.IsNull()); |
| - library_.AddImport(core_lib); |
| + library_.AddImportAll(core_lib); |
| } |
| while (IsLiteral("part")) { |
| ParseLibraryPart(); |
| @@ -7984,6 +8021,28 @@ |
| } |
| +static RawObject* LookupNameInImport(const Namespace& ns, const String& name) { |
| + Object& obj = Object::Handle(); |
| + obj = ns.Lookup(name); |
| + if (!obj.IsNull()) { |
| + return obj.raw(); |
| + } |
| + // If the given name is filtered out by the import, don't look up the |
| + // getter and setter names. |
| + if (ns.HidesName(name)) { |
|
siva
2012/09/24 18:28:51
The name HidesName is not very readable here as it
hausner
2012/09/24 20:25:43
FiltersName does not say what the filter is doing.
|
| + return Object::null(); |
| + } |
| + String& accessor_name = String::Handle(Field::GetterName(name)); |
| + obj = ns.Lookup(accessor_name); |
| + if (!obj.IsNull()) { |
| + return obj.raw(); |
| + } |
| + accessor_name = Field::SetterName(name); |
| + obj = ns.Lookup(accessor_name); |
| + return obj.raw(); |
| +} |
| + |
| + |
| // Resolve a name by checking the global scope of the current |
| // library. If not found in the current library, then look in the scopes |
| // of all libraries that are imported without a library prefix. |
| @@ -7998,13 +8057,14 @@ |
| // Name is not found in current library. Check scope of all |
| // imported libraries. |
| String& first_lib_url = String::Handle(); |
| - Library& lib = Library::Handle(); |
| + Namespace& import = Namespace::Handle(); |
| intptr_t num_imports = library_.num_imports(); |
| - Object& resolved_obj = Object::Handle(); |
| + Object& imported_obj = Object::Handle(); |
| for (int i = 0; i < num_imports; i++) { |
| - lib ^= library_.ImportAt(i); |
| - resolved_obj = LookupNameInLibrary(lib, name); |
| - if (!resolved_obj.IsNull()) { |
| + import ^= library_.ImportAt(i); |
| + imported_obj = LookupNameInImport(import, name); |
| + if (!imported_obj.IsNull()) { |
| + const Library& lib = Library::Handle(import.library()); |
| if (!first_lib_url.IsNull()) { |
| // Found duplicate definition. |
| if (first_lib_url.raw() == lib.url()) { |
| @@ -8023,7 +8083,7 @@ |
| } |
| } else { |
| first_lib_url = lib.url(); |
| - obj = resolved_obj.raw(); |
| + obj = imported_obj.raw(); |
| } |
| } |
| } |
| @@ -8086,16 +8146,17 @@ |
| const LibraryPrefix& prefix, |
| const String& name) { |
| TRACE_PARSER("ResolveNameInPrefixScope"); |
| - Library& lib = Library::Handle(); |
| + Namespace& import = Namespace::Handle(); |
| String& first_lib_url = String::Handle(); |
| Object& obj = Object::Handle(); |
| Object& resolved_obj = Object::Handle(); |
| - for (intptr_t i = 0; i < prefix.num_libs(); i++) { |
| - lib = prefix.GetLibrary(i); |
| - ASSERT(!lib.IsNull()); |
| - resolved_obj = LookupNameInLibrary(lib, name); |
| + const Array& imports = Array::Handle(prefix.imports()); |
| + for (intptr_t i = 0; i < prefix.num_imports(); i++) { |
| + import ^= imports.At(i); |
| + resolved_obj = LookupNameInImport(import, name); |
| if (!resolved_obj.IsNull()) { |
| obj = resolved_obj.raw(); |
| + const Library& lib = Library::Handle(import.library()); |
| if (first_lib_url.IsNull()) { |
| first_lib_url = lib.url(); |
| } else { |