Ejemplo n.º 1
0
        public override bool VisitArrayType(ArrayType array, TypeQualifiers quals)
        {
            TypeMap typeMap;
            if (TypeMapDatabase.FindTypeMap(array, out typeMap) && typeMap.IsIgnored)
            {
                Ignore();
                return false;
            }

            if (array.SizeType != ArrayType.ArraySize.Constant)
                return true;

            var arrayElemType = array.Type.Desugar();

            Class @class;
            if (arrayElemType.TryGetClass(out @class) && @class.IsRefType)
                return true;

            PrimitiveType primitive;
            if ((arrayElemType.IsPrimitiveType(out primitive) && primitive != PrimitiveType.LongDouble) ||
                arrayElemType.IsPointerToPrimitiveType())
                return true;

            Ignore();
            return false;
        }
Ejemplo n.º 2
0
 public override bool VisitPrimitiveType(PrimitiveType type, TypeQualifiers quals)
 {
     // we do not support long double yet because its high-level representation is often problematic
     if (type == PrimitiveType.LongDouble)
     {
         Ignore();
         return false;
     }
     return base.VisitPrimitiveType(type, quals);
 }
Ejemplo n.º 3
0
        public override bool VisitTypedefType(TypedefType typedef,
            TypeQualifiers quals)
        {
            TypeMap typeMap;
            if (TypeMapDatabase.FindTypeMap(typedef, out typeMap)
                && typeMap.IsIgnored)
            {
                Ignore();
                return false;
            }

            return base.VisitTypedefType(typedef, quals);
        }
Ejemplo n.º 4
0
        public override bool VisitTemplateSpecializationType(TemplateSpecializationType template, TypeQualifiers quals)
        {
            if (AlreadyVisited(template) || template.Template.Access == AccessSpecifier.Private)
                return false;

            if (template.Arguments.Select(a => a.Type.Type.Desugar()).All(t => t.IsAddress() && !t.GetFinalPointee().IsDependent))
            {
                var cppTypePrinter = new CppTypePrinter { PrintScopeKind = CppTypePrintScopeKind.Qualified };
                templateInstantiations.Add(string.Format("{0}<{1}>", template.Template.Name,
                    string.Join(", ", template.Arguments.Select(a => a.Type.Type.Visit(cppTypePrinter)))));
            }

            return true;
        }
Ejemplo n.º 5
0
        public override bool VisitArrayType(ArrayType array, TypeQualifiers quals)
        {
            if (!VisitType(array, quals))
                return false;

            switch (array.SizeType)
            {
                case ArrayType.ArraySize.Constant:
                    var supportBefore = Context.SupportBefore;
                    supportBefore.WriteLine("if ({0} != nullptr)", Context.ArgName);
                    supportBefore.WriteStartBraceIndent();
                    supportBefore.WriteLine("for (int i = 0; i < {0}; i++)", array.Size);
                    supportBefore.WriteLineIndent("{0}[i] = {1}[i]{2};",
                        Context.ReturnVarName, Context.ArgName,
                        array.Type.IsPointerToPrimitiveType(PrimitiveType.Void) ? ".ToPointer()" : string.Empty);
                    supportBefore.WriteCloseBraceIndent();
                    break;
                default:
                    Context.Return.Write("null");
                    break;
            }
            return true;
        }
Ejemplo n.º 6
0
 public bool VisitPrimitiveType(PrimitiveType type, TypeQualifiers quals)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 7
0
        public override bool VisitArrayType(ArrayType array, TypeQualifiers quals)
        {
            if (!VisitType(array, quals))
                return false;

            Class @class;
            switch (array.SizeType)
            {
                case ArrayType.ArraySize.Constant:
                    var supportBefore = Context.SupportBefore;
                    string value = Generator.GeneratedIdentifier("value");
                    supportBefore.WriteLine("{0}[] {1} = null;", array.Type, value, array.Size);
                    supportBefore.WriteLine("if ({0} != null)", Context.ReturnVarName);
                    supportBefore.WriteStartBraceIndent();
                    supportBefore.WriteLine("{0} = new {1}[{2}];", value, array.Type, array.Size);
                    supportBefore.WriteLine("for (int i = 0; i < {0}; i++)", array.Size);
                    if (array.Type.IsPointerToPrimitiveType(PrimitiveType.Void))
                        supportBefore.WriteLineIndent("{0}[i] = new global::System.IntPtr({1}[i]);",
                            value, Context.ReturnVarName);
                    else if (array.Type.Desugar().TryGetClass(out @class) && @class.IsRefType)
                        supportBefore.WriteLineIndent("{0}[i] = {1}.{2}(*(({1}.Internal*)&({3}[i * sizeof({1}.Internal)])));",
                            value, array.Type, Helpers.CreateInstanceIdentifier, Context.ReturnVarName);
                    else
                        supportBefore.WriteLineIndent("{0}[i] = {1}[i];", value, Context.ReturnVarName);
                    supportBefore.WriteCloseBraceIndent();
                    Context.Return.Write(value);
                    break;
                case ArrayType.ArraySize.Variable:
                    Context.Return.Write("null");
                    break;
            }

            return true;
        }
Ejemplo n.º 8
0
 public static TypeQualifiers __CreateInstance(TypeQualifiers.Internal native)
 {
     return new TypeQualifiers(native);
 }
Ejemplo n.º 9
0
 public bool VisitBuiltinType(BuiltinType builtin, TypeQualifiers quals)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 10
0
 internal TypeQualifiers(TypeQualifiers.Internal native)
     : this(__CopyValue(native))
 {
 }
Ejemplo n.º 11
0
 private static void* __CopyValue(TypeQualifiers.__Internal native)
 {
     var ret = Marshal.AllocHGlobal(3);
     *(TypeQualifiers.__Internal*) ret = native;
     return ret.ToPointer();
 }
Ejemplo n.º 12
0
 public bool VisitUnaryTransformType(UnaryTransformType unaryTransformType, TypeQualifiers quals)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 13
0
 public override bool VisitMemberPointerType(MemberPointerType member,
     TypeQualifiers quals)
 {
     return false;
 }
Ejemplo n.º 14
0
 public bool VisitDependentNameType(DependentNameType dependent, TypeQualifiers quals)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 15
0
 public bool VisitPackExpansionType(PackExpansionType packExpansionType, TypeQualifiers quals)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 16
0
 public bool VisitInjectedClassNameType(InjectedClassNameType injected, TypeQualifiers quals)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 17
0
 public bool VisitTemplateParameterSubstitutionType(TemplateParameterSubstitutionType param, TypeQualifiers quals)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 18
0
 public bool VisitDeclaration(Declaration decl, TypeQualifiers quals)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 19
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 = 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);
        }
Ejemplo n.º 20
0
 public bool VisitVectorType(VectorType vectorType, TypeQualifiers quals)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 21
0
        public override bool VisitType(Type type, TypeQualifiers quals)
        {
            TypeMap typeMap;
            if (Context.Driver.TypeDatabase.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
            {
                typeMap.Type = type;
                typeMap.CSharpMarshalToManaged(Context);
                return false;
            }

            return true;
        }
Ejemplo n.º 22
0
 public bool VisitCILType(CILType type, TypeQualifiers quals)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 23
0
        public override bool VisitFunctionType(FunctionType type,
            TypeQualifiers quals)
        {
            var currentUniqueName = this.uniqueName;
            this.uniqueName = 0;
            var ret = base.VisitFunctionType(type, quals);
            this.uniqueName = currentUniqueName;

            return ret;
        }
Ejemplo n.º 24
0
 public bool VisitUnsupportedType(UnsupportedType type, TypeQualifiers quals)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 25
0
 internal TypeQualifiers(TypeQualifiers.Internal* native)
     : this(new global::System.IntPtr(native))
 {
 }
Ejemplo n.º 26
0
        public override TypePrinterResult VisitPointerType(PointerType pointer,
                                                           TypeQualifiers quals)
        {
            if (MarshalKind == MarshalKind.NativeField)
            {
                return(IntPtrType);
            }

            var pointee = pointer.Pointee;

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

            var isManagedContext = ContextKind == TypePrinterContextKind.Managed;

            if (allowStrings && IsConstCharString(pointer))
            {
                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(string.Format("{0} is not supported yet.",
                                                              Options.Encoding.EncodingName));
            }

            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
                bool isRefParam = Parameter != null && (Parameter.IsOut || Parameter.IsInOut);
                if (isManagedContext && isRefParam)
                {
                    return(pointer.QualifiedPointee.Visit(this));
                }

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

                if (IsConstCharString(pointee) && 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 (desugared.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 ((desugared.IsDependent || desugared.TryGetClass(out @class)) &&
                ContextKind == TypePrinterContextKind.Native)
            {
                return(IntPtrType);
            }

            return(pointer.QualifiedPointee.Visit(this));
        }
Ejemplo n.º 27
0
 private TypeQualifiers(TypeQualifiers.Internal native, bool skipVTables = false)
     : this(__CopyValue(native), skipVTables)
 {
     __ownsNativeInstance = true;
     NativeToManagedMap[__Instance] = this;
 }
Ejemplo n.º 28
0
 public bool VisitTypedefType(TypedefType typedef, TypeQualifiers quals)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 29
0
 private TypeQualifiers(TypeQualifiers.Internal native)
     : this(__CopyValue(native))
 {
     __ownsNativeInstance = true;
     NativeToManagedMap[__Instance] = this;
 }
Ejemplo n.º 30
0
 public bool VisitDecayedType(DecayedType decayed, TypeQualifiers quals)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 31
0
 public override bool VisitTemplateParameterType(TemplateParameterType param, TypeQualifiers quals)
 {
     Context.Return.Write(param.Parameter.Name);
     return true;
 }
Ejemplo n.º 32
0
 public bool VisitDependentTemplateSpecializationType(DependentTemplateSpecializationType template, TypeQualifiers quals)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 33
0
 public override TypePrinterResult VisitTemplateParameterType(
     TemplateParameterType param, TypeQualifiers quals)
 {
     return(param.Parameter.Name);
 }
Ejemplo n.º 34
0
 public bool VisitAttributedType(AttributedType attributed, TypeQualifiers quals)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 35
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 = 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);
        }
Ejemplo n.º 36
0
 public override TypePrinterResult VisitPackExpansionType(PackExpansionType type,
                                                          TypeQualifiers quals)
 {
     return(string.Empty);
 }
Ejemplo n.º 37
0
        public override bool VisitTypedefType(TypedefType typedef, TypeQualifiers quals)
        {
            if (!VisitType(typedef, quals))
                return false;

            var decl = typedef.Declaration;

            FunctionType func;
            if (decl.Type.IsPointerTo<FunctionType>(out func))
            {
                VisitDelegateType(func, typedef.Declaration.OriginalName);
                return true;
            }

            return decl.Type.Visit(this);
        }
Ejemplo n.º 38
0
 public override TypePrinterResult VisitCILType(CILType type, TypeQualifiers quals)
 {
     return(type.Type.FullName);
 }
Ejemplo n.º 39
0
        public override bool VisitFunctionType(FunctionType function, TypeQualifiers quals)
        {
            var ptrName = Generator.GeneratedIdentifier("ptr") + Context.ParameterIndex;

            Context.SupportBefore.WriteLine("var {0} = {1};", ptrName,
                Context.ReturnVarName);

            Context.Return.Write("({1})Marshal.GetDelegateForFunctionPointer({0}, typeof({1}))",
                ptrName, function.ToString());
            return true;
        }
Ejemplo n.º 40
0
        public override TypePrinterResult VisitPrimitiveType(PrimitiveType primitive,
                                                             TypeQualifiers quals)
        {
            switch (primitive)
            {
            case PrimitiveType.Bool:
                // returned structs must be blittable and bool isn't
                return(MarshalKind == MarshalKind.NativeField ?
                       "byte" : "bool");

            case PrimitiveType.Void: return("void");

            case PrimitiveType.Char16:
            case PrimitiveType.Char32:
            case PrimitiveType.WideChar: return("char");

            case PrimitiveType.Char:
                // returned structs must be blittable and char isn't
                return(Options.MarshalCharAsManagedChar &&
                       ContextKind != TypePrinterContextKind.Native
                        ? "char"
                        : "sbyte");

            case PrimitiveType.SChar: return("sbyte");

            case PrimitiveType.UChar: return("byte");

            case PrimitiveType.Short:
            case PrimitiveType.UShort:
            case PrimitiveType.Int:
            case PrimitiveType.UInt:
            case PrimitiveType.Long:
            case PrimitiveType.ULong:
            case PrimitiveType.LongLong:
            case PrimitiveType.ULongLong:
                return(GetIntString(primitive, Context.TargetInfo));

            case PrimitiveType.Int128: return(new TypePrinterResult {
                    Type = "fixed byte",
                    NameSuffix = "[16]"
                });                       // The type is always 128 bits wide

            case PrimitiveType.UInt128: return(new TypePrinterResult {
                    Type = "fixed byte",
                    NameSuffix = "[16]"
                });                       // The type is always 128 bits wide

            case PrimitiveType.Half: return(new TypePrinterResult {
                    Type = "fixed byte",
                    NameSuffix = $"[{Context.TargetInfo.HalfWidth}]"
                });

            case PrimitiveType.Float: return("float");

            case PrimitiveType.Double: return("double");

            case PrimitiveType.LongDouble: return(new TypePrinterResult {
                    Type = "fixed byte",
                    NameSuffix = $"[{Context.TargetInfo.LongDoubleWidth}]"
                });

            case PrimitiveType.IntPtr: return(IntPtrType);

            case PrimitiveType.UIntPtr: return("global::System.UIntPtr");

            case PrimitiveType.Null: return("void*");

            case PrimitiveType.String: return("string");

            case PrimitiveType.Float128: return("__float128");
            }

            throw new NotSupportedException();
        }
Ejemplo n.º 41
0
        public override bool VisitPrimitiveType(PrimitiveType primitive, TypeQualifiers quals)
        {
            switch (primitive)
            {
                case PrimitiveType.Void:
                    return true;
                case PrimitiveType.Bool:
                case PrimitiveType.Char:
                case PrimitiveType.UChar:
                case PrimitiveType.Short:
                case PrimitiveType.UShort:
                case PrimitiveType.Int:
                case PrimitiveType.UInt:
                case PrimitiveType.Long:
                case PrimitiveType.ULong:
                case PrimitiveType.LongLong:
                case PrimitiveType.ULongLong:
                case PrimitiveType.Float:
                case PrimitiveType.Double:
                case PrimitiveType.WideChar:
                case PrimitiveType.Null:
                    Context.Return.Write(Context.ReturnVarName);
                    return true;
                case PrimitiveType.Char16:
                    return false;
            }

            throw new NotImplementedException();
        }
Ejemplo n.º 42
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}");
        }
Ejemplo n.º 43
0
        public override bool VisitTypedefType(TypedefType typedef, TypeQualifiers quals)
        {
            if (!VisitType(typedef, quals))
                return false;

            var decl = typedef.Declaration;

            FunctionType function;
            if (decl.Type.IsPointerTo(out function))
            {
                var ptrName = Generator.GeneratedIdentifier("ptr") +
                    Context.ParameterIndex;

                Context.SupportBefore.WriteLine("var {0} = {1};", ptrName,
                    Context.ReturnVarName);

                Context.Return.Write("({1})Marshal.GetDelegateForFunctionPointer({0}, typeof({1}))",
                    ptrName, typedef.ToString());
                return true;
            }

            return decl.Type.Visit(this);
        }
Ejemplo n.º 44
0
 public override TypePrinterResult VisitVectorType(VectorType vectorType,
                                                   TypeQualifiers quals)
 {
     return(vectorType.ElementType.Visit(this));
 }
Ejemplo n.º 45
0
        private bool? CheckForDefaultConstruct(Type desugared, Statement arg,
            TypeQualifiers qualifiers)
        {
            // Unwrapping the underlying type behind a possible pointer/reference
            Type type = desugared.GetFinalPointee() ?? desugared;

            Class decl;
            if (!type.TryGetClass(out decl))
                return false;

            var ctor = arg.Declaration as Method;

            TypeMap typeMap;
            var typePrinterContext = new CSharpTypePrinterContext
            {
                CSharpKind = CSharpTypePrinterContextKind.DefaultExpression,
                Type = type
            };

            string typePrinterResult = null;
            if (Driver.TypeDatabase.FindTypeMap(decl, type, out typeMap))
            {
                var typeInSignature = typeMap.CSharpSignatureType(
                    typePrinterContext).SkipPointerRefs().Desugar();
                Enumeration @enum;
                if (typeInSignature.TryGetEnum(out @enum))
                    return false;

                if (ctor == null || !ctor.IsConstructor)
                    return false;

                typePrinterResult = typeMap.CSharpSignature(typePrinterContext);
                if (typePrinterResult == "string" && ctor.Parameters.Count == 0)
                {
                    arg.String = "\"\"";
                    return true;
                }
            }

            var match = regexCtor.Match(arg.String);
            if (match.Success)
            {
                if (ctor != null)
                {
                    var templateSpecializationType = type as TemplateSpecializationType;
                    var typePrinter = new CSharpTypePrinter(Driver);
                    typePrinterResult = typePrinterResult ?? (templateSpecializationType != null
                        ? typePrinter.VisitTemplateSpecializationType(
                            templateSpecializationType, qualifiers)
                        : typePrinter.VisitClassDecl((Class) ctor.Namespace)).Type;

                    arg.String = string.Format("new {0}{1}", typePrinterResult,
                        match.Groups[2].Value);
                    if (ctor.Parameters.Count > 0 && ctor.Parameters[0].Type.IsAddress())
                        arg.String = arg.String.Replace("(0)", "()");
                }
                else
                    arg.String = string.Format("new {0}", arg.String);
            }
            else
            {
                if (ctor != null && ctor.Parameters.Count > 0)
                {
                    var finalPointee = ctor.Parameters[0].Type.SkipPointerRefs().Desugar();
                    Enumeration @enum;
                    if (finalPointee.TryGetEnum(out @enum))
                        TranslateEnumExpression(ctor, arg, finalPointee, arg.String);
                }
            }

            return decl.IsValueType ? true : (bool?) null;
        }
Ejemplo n.º 46
0
 public override TypePrinterResult VisitArrayType(ArrayType array, TypeQualifiers quals)
 {
     return($"{array.Type.Visit(this)}[]");
 }
Ejemplo n.º 47
0
 private static global::System.IntPtr __CopyValue(TypeQualifiers.Internal native)
 {
     global::System.IntPtr ret = Marshal.AllocHGlobal(3);
     *(TypeQualifiers.Internal*) ret = native;
     return ret;
 }
Ejemplo n.º 48
0
 public override TypePrinterResult VisitBuiltinType(BuiltinType builtin, TypeQualifiers quals)
 {
     return(VisitPrimitiveType(builtin.Type));
 }
Ejemplo n.º 49
0
 private TypeQualifiers(TypeQualifiers.Internal native)
     : this(__CopyValue(native))
 {
     __ownsNativeInstance = true;
 }
Ejemplo n.º 50
0
 public override TypePrinterResult VisitPrimitiveType(PrimitiveType primitive, TypeQualifiers quals)
 {
     return(VisitPrimitiveType(primitive));
 }
Ejemplo n.º 51
0
 internal TypeQualifiers(TypeQualifiers.Internal native)
     : this(&native)
 {
 }
Ejemplo n.º 52
0
 public bool VisitFunctionType(FunctionType function, TypeQualifiers quals)
 {
     return(false);
 }
Ejemplo n.º 53
0
 public static TypeQualifiers __CreateInstance(TypeQualifiers.Internal native, bool skipVTables = false)
 {
     return new TypeQualifiers(native, skipVTables);
 }
Ejemplo n.º 54
0
 public bool VisitMemberPointerType(MemberPointerType member, TypeQualifiers quals)
 {
     return(false);
 }
Ejemplo n.º 55
0
 protected TypeQualifiers(TypeQualifiers.Internal* native, bool skipVTables = false)
 {
     if (native == null)
         return;
     __Instance = new global::System.IntPtr(native);
 }
Ejemplo n.º 56
0
 public bool VisitBuiltinType(BuiltinType builtin, TypeQualifiers quals)
 {
     return(false);
 }
Ejemplo n.º 57
0
 private static TypeQualifiers.Internal* __CopyValue(TypeQualifiers.Internal native)
 {
     var ret = (TypeQualifiers.Internal*) Marshal.AllocHGlobal(3);
     *ret = native;
     return ret;
 }
Ejemplo n.º 58
0
 public bool VisitTypedefType(TypedefType typedef, TypeQualifiers quals)
 {
     return(false);
 }
Ejemplo n.º 59
0
 protected TypeQualifiers(TypeQualifiers.Internal* native, bool isInternalImpl = false)
 {
     __Instance = new global::System.IntPtr(native);
 }
Ejemplo n.º 60
0
 public bool VisitMemberPointerType(MemberPointerType member, TypeQualifiers quals)
 {
     throw new NotImplementedException();
 }