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