MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / addInlineSuppressions

Function addInlineSuppressions

lib/preprocessor.cpp:198–337  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

196}
197
198static void addInlineSuppressions(const simplecpp::TokenList &tokens, const Settings &settings, SuppressionList &suppressions, std::list<BadInlineSuppression> &bad)
199{
200 std::list<SuppressionList::Suppression> inlineSuppressionsBlockBegin;
201
202 bool onlyComments = true;
203
204 polyspace::Parser polyspaceParser(settings);
205
206 for (const simplecpp::Token *tok = tokens.cfront(); tok; tok = tok->next) {
207 if (!tok->comment) {
208 onlyComments = false;
209 continue;
210 }
211
212 std::list<SuppressionList::Suppression> inlineSuppressions;
213 if (polyspace::isPolyspaceComment(tok->str())) {
214 inlineSuppressions = polyspaceParser.parse(tok->str(), tok->location.line, getRelativeFilename(tokens, tok, settings));
215 } else {
216 if (!parseInlineSuppressionCommentToken(tok, inlineSuppressions, bad))
217 continue;
218
219 if (!sameline(tok->previous, tok)) {
220 // find code after comment..
221 if (tok->next) {
222 tok = tok->next;
223
224 while (tok->comment) {
225 parseInlineSuppressionCommentToken(tok, inlineSuppressions, bad);
226 if (tok->next) {
227 tok = tok->next;
228 } else {
229 break;
230 }
231 }
232 }
233 }
234 }
235
236 if (inlineSuppressions.empty())
237 continue;
238
239 // It should never happen
240 if (!tok)
241 continue;
242
243 // Relative filename
244 const std::string relativeFilename = getRelativeFilename(tokens, tok, settings);
245
246 // Macro name
247 std::string macroName;
248 if (tok->str() == "#" && tok->next && tok->next->str() == "define") {
249 const simplecpp::Token *macroNameTok = tok->next->next;
250 if (sameline(tok, macroNameTok) && macroNameTok->name) {
251 macroName = macroNameTok->str();
252 }
253 }
254
255 // Add the suppressions.

Callers 1

inlineSuppressionsMethod · 0.85

Calls 11

getRelativeFilenameFunction · 0.85
samelineFunction · 0.70
strMethod · 0.45
parseMethod · 0.45
emptyMethod · 0.45
addSuppressionMethod · 0.45
push_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected