refactoring : Replaced "aaaa" with "str"

This commit is contained in:
Daniel Marjamäki 2008-12-20 19:57:03 +00:00
parent bb1691c65f
commit 92c1914951
1 changed files with 55 additions and 57 deletions

View File

@ -57,34 +57,34 @@ struct CheckClass::VAR *CheckClass::ClassChecking_GetVarList(const TOKEN *tok1)
if (!tok->next()) if (!tok->next())
break; break;
if (tok->aaaa0() == '{') if (tok->str() == "{")
indentlevel++; ++indentlevel;
if (tok->aaaa0() == '}') else if (tok->str() == "}")
{ {
if (indentlevel <= 1) if (indentlevel <= 1)
break; break;
indentlevel--; --indentlevel;
} }
if ( indentlevel != 1 )
continue;
if (indentlevel==1 && (strchr(";{}", tok->aaaa0()) || (tok->aaaa0()!=':' && strchr(tok->aaaa(), ':')))) // "private:" "public:" "protected:" etc
{ bool b = bool((*tok->strAt(0) != ':') && strchr(tok->strAt(0), ':') != 0);
// Search for start of statement..
if ( ! TOKEN::Match(tok, "[;{}]") && ! b )
continue;
// This is the start of a statement
const TOKEN *next = tok->next(); const TOKEN *next = tok->next();
const char *varname = 0; const char *varname = 0;
// Is it a variable declaration? // Is it a variable declaration?
if ( TOKEN::Match(next,"%type% %var% ;") ) if ( TOKEN::Match(next,"%type% %var% ;") )
{ {
const char *types[] = {"bool", "char", "int", "short", "long", "float", "double", 0}; if ( next->isStandardType() )
for ( int type = 0; types[type]; type++ ) varname = next->strAt(1);
{
if ( strcmp(next->aaaa(), types[type]) == 0)
{
varname = next->next()->aaaa();
break;
}
}
} }
// Pointer? // Pointer?
@ -93,6 +93,7 @@ struct CheckClass::VAR *CheckClass::ClassChecking_GetVarList(const TOKEN *tok1)
varname = next->strAt(2); varname = next->strAt(2);
} }
// If the varname was set in one of the two if-block above, create a entry for this variable..
if (varname) if (varname)
{ {
struct VAR *var = new VAR; struct VAR *var = new VAR;
@ -103,7 +104,6 @@ struct CheckClass::VAR *CheckClass::ClassChecking_GetVarList(const TOKEN *tok1)
varlist = var; varlist = var;
} }
} }
}
return varlist; return varlist;
} }
@ -225,17 +225,17 @@ void CheckClass::ClassChecking_VarList_Initialize(const TOKEN *tok1, const TOKEN
InitVar( varlist, ftok->aaaa() ); InitVar( varlist, ftok->aaaa() );
} }
Assign |= (ftok->aaaa0() == ':'); Assign |= (ftok->str() == ":");
} }
if (ftok->aaaa0() == '{') if (ftok->str() == "{")
{ {
indentlevel++; indentlevel++;
Assign = false; Assign = false;
} }
if (ftok->aaaa0() == '}') if (ftok->str() == "}")
{ {
if (indentlevel <= 1) if (indentlevel <= 1)
break; break;
@ -279,9 +279,9 @@ void CheckClass::ClassChecking_VarList_Initialize(const TOKEN *tok1, const TOKEN
else if (TOKEN::Match(ftok, "%var% (")) else if (TOKEN::Match(ftok, "%var% ("))
{ {
// No recursive calls! // No recursive calls!
if ( std::find(callstack.begin(),callstack.end(),ftok->aaaa()) == callstack.end() ) if ( std::find(callstack.begin(),callstack.end(),ftok->str()) == callstack.end() )
{ {
callstack.push_back( ftok->aaaa() ); callstack.push_back( ftok->str() );
int i = 0; int i = 0;
const TOKEN *ftok2 = FindClassFunction( tok1, classname, ftok->aaaa(), i ); const TOKEN *ftok2 = FindClassFunction( tok1, classname, ftok->aaaa(), i );
ClassChecking_VarList_Initialize(tok1, ftok2, varlist, classname, callstack); ClassChecking_VarList_Initialize(tok1, ftok2, varlist, classname, callstack);
@ -499,8 +499,6 @@ void CheckClass::privateFunctions()
break; break;
indent_level--; indent_level--;
} }
else if (tok->str() == "};")
break;
else if (tok->str() == "private:") else if (tok->str() == "private:")
priv = true; priv = true;
else if (tok->str() == "public:") else if (tok->str() == "public:")
@ -528,35 +526,35 @@ void CheckClass::privateFunctions()
{ {
ftok = TOKEN::findmatch(ftok,pattern_function.c_str()); ftok = TOKEN::findmatch(ftok,pattern_function.c_str());
int numpar = 0; int numpar = 0;
while (ftok && ftok->aaaa0()!=';' && ftok->aaaa0()!='{') while (ftok && !TOKEN::Match(ftok, "[;{]"))
{ {
if (ftok->aaaa0() == '(') if (ftok->str() == "(")
numpar++; ++numpar;
else if (ftok->aaaa0() == ')') else if (ftok->str() == ")")
numpar--; --numpar;
ftok = ftok->next(); ftok = ftok->next();
} }
if (!ftok) if (!ftok)
break; break;
if (ftok->aaaa0() != ';' && numpar == 0) if (ftok->str() != ";" && numpar == 0)
{ {
HasFuncImpl = true; HasFuncImpl = true;
indent_level = 0; indent_level = 0;
while (ftok) while (ftok)
{ {
if (ftok->aaaa0() == '{') if (ftok->str() == "{")
indent_level++; indent_level++;
if (ftok->aaaa0() == '}') if (ftok->str() == "}")
{ {
if (indent_level<=1) if (indent_level<=1)
break; break;
indent_level--; indent_level--;
} }
if (ftok->next() && ftok->next()->aaaa0() == '(') if (TOKEN::Match( ftok->next(), "(") )
FuncList.remove(ftok->aaaa()); FuncList.remove(ftok->str());
ftok = ftok->next(); ftok = ftok->next();
} }
} }
@ -589,7 +587,7 @@ void CheckClass::noMemset()
// Locate all 'memset' tokens.. // Locate all 'memset' tokens..
for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next()) for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next())
{ {
if (!TOKEN::Match(tok,"memset") && !TOKEN::Match(tok,"memcpy") && !TOKEN::Match(tok,"memmove")) if (!TOKEN::Match(tok,"memset|memcpy|memmove"))
continue; continue;
// Todo: Handle memcpy and memmove // Todo: Handle memcpy and memmove
@ -614,7 +612,7 @@ void CheckClass::noMemset()
if (TOKEN::findmatch(_tokenizer->tokens(),pattern1.c_str())) if (TOKEN::findmatch(_tokenizer->tokens(),pattern1.c_str()))
{ {
std::ostringstream ostr; std::ostringstream ostr;
ostr << _tokenizer->fileLine(tok) << ": Using '" << tok->aaaa() << "' on class."; ostr << _tokenizer->fileLine(tok) << ": Using '" << tok->str() << "' on class.";
_errorLogger->reportErr(ostr.str()); _errorLogger->reportErr(ostr.str());
continue; continue;
} }
@ -623,13 +621,13 @@ void CheckClass::noMemset()
const std::string pattern2(std::string("struct ") + type); const std::string pattern2(std::string("struct ") + type);
for (const TOKEN *tstruct = TOKEN::findmatch(_tokenizer->tokens(), pattern2.c_str()); tstruct; tstruct = tstruct->next()) for (const TOKEN *tstruct = TOKEN::findmatch(_tokenizer->tokens(), pattern2.c_str()); tstruct; tstruct = tstruct->next())
{ {
if (tstruct->aaaa0() == '}') if (tstruct->str() == "}")
break; break;
if (TOKEN::Match(tstruct, "std :: %type% %var% ;")) if (TOKEN::Match(tstruct, "std :: %type% %var% ;"))
{ {
std::ostringstream ostr; std::ostringstream ostr;
ostr << _tokenizer->fileLine(tok) << ": Using '" << tok->aaaa() << "' on struct that contains a 'std::" << tstruct->strAt(2) << "'"; ostr << _tokenizer->fileLine(tok) << ": Using '" << tok->str() << "' on struct that contains a 'std::" << tstruct->strAt(2) << "'";
_errorLogger->reportErr(ostr.str()); _errorLogger->reportErr(ostr.str());
break; break;
} }