Refactoring: findMatch() that supports varId added. %var1% -> %varid% changed
This commit is contained in:
parent
066e03b00a
commit
3dd3bad0ec
|
@ -322,6 +322,7 @@ void CheckClass::constructors()
|
|||
const char *className[2];
|
||||
className[0] = tok1->strAt( 1 );
|
||||
className[1] = 0;
|
||||
const Token *classNameToken = tok1->tokAt( 1 );
|
||||
|
||||
// TODO: handling of private constructors should be improved.
|
||||
bool hasPrivateConstructor = false;
|
||||
|
@ -351,7 +352,7 @@ void CheckClass::constructors()
|
|||
isPrivate = false;
|
||||
|
||||
// Is there a private constructor?
|
||||
else if ( isPrivate && Token::Match(tok, "%var1% (", 0, className) )
|
||||
else if ( isPrivate && Token::Match(tok, "%varid% (", classNameToken->varId()) )
|
||||
{
|
||||
hasPrivateConstructor = true;
|
||||
break;
|
||||
|
@ -369,9 +370,9 @@ void CheckClass::constructors()
|
|||
}
|
||||
|
||||
// Are there a class constructor?
|
||||
const Token *constructor_token = Token::findmatch( tok1, "%any% %var1% (", className );
|
||||
const Token *constructor_token = Token::findmatch( tok1, "%any% %varid% (", classNameToken->varId() );
|
||||
while ( Token::Match( constructor_token, "~" ) )
|
||||
constructor_token = Token::findmatch( constructor_token->next(), "%any% %var1% (", className );
|
||||
constructor_token = Token::findmatch( constructor_token->next(), "%any% %varid% (", classNameToken->varId() );
|
||||
|
||||
// There are no constructor.
|
||||
if ( ! constructor_token )
|
||||
|
@ -385,7 +386,7 @@ void CheckClass::constructors()
|
|||
{
|
||||
std::ostringstream ostr;
|
||||
ostr << _tokenizer->fileLine(tok1);
|
||||
ostr << " The class '" << className[0] << "' has no constructor";
|
||||
ostr << " The class '" << classNameToken->str() << "' has no constructor";
|
||||
_errorLogger->reportErr(ostr.str());
|
||||
}
|
||||
// Delete the varlist..
|
||||
|
|
10
token.cpp
10
token.cpp
|
@ -359,6 +359,16 @@ const Token *Token::findmatch(const Token *tok, const char pattern[], const char
|
|||
return 0;
|
||||
}
|
||||
|
||||
const Token *Token::findmatch(const Token *tok, const char pattern[], unsigned int varId )
|
||||
{
|
||||
for ( ; tok; tok = tok->next())
|
||||
{
|
||||
if ( Token::Match(tok, pattern, varId) )
|
||||
return tok;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int Token::varId() const
|
||||
{
|
||||
return _varId;
|
||||
|
|
1
token.h
1
token.h
|
@ -112,6 +112,7 @@ public:
|
|||
bool isBoolean() const;
|
||||
bool isStandardType() const;
|
||||
static const Token *findmatch(const Token *tok, const char pattern[], const char *varname1[]=0);
|
||||
static const Token *findmatch(const Token *tok, const char pattern[], unsigned int varId );
|
||||
|
||||
/**
|
||||
* Needle is build from multiple alternatives. If one of
|
||||
|
|
Loading…
Reference in New Issue