| Index: runtime/vm/object.h
|
| diff --git a/runtime/vm/object.h b/runtime/vm/object.h
|
| index 4271a58f28d9962cb82ce48ebf1145cc89adfd1b..9a8d743be1420fc0b17b946727c8fc131bb14d34 100644
|
| --- a/runtime/vm/object.h
|
| +++ b/runtime/vm/object.h
|
| @@ -1102,7 +1102,7 @@ class Class : public Object {
|
| bool IsObjectClass() const { return id() == kInstanceCid; }
|
|
|
| // Check if this class represents the 'Function' class.
|
| - bool IsFunctionClass() const;
|
| + bool IsDartFunctionClass() const;
|
|
|
| // Check if this class represents the 'Closure' class.
|
| bool IsClosureClass() const { return id() == kClosureCid; }
|
| @@ -1514,7 +1514,6 @@ class Class : public Object {
|
| friend class Instance;
|
| friend class Object;
|
| friend class Type;
|
| - friend class FunctionType;
|
| friend class Intrinsifier;
|
| friend class Precompiler;
|
| };
|
| @@ -2147,16 +2146,16 @@ class Function : public Object {
|
|
|
| // Return the type of this function's signature. It may not be canonical yet.
|
| // For example, if this function has a signature of the form
|
| - // '(T, [b: B, c: C]) => R', where 'T' and 'R' are type parameters of the
|
| + // '(T, [B, C]) => R', where 'T' and 'R' are type parameters of the
|
| // owner class of this function, then its signature type is a parameterized
|
| - // FunctionType with uninstantiated type arguments 'T' and 'R' as elements of
|
| + // function type with uninstantiated type arguments 'T' and 'R' as elements of
|
| // its type argument vector.
|
| - RawFunctionType* SignatureType() const;
|
| + RawType* SignatureType() const;
|
|
|
| // Update the signature type (with a canonical version).
|
| - void SetSignatureType(const FunctionType& value) const;
|
| + void SetSignatureType(const Type& value) const;
|
|
|
| - // Build a string of the form 'C<T, R>(T, {b: B, c: C}) => R' representing the
|
| + // Build a string of the form 'C<T, R>(T, {B b, C c}) => R' representing the
|
| // internal signature of the given function. In this example, T and R are
|
| // type parameters of class C, the owner of the function.
|
| RawString* Signature() const {
|
| @@ -2164,7 +2163,7 @@ class Function : public Object {
|
| return BuildSignature(instantiate, kInternalName, TypeArguments::Handle());
|
| }
|
|
|
| - // Build a string of the form '(T, {b: B, c: C}) => R' representing the
|
| + // Build a string of the form '(T, {B b, C c}) => R' representing the
|
| // user visible signature of the given function. In this example, T and R are
|
| // type parameters of class C, the owner of the function, also called the
|
| // scope class of the function type.
|
| @@ -2176,9 +2175,9 @@ class Function : public Object {
|
| instantiate, kUserVisibleName, TypeArguments::Handle());
|
| }
|
|
|
| - // Build a string of the form '(A, {b: B, c: C}) => D' representing the
|
| + // Build a string of the form '(A, {B b, C c}) => D' representing the
|
| // signature of the given function, where all generic types (e.g. '<T, R>' in
|
| - // 'C<T, R>(T, {b: B, c: C}) => R') are instantiated using the given
|
| + // 'C<T, R>(T, {B b, C c}) => R') are instantiated using the given
|
| // instantiator type argument vector of a C instance (e.g. '<A, D>').
|
| RawString* InstantiatedSignatureFrom(const TypeArguments& instantiator,
|
| NameVisibility name_visibility) const {
|
| @@ -2190,7 +2189,7 @@ class Function : public Object {
|
| // does not involve generic parameter types or generic result type.
|
| bool HasInstantiatedSignature() const;
|
|
|
| - // Build a string of the form 'T, {b: B, c: C} representing the user
|
| + // Build a string of the form 'T, {B b, C c}' representing the user
|
| // visible formal parameters of the function.
|
| RawString* UserVisibleFormalParameters() const;
|
|
|
| @@ -2868,8 +2867,8 @@ class ClosureData: public Object {
|
| void set_parent_function(const Function& value) const;
|
|
|
| // Signature type of this closure function.
|
| - RawFunctionType* signature_type() const { return raw_ptr()->signature_type_; }
|
| - void set_signature_type(const FunctionType& value) const;
|
| + RawType* signature_type() const { return raw_ptr()->signature_type_; }
|
| + void set_signature_type(const Type& value) const;
|
|
|
| RawInstance* implicit_static_closure() const {
|
| return raw_ptr()->closure_;
|
| @@ -5330,6 +5329,9 @@ class AbstractType : public Instance {
|
| virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const;
|
| virtual bool IsRecursive() const;
|
|
|
| + // Check if this type represents a function type.
|
| + virtual bool IsFunctionType() const { return false; }
|
| +
|
| // Instantiate this type using the given type argument vector.
|
| // Return a new type, or return 'this' if it is already instantiated.
|
| // If bound_error is not NULL, it may be set to reflect a bound error.
|
| @@ -5405,7 +5407,9 @@ class AbstractType : public Instance {
|
|
|
| // Check if this type represents the 'dynamic' type.
|
| bool IsDynamicType() const {
|
| - return HasResolvedTypeClass() && (type_class() == Object::dynamic_class());
|
| + return !IsFunctionType() &&
|
| + HasResolvedTypeClass() &&
|
| + (type_class() == Object::dynamic_class());
|
| }
|
|
|
| // Check if this type represents the 'Null' type.
|
| @@ -5413,12 +5417,15 @@ class AbstractType : public Instance {
|
|
|
| // Check if this type represents the 'void' type.
|
| bool IsVoidType() const {
|
| - return HasResolvedTypeClass() && (type_class() == Object::void_class());
|
| + return !IsFunctionType() &&
|
| + HasResolvedTypeClass() &&
|
| + (type_class() == Object::void_class());
|
| }
|
|
|
| bool IsObjectType() const {
|
| - return HasResolvedTypeClass() &&
|
| - Class::Handle(type_class()).IsObjectClass();
|
| + return !IsFunctionType() &&
|
| + HasResolvedTypeClass() &&
|
| + Class::Handle(type_class()).IsObjectClass();
|
| }
|
|
|
| // Check if this type represents the 'bool' type.
|
| @@ -5506,6 +5513,7 @@ class Type : public AbstractType {
|
| (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated);
|
| }
|
| virtual void SetIsFinalized() const;
|
| + void ResetIsFinalized() const; // Ignore current state and set again.
|
| virtual bool IsBeingFinalized() const {
|
| return raw_ptr()->type_state_ == RawType::kBeingFinalized;
|
| }
|
| @@ -5513,7 +5521,7 @@ class Type : public AbstractType {
|
| virtual bool IsMalformed() const;
|
| virtual bool IsMalbounded() const;
|
| virtual bool IsMalformedOrMalbounded() const;
|
| - virtual RawLanguageError* error() const { return raw_ptr()->error_; }
|
| + virtual RawLanguageError* error() const;
|
| virtual void set_error(const LanguageError& value) const;
|
| virtual bool IsResolved() const {
|
| return raw_ptr()->type_state_ >= RawType::kResolved;
|
| @@ -5529,6 +5537,12 @@ class Type : public AbstractType {
|
| virtual bool IsInstantiated(TrailPtr trail = NULL) const;
|
| virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const;
|
| virtual bool IsRecursive() const;
|
| + // If signature is not null, this type represents a function type.
|
| + RawFunction* signature() const;
|
| + void set_signature(const Function& value) const;
|
| + virtual bool IsFunctionType() const {
|
| + return signature() != Function::null();
|
| + }
|
| virtual RawAbstractType* InstantiateFrom(
|
| const TypeArguments& instantiator_type_arguments,
|
| Error* bound_error,
|
| @@ -5594,7 +5608,7 @@ class Type : public AbstractType {
|
| static RawType* ArrayType();
|
|
|
| // The 'Function' type.
|
| - static RawType* Function();
|
| + static RawType* DartFunctionType();
|
|
|
| // The finalized type of the given non-parameterized class.
|
| static RawType* NewNonParameterizedType(const Class& type_class);
|
| @@ -5616,106 +5630,6 @@ class Type : public AbstractType {
|
| };
|
|
|
|
|
| -// TODO(regis): FunctionType is very similar to Type. Instead of a separate
|
| -// class FunctionType, we could consider an object of class Type as representing
|
| -// a function type if it has a non-null function (signature) field.
|
| -// In order to save space, we could reuse the error_ field? A malformed or
|
| -// malbounded function type would lose its function reference, but the error
|
| -// string would contain relevant info.
|
| -
|
| -// A FunctionType describes the signature of a function, i.e. the result type
|
| -// and formal parameter types of the function, as well as the names of optional
|
| -// named formal parameters.
|
| -// If these types refer to type parameters of a class in scope, the function
|
| -// type is generic. A generic function type may be instantiated by a type
|
| -// argument vector.
|
| -// Therefore, a FunctionType consists of a scope class, a type argument vector,
|
| -// and a signature.
|
| -// The scope class is either a generic class (or generic typedef) declaring the
|
| -// type parameters referred to by the signature, or class _Closure in the
|
| -// non-generic case (including the non-generic typedef case).
|
| -// The type arguments specify an instantiation of the generic signature (null in
|
| -// the non-generic case).
|
| -// The signature is a reference to an actual closure function (kClosureFunction)
|
| -// or to a signature function (kSignatureFunction).
|
| -// Since typedefs cannot refer to themselves, directly or indirectly, a
|
| -// FunctionType cannot be recursive. Only individual formal parameter types can.
|
| -class FunctionType : public AbstractType {
|
| - public:
|
| - virtual bool IsFinalized() const {
|
| - return
|
| - (raw_ptr()->type_state_ == RawFunctionType::kFinalizedInstantiated) ||
|
| - (raw_ptr()->type_state_ == RawFunctionType::kFinalizedUninstantiated);
|
| - }
|
| - virtual void SetIsFinalized() const;
|
| - void ResetIsFinalized() const; // Ignore current state and set again.
|
| - virtual bool IsBeingFinalized() const {
|
| - return raw_ptr()->type_state_ == RawFunctionType::kBeingFinalized;
|
| - }
|
| - virtual void SetIsBeingFinalized() const;
|
| - virtual bool IsMalformed() const;
|
| - virtual bool IsMalbounded() const;
|
| - virtual bool IsMalformedOrMalbounded() const;
|
| - virtual RawLanguageError* error() const { return raw_ptr()->error_; }
|
| - virtual void set_error(const LanguageError& value) const;
|
| - virtual bool IsResolved() const {
|
| - return raw_ptr()->type_state_ >= RawFunctionType::kResolved;
|
| - }
|
| - virtual void SetIsResolved() const;
|
| - // The scope class of a FunctionType is always resolved. It has no actual
|
| - // type class. Returning false is important for the type testers to work, e.g.
|
| - // IsDynamicType(), IsBoolType(), etc...
|
| - virtual bool HasResolvedTypeClass() const { return false; }
|
| - // Return scope_class from virtual type_class() to factorize finalization
|
| - // with Type, also a parameterized type.
|
| - virtual RawClass* type_class() const { return scope_class(); }
|
| - RawClass* scope_class() const { return raw_ptr()->scope_class_; }
|
| - void set_scope_class(const Class& value) const;
|
| - virtual RawTypeArguments* arguments() const { return raw_ptr()->arguments_; }
|
| - virtual void set_arguments(const TypeArguments& value) const;
|
| - RawFunction* signature() const { return raw_ptr()->signature_; }
|
| - virtual TokenPosition token_pos() const { return raw_ptr()->token_pos_; }
|
| - virtual bool IsInstantiated(TrailPtr trail = NULL) const;
|
| - virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const;
|
| - virtual bool IsRecursive() const;
|
| - virtual RawAbstractType* InstantiateFrom(
|
| - const TypeArguments& instantiator_type_arguments,
|
| - Error* malformed_error,
|
| - TrailPtr instantiation_trail,
|
| - TrailPtr bound_trail,
|
| - Heap::Space space) const;
|
| - virtual RawAbstractType* CloneUnfinalized() const;
|
| - virtual RawAbstractType* CloneUninstantiated(
|
| - const Class& new_owner,
|
| - TrailPtr trail = NULL) const;
|
| - virtual RawAbstractType* Canonicalize(TrailPtr trail = NULL) const;
|
| - virtual RawString* EnumerateURIs() const;
|
| -
|
| - virtual intptr_t Hash() const;
|
| -
|
| - static intptr_t InstanceSize() {
|
| - return RoundedAllocationSize(sizeof(RawFunctionType));
|
| - }
|
| -
|
| - static RawFunctionType* New(const Class& scope_class,
|
| - const TypeArguments& arguments,
|
| - const Function& signature,
|
| - TokenPosition token_pos,
|
| - Heap::Space space = Heap::kOld);
|
| -
|
| - private:
|
| - void set_signature(const Function& value) const;
|
| - void set_token_pos(TokenPosition token_pos) const;
|
| - void set_type_state(int8_t state) const;
|
| -
|
| - static RawFunctionType* New(Heap::Space space = Heap::kOld);
|
| -
|
| - FINAL_HEAP_OBJECT_IMPLEMENTATION(FunctionType, AbstractType);
|
| - friend class Class;
|
| - friend class TypeArguments;
|
| -};
|
| -
|
| -
|
| // A TypeRef is used to break cycles in the representation of recursive types.
|
| // Its only field is the recursive AbstractType it refers to.
|
| // Note that the cycle always involves type arguments.
|
| @@ -5738,7 +5652,6 @@ class TypeRef : public AbstractType {
|
| }
|
| virtual bool IsResolved() const { return true; }
|
| virtual bool HasResolvedTypeClass() const {
|
| - // Returns false if the ref type is a function type.
|
| return AbstractType::Handle(type()).HasResolvedTypeClass();
|
| }
|
| RawAbstractType* type() const { return raw_ptr()->type_; }
|
|
|