@@ -1872,6 +1872,8 @@ open class KotlinFileExtractor(
18721872 isFunction(target, " kotlin" , " Double" , fName)
18731873 }
18741874
1875+ private fun isNumericFunction (target : IrFunction , fNames : List <String >) = fNames.any { isNumericFunction(target, it) }
1876+
18751877 private fun isArrayType (typeName : String ) =
18761878 when (typeName) {
18771879 " Array" -> true
@@ -1992,63 +1994,110 @@ open class KotlinFileExtractor(
19921994 }
19931995 }
19941996
1997+ fun unaryopReceiver (id : Label <out DbExpr >, receiver : IrExpression ? , receiverDescription : String ) {
1998+ val locId = tw.getLocation(c)
1999+ tw.writeHasLocation(id, locId)
2000+ tw.writeCallableEnclosingExpr(id, callable)
2001+ tw.writeStatementEnclosingExpr(id, enclosingStmt)
2002+
2003+ if (receiver == null ) {
2004+ logger.errorElement(" $receiverDescription not found" , c)
2005+ } else {
2006+ extractExpressionExpr(receiver, callable, id, 0 , enclosingStmt)
2007+ }
2008+ if (c.valueArgumentsCount > 0 ) {
2009+ logger.errorElement(" Extra arguments found" , c)
2010+ }
2011+ }
2012+
19952013 /* *
19962014 * Populate the lhs of a binary op from this call's dispatch receiver, and the rhs from its sole argument.
19972015 */
19982016 fun binopDisp (id : Label <out DbExpr >) {
19992017 binopReceiver(id, c.dispatchReceiver, " Dispatch receiver" )
20002018 }
20012019
2002- /* *
2003- * Populate the lhs of a binary op from this call's extension receiver, and the rhs from its sole argument.
2004- */
2005- fun binopExtensionMethod (id : Label <out DbExpr >) {
2006- binopReceiver(id, c.extensionReceiver, " Extension receiver" )
2020+ fun unaryopDisp (id : Label <out DbExpr >) {
2021+ unaryopReceiver(id, c.dispatchReceiver, " Dispatch receiver" )
20072022 }
20082023
20092024 val dr = c.dispatchReceiver
20102025 when {
2011- isNumericFunction(target, " plus" )
2012- || isFunction(target, " kotlin" , " String" , " plus" , false ) -> {
2026+ isFunction(target, " kotlin" , " String" , " plus" , false ) -> {
20132027 val id = tw.getFreshIdLabel<DbAddexpr >()
20142028 val type = useType(c.type)
20152029 tw.writeExprs_addexpr(id, type.javaResult.id, parent, idx)
20162030 tw.writeExprsKotlinType(id, type.kotlinResult.id)
2017- if (c.extensionReceiver != null )
2018- binopExtensionMethod(id)
2019- else
2020- binopDisp(id)
2031+ binopDisp(id)
20212032 }
20222033 isFunction(target, " kotlin" , " String" , " plus" , true ) -> {
20232034 findJdkIntrinsicOrWarn(" stringPlus" , c)?.let { stringPlusFn ->
20242035 extractRawMethodAccess(stringPlusFn, c, callable, parent, idx, enclosingStmt, listOf (c.extensionReceiver, c.getValueArgument(0 )), null , null )
20252036 }
20262037 }
2027- isNumericFunction(target, " minus" ) -> {
2028- val id = tw.getFreshIdLabel<DbSubexpr >()
2029- val type = useType(c.type)
2030- tw.writeExprs_subexpr(id, type.javaResult.id, parent, idx)
2031- tw.writeExprsKotlinType(id, type.kotlinResult.id)
2032- binopDisp(id)
2033- }
2034- isNumericFunction(target, " times" ) -> {
2035- val id = tw.getFreshIdLabel<DbMulexpr >()
2038+ isNumericFunction(target, listOf (" plus" , " minus" , " times" , " div" , " rem" , " and" , " or" , " xor" , " shl" , " shr" , " ushr" )) -> {
20362039 val type = useType(c.type)
2037- tw.writeExprs_mulexpr(id, type.javaResult.id, parent, idx)
2038- tw.writeExprsKotlinType(id, type.kotlinResult.id)
2039- binopDisp(id)
2040- }
2041- isNumericFunction(target, " div" ) -> {
2042- val id = tw.getFreshIdLabel<DbDivexpr >()
2043- val type = useType(c.type)
2044- tw.writeExprs_divexpr(id, type.javaResult.id, parent, idx)
2045- tw.writeExprsKotlinType(id, type.kotlinResult.id)
2046- binopDisp(id)
2047- }
2048- isNumericFunction(target, " rem" ) -> {
2049- val id = tw.getFreshIdLabel<DbRemexpr >()
2050- val type = useType(c.type)
2051- tw.writeExprs_remexpr(id, type.javaResult.id, parent, idx)
2040+ val id: Label <out DbExpr > = when (val targetName = target.name.asString()) {
2041+ " plus" -> {
2042+ val id = tw.getFreshIdLabel<DbAddexpr >()
2043+ tw.writeExprs_addexpr(id, type.javaResult.id, parent, idx)
2044+ id
2045+ }
2046+ " minus" -> {
2047+ val id = tw.getFreshIdLabel<DbSubexpr >()
2048+ tw.writeExprs_subexpr(id, type.javaResult.id, parent, idx)
2049+ id
2050+ }
2051+ " times" -> {
2052+ val id = tw.getFreshIdLabel<DbMulexpr >()
2053+ tw.writeExprs_mulexpr(id, type.javaResult.id, parent, idx)
2054+ id
2055+ }
2056+ " div" -> {
2057+ val id = tw.getFreshIdLabel<DbDivexpr >()
2058+ tw.writeExprs_divexpr(id, type.javaResult.id, parent, idx)
2059+ id
2060+ }
2061+ " rem" -> {
2062+ val id = tw.getFreshIdLabel<DbRemexpr >()
2063+ tw.writeExprs_remexpr(id, type.javaResult.id, parent, idx)
2064+ id
2065+ }
2066+ " and" -> {
2067+ val id = tw.getFreshIdLabel<DbAndbitexpr >()
2068+ tw.writeExprs_andbitexpr(id, type.javaResult.id, parent, idx)
2069+ id
2070+ }
2071+ " or" -> {
2072+ val id = tw.getFreshIdLabel<DbOrbitexpr >()
2073+ tw.writeExprs_orbitexpr(id, type.javaResult.id, parent, idx)
2074+ id
2075+ }
2076+ " xor" -> {
2077+ val id = tw.getFreshIdLabel<DbXorbitexpr >()
2078+ tw.writeExprs_xorbitexpr(id, type.javaResult.id, parent, idx)
2079+ id
2080+ }
2081+ " shl" -> {
2082+ val id = tw.getFreshIdLabel<DbLshiftexpr >()
2083+ tw.writeExprs_lshiftexpr(id, type.javaResult.id, parent, idx)
2084+ id
2085+ }
2086+ " shr" -> {
2087+ val id = tw.getFreshIdLabel<DbRshiftexpr >()
2088+ tw.writeExprs_rshiftexpr(id, type.javaResult.id, parent, idx)
2089+ id
2090+ }
2091+ " ushr" -> {
2092+ val id = tw.getFreshIdLabel<DbUrshiftexpr >()
2093+ tw.writeExprs_urshiftexpr(id, type.javaResult.id, parent, idx)
2094+ id
2095+ }
2096+ else -> {
2097+ logger.errorElement(" Unhandled target name: $targetName " , c)
2098+ return
2099+ }
2100+ }
20522101 tw.writeExprsKotlinType(id, type.kotlinResult.id)
20532102 binopDisp(id)
20542103 }
@@ -2074,6 +2123,20 @@ open class KotlinFileExtractor(
20742123 tw.writeExprsKotlinType(id, type.kotlinResult.id)
20752124 binOp(id, dr, callable, enclosingStmt)
20762125 }
2126+ isFunction(target, " kotlin" , " Boolean" , " not" ) -> {
2127+ val id = tw.getFreshIdLabel<DbLognotexpr >()
2128+ val type = useType(c.type)
2129+ tw.writeExprs_lognotexpr(id, type.javaResult.id, parent, idx)
2130+ tw.writeExprsKotlinType(id, type.kotlinResult.id)
2131+ unaryopDisp(id)
2132+ }
2133+ isNumericFunction(target, " inv" ) -> {
2134+ val id = tw.getFreshIdLabel<DbBitnotexpr >()
2135+ val type = useType(c.type)
2136+ tw.writeExprs_bitnotexpr(id, type.javaResult.id, parent, idx)
2137+ tw.writeExprsKotlinType(id, type.kotlinResult.id)
2138+ unaryopDisp(id)
2139+ }
20772140 // We need to handle all the builtin operators defines in BuiltInOperatorNames in
20782141 // compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/IrBuiltIns.kt
20792142 // as they can't be extracted as external dependencies.
0 commit comments