Change every 'tokAt(...)->str()' to 'strAt(...)'.

This commit is contained in:
Edoardo Prezioso 2011-11-13 13:10:59 +01:00
parent b28a44dc3b
commit 2c64d299ca
11 changed files with 102 additions and 102 deletions

View File

@ -480,7 +480,7 @@ void CheckBufferOverrun::parse_for_body(const Token *tok2, const ArrayInfo &arra
const char action = tok2->strAt(3)[0];
// second operator
const std::string &second(tok2->tokAt(4)->str());
const std::string &second(tok2->strAt(4));
//printf("min_index: %s %c %s\n", min_counter_value.c_str(), action, second.c_str());
//printf("max_index: %s %c %s\n", max_counter_value.c_str(), action, second.c_str());
@ -493,7 +493,7 @@ void CheckBufferOverrun::parse_for_body(const Token *tok2, const ArrayInfo &arra
const char action = tok2->strAt(3)[0];
// first operand
const std::string &first(tok2->tokAt(2)->str());
const std::string &first(tok2->strAt(2));
//printf("min_index: %s %c %s\n", first.c_str(), action, min_counter_value.c_str());
//printf("max_index: %s %c %s\n", first.c_str(), action, max_counter_value.c_str());
@ -1233,9 +1233,9 @@ void CheckBufferOverrun::checkReadlinkBufferUsage(const Token* tok, const Token
}
if (!found_termination) {
bufferNotZeroTerminatedError(tok, tok->tokAt(4 + param_offset)->str(), funcname);
bufferNotZeroTerminatedError(tok, tok->strAt(4 + param_offset), funcname);
} else if (n == total_size) {
possibleReadlinkBufferOverrunError(tok, funcname, tok->tokAt(4 + param_offset)->str());
possibleReadlinkBufferOverrunError(tok, funcname, tok->strAt(4 + param_offset));
}
}
@ -1717,7 +1717,7 @@ void CheckBufferOverrun::checkBufferAllocatedWithStrlen()
bufferOverrunError(tok);
} else if (Token::Match(tok, "sprintf ( %varid% , %str% , %var% )", dstVarId) &&
tok->tokAt(6)->varId() == srcVarId &&
tok->tokAt(4)->str().find("%s") != std::string::npos) {
tok->strAt(4).find("%s") != std::string::npos) {
bufferOverrunError(tok);
}
@ -1781,10 +1781,10 @@ void CheckBufferOverrun::checkInsecureCmdLineArgs()
Token::Match(tok, "strcpy|strcat ( %var% , %varid% [", varid)) {
cmdLineArgsError(tok);
} else if (Token::Match(tok, "sprintf ( %var% , %str% , %varid% [", varid) &&
tok->tokAt(4)->str().find("%s") != std::string::npos) {
tok->strAt(4).find("%s") != std::string::npos) {
cmdLineArgsError(tok);
} else if (Token::Match(tok, "sprintf ( %var% , %str% , * %varid%", varid) &&
tok->tokAt(4)->str().find("%s") != std::string::npos) {
tok->strAt(4).find("%s") != std::string::npos) {
cmdLineArgsError(tok);
}

View File

@ -990,10 +990,10 @@ bool CheckClass::hasAssignSelf(const Function *func, const Token *rhs)
if (tok1 && tok2) {
for (; tok1 && tok1 != tok2; tok1 = tok1->next()) {
if (Token::Match(tok1, "this ==|!= & %var%")) {
if (tok1->tokAt(3)->str() == rhs->str())
if (tok1->strAt(3) == rhs->str())
return true;
} else if (Token::Match(tok1, "& %var% ==|!= this")) {
if (tok1->tokAt(1)->str() == rhs->str())
if (tok1->strAt(1) == rhs->str())
return true;
}
}

View File

@ -173,7 +173,7 @@ void CheckExceptionSafety::checkRethrowCopy()
const Token* rethrowTok = Token::findmatch(startBlockTok, "throw %varid%", endBlockTok, varid);
if (rethrowTok) {
rethrowCopyError(rethrowTok, startBlockTok->tokAt(-2)->str());
rethrowCopyError(rethrowTok, startBlockTok->strAt(-2));
}
tok = Token::findmatch(endBlockTok->next(), catchPattern);

View File

@ -2291,7 +2291,7 @@ void CheckMemoryLeakInFunction::checkReallocUsage()
Token::Match(tokEndBrace->tokAt(-2)->link()->tokAt(-2), "{|}|; %var% ("))
continue;
}
memleakUponReallocFailureError(tok->tokAt(1), tok->tokAt(1)->str());
memleakUponReallocFailureError(tok->tokAt(1), tok->strAt(1));
}
}
}
@ -2361,12 +2361,12 @@ void CheckMemoryLeakInFunction::parseFunctionScope(const Token *tok, const Token
sz = 1;
if (Token::Match(tok, "[{};] %type% * const| %var% [;=]")) {
const Token *vartok = tok->tokAt(tok->tokAt(3)->str() != "const" ? 3 : 4);
const Token *vartok = tok->tokAt(tok->strAt(3) != "const" ? 3 : 4);
checkScope(tok->next(), vartok->str(), vartok->varId(), classmember, sz);
}
else if (Token::Match(tok, "[{};] %type% %type% * const| %var% [;=]")) {
const Token *vartok = tok->tokAt(tok->tokAt(4)->str() != "const" ? 4 : 5);
const Token *vartok = tok->tokAt(tok->strAt(4) != "const" ? 4 : 5);
checkScope(tok->next(), vartok->str(), vartok->varId(), classmember, sz);
}

View File

@ -720,7 +720,7 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
const Token *endbody = Token::simpleMatch(endpar, ") {") ? endpar->next()->link() : 0;
if (endbody &&
Token::Match(endbody->tokAt(-3), "[;{}] %var% ;") &&
isUpper(endbody->tokAt(-2)->str()))
isUpper(endbody->strAt(-2)))
continue;
}

View File

@ -291,14 +291,14 @@ void CheckOther::warningOldStylePointerCast()
continue;
unsigned char addToIndex = 0;
if (tok->tokAt(1)->str() == "const")
if (tok->strAt(1) == "const")
addToIndex = 1;
if (tok->tokAt(4 + addToIndex)->str() == "const")
if (tok->strAt(4 + addToIndex) == "const")
continue;
// Is "type" a class?
const std::string pattern("class " + tok->tokAt(1 + addToIndex)->str());
const std::string pattern("class " + tok->strAt(1 + addToIndex));
if (!Token::findmatch(_tokenizer->tokens(), pattern.c_str()))
continue;
@ -364,7 +364,7 @@ void CheckOther::checkSizeofForArrayParameter()
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
if (Token::Match(tok, "sizeof ( %var% )") || Token::Match(tok, "sizeof %var%")) {
unsigned short tokIdx = 1;
if (tok->tokAt(tokIdx)->str() == "(") {
if (tok->strAt(tokIdx) == "(") {
++tokIdx;
}
if (tok->tokAt(tokIdx)->varId() > 0) {
@ -433,7 +433,7 @@ void CheckOther::checkSizeofForStrncmpSize()
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
if (Token::Match(tok, pattern1) || Token::Match(tok, pattern2)) {
unsigned short tokIdx = 7;
if (tok->tokAt(tokIdx)->str() == "(")
if (tok->strAt(tokIdx) == "(")
++tokIdx;
const Token *tokVar = tok->tokAt(tokIdx);
if (tokVar->varId() > 0) {
@ -891,7 +891,7 @@ void CheckOther::checkIncorrectLogicOperator()
continue;
}
varFirst1 = true;
firstConstant = term1Tok->tokAt(2)->str();
firstConstant = term1Tok->strAt(2);
} else if (Token::Match(term1Tok, "%num% %any% %var%")) {
varTok = term1Tok->tokAt(2);
varId = varTok->varId();
@ -916,7 +916,7 @@ void CheckOther::checkIncorrectLogicOperator()
continue;
}
varFirst2 = true;
secondConstant = term2Tok->tokAt(2)->str();
secondConstant = term2Tok->strAt(2);
variableTested = varId;
} else if (Token::Match(term2Tok, "%num% %any% %var%")) {
const unsigned int varId2 = term1Tok->tokAt(2)->varId();
@ -1331,13 +1331,13 @@ void CheckOther::checkComparisonOfBoolWithInt()
std::map<unsigned int, bool> boolvars; // Contains all declarated standard type variables and indicates whether its a bool or not.
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
if (Token::Match(tok, "[{};(,] %type% %var% [;=,)]") && tok->tokAt(1)->isStandardType()) { // Declaration of standard type variable
boolvars[tok->tokAt(2)->varId()] = (tok->tokAt(1)->str() == "bool");
boolvars[tok->tokAt(2)->varId()] = (tok->strAt(1) == "bool");
} else if (Token::Match(tok, "%var% >|>=|==|!=|<=|< %num%")) { // Comparing variable with number
const Token *varTok = tok;
const Token *numTok = tok->tokAt(2);
std::map<unsigned int, bool>::const_iterator iVar = boolvars.find(varTok->varId());
if (iVar != boolvars.end() && iVar->second && // Variable has to be a boolean
((tok->tokAt(1)->str() != "==" && tok->tokAt(1)->str() != "!=") ||
((tok->strAt(1) != "==" && tok->strAt(1) != "!=") ||
((MathLib::toLongNumber(numTok->str()) != 0) && (!_tokenizer->code_is_c() || MathLib::toLongNumber(numTok->str()) != 1)))) { // == 0 and != 0 are allowed, for C also == 1 and != 1
comparisonOfBoolWithIntError(varTok, numTok->str());
}
@ -1346,7 +1346,7 @@ void CheckOther::checkComparisonOfBoolWithInt()
const Token *numTok = tok;
std::map<unsigned int, bool>::const_iterator iVar = boolvars.find(varTok->varId());
if (iVar != boolvars.end() && iVar->second && // Variable has to be a boolean
((tok->tokAt(1)->str() != "==" && tok->tokAt(1)->str() != "!=") ||
((tok->strAt(1) != "==" && tok->strAt(1) != "!=") ||
((MathLib::toLongNumber(numTok->str()) != 0) && (!_tokenizer->code_is_c() || MathLib::toLongNumber(numTok->str()) != 1)))) { // == 0 and != 0 are allowed, for C also == 1 and != 1
comparisonOfBoolWithIntError(varTok, numTok->str());
}
@ -1963,8 +1963,8 @@ void CheckOther::checkZeroDivision()
MathLib::toLongNumber(tok->next()->str()) == 0L) {
zerodivError(tok);
} else if (Token::Match(tok, "div|ldiv|lldiv|imaxdiv ( %num% , %num% )") &&
MathLib::isInt(tok->tokAt(4)->str()) &&
MathLib::toLongNumber(tok->tokAt(4)->str()) == 0L) {
MathLib::isInt(tok->strAt(4)) &&
MathLib::toLongNumber(tok->strAt(4)) == 0L) {
zerodivError(tok);
}
}
@ -1981,16 +1981,16 @@ void CheckOther::checkMathFunctions()
{
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
if (tok->varId() == 0 && Token::Match(tok, "log|log10 ( %num% )")) {
bool isNegative = MathLib::isNegative(tok->tokAt(2)->str());
bool isInt = MathLib::isInt(tok->tokAt(2)->str());
bool isFloat = MathLib::isFloat(tok->tokAt(2)->str());
if (isNegative && isInt && MathLib::toLongNumber(tok->tokAt(2)->str()) <= 0) {
bool isNegative = MathLib::isNegative(tok->strAt(2));
bool isInt = MathLib::isInt(tok->strAt(2));
bool isFloat = MathLib::isFloat(tok->strAt(2));
if (isNegative && isInt && MathLib::toLongNumber(tok->strAt(2)) <= 0) {
mathfunctionCallError(tok); // case log(-2)
} else if (isNegative && isFloat && MathLib::toDoubleNumber(tok->tokAt(2)->str()) <= 0.) {
} else if (isNegative && isFloat && MathLib::toDoubleNumber(tok->strAt(2)) <= 0.) {
mathfunctionCallError(tok); // case log(-2.0)
} else if (!isNegative && isFloat && MathLib::toDoubleNumber(tok->tokAt(2)->str()) <= 0.) {
} else if (!isNegative && isFloat && MathLib::toDoubleNumber(tok->strAt(2)) <= 0.) {
mathfunctionCallError(tok); // case log(0.0)
} else if (!isNegative && isInt && MathLib::toLongNumber(tok->tokAt(2)->str()) <= 0) {
} else if (!isNegative && isInt && MathLib::toLongNumber(tok->strAt(2)) <= 0) {
mathfunctionCallError(tok); // case log(0)
}
}
@ -1998,33 +1998,33 @@ void CheckOther::checkMathFunctions()
// acos( x ), asin( x ) where x is defined for intervall [-1,+1], but not beyound
else if (tok->varId() == 0 &&
Token::Match(tok, "acos|asin ( %num% )") &&
std::fabs(MathLib::toDoubleNumber(tok->tokAt(2)->str())) > 1.0) {
std::fabs(MathLib::toDoubleNumber(tok->strAt(2))) > 1.0) {
mathfunctionCallError(tok);
}
// sqrt( x ): if x is negative the result is undefined
else if (tok->varId() == 0 &&
Token::Match(tok, "sqrt|sqrtf|sqrtl ( %num% )") &&
MathLib::isNegative(tok->tokAt(2)->str())) {
MathLib::isNegative(tok->strAt(2))) {
mathfunctionCallError(tok);
}
// atan2 ( x , y): x and y can not be zero, because this is mathematically not defined
else if (tok->varId() == 0 &&
Token::Match(tok, "atan2 ( %num% , %num% )") &&
MathLib::isNullValue(tok->tokAt(2)->str()) &&
MathLib::isNullValue(tok->tokAt(4)->str())) {
MathLib::isNullValue(tok->strAt(2)) &&
MathLib::isNullValue(tok->strAt(4))) {
mathfunctionCallError(tok, 2);
}
// fmod ( x , y) If y is zero, then either a range error will occur or the function will return zero (implementation-defined).
else if (tok->varId() == 0 &&
Token::Match(tok, "fmod ( %num% , %num% )") &&
MathLib::isNullValue(tok->tokAt(4)->str())) {
MathLib::isNullValue(tok->strAt(4))) {
mathfunctionCallError(tok, 2);
}
// pow ( x , y) If x is zero, and y is negative --> division by zero
else if (tok->varId() == 0 &&
Token::Match(tok, "pow ( %num% , %num% )") &&
MathLib::isNullValue(tok->tokAt(2)->str()) &&
MathLib::isNegative(tok->tokAt(4)->str())) {
MathLib::isNullValue(tok->strAt(2)) &&
MathLib::isNegative(tok->strAt(4))) {
mathfunctionCallError(tok, 2);
}
@ -2035,9 +2035,9 @@ void CheckOther::mathfunctionCallError(const Token *tok, const unsigned int numP
{
if (tok) {
if (numParam == 1)
reportError(tok, Severity::error, "wrongmathcall", "Passing value " + tok->tokAt(2)->str() + " to " + tok->str() + "() leads to undefined result");
reportError(tok, Severity::error, "wrongmathcall", "Passing value " + tok->strAt(2) + " to " + tok->str() + "() leads to undefined result");
else if (numParam == 2)
reportError(tok, Severity::error, "wrongmathcall", "Passing value " + tok->tokAt(2)->str() + " and " + tok->tokAt(4)->str() + " to " + tok->str() + "() leads to undefined result");
reportError(tok, Severity::error, "wrongmathcall", "Passing value " + tok->strAt(2) + " and " + tok->strAt(4) + " to " + tok->str() + "() leads to undefined result");
} else
reportError(tok, Severity::error, "wrongmathcall", "Passing value " " to " "() leads to undefined result");
}
@ -2117,30 +2117,30 @@ void CheckOther::checkIncorrectStringCompare()
{
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
if (Token::Match(tok, ". substr ( %any% , %num% ) ==|!= %str%")) {
size_t clen = MathLib::toLongNumber(tok->tokAt(5)->str());
size_t clen = MathLib::toLongNumber(tok->strAt(5));
size_t slen = Token::getStrLength(tok->tokAt(8));
if (clen != slen) {
incorrectStringCompareError(tok->next(), "substr", tok->tokAt(8)->str(), tok->tokAt(5)->str());
incorrectStringCompareError(tok->next(), "substr", tok->strAt(8), tok->strAt(5));
}
}
if (Token::Match(tok, "%str% ==|!= %var% . substr ( %any% , %num% )")) {
size_t clen = MathLib::toLongNumber(tok->tokAt(8)->str());
size_t clen = MathLib::toLongNumber(tok->strAt(8));
size_t slen = Token::getStrLength(tok);
if (clen != slen) {
incorrectStringCompareError(tok->next(), "substr", tok->str(), tok->tokAt(8)->str());
incorrectStringCompareError(tok->next(), "substr", tok->str(), tok->strAt(8));
}
}
if (Token::Match(tok, "&&|%oror% %str% &&|%oror%|)")) {
// assert(condition && "debug message") would be considered a fp.
if (tok->str() == "&&" && tok->tokAt(2)->str() == ")" && tok->tokAt(2)->link()->previous()->str() == "assert")
if (tok->str() == "&&" && tok->strAt(2) == ")" && tok->tokAt(2)->link()->previous()->str() == "assert")
continue;
incorrectStringBooleanError(tok->tokAt(1), tok->tokAt(1)->str());
incorrectStringBooleanError(tok->tokAt(1), tok->strAt(1));
}
if (Token::Match(tok, "if|while|assert ( %str% &&|%oror%|)")) {
// assert("debug message" && condition) would be considered a fp.
if (tok->tokAt(3)->str() == "&&" && tok->str() == "assert")
if (tok->strAt(3) == "&&" && tok->str() == "assert")
continue;
incorrectStringBooleanError(tok->tokAt(2), tok->tokAt(2)->str());
incorrectStringBooleanError(tok->tokAt(2), tok->strAt(2));
}
}
}

View File

@ -90,7 +90,7 @@ void CheckStl::iterators()
// If insert/erase is used on different container then
// report an error
if (tok2->varId() != containerId && tok2->tokAt(5)->str() != ".") {
if (tok2->varId() != containerId && tok2->strAt(5) != ".") {
// skip error message if container is a set..
if (tok2->varId() > 0) {
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
@ -203,12 +203,12 @@ void CheckStl::mismatchingContainers()
// TODO: If iterator variables are used instead then there are false negatives.
if (Token::Match(tok, pattern2.c_str()) && algorithm2.find(tok->strAt(2)) != algorithm2.end()) {
if (tok->tokAt(4)->str() != tok->tokAt(10)->str()) {
if (tok->strAt(4) != tok->strAt(10)) {
mismatchingContainersError(tok);
}
tok = tok->tokAt(15);
} else if (Token::Match(tok, pattern22.c_str()) && algorithm22.find(tok->strAt(2)) != algorithm22.end()) {
if (tok->tokAt(4)->str() != tok->tokAt(10)->str() || tok->tokAt(16)->str() != tok->tokAt(22)->str()) {
if (tok->strAt(4) != tok->strAt(10) || tok->strAt(16) != tok->strAt(22)) {
mismatchingContainersError(tok);
}
tok = tok->tokAt(27);
@ -225,7 +225,7 @@ void CheckStl::mismatchingContainers()
break;
}
if (tok2 && Token::Match(tok2, pattern1x1_2.c_str())) {
if (tok->tokAt(4)->str() != tok2->tokAt(1)->str()) {
if (tok->strAt(4) != tok2->strAt(1)) {
mismatchingContainersError(tok);
}
tok = tok2->tokAt(6);
@ -277,7 +277,7 @@ void CheckStl::stlOutOfBounds()
if (Token::simpleMatch(tok3->next(), ". size ( )"))
break;
else if (Token::Match(tok3->next(), "[ %varid% ]", numId))
stlOutOfBoundsError(tok3, tok3->tokAt(2)->str(), tok3->str());
stlOutOfBoundsError(tok3, tok3->strAt(2), tok3->str());
}
}
break;
@ -455,8 +455,8 @@ void CheckStl::erase()
}
if (Token::Match(tok2, "%var% = %var% . begin|rbegin|cbegin|crbegin ( ) ; %var% != %var% . end|rend|cend|crend ( )") &&
tok2->str() == tok2->tokAt(8)->str() &&
tok2->tokAt(2)->str() == tok2->tokAt(10)->str()) {
tok2->str() == tok2->strAt(8) &&
tok2->strAt(2) == tok2->strAt(10)) {
EraseCheckLoop::checkScope(this, tok2);
break;
}
@ -546,7 +546,7 @@ void CheckStl::pushback()
if (iteratorid == 0)
continue;
if (iteratorDeclaredInsideLoop && tok->tokAt(4)->str() == "=") {
if (iteratorDeclaredInsideLoop && tok->strAt(4) == "=") {
// skip "> :: iterator|const_iterator"
tok = tok->tokAt(3);
}
@ -878,7 +878,7 @@ void CheckStl::redundantCondition()
"}|}|";
const Token *tok = Token::findmatch(_tokenizer->tokens(), pattern);
while (tok) {
bool b(tok->tokAt(15)->str() == "{");
bool b(tok->strAt(15) == "{");
// Get tokens for the fields %var% and %any%
const Token *var1 = tok->tokAt(2);
@ -1201,8 +1201,8 @@ void CheckStl::uselessCalls()
} else if (Token::Match(tok, "%var% . substr ( )")) {
uselessCallsSubstrError(tok, tok->str());
} else if (Token::Match(tok, "%var% . substr ( 0")) {
if (tok->tokAt(5)->str() == ")" ||
tok->tokAt(3)->link()->tokAt(-1)->str() == "npos")
if (tok->strAt(5) == ")" ||
tok->tokAt(3)->link()->strAt(-1) == "npos")
uselessCallsSubstrError(tok, tok->str());
}
}

View File

@ -548,7 +548,7 @@ private:
if (Token::Match(tok.next(), "= malloc|kmalloc") || Token::simpleMatch(tok.next(), "= new char [")) {
alloc_pointer(checks, tok.varId());
if (tok.tokAt(3)->str() == "(")
if (tok.strAt(3) == "(")
return tok.tokAt(3);
}

View File

@ -409,7 +409,7 @@ static int doAssignment(Variables &variables, const Token *tok, bool dereference
int start = 1;
// search for '='
while (tok->tokAt(start)->str() != "=")
while (tok->strAt(start) != "=")
start++;
start++;
@ -426,21 +426,21 @@ static int doAssignment(Variables &variables, const Token *tok, bool dereference
variables.use(tok->tokAt(start)->varId()); // use = read + write
// check for C style cast
if (tok->tokAt(start)->str() == "(") {
if (tok->tokAt(start + 1)->str() == "const")
if (tok->strAt(start) == "(") {
if (tok->strAt(start + 1) == "const")
offset++;
if (Token::Match(tok->tokAt(start + 1 + offset), "struct|union"))
offset++;
if (tok->tokAt(start + 2 + offset)->str() == "*")
if (tok->strAt(start + 2 + offset) == "*")
offset++;
if (tok->tokAt(start + 3 + offset)->str() == "&") {
if (tok->strAt(start + 3 + offset) == "&") {
addressOf = true;
next = start + 4 + offset;
} else if (tok->tokAt(start + 3 + offset)->str() == "(") {
if (tok->tokAt(start + 4 + offset)->str() == "&") {
} else if (tok->strAt(start + 3 + offset) == "(") {
if (tok->strAt(start + 4 + offset) == "&") {
addressOf = true;
next = start + 5 + offset;
} else
@ -450,18 +450,18 @@ static int doAssignment(Variables &variables, const Token *tok, bool dereference
}
// check for C++ style cast
else if (tok->tokAt(start)->str().find("cast") != std::string::npos &&
tok->tokAt(start + 1)->str() == "<") {
if (tok->tokAt(start + 2)->str() == "const")
else if (tok->strAt(start).find("cast") != std::string::npos &&
tok->strAt(start + 1) == "<") {
if (tok->strAt(start + 2) == "const")
offset++;
if (Token::Match(tok->tokAt(start + 2 + offset), "struct|union"))
offset++;
if (tok->tokAt(start + 3 + offset)->str() == "*")
if (tok->strAt(start + 3 + offset) == "*")
offset++;
if (tok->tokAt(start + 5 + offset)->str() == "&") {
if (tok->strAt(start + 5 + offset) == "&") {
addressOf = true;
next = start + 6 + offset;
} else
@ -475,10 +475,10 @@ static int doAssignment(Variables &variables, const Token *tok, bool dereference
// no cast
else {
if (tok->tokAt(start)->str() == "&") {
if (tok->strAt(start) == "&") {
addressOf = true;
next = start + 1;
} else if (tok->tokAt(start)->str() == "new")
} else if (tok->strAt(start) == "new")
return 0;
else
next = start;
@ -538,7 +538,7 @@ static int doAssignment(Variables &variables, const Token *tok, bool dereference
}
variables.alias(varid1, varid2, replace);
} else if (tok->tokAt(next + 1)->str() == "?") {
} else if (tok->strAt(next + 1) == "?") {
if (var2->_type == Variables::reference)
variables.readAliases(varid2);
else
@ -548,7 +548,7 @@ static int doAssignment(Variables &variables, const Token *tok, bool dereference
} else if (var1->_type == Variables::reference) {
variables.alias(varid1, varid2, true);
} else {
if (var2->_type == Variables::pointer && tok->tokAt(next + 1)->str() == "[")
if (var2->_type == Variables::pointer && tok->strAt(next + 1) == "[")
variables.readAliases(varid2);
variables.read(varid2);
@ -714,7 +714,7 @@ void CheckUnusedVar::checkFunctionVariableUsage()
if (tok->isStandardType() || isRecordTypeWithoutSideEffects(tok->next())) {
variables.addVar(tok->next(), Variables::standard, info,
tok->tokAt(2)->str() == "=" || isStatic);
tok->strAt(2) == "=" || isStatic);
}
tok = tok->next();
}
@ -757,7 +757,7 @@ void CheckUnusedVar::checkFunctionVariableUsage()
tok = tok->next();
variables.addVar(tok->next(), Variables::standard, info,
tok->tokAt(2)->str() == "=" || isStatic);
tok->strAt(2) == "=" || isStatic);
tok = tok->next();
}
@ -796,7 +796,7 @@ void CheckUnusedVar::checkFunctionVariableUsage()
const Token * const nametok = tok->tokAt(isPointer ? 2 : 1);
variables.addVar(nametok, isPointer ? Variables::pointerArray : Variables::array, info,
nametok->tokAt(4)->str() == "=" || isStatic);
nametok->strAt(4) == "=" || isStatic);
// check for reading array size from local variable
if (nametok->tokAt(2)->varId() != 0)
@ -838,7 +838,7 @@ void CheckUnusedVar::checkFunctionVariableUsage()
else
type = Variables::reference;
bool written = tok->tokAt(3)->str() == "=";
bool written = tok->strAt(3) == "=";
variables.addVar(tok->tokAt(2), type, info, written || isStatic);
@ -865,7 +865,7 @@ void CheckUnusedVar::checkFunctionVariableUsage()
tok = tok->next();
if (tok->str() != "return") {
bool written = tok->tokAt(4)->str() == "=";
bool written = tok->strAt(4) == "=";
variables.addVar(tok->tokAt(3), Variables::pointerPointer, info, written || isStatic);
@ -972,7 +972,7 @@ void CheckUnusedVar::checkFunctionVariableUsage()
if (tok->str() != "return") {
variables.addVar(tok->tokAt(2),
tok->next()->str() == "*" ? Variables::pointerArray : Variables::referenceArray, info,
tok->tokAt(6)->str() == "=" || isStatic);
tok->strAt(6) == "=" || isStatic);
// check for reading array size from local variable
if (tok->tokAt(4)->varId() != 0)
@ -995,8 +995,8 @@ void CheckUnusedVar::checkFunctionVariableUsage()
tok = tok->next();
variables.addVar(tok->tokAt(3),
tok->tokAt(2)->str() == "*" ? Variables::pointerArray : Variables::referenceArray, info,
tok->tokAt(7)->str() == "=" || isStatic);
tok->strAt(2) == "*" ? Variables::pointerArray : Variables::referenceArray, info,
tok->strAt(7) == "=" || isStatic);
// check for reading array size from local variable
if (tok->tokAt(5)->varId() != 0)

View File

@ -375,7 +375,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
// class destructor
else if (tok->previous() && tok->previous()->str() == "~" &&
tok->tokAt(-2) && tok->tokAt(-2)->str() == "::")
tok->tokAt(-2) && tok->strAt(-2) == "::")
addFunction(&scope, &tok, argStart);
// regular function

View File

@ -1010,7 +1010,7 @@ void Tokenizer::simplifyTypedef()
}
// check for template
if (tok->tokAt(offset)->str() == "<") {
if (tok->strAt(offset) == "<") {
unsigned int level = 0;
unsigned int paren = 0;
typeEnd = tok->tokAt(offset + 1);
@ -1050,7 +1050,7 @@ void Tokenizer::simplifyTypedef()
// check for pointers and references
while (Token::Match(tok->tokAt(offset), "*|&|const"))
pointers.push_back(tok->tokAt(offset++)->str());
pointers.push_back(tok->strAt(offset++));
// check for invalid input
if (!tok->tokAt(offset)) {
@ -1063,7 +1063,7 @@ void Tokenizer::simplifyTypedef()
typeName = tok->tokAt(offset++);
// check for array
if (tok->tokAt(offset) && tok->tokAt(offset)->str() == "[") {
if (tok->tokAt(offset) && tok->strAt(offset) == "[") {
arrayStart = tok->tokAt(offset);
bool atEnd = false;
@ -1073,9 +1073,9 @@ void Tokenizer::simplifyTypedef()
if (!tok->tokAt(offset + 1))
return; // invalid input
else if (tok->tokAt(offset + 1)->str() == ";")
else if (tok->strAt(offset + 1) == ";")
atEnd = true;
else if (tok->tokAt(offset)->str() == "]")
else if (tok->strAt(offset) == "]")
atEnd = true;
else
++offset;
@ -1161,7 +1161,7 @@ void Tokenizer::simplifyTypedef()
// function: typedef ... ( .... type )( ... );
// typedef ... (( .... type )( ... ));
// typedef ... ( * ( .... type )( ... ));
else if ((tok->tokAt(offset)->str() == "(" &&
else if ((tok->strAt(offset) == "(" &&
Token::Match(tok->tokAt(offset)->link()->previous(), "%type% ) (") &&
Token::Match(tok->tokAt(offset)->link()->next()->link(), ") const|volatile|;")) ||
(Token::simpleMatch(tok->tokAt(offset), "( (") &&
@ -1260,8 +1260,8 @@ void Tokenizer::simplifyTypedef()
// pointer/reference to array
else if (Token::Match(tok->tokAt(offset), "( *|& %type% ) [")) {
ptrToArray = (tok->tokAt(offset + 1)->str() == "*");
refToArray = (tok->tokAt(offset + 1)->str() == "&");
ptrToArray = (tok->strAt(offset + 1) == "*");
refToArray = (tok->strAt(offset + 1) == "&");
typeName = tok->tokAt(offset + 2);
arrayStart = tok->tokAt(offset + 4);
arrayEnd = arrayStart->link();
@ -1761,12 +1761,12 @@ void Tokenizer::simplifyTypedef()
pointers.clear();
while (Token::Match(tok->tokAt(offset), "*|&"))
pointers.push_back(tok->tokAt(offset++)->str());
pointers.push_back(tok->strAt(offset++));
if (Token::Match(tok->tokAt(offset), "%type%")) {
typeName = tok->tokAt(offset++);
if (tok->tokAt(offset) && tok->tokAt(offset)->str() == "[") {
if (tok->tokAt(offset) && tok->strAt(offset) == "[") {
arrayStart = tok->tokAt(offset);
bool atEnd = false;
@ -1776,9 +1776,9 @@ void Tokenizer::simplifyTypedef()
if (!tok->tokAt(offset + 1))
return; // invalid input
else if (tok->tokAt(offset + 1)->str() == ";")
else if (tok->strAt(offset + 1) == ";")
atEnd = true;
else if (tok->tokAt(offset)->str() == "]")
else if (tok->strAt(offset) == "]")
atEnd = true;
else
++offset;
@ -2984,7 +2984,7 @@ void Tokenizer::simplifyTemplatesInstantiate(const Token *tok,
}
return;
}
if ((tok->tokAt(namepos)->str() == "*" || tok->tokAt(namepos)->str() == "&"))
if ((tok->strAt(namepos) == "*" || tok->strAt(namepos) == "&"))
++namepos;
// name of template function/class..
@ -4724,7 +4724,7 @@ void Tokenizer::removeRedundantFor()
// Same variable name..
const std::string varname(tok->strAt(3));
const unsigned int varid(tok->tokAt(3)->varId());
if (varname != tok->tokAt(7)->str())
if (varname != tok->strAt(7))
continue;
const Token *vartok = tok->tokAt(11);
if (vartok->str() == "++")
@ -6794,7 +6794,7 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
--indentlevel3;
if (indentlevel3 < indentlevel) {
if (Token::Match((*tok2)->tokAt(-7), "%type% * %var% ; %var% = & %var% ;") &&
(*tok2)->tokAt(-5)->str() == (*tok2)->strAt(-3)) {
(*tok2)->strAt(-5) == (*tok2)->strAt(-3)) {
(*tok2) = (*tok2)->tokAt(-4);
Token::eraseTokens((*tok2), (*tok2)->tokAt(5));
}