コード例 #1
0
	public static Vector3 GetPointerPos(PointerType type) {
		if (_pointerPosDict.ContainsKey (type)) {
			return _pointerPosDict[type];
		} else {
			return Vector3.zero;
		}
	}
コード例 #2
0
	public static void SetPointerPos(PointerType type, Vector3 pos) {
		if (_pointerPosDict.ContainsKey (type)) {
			_pointerPosDict [type] = pos;
		} else {
			_pointerPosDict.Add (type, pos);
		}
	}
コード例 #3
0
ファイル: Screens.cs プロジェクト: reelgood/dcsg
 public Screen()
 {
     _pointer = PointerType.DEFAULT;
     sb = new SpriteBatch(DCSG.MainObject.GraphicsDevice);
     DCSG.OnUpdate += new DCSG.XNAHookEvent(Update);
     DCSG.OnDraw += new DCSG.XNADrawEvent(Draw);
 }
コード例 #4
0
        internal override bool PointerDown(Microsoft.Xna.Framework.Vector2 position, PointerType pointerType)
        {
            isPressed = true;
             lastPos = position;

             return true;
        }
コード例 #5
0
        internal override bool PointerUp(Microsoft.Xna.Framework.Vector2 position, PointerType pointerType)
        {
            isPressed = false;

             SelectUnitAt (position);

             return true;
        }
コード例 #6
0
    public void Build(PointerSettings pSettings, PointerType type) {
		_type = type;

		_pointerRendererObj = new GameObject ("Renderer");
		_pointerRendererObj.transform.SetParent (gameObject.transform, false);

		_uiPointer = _pointerRendererObj.AddComponent<UIPointer> ();
		_uiPointer.Build (pSettings, _type);
	}
コード例 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PointerEvent" /> class.
 /// </summary>
 /// <param name="pointerId">The pointer id.</param>
 /// <param name="position">The position.</param>
 /// <param name="deltaPosition">The delta position.</param>
 /// <param name="deltaTime">The delta time.</param>
 /// <param name="state">The state.</param>
 /// <param name="pointerType">Type of the pointer.</param>
 /// <param name="isPrimary">if set to <c>true</c> [is primary].</param>
 internal PointerEvent(int pointerId, Vector2 position, Vector2 deltaPosition, TimeSpan deltaTime, PointerState state, PointerType pointerType, bool isPrimary)
 {
     PointerId = pointerId;
     Position = position;
     DeltaPosition = deltaPosition;
     DeltaTime = deltaTime;
     State = state;
     PointerType = pointerType;
     IsPrimary = isPrimary;
 }
コード例 #8
0
ファイル: UIWindowManager.cs プロジェクト: CAMongrel/WinWar
        internal static bool PointerUp(Microsoft.Xna.Framework.Vector2 position, PointerType pointerType)
        {
            for (int i = windows.Count - 1; i >= 0; i--)
             {
            if (!WinWarCS.Util.MathHelper.InsideRect(position, new Rectangle((int)windows[i].X, (int)windows[i].Y, windows[i].Width, windows[i].Height)))
               continue;

            if (windows[i].PointerUp(position, pointerType))
               return true;
             }

             return false;
        }
コード例 #9
0
        internal override bool PointerDown(Microsoft.Xna.Framework.Vector2 position, PointerType pointerType)
        {
            if (pointerType == PointerType.LeftMouse)
             {
            isLeftPressed = true;

            selectionRectangle.X = position.X;
            selectionRectangle.Y = position.Y;
             }
             if (pointerType == PointerType.RightMouse)
            isRightPressed = true;

             return true;
        }
コード例 #10
0
        private void CheckInvalidOperators(Class @class)
        {
            foreach (var @operator in @class.Operators.Where(o => o.IsGenerated))
            {
                if (!IsValidOperatorOverload(@operator))
                {
                    Driver.Diagnostics.Debug("Invalid operator overload {0}::{1}",
                        @class.OriginalName, @operator.OperatorKind);
                    @operator.ExplicitlyIgnore();
                    continue;
                }

                if (@operator.IsNonMemberOperator)
                    continue;

                if (@operator.OperatorKind == CXXOperatorKind.Subscript)
                {
                    CreateIndexer(@class, @operator);
                }
                else
                {
                    // Handle missing operator parameters
                    if (@operator.IsStatic)
                        @operator.Parameters = @operator.Parameters.Skip(1).ToList();

                    if (@operator.ConversionType.Type == null || @operator.Parameters.Count == 0)
                    {
                        var type = new PointerType
                        {
                            QualifiedPointee = new QualifiedType(new TagType(@class)),
                            Modifier = PointerType.TypeModifier.LVReference
                        };

                        @operator.Parameters.Insert(0, new Parameter
                        {
                            Name = Generator.GeneratedIdentifier("op"),
                            QualifiedType = new QualifiedType(type),
                            Kind = ParameterKind.OperatorParameter
                        });
                    }
                }
            }
        }
コード例 #11
0
	// Use this for initialization
	internal void Build(PointerSettings pSettings, PointerType type) {
		_type = type;

		_color = pSettings.Color;
		_radiusNormal = pSettings.RadiusNormal;
		_radiusHighlighted = pSettings.RadiusHighlighted;
		_thickness = pSettings.Thickness;

		_pointerObj = new GameObject ("Pointer");
		_pointerObj.transform.SetParent (gameObject.transform, false);

		
		MeshRenderer meshRenderer = _pointerObj.AddComponent <MeshRenderer> ();
		meshRenderer.sharedMaterial = ShortcutUtil.GetMaterial ();

		
		_pointerObj.AddComponent<MeshFilter> ();
		
		_meshBuilder = new MeshBuilder ();
		_pointerObj.GetComponent<MeshFilter> ().sharedMesh = _meshBuilder.Mesh;
	}
コード例 #12
0
ファイル: UIMinimapControl.cs プロジェクト: CAMongrel/WinWar
        internal override bool PointerDown(Microsoft.Xna.Framework.Vector2 position, PointerType pointerType)
        {
            if (pointerType == PointerType.LeftMouse)
             {
            isLeftPressed = true;
             }
             if (pointerType == PointerType.RightMouse)
             {
            isRightPressed = true;
             }

             bool shouldCenter = isLeftPressed;
             if (MapControl.InputHandler.InputMode == InputMode.Classic)
            shouldCenter |= isRightPressed;

             if (shouldCenter)
             {
            CenterOnPosition (position);
             }

             return base.PointerDown (position, pointerType);
        }
コード例 #13
0
		static bool comparePointerTypes(Type a, PointerType b) {
			if (!a.IsPointer)
				return false;
			return compareTypes(a.GetElementType(), b.ElementType);
		}
コード例 #14
0
ファイル: CSharpMarshal.cs プロジェクト: zeecorleone/CppSharp
        public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
        {
            if (!VisitType(pointer, quals))
            {
                return(false);
            }

            if (Context.Function != null && pointer.IsPrimitiveTypeConvertibleToRef() &&
                Context.Kind != CSharpMarshalKind.VTableReturnValue)
            {
                var refParamPtr = string.Format("__refParamPtr{0}", Context.ParameterIndex);
                Context.SupportBefore.WriteLine("fixed ({0} {1} = &{2})",
                                                pointer, refParamPtr, Context.Parameter.Name);
                Context.HasCodeBlock = true;
                Context.SupportBefore.WriteStartBraceIndent();
                Context.Return.Write(refParamPtr);
                return(true);
            }

            var param      = Context.Parameter;
            var isRefParam = param != null && (param.IsInOut || param.IsOut);

            var pointee = pointer.Pointee.Desugar();

            if (CSharpTypePrinter.IsConstCharString(pointee) && isRefParam)
            {
                if (param.IsOut)
                {
                    Context.Return.Write("IntPtr.Zero");
                    Context.ArgumentPrefix.Write("&");
                }
                else if (param.IsInOut)
                {
                    Context.Return.Write(MarshalStringToUnmanaged(Context.Parameter.Name));
                    Context.ArgumentPrefix.Write("&");
                }
                else
                {
                    Context.Return.Write(MarshalStringToUnmanaged(Context.Parameter.Name));
                    Context.Cleanup.WriteLine("Marshal.FreeHGlobal({0});", Context.ArgName);
                }
                return(true);
            }

            if (pointee is FunctionType)
            {
                var function = pointee as FunctionType;
                return(VisitDelegateType(function, function.ToString()));
            }

            Class @class;

            if (pointee.TryGetClass(out @class) && @class.IsValueType)
            {
                if (Context.Parameter.Usage == ParameterUsage.Out)
                {
                    var qualifiedIdentifier = (@class.OriginalClass ?? @class).Visit(typePrinter);
                    Context.SupportBefore.WriteLine("var {0} = new {1}.{2}();",
                                                    Generator.GeneratedIdentifier(Context.ArgName), qualifiedIdentifier,
                                                    Helpers.InternalStruct);
                }
                else
                {
                    Context.SupportBefore.WriteLine("var {0} = {1}.{2};",
                                                    Generator.GeneratedIdentifier(Context.ArgName),
                                                    Context.Parameter.Name,
                                                    Helpers.InstanceIdentifier);
                }

                Context.Return.Write("new global::System.IntPtr(&{0})",
                                     Generator.GeneratedIdentifier(Context.ArgName));
                return(true);
            }

            var           marshalAsString = CSharpTypePrinter.IsConstCharString(pointer);
            var           finalPointee    = pointer.GetFinalPointee();
            PrimitiveType primitive;

            if (finalPointee.IsPrimitiveType(out primitive) || finalPointee.IsEnumType() ||
                marshalAsString)
            {
                // From MSDN: "note that a ref or out parameter is classified as a moveable
                // variable". This means we must create a local variable to hold the result
                // and then assign this value to the parameter.

                if (isRefParam)
                {
                    var typeName = Type.TypePrinterDelegate(finalPointee);

                    if (param.IsInOut)
                    {
                        Context.SupportBefore.WriteLine("{0} _{1} = {1};", typeName, param.Name);
                    }
                    else
                    {
                        Context.SupportBefore.WriteLine("{0} _{1};", typeName, param.Name);
                    }

                    Context.Return.Write("&_{0}", param.Name);
                }
                else
                {
                    if (!marshalAsString &&
                        Context.Context.Options.MarshalCharAsManagedChar &&
                        primitive == PrimitiveType.Char)
                    {
                        typePrinter.PushContext(CSharpTypePrinterContextKind.Native);
                        Context.Return.Write(string.Format("({0}) ", pointer.Visit(typePrinter)));
                        typePrinter.PopContext();
                    }
                    if (marshalAsString && (Context.Kind == CSharpMarshalKind.NativeField ||
                                            Context.Kind == CSharpMarshalKind.VTableReturnValue ||
                                            Context.Kind == CSharpMarshalKind.Variable))
                    {
                        Context.Return.Write(MarshalStringToUnmanaged(Context.Parameter.Name));
                    }
                    else
                    {
                        Context.Return.Write(Context.Parameter.Name);
                    }
                }

                return(true);
            }

            return(pointer.QualifiedPointee.Visit(this));
        }
コード例 #15
0
    public static float GetPointerHighlightProgress(PointerType type)
    {
        float nearestDis = findNearestItemDistance(_pointerPosDict [type]);

        return(nearestDis);
    }
コード例 #16
0
        public override bool VisitArrayType(ArrayType array, TypeQualifiers quals)
        {
            if (!VisitType(array, quals))
            {
                return(false);
            }

            switch (array.SizeType)
            {
            case ArrayType.ArraySize.Constant:
                if (Context.MarshalKind != MarshalKind.NativeField &&
                    Context.MarshalKind != MarshalKind.ReturnVariableArray)
                {
                    goto case ArrayType.ArraySize.Incomplete;
                }

                var    supportBefore = Context.Before;
                string value         = Generator.GeneratedIdentifier("value");
                var    arrayType     = array.Type.Desugar();
                supportBefore.WriteLine($"{arrayType}[] {value} = null;");
                supportBefore.WriteLine($"if ({Context.ReturnVarName} != null)");
                supportBefore.WriteOpenBraceAndIndent();
                supportBefore.WriteLine($"{value} = new {arrayType}[{array.Size}];");
                supportBefore.WriteLine($"for (int i = 0; i < {array.Size}; i++)");
                if (array.Type.IsPointerToPrimitiveType(PrimitiveType.Void))
                {
                    supportBefore.WriteLineIndent($@"{value}[i] = new global::System.IntPtr({
                            Context.ReturnVarName}[i]);");
                }
                else
                {
                    var   finalArrayType = arrayType.GetPointee() ?? arrayType;
                    Class @class;
                    if ((finalArrayType.TryGetClass(out @class)) && @class.IsRefType)
                    {
                        if (arrayType == finalArrayType)
                        {
                            supportBefore.WriteLineIndent(
                                "{0}[i] = {1}.{2}(*(({1}.{3}*)&({4}[i * sizeof({1}.{3})])));",
                                value, array.Type, Helpers.CreateInstanceIdentifier,
                                Helpers.InternalStruct, Context.ReturnVarName);
                        }
                        else
                        {
                            supportBefore.WriteLineIndent(
                                $@"{value}[i] = {finalArrayType}.{Helpers.CreateInstanceIdentifier}(({
                                        typePrinter.IntPtrType}) {Context.ReturnVarName}[i]);");
                        }
                    }
                    else
                    {
                        if (arrayType.IsPrimitiveType(PrimitiveType.Bool))
                        {
                            supportBefore.WriteLineIndent($@"{value}[i] = {
                                    Context.ReturnVarName}[i] != 0;");
                        }
                        else if (arrayType.IsPrimitiveType(PrimitiveType.Char) &&
                                 Context.Context.Options.MarshalCharAsManagedChar)
                        {
                            supportBefore.WriteLineIndent($@"{value}[i] = global::System.Convert.ToChar({
                                    Context.ReturnVarName}[i]);");
                        }
                        else
                        {
                            supportBefore.WriteLineIndent($@"{value}[i] = {
                                    Context.ReturnVarName}[i];");
                        }
                    }
                }
                supportBefore.UnindentAndWriteCloseBrace();
                Context.Return.Write(value);
                break;

            case ArrayType.ArraySize.Incomplete:
                // const char* and const char[] are the same so we can use a string
                if (array.Type.Desugar().IsPrimitiveType(PrimitiveType.Char) &&
                    array.QualifiedType.Qualifiers.IsConst)
                {
                    var pointer = new PointerType {
                        QualifiedPointee = array.QualifiedType
                    };
                    Context.ReturnType = new QualifiedType(pointer);
                    return(this.VisitPointerType(pointer, quals));
                }
                MarshalArray(array);
                break;

            case ArrayType.ArraySize.Variable:
                Context.Return.Write(Context.ReturnVarName);
                break;
            }

            return(true);
        }
コード例 #17
0
        public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
        {
            if (!VisitType(pointer, quals))
            {
                return(false);
            }

            var param      = Context.Parameter;
            var isRefParam = param != null && (param.IsInOut || param.IsOut);

            var           pointee      = pointer.Pointee.Desugar();
            var           finalPointee = pointer.GetFinalPointee().Desugar();
            PrimitiveType primitive;

            if ((pointee.IsConstCharString() && isRefParam) ||
                (!finalPointee.IsPrimitiveType(out primitive) &&
                 !finalPointee.IsEnumType()))
            {
                return(pointer.QualifiedPointee.Visit(this));
            }

            if (isRefParam)
            {
                Context.Return.Write(Generator.GeneratedIdentifier(param.Name));
                return(true);
            }

            if (Context.Context.Options.MarshalCharAsManagedChar &&
                primitive == PrimitiveType.Char)
            {
                Context.Return.Write($"({pointer}) ");
            }

            var type = Context.ReturnType.Type.Desugar(
                resolveTemplateSubstitution: false);

            if (Context.Function != null &&
                Context.Function.OperatorKind == CXXOperatorKind.Subscript)
            {
                if (type.IsPrimitiveType(primitive))
                {
                    Context.Return.Write("*");
                }
                else
                {
                    var substitution = pointer.Pointee.Desugar(
                        resolveTemplateSubstitution: false) as TemplateParameterSubstitutionType;
                    if (substitution != null)
                    {
                        Context.Return.Write($@"({
                            substitution.ReplacedParameter.Parameter.Name}) (object) *");
                    }
                }
            }

            if (new QualifiedType(pointer, quals).IsConstRefToPrimitive())
            {
                Context.Return.Write("*");
            }

            Context.Return.Write(Context.ReturnVarName);
            return(true);
        }
コード例 #18
0
        private void EmitBody()
        {
            this.builder.AppendLine("{");
            var body = this.method.Body;
            var vars = body.Variables;

            foreach (var v in vars)
            {
                string name = null;
                if (!typeMap.TryGetValue(v.VariableType.FullName, out name))
                {
                    throw new ArgumentException(String.Format("Unsupported type: {0}.", v.VariableType.FullName));
                }
                this.builder.AppendFormat("{0} __V{1};\n", name, v.Index);
            }
            var code = body.Instructions;

            foreach (var instr in code)
            {
                switch (instr.OpCode.OperandType)
                {
                case OperandType.ShortInlineBrTarget:
                case OperandType.InlineBrTarget: {
                    var        sofs = instr.Offset;
                    var        tofs = (instr.Operand as Instruction).Offset;
                    BranchType type;
                    if (instr.OpCode.Code == Code.Br || instr.OpCode.Code == Code.Br_S)
                    {
                        type = BranchType.Goto;
                    }
                    else if (sofs < tofs)
                    {
                        type = BranchType.If;
                    }
                    else
                    {
                        type = BranchType.While;
                    }
                    this.labels.Add(tofs, type);
                    break;
                }

                default:
                    break;
                }
            }
            var stack = new Stack <AstNode>();
            var ndups = 0;

            foreach (var instr in code)
            {
                if (this.labels.ContainsKey(instr.Offset))
                {
                    switch (this.labels[instr.Offset])
                    {
                    case BranchType.Goto:
                        this.builder.AppendFormat("__L{0:x4}: {{ }}\n", instr.Offset);
                        break;

                    case BranchType.If:
                        this.builder.AppendLine("}");
                        break;

                    case BranchType.While:
                        this.builder.AppendLine("do {");
                        break;
                    }
                }
                // ***DEBUG***
//                this.builder.AppendLine(instr.ToString());
                // ***ENDEBUG***
                switch (instr.OpCode.Code)
                {
                case Code.Nop:
                    // nothing to do...
                    break;

                case Code.Dup: {
                    var    node = stack.Pop();
                    string name = null;
                    if (!typeMap.TryGetValue(node.CliType.SystemType.FullName, out name))
                    {
                        throw new ArgumentException(String.Format("Unsupported type: {0}.", node.CliType));
                    }
                    this.builder.AppendFormat("{0} __T{1} = ", name, ndups);
                    node.Accept(printer);
                    this.builder.AppendLine(";");
                    stack.Push(new VarRef(node.CliType, ndups, true));
                    stack.Push(new VarRef(node.CliType, ndups, true));
                    ndups++;
                    break;
                }

                case Code.Ldc_I4_0:
                    stack.Push(new Const <int>(CliType.FromType(typeof(System.Int32)), 0));
                    break;

                case Code.Ldc_I4_1:
                    stack.Push(new Const <int>(CliType.FromType(typeof(System.Int32)), 1));
                    break;

                case Code.Ldc_I4_2:
                    stack.Push(new Const <int>(CliType.FromType(typeof(System.Int32)), 2));
                    break;

                case Code.Ldc_I4_3:
                    stack.Push(new Const <int>(CliType.FromType(typeof(System.Int32)), 3));
                    break;

                case Code.Ldc_I4_4:
                    stack.Push(new Const <int>(CliType.FromType(typeof(System.Int32)), 4));
                    break;

                case Code.Ldc_I4_5:
                    stack.Push(new Const <int>(CliType.FromType(typeof(System.Int32)), 5));
                    break;

                case Code.Ldc_I4_6:
                    stack.Push(new Const <int>(CliType.FromType(typeof(System.Int32)), 6));
                    break;

                case Code.Ldc_I4_7:
                    stack.Push(new Const <int>(CliType.FromType(typeof(System.Int32)), 7));
                    break;

                case Code.Ldc_I4_8:
                    stack.Push(new Const <int>(CliType.FromType(typeof(System.Int32)), 8));
                    break;

                case Code.Ldc_I4_M1:
                    stack.Push(new Const <int>(CliType.FromType(typeof(System.Int32)), -1));
                    break;

                case Code.Ldc_I4:
                    stack.Push(new Const <int>(CliType.FromType(typeof(System.Int32)), (int)instr.Operand));
                    break;

                case Code.Ldc_I4_S:
                    stack.Push(new Const <int>(CliType.FromType(typeof(System.Int32)), (sbyte)instr.Operand));
                    break;

                case Code.Ldc_I8:
                    stack.Push(new Const <long>(CliType.FromType(typeof(System.Int64)), (long)instr.Operand));
                    break;

                case Code.Ldc_R4:
                    stack.Push(new Const <float>(CliType.FromType(typeof(System.Single)), (float)instr.Operand));
                    break;

                case Code.Ldc_R8:
                    stack.Push(new Const <double>(CliType.FromType(typeof(System.Double)), (double)instr.Operand));
                    break;

                case Code.Ldarg_0: {
                    var arg = this.method.Parameters[0];
                    stack.Push(new ParamRef(CliType.FromType(arg.ParameterType), arg.Name));
                    break;
                }

                case Code.Ldarg_1: {
                    var arg = this.method.Parameters[1];
                    stack.Push(new ParamRef(CliType.FromType(arg.ParameterType), arg.Name));
                    break;
                }

                case Code.Ldarg_2: {
                    var arg = this.method.Parameters[2];
                    stack.Push(new ParamRef(CliType.FromType(arg.ParameterType), arg.Name));
                    break;
                }

                case Code.Ldarg_3: {
                    var arg = this.method.Parameters[3];
                    stack.Push(new ParamRef(CliType.FromType(arg.ParameterType), arg.Name));
                    break;
                }

                case Code.Ldarg:
                case Code.Ldarg_S: {
                    var arg = instr.Operand as ParameterDefinition;
                    stack.Push(new ParamRef(CliType.FromType(arg.ParameterType), arg.Name));
                    break;
                }

                case Code.Ldloc_0:
                    stack.Push(new VarRef(CliType.FromType(vars[0].VariableType), 0));
                    break;

                case Code.Ldloc_1:
                    stack.Push(new VarRef(CliType.FromType(vars[1].VariableType), 1));
                    break;

                case Code.Ldloc_2:
                    stack.Push(new VarRef(CliType.FromType(vars[2].VariableType), 2));
                    break;

                case Code.Ldloc_3:
                    stack.Push(new VarRef(CliType.FromType(vars[3].VariableType), 3));
                    break;

                case Code.Ldloc:
                case Code.Ldloc_S: {
                    var loc = instr.Operand as VariableDefinition;
                    stack.Push(new VarRef(CliType.FromType(loc.VariableType), loc.Index));
                    break;
                }

                case Code.Ldelem_Any: {
                    var idx = stack.Pop();
                    var arr = stack.Pop();
                    stack.Push(new ElemRef(CliType.FromType(instr.Operand as TypeReference), arr, idx));
                    break;
                }

                case Code.Ldelem_I: {
                    var idx = stack.Pop();
                    var arr = stack.Pop();
                    stack.Push(new ElemRef(CliType.FromType(typeof(System.IntPtr)), arr, idx));
                    break;
                }

                case Code.Ldelem_I1: {
                    var idx = stack.Pop();
                    var arr = stack.Pop();
                    stack.Push(new ElemRef(CliType.FromType(typeof(System.SByte)), arr, idx));
                    break;
                }

                case Code.Ldelem_I2: {
                    var idx = stack.Pop();
                    var arr = stack.Pop();
                    stack.Push(new ElemRef(CliType.FromType(typeof(System.Int16)), arr, idx));
                    break;
                }

                case Code.Ldelem_I4: {
                    var idx = stack.Pop();
                    var arr = stack.Pop();
                    stack.Push(new ElemRef(CliType.FromType(typeof(System.Int32)), arr, idx));
                    break;
                }

                case Code.Ldelem_U1: {
                    var idx = stack.Pop();
                    var arr = stack.Pop();
                    stack.Push(new ElemRef(CliType.FromType(typeof(System.Byte)), arr, idx));
                    break;
                }

                case Code.Ldelem_U2: {
                    var idx = stack.Pop();
                    var arr = stack.Pop();
                    stack.Push(new ElemRef(CliType.FromType(typeof(System.UInt16)), arr, idx));
                    break;
                }

                case Code.Ldelem_U4: {
                    var idx = stack.Pop();
                    var arr = stack.Pop();
                    stack.Push(new ElemRef(CliType.FromType(typeof(System.UInt32)), arr, idx));
                    break;
                }

                case Code.Ldelem_I8: {
                    var idx = stack.Pop();
                    var arr = stack.Pop();
                    stack.Push(new ElemRef(CliType.FromType(typeof(System.Int64)), arr, idx));
                    break;
                }

                case Code.Ldelem_R4: {
                    var idx = stack.Pop();
                    var arr = stack.Pop();
                    stack.Push(new ElemRef(CliType.FromType(typeof(System.Single)), arr, idx));
                    break;
                }

                case Code.Ldelem_R8: {
                    var idx = stack.Pop();
                    var arr = stack.Pop();
                    stack.Push(new ElemRef(CliType.FromType(typeof(System.Double)), arr, idx));
                    break;
                }

                case Code.Ldind_I:
                case Code.Ldind_I1:
                case Code.Ldind_I2:
                case Code.Ldind_I4:
                case Code.Ldind_I8:
                case Code.Ldind_R4:
                case Code.Ldind_R8:
                case Code.Ldobj: {
                    var ptr = stack.Pop();
                    stack.Push(new LoadAddr(ptr));
                    break;
                }

                case Code.Ldarga:
                case Code.Ldarga_S: {
                    var arg  = instr.Operand as ParameterDefinition;
                    var type = new PointerType(arg.ParameterType);
                    stack.Push(new ParamAddr(new CliPointerType(type), arg.Name));
                    break;
                }

                case Code.Ldloca:
                case Code.Ldloca_S: {
                    var loc  = instr.Operand as VariableDefinition;
                    var type = new PointerType(loc.VariableType);
                    stack.Push(new VarAddr(new CliPointerType(type), loc.Index));
                    break;
                }

                case Code.Ldelema: {
                    var idx = stack.Pop();
                    var arr = stack.Pop();
                    stack.Push(new ElemAddr(arr.CliType, arr, idx));
                    break;
                }

                case Code.Localloc: {
                    var size = stack.Pop();
                    stack.Push(new LocAlloc(size));
                    break;
                }

                case Code.Stloc_0: {
                    this.builder.Append("__V0 = ");
                    stack.Pop().Accept(this.printer);
                    this.builder.AppendLine(";");
                    break;
                }

                case Code.Stloc_1: {
                    this.builder.Append("__V1 = ");
                    stack.Pop().Accept(this.printer);
                    this.builder.AppendLine(";");
                    break;
                }

                case Code.Stloc_2: {
                    this.builder.Append("__V2 = ");
                    stack.Pop().Accept(this.printer);
                    this.builder.AppendLine(";");
                    break;
                }

                case Code.Stloc_3: {
                    this.builder.Append("__V3 = ");
                    stack.Pop().Accept(this.printer);
                    this.builder.AppendLine(";");
                    break;
                }

                case Code.Stloc:
                case Code.Stloc_S: {
                    this.builder.AppendFormat("__V{0} = ", (instr.Operand as VariableDefinition).Index);
                    stack.Pop().Accept(this.printer);
                    this.builder.AppendLine(";");
                    break;
                }

                case Code.Stelem_Any:
                case Code.Stelem_I:
                case Code.Stelem_I1:
                case Code.Stelem_I2:
                case Code.Stelem_I4:
                case Code.Stelem_I8:
                case Code.Stelem_R4:
                case Code.Stelem_R8: {
                    var val = stack.Pop();
                    var idx = stack.Pop();
                    var arr = stack.Pop();
                    arr.Accept(this.printer);
                    this.builder.Append("[");
                    idx.Accept(this.printer);
                    this.builder.Append("] = ");
                    val.Accept(this.printer);
                    this.builder.AppendLine(";");
                    break;
                }

                case Code.Stind_I:
                case Code.Stind_I1:
                case Code.Stind_I2:
                case Code.Stind_I4:
                case Code.Stind_I8:
                case Code.Stind_R4:
                case Code.Stind_R8:
                case Code.Stobj: {
                    var val = stack.Pop();
                    var ptr = stack.Pop();
                    this.builder.Append("*(");
                    ptr.Accept(this.printer);
                    this.builder.Append(") = ");
                    val.Accept(this.printer);
                    this.builder.AppendLine(";");
                    break;
                }

                case Code.Conv_I:
                case Code.Conv_Ovf_I:
                case Code.Conv_Ovf_I_Un:
                    stack.Push(new Conv(typeof(IntPtr), stack.Pop()));
                    break;

                case Code.Conv_I1:
                case Code.Conv_Ovf_I1:
                case Code.Conv_Ovf_I1_Un:
                    stack.Push(new Conv(typeof(SByte), stack.Pop()));
                    break;

                case Code.Conv_I2:
                case Code.Conv_Ovf_I2:
                case Code.Conv_Ovf_I2_Un:
                    stack.Push(new Conv(typeof(Int16), stack.Pop()));
                    break;

                case Code.Conv_I4:
                case Code.Conv_Ovf_I4:
                case Code.Conv_Ovf_I4_Un:
                    stack.Push(new Conv(typeof(Int32), stack.Pop()));
                    break;

                case Code.Conv_I8:
                case Code.Conv_Ovf_I8:
                case Code.Conv_Ovf_I8_Un:
                    stack.Push(new Conv(typeof(Int64), stack.Pop()));
                    break;

                case Code.Conv_U:
                case Code.Conv_Ovf_U:
                case Code.Conv_Ovf_U_Un:
                    stack.Push(new Conv(typeof(UIntPtr), stack.Pop()));
                    break;

                case Code.Conv_U1:
                case Code.Conv_Ovf_U1:
                case Code.Conv_Ovf_U1_Un:
                    stack.Push(new Conv(typeof(Byte), stack.Pop()));
                    break;

                case Code.Conv_U2:
                case Code.Conv_Ovf_U2:
                case Code.Conv_Ovf_U2_Un:
                    stack.Push(new Conv(typeof(UInt16), stack.Pop()));
                    break;

                case Code.Conv_U4:
                case Code.Conv_Ovf_U4:
                case Code.Conv_Ovf_U4_Un:
                    stack.Push(new Conv(typeof(UInt32), stack.Pop()));
                    break;

                case Code.Conv_U8:
                case Code.Conv_Ovf_U8:
                case Code.Conv_Ovf_U8_Un:
                    stack.Push(new Conv(typeof(UInt64), stack.Pop()));
                    break;

                case Code.Conv_R4:
                    stack.Push(new Conv(typeof(Single), stack.Pop()));
                    break;

                case Code.Conv_R8:
                    stack.Push(new Conv(typeof(Double), stack.Pop()));
                    break;

                case Code.Add:
                case Code.Add_Ovf:
                case Code.Add_Ovf_Un: {
                    var r = stack.Pop();
                    var l = stack.Pop();
                    var t = CliType.FromOpAdd(l.CliType, r.CliType);
                    if (l.CliType is CliPointerType)
                    {
                        var e = (l.CliType as CliPointerType).Element;
                        var s = Marshal.SizeOf(e);
                        r = new BinaryOp(r.CliType, BinaryOp.OpCode.Div, r, new Const <int> (r.CliType, s));
                    }
                    stack.Push(new BinaryOp(t, BinaryOp.OpCode.Add, l, r));
                    break;
                }

                case Code.Sub:
                case Code.Sub_Ovf:
                case Code.Sub_Ovf_Un: {
                    var r = stack.Pop();
                    var l = stack.Pop();
                    var t = CliType.FromOpSub(l.CliType, r.CliType);
                    stack.Push(new BinaryOp(t, BinaryOp.OpCode.Sub, l, r));
                    break;
                }

                case Code.Mul:
                case Code.Mul_Ovf:
                case Code.Mul_Ovf_Un: {
                    var r = stack.Pop();
                    var l = stack.Pop();
                    var t = CliType.FromOpMul(l.CliType, r.CliType);
                    stack.Push(new BinaryOp(t, BinaryOp.OpCode.Mul, l, r));
                    break;
                }

                case Code.Div:
                case Code.Div_Un: {
                    var r = stack.Pop();
                    var l = stack.Pop();
                    var t = CliType.FromOpDiv(l.CliType, r.CliType);
                    stack.Push(new BinaryOp(t, BinaryOp.OpCode.Div, l, r));
                    break;
                }

                case Code.And: {
                    var r = stack.Pop();
                    var l = stack.Pop();
                    var t = CliType.FromOpBitwise(l.CliType, r.CliType);
                    stack.Push(new BinaryOp(t, BinaryOp.OpCode.And, l, r));
                    break;
                }

                case Code.Or: {
                    var r = stack.Pop();
                    var l = stack.Pop();
                    var t = CliType.FromOpBitwise(l.CliType, r.CliType);
                    stack.Push(new BinaryOp(t, BinaryOp.OpCode.Or, l, r));
                    break;
                }

                case Code.Xor: {
                    var r = stack.Pop();
                    var l = stack.Pop();
                    var t = CliType.FromOpBitwise(l.CliType, r.CliType);
                    stack.Push(new BinaryOp(t, BinaryOp.OpCode.Xor, l, r));
                    break;
                }

                case Code.Shl: {
                    var r = stack.Pop();
                    var l = stack.Pop();
                    var t = CliType.FromOpBitwise(l.CliType, r.CliType);
                    stack.Push(new BinaryOp(t, BinaryOp.OpCode.Shl, l, r));
                    break;
                }

                case Code.Shr:
                case Code.Shr_Un: {
                    var r = stack.Pop();
                    var l = stack.Pop();
                    var t = CliType.FromOpBitwise(l.CliType, r.CliType);
                    stack.Push(new BinaryOp(t, BinaryOp.OpCode.Shr, l, r));
                    break;
                }

                case Code.Call: {
                    var mref  = instr.Operand as MethodReference;
                    var mdef  = mref.Resolve();
                    var name  = GetMethodName(mdef);
                    var nargs = mref.Parameters.Count;
                    if (mdef.HasThis && !mdef.ExplicitThis)
                    {
                        nargs++;
                    }
                    var args = new AstNode[nargs];
                    for (var i = nargs - 1; i >= 0; i--)
                    {
                        args[i] = stack.Pop();
                    }
                    if (mdef.IsConstructor)
                    {
                        var tdef = mdef.DeclaringType;
                        if (tdef.IsValueType)
                        {
                            // Note: this assumes that the struct constructor
                            // is compatible with C-style compound literals.
                            this.builder.Append("*(");
                            args[0].Accept(this.printer);
                            this.builder.AppendFormat(") = ({0}){{ ", typeMap[tdef.FullName]);
                            for (int i = 1; i < nargs; i++)
                            {
                                if (i > 1)
                                {
                                    this.builder.Append(", ");
                                }
                                args[i].Accept(this.printer);
                            }
                            this.builder.AppendLine(" };");
                        }
                    }
                    else
                    {
                        var rtype = CliType.FromType(mdef.ReturnType);
                        switch (name)
                        {
                        case "op_Addition":
                            stack.Push(new BinaryOp(rtype, BinaryOp.OpCode.Add, args[0], args[1]));
                            break;

                        case "op_Subtraction":
                            stack.Push(new BinaryOp(rtype, BinaryOp.OpCode.Sub, args[0], args[1]));
                            break;

                        case "op_Multiply":
                            stack.Push(new BinaryOp(rtype, BinaryOp.OpCode.Mul, args[0], args[1]));
                            break;

                        case "op_Division":
                            stack.Push(new BinaryOp(rtype, BinaryOp.OpCode.Div, args[0], args[1]));
                            break;

                        case "op_Equality":
                            stack.Push(new BinaryOp(rtype, BinaryOp.OpCode.Eq, args[0], args[1]));
                            break;

                        case "op_Inequality":
                            stack.Push(new BinaryOp(rtype, BinaryOp.OpCode.Neq, args[0], args[1]));
                            break;

                        case "op_LessThan":
                            stack.Push(new BinaryOp(rtype, BinaryOp.OpCode.Lt, args[0], args[1]));
                            break;

                        case "op_LessThanOrEqual":
                            stack.Push(new BinaryOp(rtype, BinaryOp.OpCode.Le, args[0], args[1]));
                            break;

                        case "op_GreaterThan":
                            stack.Push(new BinaryOp(rtype, BinaryOp.OpCode.Gt, args[0], args[1]));
                            break;

                        case "op_GreaterThanOrEqual":
                            stack.Push(new BinaryOp(rtype, BinaryOp.OpCode.Ge, args[0], args[1]));
                            break;

                        case "op_BitwiseAnd":
                            stack.Push(new BinaryOp(rtype, BinaryOp.OpCode.And, args[0], args[1]));
                            break;

                        case "op_BitwiseOr":
                            stack.Push(new BinaryOp(rtype, BinaryOp.OpCode.Or, args[0], args[1]));
                            break;

                        case "op_ExclusiveOr":
                            stack.Push(new BinaryOp(rtype, BinaryOp.OpCode.Xor, args[0], args[1]));
                            break;

                        case "op_OnesComplement":
                            stack.Push(new UnaryOp(UnaryOp.OpCode.Not, args[0]));
                            break;

                        default:
                            if (mdef.HasThis && name.StartsWith("get_"))
                            {
                                // Note: this assumes that the property getter is a valid
                                // C-style field reference.
                                stack.Push(new FieldRef(rtype, name.Substring(4), args[0]));
                            }
                            else if (mdef.HasThis && name.StartsWith("set_"))
                            {
                                // Note: this assumes that the property setter is a valid
                                // C-style field reference.
                                this.builder.Append("(*");
                                args[0].Accept(this.printer);
                                this.builder.AppendFormat(").{0} = ", name.Substring(4));
                                args[1].Accept(this.printer);
                                this.builder.AppendLine(";");
                            }
                            else
                            {
                                stack.Push(new Call(rtype, name, args));
                            }
                            break;
                        }
                    }
                    break;
                }

                case Code.Br:
                case Code.Br_S:
                    this.builder.AppendFormat("goto __L{0:x4};\n", (instr.Operand as Instruction).Offset);
                    break;

                case Code.Brfalse:
                case Code.Brfalse_S:
                case Code.Brtrue:
                case Code.Brtrue_S: {
                    var b = stack.Pop();
                    EmitUnaryBranch(instr, b);
                    break;
                }

                case Code.Beq:
                case Code.Beq_S: {
                    var v = stack.Pop();
                    var u = stack.Pop();
                    EmitBinaryBranch(instr, " == ", u, v);
                    break;
                }

                case Code.Bne_Un:
                case Code.Bne_Un_S: {
                    var v = stack.Pop();
                    var u = stack.Pop();
                    EmitBinaryBranch(instr, " != ", u, v);
                    break;
                }

                case Code.Blt:
                case Code.Blt_S:
                case Code.Blt_Un:
                case Code.Blt_Un_S: {
                    var v = stack.Pop();
                    var u = stack.Pop();
                    EmitBinaryBranch(instr, " < ", u, v);
                    break;
                }

                case Code.Ble:
                case Code.Ble_S:
                case Code.Ble_Un:
                case Code.Ble_Un_S: {
                    var v = stack.Pop();
                    var u = stack.Pop();
                    EmitBinaryBranch(instr, " <= ", u, v);
                    break;
                }

                case Code.Bgt:
                case Code.Bgt_S:
                case Code.Bgt_Un:
                case Code.Bgt_Un_S: {
                    var v = stack.Pop();
                    var u = stack.Pop();
                    EmitBinaryBranch(instr, " > ", u, v);
                    break;
                }

                case Code.Bge:
                case Code.Bge_S:
                case Code.Bge_Un:
                case Code.Bge_Un_S: {
                    var v = stack.Pop();
                    var u = stack.Pop();
                    EmitBinaryBranch(instr, " >= ", u, v);
                    break;
                }

                case Code.Ret:
                    this.builder.Append("return");
                    if (this.method.ReturnType.FullName != "System.Void")
                    {
                        this.builder.Append(" ");
                        stack.Pop().Accept(this.printer);
                    }
                    this.builder.AppendLine(";");
                    break;

                default:
                    throw new CompilerException(String.Format("Unsupported opcode: {0}.", instr.OpCode));
//                    break;
                }
            }
            this.builder.AppendLine("}");
        }
コード例 #19
0
ファイル: AST.cs プロジェクト: RainsSoft/CppSharp
 public static PointerType __CreateInstance(PointerType.Internal native)
 {
     return new PointerType(native);
 }
コード例 #20
0
        public string VisitPointerType(PointerType pointer, TypeQualifiers quals)
        {
            var pointee = pointer.Pointee.Desugar();

            if (pointee is FunctionType)
            {
                var function = pointee as FunctionType;
                return(string.Format("{0}^", function.Visit(this, quals)));
            }

            if (CSharpTypePrinter.IsConstCharString(pointer))
            {
                return("System::String^");
            }

            // From http://msdn.microsoft.com/en-us/library/y31yhkeb.aspx
            // Any of the following types may be a pointer type:
            // * sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, or bool.
            // * Any enum type.
            // * Any pointer type.
            // * Any user-defined struct type that contains fields of unmanaged types only.
            var finalPointee = pointer.GetFinalPointee();

            if (finalPointee.IsPrimitiveType())
            {
                // Skip one indirection if passed by reference
                var  param      = Context.Parameter;
                bool isRefParam = param != null && (param.IsOut || param.IsInOut);
                if (isRefParam)
                {
                    return(pointee.Visit(this, quals));
                }

                if (pointee.IsPrimitiveType(PrimitiveType.Void))
                {
                    return("::System::IntPtr");
                }

                var result = pointee.Visit(this, quals);
                return(!isRefParam && result == "::System::IntPtr" ? "void**" : result + "*");
            }

            Enumeration @enum;

            if (pointee.TryGetEnum(out @enum))
            {
                var typeName = @enum.Visit(this);

                // Skip one indirection if passed by reference
                var param = Context.Parameter;
                if (param != null && (param.IsOut || param.IsInOut) &&
                    pointee == finalPointee)
                {
                    return(string.Format("{0}", typeName));
                }

                return(string.Format("{0}*", typeName));
            }

            return(pointer.Pointee.Visit(this, quals));
        }
コード例 #21
0
 public override void AppendName(StringBuilder sb, PointerType type)
 {
     AppendName(sb, type.ParameterType);
     sb.Append('*');
 }
コード例 #22
0
        public CSharpTypePrinterResult VisitPointerType(PointerType pointer,
                                                        TypeQualifiers quals)
        {
            var pointee = pointer.Pointee;

            if (pointee is FunctionType)
            {
                var function = pointee as FunctionType;
                return(string.Format("{0}", function.Visit(this, quals)));
            }

            var isManagedContext = ContextKind == CSharpTypePrinterContextKind.Managed;

            if (IsConstCharString(pointer))
            {
                return(isManagedContext ? "string" : "global::System.IntPtr");
            }

            var desugared = pointee.Desugar();

            // From http://msdn.microsoft.com/en-us/library/y31yhkeb.aspx
            // Any of the following types may be a pointer type:
            // * sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, or bool.
            // * Any enum type.
            // * Any pointer type.
            // * Any user-defined struct type that contains fields of unmanaged types only.
            var finalPointee = pointer.GetFinalPointee();

            if (finalPointee.IsPrimitiveType())
            {
                // Skip one indirection if passed by reference
                var  param      = Context.Parameter;
                bool isRefParam = param != null && (param.IsOut || param.IsInOut);
                if (isManagedContext && isRefParam)
                {
                    return(pointee.Visit(this, quals));
                }

                if (ContextKind == CSharpTypePrinterContextKind.GenericDelegate ||
                    pointee.IsPrimitiveType(PrimitiveType.Void))
                {
                    return("global::System.IntPtr");
                }

                var result = pointee.Visit(this, quals);
                return(!isRefParam && result.Type == "global::System.IntPtr" ? "void**" : result + "*");
            }

            Enumeration @enum;

            if (desugared.TryGetEnum(out @enum))
            {
                // Skip one indirection if passed by reference
                var param = Context.Parameter;
                if (isManagedContext && param != null && (param.IsOut || param.IsInOut) &&
                    pointee == finalPointee)
                {
                    return(pointee.Visit(this, quals));
                }

                return(pointee.Visit(this, quals) + "*");
            }

            Class @class;

            if ((desugared.IsDependent || desugared.TryGetClass(out @class)) &&
                ContextKind == CSharpTypePrinterContextKind.Native)
            {
                return("global::System.IntPtr");
            }

            return(pointee.Visit(this, quals));
        }
コード例 #23
0
        private static void RewriteMethod(MethodDefinition method)
        {
            var il = method.Body.GetILProcessor();

            il.Body.Instructions.Clear();

            List <VariableDefinition> stringParams = new List <VariableDefinition>();

            for (int i = 0; i < method.Parameters.Count; i++)
            {
                EmitLoadArgument(il, i, method.Parameters);
                TypeReference parameterType = method.Parameters[i].ParameterType;
                if (parameterType.FullName == "System.String")
                {
                    VariableDefinition variableDef = new VariableDefinition(s_stringHandleRef);
                    method.Body.Variables.Add(variableDef);
                    il.Emit(OpCodes.Call, s_stringToHGlobalUtf8Ref);
                    il.Emit(OpCodes.Stloc, variableDef);
                    il.Emit(OpCodes.Ldloc, variableDef);
                    stringParams.Add(variableDef);
                }
                else if (parameterType.IsByReference)
                {
                    VariableDefinition byRefVariable = new VariableDefinition(new PinnedType(parameterType));
                    method.Body.Variables.Add(byRefVariable);
                    il.Emit(OpCodes.Stloc, byRefVariable);
                    il.Emit(OpCodes.Ldloc, byRefVariable);
                    il.Emit(OpCodes.Conv_I);
                }
            }

            string functionPtrName = method.Name + "_ptr";
            var    field           = method.DeclaringType.Fields.SingleOrDefault(fd => fd.Name == functionPtrName);

            if (field == null)
            {
                throw new InvalidOperationException("Can't find function pointer field for " + method.Name);
            }
            il.Emit(OpCodes.Ldsfld, field);

            CallSite callSite = new CallSite(method.ReturnType)
            {
                CallingConvention = MethodCallingConvention.StdCall
            };

            foreach (ParameterDefinition pd in method.Parameters)
            {
                TypeReference parameterType;
                if (pd.ParameterType.IsByReference)
                {
                    parameterType = new PointerType(pd.ParameterType.GetElementType());
                }
                else if (pd.ParameterType.FullName == "System.String")
                {
                    parameterType = s_stringHandleRef;
                }
                else
                {
                    parameterType = pd.ParameterType;
                }
                ParameterDefinition calliPD = new ParameterDefinition(pd.Name, pd.Attributes, parameterType);

                callSite.Parameters.Add(calliPD);
            }
            il.Emit(OpCodes.Calli, callSite);

            foreach (var stringVar in stringParams)
            {
                il.Emit(OpCodes.Ldloc, stringVar);
                il.Emit(OpCodes.Call, s_freeHGlobalRef);
            }

            il.Emit(OpCodes.Ret);

            if (method.Body.Variables.Count > 0)
            {
                method.Body.InitLocals = true;
            }
        }
コード例 #24
0
 public void VisitPointerType(PointerType pointerType, StringBuilder builder)
 {
     VisitTypeReference(pointerType.ElementType, builder);
     builder.Append('*');
 }
コード例 #25
0
 private static void* __CopyValue(PointerType.__Internal native)
 {
     var ret = Marshal.AllocHGlobal(20);
     global::CppSharp.Parser.AST.PointerType.__Internal.cctor_2(ret, new global::System.IntPtr(&native));
     return ret.ToPointer();
 }
コード例 #26
0
ファイル: CodeGenerator.cs プロジェクト: bryanperris/CppSharp
 public bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
 {
     throw new NotImplementedException();
 }
コード例 #27
0
ファイル: AST.cs プロジェクト: CSRedRat/CppSharp
 private PointerType(PointerType.Internal native, bool skipVTables = false)
     : this(__CopyValue(native), skipVTables)
 {
     __ownsNativeInstance = true;
     NativeToManagedMap[__Instance] = this;
 }
コード例 #28
0
 public override IEntity VisitPointerType(IPointerTypeSymbol symbol) => PointerType.Create(cx, symbol);
コード例 #29
0
ファイル: AST.cs プロジェクト: RainsSoft/CppSharp
 private PointerType(PointerType.Internal native)
     : this(__CopyValue(native))
 {
     __ownsNativeInstance = true;
     NativeToManagedMap[__Instance] = this;
 }
コード例 #30
0
ファイル: CSharpMarshal.cs プロジェクト: fangsunjian/CppSharp
        public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
        {
            if (!VisitType(pointer, quals))
                return false;

            var param = Context.Parameter;
            var isRefParam = param != null && (param.IsInOut || param.IsOut);

            var pointee = pointer.Pointee.Desugar();
            bool marshalPointeeAsString = CSharpTypePrinter.IsConstCharString(pointee) && isRefParam;

            if (CSharpTypePrinter.IsConstCharString(pointer) || marshalPointeeAsString)
            {
                if (param.IsOut)
                {
                    Context.Return.Write("IntPtr.Zero");
                    CSharpContext.ArgumentPrefix.Write("&");
                }
                else if (param.IsInOut)
                {
                    Context.Return.Write(MarshalStringToUnmanaged(Context.Parameter.Name));
                    CSharpContext.ArgumentPrefix.Write("&");
                }
                else
                {
                    Context.Return.Write(MarshalStringToUnmanaged(Context.Parameter.Name));
                    CSharpContext.Cleanup.WriteLine("Marshal.FreeHGlobal({0});", Context.ArgName);
                }
                return true;
            }

            if (pointee is FunctionType)
            {
                var function = pointee as FunctionType;
                return VisitDelegateType(function, function.ToString());
            }

            Class @class;
            if (pointee.TryGetClass(out @class) && @class.IsValueType)
            {
                if (Context.Parameter.Usage == ParameterUsage.Out)
                {
                    Context.SupportBefore.WriteLine("var {0} = new {1}.Internal();",
                        Generator.GeneratedIdentifier(Context.ArgName), @class.Name);
                }
                else
                {
                    Context.SupportBefore.WriteLine("var {0} = {1}.{2};",
                            Generator.GeneratedIdentifier(Context.ArgName),
                            Context.Parameter.Name,
                            Helpers.InstanceIdentifier);
                }

                Context.Return.Write("new global::System.IntPtr(&{0})",
                    Generator.GeneratedIdentifier(Context.ArgName));
                return true;
            }

            var finalPointee = pointer.GetFinalPointee();
            PrimitiveType primitive;
            if (finalPointee.IsPrimitiveType(out primitive) || finalPointee.IsEnumType())
            {
                // From MSDN: "note that a ref or out parameter is classified as a moveable
                // variable". This means we must create a local variable to hold the result
                // and then assign this value to the parameter.

                if (isRefParam)
                {
                    var typeName = Type.TypePrinterDelegate(finalPointee);

                    if (param.IsInOut)
                        Context.SupportBefore.WriteLine("{0} _{1} = {1};", typeName, param.Name);
                    else
                        Context.SupportBefore.WriteLine("{0} _{1};", typeName, param.Name);

                    Context.Return.Write("&_{0}", param.Name);
                }
                else
                    Context.Return.Write(Context.Parameter.Name);

                return true;
            }

            return pointer.Pointee.Visit(this, quals);
        }
コード例 #31
0
ファイル: ILDisassembler.cs プロジェクト: zwei222/coreclr
 public override void AppendName(StringBuilder sb, PointerType type)
 {
     AppendNameWithValueClassPrefix(sb, type.ParameterType);
     sb.Append('*');
 }
コード例 #32
0
ファイル: CxxBinder.cs プロジェクト: corefan/urho
		// 
		// Given a pointer type, returns the underlying type 
		//
		static RecordType GetPointersUnderlyingType(PointerType ptrType)
		{
			return (ptrType.PointeeQualType.Type.UnqualifiedDesugaredType as RecordType);
		}
コード例 #33
0
        public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
        {
            if (!VisitType(pointer, quals))
            {
                return(false);
            }

            var param      = Context.Parameter;
            var isRefParam = param != null && (param.IsInOut || param.IsOut);

            var pointee = pointer.Pointee.Desugar();

            if (pointee.IsConstCharString())
            {
                if (param.IsOut)
                {
                    MarshalString(pointee);
                    Context.Return.Write("IntPtr.Zero");
                    Context.ArgumentPrefix.Write("&");
                    return(true);
                }
                if (param.IsInOut)
                {
                    MarshalString(pointee);
                    pointer.QualifiedPointee.Visit(this);
                    Context.ArgumentPrefix.Write("&");
                    return(true);
                }
                if (pointer.IsReference)
                {
                    Context.Return.Write($@"({typePrinter.PrintNative(
                        pointee.GetQualifiedPointee())}*) ");
                    pointer.QualifiedPointee.Visit(this);
                    Context.ArgumentPrefix.Write("&");
                    return(true);
                }
            }

            var finalPointee = (pointee.GetFinalPointee() ?? pointee).Desugar();

            if (finalPointee.IsPrimitiveType(out PrimitiveType primitive) ||
                finalPointee.IsEnumType())
            {
                if (isRefParam)
                {
                    var local = Generator.GeneratedIdentifier($@"{
                        param.Name}{Context.ParameterIndex}");
                    Context.Before.WriteLine($@"fixed ({
                        pointer.Visit(typePrinter)} {local} = &{param.Name})");
                    Context.HasCodeBlock = true;
                    Context.Before.WriteOpenBraceAndIndent();
                    Context.Return.Write(local);
                    return(true);
                }

                if (Context.Context.Options.MarshalCharAsManagedChar &&
                    primitive == PrimitiveType.Char)
                {
                    Context.Return.Write($"({typePrinter.PrintNative(pointer)}) ");
                    Context.Return.Write(param.Name);
                    return(true);
                }

                pointer.QualifiedPointee.Visit(this);
                bool isVoid = primitive == PrimitiveType.Void &&
                              pointee.IsAddress() && pointer.IsReference();
                if (pointer.Pointee.Desugar(false) is TemplateParameterSubstitutionType ||
                    isVoid)
                {
                    var    local = Generator.GeneratedIdentifier($@"{
                        param.Name}{Context.ParameterIndex}");
                    string cast  = isVoid ? $@"({pointee.Visit(
                        new CppTypePrinter { PrintTypeQualifiers = false })}) " : string.Empty;
                    Context.Before.WriteLine($"var {local} = {cast}{Context.Return};");
                    Context.Return.StringBuilder.Clear();
                    Context.Return.Write(local);
                }
                if (new QualifiedType(pointer, quals).IsConstRefToPrimitive())
                {
                    Context.Return.StringBuilder.Insert(0, '&');
                }

                return(true);
            }

            if (pointee.TryGetClass(out Class @class) && @class.IsValueType)
            {
                if (Context.Parameter.Usage == ParameterUsage.Out)
                {
                    var qualifiedIdentifier = (@class.OriginalClass ?? @class).Visit(typePrinter);
                    Context.Before.WriteLine("var {0} = new {1}.{2}();",
                                             Generator.GeneratedIdentifier(Context.ArgName), qualifiedIdentifier,
                                             Helpers.InternalStruct);
                }
                else
                {
                    Context.Before.WriteLine("var {0} = {1}.{2};",
                                             Generator.GeneratedIdentifier(Context.ArgName),
                                             Context.Parameter.Name,
                                             Helpers.InstanceIdentifier);
                }

                Context.Return.Write("new global::System.IntPtr(&{0})",
                                     Generator.GeneratedIdentifier(Context.ArgName));
                return(true);
            }

            return(pointer.QualifiedPointee.Visit(this));
        }
コード例 #34
0
        public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
        {
            if (!VisitType(pointer, quals))
            {
                return(false);
            }

            var pointee = pointer.Pointee.Desugar();

            if ((pointee.IsPrimitiveType(PrimitiveType.Char) ||
                 pointee.IsPrimitiveType(PrimitiveType.WideChar)) &&
                pointer.QualifiedPointee.Qualifiers.IsConst)
            {
                Context.SupportBefore.WriteLine(
                    "auto _{0} = clix::marshalString<clix::E_UTF8>({1});",
                    Context.ArgName, Context.Parameter.Name);

                Context.Return.Write("_{0}.c_str()", Context.ArgName);
                return(true);
            }

            if (pointee is FunctionType)
            {
                var function = pointee as FunctionType;

                var cppTypePrinter = new CppTypePrinter(Context.Driver.TypeDatabase);
                var cppTypeName    = pointer.Visit(cppTypePrinter, quals);

                return(VisitDelegateType(function, cppTypeName));
            }

            Enumeration @enum;

            if (pointee.TryGetEnum(out @enum))
            {
                var isRef = Context.Parameter.Usage == ParameterUsage.Out ||
                            Context.Parameter.Usage == ParameterUsage.InOut;

                ArgumentPrefix.Write("&");
                Context.Return.Write("(::{0}){1}{2}", @enum.QualifiedOriginalName,
                                     isRef ? string.Empty : "*", Context.Parameter.Name);
                return(true);
            }

            Class @class;

            if (pointee.TryGetClass(out @class) && @class.IsValueType)
            {
                if (Context.Function == null)
                {
                    Context.Return.Write("&");
                }
                return(pointee.Visit(this, quals));
            }

            var finalPointee = pointer.GetFinalPointee();

            if (finalPointee.IsPrimitiveType())
            {
                var cppTypePrinter = new CppTypePrinter(Context.Driver.TypeDatabase);
                var cppTypeName    = pointer.Visit(cppTypePrinter, quals);

                Context.Return.Write("({0})", cppTypeName);
                Context.Return.Write(Context.Parameter.Name);
                return(true);
            }

            return(pointer.Pointee.Visit(this, quals));
        }
コード例 #35
0
        public override TypePrinterResult VisitPointerType(PointerType pointer,
                                                           TypeQualifiers quals)
        {
            TypeMap typeMap;

            if (Context.TypeMaps.FindTypeMap(pointer.Desugar(), out typeMap))
            {
                var typePrinterContext = new TypePrinterContext
                {
                    Kind        = ContextKind,
                    MarshalKind = MarshalKind,
                    Type        = pointer
                };

                return(typeMap.CLISignatureType(typePrinterContext).Visit(this));
            }

            var pointee = pointer.Pointee.Desugar();

            if (pointee is FunctionType)
            {
                var function = pointee as FunctionType;
                return(string.Format("{0}^", function.Visit(this, quals)));
            }

            // From http://msdn.microsoft.com/en-us/library/y31yhkeb.aspx
            // Any of the following types may be a pointer type:
            // * sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, or bool.
            // * Any enum type.
            // * Any pointer type.
            // * Any user-defined struct type that contains fields of unmanaged types only.
            var finalPointee = pointer.GetFinalPointee();

            if (finalPointee.IsPrimitiveType())
            {
                // Skip one indirection if passed by reference
                bool isRefParam = Parameter != null && (Parameter.IsOut || Parameter.IsInOut);
                if (isRefParam)
                {
                    return(pointer.QualifiedPointee.Visit(this));
                }

                if (pointee.IsPrimitiveType(PrimitiveType.Void))
                {
                    return("::System::IntPtr");
                }

                var result = pointer.QualifiedPointee.Visit(this).ToString();
                return(!isRefParam && result == "::System::IntPtr" ? "void**" : result + "*");
            }

            Enumeration @enum;

            if (pointee.TryGetEnum(out @enum))
            {
                var typeName = @enum.Visit(this);

                // Skip one indirection if passed by reference
                if (Parameter != null && (Parameter.IsOut || Parameter.IsInOut) &&
                    pointee == finalPointee)
                {
                    return(string.Format("{0}", typeName));
                }

                return(string.Format("{0}*", typeName));
            }

            return(pointer.QualifiedPointee.Visit(this));
        }
コード例 #36
0
 bool HandleDecl(TemplateTypeParameter parameter, PointerDecl p, PointerType r)
 {
     return(r != null &&
            r.DeclarationOrExpressionBase is PointerDecl &&
            HandleDecl(parameter, p.InnerDeclaration, r.Base));
 }
コード例 #37
0
        public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
        {
            if (!VisitType(pointer, quals))
            {
                return(false);
            }

            var pointee = pointer.Pointee.Desugar();

            PrimitiveType primitive;
            var           param = Context.Parameter;

            if (param != null && (param.IsOut || param.IsInOut) &&
                pointee.IsPrimitiveType(out primitive))
            {
                Context.Return.Write(Context.ReturnVarName);
                return(true);
            }

            if (pointee.IsPrimitiveType(out primitive))
            {
                var returnVarName = Context.ReturnVarName;

                if (pointer.GetFinalQualifiedPointee().Qualifiers.IsConst !=
                    Context.ReturnType.Qualifiers.IsConst)
                {
                    var nativeTypePrinter = new CppTypePrinter(Context.Context)
                    {
                        PrintTypeQualifiers = false
                    };
                    var returnType       = Context.ReturnType.Type.Desugar();
                    var constlessPointer = new PointerType()
                    {
                        IsDependent      = pointer.IsDependent,
                        Modifier         = pointer.Modifier,
                        QualifiedPointee = new QualifiedType(returnType.GetPointee())
                    };
                    var nativeConstlessTypeName = constlessPointer.Visit(nativeTypePrinter, new TypeQualifiers());
                    returnVarName = string.Format("const_cast<{0}>({1})",
                                                  nativeConstlessTypeName, Context.ReturnVarName);
                }

                if (pointer.Pointee is TypedefType)
                {
                    var desugaredPointer = new PointerType()
                    {
                        IsDependent      = pointer.IsDependent,
                        Modifier         = pointer.Modifier,
                        QualifiedPointee = new QualifiedType(pointee)
                    };
                    var nativeTypePrinter = new CppTypePrinter(Context.Context);
                    var nativeTypeName    = desugaredPointer.Visit(nativeTypePrinter, quals);
                    Context.Return.Write("reinterpret_cast<{0}>({1})", nativeTypeName,
                                         returnVarName);
                }
                else
                {
                    Context.Return.Write(returnVarName);
                }

                return(true);
            }

            TypeMap typeMap = null;

            Context.Context.TypeMaps.FindTypeMap(pointee, out typeMap);

            Class @class;

            if (pointee.TryGetClass(out @class) && typeMap == null)
            {
                var instance = (pointer.IsReference) ? "&" + Context.ReturnVarName
                    : Context.ReturnVarName;
                WriteClassInstance(@class, instance);
                return(true);
            }

            return(pointer.QualifiedPointee.Visit(this));
        }
コード例 #38
0
ファイル: AST.cs プロジェクト: kidleon/CppSharp
 internal PointerType(PointerType.Internal native)
     : this(&native)
 {
 }
コード例 #39
0
        internal override void PointerUp(Microsoft.Xna.Framework.Vector2 position, PointerType pointerType)
        {
            base.PointerUp(position, pointerType);

             MainGame.WinWarGame.SetNextGameScreen(new MenuGameScreen(false));
        }
コード例 #40
0
 static void AppendTypeName(StringBuilder b, TypeReference type)
 {
     if (type is GenericInstanceType)
     {
         GenericInstanceType giType = (GenericInstanceType)type;
         if (type.DeclaringType != null)
         {
             AppendTypeName(b, type.DeclaringType);
             b.Append('.');
         }
         else if (!string.IsNullOrEmpty(type.Namespace))
         {
             b.Append(type.Namespace);
             b.Append('.');
         }
         b.Append(NRefactory.TypeSystem.ReflectionHelper.SplitTypeParameterCountFromReflectionName(type.Name));
         b.Append('{');
         for (int i = 0; i < giType.GenericArguments.Count; i++)
         {
             if (i > 0)
             {
                 b.Append(',');
             }
             AppendTypeName(b, giType.GenericArguments[i]);
         }
         b.Append('}');
     }
     else if (type is TypeSpecification)
     {
         AppendTypeName(b, ((TypeSpecification)type).ElementType);
         ArrayType arrayType = type as ArrayType;
         if (arrayType != null)
         {
             b.Append('[');
             for (int i = 1; i < arrayType.Dimensions.Count; i++)
             {
                 b.Append(',');
             }
             b.Append(']');
         }
         ByReferenceType refType = type as ByReferenceType;
         if (refType != null)
         {
             b.Append('@');
         }
         PointerType ptrType = type as PointerType;
         if (ptrType != null)
         {
             b.Append('*');                     // TODO: is this correct?
         }
     }
     else
     {
         GenericParameter gp = type as GenericParameter;
         if (gp != null)
         {
             b.Append('`');
             if (gp.Owner.GenericParameterType == GenericParameterType.Method)
             {
                 b.Append('`');
             }
             b.Append(gp.Position);
         }
         else if (type.DeclaringType != null)
         {
             AppendTypeName(b, type.DeclaringType);
             b.Append('.');
             b.Append(type.Name);
         }
         else
         {
             b.Append(type.FullName);
         }
     }
 }
コード例 #41
0
 public virtual TypeReference Visit(PointerType type)
 {
     type = type.ChangePointerType(VisitDynamic(type.ElementType));
     return(type.ChangeGenericParameters(Visit(type.GenericParameters)));
 }
コード例 #42
0
ファイル: AST.cs プロジェクト: KonajuGames/CppSharp
 private PointerType(PointerType.Internal native)
     : this(__CopyValue(native))
 {
     __ownsNativeInstance = true;
 }
コード例 #43
0
ファイル: CSharpMarshal.cs プロジェクト: fangsunjian/CppSharp
        public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
        {
            if (!VisitType(pointer, quals))
                return false;

            var param = Context.Parameter;
            var isRefParam = param != null && (param.IsInOut || param.IsOut);

            var pointee = pointer.Pointee.Desugar();
            bool marshalPointeeAsString = CSharpTypePrinter.IsConstCharString(pointee) && isRefParam;

            if (CSharpTypePrinter.IsConstCharString(pointer) || marshalPointeeAsString)
            {
                Context.Return.Write(MarshalStringToManaged(Context.ReturnVarName,
                    pointer.GetFinalPointee() as BuiltinType));
                return true;
            }

            var finalPointee = pointer.GetFinalPointee();
            PrimitiveType primitive;
            if (finalPointee.IsPrimitiveType(out primitive) || finalPointee.IsEnumType())
            {
                if (isRefParam)
                {
                    Context.Return.Write("_{0}", param.Name);
                    return true;
                }

                Context.Return.Write(Context.ReturnVarName);
                return true;
            }

            return pointer.Pointee.Visit(this, quals);
        }
コード例 #44
0
        public override TypePrinterResult VisitPointerType(PointerType pointer,
                                                           TypeQualifiers quals)
        {
            if (MarshalKind == MarshalKind.NativeField && !pointer.Pointee.IsEnumType())
            {
                return(IntPtrType);
            }

            if (pointer.Pointee is FunctionType)
            {
                return(pointer.Pointee.Visit(this, quals));
            }

            var isManagedContext = ContextKind == TypePrinterContextKind.Managed;

            if (allowStrings && pointer.IsConstCharString())
            {
                if (isManagedContext)
                {
                    return("string");
                }
                if (Parameter == null || Parameter.Name == Helpers.ReturnIdentifier)
                {
                    return(IntPtrType);
                }
                if (Options.Encoding == Encoding.ASCII)
                {
                    return(string.Format("[MarshalAs(UnmanagedType.LPStr)] string"));
                }
                if (Options.Encoding == Encoding.Unicode ||
                    Options.Encoding == Encoding.BigEndianUnicode)
                {
                    return(string.Format("[MarshalAs(UnmanagedType.LPWStr)] string"));
                }
                throw new NotSupportedException($"{Options.Encoding.EncodingName} is not supported yet.");
            }

            var pointee = pointer.Pointee.Desugar();

            if (isManagedContext &&
                new QualifiedType(pointer, quals).IsConstRefToPrimitive())
            {
                return(pointee.Visit(this));
            }

            // From http://msdn.microsoft.com/en-us/library/y31yhkeb.aspx
            // Any of the following types may be a pointer type:
            // * sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double,
            //   decimal, or bool.
            // * Any enum type.
            // * Any pointer type.
            // * Any user-defined struct type that contains fields of unmanaged types only.
            var finalPointee = pointer.GetFinalPointee();

            if (finalPointee.IsPrimitiveType())
            {
                // Skip one indirection if passed by reference
                bool isRefParam = Parameter != null && (Parameter.IsOut || Parameter.IsInOut);
                if (isManagedContext && isRefParam)
                {
                    return(pointer.QualifiedPointee.Visit(this));
                }

                if (pointee.IsPrimitiveType(PrimitiveType.Void))
                {
                    return(IntPtrType);
                }

                if (pointee.IsConstCharString() && isRefParam)
                {
                    return(IntPtrType + "*");
                }

                // Do not allow strings inside primitive arrays case, else we'll get invalid types
                // like string* for const char **.
                allowStrings = isRefParam;
                var result = pointer.QualifiedPointee.Visit(this);
                allowStrings = true;

                return(!isRefParam && result.Type == IntPtrType ? "void**" : result + "*");
            }

            Enumeration @enum;

            if (pointee.TryGetEnum(out @enum))
            {
                // Skip one indirection if passed by reference
                if (isManagedContext && Parameter != null && (Parameter.IsOut || Parameter.IsInOut) &&
                    pointee == finalPointee)
                {
                    return(pointer.QualifiedPointee.Visit(this));
                }

                return(pointer.QualifiedPointee.Visit(this) + "*");
            }

            Class @class;

            if ((pointee.IsDependent || pointee.TryGetClass(out @class)) &&
                ContextKind == TypePrinterContextKind.Native)
            {
                return(IntPtrType);
            }

            return(pointer.QualifiedPointee.Visit(this));
        }
コード例 #45
0
ファイル: MenuGameScreen.cs プロジェクト: CAMongrel/WinWar
 internal override void PointerUp(Microsoft.Xna.Framework.Vector2 position, PointerType pointerType)
 {
     UIWindowManager.PointerUp(position, pointerType);
 }
コード例 #46
0
        public override TypePrinterResult VisitArrayType(ArrayType array,
                                                         TypeQualifiers quals)
        {
            Type arrayType = array.Type.Desugar();

            if ((MarshalKind == MarshalKind.NativeField ||
                 (ContextKind == TypePrinterContextKind.Native &&
                  MarshalKind == MarshalKind.ReturnVariableArray)) &&
                array.SizeType == ArrayType.ArraySize.Constant)
            {
                if (array.Size == 0)
                {
                    var pointer = new PointerType(array.QualifiedType);
                    return(pointer.Visit(this));
                }

                PrimitiveType primitiveType;
                if ((arrayType.IsPointerToPrimitiveType(out primitiveType) &&
                     !(arrayType is FunctionType)) ||
                    (arrayType.IsPrimitiveType() && MarshalKind != MarshalKind.NativeField))
                {
                    if (primitiveType == PrimitiveType.Void)
                    {
                        return("void*");
                    }

                    return(array.QualifiedType.Visit(this));
                }

                if (Parameter != null)
                {
                    return(IntPtrType);
                }

                Enumeration @enum;
                if (arrayType.TryGetEnum(out @enum))
                {
                    return(new TypePrinterResult
                    {
                        Type = $"fixed {@enum.BuiltinType}",
                        NameSuffix = $"[{array.Size}]"
                    });
                }

                Class @class;
                if (arrayType.TryGetClass(out @class))
                {
                    return(new TypePrinterResult
                    {
                        Type = "fixed byte",
                        NameSuffix = $"[{array.Size * @class.Layout.Size}]"
                    });
                }

                var arrayElemType = array.QualifiedType.Visit(this).ToString();

                // C# does not support fixed arrays of machine pointer type (void* or IntPtr).
                // In that case, replace it by a pointer to an integer type of the same size.
                if (arrayElemType == IntPtrType)
                {
                    arrayElemType = Context.TargetInfo.PointerWidth == 64 ? "long" : "int";
                }

                // Do not write the fixed keyword multiple times for nested array types
                var fixedKeyword = arrayType is ArrayType ? string.Empty : "fixed ";
                return(new TypePrinterResult
                {
                    Type = $"{fixedKeyword}{arrayElemType}",
                    NameSuffix = $"[{array.Size}]"
                });
            }

            // const char* and const char[] are the same so we can use a string
            if (array.SizeType == ArrayType.ArraySize.Incomplete &&
                arrayType.IsPrimitiveType(PrimitiveType.Char) &&
                array.QualifiedType.Qualifiers.IsConst)
            {
                return("string");
            }

            if (arrayType.IsPointerToPrimitiveType(PrimitiveType.Char))
            {
                var prefix = ContextKind == TypePrinterContextKind.Managed ? string.Empty :
                             "[MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr)] ";
                return($"{prefix}string[]");
            }

            var arraySuffix = array.SizeType != ArrayType.ArraySize.Constant &&
                              MarshalKind == MarshalKind.ReturnVariableArray ?
                              (ContextKind == TypePrinterContextKind.Managed &&
                               arrayType.IsPrimitiveType() ? "*" : string.Empty) : "[]";

            return($"{arrayType.Visit(this)}{arraySuffix}");
        }
コード例 #47
0
ファイル: AST.cs プロジェクト: vovkasm/CppSharp
 internal PointerType(PointerType.Internal native)
     : this(__CopyValue(native))
 {
 }
コード例 #48
0
 public ISymbolValue VisitPointerType(PointerType t)
 {
     throw new NotImplementedException();
 }
コード例 #49
0
ファイル: AST.cs プロジェクト: kidleon/CppSharp
 internal PointerType(PointerType.Internal* native)
     : this(new global::System.IntPtr(native))
 {
 }
コード例 #50
0
 internal static Tuple cil_pointer_type(PointerType t, Type pointee) =>
 new Tuple("cil_pointer_type", t, pointee);
コード例 #51
0
 bool HandleDecl(TemplateTypeParameter parameter, PointerDecl p, PointerType r)
 {
     return r != null &&
         r.DeclarationOrExpressionBase is PointerDecl &&
         HandleDecl(parameter, p.InnerDeclaration, r.Base);
 }
コード例 #52
0
 public override IType VisitPointerType(PointerType type)
 {
     base.VisitPointerType(type);
     builder.Append('*');
     return(type);
 }
コード例 #53
0
ファイル: AST.cs プロジェクト: CSRedRat/CppSharp
 public static PointerType __CreateInstance(PointerType.Internal native, bool skipVTables = false)
 {
     return new PointerType(native, skipVTables);
 }
コード例 #54
0
ファイル: StackRef.cs プロジェクト: Z01wvay/Rhydon
 public VMSlot GetValue(EmuContext ctx, PointerType type)
 {
     throw new NotImplementedException();
 }
コード例 #55
0
ファイル: AST.cs プロジェクト: CSRedRat/CppSharp
 protected PointerType(PointerType.Internal* native, bool skipVTables = false)
     : base((CppSharp.Parser.AST.Type.Internal*) null)
 {
     __PointerAdjustment = 0;
     if (native == null)
         return;
     __Instance = new global::System.IntPtr(native);
 }
コード例 #56
0
ファイル: StackRef.cs プロジェクト: Z01wvay/Rhydon
 public void SetValue(EmuContext ctx, VMSlot slot, PointerType type)
 {
     throw new NotImplementedException();
 }
コード例 #57
0
ファイル: AST.cs プロジェクト: RainsSoft/CppSharp
 private static PointerType.Internal* __CopyValue(PointerType.Internal native)
 {
     var ret = Marshal.AllocHGlobal(32);
     CppSharp.Parser.AST.PointerType.Internal.cctor_2(ret, new global::System.IntPtr(&native));
     return (PointerType.Internal*) ret;
 }
コード例 #58
0
        public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
        {
            if (!VisitType(pointer, quals))
            {
                return(false);
            }

            var param      = Context.Parameter;
            var isRefParam = param != null && (param.IsInOut || param.IsOut);

            var  pointee = pointer.Pointee.Desugar();
            bool marshalPointeeAsString = pointee.IsConstCharString() && isRefParam;

            if ((pointer.IsConstCharString() && !MarshalsParameter) ||
                marshalPointeeAsString)
            {
                Context.Return.Write(MarshalStringToManaged(Context.ReturnVarName,
                                                            pointer.GetFinalPointee().Desugar() as BuiltinType));
                return(true);
            }

            var           finalPointee = pointer.GetFinalPointee();
            PrimitiveType primitive;

            if (finalPointee.IsPrimitiveType(out primitive) || finalPointee.IsEnumType())
            {
                if (isRefParam)
                {
                    Context.Return.Write("_{0}", param.Name);
                    return(true);
                }

                if (Context.Context.Options.MarshalCharAsManagedChar &&
                    primitive == PrimitiveType.Char)
                {
                    Context.Return.Write($"({pointer}) ");
                }

                var type = Context.ReturnType.Type.Desugar(
                    resolveTemplateSubstitution: false);
                if (Context.Function != null &&
                    Context.Function.OperatorKind == CXXOperatorKind.Subscript)
                {
                    if (type.IsPrimitiveType(primitive))
                    {
                        Context.Return.Write("*");
                    }
                    else
                    {
                        var templateParameter = type as TemplateParameterType;
                        if (templateParameter != null)
                        {
                            Context.Return.Write($"({templateParameter.Parameter.Name}) (object) *");
                        }
                    }
                }

                if (new QualifiedType(pointer, quals).IsConstRefToPrimitive())
                {
                    Context.Return.Write("*");
                }

                Context.Return.Write(Context.ReturnVarName);
                return(true);
            }

            return(pointer.QualifiedPointee.Visit(this));
        }
コード例 #59
0
ファイル: AST.cs プロジェクト: RainsSoft/CppSharp
 protected PointerType(PointerType.Internal* native, bool isInternalImpl = false)
     : base((CppSharp.Parser.AST.Type.Internal*) native)
 {
 }
コード例 #60
0
        public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
        {
            if (!VisitType(pointer, quals))
            {
                return(false);
            }

            var qualifiedPointer = new QualifiedType(pointer, quals);

            var         templateSubstitution = pointer.Pointee as TemplateParameterSubstitutionType;
            PointerType realPointer          = null;

            if (templateSubstitution != null)
            {
                realPointer = templateSubstitution.Replacement.Type.Desugar() as PointerType;
            }
            realPointer = realPointer ?? pointer;
            var pointee = pointer.Pointee.Desugar();

            if (Context.Function != null &&
                (realPointer.IsPrimitiveTypeConvertibleToRef() ||
                 (templateSubstitution != null && realPointer.Pointee.IsEnumType())) &&
                Context.MarshalKind != MarshalKind.VTableReturnValue)
            {
                var refParamPtr = $"__refParamPtr{Context.ParameterIndex}";
                if (templateSubstitution != null)
                {
                    var castParam = $"__{Context.Parameter.Name}{Context.ParameterIndex}";
                    Context.Before.Write($"var {castParam} = ({templateSubstitution}) ");
                    if (realPointer != pointer)
                    {
                        Context.Before.Write($"({CSharpTypePrinter.IntPtrType}) ");
                    }
                    Context.Before.WriteLine($"(object) {Context.Parameter.Name};");
                    Context.Before.Write($"var {refParamPtr} = ");
                    if (realPointer == pointer)
                    {
                        Context.Before.Write("&");
                    }
                    Context.Before.WriteLine($"{castParam};");
                    Context.Return.Write(refParamPtr);
                    return(true);
                }
                if (Context.Function.OperatorKind != CXXOperatorKind.Subscript)
                {
                    if (Context.Parameter.Kind == ParameterKind.PropertyValue ||
                        qualifiedPointer.IsConstRefToPrimitive())
                    {
                        Context.Return.Write($"&{Context.Parameter.Name}");
                    }
                    else
                    {
                        Context.Before.WriteLine(
                            $"fixed ({realPointer} {refParamPtr} = &{Context.Parameter.Name})");
                        Context.HasCodeBlock = true;
                        Context.Before.WriteOpenBraceAndIndent();
                        Context.Return.Write(refParamPtr);
                    }
                    return(true);
                }
            }

            var param      = Context.Parameter;
            var isRefParam = param != null && (param.IsInOut || param.IsOut);

            if (pointee.IsConstCharString() && isRefParam)
            {
                if (param.IsOut)
                {
                    Context.Return.Write("IntPtr.Zero");
                    Context.ArgumentPrefix.Write("&");
                }
                else if (param.IsInOut)
                {
                    Context.Return.Write(MarshalStringToUnmanaged(Context.Parameter.Name));
                    Context.ArgumentPrefix.Write("&");
                }
                else
                {
                    Context.Return.Write(MarshalStringToUnmanaged(Context.Parameter.Name));
                    Context.Cleanup.WriteLine("Marshal.FreeHGlobal({0});", Context.ArgName);
                }
                return(true);
            }

            if (pointee is FunctionType)
            {
                return(VisitDelegateType());
            }

            Class @class;

            if (pointee.TryGetClass(out @class) && @class.IsValueType)
            {
                if (Context.Parameter.Usage == ParameterUsage.Out)
                {
                    var qualifiedIdentifier = (@class.OriginalClass ?? @class).Visit(typePrinter);
                    Context.Before.WriteLine("var {0} = new {1}.{2}();",
                                             Generator.GeneratedIdentifier(Context.ArgName), qualifiedIdentifier,
                                             Helpers.InternalStruct);
                }
                else
                {
                    Context.Before.WriteLine("var {0} = {1}.{2};",
                                             Generator.GeneratedIdentifier(Context.ArgName),
                                             Context.Parameter.Name,
                                             Helpers.InstanceIdentifier);
                }

                Context.Return.Write("new global::System.IntPtr(&{0})",
                                     Generator.GeneratedIdentifier(Context.ArgName));
                return(true);
            }

            var           marshalAsString = pointer.IsConstCharString();
            var           finalPointee    = pointer.GetFinalPointee();
            PrimitiveType primitive;

            if (finalPointee.IsPrimitiveType(out primitive) || finalPointee.IsEnumType() ||
                marshalAsString)
            {
                // From MSDN: "note that a ref or out parameter is classified as a moveable
                // variable". This means we must create a local variable to hold the result
                // and then assign this value to the parameter.

                if (isRefParam)
                {
                    var typeName = Type.TypePrinterDelegate(finalPointee);
                    if (Context.Function.OperatorKind == CXXOperatorKind.Subscript)
                    {
                        Context.Return.Write(param.Name);
                    }
                    else
                    {
                        if (param.IsInOut)
                        {
                            Context.Before.WriteLine($"{typeName} _{param.Name} = {param.Name};");
                        }
                        else
                        {
                            Context.Before.WriteLine($"{typeName} _{param.Name};");
                        }

                        Context.Return.Write($"&_{param.Name}");
                    }
                }
                else
                {
                    if (!marshalAsString &&
                        Context.Context.Options.MarshalCharAsManagedChar &&
                        primitive == PrimitiveType.Char)
                    {
                        Context.Return.Write($"({typePrinter.PrintNative(pointer)}) ");
                    }

                    if (marshalAsString && (Context.MarshalKind == MarshalKind.NativeField ||
                                            Context.MarshalKind == MarshalKind.VTableReturnValue ||
                                            Context.MarshalKind == MarshalKind.Variable))
                    {
                        Context.Return.Write(MarshalStringToUnmanaged(Context.Parameter.Name));
                    }
                    else
                    {
                        if (qualifiedPointer.IsConstRefToPrimitive())
                        {
                            Context.Return.Write("&");
                        }
                        Context.Return.Write(Context.Parameter.Name);
                    }
                }

                return(true);
            }

            return(pointer.QualifiedPointee.Visit(this));
        }