Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re-enabled debug-only type validation after simplification #7259

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3484,6 +3484,8 @@ bool Tokenizer::simplifyTokens1(const std::string &configuration)
mSymbolDatabase->setArrayDimensionsUsingValueFlow();
}

validateTypes();

printDebugOutput(1, std::cout);

return true;
Expand Down Expand Up @@ -5926,25 +5928,29 @@ void Tokenizer::printDebugOutput(int simplification, std::ostream &out) const
if (mSettings.xml)
out << "</debug>" << std::endl;
}
}

if (mSymbolDatabase && simplification == 2U && mSettings.debugwarnings) {
printUnknownTypes();
void Tokenizer::validateTypes() const
{
if (!mSymbolDatabase || !mSettings.debugwarnings)
return;

// the typeStartToken() should come before typeEndToken()
for (const Variable *var : mSymbolDatabase->variableList()) {
if (!var)
continue;
printUnknownTypes();

const Token * typetok = var->typeStartToken();
while (typetok && typetok != var->typeEndToken())
typetok = typetok->next();
// the typeStartToken() should come before typeEndToken()
for (const Variable *var : mSymbolDatabase->variableList()) {
if (!var)
continue;

if (typetok != var->typeEndToken()) {
reportError(var->typeStartToken(),
Severity::debug,
"debug",
"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()));
}
const Token * typetok = var->typeStartToken();
while (typetok && typetok != var->typeEndToken())
typetok = typetok->next();

if (typetok != var->typeEndToken()) {
reportError(var->typeStartToken(),
Severity::debug,
"debug",
"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()));
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions lib/tokenize.h
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,8 @@ class CPPCHECKLIB Tokenizer {

static bool operatorEnd(const Token * tok);

void validateTypes() const;

public:
const SymbolDatabase *getSymbolDatabase() const {
return mSymbolDatabase;
Expand Down
Loading