]> git.sur5r.net Git - cc65/blobdiff - src/ca65/nexttok.c
Renamed variables for better readability.
[cc65] / src / ca65 / nexttok.c
index 5aa3d0217a0da4ab00074933572a83effca35adf..dab0697f94d5902c6272ed1908ed0040a25013ab 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000-2010, Ullrich von Bassewitz                                      */
+/* (C) 2000-2011, Ullrich von Bassewitz                                      */
 /*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
@@ -42,6 +42,7 @@
 #include "strbuf.h"
 
 /* ca65 */
+#include "condasm.h"
 #include "error.h"
 #include "expr.h"
 #include "global.h"
@@ -73,7 +74,7 @@ static int LookAtStrCon (void)
  * true.
  */
 {
-    if (Tok != TOK_STRCON) {
+    if (CurTok.Tok != TOK_STRCON) {
         Error ("String constant expected");
         SkipUntilSep ();
         return 0;
@@ -102,14 +103,14 @@ static TokList* CollectTokens (unsigned Start, unsigned Count)
     TokList* List = NewTokList ();
 
     /* Determine if the list is enclosed in curly braces. */
-    Token Term = GetTokListTerm (TOK_RPAREN);
+    token_t Term = GetTokListTerm (TOK_RPAREN);
 
     /* Read the token list */
     unsigned Current = 0;
-    while (Tok != Term) {
+    while (CurTok.Tok != Term) {
 
        /* Check for end of line or end of input */
-       if (TokIsSep (Tok)) {
+       if (TokIsSep (CurTok.Tok)) {
            Error ("Unexpected end of line");
            return List;
        }
@@ -160,13 +161,13 @@ static void FuncConcat (void)
        }
 
         /* Append the string */
-        SB_Append (&Buf, &SVal);
+        SB_Append (&Buf, &CurTok.SVal);
 
        /* Skip the string token */
        NextTok ();
 
        /* Comma means another argument */
-       if (Tok == TOK_COMMA) {
+       if (CurTok.Tok == TOK_COMMA) {
            NextTok ();
        } else {
            /* Done */
@@ -177,11 +178,12 @@ static void FuncConcat (void)
     /* We expect a closing parenthesis, but will not skip it but replace it
      * by the string token just created.
      */
-    if (Tok != TOK_RPAREN) {
+    if (CurTok.Tok != TOK_RPAREN) {
        Error ("`)' expected");
     } else {
-       Tok = TOK_STRCON;
-       SB_Copy (&SVal, &Buf);
+       CurTok.Tok = TOK_STRCON;
+       SB_Copy (&CurTok.SVal, &Buf);
+        SB_Terminate (&CurTok.SVal);
     }
 
     /* Free the string buffer */
@@ -203,7 +205,7 @@ static void FuncIdent (void)
 /* Handle the .IDENT function */
 {
     StrBuf    Buf = STATIC_STRBUF_INITIALIZER;
-    Token     Id;
+    token_t   Id;
     unsigned  I;
 
     /* Skip it */
@@ -220,23 +222,23 @@ static void FuncIdent (void)
     /* Check that the string contains a valid identifier. While doing so,
      * determine if it is a cheap local, or global one.
      */
-    SB_Reset (&SVal);
+    SB_Reset (&CurTok.SVal);
 
     /* Check for a cheap local symbol */
-    if (SB_Peek (&SVal) == LocalStart) {
-        SB_Skip (&SVal);
+    if (SB_Peek (&CurTok.SVal) == LocalStart) {
+        SB_Skip (&CurTok.SVal);
         Id = TOK_LOCAL_IDENT;
     } else {
         Id = TOK_IDENT;
     }
 
     /* Next character must be a valid identifier start */
-    if (!IsIdStart (SB_Get (&SVal))) {
+    if (!IsIdStart (SB_Get (&CurTok.SVal))) {
         NoIdent ();
         return;
     }
-    for (I = SB_GetIndex (&SVal); I < SB_GetLen (&SVal); ++I) {
-        if (!IsIdChar (SB_AtUnchecked (&SVal, I))) {
+    for (I = SB_GetIndex (&CurTok.SVal); I < SB_GetLen (&CurTok.SVal); ++I) {
+        if (!IsIdChar (SB_AtUnchecked (&CurTok.SVal, I))) {
             NoIdent ();
             return;
         }
@@ -248,13 +250,14 @@ static void FuncIdent (void)
     /* If anything is ok, save and skip the string. Check that the next token
      * is a right paren, then replace the token by an identifier token.
      */
-    SB_Copy (&Buf, &SVal);
+    SB_Copy (&Buf, &CurTok.SVal);
     NextTok ();
-    if (Tok != TOK_RPAREN) {
+    if (CurTok.Tok != TOK_RPAREN) {
        Error ("`)' expected");
     } else {
-        Tok = Id;
-        SB_Copy (&SVal, &Buf);
+        CurTok.Tok = Id;
+        SB_Copy (&CurTok.SVal, &Buf);
+        SB_Terminate (&CurTok.SVal);
     }
 
     /* Free buffer memory */
@@ -442,7 +445,7 @@ static void FuncSPrintF (void)
     if (!LookAtStrCon ()) {
         return;
     }
-    SB_Copy (&Format, &SVal);
+    SB_Copy (&Format, &CurTok.SVal);
     NextTok ();
 
     /* Walk over the format string, generating the function result in R */
@@ -544,11 +547,11 @@ static void FuncSPrintF (void)
                 /* The argument must be a string constant */
                 if (!LookAtStrCon ()) {
                     /* Make it one */
-                    SB_CopyStr (&SVal, "**undefined**");
+                    SB_CopyStr (&CurTok.SVal, "**undefined**");
                 }
 
                 /* Format this argument according to the spec */
-                SB_Printf (&R1, SB_GetConstBuf (&F1), SVal);
+                SB_Printf (&R1, SB_GetConstBuf (&F1), SB_GetConstBuf (&CurTok.SVal));
 
                 /* Skip the string constant */
                 NextTok ();
@@ -596,11 +599,12 @@ static void FuncSPrintF (void)
     /* We expect a closing parenthesis, but will not skip it but replace it
      * by the string token just created.
      */
-    if (Tok != TOK_RPAREN) {
+    if (CurTok.Tok != TOK_RPAREN) {
        Error ("`)' expected");
     } else {
-       Tok = TOK_STRCON;
-        SB_Copy (&SVal, &R);
+       CurTok.Tok = TOK_STRCON;
+        SB_Copy (&CurTok.SVal, &R);
+        SB_Terminate (&CurTok.SVal);
     }
 
 
@@ -625,9 +629,9 @@ static void FuncString (void)
     ConsumeLParen ();
 
     /* Accept identifiers or numeric expressions */
-    if (Tok == TOK_IDENT || Tok == TOK_LOCAL_IDENT) {
+    if (CurTok.Tok == TOK_IDENT || CurTok.Tok == TOK_LOCAL_IDENT) {
        /* Save the identifier, then skip it */
-               SB_Copy (&Buf, &SVal);
+               SB_Copy (&Buf, &CurTok.SVal);
        NextTok ();
     } else {
        /* Numeric expression */
@@ -638,11 +642,12 @@ static void FuncString (void)
     /* We expect a closing parenthesis, but will not skip it but replace it
      * by the string token just created.
      */
-    if (Tok != TOK_RPAREN) {
+    if (CurTok.Tok != TOK_RPAREN) {
        Error ("`)' expected");
     } else {
-       Tok = TOK_STRCON;
-       SB_Copy (&SVal, &Buf);
+       CurTok.Tok = TOK_STRCON;
+       SB_Copy (&CurTok.SVal, &Buf);
+        SB_Terminate (&CurTok.SVal);
     }
 
     /* Free string memory */
@@ -657,11 +662,13 @@ void NextTok (void)
     /* Get the next raw token */
     NextRawTok ();
 
-    /* In raw mode, pass the token unchanged */
-    if (RawMode == 0) {
+    /* In raw mode, or when output is suppressed via conditional assembly,
+     * pass the token unchanged.
+     */
+    if (RawMode == 0 && IfCond) {
 
        /* Execute token handling functions */
-       switch (Tok) {
+       switch (CurTok.Tok) {
 
            case TOK_CONCAT:
                FuncConcat ();
@@ -701,10 +708,10 @@ void NextTok (void)
 
 
 
-void Consume (Token Expected, const char* ErrMsg)
+void Consume (token_t Expected, const char* ErrMsg)
 /* Consume Expected, print an error if we don't find it */
 {
-    if (Tok == Expected) {
+    if (CurTok.Tok == Expected) {
        NextTok ();
     } else {
                Error ("%s", ErrMsg);
@@ -720,7 +727,7 @@ void ConsumeSep (void)
     ExpectSep ();
 
     /* If we are at end of line, skip it */
-    if (Tok == TOK_SEP) {
+    if (CurTok.Tok == TOK_SEP) {
        NextTok ();
     }
 }
@@ -754,7 +761,7 @@ void ConsumeComma (void)
 void SkipUntilSep (void)
 /* Skip tokens until we reach a line separator or end of file */
 {
-    while (!TokIsSep (Tok)) {
+    while (!TokIsSep (CurTok.Tok)) {
        NextTok ();
     }
 }
@@ -766,7 +773,7 @@ void ExpectSep (void)
  * not skip the line separator.
  */
 {
-    if (!TokIsSep (Tok)) {
+    if (!TokIsSep (CurTok.Tok)) {
                ErrorSkip ("Unexpected trailing garbage characters");
     }
 }