Ejemplo n.º 1
0
 public override string CLISignature(TypePrinterContext ctx)
 {
     return("System::IO::TextWriter^");
 }
Ejemplo n.º 2
0
 public override string CLISignature(TypePrinterContext ctx)
 {
     return("System::String^");
 }
Ejemplo n.º 3
0
 public override string CLISignature(TypePrinterContext ctx)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 4
0
 public override Type CLISignatureType(TypePrinterContext ctx)
 {
     return(new CILType(typeof(string)));
 }
Ejemplo n.º 5
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())
            {
                TypeMap typeMap;
                TypeMapDatabase.FindTypeMap(pointer, out typeMap);
                var typePrinterContext = new TypePrinterContext()
                {
                    Kind        = Kind,
                    MarshalKind = MarshalKind,
                    Type        = pointer.Pointee,
                    Parameter   = Parameter
                };
                return(typeMap.CSharpSignatureType(typePrinterContext).Visit(this));
            }

            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 = (pointee.GetFinalPointee() ?? pointee).Desugar();
            Enumeration @enum;

            if (finalPointee.IsPrimitiveType() || finalPointee.TryGetEnum(out @enum))
            {
                // 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;

                string @ref = Parameter != null && Parameter.IsIndirect ? string.Empty : "*";
                return(!isRefParam && result.Type == this.IntPtrType ? "void**" : result + @ref);
            }

            Class @class;

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

            return(pointer.QualifiedPointee.Visit(this));
        }
Ejemplo n.º 6
0
 public override Type CSharpSignatureType(TypePrinterContext ctx)
 {
     return(new CILType(ctx.Kind == TypePrinterContextKind.Native ||
                        !Options.MarshalCharAsManagedChar ? typeof(sbyte) : typeof(char)));
 }
Ejemplo n.º 7
0
 public override Type CLISignatureType(TypePrinterContext ctx)
 {
     return(new CustomType(
                $"::System::Collections::Generic::List<{ctx.GetTemplateParameterList()}>^"));
 }
Ejemplo n.º 8
0
 public override Type CSharpSignatureType(TypePrinterContext ctx)
 {
     return(new BuiltinType(PrimitiveType.Bool));
 }
Ejemplo n.º 9
0
 public override Type CSharpSignatureType(TypePrinterContext ctx)
 {
     return(GetEnumType(ctx.Type));
 }
Ejemplo n.º 10
0
 public override string CSharpSignature(TypePrinterContext ctx)
 {
     // doesn't matter, we just need it to compile
     return("int");
 }
Ejemplo n.º 11
0
 public override Type CLISignatureType(TypePrinterContext ctx)
 {
     return(new CustomType("CLI::Employee^"));
 }
Ejemplo n.º 12
0
 public override Type CSharpSignatureType(TypePrinterContext ctx)
 {
     return(new TagType(new Enumeration()));
 }
Ejemplo n.º 13
0
 public override string CSharpSignature(TypePrinterContext ctx)
 {
     return(CSharpSignatureType(ctx).ToString());
 }
Ejemplo n.º 14
0
 public override Type CLISignatureType(TypePrinterContext ctx)
 {
     return(new BuiltinType(PrimitiveType.UShort));
 }
Ejemplo n.º 15
0
 public override string CSharpSignature(TypePrinterContext ctx)
 {
     return(CSharpTypePrinter.IntPtrType);
 }
Ejemplo n.º 16
0
 public override Type CSharpSignatureType(TypePrinterContext ctx)
 {
     return(new TagType(flags ?? (flags = Context.ASTContext.FindEnum("Flags").First())));
 }
Ejemplo n.º 17
0
        private bool?CheckForDefaultConstruct(Type desugared, ExpressionObsolete expression,
                                              ref string result)
        {
            var type = desugared.GetFinalPointee() ?? desugared;

            Class decl;

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

            var ctor = expression as CXXConstructExprObsolete;

            var typePrinter = new CSharpTypePrinter(Context);

            typePrinter.PushMarshalKind(MarshalKind.DefaultExpression);

            var typePrinterResult = type.Visit(typePrinter).Type;

            TypeMap typeMap;

            if (TypeMaps.FindTypeMap(type, out typeMap))
            {
                var typePrinterContext = new TypePrinterContext()
                {
                    Kind        = typePrinter.Kind,
                    MarshalKind = typePrinter.MarshalKind,
                    Type        = type
                };

                var typeInSignature = typeMap.CSharpSignatureType(typePrinterContext)
                                      .SkipPointerRefs().Desugar();

                Enumeration @enum;
                if (typeInSignature.TryGetEnum(out @enum))
                {
                    if (ctor != null &&
                        (ctor.Arguments.Count == 0 ||
                         HasSingleZeroArgExpression((Function)ctor.Declaration)))
                    {
                        result = "0";
                        return(true);
                    }
                    return(false);
                }

                if (ctor != null && typePrinterResult == "string" && ctor.Arguments.Count == 0)
                {
                    result = "\"\"";
                    return(true);
                }
            }

            if (ctor == null)
            {
                CheckForSimpleExpressions(expression, ref result, desugared);
                return(decl.IsValueType ? (bool?)false : null);
            }

            var method = (Method)expression.Declaration;
            var expressionSupported = decl.IsValueType && method.Parameters.Count == 0;

            if (expression.String.Contains('(') || expression.String.StartsWith("{"))
            {
                var argsBuilder = new StringBuilder("new ");
                argsBuilder.Append(typePrinterResult);
                argsBuilder.Append('(');
                for (var i = 0; i < ctor.Arguments.Count; i++)
                {
                    var argument  = ctor.Arguments[i];
                    var argResult = argument.String;
                    expressionSupported &= PrintExpression(method,
                                                           method.Parameters[i].Type.Desugar(), argument, ref argResult) ?? false;
                    argsBuilder.Append(argResult);
                    if (i < ctor.Arguments.Count - 1)
                    {
                        argsBuilder.Append(", ");
                    }
                }
                argsBuilder.Append(')');
                result = argsBuilder.ToString();
            }
            return(expressionSupported ? true : (bool?)null);
        }
Ejemplo n.º 18
0
 public override Type CSharpSignatureType(TypePrinterContext ctx)
 {
     // doesn't matter, we just need it to compile
     return(new BuiltinType(PrimitiveType.Int));
 }
Ejemplo n.º 19
0
 public override Type CSharpSignatureType(TypePrinterContext ctx)
 {
     return(new CILType(typeof(char)));
 }
Ejemplo n.º 20
0
 public override string CSharpSignature(TypePrinterContext ctx)
 {
     return("va_list");
 }
Ejemplo n.º 21
0
 public override Type CLISignatureType(TypePrinterContext ctx)
 {
     return(new CILType(typeof(System.IO.TextWriter)));
 }
Ejemplo n.º 22
0
 public override string CLISignature(TypePrinterContext ctx)
 {
     return(string.Format("System::Collections::Generic::List<{0}>^",
                          ctx.GetTemplateParameterList()));
 }
Ejemplo n.º 23
0
 public override Type CSharpSignatureType(TypePrinterContext ctx) =>
 CSharpTypePrinter.GetUnsignedType(Context.TargetInfo.LongWidth);
Ejemplo n.º 24
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($"{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 + (pointer.IsReference ? "" : "*"));
            }

            Enumeration @enum;

            if (pointee.TryGetEnum(out @enum))
            {
                var typeName = VisitDeclaration(@enum, quals);

                // Skip one indirection if passed by reference
                if (Parameter != null && (Parameter.Type.IsReference() ||
                                          ((Parameter.IsOut || Parameter.IsInOut) &&
                                           pointee == finalPointee)))
                {
                    return(typeName);
                }

                return($"{typeName}*");
            }

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