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:
PKEuS 2015-08-14 20:46:13 +02:00
parent aaefdd2f92
commit 4d80df2f4a
25 changed files with 218 additions and 204 deletions

View File

@ -238,7 +238,7 @@ bool isSameExpression(bool cpp, const Token *tok1, const Token *tok2, const std:
if (t1 != end1 || t2 != end2)
return false;
}
if (tok1->type() == Token::eIncDecOp || tok1->isAssignmentOp())
if (tok1->tokType() == Token::eIncDecOp || tok1->isAssignmentOp())
return false;
// bailout when we see ({..})
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())
return false;
}
if (tok->type() == Token::eIncDecOp)
if (tok->tokType() == Token::eIncDecOp)
return false;
// bailout when we see ({..})
if (tok->str() == "{")

View File

@ -44,7 +44,7 @@ void CheckAssert::assertWithSideEffects()
for (const Token* tmp = tok->next(); tmp != endTok; tmp = tmp->next()) {
checkVariableAssignment(tmp);
if (tmp->type() == Token::eFunction) {
if (tmp->tokType() == Token::eFunction) {
const Function* f = tmp->function();
if (f->nestedIn->isClassOrStruct() && !f->isStatic() && !f->isConst())
@ -54,7 +54,7 @@ void CheckAssert::assertWithSideEffects()
if (!scope) continue;
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;
const Variable* var = tok2->previous()->variable();
@ -113,7 +113,7 @@ void CheckAssert::checkVariableAssignment(const Token* assignTok)
return;
// assignment
if (assignTok->isAssignmentOp() || assignTok->type() == Token::eIncDecOp) {
if (assignTok->isAssignmentOp() || assignTok->tokType() == Token::eIncDecOp) {
if (prevVar->isConst())
return;

View File

@ -305,8 +305,6 @@ void CheckAutoVariables::errorUselessAssignmentPtrArg(const Token *tok)
// return temporary?
bool CheckAutoVariables::returnTemporary(const Token *tok) const
{
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
bool func = false; // Might it be a function call?
bool retref = false; // is there such a function that returns a reference?
bool retvalue = false; // is there such a function that returns a value?
@ -330,7 +328,7 @@ bool CheckAutoVariables::returnTemporary(const Token *tok) const
else
retref = true; // Assume that a reference is returned
} else {
if (symbolDatabase->isClassOrStruct(start->str()))
if (start->type())
retvalue = true;
else
retref = true;
@ -338,7 +336,7 @@ bool CheckAutoVariables::returnTemporary(const Token *tok) const
}
func = true;
}
if (!func && symbolDatabase->isClassOrStruct(tok->str()))
if (!func && tok->type())
return true;
return bool(!retref && retvalue);

View File

@ -227,7 +227,7 @@ void CheckBool::checkComparisonOfFuncReturningBool()
for (std::size_t i = 0; i < functionsCount; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
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;
const Token *firstToken = tok->previous();
if (tok->strAt(-1) == ")") {
@ -291,7 +291,7 @@ void CheckBool::checkComparisonOfBoolWithBool()
for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
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;
bool firstTokenBool = false;

View File

@ -319,7 +319,7 @@ static bool checkMinSizes(const std::list<Library::ArgumentChecks::MinSize> &min
const MathLib::bigint sz = MathLib::toLongNumber(argtok->str());
if ((std::size_t)sz > arraySize)
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);
break;
case Library::ArgumentChecks::MinSize::MUL:
@ -352,7 +352,7 @@ static bool checkMinSizes(const std::list<Library::ArgumentChecks::MinSize> &min
}
break;
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;
break;
case Library::ArgumentChecks::MinSize::NONE:
@ -1470,13 +1470,13 @@ MathLib::biguint CheckBufferOverrun::countSprintfLength(const std::string &input
break;
case 'd':
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();
handleNextParameter = true;
break;
case 's':
if (paramIter != parameters.end() && *paramIter && (*paramIter)->type() == Token::eString)
if (paramIter != parameters.end() && *paramIter && (*paramIter)->tokType() == Token::eString)
parameterLength = Token::getStrLength(*paramIter);
handleNextParameter = true;
@ -1765,7 +1765,7 @@ void CheckBufferOverrun::arrayIndexThenCheck()
return;
// skip comparison
if (tok->type() == Token::eComparisonOp)
if (tok->tokType() == Token::eComparisonOp)
tok = tok->tokAt(2);
if (!tok)

View File

@ -1043,11 +1043,8 @@ void CheckClass::checkMemset()
if (typeTok && typeTok->str() == "(")
typeTok = typeTok->next();
if (!type) {
const Type* t = symbolDatabase->findVariableType(scope, typeTok);
if (t)
type = t->classScope;
}
if (!type && typeTok->type())
type = typeTok->type()->classScope;
if (type) {
std::list<const Scope *> parsedTypes;
@ -1693,7 +1690,7 @@ void CheckClass::checkConst()
} else {
// don't warn for unknown types..
// LPVOID, HDC, etc
if (previous->isUpperCaseName() && previous->str().size() > 2 && !symbolDatabase->isClassOrStruct(previous->str()))
if (previous->str().size() > 2 && !previous->type() && previous->isUpperCaseName())
continue;
}
@ -1854,13 +1851,13 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool&
const Token* lhs = tok1->tokAt(-1);
if (lhs->str() == "&") {
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())
return false;
}
} else {
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())
return false;
}
@ -1900,7 +1897,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool&
}
// Assignment
else if (end->next()->type() == Token::eAssignmentOp)
else if (end->next()->tokType() == Token::eAssignmentOp)
return (false);
// Streaming
@ -1910,7 +1907,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool&
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);

View File

@ -852,7 +852,7 @@ void CheckCondition::clarifyCondition()
for (const Token *tok2 = tok->tokAt(3); tok2; tok2 = tok2->next()) {
if (tok2->str() == "(" || tok2->str() == "[")
tok2 = tok2->link();
else if (tok2->type() == Token::eComparisonOp) {
else if (tok2->tokType() == Token::eComparisonOp) {
// This might be a template
if (!isC && tok2->link())
break;

View File

@ -41,7 +41,7 @@ void CheckInternal::checkTokenMatchPatterns()
// Get pattern string
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;
const std::string pattern = pattern_tok->strValue();
@ -89,7 +89,7 @@ void CheckInternal::checkTokenSimpleMatchPatterns()
// Get pattern string
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;
const std::string pattern = pattern_tok->strValue();
@ -171,7 +171,7 @@ void CheckInternal::checkMissingPercentCharacter()
// Get pattern string
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;
const std::string pattern = pattern_tok->strValue();
@ -226,7 +226,7 @@ void CheckInternal::checkUnknownPattern()
// Get pattern string
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;
const std::string pattern = pattern_tok->strValue();
@ -286,7 +286,7 @@ void CheckInternal::checkExtraWhitespace()
// Get pattern string
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;
const std::string pattern = pattern_tok->strValue();

View File

@ -168,7 +168,7 @@ void CheckIO::checkFileUsage()
tok->strAt(-1) == "=") {
if (tok->str() != "tmpfile") {
const Token* modeTok = tok->tokAt(2)->nextArgument();
if (modeTok && modeTok->type() == Token::eString)
if (modeTok && modeTok->tokType() == Token::eString)
mode = modeTok->strValue();
} else
mode = "wb+";
@ -176,7 +176,7 @@ void CheckIO::checkFileUsage()
operation = Filepointer::OPEN;
} else if (windows && Token::Match(tok, "fopen_s|freopen_s|_wfopen_s|_wfreopen_s ( & %name%")) {
const Token* modeTok = tok->tokAt(2)->nextArgument()->nextArgument();
if (modeTok && modeTok->type() == Token::eString)
if (modeTok && modeTok->tokType() == Token::eString)
mode = modeTok->strValue();
fileTok = tok->tokAt(3);
operation = Filepointer::OPEN;
@ -380,7 +380,7 @@ void CheckIO::invalidScanf()
formatToken = tok->tokAt(2);
else if (Token::Match(tok, "sscanf|vsscanf|fscanf|vfscanf (")) {
const Token* nextArg = tok->tokAt(2)->nextArgument();
if (nextArg && nextArg->type() == Token::eString)
if (nextArg && nextArg->tokType() == Token::eString)
formatToken = nextArg;
else
continue;
@ -678,7 +678,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
invalidScanfFormatWidthError(tok, numFormat, numWidth, argInfo.variableInfo);
}
}
if (argListTok && argListTok->type() != Token::eString &&
if (argListTok && argListTok->tokType() != Token::eString &&
argInfo.isKnownType() && argInfo.isArrayOrPointer() &&
(!Token::Match(argInfo.typeToken, "char|wchar_t") ||
argInfo.typeToken->strAt(-1) == "const")) {
@ -706,7 +706,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
case 'X':
case 'o':
specifier += *i;
if (argInfo.typeToken->type() == Token::eString)
if (argInfo.typeToken->tokType() == Token::eString)
invalidScanfArgTypeError_int(tok, numFormat, specifier, &argInfo, true);
else if (argInfo.isKnownType()) {
if (!Token::Match(argInfo.typeToken, "char|short|int|long")) {
@ -783,7 +783,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
case 'd':
case 'i':
specifier += *i;
if (argInfo.typeToken->type() == Token::eString)
if (argInfo.typeToken->tokType() == Token::eString)
invalidScanfArgTypeError_int(tok, numFormat, specifier, &argInfo, false);
else if (argInfo.isKnownType()) {
if (!Token::Match(argInfo.typeToken, "char|short|int|long")) {
@ -856,7 +856,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
break;
case 'u':
specifier += *i;
if (argInfo.typeToken->type() == Token::eString)
if (argInfo.typeToken->tokType() == Token::eString)
invalidScanfArgTypeError_int(tok, numFormat, specifier, &argInfo, true);
else if (argInfo.isKnownType()) {
if (!Token::Match(argInfo.typeToken, "char|short|int|long")) {
@ -937,7 +937,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
case 'G':
case 'a':
specifier += *i;
if (argInfo.typeToken->type() == Token::eString)
if (argInfo.typeToken->tokType() == Token::eString)
invalidScanfArgTypeError_float(tok, numFormat, specifier, &argInfo);
else if (argInfo.isKnownType()) {
if (!Token::Match(argInfo.typeToken, "float|double")) {
@ -1022,7 +1022,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
while (!done) {
switch (*i) {
case 's':
if (argListTok->type() != Token::eString &&
if (argListTok->tokType() != Token::eString &&
argInfo.isKnownType() && !argInfo.isArrayOrPointer()) {
if (!Token::Match(argInfo.typeToken, "char|wchar_t")) {
if (!(!argInfo.isArrayOrPointer() && argInfo.element))
@ -1032,7 +1032,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
done = true;
break;
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);
done = true;
break;
@ -1041,7 +1041,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
case 'X':
case 'o':
specifier += *i;
if (argInfo.typeToken->type() == Token::eString)
if (argInfo.typeToken->tokType() == Token::eString)
invalidPrintfArgTypeError_int(tok, numFormat, specifier, &argInfo);
else if (argInfo.isKnownType()) {
if (argInfo.isArrayOrPointer() && !argInfo.element) {
@ -1103,7 +1103,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
case 'd':
case 'i':
specifier += *i;
if (argInfo.typeToken->type() == Token::eString) {
if (argInfo.typeToken->tokType() == Token::eString) {
invalidPrintfArgTypeError_sint(tok, numFormat, specifier, &argInfo);
} else if (argInfo.isKnownType()) {
if (argInfo.isArrayOrPointer() && !argInfo.element) {
@ -1169,7 +1169,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
break;
case 'u':
specifier += *i;
if (argInfo.typeToken->type() == Token::eString) {
if (argInfo.typeToken->tokType() == Token::eString) {
invalidPrintfArgTypeError_uint(tok, numFormat, specifier, &argInfo);
} else if (argInfo.isKnownType()) {
if (argInfo.isArrayOrPointer() && !argInfo.element) {
@ -1229,7 +1229,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
done = true;
break;
case 'p':
if (argInfo.typeToken->type() == Token::eString)
if (argInfo.typeToken->tokType() == Token::eString)
invalidPrintfArgTypeError_p(tok, numFormat, &argInfo);
else if (argInfo.isKnownType() && !argInfo.isArrayOrPointer())
invalidPrintfArgTypeError_p(tok, numFormat, &argInfo);
@ -1241,7 +1241,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
case 'g':
case 'G':
specifier += *i;
if (argInfo.typeToken->type() == Token::eString)
if (argInfo.typeToken->tokType() == Token::eString)
invalidPrintfArgTypeError_float(tok, numFormat, specifier, &argInfo);
else if (argInfo.isKnownType()) {
if (argInfo.isArrayOrPointer() && !argInfo.element) {
@ -1362,11 +1362,11 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings,
, tempToken(nullptr)
{
if (tok) {
if (tok->type() == Token::eString) {
if (tok->tokType() == Token::eString) {
typeToken = tok;
return;
} else if (tok->str() == "&" || tok->type() == Token::eVariable ||
tok->type() == Token::eFunction || Token::Match(tok, "%type% ::") ||
} else if (tok->str() == "&" || tok->tokType() == Token::eVariable ||
tok->tokType() == Token::eFunction || Token::Match(tok, "%type% ::") ||
(Token::Match(tok, "static_cast|reinterpret_cast|const_cast <") &&
Token::simpleMatch(tok->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% ::"))
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;
const Token *varTok = nullptr;
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->previous()->str() == "]") {
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();
if (function && function->retDef) {
typeToken = function->retDef;
@ -1401,7 +1401,7 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings,
}
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();
if (function && function->retDef) {
typeToken = function->retDef;
@ -1467,7 +1467,7 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings,
}
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;
}
@ -1875,7 +1875,7 @@ void CheckIO::argumentType(std::ostream& os, const ArgumentInfo * argInfo)
if (argInfo) {
os << "\'";
const Token *type = argInfo->typeToken;
if (type->type() == Token::eString) {
if (type->tokType() == Token::eString) {
if (type->isLong())
os << "const wchar_t *";
else

View File

@ -85,13 +85,13 @@ void CheckNullPointer::parseFunctionCall(const Token &tok, std::list<const Token
argListTok = secondParam;
} else if (Token::Match(&tok, "sprintf|fprintf|sscanf|fscanf|fwprintf|fwscanf|swscanf")) {
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)
formatString = formatStringTok->strValue();
}
} else if (Token::Match(&tok, "snprintf|fnprintf|swprintf") && secondParam) {
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)
formatString = formatStringTok->strValue();
}

View File

@ -127,7 +127,7 @@ void CheckOther::clarifyCalculation()
// ? operator where lhs is arithmetical expression
if (tok->str() != "?" || !tok->astOperand1() || !tok->astOperand1()->isCalculation())
continue;
if (!tok->astOperand1()->isArithmeticalOp() && tok->astOperand1()->type() != Token::eBitOp)
if (!tok->astOperand1()->isArithmeticalOp() && tok->astOperand1()->tokType() != Token::eBitOp)
continue;
// Is code clarified by parentheses already?
@ -267,7 +267,7 @@ void CheckOther::warningOldStylePointerCast()
continue;
// Is "type" a class?
if (_tokenizer->getSymbolDatabase()->isClassOrStruct(typeTok->str()))
if (typeTok->type())
cstyleCastError(tok);
}
}
@ -497,7 +497,7 @@ void CheckOther::checkRedundantAssignment()
} else if (Token::Match(tok, "break|return|continue|throw|goto|asm")) {
varAssignments.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
if (!Token::Match(tok, "%var% ["))
initialized.insert(tok->varId());
@ -550,7 +550,7 @@ void CheckOther::checkRedundantAssignment()
varAssignments[tok->varId()] = tok;
memAssignments.erase(tok->varId());
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;
memAssignments.erase(tok->varId());
eraseMemberAssignments(tok->varId(), membervars, varAssignments);
@ -1220,7 +1220,7 @@ void CheckOther::checkVariableScope()
const Token* tok = var->nameToken()->next();
if (Token::Match(tok, "; %varid% = %any% ;", var->declarationId())) {
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;
}
bool reduce = true;
@ -1797,9 +1797,9 @@ void CheckOther::checkMisusedScopedObject()
for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
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), ") ; !!}")
&& symbolDatabase->isClassOrStruct(tok->next()->str())
&& (!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 = tok->next();

View File

@ -768,7 +768,7 @@ void CheckStl::size()
// check for using as boolean expression
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))
sizeError(tok1);
}

View File

@ -151,16 +151,16 @@ void CheckString::checkSuspiciousStringCompare()
for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
if (tok->type() != Token::eComparisonOp)
if (tok->tokType() != Token::eComparisonOp)
continue;
const Token* varTok = tok->astOperand1();
const Token* litTok = tok->astOperand2();
if (!varTok || !litTok) // <- failed to create AST for comparison
continue;
if (varTok->type() == Token::eString || varTok->type() == Token::eNumber)
if (varTok->tokType() == Token::eString || varTok->tokType() == Token::eNumber)
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;
// Pointer addition?
@ -176,7 +176,7 @@ void CheckString::checkSuspiciousStringCompare()
}
if (varTok->str() == "*") {
if (!_tokenizer->isC() || varTok->astOperand2() != nullptr || litTok->type() != Token::eString)
if (!_tokenizer->isC() || varTok->astOperand2() != nullptr || litTok->tokType() != Token::eString)
continue;
varTok = varTok->astOperand1();
}
@ -192,7 +192,7 @@ void CheckString::checkSuspiciousStringCompare()
varTok = varTok->astParent();
const std::string varname = varTok->expressionString();
if (litTok->type() == Token::eString) {
if (litTok->tokType() == Token::eString) {
if (_tokenizer->isC() || (var && var->isArrayOrPointer()))
suspiciousStringCompareError(tok, varname);
} else if (litTok->originalName() == "'\\0'" && var && var->isPointer()) {
@ -232,8 +232,8 @@ void CheckString::strPlusChar()
const Scope * scope = symbolDatabase->functionScopes[i];
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
if (tok->str() == "+") {
if (tok->astOperand1() && (tok->astOperand1()->type() == 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->astOperand1() && (tok->astOperand1()->tokType() == Token::eString)) { // string literal...
if (tok->astOperand2() && (tok->astOperand2()->tokType() == Token::eChar || isChar(tok->astOperand2()->variable()))) // added to char variable or char constant
strPlusCharError(tok);
}
}

View File

@ -878,12 +878,12 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
else if (tok->str() == "(")
tok = tok->next();
if (tok->type() == Token::eIncDecOp) {
if (tok->tokType() == Token::eIncDecOp) {
pre = true;
tok = tok->next();
}
if (tok->next()->type() == Token::eIncDecOp)
if (tok->next()->tokType() == Token::eIncDecOp)
post = true;
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())
variables.use(tok->next()->astOperand1()->varId(), tok);
else

View File

@ -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
for (const Token* tok = _tokenizer->list.front(); tok != _tokenizer->list.back(); tok = tok->next()) {
if (tok->varId())
@ -1287,9 +1295,10 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
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()) {
const_cast<Token *>(tok)->scope(0);
const_cast<Token *>(tok)->type(0);
const_cast<Token *>(tok)->function(0);
const_cast<Token *>(tok)->variable(0);
}

View File

@ -975,13 +975,6 @@ public:
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 {
return _variableList.at(varId);
}

View File

@ -277,7 +277,7 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok)
return 0;
// num/type ..
if (!tok->isNumber() && tok->type() != Token::eChar && !tok->isName())
if (!tok->isNumber() && tok->tokType() != Token::eChar && !tok->isName())
return 0;
tok = tok->next();
if (!tok)

View File

@ -44,7 +44,7 @@ Token::Token(Token **t) :
_fileIndex(0),
_linenr(0),
_progressValue(0),
_type(eNone),
_tokType(eNone),
_flags(0),
_astOperand1(nullptr),
_astOperand2(nullptr),
@ -62,32 +62,32 @@ void Token::update_property_info()
{
if (!_str.empty()) {
if (_str == "true" || _str == "false")
_type = eBoolean;
_tokType = eBoolean;
else if (_str[0] == '_' || std::isalpha((unsigned char)_str[0])) { // Name
if (_varId)
_type = eVariable;
else if (_type != eVariable && _type != eFunction && _type != eType && _type != eKeyword)
_type = eName;
_tokType = eVariable;
else if (_tokType != eVariable && _tokType != eFunction && _tokType != eType && _tokType != eKeyword)
_tokType = eName;
} 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() == '"')
_type = eString;
_tokType = eString;
else if (_str.length() > 1 && _str[0] == '\'' && _str.back() == '\'')
_type = eChar;
_tokType = eChar;
else if (_str == "=" || _str == "<<=" || _str == ">>=" ||
(_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)
_type = eExtendedOp;
_tokType = eExtendedOp;
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)
_type = eBitOp;
_tokType = eBitOp;
else if (_str.size() <= 2 &&
(_str == "&&" ||
_str == "||" ||
_str == "!"))
_type = eLogicalOp;
_tokType = eLogicalOp;
else if (_str.size() <= 2 && !_link &&
(_str == "==" ||
_str == "!=" ||
@ -95,17 +95,17 @@ void Token::update_property_info()
_str == "<=" ||
_str == ">" ||
_str == ">="))
_type = eComparisonOp;
_tokType = eComparisonOp;
else if (_str.size() == 2 &&
(_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)))
_type = eBracket;
_tokType = eBracket;
else
_type = eOther;
_tokType = eOther;
} else {
_type = eNone;
_tokType = eNone;
}
update_property_isStandardType();
@ -125,7 +125,7 @@ void Token::update_property_isStandardType()
if (stdTypes.find(_str)!=stdTypes.end()) {
isStandardType(true);
_type = eType;
_tokType = eType;
}
}
@ -151,10 +151,10 @@ void Token::concatStr(std::string const& b)
std::string Token::strValue() const
{
assert(_type == eString);
assert(_tokType == eString);
std::string ret(_str.substr(1, _str.length() - 2));
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);
if (ret[pos] >= 'a') {
if (ret[pos] == 'n')
@ -192,7 +192,7 @@ void Token::swapWithNext()
Token temp(0);
temp._str = _next->_str;
temp._type = _next->_type;
temp._tokType = _next->_tokType;
temp._flags = _next->_flags;
temp._varId = _next->_varId;
temp._fileIndex = _next->_fileIndex;
@ -204,7 +204,7 @@ void Token::swapWithNext()
temp._progressValue = _next->_progressValue;
_next->_str = _str;
_next->_type = _type;
_next->_tokType = _tokType;
_next->_flags = _flags;
_next->_varId = _varId;
_next->_fileIndex = _fileIndex;
@ -216,7 +216,7 @@ void Token::swapWithNext()
_next->_progressValue = _progressValue;
_str = temp._str;
_type = temp._type;
_tokType = temp._tokType;
_flags = temp._flags;
_varId = temp._varId;
_fileIndex = temp._fileIndex;
@ -233,7 +233,7 @@ void Token::deleteThis()
{
if (_next) { // Copy next to this and delete next
_str = _next->_str;
_type = _next->_type;
_tokType = _next->_tokType;
_flags = _next->_flags;
_varId = _next->_varId;
_fileIndex = _next->_fileIndex;
@ -242,6 +242,7 @@ void Token::deleteThis()
_scope = _next->_scope;
_function = _next->_function;
_variable = _next->_variable;
_type = _next->_type;
if (_next->_originalName) {
_originalName = _next->_originalName;
_next->_originalName = nullptr;
@ -253,7 +254,7 @@ void Token::deleteThis()
deleteNext();
} else if (_previous && _previous->_previous) { // Copy previous to this and delete previous
_str = _previous->_str;
_type = _previous->_type;
_tokType = _previous->_tokType;
_flags = _previous->_flags;
_varId = _previous->_varId;
_fileIndex = _previous->_fileIndex;
@ -262,6 +263,7 @@ void Token::deleteThis()
_scope = _previous->_scope;
_function = _previous->_function;
_variable = _previous->_variable;
_type = _previous->_type;
if (_previous->_originalName) {
_originalName = _previous->_originalName;
_previous->_originalName = nullptr;
@ -406,7 +408,7 @@ static int multiComparePercent(const Token *tok, const char*& haystack, bool emp
// Character (%char%)
if (haystack[0] == 'h') {
haystack += 4;
if (tok->type() == Token::eChar)
if (tok->tokType() == Token::eChar)
return 1;
}
// Const operator (%cop%)
@ -427,7 +429,7 @@ static int multiComparePercent(const Token *tok, const char*& haystack, bool emp
// String (%str%)
{
haystack += 4;
if (tok->type() == Token::eString)
if (tok->tokType() == Token::eString)
return 1;
}
break;
@ -451,7 +453,7 @@ static int multiComparePercent(const Token *tok, const char*& haystack, bool emp
// Or (%or%)
else {
haystack += 2;
if (tok->type() == Token::eBitOp && tok->str() == "|")
if (tok->tokType() == Token::eBitOp && tok->str() == "|")
return 1;
}
}
@ -459,7 +461,7 @@ static int multiComparePercent(const Token *tok, const char*& haystack, bool emp
// Oror (%oror%)
else {
haystack += 4;
if (tok->type() == Token::eLogicalOp && tok->str() == "||")
if (tok->tokType() == Token::eLogicalOp && tok->str() == "||")
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)
{
assert(tok != nullptr);
assert(tok->_type == eString);
assert(tok->_tokType == eString);
std::size_t len = 0;
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)
{
assert(tok != nullptr && tok->type() == eString);
assert(tok != nullptr && tok->tokType() == eString);
const std::string &str = tok->str();
unsigned int sizeofstring = 1U;
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())
os << "signed ";
if (isLong()) {
if (_type == eString || _type == eChar)
if (_tokType == eString || _tokType == eChar)
os << "L";
else
os << "long ";
@ -1015,7 +1017,7 @@ void Token::stringify(std::ostream& os, bool varid, bool attributes, bool macro)
}
if (macro && isExpandedMacro())
os << "$";
if (_str[0] != '\"' || _str.find("\0") == std::string::npos)
if (_str[0] != '\"' || _str.find('\0') == std::string::npos)
os << _str;
else {
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::list<ValueFlow::Value>::const_iterator 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);
if (!ret || size < minsize) {
minsize = size;
@ -1444,7 +1446,7 @@ const Token *Token::getValueTokenMaxStrLength() const
std::size_t maxlength = 0U;
std::list<ValueFlow::Value>::const_iterator 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);
if (!ret || length > maxlength) {
maxlength = length;

View File

@ -30,6 +30,7 @@
#include "mathlib.h"
class Scope;
class Type;
class Function;
class Variable;
class Settings;
@ -222,59 +223,59 @@ public:
**/
static std::string getCharAt(const Token *tok, std::size_t index);
Type type() const {
return _type;
Token::Type tokType() const {
return _tokType;
}
void type(Type t) {
_type = t;
void tokType(Token::Type t) {
_tokType = t;
}
void isKeyword(bool kwd) {
if (kwd)
_type = eKeyword;
else if (_type == eKeyword)
_type = eName;
_tokType = eKeyword;
else if (_tokType == eKeyword)
_tokType = eName;
}
bool isKeyword() const {
return _type == eKeyword;
return _tokType == eKeyword;
}
bool isName() const {
return _type == eName || _type == eType || _type == eVariable || _type == eFunction || _type == eKeyword ||
_type == eBoolean; // TODO: "true"/"false" aren't really a name...
return _tokType == eName || _tokType == eType || _tokType == eVariable || _tokType == eFunction || _tokType == eKeyword ||
_tokType == eBoolean; // TODO: "true"/"false" aren't really a name...
}
bool isUpperCaseName() const;
bool isLiteral() const {
return _type == eNumber || _type == eString || _type == eChar ||
_type == eBoolean || _type == eLiteral;
return _tokType == eNumber || _tokType == eString || _tokType == eChar ||
_tokType == eBoolean || _tokType == eLiteral;
}
bool isNumber() const {
return _type == eNumber;
return _tokType == eNumber;
}
bool isOp() const {
return (isConstOp() ||
isAssignmentOp() ||
_type == eIncDecOp);
_tokType == eIncDecOp);
}
bool isConstOp() const {
return (isArithmeticalOp() ||
_type == eLogicalOp ||
_type == eComparisonOp ||
_type == eBitOp);
_tokType == eLogicalOp ||
_tokType == eComparisonOp ||
_tokType == eBitOp);
}
bool isExtendedOp() const {
return isConstOp() ||
_type == eExtendedOp;
_tokType == eExtendedOp;
}
bool isArithmeticalOp() const {
return _type == eArithmeticalOp;
return _tokType == eArithmeticalOp;
}
bool isComparisonOp() const {
return _type == eComparisonOp;
return _tokType == eComparisonOp;
}
bool isAssignmentOp() const {
return _type == eAssignmentOp;
return _tokType == eAssignmentOp;
}
bool isBoolean() const {
return _type == eBoolean;
return _tokType == eBoolean;
}
bool isUnaryPreOp() const;
@ -464,7 +465,7 @@ public:
void varId(unsigned int id) {
_varId = id;
if (id != 0)
_type = eVariable;
_tokType = eVariable;
else
update_property_info();
}
@ -576,16 +577,16 @@ public:
void function(const Function *f) {
_function = f;
if (f)
_type = eFunction;
else if (_type == eFunction)
_type = eName;
_tokType = eFunction;
else if (_tokType == eFunction)
_tokType = eName;
}
/**
* @return a pointer to the Function associated with this token.
*/
const Function *function() const {
return _type == eFunction ? _function : 0;
return _tokType == eFunction ? _function : 0;
}
/**
@ -595,16 +596,35 @@ public:
void variable(const Variable *v) {
_variable = v;
if (v || _varId)
_type = eVariable;
else if (_type == eVariable)
_type = eName;
_tokType = eVariable;
else if (_tokType == eVariable)
_tokType = eName;
}
/**
* @return a pointer to the variable associated with this token.
*/
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 {
const Function *_function;
const Variable *_variable;
const ::Type* _type;
};
unsigned int _varId;
@ -763,7 +784,7 @@ private:
*/
unsigned int _progressValue;
Type _type;
Token::Type _tokType;
enum {
fIsUnsigned = (1 << 0),

View File

@ -134,7 +134,7 @@ unsigned int Tokenizer::sizeOfType(const Token *type) const
if (!type || type->str().empty())
return 0;
if (type->type() == Token::eString)
if (type->tokType() == Token::eString)
return static_cast<unsigned int>(Token::getStrLength(type) + 1);
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->fileIndex(commonFileIndex);
tok2->linenr(linenrs);
tok2->type(tok->type());
tok2->tokType(tok->tokType());
tok2->flags(tok->flags());
tok2->varId(tok->varId());
@ -1935,7 +1935,7 @@ void Tokenizer::combineStrings()
for (Token *tok = list.front();
tok;
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"'
tok->str(tok->next()->str());
tok->deleteNext();
@ -1951,7 +1951,7 @@ void Tokenizer::combineStrings()
continue;
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()));
// Two strings after each other, combine them
@ -2007,7 +2007,7 @@ void Tokenizer::simplifyNull()
void Tokenizer::concatenateNegativeNumberAndAnyPositive()
{
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;
if (tok->next()->str() == "+")
tok->deleteNext();
@ -3893,9 +3893,9 @@ void Tokenizer::dump(std::ostream &out) const
out << " isInt=\"True\"";
if (MathLib::isFloat(tok->str()))
out << " isFloat=\"True\"";
} else if (tok->type() == Token::eString)
} else if (tok->tokType() == Token::eString)
out << " type=\"string\" strlen=\"" << Token::getStrLength(tok) << '\"';
else if (tok->type() == Token::eChar)
else if (tok->tokType() == Token::eChar)
out << " type=\"char\"";
else if (tok->isBoolean())
out << " type=\"boolean\"";
@ -3907,7 +3907,7 @@ void Tokenizer::dump(std::ostream &out) const
out << " isAssignmentOp=\"True\"";
else if (tok->isComparisonOp())
out << " isComparisonOp=\"True\"";
else if (tok->type() == Token::eLogicalOp)
else if (tok->tokType() == Token::eLogicalOp)
out << " isLogicalOp=\"True\"";
}
if (tok->link())
@ -4499,8 +4499,8 @@ Token *Tokenizer::simplifyAddBracesPair(Token *tok, bool commandWithCondition)
tokAfterCondition=tokAfterCondition->next();
}
if (!tokAfterCondition ||
((tokAfterCondition->type()==Token::eBracket ||
tokAfterCondition->type()==Token::eExtendedOp)&&
((tokAfterCondition->tokType()==Token::eBracket ||
tokAfterCondition->tokType()==Token::eExtendedOp)&&
Token::Match(tokAfterCondition,")|}|>|,"))) {
// No tokens left where to add braces around
return tok;
@ -4532,11 +4532,11 @@ Token *Tokenizer::simplifyAddBracesPair(Token *tok, bool commandWithCondition)
// Look for ; to add own closing brace after it
while (tokEnd &&
tokEnd->str()!=";" &&
!((tokEnd->type()==Token::eBracket ||
tokEnd->type()==Token::eExtendedOp)&&
!((tokEnd->tokType()==Token::eBracket ||
tokEnd->tokType()==Token::eExtendedOp)&&
Token::Match(tokEnd,")|}|>"))) {
if (tokEnd->type()==Token::eBracket ||
(tokEnd->type()==Token::eExtendedOp && tokEnd->str()=="(")) {
if (tokEnd->tokType()==Token::eBracket ||
(tokEnd->tokType()==Token::eExtendedOp && tokEnd->str()=="(")) {
Token *tokInnerCloseBraket=tokEnd->link();
if (!tokInnerCloseBraket) {
// Inner bracket does not close
@ -4649,7 +4649,7 @@ void Tokenizer::simplifyCompoundAssignment()
for (Token *tok2 = tok->previous(); tok2 && tok2 != tok1; tok2 = tok2->previous()) {
// Don't duplicate ++ and --. Put preincrement in lhs. Put
// postincrement in rhs.
if (tok2->type() == Token::eIncDecOp) {
if (tok2->tokType() == Token::eIncDecOp) {
// pre increment/decrement => don't copy
if (tok2->next()->isName()) {
continue;
@ -5693,7 +5693,7 @@ void Tokenizer::simplifyPlatformTypes()
_settings->platformType == Settings::Win32W ? "win32W" : "win64";
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;
const Library::PlatformType * const platformtype = _settings->library.platform_type(tok->str(), platform_type);
@ -5703,7 +5703,7 @@ void Tokenizer::simplifyPlatformTypes()
if (tok->strAt(-1) == "::") {
const Token * tok1 = tok->tokAt(-2);
// skip when non-global namespace defined
if (tok1 && tok1->type() == Token::eName)
if (tok1 && tok1->tokType() == Token::eName)
continue;
tok = tok->tokAt(-1);
tok->deleteThis();

View File

@ -196,7 +196,7 @@ void TokenList::insertTokens(Token *dest, const Token *src, unsigned int n)
dest->fileIndex(src->fileIndex());
dest->linenr(src->linenr());
dest->varId(src->varId());
dest->type(src->type());
dest->tokType(src->tokType());
dest->flags(src->flags());
src = src->next();
--n;
@ -400,7 +400,7 @@ unsigned long long TokenList::calculateChecksum() const
{
unsigned long long checksum = 0;
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;
for (std::size_t i = 0; i < tok->str().size(); i++)
subchecksum2 += (unsigned int)tok->str()[i];
@ -582,7 +582,7 @@ static bool isPrefixUnary(const Token* tok, bool cpp)
{
if (!tok->previous()
|| ((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 tok->strAt(-1) == ")" && iscast(tok->linkAt(-1));
@ -592,7 +592,7 @@ static void compilePrecedence2(Token *&tok, AST_state& state)
{
compileScope(tok, state);
while (tok) {
if (tok->type() == Token::eIncDecOp && !isPrefixUnary(tok, state.cpp)) {
if (tok->tokType() == Token::eIncDecOp && !isPrefixUnary(tok, state.cpp)) {
compileUnaryOp(tok, state, compileScope);
} else if (tok->str() == "." && tok->strAt(1) != "*") {
if (tok->strAt(1) == ".") {
@ -651,7 +651,7 @@ static void compilePrecedence3(Token *&tok, AST_state& state)
{
compilePrecedence2(tok, state);
while (tok) {
if ((Token::Match(tok, "[+-!~*&]") || tok->type() == Token::eIncDecOp) &&
if ((Token::Match(tok, "[+-!~*&]") || tok->tokType() == Token::eIncDecOp) &&
isPrefixUnary(tok, state.cpp)) {
if (Token::Match(tok, "* [*,)]")) {
Token* tok2 = tok;

View File

@ -296,7 +296,7 @@ static bool isVariableChanged(const Token *start, const Token *end, const unsign
const Token *parent = tok->astParent();
while (Token::Match(parent, ".|::"))
parent = parent->astParent();
if (parent && parent->type() == Token::eIncDecOp)
if (parent && parent->tokType() == Token::eIncDecOp)
return true;
}
}
@ -401,10 +401,10 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value)
parent->astOperand2()->values.front().isKnown()));
std::list<ValueFlow::Value>::const_iterator value1, value2;
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;
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;
if (known || value1->varId == 0U || value2->varId == 0U ||
(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.varId = (value1->varId != 0U) ? value1->varId : value2->varId;
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 MathLib::bigint index = value2->intvalue;
if (index >= 0 && index < s.size()) {
@ -569,7 +569,7 @@ static void valueFlowNumber(TokenList *tokenlist)
static void valueFlowString(TokenList *tokenlist)
{
for (Token *tok = tokenlist->front(); tok; tok = tok->next()) {
if (tok->type() == Token::eString) {
if (tok->tokType() == Token::eString) {
ValueFlow::Value strvalue;
strvalue.tokvalue = tok;
strvalue.setKnown();

View File

@ -1866,9 +1866,6 @@ private:
"class Bar;\n"
"class Sub;\n");
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)
return;
std::list<Type>::const_iterator i = db->typeList.begin();
@ -1938,9 +1935,6 @@ private:
" struct Barney barney;\n"
"};\n");
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)
return;
std::list<Type>::const_iterator i = db->typeList.begin();

View File

@ -237,8 +237,8 @@ private:
void multiCompare4() const {
givenACodeSampleToTokenize var("std :: queue < int > foo ;");
ASSERT_EQUALS(Token::eBracket, var.tokens()->tokAt(3)->type());
ASSERT_EQUALS(Token::eBracket, var.tokens()->tokAt(5)->type());
ASSERT_EQUALS(Token::eBracket, var.tokens()->tokAt(3)->tokType());
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 x|%op%"));
@ -762,47 +762,47 @@ private:
for (test_op = extendedOps.begin(); test_op != extendedOps.end(); ++test_op) {
Token tok(nullptr);
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) {
Token tok(nullptr);
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) {
Token tok(nullptr);
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) {
Token tok(nullptr);
tok.str(*test_op);
ASSERT_EQUALS(Token::eComparisonOp, tok.type());
ASSERT_EQUALS(Token::eComparisonOp, tok.tokType());
}
Token tok(nullptr);
tok.str("++");
ASSERT_EQUALS(Token::eIncDecOp, tok.type());
ASSERT_EQUALS(Token::eIncDecOp, tok.tokType());
tok.str("--");
ASSERT_EQUALS(Token::eIncDecOp, tok.type());
ASSERT_EQUALS(Token::eIncDecOp, tok.tokType());
}
void literals() const {
Token tok(nullptr);
tok.str("\"foo\"");
ASSERT(tok.type() == Token::eString);
ASSERT(tok.tokType() == Token::eString);
tok.str("\"\"");
ASSERT(tok.type() == Token::eString);
ASSERT(tok.tokType() == Token::eString);
tok.str("'f'");
ASSERT(tok.type() == Token::eChar);
ASSERT(tok.tokType() == Token::eChar);
tok.str("12345");
ASSERT(tok.type() == Token::eNumber);
ASSERT(tok.tokType() == Token::eNumber);
tok.str("-55");
ASSERT(tok.type() == Token::eNumber);
ASSERT(tok.tokType() == Token::eNumber);
tok.str("true");
ASSERT(tok.type() == Token::eBoolean);
ASSERT(tok.tokType() == Token::eBoolean);
tok.str("false");
ASSERT(tok.type() == Token::eBoolean);
ASSERT(tok.tokType() == Token::eBoolean);
}
void isStandardType() const {

View File

@ -86,7 +86,7 @@ class MatchCompiler:
elif tok == '%bool%':
return 'tok->isBoolean()'
elif tok == '%char%':
return '(tok->type()==Token::eChar)'
return '(tok->tokType()==Token::eChar)'
elif tok == '%comp%':
return 'tok->isComparisonOp()'
elif tok == '%num%':
@ -96,11 +96,11 @@ class MatchCompiler:
elif tok == '%op%':
return 'tok->isOp()'
elif tok == '%or%':
return '(tok->type() == Token::eBitOp && tok->str()==MatchCompiler::makeConstString("|") )'
return '(tok->tokType() == Token::eBitOp && tok->str()==MatchCompiler::makeConstString("|") )'
elif tok == '%oror%':
return '(tok->type() == Token::eLogicalOp && tok->str()==MatchCompiler::makeConstString("||"))'
return '(tok->tokType() == Token::eLogicalOp && tok->str()==MatchCompiler::makeConstString("||"))'
elif tok == '%str%':
return '(tok->type()==Token::eString)'
return '(tok->tokType()==Token::eString)'
elif tok == '%type%':
return (
'(tok->isName() && tok->varId()==0U && !tok->isKeyword())'