Add diagnostic_logger
This commit is contained in:
parent
a0c2eece5b
commit
108fd1b2ee
8 changed files with 165 additions and 15 deletions
|
|
@ -11,6 +11,39 @@
|
|||
namespace cppast
|
||||
{
|
||||
class cpp_entity_index;
|
||||
class diagnostic;
|
||||
|
||||
/// Base class for a [cppast::diagnostic]() logger.
|
||||
///
|
||||
/// Its task is controlling how diagnostic are being displayed.
|
||||
class diagnostic_logger
|
||||
{
|
||||
public:
|
||||
diagnostic_logger() noexcept = default;
|
||||
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
|
||||
{
|
||||
return do_log(source, d);
|
||||
}
|
||||
|
||||
private:
|
||||
virtual bool do_log(const char* source, const diagnostic& d) const = 0;
|
||||
};
|
||||
|
||||
/// 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
|
||||
{
|
||||
private:
|
||||
bool do_log(const char* source, const diagnostic& d) const override;
|
||||
};
|
||||
|
||||
/// Base class for a parser.
|
||||
///
|
||||
|
|
@ -33,13 +66,24 @@ namespace cppast
|
|||
}
|
||||
|
||||
protected:
|
||||
parser() = default;
|
||||
/// \effects Creates it giving it a reference to the logger it uses.
|
||||
explicit parser(type_safe::object_ref<const diagnostic_logger> logger) : logger_(logger)
|
||||
{
|
||||
}
|
||||
|
||||
/// \returns A reference to the logger used.
|
||||
const diagnostic_logger& logger() const noexcept
|
||||
{
|
||||
return *logger_;
|
||||
}
|
||||
|
||||
private:
|
||||
/// \effects Parses the given file.
|
||||
/// \returns The [cppast::cpp_file]() object describing it.
|
||||
virtual std::unique_ptr<cpp_file> do_parse(const cpp_entity_index& idx, std::string path,
|
||||
const compile_config& config) const = 0;
|
||||
|
||||
type_safe::object_ref<const diagnostic_logger> logger_;
|
||||
};
|
||||
} // namespace cppast
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue