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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/bigint_operations.h" 10 #include "vm/bigint_operations.h"
(...skipping 4127 matching lines...) Expand 10 before | Expand all | Expand 10 after
4138 intptr_t token_pos) { 4138 intptr_t token_pos) {
4139 ASSERT(name.IsOneByteString()); 4139 ASSERT(name.IsOneByteString());
4140 ASSERT(!owner.IsNull()); 4140 ASSERT(!owner.IsNull());
4141 const Function& result = Function::Handle(Function::New()); 4141 const Function& result = Function::Handle(Function::New());
4142 result.set_parameter_types(Array::Handle(Array::Empty())); 4142 result.set_parameter_types(Array::Handle(Array::Empty()));
4143 result.set_parameter_names(Array::Handle(Array::Empty())); 4143 result.set_parameter_names(Array::Handle(Array::Empty()));
4144 result.set_name(name); 4144 result.set_name(name);
4145 result.set_kind(kind); 4145 result.set_kind(kind);
4146 result.set_is_static(is_static); 4146 result.set_is_static(is_static);
4147 result.set_is_const(is_const); 4147 result.set_is_const(is_const);
4148 result.set_is_abstract(is_abstract);
4148 result.set_is_external(is_external); 4149 result.set_is_external(is_external);
4149 result.set_owner(owner); 4150 result.set_owner(owner);
4150 result.set_token_pos(token_pos); 4151 result.set_token_pos(token_pos);
4151 result.set_end_token_pos(token_pos); 4152 result.set_end_token_pos(token_pos);
4152 result.set_num_fixed_parameters(0); 4153 result.set_num_fixed_parameters(0);
4153 result.set_num_optional_parameters(0); 4154 result.set_num_optional_parameters(0);
4154 result.set_usage_counter(0); 4155 result.set_usage_counter(0);
4155 result.set_deoptimization_counter(0); 4156 result.set_deoptimization_counter(0);
4156 result.set_is_optimizable(true); 4157 result.set_is_optimizable(true);
4157 result.set_has_finally(false); 4158 result.set_has_finally(false);
4158 result.set_is_native(false); 4159 result.set_is_native(false);
4159 result.set_is_abstract(is_abstract);
4160 return result.raw(); 4160 return result.raw();
4161 } 4161 }
4162 4162
4163 4163
4164 RawFunction* Function::NewClosureFunction(const String& name, 4164 RawFunction* Function::NewClosureFunction(const String& name,
4165 const Function& parent, 4165 const Function& parent,
4166 intptr_t token_pos) { 4166 intptr_t token_pos) {
4167 ASSERT(name.IsOneByteString()); 4167 ASSERT(name.IsOneByteString());
4168 ASSERT(!parent.IsNull()); 4168 ASSERT(!parent.IsNull());
4169 const Class& parent_class = Class::Handle(parent.owner()); 4169 const Class& parent_class = Class::Handle(parent.owner());
(...skipping 1278 matching lines...) Expand 10 before | Expand all | Expand 10 after
5448 GrowDictionary(dict, dict_size); 5448 GrowDictionary(dict, dict_size);
5449 } 5449 }
5450 5450
5451 // Invalidate the cache of loaded scripts. 5451 // Invalidate the cache of loaded scripts.
5452 if (loaded_scripts() != Array::null()) { 5452 if (loaded_scripts() != Array::null()) {
5453 StorePointer(&raw_ptr()->loaded_scripts_, Array::null()); 5453 StorePointer(&raw_ptr()->loaded_scripts_, Array::null());
5454 } 5454 }
5455 } 5455 }
5456 5456
5457 5457
5458 void Library::ReplaceObject(const Object& obj, const String& name) const {
5459 ASSERT(obj.IsClass() || obj.IsFunction() || obj.IsField());
5460 ASSERT(LookupLocalObject(name) != Object::null());
5461
5462 Isolate* isolate = Isolate::Current();
5463 const Array& dict = Array::Handle(isolate, dictionary());
5464 intptr_t dict_size = dict.Length() - 1;
5465 intptr_t index = name.Hash() % dict_size;
5466
5467 Object& entry = Object::Handle(isolate, Object::null());
hausner 2012/08/07 22:56:36 No need to explicitly specify null. We don't do it
Ivan Posva 2012/08/08 00:56:52 Done.
5468 Class& cls = Class::Handle(isolate, Class::null());
5469 Function& func = Function::Handle(isolate, Function::null());
5470 Field& field = Field::Handle(isolate, Field::null());
5471 LibraryPrefix& library_prefix = LibraryPrefix::Handle(isolate,
5472 LibraryPrefix::null());
5473 String& entry_name = String::Handle(isolate, String::null());
5474 entry = dict.At(index);
5475 // Search the entry in the hash set.
5476 while (!entry.IsNull()) {
hausner 2012/08/07 22:56:36 Maybe factor out the lookup code into a separate f
Ivan Posva 2012/08/08 00:56:52 Done.
5477 // TODO(hausner): find a better way to handle this polymorphism.
5478 // Either introduce a common base class for Class, Function, Field
5479 // and LibraryPrefix or make the name() function virtual in Object.
5480 if (entry.IsClass()) {
5481 cls ^= entry.raw();
5482 entry_name = cls.Name();
5483 } else if (entry.IsFunction()) {
5484 func ^= entry.raw();
5485 entry_name = func.name();
5486 } else if (entry.IsField()) {
5487 field ^= entry.raw();
5488 entry_name = field.name();
5489 } else if (entry.IsLibraryPrefix()) {
5490 library_prefix ^= entry.raw();
5491 entry_name = library_prefix.name();
5492 } else {
5493 UNREACHABLE();
5494 }
5495 if (entry_name.Equals(name)) {
5496 dict.SetAt(index, obj);
5497 }
5498 index = (index + 1) % dict_size;
5499 entry = dict.At(index);
5500 }
5501 }
5502
5503
5458 void Library::AddClass(const Class& cls) const { 5504 void Library::AddClass(const Class& cls) const {
5459 AddObject(cls, String::Handle(cls.Name())); 5505 AddObject(cls, String::Handle(cls.Name()));
5460 // Link class to this library. 5506 // Link class to this library.
5461 cls.set_library(*this); 5507 cls.set_library(*this);
5462 } 5508 }
5463 5509
5464 5510
5465 RawArray* Library::LoadedScripts() const { 5511 RawArray* Library::LoadedScripts() const {
5466 // We compute the list of loaded scripts lazily. The result is 5512 // We compute the list of loaded scripts lazily. The result is
5467 // cached in loaded_scripts_. 5513 // cached in loaded_scripts_.
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after
6195 lib ^= libs.At(i); 6241 lib ^= libs.At(i);
6196 error_message = lib.FindDuplicateDefinition(); 6242 error_message = lib.FindDuplicateDefinition();
6197 if (!error_message.IsNull()) { 6243 if (!error_message.IsNull()) {
6198 return error_message.raw(); 6244 return error_message.raw();
6199 } 6245 }
6200 } 6246 }
6201 return String::null(); 6247 return String::null();
6202 } 6248 }
6203 6249
6204 6250
6251 RawError* Library::Patch(const String& url, const String& source) const {
6252 const Script& script = Script::Handle(
6253 Script::New(url, source, RawScript::kPatchTag));
6254 return Compiler::Compile(*this, script);
6255 }
6256
6257
6205 bool Library::IsKeyUsed(intptr_t key) { 6258 bool Library::IsKeyUsed(intptr_t key) {
6206 intptr_t lib_key; 6259 intptr_t lib_key;
6207 const GrowableObjectArray& libs = GrowableObjectArray::Handle( 6260 const GrowableObjectArray& libs = GrowableObjectArray::Handle(
6208 Isolate::Current()->object_store()->libraries()); 6261 Isolate::Current()->object_store()->libraries());
6209 Library& lib = Library::Handle(); 6262 Library& lib = Library::Handle();
6210 String& lib_url = String::Handle(); 6263 String& lib_url = String::Handle();
6211 for (int i = 0; i < libs.Length(); i++) { 6264 for (int i = 0; i < libs.Length(); i++) {
6212 lib ^= libs.At(i); 6265 lib ^= libs.At(i);
6213 lib_url ^= lib.url(); 6266 lib_url ^= lib.url();
6214 lib_key = lib_url.Hash(); 6267 lib_key = lib_url.Hash();
(...skipping 4840 matching lines...) Expand 10 before | Expand all | Expand 10 after
11055 const char* JSRegExp::ToCString() const { 11108 const char* JSRegExp::ToCString() const {
11056 const String& str = String::Handle(pattern()); 11109 const String& str = String::Handle(pattern());
11057 const char* format = "JSRegExp: pattern=%s flags=%s"; 11110 const char* format = "JSRegExp: pattern=%s flags=%s";
11058 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 11111 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
11059 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len + 1); 11112 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len + 1);
11060 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 11113 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
11061 return chars; 11114 return chars;
11062 } 11115 }
11063 11116
11064 } // namespace dart 11117 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.h » ('j') | runtime/vm/parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698