aboutsummaryrefslogtreecommitdiff
path: root/clang/tools
diff options
context:
space:
mode:
authorIvan Donchevskii <yv.ivan@gmail.com>2019-04-29 13:44:07 +0000
committerIvan Donchevskii <yv.ivan@gmail.com>2019-04-29 13:44:07 +0000
commit50be573ed207baa477e209cf9e8b247ddd402bc5 (patch)
tree779ac3518b92a420bbe4a1c9cb3f015cef7ab6ba /clang/tools
parent5a33047022ca4b7863be05b4be75678d5c0a44ee (diff)
downloadllvm-50be573ed207baa477e209cf9e8b247ddd402bc5.zip
llvm-50be573ed207baa477e209cf9e8b247ddd402bc5.tar.gz
llvm-50be573ed207baa477e209cf9e8b247ddd402bc5.tar.bz2
[libclang] Restore old clang_Cursor_isAnonymous behaviour
D54996 Changed the behaviour of clang_Cursor_isAnonymous, but there is no alternative available to get the old behaviour in some cases, which is essential for determining if a record is syntactically accessible, e.g. struct { int x; int y; } foo; struct { struct { int x; int y; }; } bar; void fun(struct { int x; int y; } *param); The only 'anonymous' struct here is the one nested in bar, since there is no way to reference the struct itself, only the fields within. Though the anonymity applies to the instance itself, not the type. To avoid confusion, I have added a new function called clang_Cursor_isAnonymousRecordDecl which has the old behaviour of clang_Cursor_isAnonymous (and updated the doc for the latter as well, which was seemingly forgotten). Patch by Jorn Vernee. Differential Revision: https://reviews.llvm.org/D61232 llvm-svn: 359448
Diffstat (limited to 'clang/tools')
-rw-r--r--clang/tools/c-index-test/c-index-test.c6
-rw-r--r--clang/tools/libclang/CXType.cpp10
2 files changed, 16 insertions, 0 deletions
diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c
index 2cf442e..17b773c 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -1665,6 +1665,12 @@ static enum CXChildVisitResult PrintType(CXCursor cursor, CXCursor p,
}
}
+ /* Print if it is an anonymous record decl */
+ {
+ unsigned isAnonRecDecl = clang_Cursor_isAnonymousRecordDecl(cursor);
+ printf(" [isAnonRecDecl=%d]", isAnonRecDecl);
+ }
+
printf("\n");
}
return CXChildVisit_Recurse;
diff --git a/clang/tools/libclang/CXType.cpp b/clang/tools/libclang/CXType.cpp
index 4d22a5e..6cb680a 100644
--- a/clang/tools/libclang/CXType.cpp
+++ b/clang/tools/libclang/CXType.cpp
@@ -1253,6 +1253,16 @@ unsigned clang_Cursor_isAnonymous(CXCursor C){
return 0;
}
+
+unsigned clang_Cursor_isAnonymousRecordDecl(CXCursor C){
+ if (!clang_isDeclaration(C.kind))
+ return 0;
+ const Decl *D = cxcursor::getCursorDecl(C);
+ if (const RecordDecl *FD = dyn_cast_or_null<RecordDecl>(D))
+ return FD->isAnonymousStructOrUnion();
+ return 0;
+}
+
CXType clang_Type_getNamedType(CXType CT){
QualType T = GetQualType(CT);
const Type *TP = T.getTypePtrOrNull();