-
Notifications
You must be signed in to change notification settings - Fork 1
/
error.h
57 lines (50 loc) · 1.16 KB
/
error.h
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
#ifndef ERROR_H
#define ERROR_H
#include <vector>
#include <string>
#include <sstream>
/*
* Classes used when dealing with list of errors that
* can occur during check phase.
* */
namespace latte_type_check
{
class Error;
class Errors;
class Error
{
public:
Error(const int _line_no, const std::string &_fn, const char* _msg): line_no(_line_no), fn(_fn), msg(_msg) {}
Error(const int _line_no, const std::string &_fn, const char* _msg, const char* id): line_no(_line_no), fn(_fn), msg(_msg) {
msg.append(": `");
msg.append(id);
msg.append("'");
}
std::string toString() const {
std::ostringstream ss;
if(line_no > 0){
ss << "line " << line_no << ": in " << fn << "(): " << msg << "\n";
}else{
ss << fn << ": " << msg << "\n";
}
return ss.str();
}
private:
int line_no;
std::string fn;
std::string msg;
friend class Errors;
};
class Errors : public std::vector<Error>
{
public:
std::string toString() const{
std::ostringstream ss;
for(auto error : *this){
ss << error.toString();
}
return ss.str();
}
};
};
#endif