OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 "vm/assembler.h" | 7 #include "vm/assembler.h" |
8 #include "vm/assert.h" | 8 #include "vm/assert.h" |
9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 const Array& type_params = Array::Handle(type_parameters()); | 831 const Array& type_params = Array::Handle(type_parameters()); |
832 if (type_params.IsNull()) { | 832 if (type_params.IsNull()) { |
833 return 0; | 833 return 0; |
834 } else { | 834 } else { |
835 return type_params.Length(); | 835 return type_params.Length(); |
836 } | 836 } |
837 } | 837 } |
838 | 838 |
839 | 839 |
840 intptr_t Class::NumTypeArguments() const { | 840 intptr_t Class::NumTypeArguments() const { |
| 841 // To work properly, this call requires the super class of this class to be |
| 842 // resolved, which is checked by the SuperClass() call. |
841 intptr_t num_type_args = NumTypeParameters(); | 843 intptr_t num_type_args = NumTypeParameters(); |
842 const Class& superclass = Class::Handle(SuperClass()); | 844 const Class& superclass = Class::Handle(SuperClass()); |
843 // Object is its own super class during bootstrap. | 845 // Object is its own super class during bootstrap. |
844 if (!superclass.IsNull() && (superclass.raw() != raw())) { | 846 if (!superclass.IsNull() && (superclass.raw() != raw())) { |
845 num_type_args += superclass.NumTypeArguments(); | 847 num_type_args += superclass.NumTypeArguments(); |
846 } | 848 } |
847 return num_type_args; | 849 return num_type_args; |
848 } | 850 } |
849 | 851 |
850 | 852 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1014 const Function& signature_function, | 1016 const Function& signature_function, |
1015 const Script& script, | 1017 const Script& script, |
1016 intptr_t token_index) { | 1018 intptr_t token_index) { |
1017 ASSERT(!signature_function.IsNull()); | 1019 ASSERT(!signature_function.IsNull()); |
1018 Type& super_type = Type::Handle(Type::ObjectType()); | 1020 Type& super_type = Type::Handle(Type::ObjectType()); |
1019 const Class& owner_class = Class::Handle(signature_function.owner()); | 1021 const Class& owner_class = Class::Handle(signature_function.owner()); |
1020 ASSERT(!owner_class.IsNull()); | 1022 ASSERT(!owner_class.IsNull()); |
1021 Array& type_parameters = Array::Handle(); | 1023 Array& type_parameters = Array::Handle(); |
1022 TypeArray& type_parameter_extends = TypeArray::Handle(); | 1024 TypeArray& type_parameter_extends = TypeArray::Handle(); |
1023 if (!signature_function.is_static()) { | 1025 if (!signature_function.is_static()) { |
1024 if (owner_class.IsParameterized() && | 1026 if ((owner_class.NumTypeParameters() > 0) && |
1025 !signature_function.HasInstantiatedSignature()) { | 1027 !signature_function.HasInstantiatedSignature()) { |
1026 // Share the function owner super class as the super class of the | 1028 // Share the function owner super class as the super class of the |
1027 // signature class, so that the type argument vector of the closure at | 1029 // signature class, so that the type argument vector of the closure at |
1028 // run time matches the type argument vector of the closure instantiator. | 1030 // run time matches the type argument vector of the closure instantiator. |
1029 type_parameters = owner_class.type_parameters(); | 1031 type_parameters = owner_class.type_parameters(); |
1030 type_parameter_extends = owner_class.type_parameter_extends(); | 1032 type_parameter_extends = owner_class.type_parameter_extends(); |
1031 if (!owner_class.is_interface()) { | 1033 if (!owner_class.is_interface()) { |
1032 super_type = owner_class.super_type(); | 1034 super_type = owner_class.super_type(); |
1033 } | 1035 } |
1034 } | 1036 } |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1207 const TypeArguments& other_type_arguments) const { | 1209 const TypeArguments& other_type_arguments) const { |
1208 // Check for VarType. | 1210 // Check for VarType. |
1209 // The VarType on the lefthand side is replaced by the bottom type, which is | 1211 // The VarType on the lefthand side is replaced by the bottom type, which is |
1210 // more specific than any type. | 1212 // more specific than any type. |
1211 // Any type is more specific than the VarType on the righthand side. | 1213 // Any type is more specific than the VarType on the righthand side. |
1212 if (IsVarClass() || other.IsVarClass()) { | 1214 if (IsVarClass() || other.IsVarClass()) { |
1213 return true; | 1215 return true; |
1214 } | 1216 } |
1215 // Check for reflexivity. | 1217 // Check for reflexivity. |
1216 if (raw() == other.raw()) { | 1218 if (raw() == other.raw()) { |
1217 if (!IsParameterized()) { | 1219 const intptr_t len = NumTypeArguments(); |
| 1220 if (len == 0) { |
1218 return true; | 1221 return true; |
1219 } | 1222 } |
1220 // Since we do not truncate the type argument vector of a subclass (see | 1223 // Since we do not truncate the type argument vector of a subclass (see |
1221 // below), we only check a prefix of the proper length. | 1224 // below), we only check a prefix of the proper length. |
1222 const intptr_t len = NumTypeArguments(); | |
1223 // Check for covariance. | 1225 // Check for covariance. |
1224 if (type_arguments.IsNull() || | 1226 if (type_arguments.IsNull() || |
1225 other_type_arguments.IsNull() || | 1227 other_type_arguments.IsNull() || |
1226 type_arguments.IsVarTypes(len) || | 1228 type_arguments.IsVarTypes(len) || |
1227 other_type_arguments.IsVarTypes(len)) { | 1229 other_type_arguments.IsVarTypes(len)) { |
1228 return true; | 1230 return true; |
1229 } | 1231 } |
1230 return type_arguments.IsMoreSpecificThan(other_type_arguments, len); | 1232 return type_arguments.IsMoreSpecificThan(other_type_arguments, len); |
1231 } | 1233 } |
1232 // Check for 'direct super type' in the case of an interface and check for | 1234 // Check for 'direct super type' in the case of an interface and check for |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1329 } | 1331 } |
1330 // TODO(regis): Merge IsMoreSpecificThan here after type checks for | 1332 // TODO(regis): Merge IsMoreSpecificThan here after type checks for |
1331 // function types are finalized and implemented. | 1333 // function types are finalized and implemented. |
1332 // For now, keep the assert below. | 1334 // For now, keep the assert below. |
1333 | 1335 |
1334 // The optionality and dubious bliss rules described in the guide have | 1336 // The optionality and dubious bliss rules described in the guide have |
1335 // already been checked in IsMoreSpecificThan call above. | 1337 // already been checked in IsMoreSpecificThan call above. |
1336 if (raw() != other.raw()) { | 1338 if (raw() != other.raw()) { |
1337 return false; | 1339 return false; |
1338 } | 1340 } |
1339 ASSERT(IsParameterized()); // Otherwise IsMoreSpecificThan would be true. | 1341 ASSERT(NumTypeArguments() > 0); // Or IsMoreSpecificThan would be true. |
1340 return false; | 1342 return false; |
1341 } | 1343 } |
1342 | 1344 |
1343 | 1345 |
1344 RawFunction* Class::LookupDynamicFunction(const String& name) const { | 1346 RawFunction* Class::LookupDynamicFunction(const String& name) const { |
1345 Function& function = Function::Handle(LookupFunction(name)); | 1347 Function& function = Function::Handle(LookupFunction(name)); |
1346 if (function.IsNull() || function.is_static()) { | 1348 if (function.IsNull() || function.is_static()) { |
1347 return Function::null(); | 1349 return Function::null(); |
1348 } | 1350 } |
1349 switch (function.kind()) { | 1351 switch (function.kind()) { |
(...skipping 3121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4471 return this->raw(); | 4473 return this->raw(); |
4472 } | 4474 } |
4473 | 4475 |
4474 | 4476 |
4475 RawType* Instance::GetType() const { | 4477 RawType* Instance::GetType() const { |
4476 if (IsNull()) { | 4478 if (IsNull()) { |
4477 return Type::NullType(); | 4479 return Type::NullType(); |
4478 } | 4480 } |
4479 const Class& cls = Class::Handle(clazz()); | 4481 const Class& cls = Class::Handle(clazz()); |
4480 TypeArguments& type_arguments = TypeArguments::Handle(); | 4482 TypeArguments& type_arguments = TypeArguments::Handle(); |
4481 if (cls.IsParameterized()) { | 4483 if (cls.NumTypeArguments() > 0) { |
4482 type_arguments = GetTypeArguments(); | 4484 type_arguments = GetTypeArguments(); |
4483 } | 4485 } |
4484 return Type::NewParameterizedType(cls, type_arguments); | 4486 return Type::NewParameterizedType(cls, type_arguments); |
4485 } | 4487 } |
4486 | 4488 |
4487 | 4489 |
4488 RawTypeArguments* Instance::GetTypeArguments() const { | 4490 RawTypeArguments* Instance::GetTypeArguments() const { |
4489 const Class& cls = Class::Handle(clazz()); | 4491 const Class& cls = Class::Handle(clazz()); |
4490 intptr_t field_offset = cls.type_arguments_instance_field_offset(); | 4492 intptr_t field_offset = cls.type_arguments_instance_field_offset(); |
4491 ASSERT(field_offset != Class::kNoTypeArguments); | 4493 ASSERT(field_offset != Class::kNoTypeArguments); |
(...skipping 27 matching lines...) Expand all Loading... |
4519 return true; | 4521 return true; |
4520 } | 4522 } |
4521 return false; | 4523 return false; |
4522 } else { | 4524 } else { |
4523 ASSERT(test == Type::kIsAssignableTo); | 4525 ASSERT(test == Type::kIsAssignableTo); |
4524 return true; | 4526 return true; |
4525 } | 4527 } |
4526 } | 4528 } |
4527 const Class& cls = Class::Handle(clazz()); | 4529 const Class& cls = Class::Handle(clazz()); |
4528 TypeArguments& type_arguments = TypeArguments::Handle(); | 4530 TypeArguments& type_arguments = TypeArguments::Handle(); |
4529 if (cls.IsParameterized()) { | 4531 const intptr_t num_type_arguments = cls.NumTypeArguments(); |
| 4532 if (num_type_arguments > 0) { |
4530 type_arguments = GetTypeArguments(); | 4533 type_arguments = GetTypeArguments(); |
4531 // Verify that the number of type arguments in the instance matches the | 4534 // Verify that the number of type arguments in the instance matches the |
4532 // number of type arguments expected by the instance class. | 4535 // number of type arguments expected by the instance class. |
4533 // A discrepancy is allowed for closures, which borrow the type argument | 4536 // A discrepancy is allowed for closures, which borrow the type argument |
4534 // vector of their instantiator, which may be of a super class of the class | 4537 // vector of their instantiator, which may be of a super class of the class |
4535 // defining the closure. Truncating the vector to the correct length on | 4538 // defining the closure. Truncating the vector to the correct length on |
4536 // instantiation is unnecessary. The vector may therefore be longer. | 4539 // instantiation is unnecessary. The vector may therefore be longer. |
4537 ASSERT(type_arguments.IsNull() || | 4540 ASSERT(type_arguments.IsNull() || |
4538 (type_arguments.Length() == cls.NumTypeArguments()) || | 4541 (type_arguments.Length() == num_type_arguments) || |
4539 (cls.IsSignatureClass() && | 4542 (cls.IsSignatureClass() && |
4540 (type_arguments.Length() > cls.NumTypeArguments()))); | 4543 (type_arguments.Length() > num_type_arguments))); |
4541 } | 4544 } |
4542 Class& other_class = Class::Handle(); | 4545 Class& other_class = Class::Handle(); |
4543 TypeArguments& other_type_arguments = TypeArguments::Handle(); | 4546 TypeArguments& other_type_arguments = TypeArguments::Handle(); |
4544 // In case 'other' is not instantiated, we could simply call | 4547 // In case 'other' is not instantiated, we could simply call |
4545 // other.InstantiateFrom(other_instantiator, 0), however, we can save the | 4548 // other.InstantiateFrom(other_instantiator, 0), however, we can save the |
4546 // allocation of a new Type by inlining the code. | 4549 // allocation of a new Type by inlining the code. |
4547 if (other.IsTypeParameter()) { | 4550 if (other.IsTypeParameter()) { |
4548 Type& instantiated_other = Type::Handle(); | 4551 Type& instantiated_other = Type::Handle(); |
4549 if (!other_instantiator.IsNull()) { | 4552 if (!other_instantiator.IsNull()) { |
4550 instantiated_other = other_instantiator.TypeAt(other.Index()); | 4553 instantiated_other = other_instantiator.TypeAt(other.Index()); |
(...skipping 1904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6455 const String& str = String::Handle(pattern()); | 6458 const String& str = String::Handle(pattern()); |
6456 const char* format = "JSRegExp: pattern=%s flags=%s"; | 6459 const char* format = "JSRegExp: pattern=%s flags=%s"; |
6457 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 6460 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
6458 char* chars = reinterpret_cast<char*>( | 6461 char* chars = reinterpret_cast<char*>( |
6459 Isolate::Current()->current_zone()->Allocate(len + 1)); | 6462 Isolate::Current()->current_zone()->Allocate(len + 1)); |
6460 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 6463 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
6461 return chars; | 6464 return chars; |
6462 } | 6465 } |
6463 | 6466 |
6464 } // namespace dart | 6467 } // namespace dart |
OLD | NEW |