예제 #1
0
        public SpecializedMethod(IMethod methodDefinition, TypeParameterSubstitution substitution)
            : base(methodDefinition)
        {
            SpecializedMethod specializedMethodDefinition = methodDefinition as SpecializedMethod;

            if (specializedMethodDefinition != null)
            {
                this.genericMethodIsSpecialized = specializedMethodDefinition.genericMethodIsSpecialized;
            }

            // The base ctor might have unpacked a SpecializedMember
            // (in case we are specializing an already-specialized method)
            methodDefinition      = (IMethod)base.baseMember;
            this.methodDefinition = methodDefinition;
            if (methodDefinition.TypeParameters.Count > 0)
            {
                // The method is generic, so we need to specialize the type parameters
                // (for specializing the constraints, and also to set the correct Owner)
                specializedTypeParameters = new ITypeParameter[methodDefinition.TypeParameters.Count];
                for (int i = 0; i < specializedTypeParameters.Length; i++)
                {
                    specializedTypeParameters[i] = new SpecializedTypeParameter(methodDefinition.TypeParameters[i], this);
                }
                if (!genericMethodIsSpecialized)
                {
                    // Add substitution that replaces the base method's type parameters with our specialized version
                    // but do this only if the type parameters on the baseMember have not already been substituted
                    substitutionWithoutSpecializedTypeParameters = this.Substitution;
                    AddSubstitution(new TypeParameterSubstitution(null, specializedTypeParameters));
                }
            }
            // Add the main substitution after the method type parameter specialization.
            AddSubstitution(substitution);
            if (substitutionWithoutSpecializedTypeParameters != null)
            {
                // If we already have a substitution without specialized type parameters, update that:
                substitutionWithoutSpecializedTypeParameters = TypeParameterSubstitution.Compose(substitution, substitutionWithoutSpecializedTypeParameters);
            }
            else
            {
                // Otherwise just use the whole substitution, as that doesn't contain specialized type parameters
                // in this case.
                substitutionWithoutSpecializedTypeParameters = this.Substitution;
            }
            if (substitution != null && substitution.MethodTypeArguments != null && methodDefinition.TypeParameters.Count > 0)
            {
                this.genericMethodIsSpecialized = true;
            }
            if (specializedTypeParameters != null)
            {
                // Set the substitution on the type parameters to the final composed substitution
                foreach (var tp in specializedTypeParameters.OfType <SpecializedTypeParameter>())
                {
                    if (tp.Owner == this)
                    {
                        tp.substitution = base.Substitution;
                    }
                }
            }
        }
예제 #2
0
            public override bool Equals(IType other)
            {
                // Compare the owner, not the substitution, because the substitution may contain this specialized type parameter recursively
                SpecializedTypeParameter o = other as SpecializedTypeParameter;

                return(o != null && baseTp.Equals(o.baseTp) && this.Owner.Equals(o.Owner));
            }
예제 #3
0
		public SpecializedMethod(IMethod methodDefinition, TypeParameterSubstitution substitution)
			: base(methodDefinition)
		{
			// The base ctor might have unpacked a SpecializedMember
			// (in case we are specializing an already-specialized method)
			methodDefinition = (IMethod)base.MemberDefinition;
			this.methodDefinition = methodDefinition;
			if (methodDefinition.TypeParameters.Any(ConstraintNeedsSpecialization)) {
				// The method is generic, and we need to specialize the type parameters
				specializedTypeParameters = new ITypeParameter[methodDefinition.TypeParameters.Count];
				for (int i = 0; i < specializedTypeParameters.Length; i++) {
					ITypeParameter tp = methodDefinition.TypeParameters[i];
					if (ConstraintNeedsSpecialization(tp))
						tp = new SpecializedTypeParameter(tp, this);
					specializedTypeParameters[i] = tp;
				}
				// add substitution that replaces the base method's type parameters with our specialized version
				AddSubstitution(new TypeParameterSubstitution(null, specializedTypeParameters));
			}
			// Add the main substitution after the method type parameter specialization.
			AddSubstitution(substitution);
			if (specializedTypeParameters != null) {
				// Set the substitution on the type parameters to the final composed substitution
				foreach (var tp in specializedTypeParameters.OfType<SpecializedTypeParameter>()) {
					if (tp.Owner == this)
						tp.substitution = base.Substitution;
				}
			}
		}
예제 #4
0
        internal protected SpecializedMethod(IType declaringType, IMethod methodDefinition, IList <IType> typeArguments, TypeVisitor substitution)
            : base(declaringType, methodDefinition)
        {
            if (declaringType == null)
            {
                throw new ArgumentNullException("declaringType");
            }
            if (methodDefinition == null)
            {
                throw new ArgumentNullException("methodDefinition");
            }

            this.methodDefinition = methodDefinition;
            this.typeArguments    = typeArguments ?? EmptyList <IType> .Instance;

            if (methodDefinition.TypeParameters.Any(ConstraintNeedsSpecialization))
            {
                // The method is generic, and we need to specialize the type parameters
                specializedTypeParameters = new ITypeParameter[methodDefinition.TypeParameters.Count];
                for (int i = 0; i < specializedTypeParameters.Count; i++)
                {
                    ITypeParameter tp = methodDefinition.TypeParameters[i];
                    if (ConstraintNeedsSpecialization(tp))
                    {
                        tp = new SpecializedTypeParameter(tp, this, substitution);
                    }
                    specializedTypeParameters[i] = tp;
                }
            }
            if (typeArguments != null && typeArguments.Count > 0)
            {
                if (typeArguments.Count != methodDefinition.TypeParameters.Count)
                {
                    throw new ArgumentException("Incorrect number of type arguments");
                }
            }
            else if (specializedTypeParameters != null)
            {
                // No type arguments were specified, but the method is generic.
                // -> substitute original type parameters with the specialized ones
                substitution = GetSubstitution(declaringType, specializedTypeParameters.ToArray <IType>());
                for (int i = 0; i < specializedTypeParameters.Count; i++)
                {
                    if (ConstraintNeedsSpecialization(methodDefinition.TypeParameters[i]))
                    {
                        ((SpecializedTypeParameter)specializedTypeParameters[i]).substitution = substitution;
                    }
                }
            }

            Initialize(substitution);
        }
예제 #5
0
        public SpecializedMethod(IMethod methodDefinition, TypeParameterSubstitution substitution)
            : base(methodDefinition)
        {
            SpecializedMethod specializedMethodDefinition = methodDefinition as SpecializedMethod;
            if (specializedMethodDefinition != null)
                this.genericMethodIsSpecialized = specializedMethodDefinition.genericMethodIsSpecialized;

            // The base ctor might have unpacked a SpecializedMember
            // (in case we are specializing an already-specialized method)
            methodDefinition = (IMethod)base.baseMember;
            this.methodDefinition = methodDefinition;
            if (methodDefinition.TypeParameters.Count > 0) {
                // The method is generic, so we need to specialize the type parameters
                // (for specializing the constraints, and also to set the correct Owner)
                specializedTypeParameters = new ITypeParameter[methodDefinition.TypeParameters.Count];
                for (int i = 0; i < specializedTypeParameters.Length; i++) {
                    specializedTypeParameters[i] = new SpecializedTypeParameter(methodDefinition.TypeParameters[i], this);
                }
                if (!genericMethodIsSpecialized) {
                    // Add substitution that replaces the base method's type parameters with our specialized version
                    // but do this only if the type parameters on the baseMember have not already been substituted
                    substitutionWithoutSpecializedTypeParameters = this.Substitution;
                    AddSubstitution(new TypeParameterSubstitution(null, specializedTypeParameters));
                }
            }
            // Add the main substitution after the method type parameter specialization.
            AddSubstitution(substitution);
            if (substitutionWithoutSpecializedTypeParameters != null) {
                // If we already have a substitution without specialized type parameters, update that:
                substitutionWithoutSpecializedTypeParameters = TypeParameterSubstitution.Compose(substitution, substitutionWithoutSpecializedTypeParameters);
            } else {
                // Otherwise just use the whole substitution, as that doesn't contain specialized type parameters
                // in this case.
                substitutionWithoutSpecializedTypeParameters = this.Substitution;
            }
            if (substitution != null && substitution.MethodTypeArguments != null && methodDefinition.TypeParameters.Count > 0)
                this.genericMethodIsSpecialized = true;
            if (specializedTypeParameters != null) {
                // Set the substitution on the type parameters to the final composed substitution
                foreach (var tp in specializedTypeParameters.OfType<SpecializedTypeParameter>()) {
                    if (tp.Owner == this)
                        tp.substitution = base.Substitution;
                }
            }
        }
예제 #6
0
		internal protected SpecializedMethod(IType declaringType, IMethod methodDefinition, IList<IType> typeArguments, TypeVisitor substitution)
			: base(declaringType, methodDefinition)
		{
			if (declaringType == null)
				throw new ArgumentNullException("declaringType");
			if (methodDefinition == null)
				throw new ArgumentNullException("methodDefinition");
			
			this.methodDefinition = methodDefinition;
			this.typeArguments = typeArguments ?? EmptyList<IType>.Instance;
			
			if (methodDefinition.TypeParameters.Any(ConstraintNeedsSpecialization)) {
				// The method is generic, and we need to specialize the type parameters
				specializedTypeParameters = new ITypeParameter[methodDefinition.TypeParameters.Count];
				for (int i = 0; i < specializedTypeParameters.Count; i++) {
					ITypeParameter tp = methodDefinition.TypeParameters[i];
					if (ConstraintNeedsSpecialization(tp))
						tp = new SpecializedTypeParameter(tp, this, substitution);
					specializedTypeParameters[i] = tp;
				}
			}
			if (typeArguments != null && typeArguments.Count > 0) {
				if (typeArguments.Count != methodDefinition.TypeParameters.Count)
					throw new ArgumentException("Incorrect number of type arguments");
			} else if (specializedTypeParameters != null) {
				// No type arguments were specified, but the method is generic.
				// -> substitute original type parameters with the specialized ones
				substitution = GetSubstitution(declaringType, specializedTypeParameters.ToArray<IType>());
				for (int i = 0; i < specializedTypeParameters.Count; i++) {
					if (ConstraintNeedsSpecialization(methodDefinition.TypeParameters[i])) {
						((SpecializedTypeParameter)specializedTypeParameters[i]).substitution = substitution;
					}
				}
			}
			
			Initialize(substitution);
		}
예제 #7
0
 public SpecializedMethod(IMethod methodDefinition, TypeParameterSubstitution substitution)
     : base(methodDefinition)
 {
     // The base ctor might have unpacked a SpecializedMember
     // (in case we are specializing an already-specialized method)
     methodDefinition      = (IMethod)base.MemberDefinition;
     this.methodDefinition = methodDefinition;
     if (methodDefinition.TypeParameters.Any(ConstraintNeedsSpecialization))
     {
         // The method is generic, and we need to specialize the type parameters
         specializedTypeParameters = new ITypeParameter[methodDefinition.TypeParameters.Count];
         for (int i = 0; i < specializedTypeParameters.Length; i++)
         {
             ITypeParameter tp = methodDefinition.TypeParameters[i];
             if (ConstraintNeedsSpecialization(tp))
             {
                 tp = new SpecializedTypeParameter(tp, this);
             }
             specializedTypeParameters[i] = tp;
         }
         // add substitution that replaces the base method's type parameters with our specialized version
         AddSubstitution(new TypeParameterSubstitution(null, specializedTypeParameters));
     }
     // Add the main substitution after the method type parameter specialization.
     AddSubstitution(substitution);
     if (specializedTypeParameters != null)
     {
         // Set the substitution on the type parameters to the final composed substitution
         foreach (var tp in specializedTypeParameters.OfType <SpecializedTypeParameter>())
         {
             if (tp.Owner == this)
             {
                 tp.substitution = base.Substitution;
             }
         }
     }
 }
예제 #8
0
            public override bool Equals(IType other)
            {
                SpecializedTypeParameter o = other as SpecializedTypeParameter;

                return(o != null && baseTp.Equals(o.baseTp) && this.Owner.Equals(o.Owner));
            }