]> 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 fde9df94595bf4ffc652ba2f51cd7b14f2a61703..10293642f6ba11b45e97d0a663b47f8ea2306524 100644 (file)
@@ -79,7 +79,6 @@ void GotoStatement (void)
         ExprDesc desc;
         CodeEntry *E;
         unsigned char val;
-        unsigned I;
 
         NextToken ();
 
@@ -90,14 +89,12 @@ void GotoStatement (void)
 
             /* Find array size */
             if (!IsTypeArray (arr->Type) || SizeOf (arr->Type) == 0 ||
+                !(arr->Flags & SC_STATIC) ||
                 SizeOf (GetElementType(arr->Type)) != 2) {
-                Error ("Expected array");
-                return;
-            }
-            if (GetElementCount (arr->Type) > 127) {
+                Error ("Expected a static array");
+            } else if (GetElementCount (arr->Type) > 127) {
                 Error ("Only arrays with <= 127 labels are supported, got %lu",
                        GetElementCount (arr->Type));
-                return;
             }
 
             ConsumeLBrack ();
@@ -137,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");
     }
 }
@@ -170,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);
     }