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; } }
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)); }
public static extern CXType Type_getTemplateArgumentAsType(CXType @T, uint @i);
public static extern CXType Type_getClassType(CXType @T);
public static extern long getNumElements(CXType @T);
public static extern int getNumArgTypes(CXType @T);
public static extern CXType getPointeeType(CXType @T);
internal PipeType(CXType handle) : base(handle, CXTypeKind.CXType_Pipe, CX_TypeClass.CX_TypeClass_Pipe) { _elementType = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.ElementType)); }
private protected TagType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { _decl = new Lazy <TagDecl>(() => TranslationUnit.GetOrCreate <TagDecl>(Handle.Declaration)); }
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)); }
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; } }
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); }
public static extern CXType getCanonicalType(CXType @T);
public static extern uint isVolatileQualifiedType(CXType @T);
internal BlockPointerType(CXType handle) : base(handle, CXTypeKind.CXType_BlockPointer, CX_TypeClass.CX_TypeClass_BlockPointer) { }
public static extern CXCallingConv getFunctionTypeCallingConv(CXType @T);
internal MemberPointerType(CXType handle) : base(handle, CXTypeKind.CXType_MemberPointer, CX_TypeClass.CX_TypeClass_MemberPointer) { }
public static extern uint isFunctionTypeVariadic(CXType @T);
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)); }
public static extern long getArraySize(CXType @T);
internal BitIntType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_BitInt) { }
public static extern long Type_getOffsetOf(CXType @T, [MarshalAs(UnmanagedType.LPStr)] string @S);
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) { }
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)); }
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; } }
public static extern uint equalTypes(CXType @A, CXType @B);
internal VariableArrayType(CXType handle) : base(handle, CXTypeKind.CXType_VariableArray, CX_TypeClass.CX_TypeClass_VariableArray) { _sizeExpr = new Lazy <Expr>(() => TranslationUnit.GetOrCreate <Expr>(handle.SizeExpr)); }
public static extern uint isConstQualifiedType(CXType @T);
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)); }
public static extern uint isRestrictQualifiedType(CXType @T);
internal UnresolvedUsingType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_UnresolvedUsing) { _decl = new Lazy <UnresolvedUsingTypenameDecl>(() => TranslationUnit.GetOrCreate <UnresolvedUsingTypenameDecl>(Handle.Declaration)); }
public static extern CXCursor getTypeDeclaration(CXType @T);
internal RecordType(CXType handle) : base(handle, CXTypeKind.CXType_Record) { }
public static extern CXType getResultType(CXType @T);
internal ObjCObjectType(CXType handle) : this(handle, CXTypeKind.CXType_ObjCObject, CX_TypeClass.CX_TypeClass_ObjCObject) { }
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)); }
public static extern uint isPODType(CXType @T);
internal BuiltinType(CXType handle) : base(handle, handle.kind, CX_TypeClass.CX_TypeClass_Builtin) { }
public static extern CXType getArrayElementType(CXType @T);
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)); }
public static extern long Type_getAlignOf(CXType @T);
internal IncompleteArrayType(CXType handle) : base(handle, CXTypeKind.CXType_IncompleteArray, CX_TypeClass.CX_TypeClass_IncompleteArray) { }
public static extern long Type_getSizeOf(CXType @T);
internal UnaryTransformType(CXType handle) : this(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_UnaryTransform) { }
public static extern int Type_getNumTemplateArguments(CXType @T);
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)); }
public static extern CXRefQualifierKind Type_getCXXRefQualifier(CXType @T);
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)); }
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)); }
internal ExtVectorType(CXType handle) : base(handle, CXTypeKind.CXType_ExtVector, CX_TypeClass.CX_TypeClass_ExtVector) { _desugaredType = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.Desugar())); }
private protected FunctionType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { _returnType = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.ResultType)); }
internal DependentSizedArrayType(CXType handle) : base(handle, CXTypeKind.CXType_DependentSizedArray, CX_TypeClass.CX_TypeClass_DependentSizedArray) { _sizeExpr = new Lazy <Expr>(() => TranslationUnit.GetOrCreate <Expr>(Handle.SizeExpr)); }
public static extern CXString getTypeSpelling(CXType @CT);