Refactoring: Remove findClosing(). It is replaced by Token::link().
This commit is contained in:
parent
6901bcae79
commit
50d9bc78ef
|
@ -1918,34 +1918,6 @@ void Tokenizer::simplifyTokenList()
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
const Token *Tokenizer::findClosing(const Token *tok, const char *start, const char *end)
|
|
||||||
{
|
|
||||||
if (!tok)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
// Find the closing "}"
|
|
||||||
int indentLevel = 0;
|
|
||||||
for (const Token *closing = tok->next(); closing; closing = closing->next())
|
|
||||||
{
|
|
||||||
if (closing->str() == start)
|
|
||||||
{
|
|
||||||
++indentLevel;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (closing->str() == end)
|
|
||||||
--indentLevel;
|
|
||||||
|
|
||||||
if (indentLevel >= 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Closing } is found.
|
|
||||||
return closing;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Tokenizer::removeReduntantConditions()
|
bool Tokenizer::removeReduntantConditions()
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
@ -1962,9 +1934,7 @@ bool Tokenizer::removeReduntantConditions()
|
||||||
const Token *elseTag = 0;
|
const Token *elseTag = 0;
|
||||||
|
|
||||||
// Find the closing "}"
|
// Find the closing "}"
|
||||||
elseTag = Tokenizer::findClosing(tok->tokAt(4), "{", "}");
|
elseTag = tok->tokAt(4)->link()->next();
|
||||||
if (elseTag)
|
|
||||||
elseTag = elseTag->next();
|
|
||||||
|
|
||||||
bool boolValue = false;
|
bool boolValue = false;
|
||||||
if (tok->tokAt(2)->str() == "true")
|
if (tok->tokAt(2)->str() == "true")
|
||||||
|
@ -1973,7 +1943,7 @@ bool Tokenizer::removeReduntantConditions()
|
||||||
// Handle if with else
|
// Handle if with else
|
||||||
if (elseTag && elseTag->str() == "else")
|
if (elseTag && elseTag->str() == "else")
|
||||||
{
|
{
|
||||||
if (elseTag->next()->str() == "if")
|
if (Token::simpleMatch(elseTag->next(), "if ("))
|
||||||
{
|
{
|
||||||
// Handle "else if"
|
// Handle "else if"
|
||||||
if (boolValue == false)
|
if (boolValue == false)
|
||||||
|
@ -1990,13 +1960,11 @@ bool Tokenizer::removeReduntantConditions()
|
||||||
{
|
{
|
||||||
if (lastTagInIf->str() == "(")
|
if (lastTagInIf->str() == "(")
|
||||||
{
|
{
|
||||||
lastTagInIf = Tokenizer::findClosing(lastTagInIf, "(", ")");
|
lastTagInIf = lastTagInIf->link()->next();
|
||||||
lastTagInIf = lastTagInIf->next();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lastTagInIf = Tokenizer::findClosing(lastTagInIf, "{", "}");
|
lastTagInIf = lastTagInIf->link()->next();
|
||||||
lastTagInIf = lastTagInIf->next();
|
if (!Token::simpleMatch(lastTagInIf, "else"))
|
||||||
if (lastTagInIf->str() != "else")
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
lastTagInIf = lastTagInIf->next();
|
lastTagInIf = lastTagInIf->next();
|
||||||
|
@ -2026,12 +1994,7 @@ bool Tokenizer::removeReduntantConditions()
|
||||||
if (elseTag->tokAt(1)->str() == "{")
|
if (elseTag->tokAt(1)->str() == "{")
|
||||||
{
|
{
|
||||||
// Convert "if( true ) {aaa;} else {bbb;}" => "{aaa;}"
|
// Convert "if( true ) {aaa;} else {bbb;}" => "{aaa;}"
|
||||||
const Token *end = Tokenizer::findClosing(elseTag->tokAt(1), "{", "}");
|
const Token *end = elseTag->tokAt(1)->link();
|
||||||
if (!end)
|
|
||||||
{
|
|
||||||
// Possibly syntax error in code
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove the "else { aaa; }"
|
// Remove the "else { aaa; }"
|
||||||
Token::eraseTokens(elseTag->previous(), end->tokAt(1));
|
Token::eraseTokens(elseTag->previous(), end->tokAt(1));
|
||||||
|
|
|
@ -221,15 +221,6 @@ private:
|
||||||
|
|
||||||
std::vector<const Token *> _functionList;
|
std::vector<const Token *> _functionList;
|
||||||
|
|
||||||
/**
|
|
||||||
* Finds matching "end" for "start".
|
|
||||||
* @param tok The start tag
|
|
||||||
* @param start e.g. "{"
|
|
||||||
* @param end e.g. "}"
|
|
||||||
* @return The end tag that matches given parameter or 0 if not found.
|
|
||||||
*/
|
|
||||||
static const Token *findClosing(const Token *tok, const char *start, const char *end);
|
|
||||||
|
|
||||||
void addtoken(const char str[], const unsigned int lineno, const unsigned int fileno);
|
void addtoken(const char str[], const unsigned int lineno, const unsigned int fileno);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue