public IMethod ResolveConstructor(ITypeResolveContext context) { CSharpResolver r = new CSharpResolver(context); IType type = attributeType.Resolve(context); int totalArgumentCount = 0; if (positionalArguments != null) totalArgumentCount += positionalArguments.Count; if (namedCtorArguments != null) totalArgumentCount += namedCtorArguments.Count; ResolveResult[] arguments = new ResolveResult[totalArgumentCount]; string[] argumentNames = new string[totalArgumentCount]; int i = 0; if (positionalArguments != null) { while (i < positionalArguments.Count) { IConstantValue cv = positionalArguments[i]; arguments[i] = new ConstantResolveResult(cv.GetValueType(context), cv.GetValue(context)); i++; } } if (namedCtorArguments != null) { foreach (var pair in namedCtorArguments) { argumentNames[i] = pair.Key; arguments[i] = new ConstantResolveResult(pair.Value.GetValueType(context), pair.Value.GetValue(context)); i++; } } MemberResolveResult mrr = r.ResolveObjectCreation(type, arguments, argumentNames) as MemberResolveResult; return mrr != null ? mrr.Member as IMethod : null; }
public override IList <ResolveResult> GetArgumentsForCall() { ResolveResult[] results = new ResolveResult[Member.Parameters.Count]; List <ResolveResult> paramsArguments = IsExpandedForm ? new List <ResolveResult>() : null; // map arguments to parameters: for (int i = 0; i < Arguments.Count; i++) { int mappedTo; if (argumentToParameterMap != null) { mappedTo = argumentToParameterMap[i]; } else { mappedTo = IsExpandedForm ? Math.Min(i, results.Length - 1) : i; } if (mappedTo >= 0 && mappedTo < results.Length) { if (IsExpandedForm && mappedTo == results.Length - 1) { paramsArguments.Add(Arguments[i]); } else { var narr = Arguments[i] as NamedArgumentResolveResult; if (narr != null) { results[mappedTo] = narr.Argument; } else { results[mappedTo] = Arguments[i]; } } } } if (IsExpandedForm) { results[results.Length - 1] = new ArrayCreateResolveResult(Member.Parameters.Last().Type, null, paramsArguments.ToArray()); } for (int i = 0; i < results.Length; i++) { if (results[i] == null) { if (Member.Parameters[i].IsOptional) { results[i] = new ConstantResolveResult(Member.Parameters[i].Type, Member.Parameters[i].ConstantValue); } else { results[i] = ErrorResolveResult.UnknownError; } } } return(results); }
bool IntegerLiteralConversion(object value, Type to) { IType fromType = value.GetType().ToTypeReference().Resolve(ctx); ConstantResolveResult crr = new ConstantResolveResult(fromType, value); IType to2 = to.ToTypeReference().Resolve(ctx); return(conversions.ImplicitConversion(crr, to2)); }
Conversion IntegerLiteralConversion(object value, Type to) { IType fromType = compilation.FindType(value.GetType()); ConstantResolveResult crr = new ConstantResolveResult(fromType, value); IType to2 = compilation.FindType(to); return(conversions.ImplicitConversion(crr, to2)); }
public void NullableConversion_BasedOnImplicitEnumerationConversion() { ResolveResult zero = new ConstantResolveResult(compilation.FindType(KnownTypeCode.Int32), 0); ResolveResult one = new ConstantResolveResult(compilation.FindType(KnownTypeCode.Int32), 1); Assert.AreEqual(C.EnumerationConversion(true, true), conversions.ExplicitConversion(zero, compilation.FindType(typeof(StringComparison?)))); Assert.AreEqual(C.EnumerationConversion(false, true), conversions.ExplicitConversion(one, compilation.FindType(typeof(StringComparison?)))); }
int BetterConversion(object value, Type t1, Type t2) { IType fromType = value.GetType().ToTypeReference().Resolve(ctx); ConstantResolveResult crr = new ConstantResolveResult(fromType, value); IType t1Type = t1.ToTypeReference().Resolve(ctx); IType t2Type = t2.ToTypeReference().Resolve(ctx); return(conversions.BetterConversion(crr, t1Type, t2Type)); }
int BetterConversion(object value, Type t1, Type t2) { IType fromType = compilation.FindType(value.GetType()); ConstantResolveResult crr = new ConstantResolveResult(fromType, value); IType t1Type = compilation.FindType(t1); IType t2Type = compilation.FindType(t2); return(conversions.BetterConversion(crr, t1Type, t2Type)); }
public void EnumerationConversion() { ResolveResult zero = new ConstantResolveResult(compilation.FindType(KnownTypeCode.Int32), 0); ResolveResult one = new ConstantResolveResult(compilation.FindType(KnownTypeCode.Int32), 1); C implicitEnumerationConversion = C.EnumerationConversion(true, false); Assert.AreEqual(implicitEnumerationConversion, conversions.ImplicitConversion(zero, compilation.FindType(typeof(StringComparison)))); Assert.AreEqual(C.None, conversions.ImplicitConversion(one, compilation.FindType(typeof(StringComparison)))); }
public void EnumBitwiseOrWithMissingBaseType() { var resolver = new CSharpResolver(enumWithMissingBaseType.Compilation); var lhs = new ConstantResolveResult(enumWithMissingBaseType, 1); var rhs = new ConstantResolveResult(enumWithMissingBaseType, 2); var rr = (ConstantResolveResult)resolver.ResolveBinaryOperator(BinaryOperatorType.BitwiseOr, lhs, rhs); Assert.AreEqual(enumWithMissingBaseType, rr.Type); Assert.AreEqual(3, rr.ConstantValue); }
public IMethod ResolveConstructor(ITypeResolveContext context) { CSharpResolver r = new CSharpResolver(context); IType type = attributeType.Resolve(context); int totalArgumentCount = 0; if (positionalArguments != null) { totalArgumentCount += positionalArguments.Count; } if (namedCtorArguments != null) { totalArgumentCount += namedCtorArguments.Count; } ResolveResult[] arguments = new ResolveResult[totalArgumentCount]; string[] argumentNames = new string[totalArgumentCount]; int i = 0; if (positionalArguments != null) { while (i < positionalArguments.Count) { IConstantValue cv = positionalArguments[i]; arguments[i] = new ConstantResolveResult(cv.GetValueType(context), cv.GetValue(context)); i++; } } if (namedCtorArguments != null) { foreach (var pair in namedCtorArguments) { argumentNames[i] = pair.Key; arguments[i] = new ConstantResolveResult(pair.Value.GetValueType(context), pair.Value.GetValue(context)); i++; } } MemberResolveResult mrr = r.ResolveObjectCreation(type, arguments, argumentNames) as MemberResolveResult; return(mrr != null ? mrr.Member as IMethod : null); }
public override IList <ResolveResult> GetArgumentsForCall() { ResolveResult[] results = new ResolveResult[Member.Parameters.Count]; List <ResolveResult> paramsArguments = IsExpandedForm ? new List <ResolveResult>() : null; // map arguments to parameters: for (int i = 0; i < Arguments.Count; i++) { int mappedTo; if (argumentToParameterMap != null) { mappedTo = argumentToParameterMap[i]; } else { mappedTo = IsExpandedForm ? Math.Min(i, results.Length - 1) : i; } if (mappedTo >= 0 && mappedTo < results.Length) { if (IsExpandedForm && mappedTo == results.Length - 1) { paramsArguments.Add(Arguments[i]); } else { if (Arguments[i] is NamedArgumentResolveResult narr) { results[mappedTo] = narr.Argument; } else { results[mappedTo] = Arguments[i]; } } } } if (IsExpandedForm) { IType arrayType = Member.Parameters.Last().Type; IType int32 = Member.Compilation.FindType(KnownTypeCode.Int32); ResolveResult[] sizeArguments = { new ConstantResolveResult(int32, paramsArguments.Count) }; results[results.Length - 1] = new ArrayCreateResolveResult(arrayType, sizeArguments, paramsArguments); } for (int i = 0; i < results.Length; i++) { if (results[i] == null) { if (Member.Parameters[i].IsOptional) { results[i] = new ConstantResolveResult(Member.Parameters[i].Type, Member.Parameters[i].ConstantValue); } else { results[i] = ErrorResolveResult.UnknownError; } } } return(results); }
int BetterConversion(object value, Type t1, Type t2) { IType fromType = value.GetType().ToTypeReference().Resolve(ctx); ConstantResolveResult crr = new ConstantResolveResult(fromType, value); IType t1Type = t1.ToTypeReference().Resolve(ctx); IType t2Type = t2.ToTypeReference().Resolve(ctx); return conversions.BetterConversion(crr, t1Type, t2Type); }
bool IntegerLiteralConversion(object value, Type to) { IType fromType = value.GetType().ToTypeReference().Resolve(ctx); ConstantResolveResult crr = new ConstantResolveResult(fromType, value); IType to2 = to.ToTypeReference().Resolve(ctx); return conversions.ImplicitConversion(crr, to2); }