nixd
Toggle main menu visibility
Loading...
Searching...
No Matches
libnixf
src
Basic
Diagnostic.cpp
Go to the documentation of this file.
1
#include "
nixf/Basic/Diagnostic.h
"
2
3
#include <sstream>
4
5
using namespace
nixf
;
6
7
namespace
{
8
9
std::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
27
const
char
*
nixf::Note::sname
(
NoteKind
Kind) {
28
switch
(Kind) {
29
#define DIAG_NOTE(SNAME, CNAME, MESSAGE) \
30
case NK_##CNAME: \
31
return SNAME;
32
#include "
nixf/Basic/NoteKinds.inc
"
33
#undef DIAG_NOTE
34
}
35
assert(
false
&&
"Invalid diagnostic kind"
);
36
__builtin_unreachable();
37
}
38
39
const
char
*
nixf::Note::message
(
NoteKind
Kind) {
40
switch
(Kind) {
41
#define DIAG_NOTE(SNAME, CNAME, MESSAGE) \
42
case NK_##CNAME: \
43
return MESSAGE;
44
#include "
nixf/Basic/NoteKinds.inc
"
45
#undef DIAG_NOTE
46
}
47
assert(
false
&&
"Invalid diagnostic kind"
);
48
__builtin_unreachable();
49
}
50
51
std::string
PartialDiagnostic::format
()
const
{
52
return
simpleFormat(
message
(), Args);
53
}
Diagnostic.h
NoteKinds.inc
nixf::Note::message
const char * message() const override
Definition
Diagnostic.h:139
nixf::Note::sname
virtual const char * sname() const
Definition
Diagnostic.h:133
nixf::Note::NoteKind
NoteKind
Internal kind.
Definition
Diagnostic.h:117
nixf::PartialDiagnostic::message
virtual const char * message() const =0
nixf::PartialDiagnostic::format
std::string format() const
Definition
Diagnostic.cpp:51
nixf
Definition
Diagnostic.h:19
Generated by
1.17.0