Refactoring: Tokenizer object given as a parameter to most of the classes
This commit is contained in:
parent
58f0f03449
commit
134985e410
|
@ -37,6 +37,15 @@ extern bool ShowAll;
|
|||
// CallStack used when parsing into subfunctions.
|
||||
static std::list<const TOKEN *> CallStack;
|
||||
|
||||
CheckBufferOverrunClass::CheckBufferOverrunClass( Tokenizer *tokenizer )
|
||||
{
|
||||
_tokenizer = tokenizer;
|
||||
}
|
||||
|
||||
CheckBufferOverrunClass::~CheckBufferOverrunClass()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Modified version of 'ReportError' that also reports the callstack
|
||||
void CheckBufferOverrunClass::ReportError(const TOKEN *tok, const char errmsg[])
|
||||
|
|
|
@ -27,6 +27,9 @@
|
|||
class CheckBufferOverrunClass
|
||||
{
|
||||
public:
|
||||
CheckBufferOverrunClass( Tokenizer *tokenizer );
|
||||
~CheckBufferOverrunClass();
|
||||
|
||||
// Buffer overrun..
|
||||
void CheckBufferOverrun();
|
||||
|
||||
|
@ -39,6 +42,7 @@ private:
|
|||
void CheckBufferOverrun_CheckScope( const TOKEN *tok, const char *varname[], const int size, const int total_size );
|
||||
void ReportError(const TOKEN *tok, const char errmsg[]);
|
||||
|
||||
Tokenizer *_tokenizer;
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
|
@ -101,6 +101,16 @@ struct VAR *CheckClass::ClassChecking_GetVarList(const TOKEN *tok1)
|
|||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
CheckClass::CheckClass( Tokenizer *tokenizer )
|
||||
{
|
||||
_tokenizer = tokenizer;
|
||||
}
|
||||
|
||||
CheckClass::~CheckClass()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
const TOKEN * CheckClass::FindClassFunction( const TOKEN *tok, const char classname[], const char funcname[], int &indentlevel )
|
||||
{
|
||||
const char *_classname[2] = {0,0};
|
||||
|
|
|
@ -34,6 +34,9 @@ struct VAR
|
|||
class CheckClass
|
||||
{
|
||||
public:
|
||||
CheckClass( Tokenizer *tokenizer );
|
||||
~CheckClass();
|
||||
|
||||
void CheckConstructors();
|
||||
|
||||
void CheckUnusedPrivateFunctions();
|
||||
|
@ -47,6 +50,8 @@ private:
|
|||
void InitVar(struct VAR *varlist, const char varname[]);
|
||||
const TOKEN *FindClassFunction( const TOKEN *tok, const char classname[], const char funcname[], int &indentlevel );
|
||||
struct VAR *ClassChecking_GetVarList(const TOKEN *tok1);
|
||||
|
||||
Tokenizer *_tokenizer;
|
||||
};
|
||||
//---------------------------------------------------------------------------
|
||||
#endif
|
||||
|
|
|
@ -35,6 +35,16 @@
|
|||
// HEADERS - No implementation in a header
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
CheckHeaders::CheckHeaders( Tokenizer *tokenizer )
|
||||
{
|
||||
_tokenizer = tokenizer;
|
||||
}
|
||||
|
||||
CheckHeaders::~CheckHeaders()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CheckHeaders::WarningHeaderWithImplementation()
|
||||
{
|
||||
for (TOKEN *tok = tokens; tok; tok = tok->next)
|
||||
|
|
|
@ -22,12 +22,18 @@
|
|||
#define CheckHeadersH
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#include "tokenize.h"
|
||||
|
||||
class CheckHeaders
|
||||
{
|
||||
public:
|
||||
CheckHeaders( Tokenizer *tokenizer );
|
||||
~CheckHeaders();
|
||||
void WarningHeaderWithImplementation();
|
||||
void WarningIncludeHeader();
|
||||
|
||||
private:
|
||||
Tokenizer *_tokenizer;
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
|
@ -41,6 +41,16 @@
|
|||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
CheckMemoryLeakClass::CheckMemoryLeakClass( Tokenizer *tokenizer )
|
||||
{
|
||||
_tokenizer = tokenizer;
|
||||
}
|
||||
|
||||
CheckMemoryLeakClass::~CheckMemoryLeakClass()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool CheckMemoryLeakClass::isclass( const std::string &typestr )
|
||||
{
|
||||
if ( typestr == "char" ||
|
||||
|
|
|
@ -33,6 +33,8 @@ enum AllocType { No, Malloc, gMalloc, New, NewA };
|
|||
class CheckMemoryLeakClass
|
||||
{
|
||||
public:
|
||||
CheckMemoryLeakClass( Tokenizer *tokenizer );
|
||||
~CheckMemoryLeakClass();
|
||||
void CheckMemoryLeak();
|
||||
|
||||
private:
|
||||
|
@ -53,6 +55,8 @@ private:
|
|||
AllocType GetDeallocationType( const TOKEN *tok, const char *varnames[] );
|
||||
AllocType GetAllocationType( const TOKEN *tok2 );
|
||||
bool isclass( const std::string &typestr );
|
||||
|
||||
Tokenizer *_tokenizer;
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
|
@ -35,6 +35,16 @@
|
|||
// Warning on C-Style casts.. p = (kalle *)foo;
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
CheckOther::CheckOther( Tokenizer *tokenizer )
|
||||
{
|
||||
_tokenizer = tokenizer;
|
||||
}
|
||||
|
||||
CheckOther::~CheckOther()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CheckOther::WarningOldStylePointerCast()
|
||||
{
|
||||
for (const TOKEN *tok = tokens; tok; tok = tok->next)
|
||||
|
|
|
@ -28,6 +28,9 @@
|
|||
class CheckOther
|
||||
{
|
||||
public:
|
||||
CheckOther( Tokenizer *tokenizer );
|
||||
~CheckOther();
|
||||
|
||||
// Casting
|
||||
void WarningOldStylePointerCast();
|
||||
|
||||
|
@ -71,6 +74,8 @@ public:
|
|||
void CheckIncompleteStatement();
|
||||
private:
|
||||
void CheckVariableScope_LookupVar( const TOKEN *tok1, const char varname[] );
|
||||
|
||||
Tokenizer *_tokenizer;
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
10
main.cpp
10
main.cpp
|
@ -177,13 +177,13 @@ static void CppCheck(const std::string &code, const char FileName[], unsigned in
|
|||
// Check that the memsets are valid.
|
||||
// The 'memset' function can do dangerous things if used wrong.
|
||||
// Important: The checking doesn't work on simplified tokens list.
|
||||
CheckClass checkClass;
|
||||
CheckClass checkClass( &tokenizer );
|
||||
checkClass.CheckMemset();
|
||||
|
||||
|
||||
// Check for unsigned divisions where one operand is signed
|
||||
// Very important to run it before 'SimplifyTokenList'
|
||||
CheckOther checkOther;
|
||||
CheckOther checkOther( &tokenizer );
|
||||
checkOther.CheckUnsignedDivision();
|
||||
|
||||
// Give warning when using char variable as array index
|
||||
|
@ -195,7 +195,7 @@ static void CppCheck(const std::string &code, const char FileName[], unsigned in
|
|||
// Including header which is not needed (too many false positives)
|
||||
// if ( CheckCodingStyle )
|
||||
// {
|
||||
// CheckHeaders checkHeaders;
|
||||
// CheckHeaders checkHeaders( &tokenizer );
|
||||
// checkHeaders.WarningIncludeHeader();
|
||||
// }
|
||||
|
||||
|
@ -203,11 +203,11 @@ static void CppCheck(const std::string &code, const char FileName[], unsigned in
|
|||
tokenizer.SimplifyTokenList();
|
||||
|
||||
// Memory leak
|
||||
CheckMemoryLeakClass checkMemoryLeak;
|
||||
CheckMemoryLeakClass checkMemoryLeak( &tokenizer );
|
||||
checkMemoryLeak.CheckMemoryLeak();
|
||||
|
||||
// Buffer overruns..
|
||||
CheckBufferOverrunClass checkBufferOverrun;
|
||||
CheckBufferOverrunClass checkBufferOverrun( &tokenizer );
|
||||
checkBufferOverrun.CheckBufferOverrun();
|
||||
|
||||
// Check that all class constructors are ok.
|
||||
|
|
|
@ -52,7 +52,7 @@ private:
|
|||
|
||||
// Check for memory leaks..
|
||||
ShowAll = true;
|
||||
CheckBufferOverrunClass checkBufferOverrun;
|
||||
CheckBufferOverrunClass checkBufferOverrun( &tokenizer );
|
||||
checkBufferOverrun.CheckBufferOverrun();
|
||||
|
||||
tokenizer.DeallocateTokens();
|
||||
|
|
|
@ -57,7 +57,7 @@ private:
|
|||
|
||||
// Check for memory leaks..
|
||||
ShowAll = true;
|
||||
CheckOther checkOther;
|
||||
CheckOther checkOther( &tokenizer );
|
||||
checkOther.CheckCharVariable();
|
||||
|
||||
tokenizer.DeallocateTokens();
|
||||
|
|
|
@ -46,7 +46,7 @@ private:
|
|||
errout.str("");
|
||||
|
||||
// Check for memory leaks..
|
||||
CheckClass checkClass;
|
||||
CheckClass checkClass( &tokenizer );
|
||||
checkClass.CheckConstructors();
|
||||
|
||||
tokenizer.DeallocateTokens();
|
||||
|
|
|
@ -51,7 +51,7 @@ private:
|
|||
|
||||
// Check for memory leaks..
|
||||
ShowAll = true;
|
||||
CheckOther checkOther;
|
||||
CheckOther checkOther( &tokenizer );
|
||||
checkOther.CheckUnsignedDivision();
|
||||
|
||||
tokenizer.DeallocateTokens();
|
||||
|
|
|
@ -48,7 +48,7 @@ private:
|
|||
errout.str("");
|
||||
|
||||
// Check for unused variables..
|
||||
CheckOther checkOther;
|
||||
CheckOther checkOther( &tokenizer );
|
||||
checkOther.CheckIncompleteStatement();
|
||||
|
||||
tokenizer.DeallocateTokens();
|
||||
|
|
|
@ -51,7 +51,7 @@ private:
|
|||
// Check for memory leaks..
|
||||
ShowAll = false;
|
||||
FillFunctionList(0);
|
||||
CheckMemoryLeakClass checkMemoryLeak;
|
||||
CheckMemoryLeakClass checkMemoryLeak( &tokenizer );
|
||||
checkMemoryLeak.CheckMemoryLeak();
|
||||
|
||||
tokenizer.DeallocateTokens();
|
||||
|
|
|
@ -54,7 +54,7 @@ private:
|
|||
errout.str("");
|
||||
|
||||
// Check for unused private functions..
|
||||
CheckClass checkClass;
|
||||
CheckClass checkClass( &tokenizer );
|
||||
checkClass.CheckUnusedPrivateFunctions();
|
||||
|
||||
tokenizer.DeallocateTokens();
|
||||
|
|
|
@ -48,7 +48,7 @@ private:
|
|||
errout.str("");
|
||||
|
||||
// Check for unused variables..
|
||||
CheckOther checkOther;
|
||||
CheckOther checkOther( &tokenizer );
|
||||
checkOther.CheckStructMemberUsage();
|
||||
|
||||
tokenizer.DeallocateTokens();
|
||||
|
|
|
@ -85,7 +85,9 @@ public:
|
|||
// Return size.
|
||||
static int SizeOfType(const char type[]);
|
||||
|
||||
|
||||
std::vector<std::string> _files;
|
||||
TOKEN *_tokens;
|
||||
TOKEN *_tokens_back;
|
||||
private:
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue