Skip to content

Commit e5f7f76

Browse files
committed
removed type debug validation
1 parent 739a167 commit e5f7f76

3 files changed

Lines changed: 0 additions & 133 deletions

File tree

lib/tokenize.cpp

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -3441,8 +3441,6 @@ bool Tokenizer::simplifyTokens1(const std::string &configuration)
34413441
mSymbolDatabase->setArrayDimensionsUsingValueFlow();
34423442
}
34433443

3444-
validateTypes();
3445-
34463444
printDebugOutput(1, std::cout);
34473445

34483446
return true;
@@ -5927,31 +5925,6 @@ void Tokenizer::printDebugOutput(int simplification, std::ostream &out) const
59275925
}
59285926
}
59295927

5930-
void Tokenizer::validateTypes() const
5931-
{
5932-
if (!mSymbolDatabase || !mSettings.debugwarnings)
5933-
return;
5934-
5935-
printUnknownTypes();
5936-
5937-
// the typeStartToken() should come before typeEndToken()
5938-
for (const Variable *var : mSymbolDatabase->variableList()) {
5939-
if (!var)
5940-
continue;
5941-
5942-
const Token * typetok = var->typeStartToken();
5943-
while (typetok && typetok != var->typeEndToken())
5944-
typetok = typetok->next();
5945-
5946-
if (typetok != var->typeEndToken()) {
5947-
reportError(var->typeStartToken(),
5948-
Severity::debug,
5949-
"debug",
5950-
"Variable::typeStartToken() of variable '" + var->name() + "' is not located before Variable::typeEndToken(). The location of the typeStartToken() is '" + var->typeStartToken()->str() + "' at line " + std::to_string(var->typeStartToken()->linenr()));
5951-
}
5952-
}
5953-
}
5954-
59555928
void Tokenizer::dump(std::ostream &out) const
59565929
{
59575930
// Create a xml data dump.
@@ -10581,84 +10554,6 @@ void Tokenizer::removeUnnecessaryQualification()
1058110554
}
1058210555
}
1058310556

10584-
void Tokenizer::printUnknownTypes() const
10585-
{
10586-
if (!mSymbolDatabase)
10587-
return;
10588-
10589-
std::vector<std::pair<std::string, const Token *>> unknowns;
10590-
10591-
for (int i = 1; i <= mVarId; ++i) {
10592-
const Variable *var = mSymbolDatabase->getVariableFromVarId(i);
10593-
if (!var)
10594-
continue;
10595-
// is unknown type?
10596-
if (var->type() || var->typeStartToken()->isStandardType())
10597-
continue;
10598-
10599-
std::string name;
10600-
const Token * nameTok;
10601-
10602-
// single token type?
10603-
if (var->typeStartToken() == var->typeEndToken()) {
10604-
nameTok = var->typeStartToken();
10605-
name = nameTok->str();
10606-
}
10607-
10608-
// complicated type
10609-
else {
10610-
const Token *tok = var->typeStartToken();
10611-
int level = 0;
10612-
10613-
nameTok = tok;
10614-
10615-
while (tok) {
10616-
// skip pointer and reference part of type
10617-
if (level == 0 && Token::Match(tok, "*|&"))
10618-
break;
10619-
10620-
name += tok->str();
10621-
10622-
if (Token::Match(tok, "struct|union|enum"))
10623-
name += " ";
10624-
10625-
// pointers and references are OK in template
10626-
else if (tok->str() == "<")
10627-
++level;
10628-
else if (tok->str() == ">")
10629-
--level;
10630-
10631-
if (tok == var->typeEndToken())
10632-
break;
10633-
10634-
tok = tok->next();
10635-
}
10636-
}
10637-
10638-
unknowns.emplace_back(std::move(name), nameTok);
10639-
}
10640-
10641-
if (!unknowns.empty()) {
10642-
std::string last;
10643-
int count = 0;
10644-
10645-
for (auto it = unknowns.cbegin(); it != unknowns.cend(); ++it) {
10646-
// skip types is std namespace because they are not interesting
10647-
if (it->first.find("std::") != 0) {
10648-
if (it->first != last) {
10649-
last = it->first;
10650-
count = 1;
10651-
reportError(it->second, Severity::debug, "debug", "Unknown type \'" + it->first + "\'.");
10652-
} else {
10653-
if (count < 3) // limit same type to 3
10654-
reportError(it->second, Severity::debug, "debug", "Unknown type \'" + it->first + "\'.");
10655-
count++;
10656-
}
10657-
}
10658-
}
10659-
}
10660-
}
10661-
1066210557
void Tokenizer::prepareTernaryOpForAST()
1066310558
{
1066410559
// http://en.cppreference.com/w/cpp/language/operator_precedence says about ternary operator:

lib/tokenize.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -546,18 +546,11 @@ class CPPCHECKLIB Tokenizer {
546546
std::map<nonneg int, std::map<std::string, nonneg int>>& structMembers,
547547
nonneg int &varId_);
548548

549-
/**
550-
* Output list of unknown types.
551-
*/
552-
void printUnknownTypes() const;
553-
554549
/** Find end of SQL (or PL/SQL) block */
555550
static const Token *findSQLBlockEnd(const Token *tokSQLStart);
556551

557552
static bool operatorEnd(const Token * tok);
558553

559-
void validateTypes() const;
560-
561554
public:
562555
const SymbolDatabase *getSymbolDatabase() const {
563556
return mSymbolDatabase;

test/testtokenize.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,6 @@ class TestTokenizer : public TestFixture {
432432
// --check-config
433433
TEST_CASE(checkConfiguration);
434434

435-
TEST_CASE(unknownType); // #8952
436-
437435
TEST_CASE(unknownMacroBeforeReturn);
438436

439437
TEST_CASE(cppcast);
@@ -7917,25 +7915,6 @@ class TestTokenizer : public TestFixture {
79177915
"There is an unknown macro here somewhere. Configuration is required. If DEBUG is a macro then please configure it.");
79187916
}
79197917

7920-
void unknownType() { // #8952
7921-
const Settings settings = settingsBuilder().debugwarnings().build();
7922-
7923-
char code[] = "class A {\n"
7924-
"public:\n"
7925-
" enum Type { Null };\n"
7926-
"};\n"
7927-
"using V = A;\n"
7928-
"V::Type value;";
7929-
7930-
// Tokenize..
7931-
SimpleTokenizer tokenizer(settings, *this);
7932-
ASSERT(tokenizer.tokenize(code));
7933-
7934-
tokenizer.printUnknownTypes();
7935-
7936-
ASSERT_EQUALS("", errout_str());
7937-
}
7938-
79397918
void unknownMacroBeforeReturn() {
79407919
ASSERT_THROW_INTERNAL(tokenizeAndStringify("int f() { X return 0; }"), UNKNOWN_MACRO);
79417920
}

0 commit comments

Comments
 (0)