Fixed several bugs from previous commits and added check code that will print errors if varid is 0 when %varid% is given in Match().

This commit is contained in:
Reijo Tomperi 2009-01-04 20:33:12 +00:00
parent 3dd3bad0ec
commit 21eaadbe31
3 changed files with 14 additions and 5 deletions

View File

@ -352,7 +352,7 @@ void CheckClass::constructors()
isPrivate = false; isPrivate = false;
// Is there a private constructor? // Is there a private constructor?
else if ( isPrivate && Token::Match(tok, "%varid% (", classNameToken->varId()) ) else if ( isPrivate && tok->next() && tok->str() == classNameToken->str() && tok->next()->str() == "(" )
{ {
hasPrivateConstructor = true; hasPrivateConstructor = true;
break; break;
@ -370,9 +370,10 @@ void CheckClass::constructors()
} }
// Are there a class constructor? // Are there a class constructor?
const Token *constructor_token = Token::findmatch( tok1, "%any% %varid% (", classNameToken->varId() ); std::string tempPattern = "%any% " + classNameToken->str() + " (";
const Token *constructor_token = Token::findmatch( tok1, tempPattern.c_str() );
while ( Token::Match( constructor_token, "~" ) ) while ( Token::Match( constructor_token, "~" ) )
constructor_token = Token::findmatch( constructor_token->next(), "%any% %varid% (", classNameToken->varId() ); constructor_token = Token::findmatch( constructor_token->next(), tempPattern.c_str() );
// There are no constructor. // There are no constructor.
if ( ! constructor_token ) if ( ! constructor_token )

View File

@ -690,7 +690,8 @@ void CheckOther::CheckCharVariable()
break; break;
} }
if ((tok2->str() != ".") && Token::Match(tok2->next(), "%var% [ %varid% ]", tok->varId())) std::string temp = "%var% [ " + tok->str() + " ]";
if ((tok2->str() != ".") && Token::Match(tok2->next(), temp.c_str()))
{ {
std::ostringstream errmsg; std::ostringstream errmsg;
errmsg << _tokenizer->fileLine(tok2->next()) << ": Warning - using char variable as array index"; errmsg << _tokenizer->fileLine(tok2->next()) << ": Warning - using char variable as array index";
@ -698,7 +699,9 @@ void CheckOther::CheckCharVariable()
break; break;
} }
if ( Token::Match(tok2, "%var% [&|] %varid%", tok->varId()) || Token::Match(tok2, "%varid% [&|]", tok->varId()) ) std::string tempFirst = "%var% [&|] " + tok->str();
std::string tempSecond = tok->str() + " [&|]";
if ( Token::Match(tok2, tempFirst.c_str()) || Token::Match(tok2, tempSecond.c_str()) )
{ {
std::ostringstream errmsg; std::ostringstream errmsg;
errmsg << _tokenizer->fileLine(tok2) << ": Warning - using char variable in bit operation"; errmsg << _tokenizer->fileLine(tok2) << ": Warning - using char variable in bit operation";

View File

@ -246,6 +246,11 @@ bool Token::Match(const Token *tok, const char pattern[], unsigned int varid, co
else if (strcmp(str,"%varid%")==0) else if (strcmp(str,"%varid%")==0)
{ {
if( varid == 0 )
{
std::cout << "\n###### If you see this, there is a bug ###### Token::Match() - varid was 0" << std::endl;
}
if ( tok->varId() != varid ) if ( tok->varId() != varid )
return false; return false;