-
Notifications
You must be signed in to change notification settings - Fork 1
/
ConsoleOutputHandler.cpp
373 lines (314 loc) · 20.1 KB
/
ConsoleOutputHandler.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
#include "header/OutputHandler.h"
#include <string>
#include <vector>
#include "header/FunctionAnalyser.h"
#include <llvm/Support/CommandLine.h>
#include "header/HelperFunctions.h"
using namespace std;
class ConsoleOutputHandler : public OutputHandler {
public:
std::string output;
std::string completeOutput;
std::string startingMessage;
int foundChanges = 0;
int foundIndividualChanges = 0;
ConsoleOutputHandler()= default;
void initialiseFunctionInstance(const functionanalysis::FunctionInstance &func) override {
this->startingMessage = "===================================== (Function) =====================================\n";
this->startingMessage += "Qualified (old) function name: " + func.qualifiedName + "\n";
this->startingMessage += "Full old params: " + helper::getAllParamsAsString(func.params) + "\n";
this->startingMessage += "Filename: " + func.filename + "\n";
if(func.isTemplateDecl){
this->startingMessage += "Is a template\n";
}
if(func.isDeclaration){
this->startingMessage += "Is a declaration\n";
}
output+= "-----------------------\n";
output = startingMessage;
}
void initialiseVariableInstance(const variableanalysis::VariableInstance &var) override {
this->startingMessage = "===================================== (Variable) =====================================\n";
this->startingMessage += "Qualified (old) variable name: " + var.qualifiedName + "\n";
this->startingMessage += "Type: " + var.type + "\n";
this->startingMessage += "Filename: " + var.filename + "\n";
this->startingMessage += "-----------------------\n";
output = startingMessage;
}
void initialiseObjectInstance(const objectanalysis::ObjectInstance& obj) override {
this->startingMessage = "===================================== (Object) =====================================\n";
this->startingMessage += "Qualified (old) object name: " + obj.qualifiedName + "\n";
this->startingMessage += "Filename: " + obj.filename + "\n";
this->startingMessage += "-----------------------\n";
output = startingMessage;
}
void outputNewParam(int oldPosition, const functionanalysis::FunctionInstance& oldFunc, std::pair<std::string, std::pair<std::string, std::string>> newParam, const functionanalysis::FunctionInstance& newFunc) override{
if(oldPosition != 0) {
output +=
"There is a new parameter (" + newParam.first + " " + newParam.second.first + ") after the param " +
oldFunc.params.at(oldPosition).first + " " + oldFunc.params.at(oldPosition).second.first
+ ". Full params: " + helper::getAllParamsAsString(oldFunc.params) + " -> " + helper::getAllParamsAsString(newFunc.params) + "\n";
}else {
output += "There is a new parameter (" + newParam.first + " " + newParam.second.first + ")" + ". Full params: " + helper::getAllParamsAsString(oldFunc.params) + " -> " + helper::getAllParamsAsString(newFunc.params) + "\n";
}
foundIndividualChanges++;
}
void outputParamChange(int oldPosition, const functionanalysis::FunctionInstance& oldFunc, std::pair<std::string, std::pair<std::string, std::string>> newParam, const functionanalysis::FunctionInstance& newFunc) override {
output += "A parameter changed from " + oldFunc.params.at(oldPosition).first + " " + oldFunc.params.at(oldPosition).second.first + " to "
+ newParam.first + " " + newParam.second.first+ " at position " + to_string(oldPosition) + ". Full params: " + helper::getAllParamsAsString(oldFunc.params) + " -> " + helper::getAllParamsAsString(newFunc.params) + "\n";
foundIndividualChanges++;
}
void outputParamDefaultChange(int oldPosition, const functionanalysis::FunctionInstance& oldFunc, std::pair<std::string, std::pair<std::string, std::string>> newParam, const functionanalysis::FunctionInstance& newFunc) override {
string oldValue = (oldFunc.params.at(oldPosition).second.second.empty()) ? oldFunc.params.at(oldPosition).first + " " + oldFunc.params.at(oldPosition).second.first : oldFunc.params.at(oldPosition).first + " " + oldFunc.params.at(oldPosition).second.first + " = " + oldFunc.params.at(oldPosition).second.second;
string newValue = (newParam.second.second.empty()) ? newParam.first + " " + newParam.second.first : newParam.first + " " + newParam.second.first + " = " + newParam.second.second;
output += "A default value of the param " + oldValue + " changed to " + newValue + ". Full params: " + helper::getAllParamsAsString(oldFunc.params) + " -> " + helper::getAllParamsAsString(newFunc.params) + "\n";
foundIndividualChanges++;
}
void outputDeletedParam(int oldPosition, const std::vector<std::pair<std::string, std::pair<std::string, std::string>>>& oldParams, const functionanalysis::FunctionInstance& newFunc) override {
output += "The parameter " + oldParams.at(oldPosition).first + " " + oldParams.at(oldPosition).second.first + " was deleted " + ". Full params: " + helper::getAllParamsAsString(oldParams) + " -> " + helper::getAllParamsAsString(newFunc.params) + "\n";;
foundIndividualChanges++;
}
void outputNewReturn(const functionanalysis::FunctionInstance &newFunc, std::string oldReturn) override {
foundIndividualChanges++;
output += "The return type changed from " + oldReturn + " to " + newFunc.returnType + "\n";
}
void outputNewScope(const functionanalysis::FunctionInstance& newFunc, const functionanalysis::FunctionInstance& oldFunc) override {
foundIndividualChanges++;
output += "The scope changed from " + oldFunc.scope + " to " + newFunc.scope + "\n";
}
void outputNewNamespaces(const functionanalysis::FunctionInstance &newFunc, const functionanalysis::FunctionInstance& oldFunc) override {
foundIndividualChanges++;
output += "The function moved namespaces from " + helper::getAllNamespacesAsString(oldFunc.location) + " to "
+ helper::getAllNamespacesAsString(newFunc.location) + "\n";
}
void outputNewFilename(const functionanalysis::FunctionInstance &newFunc, const functionanalysis::FunctionInstance& oldFunc) override{
foundIndividualChanges++;
output += "The function definition moved files from " + oldFunc.filename + " to " + newFunc.filename + "\n";
}
void outputNewDeclPositions(const functionanalysis::FunctionInstance &newFunc, std::vector<std::string> addedDecl) override {
foundIndividualChanges++;
output += "The function has new declarations in the files " + helper::getAllNamespacesAsString(addedDecl) + "\n";
}
void outputDeletedDeclPositions(const functionanalysis::FunctionInstance &newFunc, std::vector<std::string> deletedDecl, const functionanalysis::FunctionInstance& oldFunc) override {
foundIndividualChanges++;
output += "Declarations in the files " + helper::getAllNamespacesAsString(deletedDecl) + " were deleted\n";
}
void outputDeletedFunction(const functionanalysis::FunctionInstance &deletedFunc, bool overloaded) override {
foundIndividualChanges++;
if(deletedFunc.isDeclaration){
output += "A declaration in the file " + deletedFunc.filename + " was deleted";
return;
}
if(overloaded){
output += "The overloaded function with the params " + helper::getAllParamsAsString(deletedFunc.params) + " was deleted\n";
} else {
output += "A function definition was deleted from the file " + deletedFunc.filename + "\n";
}
}
void outputOverloadedDisclaimer(const functionanalysis::FunctionInstance &func, std::string percentage) override {
output += "DISCLAIMER: There is code similarity of " + percentage
+ "% between the old overloaded function and the in the following analyzed instance of the overloaded function\n";
}
void outputRenamedFunction(const functionanalysis::FunctionInstance &newFunc, std::string oldName, std::string percentage) override {
foundIndividualChanges++;
output += "The function was renamed to \"" + newFunc.name +
"\" with a code similarity of " + percentage + "%\n";
}
void outputStorageClassChange(const functionanalysis::FunctionInstance& newFunc, const functionanalysis::FunctionInstance& oldFunc) override{
foundIndividualChanges++;
output += "The functions storage class changed from " + oldFunc.storageClass + " to " + newFunc.storageClass + "\n";
}
void outputFunctionSpecifierChange(const functionanalysis::FunctionInstance& newFunc, const functionanalysis::FunctionInstance& oldFunc) override{
foundIndividualChanges++;
output += "The function specifier changed from " + oldFunc.memberFunctionSpecifier + " to " + newFunc.memberFunctionSpecifier + "\n";
}
void outputFunctionConstChange(const functionanalysis::FunctionInstance& newFunc, const functionanalysis::FunctionInstance& oldFunc) override{
foundIndividualChanges++;
if(oldFunc.isConst){
output += "The function is not declared const anymore\n";
}else{
output += "The function is now declared const\n";
}
}
bool endOfCurrentFunction() override{
if(output != startingMessage){
output += "\n";
completeOutput += output;
foundChanges++;
return true;
}
return false;
}
// Templates
void outputTemplateIsNowFunction(const functionanalysis::FunctionInstance& oldFunc, const functionanalysis::FunctionInstance& newFunc) override {
foundIndividualChanges++;
output += "The template is now a function\n";
}
void outputFunctionIsNowTemplate(const functionanalysis::FunctionInstance& oldFunc, const functionanalysis::FunctionInstance& newFunc) override {
foundIndividualChanges++;
output += "The function is now a template\n";
}
void outputTemplateParameterAdded(int oldPosition, const functionanalysis::FunctionInstance& oldFunc, std::pair<std::string, std::pair<std::string, std::string>> newParam, const functionanalysis::FunctionInstance& newFunc) override {
foundIndividualChanges++;
output += "The template parameter " + helper::getSingleTemplateParamAsString(newParam) + " was added after the position " + std::to_string(oldPosition) + ". Full params: " + helper::getAllTemplateParamsAsString(oldFunc.templateParams) + " -> " + helper::getAllTemplateParamsAsString(newFunc.templateParams) + "\n";
}
void outputTemplateParameterDeleted(int oldPosition, const functionanalysis::FunctionInstance& oldFunc, const functionanalysis::FunctionInstance& newFunc) override {
foundIndividualChanges++;
output += "The template parameter " + helper::getSingleTemplateParamAsString(oldFunc.templateParams.at(oldPosition)) + " was deleted at position " + std::to_string(oldPosition) + ". Full params: " + helper::getAllTemplateParamsAsString(oldFunc.templateParams) + " -> " + helper::getAllTemplateParamsAsString(newFunc.templateParams) + "\n";
}
void outputTemplateParameterChanged(int oldPosition, const functionanalysis::FunctionInstance& oldFunc, std::pair<std::string, std::pair<std::string, std::string>> newParam, const functionanalysis::FunctionInstance& newFunc) override {
foundIndividualChanges++;
output += "The template parameter " + helper::getSingleTemplateParamAsString(oldFunc.templateParams.at(oldPosition)) + " was changed to " + helper::getSingleTemplateParamAsString(newParam) + " at position " + std::to_string(oldPosition) + ". Full params: " + helper::getAllTemplateParamsAsString(oldFunc.templateParams) + " -> " + helper::getAllTemplateParamsAsString(newFunc.templateParams) + "\n";
}
void outputTemplateParameterDefaultChanged(int oldPosition, const functionanalysis::FunctionInstance& oldFunc, std::pair<std::string, std::pair<std::string, std::string>> newParam, const functionanalysis::FunctionInstance& newFunc) override {
foundIndividualChanges++;
output += "The template parameters " + helper::getSingleTemplateParamAsString(oldFunc.templateParams.at(oldPosition)) + " default value was changed to " + helper::getSingleTemplateParamAsString(newParam) + " at position " + std::to_string(oldPosition) + ". Full params: " + helper::getAllTemplateParamsAsString(oldFunc.templateParams) + " -> " + helper::getAllTemplateParamsAsString(newFunc.templateParams) + "\n";
}
void outputNewSpecialization(const functionanalysis::FunctionInstance& newSpec) override {
foundIndividualChanges++;
output += "A new specialization was added with the params " + helper::getAllParamsAsString(newSpec.params) + "\n";
}
void outputDeletedSpecialization(const functionanalysis::FunctionInstance& oldSpec) override {
foundIndividualChanges++;
output += "The specialization with the params " + helper::getAllParamsAsString(oldSpec.params) + " was deleted\n";
}
// Variables
void outputVariableDeleted(const variableanalysis::VariableInstance& var) override{
foundIndividualChanges++;
output += "The variable has been deleted\n";
}
void outputVariableDefinitionDeleted(const variableanalysis::VariableInstance &var) override{
foundIndividualChanges++;
output += "The variable definition in file " + var.filename + " has been deleted\n";
}
void outputVariableDefinitionAdded(const variableanalysis::VariableInstance &var) override{
foundIndividualChanges++;
output += "The variable definition in file " + var.filename + " has been added\n";
}
void outputVariableFileChange(const variableanalysis::VariableInstance& oldVar, const variableanalysis::VariableInstance& newVar) override{
foundIndividualChanges++;
output += "The variable file changed from " + oldVar.filename + " to " + newVar.filename + "\n";
}
void outputVariableLocationChange(const variableanalysis::VariableInstance& oldVar, const variableanalysis::VariableInstance& newVar) override{
foundIndividualChanges++;
output += "The variable location has changed from " + helper::getAllNamespacesAsString(oldVar.location) + " to " + helper::getAllNamespacesAsString(newVar.location) + "\n";
}
void outputVariableTypeChange(const variableanalysis::VariableInstance& oldVar, const variableanalysis::VariableInstance& newVar) override {
foundIndividualChanges++;
output += "The variable type changed from " + oldVar.type + " to " + newVar.type + "\n";
}
void outputVariableStorageClassChange(const variableanalysis::VariableInstance& oldVar, const variableanalysis::VariableInstance& newVar) override {
foundIndividualChanges++;
output += "The variable storage class changed from " + oldVar.storageClass + " to " + newVar.storageClass + "\n";
}
void outputVariableInlineChange(const variableanalysis::VariableInstance& oldVar, const variableanalysis::VariableInstance& newVar) override {
foundIndividualChanges++;
if(oldVar.isInline){
output += "The variable is not declared inline anymore\n";
}else{
output += "The variable is now declared inline\n";
}
}
void outputVariableAccessSpecifierChange(const variableanalysis::VariableInstance& oldVar, const variableanalysis::VariableInstance& newVar) override {
foundIndividualChanges++;
output += "The variable access specifier changed from " + oldVar.accessSpecifier + " to " + newVar.accessSpecifier + "\n";
}
void outputVariableConstChange(const variableanalysis::VariableInstance& oldVar, const variableanalysis::VariableInstance& newVar) override {
foundIndividualChanges++;
if(oldVar.isConst){
output += "The variable is not declared const anymore\n";
}else{
output += "The variable is now declared const\n";
}
}
void outputVariableExplicitChange(const variableanalysis::VariableInstance& oldVar, const variableanalysis::VariableInstance& newVar) override {
foundIndividualChanges++;
if(oldVar.isExplicit){
output += "The variable is not declared explicit anymore\n";
}else{
output += "The variable is now declared explicit\n";
}
}
void outputVariableVolatileChange(const variableanalysis::VariableInstance& oldVar, const variableanalysis::VariableInstance& newVar) override {
foundIndividualChanges++;
if(oldVar.isVolatile){
output += "The variable is not declared volatile anymore\n";
}else{
output += "The variable is now declared volatile\n";
}
}
void outputVariableMutableChange(const variableanalysis::VariableInstance& oldVar, const variableanalysis::VariableInstance& newVar) override {
foundIndividualChanges++;
if(oldVar.isMutable){
output += "The variable is not declared mutable anymore\n";
}else{
output += "The variable is now declared mutable\n";
}
}
void outputVariableClassMember(const variableanalysis::VariableInstance& oldVar, const variableanalysis::VariableInstance& newVar) override {
foundIndividualChanges++;
if(oldVar.isClassMember){
output += "The variable is not part of a class anymore, its original location was:" + helper::getAllNamespacesAsString(oldVar.location) + "\n";
}else{
output += "The variable is now part of a class, its new location is:" + helper::getAllNamespacesAsString(newVar.location) + "\n";
}
}
bool endOfCurrentVariable() override {
if(output != startingMessage){
output += "\n";
completeOutput += output;
foundChanges++;
return true;
}
return false;
}
void outputObjectDeleted(const objectanalysis::ObjectInstance& obj) override {
foundIndividualChanges++;
output += "The object has been deleted\n";
}
void outputObjectFilenameChange(const objectanalysis::ObjectInstance& oldObj, const objectanalysis::ObjectInstance& newObj) override {
foundIndividualChanges++;
output += "The object filename changed from " + oldObj.filename + " to " + newObj.filename + "\n";
}
void outputObjectLocationChange(const objectanalysis::ObjectInstance& oldObj, const objectanalysis::ObjectInstance& newObj) override {
foundIndividualChanges++;
output += "The object location has changed from " + helper::getAllNamespacesAsString(oldObj.location) + " to " + helper::getAllNamespacesAsString(newObj.location) + "\n";
}
void outputObjectFinalChange(const objectanalysis::ObjectInstance& oldObj, const objectanalysis::ObjectInstance& newObj) override {
foundIndividualChanges++;
if(oldObj.isFinal){
output += "The object is not declared final anymore\n";
}else{
output += "The object is now declared final\n";
}
}
void outputObjectAbstractChange(const objectanalysis::ObjectInstance& oldObj, const objectanalysis::ObjectInstance& newObj) override {
foundIndividualChanges++;
if(oldObj.isAbstract){
output += "The object is not declared abstract anymore\n";
}else{
output += "The object is now declared abstract\n";
}
}
void outputObjectTypeChange(const objectanalysis::ObjectInstance& oldObj, const objectanalysis::ObjectInstance& newObj) override {
foundIndividualChanges++;
// TODO: C++ Enums are stupid, maybe change to string..
output += "The object type changed\n";
}
bool endOfCurrentObject() override {
if(output != startingMessage){
output += "\n";
completeOutput += output;
foundChanges++;
return true;
}
return false;
}
bool printOut() override {
llvm::outs()<<completeOutput;
llvm::outs()<<foundChanges<<" entities have changes\n";
llvm::outs()<<"All in all " << foundIndividualChanges << " individual changes were found\n";
return true;
}
virtual ~ConsoleOutputHandler()= default;
};