forked from OSchip/llvm-project
[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 llvm-svn: 338815
This commit is contained in:
parent
21a8b605a1
commit
40ff105663
|
@ -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
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
@interface Foo
|
||||
-(instancetype)init;
|
||||
@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)=
|
|
@ -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;
|
||||
}
|
||||
|
@ -1782,6 +1784,23 @@ static enum CXChildVisitResult PrintTypeDeclaration(CXCursor cursor, CXCursor p,
|
|||
return CXChildVisit_Recurse;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* 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 **argv) {
|
|||
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);
|
||||
|
|
|
@ -1802,7 +1802,9 @@ bool CursorVisitor::VisitCXXRecordDecl(CXXRecordDecl *D) {
|
|||
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue