@@ -1765,6 +1765,8 @@ open class KotlinFileExtractor(
17651765 isFunction(target, " kotlin" , " Double" , fName)
17661766 }
17671767
1768+ private fun isNumericFunction (target : IrFunction , fNames : List <String >) = fNames.any { isNumericFunction(target, it) }
1769+
17681770 private fun isArrayType (typeName : String ) =
17691771 when (typeName) {
17701772 " Array" -> true
@@ -1901,47 +1903,81 @@ open class KotlinFileExtractor(
19011903
19021904 val dr = c.dispatchReceiver
19031905 when {
1904- isNumericFunction(target, " plus" )
1905- || isFunction(target, " kotlin" , " String" , " plus" , false ) -> {
1906+ isFunction(target, " kotlin" , " String" , " plus" , false ) -> {
19061907 val id = tw.getFreshIdLabel<DbAddexpr >()
19071908 val type = useType(c.type)
19081909 tw.writeExprs_addexpr(id, type.javaResult.id, parent, idx)
19091910 tw.writeExprsKotlinType(id, type.kotlinResult.id)
1910- if (c.extensionReceiver != null )
1911- binopExtensionMethod(id)
1912- else
1913- binopDisp(id)
1911+ binopDisp(id)
19141912 }
19151913 isFunction(target, " kotlin" , " String" , " plus" , true ) -> {
19161914 findJdkIntrinsicOrWarn(" stringPlus" , c)?.let { stringPlusFn ->
19171915 extractRawMethodAccess(stringPlusFn, c, callable, parent, idx, enclosingStmt, listOf (c.extensionReceiver, c.getValueArgument(0 )), null , null )
19181916 }
19191917 }
1920- isNumericFunction(target, " minus" ) -> {
1921- val id = tw.getFreshIdLabel<DbSubexpr >()
1922- val type = useType(c.type)
1923- tw.writeExprs_subexpr(id, type.javaResult.id, parent, idx)
1924- tw.writeExprsKotlinType(id, type.kotlinResult.id)
1925- binopDisp(id)
1926- }
1927- isNumericFunction(target, " times" ) -> {
1928- val id = tw.getFreshIdLabel<DbMulexpr >()
1929- val type = useType(c.type)
1930- tw.writeExprs_mulexpr(id, type.javaResult.id, parent, idx)
1931- tw.writeExprsKotlinType(id, type.kotlinResult.id)
1932- binopDisp(id)
1933- }
1934- isNumericFunction(target, " div" ) -> {
1935- val id = tw.getFreshIdLabel<DbDivexpr >()
1918+ isNumericFunction(target, listOf (" plus" , " minus" , " times" , " div" , " rem" , " and" , " or" , " xor" , " shl" , " shr" , " ushr" )) -> {
19361919 val type = useType(c.type)
1937- tw.writeExprs_divexpr(id, type.javaResult.id, parent, idx)
1938- tw.writeExprsKotlinType(id, type.kotlinResult.id)
1939- binopDisp(id)
1940- }
1941- isNumericFunction(target, " rem" ) -> {
1942- val id = tw.getFreshIdLabel<DbRemexpr >()
1943- val type = useType(c.type)
1944- tw.writeExprs_remexpr(id, type.javaResult.id, parent, idx)
1920+ val id: Label <out DbExpr > = when (val targetName = target.name.asString()) {
1921+ " plus" -> {
1922+ val id = tw.getFreshIdLabel<DbAddexpr >()
1923+ tw.writeExprs_addexpr(id, type.javaResult.id, parent, idx)
1924+ id
1925+ }
1926+ " minus" -> {
1927+ val id = tw.getFreshIdLabel<DbSubexpr >()
1928+ tw.writeExprs_subexpr(id, type.javaResult.id, parent, idx)
1929+ id
1930+ }
1931+ " times" -> {
1932+ val id = tw.getFreshIdLabel<DbMulexpr >()
1933+ tw.writeExprs_mulexpr(id, type.javaResult.id, parent, idx)
1934+ id
1935+ }
1936+ " div" -> {
1937+ val id = tw.getFreshIdLabel<DbDivexpr >()
1938+ tw.writeExprs_divexpr(id, type.javaResult.id, parent, idx)
1939+ id
1940+ }
1941+ " rem" -> {
1942+ val id = tw.getFreshIdLabel<DbRemexpr >()
1943+ tw.writeExprs_remexpr(id, type.javaResult.id, parent, idx)
1944+ id
1945+ }
1946+ " and" -> {
1947+ val id = tw.getFreshIdLabel<DbAndbitexpr >()
1948+ tw.writeExprs_andbitexpr(id, type.javaResult.id, parent, idx)
1949+ id
1950+ }
1951+ " or" -> {
1952+ val id = tw.getFreshIdLabel<DbOrbitexpr >()
1953+ tw.writeExprs_orbitexpr(id, type.javaResult.id, parent, idx)
1954+ id
1955+ }
1956+ " xor" -> {
1957+ val id = tw.getFreshIdLabel<DbXorbitexpr >()
1958+ tw.writeExprs_xorbitexpr(id, type.javaResult.id, parent, idx)
1959+ id
1960+ }
1961+ " shl" -> {
1962+ val id = tw.getFreshIdLabel<DbLshiftexpr >()
1963+ tw.writeExprs_lshiftexpr(id, type.javaResult.id, parent, idx)
1964+ id
1965+ }
1966+ " shr" -> {
1967+ val id = tw.getFreshIdLabel<DbRshiftexpr >()
1968+ tw.writeExprs_rshiftexpr(id, type.javaResult.id, parent, idx)
1969+ id
1970+ }
1971+ " ushr" -> {
1972+ val id = tw.getFreshIdLabel<DbUrshiftexpr >()
1973+ tw.writeExprs_urshiftexpr(id, type.javaResult.id, parent, idx)
1974+ id
1975+ }
1976+ else -> {
1977+ logger.errorElement(" Unhandled target name: $targetName " , c)
1978+ return
1979+ }
1980+ }
19451981 tw.writeExprsKotlinType(id, type.kotlinResult.id)
19461982 binopDisp(id)
19471983 }
0 commit comments