fix #2911 (Token::Match(tok, %oror%|&&) doesn't match &&)

This commit is contained in:
Robert Reif 2011-07-31 13:26:26 -04:00
parent 8d68981119
commit daf0c71f77
2 changed files with 23 additions and 15 deletions

View File

@ -561,6 +561,9 @@ bool Token::Match(const Token *tok, const char pattern[], unsigned int varid)
int result = multiCompare(p, tok->str().c_str());
if (result == -1)
return false; // No match
while (*p && *p != ' ')
p++;
}
// single compare..
@ -568,38 +571,40 @@ bool Token::Match(const Token *tok, const char pattern[], unsigned int varid)
{
if (tok->str() != "|")
return false;
p += 4;
}
else if (p[3] == 'p')
{
if (!tok->isOp())
return false;
p += 4;
}
else
patternUnderstood = false;
}
// Oror (%oror%)
else
else if (p[5] == '%')
{
// multicompare..
if (p[5] == '|')
if (p[6] == '|')
{
int result = multiCompare(p, tok->str().c_str());
if (result == -1)
return false; // No match
while (*p && *p != ' ')
p++;
}
// single compare..
if (tok->str() != "||")
else if (tok->str() != "||")
return false;
patternUnderstood = true;
}
else
p += 6;
if (patternUnderstood)
{
while (*p && *p != ' ')
p++;
patternUnderstood = true;
}
break;
default:

View File

@ -233,18 +233,21 @@ private:
void matchOr()
{
givenACodeSampleToTokenize bitwiseOr("|");
ASSERT_EQUALS(true, Token::Match(bitwiseOr.tokens(), "%or%"));
ASSERT_EQUALS(true, Token::Match(bitwiseOr.tokens(), "%or%"));
ASSERT_EQUALS(false, Token::Match(bitwiseOr.tokens(), "%op%"));
ASSERT_EQUALS(false, Token::Match(bitwiseOr.tokens(), "%oror%"));
givenACodeSampleToTokenize logicalOr("||");
ASSERT_EQUALS(true, Token::Match(logicalOr.tokens(), "%oror%"));
ASSERT_EQUALS(false, Token::Match(logicalOr.tokens(), "%or%"));
ASSERT_EQUALS(false, Token::Match(bitwiseOr.tokens(), "%oror%"));
ASSERT_EQUALS(true, Token::Match(logicalOr.tokens(), "&&|%oror%"));
ASSERT_EQUALS(true, Token::Match(logicalOr.tokens(), "%oror%|&&"));
ASSERT_EQUALS(false, Token::Match(logicalOr.tokens(), "%op%"));
ASSERT_EQUALS(true, Token::Match(logicalOr.tokens(), "%oror%"));
ASSERT_EQUALS(true, Token::Match(logicalOr.tokens(), "&&|%oror%"));
ASSERT_EQUALS(true, Token::Match(logicalOr.tokens(), "%oror%|&&"));
givenACodeSampleToTokenize logicalAnd("&&");
ASSERT_EQUALS(true, Token::Match(logicalAnd.tokens(), "&&"));
ASSERT_EQUALS(true, Token::Match(logicalAnd.tokens(), "&&|%oror%"));
TODO_ASSERT_EQUALS(true, false, Token::Match(logicalAnd.tokens(), "%oror%|&&"));
ASSERT_EQUALS(true, Token::Match(logicalAnd.tokens(), "%oror%|&&"));
}
void matchOp()