diff --git a/src/libclang/debug_helper.cpp b/src/libclang/debug_helper.cpp index 5b56e56..4b38029 100644 --- a/src/libclang/debug_helper.cpp +++ b/src/libclang/debug_helper.cpp @@ -16,6 +16,11 @@ detail::cxstring detail::get_display_name(const CXCursor& cur) noexcept return cxstring(clang_getCursorDisplayName(cur)); } +detail::cxstring detail::get_cursor_kind_spelling(const CXCursor& cur) noexcept +{ + return cxstring(clang_getCursorKindSpelling(clang_getCursorKind(cur))); +} + namespace { std::mutex mtx; diff --git a/src/libclang/debug_helper.hpp b/src/libclang/debug_helper.hpp index 8c1d99d..36479aa 100644 --- a/src/libclang/debug_helper.hpp +++ b/src/libclang/debug_helper.hpp @@ -13,6 +13,8 @@ namespace cppast { cxstring get_display_name(const CXCursor& cur) noexcept; + cxstring get_cursor_kind_spelling(const CXCursor& cur) noexcept; + void print_cursor_info(const CXCursor& cur) noexcept; void print_tokens(const cxtranslation_unit& tu, const CXFile& file, diff --git a/src/libclang/parse_error.hpp b/src/libclang/parse_error.hpp index 6dddc33..483ceec 100644 --- a/src/libclang/parse_error.hpp +++ b/src/libclang/parse_error.hpp @@ -17,6 +17,11 @@ namespace cppast { namespace detail { + inline source_location make_location(const CXCursor& cur) + { + return source_location::make(get_display_name(cur).c_str()); + } + // thrown on a parsing error // not meant to escape to the user class parse_error : public std::logic_error @@ -28,7 +33,7 @@ namespace cppast } parse_error(const CXCursor& cur, std::string message) - : parse_error(source_location::make(get_display_name(cur).c_str()), std::move(message)) + : parse_error(make_location(cur), std::move(message)) { } diff --git a/src/libclang/parse_functions.cpp b/src/libclang/parse_functions.cpp index 99eb48f..1a1a3c1 100644 --- a/src/libclang/parse_functions.cpp +++ b/src/libclang/parse_functions.cpp @@ -38,6 +38,10 @@ std::unique_ptr detail::parse_entity(const detail::parse_context& co break; } + auto msg = format("unhandled cursor of kind '", get_cursor_kind_spelling(cur).c_str(), "'"); + context.logger->log("libclang parser", + diagnostic{std::move(msg), make_location(cur), severity::warning}); + return nullptr; } catch (parse_error& ex)