Example #1
0
        /// <summary>
        /// Is this reference equal to the given other reference?
        /// </summary>
        public virtual bool IsSameExceptDeclaringType(XMethodReference other)
        {
            if ((Name == other.Name) &&
                (HasThis == other.HasThis) &&
                (Parameters.Count == other.Parameters.Count) &&
                ReturnType.IsSame(other.ReturnType) &&
                (IsGenericInstance == other.IsGenericInstance))
            {
                // Possibly the same
                if (Parameters.Where((t, i) => !t.IsSame(other.Parameters[i])).Any())
                {
                    return(false);
                }

                if (IsGenericInstance)
                {
                    if (!((XGenericInstanceMethod)this).IsSame((XGenericInstanceMethod)other))
                    {
                        return(false);
                    }
                }

                return(true);
            }
            return(false);
        }
 /// <summary>
 /// Default ctor
 /// </summary>
 public XGenericInstanceMethod(XMethodReference elementMethod, IEnumerable<XTypeReference> genericArguments)
     : base(elementMethod.DeclaringType)
 {
     this.elementMethod = elementMethod;
     this.genericArguments = genericArguments.ToList().AsReadOnly();
     if (this.genericArguments.Count != GenericParameters.Count)
         throw new ArgumentException("Mismatch in generic parameter/argument count");
 }
Example #3
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public XGenericInstanceMethod(XMethodReference elementMethod, IEnumerable <XTypeReference> genericArguments)
     : base(elementMethod.DeclaringType)
 {
     this.elementMethod    = elementMethod;
     this.genericArguments = genericArguments.ToList().AsReadOnly();
     if (this.genericArguments.Count != GenericParameters.Count)
     {
         throw new ArgumentException("Mismatch in generic parameter/argument count");
     }
 }
Example #4
0
        /// <summary>
        /// Try to get a method with given reference in this type.
        /// The declaring type of the method reference is assumed to refer to this type.
        /// </summary>
        public bool TryGet(XMethodReference methodRef, out XMethodDefinition method)
        {
            // Look in my own methods
            method = Methods.FirstOrDefault(x => x.IsSameExceptDeclaringType(methodRef));
            if (method != null)
            {
                return(true);
            }

            // Look in base type
            XTypeDefinition baseTypeDef;

            if ((BaseType != null) && BaseType.TryResolve(out baseTypeDef))
            {
                return(baseTypeDef.TryGet(methodRef, out method));
            }
            return(false);
        }
Example #5
0
        /// <summary>
        /// Convert a nullable .GetValueOrDefault()
        /// </summary>
        private static void ConvertPrimitiveGetValueOrDefault(AstExpression node, XMethodReference ilMethod, XTypeReference type, AstExpression target, XModule data)
        {
            // Clear node
            var originalArgs = node.Arguments.ToList();
            var getValueRef = new XMethodReference.Simple("GetValue", false, ilMethod.ReturnType, ilMethod.DeclaringType, new[] { data.TypeSystem.Object, data.TypeSystem.Bool }, null);
            node.Operand = getValueRef;
            node.Arguments.Clear();
            node.InferredType = type;
            node.ExpectedType = type;

            AddLoadArgument(node, target, originalArgs[0]);
            node.Arguments.Add(new AstExpression(node.SourceLocation, AstCode.Ldc_I4, 1) { InferredType = data.TypeSystem.Bool });
        }
Example #6
0
        /// <summary>
        /// Convert a nullable(T) ctor into a convert function.
        /// </summary>
        private static void ConvertOtherNewObj(AstExpression node, XMethodReference ctor, XTypeReference type, AstExpression value)
        {
            // Clear node
            node.CopyFrom(value);
            /*node.Arguments.Clear();
            node.InferredType = ctor.DeclaringType;
            node.ExpectedType = ctor.DeclaringType;

            node.Code = AstCode.Box;
            node.Operand = type;
            node.Arguments.Add(value);*/
        }
Example #7
0
        /// <summary>
        /// Convert a nullable ctor into a convert function.
        /// </summary>
        private static void ConvertPrimitiveCtor(AstExpression node, XMethodReference ctor, XTypeReference type, AstExpression target, AstExpression value)
        {
            // Clear node
            node.Arguments.Clear();
            node.InferredType = ctor.DeclaringType;
            node.ExpectedType = ctor.DeclaringType;

            switch (target.Code)
            {
                case AstCode.Ldloca:
                    node.Code = AstCode.Stloc;
                    node.Operand = target.Operand;
                    node.Arguments.Add(new AstExpression(node.SourceLocation, AstCode.Box, type, value));
                    break;

                case AstCode.Ldflda:
                    node.Code = AstCode.Stfld;
                    node.Operand = target.Operand;
                    node.Arguments.Add(new AstExpression(node.SourceLocation, AstCode.Box, type, value));
                    break;

                case AstCode.Ldsflda:
                    node.Code = AstCode.Stsfld;
                    node.Operand = target.Operand;
                    node.Arguments.Add(new AstExpression(node.SourceLocation, AstCode.Box, type, value));
                    break;
            }
        }
Example #8
0
        /// <summary>
        /// The given call is a call to a ctor.
        /// Convert it to newobj
        /// </summary>
        private static void ConvertCtorCall(AstExpression callNode, XMethodReference ctor)
        {
            // Create a new node to construct the object
            var newObjNode = new AstExpression(callNode.SourceLocation, AstCode.Newobj, null, callNode.Arguments.Skip(1).ToList());
            newObjNode.Operand = ctor;
            newObjNode.InferredType = ctor.DeclaringType;

            // Remove "this" argument
            var thisExpr = callNode.Arguments[0];
            callNode.Arguments.Clear();
            callNode.Arguments.Add(newObjNode);
            callNode.InferredType = ctor.DeclaringType;

            // Convert callNode to stX node
            switch (thisExpr.Code)
            {
                case AstCode.Ldloca:
                case AstCode.Ldloc:
                    callNode.Code = AstCode.Stloc;
                    callNode.Operand = thisExpr.Operand;
                    break;
                case AstCode.Ldflda:
                case AstCode.Ldfld:
                    callNode.Code = AstCode.Stfld;
                    callNode.Operand = thisExpr.Operand;
                    break;
                case AstCode.Ldsflda:
                case AstCode.Ldsfld:
                    callNode.Code = AstCode.Stsfld;
                    callNode.Operand = thisExpr.Operand;
                    break;
                default:
                    throw new NotSupportedException(string.Format("Unsupported opcode {0} in call to struct ctor", (int)thisExpr.Code));
            }
        }
Example #9
0
        /// <summary>
        /// Is this reference equal to the given other reference?
        /// </summary>
        public virtual bool IsSameExceptDeclaringType(XMethodReference other)
        {
            if ((Name == other.Name) &&
                (HasThis == other.HasThis) &&
                (Parameters.Count == other.Parameters.Count) &&
                ReturnType.IsSame(other.ReturnType) &&
                (IsGenericInstance == other.IsGenericInstance))
            {
                // Possibly the same
                if (Parameters.Where((t, i) => !t.IsSame(other.Parameters[i])).Any())
                {
                    return false;
                }

                if (IsGenericInstance)
                {
                    if (!((XGenericInstanceMethod)this).IsSame((XGenericInstanceMethod)other))
                        return false;
                }

                return true;
            }
            return false;
        }
Example #10
0
 /// <summary>
 /// Create the body of the Create(int|long) method.
 /// </summary>
 private AstBlock CreateCreateBody(XSyntheticMethodDefinition method, XMethodReference ctor)
 {
     return AstBlock.CreateOptimizedForTarget(
         new AstExpression(AstNode.NoSource, AstCode.Ret, null,
             new AstExpression(AstNode.NoSource, AstCode.Newobj, ctor,
                 new AstExpression(AstNode.NoSource, AstCode.Ldstr, "?"),
                 new AstExpression(AstNode.NoSource, AstCode.Ldc_I4, -1),
                 new AstExpression(AstNode.NoSource, AstCode.Ldloc, method.AstParameters[0]))));
 }
Example #11
0
 /// <summary>
 /// Is this reference equal to the given other reference?
 /// </summary>
 public bool IsSame(XMethodReference other)
 {
     return(DeclaringType.IsSame(other.DeclaringType) && IsSameExceptDeclaringType(other));
 }
        /// <summary>
        /// Generate code for a call to a method of an array type.
        /// </summary>
        private bool TryVisitArrayTypeMethodCallExpression(AstExpression node, XMethodReference ilMethodRef, List<RLRange> args, AstNode parent, out RLRange result)
        {
            var methodName = ilMethodRef.Name;
            var dimensions = (methodName == "Set") ? args.Count - 2 : args.Count - 1;

            // Get all but last dimensions
            var arr = frame.AllocateTemp(FrameworkReferences.Object);
            var first = this.Add(node.SourceLocation, RCode.Move_object, arr, args[0].Result);
            for (var d = 0; d < dimensions - 1; d++)
            {
                this.Add(node.SourceLocation, RCode.Aget_object, arr, arr, args[d + 1].Result);
            }

            // Get/Set value
            switch (methodName)
            {
                case "Get":
                    {
                        var valueType = node.GetResultType();
                        var lastIndexArg = args[args.Count - 1];
                        var agetCode = new XArrayType(valueType).AGet();
                        var resultReg = frame.AllocateTemp(valueType.GetReference(targetPackage));
                        var last = this.Add(node.SourceLocation, agetCode, resultReg, arr, lastIndexArg.Result);
                        result = new RLRange(first, last, resultReg);
                        return true;
                    }
                case "Set":
                    {
                        var valueType = node.Arguments[node.Arguments.Count - 1].GetResultType();
                        var lastIndexArg = args[args.Count - 2];
                        var aputCode = new XArrayType(valueType).APut();

                        // Perform type conversion if needed
                        bool isConverted;
                        var valueR = args[args.Count - 1].Result;
                        var converted = this.ConvertTypeBeforeStore(node.SourceLocation, valueType, valueType, valueR, targetPackage, frame, compiler, out isConverted);
                        if (isConverted) valueR = converted.Result;
                        
                        var last = this.Add(node.SourceLocation, aputCode, valueR, arr, lastIndexArg.Result);
                        result = new RLRange(first, last, arr);
                        return true;
                    }
                default:
                    result = null;
                    return false;
            }
        }
        /// <summary>
        /// Apply type/content conversion of arguments just before a method call.
        /// </summary>
        private void ConvertParametersAfterCall(AstExpression node, List<RLRange> args, XMethodReference targetMethod, int argsOffset, List<RLRange> originalArgs)
        {
            // Unbox generic arrays
            for (var i = 0; i < targetMethod.Parameters.Count; i++)
            {
                var parameterType = targetMethod.Parameters[i].ParameterType;
                var nodeArgI = node.Arguments[argsOffset + i];
                var nodeArgIType = nodeArgI.GetResultType();
                var boxedArg = args[argsOffset + i];
                var original = originalArgs[argsOffset + i];
                if ((parameterType.IsGenericParameterArray()) && nodeArgIType.IsPrimitiveArray())
                {
                    // Convert back using Boxing class
                    this.UnboxGenericArray(node.SourceLocation, original.Result, boxedArg.Result, nodeArgIType, targetPackage, frame, compiler);
                }
            }

            // Store byref/out arguments
            foreach (var argument in node.Arguments.Where(x => x.Code == AstCode.ByRefArray || x.Code == AstCode.ByRefOutArray))
            {
                var stExpression = argument.StoreByRefExpression;
                stExpression.Accept(this, node);
            }
        }
 /// <summary>
 /// Apply type/content conversion of arguments just before a method call.
 /// </summary>
 private void ConvertParametersBeforeCall(AstExpression node, List<RLRange> args, XMethodReference targetMethod, out int argsOffset, out List<RLRange> originalArgs)
 {
     // Convert parameters when needed
     argsOffset = (args.Count - targetMethod.Parameters.Count) - node.GenericInstanceArgCount;
     originalArgs = args.ToList();
     for (var i = 0; i < targetMethod.Parameters.Count; i++)
     {
         var parameterType = targetMethod.Parameters[i].ParameterType;
         if (parameterType.IsByte())
         {
             // Convert from byte to sbyte
             var rArg = args[argsOffset + i].Result.Register;
             this.Add(node.SourceLocation, RCode.Int_to_byte, rArg, rArg);
         }
         else if (parameterType.IsUInt16())
         {
             // Convert from ushort to short
             var rArg = args[argsOffset + i].Result.Register;
             this.Add(node.SourceLocation, RCode.Int_to_short, rArg, rArg);
         }
         else
         {
             var nodeArgI = node.Arguments[argsOffset + i];
             var nodeArgIType = nodeArgI.GetResultType();
             var originalArg = args[argsOffset + i];
             var rx = originalArg.Result;
             if ((parameterType.IsGenericParameter) && (nodeArgIType.IsPrimitive))
             {
                 // Convert using (valueOf)
                 var tmp = this.Box(node.SourceLocation, rx, nodeArgIType, targetPackage, frame);
                 args[argsOffset + i] = new RLRange(originalArg.First, originalArg.Last, tmp.Result);
             }
             else if ((parameterType.IsGenericParameterArray()) && nodeArgIType.IsPrimitiveArray())
             {
                 // Convert using Boxing class
                 var tmp = this.BoxGenericArray(node.SourceLocation, rx, nodeArgIType, targetPackage, frame, compiler);
                 args[argsOffset + i] = new RLRange(originalArg.First, originalArg.Last, tmp.Result);
             }
             else
             {
                 bool isConverted;
                 var tmp = this.ConvertTypeBeforeStore(node.SourceLocation, nodeArgIType, parameterType, rx, targetPackage, frame, compiler, out isConverted);
                 if (isConverted)
                 {
                     args[argsOffset + i] = new RLRange(originalArg.First, originalArg.Last, tmp.Result);
                 }
             }
         }
     }
 }
Example #15
0
        /// <summary>
        /// Create the body of the class ctor.
        /// </summary>
        private AstBlock CreateClassCtorBody(bool isWide, XFieldDefinition enumInfoField, XFieldDefinition defaultField, XMethodReference enumInfoCtor, XTypeReference valueType, XTypeSystem typeSystem)
        {
            var internalEnumType = Compiler.GetDot42InternalType("Enum");
            var internalEnumInfoType = Compiler.GetDot42InternalType("EnumInfo");
            var valueToFieldMap = new Dictionary<object, XFieldDefinition>();
            var ldc = isWide ? AstCode.Ldc_I8 : AstCode.Ldc_I4;

            var ast = AstBlock.CreateOptimizedForTarget(
                // Instantiate enum info field
                new AstExpression(AstNode.NoSource, AstCode.Stsfld, enumInfoField,
                    new AstExpression(AstNode.NoSource, AstCode.Newobj, enumInfoCtor)));

            // Instantiate values for each field
            var ordinal = 0;
            foreach (var field in XType.Fields.Where(x => x.IsStatic && !(x is XSyntheticFieldDefinition)))
            {
                // Find dex field
                object value;
                if (!field.TryGetEnumValue(out value))
                    throw new CompilerException(string.Format("Cannot get enum value from field {0}", field.FullName));
                value = isWide ? (object)XConvert.ToLong(value) : (object)XConvert.ToInt(value);
                XFieldDefinition existingField;
                AstExpression valueExpr;
                if (valueToFieldMap.TryGetValue(value, out existingField))
                {
                    // Re-use instance of existing field
                    valueExpr = new AstExpression(AstNode.NoSource, AstCode.Ldsfld, existingField);
                }
                else
                {
                    // Record
                    valueToFieldMap[value] = field;

                    // Call ctor
                    valueExpr = new AstExpression(AstNode.NoSource, AstCode.Newobj, ctor,
                        new AstExpression(AstNode.NoSource, AstCode.Ldstr, field.Name),
                        new AstExpression(AstNode.NoSource, AstCode.Ldc_I4, ordinal),
                        new AstExpression(AstNode.NoSource, ldc, value));
                }

                // Initialize static field
                ast.Body.Add(new AstExpression(AstNode.NoSource, AstCode.Stsfld, field, valueExpr));

                // Add to info
                var addMethod = new XMethodReference.Simple("Add", true, typeSystem.Void, internalEnumInfoType,
                    XParameter.Create("value", valueType),
                    XParameter.Create("instance", internalEnumType));
                ast.Body.Add(new AstExpression(AstNode.NoSource, AstCode.Call, addMethod,
                    new AstExpression(AstNode.NoSource, AstCode.Ldsfld, enumInfoField),
                    new AstExpression(AstNode.NoSource, ldc, value),
                    new AstExpression(AstNode.NoSource, AstCode.Ldsfld, field)));

                // Increment ordinal
                ordinal++;
            }

            // Initialize default field
            var getValueMethod = new XMethodReference.Simple("GetValue", true, internalEnumType, internalEnumInfoType,
                XParameter.Create("value", valueType));
            ast.Body.Add(new AstExpression(AstNode.NoSource, AstCode.Stsfld, defaultField,
                new AstExpression(AstNode.NoSource, AstCode.SimpleCastclass, XType,
                    new AstExpression(AstNode.NoSource, AstCode.Call, getValueMethod,
                        new AstExpression(AstNode.NoSource, AstCode.Ldsfld, enumInfoField),
                        new AstExpression(AstNode.NoSource, ldc, 0)))));

            // Return
            ast.Body.Add(new AstExpression(AstNode.NoSource, AstCode.Ret, null));
            return ast;
        }
Example #16
0
 /// <summary>
 /// Generate an Invoke opcode.
 /// </summary>
 internal static RCode Invoke(this XMethodDefinition targetMethod, XMethodReference targetMethodRef, MethodSource currentMethod, bool isSpecial = false)
 {
     if (targetMethod != null)
     {
         if (targetMethod.DeclaringType.IsDelegate())
         {
             return RCode.Invoke_interface;
         }
         if (targetMethod.IsStatic || targetMethod.IsAndroidExtension)
         {
             return RCode.Invoke_static;
         }
         if ((currentMethod != null) && targetMethod.UseInvokeSuper(currentMethod.Method))
         {
             return RCode.Invoke_super;
         }
         if (isSpecial && !targetMethod.IsConstructor && (currentMethod != null) && targetMethod.DeclaringType.IsBaseOf(currentMethod.Method.DeclaringType))
         {
             return RCode.Invoke_super;
         }
         if (targetMethod.UseInvokeInterface)
         {
             return RCode.Invoke_interface;                    
         }
         if (targetMethod.IsDirect)
         {
             return RCode.Invoke_direct;
         }
         if (targetMethod.DeclaringType.IsInterface)
         {
             return RCode.Invoke_interface;
         }
     }
     if (targetMethodRef != null)
     {
         if (!targetMethodRef.HasThis)
         {
             return RCode.Invoke_static;
         }
         switch (targetMethodRef.Name)
         {
             case "<init>":
             case "<clinit>":
             case ".ctor":
             case ".cctor":
                 return RCode.Invoke_direct;                        
         }
     }
     return RCode.Invoke_virtual;
 }
Example #17
0
        /// <summary>
        /// Try to get a method with given reference in this type.
        /// The declaring type of the method reference is assumed to refer to this type.
        /// </summary>
        public bool TryGet(XMethodReference methodRef, out XMethodDefinition method)
        {
            // Look in my own methods
            method = Methods.FirstOrDefault(x => x.IsSameExceptDeclaringType(methodRef));
            if (method != null)
                return true;

            // Look in base type
            XTypeDefinition baseTypeDef;
            if ((BaseType != null) && BaseType.TryResolve(out baseTypeDef))
            {
                return baseTypeDef.TryGet(methodRef, out method);
            }
            return false;
        }
        void ProcessArgument(AstExpression callNode, XMethodReference methodRef, int argumentIndex, MethodSource currentMethod, XModule assembly)
        {
            var node = callNode.Arguments[argumentIndex];

            // Should we do something?
            switch (node.Code)
            {
                case AstCode.Ldloca: // Parameter
                case AstCode.AddressOf: // Local variable
                case AstCode.Ldflda: // Instance field
                case AstCode.Ldsflda: // Static field
                case AstCode.Ldelema: // Array
                    break;
                case AstCode.Ldloc:
                    if (!node.MatchThis() || !currentMethod.IsDotNet)
                        return;
                    break;
                default:
                    return;
            }

            // Process argument
            var method = methodRef.Resolve();
            var argIsThis = !method.IsStatic && (argumentIndex == 0);
            var parameterIndex = method.IsStatic ? argumentIndex : argumentIndex - 1;
            var parameter = argIsThis ? null : method.Parameters[parameterIndex];
            var argType = argIsThis ? method.DeclaringType : parameter.ParameterType;
            //var argAttrs = argIsThis ? ParameterAttributes.None : parameter.Attributes;
            var argIsByRef = argType.IsByReference;
            var argIsOut = argIsThis ? false : argIsByRef && (parameter.Kind == XParameterKind.Output); // argIsByRef && argAttrs.HasFlag(ParameterAttributes.Out);
            var argIsGenByRefParam = argIsByRef && argType.ElementType.IsGenericParameter;
            switch (node.Code)
            {
                case AstCode.Ldloca: // Parameter
                    {
                        var variable = ((AstVariable)node.Operand);
                        if (variable.Type.IsPrimitive || argIsByRef)
                        {
                            // Box first
                            var ldloc = new AstExpression(node.SourceLocation, AstCode.Ldloc, node.Operand) { InferredType = variable.Type };
                            if (argIsByRef)
                            {
                                var stloc = new AstExpression(node.SourceLocation, AstCode.Stloc, node.Operand) { InferredType = variable.Type };
                                stloc.Arguments.Add(GetValueOutOfByRefArray(node, variable.Type, argIsGenByRefParam, assembly));
                                ConvertToByRefArray(node, variable.Type, ldloc, stloc, argIsOut, argIsGenByRefParam, assembly);
                            }
                            else
                            {
                                ConvertToBox(node, variable.Type, ldloc);
                            }
                        }
                        else if (variable.Type.IsGenericParameter)
                        {
                            // Convert to ldarg
                            var ldloc = new AstExpression(node.SourceLocation, AstCode.Ldloc, node.Operand) { InferredType = variable.Type };
                            callNode.Arguments[argumentIndex] = ldloc;
                        }
                    }
                    break;
                case AstCode.Ldloc: // this
                    {
                        var variable = ((AstVariable)node.Operand);
                        if (argIsThis && (variable.Type.IsByReference))
                        {
                            node.SetType(variable.Type.ElementType);
                        }
                        else if (argIsByRef)
                        {
                            var ldclone = new AstExpression(node);
                            var stExpr = new AstExpression(node.SourceLocation, AstCode.Nop, null);
                            var elementType = variable.Type;
                            if (elementType.IsByReference) elementType = elementType.ElementType;
                            ConvertToByRefArray(node, elementType, ldclone, stExpr, argIsOut, argIsGenByRefParam, assembly);
                        }
                    }
                    break;
                case AstCode.AddressOf: // Local variable
                    {
                        var arg = node.Arguments[0];
                        var type = arg.GetResultType();
                        var typeDef = type.Resolve();
                        if (typeDef.IsPrimitive)
                        {
                            if (argIsByRef)
                            {
                                throw new CompilerException("Unsupported use of AddressOf by byref argument");
                            }
                            else
                            {
                                ConvertToBox(node, type, arg);
                            }
                        }
                    }
                    break;
                case AstCode.Ldflda: // Instance field
                case AstCode.Ldsflda: // Static field
                    {
                        var fieldRef = (XFieldReference)node.Operand;
                        var field = fieldRef.Resolve();
                        if (field.FieldType.IsPrimitive || argIsByRef)
                        {
                            // Box first
                            var ldfldCode = (node.Code == AstCode.Ldflda) ? AstCode.Ldfld : AstCode.Ldsfld;
                            var ldfld = new AstExpression(node.SourceLocation, ldfldCode, node.Operand) { InferredType = field.FieldType };
                            ldfld.Arguments.AddRange(node.Arguments);
                            if (argIsByRef)
                            {
                                var stfldCode = (node.Code == AstCode.Ldflda) ? AstCode.Stfld : AstCode.Stsfld;
                                var stfld = new AstExpression(node.SourceLocation, stfldCode, node.Operand) { InferredType = field.FieldType };
                                stfld.Arguments.AddRange(node.Arguments); // instance
                                stfld.Arguments.Add(GetValueOutOfByRefArray(node, field.FieldType, argIsGenByRefParam, assembly)); // value
                                ConvertToByRefArray(node, field.FieldType, ldfld, stfld, argIsOut, argIsGenByRefParam, assembly);
                            }
                            else
                            {
                                ConvertToBox(node, field.FieldType, ldfld);
                            }
                        }
                    }
                    break;
                case AstCode.Ldelema: // Array element
                    {
                        var array = node.Arguments[0];
                        var arrayType = array.GetResultType();
                        var type = arrayType.ElementType;
                        if (type.IsPrimitive || argIsByRef)
                        {
                            // Box first
                            var ldElemCode = type.GetLdElemCode();
                            var ldelem = new AstExpression(node.SourceLocation, ldElemCode, node.Operand) { InferredType = type };
                            ldelem.Arguments.AddRange(node.Arguments);
                            if (argIsByRef)
                            {
                                var stelemCode = type.GetStElemCode();
                                var stelem = new AstExpression(node.SourceLocation, stelemCode, node.Operand) { InferredType = type };
                                stelem.Arguments.AddRange(node.Arguments);
                                stelem.Arguments.Add(GetValueOutOfByRefArray(node, type, argIsGenByRefParam, assembly));
                                ConvertToByRefArray(node, type, ldelem, stelem, argIsOut, argIsGenByRefParam, assembly);
                            }
                            else
                            {
                                ConvertToBox(node, type, ldelem);
                            }
                        }
                    }
                    break;
            }
        }
Example #19
0
        /// <summary>
        /// Gets the converted name of the given field.
        /// </summary>
        public static string GetConvertedName(XMethodReference method)
        {
            var name = method.Name;
            // Handle special names
            switch (name)
            {
                case ".ctor":
                    return "<init>";
                case ".cctor":
                    return "<clinit>";
            }

            // Handle properties in custom views.
            var methodDef = method.Resolve();
            if (methodDef.DeclaringType.HasCustomViewAttribute())
            {
                if (methodDef.IsSetter && name.StartsWith("set_"))
                {
                    name = "set" + name.Substring(4);
                }
                else if (methodDef.IsGetter && name.StartsWith("get_"))
                {
                    name = "get" + name.Substring(4);
                }
            }

            // Avoid special characters
            var originalName = name;
            name = name.Replace('<', '_');
            name = name.Replace('>', '_');
            name = name.Replace('.', '_');

            if (name != originalName)
            {
                // Add hash to ensure unique
                name = name + '_' + GetHashPostfix(originalName);
            }

            return name;
        }
Example #20
0
 /// <summary>
 /// Is this reference equal to the given other reference?
 /// </summary>
 public bool IsSame(XMethodReference other)
 {
     return DeclaringType.IsSame(other.DeclaringType) && IsSameExceptDeclaringType(other);
 }