FE 0.9.2
Header-only C++ frontend library
Loading...
Searching...
No Matches
driver.h
Go to the documentation of this file.
1#pragma once
2
3#include <sstream>
4#include <string_view>
5
6#include <fe/format.h>
7#include <fe/loc.h>
8#include <fe/sym.h>
9#include <fe/term.h>
10
11namespace fe {
12
13/// Use/derive from this class for "global" variables that you need all over the place.
14/// Well, there are not really global - that's the point of this class.
15/// Right now, it manages a SymPool (by inheriting from it) and offers `std::format`-based diagnostics.
16struct Driver : public SymPool {
17public:
18 /// @name Diagnostics
19 ///@{
20 // clang-format off
21 template<class... Args> static void note(Loc loc, std::format_string<Args...> fmt, Args&&... args) { std::cerr << loc << ": " << term::FG::Cyan << "note: " << term::FG::Reset << std::format(fmt, std::forward<Args>(args)...) << std::endl; }
22 template<class... Args> void warn(Loc loc, std::format_string<Args...> fmt, Args&&... args) { ++num_warnings_; std::cerr << loc << ": " << term::FG::Magenta << "warning: " << term::FG::Reset << std::format(fmt, std::forward<Args>(args)...) << std::endl; }
23 template<class... Args> void err (Loc loc, std::format_string<Args...> fmt, Args&&... args) { ++num_errors_; std::cerr << loc << ": " << term::FG::Red << "error: " << term::FG::Reset << std::format(fmt, std::forward<Args>(args)...) << std::endl; }
24 // clang-format on
25
26 unsigned num_errors() const { return num_errors_; }
27 unsigned num_warnings() const { return num_warnings_; }
28 ///@}
29
30private:
31 unsigned num_errors_ = 0;
32 unsigned num_warnings_ = 0;
33};
34
35} // namespace fe
SymPool(const SymPool &)=delete
@ Magenta
Definition term.h:54
Definition arena.h:13
Use/derive from this class for "global" variables that you need all over the place.
Definition driver.h:16
unsigned num_warnings() const
Definition driver.h:27
void warn(Loc loc, std::format_string< Args... > fmt, Args &&... args)
Definition driver.h:22
static void note(Loc loc, std::format_string< Args... > fmt, Args &&... args)
Definition driver.h:21
void err(Loc loc, std::format_string< Args... > fmt, Args &&... args)
Definition driver.h:23
unsigned num_errors() const
Definition driver.h:26
Location in a File.
Definition loc.h:35