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

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

Powered by Google App Engine
This is Rietveld 408576698