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:
Edoardo Prezioso 2011-11-20 19:01:31 +01:00
parent d0d5a2fcd8
commit 6889a28d31
3 changed files with 27 additions and 25 deletions

View File

@ -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)
{
reportInconclusiveError(tok, Severity::style, "functionConst",
"Technically the member function '" + classname + "::" + funcname + "' can be const.\n"
"The member function '" + classname + "::" + funcname + "' can be made a const "
"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 "
"sense conceptually. Think about your design and task of the function first - is "
"it a function that must not change object internal state?");
"Technically the member function '" + classname + "::" + funcname + "' can be const.\n"
"The member function '" + classname + "::" + funcname + "' can be made a const "
"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 "
"sense conceptually. Think about your design and task of the function first - is "
"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)
@ -1567,12 +1567,12 @@ void CheckClass::checkConstError2(const Token *tok1, const Token *tok2, const st
toks.push_back(tok1);
toks.push_back(tok2);
reportInconclusiveError(toks, Severity::style, "functionConst",
"Technically the member function '" + classname + "::" + funcname + "' can be const.\n"
"The member function '" + classname + "::" + funcname + "' can be made a const "
"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 "
"sense conceptually. Think about your design and task of the function first - is "
"it a function that must not change object internal state?");
"Technically the member function '" + classname + "::" + funcname + "' can be const.\n"
"The member function '" + classname + "::" + funcname + "' can be made a const "
"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 "
"sense conceptually. Think about your design and task of the function first - is "
"it a function that must not change object internal state?");
}
//---------------------------------------------------------------------------

View File

@ -8259,7 +8259,7 @@ void Tokenizer::eraseDeadCode(Token *begin, const Token *end)
if (!checklabel) {
if (!indentlabel) {
//remove 'switch ( ... )'
Token *endround = tok->linkAt(2);
const Token *endround = tok->linkAt(2);
Token::eraseTokens(tok, endround->next());
} else {
tok = tok->linkAt(2);
@ -8297,10 +8297,10 @@ void Tokenizer::eraseDeadCode(Token *begin, const Token *end)
if (indentswitch && indentlevel == indentcase)
--indentlevel;
if (indentlevel < indentcheck) {
Token *end2 = tok->next();
tok = tok->next()->link()->previous(); //return to initial '{'
const Token *end2 = tok->next();
tok = tok->next()->link()->previous(); //return to initial '{'
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());
checklabel = false;
tokcheck = 0;
@ -8339,8 +8339,9 @@ void Tokenizer::eraseDeadCode(Token *begin, const Token *end)
indentlevel = indentcheck;
} else {
if (indentswitch) {
//since the switch() instruction is removed, there's no sense to keep
//the case instructions. Remove them and leave out, if there are any.
//Before stopping the function, since the 'switch()'
//instruction is removed, there's no sense to keep the
//case instructions. Remove them, if there are any.
Token *tok2 = tok->tokAt(3);
const Token *end2 = tokcheck->next()->link();
unsigned int indentlevel2 = indentlevel;
@ -8348,12 +8349,11 @@ void Tokenizer::eraseDeadCode(Token *begin, const Token *end)
if (Token::Match(tok2->next(), "{|[|(")) {
tok2 = tok2->next()->link();
} 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 ;")) {
tok2 = tok2->tokAt(-2);
tok2->deleteNext();
tok2->deleteNext();
tok2 = tok2->tokAt(2);
}
} else if (tok2->next()->str() == "}") {
--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();
}
}

View File

@ -135,8 +135,10 @@ public:
* - code outside the scope where the function is called;
* - code after a change of scope caused by 'switch(...);'
* instructions, like 'case %any%;' or 'default;'
* Also, it preserves the 'switch' command if in a scope
* created by a 'case|default' instruction there is a label.
* Also, if the dead code contains a 'switch' block
* 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 end Tokens before this have a possibility to be erased.