-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIgnorableCalls.cpp
84 lines (77 loc) · 2.37 KB
/
IgnorableCalls.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
// SPDX-License-Identifier: GPL-3.0-only
/**
* @file IgnorableCalls.cpp
*
* @copyright Copyright (C) 2021-2024 srcML, LLC. (www.srcML.org)
*
* This file is part of the Stereocode application.
*/
#include "IgnorableCalls.hpp"
extern std::vector<std::string> LANGUAGE;
// Checks if 'call' is ignored
// User-defined calls are checked for all languages
//
bool ignorableCalls::isIgnored(const std::string& call, const std::string& unitLanguage) {
return (ignoredCalls.at(unitLanguage).find(call) != ignoredCalls.at(unitLanguage).end()) ||
(userIgnoredCalls.find(call) != userIgnoredCalls.end());
}
// Reads a set of user-defined calls to ignore
// File should list each one type per line
//
std::istream& operator>>(std::istream& in, ignorableCalls& calls) {
std::string name;
while(std::getline(in, name))
calls.addCall(name);
return in;
}
// Adds "ignoredCall" to user-defined calls to ignore if not already present
//
void ignorableCalls::addCall(const std::string& ignoredCall) {
userIgnoredCalls.insert(ignoredCall);
}
void ignorableCalls::outputCalls() {
std::cerr<<"---Ignored Calls---";
for (const auto& pair : ignoredCalls) {
std::cerr<<"\n[" << pair.first << "]:" ;
for (const std::string& call : pair.second)
std::cerr << ' ' << call;
}
if (userIgnoredCalls.size() > 0) {
std::cerr<<"\n[User-Defined]:";
for (const std::string& call : userIgnoredCalls)
std::cerr << ' ' << call;
}
std::cerr << "\n\n";
}
// Specific calls to ignore are used based on unit language
//
void ignorableCalls::createCallList() {
for (const auto& l : LANGUAGE) {
// cout, cin, streams, casts are all ignored (not collected) for C++ since they are not considered as <call>
if (l == "C++") {
ignoredCalls.insert({l, {
"assert",
"exit",
"abort"
}});
}
else if (l == "C#") {
ignoredCalls.insert({l, {
"WriteLine",
"Write",
"Trace",
"Assert",
"Exit"
}});
}
else if (l == "Java") {
ignoredCalls.insert({l, {
"println",
"print",
"printf",
"assert",
"exit"
}});
}
}
}