diff --git a/include/cppast/diagnostic_logger.hpp b/include/cppast/diagnostic_logger.hpp new file mode 100644 index 0000000..7748ac0 --- /dev/null +++ b/include/cppast/diagnostic_logger.hpp @@ -0,0 +1,71 @@ +// Copyright (C) 2017 Jonathan Müller +// This file is subject to the license terms in the LICENSE file +// found in the top-level directory of this distribution. + +#ifndef CPPAST_DIAGNOSTIC_LOGGER_HPP_INCLUDED +#define CPPAST_DIAGNOSTIC_LOGGER_HPP_INCLUDED + +#include + +#include + +namespace cppast +{ + /// Base class for a [cppast::diagnostic]() logger. + /// + /// Its task is controlling how diagnostic are being displayed. + class diagnostic_logger + { + public: + /// \effects Creates it either as verbose or not. + explicit diagnostic_logger(bool is_verbose = false) noexcept : verbose_(is_verbose) + { + } + + diagnostic_logger(const diagnostic_logger&) = delete; + diagnostic_logger& operator=(const diagnostic_logger&) = delete; + virtual ~diagnostic_logger() noexcept = default; + + /// \effects Logs the diagnostic by invoking the `do_log()` member function. + /// \returns Whether or not the diagnostic was logged. + /// \notes `source` points to a string literal that gives additional context to what generates the message. + bool log(const char* source, const diagnostic& d) const; + + /// \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; + + bool verbose_; + }; + + /// \returns The default logger object. + type_safe::object_ref default_logger() noexcept; + + /// \returns The default verbose logger object. + type_safe::object_ref 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; + }; +} // namespace cppast + +#endif // CPPAST_DIAGNOSTIC_LOGGER_HPP_INCLUDED diff --git a/include/cppast/parser.hpp b/include/cppast/parser.hpp index b1723c5..84badba 100644 --- a/include/cppast/parser.hpp +++ b/include/cppast/parser.hpp @@ -10,67 +10,11 @@ #include #include #include +#include namespace cppast { class cpp_entity_index; - struct diagnostic; - - /// Base class for a [cppast::diagnostic]() logger. - /// - /// Its task is controlling how diagnostic are being displayed. - class diagnostic_logger - { - public: - /// \effects Creates it either as verbose or not. - explicit diagnostic_logger(bool is_verbose = false) noexcept : verbose_(is_verbose) - { - } - - diagnostic_logger(const diagnostic_logger&) = delete; - diagnostic_logger& operator=(const diagnostic_logger&) = delete; - virtual ~diagnostic_logger() noexcept = default; - - /// \effects Logs the diagnostic by invoking the `do_log()` member function. - /// \returns Whether or not the diagnostic was logged. - /// \notes `source` points to a string literal that gives additional context to what generates the message. - bool log(const char* source, const diagnostic& d) const; - - /// \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; - - bool verbose_; - }; - - /// \returns The default logger object. - type_safe::object_ref default_logger() noexcept; - - /// \returns The default verbose logger object. - type_safe::object_ref 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; - }; /// Base class for a parser. /// diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 72a9b83..8f2af0c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -42,6 +42,7 @@ set(header ../include/cppast/cpp_variable_base.hpp ../include/cppast/cpp_variable_template.hpp ../include/cppast/diagnostic.hpp + ../include/cppast/diagnostic_logger.hpp ../include/cppast/libclang_parser.hpp ../include/cppast/parser.hpp ../include/cppast/visitor.hpp) @@ -71,7 +72,7 @@ set(source cpp_type_alias.cpp cpp_variable.cpp cpp_variable_template.cpp - parser.cpp + diagnostic_logger.cpp visitor.cpp) set(libclang_source libclang/class_parser.cpp diff --git a/src/parser.cpp b/src/diagnostic_logger.cpp similarity index 95% rename from src/parser.cpp rename to src/diagnostic_logger.cpp index 172f628..64fd823 100644 --- a/src/parser.cpp +++ b/src/diagnostic_logger.cpp @@ -2,13 +2,11 @@ // This file is subject to the license terms in the LICENSE file // found in the top-level directory of this distribution. -#include +#include #include #include -#include - using namespace cppast; bool diagnostic_logger::log(const char* source, const diagnostic& d) const