From 1e91237549378d00d0af16d856c0e1243b0d79c8 Mon Sep 17 00:00:00 2001 From: Sergey Kalinichev Date: Thu, 7 Jan 2016 09:20:40 +0000 Subject: [PATCH] [libclang] Handle AutoType in clang_getTypeDeclaration Differential Revision: http://reviews.llvm.org/D13001 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257043 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Index/print-type-declaration.cpp | 12 ++++++++++++ tools/c-index-test/c-index-test.c | 20 ++++++++++++++++++++ tools/libclang/CXType.cpp | 6 ++++++ 3 files changed, 38 insertions(+) create mode 100644 test/Index/print-type-declaration.cpp diff --git a/test/Index/print-type-declaration.cpp b/test/Index/print-type-declaration.cpp new file mode 100644 index 0000000000..31c0a73fcd --- /dev/null +++ b/test/Index/print-type-declaration.cpp @@ -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] diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index 8336491c01..2a6002537e 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -1507,6 +1507,22 @@ static enum CXChildVisitResult PrintBitWidth(CXCursor cursor, CXCursor p, return CXChildVisit_Recurse; } +/******************************************************************************/ +/* 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 {}*\n" " c-index-test -test-print-type-size {}*\n" " c-index-test -test-print-bitwidth {}*\n" + " c-index-test -test-print-type-declaration {}*\n" " c-index-test -print-usr [ {}]*\n" " c-index-test -print-usr-file \n" " c-index-test -write-pch \n"); @@ -4230,6 +4247,9 @@ int cindextest_main(int argc, const char **argv) { 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); diff --git a/tools/libclang/CXType.cpp b/tools/libclang/CXType.cpp index 72c12cd16b..44bb631f78 100644 --- a/tools/libclang/CXType.cpp +++ b/tools/libclang/CXType.cpp @@ -412,6 +412,12 @@ try_again: .getAsTemplateDecl(); break; + case Type::Auto: + TP = cast(TP)->getDeducedType().getTypePtrOrNull(); + if (TP) + goto try_again; + break; + case Type::InjectedClassName: D = cast(TP)->getDecl(); break; -- 2.50.1