From 21750a1ae8c86ffefc72f115116c80a98a0792dc Mon Sep 17 00:00:00 2001 From: Daniel Grumberg Date: Wed, 22 Mar 2023 18:50:59 +0000 Subject: [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 --- clang/tools/c-index-test/c-index-test.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'clang/tools/c-index-test/c-index-test.c') diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c index 448435e..f116111 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 \n"); fprintf(stderr, " c-index-test -single-symbol-sgfs {*}\n" + " c-index-test -single-symbol-sgf-at= {*}\n" " c-index-test -single-symbol-sgf-for= {}*\n"); fprintf(stderr, " c-index-test -write-pch \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); -- cgit v1.1