From a6ad4045d41bf6ee88c6a9f53794d52184b25da3 Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Sun, 23 Nov 2008 12:21:40 +0000 Subject: [PATCH] Refactoring: IsName() and IsNumber() are no longer static and they don't take a parameter. --- CheckBufferOverrun.cpp | 2 +- CheckClass.cpp | 2 +- CheckHeaders.cpp | 4 ++-- CheckMemoryLeak.cpp | 2 +- token.cpp | 17 +++++++++++------ token.h | 6 ++++-- tokenize.cpp | 6 +++--- 7 files changed, 23 insertions(+), 16 deletions(-) diff --git a/CheckBufferOverrun.cpp b/CheckBufferOverrun.cpp index 178375552..623461c0b 100644 --- a/CheckBufferOverrun.cpp +++ b/CheckBufferOverrun.cpp @@ -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.. diff --git a/CheckClass.cpp b/CheckClass.cpp index a635c7647..fcbaf8e98 100644 --- a/CheckClass.cpp +++ b/CheckClass.cpp @@ -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; diff --git a/CheckHeaders.cpp b/CheckHeaders.cpp index cdb7073ae..014bee1b7 100644 --- a/CheckHeaders.cpp +++ b/CheckHeaders.cpp @@ -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()) diff --git a/CheckMemoryLeak.cpp b/CheckMemoryLeak.cpp index f5fb3d0ba..c803fde27 100644 --- a/CheckMemoryLeak.cpp +++ b/CheckMemoryLeak.cpp @@ -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) ); diff --git a/token.cpp b/token.cpp index 97f45313a..462304d48 100644 --- a/token.cpp +++ b/token.cpp @@ -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; } diff --git a/token.h b/token.h index ea196d796..b71df60a6 100644 --- a/token.h +++ b/token.h @@ -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 diff --git a/tokenize.cpp b/tokenize.cpp index 0401cdba1..f0d30cbc9 100644 --- a/tokenize.cpp +++ b/tokenize.cpp @@ -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));