public XResolutionException(XReference member) : base(string.Format("Cannot resolve {0}", member.FullName)) { }
/// <summary> /// Build expressions that are used when calling a .NET method with generic instance parameters, one expression for /// each required parameter. /// </summary> private static IList<AstExpression> CreateGenericInstanceCallArguments(ISourceLocation seqp, XReference member, MethodSource currentMethod, AssemblyCompiler compiler) { // Prepare var genericInstance = member as IXGenericInstance; if (genericInstance == null) { #if DEBUG //Debugger.Launch(); #endif throw new CompilerException(string.Format("{0} is not a generic instance", member)); } var count = genericInstance.GenericArguments.Count; var typeHelperType = compiler.GetDot42InternalType(InternalConstants.TypeHelperName).Resolve(); // Foreach type argument var typeExpressions = new List<AstExpression>(); for (var i = 0; i < count; i++) { var argType = genericInstance.GenericArguments[i]; var typeExpr = LoadTypeForGenericInstance(seqp, currentMethod, argType, compiler, typeHelperType, compiler.Module.TypeSystem, TypeConversion.EnsureTrueOrMarkerType); typeExpressions.Add(typeExpr); } bool isMethod = member is XMethodReference; bool buildArray = count > (isMethod ? InternalConstants.GenericMethodParametersAsArrayThreshold : InternalConstants.GenericTypeParametersAsArrayThreshold); if (buildArray) { //TODO: when we can determine that all expressions just load our classes generic instance (array) field, // and extract all values in sequence, we should shortcut and just return a load of the field, // instead of unpacking and re-packing each value, putting pressure on the garbage collector // in the process. This is not a huge problem any longer, as we do not use arrays as often // as we used to. Nevertheless, where arrays are used, possible re-use should be faily common, // e.g. when instatiating nested classes or invoking static methods. var elementType = compiler.Module.TypeSystem.Type; return new [] { new AstExpression(seqp, AstCode.InitArrayFromArguments, new XArrayType(elementType), typeExpressions) { ExpectedType = new XArrayType(elementType) }}; } else { return typeExpressions; } }
/// <summary> /// Build expression that creates an instance of GenericInstance with arguments from the given .NET generic instance. /// </summary> private static AstExpression CreateGenericInstance(ISourceLocation seqp, XReference member, MethodSource currentMethod, AssemblyCompiler compiler) { // Prepare var genericInstance = member as IXGenericInstance; if (genericInstance == null) { #if DEBUG //Debugger.Launch(); #endif throw new CompilerException(string.Format("{0} is not a generic instance", member)); } var count = genericInstance.GenericArguments.Count; var typeHelperType = compiler.GetDot42InternalType(InternalConstants.TypeHelperName).Resolve(); // Foreach type argument var typeExpressions = new List<AstExpression>(); for (var i = 0; i < count; i++) { var argType = genericInstance.GenericArguments[i]; var typeExpr = LoadTypeForGenericInstance(seqp, currentMethod, argType, typeHelperType, compiler.Module.TypeSystem); typeExpressions.Add(typeExpr); } var elementType = compiler.Module.TypeSystem.Type; return new AstExpression(seqp, AstCode.InitArrayFromArguments, new XArrayType(elementType), typeExpressions) { ExpectedType = new XArrayType(elementType) }; }