private protected ObjCObjectType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { _baseType = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.ObjCObjectBaseType)); _interface = new Lazy <ObjCInterfaceDecl>(() => TranslationUnit.GetOrCreate <ObjCInterfaceDecl>(Handle.Declaration)); _protocols = new Lazy <IReadOnlyList <ObjCProtocolDecl> >(() => { var numProtocols = unchecked ((int)Handle.NumObjCProtocolRefs); var protocols = new List <ObjCProtocolDecl>(numProtocols); for (var i = 0; i < numProtocols; i++) { var protocol = TranslationUnit.GetOrCreate <ObjCProtocolDecl>(Handle.GetObjCProtocolDecl(unchecked ((uint)i))); protocols.Add(protocol); } return(protocols); }); _superClassType = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.UnderlyingType)); _typeArgs = new Lazy <IReadOnlyList <Type> >(() => { var numTypeArgs = unchecked ((int)Handle.NumObjCTypeArgs); var typeArgs = new List <Type>(numTypeArgs); for (var i = 0; i < numTypeArgs; i++) { var typeArg = TranslationUnit.GetOrCreate <Type>(Handle.GetObjCTypeArg(unchecked ((uint)i))); typeArgs.Add(typeArg); } return(typeArgs); }); }
public static string GetPrimitiveCsTypeOrNull(this CXTypeKind kind) { switch (kind) { case CXTypeKind.CXType_Bool: return("bool"); case CXTypeKind.CXType_Char16: case CXTypeKind.CXType_WChar: return("char"); case CXTypeKind.CXType_UChar: case CXTypeKind.CXType_Char_U: return("byte"); case CXTypeKind.CXType_SChar: case CXTypeKind.CXType_Char_S: return("sbyte"); case CXTypeKind.CXType_UShort: return("ushort"); case CXTypeKind.CXType_Short: return("short"); case CXTypeKind.CXType_Float: return("float"); case CXTypeKind.CXType_Double: return("double"); case CXTypeKind.CXType_Int: return("int"); case CXTypeKind.CXType_UInt: return("uint"); case CXTypeKind.CXType_Pointer: case CXTypeKind.CXType_NullPtr: // ugh, what else can I do? return("IntPtr"); case CXTypeKind.CXType_Long: return("int"); case CXTypeKind.CXType_ULong: return("uint"); case CXTypeKind.CXType_LongLong: return("long"); case CXTypeKind.CXType_ULongLong: return("ulong"); case CXTypeKind.CXType_Void: return("void"); default: return(null); } }
protected Type(CXType handle, CXTypeKind expectedKind) { if (handle.kind != expectedKind) { throw new ArgumentException(nameof(handle)); } Handle = handle; _canonicalType = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.CanonicalType)); _translationUnit = new Lazy <TranslationUnit>(() => TranslationUnit.GetOrCreate((CXTranslationUnit)Handle.data[1])); }
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 static bool IsPrimitiveNumericType(this CXTypeKind kind) { switch (kind) { case CXTypeKind.CXType_Bool: case CXTypeKind.CXType_UChar: case CXTypeKind.CXType_Char_U: case CXTypeKind.CXType_SChar: case CXTypeKind.CXType_Char_S: case CXTypeKind.CXType_UShort: case CXTypeKind.CXType_Short: case CXTypeKind.CXType_Float: case CXTypeKind.CXType_Double: case CXTypeKind.CXType_Int: case CXTypeKind.CXType_UInt: case CXTypeKind.CXType_Long: case CXTypeKind.CXType_ULong: case CXTypeKind.CXType_LongLong: case CXTypeKind.CXType_ULongLong: return(true); } return(false); }
internal BuiltinType(CXType handle, CXTypeKind expectedKind) : base(handle, expectedKind) { }
private protected ReferenceType(CXType handle, CXTypeKind expectedKind) : base(handle, expectedKind) { _pointeeType = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.PointeeType)); }
private protected FunctionType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { _returnType = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.ResultType)); }
public static extern CXString clang_getTypeKindSpelling( CXTypeKind K);
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)); }
private protected ObjCObjectType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { }
private protected ArrayType(CXType handle, CXTypeKind expectedKind) : base(handle, expectedKind) { _elementType = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.ArrayElementType)); }
private protected DeducedType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { _deducedType = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.DeducedType)); }
private protected UnaryTransformType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { }
/// <summary> /// The GetTypeKindSpelling /// </summary> /// <param name="typeKind">The typeKind<see cref="CXTypeKind"/></param> /// <returns>The <see cref="string"/></returns> public static string GetTypeKindSpelling(CXTypeKind typeKind) { return(clang.clang_getTypeKindSpelling(typeKind).ToStringAndDispose()); }
private protected TypeWithKeyword(CXType handle, CXTypeKind expectedKind) : base(handle, expectedKind) { }
private protected TypeWithKeyword(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { }
private protected MatrixType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { _elementType = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(handle.ElementType)); }
public static bool IsPointer(this CXTypeKind kind) { return(kind == CXTypeKind.CXType_Pointer || kind == CXTypeKind.CXType_ConstantArray); }
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)); }
private protected TagType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { _decl = new Lazy <TagDecl>(() => TranslationUnit.GetOrCreate <TagDecl>(Handle.Declaration)); }
public static string ToPrimitiveCsType(this CXTypeKind kind) { return(GetPrimitiveCsTypeOrNull(kind) ?? "__Invalid__"); }
private protected AdjustedType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { _adjustedType = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.AdjustedType)); _originalType = new Lazy <Type>(() => TranslationUnit.GetOrCreate <Type>(Handle.OriginalType)); }
public CXChildVisitResult Visit(CXCursor cursor, CXCursor parent, IntPtr data) { if (cursor.IsInSystemHeader()) { return(CXChildVisitResult.CXChildVisit_Continue); } CXCursorKind curKind = clang.getCursorKind(cursor); if (curKind == CXCursorKind.CXCursor_EnumDecl) { string inheritedEnumType; CXTypeKind kind = clang.getEnumDeclIntegerType(cursor).kind; switch (kind) { case CXTypeKind.CXType_Int: inheritedEnumType = "int"; break; case CXTypeKind.CXType_UInt: inheritedEnumType = "uint"; break; case CXTypeKind.CXType_Short: inheritedEnumType = "short"; break; case CXTypeKind.CXType_UShort: inheritedEnumType = "ushort"; break; case CXTypeKind.CXType_LongLong: inheritedEnumType = "long"; break; case CXTypeKind.CXType_ULongLong: inheritedEnumType = "ulong"; break; default: inheritedEnumType = "int"; break; } // Cross-plat hack: // For whatever reason, libclang detects untyped enums (i.e. your average 'enum X { A, B }') // as uints on Linux and ints on Windows. // Since we want to have the same generated code everywhere, we try to force 'int' // if it doesn't change semantics, i.e. if all enum values are in the right range. // Remember that 2's complement ints use the same binary representation as uints for positive numbers. if (inheritedEnumType == "uint") { bool hasOneValue = false; long minValue = long.MaxValue; long maxValue = long.MinValue; clang.visitChildren(cursor, (cxCursor, _, __) => { hasOneValue = true; long value = clang.getEnumConstantDeclValue(cxCursor); minValue = Math.Min(minValue, value); maxValue = Math.Max(maxValue, value); return(CXChildVisitResult.CXChildVisit_Continue); }, new CXClientData(IntPtr.Zero)); if (hasOneValue && minValue >= 0 && maxValue <= int.MaxValue) { inheritedEnumType = "int"; } } var enumName = clang.getCursorSpelling(cursor).ToString(); // enumName can be empty because of typedef enum { .. } enumName; // so we have to find the sibling, and this is the only way I've found // to do with libclang, maybe there is a better way? if (string.IsNullOrEmpty(enumName)) { var forwardDeclaringVisitor = new ForwardDeclarationVisitor(cursor); clang.visitChildren(clang.getCursorLexicalParent(cursor), forwardDeclaringVisitor.Visit, new CXClientData(IntPtr.Zero)); enumName = clang.getCursorSpelling(forwardDeclaringVisitor.ForwardDeclarationCursor).ToString(); if (string.IsNullOrEmpty(enumName)) { enumName = "_"; } } // if we've printed these previously, skip them if (this.printedEnums.Contains(enumName)) { return(CXChildVisitResult.CXChildVisit_Continue); } this.printedEnums.Add(enumName); this.tw.WriteLine(" public enum " + enumName + " : " + inheritedEnumType); this.tw.WriteLine(" {"); // visit all the enum values clang.visitChildren(cursor, (cxCursor, _, __) => { this.tw.WriteLine(" @" + clang.getCursorSpelling(cxCursor).ToString() + " = " + clang.getEnumConstantDeclValue(cxCursor) + ","); return(CXChildVisitResult.CXChildVisit_Continue); }, new CXClientData(IntPtr.Zero)); this.tw.WriteLine(" }"); this.tw.WriteLine(); } return(CXChildVisitResult.CXChildVisit_Recurse); }
public static bool IsChar(this CXTypeKind kind) { return(kind == CXTypeKind.CXType_UChar || kind == CXTypeKind.CXType_Char_U || kind == CXTypeKind.CXType_SChar || kind == CXTypeKind.CXType_Char_S); }
private protected DeducedType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { }
public CXChildVisitResult Visit(CXCursor cursor, CXCursor parent, IntPtr data) { if (cursor.IsInSystemHeader()) { return(CXChildVisitResult.CXChildVisit_Continue); } CXCursorKind curKind = clang.getCursorKind(cursor); if (curKind == CXCursorKind.CXCursor_EnumDecl) { string inheritedEnumType; CXTypeKind kind = clang.getEnumDeclIntegerType(cursor).kind; switch (kind) { case CXTypeKind.CXType_Int: inheritedEnumType = "int"; break; case CXTypeKind.CXType_UInt: inheritedEnumType = "uint"; break; case CXTypeKind.CXType_Short: inheritedEnumType = "short"; break; case CXTypeKind.CXType_UShort: inheritedEnumType = "ushort"; break; case CXTypeKind.CXType_LongLong: inheritedEnumType = "long"; break; case CXTypeKind.CXType_ULongLong: inheritedEnumType = "ulong"; break; default: inheritedEnumType = "int"; break; } var enumName = clang.getCursorSpelling(cursor).ToString(); // enumName can be empty because of typedef enum { .. } enumName; // so we have to find the sibling, and this is the only way I've found // to do with libclang, maybe there is a better way? if (string.IsNullOrEmpty(enumName)) { var forwardDeclaringVisitor = new ForwardDeclarationVisitor(cursor); clang.visitChildren(clang.getCursorLexicalParent(cursor), forwardDeclaringVisitor.Visit, new CXClientData(IntPtr.Zero)); enumName = clang.getCursorSpelling(forwardDeclaringVisitor.ForwardDeclarationCursor).ToString(); if (string.IsNullOrEmpty(enumName)) { enumName = "_"; } } // if we've printed these previously, skip them if (this.printedEnums.Contains(enumName)) { return(CXChildVisitResult.CXChildVisit_Continue); } this.printedEnums.Add(enumName); this.tw.WriteLine(" public enum " + enumName + " : " + inheritedEnumType); this.tw.WriteLine(" {"); // visit all the enum values clang.visitChildren(cursor, (cxCursor, _, __) => { this.tw.WriteLine(" @" + clang.getCursorSpelling(cxCursor).ToString() + " = " + clang.getEnumConstantDeclValue(cxCursor) + ","); return(CXChildVisitResult.CXChildVisit_Continue); }, new CXClientData(IntPtr.Zero)); this.tw.WriteLine(" }"); this.tw.WriteLine(); } return(CXChildVisitResult.CXChildVisit_Recurse); }
private protected ReferenceType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { }
public static extern CXString getTypeKindSpelling(CXTypeKind @K);
//public static ClangType TypedefDeclUnderlyingType(CXCursor c) { // return new ClangType(clang.getTypedefDeclUnderlyingType(c)); //} public static string KindSpelling(CXTypeKind K) { return(clang.getTypeKindSpelling(K).ToString()); }