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

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

Issue 10796004: Consolidate a few fields in RawFunction using bitfields. (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
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 3730 matching lines...) Expand 10 before | Expand all | Expand 10 after
3741 parameter_names.SetAt(index, value); 3741 parameter_names.SetAt(index, value);
3742 } 3742 }
3743 3743
3744 3744
3745 void Function::set_parameter_names(const Array& value) const { 3745 void Function::set_parameter_names(const Array& value) const {
3746 StorePointer(&raw_ptr()->parameter_names_, value.raw()); 3746 StorePointer(&raw_ptr()->parameter_names_, value.raw());
3747 } 3747 }
3748 3748
3749 3749
3750 void Function::set_kind(RawFunction::Kind value) const { 3750 void Function::set_kind(RawFunction::Kind value) const {
3751 raw_ptr()->kind_ = value; 3751 raw()->SetKind(value);
3752 } 3752 }
3753 3753
3754 3754
3755 void Function::set_is_static(bool is_static) const { 3755 void Function::set_is_static(bool is_static) const {
3756 raw_ptr()->is_static_ = is_static; 3756 raw()->SetIsStatic(is_static);
3757 } 3757 }
3758 3758
3759 3759
3760 void Function::set_is_const(bool is_const) const { 3760 void Function::set_is_const(bool is_const) const {
3761 raw_ptr()->is_const_ = is_const; 3761 raw()->SetIsConst(is_const);
3762 } 3762 }
3763 3763
3764 3764
3765 void Function::set_is_external(bool value) const { 3765 void Function::set_is_external(bool is_external) const {
3766 raw_ptr()->is_external_ = value; 3766 raw()->SetIsExternal(is_external);
3767 } 3767 }
3768 3768
3769 3769
3770 void Function::set_token_pos(intptr_t pos) const { 3770 void Function::set_token_pos(intptr_t pos) const {
3771 ASSERT(pos >= 0); 3771 ASSERT(pos >= 0);
3772 raw_ptr()->token_pos_ = pos; 3772 raw_ptr()->token_pos_ = pos;
3773 } 3773 }
3774 3774
3775 3775
3776 void Function::set_num_fixed_parameters(intptr_t n) const { 3776 void Function::set_num_fixed_parameters(intptr_t n) const {
3777 ASSERT(n >= 0); 3777 ASSERT(n >= 0);
3778 raw_ptr()->num_fixed_parameters_ = n; 3778 raw_ptr()->num_fixed_parameters_ = n;
3779 } 3779 }
3780 3780
3781 3781
3782 void Function::set_num_optional_parameters(intptr_t n) const { 3782 void Function::set_num_optional_parameters(intptr_t n) const {
3783 ASSERT(n >= 0); 3783 ASSERT(n >= 0);
3784 raw_ptr()->num_optional_parameters_ = n; 3784 raw_ptr()->num_optional_parameters_ = n;
3785 } 3785 }
3786 3786
3787 3787
3788 void Function::set_is_optimizable(bool value) const { 3788 void Function::set_is_optimizable(bool value) const {
3789 raw_ptr()->is_optimizable_ = value; 3789 raw()->SetIsOptimizable(value);
3790 } 3790 }
3791 3791
3792 3792
3793 void Function::set_is_native(bool value) const { 3793 void Function::set_is_native(bool value) const {
3794 raw_ptr()->is_native_ = value; 3794 raw()->SetIsNative(value);
3795 }
3796
3797
3798 void Function::set_is_abstract(bool value) const {
3799 raw()->SetIsAbstract(value);
3795 } 3800 }
3796 3801
3797 3802
3798 intptr_t Function::NumberOfParameters() const { 3803 intptr_t Function::NumberOfParameters() const {
3799 return num_fixed_parameters() + num_optional_parameters(); 3804 return num_fixed_parameters() + num_optional_parameters();
3800 } 3805 }
3801 3806
3802 3807
3803 intptr_t Function::NumberOfImplicitParameters() const { 3808 intptr_t Function::NumberOfImplicitParameters() const {
3804 if (kind() == RawFunction::kConstructor) { 3809 if (kind() == RawFunction::kConstructor) {
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
4114 Function::InstanceSize(), 4119 Function::InstanceSize(),
4115 Heap::kOld); 4120 Heap::kOld);
4116 return reinterpret_cast<RawFunction*>(raw); 4121 return reinterpret_cast<RawFunction*>(raw);
4117 } 4122 }
4118 4123
4119 4124
4120 RawFunction* Function::New(const String& name, 4125 RawFunction* Function::New(const String& name,
4121 RawFunction::Kind kind, 4126 RawFunction::Kind kind,
4122 bool is_static, 4127 bool is_static,
4123 bool is_const, 4128 bool is_const,
4129 bool is_abstract,
4124 bool is_external, 4130 bool is_external,
4125 intptr_t token_pos) { 4131 intptr_t token_pos) {
4126 ASSERT(name.IsOneByteString()); 4132 ASSERT(name.IsOneByteString());
4127 const Function& result = Function::Handle(Function::New()); 4133 const Function& result = Function::Handle(Function::New());
4128 result.set_parameter_types(Array::Handle(Array::Empty())); 4134 result.set_parameter_types(Array::Handle(Array::Empty()));
4129 result.set_parameter_names(Array::Handle(Array::Empty())); 4135 result.set_parameter_names(Array::Handle(Array::Empty()));
4130 result.set_name(name); 4136 result.set_name(name);
4131 result.set_kind(kind); 4137 result.set_kind(kind);
4132 result.set_is_static(is_static); 4138 result.set_is_static(is_static);
4133 result.set_is_const(is_const); 4139 result.set_is_const(is_const);
4134 result.set_is_external(is_external); 4140 result.set_is_external(is_external);
4135 result.set_token_pos(token_pos); 4141 result.set_token_pos(token_pos);
4136 result.set_end_token_pos(token_pos); 4142 result.set_end_token_pos(token_pos);
4137 result.set_num_fixed_parameters(0); 4143 result.set_num_fixed_parameters(0);
4138 result.set_num_optional_parameters(0); 4144 result.set_num_optional_parameters(0);
4139 result.set_usage_counter(0); 4145 result.set_usage_counter(0);
4140 result.set_deoptimization_counter(0); 4146 result.set_deoptimization_counter(0);
4141 result.set_is_optimizable(true); 4147 result.set_is_optimizable(true);
4142 result.set_is_native(false); 4148 result.set_is_native(false);
4149 result.set_is_abstract(is_abstract);
4143 return result.raw(); 4150 return result.raw();
4144 } 4151 }
4145 4152
4146 4153
4147 RawFunction* Function::NewClosureFunction(const String& name, 4154 RawFunction* Function::NewClosureFunction(const String& name,
4148 const Function& parent, 4155 const Function& parent,
4149 intptr_t token_pos) { 4156 intptr_t token_pos) {
4150 ASSERT(name.IsOneByteString()); 4157 ASSERT(name.IsOneByteString());
4151 ASSERT(!parent.IsNull()); 4158 ASSERT(!parent.IsNull());
4152 const Class& parent_class = Class::Handle(parent.owner()); 4159 const Class& parent_class = Class::Handle(parent.owner());
4153 ASSERT(!parent_class.IsNull()); 4160 ASSERT(!parent_class.IsNull());
4154 const Function& result = Function::Handle( 4161 const Function& result = Function::Handle(
4155 Function::New(name, 4162 Function::New(name,
4156 RawFunction::kClosureFunction, 4163 RawFunction::kClosureFunction,
4157 /* is_static = */ parent.is_static(), 4164 /* is_static = */ parent.is_static(),
4158 /* is_const = */ false, 4165 /* is_const = */ false,
4166 /* is_abstract = */ false,
4159 /* is_external = */ false, 4167 /* is_external = */ false,
4160 token_pos)); 4168 token_pos));
4161 result.set_parent_function(parent); 4169 result.set_parent_function(parent);
4162 result.set_owner(parent_class); 4170 result.set_owner(parent_class);
4163 return result.raw(); 4171 return result.raw();
4164 } 4172 }
4165 4173
4166 4174
4167 RawFunction* Function::ImplicitClosureFunction() const { 4175 RawFunction* Function::ImplicitClosureFunction() const {
4168 // Return the existing implicit closure function if any. 4176 // Return the existing implicit closure function if any.
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
4348 return true; 4356 return true;
4349 } 4357 }
4350 4358
4351 4359
4352 bool Function::HasOptimizedCode() const { 4360 bool Function::HasOptimizedCode() const {
4353 return HasCode() && Code::Handle(raw_ptr()->code_).is_optimized(); 4361 return HasCode() && Code::Handle(raw_ptr()->code_).is_optimized();
4354 } 4362 }
4355 4363
4356 4364
4357 const char* Function::ToCString() const { 4365 const char* Function::ToCString() const {
4358 const char* f0 = is_static() ? " static" : ""; 4366 const char* static_str = is_static() ? " static" : "";
4359 const char* f1 = NULL; 4367 const char* abstract_str = is_abstract() ? " abstract" : "";
4360 const char* f2 = is_const() ? " const" : ""; 4368 const char* kind_str = NULL;
4369 const char* const_str = is_const() ? " const" : "";
4361 switch (kind()) { 4370 switch (kind()) {
4362 case RawFunction::kRegularFunction: 4371 case RawFunction::kRegularFunction:
4363 case RawFunction::kClosureFunction: 4372 case RawFunction::kClosureFunction:
4364 case RawFunction::kGetterFunction: 4373 case RawFunction::kGetterFunction:
4365 case RawFunction::kSetterFunction: 4374 case RawFunction::kSetterFunction:
4366 f1 = ""; 4375 kind_str = "";
4367 break; 4376 break;
4368 case RawFunction::kSignatureFunction: 4377 case RawFunction::kSignatureFunction:
4369 f1 = " signature"; 4378 kind_str = " signature";
4370 break;
4371 case RawFunction::kAbstract:
4372 f1 = " abstract";
4373 break; 4379 break;
4374 case RawFunction::kConstructor: 4380 case RawFunction::kConstructor:
4375 f1 = is_static() ? " factory" : " constructor"; 4381 kind_str = is_static() ? " factory" : " constructor";
4376 break; 4382 break;
4377 case RawFunction::kImplicitGetter: 4383 case RawFunction::kImplicitGetter:
4378 f1 = " getter"; 4384 kind_str = " getter";
4379 break; 4385 break;
4380 case RawFunction::kImplicitSetter: 4386 case RawFunction::kImplicitSetter:
4381 f1 = " setter"; 4387 kind_str = " setter";
4382 break; 4388 break;
4383 case RawFunction::kConstImplicitGetter: 4389 case RawFunction::kConstImplicitGetter:
4384 f1 = " const-getter"; 4390 kind_str = " const-getter";
4385 break; 4391 break;
4386 default: 4392 default:
4387 UNREACHABLE(); 4393 UNREACHABLE();
4388 } 4394 }
4389 const char* kFormat = "Function '%s':%s%s%s."; 4395 const char* kFormat = "Function '%s':%s%s%s%s.";
4390 const char* function_name = String::Handle(name()).ToCString(); 4396 const char* function_name = String::Handle(name()).ToCString();
4391 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, f0, f1, f2) + 1; 4397 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name,
4398 static_str, abstract_str, kind_str, const_str) + 1;
4392 char* chars = reinterpret_cast<char*>( 4399 char* chars = reinterpret_cast<char*>(
4393 Isolate::Current()->current_zone()->Allocate(len)); 4400 Isolate::Current()->current_zone()->Allocate(len));
4394 OS::SNPrint(chars, len, kFormat, function_name, f0, f1, f2); 4401 OS::SNPrint(chars, len, kFormat, function_name,
4402 static_str, abstract_str, kind_str, const_str);
4395 return chars; 4403 return chars;
4396 } 4404 }
4397 4405
4398 4406
4399 RawString* Field::GetterName(const String& field_name) { 4407 RawString* Field::GetterName(const String& field_name) {
4400 String& str = String::Handle(); 4408 String& str = String::Handle();
4401 str = String::New(kGetterPrefix); 4409 str = String::New(kGetterPrefix);
4402 str = String::Concat(str, field_name); 4410 str = String::Concat(str, field_name);
4403 return str.raw(); 4411 return str.raw();
4404 } 4412 }
(...skipping 6466 matching lines...) Expand 10 before | Expand all | Expand 10 after
10871 const String& str = String::Handle(pattern()); 10879 const String& str = String::Handle(pattern());
10872 const char* format = "JSRegExp: pattern=%s flags=%s"; 10880 const char* format = "JSRegExp: pattern=%s flags=%s";
10873 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 10881 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
10874 char* chars = reinterpret_cast<char*>( 10882 char* chars = reinterpret_cast<char*>(
10875 Isolate::Current()->current_zone()->Allocate(len + 1)); 10883 Isolate::Current()->current_zone()->Allocate(len + 1));
10876 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 10884 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
10877 return chars; 10885 return chars;
10878 } 10886 }
10879 10887
10880 } // namespace dart 10888 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698