summaryrefslogtreecommitdiff
path: root/clang/tools
diff options
context:
space:
mode:
authorDaniel Grumberg <dgrumberg@apple.com>2023-03-22 18:50:59 +0000
committerDaniel Grumberg <dgrumberg@apple.com>2023-03-27 17:24:10 +0100
commit21750a1ae8c86ffefc72f115116c80a98a0792dc (patch)
tree8d0cca588fd81dfb11b387bfb350566935a88595 /clang/tools
parentea35740e7e189cdcdd88344ac60a53a5b8a8318d (diff)
downloadllvm-21750a1ae8c86ffefc72f115116c80a98a0792dc.tar.gz
[clang][ExtractAPI] Refactor ExtractAPIVisitor to make it more extensible
Use CRTP to enable creating statically dispatched subclasses of ExtractAPIVisitor. This enables adding extension points and customising the behavior more easily. This is used in CXExtractAPI.cpp to create a specialized visitor for Libclang as well as streamlining the batch implementation in ExtractAPIConsumer.cpp [clang][ExtractAPI] Improve tests for clang_getSymbolGraphForCursor Adds a new mode to c-index-test that can fetch a single symbol symbol graph for a given source location. This way we can be more precise when writing tests for clang_getSymbolGraphForCursor. Additionaly this makes it easier to debug the function. Differential Revision: https://reviews.llvm.org/D146656
Diffstat (limited to 'clang/tools')
-rw-r--r--clang/tools/c-index-test/c-index-test.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c
index 448435e83027..f116111fface 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -3,6 +3,7 @@
#include "clang-c/BuildSystem.h"
#include "clang-c/CXCompilationDatabase.h"
#include "clang-c/CXErrorCode.h"
+#include "clang-c/CXSourceLocation.h"
#include "clang-c/CXString.h"
#include "clang-c/Documentation.h"
#include "clang-c/Index.h"
@@ -4881,6 +4882,21 @@ dispose_index:
return result;
}
+static void inspect_single_symbol_sgf_cursor(CXCursor Cursor) {
+ CXSourceLocation CursorLoc;
+ CXString SGFData;
+ const char *SGF;
+ unsigned line, column;
+ CursorLoc = clang_getCursorLocation(Cursor);
+ clang_getSpellingLocation(CursorLoc, 0, &line, &column, 0);
+ printf("%d:%d: ", line, column);
+
+ SGFData = clang_getSymbolGraphForCursor(Cursor);
+ SGF = clang_getCString(SGFData);
+ if (SGF)
+ printf("%s\n", SGF);
+}
+
/******************************************************************************/
/* Command line processing. */
/******************************************************************************/
@@ -4940,6 +4956,7 @@ static void print_usage(void) {
" c-index-test -print-usr-file <file>\n");
fprintf(stderr,
" c-index-test -single-symbol-sgfs <symbol filter> {<args>*}\n"
+ " c-index-test -single-symbol-sgf-at=<site> {<args>*}\n"
" c-index-test -single-symbol-sgf-for=<usr> {<args>}*\n");
fprintf(stderr,
" c-index-test -write-pch <file> <compiler arguments>\n"
@@ -5076,6 +5093,9 @@ int cindextest_main(int argc, const char **argv) {
else if (argc > 3 && strcmp(argv[1], "-single-symbol-sgfs") == 0)
return perform_test_load_source(argc - 3, argv + 3, argv[2],
PrintSingleSymbolSGFs, NULL);
+ else if (argc > 2 && strstr(argv[1], "-single-symbol-sgf-at=") == argv[1])
+ return inspect_cursor_at(
+ argc, argv, "-single-symbol-sgf-at=", inspect_single_symbol_sgf_cursor);
else if (argc > 2 && strstr(argv[1], "-single-symbol-sgf-for=") == argv[1])
return perform_test_single_symbol_sgf(argv[1], argc - 2, argv + 2);