Fix codestyle (#953)
This commit is contained in:
parent
0fc35c1350
commit
f0b5327450
|
@ -101,7 +101,7 @@ void CheckBufferOverrun::arrayIndexOutOfBoundsError(const Token *tok, const Arra
|
||||||
continue;
|
continue;
|
||||||
std::string nr;
|
std::string nr;
|
||||||
if (index.size() > 1U)
|
if (index.size() > 1U)
|
||||||
nr = "(" + MathLib::toString(i + 1) + getOrdinalText(i+1) + " array index) ";
|
nr = "(" + MathLib::toString(i + 1) + getOrdinalText(i + 1) + " array index) ";
|
||||||
errorPath.push_back(ErrorPathItem(it->first, nr + info));
|
errorPath.push_back(ErrorPathItem(it->first, nr + info));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1671,11 +1671,11 @@ void Tokenizer::simplifyMulAndParens()
|
||||||
if (!tok->isName())
|
if (!tok->isName())
|
||||||
continue;
|
continue;
|
||||||
//fix ticket #2784 - improved by ticket #3184
|
//fix ticket #2784 - improved by ticket #3184
|
||||||
unsigned int closedpars = 0;
|
unsigned int closedPars = 0;
|
||||||
Token *tokend = tok->next();
|
Token *tokend = tok->next();
|
||||||
Token *tokbegin = tok->previous();
|
Token *tokbegin = tok->previous();
|
||||||
while (tokend && tokend->str() == ")") {
|
while (tokend && tokend->str() == ")") {
|
||||||
++closedpars;
|
++closedPars;
|
||||||
tokend = tokend->next();
|
tokend = tokend->next();
|
||||||
}
|
}
|
||||||
if (!tokend || !(tokend->isAssignmentOp()))
|
if (!tokend || !(tokend->isAssignmentOp()))
|
||||||
|
@ -1687,9 +1687,9 @@ void Tokenizer::simplifyMulAndParens()
|
||||||
tokbegin = tokbegin->tokAt(-2);
|
tokbegin = tokbegin->tokAt(-2);
|
||||||
tokbegin->deleteNext(2);
|
tokbegin->deleteNext(2);
|
||||||
} else if (Token::Match(tokbegin->tokAt(-3), "[;{}&(] * (")) {
|
} else if (Token::Match(tokbegin->tokAt(-3), "[;{}&(] * (")) {
|
||||||
if (!closedpars)
|
if (closedPars == 0)
|
||||||
break;
|
break;
|
||||||
--closedpars;
|
--closedPars;
|
||||||
//remove ')'
|
//remove ')'
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
//remove '* ( &'
|
//remove '* ( &'
|
||||||
|
@ -1698,27 +1698,27 @@ void Tokenizer::simplifyMulAndParens()
|
||||||
} else
|
} else
|
||||||
break;
|
break;
|
||||||
} else if (tokbegin->str() == "(") {
|
} else if (tokbegin->str() == "(") {
|
||||||
if (!closedpars)
|
if (closedPars == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//find consecutive opening parentheses
|
//find consecutive opening parentheses
|
||||||
unsigned int openpars = 0;
|
unsigned int openPars = 0;
|
||||||
while (tokbegin && tokbegin->str() == "(" && openpars <= closedpars) {
|
while (tokbegin && tokbegin->str() == "(" && openPars <= closedPars) {
|
||||||
++openpars;
|
++openPars;
|
||||||
tokbegin = tokbegin->previous();
|
tokbegin = tokbegin->previous();
|
||||||
}
|
}
|
||||||
if (!tokbegin || openpars > closedpars)
|
if (!tokbegin || openPars > closedPars)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if ((openpars == closedpars && Token::Match(tokbegin, "[;{}]")) ||
|
if ((openPars == closedPars && Token::Match(tokbegin, "[;{}]")) ||
|
||||||
Token::Match(tokbegin->tokAt(-2), "[;{}&(] * &") ||
|
Token::Match(tokbegin->tokAt(-2), "[;{}&(] * &") ||
|
||||||
Token::Match(tokbegin->tokAt(-3), "[;{}&(] * ( &")) {
|
Token::Match(tokbegin->tokAt(-3), "[;{}&(] * ( &")) {
|
||||||
//remove the excessive parentheses around the variable
|
//remove the excessive parentheses around the variable
|
||||||
while (openpars) {
|
while (openPars > 0) {
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
tokbegin->deleteNext();
|
tokbegin->deleteNext();
|
||||||
--closedpars;
|
--closedPars;
|
||||||
--openpars;
|
--openPars;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
break;
|
break;
|
||||||
|
@ -2136,13 +2136,13 @@ void Tokenizer::arraySize()
|
||||||
|
|
||||||
static Token *skipTernaryOp(Token *tok)
|
static Token *skipTernaryOp(Token *tok)
|
||||||
{
|
{
|
||||||
unsigned int colonlevel = 1;
|
unsigned int colonLevel = 1;
|
||||||
while (nullptr != (tok = tok->next())) {
|
while (nullptr != (tok = tok->next())) {
|
||||||
if (tok->str() == "?") {
|
if (tok->str() == "?") {
|
||||||
++colonlevel;
|
++colonLevel;
|
||||||
} else if (tok->str() == ":") {
|
} else if (tok->str() == ":") {
|
||||||
--colonlevel;
|
--colonLevel;
|
||||||
if (colonlevel == 0) {
|
if (colonLevel == 0) {
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2152,7 +2152,7 @@ static Token *skipTernaryOp(Token *tok)
|
||||||
else if (Token::Match(tok->next(), "[{};)]"))
|
else if (Token::Match(tok->next(), "[{};)]"))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (colonlevel) // Ticket #5214: Make sure the ':' matches the proper '?'
|
if (colonLevel > 0) // Ticket #5214: Make sure the ':' matches the proper '?'
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return tok;
|
return tok;
|
||||||
}
|
}
|
||||||
|
@ -2178,7 +2178,7 @@ const Token * Tokenizer::startOfExecutableScope(const Token * tok)
|
||||||
void Tokenizer::simplifyLabelsCaseDefault()
|
void Tokenizer::simplifyLabelsCaseDefault()
|
||||||
{
|
{
|
||||||
bool executablescope = false;
|
bool executablescope = false;
|
||||||
unsigned int indentlevel = 0;
|
unsigned int indentLevel = 0;
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
// Simplify labels in the executable scope..
|
// Simplify labels in the executable scope..
|
||||||
Token *start = const_cast<Token *>(startOfExecutableScope(tok));
|
Token *start = const_cast<Token *>(startOfExecutableScope(tok));
|
||||||
|
@ -2194,10 +2194,10 @@ void Tokenizer::simplifyLabelsCaseDefault()
|
||||||
if (tok->previous()->str() == "=")
|
if (tok->previous()->str() == "=")
|
||||||
tok = tok->link();
|
tok = tok->link();
|
||||||
else
|
else
|
||||||
++indentlevel;
|
++indentLevel;
|
||||||
} else if (tok->str() == "}") {
|
} else if (tok->str() == "}") {
|
||||||
--indentlevel;
|
--indentLevel;
|
||||||
if (!indentlevel) {
|
if (indentLevel == 0) {
|
||||||
executablescope = false;
|
executablescope = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -4235,7 +4235,7 @@ void Tokenizer::simplifyFlowControl()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Token* end = begin->linkAt(1+(begin->next()->str() == "{" ? 0 : 1));
|
Token* end = begin->linkAt(1+(begin->next()->str() == "{" ? 0 : 1));
|
||||||
unsigned int indentlevel = 0;
|
unsigned int indentLevel = 0;
|
||||||
bool stilldead = false;
|
bool stilldead = false;
|
||||||
|
|
||||||
for (Token *tok = begin; tok && tok != end; tok = tok->next()) {
|
for (Token *tok = begin; tok && tok != end; tok = tok->next()) {
|
||||||
|
@ -4249,20 +4249,20 @@ void Tokenizer::simplifyFlowControl()
|
||||||
tok = tok->link();
|
tok = tok->link();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
++indentlevel;
|
++indentLevel;
|
||||||
} else if (tok->str() == "}") {
|
} else if (tok->str() == "}") {
|
||||||
if (!indentlevel)
|
if (indentLevel == 0)
|
||||||
break;
|
break;
|
||||||
--indentlevel;
|
--indentLevel;
|
||||||
if (stilldead) {
|
if (stilldead) {
|
||||||
eraseDeadCode(tok, nullptr);
|
eraseDeadCode(tok, nullptr);
|
||||||
if (indentlevel == 1 || tok->next()->str() != "}" || !Token::Match(tok->next()->link()->previous(), ";|{|}|do {"))
|
if (indentLevel == 1 || tok->next()->str() != "}" || !Token::Match(tok->next()->link()->previous(), ";|{|}|do {"))
|
||||||
stilldead = false;
|
stilldead = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!indentlevel)
|
if (indentLevel == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (Token::Match(tok,"continue|break ;")) {
|
if (Token::Match(tok,"continue|break ;")) {
|
||||||
|
@ -4289,7 +4289,7 @@ void Tokenizer::simplifyFlowControl()
|
||||||
}
|
}
|
||||||
//if everything is removed, then remove also the code after an inferior scope
|
//if everything is removed, then remove also the code after an inferior scope
|
||||||
//only if the actual scope is not special
|
//only if the actual scope is not special
|
||||||
if (indentlevel > 1 && tok->next()->str() == "}" && Token::Match(tok->next()->link()->previous(), ";|{|}|do {"))
|
if (indentLevel > 1 && tok->next()->str() == "}" && Token::Match(tok->next()->link()->previous(), ";|{|}|do {"))
|
||||||
stilldead = true;
|
stilldead = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ private:
|
||||||
public:
|
public:
|
||||||
explicit CppcheckExecutor(const ReduceSettings & settings)
|
explicit CppcheckExecutor(const ReduceSettings & settings)
|
||||||
: ErrorLogger()
|
: ErrorLogger()
|
||||||
, cppcheck(*this,false)
|
, cppcheck(*this, false)
|
||||||
, foundLine(false)
|
, foundLine(false)
|
||||||
, stopTime(0) {
|
, stopTime(0) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue