Skip to content

Commit 1bef8d1

Browse files
PKEuSDaniel Marjamäki
authored andcommitted
Tokenizer: Code cleanups
1 parent 149ff35 commit 1bef8d1

9 files changed

Lines changed: 8 additions & 54 deletions

lib/cppcheck.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,15 @@
1717
*/
1818
#include "cppcheck.h"
1919

20-
#include "preprocessor.h" // preprocessor.
21-
#include "tokenize.h" // <- Tokenizer
20+
#include "preprocessor.h" // Preprocessor
21+
#include "tokenize.h" // Tokenizer
2222

2323
#include "check.h"
2424
#include "path.h"
2525

2626
#include <algorithm>
27-
#include <iostream>
2827
#include <fstream>
2928
#include <stdexcept>
30-
#include <ctime>
3129
#include "timer.h"
3230

3331
#ifdef HAVE_RULES
@@ -335,10 +333,6 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
335333
return;
336334
}
337335

338-
Timer timer2("Tokenizer::fillFunctionList", _settings._showtime, &S_timerResults);
339-
_tokenizer.fillFunctionList();
340-
timer2.Stop();
341-
342336
// call all "runChecks" in all registered Check classes
343337
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) {
344338
if (_settings.terminated())
@@ -357,10 +351,6 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
357351
if (!result)
358352
return;
359353

360-
Timer timer4("Tokenizer::fillFunctionList", _settings._showtime, &S_timerResults);
361-
_tokenizer.fillFunctionList();
362-
timer4.Stop();
363-
364354
// call all "runSimplifiedChecks" in all registered Check classes
365355
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) {
366356
if (_settings.terminated())

lib/tokenize.cpp

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2587,35 +2587,28 @@ void Tokenizer::labels()
25872587
if (Token::Match(tok, ") const| {")) {
25882588
// Simplify labels in the executable scope..
25892589
unsigned int indentlevel = 0;
2590-
unsigned int indentroundbraces = 0;
25912590
while (NULL != (tok = tok->next())) {
25922591
if (tok->str() == "{")
25932592
++indentlevel;
25942593
else if (tok->str() == "}") {
25952594
--indentlevel;
25962595
if (!indentlevel)
25972596
break;
2598-
}
2597+
} else if (tok->str() == "(")
2598+
tok = tok->link();
25992599

2600-
if (tok->str() == "(")
2601-
++indentroundbraces;
2602-
else if (tok->str() == ")") {
2603-
if (!indentroundbraces)
2604-
break;
2605-
--indentroundbraces;
2606-
}
2607-
if (!indentroundbraces && tok->str() == "case") {
2600+
else if (tok->str() == "case") {
26082601
while (NULL != (tok = tok->next())) {
26092602
if (tok->str() == ":")
26102603
break;
26112604
}
2612-
if (!(tok->next()) || tok->next()->str() != ";") {
2605+
if (tok && (!(tok->next()) || tok->next()->str() != ";")) {
26132606
tok->insertToken(";");
26142607
tok = tok->next();
26152608
}
26162609
}
26172610
// simplify label.. except for unhandled macro
2618-
if (!indentroundbraces && Token::Match(tok, "[;{}] %var% :")
2611+
if (Token::Match(tok, "[;{}] %var% :")
26192612
&& !Token::Match(tok->next(), "public|protected|private")
26202613
&& tok->strAt(3) != ";") {
26212614
for (Token *tok2 = tok->tokAt(3); tok2; tok2 = tok2->next()) {
@@ -7004,7 +6997,7 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
70046997
if (Token::Match(tok3, ("%var% ( " + structname + " %varid% ,").c_str(), varid)) {
70056998
const char * const functionName[] = {
70066999
"memcmp","memcpy","memmove","memset",
7007-
"strcmp","strcpy","strncpy","strdup"
7000+
"strcmp","strcpy","strncmp","strncpy","strdup"
70087001
};
70097002
for (unsigned int i = 0; i < (sizeof(functionName) / sizeof(*functionName)); ++i) {
70107003
if (tok3->str() == functionName[i]) {
@@ -8277,12 +8270,6 @@ const Token *Tokenizer::getFunctionTokenByName(const char funcname[]) const
82778270
return NULL;
82788271
}
82798272

8280-
8281-
void Tokenizer::fillFunctionList()
8282-
{
8283-
getSymbolDatabase();
8284-
}
8285-
82868273
//---------------------------------------------------------------------------
82878274

82888275
// Deallocate lists..

lib/tokenize.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <list>
2828
#include <vector>
2929
#include <set>
30-
#include <iosfwd>
3130

3231
class Token;
3332
class ErrorLogger;
@@ -181,9 +180,6 @@ class Tokenizer {
181180
*/
182181
const std::vector<std::string> *getFiles() const;
183182

184-
/** recreate symbol database */
185-
void fillFunctionList();
186-
187183
/**
188184
* Get function token by function name
189185
* @todo better handling of overloaded functions

test/testautovariables.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ class TestAutoVariables : public TestFixture {
5454
// Assign variable ids
5555
tokenizer.setVarId();
5656

57-
// Fill function list
58-
tokenizer.fillFunctionList();
59-
6057
// Check auto variables
6158
checkAutoVariables.autoVariables();
6259
checkAutoVariables.returnPointerToLocalArray();

test/testbufferoverrun.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ class TestBufferOverrun : public TestFixture {
5454
// Assign variable ids
5555
tokenizer.simplifyTokenList();
5656

57-
// Fill function list
58-
tokenizer.fillFunctionList();
59-
6057
// Check for buffer overruns..
6158
CheckBufferOverrun checkBufferOverrun(&tokenizer, &settings, this);
6259
checkBufferOverrun.bufferOverrun();

test/testmemleak.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ class TestMemleakInFunction : public TestFixture {
135135
tokenizer.setVarId();
136136
tokenizer.simplifyTokenList();
137137

138-
tokenizer.fillFunctionList();
139-
140138
// Check for memory leaks..
141139
CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, this);
142140
checkMemoryLeak.checkReallocUsage();
@@ -3789,8 +3787,6 @@ class TestMemleakInClass : public TestFixture {
37893787
tokenizer.setVarId();
37903788
tokenizer.simplifyTokenList();
37913789

3792-
tokenizer.fillFunctionList();
3793-
37943790
// Check for memory leaks..
37953791
CheckMemoryLeakInClass checkMemoryLeak(&tokenizer, &settings, this);
37963792
checkMemoryLeak.check();

test/testnonreentrantfunctions.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ class TestNonReentrantFunctions : public TestFixture {
5454
// Assign variable ids
5555
tokenizer.setVarId();
5656

57-
// Fill function list
58-
tokenizer.fillFunctionList();
59-
6057
// Check for non reentrant functions..
6158
CheckNonReentrantFunctions checkNonReentrantFunctions(&tokenizer, &settings, this);
6259
checkNonReentrantFunctions.nonReentrantFunctions();

test/testobsoletefunctions.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ class TestObsoleteFunctions : public TestFixture {
8686
// Assign variable ids
8787
tokenizer.setVarId();
8888

89-
// Fill function list
90-
tokenizer.fillFunctionList();
91-
9289
// Check for obsolete functions..
9390
CheckObsoleteFunctions checkObsoleteFunctions(&tokenizer, &settings, this);
9491
checkObsoleteFunctions.obsoleteFunctions();

test/testpostfixoperator.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ class TestPostfixOperator : public TestFixture {
5151
// Assign variable ids
5252
tokenizer.setVarId();
5353

54-
// Fill function list
55-
tokenizer.fillFunctionList();
56-
5754
// Check for postfix operators..
5855
CheckPostfixOperator checkPostfixOperator(&tokenizer, &settings, this);
5956
checkPostfixOperator.postfixOperator();

0 commit comments

Comments
 (0)