forked from viva64/plog-converter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwarning.cpp
248 lines (209 loc) · 4.82 KB
/
warning.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
// 2006-2008 (c) Viva64.com Team
// 2008-2020 (c) OOO "Program Verification Systems"
#include "warning.h"
namespace PlogConverter
{
AnalyzerType Warning::GetType() const
{
const auto errorCode = GetErrorCode();
if ((errorCode >= 100 && errorCode <= 499) || errorCode == 4)
{
return AnalyzerType::Viva64;
}
else if (errorCode >= 1 && errorCode <= 99)
{
return AnalyzerType::Fail;
}
else if (errorCode >= 500 && errorCode <= 799)
{
return AnalyzerType::General;
}
else if (errorCode >= 800 && errorCode <= 999)
{
return AnalyzerType::Optimization;
}
else if (errorCode >= 1000 && errorCode <= 1999)
{
return AnalyzerType::General;
}
else if (errorCode >= 2000 && errorCode <= 2499)
{
return AnalyzerType::CustomerSpecific;
}
else if (errorCode >= 2500 && errorCode <= 2999)
{
return AnalyzerType::Misra;
}
else if (errorCode >= 3000 && errorCode <= 3999)
{
return AnalyzerType::General; // C#
}
else if (errorCode >= 6000 && errorCode <= 6999)
{
return AnalyzerType::General; // Java
}
else if (IsExternalMessage())
{
return AnalyzerType::General; // External tools
}
return AnalyzerType::Unknown;
}
Warning Warning::GetDocumentationLinkMessage()
{
Warning docsMessage;
docsMessage.code = "Help:";
docsMessage.level = 1;
docsMessage.positions = { {"www.viva64.com/en/w", 1 } };
docsMessage.message = "The documentation for all analyzer warnings is available here: https://www.viva64.com/en/w/.";
return docsMessage;
}
bool Warning::IsDocumentationLinkMessage() const
{
return code == "Help:";
}
bool Warning::IsRenewMessage() const
{
return code == "Renew";
}
bool Warning::IsExternalMessage() const
{
return code == "External";
}
bool Warning::IsUpdateMessage() const
{
return code == "Update";
}
bool Warning::IsTrialMessage() const
{
return code == "Trial";
}
unsigned Warning::GetErrorCode() const
{
if ( code.empty()
|| code.front() != 'V'
|| !std::all_of(code.begin() + 1, code.end(), [](char c) { return isdigit(c); }))
{
return 0;
}
return static_cast<unsigned>(atoi(code.c_str() + 1));
}
std::string Warning::GetVivaUrl() const
{
if (IsRenewMessage())
{
return "https://www.viva64.com/en/renewal/";
}
if (IsExternalMessage())
{
return "https://www.viva64.com/en/w/";
}
if (IsUpdateMessage())
{
return "https://www.viva64.com/en/pvs-studio-download/";
}
if (IsTrialMessage())
{
return "https://www.viva64.com/en/pvs-studio-download/#trial_form";
}
const auto errorCode = GetErrorCode();
if (errorCode != 0)
{
return "https://www.viva64.com/en/w/v" + LeftPad(std::to_string(errorCode), 3, '0') + '/';
}
return {};
}
std::string Warning::GetCWEUrl() const
{
if (!HasCWE())
{
return {};
}
return "https://cwe.mitre.org/data/definitions/" + std::to_string(cwe) + ".html";
}
std::string Warning::GetCWEString() const
{
return cwe == 0 ? "" : CWEPrefix + std::to_string(cwe);
}
std::string Warning::GetMISRAString() const
{
return std::string(Warning::MISRACorePrefix) + misra;
}
std::string Warning::GetMISRAStringWithLanguagePrefix() const
{
if (misra.find('-') != std::string::npos)
return MISRAPrefixCPlusPlus + misra;
else if (misra.find('.') != std::string::npos)
return MISRAPrefixC + misra;
else
return "";
}
bool Warning::HasCWE() const
{
return cwe != 0;
}
bool Warning::HasMISRA() const
{
return !misra.empty();
}
bool Warning::HasProjects() const
{
return !projects.empty();
}
std::string Warning::GetLevelString() const
{
return GetLevelString("error", "warning", "note");
}
std::string Warning::GetLevelString(const std::string &l01, const std::string &l2, const std::string &l3) const
{
return GetLevelString(l01, l01, l2, l3);
}
std::string Warning::GetLevelString(const std::string &l0, const std::string &l1, const std::string &l2, const std::string &l3) const
{
switch (level)
{
case 3: return l3;
case 2: return l2;
case 1: return l1;
default: return l0;
}
}
void Warning::Clear()
{
//TODO:
*this = {};
}
std::vector<unsigned> Warning::GetExtendedLines() const
{
if (!additionalLines.empty())
{
return additionalLines;
}
std::vector<unsigned> res;
if (positions.size() <= 1)
{
return res;
}
for (const auto &pos : positions)
{
if (pos.file == positions.front().file)
{
res.push_back(pos.line);
}
}
return res;
}
const NavigationInfo &Warning::GetNavigationInfo() const
{
static const NavigationInfo empty;
return positions.empty() ? empty : positions.front().navigation;
}
const std::string &Warning::GetFile() const
{
static const std::string empty;
return positions.empty() ? empty : positions.front().file;
}
unsigned Warning::GetLine() const
{
return positions.empty() ? 0 : positions.front().line;
}
}