From 6d6db70e42bcd3e43b76fbfeb786bd2a8effe515 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 29 Oct 2022 16:29:41 +0200 Subject: [PATCH] remove type widening for bit shifts, to be consistent with other arithmetic operations. Fixes #83 --- .../astprocessing/StatementReorderer.kt | 50 ------------------- 1 file changed, 50 deletions(-) diff --git a/compiler/src/prog8/compiler/astprocessing/StatementReorderer.kt b/compiler/src/prog8/compiler/astprocessing/StatementReorderer.kt index a9c9ff5c7..b9bdc78a5 100644 --- a/compiler/src/prog8/compiler/astprocessing/StatementReorderer.kt +++ b/compiler/src/prog8/compiler/astprocessing/StatementReorderer.kt @@ -1,13 +1,11 @@ package prog8.compiler.astprocessing import prog8.ast.* -import prog8.ast.base.FatalAstException import prog8.ast.expressions.* import prog8.ast.statements.* import prog8.ast.walk.AstWalker import prog8.ast.walk.IAstModification import prog8.code.core.* -import prog8.compiler.BuiltinFunctions internal class StatementReorderer(val program: Program, val errors: IErrorReporter, @@ -195,54 +193,6 @@ internal class StatementReorderer(val program: Program, && maySwapOperandOrder(expr)) return listOf(IAstModification.SwapOperands(expr)) - // when using a simple bit shift and assigning it to a variable of a different type, - // try to make the bit shifting 'wide enough' to fall into the variable's type. - // with this, for instance, uword x = 1 << 10 will result in 1024 rather than 0 (the ubyte result). - if(expr.operator=="<<" || expr.operator==">>") { - val leftDt = expr.left.inferType(program) - when (parent) { - is Assignment -> { - val targetDt = parent.target.inferType(program) - if(leftDt != targetDt) { - val cast = TypecastExpression(expr.left, targetDt.getOr(DataType.UNDEFINED), true, parent.position) - return listOf(IAstModification.ReplaceNode(expr.left, cast, expr)) - } - } - is VarDecl -> { - if(leftDt isnot parent.datatype) { - val cast = TypecastExpression(expr.left, parent.datatype, true, parent.position) - return listOf(IAstModification.ReplaceNode(expr.left, cast, expr)) - } - } - is IFunctionCall -> { - val argnum = parent.args.indexOf(expr) - when (val callee = parent.target.targetStatement(program)) { - is Subroutine -> { - val paramType = callee.parameters[argnum].type - if(leftDt isAssignableTo paramType) { - val (replaced, cast) = expr.left.typecastTo(paramType, leftDt.getOr(DataType.UNDEFINED), true) - if(replaced) - return listOf(IAstModification.ReplaceNode(expr.left, cast, expr)) - } - } - is BuiltinFunctionPlaceholder -> { - val func = BuiltinFunctions.getValue(callee.name) - val paramTypes = func.parameters[argnum].possibleDatatypes - for(type in paramTypes) { - if(leftDt isAssignableTo type) { - val (replaced, cast) = expr.left.typecastTo(type, leftDt.getOr(DataType.UNDEFINED), true) - if(replaced) - return listOf(IAstModification.ReplaceNode(expr.left, cast, expr)) - } - } - } - else -> throw FatalAstException("weird callee") - } - } - else -> return noModifications - } - } - return noModifications }