From 21eaadbe310ba6a9c80eb369263dfdc64f298a19 Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Sun, 4 Jan 2009 20:33:12 +0000 Subject: [PATCH] Fixed several bugs from previous commits and added check code that will print errors if varid is 0 when %varid% is given in Match(). --- checkclass.cpp | 7 ++++--- checkother.cpp | 7 +++++-- token.cpp | 5 +++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/checkclass.cpp b/checkclass.cpp index 6c1030a7f..14d99c270 100644 --- a/checkclass.cpp +++ b/checkclass.cpp @@ -352,7 +352,7 @@ void CheckClass::constructors() isPrivate = false; // 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; break; @@ -370,9 +370,10 @@ void CheckClass::constructors() } // 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, "~" ) ) - 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. if ( ! constructor_token ) diff --git a/checkother.cpp b/checkother.cpp index 300fe50d8..ef2210254 100644 --- a/checkother.cpp +++ b/checkother.cpp @@ -690,7 +690,8 @@ void CheckOther::CheckCharVariable() 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; errmsg << _tokenizer->fileLine(tok2->next()) << ": Warning - using char variable as array index"; @@ -698,7 +699,9 @@ void CheckOther::CheckCharVariable() 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; errmsg << _tokenizer->fileLine(tok2) << ": Warning - using char variable in bit operation"; diff --git a/token.cpp b/token.cpp index 719f1ac4d..da0bbeaea 100644 --- a/token.cpp +++ b/token.cpp @@ -246,6 +246,11 @@ bool Token::Match(const Token *tok, const char pattern[], unsigned int varid, co 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 ) return false;