-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathError.cpp
180 lines (154 loc) · 5.2 KB
/
Error.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include <iostream>
#include "Error.h"
#include "GramTreeNode.h"
using namespace std;
int errorNum;
bool hasError()
{
return errorNum > 0;
}
void syntaxError(string currentParserFilename, string expected, Scanner::Token token)
{
errorNum++;
cerr << "Error in file " << currentParserFilename << " in line " << token.row
<< ": expect " << "\'" << expected << "\'" << ", but got " << "\'" << token.lexeme << "\'" << "\n";
}
// 类名和函数名不一致
void error1(string currentParserFilename)
{
errorNum++;
cerr << "Error in file " << currentParserFilename << ".jack: " << "classname should be same as filename" << endl;
}
// 变量重定义
void error2(string currentClass, int row, string type, string name)
{
errorNum++;
cerr << "Error in file " << currentClass << " in line " << row
<< ": redeclaration of '" << type << " " << name << "'" << endl;
}
// 函数重定义
void error3(string currentClass, int row, string type, string name)
{
errorNum++;
cerr << "Error in file " << currentClass << " in line " << row
<< ": redeclaration of '" << type << " " << name << "()" << endl;
}
// 类型未定义
void error4(string currentClassName, int row, string type)
{
errorNum++;
cerr << "Error in file " << currentClassName << " in line " << row
<< ": '" << type << "' not declaraed" << endl;
}
// 变量未定义
void error5(string currentClassName, int row, string varName)
{
errorNum++;
cerr << "Error in file " << currentClassName << " in line " << row
<< ": '" << varName << "' does not declared in this scope" << endl;
}
void error6(string currentClassName, int row, string type)
{
errorNum++;
cerr << "Error in file " << currentClassName << " in line " << row
<< ": " << type << " does not an Array type" << endl;
}
void error7(string currentClassName, string callerName, int row, string functionName)
{
errorNum++;
cerr << "Error in file " << currentClassName << " in line " << row
<< ": class " << callerName << " haven't a member function '" << functionName << "()'" << endl;
}
void error8(string currentClassName, int row, string functionName)
{
errorNum++;
cerr << "Error in file " << currentClassName << " in line " << row
<< ": subroutine " << functionName << " called as a method from within a function" << endl;
}
void error9(string currentClassName, string callerName, int row, string functionName)
{
errorNum++;
cerr << "Error in file " << currentClassName << " in line " << row
<< ": '" << functionName << "' is not a function in class " << callerName << endl;
}
// 函数类型错误
void error10(string currentClassName, string callerName, int row, string functionName)
{
errorNum++;
cerr << "Error in file " << currentClassName << " in line " << row
<< ": '" << functionName << "' is not a method in class " << callerName << endl;
}
// 返回值错误
void error11(string currentClassName, string type, int row)
{
errorNum++;
cerr << "Error in file " << currentClassName << " in line " << row
<< ": return-statement with no value, in function returning '" << type << "'" << endl;
}
// 返回值错误
void error12(string currentClassName, int row)
{
errorNum++;
cerr << "Error in file " << currentClassName << " in line " << row
<< ": return-statement with a value, in function returning void" << endl;
}
// 返回值错误
void error13(string currentClassName, int row)
{
errorNum++;
cerr << "Error in file " << currentClassName << " in line " << row
<< ": The return type of a constructor must be of the class type" << endl;
}
// 参数太少
void error14(string currentClassName, string functionName, int row)
{
errorNum++;
cerr << "Error in file " << currentClassName << " in line " << row
<< ": too few arguments to function " << functionName << "()" << endl;
}
// 参数太多
void error15(string currentClassName, string functionName, int row)
{
errorNum++;
cerr << "Error in file " << currentClassName << " in line " << row
<< ": too many arguments to function " << functionName << endl;
}
void error16()
{
errorNum++;
cerr << "Error: Main class not exsist" << endl;
}
void error17()
{
errorNum++;
cerr << "Error in file Main: main function does not exsit!" << endl;
}
void error18()
{
errorNum++;
cerr << "Error in file Main: the kind of subroutine main must be a function" << endl;
}
void error19()
{
errorNum++;
cerr << "Error in file Main: the type of subroutine main must be a void" << endl;
}
void error20()
{
errorNum++;
cerr << "Error in file Main: the argument size of subroutine main must be null" << endl;
}
void error21(string currentClassName, string callerName, int row, string functionName)
{
errorNum++;
cerr << "Error in file " << currentClassName << " in line " << row
<<", function(or method) "<< "\'" << functionName << "\' " << "is not defined" << endl;
}
// void error22(SyntaxTreeNodeBase* node, string msg)
// {
// errorNum++;
// cerr << "Error in file " << node->getClassName() << " in line " << node->getRow()
// << ", in function(or method) " << "\'"
// << node->getCurSubroutineBodyNode()->getParentNode()->getName()
// << "\', " << "节点 " << node->getLexeme() << "," << msg << endl;
// }