/*****************************************************************************/
/* */
-/* ulabel.c */
+/* ulabel.c */
/* */
-/* Unnamed labels for the ca65 macroassembler */
+/* Unnamed labels for the ca65 macroassembler */
/* */
/* */
/* */
/*****************************************************************************/
-/* Data */
+/* Data */
/*****************************************************************************/
typedef struct ULabel ULabel;
struct ULabel {
Collection LineInfos; /* Position of the label in the source */
- ExprNode* Val; /* The label value - may be NULL */
+ ExprNode* Val; /* The label value - may be NULL */
unsigned Ref; /* Number of references */
};
/* List management */
-static Collection ULabList = STATIC_COLLECTION_INITIALIZER;
-static unsigned ULabDefCount = 0; /* Number of defined labels */
+static Collection ULabList = STATIC_COLLECTION_INITIALIZER;
+static unsigned ULabDefCount = 0; /* Number of defined labels */
/*****************************************************************************/
-/* Code */
+/* Code */
/*****************************************************************************/
* must be resolved later.
*/
{
- int Index;
+ int Index;
ULabel* L;
/* Which can never be 0 */
/* Get the index of the referenced label */
if (Which > 0) {
- --Which;
+ --Which;
}
Index = (int) ULabDefCount + Which;
/* We cannot have negative label indices */
if (Index < 0) {
- /* Label does not exist */
- Error ("Undefined label");
- /* We must return something valid */
- return GenCurrentPC();
+ /* Label does not exist */
+ Error ("Undefined label");
+ /* We must return something valid */
+ return GenCurrentPC();
}
/* Check if the label exists. If not, generate enough forward labels. */
if (Index < (int) CollCount (&ULabList)) {
/* The label exists, get it. */
- L = CollAtUnchecked (&ULabList, Index);
+ L = CollAtUnchecked (&ULabList, Index);
} else {
/* Generate new, undefined labels */
- while (Index >= (int) CollCount (&ULabList)) {
+ while (Index >= (int) CollCount (&ULabList)) {
L = NewULabel (0);
- }
+ }
}
/* Mark the label as referenced */
/* Define an unnamed label at the current PC */
{
if (ULabDefCount < CollCount (&ULabList)) {
- /* We did already have a forward reference to this label, so has
- * already been generated, but doesn't have a value. Use the current
- * PC for the label value.
- */
- ULabel* L = CollAtUnchecked (&ULabList, ULabDefCount);
- CHECK (L->Val == 0);
- L->Val = GenCurrentPC ();
+ /* We did already have a forward reference to this label, so has
+ * already been generated, but doesn't have a value. Use the current
+ * PC for the label value.
+ */
+ ULabel* L = CollAtUnchecked (&ULabList, ULabDefCount);
+ CHECK (L->Val == 0);
+ L->Val = GenCurrentPC ();
ReleaseFullLineInfo (&L->LineInfos);
GetFullLineInfo (&L->LineInfos);
} else {
- /* There is no such label, create it */
- NewULabel (GenCurrentPC ());
+ /* There is no such label, create it */
+ NewULabel (GenCurrentPC ());
}
/* We have one more defined label */
/* Check if there are undefined labels */
unsigned I = ULabDefCount;
while (I < CollCount (&ULabList)) {
- ULabel* L = CollAtUnchecked (&ULabList, I);
- LIError (&L->LineInfos, "Undefined label");
- ++I;
+ ULabel* L = CollAtUnchecked (&ULabList, I);
+ LIError (&L->LineInfos, "Undefined label");
+ ++I;
}
/* Walk over all labels and emit a warning if any unreferenced ones