예제 #1
0
 internal ApplicableFunction(IMemberInfo method, Type[] methodSignature,
     Type[] appliedSignature, Type[] paramsSignature,
     Conversion[] conversions)
 {
     this.method = method;
     this.methodSignature = methodSignature;
     this.appliedSignature = appliedSignature;
     this.paramsSignature = paramsSignature;
     this.conversions = conversions;
 }
예제 #2
0
		    public UserDefined(Conversion before, IMemberInfo method, Conversion after, ITypeMapper typeMapper)
			    : base(typeMapper)
			{
				_before = before;
                _method = method;
				_fromType = method.ParameterTypes[0];
				_toType = method.ReturnType;
				_after = after;
			}
예제 #3
0
            public ConvertNullable(ITypeMapper typeMapper, Conversion internalConversation)
		        : base(typeMapper)
		    {
		        _internalConversation = internalConversation;
		    }
예제 #4
0
            public WrapNullable(ITypeMapper typeMapper, Conversion fromConv)
		        : base(typeMapper)
            {
                _fromConv = fromConv;
            }
			public UserDefined(Conversion before, IMemberInfo method, Conversion after)
			{
				this.before = before;
				this.method = method;
				this.fromType = method.ParameterTypes[0];
				this.toType = method.ReturnType;
				this.after = after;
			}
예제 #6
0
        public static ApplicableFunction ValidateCandidate(IMemberInfo candidate, Operand[] args)
        {
            Type[] cTypes = candidate.ParameterTypes;

            if (cTypes.Length == args.Length)
            {
                Conversion[] conversions = new Conversion[args.Length];

                for (int i = 0; i < cTypes.Length; i++)
                {
                    conversions[i] = Conversion.GetImplicit(args[i], cTypes[i], false);
                    if (!conversions[i].IsValid)
                        return null;
                }

                return new ApplicableFunction(candidate, cTypes, cTypes, Operand.GetTypes(args), conversions);
            }

            if (candidate.IsParameterArray && args.Length >= cTypes.Length - 1)
            {
                Type[] expandedTypes = new Type[args.Length];
                Array.Copy(cTypes, expandedTypes, cTypes.Length - 1);
                Type varType = cTypes[cTypes.Length - 1].GetElementType();

                for (int i = cTypes.Length - 1; i < expandedTypes.Length; i++)
                    expandedTypes[i] = varType;

                Conversion[] conversions = new Conversion[args.Length];

                for (int i = 0; i < expandedTypes.Length; i++)
                {
                    conversions[i] = Conversion.GetImplicit(args[i], expandedTypes[i], false);
                    if (!conversions[i].IsValid)
                        return null;
                }

                return new ApplicableFunction(candidate, cTypes, expandedTypes, Operand.GetTypes(args), conversions);
            }

            return null;
        }
예제 #7
0
        void EmitGetHelper_Conversion(Operand op, Type desiredType, Conversion conv, Type from = null)
        {
            if (conv.RequiresAddress)
            {
                if (ReferenceEquals(op, null))
                    throw new ArgumentException("Conversion from nullref to " + desiredType.Name + " is impossible; for nullables variable it's required to load address.");

                op.EmitAddressOf(this);
            }
            else if (ReferenceEquals(op, null))
                IL.Emit(OpCodes.Ldnull);
            else
                op.EmitGet(this);
            if (from == null)
                from = (object)op == null ? null : op.GetReturnType(TypeMapper);
            conv.Emit(this, from, desiredType);
        }
예제 #8
0
        internal void EmitGetHelper(Operand op, Type desiredType, Conversion conv, Type from = null)
        {
            if (conv == null)
            {
                EmitGetHelper(op, desiredType, false);
                return;
            }

            EmitGetHelper_Conversion(op, desiredType.IsByRef ? desiredType.GetElementType() : desiredType, conv, from);
            if (desiredType.IsByRef)
                EmitGetHelper_Ref(op, desiredType);
        }
			public SwitchBlock(Operand expression)
			{
				this.expression = expression;

				Type exprType = expression.Type;
				if (Array.IndexOf(validTypes, exprType) != -1)
					govType = exprType;
				else if (exprType.IsEnum)
					govType = Enum.GetUnderlyingType(exprType);
				else
				{
					// if a single implicit coversion from expression to one of the valid types exists, it's ok
					foreach (Type t in validTypes)
					{
						Conversion tmp = Conversion.GetImplicit(expression, t, false);
						if (tmp.IsValid)
						{
							if (conv == null)
							{
								conv = tmp;
								govType = t;
							}
							else
								throw new AmbiguousMatchException(Properties.Messages.ErrAmbiguousSwitchExpression);
						}
					}
				}
			}