mirror of
https://github.com/KarolS/millfork.git
synced 2025-01-27 11:30:19 +00:00
Division by zero warnings
This commit is contained in:
parent
7194bc1f1c
commit
088b28989f
@ -273,6 +273,11 @@ abstract class AbstractStatementPreprocessor(ctx: CompilationContext, statements
|
||||
case LiteralExpression(0, _) => true
|
||||
case _ => false
|
||||
}) ctx.log.warn("Multiplication by zero.", params.head.position)
|
||||
case FunctionCallExpression("/" | "/=" | "%%" | "%%=", params) =>
|
||||
if (params.tail.exists {
|
||||
case LiteralExpression(0, _) => true
|
||||
case _ => false
|
||||
}) ctx.log.warn("Division by zero.", params.head.position)
|
||||
case FunctionCallExpression("<<" | ">>" | "<<'" | "<<=" | ">>=" | "<<'=" | ">>>>", List(lhs@_, LiteralExpression(0, _))) =>
|
||||
ctx.log.warn("Shift by zero.", lhs.position)
|
||||
case _ =>
|
||||
|
@ -145,8 +145,14 @@ abstract class AbstractAssembler[T <: AbstractCode](private val program: Program
|
||||
case MathOperator.And => l & r
|
||||
case MathOperator.Exor => l ^ r
|
||||
case MathOperator.Or => l | r
|
||||
case MathOperator.Divide => l / r
|
||||
case MathOperator.Modulo => l % r
|
||||
case MathOperator.Divide => if (r == 0) {
|
||||
log.error("Constant division by zero")
|
||||
0
|
||||
} else l / r
|
||||
case MathOperator.Modulo => if (r == 0) {
|
||||
log.error("Constant division by zero")
|
||||
0
|
||||
} else l % r
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user