]> git.sur5r.net Git - cc65/blobdiff - src/cc65/goto.c
Made the code that logs indirect-goto referals be a little more efficient.
[cc65] / src / cc65 / goto.c
index 1b99a98030c3ecc20fa5aece05e3bf4a9a894894..10293642f6ba11b45e97d0a663b47f8ea2306524 100644 (file)
@@ -79,7 +79,6 @@ void GotoStatement (void)
         ExprDesc desc;
         CodeEntry *E;
         unsigned char val;
-        unsigned I;
 
         NextToken ();
 
@@ -87,15 +86,18 @@ void GotoStatement (void)
         if (CurTok.Tok == TOK_IDENT &&
             (arr = FindSym (CurTok.Ident))) {
             NextToken ();
-            ConsumeLBrack ();
 
             /* Find array size */
-            if (!IsTypeArray(arr->Type) || SizeOf(arr->Type) == 0 ||
-                SizeOf(GetElementType(arr->Type)) != 2)
-                Error ("Expected array");
-            if (GetElementCount(arr->Type) > 127)
+            if (!IsTypeArray (arr->Type) || SizeOf (arr->Type) == 0 ||
+                !(arr->Flags & SC_STATIC) ||
+                SizeOf (GetElementType(arr->Type)) != 2) {
+                Error ("Expected a static array");
+            } else if (GetElementCount (arr->Type) > 127) {
                 Error ("Only arrays with <= 127 labels are supported, got %lu",
-                       GetElementCount(arr->Type));
+                       GetElementCount (arr->Type));
+            }
+
+            ConsumeLBrack ();
 
             if (CurTok.Tok == TOK_ICONST) {
                 val = CurTok.IVal;
@@ -132,25 +134,25 @@ void GotoStatement (void)
             ConsumeRBrack ();
 
             /* Loop over all target labels, specifying this as a jump point.
-            ** It's not exact - if there's multiple gotos, the last will be used,
-            ** but it's only needed so the optimizer does not remove the labels.
+            ** It's not exact -- if there's multiple gotos, the last will be used;
+            ** but, it's needed only so the optimizer does not remove the labels.
             */
-            I = CS_GetEntryCount (CS->Code) - 1;
-            E = CS_GetEntry (CS->Code, I);
-
+            E = CS_GetEntry (CS->Code, CS_GetEntryCount (CS->Code) - 1);
             tab = GetLabelSymTab ();
             if (tab) {
                 cur = tab->SymHead;
                 while (cur) {
-                    if ((cur->Flags & (SC_LABEL|SC_GOTO_IND)) == (SC_LABEL|SC_GOTO_IND)) {
+                    if ((cur->Flags & SC_GOTO_IND) != 0) {
                         cur->V.L.IndJumpFrom = E;
                     }
                     cur = cur->NextSym;
                 }
             }
+        } else {
+            /* It was not TOK_IDENT, or we couldn't find the symbol */
+            Error ("Array name expected");
         }
     } else {
-
         Error ("Label name expected");
     }
 }
@@ -165,6 +167,7 @@ void DoLabel (void)
 
     /* Emit the jump label */
     CodeLabel* L = CS_AddLabel (CS->Code, LocalLabelName (Entry->V.L.Label));
+
     if (Entry->V.L.IndJumpFrom) {
         CollAppend (&L->JumpFrom, Entry->V.L.IndJumpFrom);
     }