From 9b56be86c6c9bea74d686dd5fca63d7426b56eec Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Mon, 1 Dec 2008 22:33:21 +0000 Subject: [PATCH] Minor improvement to code comments. --- CheckMemoryLeak.cpp | 18 +++--------------- CheckMemoryLeak.h | 27 +++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/CheckMemoryLeak.cpp b/CheckMemoryLeak.cpp index c99a77c00..651c82186 100644 --- a/CheckMemoryLeak.cpp +++ b/CheckMemoryLeak.cpp @@ -283,12 +283,6 @@ bool CheckMemoryLeakClass::notvar(const TOKEN *tok, const char *varnames[]) TOKEN::Match(tok, "%var1% == 0", varnames) ); } -/** - * Extract a new tokens list that is easier to parse than the "tokens" - * tok - start parse token - * varname - name of variable - */ - TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, std::list callstack, const char varname[], AllocType &alloctype, AllocType &dealloctype) { const char *varnames[2]; @@ -385,7 +379,7 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, std::list TOKEN::Match(tok, "if ( 0 != %var1% )", varnames) ) { addtoken("if(var)"); - + // Make sure the "use" will not be added while ( tok->str() != ")" ) tok = tok->next; @@ -533,12 +527,6 @@ void CheckMemoryLeakClass::erase(TOKEN *begin, const TOKEN *end) } } - - -/** - * Simplify code - * \param tok first token - */ void CheckMemoryLeakClass::simplifycode(TOKEN *tok) { // reduce the code.. @@ -636,14 +624,14 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok) { erase(tok2, tok2->tokAt(2)); done = false; - } + } // Delete if block: "alloc; if return use ;" if (TOKEN::Match(tok2,"alloc ; if return use ;") && !TOKEN::Match(tok2->tokAt(6),"else")) { erase(tok2, tok2->tokAt(5)); done = false; - } + } // Reduce "if return ; alloc ;" => "alloc ;" diff --git a/CheckMemoryLeak.h b/CheckMemoryLeak.h index 6800b0001..4f34c3e62 100644 --- a/CheckMemoryLeak.h +++ b/CheckMemoryLeak.h @@ -61,9 +61,32 @@ private: void CheckMemoryLeak_ClassMembers(); void CheckMemoryLeak_InFunction(); void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[] ); - void simplifycode(TOKEN *tok); + + /** + * Simplify code e.g. by replacing empty "{ }" with ";" + * @param tok first token. The tokens list can be modified. + */ + void simplifycode(TOKEN *tok); + + /** + * Delete tokens between begin and end. E.g. if begin = 1 + * and end = 5, tokens 2,3 and 4 would be erased. + * + * @param begin Tokens after this will be erased. + * @param end Tokens before this will be erased. + */ void erase(TOKEN *begin, const TOKEN *end); - + + /** + * Extract a new tokens list that is easier to parse than the "tokens" + * @param tok start parse token + * @param callstack callstack + * @param varname name of variable + * @param alloctype + * @param dealloctype + * @return Newly allocated token array. Caller needs to release reserved + * memory by calling Tokenizer::deleteTokens(returnValue); + */ TOKEN *getcode(const TOKEN *tok, std::list callstack, const char varname[], AllocType &alloctype, AllocType &dealloctype); bool notvar(const TOKEN *tok, const char *varnames[]); void instoken(TOKEN *tok, const char str[]);