Example #1
0
		public TypeInference(ICompilation compilation)
		{
			if (compilation == null)
				throw new ArgumentNullException("compilation");
			this.compilation = compilation;
			this.conversions = Conversions.Get(compilation);
		}
Example #2
0
		internal TypeInference(ICompilation compilation, Conversions conversions)
		{
			Debug.Assert(compilation != null);
			Debug.Assert(conversions != null);
			this.compilation = compilation;
			this.conversions = conversions;
		}
Example #3
0
		public CppResolver(ICompilation compilation)
		{
			if (compilation == null)
				throw new ArgumentNullException("compilation");
			this.compilation = compilation;
			this.conversions = Conversions.Get(compilation);
			this.context = new CppTypeResolveContext(compilation.MainAssembly);
		}
Example #4
0
		public CppResolver(CppTypeResolveContext context)
		{
			if (context == null)
				throw new ArgumentNullException("context");
			this.compilation = context.Compilation;
			this.conversions = Conversions.Get(compilation);
			this.context = context;
			if (context.CurrentTypeDefinition != null)
				currentTypeDefinitionCache = new TypeDefinitionCache(context.CurrentTypeDefinition);
		}
Example #5
0
		private CppResolver(ICompilation compilation, Conversions conversions, CppTypeResolveContext context, bool checkForOverflow, bool isWithinLambdaExpression, TypeDefinitionCache currentTypeDefinitionCache, ImmutableStack<IVariable> localVariableStack, ObjectInitializerContext objectInitializerStack)
		{
			this.compilation = compilation;
			this.conversions = conversions;
			this.context = context;
			this.checkForOverflow = checkForOverflow;
			this.isWithinLambdaExpression = isWithinLambdaExpression;
			this.currentTypeDefinitionCache = currentTypeDefinitionCache;
			this.localVariableStack = localVariableStack;
			this.objectInitializerStack = objectInitializerStack;
		}
Example #6
0
        public void use_a_runtime_converter_against_NULL()
        {
            var conversions = new Conversions();
            conversions.RegisterRuntimeConversion<ColorConverter>();
            var cellHandling = new CellHandling(new EquivalenceChecker(), conversions);

            var cell = new Cell(cellHandling, "color", typeof (Color));

            var values = new StepValues("foo");
            cell.ConvertValues(new Step("foo").With("color", "NULL"), values);

            values.Get("color").ShouldBeNull();
        }
Example #7
0
        public void use_a_runtime_converter_with_a_value()
        {
            var conversions = new Conversions();
            conversions.RegisterRuntimeConversion<ColorConverter>();

            var cellHandling = new CellHandling(new EquivalenceChecker(), conversions);

            var cell = new Cell(cellHandling, "color", typeof (Color));

            var values = new StepValues("foo");
            cell.ConvertValues(new Step("foo").With("color", "Red"), values);

            var delayed = values.DelayedConversions.Single();

            delayed.Key.ShouldBe("color");
            delayed.Raw.ShouldBe("Red");
            delayed.Converter.ShouldBeOfType<ColorConverter>();
        }
Example #8
0
		internal static bool IsEligibleExtensionMethod(ICompilation compilation, Conversions conversions, IType targetType, IMethod method, bool useTypeInference, out IType[] outInferredTypes)
		{
			outInferredTypes = null;
			if (targetType == null)
				return true;
			if (method.Parameters.Count == 0)
				return false;
			IType thisParameterType = method.Parameters[0].Type;
			if (useTypeInference && method.TypeParameters.Count > 0) {
				// We need to infer type arguments from targetType:
				TypeInference ti = new TypeInference(compilation, conversions);
				ResolveResult[] arguments = { new ResolveResult(targetType) };
				IType[] parameterTypes = { method.Parameters[0].Type };
				bool success;
				var inferredTypes = ti.InferTypeArguments(method.TypeParameters, arguments, parameterTypes, out success);
				var substitution = new TypeParameterSubstitution(null, inferredTypes);
				// Validate that the types that could be inferred (aren't unknown) satisfy the constraints:
				bool hasInferredTypes = false;
				for (int i = 0; i < inferredTypes.Length; i++) {
					if (inferredTypes[i].Kind != TypeKind.Unknown && inferredTypes[i].Kind != TypeKind.UnboundTypeArgument) {
						hasInferredTypes = true;
						if (!OverloadResolution.ValidateConstraints(method.TypeParameters[i], inferredTypes[i], substitution, conversions))
							return false;
					} else {
						inferredTypes[i] = method.TypeParameters[i]; // do not substitute types that could not be inferred
					}
				}
				if (hasInferredTypes)
					outInferredTypes = inferredTypes;
				thisParameterType = thisParameterType.AcceptVisitor(substitution);
			}
			Conversion c = conversions.ImplicitConversion(targetType, thisParameterType);
			return c.IsValid && (c.IsIdentityConversion || c.IsReferenceConversion || c.IsBoxingConversion);
		}
Example #9
0
		/// <summary>
		/// Sets the converter to all DataMembers that have this returnType
		/// <para xml:lang="es">
		/// Establece el convertidor para todos los miembros de datos que tienen este returnType.
		/// </para>
		/// </summary>
		/// <param name="converter">Converter to use
		/// <para xml:lang="es">Convertidor a usar</para>
		/// </param>
		/// <param name="returnType">Return type of the members that will have the converter set
		/// <para xml:lang="es">Tipo de retorno de los miembros que tendra el convertidor setConverter a usar.</para>
		/// </param>
		public static void SetConverter(Conversions.ConverterBase converter, Type returnType)
		{
			foreach (DataType dtype in DataType.AllDataTypes)
			{
				foreach (DataMember dmember in dtype.DataMembers.Where(dm => dm.Expression.ReturnType.Equals(returnType)))
				{
					dmember.Converter = converter;

					//set right column type
					if (Sql.DbTypeMapper.DbTypeMap.ContainsValue(converter.ColumnType) && converter.ColumnType != typeof(object))
					{
						dmember.Column.DbType = Sql.DbTypeMapper.Parse(converter.ColumnType);
					}
					else if (converter.ColumnType.GetTypeInfo().IsEnum)
					{
						dmember.Column.DbType = Sql.DbType.Int32;
					}
				}
			}
		}
 public ArrayConversion(Conversions conversions)
 {
     _conversions = conversions;
 }
Example #11
0
		/// <summary>
		/// Sets the converter to all DataMembers that have this returnType
		/// </summary>
		/// <param name="converter">Converter to use</param>
		/// <param name="returnType">Return type of the members that will have the converter set</param>
		public static void SetConverter(Conversions.ConverterBase converter, Type returnType)
		{
			foreach (DataType dtype in DataType.AllDataTypes)
			{
				foreach (DataMember dmember in dtype.DataMembers.Where(dm => dm.Member.ReturnType.Equals(returnType)))
				{
					dmember.Converter = converter;
				}
			}
		}
Example #12
0
		/// <summary>
		/// Gets whether the lambda body is valid for the given parameter types and return type.
		/// </summary>
		/// <returns>
		/// Produces a conversion with <see cref="Conversion.IsAnonymousFunctionConversion"/>=<c>true</c> if the lambda is valid;
		/// otherwise returns <see cref="Conversion.None"/>.
		/// </returns>
		public abstract Conversion IsValid(IType[] parameterTypes, IType returnType, Conversions conversions);
 public NullableConvertor(Conversions conversions)
 {
     _conversions = conversions;
 }
Example #14
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;
		}
Example #15
0
			public ConstraintValidatingSubstitution(IList<IType> classTypeArguments, IList<IType> methodTypeArguments, OverloadResolution overloadResolution)
				: base(classTypeArguments, methodTypeArguments)
			{
				this.conversions = overloadResolution.conversions;
			}
Example #16
0
		public OverloadResolution(ICompilation compilation, ResolveResult[] arguments, string[] argumentNames = null, IType[] typeArguments = null, Conversions conversions = null)
		{
			if (compilation == null)
				throw new ArgumentNullException("compilation");
			if (arguments == null)
				throw new ArgumentNullException("arguments");
			if (argumentNames == null)
				argumentNames = new string[arguments.Length];
			else if (argumentNames.Length != arguments.Length)
				throw new ArgumentException("argumentsNames.Length must be equal to arguments.Length");
			this.compilation = compilation;
			this.arguments = arguments;
			this.argumentNames = argumentNames;
			
			// keep explicitlyGivenTypeArguments==null when no type arguments were specified
			if (typeArguments != null && typeArguments.Length > 0)
				this.explicitlyGivenTypeArguments = typeArguments;
			
			this.conversions = conversions ?? Conversions.Get(compilation);
			this.AllowExpandingParams = true;
		}