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

Side by Side Diff: runtime/vm/object.cc

Issue 10829332: - Split functionality of adding implicit constructors and checking (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 1482 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 // Prefinalized classes have a VM internal representation and no Dart fields. 1493 // Prefinalized classes have a VM internal representation and no Dart fields.
1494 // Their instance size is precomputed and field offsets are known. 1494 // Their instance size is precomputed and field offsets are known.
1495 if (!is_prefinalized()) { 1495 if (!is_prefinalized()) {
1496 // Compute offsets of instance fields and instance size. 1496 // Compute offsets of instance fields and instance size.
1497 CalculateFieldOffsets(); 1497 CalculateFieldOffsets();
1498 } 1498 }
1499 set_is_finalized(); 1499 set_is_finalized();
1500 } 1500 }
1501 1501
1502 1502
1503 void Class::ApplyPatch(const Class& with) const { 1503 // Apply the members from the patch class to the original class.
1504 void Class::ApplyPatch(const Class& patch) const {
1504 ASSERT(!is_finalized()); 1505 ASSERT(!is_finalized());
1505 const Script& patch_script = Script::Handle(with.script()); 1506 const Script& patch_script = Script::Handle(patch.script());
1506 const PatchClass& patch = PatchClass::Handle( 1507 const PatchClass& patch_class = PatchClass::Handle(
1507 PatchClass::New(*this, patch_script)); 1508 PatchClass::New(*this, patch_script));
1508 1509
1509 const Array& orig_functions = Array::Handle(functions()); 1510 const Array& orig_functions = Array::Handle(functions());
1510 intptr_t orig_len = orig_functions.Length(); 1511 intptr_t orig_len = orig_functions.Length();
1511 1512
1512 const Array& patch_functions = Array::Handle(with.functions()); 1513 const Array& patch_functions = Array::Handle(patch.functions());
1513 intptr_t patch_len = patch_functions.Length(); 1514 intptr_t patch_len = patch_functions.Length();
1514 1515
1515 // TODO(iposva): Verify that only patching existing methods and adding only 1516 // TODO(iposva): Verify that only patching existing methods and adding only
1516 // new private methods. 1517 // new private methods. Currently we prepend all patch class members to the
1518 // members lists which makes them override the orignals.
1517 Function& func = Function::Handle(); 1519 Function& func = Function::Handle();
1518 const Array& new_functions = Array::Handle(Array::New(patch_len + orig_len)); 1520 const Array& new_functions = Array::Handle(Array::New(patch_len + orig_len));
1519 for (intptr_t i = 0; i < patch_len; i++) { 1521 for (intptr_t i = 0; i < patch_len; i++) {
1520 func ^= patch_functions.At(i); 1522 func ^= patch_functions.At(i);
1521 func.set_owner(patch); 1523 func.set_owner(patch_class);
1522 new_functions.SetAt(i, func); 1524 new_functions.SetAt(i, func);
1523 } 1525 }
1524 for (intptr_t i = 0; i < orig_len; i++) { 1526 for (intptr_t i = 0; i < orig_len; i++) {
1525 func ^= orig_functions.At(i); 1527 func ^= orig_functions.At(i);
1526 new_functions.SetAt(patch_len + i, func); 1528 new_functions.SetAt(patch_len + i, func);
1527 } 1529 }
1528 SetFunctions(new_functions); 1530 SetFunctions(new_functions);
1529 1531
1530 const Array& orig_fields = Array::Handle(fields()); 1532 const Array& orig_fields = Array::Handle(fields());
1531 orig_len = orig_fields.Length(); 1533 orig_len = orig_fields.Length();
1532 1534
1533 const Array& patch_fields = Array::Handle(with.fields()); 1535 const Array& patch_fields = Array::Handle(patch.fields());
1534 patch_len = patch_fields.Length(); 1536 patch_len = patch_fields.Length();
1535 1537
1536 // TODO(iposva): Verify that no duplicate fields are entered. 1538 // TODO(iposva): Verify that no duplicate fields are entered. Currently we
1539 // prepend all patch class members to the members lists which makes them
1540 // override the orignals.
1537 Field& field = Field::Handle(); 1541 Field& field = Field::Handle();
1538 const Array& new_fields = Array::Handle(Array::New(patch_len + orig_len)); 1542 const Array& new_fields = Array::Handle(Array::New(patch_len + orig_len));
1539 for (intptr_t i = 0; i < patch_len; i++) { 1543 for (intptr_t i = 0; i < patch_len; i++) {
1540 field ^= patch_fields.At(i); 1544 field ^= patch_fields.At(i);
1541 field.set_owner(*this); 1545 field.set_owner(*this);
1542 new_fields.SetAt(i, field); 1546 new_fields.SetAt(i, field);
1543 } 1547 }
1544 for (intptr_t i = 0; i < orig_len; i++) { 1548 for (intptr_t i = 0; i < orig_len; i++) {
1545 field ^= orig_fields.At(i); 1549 field ^= orig_fields.At(i);
1546 new_fields.SetAt(patch_len + i, field); 1550 new_fields.SetAt(patch_len + i, field);
(...skipping 2576 matching lines...) Expand 10 before | Expand all | Expand 10 after
4123 return reinterpret_cast<RawFunction*>(raw); 4127 return reinterpret_cast<RawFunction*>(raw);
4124 } 4128 }
4125 4129
4126 4130
4127 RawFunction* Function::New(const String& name, 4131 RawFunction* Function::New(const String& name,
4128 RawFunction::Kind kind, 4132 RawFunction::Kind kind,
4129 bool is_static, 4133 bool is_static,
4130 bool is_const, 4134 bool is_const,
4131 bool is_abstract, 4135 bool is_abstract,
4132 bool is_external, 4136 bool is_external,
4133 const Class& owner, 4137 const Object& owner,
4134 intptr_t token_pos) { 4138 intptr_t token_pos) {
4135 ASSERT(name.IsOneByteString()); 4139 ASSERT(name.IsOneByteString());
4136 ASSERT(!owner.IsNull()); 4140 ASSERT(!owner.IsNull());
4137 const Function& result = Function::Handle(Function::New()); 4141 const Function& result = Function::Handle(Function::New());
4138 const Array& empty_array = Array::Handle(Object::empty_array()); 4142 const Array& empty_array = Array::Handle(Object::empty_array());
4139 result.set_parameter_types(empty_array); 4143 result.set_parameter_types(empty_array);
4140 result.set_parameter_names(empty_array); 4144 result.set_parameter_names(empty_array);
4141 result.set_name(name); 4145 result.set_name(name);
4142 result.set_kind(kind); 4146 result.set_kind(kind);
4143 result.set_is_static(is_static); 4147 result.set_is_static(is_static);
(...skipping 12 matching lines...) Expand all
4156 result.set_is_native(false); 4160 result.set_is_native(false);
4157 return result.raw(); 4161 return result.raw();
4158 } 4162 }
4159 4163
4160 4164
4161 RawFunction* Function::NewClosureFunction(const String& name, 4165 RawFunction* Function::NewClosureFunction(const String& name,
4162 const Function& parent, 4166 const Function& parent,
4163 intptr_t token_pos) { 4167 intptr_t token_pos) {
4164 ASSERT(name.IsOneByteString()); 4168 ASSERT(name.IsOneByteString());
4165 ASSERT(!parent.IsNull()); 4169 ASSERT(!parent.IsNull());
4166 const Class& parent_class = Class::Handle(parent.Owner()); 4170 const Object& parent_owner = Object::Handle(parent.raw_ptr()->owner_);
4167 ASSERT(!parent_class.IsNull()); 4171 ASSERT(!parent_owner.IsNull());
4168 const Function& result = Function::Handle( 4172 const Function& result = Function::Handle(
4169 Function::New(name, 4173 Function::New(name,
4170 RawFunction::kClosureFunction, 4174 RawFunction::kClosureFunction,
4171 /* is_static = */ parent.is_static(), 4175 /* is_static = */ parent.is_static(),
4172 /* is_const = */ false, 4176 /* is_const = */ false,
4173 /* is_abstract = */ false, 4177 /* is_abstract = */ false,
4174 /* is_external = */ false, 4178 /* is_external = */ false,
4175 parent_class, 4179 parent_owner,
4176 token_pos)); 4180 token_pos));
4177 result.set_parent_function(parent); 4181 result.set_parent_function(parent);
4178 return result.raw(); 4182 return result.raw();
4179 } 4183 }
4180 4184
4181 4185
4182 RawFunction* Function::ImplicitClosureFunction() const { 4186 RawFunction* Function::ImplicitClosureFunction() const {
4183 // Return the existing implicit closure function if any. 4187 // Return the existing implicit closure function if any.
4184 if (raw_ptr()->implicit_closure_function_ != Function::null()) { 4188 if (raw_ptr()->implicit_closure_function_ != Function::null()) {
4185 return raw_ptr()->implicit_closure_function_; 4189 return raw_ptr()->implicit_closure_function_;
(...skipping 7033 matching lines...) Expand 10 before | Expand all | Expand 10 after
11219 const char* JSRegExp::ToCString() const { 11223 const char* JSRegExp::ToCString() const {
11220 const String& str = String::Handle(pattern()); 11224 const String& str = String::Handle(pattern());
11221 const char* format = "JSRegExp: pattern=%s flags=%s"; 11225 const char* format = "JSRegExp: pattern=%s flags=%s";
11222 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 11226 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
11223 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len + 1); 11227 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len + 1);
11224 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 11228 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
11225 return chars; 11229 return chars;
11226 } 11230 }
11227 11231
11228 } // namespace dart 11232 } // 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