Refactoring (Replace '->' with '.', use matching function when possible)
This commit is contained in:
parent
75debeba37
commit
44bee90d82
|
@ -192,10 +192,7 @@ static void CheckBufferOverrun_LocalVariable()
|
|||
else
|
||||
{
|
||||
// Array index..
|
||||
if (strcmp(tok2->str,varname)==0 &&
|
||||
strcmp(getstr(tok2,1),"[")==0 &&
|
||||
IsNumber(getstr(tok2,2)) &&
|
||||
strcmp(getstr(tok2,3),"]")==0 )
|
||||
if (strcmp(tok2->str,varname)==0 && match(tok2->next,"[ num ]"))
|
||||
{
|
||||
const char *str = getstr(tok2, 2);
|
||||
if (strtoul(str, NULL, 10) >= size)
|
||||
|
@ -320,11 +317,10 @@ static void CheckBufferOverrun_LocalVariable()
|
|||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
static void CheckBufferOverrun_StructVariable_CheckVar( const TOKEN *tok1, const char varname[], const char dot[], const char arrname[], const int arrsize )
|
||||
static void CheckBufferOverrun_StructVariable_CheckVar( const TOKEN *tok1, const char varname[], const char arrname[], const int arrsize )
|
||||
{
|
||||
const char *badpattern[] = {"varname",".","arrname","[","","]",NULL};
|
||||
badpattern[0] = varname;
|
||||
badpattern[1] = dot;
|
||||
badpattern[2] = arrname;
|
||||
const TOKEN *tok2 = findtoken( tok1, badpattern );
|
||||
while (tok2)
|
||||
|
@ -378,14 +374,14 @@ static void CheckBufferOverrun_StructVariable()
|
|||
if ( match( tok3->next, "var ;" ) )
|
||||
{
|
||||
const char *varname = tok3->next->str;
|
||||
CheckBufferOverrun_StructVariable_CheckVar( tok3, varname, ".", arrname, atoi(arrsize) );
|
||||
CheckBufferOverrun_StructVariable_CheckVar( tok3, varname, arrname, atoi(arrsize) );
|
||||
}
|
||||
|
||||
// Declare pointer: Fred *fred1
|
||||
else if ( match(tok3->next, "* var") && tok3->next->next->next && strchr(",);=", tok3->next->next->next->str[0]) )
|
||||
{
|
||||
const char *varname = tok3->next->next->str;
|
||||
CheckBufferOverrun_StructVariable_CheckVar( tok3, varname, "->", arrname, atoi(arrsize) );
|
||||
CheckBufferOverrun_StructVariable_CheckVar( tok3, varname, arrname, atoi(arrsize) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,9 +135,21 @@ static const TOKEN * FindClassFunction( const TOKEN *_tokens, const char classna
|
|||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
static void InitVar(struct VAR *varlist, const char varname[])
|
||||
{
|
||||
for (struct VAR *var = varlist; var; var = var->next)
|
||||
{
|
||||
if ( strcmp(var->name, varname) == 0 )
|
||||
{
|
||||
var->init = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
static void ClassChecking_VarList_Initialize(const TOKEN *ftok, struct VAR *varlist, const char classname[])
|
||||
{
|
||||
bool BeginLine = false;
|
||||
bool Assign = false;
|
||||
unsigned int indentlevel = 0;
|
||||
for (; ftok; ftok = ftok->next)
|
||||
|
@ -149,17 +161,9 @@ static void ClassChecking_VarList_Initialize(const TOKEN *ftok, struct VAR *varl
|
|||
// clKalle::clKalle() : var(value) { }
|
||||
if (indentlevel==0)
|
||||
{
|
||||
if (Assign &&
|
||||
IsName(ftok->str) &&
|
||||
ftok->next->str[0]=='(')
|
||||
if (Assign && match(ftok, "var ("))
|
||||
{
|
||||
for (struct VAR *var = varlist; var; var = var->next)
|
||||
{
|
||||
if (strcmp(var->name,ftok->str))
|
||||
continue;
|
||||
var->init = true;
|
||||
break;
|
||||
}
|
||||
InitVar( varlist, ftok->str );
|
||||
}
|
||||
|
||||
Assign |= (ftok->str[0] == ':');
|
||||
|
@ -179,8 +183,10 @@ static void ClassChecking_VarList_Initialize(const TOKEN *ftok, struct VAR *varl
|
|||
indentlevel--;
|
||||
}
|
||||
|
||||
if (BeginLine && indentlevel>=1 && IsName(ftok->str))
|
||||
if (strchr("{};", ftok->str[0]) && indentlevel>=1 && IsName(ftok->next->str))
|
||||
{
|
||||
ftok = ftok->next;
|
||||
|
||||
// Clearing all variables..
|
||||
if (match(ftok,"memset ( this ,"))
|
||||
{
|
||||
|
@ -189,7 +195,7 @@ static void ClassChecking_VarList_Initialize(const TOKEN *ftok, struct VAR *varl
|
|||
}
|
||||
|
||||
// Calling member function?
|
||||
if (ftok->next->str[0] == '(')
|
||||
else if (match(ftok, "var ("))
|
||||
{
|
||||
unsigned int i = 0;
|
||||
const TOKEN *ftok2 = FindClassFunction( tokens, classname, ftok->str, i );
|
||||
|
@ -197,40 +203,18 @@ static void ClassChecking_VarList_Initialize(const TOKEN *ftok, struct VAR *varl
|
|||
}
|
||||
|
||||
// Assignment of member variable?
|
||||
if (strcmp(ftok->next->str, "=") == 0)
|
||||
else if (match(ftok, "var ="))
|
||||
{
|
||||
for (struct VAR *var = varlist; var; var = var->next)
|
||||
{
|
||||
if (strcmp(var->name,ftok->str))
|
||||
continue;
|
||||
var->init = true;
|
||||
break;
|
||||
}
|
||||
InitVar( varlist, ftok->str );
|
||||
}
|
||||
|
||||
// Calling member function..
|
||||
if (strcmp(ftok->next->str,".")==0 || strcmp(ftok->next->str,"->")==0)
|
||||
{
|
||||
// The functions 'clear' and 'Clear' are supposed to initialize variable.
|
||||
#ifdef __linux__
|
||||
if( strcasecmp( ftok->next->next->str,"clear") == 0)
|
||||
#else
|
||||
if (stricmp(ftok->next->next->str,"clear") == 0)
|
||||
#endif
|
||||
if (match(ftok,"var . clear (") || match(ftok,"var . Clear ("))
|
||||
{
|
||||
for (struct VAR *var = varlist; var; var = var->next)
|
||||
{
|
||||
if (strcmp(var->name,ftok->str))
|
||||
continue;
|
||||
var->init = true;
|
||||
break;
|
||||
InitVar( varlist, ftok->str );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BeginLine = (strchr("{};", ftok->str[0]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -538,6 +538,15 @@ void TokenizeCode(std::istream &code, const unsigned int FileIndex)
|
|||
combine_2tokens(tok, "protected", ":");
|
||||
combine_2tokens(tok, "public", ":");
|
||||
}
|
||||
|
||||
// Replace "->" with "."
|
||||
for ( TOKEN *tok = tokens; tok; tok = tok->next )
|
||||
{
|
||||
if ( strcmp(tok->str, "->") == 0 )
|
||||
{
|
||||
strcpy( tok->str, "." );
|
||||
}
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
|
Loading…
Reference in New Issue