tokenizer: simplify redundant paranthesis
This commit is contained in:
parent
9fb11bbfcc
commit
ca0f007ca4
|
@ -915,6 +915,7 @@ void Tokenizer::simplifyTokenList()
|
||||||
modified |= simplifyFunctionReturn();
|
modified |= simplifyFunctionReturn();
|
||||||
modified |= simplifyKnownVariables();
|
modified |= simplifyKnownVariables();
|
||||||
modified |= removeReduntantConditions();
|
modified |= removeReduntantConditions();
|
||||||
|
modified |= simplifyRedundantParanthesis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@ -1367,6 +1368,39 @@ bool Tokenizer::simplifyKnownVariables()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Tokenizer::simplifyRedundantParanthesis()
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||||
|
{
|
||||||
|
if (Token::simpleMatch(tok, "( ("))
|
||||||
|
{
|
||||||
|
int parlevel = 0;
|
||||||
|
for (Token *tok2 = tok; tok2; tok2 = tok2->next())
|
||||||
|
{
|
||||||
|
if (tok2->str() == "(")
|
||||||
|
++parlevel;
|
||||||
|
|
||||||
|
else if (tok2->str() == ")")
|
||||||
|
{
|
||||||
|
--parlevel;
|
||||||
|
if (parlevel == 1)
|
||||||
|
{
|
||||||
|
if (Token::simpleMatch(tok2, ") )"))
|
||||||
|
{
|
||||||
|
tok->deleteNext();
|
||||||
|
tok2->deleteNext();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
// Helper functions for handling the tokens list
|
// Helper functions for handling the tokens list
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
|
@ -127,12 +127,18 @@ private:
|
||||||
* A simplify function that replaces a variable with its value in cases
|
* A simplify function that replaces a variable with its value in cases
|
||||||
* when the value is known. e.g. "x=10; if(x)" => "x=10;if(10)"
|
* when the value is known. e.g. "x=10; if(x)" => "x=10;if(10)"
|
||||||
*
|
*
|
||||||
* @param token The token list to check and modify.
|
|
||||||
* @return true if modifications to token-list are done.
|
* @return true if modifications to token-list are done.
|
||||||
* false if no modifications are done.
|
* false if no modifications are done.
|
||||||
*/
|
*/
|
||||||
bool simplifyKnownVariables();
|
bool simplifyKnownVariables();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove redundant paranthesis: "((x))" => "(x)"
|
||||||
|
* @return true if modifications to token-list are done.
|
||||||
|
* false if no modifications are done.
|
||||||
|
*/
|
||||||
|
bool simplifyRedundantParanthesis();
|
||||||
|
|
||||||
void InsertTokens(Token *dest, Token *src, unsigned int n);
|
void InsertTokens(Token *dest, Token *src, unsigned int n);
|
||||||
|
|
||||||
Token *_tokensBack;
|
Token *_tokensBack;
|
||||||
|
|
|
@ -75,7 +75,7 @@ private:
|
||||||
|
|
||||||
// TODO TEST_CASE(simplify_function_parameters);
|
// TODO TEST_CASE(simplify_function_parameters);
|
||||||
|
|
||||||
// TODO TEST_CASE(reduce_redundant_paranthesis); // Ticket #61
|
TEST_CASE(reduce_redundant_paranthesis); // Ticket #61
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue