astyle formatting
This commit is contained in:
parent
58b21e3071
commit
4983a6a5dc
|
@ -1771,10 +1771,10 @@ void CheckOther::misusedScopeObjectError(const Token *tok, const std::string& va
|
|||
|
||||
static const Token * getSingleExpressionInBlock(const Token * tok)
|
||||
{
|
||||
if(!tok)
|
||||
if (!tok)
|
||||
return nullptr;
|
||||
const Token * top = tok->astTop();
|
||||
if(!top)
|
||||
if (!top)
|
||||
return nullptr;
|
||||
const Token * nextExpression = nextAfterAstRightmostLeaf(top);
|
||||
if (!Token::simpleMatch(nextExpression, "; }"))
|
||||
|
@ -1840,9 +1840,9 @@ void CheckOther::checkDuplicateBranch()
|
|||
const Token * branchTop2 = getSingleExpressionInBlock(scope.bodyEnd->tokAt(3));
|
||||
if (!branchTop1 || !branchTop2)
|
||||
continue;
|
||||
if(branchTop1->str() != branchTop2->str())
|
||||
if (branchTop1->str() != branchTop2->str())
|
||||
continue;
|
||||
if(isSameExpression(mTokenizer->isCPP(), false, branchTop1->astOperand1(), branchTop2->astOperand1(), mSettings->library, true, true, &errorPath) &&
|
||||
if (isSameExpression(mTokenizer->isCPP(), false, branchTop1->astOperand1(), branchTop2->astOperand1(), mSettings->library, true, true, &errorPath) &&
|
||||
isSameExpression(mTokenizer->isCPP(), false, branchTop1->astOperand2(), branchTop2->astOperand2(), mSettings->library, true, true, &errorPath))
|
||||
duplicateBranchError(scope.classDef, scope.bodyEnd->next(), errorPath);
|
||||
}
|
||||
|
@ -2027,7 +2027,7 @@ void CheckOther::checkDuplicateExpression()
|
|||
}
|
||||
if (!assigned && !isUniqueExpression(tok->astOperand2()))
|
||||
duplicateAssignExpressionError(var1, var2, false);
|
||||
else if(mSettings->inconclusive)
|
||||
else if (mSettings->inconclusive)
|
||||
duplicateAssignExpressionError(var1, var2, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -264,8 +264,7 @@ static std::string getContainerName(const Token *containerToken)
|
|||
return ret;
|
||||
}
|
||||
|
||||
enum OperandPosition
|
||||
{
|
||||
enum OperandPosition {
|
||||
Left,
|
||||
Right
|
||||
};
|
||||
|
@ -273,18 +272,13 @@ enum OperandPosition
|
|||
static const Token* findIteratorContainer(const Token* start, const Token* end, unsigned int id)
|
||||
{
|
||||
const Token* containerToken = nullptr;
|
||||
for(const Token* tok = start; tok != end; tok = tok->next())
|
||||
{
|
||||
if (Token::Match(tok, "%varid% = %name% . %name% (", id))
|
||||
{
|
||||
for (const Token* tok = start; tok != end; tok = tok->next()) {
|
||||
if (Token::Match(tok, "%varid% = %name% . %name% (", id)) {
|
||||
// Iterator is assigned to value
|
||||
if (tok->tokAt(5)->valueType() && tok->tokAt(5)->valueType()->type == ValueType::Type::ITERATOR)
|
||||
{
|
||||
if (tok->tokAt(5)->valueType() && tok->tokAt(5)->valueType()->type == ValueType::Type::ITERATOR) {
|
||||
containerToken = tok->tokAt(2);
|
||||
}
|
||||
}
|
||||
else if (Token::Match(tok, "%varid% = %name% (", id))
|
||||
{
|
||||
} else if (Token::Match(tok, "%varid% = %name% (", id)) {
|
||||
// Prevent FP: iterator is assigned to something
|
||||
// TODO: Fix it in future
|
||||
containerToken = nullptr;
|
||||
|
@ -478,13 +472,10 @@ bool CheckStl::compareIteratorAgainstDifferentContainer(const Token* operatorTok
|
|||
|
||||
const Token *otherOperand = nullptr;
|
||||
OperandPosition operandPosition;
|
||||
if (operatorTok->astOperand1()->varId() == iteratorId)
|
||||
{
|
||||
if (operatorTok->astOperand1()->varId() == iteratorId) {
|
||||
otherOperand = operatorTok->astOperand2();
|
||||
operandPosition = OperandPosition::Right;
|
||||
}
|
||||
else if (operatorTok->astOperand2()->varId() == iteratorId)
|
||||
{
|
||||
} else if (operatorTok->astOperand2()->varId() == iteratorId) {
|
||||
otherOperand = operatorTok->astOperand1();
|
||||
operandPosition = OperandPosition::Left;
|
||||
}
|
||||
|
@ -493,43 +484,32 @@ bool CheckStl::compareIteratorAgainstDifferentContainer(const Token* operatorTok
|
|||
return false;
|
||||
|
||||
const Token * const otherExprPart = otherOperand->tokAt(-3);
|
||||
if (Token::Match(otherExprPart, "%name% . end|rend|cend|crend ( )") && otherExprPart->varId() != containerTok->varId())
|
||||
{
|
||||
if (Token::Match(otherExprPart, "%name% . end|rend|cend|crend ( )") && otherExprPart->varId() != containerTok->varId()) {
|
||||
const std::string& firstContainerName = getContainerName(containerTok);
|
||||
const std::string& secondContainerName = getContainerName(otherExprPart);
|
||||
if (firstContainerName != secondContainerName)
|
||||
{
|
||||
if (firstContainerName != secondContainerName) {
|
||||
if (operandPosition == OperandPosition::Right)
|
||||
iteratorsError(operatorTok, containerTok, firstContainerName, secondContainerName);
|
||||
else
|
||||
iteratorsError(operatorTok, containerTok, secondContainerName, firstContainerName);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
iteratorsError(operatorTok, containerTok, firstContainerName);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
const unsigned int otherId = otherOperand->varId();
|
||||
auto it = iteratorScopeBeginInfo.find(otherId);
|
||||
if (it != iteratorScopeBeginInfo.end())
|
||||
{
|
||||
if (it != iteratorScopeBeginInfo.end()) {
|
||||
const Token* otherContainerToken = findIteratorContainer(it->second, operatorTok->astOperand1(), otherId);
|
||||
if (otherContainerToken && otherContainerToken->varId() != containerTok->varId())
|
||||
{
|
||||
if (otherContainerToken && otherContainerToken->varId() != containerTok->varId()) {
|
||||
const std::string& firstContainerName = getContainerName(containerTok);
|
||||
const std::string& secondContainerName = getContainerName(otherContainerToken);
|
||||
if (firstContainerName != secondContainerName)
|
||||
{
|
||||
if (firstContainerName != secondContainerName) {
|
||||
if (operandPosition == OperandPosition::Right)
|
||||
iteratorsCmpError(operatorTok, containerTok, otherContainerToken, firstContainerName, secondContainerName);
|
||||
else
|
||||
iteratorsCmpError(operatorTok, containerTok, otherContainerToken, secondContainerName, firstContainerName);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
iteratorsCmpError(operatorTok, containerTok, otherContainerToken, firstContainerName);
|
||||
}
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue