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];
|
const char *className[2];
|
||||||
className[0] = tok1->strAt( 1 );
|
className[0] = tok1->strAt( 1 );
|
||||||
className[1] = 0;
|
className[1] = 0;
|
||||||
|
const Token *classNameToken = tok1->tokAt( 1 );
|
||||||
|
|
||||||
// TODO: handling of private constructors should be improved.
|
// TODO: handling of private constructors should be improved.
|
||||||
bool hasPrivateConstructor = false;
|
bool hasPrivateConstructor = false;
|
||||||
|
@ -351,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, "%var1% (", 0, className) )
|
else if ( isPrivate && Token::Match(tok, "%varid% (", classNameToken->varId()) )
|
||||||
{
|
{
|
||||||
hasPrivateConstructor = true;
|
hasPrivateConstructor = true;
|
||||||
break;
|
break;
|
||||||
|
@ -369,9 +370,9 @@ void CheckClass::constructors()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Are there a class constructor?
|
// 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, "~" ) )
|
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.
|
// There are no constructor.
|
||||||
if ( ! constructor_token )
|
if ( ! constructor_token )
|
||||||
|
@ -385,7 +386,7 @@ void CheckClass::constructors()
|
||||||
{
|
{
|
||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
ostr << _tokenizer->fileLine(tok1);
|
ostr << _tokenizer->fileLine(tok1);
|
||||||
ostr << " The class '" << className[0] << "' has no constructor";
|
ostr << " The class '" << classNameToken->str() << "' has no constructor";
|
||||||
_errorLogger->reportErr(ostr.str());
|
_errorLogger->reportErr(ostr.str());
|
||||||
}
|
}
|
||||||
// Delete the varlist..
|
// 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;
|
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
|
unsigned int Token::varId() const
|
||||||
{
|
{
|
||||||
return _varId;
|
return _varId;
|
||||||
|
|
1
token.h
1
token.h
|
@ -112,6 +112,7 @@ public:
|
||||||
bool isBoolean() const;
|
bool isBoolean() const;
|
||||||
bool isStandardType() 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[], 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
|
* Needle is build from multiple alternatives. If one of
|
||||||
|
|
Loading…
Reference in New Issue