From d088b44db648bc3317d2647226485d26e42a0faf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Tue, 10 Oct 2017 17:16:10 +0200 Subject: [PATCH] Add line numbers to diagnostics --- src/libclang/parse_error.hpp | 8 +++++++- src/libclang/preprocessor.cpp | 9 ++++++--- src/libclang/type_parser.cpp | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/libclang/parse_error.hpp b/src/libclang/parse_error.hpp index da34438..bb40f2d 100644 --- a/src/libclang/parse_error.hpp +++ b/src/libclang/parse_error.hpp @@ -19,7 +19,13 @@ namespace cppast { inline source_location make_location(const CXCursor& cur) { - return source_location::make_entity(get_display_name(cur).c_str()); + auto loc = clang_getCursorLocation(cur); + + CXString file; + unsigned line; + clang_getPresumedLocation(loc, &file, &line, nullptr); + + return source_location::make_file(cxstring(file).c_str(), line); } inline source_location make_location(const CXType& type) diff --git a/src/libclang/preprocessor.cpp b/src/libclang/preprocessor.cpp index 3de001c..aa75277 100644 --- a/src/libclang/preprocessor.cpp +++ b/src/libclang/preprocessor.cpp @@ -701,7 +701,8 @@ detail::preprocessor_output detail::preprocess(const libclang_compile_config& co { auto message = detail::format("parsing macro '", macro->name(), "'"); logger.log("preprocessor", - diagnostic{std::move(message), source_location::make_file(path), + diagnostic{std::move(message), + source_location::make_file(path, p.cur_line()), severity::debug}); } @@ -715,7 +716,8 @@ detail::preprocessor_output detail::preprocess(const libclang_compile_config& co { auto message = detail::format("undefining macro '", undef.value(), "'"); logger.log("preprocessor", - diagnostic{std::move(message), source_location::make_file(path), + diagnostic{std::move(message), + source_location::make_file(path, p.cur_line()), severity::debug}); } result.macros.erase(std::remove_if(result.macros.begin(), result.macros.end(), @@ -732,7 +734,8 @@ detail::preprocessor_output detail::preprocess(const libclang_compile_config& co auto message = detail::format("parsing include '", include.value().file.name(), "'"); logger.log("preprocessor", - diagnostic{std::move(message), source_location::make_file(path), + diagnostic{std::move(message), + source_location::make_file(path, p.cur_line()), severity::debug}); } result.includes.push_back(std::move(include.value())); diff --git a/src/libclang/type_parser.cpp b/src/libclang/type_parser.cpp index 827d8ed..a96332d 100644 --- a/src/libclang/type_parser.cpp +++ b/src/libclang/type_parser.cpp @@ -553,7 +553,7 @@ namespace { auto msg = detail::format("unexpected type of kind '", detail::get_type_kind_spelling(type).c_str(), "'"); - auto location = source_location::make_entity(get_type_spelling(type).c_str()); + auto location = detail::make_location(type); context.logger->log("libclang parser", diagnostic{msg, location, severity::warning}); } // fallthrough