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

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

Issue 1584223006: Remove signature classes from the VM. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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
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 #ifndef VM_OBJECT_H_ 5 #ifndef VM_OBJECT_H_
6 #define VM_OBJECT_H_ 6 #define VM_OBJECT_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/utils.h" 10 #include "platform/utils.h"
(...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 virtual RawString* DictionaryName() const { return Name(); } 934 virtual RawString* DictionaryName() const { return Name(); }
935 935
936 RawScript* script() const { return raw_ptr()->script_; } 936 RawScript* script() const { return raw_ptr()->script_; }
937 void set_script(const Script& value) const; 937 void set_script(const Script& value) const;
938 938
939 intptr_t token_pos() const { return raw_ptr()->token_pos_; } 939 intptr_t token_pos() const { return raw_ptr()->token_pos_; }
940 void set_token_pos(intptr_t value) const; 940 void set_token_pos(intptr_t value) const;
941 941
942 intptr_t ComputeEndTokenPos() const; 942 intptr_t ComputeEndTokenPos() const;
943 943
944 // This class represents the signature class of a closure function if 944 // This class represents a typedef if the signature function is not null.
945 // signature_function() is not null.
946 // The associated function may be a closure function (with code) or a
947 // signature function (without code) solely describing the result type and
948 // parameter types of the signature.
949 RawFunction* signature_function() const { 945 RawFunction* signature_function() const {
950 return raw_ptr()->signature_function_; 946 return raw_ptr()->signature_function_;
951 } 947 }
952 static intptr_t signature_function_offset() { 948 void set_signature_function(const Function& value) const;
953 return OFFSET_OF(RawClass, signature_function_);
954 }
955
956 // Return the signature type of this signature class.
957 // For example, if this class represents a signature of the form
958 // 'F<T, R>(T, [b: B, c: C]) => R', then its signature type is a parameterized
959 // type with this class as the type class and type parameters 'T' and 'R'
960 // as its type argument vector.
961 // SignatureType is used as the type of formal parameters representing a
962 // function.
963 RawType* SignatureType() const;
964 949
965 // Return the Type with type parameters declared by this class filled in with 950 // Return the Type with type parameters declared by this class filled in with
966 // dynamic and type parameters declared in superclasses filled in as declared 951 // dynamic and type parameters declared in superclasses filled in as declared
967 // in superclass clauses. 952 // in superclass clauses.
968 RawAbstractType* RareType() const; 953 RawAbstractType* RareType() const;
969 954
970 // Return the Type whose arguments are the type parameters declared by this 955 // Return the Type whose arguments are the type parameters declared by this
971 // class preceded by the type arguments declared for superclasses, etc. 956 // class preceded by the type arguments declared for superclasses, etc.
972 // e.g. given 957 // e.g. given
973 // class B<T, S> 958 // class B<T, S>
(...skipping 23 matching lines...) Expand all
997 RawTypeParameter* LookupTypeParameter(const String& type_name) const; 982 RawTypeParameter* LookupTypeParameter(const String& type_name) const;
998 983
999 // The type argument vector is flattened and includes the type arguments of 984 // The type argument vector is flattened and includes the type arguments of
1000 // the super class. 985 // the super class.
1001 intptr_t NumTypeArguments() const; 986 intptr_t NumTypeArguments() const;
1002 987
1003 // Return the number of type arguments that are specific to this class, i.e. 988 // Return the number of type arguments that are specific to this class, i.e.
1004 // not overlapping with the type arguments of the super class of this class. 989 // not overlapping with the type arguments of the super class of this class.
1005 intptr_t NumOwnTypeArguments() const; 990 intptr_t NumOwnTypeArguments() const;
1006 991
992 // Return true if this class declares type parameters.
1007 bool IsGeneric() const; 993 bool IsGeneric() const;
1008 994
1009 // If this class is parameterized, each instance has a type_arguments field. 995 // If this class is parameterized, each instance has a type_arguments field.
1010 static const intptr_t kNoTypeArguments = -1; 996 static const intptr_t kNoTypeArguments = -1;
1011 intptr_t type_arguments_field_offset() const { 997 intptr_t type_arguments_field_offset() const {
1012 ASSERT(is_type_finalized() || is_prefinalized()); 998 ASSERT(is_type_finalized() || is_prefinalized());
1013 if (raw_ptr()->type_arguments_field_offset_in_words_ == kNoTypeArguments) { 999 if (raw_ptr()->type_arguments_field_offset_in_words_ == kNoTypeArguments) {
1014 return kNoTypeArguments; 1000 return kNoTypeArguments;
1015 } 1001 }
1016 return raw_ptr()->type_arguments_field_offset_in_words_ * kWordSize; 1002 return raw_ptr()->type_arguments_field_offset_in_words_ * kWordSize;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 1073
1088 // Check if this class represents the 'void' class. 1074 // Check if this class represents the 'void' class.
1089 bool IsVoidClass() const { return id() == kVoidCid; } 1075 bool IsVoidClass() const { return id() == kVoidCid; }
1090 1076
1091 // Check if this class represents the 'Object' class. 1077 // Check if this class represents the 'Object' class.
1092 bool IsObjectClass() const { return id() == kInstanceCid; } 1078 bool IsObjectClass() const { return id() == kInstanceCid; }
1093 1079
1094 // Check if this class represents the 'Function' class. 1080 // Check if this class represents the 'Function' class.
1095 bool IsFunctionClass() const; 1081 bool IsFunctionClass() const;
1096 1082
1097 // Check if this class represents a signature class. 1083 // Check if this class represents the 'Closure' class.
1098 bool IsSignatureClass() const { 1084 bool IsClosureClass() const { return id() == kClosureCid; }
1085 static bool IsClosureClass(RawClass* cls) {
1086 NoSafepointScope no_safepoint;
1087 return cls->ptr()->id_ == kClosureCid;
1088 }
1089
1090 // Check if this class represents a typedef class.
1091 bool IsTypedefClass() const {
1099 return signature_function() != Object::null(); 1092 return signature_function() != Object::null();
1100 } 1093 }
1101 static bool IsSignatureClass(RawClass* cls) { 1094
1102 return cls->ptr()->signature_function_ != Object::null();
1103 }
1104 static bool IsInFullSnapshot(RawClass* cls) { 1095 static bool IsInFullSnapshot(RawClass* cls) {
1105 NoSafepointScope no_safepoint; 1096 NoSafepointScope no_safepoint;
1106 return cls->ptr()->library_->ptr()->is_in_fullsnapshot_; 1097 return cls->ptr()->library_->ptr()->is_in_fullsnapshot_;
1107 } 1098 }
1108 1099
1109 // Check if this class represents a canonical signature class, i.e. not an
1110 // alias as defined in a typedef.
1111 bool IsCanonicalSignatureClass() const;
1112
1113 // Check the subtype relationship. 1100 // Check the subtype relationship.
1114 bool IsSubtypeOf(const TypeArguments& type_arguments, 1101 bool IsSubtypeOf(const TypeArguments& type_arguments,
1115 const Class& other, 1102 const Class& other,
1116 const TypeArguments& other_type_arguments, 1103 const TypeArguments& other_type_arguments,
1117 Error* bound_error, 1104 Error* bound_error,
1118 Heap::Space space = Heap::kNew) const { 1105 Heap::Space space = Heap::kNew) const {
1119 return TypeTest(kIsSubtypeOf, 1106 return TypeTest(kIsSubtypeOf,
1120 type_arguments, 1107 type_arguments,
1121 other, 1108 other,
1122 other_type_arguments, 1109 other_type_arguments,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 RawFunction* LookupGetterFunction(const String& name) const; 1164 RawFunction* LookupGetterFunction(const String& name) const;
1178 RawFunction* LookupSetterFunction(const String& name) const; 1165 RawFunction* LookupSetterFunction(const String& name) const;
1179 RawField* LookupInstanceField(const String& name) const; 1166 RawField* LookupInstanceField(const String& name) const;
1180 RawField* LookupStaticField(const String& name) const; 1167 RawField* LookupStaticField(const String& name) const;
1181 RawField* LookupField(const String& name) const; 1168 RawField* LookupField(const String& name) const;
1182 1169
1183 RawLibraryPrefix* LookupLibraryPrefix(const String& name) const; 1170 RawLibraryPrefix* LookupLibraryPrefix(const String& name) const;
1184 1171
1185 void InsertCanonicalConstant(intptr_t index, const Instance& constant) const; 1172 void InsertCanonicalConstant(intptr_t index, const Instance& constant) const;
1186 1173
1187 intptr_t FindCanonicalTypeIndex(const Type& needle) const; 1174 intptr_t FindCanonicalTypeIndex(const AbstractType& needle) const;
1188 RawType* CanonicalTypeFromIndex(intptr_t idx) const; 1175 RawAbstractType* CanonicalTypeFromIndex(intptr_t idx) const;
1189 1176
1190 static intptr_t InstanceSize() { 1177 static intptr_t InstanceSize() {
1191 return RoundedAllocationSize(sizeof(RawClass)); 1178 return RoundedAllocationSize(sizeof(RawClass));
1192 } 1179 }
1193 1180
1194 bool is_implemented() const { 1181 bool is_implemented() const {
1195 return ImplementedBit::decode(raw_ptr()->state_bits_); 1182 return ImplementedBit::decode(raw_ptr()->state_bits_);
1196 } 1183 }
1197 void set_is_implemented() const; 1184 void set_is_implemented() const;
1198 1185
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 1314
1328 // Allocate the raw TypedData classes. 1315 // Allocate the raw TypedData classes.
1329 static RawClass* NewTypedDataClass(intptr_t class_id); 1316 static RawClass* NewTypedDataClass(intptr_t class_id);
1330 1317
1331 // Allocate the raw TypedDataView classes. 1318 // Allocate the raw TypedDataView classes.
1332 static RawClass* NewTypedDataViewClass(intptr_t class_id); 1319 static RawClass* NewTypedDataViewClass(intptr_t class_id);
1333 1320
1334 // Allocate the raw ExternalTypedData classes. 1321 // Allocate the raw ExternalTypedData classes.
1335 static RawClass* NewExternalTypedDataClass(intptr_t class_id); 1322 static RawClass* NewExternalTypedDataClass(intptr_t class_id);
1336 1323
1337 // Allocate a class representing a function signature described by
1338 // signature_function, which must be a closure function or a signature
1339 // function.
1340 // The class may be type parameterized unless the signature_function is in a
1341 // static scope. In that case, the type parameters are copied from the owner
1342 // class of signature_function.
1343 // A null signature function may be passed in and patched later. See below.
1344 static RawClass* NewSignatureClass(const String& name,
1345 const Function& signature_function,
1346 const Script& script,
1347 intptr_t token_pos);
1348
1349 // Patch the signature function of a signature class allocated without it.
1350 void PatchSignatureFunction(const Function& signature_function) const;
1351
1352 // Register code that has used CHA for optimization. 1324 // Register code that has used CHA for optimization.
1353 // TODO(srdjan): Also register kind of CHA optimization (e.g.: leaf class, 1325 // TODO(srdjan): Also register kind of CHA optimization (e.g.: leaf class,
1354 // leaf method, ...). 1326 // leaf method, ...).
1355 void RegisterCHACode(const Code& code); 1327 void RegisterCHACode(const Code& code);
1356 1328
1357 void DisableCHAOptimizedCode(const Class& subclass); 1329 void DisableCHAOptimizedCode(const Class& subclass);
1358 1330
1359 RawArray* cha_codes() const { return raw_ptr()->cha_codes_; } 1331 RawArray* cha_codes() const { return raw_ptr()->cha_codes_; }
1360 void set_cha_codes(const Array& value) const; 1332 void set_cha_codes(const Array& value) const;
1361 1333
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1402 kFieldsMarkedNullableBit, 1> {}; // NOLINT 1374 kFieldsMarkedNullableBit, 1> {}; // NOLINT
1403 class CycleFreeBit : public BitField<bool, kCycleFreeBit, 1> {}; 1375 class CycleFreeBit : public BitField<bool, kCycleFreeBit, 1> {};
1404 class EnumBit : public BitField<bool, kEnumBit, 1> {}; 1376 class EnumBit : public BitField<bool, kEnumBit, 1> {};
1405 class IsAllocatedBit : public BitField<bool, kIsAllocatedBit, 1> {}; 1377 class IsAllocatedBit : public BitField<bool, kIsAllocatedBit, 1> {};
1406 1378
1407 void set_name(const String& value) const; 1379 void set_name(const String& value) const;
1408 void set_pretty_name(const String& value) const; 1380 void set_pretty_name(const String& value) const;
1409 void set_user_name(const String& value) const; 1381 void set_user_name(const String& value) const;
1410 RawString* GeneratePrettyName() const; 1382 RawString* GeneratePrettyName() const;
1411 RawString* GenerateUserVisibleName() const; 1383 RawString* GenerateUserVisibleName() const;
1412 void set_signature_function(const Function& value) const;
1413 void set_signature_type(const AbstractType& value) const;
1414 void set_state_bits(intptr_t bits) const; 1384 void set_state_bits(intptr_t bits) const;
1415 1385
1416 void set_constants(const Array& value) const; 1386 void set_constants(const Array& value) const;
1417 1387
1418 void set_canonical_types(const Object& value) const; 1388 void set_canonical_types(const Object& value) const;
1419 RawObject* canonical_types() const; 1389 RawObject* canonical_types() const;
1420 1390
1421 RawArray* invocation_dispatcher_cache() const; 1391 RawArray* invocation_dispatcher_cache() const;
1422 void set_invocation_dispatcher_cache(const Array& cache) const; 1392 void set_invocation_dispatcher_cache(const Array& cache) const;
1423 RawFunction* CreateInvocationDispatcher(const String& target_name, 1393 RawFunction* CreateInvocationDispatcher(const String& target_name,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1476 const Class& other, 1446 const Class& other,
1477 const TypeArguments& other_type_arguments, 1447 const TypeArguments& other_type_arguments,
1478 Error* bound_error, 1448 Error* bound_error,
1479 Heap::Space space); 1449 Heap::Space space);
1480 1450
1481 FINAL_HEAP_OBJECT_IMPLEMENTATION(Class, Object); 1451 FINAL_HEAP_OBJECT_IMPLEMENTATION(Class, Object);
1482 friend class AbstractType; 1452 friend class AbstractType;
1483 friend class Instance; 1453 friend class Instance;
1484 friend class Object; 1454 friend class Object;
1485 friend class Type; 1455 friend class Type;
1456 friend class FunctionType;
1486 friend class Intrinsifier; 1457 friend class Intrinsifier;
1487 friend class Precompiler; 1458 friend class Precompiler;
1488 }; 1459 };
1489 1460
1490 1461
1491 // Unresolved class is used for storing unresolved names which will be resolved 1462 // Unresolved class is used for storing unresolved names which will be resolved
1492 // to a class after all classes have been loaded and finalized. 1463 // to a class after all classes have been loaded and finalized.
1493 class UnresolvedClass : public Object { 1464 class UnresolvedClass : public Object {
1494 public: 1465 public:
1495 RawLibraryPrefix* library_prefix() const { 1466 RawLibraryPrefix* library_prefix() const {
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
2101 RawString* name() const { return raw_ptr()->name_; } 2072 RawString* name() const { return raw_ptr()->name_; }
2102 RawString* PrettyName() const; 2073 RawString* PrettyName() const;
2103 RawString* UserVisibleName() const; 2074 RawString* UserVisibleName() const;
2104 RawString* QualifiedPrettyName() const; 2075 RawString* QualifiedPrettyName() const;
2105 RawString* QualifiedUserVisibleName() const; 2076 RawString* QualifiedUserVisibleName() const;
2106 const char* QualifiedUserVisibleNameCString() const; 2077 const char* QualifiedUserVisibleNameCString() const;
2107 virtual RawString* DictionaryName() const { return name(); } 2078 virtual RawString* DictionaryName() const { return name(); }
2108 2079
2109 RawString* GetSource() const; 2080 RawString* GetSource() const;
2110 2081
2082 // Return the type of this function's signature. It may not be canonical yet.
2083 // For example, if this function has a signature of the form
2084 // '(T, [b: B, c: C]) => R', where 'T' and 'R' are type parameters of the
2085 // owner class of this function, then its signature type is a parameterized
2086 // FunctionType with uninstantiated type arguments 'T' and 'R' as elements of
2087 // its type argument vector.
2088 RawFunctionType* SignatureType() const;
2089
2090 // Update the signature type (with a canonical version).
2091 void SetSignatureType(const FunctionType& value) const;
2092
2111 // Build a string of the form 'C<T, R>(T, {b: B, c: C}) => R' representing the 2093 // Build a string of the form 'C<T, R>(T, {b: B, c: C}) => R' representing the
2112 // internal signature of the given function. In this example, T and R are 2094 // internal signature of the given function. In this example, T and R are
2113 // type parameters of class C, the owner of the function. 2095 // type parameters of class C, the owner of the function.
2114 RawString* Signature() const { 2096 RawString* Signature() const {
2115 const bool instantiate = false; 2097 const bool instantiate = false;
2116 return BuildSignature(instantiate, kInternalName, TypeArguments::Handle()); 2098 return BuildSignature(instantiate, kInternalName, TypeArguments::Handle());
2117 } 2099 }
2118 2100
2119 RawString* PrettySignature() const { 2101 RawString* PrettySignature() const {
2120 const bool instantiate = false; 2102 const bool instantiate = false;
2121 return BuildSignature( 2103 return BuildSignature(
2122 instantiate, kPrettyName, TypeArguments::Handle()); 2104 instantiate, kPrettyName, TypeArguments::Handle());
2123 } 2105 }
2124 2106
2125 // Build a string of the form '(T, {b: B, c: C}) => R' representing the 2107 // Build a string of the form '(T, {b: B, c: C}) => R' representing the
2126 // user visible signature of the given function. In this example, T and R are 2108 // user visible signature of the given function. In this example, T and R are
2127 // type parameters of class C, the owner of the function. 2109 // type parameters of class C, the owner of the function, also called the
2110 // scope class of the function type.
2128 // Implicit parameters are hidden, as well as the prefix denoting the 2111 // Implicit parameters are hidden, as well as the prefix denoting the
2129 // signature class and its type parameters. 2112 // scope class and its type parameters.
2130 RawString* UserVisibleSignature() const { 2113 RawString* UserVisibleSignature() const {
2131 const bool instantiate = false; 2114 const bool instantiate = false;
2132 return BuildSignature( 2115 return BuildSignature(
2133 instantiate, kUserVisibleName, TypeArguments::Handle()); 2116 instantiate, kUserVisibleName, TypeArguments::Handle());
2134 } 2117 }
2135 2118
2136 // Build a string of the form '(A, {b: B, c: C}) => D' representing the 2119 // Build a string of the form '(A, {b: B, c: C}) => D' representing the
2137 // signature of the given function, where all generic types (e.g. '<T, R>' in 2120 // signature of the given function, where all generic types (e.g. '<T, R>' in
2138 // 'C<T, R>(T, {b: B, c: C}) => R') are instantiated using the given 2121 // 'C<T, R>(T, {b: B, c: C}) => R') are instantiated using the given
2139 // instantiator type argument vector of a C instance (e.g. '<A, D>'). 2122 // instantiator type argument vector of a C instance (e.g. '<A, D>').
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2212 bool HasBreakpoint() const; 2195 bool HasBreakpoint() const;
2213 2196
2214 RawContextScope* context_scope() const; 2197 RawContextScope* context_scope() const;
2215 void set_context_scope(const ContextScope& value) const; 2198 void set_context_scope(const ContextScope& value) const;
2216 2199
2217 RawField* LookupImplicitGetterSetterField() const; 2200 RawField* LookupImplicitGetterSetterField() const;
2218 2201
2219 // Enclosing function of this local function. 2202 // Enclosing function of this local function.
2220 RawFunction* parent_function() const; 2203 RawFunction* parent_function() const;
2221 2204
2222 // Signature class of this closure function or signature function.
2223 RawClass* signature_class() const;
2224 void set_signature_class(const Class& value) const;
2225
2226 void set_extracted_method_closure(const Function& function) const; 2205 void set_extracted_method_closure(const Function& function) const;
2227 RawFunction* extracted_method_closure() const; 2206 RawFunction* extracted_method_closure() const;
2228 2207
2229 void set_saved_args_desc(const Array& array) const; 2208 void set_saved_args_desc(const Array& array) const;
2230 RawArray* saved_args_desc() const; 2209 RawArray* saved_args_desc() const;
2231 2210
2232 bool IsMethodExtractor() const { 2211 bool IsMethodExtractor() const {
2233 return kind() == RawFunction::kMethodExtractor; 2212 return kind() == RawFunction::kMethodExtractor;
2234 } 2213 }
2235 2214
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
2487 Error* bound_error, 2466 Error* bound_error,
2488 Heap::Space space = Heap::kNew) const { 2467 Heap::Space space = Heap::kNew) const {
2489 return TypeTest(kIsMoreSpecificThan, 2468 return TypeTest(kIsMoreSpecificThan,
2490 type_arguments, 2469 type_arguments,
2491 other, 2470 other,
2492 other_type_arguments, 2471 other_type_arguments,
2493 bound_error, 2472 bound_error,
2494 space); 2473 space);
2495 } 2474 }
2496 2475
2476 // Check the subtype or 'more specific' relationship.
2477 bool TypeTest(TypeTestKind test_kind,
2478 const TypeArguments& type_arguments,
2479 const Function& other,
2480 const TypeArguments& other_type_arguments,
2481 Error* bound_error,
2482 Heap::Space space) const;
2483
2497 // Returns true if this function represents an explicit getter function. 2484 // Returns true if this function represents an explicit getter function.
2498 bool IsGetterFunction() const { 2485 bool IsGetterFunction() const {
2499 return kind() == RawFunction::kGetterFunction; 2486 return kind() == RawFunction::kGetterFunction;
2500 } 2487 }
2501 2488
2502 // Returns true if this function represents an implicit getter function. 2489 // Returns true if this function represents an implicit getter function.
2503 bool IsImplicitGetterFunction() const { 2490 bool IsImplicitGetterFunction() const {
2504 return kind() == RawFunction::kImplicitGetter; 2491 return kind() == RawFunction::kImplicitGetter;
2505 } 2492 }
2506 2493
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2550 2537
2551 // Returns true if this function represents a local function. 2538 // Returns true if this function represents a local function.
2552 bool IsLocalFunction() const { 2539 bool IsLocalFunction() const {
2553 return parent_function() != Function::null(); 2540 return parent_function() != Function::null();
2554 } 2541 }
2555 2542
2556 // Returns true if this function represents a signature function without code. 2543 // Returns true if this function represents a signature function without code.
2557 bool IsSignatureFunction() const { 2544 bool IsSignatureFunction() const {
2558 return kind() == RawFunction::kSignatureFunction; 2545 return kind() == RawFunction::kSignatureFunction;
2559 } 2546 }
2547 static bool IsSignatureFunction(RawFunction* function) {
2548 NoSafepointScope no_safepoint;
2549 return KindBits::decode(function->ptr()->kind_tag_) ==
2550 RawFunction::kSignatureFunction;
2551 }
2560 2552
2561 bool IsAsyncFunction() const { 2553 bool IsAsyncFunction() const {
2562 return modifier() == RawFunction::kAsync; 2554 return modifier() == RawFunction::kAsync;
2563 } 2555 }
2564 2556
2565 bool IsAsyncClosure() const { 2557 bool IsAsyncClosure() const {
2566 return is_generated_body() && 2558 return is_generated_body() &&
2567 Function::Handle(parent_function()).IsAsyncFunction(); 2559 Function::Handle(parent_function()).IsAsyncFunction();
2568 } 2560 }
2569 2561
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2605 static RawFunction* New(const String& name, 2597 static RawFunction* New(const String& name,
2606 RawFunction::Kind kind, 2598 RawFunction::Kind kind,
2607 bool is_static, 2599 bool is_static,
2608 bool is_const, 2600 bool is_const,
2609 bool is_abstract, 2601 bool is_abstract,
2610 bool is_external, 2602 bool is_external,
2611 bool is_native, 2603 bool is_native,
2612 const Object& owner, 2604 const Object& owner,
2613 intptr_t token_pos); 2605 intptr_t token_pos);
2614 2606
2615 // Allocates a new Function object representing a closure function, as well as 2607 // Allocates a new Function object representing a closure function.
2616 // a new associated Class object representing the signature class of the
2617 // function.
2618 // The function and the class share the same given name.
2619 static RawFunction* NewClosureFunction(const String& name, 2608 static RawFunction* NewClosureFunction(const String& name,
2620 const Function& parent, 2609 const Function& parent,
2621 intptr_t token_pos); 2610 intptr_t token_pos);
2622 2611
2612 // Allocates a new Function object representing a signature function.
2613 // The owner is the scope class of the function type.
2614 static RawFunction* NewSignatureFunction(const Class& owner,
2615 intptr_t token_pos);
2616
2623 static RawFunction* NewEvalFunction(const Class& owner, 2617 static RawFunction* NewEvalFunction(const Class& owner,
2624 const Script& script, 2618 const Script& script,
2625 bool is_static); 2619 bool is_static);
2626 2620
2627 RawFunction* CreateMethodExtractor(const String& getter_name) const; 2621 RawFunction* CreateMethodExtractor(const String& getter_name) const;
2628 RawFunction* GetMethodExtractor(const String& getter_name) const; 2622 RawFunction* GetMethodExtractor(const String& getter_name) const;
2629 2623
2630 // Allocate new function object, clone values from this function. The 2624 // Allocate new function object, clone values from this function. The
2631 // owner of the clone is new_owner. 2625 // owner of the clone is new_owner.
2632 RawFunction* Clone(const Class& new_owner) const; 2626 RawFunction* Clone(const Class& new_owner) const;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
2768 2762
2769 void BuildSignatureParameters( 2763 void BuildSignatureParameters(
2770 bool instantiate, 2764 bool instantiate,
2771 NameVisibility name_visibility, 2765 NameVisibility name_visibility,
2772 const TypeArguments& instantiator, 2766 const TypeArguments& instantiator,
2773 GrowableHandlePtrArray<const String>* pieces) const; 2767 GrowableHandlePtrArray<const String>* pieces) const;
2774 RawString* BuildSignature(bool instantiate, 2768 RawString* BuildSignature(bool instantiate,
2775 NameVisibility name_visibility, 2769 NameVisibility name_visibility,
2776 const TypeArguments& instantiator) const; 2770 const TypeArguments& instantiator) const;
2777 2771
2778 // Check the subtype or 'more specific' relationship.
2779 bool TypeTest(TypeTestKind test_kind,
2780 const TypeArguments& type_arguments,
2781 const Function& other,
2782 const TypeArguments& other_type_arguments,
2783 Error* bound_error,
2784 Heap::Space space) const;
2785
2786 // Checks the type of the formal parameter at the given position for 2772 // Checks the type of the formal parameter at the given position for
2787 // subtyping or 'more specific' relationship between the type of this function 2773 // subtyping or 'more specific' relationship between the type of this function
2788 // and the type of the other function. 2774 // and the type of the other function.
2789 bool TestParameterType(TypeTestKind test_kind, 2775 bool TestParameterType(TypeTestKind test_kind,
2790 intptr_t parameter_position, 2776 intptr_t parameter_position,
2791 intptr_t other_parameter_position, 2777 intptr_t other_parameter_position,
2792 const TypeArguments& type_arguments, 2778 const TypeArguments& type_arguments,
2793 const Function& other, 2779 const Function& other,
2794 const TypeArguments& other_type_arguments, 2780 const TypeArguments& other_type_arguments,
2795 Error* bound_error, 2781 Error* bound_error,
(...skipping 16 matching lines...) Expand all
2812 } 2798 }
2813 2799
2814 private: 2800 private:
2815 RawContextScope* context_scope() const { return raw_ptr()->context_scope_; } 2801 RawContextScope* context_scope() const { return raw_ptr()->context_scope_; }
2816 void set_context_scope(const ContextScope& value) const; 2802 void set_context_scope(const ContextScope& value) const;
2817 2803
2818 // Enclosing function of this local function. 2804 // Enclosing function of this local function.
2819 RawFunction* parent_function() const { return raw_ptr()->parent_function_; } 2805 RawFunction* parent_function() const { return raw_ptr()->parent_function_; }
2820 void set_parent_function(const Function& value) const; 2806 void set_parent_function(const Function& value) const;
2821 2807
2822 // Signature class of this closure function or signature function. 2808 // Signature type of this closure function.
2823 RawClass* signature_class() const { return raw_ptr()->signature_class_; } 2809 RawFunctionType* signature_type() const { return raw_ptr()->signature_type_; }
2824 void set_signature_class(const Class& value) const; 2810 void set_signature_type(const FunctionType& value) const;
2825 2811
2826 RawInstance* implicit_static_closure() const { 2812 RawInstance* implicit_static_closure() const {
2827 return raw_ptr()->closure_; 2813 return raw_ptr()->closure_;
2828 } 2814 }
2829 void set_implicit_static_closure(const Instance& closure) const; 2815 void set_implicit_static_closure(const Instance& closure) const;
2830 2816
2831 static RawClosureData* New(); 2817 static RawClosureData* New();
2832 2818
2833 FINAL_HEAP_OBJECT_IMPLEMENTATION(ClosureData, Object); 2819 FINAL_HEAP_OBJECT_IMPLEMENTATION(ClosureData, Object);
2834 friend class Class; 2820 friend class Class;
(...skipping 1885 matching lines...) Expand 10 before | Expand all | Expand 10 after
4720 static inline RawObject* GetTargetFunction(const Array& array, 4706 static inline RawObject* GetTargetFunction(const Array& array,
4721 intptr_t index); 4707 intptr_t index);
4722 4708
4723 FINAL_HEAP_OBJECT_IMPLEMENTATION(MegamorphicCache, Object); 4709 FINAL_HEAP_OBJECT_IMPLEMENTATION(MegamorphicCache, Object);
4724 }; 4710 };
4725 4711
4726 4712
4727 class SubtypeTestCache : public Object { 4713 class SubtypeTestCache : public Object {
4728 public: 4714 public:
4729 enum Entries { 4715 enum Entries {
4730 kInstanceClassId = 0, 4716 kInstanceClassIdOrFunction = 0,
4731 kInstanceTypeArguments = 1, 4717 kInstanceTypeArguments = 1,
4732 kInstantiatorTypeArguments = 2, 4718 kInstantiatorTypeArguments = 2,
4733 kTestResult = 3, 4719 kTestResult = 3,
4734 kTestEntryLength = 4, 4720 kTestEntryLength = 4,
4735 }; 4721 };
4736 4722
4737 intptr_t NumberOfChecks() const; 4723 intptr_t NumberOfChecks() const;
4738 void AddCheck(intptr_t class_id, 4724 void AddCheck(const Object& instance_class_id_or_function,
4739 const TypeArguments& instance_type_arguments, 4725 const TypeArguments& instance_type_arguments,
4740 const TypeArguments& instantiator_type_arguments, 4726 const TypeArguments& instantiator_type_arguments,
4741 const Bool& test_result) const; 4727 const Bool& test_result) const;
4742 void GetCheck(intptr_t ix, 4728 void GetCheck(intptr_t ix,
4743 intptr_t* class_id, 4729 Object* instance_class_id_or_function,
4744 TypeArguments* instance_type_arguments, 4730 TypeArguments* instance_type_arguments,
4745 TypeArguments* instantiator_type_arguments, 4731 TypeArguments* instantiator_type_arguments,
4746 Bool* test_result) const; 4732 Bool* test_result) const;
4747 4733
4748 static RawSubtypeTestCache* New(); 4734 static RawSubtypeTestCache* New();
4749 4735
4750 static intptr_t InstanceSize() { 4736 static intptr_t InstanceSize() {
4751 return RoundedAllocationSize(sizeof(RawSubtypeTestCache)); 4737 return RoundedAllocationSize(sizeof(RawSubtypeTestCache));
4752 } 4738 }
4753 4739
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
4951 4937
4952 RawObject* GetField(const Field& field) const { 4938 RawObject* GetField(const Field& field) const {
4953 return *FieldAddr(field); 4939 return *FieldAddr(field);
4954 } 4940 }
4955 4941
4956 void SetField(const Field& field, const Object& value) const { 4942 void SetField(const Field& field, const Object& value) const {
4957 field.RecordStore(value); 4943 field.RecordStore(value);
4958 StorePointer(FieldAddr(field), value.raw()); 4944 StorePointer(FieldAddr(field), value.raw());
4959 } 4945 }
4960 4946
4961 RawType* GetType() const; 4947 RawAbstractType* GetType() const;
4962 4948
4963 virtual RawTypeArguments* GetTypeArguments() const; 4949 virtual RawTypeArguments* GetTypeArguments() const;
4964 virtual void SetTypeArguments(const TypeArguments& value) const; 4950 virtual void SetTypeArguments(const TypeArguments& value) const;
4965 4951
4966 // Check if the type of this instance is a subtype of the given type. 4952 // Check if the type of this instance is a subtype of the given type.
4967 bool IsInstanceOf(const AbstractType& type, 4953 bool IsInstanceOf(const AbstractType& type,
4968 const TypeArguments& type_instantiator, 4954 const TypeArguments& type_instantiator,
4969 Error* bound_error) const; 4955 Error* bound_error) const;
4970 4956
4971 bool IsValidNativeIndex(int index) const { 4957 bool IsValidNativeIndex(int index) const {
4972 return ((index >= 0) && (index < clazz()->ptr()->num_native_fields_)); 4958 return ((index >= 0) && (index < clazz()->ptr()->num_native_fields_));
4973 } 4959 }
4974 4960
4975 intptr_t* NativeFieldsDataAddr() const; 4961 intptr_t* NativeFieldsDataAddr() const;
4976 inline intptr_t GetNativeField(int index) const; 4962 inline intptr_t GetNativeField(int index) const;
4977 inline void GetNativeFields(uint16_t num_fields, 4963 inline void GetNativeFields(uint16_t num_fields,
4978 intptr_t* field_values) const; 4964 intptr_t* field_values) const;
4979 void SetNativeFields(uint16_t num_fields, 4965 void SetNativeFields(uint16_t num_fields,
4980 const intptr_t* field_values) const; 4966 const intptr_t* field_values) const;
4981 4967
4982 uint16_t NumNativeFields() const { 4968 uint16_t NumNativeFields() const {
4983 return clazz()->ptr()->num_native_fields_; 4969 return clazz()->ptr()->num_native_fields_;
4984 } 4970 }
4985 4971
4986 void SetNativeField(int index, intptr_t value) const; 4972 void SetNativeField(int index, intptr_t value) const;
4987 4973
4988 // Returns true if the instance is a closure object.
4989 bool IsClosure() const;
4990
4991 // If the instance is a callable object, i.e. a closure or the instance of a 4974 // If the instance is a callable object, i.e. a closure or the instance of a
4992 // class implementing a 'call' method, return true and set the function 4975 // class implementing a 'call' method, return true and set the function
4993 // (if not NULL) to call. 4976 // (if not NULL) to call.
4994 bool IsCallable(Function* function) const; 4977 bool IsCallable(Function* function) const;
4995 4978
4996 // Evaluate the given expression as if it appeared in an instance 4979 // Evaluate the given expression as if it appeared in an instance
4997 // method of this instance and return the resulting value, or an 4980 // method of this instance and return the resulting value, or an
4998 // error object if evaluating the expression fails. The method has 4981 // error object if evaluating the expression fails. The method has
4999 // the formal parameters given in param_names, and is invoked with 4982 // the formal parameters given in param_names, and is invoked with
5000 // the argument values given in param_values. 4983 // the argument values given in param_values.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
5107 FINAL_HEAP_OBJECT_IMPLEMENTATION(LibraryPrefix, Instance); 5090 FINAL_HEAP_OBJECT_IMPLEMENTATION(LibraryPrefix, Instance);
5108 friend class Class; 5091 friend class Class;
5109 }; 5092 };
5110 5093
5111 5094
5112 // AbstractType is an abstract superclass. 5095 // AbstractType is an abstract superclass.
5113 // Subclasses of AbstractType are Type and TypeParameter. 5096 // Subclasses of AbstractType are Type and TypeParameter.
5114 class AbstractType : public Instance { 5097 class AbstractType : public Instance {
5115 public: 5098 public:
5116 virtual bool IsFinalized() const; 5099 virtual bool IsFinalized() const;
5100 virtual void SetIsFinalized() const;
5117 virtual bool IsBeingFinalized() const; 5101 virtual bool IsBeingFinalized() const;
5102 virtual void SetIsBeingFinalized() const;
5118 virtual bool IsMalformed() const; 5103 virtual bool IsMalformed() const;
5119 virtual bool IsMalbounded() const; 5104 virtual bool IsMalbounded() const;
5120 virtual bool IsMalformedOrMalbounded() const; 5105 virtual bool IsMalformedOrMalbounded() const;
5121 virtual RawLanguageError* error() const; 5106 virtual RawLanguageError* error() const;
5122 virtual void set_error(const LanguageError& value) const; 5107 virtual void set_error(const LanguageError& value) const;
5123 virtual bool IsResolved() const; 5108 virtual bool IsResolved() const;
5109 virtual void SetIsResolved() const;
5124 virtual bool HasResolvedTypeClass() const; 5110 virtual bool HasResolvedTypeClass() const;
5125 virtual RawClass* type_class() const; 5111 virtual RawClass* type_class() const;
5126 virtual RawUnresolvedClass* unresolved_class() const; 5112 virtual RawUnresolvedClass* unresolved_class() const;
5127 virtual RawTypeArguments* arguments() const; 5113 virtual RawTypeArguments* arguments() const;
5114 virtual void set_arguments(const TypeArguments& value) const;
5128 virtual intptr_t token_pos() const; 5115 virtual intptr_t token_pos() const;
5129 virtual bool IsInstantiated(TrailPtr trail = NULL) const; 5116 virtual bool IsInstantiated(TrailPtr trail = NULL) const;
5130 virtual bool CanonicalizeEquals(const Instance& other) const { 5117 virtual bool CanonicalizeEquals(const Instance& other) const {
5131 return Equals(other); 5118 return Equals(other);
5132 } 5119 }
5133 virtual bool Equals(const Instance& other) const { 5120 virtual bool Equals(const Instance& other) const {
5134 return IsEquivalent(other); 5121 return IsEquivalent(other);
5135 } 5122 }
5136 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const; 5123 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const;
5137 virtual bool IsRecursive() const; 5124 virtual bool IsRecursive() const;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
5232 5219
5233 // Check if this type represents the 'num' type. 5220 // Check if this type represents the 'num' type.
5234 bool IsNumberType() const; 5221 bool IsNumberType() const;
5235 5222
5236 // Check if this type represents the '_Smi' type. 5223 // Check if this type represents the '_Smi' type.
5237 bool IsSmiType() const; 5224 bool IsSmiType() const;
5238 5225
5239 // Check if this type represents the 'String' type. 5226 // Check if this type represents the 'String' type.
5240 bool IsStringType() const; 5227 bool IsStringType() const;
5241 5228
5242 // Check if this type represents the 'Function' type. 5229 // Check if this type represents the Dart 'Function' type.
5243 bool IsFunctionType() const; 5230 bool IsDartFunctionType() const;
5244 5231
5245 // Check the subtype relationship. 5232 // Check the subtype relationship.
5246 bool IsSubtypeOf(const AbstractType& other, 5233 bool IsSubtypeOf(const AbstractType& other,
5247 Error* bound_error, 5234 Error* bound_error,
5248 Heap::Space space = Heap::kNew) const { 5235 Heap::Space space = Heap::kNew) const {
5249 return TypeTest(kIsSubtypeOf, other, bound_error, space); 5236 return TypeTest(kIsSubtypeOf, other, bound_error, space);
5250 } 5237 }
5251 5238
5252 // Check the 'more specific' relationship. 5239 // Check the 'more specific' relationship.
5253 bool IsMoreSpecificThan(const AbstractType& other, 5240 bool IsMoreSpecificThan(const AbstractType& other,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
5285 class Type : public AbstractType { 5272 class Type : public AbstractType {
5286 public: 5273 public:
5287 static intptr_t type_class_offset() { 5274 static intptr_t type_class_offset() {
5288 return OFFSET_OF(RawType, type_class_); 5275 return OFFSET_OF(RawType, type_class_);
5289 } 5276 }
5290 virtual bool IsFinalized() const { 5277 virtual bool IsFinalized() const {
5291 return 5278 return
5292 (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) || 5279 (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) ||
5293 (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated); 5280 (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated);
5294 } 5281 }
5295 void SetIsFinalized() const; 5282 virtual void SetIsFinalized() const;
5296 void ResetIsFinalized() const; // Ignore current state and set again.
5297 virtual bool IsBeingFinalized() const { 5283 virtual bool IsBeingFinalized() const {
5298 return raw_ptr()->type_state_ == RawType::kBeingFinalized; 5284 return raw_ptr()->type_state_ == RawType::kBeingFinalized;
5299 } 5285 }
5300 void set_is_being_finalized() const; 5286 virtual void SetIsBeingFinalized() const;
5301 virtual bool IsMalformed() const; 5287 virtual bool IsMalformed() const;
5302 virtual bool IsMalbounded() const; 5288 virtual bool IsMalbounded() const;
5303 virtual bool IsMalformedOrMalbounded() const; 5289 virtual bool IsMalformedOrMalbounded() const;
5304 virtual RawLanguageError* error() const { return raw_ptr()->error_; } 5290 virtual RawLanguageError* error() const { return raw_ptr()->error_; }
5305 virtual void set_error(const LanguageError& value) const; 5291 virtual void set_error(const LanguageError& value) const;
5306 virtual bool IsResolved() const { 5292 virtual bool IsResolved() const {
5307 return raw_ptr()->type_state_ >= RawType::kResolved; 5293 return raw_ptr()->type_state_ >= RawType::kResolved;
5308 } 5294 }
5309 void set_is_resolved() const; 5295 virtual void SetIsResolved() const;
5310 virtual bool HasResolvedTypeClass() const; // Own type class resolved. 5296 virtual bool HasResolvedTypeClass() const; // Own type class resolved.
5311 virtual RawClass* type_class() const; 5297 virtual RawClass* type_class() const;
5312 void set_type_class(const Object& value) const; 5298 void set_type_class(const Object& value) const;
5313 virtual RawUnresolvedClass* unresolved_class() const; 5299 virtual RawUnresolvedClass* unresolved_class() const;
5314 virtual RawTypeArguments* arguments() const; 5300 virtual RawTypeArguments* arguments() const { return raw_ptr()->arguments_; }
5315 void set_arguments(const TypeArguments& value) const; 5301 virtual void set_arguments(const TypeArguments& value) const;
5316 virtual intptr_t token_pos() const { return raw_ptr()->token_pos_; } 5302 virtual intptr_t token_pos() const { return raw_ptr()->token_pos_; }
5317 virtual bool IsInstantiated(TrailPtr trail = NULL) const; 5303 virtual bool IsInstantiated(TrailPtr trail = NULL) const;
5318 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const; 5304 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const;
5319 virtual bool IsRecursive() const; 5305 virtual bool IsRecursive() const;
5320 virtual RawAbstractType* InstantiateFrom( 5306 virtual RawAbstractType* InstantiateFrom(
5321 const TypeArguments& instantiator_type_arguments, 5307 const TypeArguments& instantiator_type_arguments,
5322 Error* bound_error, 5308 Error* bound_error,
5323 TrailPtr trail = NULL, 5309 TrailPtr trail = NULL,
5324 Heap::Space space = Heap::kNew) const; 5310 Heap::Space space = Heap::kNew) const;
5325 virtual RawAbstractType* CloneUnfinalized() const; 5311 virtual RawAbstractType* CloneUnfinalized() const;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
5395 void set_type_state(int8_t state) const; 5381 void set_type_state(int8_t state) const;
5396 5382
5397 static RawType* New(Heap::Space space = Heap::kOld); 5383 static RawType* New(Heap::Space space = Heap::kOld);
5398 5384
5399 FINAL_HEAP_OBJECT_IMPLEMENTATION(Type, AbstractType); 5385 FINAL_HEAP_OBJECT_IMPLEMENTATION(Type, AbstractType);
5400 friend class Class; 5386 friend class Class;
5401 friend class TypeArguments; 5387 friend class TypeArguments;
5402 }; 5388 };
5403 5389
5404 5390
5391 // TODO(regis): FunctionType is very similar to Type. Instead of a separate
5392 // class FunctionType, we could consider an object of class Type as representing
5393 // a function type if it has a non-null function (signature) field.
5394 // In order to save space, we could reuse the error_ field? A malformed or
5395 // malbounded function type would lose its function reference, but the error
5396 // string would contain relevant info.
5397
5398 // A FunctionType describes the signature of a function, i.e. the result type
5399 // and formal parameter types of the function, as well as the names of optional
5400 // named formal parameters.
5401 // If these types refer to type parameters of a class in scope, the function
5402 // type is generic. A generic function type may be instantiated by a type
5403 // argument vector.
5404 // Therefore, a FunctionType consists of a scope class, a type argument vector,
5405 // and a signature.
5406 // The scope class is either a generic class (or generic typedef) declaring the
5407 // type parameters referred to by the signature, or class _Closure in the
5408 // non-generic case (including the non-generic typedef case).
5409 // The type arguments specify an instantiation of the generic signature (null in
5410 // the non-generic case).
5411 // The signature is a reference to an actual closure function (kClosureFunction)
5412 // or to a signature function (kSignatureFunction).
5413 // Since typedefs cannot refer to themselves, directly or indirectly, a
5414 // FunctionType cannot be recursive. Only individual formal parameter types can.
5415 class FunctionType : public AbstractType {
5416 public:
5417 virtual bool IsFinalized() const {
5418 return
5419 (raw_ptr()->type_state_ == RawFunctionType::kFinalizedInstantiated) ||
5420 (raw_ptr()->type_state_ == RawFunctionType::kFinalizedUninstantiated);
5421 }
5422 virtual void SetIsFinalized() const;
5423 void ResetIsFinalized() const; // Ignore current state and set again.
5424 virtual bool IsBeingFinalized() const {
5425 return raw_ptr()->type_state_ == RawFunctionType::kBeingFinalized;
5426 }
5427 virtual void SetIsBeingFinalized() const;
5428 virtual bool IsMalformed() const;
5429 virtual bool IsMalbounded() const;
5430 virtual bool IsMalformedOrMalbounded() const;
5431 virtual RawLanguageError* error() const { return raw_ptr()->error_; }
5432 virtual void set_error(const LanguageError& value) const;
5433 virtual bool IsResolved() const {
5434 return raw_ptr()->type_state_ >= RawFunctionType::kResolved;
5435 }
5436 virtual void SetIsResolved() const;
5437 // The scope class of a FunctionType is always resolved. It has no actual
5438 // type class. Returning false is important for the type testers to work, e.g.
5439 // IsDynamicType(), IsBoolType(), etc...
5440 virtual bool HasResolvedTypeClass() const { return false; }
5441 // Return scope_class from virtual type_class() to factorize finalization
5442 // with Type, also a parameterized type.
5443 virtual RawClass* type_class() const { return scope_class(); }
5444 RawClass* scope_class() const { return raw_ptr()->scope_class_; }
5445 void set_scope_class(const Class& value) const;
5446 virtual RawTypeArguments* arguments() const { return raw_ptr()->arguments_; }
5447 virtual void set_arguments(const TypeArguments& value) const;
5448 RawFunction* signature() const { return raw_ptr()->signature_; }
5449 virtual intptr_t token_pos() const { return raw_ptr()->token_pos_; }
5450 virtual bool IsInstantiated(TrailPtr trail = NULL) const;
5451 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const;
5452 virtual bool IsRecursive() const;
5453 virtual RawAbstractType* InstantiateFrom(
5454 const TypeArguments& instantiator_type_arguments,
5455 Error* malformed_error,
5456 TrailPtr trail = NULL,
5457 Heap::Space space = Heap::kNew) const;
5458 virtual RawAbstractType* CloneUnfinalized() const;
5459 virtual RawAbstractType* CloneUninstantiated(
5460 const Class& new_owner,
5461 TrailPtr trail = NULL) const;
5462 virtual RawAbstractType* Canonicalize(TrailPtr trail = NULL) const;
5463
5464 virtual intptr_t Hash() const;
5465
5466 static intptr_t InstanceSize() {
5467 return RoundedAllocationSize(sizeof(RawFunctionType));
5468 }
5469
5470 static RawFunctionType* New(const Class& scope_class,
5471 const TypeArguments& arguments,
5472 const Function& signature,
5473 intptr_t token_pos,
5474 Heap::Space space = Heap::kOld);
5475
5476 private:
5477 void set_signature(const Function& value) const;
5478 void set_token_pos(intptr_t token_pos) const;
5479 void set_type_state(int8_t state) const;
5480
5481 static RawFunctionType* New(Heap::Space space = Heap::kOld);
5482
5483 FINAL_HEAP_OBJECT_IMPLEMENTATION(FunctionType, AbstractType);
5484 friend class Class;
5485 friend class TypeArguments;
5486 };
5487
5488
5405 // A TypeRef is used to break cycles in the representation of recursive types. 5489 // A TypeRef is used to break cycles in the representation of recursive types.
5406 // Its only field is the recursive AbstractType it refers to. 5490 // Its only field is the recursive AbstractType it refers to.
5407 // Note that the cycle always involves type arguments. 5491 // Note that the cycle always involves type arguments.
5408 class TypeRef : public AbstractType { 5492 class TypeRef : public AbstractType {
5409 public: 5493 public:
5410 virtual bool IsFinalized() const { 5494 virtual bool IsFinalized() const {
5411 return AbstractType::Handle(type()).IsFinalized(); 5495 return AbstractType::Handle(type()).IsFinalized();
5412 } 5496 }
5413 virtual bool IsBeingFinalized() const { 5497 virtual bool IsBeingFinalized() const {
5414 return AbstractType::Handle(type()).IsBeingFinalized(); 5498 return AbstractType::Handle(type()).IsBeingFinalized();
5415 } 5499 }
5416 virtual bool IsMalformed() const { 5500 virtual bool IsMalformed() const {
5417 return AbstractType::Handle(type()).IsMalformed(); 5501 return AbstractType::Handle(type()).IsMalformed();
5418 } 5502 }
5419 virtual bool IsMalbounded() const { 5503 virtual bool IsMalbounded() const {
5420 return AbstractType::Handle(type()).IsMalbounded(); 5504 return AbstractType::Handle(type()).IsMalbounded();
5421 } 5505 }
5422 virtual bool IsMalformedOrMalbounded() const { 5506 virtual bool IsMalformedOrMalbounded() const {
5423 return AbstractType::Handle(type()).IsMalformedOrMalbounded(); 5507 return AbstractType::Handle(type()).IsMalformedOrMalbounded();
5424 } 5508 }
5425 virtual bool IsResolved() const { return true; } 5509 virtual bool IsResolved() const { return true; }
5426 virtual bool HasResolvedTypeClass() const { return true; } 5510 virtual bool HasResolvedTypeClass() const {
5511 // Returns false if the ref type is a function type.
5512 return AbstractType::Handle(type()).HasResolvedTypeClass();
5513 }
5427 RawAbstractType* type() const { return raw_ptr()->type_; } 5514 RawAbstractType* type() const { return raw_ptr()->type_; }
5428 void set_type(const AbstractType& value) const; 5515 void set_type(const AbstractType& value) const;
5429 virtual RawClass* type_class() const { 5516 virtual RawClass* type_class() const {
5430 return AbstractType::Handle(type()).type_class(); 5517 return AbstractType::Handle(type()).type_class();
5431 } 5518 }
5432 virtual RawTypeArguments* arguments() const { 5519 virtual RawTypeArguments* arguments() const {
5433 return AbstractType::Handle(type()).arguments(); 5520 return AbstractType::Handle(type()).arguments();
5434 } 5521 }
5435 virtual intptr_t token_pos() const { 5522 virtual intptr_t token_pos() const {
5436 return AbstractType::Handle(type()).token_pos(); 5523 return AbstractType::Handle(type()).token_pos();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
5485 // Upon finalization, the TypeParameter index is changed to reflect its position 5572 // Upon finalization, the TypeParameter index is changed to reflect its position
5486 // as type argument (rather than type parameter) of the parameterized class. 5573 // as type argument (rather than type parameter) of the parameterized class.
5487 // If the type parameter is declared without an extends clause, its bound is set 5574 // If the type parameter is declared without an extends clause, its bound is set
5488 // to the ObjectType. 5575 // to the ObjectType.
5489 class TypeParameter : public AbstractType { 5576 class TypeParameter : public AbstractType {
5490 public: 5577 public:
5491 virtual bool IsFinalized() const { 5578 virtual bool IsFinalized() const {
5492 ASSERT(raw_ptr()->type_state_ != RawTypeParameter::kFinalizedInstantiated); 5579 ASSERT(raw_ptr()->type_state_ != RawTypeParameter::kFinalizedInstantiated);
5493 return raw_ptr()->type_state_ == RawTypeParameter::kFinalizedUninstantiated; 5580 return raw_ptr()->type_state_ == RawTypeParameter::kFinalizedUninstantiated;
5494 } 5581 }
5495 void set_is_finalized() const; 5582 virtual void SetIsFinalized() const;
5496 virtual bool IsBeingFinalized() const { return false; } 5583 virtual bool IsBeingFinalized() const { return false; }
5497 virtual bool IsMalformed() const { return false; } 5584 virtual bool IsMalformed() const { return false; }
5498 virtual bool IsMalbounded() const { return false; } 5585 virtual bool IsMalbounded() const { return false; }
5499 virtual bool IsMalformedOrMalbounded() const { return false; } 5586 virtual bool IsMalformedOrMalbounded() const { return false; }
5500 virtual bool IsResolved() const { return true; } 5587 virtual bool IsResolved() const { return true; }
5501 virtual bool HasResolvedTypeClass() const { return false; } 5588 virtual bool HasResolvedTypeClass() const { return false; }
5502 RawClass* parameterized_class() const { 5589 RawClass* parameterized_class() const {
5503 return raw_ptr()->parameterized_class_; 5590 return raw_ptr()->parameterized_class_;
5504 } 5591 }
5505 RawString* name() const { return raw_ptr()->name_; } 5592 RawString* name() const { return raw_ptr()->name_; }
(...skipping 2155 matching lines...) Expand 10 before | Expand all | Expand 10 after
7661 static const intptr_t kInitialIndexSize = 1 << (kInitialIndexBits + 1); 7748 static const intptr_t kInitialIndexSize = 1 << (kInitialIndexBits + 1);
7662 7749
7663 // Allocate a map, but leave all fields set to null. 7750 // Allocate a map, but leave all fields set to null.
7664 // Used during deserialization (since map might contain itself as key/value). 7751 // Used during deserialization (since map might contain itself as key/value).
7665 static RawLinkedHashMap* NewUninitialized(Heap::Space space = Heap::kNew); 7752 static RawLinkedHashMap* NewUninitialized(Heap::Space space = Heap::kNew);
7666 7753
7667 friend class Class; 7754 friend class Class;
7668 }; 7755 };
7669 7756
7670 7757
7671 class Closure : public AllStatic { 7758 class Closure : public Instance {
7672 public: 7759 public:
7673 static RawFunction* function(const Instance& closure) { 7760 RawFunction* function() const { return raw_ptr()->function_; }
7674 return *FunctionAddr(closure); 7761 void set_function(const Function& function) const {
7762 // TODO(regis): Only used from deferred_objects.cc. Remove once fixed.
7763 StorePointer(&raw_ptr()->function_, function.raw());
7675 } 7764 }
7676 static intptr_t function_offset() { 7765 static intptr_t function_offset() { return OFFSET_OF(RawClosure, function_); }
7677 return static_cast<intptr_t>(kFunctionOffset * kWordSize); 7766
7767 RawContext* context() const { return raw_ptr()->context_; }
7768 void set_context(const Context& context) const {
7769 // TODO(regis): Only used from deferred_objects.cc. Remove once fixed.
7770 StorePointer(&raw_ptr()->context_, context.raw());
7771 }
7772 static intptr_t context_offset() { return OFFSET_OF(RawClosure, context_); }
7773
7774 static intptr_t type_arguments_offset() {
7775 return OFFSET_OF(RawClosure, type_arguments_);
7678 } 7776 }
7679 7777
7680 static RawContext* context(const Instance& closure) { 7778 static intptr_t InstanceSize() {
7681 return *ContextAddr(closure); 7779 return RoundedAllocationSize(sizeof(RawClosure));
7682 }
7683 static intptr_t context_offset() {
7684 return static_cast<intptr_t>(kContextOffset * kWordSize);
7685 } 7780 }
7686 7781
7687 static RawTypeArguments* GetTypeArguments(const Instance& closure) { 7782 // Returns true if all elements are OK for canonicalization.
7688 return *TypeArgumentsAddr(closure); 7783 virtual bool CheckAndCanonicalizeFields(const char** error_str) const {
7689 } 7784 // None of the fields of a closure are instances.
7690 static void SetTypeArguments(const Instance& closure, 7785 return true;
7691 const TypeArguments& value) {
7692 ASSERT(value.IsNull() || value.IsCanonical());
7693 closure.StorePointer(TypeArgumentsAddr(closure), value.raw());
7694 }
7695 static intptr_t type_arguments_offset() {
7696 return static_cast<intptr_t>(kTypeArgumentsOffset * kWordSize);
7697 } 7786 }
7698 7787
7699 static const char* ToCString(const Instance& closure); 7788 static RawClosure* New(const Function& function,
7700 7789 const Context& context,
7701 static intptr_t InstanceSize() { 7790 Heap::Space space = Heap::kNew);
7702 intptr_t size = sizeof(RawInstance) + (kNumFields * kWordSize);
7703 ASSERT(size == Object::RoundedAllocationSize(size));
7704 return size;
7705 }
7706
7707 static RawInstance* New(const Function& function,
7708 const Context& context,
7709 Heap::Space space = Heap::kNew);
7710 7791
7711 private: 7792 private:
7712 static const int kTypeArgumentsOffset = 1; 7793 static RawClosure* New();
7713 static const int kFunctionOffset = 2;
7714 static const int kContextOffset = 3;
7715 static const int kNumFields = 3;
7716 7794
7717 static RawTypeArguments** TypeArgumentsAddr(const Instance& obj) { 7795 FINAL_HEAP_OBJECT_IMPLEMENTATION(Closure, Instance);
7718 ASSERT(obj.IsClosure());
7719 return reinterpret_cast<RawTypeArguments**>(
7720 reinterpret_cast<intptr_t>(obj.raw_ptr()) + type_arguments_offset());
7721 }
7722 static RawFunction** FunctionAddr(const Instance& obj) {
7723 ASSERT(obj.IsClosure());
7724 return reinterpret_cast<RawFunction**>(
7725 reinterpret_cast<intptr_t>(obj.raw_ptr()) + function_offset());
7726 }
7727 static RawContext** ContextAddr(const Instance& obj) {
7728 ASSERT(obj.IsClosure());
7729 return reinterpret_cast<RawContext**>(
7730 reinterpret_cast<intptr_t>(obj.raw_ptr()) + context_offset());
7731 }
7732 static void set_function(const Instance& closure,
7733 const Function& value) {
7734 closure.StorePointer(FunctionAddr(closure), value.raw());
7735 }
7736 static void set_context(const Instance& closure,
7737 const Context& value) {
7738 closure.StorePointer(ContextAddr(closure), value.raw());
7739 }
7740 static intptr_t NextFieldOffset() {
7741 // Indicates this class cannot be extended by dart code.
7742 return -kWordSize;
7743 }
7744 static RawFunction* GetFunction(RawObject* obj) {
7745 return *(reinterpret_cast<RawFunction**>(
7746 reinterpret_cast<intptr_t>(obj->ptr()) + function_offset()));
7747 }
7748
7749 friend class Class; 7796 friend class Class;
7750 friend class SnapshotWriter;
7751 }; 7797 };
7752 7798
7753 7799
7754 class Capability : public Instance { 7800 class Capability : public Instance {
7755 public: 7801 public:
7756 uint64_t Id() const { return raw_ptr()->id_; } 7802 uint64_t Id() const { return raw_ptr()->id_; }
7757 7803
7758 static intptr_t InstanceSize() { 7804 static intptr_t InstanceSize() {
7759 return RoundedAllocationSize(sizeof(RawCapability)); 7805 return RoundedAllocationSize(sizeof(RawCapability));
7760 } 7806 }
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
8244 8290
8245 8291
8246 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, 8292 RawObject* MegamorphicCache::GetTargetFunction(const Array& array,
8247 intptr_t index) { 8293 intptr_t index) {
8248 return array.At((index * kEntryLength) + kTargetFunctionIndex); 8294 return array.At((index * kEntryLength) + kTargetFunctionIndex);
8249 } 8295 }
8250 8296
8251 } // namespace dart 8297 } // namespace dart
8252 8298
8253 #endif // VM_OBJECT_H_ 8299 #endif // VM_OBJECT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698