astyle formatting
This commit is contained in:
parent
d3035c246f
commit
07c1f28035
|
@ -1395,15 +1395,15 @@ void CheckOther::checkConstVariable()
|
||||||
if (Function::returnsReference(function) && !Function::returnsConst(function)) {
|
if (Function::returnsReference(function) && !Function::returnsConst(function)) {
|
||||||
std::vector<const Token*> returns = Function::findReturns(function);
|
std::vector<const Token*> returns = Function::findReturns(function);
|
||||||
if (std::any_of(returns.begin(), returns.end(), [&](const Token* retTok) {
|
if (std::any_of(returns.begin(), returns.end(), [&](const Token* retTok) {
|
||||||
if (retTok->varId() == var->declarationId())
|
if (retTok->varId() == var->declarationId())
|
||||||
return true;
|
return true;
|
||||||
while (retTok && retTok->isCast())
|
while (retTok && retTok->isCast())
|
||||||
retTok = retTok->astOperand2();
|
retTok = retTok->astOperand2();
|
||||||
while (Token::simpleMatch(retTok, "."))
|
while (Token::simpleMatch(retTok, "."))
|
||||||
retTok = retTok->astOperand2();
|
retTok = retTok->astOperand2();
|
||||||
return hasLifetimeToken(getParentLifetime(retTok), var->nameToken());
|
return hasLifetimeToken(getParentLifetime(retTok), var->nameToken());
|
||||||
}))
|
}))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Skip if address is taken
|
// Skip if address is taken
|
||||||
if (Token::findmatch(var->nameToken(), "& %varid%", scope->bodyEnd, var->declarationId()))
|
if (Token::findmatch(var->nameToken(), "& %varid%", scope->bodyEnd, var->declarationId()))
|
||||||
|
|
|
@ -78,11 +78,10 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
|
|
||||||
static const Token* skipScopeIdentifiers(const Token* tok)
|
static const Token* skipScopeIdentifiers(const Token* tok)
|
||||||
{
|
{
|
||||||
if (tok && tok->str() == "::") {
|
if (Token::Match(tok, ":: %name%"))
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
}
|
|
||||||
while (Token::Match(tok, "%name% ::") ||
|
while (Token::Match(tok, "%name% ::") ||
|
||||||
(Token::Match(tok, "%name% <") && Token::simpleMatch(tok->linkAt(1), "> ::"))) {
|
(Token::Match(tok, "%name% <") && Token::Match(tok->linkAt(1), ">|>> ::"))) {
|
||||||
if (tok->strAt(1) == "::")
|
if (tok->strAt(1) == "::")
|
||||||
tok = tok->tokAt(2);
|
tok = tok->tokAt(2);
|
||||||
else
|
else
|
||||||
|
@ -2633,10 +2632,7 @@ static bool isUnknownType(const Token* start, const Token* end)
|
||||||
{
|
{
|
||||||
while (Token::Match(start, "const|volatile"))
|
while (Token::Match(start, "const|volatile"))
|
||||||
start = start->next();
|
start = start->next();
|
||||||
if (Token::Match(start, ":: %name%"))
|
start = skipScopeIdentifiers(start);
|
||||||
start = start->next();
|
|
||||||
while (Token::Match(start, "%name% :: %name%"))
|
|
||||||
start = start->tokAt(2);
|
|
||||||
if (start->tokAt(1) == end && !start->type() && !start->isStandardType())
|
if (start->tokAt(1) == end && !start->type() && !start->isStandardType())
|
||||||
return true;
|
return true;
|
||||||
// TODO: Try to deduce the type of the expression
|
// TODO: Try to deduce the type of the expression
|
||||||
|
|
|
@ -10799,63 +10799,67 @@ void Tokenizer::simplifyAttributeList()
|
||||||
{
|
{
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
while (Token::Match(tok, "__attribute__|__attribute (") &&
|
while (Token::Match(tok, "__attribute__|__attribute (") &&
|
||||||
tok->next()->link() != tok->next()->next() &&
|
tok->next()->link() != tok->next()->next() &&
|
||||||
tok->next()->link() && tok->next()->link()->next()) {
|
tok->next()->link() && tok->next()->link()->next()) {
|
||||||
|
|
||||||
// tokens for braces in __attribute__ (( ))
|
// tokens for braces in __attribute__ (( ))
|
||||||
// (left to right: outerLeftBr, innerLeftBr, innerRightBr, outerRightBr)
|
// (left to right: outerLeftBr, innerLeftBr, innerRightBr, outerRightBr)
|
||||||
Token *outerLeftBr = tok->next(), *outerRightBr = outerLeftBr->link();
|
Token *outerLeftBr = tok->next(), *outerRightBr = outerLeftBr->link();
|
||||||
Token *innerLeftBr = tok->next()->next(), *innerRightBr = innerLeftBr->link();
|
Token *innerLeftBr = tok->next()->next(), *innerRightBr = innerLeftBr->link();
|
||||||
|
|
||||||
// new intermediate __attribute__|__attribute in place of comma
|
// new intermediate __attribute__|__attribute in place of comma
|
||||||
Token *newtok = nullptr;
|
Token *newtok = nullptr;
|
||||||
|
|
||||||
// new tokens for comma replacement
|
// new tokens for comma replacement
|
||||||
// __attribute__ ((attr1,attr2)) -> __attribute__ ((attr1)) __attribute__((attr2))
|
// __attribute__ ((attr1,attr2)) -> __attribute__ ((attr1)) __attribute__((attr2))
|
||||||
// replaced by ------> \________________/
|
// replaced by ------> \________________/
|
||||||
Token *newInnerRightBr, *newOuterRightBr, *newInnerLeftBr, *newOuterLeftBr;
|
Token *newInnerRightBr, *newOuterRightBr, *newInnerLeftBr, *newOuterLeftBr;
|
||||||
|
|
||||||
Token *attrlist = innerLeftBr->next();
|
Token *attrlist = innerLeftBr->next();
|
||||||
|
|
||||||
// scanning between initial (( and ))
|
// scanning between initial (( and ))
|
||||||
while(attrlist != innerRightBr && !newtok) {
|
while (attrlist != innerRightBr && !newtok) {
|
||||||
|
|
||||||
if (attrlist->str() == ",") {
|
if (attrlist->str() == ",") {
|
||||||
|
|
||||||
attrlist->insertToken(")"); newInnerRightBr = attrlist->next();
|
attrlist->insertToken(")");
|
||||||
Token::createMutualLinks(innerLeftBr, newInnerRightBr);
|
newInnerRightBr = attrlist->next();
|
||||||
|
Token::createMutualLinks(innerLeftBr, newInnerRightBr);
|
||||||
|
|
||||||
newInnerRightBr->insertToken(")"); newOuterRightBr = newInnerRightBr->next();
|
newInnerRightBr->insertToken(")");
|
||||||
Token::createMutualLinks(outerLeftBr, newOuterRightBr);
|
newOuterRightBr = newInnerRightBr->next();
|
||||||
|
Token::createMutualLinks(outerLeftBr, newOuterRightBr);
|
||||||
|
|
||||||
newOuterRightBr->insertToken(tok->str());
|
newOuterRightBr->insertToken(tok->str());
|
||||||
newtok = newOuterRightBr->next();
|
newtok = newOuterRightBr->next();
|
||||||
|
|
||||||
newtok->insertToken("("); newOuterLeftBr = newtok->next();
|
newtok->insertToken("(");
|
||||||
Token::createMutualLinks(newOuterLeftBr, outerRightBr);
|
newOuterLeftBr = newtok->next();
|
||||||
|
Token::createMutualLinks(newOuterLeftBr, outerRightBr);
|
||||||
|
|
||||||
newOuterLeftBr->insertToken("("); newInnerLeftBr = newOuterLeftBr->next();
|
newOuterLeftBr->insertToken("(");
|
||||||
Token::createMutualLinks(newInnerLeftBr, innerRightBr);
|
newInnerLeftBr = newOuterLeftBr->next();
|
||||||
|
Token::createMutualLinks(newInnerLeftBr, innerRightBr);
|
||||||
|
|
||||||
tok = newtok;
|
tok = newtok;
|
||||||
|
|
||||||
// e.g. "," -> ")) __attribute__ (("
|
// e.g. "," -> ")) __attribute__ (("
|
||||||
Token::replace(attrlist, newInnerRightBr, newInnerLeftBr);
|
Token::replace(attrlist, newInnerRightBr, newInnerLeftBr);
|
||||||
|
|
||||||
// jump over internal attribute parameters (e.g. format definition)
|
// jump over internal attribute parameters (e.g. format definition)
|
||||||
// example: __attribute__((format(printf, 1, 2), noreturn))
|
// example: __attribute__((format(printf, 1, 2), noreturn))
|
||||||
} else if (attrlist->str() == "(") {
|
} else if (attrlist->str() == "(") {
|
||||||
attrlist = attrlist->link()->next();
|
attrlist = attrlist->link()->next();
|
||||||
} else {
|
} else {
|
||||||
attrlist = attrlist->next();
|
attrlist = attrlist->next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// passing to next token just after __attribute__ ((...))
|
// passing to next token just after __attribute__ ((...))
|
||||||
// (there may be another __attribute__ ((...)) )
|
// (there may be another __attribute__ ((...)) )
|
||||||
if(!newtok) {
|
if (!newtok) {
|
||||||
tok = outerRightBr->next();
|
tok = outerRightBr->next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2678,10 +2678,10 @@ ValueFlow::Value getLifetimeObjValue(const Token *tok, bool inconclusive)
|
||||||
|
|
||||||
template <class Predicate>
|
template <class Predicate>
|
||||||
static std::vector<LifetimeToken> getLifetimeTokens(const Token* tok,
|
static std::vector<LifetimeToken> getLifetimeTokens(const Token* tok,
|
||||||
bool escape,
|
bool escape,
|
||||||
ValueFlow::Value::ErrorPath errorPath,
|
ValueFlow::Value::ErrorPath errorPath,
|
||||||
Predicate pred,
|
Predicate pred,
|
||||||
int depth = 20)
|
int depth = 20)
|
||||||
{
|
{
|
||||||
if (!tok)
|
if (!tok)
|
||||||
return std::vector<LifetimeToken> {};
|
return std::vector<LifetimeToken> {};
|
||||||
|
@ -2748,8 +2748,8 @@ static std::vector<LifetimeToken> getLifetimeTokens(const Token* tok,
|
||||||
lt.errorPath.emplace_back(returnTok, "Return reference.");
|
lt.errorPath.emplace_back(returnTok, "Return reference.");
|
||||||
lt.errorPath.emplace_back(tok->previous(), "Called function passing '" + argTok->expressionString() + "'.");
|
lt.errorPath.emplace_back(tok->previous(), "Called function passing '" + argTok->expressionString() + "'.");
|
||||||
std::vector<LifetimeToken> arglts = LifetimeToken::setInconclusive(
|
std::vector<LifetimeToken> arglts = LifetimeToken::setInconclusive(
|
||||||
getLifetimeTokens(argTok, escape, std::move(lt.errorPath), pred, depth - returns.size()),
|
getLifetimeTokens(argTok, escape, std::move(lt.errorPath), pred, depth - returns.size()),
|
||||||
returns.size() > 1);
|
returns.size() > 1);
|
||||||
result.insert(result.end(), arglts.begin(), arglts.end());
|
result.insert(result.end(), arglts.begin(), arglts.end());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2761,8 +2761,8 @@ static std::vector<LifetimeToken> getLifetimeTokens(const Token* tok,
|
||||||
if (y == Library::Container::Yield::AT_INDEX || y == Library::Container::Yield::ITEM) {
|
if (y == Library::Container::Yield::AT_INDEX || y == Library::Container::Yield::ITEM) {
|
||||||
errorPath.emplace_back(tok->previous(), "Accessing container.");
|
errorPath.emplace_back(tok->previous(), "Accessing container.");
|
||||||
return LifetimeToken::setAddressOf(
|
return LifetimeToken::setAddressOf(
|
||||||
getLifetimeTokens(tok->tokAt(-2)->astOperand1(), escape, std::move(errorPath), pred, depth - 1),
|
getLifetimeTokens(tok->tokAt(-2)->astOperand1(), escape, std::move(errorPath), pred, depth - 1),
|
||||||
false);
|
false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (Token::Match(tok, ".|::|[")) {
|
} else if (Token::Match(tok, ".|::|[")) {
|
||||||
|
@ -2799,7 +2799,9 @@ static std::vector<LifetimeToken> getLifetimeTokens(const Token* tok,
|
||||||
|
|
||||||
std::vector<LifetimeToken> getLifetimeTokens(const Token* tok, bool escape, ValueFlow::Value::ErrorPath errorPath)
|
std::vector<LifetimeToken> getLifetimeTokens(const Token* tok, bool escape, ValueFlow::Value::ErrorPath errorPath)
|
||||||
{
|
{
|
||||||
return getLifetimeTokens(tok, escape, std::move(errorPath), [](const Token*) { return false; });
|
return getLifetimeTokens(tok, escape, std::move(errorPath), [](const Token*) {
|
||||||
|
return false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasLifetimeToken(const Token* tok, const Token* lifetime)
|
bool hasLifetimeToken(const Token* tok, const Token* lifetime)
|
||||||
|
|
|
@ -427,8 +427,8 @@ ValueFlow::Value inferCondition(std::string op, MathLib::bigint val, const Token
|
||||||
ValueFlow::Value inferCondition(const std::string& op, const Token* varTok, MathLib::bigint val);
|
ValueFlow::Value inferCondition(const std::string& op, const Token* varTok, MathLib::bigint val);
|
||||||
|
|
||||||
std::vector<LifetimeToken> getLifetimeTokens(const Token* tok,
|
std::vector<LifetimeToken> getLifetimeTokens(const Token* tok,
|
||||||
bool escape = false,
|
bool escape = false,
|
||||||
ValueFlow::Value::ErrorPath errorPath = ValueFlow::Value::ErrorPath{});
|
ValueFlow::Value::ErrorPath errorPath = ValueFlow::Value::ErrorPath{});
|
||||||
|
|
||||||
bool hasLifetimeToken(const Token* tok, const Token* lifetime);
|
bool hasLifetimeToken(const Token* tok, const Token* lifetime);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue