1) Run runastyle;
2) Clarify some comments in 'Tokenizer::simplifyFlowControl' and in 'Tokenizer::eraseDeadCode'; 3) Add some 'const' variables inside 'Tokenizer::eraseDeadCode'.
This commit is contained in:
parent
d0d5a2fcd8
commit
6889a28d31
|
@ -1553,12 +1553,12 @@ bool CheckClass::isVirtualFunc(const Scope *scope, const Token *functionToken) c
|
||||||
void CheckClass::checkConstError(const Token *tok, const std::string &classname, const std::string &funcname)
|
void CheckClass::checkConstError(const Token *tok, const std::string &classname, const std::string &funcname)
|
||||||
{
|
{
|
||||||
reportInconclusiveError(tok, Severity::style, "functionConst",
|
reportInconclusiveError(tok, Severity::style, "functionConst",
|
||||||
"Technically the member function '" + classname + "::" + funcname + "' can be const.\n"
|
"Technically the member function '" + classname + "::" + funcname + "' can be const.\n"
|
||||||
"The member function '" + classname + "::" + funcname + "' can be made a const "
|
"The member function '" + classname + "::" + funcname + "' can be made a const "
|
||||||
"function. Making this function const function should not cause compiler errors. "
|
"function. Making this function const function should not cause compiler errors. "
|
||||||
"Even though the function can be made const function technically it may not make "
|
"Even though the function can be made const function technically it may not make "
|
||||||
"sense conceptually. Think about your design and task of the function first - is "
|
"sense conceptually. Think about your design and task of the function first - is "
|
||||||
"it a function that must not change object internal state?");
|
"it a function that must not change object internal state?");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckClass::checkConstError2(const Token *tok1, const Token *tok2, const std::string &classname, const std::string &funcname)
|
void CheckClass::checkConstError2(const Token *tok1, const Token *tok2, const std::string &classname, const std::string &funcname)
|
||||||
|
@ -1567,12 +1567,12 @@ void CheckClass::checkConstError2(const Token *tok1, const Token *tok2, const st
|
||||||
toks.push_back(tok1);
|
toks.push_back(tok1);
|
||||||
toks.push_back(tok2);
|
toks.push_back(tok2);
|
||||||
reportInconclusiveError(toks, Severity::style, "functionConst",
|
reportInconclusiveError(toks, Severity::style, "functionConst",
|
||||||
"Technically the member function '" + classname + "::" + funcname + "' can be const.\n"
|
"Technically the member function '" + classname + "::" + funcname + "' can be const.\n"
|
||||||
"The member function '" + classname + "::" + funcname + "' can be made a const "
|
"The member function '" + classname + "::" + funcname + "' can be made a const "
|
||||||
"function. Making this function const function should not cause compiler errors. "
|
"function. Making this function const function should not cause compiler errors. "
|
||||||
"Even though the function can be made const function technically it may not make "
|
"Even though the function can be made const function technically it may not make "
|
||||||
"sense conceptually. Think about your design and task of the function first - is "
|
"sense conceptually. Think about your design and task of the function first - is "
|
||||||
"it a function that must not change object internal state?");
|
"it a function that must not change object internal state?");
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
|
@ -8259,7 +8259,7 @@ void Tokenizer::eraseDeadCode(Token *begin, const Token *end)
|
||||||
if (!checklabel) {
|
if (!checklabel) {
|
||||||
if (!indentlabel) {
|
if (!indentlabel) {
|
||||||
//remove 'switch ( ... )'
|
//remove 'switch ( ... )'
|
||||||
Token *endround = tok->linkAt(2);
|
const Token *endround = tok->linkAt(2);
|
||||||
Token::eraseTokens(tok, endround->next());
|
Token::eraseTokens(tok, endround->next());
|
||||||
} else {
|
} else {
|
||||||
tok = tok->linkAt(2);
|
tok = tok->linkAt(2);
|
||||||
|
@ -8297,10 +8297,10 @@ void Tokenizer::eraseDeadCode(Token *begin, const Token *end)
|
||||||
if (indentswitch && indentlevel == indentcase)
|
if (indentswitch && indentlevel == indentcase)
|
||||||
--indentlevel;
|
--indentlevel;
|
||||||
if (indentlevel < indentcheck) {
|
if (indentlevel < indentcheck) {
|
||||||
Token *end2 = tok->next();
|
const Token *end2 = tok->next();
|
||||||
tok = tok->next()->link()->previous(); //return to initial '{'
|
tok = tok->next()->link()->previous(); //return to initial '{'
|
||||||
if (indentswitch && Token::simpleMatch(tok, ") {") && Token::Match(tok->link()->tokAt(-2), "[{};] switch ("))
|
if (indentswitch && Token::simpleMatch(tok, ") {") && Token::Match(tok->link()->tokAt(-2), "[{};] switch ("))
|
||||||
tok = tok->link()->tokAt(-2); //remove also 'switch ( ... )'
|
tok = tok->link()->tokAt(-2); //remove also 'switch ( ... )'
|
||||||
Token::eraseTokens(tok, end2->next());
|
Token::eraseTokens(tok, end2->next());
|
||||||
checklabel = false;
|
checklabel = false;
|
||||||
tokcheck = 0;
|
tokcheck = 0;
|
||||||
|
@ -8339,8 +8339,9 @@ void Tokenizer::eraseDeadCode(Token *begin, const Token *end)
|
||||||
indentlevel = indentcheck;
|
indentlevel = indentcheck;
|
||||||
} else {
|
} else {
|
||||||
if (indentswitch) {
|
if (indentswitch) {
|
||||||
//since the switch() instruction is removed, there's no sense to keep
|
//Before stopping the function, since the 'switch()'
|
||||||
//the case instructions. Remove them and leave out, if there are any.
|
//instruction is removed, there's no sense to keep the
|
||||||
|
//case instructions. Remove them, if there are any.
|
||||||
Token *tok2 = tok->tokAt(3);
|
Token *tok2 = tok->tokAt(3);
|
||||||
const Token *end2 = tokcheck->next()->link();
|
const Token *end2 = tokcheck->next()->link();
|
||||||
unsigned int indentlevel2 = indentlevel;
|
unsigned int indentlevel2 = indentlevel;
|
||||||
|
@ -8348,12 +8349,11 @@ void Tokenizer::eraseDeadCode(Token *begin, const Token *end)
|
||||||
if (Token::Match(tok2->next(), "{|[|(")) {
|
if (Token::Match(tok2->next(), "{|[|(")) {
|
||||||
tok2 = tok2->next()->link();
|
tok2 = tok2->next()->link();
|
||||||
} else if (Token::Match(tok2, "[{};] case %any% : ;") || Token::Match(tok2, "[{};] default : ;")) {
|
} else if (Token::Match(tok2, "[{};] case %any% : ;") || Token::Match(tok2, "[{};] default : ;")) {
|
||||||
Token::eraseTokens(tok2, tok2->tokAt(4 + (tok2->next()->str() == "case")));
|
const Token *end3 = tok2->tokAt(4 + (tok2->next()->str() == "case"));
|
||||||
|
Token::eraseTokens(tok2, end3);
|
||||||
if (Token::simpleMatch(tok2->previous(), "break ; break ;")) {
|
if (Token::simpleMatch(tok2->previous(), "break ; break ;")) {
|
||||||
tok2 = tok2->tokAt(-2);
|
|
||||||
tok2->deleteNext();
|
tok2->deleteNext();
|
||||||
tok2->deleteNext();
|
tok2->deleteNext();
|
||||||
tok2 = tok2->tokAt(2);
|
|
||||||
}
|
}
|
||||||
} else if (tok2->next()->str() == "}") {
|
} else if (tok2->next()->str() == "}") {
|
||||||
--indentlevel2;
|
--indentlevel2;
|
||||||
|
@ -8365,9 +8365,9 @@ void Tokenizer::eraseDeadCode(Token *begin, const Token *end)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break; //stop removing tokens, we arrived to the label
|
break; //stop removing tokens, we arrived to the label.
|
||||||
}
|
}
|
||||||
} else { //I don't need to keep anything different from '{|}|switch|case|default'
|
} else { //no need to keep the other strings, remove them.
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,8 +135,10 @@ public:
|
||||||
* - code outside the scope where the function is called;
|
* - code outside the scope where the function is called;
|
||||||
* - code after a change of scope caused by 'switch(...);'
|
* - code after a change of scope caused by 'switch(...);'
|
||||||
* instructions, like 'case %any%;' or 'default;'
|
* instructions, like 'case %any%;' or 'default;'
|
||||||
* Also, it preserves the 'switch' command if in a scope
|
* Also, if the dead code contains a 'switch' block
|
||||||
* created by a 'case|default' instruction there is a label.
|
* and inside it there's a label, the function removes all
|
||||||
|
* the 'switch(..)' tokens and every occurrence of 'case %any%; | default;'
|
||||||
|
* expression, such as the 'switch' block is reduced to a simple block.
|
||||||
*
|
*
|
||||||
* @param begin Tokens after this have a possibility to be erased.
|
* @param begin Tokens after this have a possibility to be erased.
|
||||||
* @param end Tokens before this have a possibility to be erased.
|
* @param end Tokens before this have a possibility to be erased.
|
||||||
|
|
Loading…
Reference in New Issue