r257043 - [libclang] Handle AutoType in clang_getTypeDeclaration

Sergey Kalinichev via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 7 01:20:41 PST 2016


Author: skalinichev
Date: Thu Jan  7 03:20:40 2016
New Revision: 257043

URL: http://llvm.org/viewvc/llvm-project?rev=257043&view=rev
Log:
[libclang] Handle AutoType in clang_getTypeDeclaration

Differential Revision: http://reviews.llvm.org/D13001

Added:
    cfe/trunk/test/Index/print-type-declaration.cpp
Modified:
    cfe/trunk/tools/c-index-test/c-index-test.c
    cfe/trunk/tools/libclang/CXType.cpp

Added: cfe/trunk/test/Index/print-type-declaration.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/print-type-declaration.cpp?rev=257043&view=auto
==============================================================================
--- cfe/trunk/test/Index/print-type-declaration.cpp (added)
+++ cfe/trunk/test/Index/print-type-declaration.cpp Thu Jan  7 03:20:40 2016
@@ -0,0 +1,12 @@
+
+class Test{};
+
+int main()
+{
+  auto a = Test();
+  auto b = a;
+}
+
+// RUN: c-index-test -test-print-type-declaration -std=c++11 %s | FileCheck %s
+// CHECK: VarDecl=a:6:8 (Definition) [typedeclaration=Test] [typekind=Record]
+// CHECK: VarDecl=b:7:8 (Definition) [typedeclaration=Test] [typekind=Record]

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=257043&r1=257042&r2=257043&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Thu Jan  7 03:20:40 2016
@@ -1508,6 +1508,22 @@ static enum CXChildVisitResult PrintBitW
 }
 
 /******************************************************************************/
+/* Type declaration testing                                                   */
+/******************************************************************************/
+
+static enum CXChildVisitResult PrintTypeDeclaration(CXCursor cursor, CXCursor p,
+                                             CXClientData d) {
+  CXCursor typeDeclaration = clang_getTypeDeclaration(clang_getCursorType(cursor));
+
+  if (clang_isDeclaration(typeDeclaration.kind)) {
+    PrintCursor(cursor, NULL);
+    PrintTypeAndTypeKind(clang_getCursorType(typeDeclaration), " [typedeclaration=%s] [typekind=%s]\n");
+  }
+
+  return CXChildVisit_Recurse;
+}
+
+/******************************************************************************/
 /* Loading ASTs/source.                                                       */
 /******************************************************************************/
 
@@ -4137,6 +4153,7 @@ static void print_usage(void) {
     "       c-index-test -test-print-type {<args>}*\n"
     "       c-index-test -test-print-type-size {<args>}*\n"
     "       c-index-test -test-print-bitwidth {<args>}*\n"
+    "       c-index-test -test-print-type-declaration {<args>}*\n"
     "       c-index-test -print-usr [<CursorKind> {<args>}]*\n"
     "       c-index-test -print-usr-file <file>\n"
     "       c-index-test -write-pch <file> <compiler arguments>\n");
@@ -4230,6 +4247,9 @@ int cindextest_main(int argc, const char
   else if (argc > 2 && strcmp(argv[1], "-test-print-type-size") == 0)
     return perform_test_load_source(argc - 2, argv + 2, "all",
                                     PrintTypeSize, 0);
+  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-bitwidth") == 0)
     return perform_test_load_source(argc - 2, argv + 2, "all",
                                     PrintBitWidth, 0);

Modified: cfe/trunk/tools/libclang/CXType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXType.cpp?rev=257043&r1=257042&r2=257043&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXType.cpp (original)
+++ cfe/trunk/tools/libclang/CXType.cpp Thu Jan  7 03:20:40 2016
@@ -412,6 +412,12 @@ try_again:
                                                          .getAsTemplateDecl();
     break;
 
+  case Type::Auto:
+    TP = cast<AutoType>(TP)->getDeducedType().getTypePtrOrNull();
+    if (TP)
+      goto try_again;
+    break;
+
   case Type::InjectedClassName:
     D = cast<InjectedClassNameType>(TP)->getDecl();
     break;




More information about the cfe-commits mailing list