mirror of
https://github.com/irmen/prog8.git
synced 2024-12-25 23:29:55 +00:00
compiler warning for unreachable code following a call to exit()
This commit is contained in:
parent
85c7f8314b
commit
e6be428589
@ -327,6 +327,8 @@ internal class AstChecker(private val program: Program,
|
|||||||
err("Pass-by-reference types (str, array) cannot occur as a parameter type directly. Instead, use an uword for their address, or access the variable from the outer scope directly.")
|
err("Pass-by-reference types (str, array) cannot occur as a parameter type directly. Instead, use an uword for their address, or access the variable from the outer scope directly.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
visitStatements(subroutine.statements)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visit(repeatLoop: RepeatLoop) {
|
override fun visit(repeatLoop: RepeatLoop) {
|
||||||
@ -1040,6 +1042,20 @@ internal class AstChecker(private val program: Program,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun visit(scope: AnonymousScope) {
|
||||||
|
visitStatements(scope.statements)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun visitStatements(statements: List<Statement>) {
|
||||||
|
for((index, stmt) in statements.withIndex()) {
|
||||||
|
if(stmt is FunctionCallStatement && stmt.target.nameInSource.last()=="exit") {
|
||||||
|
if(index < statements.size-1) {
|
||||||
|
printWarning("unreachable code", statements[index+1].position, "exit call above never returns")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun checkFunctionOrLabelExists(target: IdentifierReference, statement: Statement): Statement? {
|
private fun checkFunctionOrLabelExists(target: IdentifierReference, statement: Statement): Statement? {
|
||||||
val targetStatement = target.targetStatement(program.namespace)
|
val targetStatement = target.targetStatement(program.namespace)
|
||||||
if(targetStatement is Label || targetStatement is Subroutine || targetStatement is BuiltinFunctionStatementPlaceholder)
|
if(targetStatement is Label || targetStatement is Subroutine || targetStatement is BuiltinFunctionStatementPlaceholder)
|
||||||
|
@ -3,7 +3,6 @@ TODO
|
|||||||
====
|
====
|
||||||
|
|
||||||
- option to load library files from a directory instead of the embedded ones
|
- option to load library files from a directory instead of the embedded ones
|
||||||
- compiler warning 'unreachable code' for statement following an exit() function call
|
|
||||||
- code optimizer: remove all statements following an exit() function call
|
- code optimizer: remove all statements following an exit() function call
|
||||||
- vector inc/dec/add/sub/mul/div...?
|
- vector inc/dec/add/sub/mul/div...?
|
||||||
arrayvar++ / arrayvar-- / arrayvar += 2 / arrayvar -= 2 / arrayvar *= 3 / arrayvar /= 3
|
arrayvar++ / arrayvar-- / arrayvar += 2 / arrayvar -= 2 / arrayvar *= 3 / arrayvar /= 3
|
||||||
|
@ -21,9 +21,9 @@ main {
|
|||||||
c64scr.print("sp2:")
|
c64scr.print("sp2:")
|
||||||
print_stackpointer()
|
print_stackpointer()
|
||||||
exit(65)
|
exit(65)
|
||||||
sub3() ; TODO unreachable code compiler warning + remove the code in optimizer
|
sub3() ; TODO remove the code in optimizer
|
||||||
sub3() ; TODO unreachable code compiler warning + remove the code in optimizer
|
sub3() ; TODO remove the code in optimizer
|
||||||
sub3() ; TODO unreachable code compiler warning + remove the code in optimizer
|
sub3() ; TODO remove the code in optimizer
|
||||||
}
|
}
|
||||||
|
|
||||||
sub sub3() {
|
sub sub3() {
|
||||||
|
Loading…
Reference in New Issue
Block a user