astyle formatting

This commit is contained in:
Daniel Marjamäki 2018-10-18 20:08:32 +02:00
parent 58b21e3071
commit 4983a6a5dc
4 changed files with 106 additions and 126 deletions

View File

@ -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;