| 79 | } |
| 80 | |
| 81 | static bool parseInlineSuppressionCommentToken(const simplecpp::Token *tok, std::list<SuppressionList::Suppression> &inlineSuppressions, std::list<BadInlineSuppression> &bad) |
| 82 | { |
| 83 | const std::string cppchecksuppress("cppcheck-suppress"); |
| 84 | |
| 85 | const std::string &comment = tok->str(); |
| 86 | if (comment.size() < cppchecksuppress.size()) |
| 87 | return false; |
| 88 | const std::string::size_type pos1 = comment.find_first_not_of("/* \t"); |
| 89 | if (pos1 == std::string::npos) |
| 90 | return false; |
| 91 | if (comment.substr(pos1, cppchecksuppress.size()) != cppchecksuppress) |
| 92 | return false; |
| 93 | if (pos1 + cppchecksuppress.size() >= comment.size()) { |
| 94 | bad.emplace_back(tok->location, "suppression without error ID"); |
| 95 | return false; |
| 96 | } |
| 97 | |
| 98 | // check if it has a prefix |
| 99 | const std::string::size_type posEndComment = comment.find_first_of(" [", pos1+cppchecksuppress.size()); |
| 100 | |
| 101 | // skip spaces after "cppcheck-suppress" and its possible prefix |
| 102 | const std::string::size_type pos2 = comment.find_first_not_of(' ', posEndComment); |
| 103 | if (pos2 == std::string::npos) { |
| 104 | bad.emplace_back(tok->location, "suppression without error ID"); |
| 105 | return false; |
| 106 | } |
| 107 | |
| 108 | SuppressionList::Type errorType = SuppressionList::Type::unique; |
| 109 | |
| 110 | // determine prefix if specified |
| 111 | if (posEndComment >= (pos1 + cppchecksuppress.size() + 1)) { |
| 112 | const std::string suppressCmdString = comment.substr(pos1, pos2-pos1-1); |
| 113 | if (comment.at(pos1 + cppchecksuppress.size()) != '-') { |
| 114 | bad.emplace_back(tok->location, "unknown suppression type '" + suppressCmdString + "'"); |
| 115 | return false; |
| 116 | } |
| 117 | |
| 118 | const unsigned int argumentLength = |
| 119 | posEndComment - (pos1 + cppchecksuppress.size() + 1); |
| 120 | |
| 121 | const std::string suppressTypeString = |
| 122 | comment.substr(pos1 + cppchecksuppress.size() + 1, argumentLength); |
| 123 | |
| 124 | if ("file" == suppressTypeString) |
| 125 | errorType = SuppressionList::Type::file; |
| 126 | else if ("begin" == suppressTypeString) |
| 127 | errorType = SuppressionList::Type::blockBegin; |
| 128 | else if ("end" == suppressTypeString) |
| 129 | errorType = SuppressionList::Type::blockEnd; |
| 130 | else if ("macro" == suppressTypeString) |
| 131 | errorType = SuppressionList::Type::macro; |
| 132 | else { |
| 133 | bad.emplace_back(tok->location, "unknown suppression type '" + suppressCmdString + "'"); |
| 134 | return false; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | if (comment[pos2] == '[') { |
no test coverage detected