| 32 | #include <vector> |
| 33 | |
| 34 | void CheckInternalImpl::checkTokenMatchPatterns() |
| 35 | { |
| 36 | const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); |
| 37 | for (const Scope *scope : symbolDatabase->functionScopes) { |
| 38 | for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { |
| 39 | if (!Token::simpleMatch(tok, "Token :: Match (") && !Token::simpleMatch(tok, "Token :: findmatch (")) |
| 40 | continue; |
| 41 | |
| 42 | const std::string& funcname = tok->strAt(2); |
| 43 | |
| 44 | // Get pattern string |
| 45 | const Token *patternTok = tok->tokAt(4)->nextArgument(); |
| 46 | if (!patternTok || patternTok->tokType() != Token::eString) |
| 47 | continue; |
| 48 | |
| 49 | const std::string pattern = patternTok->strValue(); |
| 50 | if (pattern.empty()) { |
| 51 | simplePatternError(tok, pattern, funcname); |
| 52 | continue; |
| 53 | } |
| 54 | |
| 55 | if (pattern.find("||") != std::string::npos || pattern.find(" | ") != std::string::npos || pattern[0] == '|' || (pattern[pattern.length() - 1] == '|' && pattern[pattern.length() - 2] == ' ')) |
| 56 | orInComplexPattern(tok, pattern, funcname); |
| 57 | |
| 58 | // Check for signs of complex patterns |
| 59 | if (pattern.find_first_of("[|") != std::string::npos) |
| 60 | continue; |
| 61 | if (pattern.find("!!") != std::string::npos) |
| 62 | continue; |
| 63 | |
| 64 | bool complex = false; |
| 65 | size_t index = pattern.find('%'); |
| 66 | while (index != std::string::npos) { |
| 67 | if (pattern.length() <= index + 2) { |
| 68 | complex = true; |
| 69 | break; |
| 70 | } |
| 71 | if (pattern[index + 1] == 'o' && pattern[index + 2] == 'r') // %or% or %oror% |
| 72 | index = pattern.find('%', index + 1); |
| 73 | else { |
| 74 | complex = true; |
| 75 | break; |
| 76 | } |
| 77 | index = pattern.find('%', index + 1); |
| 78 | } |
| 79 | if (!complex) |
| 80 | simplePatternError(tok, pattern, funcname); |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | void CheckInternalImpl::checkRedundantTokCheck() |
| 86 | { |
no test coverage detected