-
Notifications
You must be signed in to change notification settings - Fork 2
/
FaultHandler.cpp
55 lines (46 loc) · 1.23 KB
/
FaultHandler.cpp
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
#include"FaultHandler.h"
FaultHandler::FaultHandler(string filename) {
debug = false;
if (filename == "") {
filename = "/dev/null";
}
fout.open(filename, ios_base::out | ios_base::trunc);
messages[LEXICALERROR] = "lexical error";
messages[REDEFINED] = "redefined symbol";
messages[UNDEFINED] = "undifined symbol";
messages[PARANUMERROR] = "number of parameters does not match";
messages[PARATYPEERROR] = "type does not match";
messages[NOSEMICN] = " ; required";
messages[NORPARENT] = ") required";
messages[NORBRACK] = "] required";
}
FaultHandler::~FaultHandler() {
fout.close();
}
void FaultHandler::handleCourseFault(int line, FaultType type) {
fout << line << " "<<(char)type<<endl;
hasBug = true;
//handleFault(line, messages[type]);
}
void FaultHandler::handleFault(int line, string information) {
hasBug = true;
if (debug) {
cout << "Error @ line " << line << ": " << information << endl;
}
}
void FaultHandler::debugOn() {
debug = true;
}
void FaultHandler::terminate() {
cout << endl << "Compilation Terminated"<<endl;
system("pause");
exit(0);
}
void FaultHandler::test() {
/*debugOn();
handleCourseFault(15, LEXICALERROR);
handleCourseFault(107,NORPARENT);*/
}
bool FaultHandler::haveBug() {
return hasBug;
}