FE 0.5.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 template<class... Args> static void note(Loc loc, format::format_string<Args...> fmt, Args&&... args) {
20 std::cerr << loc << ": note: " << format::format(fmt, std::forward<Args&&>(args)...) << std::endl;
21 }
22 template<class... Args> void warn(Loc loc, format::format_string<Args...> fmt, Args&&... args) {
23 ++num_warnings_;
24 std::cerr << loc << ": warning: " << format::format(fmt, std::forward<Args&&>(args)...) << std::endl;
25 }
26 template<class... Args> void err(Loc loc, format::format_string<Args...> fmt, Args&&... args) {
27 ++num_errors_;
28 std::cerr << loc << ": error: " << format::format(fmt, std::forward<Args&&>(args)...) << std::endl;
29 }
30
31 unsigned num_errors() const { return num_errors_; }
32 unsigned num_warnings() const { return num_warnings_; }
33 ///@}
34
35private:
36 unsigned num_errors_ = 0;
37 unsigned num_warnings_ = 0;
38};
39
40} // namespace fe
Hash set where all strings - wrapped in Symbol - live in.
Definition sym.h:192
Definition arena.h:9
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:32
void err(Loc loc, format::format_string< Args... > fmt, Args &&... args)
Definition driver.h:26
unsigned num_errors() const
Definition driver.h:31
void warn(Loc loc, format::format_string< Args... > fmt, Args &&... args)
Definition driver.h:22
static void note(Loc loc, format::format_string< Args... > fmt, Args &&... args)
Definition driver.h:19
Location in a File.
Definition loc.h:33