From 9c0bf144544466158a290e78c15173d7be7b1ed8 Mon Sep 17 00:00:00 2001 From: cuz Date: Sat, 17 Jul 2004 22:14:30 +0000 Subject: [PATCH] Fixed problems with unnamed labels git-svn-id: svn://svn.cc65.org/cc65/trunk@3160 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ca65/ulabel.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/ca65/ulabel.c b/src/ca65/ulabel.c index c997d9b49..4a425e7b3 100644 --- a/src/ca65/ulabel.c +++ b/src/ca65/ulabel.c @@ -113,7 +113,7 @@ ExprNode* ULabRef (int Which) if (Which > 0) { --Which; } - Index = (int) CollCount (&ULabList) + Which; + Index = (int) ULabDefCount + Which; /* We cannot have negative label indices */ if (Index < 0) { @@ -123,19 +123,27 @@ ExprNode* ULabRef (int Which) return GenCurrentPC(); } - /* If the label does already exist, return it's value, otherwise create - * enough forward references, and return a label reference. - */ + /* 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->Ref; - return CloneExpr (L->Val); } else { + /* Generate new, undefined labels */ while (Index >= (int) CollCount (&ULabList)) { L = NewULabel (0); } - ++L->Ref; - return GenULabelExpr (Index); + } + + /* Mark the label as referenced */ + ++L->Ref; + + /* If the label is already defined, return its value, otherwise return + * just a reference. + */ + if (L->Val) { + return CloneExpr (L->Val); + } else { + return GenULabelExpr (Index); } } -- 2.39.5