mirror of
https://github.com/irmen/prog8.git
synced 2025-01-10 20:30:23 +00:00
fix reporting of (not) unused code after GoSub jump
This commit is contained in:
parent
c838821615
commit
69dcb4dbda
@ -28,27 +28,28 @@ class UnusedCodeRemover(private val program: Program,
|
||||
}
|
||||
|
||||
override fun before(breakStmt: Break, parent: Node): Iterable<IAstModification> {
|
||||
reportUnreachable(breakStmt, parent as IStatementContainer)
|
||||
reportUnreachable(breakStmt)
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
override fun before(jump: Jump, parent: Node): Iterable<IAstModification> {
|
||||
reportUnreachable(jump, parent as IStatementContainer)
|
||||
if(!jump.isGosub)
|
||||
reportUnreachable(jump)
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
override fun before(returnStmt: Return, parent: Node): Iterable<IAstModification> {
|
||||
reportUnreachable(returnStmt, parent as IStatementContainer)
|
||||
reportUnreachable(returnStmt)
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
override fun before(functionCallStatement: FunctionCallStatement, parent: Node): Iterable<IAstModification> {
|
||||
if(functionCallStatement.target.nameInSource.last() == "exit")
|
||||
reportUnreachable(functionCallStatement, parent as IStatementContainer)
|
||||
reportUnreachable(functionCallStatement)
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
private fun reportUnreachable(stmt: Statement, parent: IStatementContainer) {
|
||||
private fun reportUnreachable(stmt: Statement) {
|
||||
when(val next = stmt.nextSibling()) {
|
||||
null, is Label, is Directive, is VarDecl, is InlineAssembly, is Subroutine -> {}
|
||||
else -> errors.warn("unreachable code", next.position)
|
||||
|
@ -21,6 +21,13 @@ main {
|
||||
; void sys.pop()
|
||||
|
||||
routine2(uw, 11,22, true, 33)
|
||||
routine2(uw, 11,22, true, 33)
|
||||
routine2(uw, 11,22, true, 33)
|
||||
routine2(uw, 11,22, true, 33)
|
||||
blerp(22)
|
||||
blerp(22)
|
||||
blerp(22)
|
||||
blerp(22)
|
||||
|
||||
test_stack.test()
|
||||
|
||||
@ -29,6 +36,10 @@ main {
|
||||
|
||||
}
|
||||
|
||||
sub blerp(uword z) {
|
||||
z++
|
||||
}
|
||||
|
||||
asmsub routine2(uword num @AY, ubyte a1 @R1, ubyte a2 @R2, ubyte switch @Pc, ubyte a3 @X) {
|
||||
%asm {{
|
||||
adc #20
|
||||
|
Loading…
x
Reference in New Issue
Block a user