nixd
Loading...
Searching...
No Matches
Diagnostic.cpp
Go to the documentation of this file.
2
3#include <sstream>
4
5using namespace nixf;
6
7namespace {
8
9std::string simpleFormat(const char *Fmt,
10 const std::vector<std::string> &Args) {
11 std::stringstream SS;
12 std::size_t ArgIdx = 0;
13 for (const char *Cur = Fmt; *Cur;) {
14 if (*Cur == '{' && *(Cur + 1) == '}') {
15 SS << Args[ArgIdx++];
16 Cur += 2;
17 } else {
18 SS << *Cur;
19 ++Cur;
20 }
21 }
22 return SS.str();
23}
24
25} // namespace
26
27const char *nixf::Note::sname(NoteKind Kind) {
28 switch (Kind) {
29#define DIAG_NOTE(SNAME, CNAME, MESSAGE) \
30 case NK_##CNAME: \
31 return SNAME;
33#undef DIAG_NOTE
34 }
35 assert(false && "Invalid diagnostic kind");
36 __builtin_unreachable();
37}
38
39const char *nixf::Note::message(NoteKind Kind) {
40 switch (Kind) {
41#define DIAG_NOTE(SNAME, CNAME, MESSAGE) \
42 case NK_##CNAME: \
43 return MESSAGE;
45#undef DIAG_NOTE
46 }
47 assert(false && "Invalid diagnostic kind");
48 __builtin_unreachable();
49}
50
51std::string PartialDiagnostic::format() const {
52 return simpleFormat(message(), Args);
53}
const char * message() const override
Definition Diagnostic.h:139
virtual const char * sname() const
Definition Diagnostic.h:133
NoteKind
Internal kind.
Definition Diagnostic.h:117
virtual const char * message() const =0
std::string format() const