astyle formatting

This commit is contained in:
Daniel Marjamäki 2021-05-01 07:35:03 +02:00
parent d3035c246f
commit 07c1f28035
6 changed files with 74 additions and 72 deletions

View File

@ -1395,15 +1395,15 @@ void CheckOther::checkConstVariable()
if (Function::returnsReference(function) && !Function::returnsConst(function)) {
std::vector<const Token*> returns = Function::findReturns(function);
if (std::any_of(returns.begin(), returns.end(), [&](const Token* retTok) {
if (retTok->varId() == var->declarationId())
return true;
while (retTok && retTok->isCast())
retTok = retTok->astOperand2();
while (Token::simpleMatch(retTok, "."))
retTok = retTok->astOperand2();
return hasLifetimeToken(getParentLifetime(retTok), var->nameToken());
}))
continue;
if (retTok->varId() == var->declarationId())
return true;
while (retTok && retTok->isCast())
retTok = retTok->astOperand2();
while (Token::simpleMatch(retTok, "."))
retTok = retTok->astOperand2();
return hasLifetimeToken(getParentLifetime(retTok), var->nameToken());
}))
continue;
}
// Skip if address is taken
if (Token::findmatch(var->nameToken(), "& %varid%", scope->bodyEnd, var->declarationId()))

View File

@ -78,11 +78,10 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
static const Token* skipScopeIdentifiers(const Token* tok)
{
if (tok && tok->str() == "::") {
if (Token::Match(tok, ":: %name%"))
tok = tok->next();
}
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) == "::")
tok = tok->tokAt(2);
else
@ -2633,10 +2632,7 @@ static bool isUnknownType(const Token* start, const Token* end)
{
while (Token::Match(start, "const|volatile"))
start = start->next();
if (Token::Match(start, ":: %name%"))
start = start->next();
while (Token::Match(start, "%name% :: %name%"))
start = start->tokAt(2);
start = skipScopeIdentifiers(start);
if (start->tokAt(1) == end && !start->type() && !start->isStandardType())
return true;
// TODO: Try to deduce the type of the expression

View File

@ -10799,63 +10799,67 @@ void Tokenizer::simplifyAttributeList()
{
for (Token *tok = list.front(); tok; tok = tok->next()) {
while (Token::Match(tok, "__attribute__|__attribute (") &&
tok->next()->link() != tok->next()->next() &&
tok->next()->link() && tok->next()->link()->next()) {
tok->next()->link() != tok->next()->next() &&
tok->next()->link() && tok->next()->link()->next()) {
// tokens for braces in __attribute__ (( ))
// (left to right: outerLeftBr, innerLeftBr, innerRightBr, outerRightBr)
Token *outerLeftBr = tok->next(), *outerRightBr = outerLeftBr->link();
Token *innerLeftBr = tok->next()->next(), *innerRightBr = innerLeftBr->link();
// tokens for braces in __attribute__ (( ))
// (left to right: outerLeftBr, innerLeftBr, innerRightBr, outerRightBr)
Token *outerLeftBr = tok->next(), *outerRightBr = outerLeftBr->link();
Token *innerLeftBr = tok->next()->next(), *innerRightBr = innerLeftBr->link();
// new intermediate __attribute__|__attribute in place of comma
Token *newtok = nullptr;
// new intermediate __attribute__|__attribute in place of comma
Token *newtok = nullptr;
// new tokens for comma replacement
// __attribute__ ((attr1,attr2)) -> __attribute__ ((attr1)) __attribute__((attr2))
// replaced by ------> \________________/
Token *newInnerRightBr, *newOuterRightBr, *newInnerLeftBr, *newOuterLeftBr;
// new tokens for comma replacement
// __attribute__ ((attr1,attr2)) -> __attribute__ ((attr1)) __attribute__((attr2))
// replaced by ------> \________________/
Token *newInnerRightBr, *newOuterRightBr, *newInnerLeftBr, *newOuterLeftBr;
Token *attrlist = innerLeftBr->next();
Token *attrlist = innerLeftBr->next();
// scanning between initial (( and ))
while(attrlist != innerRightBr && !newtok) {
// scanning between initial (( and ))
while (attrlist != innerRightBr && !newtok) {
if (attrlist->str() == ",") {
if (attrlist->str() == ",") {
attrlist->insertToken(")"); newInnerRightBr = attrlist->next();
Token::createMutualLinks(innerLeftBr, newInnerRightBr);
attrlist->insertToken(")");
newInnerRightBr = attrlist->next();
Token::createMutualLinks(innerLeftBr, newInnerRightBr);
newInnerRightBr->insertToken(")"); newOuterRightBr = newInnerRightBr->next();
Token::createMutualLinks(outerLeftBr, newOuterRightBr);
newInnerRightBr->insertToken(")");
newOuterRightBr = newInnerRightBr->next();
Token::createMutualLinks(outerLeftBr, newOuterRightBr);
newOuterRightBr->insertToken(tok->str());
newtok = newOuterRightBr->next();
newOuterRightBr->insertToken(tok->str());
newtok = newOuterRightBr->next();
newtok->insertToken("("); newOuterLeftBr = newtok->next();
Token::createMutualLinks(newOuterLeftBr, outerRightBr);
newtok->insertToken("(");
newOuterLeftBr = newtok->next();
Token::createMutualLinks(newOuterLeftBr, outerRightBr);
newOuterLeftBr->insertToken("("); newInnerLeftBr = newOuterLeftBr->next();
Token::createMutualLinks(newInnerLeftBr, innerRightBr);
newOuterLeftBr->insertToken("(");
newInnerLeftBr = newOuterLeftBr->next();
Token::createMutualLinks(newInnerLeftBr, innerRightBr);
tok = newtok;
tok = newtok;
// e.g. "," -> ")) __attribute__ (("
Token::replace(attrlist, newInnerRightBr, newInnerLeftBr);
// e.g. "," -> ")) __attribute__ (("
Token::replace(attrlist, newInnerRightBr, newInnerLeftBr);
// jump over internal attribute parameters (e.g. format definition)
// example: __attribute__((format(printf, 1, 2), noreturn))
} else if (attrlist->str() == "(") {
attrlist = attrlist->link()->next();
} else {
attrlist = attrlist->next();
}
}
// jump over internal attribute parameters (e.g. format definition)
// example: __attribute__((format(printf, 1, 2), noreturn))
} else if (attrlist->str() == "(") {
attrlist = attrlist->link()->next();
} else {
attrlist = attrlist->next();
}
}
// passing to next token just after __attribute__ ((...))
// (there may be another __attribute__ ((...)) )
if(!newtok) {
tok = outerRightBr->next();
}
// passing to next token just after __attribute__ ((...))
// (there may be another __attribute__ ((...)) )
if (!newtok) {
tok = outerRightBr->next();
}
}
}
}

View File

@ -2678,10 +2678,10 @@ ValueFlow::Value getLifetimeObjValue(const Token *tok, bool inconclusive)
template <class Predicate>
static std::vector<LifetimeToken> getLifetimeTokens(const Token* tok,
bool escape,
ValueFlow::Value::ErrorPath errorPath,
Predicate pred,
int depth = 20)
bool escape,
ValueFlow::Value::ErrorPath errorPath,
Predicate pred,
int depth = 20)
{
if (!tok)
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(tok->previous(), "Called function passing '" + argTok->expressionString() + "'.");
std::vector<LifetimeToken> arglts = LifetimeToken::setInconclusive(
getLifetimeTokens(argTok, escape, std::move(lt.errorPath), pred, depth - returns.size()),
returns.size() > 1);
getLifetimeTokens(argTok, escape, std::move(lt.errorPath), pred, depth - returns.size()),
returns.size() > 1);
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) {
errorPath.emplace_back(tok->previous(), "Accessing container.");
return LifetimeToken::setAddressOf(
getLifetimeTokens(tok->tokAt(-2)->astOperand1(), escape, std::move(errorPath), pred, depth - 1),
false);
getLifetimeTokens(tok->tokAt(-2)->astOperand1(), escape, std::move(errorPath), pred, depth - 1),
false);
}
}
} 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)
{
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)

View File

@ -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);
std::vector<LifetimeToken> getLifetimeTokens(const Token* tok,
bool escape = false,
ValueFlow::Value::ErrorPath errorPath = ValueFlow::Value::ErrorPath{});
bool escape = false,
ValueFlow::Value::ErrorPath errorPath = ValueFlow::Value::ErrorPath{});
bool hasLifetimeToken(const Token* tok, const Token* lifetime);