From 749ad700d830fa95f149e577445f1aeed0d7aa86 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Fri, 7 Jan 2022 21:02:37 +0100 Subject: [PATCH] naming consistency for some expression classes --- .../codegen/target/cpu6502/codegen/AsmGen.kt | 10 +++--- .../target/cpu6502/codegen/AsmsubHelpers.kt | 2 +- .../cpu6502/codegen/BuiltinFunctionsAsmGen.kt | 4 +-- .../cpu6502/codegen/ExpressionsAsmGen.kt | 6 ++-- .../target/cpu6502/codegen/ForLoopsAsmGen.kt | 12 +++---- .../codegen/assignment/AsmAssignment.kt | 2 +- .../codegen/assignment/AssignmentAsmGen.kt | 6 ++-- .../optimizer/ConstantFoldingOptimizer.kt | 8 ++--- .../optimizer/ConstantIdentifierReplacer.kt | 6 ++-- .../prog8/optimizer/ExpressionSimplifier.kt | 22 ++++++------ .../src/prog8/optimizer/StatementOptimizer.kt | 4 +-- .../src/prog8/optimizer/UnusedCodeRemover.kt | 2 +- .../compiler/astprocessing/AstChecker.kt | 27 +++++++-------- .../astprocessing/AstIdentifiersChecker.kt | 4 +-- .../compiler/astprocessing/AstPreprocessor.kt | 2 +- .../compiler/astprocessing/CodeDesugarer.kt | 2 +- .../astprocessing/ParentNodeChecker.kt | 4 +-- .../compiler/astprocessing/TypecastsAdder.kt | 2 +- .../compiler/astprocessing/VariousCleanups.kt | 4 +-- .../astprocessing/VerifyFunctionArgTypes.kt | 4 +-- compiler/test/TestCompilerOnRanges.kt | 16 ++++----- compiler/test/TestPipes.kt | 6 ++-- compiler/test/ast/TestProg8Parser.kt | 8 ++--- .../src/prog8/ast/AstToSourceTextConverter.kt | 4 +-- .../src/prog8/ast/antlr/Antlr2Kotlin.kt | 8 ++--- .../prog8/ast/expressions/AstExpressions.kt | 34 +++++++++---------- compilerAst/src/prog8/ast/walk/AstWalker.kt | 12 +++---- compilerAst/src/prog8/ast/walk/IAstVisitor.kt | 4 +-- .../src/prog8/compilerinterface/CallGraph.kt | 2 +- examples/test.p8 | 9 +++-- 30 files changed, 119 insertions(+), 117 deletions(-) diff --git a/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/AsmGen.kt b/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/AsmGen.kt index 75197850b..d13a4f718 100644 --- a/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/AsmGen.kt +++ b/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/AsmGen.kt @@ -956,10 +956,10 @@ class AsmGen(private val program: Program, internal fun translateExpression(expression: Expression) = expressionsAsmGen.translateExpression(expression) - internal fun translateBuiltinFunctionCallExpression(functionCallExpr: FunctionCallExpr, signature: FSignature, resultToStack: Boolean, resultRegister: RegisterOrPair?) = + internal fun translateBuiltinFunctionCallExpression(functionCallExpr: FunctionCallExpression, signature: FSignature, resultToStack: Boolean, resultRegister: RegisterOrPair?) = builtinFunctionsAsmGen.translateFunctioncallExpression(functionCallExpr, signature, resultToStack, resultRegister) - internal fun translateFunctionCall(functionCallExpr: FunctionCallExpr, isExpression: Boolean) = + internal fun translateFunctionCall(functionCallExpr: FunctionCallExpression, isExpression: Boolean) = functioncallAsmGen.translateFunctionCall(functionCallExpr, isExpression) internal fun saveXbeforeCall(functionCall: IFunctionCall) = @@ -1636,7 +1636,7 @@ $label nop""") pipe.expressions.drop(1).dropLast(1).forEach { val callName = it as IdentifierReference val args = mutableListOf(IdentifierReference(valueVar, it.position)) - val call = FunctionCallExpr(callName, args,it.position) + val call = FunctionCallExpression(callName, args,it.position) call.linkParents(pipe) valueDt = call.inferType(program).getOrElse { throw AssemblyError("invalid dt") } valueVar = getTempVarName(valueDt) @@ -1880,7 +1880,7 @@ $label nop""") } if(dt==DataType.UBYTE) { assignExpressionToRegister(left, RegisterOrPair.A, false) - if (left is FunctionCallExpr && !left.isSimple) + if (left is FunctionCallExpression && !left.isSimple) out(" cmp #0") } else { assignExpressionToRegister(left, RegisterOrPair.AY, false) @@ -1896,7 +1896,7 @@ $label nop""") } DataType.BYTE -> { assignExpressionToRegister(left, RegisterOrPair.A, true) - if (left is FunctionCallExpr && !left.isSimple) + if (left is FunctionCallExpression && !left.isSimple) out(" cmp #0") when (operator) { "==" -> out(" bne $jumpIfFalseLabel") diff --git a/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/AsmsubHelpers.kt b/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/AsmsubHelpers.kt index 202588248..33d496c0c 100644 --- a/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/AsmsubHelpers.kt +++ b/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/AsmsubHelpers.kt @@ -44,7 +44,7 @@ internal fun asmsub6502ArgsHaveRegisterClobberRisk(args: List, it.registerOrPair in listOf(RegisterOrPair.Y, RegisterOrPair.AY, RegisterOrPair.XY) } } - is FunctionCallExpr -> { + is FunctionCallExpression -> { if (expr.target.nameInSource == listOf("lsb") || expr.target.nameInSource == listOf("msb")) return isClobberRisk(expr.args[0]) if (expr.target.nameInSource == listOf("mkword")) diff --git a/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/BuiltinFunctionsAsmGen.kt b/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/BuiltinFunctionsAsmGen.kt index 99acffec3..70d4141da 100644 --- a/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/BuiltinFunctionsAsmGen.kt +++ b/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/BuiltinFunctionsAsmGen.kt @@ -19,7 +19,7 @@ import prog8.compilerinterface.subroutineFloatEvalResultVar2 internal class BuiltinFunctionsAsmGen(private val program: Program, private val asmgen: AsmGen, private val assignAsmGen: AssignmentAsmGen) { - internal fun translateFunctioncallExpression(fcall: FunctionCallExpr, func: FSignature, resultToStack: Boolean, resultRegister: RegisterOrPair?) { + internal fun translateFunctioncallExpression(fcall: FunctionCallExpression, func: FSignature, resultToStack: Boolean, resultRegister: RegisterOrPair?) { translateFunctioncall(fcall, func, discardResult = false, resultToStack = resultToStack, resultRegister = resultRegister) } @@ -414,7 +414,7 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val } private fun funcMemory(fcall: IFunctionCall, discardResult: Boolean, resultToStack: Boolean, resultRegister: RegisterOrPair?) { - if(discardResult || fcall !is FunctionCallExpr) + if(discardResult || fcall !is FunctionCallExpression) throw AssemblyError("should not discard result of memory allocation at $fcall") val nameRef = fcall.args[0] as IdentifierReference val name = (nameRef.targetVarDecl(program)!!.value as StringLiteralValue).value diff --git a/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/ExpressionsAsmGen.kt b/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/ExpressionsAsmGen.kt index d85e21f7d..dd545fb69 100644 --- a/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/ExpressionsAsmGen.kt +++ b/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/ExpressionsAsmGen.kt @@ -36,16 +36,16 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge is DirectMemoryRead -> asmgen.translateDirectMemReadExpressionToRegAorStack(expression, true) is NumericLiteralValue -> translateExpression(expression) is IdentifierReference -> translateExpression(expression) - is FunctionCallExpr -> translateFunctionCallResultOntoStack(expression) + is FunctionCallExpression -> translateFunctionCallResultOntoStack(expression) is ContainmentCheck -> throw AssemblyError("containment check as complex expression value is not supported") is ArrayLiteralValue, is StringLiteralValue -> throw AssemblyError("no asm gen for string/array literal value assignment - should have been replaced by a variable") - is RangeExpr -> throw AssemblyError("range expression should have been changed into array values") + is RangeExpression -> throw AssemblyError("range expression should have been changed into array values") is CharLiteral -> throw AssemblyError("charliteral should have been replaced by ubyte using certain encoding") else -> TODO("missing expression asmgen for $expression") } } - private fun translateFunctionCallResultOntoStack(call: FunctionCallExpr) { + private fun translateFunctionCallResultOntoStack(call: FunctionCallExpression) { // only for use in nested expression evaluation val sub = call.target.targetStatement(program) diff --git a/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/ForLoopsAsmGen.kt b/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/ForLoopsAsmGen.kt index fbc693ce2..92aa8a172 100644 --- a/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/ForLoopsAsmGen.kt +++ b/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/ForLoopsAsmGen.kt @@ -5,7 +5,7 @@ import prog8.ast.base.ArrayToElementTypes import prog8.ast.base.DataType import prog8.ast.base.RegisterOrPair import prog8.ast.expressions.IdentifierReference -import prog8.ast.expressions.RangeExpr +import prog8.ast.expressions.RangeExpression import prog8.ast.statements.ForLoop import prog8.ast.toHex import prog8.codegen.target.AssemblyError @@ -18,10 +18,10 @@ internal class ForLoopsAsmGen(private val program: Program, private val asmgen: if(!iterableDt.isKnown) throw AssemblyError("unknown dt") when(stmt.iterable) { - is RangeExpr -> { - val range = (stmt.iterable as RangeExpr).toConstantIntegerRange() + is RangeExpression -> { + val range = (stmt.iterable as RangeExpression).toConstantIntegerRange() if(range==null) { - translateForOverNonconstRange(stmt, iterableDt.getOrElse { throw AssemblyError("unknown dt") }, stmt.iterable as RangeExpr) + translateForOverNonconstRange(stmt, iterableDt.getOrElse { throw AssemblyError("unknown dt") }, stmt.iterable as RangeExpression) } else { translateForOverConstRange(stmt, iterableDt.getOrElse { throw AssemblyError("unknown dt") }, range) } @@ -33,7 +33,7 @@ internal class ForLoopsAsmGen(private val program: Program, private val asmgen: } } - private fun translateForOverNonconstRange(stmt: ForLoop, iterableDt: DataType, range: RangeExpr) { + private fun translateForOverNonconstRange(stmt: ForLoop, iterableDt: DataType, range: RangeExpression) { val loopLabel = asmgen.makeLabel("for_loop") val endLabel = asmgen.makeLabel("for_end") val modifiedLabel = asmgen.makeLabel("for_modified") @@ -587,7 +587,7 @@ $loopLabel""") asmgen.loopEndLabels.pop() } - private fun assignLoopvar(stmt: ForLoop, range: RangeExpr) = + private fun assignLoopvar(stmt: ForLoop, range: RangeExpression) = asmgen.assignExpressionToVariable( range.from, asmgen.asmVariableName(stmt.loopVar), diff --git a/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/assignment/AsmAssignment.kt b/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/assignment/AsmAssignment.kt index a245da8d5..fb9ed3bce 100644 --- a/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/assignment/AsmAssignment.kt +++ b/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/assignment/AsmAssignment.kt @@ -167,7 +167,7 @@ internal class AsmAssignSource(val kind: SourceStorageKind, val dt = value.inferType(program).getOrElse { throw AssemblyError("unknown dt") } AsmAssignSource(SourceStorageKind.ARRAY, program, asmgen, dt, array = value) } - is FunctionCallExpr -> { + is FunctionCallExpression -> { when (val sub = value.target.targetStatement(program)) { is Subroutine -> { val returnType = sub.returntypes.zip(sub.asmReturnvaluesRegisters).firstOrNull { rr -> rr.second.registerOrPair != null || rr.second.statusflag!=null }?.first diff --git a/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/assignment/AssignmentAsmGen.kt b/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/assignment/AssignmentAsmGen.kt index 7c8f7e799..c21957626 100644 --- a/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/assignment/AssignmentAsmGen.kt +++ b/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/assignment/AssignmentAsmGen.kt @@ -159,7 +159,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen is ArrayIndexedExpression -> throw AssemblyError("source kind should have been array") is DirectMemoryRead -> throw AssemblyError("source kind should have been memory") is TypecastExpression -> assignTypeCastedValue(assign.target, value.type, value.expression, value) - is FunctionCallExpr -> { + is FunctionCallExpression -> { when (val sub = value.target.targetStatement(program)) { is Subroutine -> { asmgen.saveXbeforeCall(value) @@ -300,7 +300,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen private fun containmentCheckIntoA(containment: ContainmentCheck) { val elementDt = containment.element.inferType(program) - val range = containment.iterable as? RangeExpr + val range = containment.iterable as? RangeExpression if(range!=null) { val constRange = range.toConstantIntegerRange() if(constRange!=null) @@ -596,7 +596,7 @@ $containsLabel lda #1 } private fun assignCastViaLsbFunc(value: Expression, target: AsmAssignTarget) { - val lsb = FunctionCallExpr(IdentifierReference(listOf("lsb"), value.position), mutableListOf(value), value.position) + val lsb = FunctionCallExpression(IdentifierReference(listOf("lsb"), value.position), mutableListOf(value), value.position) lsb.linkParents(value.parent) val src = AsmAssignSource(SourceStorageKind.EXPRESSION, program, asmgen, DataType.UBYTE, expression = lsb) val assign = AsmAssignment(src, target, false, program.memsizer, value.position) diff --git a/codeOptimizers/src/prog8/optimizer/ConstantFoldingOptimizer.kt b/codeOptimizers/src/prog8/optimizer/ConstantFoldingOptimizer.kt index aa5104eb3..a31d7c0a0 100644 --- a/codeOptimizers/src/prog8/optimizer/ConstantFoldingOptimizer.kt +++ b/codeOptimizers/src/prog8/optimizer/ConstantFoldingOptimizer.kt @@ -310,7 +310,7 @@ class ConstantFoldingOptimizer(private val program: Program) : AstWalker() { return noModifications } - override fun after(functionCallExpr: FunctionCallExpr, parent: Node): Iterable { + override fun after(functionCallExpr: FunctionCallExpression, parent: Node): Iterable { // the args of a fuction are constfolded via recursion already. val constvalue = functionCallExpr.constValue(program) return if(constvalue!=null) @@ -320,7 +320,7 @@ class ConstantFoldingOptimizer(private val program: Program) : AstWalker() { } override fun after(forLoop: ForLoop, parent: Node): Iterable { - fun adjustRangeDt(rangeFrom: NumericLiteralValue, targetDt: DataType, rangeTo: NumericLiteralValue, stepLiteral: NumericLiteralValue?, range: RangeExpr): RangeExpr? { + fun adjustRangeDt(rangeFrom: NumericLiteralValue, targetDt: DataType, rangeTo: NumericLiteralValue, stepLiteral: NumericLiteralValue?, range: RangeExpression): RangeExpression? { val fromCast = rangeFrom.cast(targetDt) val toCast = rangeTo.cast(targetDt) if(!fromCast.isValid || !toCast.isValid) @@ -337,11 +337,11 @@ class ConstantFoldingOptimizer(private val program: Program) : AstWalker() { range.step } - return RangeExpr(fromCast.valueOrZero(), toCast.valueOrZero(), newStep, range.position) + return RangeExpression(fromCast.valueOrZero(), toCast.valueOrZero(), newStep, range.position) } // adjust the datatype of a range expression in for loops to the loop variable. - val iterableRange = forLoop.iterable as? RangeExpr ?: return noModifications + val iterableRange = forLoop.iterable as? RangeExpression ?: return noModifications val rangeFrom = iterableRange.from as? NumericLiteralValue val rangeTo = iterableRange.to as? NumericLiteralValue if(rangeFrom==null || rangeTo==null) return noModifications diff --git a/codeOptimizers/src/prog8/optimizer/ConstantIdentifierReplacer.kt b/codeOptimizers/src/prog8/optimizer/ConstantIdentifierReplacer.kt index c48fcff72..1d026ccbb 100644 --- a/codeOptimizers/src/prog8/optimizer/ConstantIdentifierReplacer.kt +++ b/codeOptimizers/src/prog8/optimizer/ConstantIdentifierReplacer.kt @@ -40,7 +40,7 @@ class VarConstantValueTypeAdjuster(private val program: Program, private val err return noModifications } - override fun after(range: RangeExpr, parent: Node): Iterable { + override fun after(range: RangeExpression, parent: Node): Iterable { val from = range.from.constValue(program)?.number val to = range.to.constValue(program)?.number val step = range.step.constValue(program)?.number @@ -139,7 +139,7 @@ internal class ConstantIdentifierReplacer(private val program: Program, private } } DataType.ARRAY_UB, DataType.ARRAY_B, DataType.ARRAY_UW, DataType.ARRAY_W -> { - val rangeExpr = decl.value as? RangeExpr + val rangeExpr = decl.value as? RangeExpression if(rangeExpr!=null) { // convert the initializer range expression to an actual array val declArraySize = decl.arraysize?.constIndex() @@ -193,7 +193,7 @@ internal class ConstantIdentifierReplacer(private val program: Program, private } } DataType.ARRAY_F -> { - val rangeExpr = decl.value as? RangeExpr + val rangeExpr = decl.value as? RangeExpression if(rangeExpr!=null) { // convert the initializer range expression to an actual array of floats val declArraySize = decl.arraysize?.constIndex() diff --git a/codeOptimizers/src/prog8/optimizer/ExpressionSimplifier.kt b/codeOptimizers/src/prog8/optimizer/ExpressionSimplifier.kt index 401830445..29e07084a 100644 --- a/codeOptimizers/src/prog8/optimizer/ExpressionSimplifier.kt +++ b/codeOptimizers/src/prog8/optimizer/ExpressionSimplifier.kt @@ -209,7 +209,7 @@ class ExpressionSimplifier(private val program: Program, private val errors: IEr // signedw < 0 --> msb(signedw) & $80 return listOf(IAstModification.ReplaceNode( expr, - BinaryExpression(FunctionCallExpr(IdentifierReference(listOf("msb"), expr.position), + BinaryExpression(FunctionCallExpression(IdentifierReference(listOf("msb"), expr.position), mutableListOf(expr.left), expr.position ), "&", NumericLiteralValue.optimalInteger(0x80, expr.position), expr.position), @@ -299,7 +299,7 @@ class ExpressionSimplifier(private val program: Program, private val errors: IEr return noModifications } - override fun after(functionCallExpr: FunctionCallExpr, parent: Node): Iterable { + override fun after(functionCallExpr: FunctionCallExpression, parent: Node): Iterable { if(functionCallExpr.target.nameInSource == listOf("lsb")) { val arg = functionCallExpr.args[0] if(arg is TypecastExpression) { @@ -343,7 +343,7 @@ class ExpressionSimplifier(private val program: Program, private val errors: IEr } override fun after(containment: ContainmentCheck, parent: Node): Iterable { - val range = containment.iterable as? RangeExpr + val range = containment.iterable as? RangeExpression if(range!=null && range.step.constValue(program)?.number==1.0) { val from = range.from.constValue(program) val to = range.to.constValue(program) @@ -365,14 +365,14 @@ class ExpressionSimplifier(private val program: Program, private val errors: IEr val firstValue = pipe.expressions.first() if(firstValue.isSimple) { val funcname = pipe.expressions[1] as IdentifierReference - val first = FunctionCallExpr(funcname.copy(), mutableListOf(firstValue), firstValue.position) + val first = FunctionCallExpression(funcname.copy(), mutableListOf(firstValue), firstValue.position) val newExprs = mutableListOf(first) newExprs.addAll(pipe.expressions.drop(2)) return listOf(IAstModification.ReplaceNode(pipe, Pipe(newExprs, pipe.position), parent)) } val singleExpr = pipe.expressions.singleOrNull() if(singleExpr!=null) { - val callExpr = singleExpr as FunctionCallExpr + val callExpr = singleExpr as FunctionCallExpression val call = FunctionCallStatement(callExpr.target, callExpr.args, true, callExpr.position) return listOf(IAstModification.ReplaceNode(pipe, call, parent)) } @@ -490,7 +490,7 @@ class ExpressionSimplifier(private val program: Program, private val errors: IEr } 0.5 -> { // sqrt(left) - return FunctionCallExpr(IdentifierReference(listOf("sqrt"), expr.position), mutableListOf(expr.left), expr.position) + return FunctionCallExpression(IdentifierReference(listOf("sqrt"), expr.position), mutableListOf(expr.left), expr.position) } 1.0 -> { // left @@ -683,12 +683,12 @@ class ExpressionSimplifier(private val program: Program, private val errors: IEr if (amount >= 16) { return NumericLiteralValue(targetDt, 0.0, expr.position) } else if (amount >= 8) { - val lsb = FunctionCallExpr(IdentifierReference(listOf("lsb"), expr.position), mutableListOf(expr.left), expr.position) + val lsb = FunctionCallExpression(IdentifierReference(listOf("lsb"), expr.position), mutableListOf(expr.left), expr.position) if (amount == 8) { - return FunctionCallExpr(IdentifierReference(listOf("mkword"), expr.position), mutableListOf(lsb, NumericLiteralValue.optimalInteger(0, expr.position)), expr.position) + return FunctionCallExpression(IdentifierReference(listOf("mkword"), expr.position), mutableListOf(lsb, NumericLiteralValue.optimalInteger(0, expr.position)), expr.position) } val shifted = BinaryExpression(lsb, "<<", NumericLiteralValue.optimalInteger(amount - 8, expr.position), expr.position) - return FunctionCallExpr(IdentifierReference(listOf("mkword"), expr.position), mutableListOf(shifted, NumericLiteralValue.optimalInteger(0, expr.position)), expr.position) + return FunctionCallExpression(IdentifierReference(listOf("mkword"), expr.position), mutableListOf(shifted, NumericLiteralValue.optimalInteger(0, expr.position)), expr.position) } } else -> { @@ -725,11 +725,11 @@ class ExpressionSimplifier(private val program: Program, private val errors: IEr return NumericLiteralValue.optimalInteger(0, expr.position) } else if (amount >= 8) { - val msb = FunctionCallExpr(IdentifierReference(listOf("msb"), expr.position), mutableListOf(expr.left), expr.position) + val msb = FunctionCallExpression(IdentifierReference(listOf("msb"), expr.position), mutableListOf(expr.left), expr.position) if (amount == 8) { // mkword(0, msb(v)) val zero = NumericLiteralValue(DataType.UBYTE, 0.0, expr.position) - return FunctionCallExpr(IdentifierReference(listOf("mkword"), expr.position), mutableListOf(zero, msb), expr.position) + return FunctionCallExpression(IdentifierReference(listOf("mkword"), expr.position), mutableListOf(zero, msb), expr.position) } return TypecastExpression(BinaryExpression(msb, ">>", NumericLiteralValue.optimalInteger(amount - 8, expr.position), expr.position), DataType.UWORD, true, expr.position) } diff --git a/codeOptimizers/src/prog8/optimizer/StatementOptimizer.kt b/codeOptimizers/src/prog8/optimizer/StatementOptimizer.kt index cab6a9e1d..c8f435ee9 100644 --- a/codeOptimizers/src/prog8/optimizer/StatementOptimizer.kt +++ b/codeOptimizers/src/prog8/optimizer/StatementOptimizer.kt @@ -17,7 +17,7 @@ class StatementOptimizer(private val program: Program, private val compTarget: ICompilationTarget ) : AstWalker() { - override fun before(functionCallExpr: FunctionCallExpr, parent: Node): Iterable { + override fun before(functionCallExpr: FunctionCallExpression, parent: Node): Iterable { // if the first instruction in the called subroutine is a return statement with a simple value, // remove the jump altogeter and inline the returnvalue directly. @@ -177,7 +177,7 @@ class StatementOptimizer(private val program: Program, } } - val range = forLoop.iterable as? RangeExpr + val range = forLoop.iterable as? RangeExpression if(range!=null) { if (range.size() == 1) { // for loop over a (constant) range of just a single value-- optimize the loop away diff --git a/codeOptimizers/src/prog8/optimizer/UnusedCodeRemover.kt b/codeOptimizers/src/prog8/optimizer/UnusedCodeRemover.kt index 963e326f1..f5b91f060 100644 --- a/codeOptimizers/src/prog8/optimizer/UnusedCodeRemover.kt +++ b/codeOptimizers/src/prog8/optimizer/UnusedCodeRemover.kt @@ -234,7 +234,7 @@ class UnusedCodeRemover(private val program: Program, is PrefixExpression, is BinaryExpression, is TypecastExpression, - is FunctionCallExpr -> { /* don't remove */ } + is FunctionCallExpression -> { /* don't remove */ } else -> linesToRemove.add(assign1) } } diff --git a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt index 12be72981..1923e2df6 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt @@ -4,7 +4,6 @@ import prog8.ast.* import prog8.ast.base.* import prog8.ast.expressions.* import prog8.ast.statements.* -import prog8.ast.walk.IAstModification import prog8.ast.walk.IAstVisitor import prog8.compilerinterface.* import java.io.CharConversionException @@ -86,7 +85,7 @@ internal class AstChecker(private val program: Program, override fun visit(forLoop: ForLoop) { - fun checkUnsignedLoopDownto0(range: RangeExpr?) { + fun checkUnsignedLoopDownto0(range: RangeExpression?) { if(range==null) return val step = range.step.constValue(program)?.number ?: 1.0 @@ -98,7 +97,7 @@ internal class AstChecker(private val program: Program, } val iterableDt = forLoop.iterable.inferType(program).getOr(DataType.BYTE) - if(iterableDt !in IterableDatatypes && forLoop.iterable !is RangeExpr) { + if(iterableDt !in IterableDatatypes && forLoop.iterable !is RangeExpression) { errors.err("can only loop over an iterable type", forLoop.position) } else { val loopvar = forLoop.loopVar.targetVarDecl(program) @@ -110,14 +109,14 @@ internal class AstChecker(private val program: Program, if(iterableDt!= DataType.UBYTE && iterableDt!= DataType.ARRAY_UB && iterableDt != DataType.STR) errors.err("ubyte loop variable can only loop over unsigned bytes or strings", forLoop.position) - checkUnsignedLoopDownto0(forLoop.iterable as? RangeExpr) + checkUnsignedLoopDownto0(forLoop.iterable as? RangeExpression) } DataType.UWORD -> { if(iterableDt!= DataType.UBYTE && iterableDt!= DataType.UWORD && iterableDt != DataType.STR && iterableDt != DataType.ARRAY_UB && iterableDt!= DataType.ARRAY_UW) errors.err("uword loop variable can only loop over unsigned bytes, words or strings", forLoop.position) - checkUnsignedLoopDownto0(forLoop.iterable as? RangeExpr) + checkUnsignedLoopDownto0(forLoop.iterable as? RangeExpression) } DataType.BYTE -> { if(iterableDt!= DataType.BYTE && iterableDt!= DataType.ARRAY_B) @@ -138,7 +137,7 @@ internal class AstChecker(private val program: Program, } if(errors.noErrors()) { // check loop range values - val range = forLoop.iterable as? RangeExpr + val range = forLoop.iterable as? RangeExpression if(range!=null) { val from = range.from as? NumericLiteralValue val to = range.to as? NumericLiteralValue @@ -501,7 +500,7 @@ internal class AstChecker(private val program: Program, } else { val sourceDatatype = assignment.value.inferType(program) if (sourceDatatype.isUnknown) { - if (assignment.value !is FunctionCallExpr) + if (assignment.value !is FunctionCallExpression) errors.err("assignment value is invalid or has no proper datatype", assignment.value.position) } else { checkAssignmentCompatible(targetDatatype.getOr(DataType.BYTE), @@ -556,7 +555,7 @@ internal class AstChecker(private val program: Program, err("unsized array declaration cannot use a single literal initialization value") return } - if(decl.value is RangeExpr) + if(decl.value is RangeExpression) throw FatalAstException("range expressions in vardecls should have been converted into array values during constFolding $decl") } @@ -566,7 +565,7 @@ internal class AstChecker(private val program: Program, null -> { // a vardecl without an initial value, don't bother with it } - is RangeExpr -> throw FatalAstException("range expression should have been converted to a true array value") + is RangeExpression -> throw FatalAstException("range expression should have been converted to a true array value") is StringLiteralValue -> { checkValueTypeAndRangeString(decl.datatype, decl.value as StringLiteralValue) } @@ -901,7 +900,7 @@ internal class AstChecker(private val program: Program, super.visit(typecast) } - override fun visit(range: RangeExpr) { + override fun visit(range: RangeExpression) { fun err(msg: String) { errors.err(msg, range.position) } @@ -934,7 +933,7 @@ internal class AstChecker(private val program: Program, } } - override fun visit(functionCallExpr: FunctionCallExpr) { + override fun visit(functionCallExpr: FunctionCallExpression) { // this function call is (part of) an expression, which should be in a statement somewhere. val stmtOfExpression = findParentNode(functionCallExpr) ?: throw FatalAstException("cannot determine statement scope of function call expression at ${functionCallExpr.position}") @@ -1079,8 +1078,8 @@ internal class AstChecker(private val program: Program, var ident: IdentifierReference? = null if(arg.value is IdentifierReference) ident = arg.value as IdentifierReference - else if(arg.value is FunctionCallExpr) { - val fcall = arg.value as FunctionCallExpr + else if(arg.value is FunctionCallExpression) { + val fcall = arg.value as FunctionCallExpression if(fcall.target.nameInSource == listOf("lsb") || fcall.target.nameInSource == listOf("msb")) ident = fcall.args[0] as? IdentifierReference } @@ -1473,7 +1472,7 @@ internal class AstChecker(private val program: Program, sourceValue: Expression) : Boolean { val position = sourceValue.position - if(sourceValue is RangeExpr) + if(sourceValue is RangeExpression) errors.err("can't assign a range value to something else", position) val result = when(targetDatatype) { diff --git a/compiler/src/prog8/compiler/astprocessing/AstIdentifiersChecker.kt b/compiler/src/prog8/compiler/astprocessing/AstIdentifiersChecker.kt index c0975f997..1dd7fb2b8 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstIdentifiersChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstIdentifiersChecker.kt @@ -4,7 +4,7 @@ import prog8.ast.IFunctionCall import prog8.ast.Node import prog8.ast.Program import prog8.ast.base.Position -import prog8.ast.expressions.FunctionCallExpr +import prog8.ast.expressions.FunctionCallExpression import prog8.ast.expressions.StringLiteralValue import prog8.ast.statements.* import prog8.ast.walk.IAstVisitor @@ -128,7 +128,7 @@ internal class AstIdentifiersChecker(private val errors: IErrorReporter, super.visit(string) } - override fun visit(functionCallExpr: FunctionCallExpr) = visitFunctionCall(functionCallExpr) + override fun visit(functionCallExpr: FunctionCallExpression) = visitFunctionCall(functionCallExpr) override fun visit(functionCallStatement: FunctionCallStatement) = visitFunctionCall(functionCallStatement) private fun visitFunctionCall(call: IFunctionCall) { diff --git a/compiler/src/prog8/compiler/astprocessing/AstPreprocessor.kt b/compiler/src/prog8/compiler/astprocessing/AstPreprocessor.kt index 38b50b816..5cea38db7 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstPreprocessor.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstPreprocessor.kt @@ -12,7 +12,7 @@ import prog8.compilerinterface.IErrorReporter class AstPreprocessor(val program: Program, val errors: IErrorReporter) : AstWalker() { - override fun after(range: RangeExpr, parent: Node): Iterable { + override fun after(range: RangeExpression, parent: Node): Iterable { // has to be done before the constant folding, otherwise certain checks there will fail on invalid range sizes val modifications = mutableListOf() if(range.from !is NumericLiteralValue) { diff --git a/compiler/src/prog8/compiler/astprocessing/CodeDesugarer.kt b/compiler/src/prog8/compiler/astprocessing/CodeDesugarer.kt index 6ec61c430..5c277131f 100644 --- a/compiler/src/prog8/compiler/astprocessing/CodeDesugarer.kt +++ b/compiler/src/prog8/compiler/astprocessing/CodeDesugarer.kt @@ -117,7 +117,7 @@ _after: override fun before(functionCallStatement: FunctionCallStatement, parent: Node) = before(functionCallStatement as IFunctionCall, parent, functionCallStatement.position) - override fun before(functionCallExpr: FunctionCallExpr, parent: Node) = + override fun before(functionCallExpr: FunctionCallExpression, parent: Node) = before(functionCallExpr as IFunctionCall, parent, functionCallExpr.position) private fun before(functionCall: IFunctionCall, parent: Node, position: Position): Iterable { diff --git a/compiler/src/prog8/compiler/astprocessing/ParentNodeChecker.kt b/compiler/src/prog8/compiler/astprocessing/ParentNodeChecker.kt index 25e9febe0..2cea34ec0 100644 --- a/compiler/src/prog8/compiler/astprocessing/ParentNodeChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/ParentNodeChecker.kt @@ -161,7 +161,7 @@ internal class ParentNodeChecker: AstWalker() { return noModifications } - override fun before(range: RangeExpr, parent: Node): Iterable { + override fun before(range: RangeExpression, parent: Node): Iterable { if(range.parent!==parent) throw FatalAstException("parent node mismatch at $range") return noModifications @@ -221,7 +221,7 @@ internal class ParentNodeChecker: AstWalker() { return noModifications } - override fun before(functionCallExpr: FunctionCallExpr, parent: Node): Iterable { + override fun before(functionCallExpr: FunctionCallExpression, parent: Node): Iterable { if(functionCallExpr.parent!==parent) throw FatalAstException("parent node mismatch at $functionCallExpr") return noModifications diff --git a/compiler/src/prog8/compiler/astprocessing/TypecastsAdder.kt b/compiler/src/prog8/compiler/astprocessing/TypecastsAdder.kt index 081340f72..fa1020113 100644 --- a/compiler/src/prog8/compiler/astprocessing/TypecastsAdder.kt +++ b/compiler/src/prog8/compiler/astprocessing/TypecastsAdder.kt @@ -135,7 +135,7 @@ class TypecastsAdder(val program: Program, val options: CompilationOptions, val return afterFunctionCallArgs(functionCallStatement) } - override fun after(functionCallExpr: FunctionCallExpr, parent: Node): Iterable { + override fun after(functionCallExpr: FunctionCallExpression, parent: Node): Iterable { return afterFunctionCallArgs(functionCallExpr) } diff --git a/compiler/src/prog8/compiler/astprocessing/VariousCleanups.kt b/compiler/src/prog8/compiler/astprocessing/VariousCleanups.kt index 7feb57ee5..fd5c05e02 100644 --- a/compiler/src/prog8/compiler/astprocessing/VariousCleanups.kt +++ b/compiler/src/prog8/compiler/astprocessing/VariousCleanups.kt @@ -182,8 +182,8 @@ internal class VariousCleanups(val program: Program, val errors: IErrorReporter, else -> {} } } - is RangeExpr -> { - val constValues = (containment.iterable as RangeExpr).toConstantIntegerRange() + is RangeExpression -> { + val constValues = (containment.iterable as RangeExpression).toConstantIntegerRange() if(constValues!=null) { if (constValues.isEmpty()) return replaceWithFalse() diff --git a/compiler/src/prog8/compiler/astprocessing/VerifyFunctionArgTypes.kt b/compiler/src/prog8/compiler/astprocessing/VerifyFunctionArgTypes.kt index e15db43f6..8c8d0a4f8 100644 --- a/compiler/src/prog8/compiler/astprocessing/VerifyFunctionArgTypes.kt +++ b/compiler/src/prog8/compiler/astprocessing/VerifyFunctionArgTypes.kt @@ -4,7 +4,7 @@ import prog8.ast.IFunctionCall import prog8.ast.Program import prog8.ast.base.DataType import prog8.ast.expressions.Expression -import prog8.ast.expressions.FunctionCallExpr +import prog8.ast.expressions.FunctionCallExpression import prog8.ast.expressions.TypecastExpression import prog8.ast.statements.* import prog8.ast.walk.IAstVisitor @@ -13,7 +13,7 @@ import prog8.compilerinterface.InternalCompilerException internal class VerifyFunctionArgTypes(val program: Program) : IAstVisitor { - override fun visit(functionCallExpr: FunctionCallExpr) { + override fun visit(functionCallExpr: FunctionCallExpression) { val error = checkTypes(functionCallExpr as IFunctionCall, program) if(error!=null) throw InternalCompilerException(error) diff --git a/compiler/test/TestCompilerOnRanges.kt b/compiler/test/TestCompilerOnRanges.kt index 5cfdc7f27..76145d1b7 100644 --- a/compiler/test/TestCompilerOnRanges.kt +++ b/compiler/test/TestCompilerOnRanges.kt @@ -145,7 +145,7 @@ class TestCompilerOnRanges: FunSpec({ val iterable = startSub .statements.filterIsInstance() .map { it.iterable }[0] - val rangeExpr = iterable as RangeExpr + val rangeExpr = iterable as RangeExpression val expectedStart = platform.encodeString("a", true)[0].toInt() val expectedEnd = platform.encodeString("f", false)[0].toInt() @@ -179,7 +179,7 @@ class TestCompilerOnRanges: FunSpec({ val rangeExpr = startSub .statements.filterIsInstance() .map { it.iterable } - .filterIsInstance()[0] + .filterIsInstance()[0] rangeExpr.size() shouldBe 2 val intProgression = rangeExpr.toConstantIntegerRange() @@ -205,7 +205,7 @@ class TestCompilerOnRanges: FunSpec({ val rangeExpr = startSub .statements.filterIsInstance() .map { it.iterable } - .filterIsInstance()[0] + .filterIsInstance()[0] rangeExpr.size() shouldBe 9 val intProgression = rangeExpr.toConstantIntegerRange() @@ -253,7 +253,7 @@ class TestCompilerOnRanges: FunSpec({ } test("testRangeExprNumericSize") { - val expr = RangeExpr( + val expr = RangeExpression( NumericLiteralValue.optimalInteger(10, Position.DUMMY), NumericLiteralValue.optimalInteger(20, Position.DUMMY), NumericLiteralValue.optimalInteger(2, Position.DUMMY), @@ -278,8 +278,8 @@ class TestCompilerOnRanges: FunSpec({ array shouldBe instanceOf() (array as ArrayLiteralValue).value.size shouldBe 26 val forloop = (statements.dropLast(1).last() as ForLoop) - forloop.iterable shouldBe instanceOf() - (forloop.iterable as RangeExpr).step shouldBe NumericLiteralValue(DataType.UBYTE, -2.0, Position.DUMMY) + forloop.iterable shouldBe instanceOf() + (forloop.iterable as RangeExpression).step shouldBe NumericLiteralValue(DataType.UBYTE, -2.0, Position.DUMMY) } test("range with start/end variables should be ok") { @@ -296,8 +296,8 @@ class TestCompilerOnRanges: FunSpec({ """).assertSuccess() val statements = result.program.entrypoint.statements val forloop = (statements.dropLast(1).last() as ForLoop) - forloop.iterable shouldBe instanceOf() - (forloop.iterable as RangeExpr).step shouldBe NumericLiteralValue(DataType.UBYTE, -2.0, Position.DUMMY) + forloop.iterable shouldBe instanceOf() + (forloop.iterable as RangeExpression).step shouldBe NumericLiteralValue(DataType.UBYTE, -2.0, Position.DUMMY) } diff --git a/compiler/test/TestPipes.kt b/compiler/test/TestPipes.kt index dfa2a8aac..43727e9f7 100644 --- a/compiler/test/TestPipes.kt +++ b/compiler/test/TestPipes.kt @@ -4,7 +4,7 @@ import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.shouldBe import io.kotest.matchers.string.shouldContain import io.kotest.matchers.types.instanceOf -import prog8.ast.expressions.FunctionCallExpr +import prog8.ast.expressions.FunctionCallExpression import prog8.ast.expressions.IdentifierReference import prog8.ast.statements.Pipe import prog8.codegen.target.C64Target @@ -45,12 +45,12 @@ class TestPipes: FunSpec({ stmts.size shouldBe 3 val pipef = stmts[0] as Pipe pipef.expressions.size shouldBe 2 - pipef.expressions[0] shouldBe instanceOf() + pipef.expressions[0] shouldBe instanceOf() pipef.expressions[1] shouldBe instanceOf() val pipew = stmts[1] as Pipe pipew.expressions.size shouldBe 2 - pipew.expressions[0] shouldBe instanceOf() + pipew.expressions[0] shouldBe instanceOf() pipew.expressions[1] shouldBe instanceOf() } diff --git a/compiler/test/ast/TestProg8Parser.kt b/compiler/test/ast/TestProg8Parser.kt index 8bfe26dfc..3460c6349 100644 --- a/compiler/test/ast/TestProg8Parser.kt +++ b/compiler/test/ast/TestProg8Parser.kt @@ -512,22 +512,22 @@ class TestProg8Parser: FunSpec( { iterables.size shouldBe 5 - val it0 = iterables[0] as RangeExpr + val it0 = iterables[0] as RangeExpression it0.from shouldBe instanceOf() it0.to shouldBe instanceOf() val it1 = iterables[1] as StringLiteralValue it1.value shouldBe "something" - val it2 = iterables[2] as RangeExpr + val it2 = iterables[2] as RangeExpression it2.from shouldBe instanceOf() it2.to shouldBe instanceOf() - val it3 = iterables[3] as RangeExpr + val it3 = iterables[3] as RangeExpression it3.from shouldBe instanceOf() it3.to shouldBe instanceOf() - val it4 = iterables[4] as RangeExpr + val it4 = iterables[4] as RangeExpression it4.from shouldBe instanceOf() it4.to shouldBe instanceOf() } diff --git a/compilerAst/src/prog8/ast/AstToSourceTextConverter.kt b/compilerAst/src/prog8/ast/AstToSourceTextConverter.kt index f1274512b..d6375649a 100644 --- a/compilerAst/src/prog8/ast/AstToSourceTextConverter.kt +++ b/compilerAst/src/prog8/ast/AstToSourceTextConverter.kt @@ -201,7 +201,7 @@ class AstToSourceTextConverter(val output: (text: String) -> Unit, val program: } } - override fun visit(functionCallExpr: FunctionCallExpr) { + override fun visit(functionCallExpr: FunctionCallExpression) { printout(functionCallExpr as IFunctionCall) } @@ -262,7 +262,7 @@ class AstToSourceTextConverter(val output: (text: String) -> Unit, val program: } } - override fun visit(range: RangeExpr) { + override fun visit(range: RangeExpression) { range.from.accept(this) output(" to ") range.to.accept(this) diff --git a/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt b/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt index 0195febd9..52e3be0cc 100644 --- a/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt +++ b/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt @@ -283,12 +283,12 @@ private fun Prog8ANTLRParser.Functioncall_stmtContext.toAst(): Statement { FunctionCallStatement(location, expression_list().toAst().toMutableList(), void, toPosition()) } -private fun Prog8ANTLRParser.FunctioncallContext.toAst(): FunctionCallExpr { +private fun Prog8ANTLRParser.FunctioncallContext.toAst(): FunctionCallExpression { val location = scoped_identifier().toAst() return if(expression_list() == null) - FunctionCallExpr(location, mutableListOf(), toPosition()) + FunctionCallExpression(location, mutableListOf(), toPosition()) else - FunctionCallExpr(location, expression_list().toAst().toMutableList(), toPosition()) + FunctionCallExpression(location, expression_list().toAst().toMutableList(), toPosition()) } private fun Prog8ANTLRParser.InlineasmContext.toAst(): InlineAssembly { @@ -463,7 +463,7 @@ private fun Prog8ANTLRParser.ExpressionContext.toAst() : Expression { if (rangefrom!=null && rangeto!=null) { val defaultstep = if(rto.text == "to") 1 else -1 val step = rangestep?.toAst() ?: NumericLiteralValue(DataType.UBYTE, defaultstep.toDouble(), toPosition()) - return RangeExpr(rangefrom.toAst(), rangeto.toAst(), step, toPosition()) + return RangeExpression(rangefrom.toAst(), rangeto.toAst(), step, toPosition()) } if(childCount==3 && children[0].text=="(" && children[2].text==")") diff --git a/compilerAst/src/prog8/ast/expressions/AstExpressions.kt b/compilerAst/src/prog8/ast/expressions/AstExpressions.kt index f9598ec0d..2a0cf4d82 100644 --- a/compilerAst/src/prog8/ast/expressions/AstExpressions.kt +++ b/compilerAst/src/prog8/ast/expressions/AstExpressions.kt @@ -64,11 +64,11 @@ sealed class Expression: Node { is AddressOf -> { (other is AddressOf && other.identifier.nameInSource == identifier.nameInSource) } - is RangeExpr -> { - (other is RangeExpr && other.from==from && other.to==to && other.step==step) + is RangeExpression -> { + (other is RangeExpression && other.from==from && other.to==to && other.step==step) } - is FunctionCallExpr -> { - (other is FunctionCallExpr && other.target.nameInSource == target.nameInSource + is FunctionCallExpression -> { + (other is FunctionCallExpression && other.target.nameInSource == target.nameInSource && other.args.size == args.size && other.args.zip(args).all { it.first isSameAs it.second } ) } @@ -747,10 +747,10 @@ class ArrayLiteralValue(val type: InferredTypes.InferredType, // inferred be } } -class RangeExpr(var from: Expression, - var to: Expression, - var step: Expression, - override val position: Position) : Expression() { +class RangeExpression(var from: Expression, + var to: Expression, + var step: Expression, + override val position: Position) : Expression() { override lateinit var parent: Node override fun linkParents(parent: Node) { @@ -773,7 +773,7 @@ class RangeExpr(var from: Expression, replacement.parent = this } - override fun copy() = RangeExpr(from.copy(), to.copy(), step.copy(), position) + override fun copy() = RangeExpression(from.copy(), to.copy(), step.copy(), position) override fun constValue(program: Program): NumericLiteralValue? = null override fun accept(visitor: IAstVisitor) = visitor.visit(this) override fun accept(visitor: AstWalker, parent: Node)= visitor.visit(this, parent) @@ -906,9 +906,9 @@ data class IdentifierReference(val nameInSource: List, override val posi } } -class FunctionCallExpr(override var target: IdentifierReference, - override var args: MutableList, - override val position: Position) : Expression(), IFunctionCall { +class FunctionCallExpression(override var target: IdentifierReference, + override var args: MutableList, + override val position: Position) : Expression(), IFunctionCall { override lateinit var parent: Node override fun linkParents(parent: Node) { @@ -917,7 +917,7 @@ class FunctionCallExpr(override var target: IdentifierReference, args.forEach { it.linkParents(this) } } - override fun copy() = FunctionCallExpr(target.copy(), args.map { it.copy() }.toMutableList(), position) + override fun copy() = FunctionCallExpression(target.copy(), args.map { it.copy() }.toMutableList(), position) override val isSimple = target.nameInSource.size==1 && (target.nameInSource[0] in arrayOf("msb", "lsb", "peek", "peekw")) override fun replaceChildNode(node: Node, replacement: Node) { @@ -1011,8 +1011,8 @@ class ContainmentCheck(var element: Expression, val exists = (iterable as ArrayLiteralValue).value.any { it.constValue(program)==elementConst } return NumericLiteralValue.fromBoolean(exists, position) } - is RangeExpr -> { - val intRange = (iterable as RangeExpr).toConstantIntegerRange() + is RangeExpression -> { + val intRange = (iterable as RangeExpression).toConstantIntegerRange() if(intRange!=null && elementConst.type in IntegerDatatypes) { val exists = elementConst.number.toInt() in intRange return NumericLiteralValue.fromBoolean(exists, position) @@ -1035,8 +1035,8 @@ class ContainmentCheck(var element: Expression, if(array.value.isEmpty()) return NumericLiteralValue.fromBoolean(false, position) } - is RangeExpr -> { - val size = (iterable as RangeExpr).size() + is RangeExpression -> { + val size = (iterable as RangeExpression).size() if(size!=null && size==0) return NumericLiteralValue.fromBoolean(false, position) } diff --git a/compilerAst/src/prog8/ast/walk/AstWalker.kt b/compilerAst/src/prog8/ast/walk/AstWalker.kt index 987d988d8..92d8e0aa8 100644 --- a/compilerAst/src/prog8/ast/walk/AstWalker.kt +++ b/compilerAst/src/prog8/ast/walk/AstWalker.kt @@ -94,7 +94,7 @@ abstract class AstWalker { open fun before(expr: PrefixExpression, parent: Node): Iterable = noModifications open fun before(forLoop: ForLoop, parent: Node): Iterable = noModifications open fun before(repeatLoop: RepeatLoop, parent: Node): Iterable = noModifications - open fun before(functionCallExpr: FunctionCallExpr, parent: Node): Iterable = noModifications + open fun before(functionCallExpr: FunctionCallExpression, parent: Node): Iterable = noModifications open fun before(functionCallStatement: FunctionCallStatement, parent: Node): Iterable = noModifications open fun before(identifier: IdentifierReference, parent: Node): Iterable = noModifications open fun before(ifElse: IfElse, parent: Node): Iterable = noModifications @@ -109,7 +109,7 @@ abstract class AstWalker { open fun before(numLiteral: NumericLiteralValue, parent: Node): Iterable = noModifications open fun before(postIncrDecr: PostIncrDecr, parent: Node): Iterable = noModifications open fun before(program: Program): Iterable = noModifications - open fun before(range: RangeExpr, parent: Node): Iterable = noModifications + open fun before(range: RangeExpression, parent: Node): Iterable = noModifications open fun before(untilLoop: UntilLoop, parent: Node): Iterable = noModifications open fun before(returnStmt: Return, parent: Node): Iterable = noModifications open fun before(scope: AnonymousScope, parent: Node): Iterable = noModifications @@ -138,7 +138,7 @@ abstract class AstWalker { open fun after(expr: PrefixExpression, parent: Node): Iterable = noModifications open fun after(forLoop: ForLoop, parent: Node): Iterable = noModifications open fun after(repeatLoop: RepeatLoop, parent: Node): Iterable = noModifications - open fun after(functionCallExpr: FunctionCallExpr, parent: Node): Iterable = noModifications + open fun after(functionCallExpr: FunctionCallExpression, parent: Node): Iterable = noModifications open fun after(functionCallStatement: FunctionCallStatement, parent: Node): Iterable = noModifications open fun after(identifier: IdentifierReference, parent: Node): Iterable = noModifications open fun after(ifElse: IfElse, parent: Node): Iterable = noModifications @@ -153,7 +153,7 @@ abstract class AstWalker { open fun after(numLiteral: NumericLiteralValue, parent: Node): Iterable = noModifications open fun after(postIncrDecr: PostIncrDecr, parent: Node): Iterable = noModifications open fun after(program: Program): Iterable = noModifications - open fun after(range: RangeExpr, parent: Node): Iterable = noModifications + open fun after(range: RangeExpression, parent: Node): Iterable = noModifications open fun after(untilLoop: UntilLoop, parent: Node): Iterable = noModifications open fun after(returnStmt: Return, parent: Node): Iterable = noModifications open fun after(scope: AnonymousScope, parent: Node): Iterable = noModifications @@ -258,7 +258,7 @@ abstract class AstWalker { track(after(subroutine, parent), subroutine, parent) } - fun visit(functionCallExpr: FunctionCallExpr, parent: Node) { + fun visit(functionCallExpr: FunctionCallExpression, parent: Node) { track(before(functionCallExpr, parent), functionCallExpr, parent) functionCallExpr.target.accept(this, functionCallExpr) functionCallExpr.args.forEach { it.accept(this, functionCallExpr) } @@ -304,7 +304,7 @@ abstract class AstWalker { track(after(branch, parent), branch, parent) } - fun visit(range: RangeExpr, parent: Node) { + fun visit(range: RangeExpression, parent: Node) { track(before(range, parent), range, parent) range.from.accept(this, range) range.to.accept(this, range) diff --git a/compilerAst/src/prog8/ast/walk/IAstVisitor.kt b/compilerAst/src/prog8/ast/walk/IAstVisitor.kt index d4db1402a..2fb101127 100644 --- a/compilerAst/src/prog8/ast/walk/IAstVisitor.kt +++ b/compilerAst/src/prog8/ast/walk/IAstVisitor.kt @@ -44,7 +44,7 @@ interface IAstVisitor { subroutine.statements.forEach { it.accept(this) } } - fun visit(functionCallExpr: FunctionCallExpr) { + fun visit(functionCallExpr: FunctionCallExpression) { functionCallExpr.target.accept(this) functionCallExpr.args.forEach { it.accept(this) } } @@ -76,7 +76,7 @@ interface IAstVisitor { branch.elsepart.accept(this) } - fun visit(range: RangeExpr) { + fun visit(range: RangeExpression) { range.from.accept(this) range.to.accept(this) range.step.accept(this) diff --git a/compilerInterfaces/src/prog8/compilerinterface/CallGraph.kt b/compilerInterfaces/src/prog8/compilerinterface/CallGraph.kt index 3ff0e824a..37d052698 100644 --- a/compilerInterfaces/src/prog8/compilerinterface/CallGraph.kt +++ b/compilerInterfaces/src/prog8/compilerinterface/CallGraph.kt @@ -57,7 +57,7 @@ class CallGraph(private val program: Program) : IAstVisitor { super.visit(directive) } - override fun visit(functionCallExpr: FunctionCallExpr) { + override fun visit(functionCallExpr: FunctionCallExpression) { val otherSub = functionCallExpr.target.targetSubroutine(program) if (otherSub != null) { functionCallExpr.definingSubroutine?.let { thisSub -> diff --git a/examples/test.p8 b/examples/test.p8 index 70844469c..8611eb77b 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -3,9 +3,12 @@ main { sub start() { - 9 + 3 - |> add_one |> times_two - |> txt.print_uw + times_two(554 as ubyte) +; txt.print_uw(times_two(add_one(9+3))) +; txt.nl() +; 9 + 3 +; |> add_one |> times_two +; |> txt.print_uw } sub add_one(ubyte input) -> ubyte {