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

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

Issue 10800002: Hide names of internal classes from the user by mapping them to the documented (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 5 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 "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 16 matching lines...) Expand all
27 #include "vm/runtime_entry.h" 27 #include "vm/runtime_entry.h"
28 #include "vm/scopes.h" 28 #include "vm/scopes.h"
29 #include "vm/stack_frame.h" 29 #include "vm/stack_frame.h"
30 #include "vm/timer.h" 30 #include "vm/timer.h"
31 #include "vm/unicode.h" 31 #include "vm/unicode.h"
32 32
33 namespace dart { 33 namespace dart {
34 34
35 DEFINE_FLAG(bool, generate_gdb_symbols, false, 35 DEFINE_FLAG(bool, generate_gdb_symbols, false,
36 "Generate symbols of generated dart functions for debugging with GDB"); 36 "Generate symbols of generated dart functions for debugging with GDB");
37 DEFINE_FLAG(bool, show_internal_names, false,
38 "Show names of internal classes (e.g. \"OneByteString\") in error messages "
39 "instead of showing the corresponding interface names (e.g. \"String\")");
37 DECLARE_FLAG(bool, trace_compiler); 40 DECLARE_FLAG(bool, trace_compiler);
38 DECLARE_FLAG(bool, enable_type_checks); 41 DECLARE_FLAG(bool, enable_type_checks);
39 42
40 static const char* kGetterPrefix = "get:"; 43 static const char* kGetterPrefix = "get:";
41 static const intptr_t kGetterPrefixLength = strlen(kGetterPrefix); 44 static const intptr_t kGetterPrefixLength = strlen(kGetterPrefix);
42 static const char* kSetterPrefix = "set:"; 45 static const char* kSetterPrefix = "set:";
43 static const intptr_t kSetterPrefixLength = strlen(kSetterPrefix); 46 static const intptr_t kSetterPrefixLength = strlen(kSetterPrefix);
44 47
45 cpp_vtable Object::handle_vtable_ = 0; 48 cpp_vtable Object::handle_vtable_ = 0;
46 cpp_vtable Object::builtin_vtables_[kNumPredefinedKinds] = { 0 }; 49 cpp_vtable Object::builtin_vtables_[kNumPredefinedKinds] = { 0 };
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 object_store->set_pending_classes(pending_classes); 521 object_store->set_pending_classes(pending_classes);
519 522
520 Context& context = Context::Handle(Context::New(0, Heap::kOld)); 523 Context& context = Context::Handle(Context::New(0, Heap::kOld));
521 object_store->set_empty_context(context); 524 object_store->set_empty_context(context);
522 525
523 // Now that the symbol table is initialized and that the core dictionary as 526 // Now that the symbol table is initialized and that the core dictionary as
524 // well as the core implementation dictionary have been setup, preallocate 527 // well as the core implementation dictionary have been setup, preallocate
525 // remaining classes and register them by name in the dictionaries. 528 // remaining classes and register them by name in the dictionaries.
526 const Script& impl_script = Script::Handle(Bootstrap::LoadImplScript()); 529 const Script& impl_script = Script::Handle(Bootstrap::LoadImplScript());
527 530
531 cls = Class::New<Integer>();
532 object_store->set_integer_implementation_class(cls);
533 RegisterClass(cls, "IntegerImplementation", impl_script, core_impl_lib);
534 pending_classes.Add(cls, Heap::kOld);
535
528 cls = Class::New<Smi>(); 536 cls = Class::New<Smi>();
529 object_store->set_smi_class(cls); 537 object_store->set_smi_class(cls);
530 RegisterClass(cls, "Smi", impl_script, core_impl_lib); 538 RegisterClass(cls, "Smi", impl_script, core_impl_lib);
531 pending_classes.Add(cls, Heap::kOld); 539 pending_classes.Add(cls, Heap::kOld);
532 540
533 cls = Class::New<Mint>(); 541 cls = Class::New<Mint>();
534 object_store->set_mint_class(cls); 542 object_store->set_mint_class(cls);
535 RegisterClass(cls, "Mint", impl_script, core_impl_lib); 543 RegisterClass(cls, "Mint", impl_script, core_impl_lib);
536 pending_classes.Add(cls, Heap::kOld); 544 pending_classes.Add(cls, Heap::kOld);
537 545
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 909
902 cls = Class::New<ExternalUint64Array>(); 910 cls = Class::New<ExternalUint64Array>();
903 object_store->set_external_uint64_array_class(cls); 911 object_store->set_external_uint64_array_class(cls);
904 912
905 cls = Class::New<ExternalFloat32Array>(); 913 cls = Class::New<ExternalFloat32Array>();
906 object_store->set_external_float32_array_class(cls); 914 object_store->set_external_float32_array_class(cls);
907 915
908 cls = Class::New<ExternalFloat64Array>(); 916 cls = Class::New<ExternalFloat64Array>();
909 object_store->set_external_float64_array_class(cls); 917 object_store->set_external_float64_array_class(cls);
910 918
919 cls = Class::New<Integer>();
920 object_store->set_integer_implementation_class(cls);
921
911 cls = Class::New<Smi>(); 922 cls = Class::New<Smi>();
912 object_store->set_smi_class(cls); 923 object_store->set_smi_class(cls);
913 924
914 cls = Class::New<Mint>(); 925 cls = Class::New<Mint>();
915 object_store->set_mint_class(cls); 926 object_store->set_mint_class(cls);
916 927
917 cls = Class::New<Double>(); 928 cls = Class::New<Double>();
918 object_store->set_double_class(cls); 929 object_store->set_double_class(cls);
919 930
920 cls = Class::New<Bigint>(); 931 cls = Class::New<Bigint>();
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 RawString* Class::Name() const { 1050 RawString* Class::Name() const {
1040 if (raw_ptr()->name_ != String::null()) { 1051 if (raw_ptr()->name_ != String::null()) {
1041 return raw_ptr()->name_; 1052 return raw_ptr()->name_;
1042 } 1053 }
1043 ASSERT(class_class() != Class::null()); // class_class_ should be set up. 1054 ASSERT(class_class() != Class::null()); // class_class_ should be set up.
1044 intptr_t index = GetSingletonClassIndex(raw()); 1055 intptr_t index = GetSingletonClassIndex(raw());
1045 return String::NewSymbol(GetSingletonClassName(index)); 1056 return String::NewSymbol(GetSingletonClassName(index));
1046 } 1057 }
1047 1058
1048 1059
1060 RawString* Class::UserVisibleName() const {
srdjan 2012/07/18 21:25:29 Maybe simpler: if (FLAG_show_internal_names) retur
regis 2012/07/18 21:40:11 Done.
1061 if (!FLAG_show_internal_names) {
1062 switch (id()) {
1063 case kInteger:
1064 case kSmi:
1065 case kMint:
1066 case kBigint:
1067 return String::NewSymbol("int");
1068 case kDouble:
1069 return String::NewSymbol("double");
1070 case kOneByteString:
1071 case kTwoByteString:
1072 case kFourByteString:
1073 case kExternalOneByteString:
1074 case kExternalTwoByteString:
1075 case kExternalFourByteString:
1076 return String::NewSymbol("String");
1077 case kBool:
1078 return String::NewSymbol("bool");
1079 case kArray:
1080 case kImmutableArray:
1081 case kGrowableObjectArray:
1082 return String::NewSymbol("List");
1083 case kInt8Array:
1084 case kExternalInt8Array:
1085 return String::NewSymbol("Int8List");
1086 case kUint8Array:
1087 case kExternalUint8Array:
1088 return String::NewSymbol("Uint8List");
1089 case kInt16Array:
1090 case kExternalInt16Array:
1091 return String::NewSymbol("Int16List");
1092 case kUint16Array:
1093 case kExternalUint16Array:
1094 return String::NewSymbol("Uint16List");
1095 case kInt32Array:
1096 case kExternalInt32Array:
1097 return String::NewSymbol("Int32List");
1098 case kUint32Array:
1099 case kExternalUint32Array:
1100 return String::NewSymbol("Uint32List");
1101 case kInt64Array:
1102 case kExternalInt64Array:
1103 return String::NewSymbol("Int64List");
1104 case kUint64Array:
1105 case kExternalUint64Array:
1106 return String::NewSymbol("Uint64List");
1107 case kFloat32Array:
1108 case kExternalFloat32Array:
1109 return String::NewSymbol("Float32List");
1110 case kFloat64Array:
1111 case kExternalFloat64Array:
1112 return String::NewSymbol("Float64List");
1113 default: break;
1114 }
1115 }
1116 return Name();
1117 }
1118
1119
1049 RawType* Class::SignatureType() const { 1120 RawType* Class::SignatureType() const {
1050 ASSERT(IsSignatureClass()); 1121 ASSERT(IsSignatureClass());
1051 const Function& function = Function::Handle(signature_function()); 1122 const Function& function = Function::Handle(signature_function());
1052 ASSERT(!function.IsNull()); 1123 ASSERT(!function.IsNull());
1053 if (function.signature_class() != raw()) { 1124 if (function.signature_class() != raw()) {
1054 // This class is a function type alias. Return the canonical signature type. 1125 // This class is a function type alias. Return the canonical signature type.
1055 const Class& canonical_class = Class::Handle(function.signature_class()); 1126 const Class& canonical_class = Class::Handle(function.signature_class());
1056 return canonical_class.SignatureType(); 1127 return canonical_class.SignatureType();
1057 } 1128 }
1058 // Return the first canonical signature type if already computed. 1129 // Return the first canonical signature type if already computed.
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1320 intptr_t token_pos) const { 1391 intptr_t token_pos) const {
1321 ASSERT(!type_name.IsNull()); 1392 ASSERT(!type_name.IsNull());
1322 const TypeArguments& type_params = TypeArguments::Handle(type_parameters()); 1393 const TypeArguments& type_params = TypeArguments::Handle(type_parameters());
1323 if (!type_params.IsNull()) { 1394 if (!type_params.IsNull()) {
1324 intptr_t num_type_params = type_params.Length(); 1395 intptr_t num_type_params = type_params.Length();
1325 TypeParameter& type_param = TypeParameter::Handle(); 1396 TypeParameter& type_param = TypeParameter::Handle();
1326 String& type_param_name = String::Handle(); 1397 String& type_param_name = String::Handle();
1327 AbstractType& bound = AbstractType::Handle(); 1398 AbstractType& bound = AbstractType::Handle();
1328 for (intptr_t i = 0; i < num_type_params; i++) { 1399 for (intptr_t i = 0; i < num_type_params; i++) {
1329 type_param ^= type_params.TypeAt(i); 1400 type_param ^= type_params.TypeAt(i);
1330 type_param_name = type_param.Name(); 1401 type_param_name = type_param.name();
1331 if (type_param_name.Equals(type_name)) { 1402 if (type_param_name.Equals(type_name)) {
1332 intptr_t index = type_param.index(); 1403 intptr_t index = type_param.index();
1333 bound = type_param.bound(); 1404 bound = type_param.bound();
1334 // Create a non-finalized new TypeParameter with the given token_pos. 1405 // Create a non-finalized new TypeParameter with the given token_pos.
1335 if (type_param.IsFinalized()) { 1406 if (type_param.IsFinalized()) {
1336 // The index was adjusted during finalization. Revert. 1407 // The index was adjusted during finalization. Revert.
1337 index -= NumTypeArguments() - num_type_params; 1408 index -= NumTypeArguments() - num_type_params;
1338 } else { 1409 } else {
1339 ASSERT(type_param.index() == i); 1410 ASSERT(type_param.index() == i);
1340 } 1411 }
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1529 const Array& new_canonical_types = Array::Handle(Array::New(1, Heap::kOld)); 1600 const Array& new_canonical_types = Array::Handle(Array::New(1, Heap::kOld));
1530 new_canonical_types.SetAt(0, signature_type); 1601 new_canonical_types.SetAt(0, signature_type);
1531 result.set_canonical_types(new_canonical_types); 1602 result.set_canonical_types(new_canonical_types);
1532 return result.raw(); 1603 return result.raw();
1533 } 1604 }
1534 1605
1535 1606
1536 RawClass* Class::GetClass(ObjectKind kind) { 1607 RawClass* Class::GetClass(ObjectKind kind) {
1537 ObjectStore* object_store = Isolate::Current()->object_store(); 1608 ObjectStore* object_store = Isolate::Current()->object_store();
1538 switch (kind) { 1609 switch (kind) {
1610 case kInteger:
1611 ASSERT(object_store->integer_implementation_class() != Class::null());
1612 return object_store->integer_implementation_class();
1539 case kSmi: 1613 case kSmi:
1540 ASSERT(object_store->smi_class() != Class::null()); 1614 ASSERT(object_store->smi_class() != Class::null());
1541 return object_store->smi_class(); 1615 return object_store->smi_class();
1542 case kMint: 1616 case kMint:
1543 ASSERT(object_store->mint_class() != Class::null()); 1617 ASSERT(object_store->mint_class() != Class::null());
1544 return object_store->mint_class(); 1618 return object_store->mint_class();
1545 case kBigint: 1619 case kBigint:
1546 ASSERT(object_store->bigint_class() != Class::null()); 1620 ASSERT(object_store->bigint_class() != Class::null());
1547 return object_store->bigint_class(); 1621 return object_store->bigint_class();
1548 case kDouble: 1622 case kDouble:
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after
2303 } 2377 }
2304 2378
2305 2379
2306 RawAbstractType* AbstractType::Canonicalize() const { 2380 RawAbstractType* AbstractType::Canonicalize() const {
2307 // AbstractType is an abstract class. 2381 // AbstractType is an abstract class.
2308 UNREACHABLE(); 2382 UNREACHABLE();
2309 return NULL; 2383 return NULL;
2310 } 2384 }
2311 2385
2312 2386
2313 // TODO(regis): Investigate if we can safely map internal integer types (Smi, 2387 RawString* AbstractType::BuildName(NameVisibility name_visibility) const {
2314 // Mint, and Bigint) to 'int' and internal String types (OneByteString, etc...) 2388 if (IsTypeParameter()) {
2315 // to 'String' here. It may be too early. Also consider the upcoming type() 2389 return TypeParameter::Cast(*this).name();
2316 // method. 2390 }
2317 RawString* AbstractType::Name() const {
2318 // If the type is still being finalized, we may be reporting an error about 2391 // If the type is still being finalized, we may be reporting an error about
2319 // an illformed type, so proceed with caution. 2392 // a malformed type, so proceed with caution.
2320 const AbstractTypeArguments& args = 2393 const AbstractTypeArguments& args =
2321 AbstractTypeArguments::Handle(arguments()); 2394 AbstractTypeArguments::Handle(arguments());
2322 const intptr_t num_args = args.IsNull() ? 0 : args.Length(); 2395 const intptr_t num_args = args.IsNull() ? 0 : args.Length();
2323 String& class_name = String::Handle(); 2396 String& class_name = String::Handle();
2324 intptr_t first_type_param_index; 2397 intptr_t first_type_param_index;
2325 intptr_t num_type_params; // Number of type parameters to print. 2398 intptr_t num_type_params; // Number of type parameters to print.
2326 if (HasResolvedTypeClass()) { 2399 if (HasResolvedTypeClass()) {
2327 const Class& cls = Class::Handle(type_class()); 2400 const Class& cls = Class::Handle(type_class());
2328 class_name = cls.Name();
2329 num_type_params = cls.NumTypeParameters(); // Do not print the full vector. 2401 num_type_params = cls.NumTypeParameters(); // Do not print the full vector.
2402 if (name_visibility == kInternalName) {
2403 class_name = cls.Name();
2404 } else {
2405 ASSERT(name_visibility == kUserVisibleName);
2406 // Map internal types to their corresponding public interfaces.
2407 class_name = cls.UserVisibleName();
2408 }
2330 if (num_type_params > num_args) { 2409 if (num_type_params > num_args) {
2331 first_type_param_index = 0; 2410 first_type_param_index = 0;
2332 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) { 2411 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) {
2333 // Most probably an illformed type. Do not fill up with "Dynamic", 2412 // Most probably a malformed type. Do not fill up with "Dynamic",
2334 // but use actual vector. 2413 // but use actual vector.
2335 num_type_params = num_args; 2414 num_type_params = num_args;
2336 } else { 2415 } else {
2337 ASSERT(num_args == 0); // Type is raw. 2416 ASSERT(num_args == 0); // Type is raw.
2338 // No need to fill up with "Dynamic". 2417 // No need to fill up with "Dynamic".
2339 num_type_params = 0; 2418 num_type_params = 0;
2340 } 2419 }
2341 } else { 2420 } else {
2342 first_type_param_index = num_args - num_type_params; 2421 first_type_param_index = num_args - num_type_params;
2343 } 2422 }
2344 if (cls.IsSignatureClass()) { 2423 if (cls.IsSignatureClass()) {
2345 // We may be reporting an error about an illformed function type. In that 2424 // We may be reporting an error about a malformed function type. In that
2346 // case, avoid instantiating the signature, since it may lead to cycles. 2425 // case, avoid instantiating the signature, since it may lead to cycles.
2347 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) { 2426 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) {
2348 return class_name.raw(); 2427 return class_name.raw();
2349 } 2428 }
2350 if (num_type_params > 0) { 2429 // In order to avoid cycles, print the name of a typedef (non-canonical
2430 // signature class) as a regular, possibly parameterized, class.
2431 if (cls.IsCanonicalSignatureClass()) {
2351 const Function& signature_function = Function::Handle( 2432 const Function& signature_function = Function::Handle(
2352 cls.signature_function()); 2433 cls.signature_function());
2353 // Signature classes have no super type. 2434 // Signature classes have no super type.
2354 ASSERT(first_type_param_index == 0); 2435 ASSERT(first_type_param_index == 0);
2355 return signature_function.InstantiatedSignatureFrom(args); 2436 return signature_function.InstantiatedSignatureFrom(args,
2437 name_visibility);
2356 } 2438 }
2357 } 2439 }
2358 } else { 2440 } else {
2359 const UnresolvedClass& cls = UnresolvedClass::Handle(unresolved_class()); 2441 const UnresolvedClass& cls = UnresolvedClass::Handle(unresolved_class());
2360 class_name = cls.Name(); 2442 class_name = cls.Name();
2361 num_type_params = num_args; 2443 num_type_params = num_args;
2362 first_type_param_index = 0; 2444 first_type_param_index = 0;
2363 } 2445 }
2364 String& type_name = String::Handle(); 2446 String& type_name = String::Handle();
2365 if (num_type_params == 0) { 2447 if (num_type_params == 0) {
2366 type_name = class_name.raw(); 2448 type_name = class_name.raw();
2367 } else { 2449 } else {
2368 const String& args_name = String::Handle( 2450 const String& args_name = String::Handle(
2369 args.SubvectorName(first_type_param_index, num_type_params)); 2451 args.SubvectorName(first_type_param_index,
2452 num_type_params,
2453 name_visibility));
2370 type_name = String::Concat(class_name, args_name); 2454 type_name = String::Concat(class_name, args_name);
2371 } 2455 }
2372 // The name is only used for type checking and debugging purposes. 2456 // The name is only used for type checking and debugging purposes.
2373 // Unless profiling data shows otherwise, it is not worth caching the name in 2457 // Unless profiling data shows otherwise, it is not worth caching the name in
2374 // the type. 2458 // the type.
2375 return String::NewSymbol(type_name); 2459 return String::NewSymbol(type_name);
2376 } 2460 }
2377 2461
2378 2462
2379 RawString* AbstractType::ClassName() const { 2463 RawString* AbstractType::ClassName() const {
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
2867 const TypeParameter& other_type_param = TypeParameter::Cast(other); 2951 const TypeParameter& other_type_param = TypeParameter::Cast(other);
2868 if (IsFinalized() != other_type_param.IsFinalized()) { 2952 if (IsFinalized() != other_type_param.IsFinalized()) {
2869 return false; 2953 return false;
2870 } 2954 }
2871 if (parameterized_class() != other_type_param.parameterized_class()) { 2955 if (parameterized_class() != other_type_param.parameterized_class()) {
2872 return false; 2956 return false;
2873 } 2957 }
2874 if (index() != other_type_param.index()) { 2958 if (index() != other_type_param.index()) {
2875 return false; 2959 return false;
2876 } 2960 }
2877 const String& name = String::Handle(Name()); 2961 const String& type_param_name = String::Handle(name());
2878 const String& other_type_param_name = String::Handle(other_type_param.Name()); 2962 const String& other_type_param_name = String::Handle(other_type_param.name());
2879 return name.Equals(other_type_param_name); 2963 return type_param_name.Equals(other_type_param_name);
2880 } 2964 }
2881 2965
2882 2966
2883 bool TypeParameter::IsIdentical(const AbstractType& other, 2967 bool TypeParameter::IsIdentical(const AbstractType& other,
2884 bool check_type_parameter_bound) const { 2968 bool check_type_parameter_bound) const {
2885 if (raw() == other.raw()) { 2969 if (raw() == other.raw()) {
2886 return true; 2970 return true;
2887 } 2971 }
2888 if (!other.IsTypeParameter()) { 2972 if (!other.IsTypeParameter()) {
2889 return false; 2973 return false;
2890 } 2974 }
2891 const TypeParameter& other_type_param = TypeParameter::Cast(other); 2975 const TypeParameter& other_type_param = TypeParameter::Cast(other);
2892 // IsIdentical may be called on type parameters belonging to different 2976 // IsIdentical may be called on type parameters belonging to different
2893 // classes, e.g. to an interface and to its default factory class. 2977 // classes, e.g. to an interface and to its default factory class.
2894 // Therefore, both type parameters may have different parameterized classes 2978 // Therefore, both type parameters may have different parameterized classes
2895 // and different indices. Compare the type parameter names only, and their 2979 // and different indices. Compare the type parameter names only, and their
2896 // bounds if requested. 2980 // bounds if requested.
2897 String& name = String::Handle(Name()); 2981 String& type_param_name = String::Handle(name());
2898 String& other_name = String::Handle(other_type_param.Name()); 2982 String& other_type_param_name = String::Handle(other_type_param.name());
2899 if (!name.Equals(other_name)) { 2983 if (!type_param_name.Equals(other_type_param_name)) {
2900 return false; 2984 return false;
2901 } 2985 }
2902 if (check_type_parameter_bound) { 2986 if (check_type_parameter_bound) {
2903 AbstractType& this_bound = AbstractType::Handle(bound()); 2987 AbstractType& this_bound = AbstractType::Handle(bound());
2904 AbstractType& other_bound = AbstractType::Handle(other_type_param.bound()); 2988 AbstractType& other_bound = AbstractType::Handle(other_type_param.bound());
2905 // Bounds are only checked at the top level. 2989 // Bounds are only checked at the top level.
2906 const bool check_type_parameter_bounds = false; 2990 const bool check_type_parameter_bounds = false;
2907 if (!this_bound.IsIdentical(other_bound, check_type_parameter_bounds)) { 2991 if (!this_bound.IsIdentical(other_bound, check_type_parameter_bounds)) {
2908 return false; 2992 return false;
2909 } 2993 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
3030 } 3114 }
3031 3115
3032 3116
3033 bool AbstractTypeArguments::IsUninstantiatedIdentity() const { 3117 bool AbstractTypeArguments::IsUninstantiatedIdentity() const {
3034 // AbstractTypeArguments is an abstract class. 3118 // AbstractTypeArguments is an abstract class.
3035 UNREACHABLE(); 3119 UNREACHABLE();
3036 return false; 3120 return false;
3037 } 3121 }
3038 3122
3039 3123
3040 RawString* AbstractTypeArguments::SubvectorName(intptr_t from_index, 3124 RawString* AbstractTypeArguments::SubvectorName(
3041 intptr_t len) const { 3125 intptr_t from_index,
3126 intptr_t len,
3127 NameVisibility name_visibility) const {
3042 ASSERT(from_index + len <= Length()); 3128 ASSERT(from_index + len <= Length());
3043 String& name = String::Handle(); 3129 String& name = String::Handle();
3044 const intptr_t num_strings = 2*len + 1; // "<""T"", ""T"">". 3130 const intptr_t num_strings = 2*len + 1; // "<""T"", ""T"">".
3045 const Array& strings = Array::Handle(Array::New(num_strings)); 3131 const Array& strings = Array::Handle(Array::New(num_strings));
3046 intptr_t s = 0; 3132 intptr_t s = 0;
3047 strings.SetAt(s++, String::Handle(String::NewSymbol("<"))); 3133 strings.SetAt(s++, String::Handle(String::NewSymbol("<")));
3048 const String& kCommaSpace = String::Handle(String::NewSymbol(", ")); 3134 const String& kCommaSpace = String::Handle(String::NewSymbol(", "));
3049 AbstractType& type = AbstractType::Handle(); 3135 AbstractType& type = AbstractType::Handle();
3050 for (intptr_t i = 0; i < len; i++) { 3136 for (intptr_t i = 0; i < len; i++) {
3051 type = TypeAt(from_index + i); 3137 type = TypeAt(from_index + i);
3052 name = type.Name(); 3138 name = type.BuildName(name_visibility);
3053 strings.SetAt(s++, name); 3139 strings.SetAt(s++, name);
3054 if (i < len - 1) { 3140 if (i < len - 1) {
3055 strings.SetAt(s++, kCommaSpace); 3141 strings.SetAt(s++, kCommaSpace);
3056 } 3142 }
3057 } 3143 }
3058 strings.SetAt(s++, String::Handle(String::NewSymbol(">"))); 3144 strings.SetAt(s++, String::Handle(String::NewSymbol(">")));
3059 ASSERT(s == num_strings); 3145 ASSERT(s == num_strings);
3060 name = String::ConcatAll(strings); 3146 name = String::ConcatAll(strings);
3061 return String::NewSymbol(name); 3147 return String::NewSymbol(name);
3062 } 3148 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
3208 if (bound.IsMalformed()) { 3294 if (bound.IsMalformed()) {
3209 malformed_bound_error = bound.malformed_error(); 3295 malformed_bound_error = bound.malformed_error();
3210 } else if (!bound.IsInstantiated()) { 3296 } else if (!bound.IsInstantiated()) {
3211 bound = bound.InstantiateFrom(bounds_instantiator); 3297 bound = bound.InstantiateFrom(bounds_instantiator);
3212 } 3298 }
3213 if (!malformed_bound_error.IsNull() || 3299 if (!malformed_bound_error.IsNull() ||
3214 !this_type_arg.IsSubtypeOf(bound, malformed_error)) { 3300 !this_type_arg.IsSubtypeOf(bound, malformed_error)) {
3215 // Ignore this bound error if another malformed error was already 3301 // Ignore this bound error if another malformed error was already
3216 // reported for this type test. 3302 // reported for this type test.
3217 if (malformed_error->IsNull()) { 3303 if (malformed_error->IsNull()) {
3218 const String& type_arg_name = String::Handle(this_type_arg.Name()); 3304 const String& type_arg_name =
3305 String::Handle(this_type_arg.UserVisibleName());
3219 const String& class_name = String::Handle(cls.Name()); 3306 const String& class_name = String::Handle(cls.Name());
3220 const String& bound_name = String::Handle(bound.Name()); 3307 const String& bound_name = String::Handle(bound.UserVisibleName());
3221 const Script& script = Script::Handle(cls.script()); 3308 const Script& script = Script::Handle(cls.script());
3222 // Since the bound was canonicalized, its token index was lost, 3309 // Since the bound was canonicalized, its token index was lost,
3223 // therefore, use the token index of the corresponding type parameter. 3310 // therefore, use the token index of the corresponding type parameter.
3224 *malformed_error ^= FormatError(malformed_bound_error, 3311 *malformed_error ^= FormatError(malformed_bound_error,
3225 script, cls_type_param.token_pos(), 3312 script, cls_type_param.token_pos(),
3226 "type argument '%s' does not " 3313 "type argument '%s' does not "
3227 "extend bound '%s' of '%s'\n", 3314 "extend bound '%s' of '%s'\n",
3228 type_arg_name.ToCString(), 3315 type_arg_name.ToCString(),
3229 bound_name.ToCString(), 3316 bound_name.ToCString(),
3230 class_name.ToCString()); 3317 class_name.ToCString());
(...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after
4117 } 4204 }
4118 ASSERT(closure_function.signature_class() == signature_class.raw()); 4205 ASSERT(closure_function.signature_class() == signature_class.raw());
4119 set_implicit_closure_function(closure_function); 4206 set_implicit_closure_function(closure_function);
4120 ASSERT(closure_function.IsImplicitClosureFunction()); 4207 ASSERT(closure_function.IsImplicitClosureFunction());
4121 return closure_function.raw(); 4208 return closure_function.raw();
4122 } 4209 }
4123 4210
4124 4211
4125 RawString* Function::BuildSignature( 4212 RawString* Function::BuildSignature(
4126 bool instantiate, 4213 bool instantiate,
4214 NameVisibility name_visibility,
4127 const AbstractTypeArguments& instantiator) const { 4215 const AbstractTypeArguments& instantiator) const {
4128 const GrowableObjectArray& pieces = 4216 const GrowableObjectArray& pieces =
4129 GrowableObjectArray::Handle(GrowableObjectArray::New()); 4217 GrowableObjectArray::Handle(GrowableObjectArray::New());
4130 const String& kCommaSpace = String::Handle(String::NewSymbol(", ")); 4218 const String& kCommaSpace = String::Handle(String::NewSymbol(", "));
4131 const String& kColonSpace = String::Handle(String::NewSymbol(": ")); 4219 const String& kColonSpace = String::Handle(String::NewSymbol(": "));
4132 const String& kLParen = String::Handle(String::NewSymbol("(")); 4220 const String& kLParen = String::Handle(String::NewSymbol("("));
4133 const String& kRParen = String::Handle(String::NewSymbol(") => ")); 4221 const String& kRParen = String::Handle(String::NewSymbol(") => "));
4134 const String& kLBracket = String::Handle(String::NewSymbol("[")); 4222 const String& kLBracket = String::Handle(String::NewSymbol("["));
4135 const String& kRBracket = String::Handle(String::NewSymbol("]")); 4223 const String& kRBracket = String::Handle(String::NewSymbol("]"));
4136 String& name = String::Handle(); 4224 String& name = String::Handle();
4137 if (!instantiate && !is_static()) { 4225 if (!instantiate && !is_static()) {
4226 // Prefix the signature with its type parameters, if any (e.g. "<K, V>").
4227 // The signature of static functions cannot be type parameterized.
4138 const String& kSpaceExtendsSpace = 4228 const String& kSpaceExtendsSpace =
4139 String::Handle(String::NewSymbol(" extends ")); 4229 String::Handle(String::NewSymbol(" extends "));
4140 const String& kLAngleBracket = String::Handle(String::NewSymbol("<")); 4230 const String& kLAngleBracket = String::Handle(String::NewSymbol("<"));
4141 const String& kRAngleBracket = String::Handle(String::NewSymbol(">")); 4231 const String& kRAngleBracket = String::Handle(String::NewSymbol(">"));
4142 const Class& function_class = Class::Handle(owner()); 4232 const Class& function_class = Class::Handle(owner());
4143 ASSERT(!function_class.IsNull()); 4233 ASSERT(!function_class.IsNull());
4144 const TypeArguments& type_parameters = TypeArguments::Handle( 4234 const TypeArguments& type_parameters = TypeArguments::Handle(
4145 function_class.type_parameters()); 4235 function_class.type_parameters());
4146 if (!type_parameters.IsNull()) { 4236 if (!type_parameters.IsNull()) {
4147 intptr_t num_type_parameters = type_parameters.Length(); 4237 intptr_t num_type_parameters = type_parameters.Length();
4148 pieces.Add(kLAngleBracket); 4238 pieces.Add(kLAngleBracket);
4149 TypeParameter& type_parameter = TypeParameter::Handle(); 4239 TypeParameter& type_parameter = TypeParameter::Handle();
4150 AbstractType& bound = AbstractType::Handle(); 4240 AbstractType& bound = AbstractType::Handle();
4151 for (intptr_t i = 0; i < num_type_parameters; i++) { 4241 for (intptr_t i = 0; i < num_type_parameters; i++) {
4152 type_parameter ^= type_parameters.TypeAt(i); 4242 type_parameter ^= type_parameters.TypeAt(i);
4153 name = type_parameter.Name(); 4243 name = type_parameter.name();
4154 pieces.Add(name); 4244 pieces.Add(name);
4155 bound = type_parameter.bound(); 4245 bound = type_parameter.bound();
4156 if (!bound.IsNull() && !bound.IsDynamicType()) { 4246 if (!bound.IsNull() && !bound.IsDynamicType()) {
4157 pieces.Add(kSpaceExtendsSpace); 4247 pieces.Add(kSpaceExtendsSpace);
4158 name = bound.Name(); 4248 name = bound.BuildName(name_visibility);
4159 pieces.Add(name); 4249 pieces.Add(name);
4160 } 4250 }
4161 if (i < num_type_parameters - 1) { 4251 if (i < num_type_parameters - 1) {
4162 pieces.Add(kCommaSpace); 4252 pieces.Add(kCommaSpace);
4163 } 4253 }
4164 } 4254 }
4165 pieces.Add(kRAngleBracket); 4255 pieces.Add(kRAngleBracket);
4166 } 4256 }
4167 } 4257 }
4168 AbstractType& param_type = AbstractType::Handle(); 4258 AbstractType& param_type = AbstractType::Handle();
4169 const intptr_t num_params = NumberOfParameters(); 4259 const intptr_t num_params = NumberOfParameters();
4170 const intptr_t num_fixed_params = num_fixed_parameters(); 4260 const intptr_t num_fixed_params = num_fixed_parameters();
4171 const intptr_t num_opt_params = num_optional_parameters(); 4261 const intptr_t num_opt_params = num_optional_parameters();
4172 ASSERT((num_fixed_params + num_opt_params) == num_params); 4262 ASSERT((num_fixed_params + num_opt_params) == num_params);
4173 pieces.Add(kLParen); 4263 pieces.Add(kLParen);
4174 for (intptr_t i = 0; i < num_fixed_params; i++) { 4264 for (intptr_t i = 0; i < num_fixed_params; i++) {
4175 param_type = ParameterTypeAt(i); 4265 param_type = ParameterTypeAt(i);
4176 ASSERT(!param_type.IsNull()); 4266 ASSERT(!param_type.IsNull());
4177 if (instantiate && !param_type.IsInstantiated()) { 4267 if (instantiate && !param_type.IsInstantiated()) {
4178 param_type = param_type.InstantiateFrom(instantiator); 4268 param_type = param_type.InstantiateFrom(instantiator);
4179 } 4269 }
4180 name = param_type.Name(); 4270 name = param_type.BuildName(name_visibility);
4181 pieces.Add(name); 4271 pieces.Add(name);
4182 if (i != (num_params - 1)) { 4272 if (i != (num_params - 1)) {
4183 pieces.Add(kCommaSpace); 4273 pieces.Add(kCommaSpace);
4184 } 4274 }
4185 } 4275 }
4186 if (num_opt_params > 0) { 4276 if (num_opt_params > 0) {
4187 pieces.Add(kLBracket); 4277 pieces.Add(kLBracket);
4188 for (intptr_t i = num_fixed_params; i < num_params; i++) { 4278 for (intptr_t i = num_fixed_params; i < num_params; i++) {
4189 name = ParameterNameAt(i); 4279 name = ParameterNameAt(i);
4190 pieces.Add(name); 4280 pieces.Add(name);
4191 pieces.Add(kColonSpace); 4281 pieces.Add(kColonSpace);
4192 param_type = ParameterTypeAt(i); 4282 param_type = ParameterTypeAt(i);
4193 if (instantiate && !param_type.IsInstantiated()) { 4283 if (instantiate && !param_type.IsInstantiated()) {
4194 param_type = param_type.InstantiateFrom(instantiator); 4284 param_type = param_type.InstantiateFrom(instantiator);
4195 } 4285 }
4196 ASSERT(!param_type.IsNull()); 4286 ASSERT(!param_type.IsNull());
4197 name = param_type.Name(); 4287 name = param_type.BuildName(name_visibility);
4198 pieces.Add(name); 4288 pieces.Add(name);
4199 if (i != (num_params - 1)) { 4289 if (i != (num_params - 1)) {
4200 pieces.Add(kCommaSpace); 4290 pieces.Add(kCommaSpace);
4201 } 4291 }
4202 } 4292 }
4203 pieces.Add(kRBracket); 4293 pieces.Add(kRBracket);
4204 } 4294 }
4205 pieces.Add(kRParen); 4295 pieces.Add(kRParen);
4206 AbstractType& res_type = AbstractType::Handle(result_type()); 4296 AbstractType& res_type = AbstractType::Handle(result_type());
4207 if (instantiate && !res_type.IsInstantiated()) { 4297 if (instantiate && !res_type.IsInstantiated()) {
4208 res_type = res_type.InstantiateFrom(instantiator); 4298 res_type = res_type.InstantiateFrom(instantiator);
4209 } 4299 }
4210 name = res_type.Name(); 4300 name = res_type.BuildName(name_visibility);
4211 pieces.Add(name); 4301 pieces.Add(name);
4212 const Array& strings = Array::Handle(Array::MakeArray(pieces)); 4302 const Array& strings = Array::Handle(Array::MakeArray(pieces));
4213 return String::NewSymbol(String::Handle(String::ConcatAll(strings))); 4303 return String::NewSymbol(String::Handle(String::ConcatAll(strings)));
4214 } 4304 }
4215 4305
4216 4306
4217 bool Function::HasInstantiatedSignature() const { 4307 bool Function::HasInstantiatedSignature() const {
4218 AbstractType& type = AbstractType::Handle(result_type()); 4308 AbstractType& type = AbstractType::Handle(result_type());
4219 if (!type.IsInstantiated()) { 4309 if (!type.IsInstantiated()) {
4220 return false; 4310 return false;
(...skipping 6559 matching lines...) Expand 10 before | Expand all | Expand 10 after
10780 const String& str = String::Handle(pattern()); 10870 const String& str = String::Handle(pattern());
10781 const char* format = "JSRegExp: pattern=%s flags=%s"; 10871 const char* format = "JSRegExp: pattern=%s flags=%s";
10782 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 10872 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
10783 char* chars = reinterpret_cast<char*>( 10873 char* chars = reinterpret_cast<char*>(
10784 Isolate::Current()->current_zone()->Allocate(len + 1)); 10874 Isolate::Current()->current_zone()->Allocate(len + 1));
10785 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 10875 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
10786 return chars; 10876 return chars;
10787 } 10877 }
10788 10878
10789 } // namespace dart 10879 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_store.h » ('j') | runtime/vm/object_store.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698