forked from sahilpparmar/emmCompiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Error.C
66 lines (54 loc) · 1.39 KB
/
Error.C
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
#include "Error.h"
#include "ParserUtil.h"
using namespace std;
static int errorCount = 0;
static int warningCount = 0;
static void msg(const string& type, const string& errorMsg, int line, int col, const char* file) {
if (line == 0) {
line = yylinenum;
file = yyfilename;
}
cerr << file << ':' << line;
if (col != 0)
cerr << '.' << col;
cerr << ':';
cerr << type << errorMsg << endl;
}
void
internalError(const string& s, int line, const char* file) {
msg("Internal error: ", s, line, 0, file);
}
void errMsg(const string& errorMsg, int line, int col, const char* file) {
msg("Error: ", errorMsg, line, col, file);
errorCount++;
if (errorCount > MAX_ERROR_BEFORE_QUIT) {
cerr << "Too many errors. Exiting ... " << endl;
exit(-1);
}
}
void errMsg(const string& msg, const ProgramElem* p) {
if (p == NULL)
errMsg(msg);
else errMsg(msg, p->line(), p->column(), p->file().c_str());
}
void warnMsg(const string& warningMsg, int line, int col, const char* file) {
msg("Warning: ", warningMsg, line, col, file);
warningCount++;
}
void warnMsg(const string& msg , const ProgramElem* p) {
if (p == NULL)
warnMsg(msg);
else warnMsg(msg, p->line(), p->column(), p->file().c_str());
}
void resetErrs() {
warningCount = errorCount = 0;
}
void resetWarns() {
warningCount = 0;
}
int warnCount() {
return warningCount;
}
int errCount() {
return errorCount;
}