]> git.sur5r.net Git - cc65/blobdiff - src/ca65/ulabel.c
New module strstack
[cc65] / src / ca65 / ulabel.c
index adfe2e5f177299cadbc6e4a61c5a8580eeecd65e..45f1f7da248887d910862c59674dc256307e8fe2 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000      Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* (C) 2000-2003 Ullrich von Bassewitz                                       */
+/*               Römerstraße 52                                              */
+/*               D-70794 Filderstadt                                         */
+/* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
 
 
 
-#include "../common/filepos.h"
+/* common */
+#include "check.h"
+#include "filepos.h"
+#include "xmalloc.h"
 
+/* ca65 */
 #include "error.h"
 #include "expr.h"
-#include "mem.h"
 #include "scanner.h"
 #include "ulabel.h"
 
@@ -50,8 +53,8 @@
 
 
 /* Struct that describes an unnamed label */
-typedef struct ULabel_ ULabel;
-struct ULabel_ {
+typedef struct ULabel ULabel;
+struct ULabel {
     ULabel*            Prev;                   /* Pointer to previous node in list */
     ULabel*            Next;                   /* Pointer to next node in list */
     FilePos    Pos;                    /* Position of the label in the source */
@@ -80,7 +83,7 @@ static ULabel* NewULabel (ExprNode* Val)
  */
 {
     /* Allocate memory for the ULabel structure */
-    ULabel* L = Xmalloc (sizeof (ULabel));
+    ULabel* L = xmalloc (sizeof (ULabel));
 
     /* Initialize the fields */
     L->Pos = CurPos;
@@ -132,9 +135,9 @@ ExprNode* ULabRef (int Which)
        }
        if (L == 0) {
            /* Label does not exist */
-           Error (ERR_UNDEFINED_LABEL);
+           Error ("Undefined label");
            /* We must return something valid */
-           return CurrentPC();
+           return GenCurrentPC();
        } else {
            /* Return a copy of the label value */
            return CloneExpr (L->Val);
@@ -142,15 +145,12 @@ ExprNode* ULabRef (int Which)
     } else {
        /* Forward reference. Create labels as needed */
        unsigned LabelNum = ULabDefCount + Which - 1;
-       while (Which > 0) {
-           if (L->Next == 0) {
-               NewULabel (0);
-           }
-           L = L->Next;
-           --Which;
-       }
-       /* Return an unnamed label expression */
-               return ULabelExpr (LabelNum);
+       while (LabelNum < ULabCount) {
+                   NewULabel (0);
+       }
+
+       /* Return an unnamed label expression */
+               return GenULabelExpr (LabelNum);
     }
 }
 
@@ -162,11 +162,11 @@ void ULabDef (void)
     /* Create a new label if needed, or use an existing one */
     if (ULabLastDef == 0 || ULabLastDef->Next == 0) {
        /* The last label is also the last defined label, we need a new one */
-       ULabLastDef = NewULabel (CurrentPC ());
+       ULabLastDef = NewULabel (GenCurrentPC ());
     } else {
        /* We do already have the label, but it's undefined until now */
        ULabLastDef = ULabLastDef->Next;
-       ULabLastDef->Val = CurrentPC ();
+       ULabLastDef->Val = GenCurrentPC ();
        ULabLastDef->Pos = CurPos;
     }
     ++ULabDefCount;
@@ -199,7 +199,7 @@ ExprNode* ULabResolve (unsigned Index)
 
     /* If the label is open (not defined), return some valid value */
     if (L->Val == 0) {
-       return LiteralExpr (0);
+       return GenLiteralExpr (0);
     } else {
        return CloneExpr (L->Val);
     }
@@ -216,7 +216,7 @@ void ULabCheck (void)
     if (ULabLastDef) {
        L = ULabLastDef->Next;
        while (L) {
-           PError (&L->Pos, ERR_UNDEFINED_LABEL);
+           PError (&L->Pos, "Undefined label");
            L = L->Next;
        }
     }
@@ -227,7 +227,7 @@ void ULabCheck (void)
      */
     if (ULabCount) {
        unsigned I = 0;
-       ULabList = Xmalloc (ULabCount * sizeof (ULabel*));
+       ULabList = xmalloc (ULabCount * sizeof (ULabel*));
        L = ULabRoot;
        while (L) {
            ULabList[I] = L;