mirror of
https://github.com/irmen/prog8.git
synced 2025-11-03 19:16:13 +00:00
removed some redundant arguments
This commit is contained in:
@@ -126,7 +126,7 @@ class Program(val name: String,
|
||||
private class StringSearch(val program: Program): IAstVisitor {
|
||||
val removals = mutableListOf<List<String>>()
|
||||
override fun visit(identifier: IdentifierReference) {
|
||||
if(identifier.wasStringLiteral(program))
|
||||
if(identifier.wasStringLiteral())
|
||||
removals.add(identifier.nameInSource)
|
||||
}
|
||||
|
||||
|
||||
@@ -1164,14 +1164,14 @@ data class IdentifierReference(val nameInSource: List<String>, override val posi
|
||||
|
||||
override val isSimple = true
|
||||
|
||||
fun targetStatement(program: Program) =
|
||||
if(nameInSource.singleOrNull() in program.builtinFunctions.names)
|
||||
fun targetStatement(program: Program?) =
|
||||
if(program!=null && nameInSource.singleOrNull() in program.builtinFunctions.names)
|
||||
BuiltinFunctionPlaceholder(nameInSource[0], position, parent)
|
||||
else
|
||||
definingScope.lookup(nameInSource)
|
||||
|
||||
fun targetVarDecl(program: Program): VarDecl? = targetStatement(program) as? VarDecl
|
||||
fun targetSubroutine(program: Program): Subroutine? = targetStatement(program) as? Subroutine
|
||||
fun targetVarDecl(): VarDecl? = targetStatement(null) as? VarDecl
|
||||
fun targetSubroutine(): Subroutine? = targetStatement(null) as? Subroutine
|
||||
|
||||
fun targetNameAndType(program: Program): Pair<String, DataType> {
|
||||
val target = targetStatement(program) as? INamedStatement ?: throw FatalAstException("can't find target for $nameInSource")
|
||||
@@ -1241,8 +1241,8 @@ data class IdentifierReference(val nameInSource: List<String>, override val posi
|
||||
}
|
||||
}
|
||||
|
||||
fun wasStringLiteral(program: Program): Boolean {
|
||||
val decl = targetVarDecl(program)
|
||||
fun wasStringLiteral(): Boolean {
|
||||
val decl = targetVarDecl()
|
||||
if(decl == null || decl.origin!=VarDeclOrigin.STRINGLITERAL)
|
||||
return false
|
||||
|
||||
|
||||
@@ -647,7 +647,7 @@ data class AssignTarget(var identifier: IdentifierReference?,
|
||||
return target.isIOAddress(addr.number.toUInt())
|
||||
return when (memAddr.addressExpression) {
|
||||
is IdentifierReference -> {
|
||||
val decl = (memAddr.addressExpression as IdentifierReference).targetVarDecl(definingModule.program)
|
||||
val decl = (memAddr.addressExpression as IdentifierReference).targetVarDecl()
|
||||
val result = if ((decl?.type == VarDeclType.MEMORY || decl?.type == VarDeclType.CONST) && decl.value is NumericLiteral)
|
||||
target.isIOAddress((decl.value as NumericLiteral).number.toUInt())
|
||||
else
|
||||
@@ -658,7 +658,7 @@ data class AssignTarget(var identifier: IdentifierReference?,
|
||||
}
|
||||
}
|
||||
arrayIdx != null -> {
|
||||
val targetStmt = arrayIdx.arrayvar.targetVarDecl(definingModule.program)
|
||||
val targetStmt = arrayIdx.arrayvar.targetVarDecl()
|
||||
return if (targetStmt?.type == VarDeclType.MEMORY) {
|
||||
val addr = targetStmt.value as? NumericLiteral
|
||||
if (addr != null)
|
||||
@@ -668,7 +668,7 @@ data class AssignTarget(var identifier: IdentifierReference?,
|
||||
} else false
|
||||
}
|
||||
ident != null -> {
|
||||
val decl = ident.targetVarDecl(definingModule.program) ?: throw FatalAstException("invalid identifier ${ident.nameInSource}")
|
||||
val decl = ident.targetVarDecl() ?: throw FatalAstException("invalid identifier ${ident.nameInSource}")
|
||||
return if (decl.type == VarDeclType.MEMORY && decl.value is NumericLiteral)
|
||||
target.isIOAddress((decl.value as NumericLiteral).number.toUInt())
|
||||
else
|
||||
|
||||
@@ -78,7 +78,7 @@ class CallGraph(private val program: Program) : IAstVisitor {
|
||||
}
|
||||
|
||||
override fun visit(functionCallExpr: FunctionCallExpression) {
|
||||
val otherSub = functionCallExpr.target.targetSubroutine(program)
|
||||
val otherSub = functionCallExpr.target.targetSubroutine()
|
||||
if (otherSub != null) {
|
||||
val definingSub = functionCallExpr.definingSubroutine
|
||||
if(definingSub!=null) {
|
||||
@@ -90,7 +90,7 @@ class CallGraph(private val program: Program) : IAstVisitor {
|
||||
}
|
||||
|
||||
override fun visit(functionCallStatement: FunctionCallStatement) {
|
||||
val otherSub = functionCallStatement.target.targetSubroutine(program)
|
||||
val otherSub = functionCallStatement.target.targetSubroutine()
|
||||
if (otherSub != null) {
|
||||
functionCallStatement.definingSubroutine?.let { thisSub ->
|
||||
calls[thisSub] = calls.getValue(thisSub) + otherSub
|
||||
@@ -101,12 +101,12 @@ class CallGraph(private val program: Program) : IAstVisitor {
|
||||
}
|
||||
|
||||
override fun visit(addressOf: AddressOf) {
|
||||
addressOf.identifier.targetSubroutine(program)?.let { notCalledButReferenced.add(it) }
|
||||
addressOf.identifier.targetSubroutine()?.let { notCalledButReferenced.add(it) }
|
||||
super.visit(addressOf)
|
||||
}
|
||||
|
||||
override fun visit(jump: Jump) {
|
||||
val otherSub = (jump.target as? IdentifierReference)?.targetSubroutine(program)
|
||||
val otherSub = (jump.target as? IdentifierReference)?.targetSubroutine()
|
||||
if (otherSub != null) {
|
||||
jump.definingSubroutine?.let { thisSub ->
|
||||
calls[thisSub] = calls.getValue(thisSub) + otherSub
|
||||
@@ -225,8 +225,6 @@ class CallGraph(private val program: Program) : IAstVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
inline fun unused(label: Label) = false // just always output labels
|
||||
|
||||
fun unused(stmt: INamedStatement): Boolean {
|
||||
return when(stmt) {
|
||||
is Subroutine -> unused(stmt)
|
||||
|
||||
Reference in New Issue
Block a user