Permalink
Browse files

Fix variable initialisation problem in objc parser, causing erroneous

parsing of second file.

Patch sent by Lars C. Hassing
  • Loading branch information...
1 parent 1ad6faf commit 7704abc3bbf9d88fa3060f14f77629458eb32d26 Vincent Berthoux committed Sep 17, 2012
Showing with 36 additions and 29 deletions.
  1. +36 −29 objc.c
View
65 objc.c
@@ -508,30 +508,30 @@ static void tillTokenOrFallBack (vString * const UNUSED (ident), objcToken what)
}
}
+static int ignoreBalanced_count = 0;
static void ignoreBalanced (vString * const UNUSED (ident), objcToken what)
{
- static int count = 0;
switch (what)
{
case Tok_PARL:
case Tok_CurlL:
case Tok_SQUAREL:
- count++;
+ ignoreBalanced_count++;
break;
case Tok_PARR:
case Tok_CurlR:
case Tok_SQUARER:
- count--;
+ ignoreBalanced_count--;
break;
default:
/* don't care */
break;
}
- if (count == 0)
+ if (ignoreBalanced_count == 0)
toDoNext = comeAfter;
}
@@ -818,22 +818,21 @@ static void parseStructMembers (vString * const ident, objcToken what)
}
/* Called just after the struct keyword */
+static boolean parseStruct_gotName = FALSE;
static void parseStruct (vString * const ident, objcToken what)
{
- static boolean gotName = FALSE;
-
switch (what)
{
case ObjcIDENTIFIER:
- if (!gotName)
+ if (!parseStruct_gotName)
{
addTag (ident, K_STRUCT);
pushEnclosingContext (ident, K_STRUCT);
- gotName = TRUE;
+ parseStruct_gotName = TRUE;
}
else
{
- gotName = FALSE;
+ parseStruct_gotName = FALSE;
popEnclosingContext ();
toDoNext = comeAfter;
comeAfter (ident, what);
@@ -847,7 +846,7 @@ static void parseStruct (vString * const ident, objcToken what)
/* maybe it was just a forward declaration
* in which case, we pop the context */
case Tok_semi:
- if (gotName)
+ if (parseStruct_gotName)
popEnclosingContext ();
toDoNext = comeAfter;
@@ -861,21 +860,20 @@ static void parseStruct (vString * const ident, objcToken what)
}
/* Parse enumeration members, ignoring potential initialization */
+static parseNext parseEnumFields_prev = NULL;
static void parseEnumFields (vString * const ident, objcToken what)
{
- static parseNext prev = NULL;
-
- if (prev != NULL)
+ if (parseEnumFields_prev != NULL)
{
- comeAfter = prev;
- prev = NULL;
+ comeAfter = parseEnumFields_prev;
+ parseEnumFields_prev = NULL;
}
switch (what)
{
case ObjcIDENTIFIER:
addTag (ident, K_ENUM);
- prev = comeAfter;
+ parseEnumFields_prev = comeAfter;
waitedToken = Tok_COMA;
/* last item might not have a coma */
fallBackToken = Tok_CurlR;
@@ -896,22 +894,21 @@ static void parseEnumFields (vString * const ident, objcToken what)
}
/* parse enum ... { ... */
+static boolean parseEnum_named = FALSE;
static void parseEnum (vString * const ident, objcToken what)
{
- static boolean named = FALSE;
-
switch (what)
{
case ObjcIDENTIFIER:
- if (!named)
+ if (!parseEnum_named)
{
addTag (ident, K_ENUM);
pushEnclosingContext (ident, K_ENUM);
- named = TRUE;
+ parseEnum_named = TRUE;
}
else
{
- named = FALSE;
+ parseEnum_named = FALSE;
popEnclosingContext ();
toDoNext = comeAfter;
comeAfter (ident, what);
@@ -920,11 +917,11 @@ static void parseEnum (vString * const ident, objcToken what)
case Tok_CurlL: /* '{' */
toDoNext = &parseEnumFields;
- named = FALSE;
+ parseEnum_named = FALSE;
break;
case Tok_semi: /* ';' */
- if (named)
+ if (parseEnum_named)
popEnclosingContext ();
toDoNext = comeAfter;
comeAfter (ident, what);
@@ -971,20 +968,19 @@ static void parseTypedef (vString * const ident, objcToken what)
}
}
+static boolean ignorePreprocStuff_escaped = FALSE;
static void ignorePreprocStuff (vString * const UNUSED (ident), objcToken what)
{
- static boolean escaped = FALSE;
-
switch (what)
{
case Tok_Backslash:
- escaped = TRUE;
+ ignorePreprocStuff_escaped = TRUE;
break;
case Tok_EOL:
- if (escaped)
+ if (ignorePreprocStuff_escaped)
{
- escaped = FALSE;
+ ignorePreprocStuff_escaped = FALSE;
}
else
{
@@ -993,7 +989,7 @@ static void ignorePreprocStuff (vString * const UNUSED (ident), objcToken what)
break;
default:
- escaped = FALSE;
+ ignorePreprocStuff_escaped = FALSE;
break;
}
}
@@ -1102,6 +1098,17 @@ static void findObjcTags (void)
fullMethodName = vStringNew ();
prevIdent = vStringNew ();
+ /* (Re-)initialize state variables, this might be a second file */
+ comeAfter = NULL;
+ fallback = NULL;
+ parentType = K_INTERFACE;
+ ignoreBalanced_count = 0;
+ methodKind = 0;
+ parseStruct_gotName = FALSE;
+ parseEnumFields_prev = NULL;
+ parseEnum_named = FALSE;
+ ignorePreprocStuff_escaped = FALSE;
+
st.name = vStringNew ();
st.cp = fileReadLine ();
toDoNext = &globalScope;

0 comments on commit 7704abc

Please sign in to comment.