Refactoring: IsName() and IsNumber() are no longer static and they don't take a parameter.

This commit is contained in:
Reijo Tomperi 2008-11-23 12:21:40 +00:00
parent 43fc511f55
commit a6ad4045d4
7 changed files with 23 additions and 16 deletions

View File

@ -369,7 +369,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_StructVariable()
const char *structname = tok->next->str;
if ( ! TOKEN::IsName( structname ) )
if ( !(tok->next->isName()) )
continue;
// Found a struct declaration. Search for arrays..

View File

@ -315,7 +315,7 @@ void CheckClass::CheckConstructors()
while (tok1)
{
const char *classname = tok1->next->str;
if ( ! TOKEN::IsName(classname) )
if ( !(tok1->next->isName()) )
{
tok1 = TOKEN::findtoken( tok1->next, pattern_classname );
continue;

View File

@ -153,7 +153,7 @@ void CheckHeaders::WarningIncludeHeader()
tok1 = tok1->next;
while (tok1->next && tok1->str[0]!=';')
{
if ( TOKEN::IsName(tok1->str) )
if ( tok1->isName() )
namelist.push_back(tok1->str);
tok1 = tok1->next;
}
@ -221,7 +221,7 @@ void CheckHeaders::WarningIncludeHeader()
}
}
if ( ! TOKEN::IsName(tok1->str) )
if ( ! tok1->isName() )
continue;
if (std::find(namelist.begin(),namelist.end(),tok1->str ) != namelist.end())

View File

@ -980,7 +980,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_ParseClass( const TOKEN
// Declaring member variable.. check allocations and deallocations
if ( TOKEN::Match(tok->next, "%type% * %var% ;") )
{
if ( TOKEN::IsName(tok->str) || strchr(";}", tok->str[0]) )
if ( tok->isName() || strchr(";}", tok->str[0]) )
{
if (_settings._showAll || !isclass(tok->strAt(1)))
CheckMemoryLeak_ClassMembers_Variable( classname, tok->strAt(3) );

View File

@ -27,6 +27,8 @@ TOKEN::TOKEN()
_str = 0;
linenr = 0;
next = 0;
_isName = false;
_isNumber = false;
}
TOKEN::~TOKEN()
@ -43,6 +45,9 @@ void TOKEN::setstr( const char s[] )
_str = _strdup(s);
#endif
str = _str ? _str : "";
_isName = bool(str[0]=='_' || isalpha(str[0]));
_isNumber = bool(isdigit(str[0]) != 0);
}
void TOKEN::combineWithNext(const char str1[], const char str2[])
@ -111,7 +116,7 @@ bool TOKEN::Match(const TOKEN *tok, const char pattern[], const char *varname1[]
// Any symbolname..
if (strcmp(str,"%var%")==0 || strcmp(str,"%type%")==0)
{
if (!TOKEN::IsName(tok->str))
if (!tok->isName())
return false;
}
@ -143,7 +148,7 @@ bool TOKEN::Match(const TOKEN *tok, const char pattern[], const char *varname1[]
else if (strcmp(str,"%num%")==0)
{
if ( ! TOKEN::IsNumber(tok->str) )
if ( ! tok->isNumber() )
return false;
}
@ -174,14 +179,14 @@ bool TOKEN::Match(const TOKEN *tok, const char pattern[], const char *varname1[]
return true;
}
bool TOKEN::IsName(const char str[])
bool TOKEN::isName() const
{
return bool(str[0]=='_' || isalpha(str[0]));
return _isName;
}
bool TOKEN::IsNumber(const char str[])
bool TOKEN::isNumber() const
{
return bool(isdigit(str[0]) != 0);
return _isNumber;
}

View File

@ -47,8 +47,8 @@ public:
const char *strAt(int index) const;
static bool Match(const TOKEN *tok, const char pattern[], const char *varname1[]=0, const char *varname2[]=0);
static bool IsName(const char str[]);
static bool IsNumber(const char str[]);
bool isName() const;
bool isNumber() const;
static bool IsStandardType(const char str[]);
static const TOKEN *findmatch(const TOKEN *tok, const char pattern[], const char *varname1[]=0, const char *varname2[]=0);
static const TOKEN *findtoken(const TOKEN *tok1, const char *tokenstr[]);
@ -59,6 +59,8 @@ public:
private:
char * _str;
bool _isName;
bool _isNumber;
};
#endif // TOKEN_H

View File

@ -764,11 +764,11 @@ void Tokenizer::SimplifyTokenList()
done = false;
}
// (1-2)
// (1-2)
if (strchr("[,(=<>",tok->str[0]) &&
TOKEN::IsNumber(tok->strAt(1)) &&
(tok->tokAt(1) && tok->tokAt(1)->isNumber()) &&
strchr("+-*/",*(tok->strAt(2))) &&
TOKEN::IsNumber(tok->strAt(3)) &&
(tok->tokAt(3) && tok->tokAt(3)->isNumber()) &&
strchr("],);=<>",*(tok->strAt(4))) )
{
int i1 = atoi(tok->strAt(1));