tokenize: bug fixes. Handling typedefs.

This commit is contained in:
Daniel Marjamäki 2007-06-03 17:08:30 +00:00
parent 2ebf2dd530
commit 7a8ee64068
1 changed files with 33 additions and 3 deletions

View File

@ -562,8 +562,18 @@ void SimplifyTokenList()
{ {
if (strcmp(tok2->str,"typedef")==0) if (strcmp(tok2->str,"typedef")==0)
{ {
while (tok2->next->str[0] != ';') int parlevel = 0;
while (parlevel > 0 || tok2->next->str[0] != ';')
{
if (tok2->str[0] == '{')
parlevel++;
else if (tok2->str[0] == '}')
parlevel--;
tok2 = tok2->next; tok2 = tok2->next;
if (!tok2->next)
break;
}
continue; continue;
} }
@ -580,12 +590,23 @@ void SimplifyTokenList()
// Delete typedef.. // Delete typedef..
if (!prev) if (!prev)
{ {
while ( tokens && tokens->str[0] != ';' ) int parlevel = 0;
while ( parlevel > 0 || tokens->str[0] != ';' )
{ {
if ( strchr( "({", tokens->str[0] ) )
parlevel++;
else if ( strchr( ")}", tokens->str[0] ) )
parlevel--;
// Delete the first element in the tokens list.
TOKEN *next = tokens->next; TOKEN *next = tokens->next;
free(tokens->str); free(tokens->str);
delete tokens; delete tokens;
tokens = next; tokens = next;
if (!tokens)
break;
} }
tok = tokens; tok = tokens;
prev = NULL; prev = NULL;
@ -593,8 +614,17 @@ void SimplifyTokenList()
} }
else else
{ {
while ( prev->next->str[0] != ';' ) int parlevel = 0;
while ( parlevel > 0 || prev->next->str[0] != ';' )
{
if ( strchr( "({", prev->next->str[0] ) )
parlevel++;
else if ( strchr( ")}", prev->next->str[0] ) )
parlevel--;
DeleteNextToken(prev); DeleteNextToken(prev);
if (!prev->next)
break;
}
tok = prev; tok = prev;
} }
} }