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

Unified Diff: runtime/vm/object.cc

Issue 10824209: - Allow patching of top-level methods and accessors. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 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
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
===================================================================
--- runtime/vm/object.cc (revision 10353)
+++ runtime/vm/object.cc (working copy)
@@ -4145,6 +4145,7 @@
result.set_kind(kind);
result.set_is_static(is_static);
result.set_is_const(is_const);
+ result.set_is_abstract(is_abstract);
result.set_is_external(is_external);
result.set_owner(owner);
result.set_token_pos(token_pos);
@@ -4156,7 +4157,6 @@
result.set_is_optimizable(true);
result.set_has_finally(false);
result.set_is_native(false);
- result.set_is_abstract(is_abstract);
return result.raw();
}
@@ -5455,6 +5455,61 @@
}
+RawObject* Library::LookupEntry(const String& name, intptr_t *index) const {
+ Isolate* isolate = Isolate::Current();
+ const Array& dict = Array::Handle(isolate, dictionary());
+ intptr_t dict_size = dict.Length() - 1;
+ *index = name.Hash() % dict_size;
+
+ Object& entry = Object::Handle(isolate);
+ Class& cls = Class::Handle(isolate);
+ Function& func = Function::Handle(isolate);
+ Field& field = Field::Handle(isolate);
+ LibraryPrefix& library_prefix = LibraryPrefix::Handle(isolate);
+ String& entry_name = String::Handle(isolate);
+ entry = dict.At(*index);
+ // Search the entry in the hash set.
+ while (!entry.IsNull()) {
+ // TODO(hausner): find a better way to handle this polymorphism.
+ // Either introduce a common base class for Class, Function, Field
+ // and LibraryPrefix or make the name() function virtual in Object.
+ if (entry.IsClass()) {
+ cls ^= entry.raw();
+ entry_name = cls.Name();
+ } else if (entry.IsFunction()) {
+ func ^= entry.raw();
+ entry_name = func.name();
+ } else if (entry.IsField()) {
+ field ^= entry.raw();
+ entry_name = field.name();
+ } else if (entry.IsLibraryPrefix()) {
+ library_prefix ^= entry.raw();
+ entry_name = library_prefix.name();
+ } else {
+ UNREACHABLE();
+ }
+ if (entry_name.Equals(name)) {
+ return entry.raw();
+ }
+ *index = (*index + 1) % dict_size;
+ entry = dict.At(*index);
+ }
+ return Object::null();
+}
+
+
+void Library::ReplaceObject(const Object& obj, const String& name) const {
+ ASSERT(obj.IsClass() || obj.IsFunction() || obj.IsField());
+ ASSERT(LookupLocalObject(name) != Object::null());
+
+ intptr_t index;
+ LookupEntry(name, &index);
+ // The value is guaranteed to be found.
+ const Array& dict = Array::Handle(dictionary());
+ dict.SetAt(index, obj);
+}
+
+
void Library::AddClass(const Class& cls) const {
AddObject(cls, String::Handle(cls.Name()));
// Link class to this library.
@@ -5584,46 +5639,8 @@
RawObject* Library::LookupLocalObject(const String& name) const {
- Isolate* isolate = Isolate::Current();
- const Array& dict = Array::Handle(isolate, dictionary());
- intptr_t dict_size = dict.Length() - 1;
- intptr_t index = name.Hash() % dict_size;
-
- Object& entry = Object::Handle(isolate, Object::null());
- Class& cls = Class::Handle(isolate, Class::null());
- Function& func = Function::Handle(isolate, Function::null());
- Field& field = Field::Handle(isolate, Field::null());
- LibraryPrefix& library_prefix = LibraryPrefix::Handle(isolate,
- LibraryPrefix::null());
- String& entry_name = String::Handle(isolate, String::null());
- entry = dict.At(index);
- // Search the entry in the hash set.
- while (!entry.IsNull()) {
- // TODO(hausner): find a better way to handle this polymorphism.
- // Either introduce a common base class for Class, Function, Field
- // and LibraryPrefix or make the name() function virtual in Object.
- if (entry.IsClass()) {
- cls ^= entry.raw();
- entry_name = cls.Name();
- } else if (entry.IsFunction()) {
- func ^= entry.raw();
- entry_name = func.name();
- } else if (entry.IsField()) {
- field ^= entry.raw();
- entry_name = field.name();
- } else if (entry.IsLibraryPrefix()) {
- library_prefix ^= entry.raw();
- entry_name = library_prefix.name();
- } else {
- UNREACHABLE();
- }
- if (entry_name.Equals(name)) {
- return entry.raw();
- }
- index = (index + 1) % dict_size;
- entry = dict.At(index);
- }
- return Class::null();
+ intptr_t index;
+ return LookupEntry(name, &index);
}
@@ -6202,6 +6219,13 @@
}
+RawError* Library::Patch(const String& url, const String& source) const {
+ const Script& script = Script::Handle(
+ Script::New(url, source, RawScript::kPatchTag));
+ return Compiler::Compile(*this, script);
+}
+
+
bool Library::IsKeyUsed(intptr_t key) {
intptr_t lib_key;
const GrowableObjectArray& libs = GrowableObjectArray::Handle(
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698