[PATCH] D49631: [libclang 6/8] Add support for reading implicit attributes

Phabricator via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 2 22:20:53 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rC338815: [libclang 6/8] Add support for reading implicit attributes (authored by mwu, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D49631?vs=156666&id=158918#toc

Repository:
  rC Clang

https://reviews.llvm.org/D49631

Files:
  include/clang-c/Index.h
  test/Index/implicit-attrs.m
  tools/c-index-test/c-index-test.c
  tools/libclang/CIndex.cpp


Index: test/Index/implicit-attrs.m
===================================================================
--- test/Index/implicit-attrs.m
+++ test/Index/implicit-attrs.m
@@ -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)=
Index: tools/libclang/CIndex.cpp
===================================================================
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -1802,7 +1802,9 @@
 
 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;
Index: tools/c-index-test/c-index-test.c
===================================================================
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -86,6 +86,8 @@
     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 @@
 }
 
 /******************************************************************************/
+/* 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 @@
   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);
Index: include/clang-c/Index.h
===================================================================
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -1336,7 +1336,12 @@
   /**
    * 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
 };
 
 /**


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49631.158918.patch
Type: text/x-patch
Size: 3581 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180803/1a3eeb44/attachment.bin>


More information about the cfe-commits mailing list