[clang] [libclang] Visit function template instantiations (PR #67928)
https://github.com/Danacus updated https://github.com/llvm/llvm-project/pull/67928 >From a137ab3f276bfc7f31ff12811232420aa4d7d308 Mon Sep 17 00:00:00 2001 From: Daan Vanoverloop Date: Sat, 7 Oct 2023 10:43:32 +0200 Subject: [PATCH 1/2] [libclang] Add support for template arguments of CXXMethod cursors --- clang/include/clang-c/Index.h | 13 +++-- clang/tools/c-index-test/c-index-test.c | 9 + clang/tools/libclang/CXCursor.cpp | 8 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index 1b91feabd584c50..eeb23ce41ef373c 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -3126,9 +3126,9 @@ CINDEX_LINKAGE int clang_Cursor_getNumTemplateArguments(CXCursor C); /** * Retrieve the kind of the I'th template argument of the CXCursor C. * - * If the argument CXCursor does not represent a FunctionDecl, StructDecl, or - * ClassTemplatePartialSpecialization, an invalid template argument kind is - * returned. + * If the argument CXCursor does not represent a FunctionDecl, CXXMethod, + * StructDecl, or ClassTemplatePartialSpecialization, an invalid template + * argument kind is returned. * * For example, for the following declaration and specialization: * template @@ -3147,9 +3147,10 @@ clang_Cursor_getTemplateArgumentKind(CXCursor C, unsigned I); * Retrieve a CXType representing the type of a TemplateArgument of a * function decl representing a template specialization. * - * If the argument CXCursor does not represent a FunctionDecl, StructDecl, - * ClassDecl or ClassTemplatePartialSpecialization whose I'th template argument - * has a kind of CXTemplateArgKind_Integral, an invalid type is returned. + * If the argument CXCursor does not represent a FunctionDecl, CXXMethod, + * StructDecl, ClassDecl or ClassTemplatePartialSpecialization whose I'th + * template argument has a kind of CXTemplateArgKind_Integral, an invalid type + * is returned. * * For example, for the following declaration and specialization: * template diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c index 9d66a22f3b43b55..b41aaf00c68ee09 100644 --- a/clang/tools/c-index-test/c-index-test.c +++ b/clang/tools/c-index-test/c-index-test.c @@ -1039,10 +1039,11 @@ static void PrintCursor(CXCursor Cursor, const char *CommentSchemaFile) { clang_getCString(Name), line, column); clang_disposeString(Name); - if (Cursor.kind == CXCursor_FunctionDecl - || Cursor.kind == CXCursor_StructDecl - || Cursor.kind == CXCursor_ClassDecl - || Cursor.kind == CXCursor_ClassTemplatePartialSpecialization) { + if (Cursor.kind == CXCursor_FunctionDecl || + Cursor.kind == CXCursor_CXXMethod || + Cursor.kind == CXCursor_StructDecl || + Cursor.kind == CXCursor_ClassDecl || + Cursor.kind == CXCursor_ClassTemplatePartialSpecialization) { /* Collect the template parameter kinds from the base template. */ int NumTemplateArgs = clang_Cursor_getNumTemplateArguments(Cursor); int I; diff --git a/clang/tools/libclang/CXCursor.cpp b/clang/tools/libclang/CXCursor.cpp index fd03c48ba1a42aa..190e0063b78d740 100644 --- a/clang/tools/libclang/CXCursor.cpp +++ b/clang/tools/libclang/CXCursor.cpp @@ -1364,8 +1364,8 @@ CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i) { int clang_Cursor_getNumTemplateArguments(CXCursor C) { CXCursorKind kind = clang_getCursorKind(C); - if (kind != CXCursor_FunctionDecl && kind != CXCursor_StructDecl && - kind != CXCursor_ClassDecl && + if (kind != CXCursor_FunctionDecl && kind != CXCursor_CXXMethod && + kind != CXCursor_StructDecl && kind != CXCursor_ClassDecl && kind != CXCursor_ClassTemplatePartialSpecialization) { return -1; } @@ -1411,8 +1411,8 @@ enum CXGetTemplateArgumentStatus { static int clang_Cursor_getTemplateArgument(CXCursor C, unsigned I, TemplateArgument *TA) { CXCursorKind kind = clang_getCursorKind(C); - if (kind != CXCursor_FunctionDecl && kind != CXCursor_StructDecl && - kind != CXCursor_ClassDecl && + if (kind != CXCursor_FunctionDecl && kind != CXCursor_CXXMethod && + kind != CXCursor_StructDecl && kind != CXCursor_ClassDecl && kind != CXCursor_ClassTemplatePartialSpecialization) { return -1; } >From 6e43193805840c8a1732d2a7ee325c29568bb1f3 Mon Sep 17 00:00:00 2001 From: Daan Vanoverloop Date: Sat, 7 Oct 2023 10:43:48 +0200 Subject: [PATCH 2/2] [libclang] Visit function template instantiations --- clang/test/Index/index-templates.cpp | 17 +++-- clang/test/Index/print-display-names.cpp | 3 +++ clang/tools/libclang/CIndex.cpp | 9 - 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/clang/test/Index/index-templates.cpp
[clang] [libclang] Visit function template instantiations (PR #67928)
https://github.com/Danacus updated https://github.com/llvm/llvm-project/pull/67928 >From fb6ede7cc1156f18eb397b7a19a2ebfddde22285 Mon Sep 17 00:00:00 2001 From: Daan Vanoverloop Date: Sun, 1 Oct 2023 18:48:26 +0200 Subject: [PATCH 1/2] [libclang] Add support for template arguments of CXXMethod cursors --- clang/include/clang-c/Index.h | 13 +++-- clang/tools/c-index-test/c-index-test.c | 1 + clang/tools/libclang/CXCursor.cpp | 8 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index 1b91feabd584c50..eeb23ce41ef373c 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -3126,9 +3126,9 @@ CINDEX_LINKAGE int clang_Cursor_getNumTemplateArguments(CXCursor C); /** * Retrieve the kind of the I'th template argument of the CXCursor C. * - * If the argument CXCursor does not represent a FunctionDecl, StructDecl, or - * ClassTemplatePartialSpecialization, an invalid template argument kind is - * returned. + * If the argument CXCursor does not represent a FunctionDecl, CXXMethod, + * StructDecl, or ClassTemplatePartialSpecialization, an invalid template + * argument kind is returned. * * For example, for the following declaration and specialization: * template @@ -3147,9 +3147,10 @@ clang_Cursor_getTemplateArgumentKind(CXCursor C, unsigned I); * Retrieve a CXType representing the type of a TemplateArgument of a * function decl representing a template specialization. * - * If the argument CXCursor does not represent a FunctionDecl, StructDecl, - * ClassDecl or ClassTemplatePartialSpecialization whose I'th template argument - * has a kind of CXTemplateArgKind_Integral, an invalid type is returned. + * If the argument CXCursor does not represent a FunctionDecl, CXXMethod, + * StructDecl, ClassDecl or ClassTemplatePartialSpecialization whose I'th + * template argument has a kind of CXTemplateArgKind_Integral, an invalid type + * is returned. * * For example, for the following declaration and specialization: * template diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c index 9d66a22f3b43b55..238c9951269d159 100644 --- a/clang/tools/c-index-test/c-index-test.c +++ b/clang/tools/c-index-test/c-index-test.c @@ -1040,6 +1040,7 @@ static void PrintCursor(CXCursor Cursor, const char *CommentSchemaFile) { clang_disposeString(Name); if (Cursor.kind == CXCursor_FunctionDecl + || Cursor.kind == CXCursor_CXXMethod || Cursor.kind == CXCursor_StructDecl || Cursor.kind == CXCursor_ClassDecl || Cursor.kind == CXCursor_ClassTemplatePartialSpecialization) { diff --git a/clang/tools/libclang/CXCursor.cpp b/clang/tools/libclang/CXCursor.cpp index fd03c48ba1a42aa..190e0063b78d740 100644 --- a/clang/tools/libclang/CXCursor.cpp +++ b/clang/tools/libclang/CXCursor.cpp @@ -1364,8 +1364,8 @@ CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i) { int clang_Cursor_getNumTemplateArguments(CXCursor C) { CXCursorKind kind = clang_getCursorKind(C); - if (kind != CXCursor_FunctionDecl && kind != CXCursor_StructDecl && - kind != CXCursor_ClassDecl && + if (kind != CXCursor_FunctionDecl && kind != CXCursor_CXXMethod && + kind != CXCursor_StructDecl && kind != CXCursor_ClassDecl && kind != CXCursor_ClassTemplatePartialSpecialization) { return -1; } @@ -1411,8 +1411,8 @@ enum CXGetTemplateArgumentStatus { static int clang_Cursor_getTemplateArgument(CXCursor C, unsigned I, TemplateArgument *TA) { CXCursorKind kind = clang_getCursorKind(C); - if (kind != CXCursor_FunctionDecl && kind != CXCursor_StructDecl && - kind != CXCursor_ClassDecl && + if (kind != CXCursor_FunctionDecl && kind != CXCursor_CXXMethod && + kind != CXCursor_StructDecl && kind != CXCursor_ClassDecl && kind != CXCursor_ClassTemplatePartialSpecialization) { return -1; } >From d57843bd42336364c94cabe1c184c46edc5066c6 Mon Sep 17 00:00:00 2001 From: Daan Vanoverloop Date: Sun, 1 Oct 2023 18:48:32 +0200 Subject: [PATCH 2/2] [libclang] Visit function template instantiations --- clang/test/Index/index-templates.cpp | 17 +++-- clang/test/Index/print-display-names.cpp | 3 +++ clang/tools/c-index-test/c-index-test.c | 20 ++-- clang/tools/libclang/CIndex.cpp | 9 - 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/clang/test/Index/index-templates.cpp b/clang/test/Index/index-templates.cpp index 430a156b189d9e3..4994ddcde8d9ebc 100644 --- a/clang/test/Index/index-templates.cpp +++ b/clang/test/Index/index-templates.cpp @@ -54,7 +54,7 @@ void template_exprs() { f(value()); Z4().getAs(); } - +extern template float Z4::getAs(); template void swap(T&, T&); template void swap(Y&, Y&); void swap(Z4&, Z4&); @@ -110,6 +110,8 @@
[clang] [libclang] Visit function template instantiations (PR #67928)
https://github.com/Danacus updated https://github.com/llvm/llvm-project/pull/67928 >From a516d2c53451db78147a631b5c092dbfeba73e89 Mon Sep 17 00:00:00 2001 From: Daan Vanoverloop Date: Sun, 1 Oct 2023 18:48:26 +0200 Subject: [PATCH 1/6] [libclang] Add support for template arguments of CXXMethod cursors --- clang/include/clang-c/Index.h | 13 +++-- clang/tools/c-index-test/c-index-test.c | 1 + clang/tools/libclang/CXCursor.cpp | 8 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index 1b91feabd584c50..eeb23ce41ef373c 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -3126,9 +3126,9 @@ CINDEX_LINKAGE int clang_Cursor_getNumTemplateArguments(CXCursor C); /** * Retrieve the kind of the I'th template argument of the CXCursor C. * - * If the argument CXCursor does not represent a FunctionDecl, StructDecl, or - * ClassTemplatePartialSpecialization, an invalid template argument kind is - * returned. + * If the argument CXCursor does not represent a FunctionDecl, CXXMethod, + * StructDecl, or ClassTemplatePartialSpecialization, an invalid template + * argument kind is returned. * * For example, for the following declaration and specialization: * template @@ -3147,9 +3147,10 @@ clang_Cursor_getTemplateArgumentKind(CXCursor C, unsigned I); * Retrieve a CXType representing the type of a TemplateArgument of a * function decl representing a template specialization. * - * If the argument CXCursor does not represent a FunctionDecl, StructDecl, - * ClassDecl or ClassTemplatePartialSpecialization whose I'th template argument - * has a kind of CXTemplateArgKind_Integral, an invalid type is returned. + * If the argument CXCursor does not represent a FunctionDecl, CXXMethod, + * StructDecl, ClassDecl or ClassTemplatePartialSpecialization whose I'th + * template argument has a kind of CXTemplateArgKind_Integral, an invalid type + * is returned. * * For example, for the following declaration and specialization: * template diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c index 9d66a22f3b43b55..238c9951269d159 100644 --- a/clang/tools/c-index-test/c-index-test.c +++ b/clang/tools/c-index-test/c-index-test.c @@ -1040,6 +1040,7 @@ static void PrintCursor(CXCursor Cursor, const char *CommentSchemaFile) { clang_disposeString(Name); if (Cursor.kind == CXCursor_FunctionDecl + || Cursor.kind == CXCursor_CXXMethod || Cursor.kind == CXCursor_StructDecl || Cursor.kind == CXCursor_ClassDecl || Cursor.kind == CXCursor_ClassTemplatePartialSpecialization) { diff --git a/clang/tools/libclang/CXCursor.cpp b/clang/tools/libclang/CXCursor.cpp index fd03c48ba1a42aa..190e0063b78d740 100644 --- a/clang/tools/libclang/CXCursor.cpp +++ b/clang/tools/libclang/CXCursor.cpp @@ -1364,8 +1364,8 @@ CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i) { int clang_Cursor_getNumTemplateArguments(CXCursor C) { CXCursorKind kind = clang_getCursorKind(C); - if (kind != CXCursor_FunctionDecl && kind != CXCursor_StructDecl && - kind != CXCursor_ClassDecl && + if (kind != CXCursor_FunctionDecl && kind != CXCursor_CXXMethod && + kind != CXCursor_StructDecl && kind != CXCursor_ClassDecl && kind != CXCursor_ClassTemplatePartialSpecialization) { return -1; } @@ -1411,8 +1411,8 @@ enum CXGetTemplateArgumentStatus { static int clang_Cursor_getTemplateArgument(CXCursor C, unsigned I, TemplateArgument *TA) { CXCursorKind kind = clang_getCursorKind(C); - if (kind != CXCursor_FunctionDecl && kind != CXCursor_StructDecl && - kind != CXCursor_ClassDecl && + if (kind != CXCursor_FunctionDecl && kind != CXCursor_CXXMethod && + kind != CXCursor_StructDecl && kind != CXCursor_ClassDecl && kind != CXCursor_ClassTemplatePartialSpecialization) { return -1; } >From fa471bdf99b7d4e44f92c6e88af4f3d9876f6b95 Mon Sep 17 00:00:00 2001 From: Daan Vanoverloop Date: Sun, 1 Oct 2023 18:48:32 +0200 Subject: [PATCH 2/6] [libclang] Visit function template instantiations --- clang/test/Index/index-templates.cpp | 17 +++-- clang/test/Index/print-display-names.cpp | 3 +++ clang/tools/libclang/CIndex.cpp | 9 - 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/clang/test/Index/index-templates.cpp b/clang/test/Index/index-templates.cpp index 430a156b189d9e3..4994ddcde8d9ebc 100644 --- a/clang/test/Index/index-templates.cpp +++ b/clang/test/Index/index-templates.cpp @@ -54,7 +54,7 @@ void template_exprs() { f(value()); Z4().getAs(); } - +extern template float Z4::getAs(); template void swap(T&, T&); template void swap(Y&, Y&); void swap(Z4&, Z4&); @@ -110,6 +110,8 @@ static const int FxnTmpl_Var = 7; template <> void foo(float Value);
[clang] [libclang] Visit function template instantiations (PR #67928)
https://github.com/Danacus updated https://github.com/llvm/llvm-project/pull/67928 >From a516d2c53451db78147a631b5c092dbfeba73e89 Mon Sep 17 00:00:00 2001 From: Daan Vanoverloop Date: Sun, 1 Oct 2023 18:48:26 +0200 Subject: [PATCH 1/4] [libclang] Add support for template arguments of CXXMethod cursors --- clang/include/clang-c/Index.h | 13 +++-- clang/tools/c-index-test/c-index-test.c | 1 + clang/tools/libclang/CXCursor.cpp | 8 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index 1b91feabd584c50..eeb23ce41ef373c 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -3126,9 +3126,9 @@ CINDEX_LINKAGE int clang_Cursor_getNumTemplateArguments(CXCursor C); /** * Retrieve the kind of the I'th template argument of the CXCursor C. * - * If the argument CXCursor does not represent a FunctionDecl, StructDecl, or - * ClassTemplatePartialSpecialization, an invalid template argument kind is - * returned. + * If the argument CXCursor does not represent a FunctionDecl, CXXMethod, + * StructDecl, or ClassTemplatePartialSpecialization, an invalid template + * argument kind is returned. * * For example, for the following declaration and specialization: * template @@ -3147,9 +3147,10 @@ clang_Cursor_getTemplateArgumentKind(CXCursor C, unsigned I); * Retrieve a CXType representing the type of a TemplateArgument of a * function decl representing a template specialization. * - * If the argument CXCursor does not represent a FunctionDecl, StructDecl, - * ClassDecl or ClassTemplatePartialSpecialization whose I'th template argument - * has a kind of CXTemplateArgKind_Integral, an invalid type is returned. + * If the argument CXCursor does not represent a FunctionDecl, CXXMethod, + * StructDecl, ClassDecl or ClassTemplatePartialSpecialization whose I'th + * template argument has a kind of CXTemplateArgKind_Integral, an invalid type + * is returned. * * For example, for the following declaration and specialization: * template diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c index 9d66a22f3b43b55..238c9951269d159 100644 --- a/clang/tools/c-index-test/c-index-test.c +++ b/clang/tools/c-index-test/c-index-test.c @@ -1040,6 +1040,7 @@ static void PrintCursor(CXCursor Cursor, const char *CommentSchemaFile) { clang_disposeString(Name); if (Cursor.kind == CXCursor_FunctionDecl + || Cursor.kind == CXCursor_CXXMethod || Cursor.kind == CXCursor_StructDecl || Cursor.kind == CXCursor_ClassDecl || Cursor.kind == CXCursor_ClassTemplatePartialSpecialization) { diff --git a/clang/tools/libclang/CXCursor.cpp b/clang/tools/libclang/CXCursor.cpp index fd03c48ba1a42aa..190e0063b78d740 100644 --- a/clang/tools/libclang/CXCursor.cpp +++ b/clang/tools/libclang/CXCursor.cpp @@ -1364,8 +1364,8 @@ CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i) { int clang_Cursor_getNumTemplateArguments(CXCursor C) { CXCursorKind kind = clang_getCursorKind(C); - if (kind != CXCursor_FunctionDecl && kind != CXCursor_StructDecl && - kind != CXCursor_ClassDecl && + if (kind != CXCursor_FunctionDecl && kind != CXCursor_CXXMethod && + kind != CXCursor_StructDecl && kind != CXCursor_ClassDecl && kind != CXCursor_ClassTemplatePartialSpecialization) { return -1; } @@ -1411,8 +1411,8 @@ enum CXGetTemplateArgumentStatus { static int clang_Cursor_getTemplateArgument(CXCursor C, unsigned I, TemplateArgument *TA) { CXCursorKind kind = clang_getCursorKind(C); - if (kind != CXCursor_FunctionDecl && kind != CXCursor_StructDecl && - kind != CXCursor_ClassDecl && + if (kind != CXCursor_FunctionDecl && kind != CXCursor_CXXMethod && + kind != CXCursor_StructDecl && kind != CXCursor_ClassDecl && kind != CXCursor_ClassTemplatePartialSpecialization) { return -1; } >From fa471bdf99b7d4e44f92c6e88af4f3d9876f6b95 Mon Sep 17 00:00:00 2001 From: Daan Vanoverloop Date: Sun, 1 Oct 2023 18:48:32 +0200 Subject: [PATCH 2/4] [libclang] Visit function template instantiations --- clang/test/Index/index-templates.cpp | 17 +++-- clang/test/Index/print-display-names.cpp | 3 +++ clang/tools/libclang/CIndex.cpp | 9 - 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/clang/test/Index/index-templates.cpp b/clang/test/Index/index-templates.cpp index 430a156b189d9e3..4994ddcde8d9ebc 100644 --- a/clang/test/Index/index-templates.cpp +++ b/clang/test/Index/index-templates.cpp @@ -54,7 +54,7 @@ void template_exprs() { f(value()); Z4().getAs(); } - +extern template float Z4::getAs(); template void swap(T&, T&); template void swap(Y&, Y&); void swap(Z4&, Z4&); @@ -110,6 +110,8 @@ static const int FxnTmpl_Var = 7; template <> void foo(float Value);
[clang] [libclang] Visit function template instantiations (PR #67928)
https://github.com/Danacus updated https://github.com/llvm/llvm-project/pull/67928 >From a516d2c53451db78147a631b5c092dbfeba73e89 Mon Sep 17 00:00:00 2001 From: Daan Vanoverloop Date: Sun, 1 Oct 2023 18:48:26 +0200 Subject: [PATCH 1/3] [libclang] Add support for template arguments of CXXMethod cursors --- clang/include/clang-c/Index.h | 13 +++-- clang/tools/c-index-test/c-index-test.c | 1 + clang/tools/libclang/CXCursor.cpp | 8 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index 1b91feabd584c50..eeb23ce41ef373c 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -3126,9 +3126,9 @@ CINDEX_LINKAGE int clang_Cursor_getNumTemplateArguments(CXCursor C); /** * Retrieve the kind of the I'th template argument of the CXCursor C. * - * If the argument CXCursor does not represent a FunctionDecl, StructDecl, or - * ClassTemplatePartialSpecialization, an invalid template argument kind is - * returned. + * If the argument CXCursor does not represent a FunctionDecl, CXXMethod, + * StructDecl, or ClassTemplatePartialSpecialization, an invalid template + * argument kind is returned. * * For example, for the following declaration and specialization: * template @@ -3147,9 +3147,10 @@ clang_Cursor_getTemplateArgumentKind(CXCursor C, unsigned I); * Retrieve a CXType representing the type of a TemplateArgument of a * function decl representing a template specialization. * - * If the argument CXCursor does not represent a FunctionDecl, StructDecl, - * ClassDecl or ClassTemplatePartialSpecialization whose I'th template argument - * has a kind of CXTemplateArgKind_Integral, an invalid type is returned. + * If the argument CXCursor does not represent a FunctionDecl, CXXMethod, + * StructDecl, ClassDecl or ClassTemplatePartialSpecialization whose I'th + * template argument has a kind of CXTemplateArgKind_Integral, an invalid type + * is returned. * * For example, for the following declaration and specialization: * template diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c index 9d66a22f3b43b55..238c9951269d159 100644 --- a/clang/tools/c-index-test/c-index-test.c +++ b/clang/tools/c-index-test/c-index-test.c @@ -1040,6 +1040,7 @@ static void PrintCursor(CXCursor Cursor, const char *CommentSchemaFile) { clang_disposeString(Name); if (Cursor.kind == CXCursor_FunctionDecl + || Cursor.kind == CXCursor_CXXMethod || Cursor.kind == CXCursor_StructDecl || Cursor.kind == CXCursor_ClassDecl || Cursor.kind == CXCursor_ClassTemplatePartialSpecialization) { diff --git a/clang/tools/libclang/CXCursor.cpp b/clang/tools/libclang/CXCursor.cpp index fd03c48ba1a42aa..190e0063b78d740 100644 --- a/clang/tools/libclang/CXCursor.cpp +++ b/clang/tools/libclang/CXCursor.cpp @@ -1364,8 +1364,8 @@ CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i) { int clang_Cursor_getNumTemplateArguments(CXCursor C) { CXCursorKind kind = clang_getCursorKind(C); - if (kind != CXCursor_FunctionDecl && kind != CXCursor_StructDecl && - kind != CXCursor_ClassDecl && + if (kind != CXCursor_FunctionDecl && kind != CXCursor_CXXMethod && + kind != CXCursor_StructDecl && kind != CXCursor_ClassDecl && kind != CXCursor_ClassTemplatePartialSpecialization) { return -1; } @@ -1411,8 +1411,8 @@ enum CXGetTemplateArgumentStatus { static int clang_Cursor_getTemplateArgument(CXCursor C, unsigned I, TemplateArgument *TA) { CXCursorKind kind = clang_getCursorKind(C); - if (kind != CXCursor_FunctionDecl && kind != CXCursor_StructDecl && - kind != CXCursor_ClassDecl && + if (kind != CXCursor_FunctionDecl && kind != CXCursor_CXXMethod && + kind != CXCursor_StructDecl && kind != CXCursor_ClassDecl && kind != CXCursor_ClassTemplatePartialSpecialization) { return -1; } >From fa471bdf99b7d4e44f92c6e88af4f3d9876f6b95 Mon Sep 17 00:00:00 2001 From: Daan Vanoverloop Date: Sun, 1 Oct 2023 18:48:32 +0200 Subject: [PATCH 2/3] [libclang] Visit function template instantiations --- clang/test/Index/index-templates.cpp | 17 +++-- clang/test/Index/print-display-names.cpp | 3 +++ clang/tools/libclang/CIndex.cpp | 9 - 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/clang/test/Index/index-templates.cpp b/clang/test/Index/index-templates.cpp index 430a156b189d9e3..4994ddcde8d9ebc 100644 --- a/clang/test/Index/index-templates.cpp +++ b/clang/test/Index/index-templates.cpp @@ -54,7 +54,7 @@ void template_exprs() { f(value()); Z4().getAs(); } - +extern template float Z4::getAs(); template void swap(T&, T&); template void swap(Y&, Y&); void swap(Z4&, Z4&); @@ -110,6 +110,8 @@ static const int FxnTmpl_Var = 7; template <> void foo(float Value);
[clang] [libclang] Visit function template instantiations (PR #67928)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 632022e61c54428068576685b4743f105f2e fa471bdf99b7d4e44f92c6e88af4f3d9876f6b95 -- clang/include/clang-c/Index.h clang/test/Index/index-templates.cpp clang/test/Index/print-display-names.cpp clang/tools/c-index-test/c-index-test.c clang/tools/libclang/CIndex.cpp clang/tools/libclang/CXCursor.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c index 238c99512..b41aaf00c 100644 --- a/clang/tools/c-index-test/c-index-test.c +++ b/clang/tools/c-index-test/c-index-test.c @@ -1039,11 +1039,11 @@ static void PrintCursor(CXCursor Cursor, const char *CommentSchemaFile) { clang_getCString(Name), line, column); clang_disposeString(Name); - if (Cursor.kind == CXCursor_FunctionDecl - || Cursor.kind == CXCursor_CXXMethod - || Cursor.kind == CXCursor_StructDecl - || Cursor.kind == CXCursor_ClassDecl - || Cursor.kind == CXCursor_ClassTemplatePartialSpecialization) { + if (Cursor.kind == CXCursor_FunctionDecl || + Cursor.kind == CXCursor_CXXMethod || + Cursor.kind == CXCursor_StructDecl || + Cursor.kind == CXCursor_ClassDecl || + Cursor.kind == CXCursor_ClassTemplatePartialSpecialization) { /* Collect the template parameter kinds from the base template. */ int NumTemplateArgs = clang_Cursor_getNumTemplateArguments(Cursor); int I; diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index aeb685694..7cb85ee61 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -967,8 +967,8 @@ bool CursorVisitor::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { for (auto *Child : D->specializations()) if (Visit(MakeCXCursor(Child, TU))) - return true; - + return true; + return false; } `` https://github.com/llvm/llvm-project/pull/67928 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libclang] Visit function template instantiations (PR #67928)
https://github.com/Danacus created https://github.com/llvm/llvm-project/pull/67928 This PR changes `CursorVisitor::VisitFunctionTemplateDecl` such that instantiations of the function template (e.g. `template void foo();`) are visited as children of the `FunctionTemplateDecl`. This also applies to class methods. The use case for this I have in mind would be to add limited support for function templates in `rust-bindgen` (see https://github.com/rust-lang/rust-bindgen/pull/2650). Additionally, I have taken the liberty to add `CXCursor_CXXMethod` to the list of cursors supported by `getTemplateArgument`, since I found it a bit odd that this was not the case before. Please let me know if there is anything that needs to be changed, I'm happy to make changes if necessary. >From a516d2c53451db78147a631b5c092dbfeba73e89 Mon Sep 17 00:00:00 2001 From: Daan Vanoverloop Date: Sun, 1 Oct 2023 18:48:26 +0200 Subject: [PATCH 1/2] [libclang] Add support for template arguments of CXXMethod cursors --- clang/include/clang-c/Index.h | 13 +++-- clang/tools/c-index-test/c-index-test.c | 1 + clang/tools/libclang/CXCursor.cpp | 8 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index 1b91feabd584c50..eeb23ce41ef373c 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -3126,9 +3126,9 @@ CINDEX_LINKAGE int clang_Cursor_getNumTemplateArguments(CXCursor C); /** * Retrieve the kind of the I'th template argument of the CXCursor C. * - * If the argument CXCursor does not represent a FunctionDecl, StructDecl, or - * ClassTemplatePartialSpecialization, an invalid template argument kind is - * returned. + * If the argument CXCursor does not represent a FunctionDecl, CXXMethod, + * StructDecl, or ClassTemplatePartialSpecialization, an invalid template + * argument kind is returned. * * For example, for the following declaration and specialization: * template @@ -3147,9 +3147,10 @@ clang_Cursor_getTemplateArgumentKind(CXCursor C, unsigned I); * Retrieve a CXType representing the type of a TemplateArgument of a * function decl representing a template specialization. * - * If the argument CXCursor does not represent a FunctionDecl, StructDecl, - * ClassDecl or ClassTemplatePartialSpecialization whose I'th template argument - * has a kind of CXTemplateArgKind_Integral, an invalid type is returned. + * If the argument CXCursor does not represent a FunctionDecl, CXXMethod, + * StructDecl, ClassDecl or ClassTemplatePartialSpecialization whose I'th + * template argument has a kind of CXTemplateArgKind_Integral, an invalid type + * is returned. * * For example, for the following declaration and specialization: * template diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c index 9d66a22f3b43b55..238c9951269d159 100644 --- a/clang/tools/c-index-test/c-index-test.c +++ b/clang/tools/c-index-test/c-index-test.c @@ -1040,6 +1040,7 @@ static void PrintCursor(CXCursor Cursor, const char *CommentSchemaFile) { clang_disposeString(Name); if (Cursor.kind == CXCursor_FunctionDecl + || Cursor.kind == CXCursor_CXXMethod || Cursor.kind == CXCursor_StructDecl || Cursor.kind == CXCursor_ClassDecl || Cursor.kind == CXCursor_ClassTemplatePartialSpecialization) { diff --git a/clang/tools/libclang/CXCursor.cpp b/clang/tools/libclang/CXCursor.cpp index fd03c48ba1a42aa..190e0063b78d740 100644 --- a/clang/tools/libclang/CXCursor.cpp +++ b/clang/tools/libclang/CXCursor.cpp @@ -1364,8 +1364,8 @@ CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i) { int clang_Cursor_getNumTemplateArguments(CXCursor C) { CXCursorKind kind = clang_getCursorKind(C); - if (kind != CXCursor_FunctionDecl && kind != CXCursor_StructDecl && - kind != CXCursor_ClassDecl && + if (kind != CXCursor_FunctionDecl && kind != CXCursor_CXXMethod && + kind != CXCursor_StructDecl && kind != CXCursor_ClassDecl && kind != CXCursor_ClassTemplatePartialSpecialization) { return -1; } @@ -1411,8 +1411,8 @@ enum CXGetTemplateArgumentStatus { static int clang_Cursor_getTemplateArgument(CXCursor C, unsigned I, TemplateArgument *TA) { CXCursorKind kind = clang_getCursorKind(C); - if (kind != CXCursor_FunctionDecl && kind != CXCursor_StructDecl && - kind != CXCursor_ClassDecl && + if (kind != CXCursor_FunctionDecl && kind != CXCursor_CXXMethod && + kind != CXCursor_StructDecl && kind != CXCursor_ClassDecl && kind != CXCursor_ClassTemplatePartialSpecialization) { return -1; } >From fa471bdf99b7d4e44f92c6e88af4f3d9876f6b95 Mon Sep 17 00:00:00 2001 From: Daan Vanoverloop Date: Sun, 1 Oct 2023 18:48:32 +0200 Subject: [PATCH 2/2] [libclang] Visit function template instantiations ---