Added pointer to Type to Token (similar to Token::Variable() and Token::function()):
- Accessible via Token::type() - Renamed former Token::type() to Token::tokType() - Removed SymbolDatabase::isClassOrStruct()
This commit is contained in:
parent
aaefdd2f92
commit
4d80df2f4a
|
@ -238,7 +238,7 @@ bool isSameExpression(bool cpp, const Token *tok1, const Token *tok2, const std:
|
||||||
if (t1 != end1 || t2 != end2)
|
if (t1 != end1 || t2 != end2)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (tok1->type() == Token::eIncDecOp || tok1->isAssignmentOp())
|
if (tok1->tokType() == Token::eIncDecOp || tok1->isAssignmentOp())
|
||||||
return false;
|
return false;
|
||||||
// bailout when we see ({..})
|
// bailout when we see ({..})
|
||||||
if (tok1->str() == "{")
|
if (tok1->str() == "{")
|
||||||
|
@ -328,7 +328,7 @@ bool isConstExpression(const Token *tok, const std::set<std::string> &constFunct
|
||||||
else if (tok->function() && !tok->function()->isConst())
|
else if (tok->function() && !tok->function()->isConst())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (tok->type() == Token::eIncDecOp)
|
if (tok->tokType() == Token::eIncDecOp)
|
||||||
return false;
|
return false;
|
||||||
// bailout when we see ({..})
|
// bailout when we see ({..})
|
||||||
if (tok->str() == "{")
|
if (tok->str() == "{")
|
||||||
|
|
|
@ -44,7 +44,7 @@ void CheckAssert::assertWithSideEffects()
|
||||||
for (const Token* tmp = tok->next(); tmp != endTok; tmp = tmp->next()) {
|
for (const Token* tmp = tok->next(); tmp != endTok; tmp = tmp->next()) {
|
||||||
checkVariableAssignment(tmp);
|
checkVariableAssignment(tmp);
|
||||||
|
|
||||||
if (tmp->type() == Token::eFunction) {
|
if (tmp->tokType() == Token::eFunction) {
|
||||||
const Function* f = tmp->function();
|
const Function* f = tmp->function();
|
||||||
|
|
||||||
if (f->nestedIn->isClassOrStruct() && !f->isStatic() && !f->isConst())
|
if (f->nestedIn->isClassOrStruct() && !f->isStatic() && !f->isConst())
|
||||||
|
@ -54,7 +54,7 @@ void CheckAssert::assertWithSideEffects()
|
||||||
if (!scope) continue;
|
if (!scope) continue;
|
||||||
|
|
||||||
for (const Token *tok2 = scope->classStart; tok2 != scope->classEnd; tok2 = tok2->next()) {
|
for (const Token *tok2 = scope->classStart; tok2 != scope->classEnd; tok2 = tok2->next()) {
|
||||||
if (tok2->type() != Token::eAssignmentOp && tok2->type() != Token::eIncDecOp)
|
if (tok2->tokType() != Token::eAssignmentOp && tok2->tokType() != Token::eIncDecOp)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const Variable* var = tok2->previous()->variable();
|
const Variable* var = tok2->previous()->variable();
|
||||||
|
@ -113,7 +113,7 @@ void CheckAssert::checkVariableAssignment(const Token* assignTok)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// assignment
|
// assignment
|
||||||
if (assignTok->isAssignmentOp() || assignTok->type() == Token::eIncDecOp) {
|
if (assignTok->isAssignmentOp() || assignTok->tokType() == Token::eIncDecOp) {
|
||||||
if (prevVar->isConst())
|
if (prevVar->isConst())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -305,8 +305,6 @@ void CheckAutoVariables::errorUselessAssignmentPtrArg(const Token *tok)
|
||||||
// return temporary?
|
// return temporary?
|
||||||
bool CheckAutoVariables::returnTemporary(const Token *tok) const
|
bool CheckAutoVariables::returnTemporary(const Token *tok) const
|
||||||
{
|
{
|
||||||
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
|
|
||||||
|
|
||||||
bool func = false; // Might it be a function call?
|
bool func = false; // Might it be a function call?
|
||||||
bool retref = false; // is there such a function that returns a reference?
|
bool retref = false; // is there such a function that returns a reference?
|
||||||
bool retvalue = false; // is there such a function that returns a value?
|
bool retvalue = false; // is there such a function that returns a value?
|
||||||
|
@ -330,7 +328,7 @@ bool CheckAutoVariables::returnTemporary(const Token *tok) const
|
||||||
else
|
else
|
||||||
retref = true; // Assume that a reference is returned
|
retref = true; // Assume that a reference is returned
|
||||||
} else {
|
} else {
|
||||||
if (symbolDatabase->isClassOrStruct(start->str()))
|
if (start->type())
|
||||||
retvalue = true;
|
retvalue = true;
|
||||||
else
|
else
|
||||||
retref = true;
|
retref = true;
|
||||||
|
@ -338,7 +336,7 @@ bool CheckAutoVariables::returnTemporary(const Token *tok) const
|
||||||
}
|
}
|
||||||
func = true;
|
func = true;
|
||||||
}
|
}
|
||||||
if (!func && symbolDatabase->isClassOrStruct(tok->str()))
|
if (!func && tok->type())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return bool(!retref && retvalue);
|
return bool(!retref && retvalue);
|
||||||
|
|
|
@ -227,7 +227,7 @@ void CheckBool::checkComparisonOfFuncReturningBool()
|
||||||
for (std::size_t i = 0; i < functionsCount; ++i) {
|
for (std::size_t i = 0; i < functionsCount; ++i) {
|
||||||
const Scope * scope = symbolDatabase->functionScopes[i];
|
const Scope * scope = symbolDatabase->functionScopes[i];
|
||||||
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
|
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
|
||||||
if (tok->type() != Token::eComparisonOp || tok->str() == "==" || tok->str() == "!=")
|
if (tok->tokType() != Token::eComparisonOp || tok->str() == "==" || tok->str() == "!=")
|
||||||
continue;
|
continue;
|
||||||
const Token *firstToken = tok->previous();
|
const Token *firstToken = tok->previous();
|
||||||
if (tok->strAt(-1) == ")") {
|
if (tok->strAt(-1) == ")") {
|
||||||
|
@ -291,7 +291,7 @@ void CheckBool::checkComparisonOfBoolWithBool()
|
||||||
for (std::size_t i = 0; i < functions; ++i) {
|
for (std::size_t i = 0; i < functions; ++i) {
|
||||||
const Scope * scope = symbolDatabase->functionScopes[i];
|
const Scope * scope = symbolDatabase->functionScopes[i];
|
||||||
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
|
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
|
||||||
if (tok->type() != Token::eComparisonOp || tok->str() == "==" || tok->str() == "!=")
|
if (tok->tokType() != Token::eComparisonOp || tok->str() == "==" || tok->str() == "!=")
|
||||||
continue;
|
continue;
|
||||||
bool firstTokenBool = false;
|
bool firstTokenBool = false;
|
||||||
|
|
||||||
|
|
|
@ -319,7 +319,7 @@ static bool checkMinSizes(const std::list<Library::ArgumentChecks::MinSize> &min
|
||||||
const MathLib::bigint sz = MathLib::toLongNumber(argtok->str());
|
const MathLib::bigint sz = MathLib::toLongNumber(argtok->str());
|
||||||
if ((std::size_t)sz > arraySize)
|
if ((std::size_t)sz > arraySize)
|
||||||
error = true;
|
error = true;
|
||||||
} else if (argtok->type() == Token::eChar && Token::Match(argtok->next(), ",|)") && charSizeToken)
|
} else if (argtok->tokType() == Token::eChar && Token::Match(argtok->next(), ",|)") && charSizeToken)
|
||||||
*charSizeToken = argtok; //sizeArgumentAsCharError(argtok);
|
*charSizeToken = argtok; //sizeArgumentAsCharError(argtok);
|
||||||
break;
|
break;
|
||||||
case Library::ArgumentChecks::MinSize::MUL:
|
case Library::ArgumentChecks::MinSize::MUL:
|
||||||
|
@ -352,7 +352,7 @@ static bool checkMinSizes(const std::list<Library::ArgumentChecks::MinSize> &min
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Library::ArgumentChecks::MinSize::SIZEOF:
|
case Library::ArgumentChecks::MinSize::SIZEOF:
|
||||||
if (argtok->type() == Token::eString && Token::getStrLength(argtok) >= arraySize)
|
if (argtok->tokType() == Token::eString && Token::getStrLength(argtok) >= arraySize)
|
||||||
error = true;
|
error = true;
|
||||||
break;
|
break;
|
||||||
case Library::ArgumentChecks::MinSize::NONE:
|
case Library::ArgumentChecks::MinSize::NONE:
|
||||||
|
@ -1470,13 +1470,13 @@ MathLib::biguint CheckBufferOverrun::countSprintfLength(const std::string &input
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
i_d_x_f_found = true;
|
i_d_x_f_found = true;
|
||||||
if (paramIter != parameters.end() && *paramIter && (*paramIter)->type() != Token::eString)
|
if (paramIter != parameters.end() && *paramIter && (*paramIter)->tokType() != Token::eString)
|
||||||
parameterLength = (*paramIter)->str().length();
|
parameterLength = (*paramIter)->str().length();
|
||||||
|
|
||||||
handleNextParameter = true;
|
handleNextParameter = true;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
if (paramIter != parameters.end() && *paramIter && (*paramIter)->type() == Token::eString)
|
if (paramIter != parameters.end() && *paramIter && (*paramIter)->tokType() == Token::eString)
|
||||||
parameterLength = Token::getStrLength(*paramIter);
|
parameterLength = Token::getStrLength(*paramIter);
|
||||||
|
|
||||||
handleNextParameter = true;
|
handleNextParameter = true;
|
||||||
|
@ -1765,7 +1765,7 @@ void CheckBufferOverrun::arrayIndexThenCheck()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// skip comparison
|
// skip comparison
|
||||||
if (tok->type() == Token::eComparisonOp)
|
if (tok->tokType() == Token::eComparisonOp)
|
||||||
tok = tok->tokAt(2);
|
tok = tok->tokAt(2);
|
||||||
|
|
||||||
if (!tok)
|
if (!tok)
|
||||||
|
|
|
@ -1043,11 +1043,8 @@ void CheckClass::checkMemset()
|
||||||
if (typeTok && typeTok->str() == "(")
|
if (typeTok && typeTok->str() == "(")
|
||||||
typeTok = typeTok->next();
|
typeTok = typeTok->next();
|
||||||
|
|
||||||
if (!type) {
|
if (!type && typeTok->type())
|
||||||
const Type* t = symbolDatabase->findVariableType(scope, typeTok);
|
type = typeTok->type()->classScope;
|
||||||
if (t)
|
|
||||||
type = t->classScope;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type) {
|
if (type) {
|
||||||
std::list<const Scope *> parsedTypes;
|
std::list<const Scope *> parsedTypes;
|
||||||
|
@ -1693,7 +1690,7 @@ void CheckClass::checkConst()
|
||||||
} else {
|
} else {
|
||||||
// don't warn for unknown types..
|
// don't warn for unknown types..
|
||||||
// LPVOID, HDC, etc
|
// LPVOID, HDC, etc
|
||||||
if (previous->isUpperCaseName() && previous->str().size() > 2 && !symbolDatabase->isClassOrStruct(previous->str()))
|
if (previous->str().size() > 2 && !previous->type() && previous->isUpperCaseName())
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1854,13 +1851,13 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool&
|
||||||
const Token* lhs = tok1->tokAt(-1);
|
const Token* lhs = tok1->tokAt(-1);
|
||||||
if (lhs->str() == "&") {
|
if (lhs->str() == "&") {
|
||||||
lhs = lhs->previous();
|
lhs = lhs->previous();
|
||||||
if (lhs->type() == Token::eAssignmentOp && lhs->previous()->variable()) {
|
if (lhs->tokType() == Token::eAssignmentOp && lhs->previous()->variable()) {
|
||||||
if (lhs->previous()->variable()->typeStartToken()->strAt(-1) != "const" && lhs->previous()->variable()->isPointer())
|
if (lhs->previous()->variable()->typeStartToken()->strAt(-1) != "const" && lhs->previous()->variable()->isPointer())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const Variable* v2 = lhs->previous()->variable();
|
const Variable* v2 = lhs->previous()->variable();
|
||||||
if (lhs->type() == Token::eAssignmentOp && v2)
|
if (lhs->tokType() == Token::eAssignmentOp && v2)
|
||||||
if (!v2->isConst() && v2->isReference() && lhs == v2->nameToken()->next())
|
if (!v2->isConst() && v2->isReference() && lhs == v2->nameToken()->next())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1900,7 +1897,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool&
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assignment
|
// Assignment
|
||||||
else if (end->next()->type() == Token::eAssignmentOp)
|
else if (end->next()->tokType() == Token::eAssignmentOp)
|
||||||
return (false);
|
return (false);
|
||||||
|
|
||||||
// Streaming
|
// Streaming
|
||||||
|
@ -1910,7 +1907,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool&
|
||||||
return (false);
|
return (false);
|
||||||
|
|
||||||
// ++/--
|
// ++/--
|
||||||
else if (end->next()->type() == Token::eIncDecOp || tok1->previous()->type() == Token::eIncDecOp)
|
else if (end->next()->tokType() == Token::eIncDecOp || tok1->previous()->tokType() == Token::eIncDecOp)
|
||||||
return (false);
|
return (false);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -852,7 +852,7 @@ void CheckCondition::clarifyCondition()
|
||||||
for (const Token *tok2 = tok->tokAt(3); tok2; tok2 = tok2->next()) {
|
for (const Token *tok2 = tok->tokAt(3); tok2; tok2 = tok2->next()) {
|
||||||
if (tok2->str() == "(" || tok2->str() == "[")
|
if (tok2->str() == "(" || tok2->str() == "[")
|
||||||
tok2 = tok2->link();
|
tok2 = tok2->link();
|
||||||
else if (tok2->type() == Token::eComparisonOp) {
|
else if (tok2->tokType() == Token::eComparisonOp) {
|
||||||
// This might be a template
|
// This might be a template
|
||||||
if (!isC && tok2->link())
|
if (!isC && tok2->link())
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -41,7 +41,7 @@ void CheckInternal::checkTokenMatchPatterns()
|
||||||
|
|
||||||
// Get pattern string
|
// Get pattern string
|
||||||
const Token *pattern_tok = tok->tokAt(4)->nextArgument();
|
const Token *pattern_tok = tok->tokAt(4)->nextArgument();
|
||||||
if (!pattern_tok || pattern_tok->type() != Token::eString)
|
if (!pattern_tok || pattern_tok->tokType() != Token::eString)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const std::string pattern = pattern_tok->strValue();
|
const std::string pattern = pattern_tok->strValue();
|
||||||
|
@ -89,7 +89,7 @@ void CheckInternal::checkTokenSimpleMatchPatterns()
|
||||||
|
|
||||||
// Get pattern string
|
// Get pattern string
|
||||||
const Token *pattern_tok = tok->tokAt(4)->nextArgument();
|
const Token *pattern_tok = tok->tokAt(4)->nextArgument();
|
||||||
if (!pattern_tok || pattern_tok->type() != Token::eString)
|
if (!pattern_tok || pattern_tok->tokType() != Token::eString)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const std::string pattern = pattern_tok->strValue();
|
const std::string pattern = pattern_tok->strValue();
|
||||||
|
@ -171,7 +171,7 @@ void CheckInternal::checkMissingPercentCharacter()
|
||||||
|
|
||||||
// Get pattern string
|
// Get pattern string
|
||||||
const Token *pattern_tok = tok->tokAt(4)->nextArgument();
|
const Token *pattern_tok = tok->tokAt(4)->nextArgument();
|
||||||
if (!pattern_tok || pattern_tok->type() != Token::eString)
|
if (!pattern_tok || pattern_tok->tokType() != Token::eString)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const std::string pattern = pattern_tok->strValue();
|
const std::string pattern = pattern_tok->strValue();
|
||||||
|
@ -226,7 +226,7 @@ void CheckInternal::checkUnknownPattern()
|
||||||
|
|
||||||
// Get pattern string
|
// Get pattern string
|
||||||
const Token *pattern_tok = tok->tokAt(4)->nextArgument();
|
const Token *pattern_tok = tok->tokAt(4)->nextArgument();
|
||||||
if (!pattern_tok || pattern_tok->type() != Token::eString)
|
if (!pattern_tok || pattern_tok->tokType() != Token::eString)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const std::string pattern = pattern_tok->strValue();
|
const std::string pattern = pattern_tok->strValue();
|
||||||
|
@ -286,7 +286,7 @@ void CheckInternal::checkExtraWhitespace()
|
||||||
|
|
||||||
// Get pattern string
|
// Get pattern string
|
||||||
const Token *pattern_tok = tok->tokAt(4)->nextArgument();
|
const Token *pattern_tok = tok->tokAt(4)->nextArgument();
|
||||||
if (!pattern_tok || pattern_tok->type() != Token::eString)
|
if (!pattern_tok || pattern_tok->tokType() != Token::eString)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const std::string pattern = pattern_tok->strValue();
|
const std::string pattern = pattern_tok->strValue();
|
||||||
|
|
|
@ -168,7 +168,7 @@ void CheckIO::checkFileUsage()
|
||||||
tok->strAt(-1) == "=") {
|
tok->strAt(-1) == "=") {
|
||||||
if (tok->str() != "tmpfile") {
|
if (tok->str() != "tmpfile") {
|
||||||
const Token* modeTok = tok->tokAt(2)->nextArgument();
|
const Token* modeTok = tok->tokAt(2)->nextArgument();
|
||||||
if (modeTok && modeTok->type() == Token::eString)
|
if (modeTok && modeTok->tokType() == Token::eString)
|
||||||
mode = modeTok->strValue();
|
mode = modeTok->strValue();
|
||||||
} else
|
} else
|
||||||
mode = "wb+";
|
mode = "wb+";
|
||||||
|
@ -176,7 +176,7 @@ void CheckIO::checkFileUsage()
|
||||||
operation = Filepointer::OPEN;
|
operation = Filepointer::OPEN;
|
||||||
} else if (windows && Token::Match(tok, "fopen_s|freopen_s|_wfopen_s|_wfreopen_s ( & %name%")) {
|
} else if (windows && Token::Match(tok, "fopen_s|freopen_s|_wfopen_s|_wfreopen_s ( & %name%")) {
|
||||||
const Token* modeTok = tok->tokAt(2)->nextArgument()->nextArgument();
|
const Token* modeTok = tok->tokAt(2)->nextArgument()->nextArgument();
|
||||||
if (modeTok && modeTok->type() == Token::eString)
|
if (modeTok && modeTok->tokType() == Token::eString)
|
||||||
mode = modeTok->strValue();
|
mode = modeTok->strValue();
|
||||||
fileTok = tok->tokAt(3);
|
fileTok = tok->tokAt(3);
|
||||||
operation = Filepointer::OPEN;
|
operation = Filepointer::OPEN;
|
||||||
|
@ -380,7 +380,7 @@ void CheckIO::invalidScanf()
|
||||||
formatToken = tok->tokAt(2);
|
formatToken = tok->tokAt(2);
|
||||||
else if (Token::Match(tok, "sscanf|vsscanf|fscanf|vfscanf (")) {
|
else if (Token::Match(tok, "sscanf|vsscanf|fscanf|vfscanf (")) {
|
||||||
const Token* nextArg = tok->tokAt(2)->nextArgument();
|
const Token* nextArg = tok->tokAt(2)->nextArgument();
|
||||||
if (nextArg && nextArg->type() == Token::eString)
|
if (nextArg && nextArg->tokType() == Token::eString)
|
||||||
formatToken = nextArg;
|
formatToken = nextArg;
|
||||||
else
|
else
|
||||||
continue;
|
continue;
|
||||||
|
@ -678,7 +678,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
|
||||||
invalidScanfFormatWidthError(tok, numFormat, numWidth, argInfo.variableInfo);
|
invalidScanfFormatWidthError(tok, numFormat, numWidth, argInfo.variableInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (argListTok && argListTok->type() != Token::eString &&
|
if (argListTok && argListTok->tokType() != Token::eString &&
|
||||||
argInfo.isKnownType() && argInfo.isArrayOrPointer() &&
|
argInfo.isKnownType() && argInfo.isArrayOrPointer() &&
|
||||||
(!Token::Match(argInfo.typeToken, "char|wchar_t") ||
|
(!Token::Match(argInfo.typeToken, "char|wchar_t") ||
|
||||||
argInfo.typeToken->strAt(-1) == "const")) {
|
argInfo.typeToken->strAt(-1) == "const")) {
|
||||||
|
@ -706,7 +706,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
|
||||||
case 'X':
|
case 'X':
|
||||||
case 'o':
|
case 'o':
|
||||||
specifier += *i;
|
specifier += *i;
|
||||||
if (argInfo.typeToken->type() == Token::eString)
|
if (argInfo.typeToken->tokType() == Token::eString)
|
||||||
invalidScanfArgTypeError_int(tok, numFormat, specifier, &argInfo, true);
|
invalidScanfArgTypeError_int(tok, numFormat, specifier, &argInfo, true);
|
||||||
else if (argInfo.isKnownType()) {
|
else if (argInfo.isKnownType()) {
|
||||||
if (!Token::Match(argInfo.typeToken, "char|short|int|long")) {
|
if (!Token::Match(argInfo.typeToken, "char|short|int|long")) {
|
||||||
|
@ -783,7 +783,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
|
||||||
case 'd':
|
case 'd':
|
||||||
case 'i':
|
case 'i':
|
||||||
specifier += *i;
|
specifier += *i;
|
||||||
if (argInfo.typeToken->type() == Token::eString)
|
if (argInfo.typeToken->tokType() == Token::eString)
|
||||||
invalidScanfArgTypeError_int(tok, numFormat, specifier, &argInfo, false);
|
invalidScanfArgTypeError_int(tok, numFormat, specifier, &argInfo, false);
|
||||||
else if (argInfo.isKnownType()) {
|
else if (argInfo.isKnownType()) {
|
||||||
if (!Token::Match(argInfo.typeToken, "char|short|int|long")) {
|
if (!Token::Match(argInfo.typeToken, "char|short|int|long")) {
|
||||||
|
@ -856,7 +856,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
specifier += *i;
|
specifier += *i;
|
||||||
if (argInfo.typeToken->type() == Token::eString)
|
if (argInfo.typeToken->tokType() == Token::eString)
|
||||||
invalidScanfArgTypeError_int(tok, numFormat, specifier, &argInfo, true);
|
invalidScanfArgTypeError_int(tok, numFormat, specifier, &argInfo, true);
|
||||||
else if (argInfo.isKnownType()) {
|
else if (argInfo.isKnownType()) {
|
||||||
if (!Token::Match(argInfo.typeToken, "char|short|int|long")) {
|
if (!Token::Match(argInfo.typeToken, "char|short|int|long")) {
|
||||||
|
@ -937,7 +937,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
|
||||||
case 'G':
|
case 'G':
|
||||||
case 'a':
|
case 'a':
|
||||||
specifier += *i;
|
specifier += *i;
|
||||||
if (argInfo.typeToken->type() == Token::eString)
|
if (argInfo.typeToken->tokType() == Token::eString)
|
||||||
invalidScanfArgTypeError_float(tok, numFormat, specifier, &argInfo);
|
invalidScanfArgTypeError_float(tok, numFormat, specifier, &argInfo);
|
||||||
else if (argInfo.isKnownType()) {
|
else if (argInfo.isKnownType()) {
|
||||||
if (!Token::Match(argInfo.typeToken, "float|double")) {
|
if (!Token::Match(argInfo.typeToken, "float|double")) {
|
||||||
|
@ -1022,7 +1022,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
|
||||||
while (!done) {
|
while (!done) {
|
||||||
switch (*i) {
|
switch (*i) {
|
||||||
case 's':
|
case 's':
|
||||||
if (argListTok->type() != Token::eString &&
|
if (argListTok->tokType() != Token::eString &&
|
||||||
argInfo.isKnownType() && !argInfo.isArrayOrPointer()) {
|
argInfo.isKnownType() && !argInfo.isArrayOrPointer()) {
|
||||||
if (!Token::Match(argInfo.typeToken, "char|wchar_t")) {
|
if (!Token::Match(argInfo.typeToken, "char|wchar_t")) {
|
||||||
if (!(!argInfo.isArrayOrPointer() && argInfo.element))
|
if (!(!argInfo.isArrayOrPointer() && argInfo.element))
|
||||||
|
@ -1032,7 +1032,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
|
||||||
done = true;
|
done = true;
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
if ((argInfo.isKnownType() && (!argInfo.isArrayOrPointer() || argInfo.typeToken->strAt(-1) == "const")) || argListTok->type() == Token::eString)
|
if ((argInfo.isKnownType() && (!argInfo.isArrayOrPointer() || argInfo.typeToken->strAt(-1) == "const")) || argListTok->tokType() == Token::eString)
|
||||||
invalidPrintfArgTypeError_n(tok, numFormat, &argInfo);
|
invalidPrintfArgTypeError_n(tok, numFormat, &argInfo);
|
||||||
done = true;
|
done = true;
|
||||||
break;
|
break;
|
||||||
|
@ -1041,7 +1041,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
|
||||||
case 'X':
|
case 'X':
|
||||||
case 'o':
|
case 'o':
|
||||||
specifier += *i;
|
specifier += *i;
|
||||||
if (argInfo.typeToken->type() == Token::eString)
|
if (argInfo.typeToken->tokType() == Token::eString)
|
||||||
invalidPrintfArgTypeError_int(tok, numFormat, specifier, &argInfo);
|
invalidPrintfArgTypeError_int(tok, numFormat, specifier, &argInfo);
|
||||||
else if (argInfo.isKnownType()) {
|
else if (argInfo.isKnownType()) {
|
||||||
if (argInfo.isArrayOrPointer() && !argInfo.element) {
|
if (argInfo.isArrayOrPointer() && !argInfo.element) {
|
||||||
|
@ -1103,7 +1103,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
|
||||||
case 'd':
|
case 'd':
|
||||||
case 'i':
|
case 'i':
|
||||||
specifier += *i;
|
specifier += *i;
|
||||||
if (argInfo.typeToken->type() == Token::eString) {
|
if (argInfo.typeToken->tokType() == Token::eString) {
|
||||||
invalidPrintfArgTypeError_sint(tok, numFormat, specifier, &argInfo);
|
invalidPrintfArgTypeError_sint(tok, numFormat, specifier, &argInfo);
|
||||||
} else if (argInfo.isKnownType()) {
|
} else if (argInfo.isKnownType()) {
|
||||||
if (argInfo.isArrayOrPointer() && !argInfo.element) {
|
if (argInfo.isArrayOrPointer() && !argInfo.element) {
|
||||||
|
@ -1169,7 +1169,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
specifier += *i;
|
specifier += *i;
|
||||||
if (argInfo.typeToken->type() == Token::eString) {
|
if (argInfo.typeToken->tokType() == Token::eString) {
|
||||||
invalidPrintfArgTypeError_uint(tok, numFormat, specifier, &argInfo);
|
invalidPrintfArgTypeError_uint(tok, numFormat, specifier, &argInfo);
|
||||||
} else if (argInfo.isKnownType()) {
|
} else if (argInfo.isKnownType()) {
|
||||||
if (argInfo.isArrayOrPointer() && !argInfo.element) {
|
if (argInfo.isArrayOrPointer() && !argInfo.element) {
|
||||||
|
@ -1229,7 +1229,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
|
||||||
done = true;
|
done = true;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
if (argInfo.typeToken->type() == Token::eString)
|
if (argInfo.typeToken->tokType() == Token::eString)
|
||||||
invalidPrintfArgTypeError_p(tok, numFormat, &argInfo);
|
invalidPrintfArgTypeError_p(tok, numFormat, &argInfo);
|
||||||
else if (argInfo.isKnownType() && !argInfo.isArrayOrPointer())
|
else if (argInfo.isKnownType() && !argInfo.isArrayOrPointer())
|
||||||
invalidPrintfArgTypeError_p(tok, numFormat, &argInfo);
|
invalidPrintfArgTypeError_p(tok, numFormat, &argInfo);
|
||||||
|
@ -1241,7 +1241,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
|
||||||
case 'g':
|
case 'g':
|
||||||
case 'G':
|
case 'G':
|
||||||
specifier += *i;
|
specifier += *i;
|
||||||
if (argInfo.typeToken->type() == Token::eString)
|
if (argInfo.typeToken->tokType() == Token::eString)
|
||||||
invalidPrintfArgTypeError_float(tok, numFormat, specifier, &argInfo);
|
invalidPrintfArgTypeError_float(tok, numFormat, specifier, &argInfo);
|
||||||
else if (argInfo.isKnownType()) {
|
else if (argInfo.isKnownType()) {
|
||||||
if (argInfo.isArrayOrPointer() && !argInfo.element) {
|
if (argInfo.isArrayOrPointer() && !argInfo.element) {
|
||||||
|
@ -1362,11 +1362,11 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings,
|
||||||
, tempToken(nullptr)
|
, tempToken(nullptr)
|
||||||
{
|
{
|
||||||
if (tok) {
|
if (tok) {
|
||||||
if (tok->type() == Token::eString) {
|
if (tok->tokType() == Token::eString) {
|
||||||
typeToken = tok;
|
typeToken = tok;
|
||||||
return;
|
return;
|
||||||
} else if (tok->str() == "&" || tok->type() == Token::eVariable ||
|
} else if (tok->str() == "&" || tok->tokType() == Token::eVariable ||
|
||||||
tok->type() == Token::eFunction || Token::Match(tok, "%type% ::") ||
|
tok->tokType() == Token::eFunction || Token::Match(tok, "%type% ::") ||
|
||||||
(Token::Match(tok, "static_cast|reinterpret_cast|const_cast <") &&
|
(Token::Match(tok, "static_cast|reinterpret_cast|const_cast <") &&
|
||||||
Token::simpleMatch(tok->linkAt(1), "> (") &&
|
Token::simpleMatch(tok->linkAt(1), "> (") &&
|
||||||
Token::Match(tok->linkAt(1)->linkAt(1), ") ,|)"))) {
|
Token::Match(tok->linkAt(1)->linkAt(1), ") ,|)"))) {
|
||||||
|
@ -1382,7 +1382,7 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings,
|
||||||
}
|
}
|
||||||
while (Token::Match(tok, "%type% ::"))
|
while (Token::Match(tok, "%type% ::"))
|
||||||
tok = tok->tokAt(2);
|
tok = tok->tokAt(2);
|
||||||
if (!tok || !(tok->type() == Token::eVariable || tok->type() == Token::eFunction))
|
if (!tok || !(tok->tokType() == Token::eVariable || tok->tokType() == Token::eFunction))
|
||||||
return;
|
return;
|
||||||
const Token *varTok = nullptr;
|
const Token *varTok = nullptr;
|
||||||
const Token *tok1 = tok->next();
|
const Token *tok1 = tok->next();
|
||||||
|
@ -1390,7 +1390,7 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings,
|
||||||
if (tok1->str() == "," || tok1->str() == ")") {
|
if (tok1->str() == "," || tok1->str() == ")") {
|
||||||
if (tok1->previous()->str() == "]") {
|
if (tok1->previous()->str() == "]") {
|
||||||
varTok = tok1->linkAt(-1)->previous();
|
varTok = tok1->linkAt(-1)->previous();
|
||||||
if (varTok->str() == ")" && varTok->link()->previous()->type() == Token::eFunction) {
|
if (varTok->str() == ")" && varTok->link()->previous()->tokType() == Token::eFunction) {
|
||||||
const Function * function = varTok->link()->previous()->function();
|
const Function * function = varTok->link()->previous()->function();
|
||||||
if (function && function->retDef) {
|
if (function && function->retDef) {
|
||||||
typeToken = function->retDef;
|
typeToken = function->retDef;
|
||||||
|
@ -1401,7 +1401,7 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings,
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (tok1->previous()->str() == ")" && tok1->linkAt(-1)->previous()->type() == Token::eFunction) {
|
} else if (tok1->previous()->str() == ")" && tok1->linkAt(-1)->previous()->tokType() == Token::eFunction) {
|
||||||
const Function * function = tok1->linkAt(-1)->previous()->function();
|
const Function * function = tok1->linkAt(-1)->previous()->function();
|
||||||
if (function && function->retDef) {
|
if (function && function->retDef) {
|
||||||
typeToken = function->retDef;
|
typeToken = function->retDef;
|
||||||
|
@ -1467,7 +1467,7 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings,
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} else if (!(tok1->str() == "." || tok1->type() == Token::eVariable || tok1->type() == Token::eFunction))
|
} else if (!(tok1->str() == "." || tok1->tokType() == Token::eVariable || tok1->tokType() == Token::eFunction))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1875,7 +1875,7 @@ void CheckIO::argumentType(std::ostream& os, const ArgumentInfo * argInfo)
|
||||||
if (argInfo) {
|
if (argInfo) {
|
||||||
os << "\'";
|
os << "\'";
|
||||||
const Token *type = argInfo->typeToken;
|
const Token *type = argInfo->typeToken;
|
||||||
if (type->type() == Token::eString) {
|
if (type->tokType() == Token::eString) {
|
||||||
if (type->isLong())
|
if (type->isLong())
|
||||||
os << "const wchar_t *";
|
os << "const wchar_t *";
|
||||||
else
|
else
|
||||||
|
|
|
@ -85,13 +85,13 @@ void CheckNullPointer::parseFunctionCall(const Token &tok, std::list<const Token
|
||||||
argListTok = secondParam;
|
argListTok = secondParam;
|
||||||
} else if (Token::Match(&tok, "sprintf|fprintf|sscanf|fscanf|fwprintf|fwscanf|swscanf")) {
|
} else if (Token::Match(&tok, "sprintf|fprintf|sscanf|fscanf|fwprintf|fwscanf|swscanf")) {
|
||||||
const Token* formatStringTok = secondParam; // Find second parameter (format string)
|
const Token* formatStringTok = secondParam; // Find second parameter (format string)
|
||||||
if (formatStringTok && formatStringTok->type() == Token::eString) {
|
if (formatStringTok && formatStringTok->tokType() == Token::eString) {
|
||||||
argListTok = formatStringTok->nextArgument(); // Find third parameter (first argument of va_args)
|
argListTok = formatStringTok->nextArgument(); // Find third parameter (first argument of va_args)
|
||||||
formatString = formatStringTok->strValue();
|
formatString = formatStringTok->strValue();
|
||||||
}
|
}
|
||||||
} else if (Token::Match(&tok, "snprintf|fnprintf|swprintf") && secondParam) {
|
} else if (Token::Match(&tok, "snprintf|fnprintf|swprintf") && secondParam) {
|
||||||
const Token* formatStringTok = secondParam->nextArgument(); // Find third parameter (format string)
|
const Token* formatStringTok = secondParam->nextArgument(); // Find third parameter (format string)
|
||||||
if (formatStringTok && formatStringTok->type() == Token::eString) {
|
if (formatStringTok && formatStringTok->tokType() == Token::eString) {
|
||||||
argListTok = formatStringTok->nextArgument(); // Find fourth parameter (first argument of va_args)
|
argListTok = formatStringTok->nextArgument(); // Find fourth parameter (first argument of va_args)
|
||||||
formatString = formatStringTok->strValue();
|
formatString = formatStringTok->strValue();
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,7 +127,7 @@ void CheckOther::clarifyCalculation()
|
||||||
// ? operator where lhs is arithmetical expression
|
// ? operator where lhs is arithmetical expression
|
||||||
if (tok->str() != "?" || !tok->astOperand1() || !tok->astOperand1()->isCalculation())
|
if (tok->str() != "?" || !tok->astOperand1() || !tok->astOperand1()->isCalculation())
|
||||||
continue;
|
continue;
|
||||||
if (!tok->astOperand1()->isArithmeticalOp() && tok->astOperand1()->type() != Token::eBitOp)
|
if (!tok->astOperand1()->isArithmeticalOp() && tok->astOperand1()->tokType() != Token::eBitOp)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Is code clarified by parentheses already?
|
// Is code clarified by parentheses already?
|
||||||
|
@ -267,7 +267,7 @@ void CheckOther::warningOldStylePointerCast()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Is "type" a class?
|
// Is "type" a class?
|
||||||
if (_tokenizer->getSymbolDatabase()->isClassOrStruct(typeTok->str()))
|
if (typeTok->type())
|
||||||
cstyleCastError(tok);
|
cstyleCastError(tok);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -497,7 +497,7 @@ void CheckOther::checkRedundantAssignment()
|
||||||
} else if (Token::Match(tok, "break|return|continue|throw|goto|asm")) {
|
} else if (Token::Match(tok, "break|return|continue|throw|goto|asm")) {
|
||||||
varAssignments.clear();
|
varAssignments.clear();
|
||||||
memAssignments.clear();
|
memAssignments.clear();
|
||||||
} else if (tok->type() == Token::eVariable && !Token::Match(tok, "%name% (")) {
|
} else if (tok->tokType() == Token::eVariable && !Token::Match(tok, "%name% (")) {
|
||||||
// Set initialization flag
|
// Set initialization flag
|
||||||
if (!Token::Match(tok, "%var% ["))
|
if (!Token::Match(tok, "%var% ["))
|
||||||
initialized.insert(tok->varId());
|
initialized.insert(tok->varId());
|
||||||
|
@ -550,7 +550,7 @@ void CheckOther::checkRedundantAssignment()
|
||||||
varAssignments[tok->varId()] = tok;
|
varAssignments[tok->varId()] = tok;
|
||||||
memAssignments.erase(tok->varId());
|
memAssignments.erase(tok->varId());
|
||||||
eraseMemberAssignments(tok->varId(), membervars, varAssignments);
|
eraseMemberAssignments(tok->varId(), membervars, varAssignments);
|
||||||
} else if (tok->next()->type() == Token::eIncDecOp || (tok->previous()->type() == Token::eIncDecOp && tok->strAt(1) == ";")) { // Variable incremented/decremented; Prefix-Increment is only suspicious, if its return value is unused
|
} else if (tok->next()->tokType() == Token::eIncDecOp || (tok->previous()->tokType() == Token::eIncDecOp && tok->strAt(1) == ";")) { // Variable incremented/decremented; Prefix-Increment is only suspicious, if its return value is unused
|
||||||
varAssignments[tok->varId()] = tok;
|
varAssignments[tok->varId()] = tok;
|
||||||
memAssignments.erase(tok->varId());
|
memAssignments.erase(tok->varId());
|
||||||
eraseMemberAssignments(tok->varId(), membervars, varAssignments);
|
eraseMemberAssignments(tok->varId(), membervars, varAssignments);
|
||||||
|
@ -1220,7 +1220,7 @@ void CheckOther::checkVariableScope()
|
||||||
const Token* tok = var->nameToken()->next();
|
const Token* tok = var->nameToken()->next();
|
||||||
if (Token::Match(tok, "; %varid% = %any% ;", var->declarationId())) {
|
if (Token::Match(tok, "; %varid% = %any% ;", var->declarationId())) {
|
||||||
tok = tok->tokAt(3);
|
tok = tok->tokAt(3);
|
||||||
if (!tok->isNumber() && tok->type() != Token::eString && tok->type() != Token::eChar && !tok->isBoolean())
|
if (!tok->isNumber() && tok->tokType() != Token::eString && tok->tokType() != Token::eChar && !tok->isBoolean())
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
bool reduce = true;
|
bool reduce = true;
|
||||||
|
@ -1797,9 +1797,9 @@ void CheckOther::checkMisusedScopedObject()
|
||||||
for (std::size_t i = 0; i < functions; ++i) {
|
for (std::size_t i = 0; i < functions; ++i) {
|
||||||
const Scope * scope = symbolDatabase->functionScopes[i];
|
const Scope * scope = symbolDatabase->functionScopes[i];
|
||||||
for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) {
|
for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) {
|
||||||
if (Token::Match(tok, "[;{}] %name% (")
|
if ((tok->next()->type() || (tok->next()->function() && tok->next()->function()->isConstructor())) // TODO: The rhs of || should be removed; It is a workaround for a symboldatabase bug
|
||||||
|
&& Token::Match(tok, "[;{}] %name% (")
|
||||||
&& Token::Match(tok->linkAt(2), ") ; !!}")
|
&& Token::Match(tok->linkAt(2), ") ; !!}")
|
||||||
&& symbolDatabase->isClassOrStruct(tok->next()->str())
|
|
||||||
&& (!tok->next()->function() || // is not a function on this scope
|
&& (!tok->next()->function() || // is not a function on this scope
|
||||||
tok->next()->function()->isConstructor())) { // or is function in this scope and it's a ctor
|
tok->next()->function()->isConstructor())) { // or is function in this scope and it's a ctor
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
|
|
@ -768,7 +768,7 @@ void CheckStl::size()
|
||||||
|
|
||||||
// check for using as boolean expression
|
// check for using as boolean expression
|
||||||
else if ((Token::Match(tok->tokAt(-2), "if|while (") && end->str() == ")") ||
|
else if ((Token::Match(tok->tokAt(-2), "if|while (") && end->str() == ")") ||
|
||||||
(tok->previous()->type() == Token::eLogicalOp && Token::Match(end, "&&|)|,|;|%oror%"))) {
|
(tok->previous()->tokType() == Token::eLogicalOp && Token::Match(end, "&&|)|,|;|%oror%"))) {
|
||||||
if (isCpp03ContainerSizeSlow(tok1))
|
if (isCpp03ContainerSizeSlow(tok1))
|
||||||
sizeError(tok1);
|
sizeError(tok1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,16 +151,16 @@ void CheckString::checkSuspiciousStringCompare()
|
||||||
for (std::size_t i = 0; i < functions; ++i) {
|
for (std::size_t i = 0; i < functions; ++i) {
|
||||||
const Scope * scope = symbolDatabase->functionScopes[i];
|
const Scope * scope = symbolDatabase->functionScopes[i];
|
||||||
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
|
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
|
||||||
if (tok->type() != Token::eComparisonOp)
|
if (tok->tokType() != Token::eComparisonOp)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const Token* varTok = tok->astOperand1();
|
const Token* varTok = tok->astOperand1();
|
||||||
const Token* litTok = tok->astOperand2();
|
const Token* litTok = tok->astOperand2();
|
||||||
if (!varTok || !litTok) // <- failed to create AST for comparison
|
if (!varTok || !litTok) // <- failed to create AST for comparison
|
||||||
continue;
|
continue;
|
||||||
if (varTok->type() == Token::eString || varTok->type() == Token::eNumber)
|
if (varTok->tokType() == Token::eString || varTok->tokType() == Token::eNumber)
|
||||||
std::swap(varTok, litTok);
|
std::swap(varTok, litTok);
|
||||||
else if (litTok->type() != Token::eString && litTok->type() != Token::eNumber)
|
else if (litTok->tokType() != Token::eString && litTok->tokType() != Token::eNumber)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Pointer addition?
|
// Pointer addition?
|
||||||
|
@ -176,7 +176,7 @@ void CheckString::checkSuspiciousStringCompare()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (varTok->str() == "*") {
|
if (varTok->str() == "*") {
|
||||||
if (!_tokenizer->isC() || varTok->astOperand2() != nullptr || litTok->type() != Token::eString)
|
if (!_tokenizer->isC() || varTok->astOperand2() != nullptr || litTok->tokType() != Token::eString)
|
||||||
continue;
|
continue;
|
||||||
varTok = varTok->astOperand1();
|
varTok = varTok->astOperand1();
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,7 @@ void CheckString::checkSuspiciousStringCompare()
|
||||||
varTok = varTok->astParent();
|
varTok = varTok->astParent();
|
||||||
const std::string varname = varTok->expressionString();
|
const std::string varname = varTok->expressionString();
|
||||||
|
|
||||||
if (litTok->type() == Token::eString) {
|
if (litTok->tokType() == Token::eString) {
|
||||||
if (_tokenizer->isC() || (var && var->isArrayOrPointer()))
|
if (_tokenizer->isC() || (var && var->isArrayOrPointer()))
|
||||||
suspiciousStringCompareError(tok, varname);
|
suspiciousStringCompareError(tok, varname);
|
||||||
} else if (litTok->originalName() == "'\\0'" && var && var->isPointer()) {
|
} else if (litTok->originalName() == "'\\0'" && var && var->isPointer()) {
|
||||||
|
@ -232,8 +232,8 @@ void CheckString::strPlusChar()
|
||||||
const Scope * scope = symbolDatabase->functionScopes[i];
|
const Scope * scope = symbolDatabase->functionScopes[i];
|
||||||
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
|
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
|
||||||
if (tok->str() == "+") {
|
if (tok->str() == "+") {
|
||||||
if (tok->astOperand1() && (tok->astOperand1()->type() == Token::eString)) { // string literal...
|
if (tok->astOperand1() && (tok->astOperand1()->tokType() == Token::eString)) { // string literal...
|
||||||
if (tok->astOperand2() && (tok->astOperand2()->type() == Token::eChar || isChar(tok->astOperand2()->variable()))) // added to char variable or char constant
|
if (tok->astOperand2() && (tok->astOperand2()->tokType() == Token::eChar || isChar(tok->astOperand2()->variable()))) // added to char variable or char constant
|
||||||
strPlusCharError(tok);
|
strPlusCharError(tok);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -878,12 +878,12 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
||||||
else if (tok->str() == "(")
|
else if (tok->str() == "(")
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
|
||||||
if (tok->type() == Token::eIncDecOp) {
|
if (tok->tokType() == Token::eIncDecOp) {
|
||||||
pre = true;
|
pre = true;
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tok->next()->type() == Token::eIncDecOp)
|
if (tok->next()->tokType() == Token::eIncDecOp)
|
||||||
post = true;
|
post = true;
|
||||||
|
|
||||||
const unsigned int varid1 = tok->varId();
|
const unsigned int varid1 = tok->varId();
|
||||||
|
@ -1049,7 +1049,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
||||||
}
|
}
|
||||||
|
|
||||||
// ++|--
|
// ++|--
|
||||||
else if (tok->next() && tok->next()->type() == Token::eIncDecOp && tok->next()->astOperand1() && tok->next()->astOperand1()->varId()) {
|
else if (tok->next() && tok->next()->tokType() == Token::eIncDecOp && tok->next()->astOperand1() && tok->next()->astOperand1()->varId()) {
|
||||||
if (tok->next()->astParent())
|
if (tok->next()->astParent())
|
||||||
variables.use(tok->next()->astOperand1()->varId(), tok);
|
variables.use(tok->next()->astOperand1()->varId(), tok);
|
||||||
else
|
else
|
||||||
|
|
|
@ -1225,6 +1225,14 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set type pointers
|
||||||
|
for (const Token* tok = _tokenizer->list.front(); tok != _tokenizer->list.back(); tok = tok->next()) {
|
||||||
|
if (!tok->isName() || tok->varId() || tok->function())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const_cast<Token *>(tok)->type(findVariableType(tok->scope(), tok));
|
||||||
|
}
|
||||||
|
|
||||||
// Set variable pointers
|
// Set variable pointers
|
||||||
for (const Token* tok = _tokenizer->list.front(); tok != _tokenizer->list.back(); tok = tok->next()) {
|
for (const Token* tok = _tokenizer->list.front(); tok != _tokenizer->list.back(); tok = tok->next()) {
|
||||||
if (tok->varId())
|
if (tok->varId())
|
||||||
|
@ -1287,9 +1295,10 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
|
|
||||||
SymbolDatabase::~SymbolDatabase()
|
SymbolDatabase::~SymbolDatabase()
|
||||||
{
|
{
|
||||||
// Clear scope, function, and variable pointers
|
// Clear scope, type, function and variable pointers
|
||||||
for (const Token* tok = _tokenizer->list.front(); tok != _tokenizer->list.back(); tok = tok->next()) {
|
for (const Token* tok = _tokenizer->list.front(); tok != _tokenizer->list.back(); tok = tok->next()) {
|
||||||
const_cast<Token *>(tok)->scope(0);
|
const_cast<Token *>(tok)->scope(0);
|
||||||
|
const_cast<Token *>(tok)->type(0);
|
||||||
const_cast<Token *>(tok)->function(0);
|
const_cast<Token *>(tok)->function(0);
|
||||||
const_cast<Token *>(tok)->variable(0);
|
const_cast<Token *>(tok)->variable(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -975,13 +975,6 @@ public:
|
||||||
return const_cast<Scope *>(this->findScope(tok, static_cast<const Scope *>(startScope)));
|
return const_cast<Scope *>(this->findScope(tok, static_cast<const Scope *>(startScope)));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isClassOrStruct(const std::string &type) const {
|
|
||||||
for (std::list<Type>::const_iterator i = typeList.begin(); i != typeList.end(); ++i)
|
|
||||||
if (i->name() == type)
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Variable *getVariableFromVarId(std::size_t varId) const {
|
const Variable *getVariableFromVarId(std::size_t varId) const {
|
||||||
return _variableList.at(varId);
|
return _variableList.at(varId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -277,7 +277,7 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// num/type ..
|
// num/type ..
|
||||||
if (!tok->isNumber() && tok->type() != Token::eChar && !tok->isName())
|
if (!tok->isNumber() && tok->tokType() != Token::eChar && !tok->isName())
|
||||||
return 0;
|
return 0;
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
if (!tok)
|
if (!tok)
|
||||||
|
|
|
@ -44,7 +44,7 @@ Token::Token(Token **t) :
|
||||||
_fileIndex(0),
|
_fileIndex(0),
|
||||||
_linenr(0),
|
_linenr(0),
|
||||||
_progressValue(0),
|
_progressValue(0),
|
||||||
_type(eNone),
|
_tokType(eNone),
|
||||||
_flags(0),
|
_flags(0),
|
||||||
_astOperand1(nullptr),
|
_astOperand1(nullptr),
|
||||||
_astOperand2(nullptr),
|
_astOperand2(nullptr),
|
||||||
|
@ -62,32 +62,32 @@ void Token::update_property_info()
|
||||||
{
|
{
|
||||||
if (!_str.empty()) {
|
if (!_str.empty()) {
|
||||||
if (_str == "true" || _str == "false")
|
if (_str == "true" || _str == "false")
|
||||||
_type = eBoolean;
|
_tokType = eBoolean;
|
||||||
else if (_str[0] == '_' || std::isalpha((unsigned char)_str[0])) { // Name
|
else if (_str[0] == '_' || std::isalpha((unsigned char)_str[0])) { // Name
|
||||||
if (_varId)
|
if (_varId)
|
||||||
_type = eVariable;
|
_tokType = eVariable;
|
||||||
else if (_type != eVariable && _type != eFunction && _type != eType && _type != eKeyword)
|
else if (_tokType != eVariable && _tokType != eFunction && _tokType != eType && _tokType != eKeyword)
|
||||||
_type = eName;
|
_tokType = eName;
|
||||||
} else if (std::isdigit((unsigned char)_str[0]) || (_str.length() > 1 && _str[0] == '-' && std::isdigit((unsigned char)_str[1])))
|
} else if (std::isdigit((unsigned char)_str[0]) || (_str.length() > 1 && _str[0] == '-' && std::isdigit((unsigned char)_str[1])))
|
||||||
_type = eNumber;
|
_tokType = eNumber;
|
||||||
else if (_str.length() > 1 && _str[0] == '"' && _str.back() == '"')
|
else if (_str.length() > 1 && _str[0] == '"' && _str.back() == '"')
|
||||||
_type = eString;
|
_tokType = eString;
|
||||||
else if (_str.length() > 1 && _str[0] == '\'' && _str.back() == '\'')
|
else if (_str.length() > 1 && _str[0] == '\'' && _str.back() == '\'')
|
||||||
_type = eChar;
|
_tokType = eChar;
|
||||||
else if (_str == "=" || _str == "<<=" || _str == ">>=" ||
|
else if (_str == "=" || _str == "<<=" || _str == ">>=" ||
|
||||||
(_str.size() == 2U && _str[1] == '=' && std::strchr("+-*/%&^|", _str[0])))
|
(_str.size() == 2U && _str[1] == '=' && std::strchr("+-*/%&^|", _str[0])))
|
||||||
_type = eAssignmentOp;
|
_tokType = eAssignmentOp;
|
||||||
else if (_str.size() == 1 && _str.find_first_of(",[]()?:") != std::string::npos)
|
else if (_str.size() == 1 && _str.find_first_of(",[]()?:") != std::string::npos)
|
||||||
_type = eExtendedOp;
|
_tokType = eExtendedOp;
|
||||||
else if (_str=="<<" || _str==">>" || (_str.size()==1 && _str.find_first_of("+-*/%") != std::string::npos))
|
else if (_str=="<<" || _str==">>" || (_str.size()==1 && _str.find_first_of("+-*/%") != std::string::npos))
|
||||||
_type = eArithmeticalOp;
|
_tokType = eArithmeticalOp;
|
||||||
else if (_str.size() == 1 && _str.find_first_of("&|^~") != std::string::npos)
|
else if (_str.size() == 1 && _str.find_first_of("&|^~") != std::string::npos)
|
||||||
_type = eBitOp;
|
_tokType = eBitOp;
|
||||||
else if (_str.size() <= 2 &&
|
else if (_str.size() <= 2 &&
|
||||||
(_str == "&&" ||
|
(_str == "&&" ||
|
||||||
_str == "||" ||
|
_str == "||" ||
|
||||||
_str == "!"))
|
_str == "!"))
|
||||||
_type = eLogicalOp;
|
_tokType = eLogicalOp;
|
||||||
else if (_str.size() <= 2 && !_link &&
|
else if (_str.size() <= 2 && !_link &&
|
||||||
(_str == "==" ||
|
(_str == "==" ||
|
||||||
_str == "!=" ||
|
_str == "!=" ||
|
||||||
|
@ -95,17 +95,17 @@ void Token::update_property_info()
|
||||||
_str == "<=" ||
|
_str == "<=" ||
|
||||||
_str == ">" ||
|
_str == ">" ||
|
||||||
_str == ">="))
|
_str == ">="))
|
||||||
_type = eComparisonOp;
|
_tokType = eComparisonOp;
|
||||||
else if (_str.size() == 2 &&
|
else if (_str.size() == 2 &&
|
||||||
(_str == "++" ||
|
(_str == "++" ||
|
||||||
_str == "--"))
|
_str == "--"))
|
||||||
_type = eIncDecOp;
|
_tokType = eIncDecOp;
|
||||||
else if (_str.size() == 1 && (_str.find_first_of("{}") != std::string::npos || (_link && _str.find_first_of("<>") != std::string::npos)))
|
else if (_str.size() == 1 && (_str.find_first_of("{}") != std::string::npos || (_link && _str.find_first_of("<>") != std::string::npos)))
|
||||||
_type = eBracket;
|
_tokType = eBracket;
|
||||||
else
|
else
|
||||||
_type = eOther;
|
_tokType = eOther;
|
||||||
} else {
|
} else {
|
||||||
_type = eNone;
|
_tokType = eNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
update_property_isStandardType();
|
update_property_isStandardType();
|
||||||
|
@ -125,7 +125,7 @@ void Token::update_property_isStandardType()
|
||||||
|
|
||||||
if (stdTypes.find(_str)!=stdTypes.end()) {
|
if (stdTypes.find(_str)!=stdTypes.end()) {
|
||||||
isStandardType(true);
|
isStandardType(true);
|
||||||
_type = eType;
|
_tokType = eType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,10 +151,10 @@ void Token::concatStr(std::string const& b)
|
||||||
|
|
||||||
std::string Token::strValue() const
|
std::string Token::strValue() const
|
||||||
{
|
{
|
||||||
assert(_type == eString);
|
assert(_tokType == eString);
|
||||||
std::string ret(_str.substr(1, _str.length() - 2));
|
std::string ret(_str.substr(1, _str.length() - 2));
|
||||||
std::string::size_type pos = 0U;
|
std::string::size_type pos = 0U;
|
||||||
while ((pos = ret.find("\\",pos)) != std::string::npos) {
|
while ((pos = ret.find('\\', pos)) != std::string::npos) {
|
||||||
ret.erase(pos,1U);
|
ret.erase(pos,1U);
|
||||||
if (ret[pos] >= 'a') {
|
if (ret[pos] >= 'a') {
|
||||||
if (ret[pos] == 'n')
|
if (ret[pos] == 'n')
|
||||||
|
@ -192,7 +192,7 @@ void Token::swapWithNext()
|
||||||
Token temp(0);
|
Token temp(0);
|
||||||
|
|
||||||
temp._str = _next->_str;
|
temp._str = _next->_str;
|
||||||
temp._type = _next->_type;
|
temp._tokType = _next->_tokType;
|
||||||
temp._flags = _next->_flags;
|
temp._flags = _next->_flags;
|
||||||
temp._varId = _next->_varId;
|
temp._varId = _next->_varId;
|
||||||
temp._fileIndex = _next->_fileIndex;
|
temp._fileIndex = _next->_fileIndex;
|
||||||
|
@ -204,7 +204,7 @@ void Token::swapWithNext()
|
||||||
temp._progressValue = _next->_progressValue;
|
temp._progressValue = _next->_progressValue;
|
||||||
|
|
||||||
_next->_str = _str;
|
_next->_str = _str;
|
||||||
_next->_type = _type;
|
_next->_tokType = _tokType;
|
||||||
_next->_flags = _flags;
|
_next->_flags = _flags;
|
||||||
_next->_varId = _varId;
|
_next->_varId = _varId;
|
||||||
_next->_fileIndex = _fileIndex;
|
_next->_fileIndex = _fileIndex;
|
||||||
|
@ -216,7 +216,7 @@ void Token::swapWithNext()
|
||||||
_next->_progressValue = _progressValue;
|
_next->_progressValue = _progressValue;
|
||||||
|
|
||||||
_str = temp._str;
|
_str = temp._str;
|
||||||
_type = temp._type;
|
_tokType = temp._tokType;
|
||||||
_flags = temp._flags;
|
_flags = temp._flags;
|
||||||
_varId = temp._varId;
|
_varId = temp._varId;
|
||||||
_fileIndex = temp._fileIndex;
|
_fileIndex = temp._fileIndex;
|
||||||
|
@ -233,7 +233,7 @@ void Token::deleteThis()
|
||||||
{
|
{
|
||||||
if (_next) { // Copy next to this and delete next
|
if (_next) { // Copy next to this and delete next
|
||||||
_str = _next->_str;
|
_str = _next->_str;
|
||||||
_type = _next->_type;
|
_tokType = _next->_tokType;
|
||||||
_flags = _next->_flags;
|
_flags = _next->_flags;
|
||||||
_varId = _next->_varId;
|
_varId = _next->_varId;
|
||||||
_fileIndex = _next->_fileIndex;
|
_fileIndex = _next->_fileIndex;
|
||||||
|
@ -242,6 +242,7 @@ void Token::deleteThis()
|
||||||
_scope = _next->_scope;
|
_scope = _next->_scope;
|
||||||
_function = _next->_function;
|
_function = _next->_function;
|
||||||
_variable = _next->_variable;
|
_variable = _next->_variable;
|
||||||
|
_type = _next->_type;
|
||||||
if (_next->_originalName) {
|
if (_next->_originalName) {
|
||||||
_originalName = _next->_originalName;
|
_originalName = _next->_originalName;
|
||||||
_next->_originalName = nullptr;
|
_next->_originalName = nullptr;
|
||||||
|
@ -253,7 +254,7 @@ void Token::deleteThis()
|
||||||
deleteNext();
|
deleteNext();
|
||||||
} else if (_previous && _previous->_previous) { // Copy previous to this and delete previous
|
} else if (_previous && _previous->_previous) { // Copy previous to this and delete previous
|
||||||
_str = _previous->_str;
|
_str = _previous->_str;
|
||||||
_type = _previous->_type;
|
_tokType = _previous->_tokType;
|
||||||
_flags = _previous->_flags;
|
_flags = _previous->_flags;
|
||||||
_varId = _previous->_varId;
|
_varId = _previous->_varId;
|
||||||
_fileIndex = _previous->_fileIndex;
|
_fileIndex = _previous->_fileIndex;
|
||||||
|
@ -262,6 +263,7 @@ void Token::deleteThis()
|
||||||
_scope = _previous->_scope;
|
_scope = _previous->_scope;
|
||||||
_function = _previous->_function;
|
_function = _previous->_function;
|
||||||
_variable = _previous->_variable;
|
_variable = _previous->_variable;
|
||||||
|
_type = _previous->_type;
|
||||||
if (_previous->_originalName) {
|
if (_previous->_originalName) {
|
||||||
_originalName = _previous->_originalName;
|
_originalName = _previous->_originalName;
|
||||||
_previous->_originalName = nullptr;
|
_previous->_originalName = nullptr;
|
||||||
|
@ -406,7 +408,7 @@ static int multiComparePercent(const Token *tok, const char*& haystack, bool emp
|
||||||
// Character (%char%)
|
// Character (%char%)
|
||||||
if (haystack[0] == 'h') {
|
if (haystack[0] == 'h') {
|
||||||
haystack += 4;
|
haystack += 4;
|
||||||
if (tok->type() == Token::eChar)
|
if (tok->tokType() == Token::eChar)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
// Const operator (%cop%)
|
// Const operator (%cop%)
|
||||||
|
@ -427,7 +429,7 @@ static int multiComparePercent(const Token *tok, const char*& haystack, bool emp
|
||||||
// String (%str%)
|
// String (%str%)
|
||||||
{
|
{
|
||||||
haystack += 4;
|
haystack += 4;
|
||||||
if (tok->type() == Token::eString)
|
if (tok->tokType() == Token::eString)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -451,7 +453,7 @@ static int multiComparePercent(const Token *tok, const char*& haystack, bool emp
|
||||||
// Or (%or%)
|
// Or (%or%)
|
||||||
else {
|
else {
|
||||||
haystack += 2;
|
haystack += 2;
|
||||||
if (tok->type() == Token::eBitOp && tok->str() == "|")
|
if (tok->tokType() == Token::eBitOp && tok->str() == "|")
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -459,7 +461,7 @@ static int multiComparePercent(const Token *tok, const char*& haystack, bool emp
|
||||||
// Oror (%oror%)
|
// Oror (%oror%)
|
||||||
else {
|
else {
|
||||||
haystack += 4;
|
haystack += 4;
|
||||||
if (tok->type() == Token::eLogicalOp && tok->str() == "||")
|
if (tok->tokType() == Token::eLogicalOp && tok->str() == "||")
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -683,7 +685,7 @@ bool Token::Match(const Token *tok, const char pattern[], unsigned int varid)
|
||||||
std::size_t Token::getStrLength(const Token *tok)
|
std::size_t Token::getStrLength(const Token *tok)
|
||||||
{
|
{
|
||||||
assert(tok != nullptr);
|
assert(tok != nullptr);
|
||||||
assert(tok->_type == eString);
|
assert(tok->_tokType == eString);
|
||||||
|
|
||||||
std::size_t len = 0;
|
std::size_t len = 0;
|
||||||
std::string::const_iterator it = tok->str().begin() + 1U;
|
std::string::const_iterator it = tok->str().begin() + 1U;
|
||||||
|
@ -710,7 +712,7 @@ std::size_t Token::getStrLength(const Token *tok)
|
||||||
|
|
||||||
std::size_t Token::getStrSize(const Token *tok)
|
std::size_t Token::getStrSize(const Token *tok)
|
||||||
{
|
{
|
||||||
assert(tok != nullptr && tok->type() == eString);
|
assert(tok != nullptr && tok->tokType() == eString);
|
||||||
const std::string &str = tok->str();
|
const std::string &str = tok->str();
|
||||||
unsigned int sizeofstring = 1U;
|
unsigned int sizeofstring = 1U;
|
||||||
for (unsigned int i = 1U; i < str.size() - 1U; i++) {
|
for (unsigned int i = 1U; i < str.size() - 1U; i++) {
|
||||||
|
@ -1007,7 +1009,7 @@ void Token::stringify(std::ostream& os, bool varid, bool attributes, bool macro)
|
||||||
else if (isSigned())
|
else if (isSigned())
|
||||||
os << "signed ";
|
os << "signed ";
|
||||||
if (isLong()) {
|
if (isLong()) {
|
||||||
if (_type == eString || _type == eChar)
|
if (_tokType == eString || _tokType == eChar)
|
||||||
os << "L";
|
os << "L";
|
||||||
else
|
else
|
||||||
os << "long ";
|
os << "long ";
|
||||||
|
@ -1015,7 +1017,7 @@ void Token::stringify(std::ostream& os, bool varid, bool attributes, bool macro)
|
||||||
}
|
}
|
||||||
if (macro && isExpandedMacro())
|
if (macro && isExpandedMacro())
|
||||||
os << "$";
|
os << "$";
|
||||||
if (_str[0] != '\"' || _str.find("\0") == std::string::npos)
|
if (_str[0] != '\"' || _str.find('\0') == std::string::npos)
|
||||||
os << _str;
|
os << _str;
|
||||||
else {
|
else {
|
||||||
for (std::size_t i = 0U; i < _str.size(); ++i) {
|
for (std::size_t i = 0U; i < _str.size(); ++i) {
|
||||||
|
@ -1427,7 +1429,7 @@ const Token *Token::getValueTokenMinStrSize() const
|
||||||
std::size_t minsize = ~0U;
|
std::size_t minsize = ~0U;
|
||||||
std::list<ValueFlow::Value>::const_iterator it;
|
std::list<ValueFlow::Value>::const_iterator it;
|
||||||
for (it = values.begin(); it != values.end(); ++it) {
|
for (it = values.begin(); it != values.end(); ++it) {
|
||||||
if (it->tokvalue && it->tokvalue->type() == Token::eString) {
|
if (it->tokvalue && it->tokvalue->tokType() == Token::eString) {
|
||||||
std::size_t size = getStrSize(it->tokvalue);
|
std::size_t size = getStrSize(it->tokvalue);
|
||||||
if (!ret || size < minsize) {
|
if (!ret || size < minsize) {
|
||||||
minsize = size;
|
minsize = size;
|
||||||
|
@ -1444,7 +1446,7 @@ const Token *Token::getValueTokenMaxStrLength() const
|
||||||
std::size_t maxlength = 0U;
|
std::size_t maxlength = 0U;
|
||||||
std::list<ValueFlow::Value>::const_iterator it;
|
std::list<ValueFlow::Value>::const_iterator it;
|
||||||
for (it = values.begin(); it != values.end(); ++it) {
|
for (it = values.begin(); it != values.end(); ++it) {
|
||||||
if (it->tokvalue && it->tokvalue->type() == Token::eString) {
|
if (it->tokvalue && it->tokvalue->tokType() == Token::eString) {
|
||||||
std::size_t length = getStrLength(it->tokvalue);
|
std::size_t length = getStrLength(it->tokvalue);
|
||||||
if (!ret || length > maxlength) {
|
if (!ret || length > maxlength) {
|
||||||
maxlength = length;
|
maxlength = length;
|
||||||
|
|
85
lib/token.h
85
lib/token.h
|
@ -30,6 +30,7 @@
|
||||||
#include "mathlib.h"
|
#include "mathlib.h"
|
||||||
|
|
||||||
class Scope;
|
class Scope;
|
||||||
|
class Type;
|
||||||
class Function;
|
class Function;
|
||||||
class Variable;
|
class Variable;
|
||||||
class Settings;
|
class Settings;
|
||||||
|
@ -222,59 +223,59 @@ public:
|
||||||
**/
|
**/
|
||||||
static std::string getCharAt(const Token *tok, std::size_t index);
|
static std::string getCharAt(const Token *tok, std::size_t index);
|
||||||
|
|
||||||
Type type() const {
|
Token::Type tokType() const {
|
||||||
return _type;
|
return _tokType;
|
||||||
}
|
}
|
||||||
void type(Type t) {
|
void tokType(Token::Type t) {
|
||||||
_type = t;
|
_tokType = t;
|
||||||
}
|
}
|
||||||
void isKeyword(bool kwd) {
|
void isKeyword(bool kwd) {
|
||||||
if (kwd)
|
if (kwd)
|
||||||
_type = eKeyword;
|
_tokType = eKeyword;
|
||||||
else if (_type == eKeyword)
|
else if (_tokType == eKeyword)
|
||||||
_type = eName;
|
_tokType = eName;
|
||||||
}
|
}
|
||||||
bool isKeyword() const {
|
bool isKeyword() const {
|
||||||
return _type == eKeyword;
|
return _tokType == eKeyword;
|
||||||
}
|
}
|
||||||
bool isName() const {
|
bool isName() const {
|
||||||
return _type == eName || _type == eType || _type == eVariable || _type == eFunction || _type == eKeyword ||
|
return _tokType == eName || _tokType == eType || _tokType == eVariable || _tokType == eFunction || _tokType == eKeyword ||
|
||||||
_type == eBoolean; // TODO: "true"/"false" aren't really a name...
|
_tokType == eBoolean; // TODO: "true"/"false" aren't really a name...
|
||||||
}
|
}
|
||||||
bool isUpperCaseName() const;
|
bool isUpperCaseName() const;
|
||||||
bool isLiteral() const {
|
bool isLiteral() const {
|
||||||
return _type == eNumber || _type == eString || _type == eChar ||
|
return _tokType == eNumber || _tokType == eString || _tokType == eChar ||
|
||||||
_type == eBoolean || _type == eLiteral;
|
_tokType == eBoolean || _tokType == eLiteral;
|
||||||
}
|
}
|
||||||
bool isNumber() const {
|
bool isNumber() const {
|
||||||
return _type == eNumber;
|
return _tokType == eNumber;
|
||||||
}
|
}
|
||||||
bool isOp() const {
|
bool isOp() const {
|
||||||
return (isConstOp() ||
|
return (isConstOp() ||
|
||||||
isAssignmentOp() ||
|
isAssignmentOp() ||
|
||||||
_type == eIncDecOp);
|
_tokType == eIncDecOp);
|
||||||
}
|
}
|
||||||
bool isConstOp() const {
|
bool isConstOp() const {
|
||||||
return (isArithmeticalOp() ||
|
return (isArithmeticalOp() ||
|
||||||
_type == eLogicalOp ||
|
_tokType == eLogicalOp ||
|
||||||
_type == eComparisonOp ||
|
_tokType == eComparisonOp ||
|
||||||
_type == eBitOp);
|
_tokType == eBitOp);
|
||||||
}
|
}
|
||||||
bool isExtendedOp() const {
|
bool isExtendedOp() const {
|
||||||
return isConstOp() ||
|
return isConstOp() ||
|
||||||
_type == eExtendedOp;
|
_tokType == eExtendedOp;
|
||||||
}
|
}
|
||||||
bool isArithmeticalOp() const {
|
bool isArithmeticalOp() const {
|
||||||
return _type == eArithmeticalOp;
|
return _tokType == eArithmeticalOp;
|
||||||
}
|
}
|
||||||
bool isComparisonOp() const {
|
bool isComparisonOp() const {
|
||||||
return _type == eComparisonOp;
|
return _tokType == eComparisonOp;
|
||||||
}
|
}
|
||||||
bool isAssignmentOp() const {
|
bool isAssignmentOp() const {
|
||||||
return _type == eAssignmentOp;
|
return _tokType == eAssignmentOp;
|
||||||
}
|
}
|
||||||
bool isBoolean() const {
|
bool isBoolean() const {
|
||||||
return _type == eBoolean;
|
return _tokType == eBoolean;
|
||||||
}
|
}
|
||||||
bool isUnaryPreOp() const;
|
bool isUnaryPreOp() const;
|
||||||
|
|
||||||
|
@ -464,7 +465,7 @@ public:
|
||||||
void varId(unsigned int id) {
|
void varId(unsigned int id) {
|
||||||
_varId = id;
|
_varId = id;
|
||||||
if (id != 0)
|
if (id != 0)
|
||||||
_type = eVariable;
|
_tokType = eVariable;
|
||||||
else
|
else
|
||||||
update_property_info();
|
update_property_info();
|
||||||
}
|
}
|
||||||
|
@ -576,16 +577,16 @@ public:
|
||||||
void function(const Function *f) {
|
void function(const Function *f) {
|
||||||
_function = f;
|
_function = f;
|
||||||
if (f)
|
if (f)
|
||||||
_type = eFunction;
|
_tokType = eFunction;
|
||||||
else if (_type == eFunction)
|
else if (_tokType == eFunction)
|
||||||
_type = eName;
|
_tokType = eName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return a pointer to the Function associated with this token.
|
* @return a pointer to the Function associated with this token.
|
||||||
*/
|
*/
|
||||||
const Function *function() const {
|
const Function *function() const {
|
||||||
return _type == eFunction ? _function : 0;
|
return _tokType == eFunction ? _function : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -595,16 +596,35 @@ public:
|
||||||
void variable(const Variable *v) {
|
void variable(const Variable *v) {
|
||||||
_variable = v;
|
_variable = v;
|
||||||
if (v || _varId)
|
if (v || _varId)
|
||||||
_type = eVariable;
|
_tokType = eVariable;
|
||||||
else if (_type == eVariable)
|
else if (_tokType == eVariable)
|
||||||
_type = eName;
|
_tokType = eName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return a pointer to the variable associated with this token.
|
* @return a pointer to the variable associated with this token.
|
||||||
*/
|
*/
|
||||||
const Variable *variable() const {
|
const Variable *variable() const {
|
||||||
return _type == eVariable ? _variable : 0;
|
return _tokType == eVariable ? _variable : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Associate this token with given type
|
||||||
|
* @param t Type to be associated
|
||||||
|
*/
|
||||||
|
void type(const ::Type *t) {
|
||||||
|
_type = t;
|
||||||
|
if (t)
|
||||||
|
_tokType = eType;
|
||||||
|
else if (_tokType == eType)
|
||||||
|
_tokType = eName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a pointer to the type associated with this token.
|
||||||
|
*/
|
||||||
|
const ::Type *type() const {
|
||||||
|
return _tokType == eType ? _type : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -751,6 +771,7 @@ private:
|
||||||
union {
|
union {
|
||||||
const Function *_function;
|
const Function *_function;
|
||||||
const Variable *_variable;
|
const Variable *_variable;
|
||||||
|
const ::Type* _type;
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned int _varId;
|
unsigned int _varId;
|
||||||
|
@ -763,7 +784,7 @@ private:
|
||||||
*/
|
*/
|
||||||
unsigned int _progressValue;
|
unsigned int _progressValue;
|
||||||
|
|
||||||
Type _type;
|
Token::Type _tokType;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
fIsUnsigned = (1 << 0),
|
fIsUnsigned = (1 << 0),
|
||||||
|
|
|
@ -134,7 +134,7 @@ unsigned int Tokenizer::sizeOfType(const Token *type) const
|
||||||
if (!type || type->str().empty())
|
if (!type || type->str().empty())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (type->type() == Token::eString)
|
if (type->tokType() == Token::eString)
|
||||||
return static_cast<unsigned int>(Token::getStrLength(type) + 1);
|
return static_cast<unsigned int>(Token::getStrLength(type) + 1);
|
||||||
|
|
||||||
std::map<std::string, unsigned int>::const_iterator it = _typeSize.find(type->str());
|
std::map<std::string, unsigned int>::const_iterator it = _typeSize.find(type->str());
|
||||||
|
@ -163,7 +163,7 @@ Token *Tokenizer::copyTokens(Token *dest, const Token *first, const Token *last,
|
||||||
tok2 = tok2->next();
|
tok2 = tok2->next();
|
||||||
tok2->fileIndex(commonFileIndex);
|
tok2->fileIndex(commonFileIndex);
|
||||||
tok2->linenr(linenrs);
|
tok2->linenr(linenrs);
|
||||||
tok2->type(tok->type());
|
tok2->tokType(tok->tokType());
|
||||||
tok2->flags(tok->flags());
|
tok2->flags(tok->flags());
|
||||||
tok2->varId(tok->varId());
|
tok2->varId(tok->varId());
|
||||||
|
|
||||||
|
@ -1935,7 +1935,7 @@ void Tokenizer::combineStrings()
|
||||||
for (Token *tok = list.front();
|
for (Token *tok = list.front();
|
||||||
tok;
|
tok;
|
||||||
tok = tok->next()) {
|
tok = tok->next()) {
|
||||||
while (tok->str() == "L" && tok->next() && tok->next()->type() == Token::eString) {
|
while (tok->str() == "L" && tok->next() && tok->next()->tokType() == Token::eString) {
|
||||||
// Combine 'L "string"'
|
// Combine 'L "string"'
|
||||||
tok->str(tok->next()->str());
|
tok->str(tok->next()->str());
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
|
@ -1951,7 +1951,7 @@ void Tokenizer::combineStrings()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
tok->str(simplifyString(tok->str()));
|
tok->str(simplifyString(tok->str()));
|
||||||
while (tok->next() && tok->next()->type() == Token::eString) {
|
while (tok->next() && tok->next()->tokType() == Token::eString) {
|
||||||
tok->next()->str(simplifyString(tok->next()->str()));
|
tok->next()->str(simplifyString(tok->next()->str()));
|
||||||
|
|
||||||
// Two strings after each other, combine them
|
// Two strings after each other, combine them
|
||||||
|
@ -2007,7 +2007,7 @@ void Tokenizer::simplifyNull()
|
||||||
void Tokenizer::concatenateNegativeNumberAndAnyPositive()
|
void Tokenizer::concatenateNegativeNumberAndAnyPositive()
|
||||||
{
|
{
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
if (!Token::Match(tok, "?|:|,|(|[|{|return|case|sizeof|%op% +|-") || tok->type() == Token::eIncDecOp)
|
if (!Token::Match(tok, "?|:|,|(|[|{|return|case|sizeof|%op% +|-") || tok->tokType() == Token::eIncDecOp)
|
||||||
continue;
|
continue;
|
||||||
if (tok->next()->str() == "+")
|
if (tok->next()->str() == "+")
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
|
@ -3893,9 +3893,9 @@ void Tokenizer::dump(std::ostream &out) const
|
||||||
out << " isInt=\"True\"";
|
out << " isInt=\"True\"";
|
||||||
if (MathLib::isFloat(tok->str()))
|
if (MathLib::isFloat(tok->str()))
|
||||||
out << " isFloat=\"True\"";
|
out << " isFloat=\"True\"";
|
||||||
} else if (tok->type() == Token::eString)
|
} else if (tok->tokType() == Token::eString)
|
||||||
out << " type=\"string\" strlen=\"" << Token::getStrLength(tok) << '\"';
|
out << " type=\"string\" strlen=\"" << Token::getStrLength(tok) << '\"';
|
||||||
else if (tok->type() == Token::eChar)
|
else if (tok->tokType() == Token::eChar)
|
||||||
out << " type=\"char\"";
|
out << " type=\"char\"";
|
||||||
else if (tok->isBoolean())
|
else if (tok->isBoolean())
|
||||||
out << " type=\"boolean\"";
|
out << " type=\"boolean\"";
|
||||||
|
@ -3907,7 +3907,7 @@ void Tokenizer::dump(std::ostream &out) const
|
||||||
out << " isAssignmentOp=\"True\"";
|
out << " isAssignmentOp=\"True\"";
|
||||||
else if (tok->isComparisonOp())
|
else if (tok->isComparisonOp())
|
||||||
out << " isComparisonOp=\"True\"";
|
out << " isComparisonOp=\"True\"";
|
||||||
else if (tok->type() == Token::eLogicalOp)
|
else if (tok->tokType() == Token::eLogicalOp)
|
||||||
out << " isLogicalOp=\"True\"";
|
out << " isLogicalOp=\"True\"";
|
||||||
}
|
}
|
||||||
if (tok->link())
|
if (tok->link())
|
||||||
|
@ -4499,8 +4499,8 @@ Token *Tokenizer::simplifyAddBracesPair(Token *tok, bool commandWithCondition)
|
||||||
tokAfterCondition=tokAfterCondition->next();
|
tokAfterCondition=tokAfterCondition->next();
|
||||||
}
|
}
|
||||||
if (!tokAfterCondition ||
|
if (!tokAfterCondition ||
|
||||||
((tokAfterCondition->type()==Token::eBracket ||
|
((tokAfterCondition->tokType()==Token::eBracket ||
|
||||||
tokAfterCondition->type()==Token::eExtendedOp)&&
|
tokAfterCondition->tokType()==Token::eExtendedOp)&&
|
||||||
Token::Match(tokAfterCondition,")|}|>|,"))) {
|
Token::Match(tokAfterCondition,")|}|>|,"))) {
|
||||||
// No tokens left where to add braces around
|
// No tokens left where to add braces around
|
||||||
return tok;
|
return tok;
|
||||||
|
@ -4532,11 +4532,11 @@ Token *Tokenizer::simplifyAddBracesPair(Token *tok, bool commandWithCondition)
|
||||||
// Look for ; to add own closing brace after it
|
// Look for ; to add own closing brace after it
|
||||||
while (tokEnd &&
|
while (tokEnd &&
|
||||||
tokEnd->str()!=";" &&
|
tokEnd->str()!=";" &&
|
||||||
!((tokEnd->type()==Token::eBracket ||
|
!((tokEnd->tokType()==Token::eBracket ||
|
||||||
tokEnd->type()==Token::eExtendedOp)&&
|
tokEnd->tokType()==Token::eExtendedOp)&&
|
||||||
Token::Match(tokEnd,")|}|>"))) {
|
Token::Match(tokEnd,")|}|>"))) {
|
||||||
if (tokEnd->type()==Token::eBracket ||
|
if (tokEnd->tokType()==Token::eBracket ||
|
||||||
(tokEnd->type()==Token::eExtendedOp && tokEnd->str()=="(")) {
|
(tokEnd->tokType()==Token::eExtendedOp && tokEnd->str()=="(")) {
|
||||||
Token *tokInnerCloseBraket=tokEnd->link();
|
Token *tokInnerCloseBraket=tokEnd->link();
|
||||||
if (!tokInnerCloseBraket) {
|
if (!tokInnerCloseBraket) {
|
||||||
// Inner bracket does not close
|
// Inner bracket does not close
|
||||||
|
@ -4649,7 +4649,7 @@ void Tokenizer::simplifyCompoundAssignment()
|
||||||
for (Token *tok2 = tok->previous(); tok2 && tok2 != tok1; tok2 = tok2->previous()) {
|
for (Token *tok2 = tok->previous(); tok2 && tok2 != tok1; tok2 = tok2->previous()) {
|
||||||
// Don't duplicate ++ and --. Put preincrement in lhs. Put
|
// Don't duplicate ++ and --. Put preincrement in lhs. Put
|
||||||
// postincrement in rhs.
|
// postincrement in rhs.
|
||||||
if (tok2->type() == Token::eIncDecOp) {
|
if (tok2->tokType() == Token::eIncDecOp) {
|
||||||
// pre increment/decrement => don't copy
|
// pre increment/decrement => don't copy
|
||||||
if (tok2->next()->isName()) {
|
if (tok2->next()->isName()) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -5693,7 +5693,7 @@ void Tokenizer::simplifyPlatformTypes()
|
||||||
_settings->platformType == Settings::Win32W ? "win32W" : "win64";
|
_settings->platformType == Settings::Win32W ? "win32W" : "win64";
|
||||||
|
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
if (tok->type() != Token::eType && tok->type() != Token::eName)
|
if (tok->tokType() != Token::eType && tok->tokType() != Token::eName)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const Library::PlatformType * const platformtype = _settings->library.platform_type(tok->str(), platform_type);
|
const Library::PlatformType * const platformtype = _settings->library.platform_type(tok->str(), platform_type);
|
||||||
|
@ -5703,7 +5703,7 @@ void Tokenizer::simplifyPlatformTypes()
|
||||||
if (tok->strAt(-1) == "::") {
|
if (tok->strAt(-1) == "::") {
|
||||||
const Token * tok1 = tok->tokAt(-2);
|
const Token * tok1 = tok->tokAt(-2);
|
||||||
// skip when non-global namespace defined
|
// skip when non-global namespace defined
|
||||||
if (tok1 && tok1->type() == Token::eName)
|
if (tok1 && tok1->tokType() == Token::eName)
|
||||||
continue;
|
continue;
|
||||||
tok = tok->tokAt(-1);
|
tok = tok->tokAt(-1);
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
|
|
|
@ -196,7 +196,7 @@ void TokenList::insertTokens(Token *dest, const Token *src, unsigned int n)
|
||||||
dest->fileIndex(src->fileIndex());
|
dest->fileIndex(src->fileIndex());
|
||||||
dest->linenr(src->linenr());
|
dest->linenr(src->linenr());
|
||||||
dest->varId(src->varId());
|
dest->varId(src->varId());
|
||||||
dest->type(src->type());
|
dest->tokType(src->tokType());
|
||||||
dest->flags(src->flags());
|
dest->flags(src->flags());
|
||||||
src = src->next();
|
src = src->next();
|
||||||
--n;
|
--n;
|
||||||
|
@ -400,7 +400,7 @@ unsigned long long TokenList::calculateChecksum() const
|
||||||
{
|
{
|
||||||
unsigned long long checksum = 0;
|
unsigned long long checksum = 0;
|
||||||
for (const Token* tok = front(); tok; tok = tok->next()) {
|
for (const Token* tok = front(); tok; tok = tok->next()) {
|
||||||
const unsigned int subchecksum1 = tok->flags() + tok->varId() + static_cast<unsigned int>(tok->type());
|
const unsigned int subchecksum1 = tok->flags() + tok->varId() + static_cast<unsigned int>(tok->tokType());
|
||||||
unsigned int subchecksum2 = 0;
|
unsigned int subchecksum2 = 0;
|
||||||
for (std::size_t i = 0; i < tok->str().size(); i++)
|
for (std::size_t i = 0; i < tok->str().size(); i++)
|
||||||
subchecksum2 += (unsigned int)tok->str()[i];
|
subchecksum2 += (unsigned int)tok->str()[i];
|
||||||
|
@ -582,7 +582,7 @@ static bool isPrefixUnary(const Token* tok, bool cpp)
|
||||||
{
|
{
|
||||||
if (!tok->previous()
|
if (!tok->previous()
|
||||||
|| ((Token::Match(tok->previous(), "(|[|{|%op%|;|}|?|:|,|.|return|::") || (cpp && tok->strAt(-1) == "throw"))
|
|| ((Token::Match(tok->previous(), "(|[|{|%op%|;|}|?|:|,|.|return|::") || (cpp && tok->strAt(-1) == "throw"))
|
||||||
&& (tok->previous()->type() != Token::eIncDecOp || tok->type() == Token::eIncDecOp)))
|
&& (tok->previous()->tokType() != Token::eIncDecOp || tok->tokType() == Token::eIncDecOp)))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return tok->strAt(-1) == ")" && iscast(tok->linkAt(-1));
|
return tok->strAt(-1) == ")" && iscast(tok->linkAt(-1));
|
||||||
|
@ -592,7 +592,7 @@ static void compilePrecedence2(Token *&tok, AST_state& state)
|
||||||
{
|
{
|
||||||
compileScope(tok, state);
|
compileScope(tok, state);
|
||||||
while (tok) {
|
while (tok) {
|
||||||
if (tok->type() == Token::eIncDecOp && !isPrefixUnary(tok, state.cpp)) {
|
if (tok->tokType() == Token::eIncDecOp && !isPrefixUnary(tok, state.cpp)) {
|
||||||
compileUnaryOp(tok, state, compileScope);
|
compileUnaryOp(tok, state, compileScope);
|
||||||
} else if (tok->str() == "." && tok->strAt(1) != "*") {
|
} else if (tok->str() == "." && tok->strAt(1) != "*") {
|
||||||
if (tok->strAt(1) == ".") {
|
if (tok->strAt(1) == ".") {
|
||||||
|
@ -651,7 +651,7 @@ static void compilePrecedence3(Token *&tok, AST_state& state)
|
||||||
{
|
{
|
||||||
compilePrecedence2(tok, state);
|
compilePrecedence2(tok, state);
|
||||||
while (tok) {
|
while (tok) {
|
||||||
if ((Token::Match(tok, "[+-!~*&]") || tok->type() == Token::eIncDecOp) &&
|
if ((Token::Match(tok, "[+-!~*&]") || tok->tokType() == Token::eIncDecOp) &&
|
||||||
isPrefixUnary(tok, state.cpp)) {
|
isPrefixUnary(tok, state.cpp)) {
|
||||||
if (Token::Match(tok, "* [*,)]")) {
|
if (Token::Match(tok, "* [*,)]")) {
|
||||||
Token* tok2 = tok;
|
Token* tok2 = tok;
|
||||||
|
|
|
@ -296,7 +296,7 @@ static bool isVariableChanged(const Token *start, const Token *end, const unsign
|
||||||
const Token *parent = tok->astParent();
|
const Token *parent = tok->astParent();
|
||||||
while (Token::Match(parent, ".|::"))
|
while (Token::Match(parent, ".|::"))
|
||||||
parent = parent->astParent();
|
parent = parent->astParent();
|
||||||
if (parent && parent->type() == Token::eIncDecOp)
|
if (parent && parent->tokType() == Token::eIncDecOp)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -401,10 +401,10 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value)
|
||||||
parent->astOperand2()->values.front().isKnown()));
|
parent->astOperand2()->values.front().isKnown()));
|
||||||
std::list<ValueFlow::Value>::const_iterator value1, value2;
|
std::list<ValueFlow::Value>::const_iterator value1, value2;
|
||||||
for (value1 = parent->astOperand1()->values.begin(); value1 != parent->astOperand1()->values.end(); ++value1) {
|
for (value1 = parent->astOperand1()->values.begin(); value1 != parent->astOperand1()->values.end(); ++value1) {
|
||||||
if (value1->tokvalue && (!parent->isComparisonOp() || value1->tokvalue->type() != Token::eString))
|
if (value1->tokvalue && (!parent->isComparisonOp() || value1->tokvalue->tokType() != Token::eString))
|
||||||
continue;
|
continue;
|
||||||
for (value2 = parent->astOperand2()->values.begin(); value2 != parent->astOperand2()->values.end(); ++value2) {
|
for (value2 = parent->astOperand2()->values.begin(); value2 != parent->astOperand2()->values.end(); ++value2) {
|
||||||
if (value2->tokvalue && (!parent->isComparisonOp() || value2->tokvalue->type() != Token::eString || value1->tokvalue))
|
if (value2->tokvalue && (!parent->isComparisonOp() || value2->tokvalue->tokType() != Token::eString || value1->tokvalue))
|
||||||
continue;
|
continue;
|
||||||
if (known || value1->varId == 0U || value2->varId == 0U ||
|
if (known || value1->varId == 0U || value2->varId == 0U ||
|
||||||
(value1->varId == value2->varId && value1->varvalue == value2->varvalue && !value1->tokvalue && !value2->tokvalue)) {
|
(value1->varId == value2->varId && value1->varvalue == value2->varvalue && !value1->tokvalue && !value2->tokvalue)) {
|
||||||
|
@ -517,7 +517,7 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value)
|
||||||
result.inconclusive = value1->inconclusive | value2->inconclusive;
|
result.inconclusive = value1->inconclusive | value2->inconclusive;
|
||||||
result.varId = (value1->varId != 0U) ? value1->varId : value2->varId;
|
result.varId = (value1->varId != 0U) ? value1->varId : value2->varId;
|
||||||
result.varvalue = (result.varId == value1->varId) ? value1->intvalue : value2->intvalue;
|
result.varvalue = (result.varId == value1->varId) ? value1->intvalue : value2->intvalue;
|
||||||
if (value1->tokvalue->type() == Token::eString) {
|
if (value1->tokvalue->tokType() == Token::eString) {
|
||||||
const std::string s = value1->tokvalue->strValue();
|
const std::string s = value1->tokvalue->strValue();
|
||||||
const MathLib::bigint index = value2->intvalue;
|
const MathLib::bigint index = value2->intvalue;
|
||||||
if (index >= 0 && index < s.size()) {
|
if (index >= 0 && index < s.size()) {
|
||||||
|
@ -569,7 +569,7 @@ static void valueFlowNumber(TokenList *tokenlist)
|
||||||
static void valueFlowString(TokenList *tokenlist)
|
static void valueFlowString(TokenList *tokenlist)
|
||||||
{
|
{
|
||||||
for (Token *tok = tokenlist->front(); tok; tok = tok->next()) {
|
for (Token *tok = tokenlist->front(); tok; tok = tok->next()) {
|
||||||
if (tok->type() == Token::eString) {
|
if (tok->tokType() == Token::eString) {
|
||||||
ValueFlow::Value strvalue;
|
ValueFlow::Value strvalue;
|
||||||
strvalue.tokvalue = tok;
|
strvalue.tokvalue = tok;
|
||||||
strvalue.setKnown();
|
strvalue.setKnown();
|
||||||
|
|
|
@ -1866,9 +1866,6 @@ private:
|
||||||
"class Bar;\n"
|
"class Bar;\n"
|
||||||
"class Sub;\n");
|
"class Sub;\n");
|
||||||
ASSERT(db && db->typeList.size() == 5);
|
ASSERT(db && db->typeList.size() == 5);
|
||||||
ASSERT(db && db->isClassOrStruct("Foo"));
|
|
||||||
ASSERT(db && db->isClassOrStruct("Bar"));
|
|
||||||
ASSERT(db && db->isClassOrStruct("Sub"));
|
|
||||||
if (!db || db->typeList.size() < 5)
|
if (!db || db->typeList.size() < 5)
|
||||||
return;
|
return;
|
||||||
std::list<Type>::const_iterator i = db->typeList.begin();
|
std::list<Type>::const_iterator i = db->typeList.begin();
|
||||||
|
@ -1938,9 +1935,6 @@ private:
|
||||||
" struct Barney barney;\n"
|
" struct Barney barney;\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT(db && db->typeList.size() == 3);
|
ASSERT(db && db->typeList.size() == 3);
|
||||||
ASSERT(db && db->isClassOrStruct("Fred"));
|
|
||||||
ASSERT(db && db->isClassOrStruct("Wilma"));
|
|
||||||
ASSERT(db && db->isClassOrStruct("Barney"));
|
|
||||||
if (!db || db->typeList.size() != 3)
|
if (!db || db->typeList.size() != 3)
|
||||||
return;
|
return;
|
||||||
std::list<Type>::const_iterator i = db->typeList.begin();
|
std::list<Type>::const_iterator i = db->typeList.begin();
|
||||||
|
|
|
@ -237,8 +237,8 @@ private:
|
||||||
void multiCompare4() const {
|
void multiCompare4() const {
|
||||||
givenACodeSampleToTokenize var("std :: queue < int > foo ;");
|
givenACodeSampleToTokenize var("std :: queue < int > foo ;");
|
||||||
|
|
||||||
ASSERT_EQUALS(Token::eBracket, var.tokens()->tokAt(3)->type());
|
ASSERT_EQUALS(Token::eBracket, var.tokens()->tokAt(3)->tokType());
|
||||||
ASSERT_EQUALS(Token::eBracket, var.tokens()->tokAt(5)->type());
|
ASSERT_EQUALS(Token::eBracket, var.tokens()->tokAt(5)->tokType());
|
||||||
|
|
||||||
ASSERT_EQUALS(false, Token::Match(var.tokens(), "std :: queue %op%"));
|
ASSERT_EQUALS(false, Token::Match(var.tokens(), "std :: queue %op%"));
|
||||||
ASSERT_EQUALS(false, Token::Match(var.tokens(), "std :: queue x|%op%"));
|
ASSERT_EQUALS(false, Token::Match(var.tokens(), "std :: queue x|%op%"));
|
||||||
|
@ -762,47 +762,47 @@ private:
|
||||||
for (test_op = extendedOps.begin(); test_op != extendedOps.end(); ++test_op) {
|
for (test_op = extendedOps.begin(); test_op != extendedOps.end(); ++test_op) {
|
||||||
Token tok(nullptr);
|
Token tok(nullptr);
|
||||||
tok.str(*test_op);
|
tok.str(*test_op);
|
||||||
ASSERT_EQUALS(Token::eExtendedOp, tok.type());
|
ASSERT_EQUALS(Token::eExtendedOp, tok.tokType());
|
||||||
}
|
}
|
||||||
for (test_op = logicalOps.begin(); test_op != logicalOps.end(); ++test_op) {
|
for (test_op = logicalOps.begin(); test_op != logicalOps.end(); ++test_op) {
|
||||||
Token tok(nullptr);
|
Token tok(nullptr);
|
||||||
tok.str(*test_op);
|
tok.str(*test_op);
|
||||||
ASSERT_EQUALS(Token::eLogicalOp, tok.type());
|
ASSERT_EQUALS(Token::eLogicalOp, tok.tokType());
|
||||||
}
|
}
|
||||||
for (test_op = bitOps.begin(); test_op != bitOps.end(); ++test_op) {
|
for (test_op = bitOps.begin(); test_op != bitOps.end(); ++test_op) {
|
||||||
Token tok(nullptr);
|
Token tok(nullptr);
|
||||||
tok.str(*test_op);
|
tok.str(*test_op);
|
||||||
ASSERT_EQUALS(Token::eBitOp, tok.type());
|
ASSERT_EQUALS(Token::eBitOp, tok.tokType());
|
||||||
}
|
}
|
||||||
for (test_op = comparisonOps.begin(); test_op != comparisonOps.end(); ++test_op) {
|
for (test_op = comparisonOps.begin(); test_op != comparisonOps.end(); ++test_op) {
|
||||||
Token tok(nullptr);
|
Token tok(nullptr);
|
||||||
tok.str(*test_op);
|
tok.str(*test_op);
|
||||||
ASSERT_EQUALS(Token::eComparisonOp, tok.type());
|
ASSERT_EQUALS(Token::eComparisonOp, tok.tokType());
|
||||||
}
|
}
|
||||||
Token tok(nullptr);
|
Token tok(nullptr);
|
||||||
tok.str("++");
|
tok.str("++");
|
||||||
ASSERT_EQUALS(Token::eIncDecOp, tok.type());
|
ASSERT_EQUALS(Token::eIncDecOp, tok.tokType());
|
||||||
tok.str("--");
|
tok.str("--");
|
||||||
ASSERT_EQUALS(Token::eIncDecOp, tok.type());
|
ASSERT_EQUALS(Token::eIncDecOp, tok.tokType());
|
||||||
}
|
}
|
||||||
|
|
||||||
void literals() const {
|
void literals() const {
|
||||||
Token tok(nullptr);
|
Token tok(nullptr);
|
||||||
|
|
||||||
tok.str("\"foo\"");
|
tok.str("\"foo\"");
|
||||||
ASSERT(tok.type() == Token::eString);
|
ASSERT(tok.tokType() == Token::eString);
|
||||||
tok.str("\"\"");
|
tok.str("\"\"");
|
||||||
ASSERT(tok.type() == Token::eString);
|
ASSERT(tok.tokType() == Token::eString);
|
||||||
tok.str("'f'");
|
tok.str("'f'");
|
||||||
ASSERT(tok.type() == Token::eChar);
|
ASSERT(tok.tokType() == Token::eChar);
|
||||||
tok.str("12345");
|
tok.str("12345");
|
||||||
ASSERT(tok.type() == Token::eNumber);
|
ASSERT(tok.tokType() == Token::eNumber);
|
||||||
tok.str("-55");
|
tok.str("-55");
|
||||||
ASSERT(tok.type() == Token::eNumber);
|
ASSERT(tok.tokType() == Token::eNumber);
|
||||||
tok.str("true");
|
tok.str("true");
|
||||||
ASSERT(tok.type() == Token::eBoolean);
|
ASSERT(tok.tokType() == Token::eBoolean);
|
||||||
tok.str("false");
|
tok.str("false");
|
||||||
ASSERT(tok.type() == Token::eBoolean);
|
ASSERT(tok.tokType() == Token::eBoolean);
|
||||||
}
|
}
|
||||||
|
|
||||||
void isStandardType() const {
|
void isStandardType() const {
|
||||||
|
|
|
@ -86,7 +86,7 @@ class MatchCompiler:
|
||||||
elif tok == '%bool%':
|
elif tok == '%bool%':
|
||||||
return 'tok->isBoolean()'
|
return 'tok->isBoolean()'
|
||||||
elif tok == '%char%':
|
elif tok == '%char%':
|
||||||
return '(tok->type()==Token::eChar)'
|
return '(tok->tokType()==Token::eChar)'
|
||||||
elif tok == '%comp%':
|
elif tok == '%comp%':
|
||||||
return 'tok->isComparisonOp()'
|
return 'tok->isComparisonOp()'
|
||||||
elif tok == '%num%':
|
elif tok == '%num%':
|
||||||
|
@ -96,11 +96,11 @@ class MatchCompiler:
|
||||||
elif tok == '%op%':
|
elif tok == '%op%':
|
||||||
return 'tok->isOp()'
|
return 'tok->isOp()'
|
||||||
elif tok == '%or%':
|
elif tok == '%or%':
|
||||||
return '(tok->type() == Token::eBitOp && tok->str()==MatchCompiler::makeConstString("|") )'
|
return '(tok->tokType() == Token::eBitOp && tok->str()==MatchCompiler::makeConstString("|") )'
|
||||||
elif tok == '%oror%':
|
elif tok == '%oror%':
|
||||||
return '(tok->type() == Token::eLogicalOp && tok->str()==MatchCompiler::makeConstString("||"))'
|
return '(tok->tokType() == Token::eLogicalOp && tok->str()==MatchCompiler::makeConstString("||"))'
|
||||||
elif tok == '%str%':
|
elif tok == '%str%':
|
||||||
return '(tok->type()==Token::eString)'
|
return '(tok->tokType()==Token::eString)'
|
||||||
elif tok == '%type%':
|
elif tok == '%type%':
|
||||||
return (
|
return (
|
||||||
'(tok->isName() && tok->varId()==0U && !tok->isKeyword())'
|
'(tok->isName() && tok->varId()==0U && !tok->isKeyword())'
|
||||||
|
|
Loading…
Reference in New Issue