-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrorHandler.cpp
More file actions
53 lines (47 loc) · 1.5 KB
/
errorHandler.cpp
File metadata and controls
53 lines (47 loc) · 1.5 KB
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
#include "errorHandler.h"
errorHandler::errorHandler(bool mode,string targetfile)
{
this->mode = mode;
this->targetfile = targetfile;
if (mode) {
initNaiveMap();
}
}
void errorHandler::newError(int row, int col, type T)
{
if (mode) {
errorsList.push_back(make_tuple(row, col, naiveHandler[T]));
}
}
bool errorHandler::cmp(tuple<int, int, string> a, tuple<int, int, string> b)
{
return (get<0>(a)<get<0>(b))||(get<0>(a) == get<0>(b)&&get<1>(a) < get<1>(b));
}
void errorHandler::output()
{
sort(errorsList.begin(), errorsList.end(), cmp);
if (mode) {
for (int i = 0; i < errorsList.size(); i++) {
outputList.push_back(to_string(get<0>(errorsList[i])) + " " + get<2>(errorsList[i]));
}
}
outputHandler output = outputHandler(outputList, targetfile);
}
void errorHandler::initNaiveMap()
{
naiveHandler[illegalSymbolOrLexicalInconformity] = "a";
naiveHandler[nameRedefinition] = "b";
naiveHandler[undefinedName] = "c";
naiveHandler[numberOfArgumentsNotMatch] = "d";
naiveHandler[typeOfArgumentsNotMatch] = "e";
naiveHandler[illegalTypesInCondition] = "f";
naiveHandler[functionWithoutReturnValueMismatch] = "g";
naiveHandler[functionWithReturnValueMismatchOrLose] = "h";
naiveHandler[indexOfArrayCanOnlyBeIntegerExpresion] = "i";
naiveHandler[cannotChangeValueOfConstant] = "j";
naiveHandler[shouldBeSemicolon] = "k";
naiveHandler[shouldBeRparent] = "l";
naiveHandler[shouldBeRbrack] = "m";
naiveHandler[loseWhileIn_DoWhile] = "n";
naiveHandler[constantCanOnlyBeFollowedByIntegerOrCharacter] = "o";
}