Merge pull request #378 from Dmitry-Me/reusePreviouslyComputedValues
Reuse previously computed values, use more const.
This commit is contained in:
commit
55a8009e97
|
@ -1560,7 +1560,7 @@ void CheckStl::readingEmptyStlContainer()
|
||||||
const Variable* var = tok->variable();
|
const Variable* var = tok->variable();
|
||||||
if (var) {
|
if (var) {
|
||||||
bool insert = false;
|
bool insert = false;
|
||||||
if (tok->variable()->nameToken() == tok && var->isLocal() && !var->isStatic()) { // Local variable declared
|
if (var->nameToken() == tok && var->isLocal() && !var->isStatic()) { // Local variable declared
|
||||||
insert = !Token::Match(tok->tokAt(1), "[(=]"); // Only if not initialized
|
insert = !Token::Match(tok->tokAt(1), "[(=]"); // Only if not initialized
|
||||||
} else if (Token::Match(tok, "%var% . clear ( ) ;")) {
|
} else if (Token::Match(tok, "%var% . clear ( ) ;")) {
|
||||||
insert = true;
|
insert = true;
|
||||||
|
@ -1575,7 +1575,7 @@ void CheckStl::readingEmptyStlContainer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool map = empty_map.find(tok->varId()) != empty_map.end();
|
const bool map = empty_map.find(tok->varId()) != empty_map.end();
|
||||||
if (!map && empty_nonmap.find(tok->varId()) == empty_nonmap.end())
|
if (!map && empty_nonmap.find(tok->varId()) == empty_nonmap.end())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
|
@ -7453,7 +7453,7 @@ public:
|
||||||
if (other.value != nullptr)
|
if (other.value != nullptr)
|
||||||
tok->str(other.value->str());
|
tok->str(other.value->str());
|
||||||
else {
|
else {
|
||||||
bool islast = (tok == end);
|
const bool islast = (tok == end);
|
||||||
Token *last = Tokenizer::copyTokens(tok, other.start, other.end);
|
Token *last = Tokenizer::copyTokens(tok, other.start, other.end);
|
||||||
if (last == tok->next()) // tok->deleteThis() invalidates a pointer that points at the next token
|
if (last == tok->next()) // tok->deleteThis() invalidates a pointer that points at the next token
|
||||||
last = tok;
|
last = tok;
|
||||||
|
@ -8177,7 +8177,7 @@ void Tokenizer::eraseDeadCode(Token *begin, const Token *end)
|
||||||
--indentlevel;
|
--indentlevel;
|
||||||
if (indentlevel < indentcheck) {
|
if (indentlevel < indentcheck) {
|
||||||
const Token *end2 = tok->next();
|
const Token *end2 = tok->next();
|
||||||
tok = tok->next()->link()->previous(); //return to initial '{'
|
tok = end2->link()->previous(); //return to initial '{'
|
||||||
if (indentswitch && Token::simpleMatch(tok, ") {") && Token::Match(tok->link()->tokAt(-2), "[{};] switch ("))
|
if (indentswitch && Token::simpleMatch(tok, ") {") && Token::Match(tok->link()->tokAt(-2), "[{};] switch ("))
|
||||||
tok = tok->link()->tokAt(-2); //remove also 'switch ( ... )'
|
tok = tok->link()->tokAt(-2); //remove also 'switch ( ... )'
|
||||||
Token::eraseTokens(tok, end2->next());
|
Token::eraseTokens(tok, end2->next());
|
||||||
|
@ -8282,7 +8282,7 @@ void Tokenizer::eraseDeadCode(Token *begin, const Token *end)
|
||||||
} else { //no need to keep the other strings, remove them.
|
} else { //no need to keep the other strings, remove them.
|
||||||
if (tok->strAt(1) == "while") {
|
if (tok->strAt(1) == "while") {
|
||||||
if (tok->str() == "}" && tok->link()->strAt(-1) == "do")
|
if (tok->str() == "}" && tok->link()->strAt(-1) == "do")
|
||||||
tok->link()->tokAt(-1)->deleteThis();
|
tok->link()->previous()->deleteThis();
|
||||||
}
|
}
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
}
|
}
|
||||||
|
@ -8945,7 +8945,7 @@ void Tokenizer::simplifyWhile0()
|
||||||
Token *tok2 = tok->previous()->link();
|
Token *tok2 = tok->previous()->link();
|
||||||
tok2 = tok2->previous();
|
tok2 = tok2->previous();
|
||||||
if (tok2 && tok2->str() == "do") {
|
if (tok2 && tok2->str() == "do") {
|
||||||
bool flowmatch = Token::findmatch(tok2, "continue|break", tok) != nullptr;
|
const bool flowmatch = Token::findmatch(tok2, "continue|break", tok) != nullptr;
|
||||||
// delete "do ({)"
|
// delete "do ({)"
|
||||||
tok2->deleteThis();
|
tok2->deleteThis();
|
||||||
if (!flowmatch)
|
if (!flowmatch)
|
||||||
|
@ -9468,7 +9468,7 @@ void Tokenizer::simplifyAsm()
|
||||||
tok = tok->tokAt(2);
|
tok = tok->tokAt(2);
|
||||||
if (tok->next() && tok->next()->str() == ";" &&
|
if (tok->next() && tok->next()->str() == ";" &&
|
||||||
tok->next()->linenr() != tok->linenr()) {
|
tok->next()->linenr() != tok->linenr()) {
|
||||||
unsigned int endposition = tok->next()->linenr();
|
const unsigned int endposition = tok->next()->linenr();
|
||||||
tok = tok->tokAt(-3);
|
tok = tok->tokAt(-3);
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
@ -9507,10 +9507,10 @@ void Tokenizer::simplifyBitfields()
|
||||||
}
|
}
|
||||||
} else if (Token::Match(tok, ";|{|}|public:|protected:|private: const| %type% : %any% ;") &&
|
} else if (Token::Match(tok, ";|{|}|public:|protected:|private: const| %type% : %any% ;") &&
|
||||||
tok->next()->str() != "default") {
|
tok->next()->str() != "default") {
|
||||||
const bool offset = (tok->next()->str() == "const");
|
const int offset = (tok->next()->str() == "const") ? 1 : 0;
|
||||||
|
|
||||||
if (!Token::Match(tok->tokAt(3 + (offset ? 1 : 0)), "[{};()]")) {
|
if (!Token::Match(tok->tokAt(3 + offset), "[{};()]")) {
|
||||||
tok->deleteNext(4 + (offset ? 1 : 0));
|
tok->deleteNext(4 + offset);
|
||||||
goback = true;
|
goback = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10404,8 +10404,8 @@ void Tokenizer::printUnknownTypes() const
|
||||||
|
|
||||||
// single token type?
|
// single token type?
|
||||||
if (var->typeStartToken() == var->typeEndToken()) {
|
if (var->typeStartToken() == var->typeEndToken()) {
|
||||||
name = var->typeStartToken()->str();
|
|
||||||
nameTok = var->typeStartToken();
|
nameTok = var->typeStartToken();
|
||||||
|
name = nameTok->str();
|
||||||
}
|
}
|
||||||
|
|
||||||
// complicated type
|
// complicated type
|
||||||
|
@ -10485,14 +10485,14 @@ void Tokenizer::simplifyMathExpressions()
|
||||||
if (!isTwoNumber(leftExponent))
|
if (!isTwoNumber(leftExponent))
|
||||||
continue; // left exponent is not 2
|
continue; // left exponent is not 2
|
||||||
Token * const tok3 = tok2->tokAt(8);
|
Token * const tok3 = tok2->tokAt(8);
|
||||||
if (!Token::Match(tok3->link(), ") , %num% )"))
|
|
||||||
continue;
|
|
||||||
Token * const tok4 = tok3->link();
|
Token * const tok4 = tok3->link();
|
||||||
|
if (!Token::Match(tok4, ") , %num% )"))
|
||||||
|
continue;
|
||||||
const std::string& rightExponent = tok4->strAt(2);
|
const std::string& rightExponent = tok4->strAt(2);
|
||||||
if (!isTwoNumber(rightExponent))
|
if (!isTwoNumber(rightExponent))
|
||||||
continue; // right exponent is not 2
|
continue; // right exponent is not 2
|
||||||
if (tok->tokAt(3)->stringifyList(tok2->next()) == tok3->stringifyList(tok3->link()->next())) {
|
if (tok->tokAt(3)->stringifyList(tok2->next()) == tok3->stringifyList(tok4->next())) {
|
||||||
Token::eraseTokens(tok, tok3->link()->tokAt(4));
|
Token::eraseTokens(tok, tok4->tokAt(4));
|
||||||
tok->str("1");
|
tok->str("1");
|
||||||
}
|
}
|
||||||
} else if (Token::Match(tok->tokAt(2), "cos|cosf|cosl (")) {
|
} else if (Token::Match(tok->tokAt(2), "cos|cosf|cosl (")) {
|
||||||
|
@ -10503,14 +10503,14 @@ void Tokenizer::simplifyMathExpressions()
|
||||||
if (!isTwoNumber(leftExponent))
|
if (!isTwoNumber(leftExponent))
|
||||||
continue; // left exponent is not 2
|
continue; // left exponent is not 2
|
||||||
Token * const tok3 = tok2->tokAt(8);
|
Token * const tok3 = tok2->tokAt(8);
|
||||||
if (!Token::Match(tok3->link(), ") , %num% )"))
|
|
||||||
continue;
|
|
||||||
Token * const tok4 = tok3->link();
|
Token * const tok4 = tok3->link();
|
||||||
|
if (!Token::Match(tok4, ") , %num% )"))
|
||||||
|
continue;
|
||||||
const std::string& rightExponent = tok4->strAt(2);
|
const std::string& rightExponent = tok4->strAt(2);
|
||||||
if (!isTwoNumber(rightExponent))
|
if (!isTwoNumber(rightExponent))
|
||||||
continue; // right exponent is not 2
|
continue; // right exponent is not 2
|
||||||
if (tok->tokAt(3)->stringifyList(tok2->next()) == tok3->stringifyList(tok3->link()->next())) {
|
if (tok->tokAt(3)->stringifyList(tok2->next()) == tok3->stringifyList(tok4->next())) {
|
||||||
Token::eraseTokens(tok, tok3->link()->tokAt(4));
|
Token::eraseTokens(tok, tok4->tokAt(4));
|
||||||
tok->str("1");
|
tok->str("1");
|
||||||
}
|
}
|
||||||
} else if (Token::Match(tok->tokAt(2), "sinh|sinhf|sinhl (")) {
|
} else if (Token::Match(tok->tokAt(2), "sinh|sinhf|sinhl (")) {
|
||||||
|
@ -10521,14 +10521,14 @@ void Tokenizer::simplifyMathExpressions()
|
||||||
if (!isTwoNumber(leftExponent))
|
if (!isTwoNumber(leftExponent))
|
||||||
continue; // left exponent is not 2
|
continue; // left exponent is not 2
|
||||||
Token * const tok3 = tok2->tokAt(8);
|
Token * const tok3 = tok2->tokAt(8);
|
||||||
if (!Token::Match(tok3->link(), ") , %num% )"))
|
|
||||||
continue;
|
|
||||||
Token * const tok4 = tok3->link();
|
Token * const tok4 = tok3->link();
|
||||||
|
if (!Token::Match(tok4, ") , %num% )"))
|
||||||
|
continue;
|
||||||
const std::string& rightExponent = tok4->strAt(2);
|
const std::string& rightExponent = tok4->strAt(2);
|
||||||
if (!isTwoNumber(rightExponent))
|
if (!isTwoNumber(rightExponent))
|
||||||
continue; // right exponent is not 2
|
continue; // right exponent is not 2
|
||||||
if (tok->tokAt(3)->stringifyList(tok2->next()) == tok3->stringifyList(tok3->link()->next())) {
|
if (tok->tokAt(3)->stringifyList(tok2->next()) == tok3->stringifyList(tok4->next())) {
|
||||||
Token::eraseTokens(tok, tok3->link()->tokAt(4));
|
Token::eraseTokens(tok, tok4->tokAt(4));
|
||||||
tok->str("-1");
|
tok->str("-1");
|
||||||
}
|
}
|
||||||
} else if (Token::Match(tok->tokAt(2), "cosh|coshf|coshl (")) {
|
} else if (Token::Match(tok->tokAt(2), "cosh|coshf|coshl (")) {
|
||||||
|
@ -10539,14 +10539,14 @@ void Tokenizer::simplifyMathExpressions()
|
||||||
if (!isTwoNumber(leftExponent))
|
if (!isTwoNumber(leftExponent))
|
||||||
continue; // left exponent is not 2
|
continue; // left exponent is not 2
|
||||||
Token * const tok3 = tok2->tokAt(8);
|
Token * const tok3 = tok2->tokAt(8);
|
||||||
if (!Token::Match(tok3->link(), ") , %num% )"))
|
|
||||||
continue;
|
|
||||||
Token * const tok4 = tok3->link();
|
Token * const tok4 = tok3->link();
|
||||||
|
if (!Token::Match(tok4, ") , %num% )"))
|
||||||
|
continue;
|
||||||
const std::string& rightExponent = tok4->strAt(2);
|
const std::string& rightExponent = tok4->strAt(2);
|
||||||
if (!isTwoNumber(rightExponent))
|
if (!isTwoNumber(rightExponent))
|
||||||
continue; // right exponent is not 2
|
continue; // right exponent is not 2
|
||||||
if (tok->tokAt(3)->stringifyList(tok2->next()) == tok3->stringifyList(tok3->link()->next())) {
|
if (tok->tokAt(3)->stringifyList(tok2->next()) == tok3->stringifyList(tok4->next())) {
|
||||||
Token::eraseTokens(tok, tok3->link()->tokAt(4));
|
Token::eraseTokens(tok, tok4->tokAt(4));
|
||||||
tok->str("-1");
|
tok->str("-1");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue