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

Unified Diff: runtime/vm/object.cc

Issue 11047027: Implement export clause in VM (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/object.cc
===================================================================
--- runtime/vm/object.cc (revision 13255)
+++ runtime/vm/object.cc (working copy)
@@ -5384,6 +5384,28 @@
}
+// Lookup a name in the library's export namespace.
siva 2012/10/08 20:17:42 maybe "library's exported namespace." The name Lo
Ivan Posva 2012/10/08 21:35:50 I will change it so that LookupExport will only lo
Ivan Posva 2012/10/09 00:53:19 Done.
+RawObject* Library::LookupExport(const String& name) const {
+ intptr_t ignore = 0;
+ Object& obj = Object::Handle(LookupEntry(name, &ignore));
+ if (!obj.IsNull()) {
+ return obj.raw();
+ }
+ if (HasExports()) {
+ const Array& exports = Array::Handle(this->exports());
+ Namespace& ns = Namespace::Handle();
+ for (int i = 0; i < exports.Length(); i++) {
+ ns ^= exports.At(i);
+ obj = ns.Lookup(name);
+ if (!obj.IsNull()) {
+ return obj.raw();
+ }
+ }
+ }
+ return Object::null();
+}
+
+
RawObject* Library::LookupEntry(const String& name, intptr_t *index) const {
Isolate* isolate = Isolate::Current();
const Array& dict = Array::Handle(isolate, dictionary());
@@ -5740,25 +5762,6 @@
}
-RawLibrary* Library::LookupImport(const String& url) const {
- Isolate* isolate = Isolate::Current();
- const Array& imports = Array::Handle(isolate, this->imports());
- intptr_t num_imports = this->num_imports();
- Namespace& import = Namespace::Handle(isolate, Namespace::null());
- Library& lib = Library::Handle(isolate, Library::null());
- String& import_url = String::Handle(isolate, String::null());
- for (int i = 0; i < num_imports; i++) {
- import ^= imports.At(i);
- lib = import.library();
- import_url = lib.url();
- if (url.Equals(import_url)) {
- return lib.raw();
- }
- }
- return Library::null();
-}
-
-
RawLibrary* Library::ImportLibraryAt(intptr_t index) const {
Namespace& import = Namespace::Handle(ImportAt(index));
if (import.IsNull()) {
@@ -5819,6 +5822,25 @@
}
+// Convenience function to determine whether the export list is
+// non-empty.
+bool Library::HasExports() const {
+ return exports() != Object::empty_array();
+}
+
+
+// We add one namespace at a time to the exports array and don't
+// pre-allocate any unused capacity. The assumption is that
+// re-exports are quite rare.
+void Library::AddExport(const Namespace& ns) const {
+ Array &exports = Array::Handle(this->exports());
+ intptr_t num_exports = exports.Length();
+ exports = Array::Grow(exports, num_exports + 1);
+ StorePointer(&raw_ptr()->exports_, exports.raw());
+ exports.SetAt(num_exports, ns);
+}
+
+
void Library::InitClassDictionary() const {
// The last element of the dictionary specifies the number of in use slots.
// TODO(iposva): Find reasonable initial size.
@@ -5858,6 +5880,7 @@
result.raw_ptr()->anonymous_classes_ = Object::empty_array();
result.raw_ptr()->num_anonymous_ = 0;
result.raw_ptr()->imports_ = Object::empty_array();
+ result.raw_ptr()->exports_ = Object::empty_array();
result.raw_ptr()->loaded_scripts_ = Array::null();
result.set_native_entry_resolver(NULL);
result.raw_ptr()->corelib_imported_ = true;
@@ -6266,9 +6289,8 @@
RawObject* Namespace::Lookup(const String& name) const {
- intptr_t i = 0;
const Library& lib = Library::Handle(library());
- const Object& obj = Object::Handle(lib.LookupEntry(name, &i));
+ const Object& obj = Object::Handle(lib.LookupExport(name));
if (obj.IsNull() || HidesName(name)) {
return Object::null();
}
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.cc » ('j') | runtime/vm/raw_object.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698