Esempio n. 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;
     }
 }
Esempio n. 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));
        }
Esempio n. 5
0
 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));
 }
Esempio n. 6
0
 public static extern CXType Type_getTemplateArgumentAsType(CXType @T, uint @i);
Esempio n. 7
0
 public static extern CXType Type_getClassType(CXType @T);
Esempio n. 8
0
 public static extern long getNumElements(CXType @T);
Esempio n. 9
0
 public static extern int getNumArgTypes(CXType @T);
Esempio n. 10
0
 public static extern CXType getPointeeType(CXType @T);
Esempio n. 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));
 }
Esempio n. 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));
 }
Esempio n. 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));
 }
Esempio n. 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;
     }
 }
Esempio n. 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);
        }
Esempio n. 16
0
 public static extern CXType getCanonicalType(CXType @T);
Esempio n. 17
0
 public static extern uint isVolatileQualifiedType(CXType @T);
Esempio n. 18
0
 internal BlockPointerType(CXType handle) : base(handle, CXTypeKind.CXType_BlockPointer, CX_TypeClass.CX_TypeClass_BlockPointer)
 {
 }
Esempio n. 19
0
 public static extern CXCallingConv getFunctionTypeCallingConv(CXType @T);
Esempio n. 20
0
 internal MemberPointerType(CXType handle) : base(handle, CXTypeKind.CXType_MemberPointer, CX_TypeClass.CX_TypeClass_MemberPointer)
 {
 }
Esempio n. 21
0
 public static extern uint isFunctionTypeVariadic(CXType @T);
Esempio n. 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));
 }
Esempio n. 23
0
 public static extern long getArraySize(CXType @T);
Esempio n. 24
0
 internal BitIntType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_BitInt)
 {
 }
Esempio n. 25
0
 public static extern long Type_getOffsetOf(CXType @T, [MarshalAs(UnmanagedType.LPStr)] string @S);
Esempio n. 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)
 {
 }
Esempio n. 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));
 }
Esempio n. 29
0
 internal PipeType(CXType handle) : base(handle, CXTypeKind.CXType_Pipe, CX_TypeClass.CX_TypeClass_Pipe)
 {
 }
Esempio n. 30
0
        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;
            }
        }
Esempio n. 31
0
 public static extern uint equalTypes(CXType @A, CXType @B);
Esempio n. 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));
 }
Esempio n. 33
0
 public static extern uint isConstQualifiedType(CXType @T);
Esempio n. 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));
 }
Esempio n. 35
0
 public static extern uint isRestrictQualifiedType(CXType @T);
Esempio n. 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));
 }
Esempio n. 37
0
 public static extern CXCursor getTypeDeclaration(CXType @T);
Esempio n. 38
0
 internal RecordType(CXType handle) : base(handle, CXTypeKind.CXType_Record)
 {
 }
Esempio n. 39
0
 public static extern CXType getResultType(CXType @T);
Esempio n. 40
0
 internal ObjCObjectType(CXType handle) : this(handle, CXTypeKind.CXType_ObjCObject, CX_TypeClass.CX_TypeClass_ObjCObject)
 {
 }
Esempio n. 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));
 }
Esempio n. 43
0
 public static extern uint isPODType(CXType @T);
Esempio n. 44
0
 internal BuiltinType(CXType handle) : base(handle, handle.kind, CX_TypeClass.CX_TypeClass_Builtin)
 {
 }
Esempio n. 45
0
 public static extern CXType getArrayElementType(CXType @T);
Esempio n. 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));
 }
Esempio n. 47
0
 public static extern long Type_getAlignOf(CXType @T);
Esempio n. 48
0
 internal IncompleteArrayType(CXType handle) : base(handle, CXTypeKind.CXType_IncompleteArray, CX_TypeClass.CX_TypeClass_IncompleteArray)
 {
 }
Esempio n. 49
0
 public static extern long Type_getSizeOf(CXType @T);
Esempio n. 50
0
 internal UnaryTransformType(CXType handle) : this(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_UnaryTransform)
 {
 }
Esempio n. 51
0
 public static extern int Type_getNumTemplateArguments(CXType @T);
Esempio n. 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));
 }
Esempio n. 53
0
 public static extern CXRefQualifierKind Type_getCXXRefQualifier(CXType @T);
Esempio n. 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));
 }
Esempio n. 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));
 }
Esempio n. 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()));
 }
Esempio n. 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));
 }
Esempio n. 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));
 }
Esempio n. 60
0
 public static extern CXString getTypeSpelling(CXType @CT);