public InvocationTypeInferenceRules() : base(CompilerContext.Current) { var Array_EnumerableConstructor = Map(Methods.Of <IEnumerable, Array>(Builtins.array)); var Array_TypedEnumerableConstructor = Map(Methods.Of <Type, IEnumerable, Array>(Builtins.array)); var MultiDimensionalArray_TypedConstructor = Map(Methods.Of <Type, int[], Array>(Builtins.matrix)); RegisterTypeInferenceRuleFor( MultiDimensionalArray_TypedConstructor, (invocation, method) => { IType type = TypeSystemServices.GetReferencedType(invocation.Arguments[0]); if (type == null) { return(null); } return(type.MakeArrayType(invocation.Arguments.Count - 1)); }); RegisterTypeInferenceRuleFor( Array_EnumerableConstructor, (invocation, method) => { IType enumeratorItemType = TypeSystemServices.GetEnumeratorItemType(TypeSystemServices.GetExpressionType(invocation.Arguments[0])); if (TypeSystemServices.ObjectType == enumeratorItemType) { return(null); } invocation.Target.Entity = Array_TypedEnumerableConstructor; invocation.ExpressionType = Array_TypedEnumerableConstructor.ReturnType; invocation.Arguments.Insert(0, CodeBuilder.CreateReference(enumeratorItemType)); return(enumeratorItemType.MakeArrayType(1)); }); }
public static IType ArrayOfTypeReferencedByFirstArgument(MethodInvocationExpression invocation, IMethod method) { var type = TypeSystemServices.GetReferencedType(invocation.Arguments[0]); if (type == null) { return(null); } return(type.MakeArrayType(1)); }
public static IType TypeReferencedBySecondArgument(MethodInvocationExpression invocation, IMethod method) { return(TypeSystemServices.GetReferencedType(invocation.Arguments[1])); }