Example #1
0
        public static void ArgumentHelper(CXType functionType, CXCursor paramCursor, TextWriter tw, uint index)
        {
            var numArgTypes = clang.getNumArgTypes(functionType);
            var type = clang.getArgType(functionType, index);
            var cursorType = clang.getCursorType(paramCursor);

            var spelling = clang.getCursorSpelling(paramCursor).ToString();
            if (string.IsNullOrEmpty(spelling))
            {
                spelling = "param" + index;
            }

            switch (type.kind)
            {
                case CXTypeKind.CXType_Pointer:
                    var pointee = clang.getPointeeType(type);
                    switch (pointee.kind)
                    {
                        case CXTypeKind.CXType_Pointer:
                            tw.Write(pointee.IsPtrToConstChar() && clang.isConstQualifiedType(pointee) != 0 ? "string[]" : "out IntPtr");
                            break;
                        case CXTypeKind.CXType_FunctionProto:
                            tw.Write(clang.getTypeSpelling(cursorType).ToString());
                            break;
                        case CXTypeKind.CXType_Void:
                            tw.Write("IntPtr");
                            break;
                        case CXTypeKind.CXType_Char_S:
                            tw.Write(type.IsPtrToConstChar() ? "[MarshalAs(UnmanagedType.LPStr)] string" : "IntPtr"); // if it's not a const, it's best to go with IntPtr
                            break;
                        case CXTypeKind.CXType_WChar:
                            tw.Write(type.IsPtrToConstChar() ? "[MarshalAs(UnmanagedType.LPWStr)] string" : "IntPtr");
                            break;
                        default:
                            CommonTypeHandling(pointee, tw, "out ");
                            break;
                    }
                    break;
                default:
                    CommonTypeHandling(type, tw);
                    break;
            }

            tw.Write(" @");
            tw.Write(spelling);

            if (index != numArgTypes - 1)
            {
                tw.Write(", ");
            }
        }
 public static void WriteReturnType(CXType resultType, TextWriter tw)
 {
     switch (resultType.kind)
     {
         case CXTypeKind.CXType_Pointer:
             // const char* gets special treatment
             var typeString = resultType.IsPtrToConstChar() ? @"string" : resultType.ToPlainTypeString();
             tw.Write(typeString);
             break;
         default:
             WriteCommonType(resultType, tw);
             break;
     }
 }
Example #3
0
        protected Type(CXType handle, CXTypeKind expectedKind, CX_TypeClass expectedTypeClass)
        {
            if (handle.kind != expectedKind)
            {
                throw new ArgumentOutOfRangeException(nameof(handle));
            }

            if ((handle.TypeClass == CX_TypeClass.CX_TypeClass_Invalid) || (handle.TypeClass != expectedTypeClass))
            {
                throw new ArgumentOutOfRangeException(nameof(handle));
            }
            Handle = handle;

            _canonicalType   = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.CanonicalType));
            _desugar         = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.Desugar));
            _pointeeType     = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.PointeeType));
            _translationUnit = new Lazy <TranslationUnit>(() => TranslationUnit.GetOrCreate((CXTranslationUnit)Handle.data[1]));
        }
        public TypeSyntax PortType(CXType type)
        {
            if (type.kind == CXTypeKind.CXType_Pointer)
                return CommonTypes.IntPtrTypeSyntax;

            if (type.kind == CXTypeKind.CXType_ObjCObjectPointer) {
                type = type.GetPointee ();
                return SF.ParseTypeName (type.ToString ());
            }

            if (type.kind == CXTypeKind.CXType_Void)
                return CommonTypes.VoidTypeSyntax;

            if (type.kind == CXTypeKind.CXType_Int)
                return CommonTypes.IntTypeSyntax;

            if (type.kind == CXTypeKind.CXType_Float)
                return CommonTypes.FloatTypeSyntax;

            if (type.kind == CXTypeKind.CXType_Double)
                return CommonTypes.DoubleTypeSyntax;

            return SF.ParseTypeName (Prettify (type));
        }
 internal DependentVectorType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_DependentVector)
 {
     _desugaredType = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.Desugar()));
     _elementType   = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.ElementType));
     _sizeExpr      = new Lazy <Expr>(() => TranslationUnit.GetOrCreate <Expr>(Handle.SizeExpr));
 }
Example #6
0
 public static extern CXType Type_getTemplateArgumentAsType(CXType @T, uint @i);
Example #7
0
 public static extern CXType Type_getClassType(CXType @T);
Example #8
0
 public static extern long getNumElements(CXType @T);
Example #9
0
 public static extern int getNumArgTypes(CXType @T);
Example #10
0
 public static extern CXType getPointeeType(CXType @T);
Example #11
0
 internal PipeType(CXType handle) : base(handle, CXTypeKind.CXType_Pipe, CX_TypeClass.CX_TypeClass_Pipe)
 {
     _elementType = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.ElementType));
 }
Example #12
0
 private protected TagType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass)
 {
     _decl = new Lazy <TagDecl>(() => TranslationUnit.GetOrCreate <TagDecl>(Handle.Declaration));
 }
Example #13
0
 internal DependentExtIntType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_DependentExtInt)
 {
     _desugaredType = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.Desugar()));
     _numBitsExpr   = new Lazy <Expr>(() => TranslationUnit.GetOrCreate <Expr>(handle.NumBitsExpr));
 }
Example #14
0
 public static void ReturnTypeHelper(CXType resultType, TextWriter tw)
 {
     switch (resultType.kind)
     {
         case CXTypeKind.CXType_Pointer:
             tw.Write(resultType.IsPtrToConstChar() ? "string" : "IntPtr"); // const char* gets special treatment
             break;
         default:
             CommonTypeHandling(resultType, tw);
             break;
     }
 }
Example #15
0
        private static void CommonTypeHandling(CXType type, TextWriter tw, string outParam = "")
        {
            bool isConstQualifiedType = clang.isConstQualifiedType(type) != 0;
            string spelling;
            switch (type.kind)
            {
                case CXTypeKind.CXType_Typedef:
                    var cursor = clang.getTypeDeclaration(type);
                    if (clang.Location_isInSystemHeader(clang.getCursorLocation(cursor)) != 0)
                    {
                        spelling = clang.getCanonicalType(type).ToPlainTypeString();
                    }
                    else
                    {
                        spelling = clang.getCursorSpelling(cursor).ToString();
                    }
                    break;
                case CXTypeKind.CXType_Record:
                case CXTypeKind.CXType_Enum:
                    spelling = clang.getTypeSpelling(type).ToString();
                    break;
                case CXTypeKind.CXType_IncompleteArray:
                    CommonTypeHandling(clang.getArrayElementType(type), tw);
                    spelling = "[]";
                    break;
                case CXTypeKind.CXType_Unexposed: // Often these are enums and canonical type gets you the enum spelling
                    var canonical = clang.getCanonicalType(type);
                    // unexposed decl which turns into a function proto seems to be an un-typedef'd fn pointer
                    if (canonical.kind == CXTypeKind.CXType_FunctionProto)
                    {
                        spelling = "IntPtr";
                    }
                    else
                    {
                        spelling = clang.getTypeSpelling(canonical).ToString();
                    }
                    break;
                default:
                    spelling = clang.getCanonicalType(type).ToPlainTypeString();
                    break;
            }

            if (isConstQualifiedType)
            {
                spelling = spelling.Replace("const ", string.Empty); // ugh
            }

            tw.Write(outParam + spelling);
        }
Example #16
0
 public static extern CXType getCanonicalType(CXType @T);
Example #17
0
 public static extern uint isVolatileQualifiedType(CXType @T);
Example #18
0
 internal BlockPointerType(CXType handle) : base(handle, CXTypeKind.CXType_BlockPointer, CX_TypeClass.CX_TypeClass_BlockPointer)
 {
 }
Example #19
0
 public static extern CXCallingConv getFunctionTypeCallingConv(CXType @T);
Example #20
0
 internal MemberPointerType(CXType handle) : base(handle, CXTypeKind.CXType_MemberPointer, CX_TypeClass.CX_TypeClass_MemberPointer)
 {
 }
Example #21
0
 public static extern uint isFunctionTypeVariadic(CXType @T);
Example #22
0
 internal DecltypeType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_Decltype)
 {
     _underlyingExpr = new Lazy <Expr>(() => TranslationUnit.GetOrCreate <Expr>(Handle.UnderlyingExpr));
     _underlyingType = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.UnderlyingType));
 }
Example #23
0
 public static extern long getArraySize(CXType @T);
Example #24
0
 internal BitIntType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_BitInt)
 {
 }
Example #25
0
 public static extern long Type_getOffsetOf(CXType @T, [MarshalAs(UnmanagedType.LPStr)] string @S);
Example #26
0
 internal VectorType(CXType handle) : base(handle, CXTypeKind.CXType_Vector, CX_TypeClass.CX_TypeClass_Vector)
 {
 }
 internal FunctionNoProtoType(CXType handle) : base(handle, CXTypeKind.CXType_FunctionNoProto, CX_TypeClass.CX_TypeClass_FunctionNoProto)
 {
 }
Example #28
0
 private protected VectorType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass)
 {
     _desugaredType = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.Desugar()));
     _elementType   = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.ElementType));
 }
Example #29
0
 internal PipeType(CXType handle) : base(handle, CXTypeKind.CXType_Pipe, CX_TypeClass.CX_TypeClass_Pipe)
 {
 }
        private static string GetTypeName(string cursorSpelling, CXType type)
        {
            var canonical = clang.getCanonicalType(type);
            switch (canonical.kind)
            {
                case CXTypeKind.CXType_Pointer:
                    var pointeeType = clang.getCanonicalType(clang.getPointeeType(canonical));
                    switch (pointeeType.kind)
                    {
                        case CXTypeKind.CXType_ConstantArray:
                        case CXTypeKind.CXType_FunctionProto:
                            return @"IntPtr";
                        default:
                            return GetTypeName(cursorSpelling, pointeeType) + @"*";
                    }

                default:
                    var typeString = canonical.ToPlainTypeString();
                    if (typeString.Contains(@"anonymous union at") || typeString.Contains(@"anonymous struct at") || typeString.Contains(@"anonymous enum at"))
                    {
                        typeString = cursorSpelling;
                    }
                    return typeString;
            }
        }
Example #31
0
 public static extern uint equalTypes(CXType @A, CXType @B);
Example #32
0
 internal VariableArrayType(CXType handle) : base(handle, CXTypeKind.CXType_VariableArray, CX_TypeClass.CX_TypeClass_VariableArray)
 {
     _sizeExpr = new Lazy <Expr>(() => TranslationUnit.GetOrCreate <Expr>(handle.SizeExpr));
 }
Example #33
0
 public static extern uint isConstQualifiedType(CXType @T);
Example #34
0
 internal DecayedType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_Decayed)
 {
     _decayedType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.DecayedType));
     _pointeeType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.PointeeType));
 }
Example #35
0
 public static extern uint isRestrictQualifiedType(CXType @T);
Example #36
0
 internal UnresolvedUsingType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_UnresolvedUsing)
 {
     _decl = new Lazy <UnresolvedUsingTypenameDecl>(() => TranslationUnit.GetOrCreate <UnresolvedUsingTypenameDecl>(Handle.Declaration));
 }
Example #37
0
 public static extern CXCursor getTypeDeclaration(CXType @T);
Example #38
0
 internal RecordType(CXType handle) : base(handle, CXTypeKind.CXType_Record)
 {
 }
Example #39
0
 public static extern CXType getResultType(CXType @T);
 internal ObjCObjectType(CXType handle) : this(handle, CXTypeKind.CXType_ObjCObject, CX_TypeClass.CX_TypeClass_ObjCObject)
 {
 }
Example #41
0
 public static extern CXType getArgType(CXType @T, uint @i);
 internal ObjCInterfaceType(CXType handle) : base(handle, CXTypeKind.CXType_ObjCObject, CX_TypeClass.CX_TypeClass_ObjCInterface)
 {
     _decl = new Lazy <ObjCInterfaceDecl>(() => TranslationUnit.GetOrCreate <ObjCInterfaceDecl>(Handle.Declaration));
 }
Example #43
0
 public static extern uint isPODType(CXType @T);
Example #44
0
 internal BuiltinType(CXType handle) : base(handle, handle.kind, CX_TypeClass.CX_TypeClass_Builtin)
 {
 }
Example #45
0
 public static extern CXType getArrayElementType(CXType @T);
Example #46
0
 internal BlockPointerType(CXType handle) : base(handle, CXTypeKind.CXType_BlockPointer, CX_TypeClass.CX_TypeClass_BlockPointer)
 {
     _desugaredType = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.Desugar()));
     _pointeeType   = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.PointeeType));
 }
Example #47
0
 public static extern long Type_getAlignOf(CXType @T);
Example #48
0
 internal IncompleteArrayType(CXType handle) : base(handle, CXTypeKind.CXType_IncompleteArray, CX_TypeClass.CX_TypeClass_IncompleteArray)
 {
 }
Example #49
0
 public static extern long Type_getSizeOf(CXType @T);
Example #50
0
 internal UnaryTransformType(CXType handle) : this(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_UnaryTransform)
 {
 }
Example #51
0
 public static extern int Type_getNumTemplateArguments(CXType @T);
Example #52
0
 private protected UnaryTransformType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass)
 {
     _baseType       = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.BaseType));
     _underlyingType = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.UnderlyingType));
 }
Example #53
0
 public static extern CXRefQualifierKind Type_getCXXRefQualifier(CXType @T);
Example #54
0
 internal ConstantArrayType(CXType handle) : base(handle, CXTypeKind.CXType_ConstantArray, CX_TypeClass.CX_TypeClass_ConstantArray)
 {
     _desugaredType = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.Desugar()));
     _sizeExpr      = new Lazy <Expr>(() => TranslationUnit.GetOrCreate <Expr>(Handle.SizeExpr));
 }
 internal DependentBitIntType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_DependentBitInt)
 {
     _numBitsExpr = new Lazy <Expr>(() => TranslationUnit.GetOrCreate <Expr>(handle.NumBitsExpr));
 }
Example #56
0
 internal DependentAddressSpaceType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_DependentAddressSpace)
 {
     _addrSpaceExpr = new Lazy <Expr>(() => TranslationUnit.GetOrCreate <Expr>(Handle.AddrSpaceExpr));
     _desugaredType = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.Desugar()));
     _pointeeType   = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.PointeeType));
 }
Example #57
0
 internal ExtVectorType(CXType handle) : base(handle, CXTypeKind.CXType_ExtVector, CX_TypeClass.CX_TypeClass_ExtVector)
 {
     _desugaredType = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.Desugar()));
 }
Example #58
0
 private protected FunctionType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass)
 {
     _returnType = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.ResultType));
 }
Example #59
0
 internal DependentSizedArrayType(CXType handle) : base(handle, CXTypeKind.CXType_DependentSizedArray, CX_TypeClass.CX_TypeClass_DependentSizedArray)
 {
     _sizeExpr = new Lazy <Expr>(() => TranslationUnit.GetOrCreate <Expr>(Handle.SizeExpr));
 }
Example #60
0
 public static extern CXString getTypeSpelling(CXType @CT);