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

Method checkUnknownPattern

lib/checkinternal.cpp:251–283  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

249}
250
251void CheckInternalImpl::checkUnknownPattern()
252{
253 const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
254 for (const Scope* scope : symbolDatabase->functionScopes) {
255 for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
256 if (!Token::simpleMatch(tok, "Token :: Match (") && !Token::simpleMatch(tok, "Token :: findmatch ("))
257 continue;
258
259 // Get pattern string
260 const Token *patternTok = tok->tokAt(4)->nextArgument();
261 if (!patternTok || patternTok->tokType() != Token::eString)
262 continue;
263
264 const std::string pattern = patternTok->strValue();
265 bool inBrackets = false;
266
267 for (std::string::size_type j = 0; j < pattern.length() - 1; j++) {
268 if (pattern[j] == '[' && (j == 0 || pattern[j - 1] == ' '))
269 inBrackets = true;
270 else if (pattern[j] == ']')
271 inBrackets = false;
272 else if (pattern[j] == '%' && pattern[j + 1] != ' ' && pattern[j + 1] != '|' && !inBrackets) {
273 const std::string::size_type end = pattern.find('%', j + 1);
274 if (end != std::string::npos) {
275 const std::string s = pattern.substr(j, end - j + 1);
276 if (knownPatterns.find(s) == knownPatterns.end())
277 unknownPatternError(tok, s);
278 }
279 }
280 }
281 }
282 }
283}
284
285void CheckInternalImpl::checkRedundantNextPrevious()
286{

Callers 1

runChecksMethod · 0.80

Calls 7

nextMethod · 0.80
simpleMatchFunction · 0.70
nextArgumentMethod · 0.45
tokAtMethod · 0.45
strValueMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected