Refactoring: Tokenizer class added, functions still mostly static and
using globals
This commit is contained in:
parent
e9a6f223e6
commit
ef9f472188
|
@ -67,7 +67,7 @@ static void CheckBufferOverrun_CheckScope( const TOKEN *tok, const char *varname
|
|||
// Array index..
|
||||
if ( Match(tok, "%var1% [ %num% ]", varname) )
|
||||
{
|
||||
const char *num = getstr(tok, 2 + varc);
|
||||
const char *num = Tokenizer::getstr(tok, 2 + varc);
|
||||
if (strtol(num, NULL, 10) >= size)
|
||||
{
|
||||
ReportError(tok->next, "Array index out of bounds");
|
||||
|
@ -93,12 +93,12 @@ static void CheckBufferOverrun_CheckScope( const TOKEN *tok, const char *varname
|
|||
// Array index..
|
||||
if ( !Match(tok, "%var%") && !Match(tok,"[.&]") && Match(tok->next, "%var1% [ %num% ]", varname) )
|
||||
{
|
||||
const char *num = getstr(tok->next, 2 + varc);
|
||||
const char *num = Tokenizer::getstr(tok->next, 2 + varc);
|
||||
if (strtol(num, NULL, 10) >= size)
|
||||
{
|
||||
ReportError(tok->next, "Array index out of bounds");
|
||||
}
|
||||
tok = gettok(tok, 4);
|
||||
tok = Tokenizer::gettok(tok, 4);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,7 @@ static void CheckBufferOverrun_CheckScope( const TOKEN *tok, const char *varname
|
|||
if ( Match( tok->next, "( %var1% , %num% , %num% )", varname ) ||
|
||||
Match( tok->next, "( %var% , %var1% , %num% )", varname ) )
|
||||
{
|
||||
const char *num = getstr(tok, varc + 6);
|
||||
const char *num = Tokenizer::getstr(tok, varc + 6);
|
||||
if ( atoi(num) > total_size )
|
||||
{
|
||||
ReportError(tok, "Buffer overrun");
|
||||
|
@ -127,15 +127,15 @@ static void CheckBufferOverrun_CheckScope( const TOKEN *tok, const char *varname
|
|||
// Loop..
|
||||
if ( Match(tok, "for (") )
|
||||
{
|
||||
const TOKEN *tok2 = gettok( tok, 2 );
|
||||
const TOKEN *tok2 = Tokenizer::gettok( tok, 2 );
|
||||
|
||||
// for - setup..
|
||||
if ( Match(tok2, "%var% = 0 ;") )
|
||||
tok2 = gettok(tok2, 4);
|
||||
tok2 = Tokenizer::gettok(tok2, 4);
|
||||
else if ( Match(tok2, "%type% %var% = 0 ;") )
|
||||
tok2 = gettok(tok2, 5);
|
||||
tok2 = Tokenizer::gettok(tok2, 5);
|
||||
else if ( Match(tok2, "%type% %type% %var% = 0 ;") )
|
||||
tok2 = gettok(tok2, 6);
|
||||
tok2 = Tokenizer::gettok(tok2, 6);
|
||||
else
|
||||
continue;
|
||||
|
||||
|
@ -145,14 +145,14 @@ static void CheckBufferOverrun_CheckScope( const TOKEN *tok, const char *varname
|
|||
|
||||
// Get index variable and stopsize.
|
||||
const char *strindex = tok2->str;
|
||||
int value = (tok2->next->str[1] ? 1 : 0) + atoi(getstr(tok2, 2));
|
||||
int value = (tok2->next->str[1] ? 1 : 0) + atoi(Tokenizer::getstr(tok2, 2));
|
||||
if ( value <= size )
|
||||
continue;
|
||||
|
||||
// Goto the end of the for loop..
|
||||
while (tok2 && strcmp(tok2->str,")"))
|
||||
tok2 = tok2->next;
|
||||
if (!gettok(tok2,5))
|
||||
if (!Tokenizer::gettok(tok2,5))
|
||||
break;
|
||||
|
||||
std::ostringstream pattern;
|
||||
|
@ -190,7 +190,7 @@ static void CheckBufferOverrun_CheckScope( const TOKEN *tok, const char *varname
|
|||
if ( Match(tok, "strcpy ( %var1% , %str% )", varname) )
|
||||
{
|
||||
int len = 0;
|
||||
const char *str = getstr(tok, varc + 4 );
|
||||
const char *str = Tokenizer::getstr(tok, varc + 4 );
|
||||
while ( *str )
|
||||
{
|
||||
if (*str=='\\')
|
||||
|
@ -254,7 +254,7 @@ static void CheckBufferOverrun_CheckScope( const TOKEN *tok, const char *varname
|
|||
continue;
|
||||
|
||||
// Parse head of function..
|
||||
ftok = gettok( ftok, 2 );
|
||||
ftok = Tokenizer::gettok( ftok, 2 );
|
||||
parlevel = 1;
|
||||
while ( ftok && parlevel == 1 && par >= 1 )
|
||||
{
|
||||
|
@ -318,28 +318,28 @@ static void CheckBufferOverrun_LocalVariable()
|
|||
|
||||
if (Match(tok, "%type% %var% [ %num% ] ;"))
|
||||
{
|
||||
varname[0] = getstr(tok,1);
|
||||
size = strtoul(getstr(tok,3), NULL, 10);
|
||||
varname[0] = Tokenizer::getstr(tok,1);
|
||||
size = strtoul(Tokenizer::getstr(tok,3), NULL, 10);
|
||||
type = tok->str;
|
||||
}
|
||||
else if (indentlevel > 0 && Match(tok, "[*;{}] %var% = new %type% [ %num% ]"))
|
||||
{
|
||||
varname[0] = getstr(tok,1);
|
||||
size = strtoul(getstr(tok,6), NULL, 10);
|
||||
type = getstr(tok, 4);
|
||||
varname[0] = Tokenizer::getstr(tok,1);
|
||||
size = strtoul(Tokenizer::getstr(tok,6), NULL, 10);
|
||||
type = Tokenizer::getstr(tok, 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int total_size = size * SizeOfType(type);
|
||||
int total_size = size * Tokenizer::SizeOfType(type);
|
||||
if (total_size == 0)
|
||||
continue;
|
||||
|
||||
// The callstack is empty
|
||||
CallStack.clear();
|
||||
CheckBufferOverrun_CheckScope( gettok(tok,5), varname, size, total_size );
|
||||
CheckBufferOverrun_CheckScope( Tokenizer::gettok(tok,5), varname, size, total_size );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -353,9 +353,9 @@ static void CheckBufferOverrun_LocalVariable()
|
|||
static void CheckBufferOverrun_StructVariable()
|
||||
{
|
||||
const char *declstruct_pattern[] = {"","","{",0};
|
||||
for ( const TOKEN * tok = findtoken( tokens, declstruct_pattern );
|
||||
for ( const TOKEN * tok = Tokenizer::findtoken( tokens, declstruct_pattern );
|
||||
tok;
|
||||
tok = findtoken( tok->next, declstruct_pattern ) )
|
||||
tok = Tokenizer::findtoken( tok->next, declstruct_pattern ) )
|
||||
{
|
||||
if ( strcmp(tok->str, "struct") && strcmp(tok->str, "class") )
|
||||
continue;
|
||||
|
@ -387,9 +387,9 @@ static void CheckBufferOverrun_StructVariable()
|
|||
continue;
|
||||
|
||||
const char *varname[3] = {0,0,0};
|
||||
varname[1] = getstr(tok2, ivar);
|
||||
int arrsize = atoi(getstr(tok2, ivar+2));
|
||||
int total_size = arrsize * SizeOfType(tok2->next->str);
|
||||
varname[1] = Tokenizer::getstr(tok2, ivar);
|
||||
int arrsize = atoi(Tokenizer::getstr(tok2, ivar+2));
|
||||
int total_size = arrsize * Tokenizer::SizeOfType(tok2->next->str);
|
||||
if (total_size == 0)
|
||||
continue;
|
||||
|
||||
|
@ -400,11 +400,11 @@ static void CheckBufferOverrun_StructVariable()
|
|||
|
||||
// Declare variable: Fred fred1;
|
||||
if ( Match( tok3->next, "%var% ;" ) )
|
||||
varname[0] = getstr(tok3, 1);
|
||||
varname[0] = Tokenizer::getstr(tok3, 1);
|
||||
|
||||
// Declare pointer: Fred *fred1
|
||||
else if ( Match(tok3->next, "* %var% [,);=]") )
|
||||
varname[0] = getstr(tok3, 2);
|
||||
varname[0] = Tokenizer::getstr(tok3, 2);
|
||||
|
||||
else
|
||||
continue;
|
||||
|
@ -428,7 +428,7 @@ static void CheckBufferOverrun_StructVariable()
|
|||
// Function implementation..
|
||||
if ( Match(tok3, ") {") )
|
||||
{
|
||||
CheckTok = gettok(tok3, 2);
|
||||
CheckTok = Tokenizer::gettok(tok3, 2);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -475,7 +475,7 @@ void WarningDangerousFunctions()
|
|||
ReportErr(ostr.str());
|
||||
}
|
||||
|
||||
else if (Match(tok, "scanf (") && strcmp(getstr(tok,2),"\"%s\"") == 0)
|
||||
else if (Match(tok, "scanf (") && strcmp(Tokenizer::getstr(tok,2),"\"%s\"") == 0)
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
ostr << FileLine(tok) << ": Found 'scanf'. You should use 'fgets' instead";
|
||||
|
|
|
@ -87,7 +87,7 @@ static struct VAR *ClassChecking_GetVarList(const TOKEN *tok1)
|
|||
// Pointer?
|
||||
else if ( Match(next, "%type% * %var% ;") )
|
||||
{
|
||||
varname = getstr(next, 2);
|
||||
varname = Tokenizer::getstr(next, 2);
|
||||
}
|
||||
|
||||
if (varname)
|
||||
|
@ -123,9 +123,9 @@ static const TOKEN * FindClassFunction( const TOKEN *tok, const char classname[]
|
|||
Match(tok, "class %var1% : %type% {", _classname) ) )
|
||||
{
|
||||
if ( Match(tok, "class %var% {") )
|
||||
tok = gettok(tok, 3);
|
||||
tok = Tokenizer::gettok(tok, 3);
|
||||
else
|
||||
tok = gettok(tok, 5);
|
||||
tok = Tokenizer::gettok(tok, 5);
|
||||
indentlevel = 1;
|
||||
}
|
||||
|
||||
|
@ -258,7 +258,7 @@ static void ClassChecking_VarList_Initialize(const TOKEN *tok1, const TOKEN *fto
|
|||
|
||||
// Skip "this->"
|
||||
if ( Match(ftok, "this .") )
|
||||
ftok = gettok(ftok, 2);
|
||||
ftok = Tokenizer::gettok(ftok, 2);
|
||||
|
||||
// Clearing all variables..
|
||||
if (Match(ftok,"memset ( this ,"))
|
||||
|
@ -308,22 +308,22 @@ void CheckConstructors()
|
|||
{
|
||||
// Locate class
|
||||
const char *pattern_classname[] = {"class","","{",NULL};
|
||||
const TOKEN *tok1 = findtoken(tokens, pattern_classname);
|
||||
const TOKEN *tok1 = Tokenizer::findtoken(tokens, pattern_classname);
|
||||
while (tok1)
|
||||
{
|
||||
const char *classname = tok1->next->str;
|
||||
if ( ! IsName(classname) )
|
||||
{
|
||||
tok1 = findtoken( tok1->next, pattern_classname );
|
||||
tok1 = Tokenizer::findtoken( tok1->next, pattern_classname );
|
||||
continue;
|
||||
}
|
||||
|
||||
// Are there a class constructor?
|
||||
const char *constructor_pattern[] = {"","clKalle","(",NULL};
|
||||
constructor_pattern[1] = classname;
|
||||
const TOKEN *constructor_token = findtoken( tokens, constructor_pattern );
|
||||
const TOKEN *constructor_token = Tokenizer::findtoken( tokens, constructor_pattern );
|
||||
while ( constructor_token && constructor_token->str[0] == '~' )
|
||||
constructor_token = findtoken( constructor_token->next, constructor_pattern );
|
||||
constructor_token = Tokenizer::findtoken( constructor_token->next, constructor_pattern );
|
||||
if ( ! constructor_token )
|
||||
{
|
||||
// There's no class constructor
|
||||
|
@ -347,7 +347,7 @@ void CheckConstructors()
|
|||
}
|
||||
}
|
||||
|
||||
tok1 = findtoken( tok1->next, pattern_classname );
|
||||
tok1 = Tokenizer::findtoken( tok1->next, pattern_classname );
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -367,7 +367,7 @@ void CheckConstructors()
|
|||
const char *pattern[] = {"","::","","=",NULL};
|
||||
pattern[0] = classname;
|
||||
pattern[2] = var->name;
|
||||
if (findtoken(tokens, pattern))
|
||||
if (Tokenizer::findtoken(tokens, pattern))
|
||||
continue;
|
||||
|
||||
if (!var->init)
|
||||
|
@ -394,7 +394,7 @@ void CheckConstructors()
|
|||
varlist = nextvar;
|
||||
}
|
||||
|
||||
tok1 = findtoken( tok1->next, pattern_classname );
|
||||
tok1 = Tokenizer::findtoken( tok1->next, pattern_classname );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -408,7 +408,7 @@ void CheckUnusedPrivateFunctions()
|
|||
{
|
||||
// Locate some class
|
||||
const char *pattern_class[] = {"class","","{",NULL};
|
||||
for (const TOKEN *tok1 = findtoken(tokens, pattern_class); tok1; tok1 = findtoken(tok1->next, pattern_class))
|
||||
for (const TOKEN *tok1 = Tokenizer::findtoken(tokens, pattern_class); tok1; tok1 = Tokenizer::findtoken(tok1->next, pattern_class))
|
||||
{
|
||||
const char *classname = tok1->next->str;
|
||||
|
||||
|
@ -416,7 +416,7 @@ void CheckUnusedPrivateFunctions()
|
|||
const char *pattern_classconstructor[] = {"","::","",NULL};
|
||||
pattern_classconstructor[0] = classname;
|
||||
pattern_classconstructor[2] = classname;
|
||||
if (!findtoken(tokens,pattern_classconstructor))
|
||||
if (!Tokenizer::findtoken(tokens,pattern_classconstructor))
|
||||
continue;
|
||||
|
||||
// Get private functions..
|
||||
|
@ -452,7 +452,7 @@ void CheckUnusedPrivateFunctions()
|
|||
else if (priv && indent_level == 1)
|
||||
{
|
||||
if ( Match(tok, "typedef %type% (") )
|
||||
tok = gettok(tok, 2);
|
||||
tok = Tokenizer::gettok(tok, 2);
|
||||
|
||||
if (Match(tok, "%var% (") &&
|
||||
!Match(tok,classname))
|
||||
|
@ -469,7 +469,7 @@ void CheckUnusedPrivateFunctions()
|
|||
const TOKEN *ftok = tokens;
|
||||
while (ftok)
|
||||
{
|
||||
ftok = findtoken(ftok,pattern_function);
|
||||
ftok = Tokenizer::findtoken(ftok,pattern_function);
|
||||
int numpar = 0;
|
||||
while (ftok && ftok->str[0]!=';' && ftok->str[0]!='{')
|
||||
{
|
||||
|
@ -515,13 +515,13 @@ void CheckUnusedPrivateFunctions()
|
|||
// Final check; check if the function pointer is used somewhere..
|
||||
const char *_pattern[] = {"=","",NULL};
|
||||
_pattern[1] = FuncList.front().c_str();
|
||||
fp |= (findtoken(tokens, _pattern) != NULL);
|
||||
fp |= (Tokenizer::findtoken(tokens, _pattern) != NULL);
|
||||
_pattern[0] = "(";
|
||||
fp |= (findtoken(tokens, _pattern) != NULL);
|
||||
fp |= (Tokenizer::findtoken(tokens, _pattern) != NULL);
|
||||
_pattern[0] = ")";
|
||||
fp |= (findtoken(tokens, _pattern) != NULL);
|
||||
fp |= (Tokenizer::findtoken(tokens, _pattern) != NULL);
|
||||
_pattern[0] = ",";
|
||||
fp |= (findtoken(tokens, _pattern) != NULL);
|
||||
fp |= (Tokenizer::findtoken(tokens, _pattern) != NULL);
|
||||
|
||||
if (!fp)
|
||||
{
|
||||
|
@ -549,15 +549,15 @@ void CheckMemset()
|
|||
// Todo: Handle memcpy and memmove
|
||||
const char *type = NULL;
|
||||
if (Match(tok, "memset ( %var% , %num% , sizeof ( %type% ) )"))
|
||||
type = getstr(tok, 8);
|
||||
type = Tokenizer::getstr(tok, 8);
|
||||
else if (Match(tok, "memset ( & %var% , %num% , sizeof ( %type% ) )"))
|
||||
type = getstr(tok, 9);
|
||||
type = Tokenizer::getstr(tok, 9);
|
||||
else if (Match(tok, "memset ( %var% , %num% , sizeof ( struct %type% ) )"))
|
||||
type = getstr(tok, 9);
|
||||
type = Tokenizer::getstr(tok, 9);
|
||||
else if (Match(tok, "memset ( & %var% , %num% , sizeof ( struct %type% ) )"))
|
||||
type = getstr(tok, 10);
|
||||
type = Tokenizer::getstr(tok, 10);
|
||||
else if (Match(tok, "%type% ( %var% , %var% , sizeof ( %type% ) )"))
|
||||
type = getstr(tok, 8);
|
||||
type = Tokenizer::getstr(tok, 8);
|
||||
|
||||
// No type defined => The tokens didn't match
|
||||
if (!(type && type[0]))
|
||||
|
@ -566,7 +566,7 @@ void CheckMemset()
|
|||
// Warn if type is a class..
|
||||
const char *pattern1[] = {"class","",NULL};
|
||||
pattern1[1] = type;
|
||||
if (findtoken(tokens,pattern1))
|
||||
if (Tokenizer::findtoken(tokens,pattern1))
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
ostr << FileLine(tok) << ": Using '" << tok->str << "' on class.";
|
||||
|
@ -577,7 +577,7 @@ void CheckMemset()
|
|||
// Warn if type is a struct that contains any std::*
|
||||
const char *pattern2[] = {"struct","","{",NULL};
|
||||
pattern2[1] = type;
|
||||
for (const TOKEN *tstruct = findtoken(tokens, pattern2); tstruct; tstruct = tstruct->next)
|
||||
for (const TOKEN *tstruct = Tokenizer::findtoken(tokens, pattern2); tstruct; tstruct = tstruct->next)
|
||||
{
|
||||
if (tstruct->str[0] == '}')
|
||||
break;
|
||||
|
@ -585,7 +585,7 @@ void CheckMemset()
|
|||
if (Match(tstruct, "std :: %type% %var% ;"))
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
ostr << FileLine(tok) << ": Using '" << tok->str << "' on struct that contains a 'std::" << getstr(tstruct,2) << "'";
|
||||
ostr << FileLine(tok) << ": Using '" << tok->str << "' on struct that contains a 'std::" << Tokenizer::getstr(tstruct,2) << "'";
|
||||
ReportErr(ostr.str());
|
||||
break;
|
||||
}
|
||||
|
@ -603,7 +603,7 @@ void CheckMemset()
|
|||
void CheckOperatorEq1()
|
||||
{
|
||||
const char *pattern[] = {"void", "operator", "=", "(", NULL};
|
||||
if (const TOKEN *tok = findtoken(tokens,pattern))
|
||||
if (const TOKEN *tok = Tokenizer::findtoken(tokens,pattern))
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
ostr << FileLine(tok) << ": 'operator=' should return something";
|
||||
|
|
|
@ -112,28 +112,28 @@ void WarningIncludeHeader()
|
|||
|
||||
else if (tok1->str[0] == '}')
|
||||
indentlevel--;
|
||||
|
||||
|
||||
if (indentlevel != 0)
|
||||
continue;
|
||||
|
||||
// Class or namespace declaration..
|
||||
// --------------------------------------
|
||||
if (Match(tok1,"class %var% {") || Match(tok1,"class %var% :") || Match(tok1,"namespace %var% {"))
|
||||
classlist.push_back(getstr(tok1, 1));
|
||||
classlist.push_back(Tokenizer::getstr(tok1, 1));
|
||||
|
||||
// Variable declaration..
|
||||
// --------------------------------------
|
||||
else if (Match(tok1, "%type% %var% ;") || Match(tok1, "%type% %var% ["))
|
||||
namelist.push_back(getstr(tok1, 1));
|
||||
namelist.push_back(Tokenizer::getstr(tok1, 1));
|
||||
|
||||
else if (Match(tok1, "%type% * %var% ;") || Match(tok1, "%type% * %var% ["))
|
||||
namelist.push_back(getstr(tok1, 2));
|
||||
namelist.push_back(Tokenizer::getstr(tok1, 2));
|
||||
|
||||
else if (Match(tok1, "const %type% %var% =") || Match(tok1, "const %type% %var% ["))
|
||||
namelist.push_back(getstr(tok1, 2));
|
||||
namelist.push_back(Tokenizer::getstr(tok1, 2));
|
||||
|
||||
else if (Match(tok1, "const %type% * %var% =") || Match(tok1, "const %type% * %var% ["))
|
||||
namelist.push_back(getstr(tok1, 3));
|
||||
namelist.push_back(Tokenizer::getstr(tok1, 3));
|
||||
|
||||
// enum..
|
||||
// --------------------------------------
|
||||
|
@ -147,26 +147,26 @@ void WarningIncludeHeader()
|
|||
tok1 = tok1->next;
|
||||
}
|
||||
}
|
||||
|
||||
// function..
|
||||
|
||||
// function..
|
||||
// --------------------------------------
|
||||
else if (Match(tok1,"%type% %var% ("))
|
||||
namelist.push_back(getstr(tok1, 1));
|
||||
namelist.push_back(Tokenizer::getstr(tok1, 1));
|
||||
|
||||
else if (Match(tok1,"%type% * %var% ("))
|
||||
namelist.push_back(getstr(tok1, 2));
|
||||
namelist.push_back(Tokenizer::getstr(tok1, 2));
|
||||
|
||||
else if (Match(tok1,"const %type% %var% ("))
|
||||
namelist.push_back(getstr(tok1, 2));
|
||||
namelist.push_back(Tokenizer::getstr(tok1, 2));
|
||||
|
||||
else if (Match(tok1,"const %type% * %var% ("))
|
||||
namelist.push_back(getstr(tok1, 3));
|
||||
namelist.push_back(Tokenizer::getstr(tok1, 3));
|
||||
|
||||
// typedef..
|
||||
// --------------------------------------
|
||||
else if (strcmp(tok1->str,"typedef")==0)
|
||||
{
|
||||
if (strcmp(getstr(tok1,1),"enum")==0)
|
||||
if (strcmp(Tokenizer::getstr(tok1,1),"enum")==0)
|
||||
continue;
|
||||
int parlevel = 0;
|
||||
while (tok1->next)
|
||||
|
@ -202,7 +202,7 @@ void WarningIncludeHeader()
|
|||
|
||||
if ( Match(tok1, ": %var% {") || Match(tok1, ": %type% %var% {") )
|
||||
{
|
||||
std::string classname = getstr(tok1, (strcmp(getstr(tok1,2),"{")) ? 2 : 1);
|
||||
std::string classname = Tokenizer::getstr(tok1, (strcmp(Tokenizer::getstr(tok1,2),"{")) ? 2 : 1);
|
||||
if (std::find(classlist.begin(),classlist.end(),classname)!=classlist.end())
|
||||
{
|
||||
Needed = true;
|
||||
|
@ -223,7 +223,7 @@ void WarningIncludeHeader()
|
|||
NeedDeclaration = (std::find(classlist.begin(),classlist.end(),tok1->str ) != classlist.end());
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Not a header file?
|
||||
if (includetok->FileIndex == 0)
|
||||
Needed |= NeedDeclaration;
|
||||
|
|
|
@ -152,7 +152,7 @@ static AllocType GetDeallocationType( const TOKEN *tok, const char *varnames[] )
|
|||
// Redundant condition..
|
||||
if ( Match(tok, "if ( %var1% )", varnames) )
|
||||
{
|
||||
tok = gettok( tok, 4 );
|
||||
tok = Tokenizer::gettok( tok, 4 );
|
||||
if ( Match(tok,"{") )
|
||||
tok = tok->next;
|
||||
}
|
||||
|
@ -274,14 +274,14 @@ static TOKEN *getcode(const TOKEN *tok, const char varname[])
|
|||
|
||||
if (Match(tok, "[(;{}] %var1% =", varnames))
|
||||
{
|
||||
AllocType alloc = GetAllocationType(gettok(tok,3));
|
||||
AllocType alloc = GetAllocationType(Tokenizer::gettok(tok,3));
|
||||
|
||||
// If "--all" hasn't been given, don't check classes..
|
||||
if ( alloc == New && ! ShowAll )
|
||||
{
|
||||
if ( Match(gettok(tok,3), "new %type% [(;]") )
|
||||
if ( Match(Tokenizer::gettok(tok,3), "new %type% [(;]") )
|
||||
{
|
||||
if ( isclass( getstr(tok, 4) ) )
|
||||
if ( isclass( Tokenizer::getstr(tok, 4) ) )
|
||||
alloc = No;
|
||||
}
|
||||
}
|
||||
|
@ -313,9 +313,9 @@ static TOKEN *getcode(const TOKEN *tok, const char varname[])
|
|||
Match(tok, "if ( %var1% != NULL )", varnames) )
|
||||
{
|
||||
addtoken("if(var)");
|
||||
tok = gettok(tok, 3); // Make sure the "use" will not be added
|
||||
tok = Tokenizer::gettok(tok, 3); // Make sure the "use" will not be added
|
||||
}
|
||||
else if ( Match(tok, "if (") && notvar(gettok(tok,2), varnames) )
|
||||
else if ( Match(tok, "if (") && notvar(Tokenizer::gettok(tok,2), varnames) )
|
||||
{
|
||||
addtoken("if(!var)");
|
||||
}
|
||||
|
@ -345,7 +345,7 @@ static TOKEN *getcode(const TOKEN *tok, const char varname[])
|
|||
isloop = true;
|
||||
}
|
||||
if ( Match(tok, "do") )
|
||||
{
|
||||
{
|
||||
addtoken("do");
|
||||
}
|
||||
if ( isloop && notvar(tok,varnames) )
|
||||
|
@ -426,7 +426,7 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
|
|||
continue;
|
||||
|
||||
// Remove the next token "do"
|
||||
erase( tok2, gettok(tok2, 2) );
|
||||
erase( tok2, Tokenizer::gettok(tok2, 2) );
|
||||
tok2 = tok2->next;
|
||||
|
||||
// Find the end of the "do" block..
|
||||
|
@ -479,7 +479,7 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
|
|||
// Delete extra ";"
|
||||
while (Match(tok2,"[;{}] ;"))
|
||||
{
|
||||
erase(tok2, gettok(tok2,2));
|
||||
erase(tok2, Tokenizer::gettok(tok2,2));
|
||||
done = false;
|
||||
}
|
||||
|
||||
|
@ -487,21 +487,21 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
|
|||
if ( Match(tok2->next, "{ }") )
|
||||
{
|
||||
tok2->next->setstr(";");
|
||||
erase(tok2->next, gettok(tok2,3));
|
||||
erase(tok2->next, Tokenizer::gettok(tok2,3));
|
||||
done = false;
|
||||
}
|
||||
|
||||
// Delete braces around a single instruction..
|
||||
if ( Match(tok2->next, "{ %var% ; }") )
|
||||
{
|
||||
erase( tok2, gettok(tok2,2) );
|
||||
erase( tok2->next->next, gettok(tok2,4) );
|
||||
erase( tok2, Tokenizer::gettok(tok2,2) );
|
||||
erase( tok2->next->next, Tokenizer::gettok(tok2,4) );
|
||||
done = false;
|
||||
}
|
||||
if ( Match(tok2->next, "{ return use ; }") )
|
||||
{
|
||||
erase( tok2, gettok(tok2,2) );
|
||||
erase( tok2->next->next->next, gettok(tok2,5) );
|
||||
erase( tok2, Tokenizer::gettok(tok2,2) );
|
||||
erase( tok2->next->next->next, Tokenizer::gettok(tok2,5) );
|
||||
done = false;
|
||||
}
|
||||
|
||||
|
@ -510,94 +510,94 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
|
|||
Match(tok2,"[;{}] if(var) ;") ||
|
||||
Match(tok2,"[;{}] if(!var) ;") )
|
||||
{
|
||||
if ( ! Match(gettok(tok2,3), "else") )
|
||||
if ( ! Match(Tokenizer::gettok(tok2,3), "else") )
|
||||
{
|
||||
erase(tok2, gettok(tok2, 3));
|
||||
erase(tok2, Tokenizer::gettok(tok2, 3));
|
||||
done = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Delete if block: "alloc; if return use ;"
|
||||
if (Match(tok2,"alloc ; if return use ;") && !Match(gettok(tok2,6),"else"))
|
||||
if (Match(tok2,"alloc ; if return use ;") && !Match(Tokenizer::gettok(tok2,6),"else"))
|
||||
{
|
||||
erase(tok2, gettok(tok2,5));
|
||||
erase(tok2, Tokenizer::gettok(tok2,5));
|
||||
done = false;
|
||||
}
|
||||
|
||||
// "[;{}] if alloc ; else return ;" => "[;{}] alloc ;"
|
||||
if (Match(tok2,"[;{}] if alloc ; else return ;"))
|
||||
{
|
||||
erase(tok2, gettok(tok2,2)); // Remove "if"
|
||||
erase(tok2->next, gettok(tok2,5)); // Remove "; else return"
|
||||
erase(tok2, Tokenizer::gettok(tok2,2)); // Remove "if"
|
||||
erase(tok2->next, Tokenizer::gettok(tok2,5)); // Remove "; else return"
|
||||
done = false;
|
||||
}
|
||||
|
||||
// Replace "dealloc use ;" with "dealloc ;"
|
||||
if ( Match(tok2, "dealloc use ;") )
|
||||
{
|
||||
erase(tok2, gettok(tok2,2));
|
||||
erase(tok2, Tokenizer::gettok(tok2,2));
|
||||
done = false;
|
||||
}
|
||||
|
||||
// Reducing if..
|
||||
if (Match(tok2,"if dealloc ; else") || Match(tok2,"if use ; else"))
|
||||
{
|
||||
erase(tok2, gettok(tok2, 2));
|
||||
erase(tok2, Tokenizer::gettok(tok2, 2));
|
||||
done = false;
|
||||
}
|
||||
if (Match(tok2,"[;{}] if { dealloc ; return ; }") && !Match(gettok(tok2,8),"else"))
|
||||
if (Match(tok2,"[;{}] if { dealloc ; return ; }") && !Match(Tokenizer::gettok(tok2,8),"else"))
|
||||
{
|
||||
erase(tok2,gettok(tok2,8));
|
||||
erase(tok2,Tokenizer::gettok(tok2,8));
|
||||
done = false;
|
||||
}
|
||||
|
||||
// Remove "if dealloc ;" if there is no else after it..
|
||||
if (Match(tok2,"if dealloc ;") && !Match(gettok(tok2,3),"else"))
|
||||
if (Match(tok2,"if dealloc ;") && !Match(Tokenizer::gettok(tok2,3),"else"))
|
||||
{
|
||||
erase( tok2, gettok(tok2, 2) );
|
||||
erase( tok2, Tokenizer::gettok(tok2, 2) );
|
||||
done = false;
|
||||
}
|
||||
|
||||
// Replace "loop ;" with ";"
|
||||
if ( Match(tok2->next, "loop ;") )
|
||||
{
|
||||
erase(tok2, gettok(tok2,2));
|
||||
erase(tok2, Tokenizer::gettok(tok2,2));
|
||||
done = false;
|
||||
}
|
||||
|
||||
// Replace "loop !var ;" with ";"
|
||||
if ( Match(tok2->next, "loop !var ;") )
|
||||
{
|
||||
erase(tok2, gettok(tok2,4));
|
||||
erase(tok2, Tokenizer::gettok(tok2,4));
|
||||
done = false;
|
||||
}
|
||||
|
||||
// Replace "loop !var alloc ;" with " alloc ;"
|
||||
if ( Match(tok2->next, "loop !var alloc ;") )
|
||||
{
|
||||
erase(tok2, gettok(tok2,3));
|
||||
erase(tok2, Tokenizer::gettok(tok2,3));
|
||||
done = false;
|
||||
}
|
||||
|
||||
// Delete if block in "alloc ; if(!var) return ;"
|
||||
if ( Match(tok2, "alloc ; if(!var) return ;") )
|
||||
{
|
||||
erase(tok2, gettok(tok2,4));
|
||||
erase(tok2, Tokenizer::gettok(tok2,4));
|
||||
done = false;
|
||||
}
|
||||
|
||||
// Delete second use in "use ; use ;"
|
||||
while (Match(tok2, "use ; use ;"))
|
||||
{
|
||||
erase(tok2, gettok(tok2,3));
|
||||
erase(tok2, Tokenizer::gettok(tok2,3));
|
||||
done = false;
|
||||
}
|
||||
|
||||
// Delete second case in "case ; case ;"
|
||||
while (Match(tok2, "case ; case ;"))
|
||||
{
|
||||
erase(tok2, gettok(tok2,3));
|
||||
erase(tok2, Tokenizer::gettok(tok2,3));
|
||||
done = false;
|
||||
}
|
||||
|
||||
|
@ -607,7 +607,7 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
|
|||
// Right now, I just handle if there are a few case and perhaps a default.
|
||||
bool valid = false;
|
||||
bool incase = false;
|
||||
for ( const TOKEN * _tok = gettok(tok2,2); _tok; _tok = _tok->next )
|
||||
for ( const TOKEN * _tok = Tokenizer::gettok(tok2,2); _tok; _tok = _tok->next )
|
||||
{
|
||||
if ( _tok->str[0] == '{' )
|
||||
break;
|
||||
|
@ -638,7 +638,7 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
|
|||
{
|
||||
done = false;
|
||||
tok2->setstr(";");
|
||||
erase( tok2, gettok(tok2, 2) );
|
||||
erase( tok2, Tokenizer::gettok(tok2, 2) );
|
||||
tok2 = tok2->next;
|
||||
bool first = true;
|
||||
while (Match(tok2,"case") || Match(tok2,"default"))
|
||||
|
@ -679,22 +679,22 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
|
|||
|
||||
else if ( findmatch(tok, "alloc ; if continue ;") )
|
||||
{
|
||||
MemoryLeak(gettok(findmatch(tok, "alloc ; if continue ;"), 3), varname);
|
||||
MemoryLeak(Tokenizer::gettok(findmatch(tok, "alloc ; if continue ;"), 3), varname);
|
||||
}
|
||||
|
||||
else if ( findmatch(tok, "alloc ; if return ;") )
|
||||
{
|
||||
MemoryLeak(gettok(findmatch(tok, "alloc ; if return ;"), 3), varname);
|
||||
MemoryLeak(Tokenizer::gettok(findmatch(tok, "alloc ; if return ;"), 3), varname);
|
||||
}
|
||||
|
||||
else if ( findmatch(tok, "alloc ; return ;") )
|
||||
{
|
||||
MemoryLeak(gettok(findmatch(tok,"alloc ; return ;"),2), varname);
|
||||
MemoryLeak(Tokenizer::gettok(findmatch(tok,"alloc ; return ;"),2), varname);
|
||||
}
|
||||
|
||||
else if ( findmatch(tok, "alloc ; alloc") )
|
||||
{
|
||||
MemoryLeak(gettok(findmatch(tok,"alloc ; alloc"),2), varname);
|
||||
MemoryLeak(Tokenizer::gettok(findmatch(tok,"alloc ; alloc"),2), varname);
|
||||
}
|
||||
|
||||
else if ( ! findmatch(tok,"dealloc") &&
|
||||
|
@ -745,10 +745,10 @@ static void CheckMemoryLeak_InFunction()
|
|||
if (indentlevel>0 && infunc)
|
||||
{
|
||||
if ( Match(tok, "[{};] %type% * %var% [;=]") )
|
||||
CheckMemoryLeak_CheckScope( tok->next, getstr(tok, 3) );
|
||||
CheckMemoryLeak_CheckScope( tok->next, Tokenizer::getstr(tok, 3) );
|
||||
|
||||
else if ( Match(tok, "[{};] %type% %type% * %var% [;=]") )
|
||||
CheckMemoryLeak_CheckScope( tok->next, getstr(tok, 4) );
|
||||
CheckMemoryLeak_CheckScope( tok->next, Tokenizer::getstr(tok, 4) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -778,7 +778,7 @@ static void CheckMemoryLeak_ClassMembers()
|
|||
else if ( indentlevel == 0 && Match(tok, "class %var% [{:]") )
|
||||
{
|
||||
std::vector<const char *> classname;
|
||||
classname.push_back( getstr(tok, 1) );
|
||||
classname.push_back( Tokenizer::getstr(tok, 1) );
|
||||
CheckMemoryLeak_ClassMembers_ParseClass( tok, classname );
|
||||
}
|
||||
}
|
||||
|
@ -813,7 +813,7 @@ static void CheckMemoryLeak_ClassMembers_ParseClass( const TOKEN *tok1, std::vec
|
|||
// Declaring subclass.. recursive checking
|
||||
if ( Match(tok, "class %var% [{:]") )
|
||||
{
|
||||
classname.push_back( getstr(tok, 1) );
|
||||
classname.push_back( Tokenizer::getstr(tok, 1) );
|
||||
CheckMemoryLeak_ClassMembers_ParseClass( tok, classname );
|
||||
classname.pop_back();
|
||||
}
|
||||
|
@ -823,8 +823,8 @@ static void CheckMemoryLeak_ClassMembers_ParseClass( const TOKEN *tok1, std::vec
|
|||
{
|
||||
if ( IsName(tok->str) || strchr(";}", tok->str[0]) )
|
||||
{
|
||||
if (ShowAll || !isclass(getstr(tok,1)))
|
||||
CheckMemoryLeak_ClassMembers_Variable( classname, getstr(tok, 3) );
|
||||
if (ShowAll || !isclass(Tokenizer::getstr(tok,1)))
|
||||
CheckMemoryLeak_ClassMembers_Variable( classname, Tokenizer::getstr(tok, 3) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -888,7 +888,7 @@ static void CheckMemoryLeak_ClassMembers_Variable( const std::vector<const char
|
|||
// Allocate..
|
||||
if ( Match( tok, varname_eq.str().c_str() ) )
|
||||
{
|
||||
AllocType alloc = GetAllocationType( gettok( tok, 2 ) );
|
||||
AllocType alloc = GetAllocationType( Tokenizer::gettok( tok, 2 ) );
|
||||
if ( alloc != No )
|
||||
{
|
||||
if ( Dealloc != No && Dealloc != alloc )
|
||||
|
|
|
@ -45,8 +45,8 @@ void WarningOldStylePointerCast()
|
|||
|
||||
// Is "type" a class?
|
||||
const char *pattern[] = {"class","",NULL};
|
||||
pattern[1] = getstr(tok, 1);
|
||||
if (!findtoken(tokens, pattern))
|
||||
pattern[1] = Tokenizer::getstr(tok, 1);
|
||||
if (!Tokenizer::findtoken(tokens, pattern))
|
||||
continue;
|
||||
|
||||
std::ostringstream ostr;
|
||||
|
@ -159,13 +159,13 @@ void WarningRedundantCode()
|
|||
|
||||
if (Match(tok,"if ( %var% )"))
|
||||
{
|
||||
varname1 = getstr(tok, 2);
|
||||
tok2 = gettok(tok, 4);
|
||||
varname1 = Tokenizer::getstr(tok, 2);
|
||||
tok2 = Tokenizer::gettok(tok, 4);
|
||||
}
|
||||
else if (Match(tok,"if ( %var% != NULL )"))
|
||||
{
|
||||
varname1 = getstr(tok, 2);
|
||||
tok2 = gettok(tok, 6);
|
||||
varname1 = Tokenizer::getstr(tok, 2);
|
||||
tok2 = Tokenizer::gettok(tok, 6);
|
||||
}
|
||||
|
||||
if (varname1==NULL || tok2==NULL)
|
||||
|
@ -176,13 +176,13 @@ void WarningRedundantCode()
|
|||
|
||||
bool err = false;
|
||||
if (Match(tok2,"delete %var% ;"))
|
||||
err = (strcmp(getstr(tok2,1),varname1)==0);
|
||||
err = (strcmp(Tokenizer::getstr(tok2,1),varname1)==0);
|
||||
else if (Match(tok2,"delete [ ] %var% ;"))
|
||||
err = (strcmp(getstr(tok2,1),varname1)==0);
|
||||
err = (strcmp(Tokenizer::getstr(tok2,1),varname1)==0);
|
||||
else if (Match(tok2,"free ( %var% )"))
|
||||
err = (strcmp(getstr(tok2,2),varname1)==0);
|
||||
err = (strcmp(Tokenizer::getstr(tok2,2),varname1)==0);
|
||||
else if (Match(tok2,"kfree ( %var% )"))
|
||||
err = (strcmp(getstr(tok2,2),varname1)==0);
|
||||
err = (strcmp(Tokenizer::getstr(tok2,2),varname1)==0);
|
||||
|
||||
if (err)
|
||||
{
|
||||
|
@ -225,8 +225,8 @@ void WarningIf()
|
|||
parlevel--;
|
||||
if (parlevel<=0)
|
||||
{
|
||||
if (strcmp(getstr(tok2,1), ";") == 0 &&
|
||||
strcmp(getstr(tok2,2), "else") != 0)
|
||||
if (strcmp(Tokenizer::getstr(tok2,1), ";") == 0 &&
|
||||
strcmp(Tokenizer::getstr(tok2,2), "else") != 0)
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
ostr << FileLine(tok) << ": Found \"if (condition);\"";
|
||||
|
@ -252,15 +252,15 @@ void WarningIf()
|
|||
if (!Match(tok,"%var% = %var% ; if ( %var%"))
|
||||
continue;
|
||||
|
||||
if ( strcmp(getstr(tok, 9), ")") != 0 )
|
||||
if ( strcmp(Tokenizer::getstr(tok, 9), ")") != 0 )
|
||||
continue;
|
||||
|
||||
// var1 = var2 ; if ( var3 cond var4 )
|
||||
const char *var1 = tok->str;
|
||||
const char *var2 = getstr(tok, 2);
|
||||
const char *var3 = getstr(tok, 6);
|
||||
const char *cond = getstr(tok, 7);
|
||||
const char *var4 = getstr(tok, 8);
|
||||
const char *var2 = Tokenizer::getstr(tok, 2);
|
||||
const char *var3 = Tokenizer::getstr(tok, 6);
|
||||
const char *cond = Tokenizer::getstr(tok, 7);
|
||||
const char *var4 = Tokenizer::getstr(tok, 8);
|
||||
|
||||
// Check that var3 is equal with either var1 or var2
|
||||
if (strcmp(var1,var3) && strcmp(var2,var3))
|
||||
|
@ -280,7 +280,7 @@ void WarningIf()
|
|||
|
||||
// we found the error. Report.
|
||||
std::ostringstream ostr;
|
||||
ostr << FileLine(gettok(tok,4)) << ": The condition is always ";
|
||||
ostr << FileLine(Tokenizer::gettok(tok,4)) << ": The condition is always ";
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (strcmp(cond, p[i]) == 0)
|
||||
|
@ -371,18 +371,18 @@ void CheckUnsignedDivision()
|
|||
{
|
||||
if ( Match(tok, "[{};(,] %type% %var% [;=,)]") )
|
||||
{
|
||||
const char *type = getstr(tok, 1);
|
||||
const char *type = Tokenizer::getstr(tok, 1);
|
||||
if (strcmp(type,"char")==0 || strcmp(type,"short")==0 || strcmp(type,"int")==0)
|
||||
varsign[getstr(tok,2)] = 's';
|
||||
varsign[Tokenizer::getstr(tok,2)] = 's';
|
||||
}
|
||||
|
||||
else if ( Match(tok, "[{};(,] unsigned %type% %var% [;=,)]") )
|
||||
varsign[getstr(tok,3)] = 'u';
|
||||
varsign[Tokenizer::getstr(tok,3)] = 'u';
|
||||
|
||||
else if (!Match(tok,"[).]") && Match(tok->next, "%var% / %var%"))
|
||||
{
|
||||
const char *varname1 = getstr(tok,1);
|
||||
const char *varname2 = getstr(tok,3);
|
||||
const char *varname1 = Tokenizer::getstr(tok,1);
|
||||
const char *varname2 = Tokenizer::getstr(tok,3);
|
||||
char sign1 = varsign[varname1];
|
||||
char sign2 = varsign[varname2];
|
||||
|
||||
|
@ -397,7 +397,7 @@ void CheckUnsignedDivision()
|
|||
|
||||
else if (!Match(tok,"[).]") && Match(tok->next, "%var% / - %num%"))
|
||||
{
|
||||
const char *varname1 = getstr(tok,1);
|
||||
const char *varname1 = Tokenizer::getstr(tok,1);
|
||||
char sign1 = varsign[varname1];
|
||||
if ( sign1 == 'u' )
|
||||
{
|
||||
|
@ -409,7 +409,7 @@ void CheckUnsignedDivision()
|
|||
|
||||
else if (Match(tok, "[([=*/+-] - %num% / %var%"))
|
||||
{
|
||||
const char *varname2 = getstr(tok,4);
|
||||
const char *varname2 = Tokenizer::getstr(tok,4);
|
||||
char sign2 = varsign[varname2];
|
||||
if ( sign2 == 'u' )
|
||||
{
|
||||
|
@ -504,7 +504,7 @@ void CheckVariableScope()
|
|||
if (Match(tok1, "%var% %var% ;") ||
|
||||
Match(tok1, "%var% %var% =") )
|
||||
{
|
||||
CheckVariableScope_LookupVar( tok1, getstr(tok1, 1) );
|
||||
CheckVariableScope_LookupVar( tok1, Tokenizer::getstr(tok1, 1) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -592,7 +592,7 @@ void CheckConstantFunctionParameter()
|
|||
if ( Match(tok,"[,(] const std :: %type% %var% [,)]") )
|
||||
{
|
||||
std::ostringstream errmsg;
|
||||
errmsg << FileLine(tok) << " " << getstr(tok,5) << " is passed by value, it could be passed by reference/pointer instead";
|
||||
errmsg << FileLine(tok) << " " << Tokenizer::getstr(tok,5) << " is passed by value, it could be passed by reference/pointer instead";
|
||||
ReportErr( errmsg.str() );
|
||||
}
|
||||
|
||||
|
@ -600,18 +600,18 @@ void CheckConstantFunctionParameter()
|
|||
{
|
||||
// Check if type is a struct or class.
|
||||
const char *pattern[3] = {"class","type",0};
|
||||
pattern[1] = getstr(tok, 2);
|
||||
if ( findtoken(tokens, pattern) )
|
||||
pattern[1] = Tokenizer::getstr(tok, 2);
|
||||
if ( Tokenizer::findtoken(tokens, pattern) )
|
||||
{
|
||||
std::ostringstream errmsg;
|
||||
errmsg << FileLine(tok) << " " << getstr(tok,3) << " is passed by value, it could be passed by reference/pointer instead";
|
||||
errmsg << FileLine(tok) << " " << Tokenizer::getstr(tok,3) << " is passed by value, it could be passed by reference/pointer instead";
|
||||
ReportErr( errmsg.str() );
|
||||
}
|
||||
pattern[0] = "struct";
|
||||
if ( findtoken(tokens, pattern) )
|
||||
if ( Tokenizer::findtoken(tokens, pattern) )
|
||||
{
|
||||
std::ostringstream errmsg;
|
||||
errmsg << FileLine(tok) << " " << getstr(tok,3) << " is passed by value, it could be passed by reference/pointer instead";
|
||||
errmsg << FileLine(tok) << " " << Tokenizer::getstr(tok,3) << " is passed by value, it could be passed by reference/pointer instead";
|
||||
ReportErr( errmsg.str() );
|
||||
}
|
||||
}
|
||||
|
@ -635,19 +635,19 @@ void CheckStructMemberUsage()
|
|||
if ( tok->str[0] == '}' )
|
||||
structname = 0;
|
||||
if ( Match(tok, "struct %type% {") )
|
||||
structname = getstr(tok, 1);
|
||||
structname = Tokenizer::getstr(tok, 1);
|
||||
|
||||
if (structname && Match(tok, "[{;]"))
|
||||
{
|
||||
const char *varname = 0;
|
||||
if (Match(tok->next, "%type% %var% [;[]"))
|
||||
varname = getstr( tok, 2 );
|
||||
varname = Tokenizer::getstr( tok, 2 );
|
||||
else if (Match(tok->next, "%type% %type% %var% [;[]"))
|
||||
varname = getstr( tok, 2 );
|
||||
varname = Tokenizer::getstr( tok, 2 );
|
||||
else if (Match(tok->next, "%type% * %var% [;[]"))
|
||||
varname = getstr( tok, 3 );
|
||||
varname = Tokenizer::getstr( tok, 3 );
|
||||
else if (Match(tok->next, "%type% %type% * %var% [;[]"))
|
||||
varname = getstr( tok, 4 );
|
||||
varname = Tokenizer::getstr( tok, 4 );
|
||||
else
|
||||
continue;
|
||||
|
||||
|
@ -662,7 +662,7 @@ void CheckStructMemberUsage()
|
|||
|
||||
if (Match(tok2, ". %var%", varnames))
|
||||
{
|
||||
if ( strcmp("=", getstr(tok2,2)) == 0 )
|
||||
if ( strcmp("=", Tokenizer::getstr(tok2,2)) == 0 )
|
||||
continue;
|
||||
used = true;
|
||||
break;
|
||||
|
@ -695,7 +695,7 @@ void CheckCharVariable()
|
|||
if ( Match(tok, "[{};(,] char %var% [;=,)]") )
|
||||
{
|
||||
const char *varname[2] = {0};
|
||||
varname[0] = getstr(tok, 2);
|
||||
varname[0] = Tokenizer::getstr(tok, 2);
|
||||
|
||||
// Check usage of char variable..
|
||||
int indentlevel = 0;
|
||||
|
@ -755,14 +755,14 @@ void CheckIncompleteStatement()
|
|||
if ( parlevel != 0 )
|
||||
continue;
|
||||
|
||||
if ( !Match(tok,"#") && Match(tok->next,"; %str%") && !Match(gettok(tok,3), ",") )
|
||||
if ( !Match(tok,"#") && Match(tok->next,"; %str%") && !Match(Tokenizer::gettok(tok,3), ",") )
|
||||
{
|
||||
std::ostringstream errmsg;
|
||||
errmsg << FileLine(tok->next) << ": Redundant code: Found a statement that begins with string constant";
|
||||
ReportErr(errmsg.str());
|
||||
}
|
||||
|
||||
if ( !Match(tok,"#") && Match(tok->next,"; %num%") && !Match(gettok(tok,3), ",") )
|
||||
if ( !Match(tok,"#") && Match(tok->next,"; %num%") && !Match(Tokenizer::gettok(tok,3), ",") )
|
||||
{
|
||||
std::ostringstream errmsg;
|
||||
errmsg << FileLine(tok->next) << ": Redundant code: Found a statement that begins with numeric constant";
|
||||
|
|
|
@ -350,16 +350,16 @@ bool Match(const TOKEN *tok, const char pattern[], const char *varname1[], const
|
|||
|
||||
for ( int i = 1; varname[i]; i++ )
|
||||
{
|
||||
if ( ! gettok(tok, 2) )
|
||||
if ( ! Tokenizer::gettok(tok, 2) )
|
||||
return false;
|
||||
|
||||
if ( strcmp(getstr(tok, 1), ".") )
|
||||
if ( strcmp(Tokenizer::getstr(tok, 1), ".") )
|
||||
return false;
|
||||
|
||||
if ( strcmp(getstr(tok, 2), varname[i]) )
|
||||
if ( strcmp(Tokenizer::getstr(tok, 2), varname[i]) )
|
||||
return false;
|
||||
|
||||
tok = gettok(tok, 2);
|
||||
tok = Tokenizer::gettok(tok, 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
10
main.cpp
10
main.cpp
|
@ -158,7 +158,9 @@ int main(int argc, char* argv[])
|
|||
//---------------------------------------------------------------------------
|
||||
|
||||
static void CppCheck(const std::string &code, const char FileName[], unsigned int FileId)
|
||||
{
|
||||
{
|
||||
Tokenizer tokenizer;
|
||||
|
||||
OnlyReportUniqueErrors = true;
|
||||
|
||||
// Tokenize the file
|
||||
|
@ -166,7 +168,7 @@ static void CppCheck(const std::string &code, const char FileName[], unsigned in
|
|||
Files.clear();
|
||||
{
|
||||
std::istringstream istr(code);
|
||||
Tokenize(istr, FileName);
|
||||
tokenizer.Tokenize(istr, FileName);
|
||||
}
|
||||
|
||||
FillFunctionList(FileId);
|
||||
|
@ -192,7 +194,7 @@ static void CppCheck(const std::string &code, const char FileName[], unsigned in
|
|||
// WarningIncludeHeader();
|
||||
|
||||
|
||||
SimplifyTokenList();
|
||||
tokenizer.SimplifyTokenList();
|
||||
|
||||
// Memory leak
|
||||
CheckMemoryLeak();
|
||||
|
@ -264,7 +266,7 @@ static void CppCheck(const std::string &code, const char FileName[], unsigned in
|
|||
}
|
||||
|
||||
// Clean up tokens..
|
||||
DeallocateTokens();
|
||||
tokenizer.DeallocateTokens();
|
||||
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
|
@ -39,9 +39,10 @@ private:
|
|||
{
|
||||
// Tokenize..
|
||||
tokens = tokens_back = NULL;
|
||||
std::istringstream istr(code);
|
||||
TokenizeCode( istr );
|
||||
SimplifyTokenList();
|
||||
std::istringstream istr(code);
|
||||
Tokenizer tokenizer;
|
||||
tokenizer.TokenizeCode( istr );
|
||||
tokenizer.SimplifyTokenList();
|
||||
|
||||
// Fill function list
|
||||
FillFunctionList(0);
|
||||
|
@ -53,7 +54,7 @@ private:
|
|||
ShowAll = true;
|
||||
CheckBufferOverrun();
|
||||
|
||||
DeallocateTokens();
|
||||
tokenizer.DeallocateTokens();
|
||||
}
|
||||
|
||||
void run()
|
||||
|
|
|
@ -45,8 +45,9 @@ private:
|
|||
{
|
||||
// Tokenize..
|
||||
tokens = tokens_back = NULL;
|
||||
std::istringstream istr(code);
|
||||
TokenizeCode( istr );
|
||||
std::istringstream istr(code);
|
||||
Tokenizer tokenizer;
|
||||
tokenizer.TokenizeCode( istr );
|
||||
|
||||
// Fill function list
|
||||
FillFunctionList(0);
|
||||
|
@ -58,7 +59,7 @@ private:
|
|||
ShowAll = true;
|
||||
CheckCharVariable();
|
||||
|
||||
DeallocateTokens();
|
||||
tokenizer.DeallocateTokens();
|
||||
}
|
||||
|
||||
void array_index()
|
||||
|
|
|
@ -37,9 +37,10 @@ private:
|
|||
{
|
||||
// Tokenize..
|
||||
tokens = tokens_back = NULL;
|
||||
std::istringstream istr(code);
|
||||
TokenizeCode( istr );
|
||||
SimplifyTokenList();
|
||||
std::istringstream istr(code);
|
||||
Tokenizer tokenizer;
|
||||
tokenizer.TokenizeCode( istr );
|
||||
tokenizer.SimplifyTokenList();
|
||||
|
||||
// Clear the error buffer..
|
||||
errout.str("");
|
||||
|
@ -47,7 +48,7 @@ private:
|
|||
// Check for memory leaks..
|
||||
CheckConstructors();
|
||||
|
||||
DeallocateTokens();
|
||||
tokenizer.DeallocateTokens();
|
||||
}
|
||||
|
||||
void run()
|
||||
|
|
|
@ -41,8 +41,9 @@ private:
|
|||
{
|
||||
// Tokenize..
|
||||
tokens = tokens_back = NULL;
|
||||
std::istringstream istr(code);
|
||||
TokenizeCode( istr );
|
||||
std::istringstream istr(code);
|
||||
Tokenizer tokenizer;
|
||||
tokenizer.TokenizeCode( istr );
|
||||
//SimplifyTokenList(); <- this can't be used as it removes 'unsigned'
|
||||
|
||||
// Clear the error buffer..
|
||||
|
@ -52,7 +53,7 @@ private:
|
|||
ShowAll = true;
|
||||
CheckUnsignedDivision();
|
||||
|
||||
DeallocateTokens();
|
||||
tokenizer.DeallocateTokens();
|
||||
}
|
||||
|
||||
void run()
|
||||
|
|
|
@ -39,9 +39,10 @@ private:
|
|||
{
|
||||
// Tokenize..
|
||||
tokens = tokens_back = NULL;
|
||||
std::istringstream istr(code);
|
||||
TokenizeCode( istr );
|
||||
SimplifyTokenList();
|
||||
std::istringstream istr(code);
|
||||
Tokenizer tokenizer;
|
||||
tokenizer.TokenizeCode( istr );
|
||||
tokenizer.SimplifyTokenList();
|
||||
|
||||
// Clear the error buffer..
|
||||
errout.str("");
|
||||
|
@ -49,7 +50,7 @@ private:
|
|||
// Check for unused variables..
|
||||
CheckIncompleteStatement();
|
||||
|
||||
DeallocateTokens();
|
||||
tokenizer.DeallocateTokens();
|
||||
}
|
||||
|
||||
void run()
|
||||
|
|
|
@ -39,9 +39,10 @@ private:
|
|||
{
|
||||
// Tokenize..
|
||||
tokens = tokens_back = NULL;
|
||||
std::istringstream istr(code);
|
||||
TokenizeCode( istr );
|
||||
SimplifyTokenList();
|
||||
std::istringstream istr(code);
|
||||
Tokenizer tokenizer;
|
||||
tokenizer.TokenizeCode( istr );
|
||||
tokenizer.SimplifyTokenList();
|
||||
|
||||
// Clear the error buffer..
|
||||
errout.str("");
|
||||
|
@ -50,7 +51,7 @@ private:
|
|||
ShowAll = false;
|
||||
CheckMemoryLeak();
|
||||
|
||||
DeallocateTokens();
|
||||
tokenizer.DeallocateTokens();
|
||||
}
|
||||
|
||||
void run()
|
||||
|
|
|
@ -60,11 +60,12 @@ private:
|
|||
|
||||
// tokenize..
|
||||
tokens = tokens_back = NULL;
|
||||
std::istringstream istr(filedata);
|
||||
TokenizeCode(istr, 0);
|
||||
std::istringstream istr(filedata);
|
||||
Tokenizer tokenizer;
|
||||
tokenizer.TokenizeCode(istr, 0);
|
||||
|
||||
// Expected result..
|
||||
const char *expected[] =
|
||||
const char *expected[] =
|
||||
{
|
||||
"def",
|
||||
"str",
|
||||
|
@ -75,7 +76,7 @@ private:
|
|||
// Compare..
|
||||
ASSERT_EQUALS( true, cmptok(expected, tokens) );
|
||||
|
||||
DeallocateTokens();
|
||||
tokenizer.DeallocateTokens();
|
||||
}
|
||||
|
||||
|
||||
|
@ -85,13 +86,14 @@ private:
|
|||
|
||||
// tokenize..
|
||||
tokens = tokens_back = NULL;
|
||||
std::istringstream istr(filedata);
|
||||
TokenizeCode(istr, 0);
|
||||
std::istringstream istr(filedata);
|
||||
Tokenizer tokenizer;
|
||||
tokenizer.TokenizeCode(istr, 0);
|
||||
|
||||
// Expected result..
|
||||
ASSERT_EQUALS( std::string(10000,'a'), std::string(tokens->str) );
|
||||
|
||||
DeallocateTokens();
|
||||
tokenizer.DeallocateTokens();
|
||||
}
|
||||
|
||||
|
||||
|
@ -105,14 +107,15 @@ private:
|
|||
" $jump1:\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
|
||||
|
||||
// tokenize..
|
||||
tokens = tokens_back = NULL;
|
||||
std::istringstream istr(filedata);
|
||||
TokenizeCode(istr, 0);
|
||||
std::istringstream istr(filedata);
|
||||
Tokenizer tokenizer;
|
||||
tokenizer.TokenizeCode(istr, 0);
|
||||
|
||||
// Expected result..
|
||||
const char *expected[] =
|
||||
const char *expected[] =
|
||||
{
|
||||
"void",
|
||||
"foo",
|
||||
|
@ -126,7 +129,7 @@ private:
|
|||
// Compare..
|
||||
ASSERT_EQUALS( true, cmptok(expected, tokens) );
|
||||
|
||||
DeallocateTokens();
|
||||
tokenizer.DeallocateTokens();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -43,8 +43,9 @@ private:
|
|||
{
|
||||
// Tokenize..
|
||||
tokens = tokens_back = NULL;
|
||||
std::istringstream istr(code);
|
||||
TokenizeCode( istr );
|
||||
std::istringstream istr(code);
|
||||
Tokenizer tokenizer;
|
||||
tokenizer.TokenizeCode( istr );
|
||||
|
||||
// Clear the error buffer..
|
||||
errout.str("");
|
||||
|
@ -52,7 +53,7 @@ private:
|
|||
// Check for unused private functions..
|
||||
CheckUnusedPrivateFunctions();
|
||||
|
||||
DeallocateTokens();
|
||||
tokenizer.DeallocateTokens();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -40,8 +40,9 @@ private:
|
|||
// Tokenize..
|
||||
tokens = tokens_back = NULL;
|
||||
std::istringstream istr(code);
|
||||
TokenizeCode( istr );
|
||||
SimplifyTokenList();
|
||||
Tokenizer tokenizer;
|
||||
tokenizer.TokenizeCode( istr );
|
||||
tokenizer.SimplifyTokenList();
|
||||
|
||||
// Clear the error buffer..
|
||||
errout.str("");
|
||||
|
@ -49,7 +50,7 @@ private:
|
|||
// Check for unused variables..
|
||||
CheckStructMemberUsage();
|
||||
|
||||
DeallocateTokens();
|
||||
tokenizer.DeallocateTokens();
|
||||
}
|
||||
|
||||
void run()
|
||||
|
|
38
tokenize.cpp
38
tokenize.cpp
|
@ -45,15 +45,7 @@
|
|||
|
||||
// Helper functions..
|
||||
|
||||
static void Define(const char Name[], const char Value[]);
|
||||
|
||||
static void addtoken(const char str[], const unsigned int lineno, const unsigned int fileno);
|
||||
|
||||
static void combine_2tokens(TOKEN *tok, const char str1[], const char str2[]);
|
||||
|
||||
static void DeleteNextToken(TOKEN *tok);
|
||||
|
||||
static TOKEN *_gettok(TOKEN *tok, int index)
|
||||
TOKEN *Tokenizer::_gettok(TOKEN *tok, int index)
|
||||
{
|
||||
while (tok && index>0)
|
||||
{
|
||||
|
@ -88,7 +80,7 @@ struct DefineSymbol
|
|||
};
|
||||
static struct DefineSymbol * dsymlist;
|
||||
|
||||
static void Define(const char Name[], const char Value[])
|
||||
void Tokenizer::Define(const char Name[], const char Value[])
|
||||
{
|
||||
if (!(Name && Name[0]))
|
||||
return;
|
||||
|
@ -144,7 +136,7 @@ static void Define(const char Name[], const char Value[])
|
|||
// add a token. Used by 'Tokenizer'
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
static void addtoken(const char str[], const unsigned int lineno, const unsigned int fileno)
|
||||
void Tokenizer::addtoken(const char str[], const unsigned int lineno, const unsigned int fileno)
|
||||
{
|
||||
if (str[0] == 0)
|
||||
return;
|
||||
|
@ -197,7 +189,7 @@ static void addtoken(const char str[], const unsigned int lineno, const unsigned
|
|||
// Combine two tokens that belong to each other. Ex: "<" and "=" may become "<="
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
static void combine_2tokens(TOKEN *tok, const char str1[], const char str2[])
|
||||
void Tokenizer::combine_2tokens(TOKEN *tok, const char str1[], const char str2[])
|
||||
{
|
||||
if (!(tok && tok->next))
|
||||
return;
|
||||
|
@ -221,7 +213,7 @@ static void combine_2tokens(TOKEN *tok, const char str1[], const char str2[])
|
|||
|
||||
std::map<std::string, unsigned int> TypeSize;
|
||||
|
||||
int SizeOfType(const char type[])
|
||||
int Tokenizer::SizeOfType(const char type[])
|
||||
{
|
||||
if (!type)
|
||||
return 0;
|
||||
|
@ -238,7 +230,7 @@ int SizeOfType(const char type[])
|
|||
// DeleteNextToken. Unlink and delete next token.
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
static void DeleteNextToken(TOKEN *tok)
|
||||
void Tokenizer::DeleteNextToken(TOKEN *tok)
|
||||
{
|
||||
TOKEN *next = tok->next;
|
||||
tok->next = next->next;
|
||||
|
@ -255,7 +247,7 @@ static void DeleteNextToken(TOKEN *tok)
|
|||
// InsertTokens - Copy and insert tokens
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
static void InsertTokens(TOKEN *dest, TOKEN *src, unsigned int n)
|
||||
void Tokenizer::InsertTokens(TOKEN *dest, TOKEN *src, unsigned int n)
|
||||
{
|
||||
while (n > 0)
|
||||
{
|
||||
|
@ -282,7 +274,7 @@ static void InsertTokens(TOKEN *dest, TOKEN *src, unsigned int n)
|
|||
// Tokenize - tokenizes a given file.
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void Tokenize(std::istream &code, const char FileName[])
|
||||
void Tokenizer::Tokenize(std::istream &code, const char FileName[])
|
||||
{
|
||||
// Has this file been tokenized already?
|
||||
for (unsigned int i = 0; i < Files.size(); i++)
|
||||
|
@ -307,7 +299,7 @@ void Tokenize(std::istream &code, const char FileName[])
|
|||
// Tokenize - tokenizes input stream
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void TokenizeCode(std::istream &code, const unsigned int FileIndex)
|
||||
void Tokenizer::TokenizeCode(std::istream &code, const unsigned int FileIndex)
|
||||
{
|
||||
// Tokenize the file.
|
||||
unsigned int lineno = 1;
|
||||
|
@ -667,7 +659,7 @@ void TokenizeCode(std::istream &code, const unsigned int FileIndex)
|
|||
// Simplify token list
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void SimplifyTokenList()
|
||||
void Tokenizer::SimplifyTokenList()
|
||||
{
|
||||
|
||||
// Remove the keyword 'unsigned'
|
||||
|
@ -1025,7 +1017,7 @@ void SimplifyTokenList()
|
|||
// Helper functions for handling the tokens list
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
const TOKEN *findtoken(const TOKEN *tok1, const char *tokenstr[])
|
||||
const TOKEN *Tokenizer::findtoken(const TOKEN *tok1, const char *tokenstr[])
|
||||
{
|
||||
for (const TOKEN *ret = tok1; ret; ret = ret->next)
|
||||
{
|
||||
|
@ -1047,7 +1039,7 @@ const TOKEN *findtoken(const TOKEN *tok1, const char *tokenstr[])
|
|||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
const TOKEN *gettok(const TOKEN *tok, int index)
|
||||
const TOKEN *Tokenizer::gettok(const TOKEN *tok, int index)
|
||||
{
|
||||
while (tok && index>0)
|
||||
{
|
||||
|
@ -1058,7 +1050,7 @@ const TOKEN *gettok(const TOKEN *tok, int index)
|
|||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
const char *getstr(const TOKEN *tok, int index)
|
||||
const char *Tokenizer::getstr(const TOKEN *tok, int index)
|
||||
{
|
||||
tok = gettok(tok, index);
|
||||
return tok ? tok->str : "";
|
||||
|
@ -1068,7 +1060,7 @@ const char *getstr(const TOKEN *tok, int index)
|
|||
|
||||
|
||||
// Deallocate lists..
|
||||
void DeallocateTokens()
|
||||
void Tokenizer::DeallocateTokens()
|
||||
{
|
||||
while (tokens)
|
||||
{
|
||||
|
@ -1084,7 +1076,7 @@ void DeallocateTokens()
|
|||
free(dsymlist->name);
|
||||
free(dsymlist->value);
|
||||
delete dsymlist;
|
||||
dsymlist = next;
|
||||
dsymlist = next;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
75
tokenize.h
75
tokenize.h
|
@ -27,7 +27,8 @@
|
|||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
extern std::vector<std::string> Files;
|
||||
extern std::vector<std::string> Files;
|
||||
|
||||
|
||||
class TOKEN
|
||||
{
|
||||
|
@ -42,14 +43,14 @@ public:
|
|||
{ std::free(_str); }
|
||||
|
||||
void setstr( const char s[] )
|
||||
{
|
||||
{
|
||||
std::free(_str);
|
||||
#ifndef _MSC_VER
|
||||
_str = strdup(s);
|
||||
#else
|
||||
_str = _strdup(s);
|
||||
#endif
|
||||
str = _str ? _str : "";
|
||||
str = _str ? _str : "";
|
||||
}
|
||||
|
||||
const char *str;
|
||||
|
@ -57,30 +58,54 @@ public:
|
|||
unsigned int FileIndex;
|
||||
unsigned int linenr;
|
||||
TOKEN *next;
|
||||
};
|
||||
extern TOKEN *tokens, *tokens_back;
|
||||
};
|
||||
|
||||
extern TOKEN *tokens, *tokens_back;
|
||||
|
||||
class Tokenizer
|
||||
{
|
||||
public:
|
||||
|
||||
void Tokenize(std::istream &code, const char FileName[]);
|
||||
|
||||
// Deallocate lists..
|
||||
void DeallocateTokens();
|
||||
|
||||
// Simplify tokenlist
|
||||
// -----------------------------
|
||||
void SimplifyTokenList();
|
||||
|
||||
void TokenizeCode(std::istream &code, const unsigned int FileIndex=0);
|
||||
|
||||
// Helper functions for handling the tokens list..
|
||||
static const TOKEN *findtoken(const TOKEN *tok1, const char *tokenstr[]);
|
||||
static const TOKEN *gettok(const TOKEN *tok, int index);
|
||||
static const char *getstr(const TOKEN *tok, int index);
|
||||
|
||||
// Return size.
|
||||
static int SizeOfType(const char type[]);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
|
||||
|
||||
static void Define(const char Name[], const char Value[]);
|
||||
|
||||
static void addtoken(const char str[], const unsigned int lineno, const unsigned int fileno);
|
||||
|
||||
static void combine_2tokens(TOKEN *tok, const char str1[], const char str2[]);
|
||||
|
||||
static void DeleteNextToken(TOKEN *tok);
|
||||
|
||||
static TOKEN *_gettok(TOKEN *tok, int index);
|
||||
|
||||
static void InsertTokens(TOKEN *dest, TOKEN *src, unsigned int n);
|
||||
};
|
||||
|
||||
|
||||
|
||||
void Tokenize(std::istream &code, const char FileName[]);
|
||||
|
||||
void TokenizeCode(std::istream &code, const unsigned int FileIndex=0);
|
||||
|
||||
// Return size.
|
||||
int SizeOfType(const char type[]);
|
||||
|
||||
// Simplify tokenlist
|
||||
// -----------------------------
|
||||
void SimplifyTokenList();
|
||||
|
||||
|
||||
// Deallocate lists..
|
||||
void DeallocateTokens();
|
||||
|
||||
|
||||
// Helper functions for handling the tokens list..
|
||||
const TOKEN *findtoken(const TOKEN *tok1, const char *tokenstr[]);
|
||||
const TOKEN *gettok(const TOKEN *tok, int index);
|
||||
const char *getstr(const TOKEN *tok, int index);
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue