Skip to content

Commit

Permalink
Unify JcNumericConstant operators and fix typo in 'minus' operator (#194
Browse files Browse the repository at this point in the history
)

Use actual operators instead of functions in operator implementations. Use '-' instead of erroneous 'div' in 'minus' operator.
  • Loading branch information
Lipen authored Oct 30, 2023
1 parent a3767c8 commit 249b9f0
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions jacodb-api/src/main/kotlin/org/jacodb/api/cfg/JcInst.kt
Original file line number Diff line number Diff line change
Expand Up @@ -906,19 +906,19 @@ data class JcByte(override val value: Byte, override val type: JcType) : JcNumer
}

override fun minus(c: JcNumericConstant): JcNumericConstant {
return JcInt(value.div(c.value.toByte()), type)
return JcInt(value - c.value.toByte(), type)
}

override fun times(c: JcNumericConstant): JcNumericConstant {
return JcInt(value.times(c.value.toByte()), type)
return JcInt(value * c.value.toByte(), type)
}

override fun div(c: JcNumericConstant): JcNumericConstant {
return JcInt(value.div(c.value.toByte()), type)
return JcInt(value / c.value.toByte(), type)
}

override fun rem(c: JcNumericConstant): JcNumericConstant {
return JcInt(value.rem(c.value.toByte()), type)
return JcInt(value % c.value.toByte(), type)
}

override fun unaryMinus(): JcNumericConstant {
Expand Down Expand Up @@ -954,7 +954,7 @@ data class JcShort(override val value: Short, override val type: JcType) : JcNum
}

override fun minus(c: JcNumericConstant): JcNumericConstant {
return JcInt(value.div(c.value.toShort()), type)
return JcInt(value - c.value.toShort(), type)
}

override fun times(c: JcNumericConstant): JcNumericConstant {
Expand All @@ -966,7 +966,7 @@ data class JcShort(override val value: Short, override val type: JcType) : JcNum
}

override fun rem(c: JcNumericConstant): JcNumericConstant {
return JcInt(value.rem(c.value.toShort()), type)
return JcInt(value % c.value.toShort(), type)
}

override fun unaryMinus(): JcNumericConstant {
Expand Down Expand Up @@ -994,7 +994,7 @@ data class JcInt(override val value: Int, override val type: JcType) : JcNumeric
}

override fun minus(c: JcNumericConstant): JcNumericConstant {
return JcInt(value.div(c.value.toInt()), type)
return JcInt(value - c.value.toInt(), type)
}

override fun times(c: JcNumericConstant): JcNumericConstant {
Expand All @@ -1006,7 +1006,7 @@ data class JcInt(override val value: Int, override val type: JcType) : JcNumeric
}

override fun rem(c: JcNumericConstant): JcNumericConstant {
return JcInt(value.rem(c.value.toInt()), type)
return JcInt(value % c.value.toInt(), type)
}

override fun unaryMinus(): JcNumericConstant {
Expand Down Expand Up @@ -1034,19 +1034,19 @@ data class JcLong(override val value: Long, override val type: JcType) : JcNumer
}

override fun minus(c: JcNumericConstant): JcNumericConstant {
return JcLong(value.div(c.value.toLong()), type)
return JcLong(value - c.value.toLong(), type)
}

override fun times(c: JcNumericConstant): JcNumericConstant {
return JcLong(value * c.value.toLong(), type)
}

override fun div(c: JcNumericConstant): JcNumericConstant {
return JcLong(value.div(c.value.toLong()), type)
return JcLong(value / c.value.toLong(), type)
}

override fun rem(c: JcNumericConstant): JcNumericConstant {
return JcLong(value.rem(c.value.toLong()), type)
return JcLong(value % c.value.toLong(), type)
}

override fun unaryMinus(): JcNumericConstant {
Expand Down Expand Up @@ -1074,23 +1074,23 @@ data class JcFloat(override val value: Float, override val type: JcType) : JcNum
}

override fun minus(c: JcNumericConstant): JcNumericConstant {
return JcFloat(value.div(c.value.toFloat()), type)
return JcFloat(value - c.value.toFloat(), type)
}

override fun times(c: JcNumericConstant): JcNumericConstant {
return JcFloat(value * c.value.toFloat(), type)
}

override fun div(c: JcNumericConstant): JcNumericConstant {
return JcFloat(value.div(c.value.toFloat()), type)
return JcFloat(value / c.value.toFloat(), type)
}

override fun rem(c: JcNumericConstant): JcNumericConstant {
return JcFloat(value.rem(c.value.toFloat()), type)
return JcFloat(value % c.value.toFloat(), type)
}

override fun unaryMinus(): JcNumericConstant {
return JcFloat(value.times(-1), type)
return JcFloat(-value, type)
}

override fun isLessThan(c: JcNumericConstant): Boolean {
Expand Down Expand Up @@ -1207,4 +1207,4 @@ data class JcMethodType(
override fun <T> accept(visitor: JcExprVisitor<T>): T {
return visitor.visitJcMethodType(this)
}
}
}

0 comments on commit 249b9f0

Please sign in to comment.