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

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: sync 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
« no previous file with comments | « runtime/vm/native_arguments.h ('k') | runtime/vm/object.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
4956 4942
4957 RawObject* GetField(const Field& field) const { 4943 RawObject* GetField(const Field& field) const {
4958 return *FieldAddr(field); 4944 return *FieldAddr(field);
4959 } 4945 }
4960 4946
4961 void SetField(const Field& field, const Object& value) const { 4947 void SetField(const Field& field, const Object& value) const {
4962 field.RecordStore(value); 4948 field.RecordStore(value);
4963 StorePointer(FieldAddr(field), value.raw()); 4949 StorePointer(FieldAddr(field), value.raw());
4964 } 4950 }
4965 4951
4966 RawType* GetType() const; 4952 RawAbstractType* GetType() const;
4967 4953
4968 virtual RawTypeArguments* GetTypeArguments() const; 4954 virtual RawTypeArguments* GetTypeArguments() const;
4969 virtual void SetTypeArguments(const TypeArguments& value) const; 4955 virtual void SetTypeArguments(const TypeArguments& value) const;
4970 4956
4971 // Check if the type of this instance is a subtype of the given type. 4957 // Check if the type of this instance is a subtype of the given type.
4972 bool IsInstanceOf(const AbstractType& type, 4958 bool IsInstanceOf(const AbstractType& type,
4973 const TypeArguments& type_instantiator, 4959 const TypeArguments& type_instantiator,
4974 Error* bound_error) const; 4960 Error* bound_error) const;
4975 4961
4976 bool IsValidNativeIndex(int index) const { 4962 bool IsValidNativeIndex(int index) const {
4977 return ((index >= 0) && (index < clazz()->ptr()->num_native_fields_)); 4963 return ((index >= 0) && (index < clazz()->ptr()->num_native_fields_));
4978 } 4964 }
4979 4965
4980 intptr_t* NativeFieldsDataAddr() const; 4966 intptr_t* NativeFieldsDataAddr() const;
4981 inline intptr_t GetNativeField(int index) const; 4967 inline intptr_t GetNativeField(int index) const;
4982 inline void GetNativeFields(uint16_t num_fields, 4968 inline void GetNativeFields(uint16_t num_fields,
4983 intptr_t* field_values) const; 4969 intptr_t* field_values) const;
4984 void SetNativeFields(uint16_t num_fields, 4970 void SetNativeFields(uint16_t num_fields,
4985 const intptr_t* field_values) const; 4971 const intptr_t* field_values) const;
4986 4972
4987 uint16_t NumNativeFields() const { 4973 uint16_t NumNativeFields() const {
4988 return clazz()->ptr()->num_native_fields_; 4974 return clazz()->ptr()->num_native_fields_;
4989 } 4975 }
4990 4976
4991 void SetNativeField(int index, intptr_t value) const; 4977 void SetNativeField(int index, intptr_t value) const;
4992 4978
4993 // Returns true if the instance is a closure object.
4994 bool IsClosure() const;
4995
4996 // If the instance is a callable object, i.e. a closure or the instance of a 4979 // If the instance is a callable object, i.e. a closure or the instance of a
4997 // class implementing a 'call' method, return true and set the function 4980 // class implementing a 'call' method, return true and set the function
4998 // (if not NULL) to call. 4981 // (if not NULL) to call.
4999 bool IsCallable(Function* function) const; 4982 bool IsCallable(Function* function) const;
5000 4983
5001 // Evaluate the given expression as if it appeared in an instance 4984 // Evaluate the given expression as if it appeared in an instance
5002 // method of this instance and return the resulting value, or an 4985 // method of this instance and return the resulting value, or an
5003 // error object if evaluating the expression fails. The method has 4986 // error object if evaluating the expression fails. The method has
5004 // the formal parameters given in param_names, and is invoked with 4987 // the formal parameters given in param_names, and is invoked with
5005 // the argument values given in param_values. 4988 // the argument values given in param_values.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
5112 FINAL_HEAP_OBJECT_IMPLEMENTATION(LibraryPrefix, Instance); 5095 FINAL_HEAP_OBJECT_IMPLEMENTATION(LibraryPrefix, Instance);
5113 friend class Class; 5096 friend class Class;
5114 }; 5097 };
5115 5098
5116 5099
5117 // AbstractType is an abstract superclass. 5100 // AbstractType is an abstract superclass.
5118 // Subclasses of AbstractType are Type and TypeParameter. 5101 // Subclasses of AbstractType are Type and TypeParameter.
5119 class AbstractType : public Instance { 5102 class AbstractType : public Instance {
5120 public: 5103 public:
5121 virtual bool IsFinalized() const; 5104 virtual bool IsFinalized() const;
5105 virtual void SetIsFinalized() const;
5122 virtual bool IsBeingFinalized() const; 5106 virtual bool IsBeingFinalized() const;
5107 virtual void SetIsBeingFinalized() const;
5123 virtual bool IsMalformed() const; 5108 virtual bool IsMalformed() const;
5124 virtual bool IsMalbounded() const; 5109 virtual bool IsMalbounded() const;
5125 virtual bool IsMalformedOrMalbounded() const; 5110 virtual bool IsMalformedOrMalbounded() const;
5126 virtual RawLanguageError* error() const; 5111 virtual RawLanguageError* error() const;
5127 virtual void set_error(const LanguageError& value) const; 5112 virtual void set_error(const LanguageError& value) const;
5128 virtual bool IsResolved() const; 5113 virtual bool IsResolved() const;
5114 virtual void SetIsResolved() const;
5129 virtual bool HasResolvedTypeClass() const; 5115 virtual bool HasResolvedTypeClass() const;
5130 virtual RawClass* type_class() const; 5116 virtual RawClass* type_class() const;
5131 virtual RawUnresolvedClass* unresolved_class() const; 5117 virtual RawUnresolvedClass* unresolved_class() const;
5132 virtual RawTypeArguments* arguments() const; 5118 virtual RawTypeArguments* arguments() const;
5119 virtual void set_arguments(const TypeArguments& value) const;
5133 virtual intptr_t token_pos() const; 5120 virtual intptr_t token_pos() const;
5134 virtual bool IsInstantiated(TrailPtr trail = NULL) const; 5121 virtual bool IsInstantiated(TrailPtr trail = NULL) const;
5135 virtual bool CanonicalizeEquals(const Instance& other) const { 5122 virtual bool CanonicalizeEquals(const Instance& other) const {
5136 return Equals(other); 5123 return Equals(other);
5137 } 5124 }
5138 virtual bool Equals(const Instance& other) const { 5125 virtual bool Equals(const Instance& other) const {
5139 return IsEquivalent(other); 5126 return IsEquivalent(other);
5140 } 5127 }
5141 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const; 5128 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const;
5142 virtual bool IsRecursive() const; 5129 virtual bool IsRecursive() const;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
5237 5224
5238 // Check if this type represents the 'num' type. 5225 // Check if this type represents the 'num' type.
5239 bool IsNumberType() const; 5226 bool IsNumberType() const;
5240 5227
5241 // Check if this type represents the '_Smi' type. 5228 // Check if this type represents the '_Smi' type.
5242 bool IsSmiType() const; 5229 bool IsSmiType() const;
5243 5230
5244 // Check if this type represents the 'String' type. 5231 // Check if this type represents the 'String' type.
5245 bool IsStringType() const; 5232 bool IsStringType() const;
5246 5233
5247 // Check if this type represents the 'Function' type. 5234 // Check if this type represents the Dart 'Function' type.
5248 bool IsFunctionType() const; 5235 bool IsDartFunctionType() const;
5249 5236
5250 // Check the subtype relationship. 5237 // Check the subtype relationship.
5251 bool IsSubtypeOf(const AbstractType& other, 5238 bool IsSubtypeOf(const AbstractType& other,
5252 Error* bound_error, 5239 Error* bound_error,
5253 Heap::Space space = Heap::kNew) const { 5240 Heap::Space space = Heap::kNew) const {
5254 return TypeTest(kIsSubtypeOf, other, bound_error, space); 5241 return TypeTest(kIsSubtypeOf, other, bound_error, space);
5255 } 5242 }
5256 5243
5257 // Check the 'more specific' relationship. 5244 // Check the 'more specific' relationship.
5258 bool IsMoreSpecificThan(const AbstractType& other, 5245 bool IsMoreSpecificThan(const AbstractType& other,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
5290 class Type : public AbstractType { 5277 class Type : public AbstractType {
5291 public: 5278 public:
5292 static intptr_t type_class_offset() { 5279 static intptr_t type_class_offset() {
5293 return OFFSET_OF(RawType, type_class_); 5280 return OFFSET_OF(RawType, type_class_);
5294 } 5281 }
5295 virtual bool IsFinalized() const { 5282 virtual bool IsFinalized() const {
5296 return 5283 return
5297 (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) || 5284 (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) ||
5298 (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated); 5285 (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated);
5299 } 5286 }
5300 void SetIsFinalized() const; 5287 virtual void SetIsFinalized() const;
5301 void ResetIsFinalized() const; // Ignore current state and set again.
5302 virtual bool IsBeingFinalized() const { 5288 virtual bool IsBeingFinalized() const {
5303 return raw_ptr()->type_state_ == RawType::kBeingFinalized; 5289 return raw_ptr()->type_state_ == RawType::kBeingFinalized;
5304 } 5290 }
5305 void set_is_being_finalized() const; 5291 virtual void SetIsBeingFinalized() const;
5306 virtual bool IsMalformed() const; 5292 virtual bool IsMalformed() const;
5307 virtual bool IsMalbounded() const; 5293 virtual bool IsMalbounded() const;
5308 virtual bool IsMalformedOrMalbounded() const; 5294 virtual bool IsMalformedOrMalbounded() const;
5309 virtual RawLanguageError* error() const { return raw_ptr()->error_; } 5295 virtual RawLanguageError* error() const { return raw_ptr()->error_; }
5310 virtual void set_error(const LanguageError& value) const; 5296 virtual void set_error(const LanguageError& value) const;
5311 virtual bool IsResolved() const { 5297 virtual bool IsResolved() const {
5312 return raw_ptr()->type_state_ >= RawType::kResolved; 5298 return raw_ptr()->type_state_ >= RawType::kResolved;
5313 } 5299 }
5314 void set_is_resolved() const; 5300 virtual void SetIsResolved() const;
5315 virtual bool HasResolvedTypeClass() const; // Own type class resolved. 5301 virtual bool HasResolvedTypeClass() const; // Own type class resolved.
5316 virtual RawClass* type_class() const; 5302 virtual RawClass* type_class() const;
5317 void set_type_class(const Object& value) const; 5303 void set_type_class(const Object& value) const;
5318 virtual RawUnresolvedClass* unresolved_class() const; 5304 virtual RawUnresolvedClass* unresolved_class() const;
5319 virtual RawTypeArguments* arguments() const; 5305 virtual RawTypeArguments* arguments() const { return raw_ptr()->arguments_; }
5320 void set_arguments(const TypeArguments& value) const; 5306 virtual void set_arguments(const TypeArguments& value) const;
5321 virtual intptr_t token_pos() const { return raw_ptr()->token_pos_; } 5307 virtual intptr_t token_pos() const { return raw_ptr()->token_pos_; }
5322 virtual bool IsInstantiated(TrailPtr trail = NULL) const; 5308 virtual bool IsInstantiated(TrailPtr trail = NULL) const;
5323 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const; 5309 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const;
5324 virtual bool IsRecursive() const; 5310 virtual bool IsRecursive() const;
5325 virtual RawAbstractType* InstantiateFrom( 5311 virtual RawAbstractType* InstantiateFrom(
5326 const TypeArguments& instantiator_type_arguments, 5312 const TypeArguments& instantiator_type_arguments,
5327 Error* bound_error, 5313 Error* bound_error,
5328 TrailPtr trail = NULL, 5314 TrailPtr trail = NULL,
5329 Heap::Space space = Heap::kNew) const; 5315 Heap::Space space = Heap::kNew) const;
5330 virtual RawAbstractType* CloneUnfinalized() const; 5316 virtual RawAbstractType* CloneUnfinalized() const;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
5400 void set_type_state(int8_t state) const; 5386 void set_type_state(int8_t state) const;
5401 5387
5402 static RawType* New(Heap::Space space = Heap::kOld); 5388 static RawType* New(Heap::Space space = Heap::kOld);
5403 5389
5404 FINAL_HEAP_OBJECT_IMPLEMENTATION(Type, AbstractType); 5390 FINAL_HEAP_OBJECT_IMPLEMENTATION(Type, AbstractType);
5405 friend class Class; 5391 friend class Class;
5406 friend class TypeArguments; 5392 friend class TypeArguments;
5407 }; 5393 };
5408 5394
5409 5395
5396 // TODO(regis): FunctionType is very similar to Type. Instead of a separate
5397 // class FunctionType, we could consider an object of class Type as representing
5398 // a function type if it has a non-null function (signature) field.
5399 // In order to save space, we could reuse the error_ field? A malformed or
5400 // malbounded function type would lose its function reference, but the error
5401 // string would contain relevant info.
5402
5403 // A FunctionType describes the signature of a function, i.e. the result type
5404 // and formal parameter types of the function, as well as the names of optional
5405 // named formal parameters.
5406 // If these types refer to type parameters of a class in scope, the function
5407 // type is generic. A generic function type may be instantiated by a type
5408 // argument vector.
5409 // Therefore, a FunctionType consists of a scope class, a type argument vector,
5410 // and a signature.
5411 // The scope class is either a generic class (or generic typedef) declaring the
5412 // type parameters referred to by the signature, or class _Closure in the
5413 // non-generic case (including the non-generic typedef case).
5414 // The type arguments specify an instantiation of the generic signature (null in
5415 // the non-generic case).
5416 // The signature is a reference to an actual closure function (kClosureFunction)
5417 // or to a signature function (kSignatureFunction).
5418 // Since typedefs cannot refer to themselves, directly or indirectly, a
5419 // FunctionType cannot be recursive. Only individual formal parameter types can.
5420 class FunctionType : public AbstractType {
5421 public:
5422 virtual bool IsFinalized() const {
5423 return
5424 (raw_ptr()->type_state_ == RawFunctionType::kFinalizedInstantiated) ||
5425 (raw_ptr()->type_state_ == RawFunctionType::kFinalizedUninstantiated);
5426 }
5427 virtual void SetIsFinalized() const;
5428 void ResetIsFinalized() const; // Ignore current state and set again.
5429 virtual bool IsBeingFinalized() const {
5430 return raw_ptr()->type_state_ == RawFunctionType::kBeingFinalized;
5431 }
5432 virtual void SetIsBeingFinalized() const;
5433 virtual bool IsMalformed() const;
5434 virtual bool IsMalbounded() const;
5435 virtual bool IsMalformedOrMalbounded() const;
5436 virtual RawLanguageError* error() const { return raw_ptr()->error_; }
5437 virtual void set_error(const LanguageError& value) const;
5438 virtual bool IsResolved() const {
5439 return raw_ptr()->type_state_ >= RawFunctionType::kResolved;
5440 }
5441 virtual void SetIsResolved() const;
5442 // The scope class of a FunctionType is always resolved. It has no actual
5443 // type class. Returning false is important for the type testers to work, e.g.
5444 // IsDynamicType(), IsBoolType(), etc...
5445 virtual bool HasResolvedTypeClass() const { return false; }
5446 // Return scope_class from virtual type_class() to factorize finalization
5447 // with Type, also a parameterized type.
5448 virtual RawClass* type_class() const { return scope_class(); }
5449 RawClass* scope_class() const { return raw_ptr()->scope_class_; }
5450 void set_scope_class(const Class& value) const;
5451 virtual RawTypeArguments* arguments() const { return raw_ptr()->arguments_; }
5452 virtual void set_arguments(const TypeArguments& value) const;
5453 RawFunction* signature() const { return raw_ptr()->signature_; }
5454 virtual intptr_t token_pos() const { return raw_ptr()->token_pos_; }
5455 virtual bool IsInstantiated(TrailPtr trail = NULL) const;
5456 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const;
5457 virtual bool IsRecursive() const;
5458 virtual RawAbstractType* InstantiateFrom(
5459 const TypeArguments& instantiator_type_arguments,
5460 Error* malformed_error,
5461 TrailPtr trail = NULL,
5462 Heap::Space space = Heap::kNew) const;
5463 virtual RawAbstractType* CloneUnfinalized() const;
5464 virtual RawAbstractType* CloneUninstantiated(
5465 const Class& new_owner,
5466 TrailPtr trail = NULL) const;
5467 virtual RawAbstractType* Canonicalize(TrailPtr trail = NULL) const;
5468
5469 virtual intptr_t Hash() const;
5470
5471 static intptr_t InstanceSize() {
5472 return RoundedAllocationSize(sizeof(RawFunctionType));
5473 }
5474
5475 static RawFunctionType* New(const Class& scope_class,
5476 const TypeArguments& arguments,
5477 const Function& signature,
5478 intptr_t token_pos,
5479 Heap::Space space = Heap::kOld);
5480
5481 private:
5482 void set_signature(const Function& value) const;
5483 void set_token_pos(intptr_t token_pos) const;
5484 void set_type_state(int8_t state) const;
5485
5486 static RawFunctionType* New(Heap::Space space = Heap::kOld);
5487
5488 FINAL_HEAP_OBJECT_IMPLEMENTATION(FunctionType, AbstractType);
5489 friend class Class;
5490 friend class TypeArguments;
5491 };
5492
5493
5410 // A TypeRef is used to break cycles in the representation of recursive types. 5494 // A TypeRef is used to break cycles in the representation of recursive types.
5411 // Its only field is the recursive AbstractType it refers to. 5495 // Its only field is the recursive AbstractType it refers to.
5412 // Note that the cycle always involves type arguments. 5496 // Note that the cycle always involves type arguments.
5413 class TypeRef : public AbstractType { 5497 class TypeRef : public AbstractType {
5414 public: 5498 public:
5415 virtual bool IsFinalized() const { 5499 virtual bool IsFinalized() const {
5416 return AbstractType::Handle(type()).IsFinalized(); 5500 return AbstractType::Handle(type()).IsFinalized();
5417 } 5501 }
5418 virtual bool IsBeingFinalized() const { 5502 virtual bool IsBeingFinalized() const {
5419 return AbstractType::Handle(type()).IsBeingFinalized(); 5503 return AbstractType::Handle(type()).IsBeingFinalized();
5420 } 5504 }
5421 virtual bool IsMalformed() const { 5505 virtual bool IsMalformed() const {
5422 return AbstractType::Handle(type()).IsMalformed(); 5506 return AbstractType::Handle(type()).IsMalformed();
5423 } 5507 }
5424 virtual bool IsMalbounded() const { 5508 virtual bool IsMalbounded() const {
5425 return AbstractType::Handle(type()).IsMalbounded(); 5509 return AbstractType::Handle(type()).IsMalbounded();
5426 } 5510 }
5427 virtual bool IsMalformedOrMalbounded() const { 5511 virtual bool IsMalformedOrMalbounded() const {
5428 return AbstractType::Handle(type()).IsMalformedOrMalbounded(); 5512 return AbstractType::Handle(type()).IsMalformedOrMalbounded();
5429 } 5513 }
5430 virtual bool IsResolved() const { return true; } 5514 virtual bool IsResolved() const { return true; }
5431 virtual bool HasResolvedTypeClass() const { return true; } 5515 virtual bool HasResolvedTypeClass() const {
5516 // Returns false if the ref type is a function type.
5517 return AbstractType::Handle(type()).HasResolvedTypeClass();
5518 }
5432 RawAbstractType* type() const { return raw_ptr()->type_; } 5519 RawAbstractType* type() const { return raw_ptr()->type_; }
5433 void set_type(const AbstractType& value) const; 5520 void set_type(const AbstractType& value) const;
5434 virtual RawClass* type_class() const { 5521 virtual RawClass* type_class() const {
5435 return AbstractType::Handle(type()).type_class(); 5522 return AbstractType::Handle(type()).type_class();
5436 } 5523 }
5437 virtual RawTypeArguments* arguments() const { 5524 virtual RawTypeArguments* arguments() const {
5438 return AbstractType::Handle(type()).arguments(); 5525 return AbstractType::Handle(type()).arguments();
5439 } 5526 }
5440 virtual intptr_t token_pos() const { 5527 virtual intptr_t token_pos() const {
5441 return AbstractType::Handle(type()).token_pos(); 5528 return AbstractType::Handle(type()).token_pos();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
5490 // Upon finalization, the TypeParameter index is changed to reflect its position 5577 // Upon finalization, the TypeParameter index is changed to reflect its position
5491 // as type argument (rather than type parameter) of the parameterized class. 5578 // as type argument (rather than type parameter) of the parameterized class.
5492 // If the type parameter is declared without an extends clause, its bound is set 5579 // If the type parameter is declared without an extends clause, its bound is set
5493 // to the ObjectType. 5580 // to the ObjectType.
5494 class TypeParameter : public AbstractType { 5581 class TypeParameter : public AbstractType {
5495 public: 5582 public:
5496 virtual bool IsFinalized() const { 5583 virtual bool IsFinalized() const {
5497 ASSERT(raw_ptr()->type_state_ != RawTypeParameter::kFinalizedInstantiated); 5584 ASSERT(raw_ptr()->type_state_ != RawTypeParameter::kFinalizedInstantiated);
5498 return raw_ptr()->type_state_ == RawTypeParameter::kFinalizedUninstantiated; 5585 return raw_ptr()->type_state_ == RawTypeParameter::kFinalizedUninstantiated;
5499 } 5586 }
5500 void set_is_finalized() const; 5587 virtual void SetIsFinalized() const;
5501 virtual bool IsBeingFinalized() const { return false; } 5588 virtual bool IsBeingFinalized() const { return false; }
5502 virtual bool IsMalformed() const { return false; } 5589 virtual bool IsMalformed() const { return false; }
5503 virtual bool IsMalbounded() const { return false; } 5590 virtual bool IsMalbounded() const { return false; }
5504 virtual bool IsMalformedOrMalbounded() const { return false; } 5591 virtual bool IsMalformedOrMalbounded() const { return false; }
5505 virtual bool IsResolved() const { return true; } 5592 virtual bool IsResolved() const { return true; }
5506 virtual bool HasResolvedTypeClass() const { return false; } 5593 virtual bool HasResolvedTypeClass() const { return false; }
5507 RawClass* parameterized_class() const { 5594 RawClass* parameterized_class() const {
5508 return raw_ptr()->parameterized_class_; 5595 return raw_ptr()->parameterized_class_;
5509 } 5596 }
5510 RawString* name() const { return raw_ptr()->name_; } 5597 RawString* name() const { return raw_ptr()->name_; }
(...skipping 2155 matching lines...) Expand 10 before | Expand all | Expand 10 after
7666 static const intptr_t kInitialIndexSize = 1 << (kInitialIndexBits + 1); 7753 static const intptr_t kInitialIndexSize = 1 << (kInitialIndexBits + 1);
7667 7754
7668 // Allocate a map, but leave all fields set to null. 7755 // Allocate a map, but leave all fields set to null.
7669 // Used during deserialization (since map might contain itself as key/value). 7756 // Used during deserialization (since map might contain itself as key/value).
7670 static RawLinkedHashMap* NewUninitialized(Heap::Space space = Heap::kNew); 7757 static RawLinkedHashMap* NewUninitialized(Heap::Space space = Heap::kNew);
7671 7758
7672 friend class Class; 7759 friend class Class;
7673 }; 7760 };
7674 7761
7675 7762
7676 class Closure : public AllStatic { 7763 class Closure : public Instance {
7677 public: 7764 public:
7678 static RawFunction* function(const Instance& closure) { 7765 RawFunction* function() const { return raw_ptr()->function_; }
7679 return *FunctionAddr(closure); 7766 void set_function(const Function& function) const {
7767 // TODO(regis): Only used from deferred_objects.cc. Remove once fixed.
7768 StorePointer(&raw_ptr()->function_, function.raw());
7680 } 7769 }
7681 static intptr_t function_offset() { 7770 static intptr_t function_offset() { return OFFSET_OF(RawClosure, function_); }
7682 return static_cast<intptr_t>(kFunctionOffset * kWordSize); 7771
7772 RawContext* context() const { return raw_ptr()->context_; }
7773 void set_context(const Context& context) const {
7774 // TODO(regis): Only used from deferred_objects.cc. Remove once fixed.
7775 StorePointer(&raw_ptr()->context_, context.raw());
7776 }
7777 static intptr_t context_offset() { return OFFSET_OF(RawClosure, context_); }
7778
7779 static intptr_t type_arguments_offset() {
7780 return OFFSET_OF(RawClosure, type_arguments_);
7683 } 7781 }
7684 7782
7685 static RawContext* context(const Instance& closure) { 7783 static intptr_t InstanceSize() {
7686 return *ContextAddr(closure); 7784 return RoundedAllocationSize(sizeof(RawClosure));
7687 }
7688 static intptr_t context_offset() {
7689 return static_cast<intptr_t>(kContextOffset * kWordSize);
7690 } 7785 }
7691 7786
7692 static RawTypeArguments* GetTypeArguments(const Instance& closure) { 7787 // Returns true if all elements are OK for canonicalization.
7693 return *TypeArgumentsAddr(closure); 7788 virtual bool CheckAndCanonicalizeFields(const char** error_str) const {
7694 } 7789 // None of the fields of a closure are instances.
7695 static void SetTypeArguments(const Instance& closure, 7790 return true;
7696 const TypeArguments& value) {
7697 ASSERT(value.IsNull() || value.IsCanonical());
7698 closure.StorePointer(TypeArgumentsAddr(closure), value.raw());
7699 }
7700 static intptr_t type_arguments_offset() {
7701 return static_cast<intptr_t>(kTypeArgumentsOffset * kWordSize);
7702 } 7791 }
7703 7792
7704 static const char* ToCString(const Instance& closure); 7793 static RawClosure* New(const Function& function,
7705 7794 const Context& context,
7706 static intptr_t InstanceSize() { 7795 Heap::Space space = Heap::kNew);
7707 intptr_t size = sizeof(RawInstance) + (kNumFields * kWordSize);
7708 ASSERT(size == Object::RoundedAllocationSize(size));
7709 return size;
7710 }
7711
7712 static RawInstance* New(const Function& function,
7713 const Context& context,
7714 Heap::Space space = Heap::kNew);
7715 7796
7716 private: 7797 private:
7717 static const int kTypeArgumentsOffset = 1; 7798 static RawClosure* New();
7718 static const int kFunctionOffset = 2;
7719 static const int kContextOffset = 3;
7720 static const int kNumFields = 3;
7721 7799
7722 static RawTypeArguments** TypeArgumentsAddr(const Instance& obj) { 7800 FINAL_HEAP_OBJECT_IMPLEMENTATION(Closure, Instance);
7723 ASSERT(obj.IsClosure());
7724 return reinterpret_cast<RawTypeArguments**>(
7725 reinterpret_cast<intptr_t>(obj.raw_ptr()) + type_arguments_offset());
7726 }
7727 static RawFunction** FunctionAddr(const Instance& obj) {
7728 ASSERT(obj.IsClosure());
7729 return reinterpret_cast<RawFunction**>(
7730 reinterpret_cast<intptr_t>(obj.raw_ptr()) + function_offset());
7731 }
7732 static RawContext** ContextAddr(const Instance& obj) {
7733 ASSERT(obj.IsClosure());
7734 return reinterpret_cast<RawContext**>(
7735 reinterpret_cast<intptr_t>(obj.raw_ptr()) + context_offset());
7736 }
7737 static void set_function(const Instance& closure,
7738 const Function& value) {
7739 closure.StorePointer(FunctionAddr(closure), value.raw());
7740 }
7741 static void set_context(const Instance& closure,
7742 const Context& value) {
7743 closure.StorePointer(ContextAddr(closure), value.raw());
7744 }
7745 static intptr_t NextFieldOffset() {
7746 // Indicates this class cannot be extended by dart code.
7747 return -kWordSize;
7748 }
7749 static RawFunction* GetFunction(RawObject* obj) {
7750 return *(reinterpret_cast<RawFunction**>(
7751 reinterpret_cast<intptr_t>(obj->ptr()) + function_offset()));
7752 }
7753
7754 friend class Class; 7801 friend class Class;
7755 friend class SnapshotWriter;
7756 }; 7802 };
7757 7803
7758 7804
7759 class Capability : public Instance { 7805 class Capability : public Instance {
7760 public: 7806 public:
7761 uint64_t Id() const { return raw_ptr()->id_; } 7807 uint64_t Id() const { return raw_ptr()->id_; }
7762 7808
7763 static intptr_t InstanceSize() { 7809 static intptr_t InstanceSize() {
7764 return RoundedAllocationSize(sizeof(RawCapability)); 7810 return RoundedAllocationSize(sizeof(RawCapability));
7765 } 7811 }
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
8249 8295
8250 8296
8251 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, 8297 RawObject* MegamorphicCache::GetTargetFunction(const Array& array,
8252 intptr_t index) { 8298 intptr_t index) {
8253 return array.At((index * kEntryLength) + kTargetFunctionIndex); 8299 return array.At((index * kEntryLength) + kTargetFunctionIndex);
8254 } 8300 }
8255 8301
8256 } // namespace dart 8302 } // namespace dart
8257 8303
8258 #endif // VM_OBJECT_H_ 8304 #endif // VM_OBJECT_H_
OLDNEW
« no previous file with comments | « runtime/vm/native_arguments.h ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698