From: cuz Date: Sat, 17 Jul 2004 22:14:30 +0000 (+0000) Subject: Fixed problems with unnamed labels X-Git-Tag: V2.12.0~673 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=9c0bf144544466158a290e78c15173d7be7b1ed8;p=cc65 Fixed problems with unnamed labels git-svn-id: svn://svn.cc65.org/cc65/trunk@3160 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- 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); } }