remove some dead code

This commit is contained in:
Irmen de Jong 2019-07-17 22:04:51 +02:00
parent a8898a5993
commit b4e1b42cec
6 changed files with 10 additions and 131 deletions

View File

@ -1,13 +1,8 @@
package prog8.ast.base
import prog8.ast.IFunctionCall
import prog8.ast.Module
import prog8.ast.Node
import prog8.ast.Program
import prog8.ast.expressions.IdentifierReference
import prog8.ast.processing.*
import prog8.ast.statements.Assignment
import prog8.ast.statements.ForLoop
import prog8.compiler.CompilationOptions
import prog8.optimizer.FlattenAnonymousScopesAndRemoveNops
@ -62,34 +57,5 @@ internal fun Program.checkIdentifiers() {
throw FatalAstException("modules should all be unique")
}
// add any anonymous variables for heap values that are used,
// and replace an iterable literalvalue by identifierref to new local variable
// TODO: this is't doing anything anymore?
for (variable in checker.anonymousVariablesFromHeap.values) {
val scope = variable.first.definingScope()
scope.statements.add(variable.second)
val parent = variable.first.parent
when {
parent is Assignment && parent.value === variable.first -> {
val idref = IdentifierReference(listOf("$autoHeapValuePrefix${variable.first.heapId}"), variable.first.position)
idref.linkParents(parent)
parent.value = idref
}
parent is IFunctionCall -> {
val parameterPos = parent.arglist.indexOf(variable.first)
val idref = IdentifierReference(listOf("$autoHeapValuePrefix${variable.first.heapId}"), variable.first.position)
idref.linkParents(parent)
parent.arglist[parameterPos] = idref
}
parent is ForLoop -> {
val idref = IdentifierReference(listOf("$autoHeapValuePrefix${variable.first.heapId}"), variable.first.position)
idref.linkParents(parent)
parent.iterable = idref
}
else -> TODO("replace literalvalue by identifierref: $variable (in $parent)")
}
variable.second.linkParents(scope as Node)
}
printErrors(checker.result(), name)
}

View File

@ -28,7 +28,7 @@ sealed class Expression: Node {
abstract fun constValue(program: Program): NumericLiteralValue?
abstract fun accept(visitor: IAstModifyingVisitor): Expression
abstract fun accept(visitor: IAstVisitor)
abstract fun referencesIdentifiers(vararg name: String): Boolean // todo: remove and use calltree instead
abstract fun referencesIdentifiers(vararg name: String): Boolean // todo: remove this here and move it into CallGraph instead
abstract fun inferType(program: Program): DataType?
infix fun isSameAs(other: Expression): Boolean {
@ -510,7 +510,8 @@ class ReferenceLiteralValue(val type: DataType, // only reference types allo
}
override fun constValue(program: Program): NumericLiteralValue? {
// TODO: what about arrays that only contain constant numbers?
// note that we can't handle arrays that only contain constant numbers here anymore
// so they're not treated as constants anymore
return null
}
@ -521,7 +522,6 @@ class ReferenceLiteralValue(val type: DataType, // only reference types allo
val valueStr = when(type) {
in StringDatatypes -> "'${escape(str!!)}'"
in ArrayDatatypes -> "$array"
DataType.STRUCT -> TODO("struct literals")
else -> throw FatalAstException("weird ref type")
}
return "ReferenceValueLiteral($type, $valueStr)"

View File

@ -391,17 +391,6 @@ internal class AstChecker(private val program: Program,
val constVal = assignment.value.constValue(program)
if (constVal != null) {
checkValueTypeAndRange(targetDatatype, constVal)
// TODO what about arrays, structs, strings etc:
// val targetVar =
// if(target.identifier!=null)
// program.namespace.lookup(target.identifier.nameInSource, assignment) as? VarDecl
// else
// null
// val arrayspec = if(target.identifier!=null) targetVar?.arraysize else null
// checkValueTypeAndRange(targetDatatype, targetVar?.struct,
// arrayspec ?: ArrayIndex(NumericLiteralValue.optimalInteger(-1, assignment.position), assignment.position),
// constVal, program.heap)
} else {
val sourceDatatype: DataType? = assignment.value.inferType(program)
if (sourceDatatype == null) {
@ -512,10 +501,7 @@ internal class AstChecker(private val program: Program,
return
}
when(decl.value) {
is RangeExpr -> {
if(decl.arraysize!=null)
checkValueTypeAndRange(decl.datatype, decl.arraysize!!, decl.value as RangeExpr)
}
is RangeExpr -> throw FatalAstException("range expression should have been converted to a true array value")
is ReferenceLiteralValue -> {
val arraySpec = decl.arraysize ?: (
if((decl.value as ReferenceLiteralValue).isArray)
@ -780,19 +766,6 @@ internal class AstChecker(private val program: Program,
else if(fromValue > toValue && step>=0)
err("descending range requires step < 0")
}
// TODO range over single-character strings (... or have they been converted to byte literals already?)
// from.isString && to.isString -> {
// val fromString = from.strvalue!!
// val toString = to.strvalue!!
// if(fromString.length!=1 || toString.length!=1)
// err("range from and to must be a single character")
// if(fromString[0] == toString[0])
// printWarning("range contains just a single character", range.position)
// else if(fromString[0] < toString[0] && step<=0)
// err("ascending range requires step > 0")
// else if(fromString[0] > toString[0] && step>=0)
// err("descending range requires step < 0")
// }
else -> err("range expression must be over integers or over characters")
}
}
@ -1005,49 +978,6 @@ internal class AstChecker(private val program: Program,
return null
}
private fun checkValueTypeAndRange(targetDt: DataType, arrayspec: ArrayIndex, range: RangeExpr) : Boolean {
val from = range.from.constValue(program)
val to = range.to.constValue(program)
if(from==null || to==null) {
checkResult.add(SyntaxError("range from and to values must be constants", range.position))
return false
}
when(targetDt) {
in NumericDatatypes -> {
checkResult.add(SyntaxError("can't assign a range to a scalar type", range.position))
return false
}
in PassByReferenceDatatypes -> {
TODO("reference type range check $targetDt")
}
// in StringDatatypes -> {
// // range check bytes (chars)
// if(!from.isString || !to.isString) {
// checkResult.add(ExpressionError("range for string must have single characters from and to values", range.position))
// return false
// }
// val rangeSize=range.size()
// if(rangeSize!=null && (rangeSize<0 || rangeSize>255)) {
// checkResult.add(ExpressionError("size of range for string must be 0..255, instead of $rangeSize", range.position))
// return false
// }
// return true
// }
// in ArrayDatatypes -> {
// // range and length check bytes
// val expectedSize = arrayspec.size()
// val rangeSize=range.size()
// if(rangeSize!=null && rangeSize != expectedSize) {
// checkResult.add(ExpressionError("range size doesn't match array size, expected $expectedSize found $rangeSize", range.position))
// return false
// }
// return true
// }
else -> throw FatalAstException("invalid targetDt")
}
}
private fun checkValueTypeAndRange(targetDt: DataType, struct: StructDecl?,
arrayspec: ArrayIndex, value: ReferenceLiteralValue, heap: HeapValues) : Boolean {
fun err(msg: String) : Boolean {
@ -1202,7 +1132,7 @@ internal class AstChecker(private val program: Program,
private fun checkArrayValues(value: ReferenceLiteralValue, type: DataType): Boolean {
if(value.isArray && value.heapId==null) {
// TODO weird, array literal that hasn't been moved to the heap yet?
// hmm weird, array literal that hasn't been moved to the heap yet?
val array = value.array!!.map { it.constValue(program)!! }
val correct: Boolean
when(type) {

View File

@ -14,7 +14,6 @@ internal class AstIdentifiersChecker(private val program: Program) : IAstModifyi
private val checkResult: MutableList<AstException> = mutableListOf()
private var blocks = mutableMapOf<String, Block>()
internal val anonymousVariablesFromHeap = mutableMapOf<String, Pair<ReferenceLiteralValue, VarDecl>>() // TODO
private val vardeclsToAdd = mutableMapOf<INameScope, MutableList<VarDecl>>()
internal fun result(): List<AstException> {
@ -239,7 +238,6 @@ internal class AstIdentifiersChecker(private val program: Program) : IAstModifyi
// replace the reference literal by a identifier reference
val identifier = IdentifierReference(listOf(variable.name), variable.position)
identifier.parent = refLiteral.parent
// TODO anonymousVariablesFromHeap[variable.name] = Pair(refLiteral, variable)
return identifier
}

View File

@ -6,7 +6,6 @@ import prog8.ast.expressions.*
import prog8.ast.processing.IAstModifyingVisitor
import prog8.ast.processing.IAstVisitor
import prog8.compiler.HeapValues
import prog8.compiler.target.c64.MachineDefinition
sealed class Statement : Node {
@ -810,19 +809,6 @@ class StructDecl(override val name: String,
val numberOfElements: Int
get() = this.statements.size
val memorySize: Int
get() = this.statements.map {
val decl = it as VarDecl
when {
decl.datatype in ByteDatatypes -> 8
decl.datatype in WordDatatypes -> 16
decl.datatype==DataType.FLOAT -> MachineDefinition.Mflpt5.MemorySize
decl.datatype in StringDatatypes -> TODO("stringvalue size")
decl.datatype in ArrayDatatypes -> decl.arraysize!!.size()!!
decl.datatype==DataType.STRUCT -> decl.struct!!.memorySize
else -> throw FatalAstException("can't get size for $decl")
}
}.sum()
override fun accept(visitor: IAstVisitor) = visitor.visit(this)
override fun accept(visitor: IAstModifyingVisitor) = visitor.visit(this)

View File

@ -6,13 +6,12 @@
~ main {
sub start() {
str bla = "asfasd" + "zzz"
str bla2 = "sdfsdf" * 4
c64scr.print(bla)
c64.CHROUT('\n')
c64scr.print(bla2)
c64.CHROUT('\n')
ubyte[] blaat = 10 to 20
for ubyte c in 'a' to 'z' {
c64.CHROUT(blaat[c])
}
}
}