]> git.sur5r.net Git - cc65/blobdiff - src/ca65/repeat.c
More lineinfo usage.
[cc65] / src / ca65 / repeat.c
index b442c165f0a57e609abe0bf57984699db643ee4a..d433d31366b0a54a2df7ea0712a6b796d29091df 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000     Ullrich von Bassewitz                                        */
-/*              Wacholderweg 14                                              */
-/*              D-70597 Stuttgart                                            */
-/* EMail:       uz@musoftware.de                                             */
+/* (C) 2000-2011, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -33,6 +33,8 @@
 
 
 
+#include <string.h>
+
 /* common */
 #include "xmalloc.h"
 
@@ -61,31 +63,22 @@ static TokList* CollectRepeatTokens (void)
 
     /* Read the token list */
     unsigned Repeats = 0;
-    while (Repeats != 0 || Tok != TOK_ENDREP) {
+    while (Repeats != 0 || CurTok.Tok != TOK_ENDREP) {
 
        /* Check for end of input */
-               if (Tok == TOK_EOF) {
-           Error (ERR_UNEXPECTED_EOF);
+               if (CurTok.Tok == TOK_EOF) {
+           Error ("Unexpected end of file");
            FreeTokList (List);
            return 0;
        }
 
-       /* If we find a token that is equal to the repeat counter name,
-        * replace it by a REPCOUNTER token. This way we have to do strcmps
-        * only once for each identifier, and not for each expansion.
-        * Note: This will fail for nested repeats using the same repeat
-        * counter name, but
-        */
-
-
-
                /* Collect all tokens in the list */
        AddCurTok (List);
 
        /* Check for and count nested .REPEATs */
-       if (Tok == TOK_REPEAT) {
+       if (CurTok.Tok == TOK_REPEAT) {
            ++Repeats;
-       } else if (Tok == TOK_ENDREP) {
+       } else if (CurTok.Tok == TOK_ENDREP) {
            --Repeats;
        }
 
@@ -106,11 +99,13 @@ static void RepeatTokenCheck (TokList* L)
 /* Called each time a token from a repeat token list is set. Is used to check
  * for and replace identifiers that are the repeat counter.
  */
-{                
-    if (Tok == TOK_IDENT && L->Data != 0 && strcmp (SVal, L->Data) == 0) {
-       /* Must replace by the repeat counter */
-       Tok  = TOK_INTCON;
-       IVal = L->RepCount;
+{
+    if (CurTok.Tok == TOK_IDENT &&
+        L->Data != 0            &&
+        SB_CompareStr (&CurTok.SVal, L->Data) == 0) {
+       /* Must replace by the repeat counter */
+       CurTok.Tok  = TOK_INTCON;
+       CurTok.IVal = L->RepCount;
     }
 }
 
@@ -125,28 +120,30 @@ void ParseRepeat (void)
     /* Repeat count follows */
     long RepCount = ConstExpression ();
     if (RepCount < 0) {
-       Error (ERR_RANGE);
-       RepCount = 0;
+       Error ("Range error");
+       RepCount = 0;
     }
 
     /* Optional there is a comma and a counter variable */
     Name = 0;
-    if (Tok == TOK_COMMA) {
+    if (CurTok.Tok == TOK_COMMA) {
 
                /* Skip the comma */
                NextTok ();
 
                /* Check for an identifier */
-               if (Tok != TOK_IDENT) {
-                   ErrorSkip (ERR_IDENT_EXPECTED);
+               if (CurTok.Tok != TOK_IDENT) {
+                   ErrorSkip ("Identifier expected");
                } else {
                    /* Remember the name and skip it */
-                   Name = xstrdup (SVal);
+            SB_Terminate (&CurTok.SVal);
+                   Name = xstrdup (SB_GetConstBuf (&CurTok.SVal));
                    NextTok ();
                }
     }
 
-    /* Separator */
+    /* Switch to raw token mode, then skip the separator */
+    EnterRawTokenMode ();
     ConsumeSep ();
 
     /* Read the token list */
@@ -154,8 +151,8 @@ void ParseRepeat (void)
 
     /* If we had an error, bail out */
     if (List == 0) {
-       xfree (Name);
-               return;
+       xfree (Name);
+               goto Done;
     }
 
     /* Update the token list for replay */
@@ -168,11 +165,15 @@ void ParseRepeat (void)
      */
     if (List->Count == 0 || RepCount == 0) {
        FreeTokList (List);
-       return;
+       goto Done;
     }
 
     /* Read input from the repeat descriptor */
     PushTokList (List, ".REPEAT");
+
+Done:
+    /* Switch out of raw token mode */
+    LeaveRawTokenMode ();
 }