CheckInternal: Improved checking of multiCompare patterns. The multiCompare pattern can contain any %cmd% until there is non-%cmd% used. For instance %var%|%num% is handled ok.

This commit is contained in:
Daniel Marjamäki 2014-01-05 23:03:36 +01:00
parent a98c66b048
commit c32d0f1992
2 changed files with 15 additions and 7 deletions

View File

@ -58,16 +58,18 @@ void CheckInternal::checkTokenMatchPatterns()
p++;
const char *end = p - 1;
if (start < end && !(*start == '[' && *end == ']')) {
bool cmd = (*start=='%' && std::isalpha(*(start+1)));
// check multicompare pattern..
for (const char *s = start; s != end; s++) {
if (*s == '|') {
if (*(s+1) == '%' &&
std::isalpha(*(s+2)) &&
std::strncmp(s+1,"%op%",4)!=0 &&
std::strncmp(s+1,"%or%",4)!=0 &&
std::strncmp(s+1,"%cop%",5)!=0 &&
std::strncmp(s+1,"%var%",5)!=0 &&
std::strncmp(s+1,"%oror%",6)!=0) {
if (!(*(s+1) == '%' && std::isalpha(*(s+2)))) {
cmd = false;
} else if (!cmd &&
std::strncmp(s+1,"%op%",4)!=0 &&
std::strncmp(s+1,"%or%",4)!=0 &&
std::strncmp(s+1,"%cop%",5)!=0 &&
std::strncmp(s+1,"%var%",5)!=0 &&
std::strncmp(s+1,"%oror%",6)!=0) {
multiComparePatternError(tok, pattern, funcname);
}
}

View File

@ -329,6 +329,12 @@ private:
" Token::Match(tok, \";|%oror%\");\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f() {\n" // The %var%|%num% works..
" const Token *tok;\n"
" Token::Match(tok, \"%var%|%num%\");\n"
"}");
ASSERT_EQUALS("", errout.str());
}
};