diff --git a/src/main/scala/millfork/env/Environment.scala b/src/main/scala/millfork/env/Environment.scala index 5f0c0ee3..4f74be20 100644 --- a/src/main/scala/millfork/env/Environment.scala +++ b/src/main/scala/millfork/env/Environment.scala @@ -1298,6 +1298,22 @@ class Environment(val parent: Option[Environment], val prefix: String, val cpuFa } } + private def expandAliases(): Unit = { + val aliasesToAdd = mutable.ListBuffer[Alias]() + things.values.foreach{ + case Alias(aliasName, target, deprecated) => + val prefix = target + "." + things.foreach{ + case (thingName, thing) => + if (thingName.startsWith(prefix)) { + aliasesToAdd += Alias(aliasName + "." + thingName.stripPrefix(prefix), thingName, deprecated) + } + } + case _ => () + } + aliasesToAdd.foreach(a => things += a.name -> a) + } + def collectDeclarations(program: Program, options: CompilationOptions): Unit = { val b = get[VariableType]("byte") val v = get[Type]("void") @@ -1320,6 +1336,7 @@ class Environment(val parent: Option[Environment], val prefix: String, val cpuFa case a: ArrayDeclarationStatement => registerArray(a, options) case _ => } + expandAliases() if (options.zpRegisterSize > 0 && !things.contains("__reg")) { addThing(BasicPlainType("__reg$type", options.zpRegisterSize), None) registerVariable(VariableDeclarationStatement( diff --git a/src/test/scala/millfork/test/BasicSymonTest.scala b/src/test/scala/millfork/test/BasicSymonTest.scala index dd6d7839..b775cf4f 100644 --- a/src/test/scala/millfork/test/BasicSymonTest.scala +++ b/src/test/scala/millfork/test/BasicSymonTest.scala @@ -173,6 +173,20 @@ class BasicSymonTest extends FunSuite with Matchers { """.stripMargin){ m => () } } + test("Deep alias test") { + EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80)( + """ + | word output @$c000 + | alias a = output + | void main () { + | a.hi = 2 + | a.lo = $55 + | } + """.stripMargin){ m => + m.readWord(0xc000) should equal(0x255) + } + } + test("Preprocessor test") { EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp)( """