Improve creation of link() for Token class. Tokenizer::simplifyTokenList() should now return

code where Token::link() actually works.
This commit is contained in:
Reijo Tomperi 2009-03-15 01:39:45 +02:00
parent 6eadbaae04
commit c385b3e045
3 changed files with 27 additions and 5 deletions

View File

@ -725,11 +725,16 @@ void Tokenizer::simplifyNamespaces()
}
}
void Tokenizer::simplifyTokenList()
bool Tokenizer::createLinks()
{
std::list<Token*> links;
for (Token *token = _tokens; token; token = token->next())
{
if (token->link())
{
token->link(0);
}
if (token->str() == "{")
{
links.push_back(token);
@ -739,7 +744,7 @@ void Tokenizer::simplifyTokenList()
if (links.size() == 0)
{
// Error, { and } don't match.
break;
return false;
}
token->link(links.back());
@ -751,8 +756,15 @@ void Tokenizer::simplifyTokenList()
if (links.size() > 0)
{
// Error, { and } don't match.
return false;
}
return true;
}
void Tokenizer::simplifyTokenList()
{
createLinks();
simplifyNamespaces();
@ -1240,6 +1252,8 @@ void Tokenizer::simplifyTokenList()
modified |= simplifyRedundantParanthesis();
modified |= simplifyCalculations();
}
createLinks();
}
//---------------------------------------------------------------------------

View File

@ -176,6 +176,14 @@ private:
void InsertTokens(Token *dest, Token *src, unsigned int n);
/**
* Setup links for tokens so that one can call Token::link().
*
* @return false if there was a mismatch with tokens, this
* should mean that source code was not valid.
*/
bool createLinks();
Token *_tokensBack;
std::map<std::string, unsigned int> _typeSize;
std::vector<std::string> _files;