Avoid 'unsigned' in Tokenizer. Use 'nonneg' instead for arguments and members.
This commit is contained in:
parent
0014fe880e
commit
534659e596
|
@ -1127,7 +1127,7 @@ void CheckUnusedVar::checkFunctionVariableUsage()
|
||||||
if (!tok->valueType())
|
if (!tok->valueType())
|
||||||
continue;
|
continue;
|
||||||
bool check = false;
|
bool check = false;
|
||||||
switch(tok->valueType()->type) {
|
switch (tok->valueType()->type) {
|
||||||
case ValueType::Type::UNKNOWN_TYPE:
|
case ValueType::Type::UNKNOWN_TYPE:
|
||||||
case ValueType::Type::NONSTD:
|
case ValueType::Type::NONSTD:
|
||||||
case ValueType::Type::RECORD:
|
case ValueType::Type::RECORD:
|
||||||
|
|
212
lib/tokenize.cpp
212
lib/tokenize.cpp
|
@ -52,14 +52,14 @@ namespace {
|
||||||
VarIdScopeInfo()
|
VarIdScopeInfo()
|
||||||
:isExecutable(false), isStructInit(false), isEnum(false), startVarid(0) {
|
:isExecutable(false), isStructInit(false), isEnum(false), startVarid(0) {
|
||||||
}
|
}
|
||||||
VarIdScopeInfo(bool _isExecutable, bool _isStructInit, bool _isEnum, unsigned int _startVarid)
|
VarIdScopeInfo(bool isExecutable, bool isStructInit, bool isEnum, nonneg int startVarid)
|
||||||
:isExecutable(_isExecutable), isStructInit(_isStructInit), isEnum(_isEnum), startVarid(_startVarid) {
|
:isExecutable(isExecutable), isStructInit(isStructInit), isEnum(isEnum), startVarid(startVarid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool isExecutable;
|
const bool isExecutable;
|
||||||
const bool isStructInit;
|
const bool isStructInit;
|
||||||
const bool isEnum;
|
const bool isEnum;
|
||||||
const unsigned int startVarid;
|
const nonneg int startVarid;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ Tokenizer::~Tokenizer()
|
||||||
// SizeOfType - gives the size of a type
|
// SizeOfType - gives the size of a type
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
unsigned int Tokenizer::sizeOfType(const Token *type) const
|
nonneg int Tokenizer::sizeOfType(const Token *type) const
|
||||||
{
|
{
|
||||||
if (!type || type->str().empty())
|
if (!type || type->str().empty())
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -197,7 +197,7 @@ unsigned int Tokenizer::sizeOfType(const Token *type) const
|
||||||
if (type->tokType() == Token::eString)
|
if (type->tokType() == Token::eString)
|
||||||
return Token::getStrLength(type) + 1U;
|
return Token::getStrLength(type) + 1U;
|
||||||
|
|
||||||
const std::map<std::string, unsigned int>::const_iterator it = mTypeSize.find(type->str());
|
const std::map<std::string, int>::const_iterator it = mTypeSize.find(type->str());
|
||||||
if (it == mTypeSize.end()) {
|
if (it == mTypeSize.end()) {
|
||||||
const Library::PodType* podtype = mSettings->library.podtype(type->str());
|
const Library::PodType* podtype = mSettings->library.podtype(type->str());
|
||||||
if (!podtype)
|
if (!podtype)
|
||||||
|
@ -410,7 +410,7 @@ namespace {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static Token *splitDefinitionFromTypedef(Token *tok, unsigned int *unnamedCount)
|
static Token *splitDefinitionFromTypedef(Token *tok, nonneg int *unnamedCount)
|
||||||
{
|
{
|
||||||
Token *tok1;
|
Token *tok1;
|
||||||
std::string name;
|
std::string name;
|
||||||
|
@ -2415,7 +2415,7 @@ void Tokenizer::combineOperators()
|
||||||
} else if (cpp && (c1 == 'p' || c1 == '_') &&
|
} else if (cpp && (c1 == 'p' || c1 == '_') &&
|
||||||
Token::Match(tok, "private|protected|public|__published : !!:")) {
|
Token::Match(tok, "private|protected|public|__published : !!:")) {
|
||||||
bool simplify = false;
|
bool simplify = false;
|
||||||
unsigned int par = 0U;
|
int par = 0;
|
||||||
for (const Token *prev = tok->previous(); prev; prev = prev->previous()) {
|
for (const Token *prev = tok->previous(); prev; prev = prev->previous()) {
|
||||||
if (prev->str() == ")") {
|
if (prev->str() == ")") {
|
||||||
++par;
|
++par;
|
||||||
|
@ -2687,7 +2687,7 @@ void Tokenizer::arraySize()
|
||||||
|
|
||||||
static Token *skipTernaryOp(Token *tok)
|
static Token *skipTernaryOp(Token *tok)
|
||||||
{
|
{
|
||||||
unsigned int colonLevel = 1;
|
int colonLevel = 1;
|
||||||
while (nullptr != (tok = tok->next())) {
|
while (nullptr != (tok = tok->next())) {
|
||||||
if (tok->str() == "?") {
|
if (tok->str() == "?") {
|
||||||
++colonLevel;
|
++colonLevel;
|
||||||
|
@ -2730,7 +2730,7 @@ void Tokenizer::simplifyLabelsCaseDefault()
|
||||||
{
|
{
|
||||||
const bool cpp = isCPP();
|
const bool cpp = isCPP();
|
||||||
bool executablescope = false;
|
bool executablescope = false;
|
||||||
unsigned int indentLevel = 0;
|
int indentLevel = 0;
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
// Simplify labels in the executable scope..
|
// Simplify labels in the executable scope..
|
||||||
Token *start = const_cast<Token *>(startOfExecutableScope(tok));
|
Token *start = const_cast<Token *>(startOfExecutableScope(tok));
|
||||||
|
@ -2847,14 +2847,14 @@ void Tokenizer::simplifyTemplates()
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
static bool setVarIdParseDeclaration(const Token **tok, const std::map<std::string,unsigned int> &variableId, bool executableScope, bool cpp, bool c)
|
static bool setVarIdParseDeclaration(const Token **tok, const std::map<std::string,int> &variableId, bool executableScope, bool cpp, bool c)
|
||||||
{
|
{
|
||||||
const Token *tok2 = *tok;
|
const Token *tok2 = *tok;
|
||||||
if (!tok2->isName())
|
if (!tok2->isName())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
unsigned int typeCount = 0;
|
int typeCount = 0;
|
||||||
unsigned int singleNameCount = 0;
|
int singleNameCount = 0;
|
||||||
bool hasstruct = false; // Is there a "struct" or "class"?
|
bool hasstruct = false; // Is there a "struct" or "class"?
|
||||||
bool bracket = false;
|
bool bracket = false;
|
||||||
bool ref = false;
|
bool ref = false;
|
||||||
|
@ -2967,17 +2967,17 @@ static bool setVarIdParseDeclaration(const Token **tok, const std::map<std::stri
|
||||||
|
|
||||||
|
|
||||||
void Tokenizer::setVarIdStructMembers(Token **tok1,
|
void Tokenizer::setVarIdStructMembers(Token **tok1,
|
||||||
std::map<unsigned int, std::map<std::string, unsigned int> >& structMembers,
|
std::map<int, std::map<std::string, int> >& structMembers,
|
||||||
unsigned int *varId)
|
nonneg int *varId)
|
||||||
{
|
{
|
||||||
Token *tok = *tok1;
|
Token *tok = *tok1;
|
||||||
|
|
||||||
if (Token::Match(tok, "%name% = { . %name% =")) {
|
if (Token::Match(tok, "%name% = { . %name% =")) {
|
||||||
const unsigned int struct_varid = tok->varId();
|
const int struct_varid = tok->varId();
|
||||||
if (struct_varid == 0)
|
if (struct_varid == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::map<std::string, unsigned int>& members = structMembers[struct_varid];
|
std::map<std::string, int>& members = structMembers[struct_varid];
|
||||||
|
|
||||||
tok = tok->tokAt(3);
|
tok = tok->tokAt(3);
|
||||||
while (tok->str() != "}") {
|
while (tok->str() != "}") {
|
||||||
|
@ -2985,7 +2985,7 @@ void Tokenizer::setVarIdStructMembers(Token **tok1,
|
||||||
tok = tok->link();
|
tok = tok->link();
|
||||||
if (Token::Match(tok->previous(), "[,{] . %name% =")) {
|
if (Token::Match(tok->previous(), "[,{] . %name% =")) {
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
const std::map<std::string, unsigned int>::iterator it = members.find(tok->str());
|
const std::map<std::string, int>::iterator it = members.find(tok->str());
|
||||||
if (it == members.end()) {
|
if (it == members.end()) {
|
||||||
members[tok->str()] = ++(*varId);
|
members[tok->str()] = ++(*varId);
|
||||||
tok->varId(*varId);
|
tok->varId(*varId);
|
||||||
|
@ -3006,7 +3006,7 @@ void Tokenizer::setVarIdStructMembers(Token **tok1,
|
||||||
tok = tok->tokAt(3);
|
tok = tok->tokAt(3);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const unsigned int struct_varid = tok->varId();
|
const int struct_varid = tok->varId();
|
||||||
tok = tok->tokAt(2);
|
tok = tok->tokAt(2);
|
||||||
if (struct_varid == 0)
|
if (struct_varid == 0)
|
||||||
continue;
|
continue;
|
||||||
|
@ -3018,8 +3018,8 @@ void Tokenizer::setVarIdStructMembers(Token **tok1,
|
||||||
if (TemplateSimplifier::templateParameters(tok->next()) > 0)
|
if (TemplateSimplifier::templateParameters(tok->next()) > 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
std::map<std::string, unsigned int>& members = structMembers[struct_varid];
|
std::map<std::string, int>& members = structMembers[struct_varid];
|
||||||
const std::map<std::string, unsigned int>::iterator it = members.find(tok->str());
|
const std::map<std::string, int>::iterator it = members.find(tok->str());
|
||||||
if (it == members.end()) {
|
if (it == members.end()) {
|
||||||
members[tok->str()] = ++(*varId);
|
members[tok->str()] = ++(*varId);
|
||||||
tok->varId(*varId);
|
tok->varId(*varId);
|
||||||
|
@ -3034,8 +3034,8 @@ void Tokenizer::setVarIdStructMembers(Token **tok1,
|
||||||
|
|
||||||
void Tokenizer::setVarIdClassDeclaration(const Token * const startToken,
|
void Tokenizer::setVarIdClassDeclaration(const Token * const startToken,
|
||||||
const VariableMap &variableMap,
|
const VariableMap &variableMap,
|
||||||
const unsigned int scopeStartVarId,
|
const nonneg int scopeStartVarId,
|
||||||
std::map<unsigned int, std::map<std::string,unsigned int> >& structMembers)
|
std::map<int, std::map<std::string,int> >& structMembers)
|
||||||
{
|
{
|
||||||
// end of scope
|
// end of scope
|
||||||
const Token * const endToken = startToken->link();
|
const Token * const endToken = startToken->link();
|
||||||
|
@ -3052,7 +3052,7 @@ void Tokenizer::setVarIdClassDeclaration(const Token * const startToken,
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace varids..
|
// replace varids..
|
||||||
unsigned int indentlevel = 0;
|
int indentlevel = 0;
|
||||||
bool initList = false;
|
bool initList = false;
|
||||||
bool inEnum = false;
|
bool inEnum = false;
|
||||||
const Token *initListArgLastToken = nullptr;
|
const Token *initListArgLastToken = nullptr;
|
||||||
|
@ -3076,7 +3076,7 @@ void Tokenizer::setVarIdClassDeclaration(const Token * const startToken,
|
||||||
--indentlevel;
|
--indentlevel;
|
||||||
inEnum = false;
|
inEnum = false;
|
||||||
} else if (initList && indentlevel == 0 && Token::Match(tok->previous(), "[,:] %name% [({]")) {
|
} else if (initList && indentlevel == 0 && Token::Match(tok->previous(), "[,:] %name% [({]")) {
|
||||||
const std::map<std::string, unsigned int>::const_iterator it = variableMap.find(tok->str());
|
const std::map<std::string, int>::const_iterator it = variableMap.find(tok->str());
|
||||||
if (it != variableMap.end()) {
|
if (it != variableMap.end()) {
|
||||||
tok->varId(it->second);
|
tok->varId(it->second);
|
||||||
}
|
}
|
||||||
|
@ -3094,7 +3094,7 @@ void Tokenizer::setVarIdClassDeclaration(const Token * const startToken,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!inEnum) {
|
if (!inEnum) {
|
||||||
const std::map<std::string, unsigned int>::const_iterator it = variableMap.find(tok->str());
|
const std::map<std::string, int>::const_iterator it = variableMap.find(tok->str());
|
||||||
if (it != variableMap.end()) {
|
if (it != variableMap.end()) {
|
||||||
tok->varId(it->second);
|
tok->varId(it->second);
|
||||||
setVarIdStructMembers(&tok, structMembers, variableMap.getVarId());
|
setVarIdStructMembers(&tok, structMembers, variableMap.getVarId());
|
||||||
|
@ -3113,9 +3113,9 @@ void Tokenizer::setVarIdClassDeclaration(const Token * const startToken,
|
||||||
void Tokenizer::setVarIdClassFunction(const std::string &classname,
|
void Tokenizer::setVarIdClassFunction(const std::string &classname,
|
||||||
Token * const startToken,
|
Token * const startToken,
|
||||||
const Token * const endToken,
|
const Token * const endToken,
|
||||||
const std::map<std::string, unsigned int> &varlist,
|
const std::map<std::string, int> &varlist,
|
||||||
std::map<unsigned int, std::map<std::string, unsigned int> >& structMembers,
|
std::map<int, std::map<std::string, int> >& structMembers,
|
||||||
unsigned int *varId_)
|
nonneg int *varId_)
|
||||||
{
|
{
|
||||||
for (Token *tok2 = startToken; tok2 && tok2 != endToken; tok2 = tok2->next()) {
|
for (Token *tok2 = startToken; tok2 && tok2 != endToken; tok2 = tok2->next()) {
|
||||||
if (tok2->varId() != 0 || !tok2->isName())
|
if (tok2->varId() != 0 || !tok2->isName())
|
||||||
|
@ -3127,7 +3127,7 @@ void Tokenizer::setVarIdClassFunction(const std::string &classname,
|
||||||
if (Token::Match(tok2->tokAt(-2), "!!this .") && !Token::simpleMatch(tok2->tokAt(-5), "( * this ) ."))
|
if (Token::Match(tok2->tokAt(-2), "!!this .") && !Token::simpleMatch(tok2->tokAt(-5), "( * this ) ."))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const std::map<std::string,unsigned int>::const_iterator it = varlist.find(tok2->str());
|
const std::map<std::string,int>::const_iterator it = varlist.find(tok2->str());
|
||||||
if (it != varlist.end()) {
|
if (it != varlist.end()) {
|
||||||
tok2->varId(it->second);
|
tok2->varId(it->second);
|
||||||
setVarIdStructMembers(&tok2, structMembers, varId_);
|
setVarIdStructMembers(&tok2, structMembers, varId_);
|
||||||
|
@ -3166,7 +3166,7 @@ void Tokenizer::setVarIdPass1()
|
||||||
const std::set<std::string>& notstart = (isC()) ? notstart_c : notstart_cpp;
|
const std::set<std::string>& notstart = (isC()) ? notstart_c : notstart_cpp;
|
||||||
|
|
||||||
VariableMap variableMap;
|
VariableMap variableMap;
|
||||||
std::map<unsigned int, std::map<std::string, unsigned int> > structMembers;
|
std::map<int, std::map<std::string, int> > structMembers;
|
||||||
|
|
||||||
std::stack<VarIdScopeInfo> scopeStack;
|
std::stack<VarIdScopeInfo> scopeStack;
|
||||||
|
|
||||||
|
@ -3359,7 +3359,7 @@ void Tokenizer::setVarIdPass1()
|
||||||
const Token *end = tok->findClosingBracket();
|
const Token *end = tok->findClosingBracket();
|
||||||
while (tok != end) {
|
while (tok != end) {
|
||||||
if (tok->isName()) {
|
if (tok->isName()) {
|
||||||
const std::map<std::string, unsigned int>::const_iterator it = variableMap.find(tok->str());
|
const std::map<std::string, int>::const_iterator it = variableMap.find(tok->str());
|
||||||
if (it != variableMap.end())
|
if (it != variableMap.end())
|
||||||
tok->varId(it->second);
|
tok->varId(it->second);
|
||||||
}
|
}
|
||||||
|
@ -3400,7 +3400,7 @@ void Tokenizer::setVarIdPass1()
|
||||||
if (!Token::Match(start, "[(,] %type% %name%|*|&"))
|
if (!Token::Match(start, "[(,] %type% %name%|*|&"))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (start->varId() > 0U)
|
if (start->varId() > 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3417,7 +3417,7 @@ void Tokenizer::setVarIdPass1()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!scopeStack.top().isEnum) {
|
if (!scopeStack.top().isEnum) {
|
||||||
const std::map<std::string, unsigned int>::const_iterator it = variableMap.find(tok->str());
|
const std::map<std::string, int>::const_iterator it = variableMap.find(tok->str());
|
||||||
if (it != variableMap.end()) {
|
if (it != variableMap.end()) {
|
||||||
tok->varId(it->second);
|
tok->varId(it->second);
|
||||||
setVarIdStructMembers(&tok, structMembers, variableMap.getVarId());
|
setVarIdStructMembers(&tok, structMembers, variableMap.getVarId());
|
||||||
|
@ -3542,7 +3542,7 @@ static Token * matchMemberFunctionName(const Member &func, const std::list<Scope
|
||||||
|
|
||||||
void Tokenizer::setVarIdPass2()
|
void Tokenizer::setVarIdPass2()
|
||||||
{
|
{
|
||||||
std::map<unsigned int, std::map<std::string, unsigned int> > structMembers;
|
std::map<int, std::map<std::string, int> > structMembers;
|
||||||
|
|
||||||
// Member functions and variables in this source
|
// Member functions and variables in this source
|
||||||
std::list<Member> allMemberFunctions;
|
std::list<Member> allMemberFunctions;
|
||||||
|
@ -3604,7 +3604,7 @@ void Tokenizer::setVarIdPass2()
|
||||||
std::list<ScopeInfo2> scopeInfo;
|
std::list<ScopeInfo2> scopeInfo;
|
||||||
|
|
||||||
// class members..
|
// class members..
|
||||||
std::map<std::string, std::map<std::string, unsigned int> > varsByClass;
|
std::map<std::string, std::map<std::string, int> > varsByClass;
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
while (tok->str() == "}" && !scopeInfo.empty() && tok == scopeInfo.back().bodyEnd)
|
while (tok->str() == "}" && !scopeInfo.empty() && tok == scopeInfo.back().bodyEnd)
|
||||||
scopeInfo.pop_back();
|
scopeInfo.pop_back();
|
||||||
|
@ -3627,7 +3627,7 @@ void Tokenizer::setVarIdPass2()
|
||||||
for (const Token *it : classnameTokens)
|
for (const Token *it : classnameTokens)
|
||||||
classname += (classname.empty() ? "" : " :: ") + it->str();
|
classname += (classname.empty() ? "" : " :: ") + it->str();
|
||||||
|
|
||||||
std::map<std::string, unsigned int> &thisClassVars = varsByClass[scopeName2 + classname];
|
std::map<std::string, int> &thisClassVars = varsByClass[scopeName2 + classname];
|
||||||
while (Token::Match(tokStart, ":|::|,|%name%")) {
|
while (Token::Match(tokStart, ":|::|,|%name%")) {
|
||||||
if (Token::Match(tokStart, "%name% <")) {
|
if (Token::Match(tokStart, "%name% <")) {
|
||||||
tokStart = tokStart->next()->findClosingBracket();
|
tokStart = tokStart->next()->findClosingBracket();
|
||||||
|
@ -3636,7 +3636,7 @@ void Tokenizer::setVarIdPass2()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (Token::Match(tokStart, "%name% ,|{")) {
|
if (Token::Match(tokStart, "%name% ,|{")) {
|
||||||
const std::map<std::string, unsigned int>& baseClassVars = varsByClass[tokStart->str()];
|
const std::map<std::string, int>& baseClassVars = varsByClass[tokStart->str()];
|
||||||
thisClassVars.insert(baseClassVars.begin(), baseClassVars.end());
|
thisClassVars.insert(baseClassVars.begin(), baseClassVars.end());
|
||||||
}
|
}
|
||||||
tokStart = tokStart->next();
|
tokStart = tokStart->next();
|
||||||
|
@ -3719,7 +3719,7 @@ void Tokenizer::setVarIdPass2()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// set varid
|
// set varid
|
||||||
const std::map<std::string, unsigned int>::const_iterator varpos = thisClassVars.find(tok3->str());
|
const std::map<std::string, int>::const_iterator varpos = thisClassVars.find(tok3->str());
|
||||||
if (varpos != thisClassVars.end())
|
if (varpos != thisClassVars.end())
|
||||||
tok3->varId(varpos->second);
|
tok3->varId(varpos->second);
|
||||||
|
|
||||||
|
@ -3941,16 +3941,16 @@ void Tokenizer::sizeofAddParentheses()
|
||||||
bool Tokenizer::simplifySizeof()
|
bool Tokenizer::simplifySizeof()
|
||||||
{
|
{
|
||||||
// Locate variable declarations and calculate the size
|
// Locate variable declarations and calculate the size
|
||||||
std::map<unsigned int, unsigned int> sizeOfVar;
|
std::map<int, int> sizeOfVar;
|
||||||
std::map<unsigned int, const Token *> declTokOfVar;
|
std::map<int, const Token *> declTokOfVar;
|
||||||
for (const Token *tok = list.front(); tok; tok = tok->next()) {
|
for (const Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
if (tok->varId() != 0 && sizeOfVar.find(tok->varId()) == sizeOfVar.end()) {
|
if (tok->varId() != 0 && sizeOfVar.find(tok->varId()) == sizeOfVar.end()) {
|
||||||
const unsigned int varId = tok->varId();
|
const int varId = tok->varId();
|
||||||
if (Token::Match(tok->tokAt(-3), "[;{}(,] %type% * %name% [;,)]") ||
|
if (Token::Match(tok->tokAt(-3), "[;{}(,] %type% * %name% [;,)]") ||
|
||||||
Token::Match(tok->tokAt(-4), "[;{}(,] const %type% * %name% [;),]") ||
|
Token::Match(tok->tokAt(-4), "[;{}(,] const %type% * %name% [;),]") ||
|
||||||
Token::Match(tok->tokAt(-2), "[;{}(,] %type% %name% [;),]") ||
|
Token::Match(tok->tokAt(-2), "[;{}(,] %type% %name% [;),]") ||
|
||||||
Token::Match(tok->tokAt(-3), "[;{}(,] const %type% %name% [;),]")) {
|
Token::Match(tok->tokAt(-3), "[;{}(,] const %type% %name% [;),]")) {
|
||||||
const unsigned int size = sizeOfType(tok->previous());
|
const int size = sizeOfType(tok->previous());
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -3961,7 +3961,7 @@ bool Tokenizer::simplifySizeof()
|
||||||
|
|
||||||
else if (Token::Match(tok->previous(), "%type% %name% [ %num% ] [[;=]") ||
|
else if (Token::Match(tok->previous(), "%type% %name% [ %num% ] [[;=]") ||
|
||||||
Token::Match(tok->tokAt(-2), "%type% * %name% [ %num% ] [[;=]")) {
|
Token::Match(tok->tokAt(-2), "%type% * %name% [ %num% ] [[;=]")) {
|
||||||
unsigned int size = sizeOfType(tok->previous());
|
int size = sizeOfType(tok->previous());
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -4039,7 +4039,7 @@ bool Tokenizer::simplifySizeof()
|
||||||
|
|
||||||
// sizeof( a )
|
// sizeof( a )
|
||||||
else if (Token::Match(tok->next(), "( %var% )")) {
|
else if (Token::Match(tok->next(), "( %var% )")) {
|
||||||
const std::map<unsigned int, unsigned int>::const_iterator sizeOfVarPos = sizeOfVar.find(tok->tokAt(2)->varId());
|
const std::map<int, int>::const_iterator sizeOfVarPos = sizeOfVar.find(tok->tokAt(2)->varId());
|
||||||
if (sizeOfVarPos != sizeOfVar.end()) {
|
if (sizeOfVarPos != sizeOfVar.end()) {
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
|
@ -4053,7 +4053,7 @@ bool Tokenizer::simplifySizeof()
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (Token::Match(tok->next(), "( %type% )")) {
|
else if (Token::Match(tok->next(), "( %type% )")) {
|
||||||
const unsigned int size = sizeOfType(tok->tokAt(2));
|
const int size = sizeOfType(tok->tokAt(2));
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
tok->str(MathLib::toString(size));
|
tok->str(MathLib::toString(size));
|
||||||
tok->deleteNext(3);
|
tok->deleteNext(3);
|
||||||
|
@ -4062,7 +4062,7 @@ bool Tokenizer::simplifySizeof()
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (Token::simpleMatch(tok->next(), "( *") || Token::Match(tok->next(), "( %name% [")) {
|
else if (Token::simpleMatch(tok->next(), "( *") || Token::Match(tok->next(), "( %name% [")) {
|
||||||
unsigned int derefs = 0;
|
int derefs = 0;
|
||||||
|
|
||||||
const Token* nametok = tok->tokAt(2);
|
const Token* nametok = tok->tokAt(2);
|
||||||
if (nametok->str() == "*") {
|
if (nametok->str() == "*") {
|
||||||
|
@ -4087,7 +4087,7 @@ bool Tokenizer::simplifySizeof()
|
||||||
// Some default value
|
// Some default value
|
||||||
MathLib::biguint size = 0;
|
MathLib::biguint size = 0;
|
||||||
|
|
||||||
const unsigned int varid = nametok->varId();
|
const int varid = nametok->varId();
|
||||||
if (derefs != 0 && varid != 0 && declTokOfVar.find(varid) != declTokOfVar.end()) {
|
if (derefs != 0 && varid != 0 && declTokOfVar.find(varid) != declTokOfVar.end()) {
|
||||||
// Try to locate variable declaration..
|
// Try to locate variable declaration..
|
||||||
const Token *decltok = declTokOfVar[varid];
|
const Token *decltok = declTokOfVar[varid];
|
||||||
|
@ -4099,7 +4099,7 @@ bool Tokenizer::simplifySizeof()
|
||||||
// Multi-dimensional array..
|
// Multi-dimensional array..
|
||||||
if (Token::Match(decltok, "%name% [") && Token::simpleMatch(decltok->linkAt(1), "] [")) {
|
if (Token::Match(decltok, "%name% [") && Token::simpleMatch(decltok->linkAt(1), "] [")) {
|
||||||
const Token *tok2 = decltok;
|
const Token *tok2 = decltok;
|
||||||
for (unsigned int i = 0; i < derefs; i++)
|
for (int i = 0; i < derefs; i++)
|
||||||
tok2 = tok2->linkAt(1); // Skip all dimensions that are dereferenced before the sizeof call
|
tok2 = tok2->linkAt(1); // Skip all dimensions that are dereferenced before the sizeof call
|
||||||
while (Token::Match(tok2, "] [ %num% ]")) {
|
while (Token::Match(tok2, "] [ %num% ]")) {
|
||||||
size *= MathLib::toULongNumber(tok2->strAt(2));
|
size *= MathLib::toULongNumber(tok2->strAt(2));
|
||||||
|
@ -4681,7 +4681,7 @@ bool Tokenizer::simplifyTokenList2()
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
void Tokenizer::printDebugOutput(unsigned int simplification) const
|
void Tokenizer::printDebugOutput(int simplification) const
|
||||||
{
|
{
|
||||||
const bool debug = (simplification != 1U && mSettings->debugSimplified) ||
|
const bool debug = (simplification != 1U && mSettings->debugSimplified) ||
|
||||||
(simplification != 2U && mSettings->debugnormal);
|
(simplification != 2U && mSettings->debugnormal);
|
||||||
|
@ -4774,7 +4774,7 @@ void Tokenizer::dump(std::ostream &out) const
|
||||||
}
|
}
|
||||||
if (tok->link())
|
if (tok->link())
|
||||||
out << " link=\"" << tok->link() << '\"';
|
out << " link=\"" << tok->link() << '\"';
|
||||||
if (tok->varId() > 0U)
|
if (tok->varId() > 0)
|
||||||
out << " varId=\"" << MathLib::toString(tok->varId()) << '\"';
|
out << " varId=\"" << MathLib::toString(tok->varId()) << '\"';
|
||||||
if (tok->variable())
|
if (tok->variable())
|
||||||
out << " variable=\"" << tok->variable() << '\"';
|
out << " variable=\"" << tok->variable() << '\"';
|
||||||
|
@ -5051,7 +5051,7 @@ void Tokenizer::removeRedundantAssignment()
|
||||||
if (start) {
|
if (start) {
|
||||||
tok = start->previous();
|
tok = start->previous();
|
||||||
// parse in this function..
|
// parse in this function..
|
||||||
std::set<unsigned int> localvars;
|
std::set<int> localvars;
|
||||||
const Token * const end = tok->next()->link();
|
const Token * const end = tok->next()->link();
|
||||||
for (Token * tok2 = tok->next(); tok2 && tok2 != end; tok2 = tok2->next()) {
|
for (Token * tok2 = tok->next(); tok2 && tok2 != end; tok2 = tok2->next()) {
|
||||||
// skip local class or struct
|
// skip local class or struct
|
||||||
|
@ -5185,7 +5185,7 @@ void Tokenizer::simplifyFlowControl()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Token* end = begin->linkAt(1+(begin->next()->str() == "{" ? 0 : 1));
|
Token* end = begin->linkAt(1+(begin->next()->str() == "{" ? 0 : 1));
|
||||||
unsigned int indentLevel = 0;
|
int indentLevel = 0;
|
||||||
bool stilldead = false;
|
bool stilldead = false;
|
||||||
|
|
||||||
for (Token *tok = begin; tok && tok != end; tok = tok->next()) {
|
for (Token *tok = begin; tok && tok != end; tok = tok->next()) {
|
||||||
|
@ -5325,7 +5325,7 @@ void Tokenizer::removeRedundantFor()
|
||||||
if (type)
|
if (type)
|
||||||
varTok = varTok->next();
|
varTok = varTok->next();
|
||||||
const std::string varname(varTok->str());
|
const std::string varname(varTok->str());
|
||||||
const unsigned int varid(varTok->varId());
|
const int varid(varTok->varId());
|
||||||
if (varname != varTok->strAt(4))
|
if (varname != varTok->strAt(4))
|
||||||
continue;
|
continue;
|
||||||
const Token *vartok2 = tok->linkAt(2)->previous();
|
const Token *vartok2 = tok->linkAt(2)->previous();
|
||||||
|
@ -5878,7 +5878,7 @@ bool Tokenizer::simplifyConstTernaryOp()
|
||||||
// delete the condition token and the "?"
|
// delete the condition token and the "?"
|
||||||
tok->deleteNext(2);
|
tok->deleteNext(2);
|
||||||
|
|
||||||
unsigned int ternaryOplevel = 0;
|
int ternaryOplevel = 0;
|
||||||
for (const Token *endTok = colon; endTok; endTok = endTok->next()) {
|
for (const Token *endTok = colon; endTok; endTok = endTok->next()) {
|
||||||
if (Token::Match(endTok, "(|[|{")) {
|
if (Token::Match(endTok, "(|[|{")) {
|
||||||
endTok = endTok->link();
|
endTok = endTok->link();
|
||||||
|
@ -5916,7 +5916,7 @@ void Tokenizer::simplifyUndefinedSizeArray()
|
||||||
|
|
||||||
tok = tok2->previous();
|
tok = tok2->previous();
|
||||||
Token *end = tok2->next();
|
Token *end = tok2->next();
|
||||||
unsigned int count = 0;
|
int count = 0;
|
||||||
do {
|
do {
|
||||||
end = end->tokAt(2);
|
end = end->tokAt(2);
|
||||||
++count;
|
++count;
|
||||||
|
@ -5955,7 +5955,7 @@ void Tokenizer::simplifyCasts()
|
||||||
// #4164 : ((unsigned char)1) => (1)
|
// #4164 : ((unsigned char)1) => (1)
|
||||||
if (Token::Match(tok->next(), "( %type% ) %num%") && tok->next()->link()->previous()->isStandardType()) {
|
if (Token::Match(tok->next(), "( %type% ) %num%") && tok->next()->link()->previous()->isStandardType()) {
|
||||||
const MathLib::bigint value = MathLib::toLongNumber(tok->next()->link()->next()->str());
|
const MathLib::bigint value = MathLib::toLongNumber(tok->next()->link()->next()->str());
|
||||||
unsigned int bits = mSettings->char_bit * mTypeSize[tok->next()->link()->previous()->str()];
|
int bits = mSettings->char_bit * mTypeSize[tok->next()->link()->previous()->str()];
|
||||||
if (!tok->tokAt(2)->isUnsigned() && bits > 0)
|
if (!tok->tokAt(2)->isUnsigned() && bits > 0)
|
||||||
bits--;
|
bits--;
|
||||||
if (bits < 31 && value >= 0 && value < (1LL << bits)) {
|
if (bits < 31 && value >= 0 && value < (1LL << bits)) {
|
||||||
|
@ -6406,7 +6406,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co
|
||||||
bool isconst = false;
|
bool isconst = false;
|
||||||
bool isstatic = false;
|
bool isstatic = false;
|
||||||
Token *tok2 = type0;
|
Token *tok2 = type0;
|
||||||
unsigned int typelen = 1;
|
int typelen = 1;
|
||||||
|
|
||||||
if (Token::Match(tok2, "::|extern")) {
|
if (Token::Match(tok2, "::|extern")) {
|
||||||
tok2 = tok2->next();
|
tok2 = tok2->next();
|
||||||
|
@ -6469,8 +6469,8 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co
|
||||||
tok2 = tok2->tokAt(2);
|
tok2 = tok2->tokAt(2);
|
||||||
if (tok2 && tok2->previous()->str() == "::")
|
if (tok2 && tok2->previous()->str() == "::")
|
||||||
continue;
|
continue;
|
||||||
unsigned int indentlevel = 0;
|
int indentlevel = 0;
|
||||||
unsigned int parens = 0;
|
int parens = 0;
|
||||||
|
|
||||||
for (Token *tok3 = tok2; tok3; tok3 = tok3->next()) {
|
for (Token *tok3 = tok2; tok3; tok3 = tok3->next()) {
|
||||||
++typelen;
|
++typelen;
|
||||||
|
@ -6484,7 +6484,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co
|
||||||
}
|
}
|
||||||
--indentlevel;
|
--indentlevel;
|
||||||
} else if (!parens && tok3->str() == ">>") {
|
} else if (!parens && tok3->str() == ">>") {
|
||||||
if (indentlevel <= 1U) {
|
if (indentlevel <= 1) {
|
||||||
tok2 = tok3->next();
|
tok2 = tok3->next();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -6781,7 +6781,7 @@ void Tokenizer::simplifyIfAndWhileAssign()
|
||||||
|
|
||||||
// If it's a while loop, insert the assignment in the loop
|
// If it's a while loop, insert the assignment in the loop
|
||||||
if (iswhile && !isDoWhile) {
|
if (iswhile && !isDoWhile) {
|
||||||
unsigned int indentlevel = 0;
|
int indentlevel = 0;
|
||||||
Token *tok3 = tok2;
|
Token *tok3 = tok2;
|
||||||
|
|
||||||
for (; tok3; tok3 = tok3->next()) {
|
for (; tok3; tok3 = tok3->next()) {
|
||||||
|
@ -6879,7 +6879,7 @@ static const std::map<std::string, std::string> cAlternativeTokens = {
|
||||||
bool Tokenizer::simplifyCAlternativeTokens()
|
bool Tokenizer::simplifyCAlternativeTokens()
|
||||||
{
|
{
|
||||||
/* executable scope level */
|
/* executable scope level */
|
||||||
unsigned int executableScopeLevel = 0;
|
int executableScopeLevel = 0;
|
||||||
|
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
|
@ -6947,7 +6947,7 @@ void Tokenizer::simplifyInitVar()
|
||||||
tok1 = tok1->next();
|
tok1 = tok1->next();
|
||||||
tok1->str(";");
|
tok1->str(";");
|
||||||
|
|
||||||
const unsigned int numTokens = (Token::Match(tok, "class|struct|union")) ? 2U : 1U;
|
const int numTokens = (Token::Match(tok, "class|struct|union")) ? 2U : 1U;
|
||||||
list.insertTokens(tok1, tok, numTokens);
|
list.insertTokens(tok1, tok, numTokens);
|
||||||
tok = initVar(tok);
|
tok = initVar(tok);
|
||||||
}
|
}
|
||||||
|
@ -7007,9 +7007,9 @@ bool Tokenizer::simplifyKnownVariables()
|
||||||
|
|
||||||
// constants..
|
// constants..
|
||||||
{
|
{
|
||||||
std::unordered_map<unsigned int, std::string> constantValues;
|
std::unordered_map<int, std::string> constantValues;
|
||||||
std::map<unsigned int, Token*> constantVars;
|
std::map<int, Token*> constantVars;
|
||||||
std::unordered_map<unsigned int, std::list<Token*>> constantValueUsages;
|
std::unordered_map<int, std::list<Token*>> constantValueUsages;
|
||||||
bool goback = false;
|
bool goback = false;
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
if (goback) {
|
if (goback) {
|
||||||
|
@ -7121,9 +7121,9 @@ bool Tokenizer::simplifyKnownVariables()
|
||||||
}
|
}
|
||||||
|
|
||||||
// variable id for local, float/double, array variables
|
// variable id for local, float/double, array variables
|
||||||
std::set<unsigned int> localvars;
|
std::set<int> localvars;
|
||||||
std::set<unsigned int> floatvars;
|
std::set<int> floatvars;
|
||||||
std::set<unsigned int> arrays;
|
std::set<int> arrays;
|
||||||
|
|
||||||
// auto variables..
|
// auto variables..
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
|
@ -7178,7 +7178,7 @@ bool Tokenizer::simplifyKnownVariables()
|
||||||
Token::Match(tok2, "%name% [ %num%| ] = %str% ;") ||
|
Token::Match(tok2, "%name% [ %num%| ] = %str% ;") ||
|
||||||
Token::Match(tok2, "%name% = & %name% ;") ||
|
Token::Match(tok2, "%name% = & %name% ;") ||
|
||||||
(Token::Match(tok2, "%name% = & %name% [ 0 ] ;") && arrays.find(tok2->tokAt(3)->varId()) != arrays.end()))) {
|
(Token::Match(tok2, "%name% = & %name% [ 0 ] ;") && arrays.find(tok2->tokAt(3)->varId()) != arrays.end()))) {
|
||||||
const unsigned int varid = tok2->varId();
|
const int varid = tok2->varId();
|
||||||
if (varid == 0)
|
if (varid == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -7221,7 +7221,7 @@ bool Tokenizer::simplifyKnownVariables()
|
||||||
const Token * const valueToken = tok2->tokAt(2);
|
const Token * const valueToken = tok2->tokAt(2);
|
||||||
|
|
||||||
std::string value;
|
std::string value;
|
||||||
unsigned int valueVarId = 0;
|
int valueVarId = 0;
|
||||||
|
|
||||||
Token *tok3 = nullptr;
|
Token *tok3 = nullptr;
|
||||||
bool valueIsPointer = false;
|
bool valueIsPointer = false;
|
||||||
|
@ -7240,7 +7240,7 @@ bool Tokenizer::simplifyKnownVariables()
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (Token::Match(tok2, "strcpy|sprintf ( %name% , %str% ) ;")) {
|
else if (Token::Match(tok2, "strcpy|sprintf ( %name% , %str% ) ;")) {
|
||||||
const unsigned int varid(tok2->tokAt(2)->varId());
|
const int varid(tok2->tokAt(2)->varId());
|
||||||
if (varid == 0)
|
if (varid == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -7254,7 +7254,7 @@ bool Tokenizer::simplifyKnownVariables()
|
||||||
++n;
|
++n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const unsigned int valueVarId(0);
|
const int valueVarId(0);
|
||||||
const bool valueIsPointer(false);
|
const bool valueIsPointer(false);
|
||||||
Token *tok3 = tok2->tokAt(6);
|
Token *tok3 = tok2->tokAt(6);
|
||||||
ret |= simplifyKnownVariablesSimplify(&tok2, tok3, varid, emptyString, value, valueVarId, valueIsPointer, valueToken, indentlevel);
|
ret |= simplifyKnownVariablesSimplify(&tok2, tok3, varid, emptyString, value, valueVarId, valueIsPointer, valueToken, indentlevel);
|
||||||
|
@ -7272,7 +7272,7 @@ bool Tokenizer::simplifyKnownVariables()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Tokenizer::simplifyKnownVariablesGetData(unsigned int varid, Token **_tok2, Token **_tok3, std::string &value, unsigned int &valueVarId, bool &valueIsPointer, bool floatvar)
|
bool Tokenizer::simplifyKnownVariablesGetData(nonneg int varid, Token **_tok2, Token **_tok3, std::string &value, nonneg int &valueVarId, bool &valueIsPointer, bool floatvar)
|
||||||
{
|
{
|
||||||
Token *tok2 = *_tok2;
|
Token *tok2 = *_tok2;
|
||||||
Token *tok3 = nullptr;
|
Token *tok3 = nullptr;
|
||||||
|
@ -7341,7 +7341,7 @@ bool Tokenizer::simplifyKnownVariablesGetData(unsigned int varid, Token **_tok2,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsigned int varid, const std::string &structname, std::string &value, unsigned int valueVarId, bool valueIsPointer, const Token * const valueToken, int indentlevel) const
|
bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, nonneg int varid, const std::string &structname, std::string &value, nonneg int valueVarId, bool valueIsPointer, const Token * const valueToken, int indentlevel) const
|
||||||
{
|
{
|
||||||
const bool pointeralias(valueToken->isName() || Token::Match(valueToken, "& %name% ["));
|
const bool pointeralias(valueToken->isName() || Token::Match(valueToken, "& %name% ["));
|
||||||
const bool varIsGlobal = (indentlevel == 0);
|
const bool varIsGlobal = (indentlevel == 0);
|
||||||
|
@ -7587,7 +7587,7 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
|
||||||
// don't simplify buffer value
|
// don't simplify buffer value
|
||||||
"memcmp","memcpy","memmove","memset","strcpy","strncmp","strncpy"
|
"memcmp","memcpy","memmove","memset","strcpy","strncmp","strncpy"
|
||||||
};
|
};
|
||||||
for (unsigned int i = 0; i < (sizeof(functionName) / sizeof(*functionName)); ++i) {
|
for (int i = 0; i < (sizeof(functionName) / sizeof(*functionName)); ++i) {
|
||||||
if (valueVarId == 0U && i >= 2)
|
if (valueVarId == 0U && i >= 2)
|
||||||
break;
|
break;
|
||||||
if (tok3->str() == functionName[i]) {
|
if (tok3->str() == functionName[i]) {
|
||||||
|
@ -7611,7 +7611,7 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
|
||||||
// don't simplify buffer value
|
// don't simplify buffer value
|
||||||
"memcmp","memcpy","memmove"
|
"memcmp","memcpy","memmove"
|
||||||
};
|
};
|
||||||
for (unsigned int i = 0; i < (sizeof(functionName) / sizeof(*functionName)); ++i) {
|
for (int i = 0; i < (sizeof(functionName) / sizeof(*functionName)); ++i) {
|
||||||
if (valueVarId == 0U && i >= 4)
|
if (valueVarId == 0U && i >= 4)
|
||||||
break;
|
break;
|
||||||
if (tok3->str() == functionName[i]) {
|
if (tok3->str() == functionName[i]) {
|
||||||
|
@ -8033,7 +8033,7 @@ void Tokenizer::simplifyReference()
|
||||||
for (Token *tok2 = tok; tok2 && tok2 != end; tok2 = tok2->next()) {
|
for (Token *tok2 = tok; tok2 && tok2 != end; tok2 = tok2->next()) {
|
||||||
// found a reference..
|
// found a reference..
|
||||||
if (Token::Match(tok2, "[;{}] %type% & %name% (|= %name% )| ;")) {
|
if (Token::Match(tok2, "[;{}] %type% & %name% (|= %name% )| ;")) {
|
||||||
const unsigned int refId = tok2->tokAt(3)->varId();
|
const int refId = tok2->tokAt(3)->varId();
|
||||||
if (!refId)
|
if (!refId)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -8094,7 +8094,7 @@ void Tokenizer::simplifyOffsetPointerDereference()
|
||||||
|
|
||||||
void Tokenizer::simplifyOffsetPointerReference()
|
void Tokenizer::simplifyOffsetPointerReference()
|
||||||
{
|
{
|
||||||
std::set<unsigned int> pod;
|
std::set<int> pod;
|
||||||
for (const Token *tok = list.front(); tok; tok = tok->next()) {
|
for (const Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
if (tok->isStandardType()) {
|
if (tok->isStandardType()) {
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
@ -8326,7 +8326,7 @@ bool Tokenizer::isFunctionParameterPassedByValue(const Token *fpar) const
|
||||||
const Token *ftok;
|
const Token *ftok;
|
||||||
|
|
||||||
// Look at function call, what parameter number is it?
|
// Look at function call, what parameter number is it?
|
||||||
unsigned int parameter = 1;
|
int parameter = 1;
|
||||||
for (ftok = fpar->previous(); ftok; ftok = ftok->previous()) {
|
for (ftok = fpar->previous(); ftok; ftok = ftok->previous()) {
|
||||||
if (ftok->str() == "(")
|
if (ftok->str() == "(")
|
||||||
break;
|
break;
|
||||||
|
@ -8352,7 +8352,7 @@ bool Tokenizer::isFunctionParameterPassedByValue(const Token *fpar) const
|
||||||
else if (Token::Match(tok, "%type% (") && tok->str() == functionName) {
|
else if (Token::Match(tok, "%type% (") && tok->str() == functionName) {
|
||||||
// Goto parameter
|
// Goto parameter
|
||||||
tok = tok->tokAt(2);
|
tok = tok->tokAt(2);
|
||||||
unsigned int par = 1;
|
int par = 1;
|
||||||
while (tok && par < parameter) {
|
while (tok && par < parameter) {
|
||||||
if (tok->str() == ")")
|
if (tok->str() == ")")
|
||||||
break;
|
break;
|
||||||
|
@ -8390,13 +8390,13 @@ void Tokenizer::eraseDeadCode(Token *begin, const Token *end)
|
||||||
if (!begin)
|
if (!begin)
|
||||||
return;
|
return;
|
||||||
const bool isgoto = Token::Match(begin->tokAt(-2), "goto %name% ;");
|
const bool isgoto = Token::Match(begin->tokAt(-2), "goto %name% ;");
|
||||||
unsigned int indentlevel = 1,
|
int indentlevel = 1;
|
||||||
indentcase = 0,
|
int indentcase = 0;
|
||||||
indentswitch = 0,
|
int indentswitch = 0;
|
||||||
indentlabel = 0,
|
int indentlabel = 0;
|
||||||
roundbraces = 0,
|
int roundbraces = 0;
|
||||||
indentcheck = 0;
|
int indentcheck = 0;
|
||||||
std::vector<unsigned int> switchindents;
|
std::vector<int> switchindents;
|
||||||
bool checklabel = false;
|
bool checklabel = false;
|
||||||
Token *tok = begin;
|
Token *tok = begin;
|
||||||
Token *tokcheck = nullptr;
|
Token *tokcheck = nullptr;
|
||||||
|
@ -8517,7 +8517,7 @@ void Tokenizer::eraseDeadCode(Token *begin, const Token *end)
|
||||||
//instruction is removed, there's no sense to keep the
|
//instruction is removed, there's no sense to keep the
|
||||||
//case instructions. Remove them, if there are any.
|
//case instructions. Remove them, if there are any.
|
||||||
Token *tok2 = tok->tokAt(3);
|
Token *tok2 = tok->tokAt(3);
|
||||||
unsigned int indentlevel2 = indentlevel;
|
int indentlevel2 = indentlevel;
|
||||||
while (tok2->next() && tok2->next() != end) {
|
while (tok2->next() && tok2->next() != end) {
|
||||||
if (Token::Match(tok2->next(), "{|[|(")) {
|
if (Token::Match(tok2->next(), "{|[|(")) {
|
||||||
tok2 = tok2->next()->link();
|
tok2 = tok2->next()->link();
|
||||||
|
@ -9077,7 +9077,7 @@ void Tokenizer::validate() const
|
||||||
cppcheckError(lastTok);
|
cppcheckError(lastTok);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const Token *findUnmatchedTernaryOp(const Token * const begin, const Token * const end, unsigned depth = 0)
|
static const Token *findUnmatchedTernaryOp(const Token * const begin, const Token * const end, int depth = 0)
|
||||||
{
|
{
|
||||||
std::stack<const Token *> ternaryOp;
|
std::stack<const Token *> ternaryOp;
|
||||||
for (const Token *tok = begin; tok != end && tok->str() != ";"; tok = tok->next()) {
|
for (const Token *tok = begin; tok != end && tok->str() != ";"; tok = tok->next()) {
|
||||||
|
@ -9207,7 +9207,7 @@ void Tokenizer::findGarbageCode() const
|
||||||
if (!Token::simpleMatch(tok, "for (")) // find for loops
|
if (!Token::simpleMatch(tok, "for (")) // find for loops
|
||||||
continue;
|
continue;
|
||||||
// count number of semicolons
|
// count number of semicolons
|
||||||
unsigned int semicolons = 0;
|
int semicolons = 0;
|
||||||
const Token* const startTok = tok;
|
const Token* const startTok = tok;
|
||||||
tok = tok->next()->link()->previous(); // find ")" of the for-loop
|
tok = tok->next()->link()->previous(); // find ")" of the for-loop
|
||||||
// walk backwards until we find the beginning (startTok) of the for() again
|
// walk backwards until we find the beginning (startTok) of the for() again
|
||||||
|
@ -9337,7 +9337,7 @@ std::string Tokenizer::simplifyString(const std::string &source)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int c = 'a'; // char
|
int c = 'a'; // char
|
||||||
unsigned int sz = 0; // size of stringdata
|
int sz = 0; // size of stringdata
|
||||||
if (str[i+1] == 'x') {
|
if (str[i+1] == 'x') {
|
||||||
sz = 2;
|
sz = 2;
|
||||||
while (sz < 4 && std::isxdigit((unsigned char)str[i+sz]))
|
while (sz < 4 && std::isxdigit((unsigned char)str[i+sz]))
|
||||||
|
@ -9452,7 +9452,7 @@ void Tokenizer::simplifyErrNoInWhile()
|
||||||
|
|
||||||
void Tokenizer::simplifyFuncInWhile()
|
void Tokenizer::simplifyFuncInWhile()
|
||||||
{
|
{
|
||||||
unsigned int count = 0;
|
int count = 0;
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
if (!Token::Match(tok, "while ( %name% ( %name% ) ) {"))
|
if (!Token::Match(tok, "while ( %name% ( %name% ) ) {"))
|
||||||
continue;
|
continue;
|
||||||
|
@ -9461,7 +9461,7 @@ void Tokenizer::simplifyFuncInWhile()
|
||||||
const Token * const var = tok->tokAt(4);
|
const Token * const var = tok->tokAt(4);
|
||||||
Token * const end = tok->next()->link()->next()->link();
|
Token * const end = tok->next()->link()->next()->link();
|
||||||
|
|
||||||
const unsigned int varid = ++mVarId; // Create new variable
|
const int varid = ++mVarId; // Create new variable
|
||||||
const std::string varname("cppcheck:r" + MathLib::toString(++count));
|
const std::string varname("cppcheck:r" + MathLib::toString(++count));
|
||||||
tok->str("int");
|
tok->str("int");
|
||||||
tok->next()->insertToken(varname);
|
tok->next()->insertToken(varname);
|
||||||
|
@ -9492,7 +9492,7 @@ void Tokenizer::simplifyStructDecl()
|
||||||
const bool cpp = isCPP();
|
const bool cpp = isCPP();
|
||||||
|
|
||||||
// A counter that is used when giving unique names for anonymous structs.
|
// A counter that is used when giving unique names for anonymous structs.
|
||||||
unsigned int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
// Skip simplification of unions in class definition
|
// Skip simplification of unions in class definition
|
||||||
std::stack<bool> skip; // true = in function, false = not in function
|
std::stack<bool> skip; // true = in function, false = not in function
|
||||||
|
@ -10002,7 +10002,7 @@ void Tokenizer::simplifyAssignmentBlock()
|
||||||
const std::string &varname = tok->next()->str();
|
const std::string &varname = tok->next()->str();
|
||||||
|
|
||||||
// goto the "} )"
|
// goto the "} )"
|
||||||
unsigned int indentlevel = 0;
|
int indentlevel = 0;
|
||||||
Token *tok2 = tok;
|
Token *tok2 = tok;
|
||||||
while (nullptr != (tok2 = tok2->next())) {
|
while (nullptr != (tok2 = tok2->next())) {
|
||||||
if (Token::Match(tok2, "(|{"))
|
if (Token::Match(tok2, "(|{"))
|
||||||
|
@ -10052,7 +10052,7 @@ void Tokenizer::simplifyAsm()
|
||||||
else if (Token::Match(tok, "_asm|__asm")) {
|
else if (Token::Match(tok, "_asm|__asm")) {
|
||||||
Token *endasm = tok->next();
|
Token *endasm = tok->next();
|
||||||
const Token *firstSemiColon = nullptr;
|
const Token *firstSemiColon = nullptr;
|
||||||
unsigned int comment = 0;
|
int comment = 0;
|
||||||
while (Token::Match(endasm, "%num%|%name%|,|:|;") || (endasm && endasm->linenr() == comment)) {
|
while (Token::Match(endasm, "%num%|%name%|,|:|;") || (endasm && endasm->linenr() == comment)) {
|
||||||
if (Token::Match(endasm, "_asm|__asm|__endasm"))
|
if (Token::Match(endasm, "_asm|__asm|__endasm"))
|
||||||
break;
|
break;
|
||||||
|
@ -10097,7 +10097,7 @@ void Tokenizer::simplifyAsm()
|
||||||
tok = tok->tokAt(2);
|
tok = tok->tokAt(2);
|
||||||
if (tok->next() && tok->next()->str() == ";" &&
|
if (tok->next() && tok->next()->str() == ";" &&
|
||||||
tok->next()->linenr() != tok->linenr()) {
|
tok->next()->linenr() != tok->linenr()) {
|
||||||
const unsigned int endposition = tok->next()->linenr();
|
const int endposition = tok->next()->linenr();
|
||||||
tok = tok->tokAt(-3);
|
tok = tok->tokAt(-3);
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
@ -10567,7 +10567,7 @@ void Tokenizer::simplifyQtSignalsSlots()
|
||||||
}
|
}
|
||||||
|
|
||||||
// count { and } for tok2
|
// count { and } for tok2
|
||||||
unsigned int indentlevel = 0;
|
int indentlevel = 0;
|
||||||
for (Token *tok2 = tok; tok2; tok2 = tok2->next()) {
|
for (Token *tok2 = tok; tok2; tok2 = tok2->next()) {
|
||||||
if (tok2->str() == "{") {
|
if (tok2->str() == "{") {
|
||||||
++indentlevel;
|
++indentlevel;
|
||||||
|
@ -10850,7 +10850,7 @@ void Tokenizer::printUnknownTypes() const
|
||||||
|
|
||||||
std::multimap<std::string, const Token *> unknowns;
|
std::multimap<std::string, const Token *> unknowns;
|
||||||
|
|
||||||
for (unsigned int i = 1; i <= mVarId; ++i) {
|
for (int i = 1; i <= mVarId; ++i) {
|
||||||
const Variable *var = mSymbolDatabase->getVariableFromVarId(i);
|
const Variable *var = mSymbolDatabase->getVariableFromVarId(i);
|
||||||
if (!var)
|
if (!var)
|
||||||
continue;
|
continue;
|
||||||
|
@ -11033,7 +11033,7 @@ void Tokenizer::prepareTernaryOpForAST()
|
||||||
for (Token* tok = list.front(); tok; tok = tok->next()) {
|
for (Token* tok = list.front(); tok; tok = tok->next()) {
|
||||||
if (tok->str() == "?") {
|
if (tok->str() == "?") {
|
||||||
bool parenthesesNeeded = false;
|
bool parenthesesNeeded = false;
|
||||||
unsigned int depth = 0;
|
int depth = 0;
|
||||||
Token* tok2 = tok->next();
|
Token* tok2 = tok->next();
|
||||||
for (; tok2; tok2 = tok2->next()) {
|
for (; tok2; tok2 = tok2->next()) {
|
||||||
if (tok2->link() && Token::Match(tok2, "[|(|<"))
|
if (tok2->link() && Token::Match(tok2, "[|(|<"))
|
||||||
|
@ -11281,7 +11281,7 @@ Tokenizer::VariableMap::VariableMap() : mVarId(0) {}
|
||||||
|
|
||||||
void Tokenizer::VariableMap::enterScope()
|
void Tokenizer::VariableMap::enterScope()
|
||||||
{
|
{
|
||||||
mScopeInfo.push(std::list<std::pair<std::string, unsigned int>>());
|
mScopeInfo.push(std::list<std::pair<std::string, int>>());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Tokenizer::VariableMap::leaveScope()
|
bool Tokenizer::VariableMap::leaveScope()
|
||||||
|
@ -11289,7 +11289,7 @@ bool Tokenizer::VariableMap::leaveScope()
|
||||||
if (mScopeInfo.empty())
|
if (mScopeInfo.empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (const std::pair<std::string, unsigned int> &outerVariable : mScopeInfo.top()) {
|
for (const std::pair<std::string, int> &outerVariable : mScopeInfo.top()) {
|
||||||
if (outerVariable.second != 0)
|
if (outerVariable.second != 0)
|
||||||
mVariableId[outerVariable.first] = outerVariable.second;
|
mVariableId[outerVariable.first] = outerVariable.second;
|
||||||
else
|
else
|
||||||
|
@ -11305,13 +11305,13 @@ void Tokenizer::VariableMap::addVariable(const std::string &varname)
|
||||||
mVariableId[varname] = ++mVarId;
|
mVariableId[varname] = ++mVarId;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::map<std::string, unsigned int>::iterator it = mVariableId.find(varname);
|
std::map<std::string, int>::iterator it = mVariableId.find(varname);
|
||||||
if (it == mVariableId.end()) {
|
if (it == mVariableId.end()) {
|
||||||
mScopeInfo.top().push_back(std::pair<std::string, unsigned int>(varname, 0));
|
mScopeInfo.top().push_back(std::pair<std::string, int>(varname, 0));
|
||||||
mVariableId[varname] = ++mVarId;
|
mVariableId[varname] = ++mVarId;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mScopeInfo.top().push_back(std::pair<std::string, unsigned int>(varname, it->second));
|
mScopeInfo.top().push_back(std::pair<std::string, int>(varname, it->second));
|
||||||
it->second = ++mVarId;
|
it->second = ++mVarId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,25 +58,25 @@ class CPPCHECKLIB Tokenizer {
|
||||||
/** Class used in Tokenizer::setVarIdPass1 */
|
/** Class used in Tokenizer::setVarIdPass1 */
|
||||||
class VariableMap {
|
class VariableMap {
|
||||||
private:
|
private:
|
||||||
std::map<std::string, unsigned int> mVariableId;
|
std::map<std::string, int> mVariableId;
|
||||||
std::stack<std::list<std::pair<std::string, unsigned int> > > mScopeInfo;
|
std::stack<std::list<std::pair<std::string,int> > > mScopeInfo;
|
||||||
mutable unsigned int mVarId;
|
mutable nonneg int mVarId;
|
||||||
public:
|
public:
|
||||||
VariableMap();
|
VariableMap();
|
||||||
void enterScope();
|
void enterScope();
|
||||||
bool leaveScope();
|
bool leaveScope();
|
||||||
void addVariable(const std::string &varname);
|
void addVariable(const std::string &varname);
|
||||||
bool hasVariable(const std::string &varname) const;
|
bool hasVariable(const std::string &varname) const;
|
||||||
std::map<std::string, unsigned int>::const_iterator find(const std::string &varname) const {
|
std::map<std::string,int>::const_iterator find(const std::string &varname) const {
|
||||||
return mVariableId.find(varname);
|
return mVariableId.find(varname);
|
||||||
}
|
}
|
||||||
std::map<std::string, unsigned int>::const_iterator end() const {
|
std::map<std::string,int>::const_iterator end() const {
|
||||||
return mVariableId.end();
|
return mVariableId.end();
|
||||||
}
|
}
|
||||||
const std::map<std::string, unsigned int> &map() const {
|
const std::map<std::string,int> &map() const {
|
||||||
return mVariableId;
|
return mVariableId;
|
||||||
}
|
}
|
||||||
unsigned int *getVarId() const {
|
nonneg int *getVarId() const {
|
||||||
return &mVarId;
|
return &mVarId;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -199,7 +199,7 @@ public:
|
||||||
* @param type Token which will contain e.g. "int", "*", or string.
|
* @param type Token which will contain e.g. "int", "*", or string.
|
||||||
* @return sizeof for given type, or 0 if it can't be calculated.
|
* @return sizeof for given type, or 0 if it can't be calculated.
|
||||||
*/
|
*/
|
||||||
unsigned int sizeOfType(const Token *type) const;
|
nonneg int sizeOfType(const Token *type) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try to determine if function parameter is passed by value by looking
|
* Try to determine if function parameter is passed by value by looking
|
||||||
|
@ -403,13 +403,13 @@ public:
|
||||||
* Utility function for simplifyKnownVariables. Get data about an
|
* Utility function for simplifyKnownVariables. Get data about an
|
||||||
* assigned variable.
|
* assigned variable.
|
||||||
*/
|
*/
|
||||||
static bool simplifyKnownVariablesGetData(unsigned int varid, Token **_tok2, Token **_tok3, std::string &value, unsigned int &valueVarId, bool &valueIsPointer, bool floatvar);
|
static bool simplifyKnownVariablesGetData(nonneg int varid, Token **_tok2, Token **_tok3, std::string &value, nonneg int &valueVarId, bool &valueIsPointer, bool floatvar);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* utility function for simplifyKnownVariables. Perform simplification
|
* utility function for simplifyKnownVariables. Perform simplification
|
||||||
* of a given variable
|
* of a given variable
|
||||||
*/
|
*/
|
||||||
bool simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsigned int varid, const std::string &structname, std::string &value, unsigned int valueVarId, bool valueIsPointer, const Token * const valueToken, int indentlevel) const;
|
bool simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, nonneg int varid, const std::string &structname, std::string &value, nonneg int valueVarId, bool valueIsPointer, const Token * const valueToken, int indentlevel) const;
|
||||||
|
|
||||||
/** Simplify useless C++ empty namespaces, like: 'namespace %name% { }'*/
|
/** Simplify useless C++ empty namespaces, like: 'namespace %name% { }'*/
|
||||||
void simplifyEmptyNamespaces();
|
void simplifyEmptyNamespaces();
|
||||||
|
@ -765,19 +765,19 @@ private:
|
||||||
|
|
||||||
void setVarIdClassDeclaration(const Token * const startToken,
|
void setVarIdClassDeclaration(const Token * const startToken,
|
||||||
const VariableMap &variableMap,
|
const VariableMap &variableMap,
|
||||||
const unsigned int scopeStartVarId,
|
const nonneg int scopeStartVarId,
|
||||||
std::map<unsigned int, std::map<std::string,unsigned int> >& structMembers);
|
std::map<int, std::map<std::string,int> >& structMembers);
|
||||||
|
|
||||||
void setVarIdStructMembers(Token **tok1,
|
void setVarIdStructMembers(Token **tok1,
|
||||||
std::map<unsigned int, std::map<std::string, unsigned int> >& structMembers,
|
std::map<int, std::map<std::string, int> >& structMembers,
|
||||||
unsigned int *varId);
|
nonneg int *varId);
|
||||||
|
|
||||||
void setVarIdClassFunction(const std::string &classname,
|
void setVarIdClassFunction(const std::string &classname,
|
||||||
Token * const startToken,
|
Token * const startToken,
|
||||||
const Token * const endToken,
|
const Token * const endToken,
|
||||||
const std::map<std::string, unsigned int> &varlist,
|
const std::map<std::string,int> &varlist,
|
||||||
std::map<unsigned int, std::map<std::string, unsigned int> >& structMembers,
|
std::map<int, std::map<std::string,int> >& structMembers,
|
||||||
unsigned int *varId_);
|
nonneg int *varId_);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simplify e.g. 'return(strncat(temp,"a",1));' into
|
* Simplify e.g. 'return(strncat(temp,"a",1));' into
|
||||||
|
@ -817,7 +817,7 @@ public:
|
||||||
* 1=1st simplifications
|
* 1=1st simplifications
|
||||||
* 2=2nd simplifications
|
* 2=2nd simplifications
|
||||||
*/
|
*/
|
||||||
void printDebugOutput(unsigned int simplification) const;
|
void printDebugOutput(int simplification) const;
|
||||||
|
|
||||||
void dump(std::ostream &out) const;
|
void dump(std::ostream &out) const;
|
||||||
|
|
||||||
|
@ -827,7 +827,7 @@ public:
|
||||||
* Get variable count.
|
* Get variable count.
|
||||||
* @return number of variables
|
* @return number of variables
|
||||||
*/
|
*/
|
||||||
unsigned int varIdCount() const {
|
nonneg int varIdCount() const {
|
||||||
return mVarId;
|
return mVarId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -895,7 +895,7 @@ private:
|
||||||
* Get new variable id.
|
* Get new variable id.
|
||||||
* @return new variable id
|
* @return new variable id
|
||||||
*/
|
*/
|
||||||
unsigned int newVarId() {
|
nonneg int newVarId() {
|
||||||
return ++mVarId;
|
return ++mVarId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -918,13 +918,13 @@ private:
|
||||||
std::string mConfiguration;
|
std::string mConfiguration;
|
||||||
|
|
||||||
/** sizeof information for known types */
|
/** sizeof information for known types */
|
||||||
std::map<std::string, unsigned int> mTypeSize;
|
std::map<std::string, int> mTypeSize;
|
||||||
|
|
||||||
/** variable count */
|
/** variable count */
|
||||||
unsigned int mVarId;
|
nonneg int mVarId;
|
||||||
|
|
||||||
/** unnamed count "Unnamed0", "Unnamed1", "Unnamed2", ... */
|
/** unnamed count "Unnamed0", "Unnamed1", "Unnamed2", ... */
|
||||||
unsigned int mUnnamedCount;
|
nonneg int mUnnamedCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* was there any templates? templates that are "unused" are
|
* was there any templates? templates that are "unused" are
|
||||||
|
|
Loading…
Reference in New Issue