From 3ce9e7d270e7df86c09c8126b4412d55be7c123b Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Fri, 30 Jul 2010 00:14:11 +0000 Subject: [PATCH] Add clang_isPODType() for querying if the CXType is POD. Implements . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109822 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang-c/Index.h | 6 ++++++ test/Index/print-typekind.c | 27 +++++++++++++++----------- tools/c-index-test/c-index-test.c | 2 ++ tools/libclang/CXTypes.cpp | 7 +++++++ tools/libclang/libclang.darwin.exports | 1 + tools/libclang/libclang.exports | 1 + 6 files changed, 33 insertions(+), 11 deletions(-) diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h index 30feb41f33..49a11612be 100644 --- a/include/clang-c/Index.h +++ b/include/clang-c/Index.h @@ -1294,6 +1294,12 @@ CINDEX_LINKAGE CXType clang_getResultType(CXType T); */ CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C); +/** + * \brief Return 1 if the CXType is a POD (plain old data) type, and 0 + * otherwise. + */ +CINDEX_LINKAGE unsigned clang_isPODType(CXType T); + /** * @} */ diff --git a/test/Index/print-typekind.c b/test/Index/print-typekind.c index 13b41198f1..18189c3c74 100644 --- a/test/Index/print-typekind.c +++ b/test/Index/print-typekind.c @@ -6,15 +6,20 @@ int *f(int *p, char *x, FooType z) { } // RUN: c-index-test -test-print-typekind %s | FileCheck %s -// CHECK: TypedefDecl=FooType:1:13 (Definition) typekind=Typedef [canonical=Int] -// CHECK: VarDecl=p:2:6 typekind=Pointer -// CHECK: FunctionDecl=f:3:6 (Definition) typekind=FunctionProto [canonical=FunctionProto] [result=Pointer] -// CHECK: ParmDecl=p:3:13 (Definition) typekind=Pointer -// CHECK: ParmDecl=x:3:22 (Definition) typekind=Pointer -// CHECK: ParmDecl=z:3:33 (Definition) typekind=Typedef [canonical=Int] -// CHECK: VarDecl=w:4:11 (Definition) typekind=Typedef [canonical=Int] -// CHECK: DeclRefExpr=z:3:33 typekind=Typedef [canonical=Int] -// CHECK: UnexposedExpr= typekind=Pointer -// CHECK: DeclRefExpr=p:3:13 typekind=Pointer -// CHECK: DeclRefExpr=z:3:33 typekind=Typedef [canonical=Int] +// CHECK: TypedefDecl=FooType:1:13 (Definition) typekind=Typedef [canonical=Int] [isPOD=1] +// CHECK: VarDecl=p:2:6 typekind=Pointer [isPOD=1] +// CHECK: FunctionDecl=f:3:6 (Definition) typekind=FunctionProto [canonical=FunctionProto] [result=Pointer] [isPOD=0] +// CHECK: ParmDecl=p:3:13 (Definition) typekind=Pointer [isPOD=1] +// CHECK: ParmDecl=x:3:22 (Definition) typekind=Pointer [isPOD=1] +// CHECK: ParmDecl=z:3:33 (Definition) typekind=Typedef [canonical=Int] [isPOD=1] +// CHECK: TypeRef=FooType:1:13 typekind=Invalid [isPOD=0] +// CHECK: UnexposedStmt= typekind=Invalid [isPOD=0] +// CHECK: UnexposedStmt= typekind=Invalid [isPOD=0] +// CHECK: VarDecl=w:4:11 (Definition) typekind=Typedef [canonical=Int] [isPOD=1] +// CHECK: TypeRef=FooType:1:13 typekind=Invalid [isPOD=0] +// CHECK: DeclRefExpr=z:3:33 typekind=Typedef [canonical=Int] [isPOD=1] +// CHECK: UnexposedStmt= typekind=Invalid [isPOD=0] +// CHECK: UnexposedExpr= typekind=Pointer [isPOD=1] +// CHECK: DeclRefExpr=p:3:13 typekind=Pointer [isPOD=1] +// CHECK: DeclRefExpr=z:3:33 typekind=Typedef [canonical=Int] [isPOD=1] diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index b8d4cb8917..795c19c0cb 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -487,6 +487,8 @@ static enum CXChildVisitResult PrintTypeKind(CXCursor cursor, CXCursor p, clang_disposeString(RS); } } + /* Print if this is a non-POD type. */ + printf(" [isPOD=%d]", clang_isPODType(T)); printf("\n"); } diff --git a/tools/libclang/CXTypes.cpp b/tools/libclang/CXTypes.cpp index d5c9f45210..b49ef191e3 100644 --- a/tools/libclang/CXTypes.cpp +++ b/tools/libclang/CXTypes.cpp @@ -283,4 +283,11 @@ CXType clang_getCursorResultType(CXCursor C) { return MakeCXType(QualType(), cxcursor::getCursorASTUnit(C)); } +unsigned clang_isPODType(CXType X) { + QualType T = GetQualType(X); + if (!T.getTypePtr()) + return 0; + return T->isPODType() ? 1 : 0; +} + } // end: extern "C" diff --git a/tools/libclang/libclang.darwin.exports b/tools/libclang/libclang.darwin.exports index e51620c786..50ed994b1f 100644 --- a/tools/libclang/libclang.darwin.exports +++ b/tools/libclang/libclang.darwin.exports @@ -82,6 +82,7 @@ _clang_isDeclaration _clang_isExpression _clang_isInvalid _clang_isPreprocessing +_clang_isPODType _clang_isReference _clang_isStatement _clang_isTranslationUnit diff --git a/tools/libclang/libclang.exports b/tools/libclang/libclang.exports index 3d3e7138c8..752c6504c9 100644 --- a/tools/libclang/libclang.exports +++ b/tools/libclang/libclang.exports @@ -82,6 +82,7 @@ clang_isDeclaration clang_isExpression clang_isInvalid clang_isPreprocessing +clang_isPODType clang_isReference clang_isStatement clang_isTranslationUnit -- 2.40.0