FE 0.6.0
A header-only C++ library for writing frontends
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
10namespace fe {
11
12/// Use/derive from this class for "global" variables that you need all over the place.
13/// Well, there are not really global - that's the point of this class.
14/// Right now, it manages a SymPool (by inherting from it) and offers `std::format`-based diagnostics.
15struct Driver : public SymPool {
16public:
17 /// @name Diagnostics
18 ///@{
19 // clang-format off
20 template<class... Args> static void note(Loc loc, format::format_string<Args...> fmt, Args&&... args) { std::cerr << loc << ": note: " << format::format(fmt, std::forward<Args>(args)...) << std::endl; }
21 template<class... Args> void warn(Loc loc, format::format_string<Args...> fmt, Args&&... args) { ++num_warnings_; std::cerr << loc << ": warning: " << format::format(fmt, std::forward<Args>(args)...) << std::endl; }
22 template<class... Args> void err (Loc loc, format::format_string<Args...> fmt, Args&&... args) { ++num_errors_; std::cerr << loc << ": error: " << format::format(fmt, std::forward<Args>(args)...) << std::endl; }
23 // clang-format on
24
25 unsigned num_errors() const { return num_errors_; }
26 unsigned num_warnings() const { return num_warnings_; }
27 ///@}
28
29private:
30 unsigned num_errors_ = 0;
31 unsigned num_warnings_ = 0;
32};
33
34} // namespace fe
Hash set where all strings - wrapped in Symbol - live in.
Definition sym.h:249
Definition arena.h:10
Use/derive from this class for "global" variables that you need all over the place.
Definition driver.h:15
unsigned num_warnings() const
Definition driver.h:26
void err(Loc loc, format::format_string< Args... > fmt, Args &&... args)
Definition driver.h:22
unsigned num_errors() const
Definition driver.h:25
void warn(Loc loc, format::format_string< Args... > fmt, Args &&... args)
Definition driver.h:21
static void note(Loc loc, format::format_string< Args... > fmt, Args &&... args)
Definition driver.h:20
Location in a File.
Definition loc.h:33