summaryrefslogtreecommitdiff
path: root/src/span.cpp
blob: 5216976db6a9ea4290c3b34adf64578e0942dfb2 (plain)
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
/*
 * 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>

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.c_str()),
    start_line(pos.line),
    start_ofs(pos.ofs),
    end_line(pos.line),
    end_ofs(pos.ofs)
{
}

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:";
    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:";
    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();
}