token : fixed so that TOKEN::_previous is updated when deleting tokens

This commit is contained in:
Daniel Marjamäki 2008-12-17 19:20:11 +00:00
parent a19b938665
commit dd853f0d59
3 changed files with 5 additions and 14 deletions

View File

@ -74,6 +74,8 @@ void TOKEN::deleteNext()
TOKEN *n = _next; TOKEN *n = _next;
_next = n->next(); _next = n->next();
delete n; delete n;
if (_next)
_next->previous(this);
} }
const TOKEN *TOKEN::tokAt(int index) const const TOKEN *TOKEN::tokAt(int index) const
@ -389,19 +391,10 @@ void TOKEN::eraseTokens( TOKEN *begin, const TOKEN *end )
while ( begin->next() && begin->next() != end ) while ( begin->next() && begin->next() != end )
{ {
begin->eraseToken(); begin->deleteNext();
} }
} }
void TOKEN::eraseToken()
{
TOKEN *next = this->next();
this->next( next->next() );
if ( next->next() )
next->next()->previous( this );
delete next;
}
unsigned int TOKEN::fileIndex() const unsigned int TOKEN::fileIndex() const
{ {
return _fileIndex; return _fileIndex;

View File

@ -134,8 +134,6 @@ public:
*/ */
static void eraseTokens( TOKEN *begin, const TOKEN *end ); static void eraseTokens( TOKEN *begin, const TOKEN *end );
void eraseToken();
/** /**
* Insert new token after this token. This function will handle * Insert new token after this token. This function will handle
* relations between next and previous token also. * relations between next and previous token also.

View File

@ -584,7 +584,7 @@ void Tokenizer::tokenizeCode(std::istream &code, const unsigned int FileIndex)
bool last = TOKEN::Match( tok->next(), "}" ); bool last = TOKEN::Match( tok->next(), "}" );
// Unlink and delete tok->next() // Unlink and delete tok->next()
tok->eraseToken(); tok->deleteNext();
// break if this was the last token to delete.. // break if this was the last token to delete..
if (last) if (last)