mirror of
https://github.com/irmen/prog8.git
synced 2025-01-12 04:30:03 +00:00
remove unused ast print func
This commit is contained in:
parent
b95608f68a
commit
0cbc56b82e
@ -14,16 +14,6 @@ sealed class PtNode(val position: Position) {
|
|||||||
val children = mutableListOf<PtNode>()
|
val children = mutableListOf<PtNode>()
|
||||||
lateinit var parent: PtNode
|
lateinit var parent: PtNode
|
||||||
|
|
||||||
fun printIndented(indent: Int) {
|
|
||||||
print(" ".repeat(indent))
|
|
||||||
print("${this.javaClass.simpleName} ")
|
|
||||||
printProperties()
|
|
||||||
println()
|
|
||||||
children.forEach { it.printIndented(indent+1) }
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract fun printProperties()
|
|
||||||
|
|
||||||
fun add(child: PtNode) {
|
fun add(child: PtNode) {
|
||||||
children.add(child)
|
children.add(child)
|
||||||
child.parent = this
|
child.parent = this
|
||||||
@ -41,9 +31,7 @@ sealed class PtNode(val position: Position) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class PtNodeGroup : PtNode(Position.DUMMY) {
|
class PtNodeGroup : PtNode(Position.DUMMY)
|
||||||
override fun printProperties() {}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
sealed class PtNamedNode(var name: String, position: Position): PtNode(position) {
|
sealed class PtNamedNode(var name: String, position: Position): PtNode(position) {
|
||||||
@ -67,10 +55,6 @@ class PtProgram(
|
|||||||
val memsizer: IMemSizer,
|
val memsizer: IMemSizer,
|
||||||
val encoding: IStringEncoding
|
val encoding: IStringEncoding
|
||||||
) : PtNode(Position.DUMMY) {
|
) : PtNode(Position.DUMMY) {
|
||||||
fun print() = printIndented(0)
|
|
||||||
override fun printProperties() {
|
|
||||||
print("'$name'")
|
|
||||||
}
|
|
||||||
|
|
||||||
// fun allModuleDirectives(): Sequence<PtDirective> =
|
// fun allModuleDirectives(): Sequence<PtDirective> =
|
||||||
// children.asSequence().flatMap { it.children }.filterIsInstance<PtDirective>().distinct()
|
// children.asSequence().flatMap { it.children }.filterIsInstance<PtDirective>().distinct()
|
||||||
@ -91,10 +75,6 @@ class PtBlock(name: String,
|
|||||||
val source: SourceCode, // taken from the module the block is defined in.
|
val source: SourceCode, // taken from the module the block is defined in.
|
||||||
position: Position
|
position: Position
|
||||||
) : PtNamedNode(name, position) {
|
) : PtNamedNode(name, position) {
|
||||||
override fun printProperties() {
|
|
||||||
print("$name addr=$address library=$library forceOutput=$forceOutput alignment=$alignment")
|
|
||||||
}
|
|
||||||
|
|
||||||
enum class BlockAlignment {
|
enum class BlockAlignment {
|
||||||
NONE,
|
NONE,
|
||||||
WORD,
|
WORD,
|
||||||
@ -104,8 +84,6 @@ class PtBlock(name: String,
|
|||||||
|
|
||||||
|
|
||||||
class PtInlineAssembly(val assembly: String, val isIR: Boolean, position: Position) : PtNode(position) {
|
class PtInlineAssembly(val assembly: String, val isIR: Boolean, position: Position) : PtNode(position) {
|
||||||
override fun printProperties() {}
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
require(!assembly.startsWith('\n') && !assembly.startsWith('\r')) { "inline assembly should be trimmed" }
|
require(!assembly.startsWith('\n') && !assembly.startsWith('\r')) { "inline assembly should be trimmed" }
|
||||||
require(!assembly.endsWith('\n') && !assembly.endsWith('\r')) { "inline assembly should be trimmed" }
|
require(!assembly.endsWith('\n') && !assembly.endsWith('\r')) { "inline assembly should be trimmed" }
|
||||||
@ -113,28 +91,16 @@ class PtInlineAssembly(val assembly: String, val isIR: Boolean, position: Positi
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class PtLabel(name: String, position: Position) : PtNamedNode(name, position) {
|
class PtLabel(name: String, position: Position) : PtNamedNode(name, position)
|
||||||
override fun printProperties() {
|
|
||||||
print(name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class PtBreakpoint(position: Position): PtNode(position) {
|
class PtBreakpoint(position: Position): PtNode(position)
|
||||||
override fun printProperties() {}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class PtIncludeBinary(val file: Path, val offset: UInt?, val length: UInt?, position: Position) : PtNode(position) {
|
class PtIncludeBinary(val file: Path, val offset: UInt?, val length: UInt?, position: Position) : PtNode(position)
|
||||||
override fun printProperties() {
|
|
||||||
print("filename=$file offset=$offset length=$length")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class PtNop(position: Position): PtNode(position) {
|
class PtNop(position: Position): PtNode(position)
|
||||||
override fun printProperties() {}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// find the parent node of a specific type or interface
|
// find the parent node of a specific type or interface
|
||||||
|
@ -21,10 +21,6 @@ sealed class PtExpression(val type: DataType, position: Position) : PtNode(posit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun printProperties() {
|
|
||||||
print(type)
|
|
||||||
}
|
|
||||||
|
|
||||||
infix fun isSameAs(other: PtExpression): Boolean {
|
infix fun isSameAs(other: PtExpression): Boolean {
|
||||||
return when(this) {
|
return when(this) {
|
||||||
is PtAddressOf -> other is PtAddressOf && other.type==type && other.identifier isSameAs identifier
|
is PtAddressOf -> other is PtAddressOf && other.type==type && other.identifier isSameAs identifier
|
||||||
@ -101,9 +97,6 @@ class PtBuiltinFunctionCall(val name: String,
|
|||||||
|
|
||||||
val args: List<PtExpression>
|
val args: List<PtExpression>
|
||||||
get() = children.map { it as PtExpression }
|
get() = children.map { it as PtExpression }
|
||||||
override fun printProperties() {
|
|
||||||
print("$name void=$void noSideFx=$hasNoSideEffects")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -113,10 +106,6 @@ class PtBinaryExpression(val operator: String, type: DataType, position: Positio
|
|||||||
get() = children[0] as PtExpression
|
get() = children[0] as PtExpression
|
||||||
val right: PtExpression
|
val right: PtExpression
|
||||||
get() = children[1] as PtExpression
|
get() = children[1] as PtExpression
|
||||||
|
|
||||||
override fun printProperties() {
|
|
||||||
print("$operator -> $type")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -139,23 +128,15 @@ class PtFunctionCall(val name: String,
|
|||||||
|
|
||||||
val args: List<PtExpression>
|
val args: List<PtExpression>
|
||||||
get() = children.map { it as PtExpression }
|
get() = children.map { it as PtExpression }
|
||||||
override fun printProperties() {
|
|
||||||
print("$name void=$void")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class PtIdentifier(val name: String, type: DataType, position: Position) : PtExpression(type, position) {
|
class PtIdentifier(val name: String, type: DataType, position: Position) : PtExpression(type, position)
|
||||||
override fun printProperties() {
|
|
||||||
print("$name $type")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class PtMemoryByte(position: Position) : PtExpression(DataType.UBYTE, position) {
|
class PtMemoryByte(position: Position) : PtExpression(DataType.UBYTE, position) {
|
||||||
val address: PtExpression
|
val address: PtExpression
|
||||||
get() = children.single() as PtExpression
|
get() = children.single() as PtExpression
|
||||||
override fun printProperties() {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -176,10 +157,6 @@ class PtNumber(type: DataType, val number: Double, position: Position) : PtExpre
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun printProperties() {
|
|
||||||
print("$number ($type)")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int = Objects.hash(type, number)
|
override fun hashCode(): Int = Objects.hash(type, number)
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
@ -200,10 +177,6 @@ class PtPrefix(val operator: String, type: DataType, position: Position): PtExpr
|
|||||||
// note: the "not" operator may no longer occur in the ast; not x should have been replaced with x==0
|
// note: the "not" operator may no longer occur in the ast; not x should have been replaced with x==0
|
||||||
require(operator in setOf("+", "-", "~")) { "invalid prefix operator: $operator" }
|
require(operator in setOf("+", "-", "~")) { "invalid prefix operator: $operator" }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun printProperties() {
|
|
||||||
print(operator)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -214,16 +187,10 @@ class PtRange(type: DataType, position: Position) : PtExpression(type, position)
|
|||||||
get() = children[1] as PtExpression
|
get() = children[1] as PtExpression
|
||||||
val step: PtNumber
|
val step: PtNumber
|
||||||
get() = children[2] as PtNumber
|
get() = children[2] as PtNumber
|
||||||
|
|
||||||
override fun printProperties() {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class PtString(val value: String, val encoding: Encoding, position: Position) : PtExpression(DataType.STR, position) {
|
class PtString(val value: String, val encoding: Encoding, position: Position) : PtExpression(DataType.STR, position) {
|
||||||
override fun printProperties() {
|
|
||||||
print("$encoding:\"$value\"")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int = Objects.hash(value, encoding)
|
override fun hashCode(): Int = Objects.hash(value, encoding)
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if(other==null || other !is PtString)
|
if(other==null || other !is PtString)
|
||||||
@ -240,11 +207,7 @@ class PtTypeCast(type: DataType, position: Position) : PtExpression(type, positi
|
|||||||
|
|
||||||
|
|
||||||
// special node that isn't created from compiling user code, but used internally in the Intermediate Code
|
// special node that isn't created from compiling user code, but used internally in the Intermediate Code
|
||||||
class PtMachineRegister(val register: Int, type: DataType, position: Position) : PtExpression(type, position) {
|
class PtMachineRegister(val register: Int, type: DataType, position: Position) : PtExpression(type, position)
|
||||||
override fun printProperties() {
|
|
||||||
print("reg=$register $type")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun constValue(expr: PtExpression): Double? = if(expr is PtNumber) expr.number else null
|
fun constValue(expr: PtExpression): Double? = if(expr is PtNumber) expr.number else null
|
||||||
|
@ -15,11 +15,7 @@ class PtAsmSub(
|
|||||||
val returns: List<Pair<RegisterOrStatusflag, DataType>>,
|
val returns: List<Pair<RegisterOrStatusflag, DataType>>,
|
||||||
val inline: Boolean,
|
val inline: Boolean,
|
||||||
position: Position
|
position: Position
|
||||||
) : PtNamedNode(name, position), IPtSubroutine {
|
) : PtNamedNode(name, position), IPtSubroutine
|
||||||
override fun printProperties() {
|
|
||||||
print("$name inline=$inline")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class PtSub(
|
class PtSub(
|
||||||
@ -28,10 +24,6 @@ class PtSub(
|
|||||||
val returntype: DataType?,
|
val returntype: DataType?,
|
||||||
position: Position
|
position: Position
|
||||||
) : PtNamedNode(name, position), IPtSubroutine {
|
) : PtNamedNode(name, position), IPtSubroutine {
|
||||||
override fun printProperties() {
|
|
||||||
print(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
// params and return value should not be str
|
// params and return value should not be str
|
||||||
if(parameters.any{ it.type !in NumericDatatypes })
|
if(parameters.any{ it.type !in NumericDatatypes })
|
||||||
@ -43,11 +35,7 @@ class PtSub(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class PtSubroutineParameter(name: String, val type: DataType, position: Position): PtNamedNode(name, position) {
|
class PtSubroutineParameter(name: String, val type: DataType, position: Position): PtNamedNode(name, position)
|
||||||
override fun printProperties() {
|
|
||||||
print("$type $name")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class PtAssignment(position: Position) : PtNode(position) {
|
class PtAssignment(position: Position) : PtNode(position) {
|
||||||
@ -56,8 +44,6 @@ class PtAssignment(position: Position) : PtNode(position) {
|
|||||||
val value: PtExpression
|
val value: PtExpression
|
||||||
get() = children[1] as PtExpression
|
get() = children[1] as PtExpression
|
||||||
|
|
||||||
override fun printProperties() { }
|
|
||||||
|
|
||||||
val isInplaceAssign: Boolean by lazy {
|
val isInplaceAssign: Boolean by lazy {
|
||||||
val target = target.children.single() as PtExpression
|
val target = target.children.single() as PtExpression
|
||||||
when(val source = value) {
|
when(val source = value) {
|
||||||
@ -105,8 +91,6 @@ class PtAssignTarget(position: Position) : PtNode(position) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun printProperties() {}
|
|
||||||
|
|
||||||
infix fun isSameAs(expression: PtExpression): Boolean = expression.isSameAs(this)
|
infix fun isSameAs(expression: PtExpression): Boolean = expression.isSameAs(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,10 +100,6 @@ class PtConditionalBranch(val condition: BranchCondition, position: Position) :
|
|||||||
get() = children[0] as PtNodeGroup
|
get() = children[0] as PtNodeGroup
|
||||||
val falseScope: PtNodeGroup
|
val falseScope: PtNodeGroup
|
||||||
get() = children[1] as PtNodeGroup
|
get() = children[1] as PtNodeGroup
|
||||||
|
|
||||||
override fun printProperties() {
|
|
||||||
print(condition)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -130,8 +110,6 @@ class PtForLoop(position: Position) : PtNode(position) {
|
|||||||
get() = children[1] as PtExpression
|
get() = children[1] as PtExpression
|
||||||
val statements: PtNodeGroup
|
val statements: PtNodeGroup
|
||||||
get() = children[2] as PtNodeGroup
|
get() = children[2] as PtNodeGroup
|
||||||
|
|
||||||
override fun printProperties() {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -142,8 +120,6 @@ class PtIfElse(position: Position) : PtNode(position) {
|
|||||||
get() = children[1] as PtNodeGroup
|
get() = children[1] as PtNodeGroup
|
||||||
val elseScope: PtNodeGroup
|
val elseScope: PtNodeGroup
|
||||||
get() = children[2] as PtNodeGroup
|
get() = children[2] as PtNodeGroup
|
||||||
|
|
||||||
override fun printProperties() {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -151,12 +127,6 @@ class PtJump(val identifier: PtIdentifier?,
|
|||||||
val address: UInt?,
|
val address: UInt?,
|
||||||
val generatedLabel: String?,
|
val generatedLabel: String?,
|
||||||
position: Position) : PtNode(position) {
|
position: Position) : PtNode(position) {
|
||||||
override fun printProperties() {
|
|
||||||
identifier?.printProperties()
|
|
||||||
if(address!=null) print(address.toHex())
|
|
||||||
if(generatedLabel!=null) print(generatedLabel)
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
identifier?.let {it.parent = this }
|
identifier?.let {it.parent = this }
|
||||||
}
|
}
|
||||||
@ -166,10 +136,6 @@ class PtJump(val identifier: PtIdentifier?,
|
|||||||
class PtPostIncrDecr(val operator: String, position: Position) : PtNode(position) {
|
class PtPostIncrDecr(val operator: String, position: Position) : PtNode(position) {
|
||||||
val target: PtAssignTarget
|
val target: PtAssignTarget
|
||||||
get() = children.single() as PtAssignTarget
|
get() = children.single() as PtAssignTarget
|
||||||
|
|
||||||
override fun printProperties() {
|
|
||||||
print(operator)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -178,8 +144,6 @@ class PtRepeatLoop(position: Position) : PtNode(position) {
|
|||||||
get() = children[0] as PtExpression
|
get() = children[0] as PtExpression
|
||||||
val statements: PtNodeGroup
|
val statements: PtNodeGroup
|
||||||
get() = children[1] as PtNodeGroup
|
get() = children[1] as PtNodeGroup
|
||||||
|
|
||||||
override fun printProperties() {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -192,8 +156,6 @@ class PtReturn(position: Position) : PtNode(position) {
|
|||||||
else
|
else
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun printProperties() {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -204,27 +166,16 @@ sealed interface IPtVariable {
|
|||||||
|
|
||||||
|
|
||||||
class PtVariable(name: String, override val type: DataType, val zeropage: ZeropageWish, val value: PtExpression?, val arraySize: UInt?, position: Position) : PtNamedNode(name, position), IPtVariable {
|
class PtVariable(name: String, override val type: DataType, val zeropage: ZeropageWish, val value: PtExpression?, val arraySize: UInt?, position: Position) : PtNamedNode(name, position), IPtVariable {
|
||||||
override fun printProperties() {
|
|
||||||
print("$type $name")
|
|
||||||
}
|
|
||||||
init {
|
init {
|
||||||
value?.let {it.parent=this}
|
value?.let {it.parent=this}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class PtConstant(name: String, override val type: DataType, val value: Double, position: Position) : PtNamedNode(name, position), IPtVariable {
|
class PtConstant(name: String, override val type: DataType, val value: Double, position: Position) : PtNamedNode(name, position), IPtVariable
|
||||||
override fun printProperties() {
|
|
||||||
print("$type $name = $value")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class PtMemMapped(name: String, override val type: DataType, val address: UInt, val arraySize: UInt?, position: Position) : PtNamedNode(name, position), IPtVariable {
|
class PtMemMapped(name: String, override val type: DataType, val address: UInt, val arraySize: UInt?, position: Position) : PtNamedNode(name, position), IPtVariable
|
||||||
override fun printProperties() {
|
|
||||||
print("&$type $name = ${address.toHex()}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class PtWhen(position: Position) : PtNode(position) {
|
class PtWhen(position: Position) : PtNode(position) {
|
||||||
@ -232,8 +183,6 @@ class PtWhen(position: Position) : PtNode(position) {
|
|||||||
get() = children[0] as PtExpression
|
get() = children[0] as PtExpression
|
||||||
val choices: PtNodeGroup
|
val choices: PtNodeGroup
|
||||||
get() = children[1] as PtNodeGroup
|
get() = children[1] as PtNodeGroup
|
||||||
|
|
||||||
override fun printProperties() {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -242,5 +191,4 @@ class PtWhenChoice(val isElse: Boolean, position: Position) : PtNode(position) {
|
|||||||
get() = children[0] as PtNodeGroup
|
get() = children[0] as PtNodeGroup
|
||||||
val statements: PtNodeGroup
|
val statements: PtNodeGroup
|
||||||
get() = children[1] as PtNodeGroup
|
get() = children[1] as PtNodeGroup
|
||||||
override fun printProperties() {}
|
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ class TestIntermediateAst: FunSpec({
|
|||||||
val fcall = (entry.children[4] as PtAssignment).value as PtFunctionCall
|
val fcall = (entry.children[4] as PtAssignment).value as PtFunctionCall
|
||||||
fcall.void shouldBe false
|
fcall.void shouldBe false
|
||||||
fcall.type shouldBe DataType.UBYTE
|
fcall.type shouldBe DataType.UBYTE
|
||||||
ast.print()
|
printAst(ast, ::println)
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
Loading…
x
Reference in New Issue
Block a user