20
20
21
21
#include " application.h"
22
22
#include " applicationlist.h"
23
+ #include " checkers.h"
23
24
#include " common.h"
24
25
#include " erroritem.h"
25
26
#include " errorlogger.h"
@@ -98,25 +99,11 @@ static constexpr int COLUMN_TAGS = 11;
98
99
static constexpr int COLUMN_CWE = 12 ;
99
100
100
101
static QString getGuideline (ReportType reportType, const QMap<QString,QString>& guidelines, const QString& errorId, Severity severity) {
101
- if (reportType == ReportType::autosar) {
102
- if (errorId.startsWith (" premium-autosar-" ))
103
- return errorId.mid (16 );
104
- if (errorId.startsWith (" premium-misra-cpp-2008-" ))
105
- return " M" + errorId.mid (23 );
106
- }
107
- if (reportType == ReportType::certC || reportType == ReportType::certCpp) {
108
- if (errorId.startsWith (" premium-cert-" ))
109
- return errorId.mid (13 ).toUpper ();
110
- }
111
- if (errorId.startsWith (" premium-" ))
112
- return getGuideline (reportType, guidelines, errorId.mid (8 ), severity);
113
- if (reportType == ReportType::misraC && (errorId.startsWith (" misra-c20" ) || errorId.startsWith (" misra-c-20" )))
114
- return errorId.mid (errorId.lastIndexOf (" -" ) + 1 );
115
- if (reportType == ReportType::misraCpp2008 && errorId.startsWith (" misra-cpp-2008-" ))
116
- return errorId.mid (15 );
117
- if (reportType == ReportType::misraCpp2023 && errorId.startsWith (" misra-cpp-2023-" ))
118
- return errorId.mid (15 );
119
- const QString& guideline = guidelines.value (errorId);
102
+ auto guideline = QString::fromStdString (checkers::getGuideline (errorId.toStdString (), reportType));
103
+ if (!guideline.isEmpty ())
104
+ return guideline;
105
+
106
+ guideline = guidelines.value (errorId);
120
107
if (!guideline.isEmpty ())
121
108
return guideline;
122
109
if (severity == Severity::error || severity == Severity::warning)
@@ -125,82 +112,7 @@ static QString getGuideline(ReportType reportType, const QMap<QString,QString>&
125
112
}
126
113
127
114
static QString getClassification (ReportType reportType, const QString& guideline) {
128
- if (guideline.isEmpty ())
129
- return QString ();
130
- auto getFromInfo = [](const std::vector<checkers::Info>& info, const QString& guideline) -> QString {
131
- for (const checkers::Info& i: info) {
132
- // cppcheck-suppress useStlAlgorithm
133
- if (guideline.compare (i.guideline , Qt::CaseInsensitive) == 0 )
134
- return i.classification ;
135
- }
136
- return QString ();
137
- };
138
- if (reportType == ReportType::autosar)
139
- return getFromInfo (checkers::autosarInfo, guideline);
140
- if (reportType == ReportType::certC || reportType == ReportType::certCpp) {
141
- if (guideline.endsWith (" -CPP" ))
142
- return getFromInfo (checkers::certCppInfo, guideline);
143
- if (guideline.endsWith (" -C" ))
144
- return getFromInfo (checkers::certCInfo, guideline);
145
- }
146
- else if (reportType == ReportType::misraC) {
147
- QStringList list = guideline.split (" ." );
148
- if (list.size () == 2 ) {
149
- bool ok = true ;
150
- const int a = list[0 ].toInt (&ok);
151
- if (!ok)
152
- return QString ();
153
- const int b = list[1 ].toInt (&ok);
154
- if (!ok)
155
- return QString ();
156
- for (const auto & info: checkers::misraC2012Rules) {
157
- // cppcheck-suppress useStlAlgorithm
158
- if (info.a == a && info.b == b)
159
- return info.str ;
160
- }
161
- }
162
- }
163
- else if (reportType == ReportType::misraCpp2008) {
164
- QStringList list = guideline.split (" -" );
165
- if (list.size () == 3 ) {
166
- bool ok = true ;
167
- const int a = list[0 ].toInt (&ok);
168
- if (!ok)
169
- return QString ();
170
- const int b = list[1 ].toInt (&ok);
171
- if (!ok)
172
- return QString ();
173
- const int c = list[2 ].toInt (&ok);
174
- if (!ok)
175
- return QString ();
176
- for (const auto & info: checkers::misraCpp2008Rules) {
177
- // cppcheck-suppress useStlAlgorithm
178
- if (info.a == a && info.b == b && info.c == c)
179
- return info.classification ;
180
- }
181
- }
182
- }
183
- else if (reportType == ReportType::misraCpp2023) {
184
- QStringList list = guideline.split (" ." );
185
- if (list.size () == 3 ) {
186
- bool ok = true ;
187
- const int a = list[0 ].toInt (&ok);
188
- if (!ok)
189
- return QString ();
190
- const int b = list[1 ].toInt (&ok);
191
- if (!ok)
192
- return QString ();
193
- const int c = list[2 ].toInt (&ok);
194
- if (!ok)
195
- return QString ();
196
- for (const auto & info: checkers::misraCpp2023Rules) {
197
- // cppcheck-suppress useStlAlgorithm
198
- if (info.a == a && info.b == b && info.c == c)
199
- return info.classification ;
200
- }
201
- }
202
- }
203
- return QString ();
115
+ return QString::fromStdString (checkers::getClassification (guideline.toStdString (), reportType));
204
116
}
205
117
206
118
static Severity getSeverityFromClassification (const QString &c) {
0 commit comments