Exemple #1
0
		public override IType VisitChildren(TypeVisitor visitor)
		{
			IType e = elementType.AcceptVisitor(visitor);
			if (e == elementType)
				return this;
			else
				return new PointerType(e);
		}
Exemple #2
0
		public IType VisitChildren(TypeVisitor visitor)
		{
			IType g = genericType.AcceptVisitor(visitor);
			ITypeDefinition def = g as ITypeDefinition;
			if (def == null)
				return g;
			// Keep ta == null as long as no elements changed, allocate the array only if necessary.
			IType[] ta = (g != genericType) ? new IType[typeArguments.Length] : null;
			for (int i = 0; i < typeArguments.Length; i++) {
				IType r = typeArguments[i].AcceptVisitor(visitor);
				if (r == null)
					throw new NullReferenceException("TypeVisitor.Visit-method returned null");
				if (ta == null && r != typeArguments[i]) {
					// we found a difference, so we need to allocate the array
					ta = new IType[typeArguments.Length];
					for (int j = 0; j < i; j++) {
						ta[j] = typeArguments[j];
					}
				}
				if (ta != null)
					ta[i] = r;
			}
			if (ta == null)
				return this;
			else
				return new ParameterizedType(def, ta);
		}
Exemple #3
0
		public IType AcceptVisitor(TypeVisitor visitor)
		{
			return visitor.VisitParameterizedType(this);
		}
Exemple #4
0
		internal static bool ValidateConstraints(ITypeParameter typeParameter, IType typeArgument, TypeVisitor substitution, Conversions conversions)
		{
			switch (typeArgument.Kind) { // void, null, and pointers cannot be used as type arguments
				case TypeKind.Void:
				case TypeKind.Null:
				case TypeKind.Pointer:
					return false;
			}
			if (typeParameter.HasReferenceTypeConstraint) {
				if (typeArgument.IsReferenceType != true)
					return false;
			}
			if (typeParameter.HasValueTypeConstraint) {
				if (!NullableType.IsNonNullableValueType(typeArgument))
					return false;
			}
			if (typeParameter.HasDefaultConstructorConstraint) {
				ITypeDefinition def = typeArgument.GetDefinition();
				if (def != null && def.IsAbstract)
					return false;
				var ctors = typeArgument.GetConstructors(
					m => m.Parameters.Count == 0 && m.Accessibility == Accessibility.Public,
					GetMemberOptions.IgnoreInheritedMembers | GetMemberOptions.ReturnMemberDefinitions
				);
				if (!ctors.Any())
					return false;
			}
			foreach (IType constraintType in typeParameter.DirectBaseTypes) {
				IType c = constraintType;
				if (substitution != null)
					c = c.AcceptVisitor(substitution);
				if (!conversions.IsConstraintConvertible(typeArgument, c))
					return false;
			}
			return true;
		}
Exemple #5
0
		/// <summary>
		/// Validates whether the given type argument satisfies the constraints for the given type parameter.
		/// </summary>
		/// <param name="typeParameter">The type parameter.</param>
		/// <param name="typeArgument">The type argument.</param>
		/// <param name="substitution">The substitution that defines how type parameters are replaced with type arguments.
		/// The substitution is used to check constraints that depend on other type parameters (or recursively on the same type parameter).</param>
		/// <returns>True if the constraints are satisfied; false otherwise.</returns>
		public static bool ValidateConstraints(ITypeParameter typeParameter, IType typeArgument, TypeVisitor substitution)
		{
			if (typeParameter == null)
				throw new ArgumentNullException("typeParameter");
			if (typeParameter.Owner == null)
				throw new ArgumentNullException("typeParameter.Owner");
			if (typeArgument == null)
				throw new ArgumentNullException("typeArgument");
			return ValidateConstraints(typeParameter, typeArgument, substitution, Conversions.Get(typeParameter.Owner.Compilation));
		}
 public IType AcceptVisitor(TypeVisitor visitor)
 {
     return(visitor.VisitParameterizedType(this));
 }
Exemple #7
0
        // NestedTypes, Events, Fields: System.Array doesn't have any; so we can use the AbstractType default implementation
        // that simply returns an empty list

        public override IType AcceptVisitor(TypeVisitor visitor)
        {
            return(visitor.VisitArrayType(this));
        }
 public IType VisitChildren(TypeVisitor visitor)
 {
     throw new NotImplementedException ();
 }
Exemple #9
0
		public override IType AcceptVisitor(TypeVisitor visitor)
		{
			return visitor.VisitPointerType(this);
		}
		public override IType AcceptVisitor(TypeVisitor visitor)
		{
			return visitor.VisitByReferenceType(this);
		}
Exemple #11
0
 public override IType AcceptVisitor(TypeVisitor visitor)
 {
     return(visitor.VisitPointerType(this));
 }
Exemple #12
0
 public override IType AcceptVisitor(TypeVisitor visitor)
 {
     return(visitor.VisitByReferenceType(this));
 }
Exemple #13
0
 IType IType.VisitChildren(TypeVisitor visitor)
 {
     Contract.Requires(visitor != null);
     Contract.Ensures(Contract.Result <IType>() != null);
     return(this);
 }
Exemple #14
0
 IType IType.AcceptVisitor(TypeVisitor visitor)
 {
     Contract.Requires(visitor != null);
     Contract.Ensures(Contract.Result <IType>() != null);
     return(this);
 }
Exemple #15
0
		// NestedTypes, Events, Fields: System.Array doesn't have any; so we can use the AbstractType default implementation
		// that simply returns an empty list
		
		public override IType AcceptVisitor(TypeVisitor visitor)
		{
			return visitor.VisitArrayType(this);
		}
Exemple #16
0
		public override IType VisitChildren(TypeVisitor visitor)
		{
			IType e = elementType.AcceptVisitor(visitor);
			if (e == elementType)
				return this;
			else
				return new ArrayType(compilation, e, dimensions);
		}
 public IType AcceptVisitor(TypeVisitor visitor)
 {
     throw new NotImplementedException ();
 }