1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
/*
* MRustC - Rust Compiler
* - By John Hodge (Mutabah/thePowersGang)
*
* span.cpp
* - Spans and error handling
*/
#include <functional>
#include <iostream>
#include <span.hpp>
#include <parse/lex.hpp>
#include <common.hpp>
Span::Span(const Span& x):
filename(x.filename),
start_line(x.start_line),
start_ofs(x.start_ofs),
end_line(x.end_line),
end_ofs(x.end_ofs)
{
}
Span::Span(const Position& pos):
filename(pos.filename),
start_line(pos.line),
start_ofs(pos.ofs),
end_line(pos.line),
end_ofs(pos.ofs)
{
}
Span::Span():
filename("")/*,
start_line(0), start_ofs(0),
end_line(0), end_ofs(0) // */
{
DEBUG("Empty span");
//filename = FMT(":" << __builtin_return_address(0));
}
void Span::bug(::std::function<void(::std::ostream&)> msg) const
{
::std::cerr << this->filename << ":" << this->start_line << ": BUG:";
msg(::std::cerr);
::std::cerr << ::std::endl;
abort();
}
void Span::error(ErrorType tag, ::std::function<void(::std::ostream&)> msg) const {
::std::cerr << this->filename << ":" << this->start_line << ": error:" << tag <<":";
msg(::std::cerr);
::std::cerr << ::std::endl;
abort();
}
void Span::warning(WarningType tag, ::std::function<void(::std::ostream&)> msg) const {
::std::cerr << this->filename << ":" << this->start_line << ": warning:" << tag << ":";
msg(::std::cerr);
::std::cerr << ::std::endl;
//abort();
}
void Span::note(::std::function<void(::std::ostream&)> msg) const {
::std::cerr << this->filename << ":" << this->start_line << ": note:";
msg(::std::cerr);
::std::cerr << ::std::endl;
//abort();
}
::std::ostream& operator<<(::std::ostream& os, const Span& sp)
{
os << sp.filename << ":" << sp.start_line;
return os;
}
|