diff --git a/include/cppast/diagnostic.hpp b/include/cppast/diagnostic.hpp index 6ac0f72..a811610 100644 --- a/include/cppast/diagnostic.hpp +++ b/include/cppast/diagnostic.hpp @@ -66,6 +66,7 @@ namespace cppast /// The severity of a [cppast::diagnostic](). enum class severity { + debug, //< A debug diagnostic that is just for debugging purposes. warning, //< A warning that doesn't impact AST generation. error, //< A non-critical error that does impact AST generation but not critically. critical, //< A critical error where AST generation isn't possible. @@ -77,6 +78,8 @@ namespace cppast { switch (s) { + case severity::debug: + return "debug"; case severity::warning: return "warning"; case severity::error: diff --git a/include/cppast/parser.hpp b/include/cppast/parser.hpp index d5fb8ea..708cc99 100644 --- a/include/cppast/parser.hpp +++ b/include/cppast/parser.hpp @@ -43,10 +43,23 @@ namespace cppast return error_; } + /// \effects Sets whether or not the logger prints debugging diagnostics. + void set_verbose(bool value) noexcept + { + verbose_ = value; + } + + /// \returns Whether or not the logger prints debugging diagnostics. + bool is_verbose() const noexcept + { + return verbose_; + } + private: virtual bool do_log(const char* source, const diagnostic& d) const = 0; mutable std::atomic error_; + bool verbose_ = false; }; /// A [cppast::diagnostic_logger]() that logs to `stderr`. diff --git a/src/libclang/parse_functions.cpp b/src/libclang/parse_functions.cpp index 1da4d49..4d0a9e0 100644 --- a/src/libclang/parse_functions.cpp +++ b/src/libclang/parse_functions.cpp @@ -74,6 +74,15 @@ std::unique_ptr detail::parse_entity(const detail::parse_context& co const CXCursor& cur, const CXCursor& parent_cur) try { + if (context.logger->is_verbose()) + { + auto message = detail::format("parsing cursor of type '", + detail::get_cursor_kind_spelling(cur).c_str(), "'"); + context.logger->log("libclang parser", + diagnostic{std::move(message), detail::make_location(cur), + severity::debug}); + } + auto kind = clang_getCursorKind(cur); switch (kind) { diff --git a/src/parser.cpp b/src/parser.cpp index 9fe8bf0..7fa4f3c 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -15,6 +15,8 @@ bool diagnostic_logger::log(const char* source, const diagnostic& d) const { if (d.severity == severity::error) error_ = true; + else if (!verbose_ && d.severity == severity::debug) + return false; return do_log(source, d); }