Refactoring: Tokenizer object given as a parameter to most of the classes

This commit is contained in:
Reijo Tomperi 2008-11-12 21:34:47 +00:00
parent 58f0f03449
commit 134985e410
20 changed files with 96 additions and 21 deletions

View File

@ -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[])

View File

@ -26,7 +26,10 @@
class CheckBufferOverrunClass
{
public:
public:
CheckBufferOverrunClass( Tokenizer *tokenizer );
~CheckBufferOverrunClass();
// Buffer overrun..
void CheckBufferOverrun();
@ -38,7 +41,8 @@ private:
void CheckBufferOverrun_LocalVariable();
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;
};
//---------------------------------------------------------------------------

View File

@ -100,6 +100,16 @@ struct VAR *CheckClass::ClassChecking_GetVarList(const TOKEN *tok1)
return varlist;
}
//---------------------------------------------------------------------------
CheckClass::CheckClass( Tokenizer *tokenizer )
{
_tokenizer = tokenizer;
}
CheckClass::~CheckClass()
{
}
const TOKEN * CheckClass::FindClassFunction( const TOKEN *tok, const char classname[], const char funcname[], int &indentlevel )
{

View File

@ -33,7 +33,10 @@ struct VAR
class CheckClass
{
public:
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

View File

@ -34,6 +34,16 @@
//---------------------------------------------------------------------------
// HEADERS - No implementation in a header
//---------------------------------------------------------------------------
CheckHeaders::CheckHeaders( Tokenizer *tokenizer )
{
_tokenizer = tokenizer;
}
CheckHeaders::~CheckHeaders()
{
}
void CheckHeaders::WarningHeaderWithImplementation()
{

View File

@ -22,12 +22,18 @@
#define CheckHeadersH
//---------------------------------------------------------------------------
#include "tokenize.h"
class CheckHeaders
{
public:
public:
CheckHeaders( Tokenizer *tokenizer );
~CheckHeaders();
void WarningHeaderWithImplementation();
void WarningIncludeHeader();
private:
Tokenizer *_tokenizer;
};
//---------------------------------------------------------------------------

View File

@ -40,6 +40,16 @@
#endif
//---------------------------------------------------------------------------
CheckMemoryLeakClass::CheckMemoryLeakClass( Tokenizer *tokenizer )
{
_tokenizer = tokenizer;
}
CheckMemoryLeakClass::~CheckMemoryLeakClass()
{
}
bool CheckMemoryLeakClass::isclass( const std::string &typestr )
{

View File

@ -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;
};
//---------------------------------------------------------------------------

View File

@ -34,6 +34,16 @@
//---------------------------------------------------------------------------
// Warning on C-Style casts.. p = (kalle *)foo;
//---------------------------------------------------------------------------
CheckOther::CheckOther( Tokenizer *tokenizer )
{
_tokenizer = tokenizer;
}
CheckOther::~CheckOther()
{
}
void CheckOther::WarningOldStylePointerCast()
{

View File

@ -27,7 +27,10 @@
class CheckOther
{
public:
public:
CheckOther( Tokenizer *tokenizer );
~CheckOther();
// Casting
void WarningOldStylePointerCast();
@ -70,7 +73,9 @@ public:
// Incomplete statement. A statement that only contains a constant or variable
void CheckIncompleteStatement();
private:
void CheckVariableScope_LookupVar( const TOKEN *tok1, const char varname[] );
void CheckVariableScope_LookupVar( const TOKEN *tok1, const char varname[] );
Tokenizer *_tokenizer;
};
//---------------------------------------------------------------------------

View File

@ -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.

View File

@ -52,7 +52,7 @@ private:
// Check for memory leaks..
ShowAll = true;
CheckBufferOverrunClass checkBufferOverrun;
CheckBufferOverrunClass checkBufferOverrun( &tokenizer );
checkBufferOverrun.CheckBufferOverrun();
tokenizer.DeallocateTokens();

View File

@ -57,7 +57,7 @@ private:
// Check for memory leaks..
ShowAll = true;
CheckOther checkOther;
CheckOther checkOther( &tokenizer );
checkOther.CheckCharVariable();
tokenizer.DeallocateTokens();

View File

@ -46,7 +46,7 @@ private:
errout.str("");
// Check for memory leaks..
CheckClass checkClass;
CheckClass checkClass( &tokenizer );
checkClass.CheckConstructors();
tokenizer.DeallocateTokens();

View File

@ -51,7 +51,7 @@ private:
// Check for memory leaks..
ShowAll = true;
CheckOther checkOther;
CheckOther checkOther( &tokenizer );
checkOther.CheckUnsignedDivision();
tokenizer.DeallocateTokens();

View File

@ -48,7 +48,7 @@ private:
errout.str("");
// Check for unused variables..
CheckOther checkOther;
CheckOther checkOther( &tokenizer );
checkOther.CheckIncompleteStatement();
tokenizer.DeallocateTokens();

View File

@ -51,7 +51,7 @@ private:
// Check for memory leaks..
ShowAll = false;
FillFunctionList(0);
CheckMemoryLeakClass checkMemoryLeak;
CheckMemoryLeakClass checkMemoryLeak( &tokenizer );
checkMemoryLeak.CheckMemoryLeak();
tokenizer.DeallocateTokens();

View File

@ -54,7 +54,7 @@ private:
errout.str("");
// Check for unused private functions..
CheckClass checkClass;
CheckClass checkClass( &tokenizer );
checkClass.CheckUnusedPrivateFunctions();
tokenizer.DeallocateTokens();

View File

@ -48,7 +48,7 @@ private:
errout.str("");
// Check for unused variables..
CheckOther checkOther;
CheckOther checkOther( &tokenizer );
checkOther.CheckStructMemberUsage();
tokenizer.DeallocateTokens();

View File

@ -85,7 +85,9 @@ public:
// Return size.
static int SizeOfType(const char type[]);
std::vector<std::string> _files;
TOKEN *_tokens;
TOKEN *_tokens_back;
private: