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

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

Issue 9325047: Add token index position to classes and types for more accurate error reporting. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 10 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 "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/bigint_operations.h" 9 #include "vm/bigint_operations.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 unwind_error_class_ = cls.raw(); 375 unwind_error_class_ = cls.raw();
376 376
377 ASSERT(class_class() != null_); 377 ASSERT(class_class() != null_);
378 } 378 }
379 379
380 380
381 RawClass* Object::CreateAndRegisterInterface(const char* cname, 381 RawClass* Object::CreateAndRegisterInterface(const char* cname,
382 const Script& script, 382 const Script& script,
383 const Library& lib) { 383 const Library& lib) {
384 const String& name = String::Handle(String::NewSymbol(cname)); 384 const String& name = String::Handle(String::NewSymbol(cname));
385 const Class& cls = Class::Handle(Class::NewInterface(name, script)); 385 const Class& cls = Class::Handle(
386 Class::NewInterface(name, script, Scanner::kDummyTokenIndex));
386 lib.AddClass(cls); 387 lib.AddClass(cls);
387 return cls.raw(); 388 return cls.raw();
388 } 389 }
389 390
390 391
391 void Object::RegisterClass(const Class& cls, 392 void Object::RegisterClass(const Class& cls,
392 const char* cname, 393 const char* cname,
393 const Script& script, 394 const Script& script,
394 const Library& lib) { 395 const Library& lib) {
395 const String& name = String::Handle(String::NewSymbol(cname)); 396 const String& name = String::Handle(String::NewSymbol(cname));
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 // A signature class extends class Instance and is parameterized in the same 815 // A signature class extends class Instance and is parameterized in the same
815 // way as the owner class of its non-static signature function. 816 // way as the owner class of its non-static signature function.
816 // It is not type parameterized if its signature function is static. 817 // It is not type parameterized if its signature function is static.
817 // See Class::NewSignatureClass() for the setup of its type parameters. 818 // See Class::NewSignatureClass() for the setup of its type parameters.
818 // During type finalization, the type arguments of the super class of the 819 // During type finalization, the type arguments of the super class of the
819 // owner class of its signature function will be prepended to the type 820 // owner class of its signature function will be prepended to the type
820 // argument vector. Therefore, we only need to set the type arguments 821 // argument vector. Therefore, we only need to set the type arguments
821 // matching the type parameters here. 822 // matching the type parameters here.
822 if (num_type_params > 0) { 823 if (num_type_params > 0) {
823 const Array& type_params = Array::Handle(type_parameters()); 824 const Array& type_params = Array::Handle(type_parameters());
825 // TODO(regis): Simply use the type parameters as type arguments, once type
826 // parameters are stored as an array of TypeParameter, rather than String.
824 signature_type_arguments = TypeArguments::New(num_type_params); 827 signature_type_arguments = TypeArguments::New(num_type_params);
825 String& type_param_name = String::Handle(); 828 String& type_param_name = String::Handle();
826 AbstractType& type_param = AbstractType::Handle(); 829 AbstractType& type_param = AbstractType::Handle();
827 for (int i = 0; i < num_type_params; i++) { 830 for (int i = 0; i < num_type_params; i++) {
828 type_param_name ^= type_params.At(i); 831 type_param_name ^= type_params.At(i);
829 type_param = AbstractType::NewTypeParameter(i, type_param_name); 832 // TODO(regis): Use dummy token index 1 for now; see TODO above.
833 type_param = AbstractType::NewTypeParameter(i, type_param_name, 1);
830 signature_type_arguments.SetTypeAt(i, type_param); 834 signature_type_arguments.SetTypeAt(i, type_param);
831 } 835 }
832 } 836 }
833 const Type& signature_type = Type::Handle( 837 const Type& signature_type = Type::Handle(
834 Type::New(*this, signature_type_arguments)); 838 Type::New(*this, signature_type_arguments, token_index()));
835 839
836 // Return the still unfinalized signature type. 840 // Return the still unfinalized signature type.
837 ASSERT(!signature_type.IsFinalized()); 841 ASSERT(!signature_type.IsFinalized());
838 return signature_type.raw(); 842 return signature_type.raw();
839 } 843 }
840 844
841 845
842 template <class FakeObject> 846 template <class FakeObject>
843 RawClass* Class::New() { 847 RawClass* Class::New() {
844 Class& class_class = Class::Handle(Object::class_class()); 848 Class& class_class = Class::Handle(Object::class_class());
(...skipping 15 matching lines...) Expand all
860 result.set_instance_size(FakeObject::InstanceSize()); 864 result.set_instance_size(FakeObject::InstanceSize());
861 result.set_next_field_offset(FakeObject::InstanceSize()); 865 result.set_next_field_offset(FakeObject::InstanceSize());
862 result.set_instance_kind(FakeObject::kInstanceKind); 866 result.set_instance_kind(FakeObject::kInstanceKind);
863 result.raw_ptr()->is_const_ = false; 867 result.raw_ptr()->is_const_ = false;
864 result.raw_ptr()->is_interface_ = false; 868 result.raw_ptr()->is_interface_ = false;
865 // VM backed classes are almost ready: run checks and resolve class 869 // VM backed classes are almost ready: run checks and resolve class
866 // references, but do not recompute size. 870 // references, but do not recompute size.
867 result.raw_ptr()->class_state_ = RawClass::kPreFinalized; 871 result.raw_ptr()->class_state_ = RawClass::kPreFinalized;
868 result.raw_ptr()->type_arguments_instance_field_offset_ = kNoTypeArguments; 872 result.raw_ptr()->type_arguments_instance_field_offset_ = kNoTypeArguments;
869 result.raw_ptr()->num_native_fields_ = 0; 873 result.raw_ptr()->num_native_fields_ = 0;
874 result.raw_ptr()->token_index_ = Scanner::kDummyTokenIndex;
870 result.InitEmptyFields(); 875 result.InitEmptyFields();
871 return result.raw(); 876 return result.raw();
872 } 877 }
873 878
874 879
875 // Initialize class fields of type Array with empty array. 880 // Initialize class fields of type Array with empty array.
876 void Class::InitEmptyFields() { 881 void Class::InitEmptyFields() {
877 const Array& empty_array = Array::Handle(Array::Empty()); 882 const Array& empty_array = Array::Handle(Array::Empty());
878 if (empty_array.IsNull()) { 883 if (empty_array.IsNull()) {
879 // The empty array has not been initialized yet. 884 // The empty array has not been initialized yet.
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 } 1022 }
1018 1023
1019 1024
1020 void Class::set_factory_class(const Object& value) const { 1025 void Class::set_factory_class(const Object& value) const {
1021 StorePointer(&raw_ptr()->factory_class_, value.raw()); 1026 StorePointer(&raw_ptr()->factory_class_, value.raw());
1022 } 1027 }
1023 1028
1024 1029
1025 // Return a TypeParameter if the type_name is a type parameter of this class. 1030 // Return a TypeParameter if the type_name is a type parameter of this class.
1026 // Return null otherwise. 1031 // Return null otherwise.
1027 RawTypeParameter* Class::LookupTypeParameter(const String& type_name) const { 1032 RawTypeParameter* Class::LookupTypeParameter(const String& type_name,
1033 intptr_t token_index) const {
1028 ASSERT(!type_name.IsNull()); 1034 ASSERT(!type_name.IsNull());
1029 const Array& type_params = Array::Handle(type_parameters()); 1035 const Array& type_params = Array::Handle(type_parameters());
1030 if (!type_params.IsNull()) { 1036 if (!type_params.IsNull()) {
1031 intptr_t num_type_params = type_params.Length(); 1037 intptr_t num_type_params = type_params.Length();
1032 String& type_param = String::Handle(); 1038 String& type_param = String::Handle();
1033 for (intptr_t i = 0; i < num_type_params; i++) { 1039 for (intptr_t i = 0; i < num_type_params; i++) {
1034 type_param ^= type_params.At(i); 1040 type_param ^= type_params.At(i);
1035 if (type_param.Equals(type_name)) { 1041 if (type_param.Equals(type_name)) {
1036 return TypeParameter::New(i, type_name); 1042 return TypeParameter::New(i, type_name, token_index);
1037 } 1043 }
1038 } 1044 }
1039 } 1045 }
1040 return TypeParameter::null(); 1046 return TypeParameter::null();
1041 } 1047 }
1042 1048
1043 1049
1044 void Class::CalculateFieldOffsets() const { 1050 void Class::CalculateFieldOffsets() const {
1045 Array& flds = Array::Handle(fields()); 1051 Array& flds = Array::Handle(fields());
1046 const Class& super = Class::Handle(SuperClass()); 1052 const Class& super = Class::Handle(SuperClass());
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 // Only static const fields may contain the Object::sentinel value. 1113 // Only static const fields may contain the Object::sentinel value.
1108 ASSERT(!(field.is_static() && field.is_final()) || 1114 ASSERT(!(field.is_static() && field.is_final()) ||
1109 (field.value() == Object::sentinel())); 1115 (field.value() == Object::sentinel()));
1110 } 1116 }
1111 // The value of static fields is already initialized to null. 1117 // The value of static fields is already initialized to null.
1112 StorePointer(&raw_ptr()->fields_, value.raw()); 1118 StorePointer(&raw_ptr()->fields_, value.raw());
1113 } 1119 }
1114 1120
1115 1121
1116 template <class FakeInstance> 1122 template <class FakeInstance>
1117 RawClass* Class::New(const String& name, const Script& script) { 1123 RawClass* Class::New(const String& name,
1124 const Script& script,
1125 intptr_t token_index) {
1126 ASSERT(token_index >= 0);
1118 Class& class_class = Class::Handle(Object::class_class()); 1127 Class& class_class = Class::Handle(Object::class_class());
1119 Class& result = Class::Handle(); 1128 Class& result = Class::Handle();
1120 { 1129 {
1121 RawObject* raw = Object::Allocate(class_class, 1130 RawObject* raw = Object::Allocate(class_class,
1122 Class::InstanceSize(), 1131 Class::InstanceSize(),
1123 Heap::kOld); 1132 Heap::kOld);
1124 NoGCScope no_gc; 1133 NoGCScope no_gc;
1125 result ^= raw; 1134 result ^= raw;
1126 } 1135 }
1127 FakeInstance fake; 1136 FakeInstance fake;
1128 ASSERT(fake.IsInstance()); 1137 ASSERT(fake.IsInstance());
1129 result.set_handle_vtable(fake.vtable()); 1138 result.set_handle_vtable(fake.vtable());
1130 result.set_instance_size(FakeInstance::InstanceSize()); 1139 result.set_instance_size(FakeInstance::InstanceSize());
1131 result.set_next_field_offset(FakeInstance::InstanceSize()); 1140 result.set_next_field_offset(FakeInstance::InstanceSize());
1132 result.set_instance_kind(FakeInstance::kInstanceKind); 1141 result.set_instance_kind(FakeInstance::kInstanceKind);
1133 result.set_name(name); 1142 result.set_name(name);
1134 result.set_script(script); 1143 result.set_script(script);
1144 result.set_token_index(token_index);
1135 result.raw_ptr()->is_const_ = false; 1145 result.raw_ptr()->is_const_ = false;
1136 result.raw_ptr()->is_interface_ = false; 1146 result.raw_ptr()->is_interface_ = false;
1137 result.raw_ptr()->class_state_ = RawClass::kAllocated; 1147 result.raw_ptr()->class_state_ = RawClass::kAllocated;
1138 result.raw_ptr()->type_arguments_instance_field_offset_ = kNoTypeArguments; 1148 result.raw_ptr()->type_arguments_instance_field_offset_ = kNoTypeArguments;
1139 result.raw_ptr()->num_native_fields_ = 0; 1149 result.raw_ptr()->num_native_fields_ = 0;
1140 result.InitEmptyFields(); 1150 result.InitEmptyFields();
1141 return result.raw(); 1151 return result.raw();
1142 } 1152 }
1143 1153
1144 1154
1145 RawClass* Class::New(const String& name, const Script& script) { 1155 RawClass* Class::New(const String& name,
1146 Class& result = Class::Handle(New<Instance>(name, script)); 1156 const Script& script,
1157 intptr_t token_index) {
1158 Class& result = Class::Handle(New<Instance>(name, script, token_index));
1147 return result.raw(); 1159 return result.raw();
1148 } 1160 }
1149 1161
1150 1162
1151 RawClass* Class::NewInterface(const String& name, const Script& script) { 1163 RawClass* Class::NewInterface(const String& name,
1152 Class& result = Class::Handle(New<Instance>(name, script)); 1164 const Script& script,
1165 intptr_t token_index) {
1166 Class& result = Class::Handle(New<Instance>(name, script, token_index));
1153 result.set_is_interface(); 1167 result.set_is_interface();
1154 return result.raw(); 1168 return result.raw();
1155 } 1169 }
1156 1170
1157 1171
1158 RawClass* Class::NewSignatureClass(const String& name, 1172 RawClass* Class::NewSignatureClass(const String& name,
1159 const Function& signature_function, 1173 const Function& signature_function,
1160 const Script& script) { 1174 const Script& script) {
1161 ASSERT(!signature_function.IsNull()); 1175 ASSERT(!signature_function.IsNull());
1162 const Class& owner_class = Class::Handle(signature_function.owner()); 1176 const Class& owner_class = Class::Handle(signature_function.owner());
1163 ASSERT(!owner_class.IsNull()); 1177 ASSERT(!owner_class.IsNull());
1164 Array& type_parameters = Array::Handle(); 1178 Array& type_parameters = Array::Handle();
1165 TypeArguments& type_parameter_extends = TypeArguments::Handle(); 1179 TypeArguments& type_parameter_extends = TypeArguments::Handle();
1166 // A signature class extends class Instance and is parameterized in the same 1180 // A signature class extends class Instance and is parameterized in the same
1167 // way as the owner class of its non-static signature function. 1181 // way as the owner class of its non-static signature function.
1168 // It is not type parameterized if its signature function is static. 1182 // It is not type parameterized if its signature function is static.
1169 if (!signature_function.is_static()) { 1183 if (!signature_function.is_static()) {
1170 if ((owner_class.NumTypeParameters() > 0) && 1184 if ((owner_class.NumTypeParameters() > 0) &&
1171 !signature_function.HasInstantiatedSignature()) { 1185 !signature_function.HasInstantiatedSignature()) {
1172 type_parameters = owner_class.type_parameters(); 1186 type_parameters = owner_class.type_parameters();
1173 type_parameter_extends = owner_class.type_parameter_extends(); 1187 type_parameter_extends = owner_class.type_parameter_extends();
1174 } 1188 }
1175 } 1189 }
1176 Class& result = Class::Handle(New<Closure>(name, script)); 1190 const intptr_t token_index = signature_function.token_index();
1191 Class& result = Class::Handle(New<Closure>(name, script, token_index));
1177 const Type& super_type = Type::Handle(Type::ObjectType()); 1192 const Type& super_type = Type::Handle(Type::ObjectType());
1178 ASSERT(!super_type.IsNull()); 1193 ASSERT(!super_type.IsNull());
1179 result.set_super_type(super_type); 1194 result.set_super_type(super_type);
1180 result.set_signature_function(signature_function); 1195 result.set_signature_function(signature_function);
1181 result.set_type_parameters(type_parameters); 1196 result.set_type_parameters(type_parameters);
1182 result.set_type_parameter_extends(type_parameter_extends); 1197 result.set_type_parameter_extends(type_parameter_extends);
1183 result.SetFields(Array::Handle(Array::Empty())); 1198 result.SetFields(Array::Handle(Array::Empty()));
1184 result.SetFunctions(Array::Handle(Array::Empty())); 1199 result.SetFunctions(Array::Handle(Array::Empty()));
1185 // Implements interface "Function". 1200 // Implements interface "Function".
1186 const Type& function_interface = Type::Handle(Type::FunctionInterface()); 1201 const Type& function_interface = Type::Handle(Type::FunctionInterface());
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 } 1284 }
1270 return Class::null(); 1285 return Class::null();
1271 } 1286 }
1272 1287
1273 1288
1274 RawClass* Class::NewNativeWrapper(Library* library, 1289 RawClass* Class::NewNativeWrapper(Library* library,
1275 const String& name, 1290 const String& name,
1276 int field_count) { 1291 int field_count) {
1277 Class& cls = Class::Handle(library->LookupClass(name)); 1292 Class& cls = Class::Handle(library->LookupClass(name));
1278 if (cls.IsNull()) { 1293 if (cls.IsNull()) {
1279 cls = New<Instance>(name, Script::Handle()); 1294 cls = New<Instance>(name, Script::Handle(), Scanner::kDummyTokenIndex);
1280 cls.SetFields(Array::Handle(Array::Empty())); 1295 cls.SetFields(Array::Handle(Array::Empty()));
1281 cls.SetFunctions(Array::Handle(Array::Empty())); 1296 cls.SetFunctions(Array::Handle(Array::Empty()));
1282 // Set super class to Object. 1297 // Set super class to Object.
1283 cls.set_super_type(Type::Handle(Type::ObjectType())); 1298 cls.set_super_type(Type::Handle(Type::ObjectType()));
1284 // Compute instance size. 1299 // Compute instance size.
1285 intptr_t instance_size = (field_count * kWordSize) + sizeof(RawObject); 1300 intptr_t instance_size = (field_count * kWordSize) + sizeof(RawObject);
1286 cls.set_instance_size(RoundedAllocationSize(instance_size)); 1301 cls.set_instance_size(RoundedAllocationSize(instance_size));
1287 cls.set_next_field_offset(instance_size); 1302 cls.set_next_field_offset(instance_size);
1288 cls.set_num_native_fields(field_count); 1303 cls.set_num_native_fields(field_count);
1289 cls.set_is_finalized(); 1304 cls.set_is_finalized();
1290 library->AddClass(cls); 1305 library->AddClass(cls);
1291 return cls.raw(); 1306 return cls.raw();
1292 } else { 1307 } else {
1293 return Class::null(); 1308 return Class::null();
1294 } 1309 }
1295 } 1310 }
1296 1311
1297 1312
1298 void Class::set_name(const String& value) const { 1313 void Class::set_name(const String& value) const {
1299 ASSERT(value.IsSymbol()); 1314 ASSERT(value.IsSymbol());
1300 StorePointer(&raw_ptr()->name_, value.raw()); 1315 StorePointer(&raw_ptr()->name_, value.raw());
1301 } 1316 }
1302 1317
1303 1318
1304 void Class::set_script(const Script& value) const { 1319 void Class::set_script(const Script& value) const {
1305 StorePointer(&raw_ptr()->script_, value.raw()); 1320 StorePointer(&raw_ptr()->script_, value.raw());
1306 } 1321 }
1307 1322
1308 1323
1324 void Class::set_token_index(intptr_t token_index) const {
1325 ASSERT(token_index >= 0);
1326 raw_ptr()->token_index_ = token_index;
1327 }
1328
1329
1309 void Class::set_is_interface() const { 1330 void Class::set_is_interface() const {
1310 raw_ptr()->is_interface_ = true; 1331 raw_ptr()->is_interface_ = true;
1311 } 1332 }
1312 1333
1313 1334
1314 void Class::set_is_const() const { 1335 void Class::set_is_const() const {
1315 raw_ptr()->is_const_ = true; 1336 raw_ptr()->is_const_ = true;
1316 } 1337 }
1317 1338
1318 1339
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
1749 const Array& new_canonical_list = 1770 const Array& new_canonical_list =
1750 Array::Handle(Array::Grow(canonical_list, new_length, Heap::kOld)); 1771 Array::Handle(Array::Grow(canonical_list, new_length, Heap::kOld));
1751 set_constants(new_canonical_list); 1772 set_constants(new_canonical_list);
1752 new_canonical_list.SetAt(index, constant); 1773 new_canonical_list.SetAt(index, constant);
1753 } else { 1774 } else {
1754 canonical_list.SetAt(index, constant); 1775 canonical_list.SetAt(index, constant);
1755 } 1776 }
1756 } 1777 }
1757 1778
1758 1779
1759 RawUnresolvedClass* UnresolvedClass::New(intptr_t token_index, 1780 RawUnresolvedClass* UnresolvedClass::New(const LibraryPrefix& library_prefix,
1760 const LibraryPrefix& library_prefix, 1781 const String& ident,
1761 const String& ident) { 1782 intptr_t token_index) {
1762 const UnresolvedClass& type = UnresolvedClass::Handle(UnresolvedClass::New()); 1783 const UnresolvedClass& type = UnresolvedClass::Handle(UnresolvedClass::New());
1763 type.set_token_index(token_index);
1764 type.set_library_prefix(library_prefix); 1784 type.set_library_prefix(library_prefix);
1765 type.set_ident(ident); 1785 type.set_ident(ident);
1786 type.set_token_index(token_index);
1766 return type.raw(); 1787 return type.raw();
1767 } 1788 }
1768 1789
1769 1790
1770 RawUnresolvedClass* UnresolvedClass::New() { 1791 RawUnresolvedClass* UnresolvedClass::New() {
1771 const Class& unresolved_class_class = 1792 const Class& unresolved_class_class =
1772 Class::Handle(Object::unresolved_class_class()); 1793 Class::Handle(Object::unresolved_class_class());
1773 RawObject* raw = Object::Allocate(unresolved_class_class, 1794 RawObject* raw = Object::Allocate(unresolved_class_class,
1774 UnresolvedClass::InstanceSize(), 1795 UnresolvedClass::InstanceSize(),
1775 Heap::kNew); 1796 Heap::kNew);
1776 return reinterpret_cast<RawUnresolvedClass*>(raw); 1797 return reinterpret_cast<RawUnresolvedClass*>(raw);
1777 } 1798 }
1778 1799
1779 1800
1780 void UnresolvedClass::set_token_index(intptr_t token_index) const { 1801 void UnresolvedClass::set_token_index(intptr_t token_index) const {
1802 ASSERT(token_index >= 0);
1781 raw_ptr()->token_index_ = token_index; 1803 raw_ptr()->token_index_ = token_index;
1782 } 1804 }
1783 1805
1784 1806
1785 void UnresolvedClass::set_ident(const String& ident) const { 1807 void UnresolvedClass::set_ident(const String& ident) const {
1786 StorePointer(&raw_ptr()->ident_, ident.raw()); 1808 StorePointer(&raw_ptr()->ident_, ident.raw());
1787 } 1809 }
1788 1810
1789 1811
1790 void UnresolvedClass::set_library_prefix( 1812 void UnresolvedClass::set_library_prefix(
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1848 } 1870 }
1849 1871
1850 1872
1851 RawAbstractTypeArguments* AbstractType::arguments() const { 1873 RawAbstractTypeArguments* AbstractType::arguments() const {
1852 // AbstractType is an abstract class. 1874 // AbstractType is an abstract class.
1853 UNREACHABLE(); 1875 UNREACHABLE();
1854 return NULL; 1876 return NULL;
1855 } 1877 }
1856 1878
1857 1879
1880 intptr_t AbstractType::token_index() const {
1881 // AbstractType is an abstract class.
1882 UNREACHABLE();
1883 return -1;
1884 }
1885
1886
1858 bool AbstractType::IsInstantiated() const { 1887 bool AbstractType::IsInstantiated() const {
1859 // AbstractType is an abstract class. 1888 // AbstractType is an abstract class.
1860 UNREACHABLE(); 1889 UNREACHABLE();
1861 return false; 1890 return false;
1862 } 1891 }
1863 1892
1864 1893
1865 bool AbstractType::IsFinalized() const { 1894 bool AbstractType::IsFinalized() const {
1866 // AbstractType is an abstract class. 1895 // AbstractType is an abstract class.
1867 UNREACHABLE(); 1896 UNREACHABLE();
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
2064 AbstractTypeArguments::Handle(other.arguments())); 2093 AbstractTypeArguments::Handle(other.arguments()));
2065 } else { 2094 } else {
2066 ASSERT(test == kIsAssignableTo); 2095 ASSERT(test == kIsAssignableTo);
2067 return cls.IsAssignableTo(AbstractTypeArguments::Handle(arguments()), 2096 return cls.IsAssignableTo(AbstractTypeArguments::Handle(arguments()),
2068 Class::Handle(other.type_class()), 2097 Class::Handle(other.type_class()),
2069 AbstractTypeArguments::Handle(other.arguments())); 2098 AbstractTypeArguments::Handle(other.arguments()));
2070 } 2099 }
2071 } 2100 }
2072 2101
2073 RawAbstractType* AbstractType::NewTypeParameter( 2102 RawAbstractType* AbstractType::NewTypeParameter(
2074 intptr_t index, const String& name) { 2103 intptr_t index, const String& name, intptr_t token_index) {
2075 return TypeParameter::New(index, name); 2104 return TypeParameter::New(index, name, token_index);
2076 } 2105 }
2077 2106
2078 2107
2079 RawAbstractType* AbstractType::NewInstantiatedType( 2108 RawAbstractType* AbstractType::NewInstantiatedType(
2080 const AbstractType& uninstantiated_type, 2109 const AbstractType& uninstantiated_type,
2081 const AbstractTypeArguments& instantiator_type_arguments) { 2110 const AbstractTypeArguments& instantiator_type_arguments) {
2082 return InstantiatedType::New(uninstantiated_type, 2111 return InstantiatedType::New(uninstantiated_type,
2083 instantiator_type_arguments); 2112 instantiator_type_arguments);
2084 } 2113 }
2085 2114
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2139 RawType* Type::FunctionInterface() { 2168 RawType* Type::FunctionInterface() {
2140 return Isolate::Current()->object_store()->function_interface(); 2169 return Isolate::Current()->object_store()->function_interface();
2141 } 2170 }
2142 2171
2143 2172
2144 RawType* Type::ListInterface() { 2173 RawType* Type::ListInterface() {
2145 return Isolate::Current()->object_store()->list_interface(); 2174 return Isolate::Current()->object_store()->list_interface();
2146 } 2175 }
2147 2176
2148 2177
2149 RawType* Type::NewRawType(const Class& type_class) { 2178 RawType* Type::NewRawType(const Class& type_class, intptr_t token_index) {
2150 const AbstractTypeArguments& type_arguments = 2179 const AbstractTypeArguments& type_arguments =
2151 AbstractTypeArguments::Handle(type_class.type_parameter_extends()); 2180 AbstractTypeArguments::Handle(type_class.type_parameter_extends());
2152 return New(Object::Handle(type_class.raw()), type_arguments); 2181 return New(Object::Handle(type_class.raw()), type_arguments, token_index);
2153 } 2182 }
2154 2183
2155 2184
2156 RawType* Type::NewNonParameterizedType( 2185 RawType* Type::NewNonParameterizedType(
2157 const Class& type_class) { 2186 const Class& type_class) {
2158 ASSERT(!type_class.HasTypeArguments()); 2187 ASSERT(!type_class.HasTypeArguments());
2159 const TypeArguments& no_type_arguments = TypeArguments::Handle(); 2188 const TypeArguments& no_type_arguments = TypeArguments::Handle();
2160 Type& type = Type::Handle(); 2189 Type& type = Type::Handle();
2161 type ^= Type::New( 2190 type ^= Type::New(Object::Handle(type_class.raw()),
2162 Object::Handle(type_class.raw()), no_type_arguments); 2191 no_type_arguments,
2192 Scanner::kDummyTokenIndex);
2163 type.set_is_finalized(); 2193 type.set_is_finalized();
2164 type ^= type.Canonicalize(); 2194 type ^= type.Canonicalize();
2165 return type.raw(); 2195 return type.raw();
2166 } 2196 }
2167 2197
2168 2198
2169 void Type::set_is_finalized() const { 2199 void Type::set_is_finalized() const {
2170 ASSERT(!IsFinalized()); 2200 ASSERT(!IsFinalized());
2171 set_type_state(RawType::kFinalized); 2201 set_type_state(RawType::kFinalized);
2172 } 2202 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2228 2258
2229 RawAbstractType* Type::InstantiateFrom( 2259 RawAbstractType* Type::InstantiateFrom(
2230 const AbstractTypeArguments& instantiator_type_arguments) const { 2260 const AbstractTypeArguments& instantiator_type_arguments) const {
2231 ASSERT(IsFinalized()); 2261 ASSERT(IsFinalized());
2232 ASSERT(!IsInstantiated()); 2262 ASSERT(!IsInstantiated());
2233 AbstractTypeArguments& type_arguments = 2263 AbstractTypeArguments& type_arguments =
2234 AbstractTypeArguments::Handle(arguments()); 2264 AbstractTypeArguments::Handle(arguments());
2235 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments); 2265 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments);
2236 const Class& cls = Class::Handle(type_class()); 2266 const Class& cls = Class::Handle(type_class());
2237 ASSERT(cls.is_finalized()); 2267 ASSERT(cls.is_finalized());
2238 Type& instantiated_type = Type::Handle(Type::New(cls, type_arguments)); 2268 Type& instantiated_type = Type::Handle(
2269 Type::New(cls, type_arguments, token_index()));
2239 ASSERT(type_arguments.IsNull() || 2270 ASSERT(type_arguments.IsNull() ||
2240 (type_arguments.Length() == cls.NumTypeArguments())); 2271 (type_arguments.Length() == cls.NumTypeArguments()));
2241 instantiated_type.set_is_finalized(); 2272 instantiated_type.set_is_finalized();
2242 return instantiated_type.raw(); 2273 return instantiated_type.raw();
2243 } 2274 }
2244 2275
2245 2276
2246 bool Type::Equals(const AbstractType& other) const { 2277 bool Type::Equals(const AbstractType& other) const {
2247 ASSERT(IsFinalized() && other.IsFinalized()); 2278 ASSERT(IsFinalized() && other.IsFinalized());
2248 if (raw() == other.raw()) { 2279 if (raw() == other.raw()) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
2324 RawType* Type::New() { 2355 RawType* Type::New() {
2325 const Class& type_class = Class::Handle(Object::type_class()); 2356 const Class& type_class = Class::Handle(Object::type_class());
2326 RawObject* raw = Object::Allocate(type_class, 2357 RawObject* raw = Object::Allocate(type_class,
2327 Type::InstanceSize(), 2358 Type::InstanceSize(),
2328 Heap::kOld); 2359 Heap::kOld);
2329 return reinterpret_cast<RawType*>(raw); 2360 return reinterpret_cast<RawType*>(raw);
2330 } 2361 }
2331 2362
2332 2363
2333 RawType* Type::New(const Object& clazz, 2364 RawType* Type::New(const Object& clazz,
2334 const AbstractTypeArguments& arguments) { 2365 const AbstractTypeArguments& arguments,
2366 intptr_t token_index) {
2335 const Type& result = Type::Handle(Type::New()); 2367 const Type& result = Type::Handle(Type::New());
2336 result.set_type_class(clazz); 2368 result.set_type_class(clazz);
2337 result.set_arguments(arguments); 2369 result.set_arguments(arguments);
2370 result.set_token_index(token_index);
2338 result.raw_ptr()->type_state_ = RawType::kAllocated; 2371 result.raw_ptr()->type_state_ = RawType::kAllocated;
2339 return result.raw(); 2372 return result.raw();
2340 } 2373 }
2341 2374
2342 2375
2376 void Type::set_token_index(intptr_t token_index) const {
2377 ASSERT(token_index >= 0);
2378 raw_ptr()->token_index_ = token_index;
2379 }
2380
2381
2343 void Type::set_type_state(int8_t state) const { 2382 void Type::set_type_state(int8_t state) const {
2344 ASSERT(state == RawType::kAllocated || 2383 ASSERT(state == RawType::kAllocated ||
2345 state == RawType::kBeingFinalized || 2384 state == RawType::kBeingFinalized ||
2346 state == RawType::kFinalized); 2385 state == RawType::kFinalized);
2347 raw_ptr()->type_state_ = state; 2386 raw_ptr()->type_state_ = state;
2348 } 2387 }
2349 2388
2350 2389
2351 const char* Type::ToCString() const { 2390 const char* Type::ToCString() const {
2352 if (IsResolved()) { 2391 if (IsResolved()) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2423 RawTypeParameter* TypeParameter::New() { 2462 RawTypeParameter* TypeParameter::New() {
2424 const Class& type_parameter_class = 2463 const Class& type_parameter_class =
2425 Class::Handle(Object::type_parameter_class()); 2464 Class::Handle(Object::type_parameter_class());
2426 RawObject* raw = Object::Allocate(type_parameter_class, 2465 RawObject* raw = Object::Allocate(type_parameter_class,
2427 TypeParameter::InstanceSize(), 2466 TypeParameter::InstanceSize(),
2428 Heap::kOld); 2467 Heap::kOld);
2429 return reinterpret_cast<RawTypeParameter*>(raw); 2468 return reinterpret_cast<RawTypeParameter*>(raw);
2430 } 2469 }
2431 2470
2432 2471
2433 RawTypeParameter* TypeParameter::New(intptr_t index, const String& name) { 2472 RawTypeParameter* TypeParameter::New(
2473 intptr_t index, const String& name, intptr_t token_index) {
2434 const TypeParameter& result = TypeParameter::Handle(TypeParameter::New()); 2474 const TypeParameter& result = TypeParameter::Handle(TypeParameter::New());
2435 result.set_index(index); 2475 result.set_index(index);
2436 result.set_name(name); 2476 result.set_name(name);
2477 result.set_token_index(token_index);
2437 result.raw_ptr()->type_state_ = RawTypeParameter::kAllocated; 2478 result.raw_ptr()->type_state_ = RawTypeParameter::kAllocated;
2438 return result.raw(); 2479 return result.raw();
2439 } 2480 }
2440 2481
2441 2482
2483 void TypeParameter::set_token_index(intptr_t token_index) const {
2484 ASSERT(token_index >= 0);
2485 raw_ptr()->token_index_ = token_index;
2486 }
2487
2488
2442 void TypeParameter::set_type_state(int8_t state) const { 2489 void TypeParameter::set_type_state(int8_t state) const {
2443 ASSERT(state == RawTypeParameter::kAllocated || 2490 ASSERT(state == RawTypeParameter::kAllocated ||
2444 state == RawTypeParameter::kBeingFinalized || 2491 state == RawTypeParameter::kBeingFinalized ||
2445 state == RawTypeParameter::kFinalized); 2492 state == RawTypeParameter::kFinalized);
2446 raw_ptr()->type_state_ = state; 2493 raw_ptr()->type_state_ = state;
2447 } 2494 }
2448 2495
2449 2496
2450 const char* TypeParameter::ToCString() const { 2497 const char* TypeParameter::ToCString() const {
2451 const char* format = "TypeParameter: name %s; index: %d"; 2498 const char* format = "TypeParameter: name %s; index: %d";
(...skipping 12 matching lines...) Expand all
2464 2511
2465 2512
2466 RawAbstractTypeArguments* InstantiatedType::arguments() const { 2513 RawAbstractTypeArguments* InstantiatedType::arguments() const {
2467 return InstantiatedTypeArguments::New( 2514 return InstantiatedTypeArguments::New(
2468 AbstractTypeArguments::Handle(AbstractType::Handle( 2515 AbstractTypeArguments::Handle(AbstractType::Handle(
2469 uninstantiated_type()).arguments()), 2516 uninstantiated_type()).arguments()),
2470 AbstractTypeArguments::Handle(instantiator_type_arguments())); 2517 AbstractTypeArguments::Handle(instantiator_type_arguments()));
2471 } 2518 }
2472 2519
2473 2520
2521 intptr_t InstantiatedType::token_index() const {
2522 return AbstractType::Handle(uninstantiated_type()).token_index();
2523 }
2524
2525
2474 void InstantiatedType::set_uninstantiated_type( 2526 void InstantiatedType::set_uninstantiated_type(
2475 const AbstractType& value) const { 2527 const AbstractType& value) const {
2476 StorePointer(&raw_ptr()->uninstantiated_type_, value.raw()); 2528 StorePointer(&raw_ptr()->uninstantiated_type_, value.raw());
2477 } 2529 }
2478 2530
2479 2531
2480 void InstantiatedType::set_instantiator_type_arguments( 2532 void InstantiatedType::set_instantiator_type_arguments(
2481 const AbstractTypeArguments& value) const { 2533 const AbstractTypeArguments& value) const {
2482 StorePointer(&raw_ptr()->instantiator_type_arguments_, value.raw()); 2534 StorePointer(&raw_ptr()->instantiator_type_arguments_, value.raw());
2483 } 2535 }
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after
3399 const Script& script = Script::Handle(owner_class.script()); 3451 const Script& script = Script::Handle(owner_class.script());
3400 signature_class = Class::NewSignatureClass(signature, 3452 signature_class = Class::NewSignatureClass(signature,
3401 closure_function, 3453 closure_function,
3402 script); 3454 script);
3403 library.AddClass(signature_class); 3455 library.AddClass(signature_class);
3404 } else { 3456 } else {
3405 closure_function.set_signature_class(signature_class); 3457 closure_function.set_signature_class(signature_class);
3406 } 3458 }
3407 const Type& signature_type = Type::Handle(signature_class.SignatureType()); 3459 const Type& signature_type = Type::Handle(signature_class.SignatureType());
3408 if (!signature_type.IsFinalized()) { 3460 if (!signature_type.IsFinalized()) {
3409 Error& error = Error::Handle(); 3461 ClassFinalizer::FinalizeType(signature_class, signature_type);
3410 ClassFinalizer::FinalizeAndCanonicalizeType(signature_class,
3411 signature_type,
3412 &error);
3413 ASSERT(error.IsNull());
3414 } 3462 }
3415 ASSERT(closure_function.signature_class() == signature_class.raw()); 3463 ASSERT(closure_function.signature_class() == signature_class.raw());
3416 set_implicit_closure_function(closure_function); 3464 set_implicit_closure_function(closure_function);
3417 ASSERT(closure_function.IsImplicitClosureFunction()); 3465 ASSERT(closure_function.IsImplicitClosureFunction());
3418 return closure_function.raw(); 3466 return closure_function.raw();
3419 } 3467 }
3420 3468
3421 3469
3422 template<typename T> 3470 template<typename T>
3423 static RawArray* NewArray(const GrowableArray<T*>& objs) { 3471 static RawArray* NewArray(const GrowableArray<T*>& objs) {
(...skipping 2086 matching lines...) Expand 10 before | Expand all | Expand 10 after
5510 5558
5511 RawType* Instance::GetType() const { 5559 RawType* Instance::GetType() const {
5512 if (IsNull()) { 5560 if (IsNull()) {
5513 return Type::NullType(); 5561 return Type::NullType();
5514 } 5562 }
5515 const Class& cls = Class::Handle(clazz()); 5563 const Class& cls = Class::Handle(clazz());
5516 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); 5564 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle();
5517 if (cls.HasTypeArguments()) { 5565 if (cls.HasTypeArguments()) {
5518 type_arguments = GetTypeArguments(); 5566 type_arguments = GetTypeArguments();
5519 } 5567 }
5520 const Type& type = Type::Handle(Type::New(cls, type_arguments)); 5568 const Type& type = Type::Handle(
5569 Type::New(cls, type_arguments, Scanner::kDummyTokenIndex));
5521 type.set_is_finalized(); 5570 type.set_is_finalized();
5522 return type.raw(); 5571 return type.raw();
5523 } 5572 }
5524 5573
5525 5574
5526 RawAbstractTypeArguments* Instance::GetTypeArguments() const { 5575 RawAbstractTypeArguments* Instance::GetTypeArguments() const {
5527 const Class& cls = Class::Handle(clazz()); 5576 const Class& cls = Class::Handle(clazz());
5528 intptr_t field_offset = cls.type_arguments_instance_field_offset(); 5577 intptr_t field_offset = cls.type_arguments_instance_field_offset();
5529 ASSERT(field_offset != Class::kNoTypeArguments); 5578 ASSERT(field_offset != Class::kNoTypeArguments);
5530 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); 5579 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle();
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
5651 // Can occur when running disassembler. 5700 // Can occur when running disassembler.
5652 return "Instance"; 5701 return "Instance";
5653 } else { 5702 } else {
5654 const char* kFormat = "Instance of '%s'"; 5703 const char* kFormat = "Instance of '%s'";
5655 Class& cls = Class::Handle(clazz()); 5704 Class& cls = Class::Handle(clazz());
5656 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); 5705 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle();
5657 const intptr_t num_type_arguments = cls.NumTypeArguments(); 5706 const intptr_t num_type_arguments = cls.NumTypeArguments();
5658 if (num_type_arguments > 0) { 5707 if (num_type_arguments > 0) {
5659 type_arguments = GetTypeArguments(); 5708 type_arguments = GetTypeArguments();
5660 } 5709 }
5661 const Type& type = Type::Handle(Type::New(cls, type_arguments)); 5710 const Type& type =
5711 Type::Handle(Type::New(cls, type_arguments, Scanner::kDummyTokenIndex));
5662 const String& type_name = String::Handle(type.Name()); 5712 const String& type_name = String::Handle(type.Name());
5663 // Calculate the size of the string. 5713 // Calculate the size of the string.
5664 intptr_t len = OS::SNPrint(NULL, 0, kFormat, type_name.ToCString()) + 1; 5714 intptr_t len = OS::SNPrint(NULL, 0, kFormat, type_name.ToCString()) + 1;
5665 char* chars = reinterpret_cast<char*>( 5715 char* chars = reinterpret_cast<char*>(
5666 Isolate::Current()->current_zone()->Allocate(len)); 5716 Isolate::Current()->current_zone()->Allocate(len));
5667 OS::SNPrint(chars, len, kFormat, type_name.ToCString()); 5717 OS::SNPrint(chars, len, kFormat, type_name.ToCString());
5668 return chars; 5718 return chars;
5669 } 5719 }
5670 } 5720 }
5671 5721
(...skipping 2264 matching lines...) Expand 10 before | Expand all | Expand 10 after
7936 const String& str = String::Handle(pattern()); 7986 const String& str = String::Handle(pattern());
7937 const char* format = "JSRegExp: pattern=%s flags=%s"; 7987 const char* format = "JSRegExp: pattern=%s flags=%s";
7938 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 7988 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
7939 char* chars = reinterpret_cast<char*>( 7989 char* chars = reinterpret_cast<char*>(
7940 Isolate::Current()->current_zone()->Allocate(len + 1)); 7990 Isolate::Current()->current_zone()->Allocate(len + 1));
7941 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 7991 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
7942 return chars; 7992 return chars;
7943 } 7993 }
7944 7994
7945 } // namespace dart 7995 } // 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