From 7a8ee64068cbce7b2a992aa91da770b051c5af35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 3 Jun 2007 17:08:30 +0000 Subject: [PATCH] tokenize: bug fixes. Handling typedefs. --- tokenize.cpp | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/tokenize.cpp b/tokenize.cpp index cf566ed2e..96f1b7c9f 100644 --- a/tokenize.cpp +++ b/tokenize.cpp @@ -562,8 +562,18 @@ void SimplifyTokenList() { 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; + if (!tok2->next) + break; + } continue; } @@ -580,12 +590,23 @@ void SimplifyTokenList() // Delete typedef.. 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; free(tokens->str); delete tokens; tokens = next; + + + if (!tokens) + break; } tok = tokens; prev = NULL; @@ -593,8 +614,17 @@ void SimplifyTokenList() } 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); + if (!prev->next) + break; + } tok = prev; } }