OLD | NEW |
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 RawClass* Object::unresolved_class_class_ = | 74 RawClass* Object::unresolved_class_class_ = |
75 reinterpret_cast<RawClass*>(RAW_NULL); | 75 reinterpret_cast<RawClass*>(RAW_NULL); |
76 RawClass* Object::type_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 76 RawClass* Object::type_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
77 RawClass* Object::type_parameter_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 77 RawClass* Object::type_parameter_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
78 RawClass* Object::type_arguments_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 78 RawClass* Object::type_arguments_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
79 RawClass* Object::instantiated_type_arguments_class_ = | 79 RawClass* Object::instantiated_type_arguments_class_ = |
80 reinterpret_cast<RawClass*>(RAW_NULL); | 80 reinterpret_cast<RawClass*>(RAW_NULL); |
81 RawClass* Object::patch_class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 81 RawClass* Object::patch_class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
82 RawClass* Object::function_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 82 RawClass* Object::function_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
83 RawClass* Object::closure_data_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 83 RawClass* Object::closure_data_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 84 RawClass* Object::redirection_data_class_ = |
| 85 reinterpret_cast<RawClass*>(RAW_NULL); |
84 RawClass* Object::field_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 86 RawClass* Object::field_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
85 RawClass* Object::literal_token_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 87 RawClass* Object::literal_token_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
86 RawClass* Object::token_stream_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 88 RawClass* Object::token_stream_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
87 RawClass* Object::script_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 89 RawClass* Object::script_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
88 RawClass* Object::library_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 90 RawClass* Object::library_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
89 RawClass* Object::library_prefix_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 91 RawClass* Object::library_prefix_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
90 RawClass* Object::code_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 92 RawClass* Object::code_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
91 RawClass* Object::instructions_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 93 RawClass* Object::instructions_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
92 RawClass* Object::pc_descriptors_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 94 RawClass* Object::pc_descriptors_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
93 RawClass* Object::stackmap_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 95 RawClass* Object::stackmap_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 | 331 |
330 cls = Class::New<PatchClass>(); | 332 cls = Class::New<PatchClass>(); |
331 patch_class_class_ = cls.raw(); | 333 patch_class_class_ = cls.raw(); |
332 | 334 |
333 cls = Class::New<Function>(); | 335 cls = Class::New<Function>(); |
334 function_class_ = cls.raw(); | 336 function_class_ = cls.raw(); |
335 | 337 |
336 cls = Class::New<ClosureData>(); | 338 cls = Class::New<ClosureData>(); |
337 closure_data_class_ = cls.raw(); | 339 closure_data_class_ = cls.raw(); |
338 | 340 |
| 341 cls = Class::New<RedirectionData>(); |
| 342 redirection_data_class_ = cls.raw(); |
| 343 |
339 cls = Class::New<Field>(); | 344 cls = Class::New<Field>(); |
340 field_class_ = cls.raw(); | 345 field_class_ = cls.raw(); |
341 | 346 |
342 cls = Class::New<LiteralToken>(); | 347 cls = Class::New<LiteralToken>(); |
343 literal_token_class_ = cls.raw(); | 348 literal_token_class_ = cls.raw(); |
344 | 349 |
345 cls = Class::New<TokenStream>(); | 350 cls = Class::New<TokenStream>(); |
346 token_stream_class_ = cls.raw(); | 351 token_stream_class_ = cls.raw(); |
347 | 352 |
348 cls = Class::New<Script>(); | 353 cls = Class::New<Script>(); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 SET_CLASS_NAME(dynamic, Dynamic); | 439 SET_CLASS_NAME(dynamic, Dynamic); |
435 SET_CLASS_NAME(void, Void); | 440 SET_CLASS_NAME(void, Void); |
436 SET_CLASS_NAME(unresolved_class, UnresolvedClass); | 441 SET_CLASS_NAME(unresolved_class, UnresolvedClass); |
437 SET_CLASS_NAME(type, Type); | 442 SET_CLASS_NAME(type, Type); |
438 SET_CLASS_NAME(type_parameter, TypeParameter); | 443 SET_CLASS_NAME(type_parameter, TypeParameter); |
439 SET_CLASS_NAME(type_arguments, TypeArguments); | 444 SET_CLASS_NAME(type_arguments, TypeArguments); |
440 SET_CLASS_NAME(instantiated_type_arguments, InstantiatedTypeArguments); | 445 SET_CLASS_NAME(instantiated_type_arguments, InstantiatedTypeArguments); |
441 SET_CLASS_NAME(patch_class, PatchClass); | 446 SET_CLASS_NAME(patch_class, PatchClass); |
442 SET_CLASS_NAME(function, Function); | 447 SET_CLASS_NAME(function, Function); |
443 SET_CLASS_NAME(closure_data, ClosureData); | 448 SET_CLASS_NAME(closure_data, ClosureData); |
| 449 SET_CLASS_NAME(redirection_data, RedirectionData); |
444 SET_CLASS_NAME(field, Field); | 450 SET_CLASS_NAME(field, Field); |
445 SET_CLASS_NAME(literal_token, LiteralToken); | 451 SET_CLASS_NAME(literal_token, LiteralToken); |
446 SET_CLASS_NAME(token_stream, TokenStream); | 452 SET_CLASS_NAME(token_stream, TokenStream); |
447 SET_CLASS_NAME(script, Script); | 453 SET_CLASS_NAME(script, Script); |
448 SET_CLASS_NAME(library, LibraryClass); | 454 SET_CLASS_NAME(library, LibraryClass); |
449 SET_CLASS_NAME(library_prefix, LibraryPrefix); | 455 SET_CLASS_NAME(library_prefix, LibraryPrefix); |
450 SET_CLASS_NAME(code, Code); | 456 SET_CLASS_NAME(code, Code); |
451 SET_CLASS_NAME(instructions, Instructions); | 457 SET_CLASS_NAME(instructions, Instructions); |
452 SET_CLASS_NAME(pc_descriptors, PcDescriptors); | 458 SET_CLASS_NAME(pc_descriptors, PcDescriptors); |
453 SET_CLASS_NAME(stackmap, Stackmap); | 459 SET_CLASS_NAME(stackmap, Stackmap); |
(...skipping 3475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3929 if (IsClosureFunction()) { | 3935 if (IsClosureFunction()) { |
3930 const Object& obj = Object::Handle(raw_ptr()->data_); | 3936 const Object& obj = Object::Handle(raw_ptr()->data_); |
3931 ASSERT(!obj.IsNull()); | 3937 ASSERT(!obj.IsNull()); |
3932 ClosureData::Cast(obj).set_signature_class(value); | 3938 ClosureData::Cast(obj).set_signature_class(value); |
3933 return; | 3939 return; |
3934 } | 3940 } |
3935 UNREACHABLE(); | 3941 UNREACHABLE(); |
3936 } | 3942 } |
3937 | 3943 |
3938 | 3944 |
| 3945 bool Function::IsRedirectingFactory() const { |
| 3946 if (!IsFactory() || (raw_ptr()->data_ == Object::null())) { |
| 3947 return false; |
| 3948 } |
| 3949 ASSERT(!IsClosure()); // A factory cannot also be a closure. |
| 3950 return true; |
| 3951 } |
| 3952 |
| 3953 |
| 3954 RawType* Function::RedirectionType() const { |
| 3955 ASSERT(IsRedirectingFactory()); |
| 3956 const Object& obj = Object::Handle(raw_ptr()->data_); |
| 3957 ASSERT(!obj.IsNull()); |
| 3958 return RedirectionData::Cast(obj).type(); |
| 3959 } |
| 3960 |
| 3961 |
| 3962 void Function::SetRedirectionType(const Type& type) const { |
| 3963 ASSERT(IsFactory()); |
| 3964 Object& obj = Object::Handle(raw_ptr()->data_); |
| 3965 if (obj.IsNull()) { |
| 3966 obj = RedirectionData::New(); |
| 3967 set_data(obj); |
| 3968 } |
| 3969 RedirectionData::Cast(obj).set_type(type); |
| 3970 } |
| 3971 |
| 3972 |
| 3973 RawString* Function::RedirectionIdentifier() const { |
| 3974 ASSERT(IsRedirectingFactory()); |
| 3975 const Object& obj = Object::Handle(raw_ptr()->data_); |
| 3976 ASSERT(!obj.IsNull()); |
| 3977 return RedirectionData::Cast(obj).identifier(); |
| 3978 } |
| 3979 |
| 3980 |
| 3981 void Function::SetRedirectionIdentifier(const String& identifier) const { |
| 3982 ASSERT(IsFactory()); |
| 3983 Object& obj = Object::Handle(raw_ptr()->data_); |
| 3984 if (obj.IsNull()) { |
| 3985 obj = RedirectionData::New(); |
| 3986 set_data(obj); |
| 3987 } |
| 3988 RedirectionData::Cast(obj).set_identifier(identifier); |
| 3989 } |
| 3990 |
| 3991 |
| 3992 RawFunction* Function::RedirectionTarget() const { |
| 3993 ASSERT(IsRedirectingFactory()); |
| 3994 const Object& obj = Object::Handle(raw_ptr()->data_); |
| 3995 ASSERT(!obj.IsNull()); |
| 3996 return RedirectionData::Cast(obj).target(); |
| 3997 } |
| 3998 |
| 3999 |
| 4000 void Function::SetRedirectionTarget(const Function& target) const { |
| 4001 ASSERT(IsFactory()); |
| 4002 Object& obj = Object::Handle(raw_ptr()->data_); |
| 4003 if (obj.IsNull()) { |
| 4004 obj = RedirectionData::New(); |
| 4005 set_data(obj); |
| 4006 } |
| 4007 RedirectionData::Cast(obj).set_target(target); |
| 4008 } |
| 4009 |
| 4010 |
3939 void Function::set_data(const Object& value) const { | 4011 void Function::set_data(const Object& value) const { |
3940 StorePointer(&raw_ptr()->data_, value.raw()); | 4012 StorePointer(&raw_ptr()->data_, value.raw()); |
3941 } | 4013 } |
3942 | 4014 |
3943 | 4015 |
3944 bool Function::IsInFactoryScope() const { | 4016 bool Function::IsInFactoryScope() const { |
3945 Function& outer_function = Function::Handle(raw()); | 4017 Function& outer_function = Function::Handle(raw()); |
3946 while (outer_function.IsLocalFunction()) { | 4018 while (outer_function.IsLocalFunction()) { |
3947 outer_function = outer_function.parent_function(); | 4019 outer_function = outer_function.parent_function(); |
3948 } | 4020 } |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4319 | 4391 |
4320 bool Function::HasCompatibleParametersWith(const Function& other) const { | 4392 bool Function::HasCompatibleParametersWith(const Function& other) const { |
4321 const intptr_t num_fixed_params = num_fixed_parameters(); | 4393 const intptr_t num_fixed_params = num_fixed_parameters(); |
4322 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters(); | 4394 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters(); |
4323 const intptr_t num_opt_named_params = NumOptionalNamedParameters(); | 4395 const intptr_t num_opt_named_params = NumOptionalNamedParameters(); |
4324 const intptr_t other_num_fixed_params = other.num_fixed_parameters(); | 4396 const intptr_t other_num_fixed_params = other.num_fixed_parameters(); |
4325 const intptr_t other_num_opt_pos_params = | 4397 const intptr_t other_num_opt_pos_params = |
4326 other.NumOptionalPositionalParameters(); | 4398 other.NumOptionalPositionalParameters(); |
4327 const intptr_t other_num_opt_named_params = | 4399 const intptr_t other_num_opt_named_params = |
4328 other.NumOptionalNamedParameters(); | 4400 other.NumOptionalNamedParameters(); |
| 4401 // A generative constructor may be compared to a redirecting factory and be |
| 4402 // compatible although it has an additional phase parameter. |
| 4403 const intptr_t num_ignored_params = |
| 4404 (other.IsRedirectingFactory() && IsConstructor()) ? 1 : 0; |
4329 if (FLAG_reject_named_argument_as_positional) { | 4405 if (FLAG_reject_named_argument_as_positional) { |
4330 // The default values of optional parameters can differ. | 4406 // The default values of optional parameters can differ. |
4331 if ((num_fixed_params != other_num_fixed_params) || | 4407 if (((num_fixed_params - num_ignored_params) != other_num_fixed_params) || |
4332 (num_opt_pos_params < other_num_opt_pos_params) || | 4408 (num_opt_pos_params < other_num_opt_pos_params) || |
4333 (num_opt_named_params < other_num_opt_named_params)) { | 4409 (num_opt_named_params < other_num_opt_named_params)) { |
4334 return false; | 4410 return false; |
4335 } | 4411 } |
4336 if (other_num_opt_named_params == 0) { | 4412 if (other_num_opt_named_params == 0) { |
4337 return true; | 4413 return true; |
4338 } | 4414 } |
4339 // Check that for each optional named parameter of the other function there | 4415 // Check that for each optional named parameter of the other function there |
4340 // exists an optional named parameter of this function with an identical | 4416 // exists an optional named parameter of this function with an identical |
4341 // name. | 4417 // name. |
(...skipping 19 matching lines...) Expand all Loading... |
4361 } | 4437 } |
4362 return true; | 4438 return true; |
4363 } | 4439 } |
4364 | 4440 |
4365 // TODO(regis): Remove the following code once the flag is removed. | 4441 // TODO(regis): Remove the following code once the flag is removed. |
4366 | 4442 |
4367 // The default values of optional parameters can differ. | 4443 // The default values of optional parameters can differ. |
4368 const intptr_t num_opt_params = num_opt_pos_params + num_opt_named_params; | 4444 const intptr_t num_opt_params = num_opt_pos_params + num_opt_named_params; |
4369 const intptr_t other_num_opt_params = | 4445 const intptr_t other_num_opt_params = |
4370 other_num_opt_pos_params + other_num_opt_named_params; | 4446 other_num_opt_pos_params + other_num_opt_named_params; |
4371 if ((num_fixed_params != other_num_fixed_params) || | 4447 if (((num_fixed_params - num_ignored_params) != other_num_fixed_params) || |
4372 (num_opt_params < other_num_opt_params)) { | 4448 (num_opt_params < other_num_opt_params)) { |
4373 return false; | 4449 return false; |
4374 } | 4450 } |
4375 // Check that for each optional named parameter of the other function there is | 4451 // Check that for each optional named parameter of the other function there is |
4376 // a corresponding optional named parameter of this function with an identical | 4452 // a corresponding optional named parameter of this function with an identical |
4377 // name at the same position. | 4453 // name at the same position. |
4378 // Note that SetParameterNameAt() guarantees that names are symbols, so we can | 4454 // Note that SetParameterNameAt() guarantees that names are symbols, so we can |
4379 // compare their raw pointers. | 4455 // compare their raw pointers. |
4380 const int other_num_params = other_num_fixed_params + other_num_opt_params; | 4456 const int other_num_params = other_num_fixed_params + other_num_opt_params; |
4381 for (intptr_t i = other_num_fixed_params; i < other_num_params; i++) { | 4457 for (intptr_t i = other_num_fixed_params; i < other_num_params; i++) { |
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4972 Heap::kOld); | 5048 Heap::kOld); |
4973 return reinterpret_cast<RawClosureData*>(raw); | 5049 return reinterpret_cast<RawClosureData*>(raw); |
4974 } | 5050 } |
4975 | 5051 |
4976 | 5052 |
4977 const char* ClosureData::ToCString() const { | 5053 const char* ClosureData::ToCString() const { |
4978 return "ClosureData class"; | 5054 return "ClosureData class"; |
4979 } | 5055 } |
4980 | 5056 |
4981 | 5057 |
| 5058 void RedirectionData::set_type(const Type& value) const { |
| 5059 ASSERT(!value.IsNull()); |
| 5060 StorePointer(&raw_ptr()->type_, value.raw()); |
| 5061 } |
| 5062 |
| 5063 |
| 5064 void RedirectionData::set_identifier(const String& value) const { |
| 5065 StorePointer(&raw_ptr()->identifier_, value.raw()); |
| 5066 } |
| 5067 |
| 5068 |
| 5069 void RedirectionData::set_target(const Function& value) const { |
| 5070 StorePointer(&raw_ptr()->target_, value.raw()); |
| 5071 } |
| 5072 |
| 5073 |
| 5074 RawRedirectionData* RedirectionData::New() { |
| 5075 ASSERT(Object::redirection_data_class() != Class::null()); |
| 5076 RawObject* raw = Object::Allocate(RedirectionData::kClassId, |
| 5077 RedirectionData::InstanceSize(), |
| 5078 Heap::kOld); |
| 5079 return reinterpret_cast<RawRedirectionData*>(raw); |
| 5080 } |
| 5081 |
| 5082 |
| 5083 const char* RedirectionData::ToCString() const { |
| 5084 return "RedirectionData class"; |
| 5085 } |
| 5086 |
| 5087 |
4982 RawString* Field::GetterName(const String& field_name) { | 5088 RawString* Field::GetterName(const String& field_name) { |
4983 String& str = String::Handle(); | 5089 String& str = String::Handle(); |
4984 str = String::New(kGetterPrefix); | 5090 str = String::New(kGetterPrefix); |
4985 str = String::Concat(str, field_name); | 5091 str = String::Concat(str, field_name); |
4986 return str.raw(); | 5092 return str.raw(); |
4987 } | 5093 } |
4988 | 5094 |
4989 | 5095 |
4990 RawString* Field::GetterSymbol(const String& field_name) { | 5096 RawString* Field::GetterSymbol(const String& field_name) { |
4991 String& str = String::Handle(); | 5097 String& str = String::Handle(); |
(...skipping 6941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11933 } | 12039 } |
11934 return result.raw(); | 12040 return result.raw(); |
11935 } | 12041 } |
11936 | 12042 |
11937 | 12043 |
11938 const char* WeakProperty::ToCString() const { | 12044 const char* WeakProperty::ToCString() const { |
11939 return "_WeakProperty"; | 12045 return "_WeakProperty"; |
11940 } | 12046 } |
11941 | 12047 |
11942 } // namespace dart | 12048 } // namespace dart |
OLD | NEW |