Add default_logger() and default_verbose_logger()
This commit is contained in:
parent
44708fff76
commit
6b7ca183f9
3 changed files with 24 additions and 3 deletions
|
|
@ -21,7 +21,8 @@ namespace cppast
|
|||
class diagnostic_logger
|
||||
{
|
||||
public:
|
||||
diagnostic_logger() noexcept : verbose_(false)
|
||||
/// \effects Creates it either as verbose or not.
|
||||
explicit diagnostic_logger(bool is_verbose = false) noexcept : verbose_(is_verbose)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -52,11 +53,20 @@ namespace cppast
|
|||
bool verbose_;
|
||||
};
|
||||
|
||||
/// \returns The default logger object.
|
||||
type_safe::object_ref<const diagnostic_logger> default_logger() noexcept;
|
||||
|
||||
/// \returns The default verbose logger object.
|
||||
type_safe::object_ref<const diagnostic_logger> default_verbose_logger() noexcept;
|
||||
|
||||
/// A [cppast::diagnostic_logger]() that logs to `stderr`.
|
||||
///
|
||||
/// It prints all diagnostics in an implementation-defined format.
|
||||
class stderr_diagnostic_logger final : public diagnostic_logger
|
||||
{
|
||||
public:
|
||||
using diagnostic_logger::diagnostic_logger;
|
||||
|
||||
private:
|
||||
bool do_log(const char* source, const diagnostic& d) const override;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -18,6 +18,18 @@ bool diagnostic_logger::log(const char* source, const diagnostic& d) const
|
|||
return do_log(source, d);
|
||||
}
|
||||
|
||||
type_safe::object_ref<const diagnostic_logger> cppast::default_logger() noexcept
|
||||
{
|
||||
static const stderr_diagnostic_logger logger(false);
|
||||
return type_safe::ref(logger);
|
||||
}
|
||||
|
||||
type_safe::object_ref<const diagnostic_logger> cppast::default_verbose_logger() noexcept
|
||||
{
|
||||
static const stderr_diagnostic_logger logger(true);
|
||||
return type_safe::ref(logger);
|
||||
}
|
||||
|
||||
bool stderr_diagnostic_logger::do_log(const char* source, const diagnostic& d) const
|
||||
{
|
||||
auto loc = d.location.to_string();
|
||||
|
|
|
|||
|
|
@ -31,8 +31,7 @@ inline std::unique_ptr<cppast::cpp_file> parse_file(const cppast::cpp_entity_ind
|
|||
libclang_compile_config config;
|
||||
config.set_flags(cpp_standard::cpp_latest);
|
||||
|
||||
stderr_diagnostic_logger logger;
|
||||
libclang_parser p(type_safe::ref(logger));
|
||||
libclang_parser p(default_logger());
|
||||
|
||||
std::unique_ptr<cppast::cpp_file> result;
|
||||
REQUIRE_NOTHROW(result = p.parse(idx, name, config));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue