r338815 - [libclang 6/8] Add support for reading implicit attributes
Michael Wu via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 2 22:20:23 PDT 2018
Author: mwu
Date: Thu Aug 2 22:20:23 2018
New Revision: 338815
URL: http://llvm.org/viewvc/llvm-project?rev=338815&view=rev
Log:
[libclang 6/8] Add support for reading implicit attributes
Summary:
Having access to implicit attributes is sometimes useful so users of libclang don't have to duplicate some of the logic in sema.
This depends on D49081 since it also adds a CXTranslationUnit flag.
Reviewers: yvvan, jbcoe
Reviewed By: yvvan
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D49631
Added:
cfe/trunk/test/Index/implicit-attrs.m
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/tools/c-index-test/c-index-test.c
cfe/trunk/tools/libclang/CIndex.cpp
Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=338815&r1=338814&r2=338815&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Thu Aug 2 22:20:23 2018
@@ -1336,7 +1336,12 @@ enum CXTranslationUnit_Flags {
/**
* Used to indicate that attributed types should be included in CXType.
*/
- CXTranslationUnit_IncludeAttributedTypes = 0x1000
+ CXTranslationUnit_IncludeAttributedTypes = 0x1000,
+
+ /**
+ * Used to indicate that implicit attributes should be visited.
+ */
+ CXTranslationUnit_VisitImplicitAttributes = 0x2000
};
/**
Added: cfe/trunk/test/Index/implicit-attrs.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/implicit-attrs.m?rev=338815&view=auto
==============================================================================
--- cfe/trunk/test/Index/implicit-attrs.m (added)
+++ cfe/trunk/test/Index/implicit-attrs.m Thu Aug 2 22:20:23 2018
@@ -0,0 +1,6 @@
+ at interface Foo
+-(instancetype)init;
+ at end
+
+// RUN: env CINDEXTEST_VISIT_IMPLICIT_ATTRIBUTES=1 c-index-test -test-print-decl-attributes %s -fobjc-arc | FileCheck %s
+// CHECK: ObjCInstanceMethodDecl=init:2:16 attribute(ns_consumes_self)= attribute(ns_returns_retained)=
Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=338815&r1=338814&r2=338815&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Thu Aug 2 22:20:23 2018
@@ -86,6 +86,8 @@ static unsigned getDefaultParsingOptions
options |= CXTranslationUnit_LimitSkipFunctionBodiesToPreamble;
if (getenv("CINDEXTEST_INCLUDE_ATTRIBUTED_TYPES"))
options |= CXTranslationUnit_IncludeAttributedTypes;
+ if (getenv("CINDEXTEST_VISIT_IMPLICIT_ATTRIBUTES"))
+ options |= CXTranslationUnit_VisitImplicitAttributes;
return options;
}
@@ -1783,6 +1785,23 @@ static enum CXChildVisitResult PrintType
}
/******************************************************************************/
+/* Declaration attributes testing */
+/******************************************************************************/
+
+static enum CXChildVisitResult PrintDeclAttributes(CXCursor cursor, CXCursor p,
+ CXClientData d) {
+ if (clang_isDeclaration(cursor.kind)) {
+ printf("\n");
+ PrintCursor(cursor, NULL);
+ return CXChildVisit_Recurse;
+ } else if (clang_isAttribute(cursor.kind)) {
+ printf(" ");
+ PrintCursor(cursor, NULL);
+ }
+ return CXChildVisit_Continue;
+}
+
+/******************************************************************************/
/* Target information testing. */
/******************************************************************************/
@@ -4793,6 +4812,9 @@ int cindextest_main(int argc, const char
else if (argc > 2 && strcmp(argv[1], "-test-print-type-declaration") == 0)
return perform_test_load_source(argc - 2, argv + 2, "all",
PrintTypeDeclaration, 0);
+ else if (argc > 2 && strcmp(argv[1], "-test-print-decl-attributes") == 0)
+ return perform_test_load_source(argc - 2, argv + 2, "all",
+ PrintDeclAttributes, 0);
else if (argc > 2 && strcmp(argv[1], "-test-print-bitwidth") == 0)
return perform_test_load_source(argc - 2, argv + 2, "all",
PrintBitWidth, 0);
Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=338815&r1=338814&r2=338815&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Thu Aug 2 22:20:23 2018
@@ -1802,7 +1802,9 @@ bool CursorVisitor::VisitCXXRecordDecl(C
bool CursorVisitor::VisitAttributes(Decl *D) {
for (const auto *I : D->attrs())
- if (!I->isImplicit() && Visit(MakeCXCursor(I, D, TU)))
+ if ((TU->ParsingOptions & CXTranslationUnit_VisitImplicitAttributes ||
+ !I->isImplicit()) &&
+ Visit(MakeCXCursor(I, D, TU)))
return true;
return false;
More information about the cfe-commits
mailing list