Tokenizer::simplifyKnownVariables: Broke out the simplification into a separate function

This commit is contained in:
Daniel Marjamäki 2011-02-11 20:12:51 +01:00
parent eddbfbee1e
commit 951a81d0d2
2 changed files with 407 additions and 393 deletions

View File

@ -6297,8 +6297,23 @@ bool Tokenizer::simplifyKnownVariables()
tok3 = tok2->next(); tok3 = tok2->next();
} }
ret |= simplifyKnownVariablesSimplify(&tok2, tok3, varid, structname, value, valueVarId, valueIsPointer, pointeralias, indentlevel);
}
}
if (tok2)
tok = tok2->previous();
}
return ret;
}
bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsigned int varid, const std::string &structname, std::string &value, unsigned int valueVarId, bool valueIsPointer, bool pointeralias, int indentlevel)
{
bool ret = false;;
Token* bailOutFromLoop = 0; Token* bailOutFromLoop = 0;
int indentlevel3 = indentlevel; // indentlevel for tok3 int indentlevel3 = indentlevel;
bool ret3 = false; bool ret3 = false;
for (; tok3; tok3 = tok3->next()) for (; tok3; tok3 = tok3->next())
{ {
@ -6311,11 +6326,11 @@ bool Tokenizer::simplifyKnownVariables()
--indentlevel3; --indentlevel3;
if (indentlevel3 < indentlevel) if (indentlevel3 < indentlevel)
{ {
if (Token::Match(tok2->tokAt(-7), "%type% * %var% ; %var% = & %var% ;") && if (Token::Match((*tok2)->tokAt(-7), "%type% * %var% ; %var% = & %var% ;") &&
tok2->tokAt(-5)->str() == tok2->tokAt(-3)->str()) (*tok2)->tokAt(-5)->str() == (*tok2)->tokAt(-3)->str())
{ {
tok2 = tok2->tokAt(-4); (*tok2) = (*tok2)->tokAt(-4);
Token::eraseTokens(tok2, tok2->tokAt(5)); Token::eraseTokens((*tok2), (*tok2)->tokAt(5));
} }
break; break;
} }
@ -6647,10 +6662,10 @@ bool Tokenizer::simplifyKnownVariables()
tok3->deleteNext(); tok3->deleteNext();
} }
incdec(value, op); incdec(value, op);
if (!Token::simpleMatch(tok2->tokAt(-2), "for (")) if (!Token::simpleMatch((*tok2)->tokAt(-2), "for ("))
{ {
tok2->tokAt(2)->str(value); (*tok2)->tokAt(2)->str(value);
tok2->tokAt(2)->varId(valueVarId); (*tok2)->tokAt(2)->varId(valueVarId);
} }
ret = true; ret = true;
} }
@ -6659,8 +6674,8 @@ bool Tokenizer::simplifyKnownVariables()
!Token::Match(tok3->tokAt(3), "[.[]")) !Token::Match(tok3->tokAt(3), "[.[]"))
{ {
incdec(value, tok3->strAt(1)); incdec(value, tok3->strAt(1));
tok2->tokAt(2)->str(value); (*tok2)->tokAt(2)->str(value);
tok2->tokAt(2)->varId(valueVarId); (*tok2)->tokAt(2)->varId(valueVarId);
if (Token::Match(tok3, "[;{}] %any% %any% ;")) if (Token::Match(tok3, "[;{}] %any% %any% ;"))
{ {
Token::eraseTokens(tok3, tok3->tokAt(3)); Token::eraseTokens(tok3, tok3->tokAt(3));
@ -6690,13 +6705,6 @@ bool Tokenizer::simplifyKnownVariables()
tok3->next()->varId(valueVarId); tok3->next()->varId(valueVarId);
} }
} }
}
}
if (tok2)
tok = tok2->previous();
}
return ret; return ret;
} }

View File

@ -308,6 +308,12 @@ public:
*/ */
bool simplifyKnownVariables(); bool simplifyKnownVariables();
/**
* utility function for simplifyKnownVariables. Perform simplification
* of a given variable
*/
bool simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsigned int varid, const std::string &structname, std::string &value, unsigned int valueVarId, bool valueIsPointer, bool pointeralias, int indentlevel);
/** Replace a "goto" with the statements */ /** Replace a "goto" with the statements */
void simplifyGoto(); void simplifyGoto();