From 07c1f28035efc8a44d6d981762685a57b7bea756 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 1 May 2021 07:35:03 +0200 Subject: [PATCH] astyle formatting --- lib/checkother.cpp | 18 ++++----- lib/symboldatabase.cpp | 10 ++--- lib/tokenize.cpp | 90 ++++++++++++++++++++++-------------------- lib/valueflow.cpp | 20 +++++----- lib/valueflow.h | 4 +- test/testtokenize.cpp | 4 +- 6 files changed, 74 insertions(+), 72 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index f4decccfb..f565b35cf 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1395,15 +1395,15 @@ void CheckOther::checkConstVariable() if (Function::returnsReference(function) && !Function::returnsConst(function)) { std::vector 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())) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index bfe7df472..4334ba7c8 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -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 diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 2a3b32518..1a5f4a6c9 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -10798,64 +10798,68 @@ void Tokenizer::simplifyDeclspec() 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()) { + while (Token::Match(tok, "__attribute__|__attribute (") && + 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(); + } } } } diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index a2f5c52ed..9cc79b487 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -2678,10 +2678,10 @@ ValueFlow::Value getLifetimeObjValue(const Token *tok, bool inconclusive) template static std::vector 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 {}; @@ -2748,8 +2748,8 @@ static std::vector getLifetimeTokens(const Token* tok, lt.errorPath.emplace_back(returnTok, "Return reference."); lt.errorPath.emplace_back(tok->previous(), "Called function passing '" + argTok->expressionString() + "'."); std::vector 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 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 getLifetimeTokens(const Token* tok, std::vector 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) diff --git a/lib/valueflow.h b/lib/valueflow.h index fe0e6f72a..f305bf412 100644 --- a/lib/valueflow.h +++ b/lib/valueflow.h @@ -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 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); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 1cf0a3f10..bf505bf5a 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -3373,7 +3373,7 @@ private: ASSERT(func5 && func5->isAttributeNoreturn()); ASSERT(func6 && func6->isAttributePure() && func6->isAttributeNothrow() && func6->isAttributeConst()); ASSERT(func7 && func7->isAttributePure() && func7->isAttributeNothrow() && func7->isAttributeConst()); - ASSERT(func8 && func8->isAttributeNoreturn() && func8->isAttributePure() && func8->isAttributeNothrow() && func8->isAttributeConst()); + ASSERT(func8 && func8->isAttributeNoreturn() && func8->isAttributePure() && func8->isAttributeNothrow() && func8->isAttributeConst()); } void functionAttributeListAfter() { @@ -3414,7 +3414,7 @@ private: ASSERT(func5 && func5->isAttributeNoreturn()); ASSERT(func6 && func6->isAttributePure() && func6->isAttributeNothrow() && func6->isAttributeConst()); ASSERT(func7 && func7->isAttributePure() && func7->isAttributeNothrow() && func7->isAttributeConst()); - ASSERT(func8 && func8->isAttributeNoreturn() && func8->isAttributePure() && func8->isAttributeNothrow() && func8->isAttributeConst()); + ASSERT(func8 && func8->isAttributeNoreturn() && func8->isAttributePure() && func8->isAttributeNothrow() && func8->isAttributeConst()); }