@@ -172,7 +172,7 @@ fun doFile(invocationTrapFile: String,
172172}
173173
174174fun <T > fakeLabel (): Label <T > {
175- if (true ) {
175+ if (false ) {
176176 println (" Fake label" )
177177 } else {
178178 val sw = StringWriter ()
@@ -1414,53 +1414,144 @@ open class KotlinFileExtractor(
14141414 }
14151415
14161416 fun extractCall (c : IrCall , callable : Label <out DbCallable >, parent : Label <out DbExprparent >, idx : Int ) {
1417- val exprId: Label <out DbExpr > = when (c.origin) {
1418- PLUS -> {
1417+ fun isFunction (pkgName : String , className : String? , fName : String ): Boolean {
1418+ val verbose = false
1419+ fun verboseln (s : String ) { if (verbose) println (s) }
1420+ verboseln(" Attempting match for $pkgName $className $fName " )
1421+ val target = c.symbol.owner
1422+ if (target.name.asString() != fName) {
1423+ verboseln(" No match as function name is ${target.name.asString()} not $fName " )
1424+ return false
1425+ }
1426+ val extensionReceiverParameter = target.extensionReceiverParameter
1427+ val targetClass = if (extensionReceiverParameter == null ) target.parent
1428+ else (extensionReceiverParameter.type as ? IrSimpleType )?.classifier?.owner
1429+ val targetPkg =
1430+ if (className != null ) {
1431+ if (targetClass !is IrClass ) {
1432+ verboseln(" No match as didn't find target class" )
1433+ return false
1434+ }
1435+ if (targetClass.name.asString() != className) {
1436+ verboseln(" No match as class name is ${targetClass.name.asString()} not $className " )
1437+ return false
1438+ }
1439+ targetClass.parent
1440+ } else {
1441+ targetClass
1442+ }
1443+ if (targetPkg !is IrPackageFragment ) {
1444+ verboseln(" No match as didn't find target package" )
1445+ return false
1446+ }
1447+ if (targetPkg.fqName.asString() != pkgName) {
1448+ verboseln(" No match as class name is ${targetPkg.fqName.asString()} not $pkgName " )
1449+ return false
1450+ }
1451+ verboseln(" Match" )
1452+ return true
1453+ }
1454+
1455+ fun binopDisp (id : Label <out DbExpr >) {
1456+ val locId = tw.getLocation(c)
1457+ tw.writeHasLocation(id, locId)
1458+ tw.writeCallableEnclosingExpr(id, callable)
1459+
1460+ val dr = c.dispatchReceiver
1461+ if (dr == null ) {
1462+ logger.warnElement(Severity .ErrorSevere , " Dispatch receiver not found" , c)
1463+ } else {
1464+ extractExpressionExpr(dr, callable, id, 0 )
1465+ }
1466+ if (c.valueArgumentsCount < 1 ) {
1467+ logger.warnElement(Severity .ErrorSevere , " No RHS found" , c)
1468+ } else {
1469+ if (c.valueArgumentsCount > 1 ) {
1470+ logger.warnElement(Severity .ErrorSevere , " Extra arguments found" , c)
1471+ }
1472+ val arg = c.getValueArgument(0 )
1473+ if (arg == null ) {
1474+ logger.warnElement(Severity .ErrorSevere , " RHS null" , c)
1475+ } else {
1476+ extractExpressionExpr(arg, callable, id, 1 )
1477+ }
1478+ }
1479+ }
1480+
1481+ fun binop (id : Label <out DbExpr >) {
1482+ val locId = tw.getLocation(c)
1483+ tw.writeHasLocation(id, locId)
1484+ tw.writeCallableEnclosingExpr(id, callable)
1485+
1486+ val dr = c.dispatchReceiver
1487+ if (dr != null ) {
1488+ logger.warnElement(Severity .ErrorSevere , " Unexpected dispatch receiver found" , c)
1489+ }
1490+ if (c.valueArgumentsCount < 1 ) {
1491+ logger.warnElement(Severity .ErrorSevere , " No arguments found" , c)
1492+ } else {
1493+ val lhs = c.getValueArgument(0 )
1494+ if (lhs == null ) {
1495+ logger.warnElement(Severity .ErrorSevere , " LHS null" , c)
1496+ } else {
1497+ extractExpressionExpr(lhs, callable, id, 0 )
1498+ }
1499+ if (c.valueArgumentsCount < 2 ) {
1500+ logger.warnElement(Severity .ErrorSevere , " No RHS found" , c)
1501+ } else {
1502+ val rhs = c.getValueArgument(1 )
1503+ if (rhs == null ) {
1504+ logger.warnElement(Severity .ErrorSevere , " RHS null" , c)
1505+ } else {
1506+ extractExpressionExpr(rhs, callable, id, 1 )
1507+ }
1508+ }
1509+ if (c.valueArgumentsCount > 2 ) {
1510+ logger.warnElement(Severity .ErrorSevere , " Extra arguments found" , c)
1511+ }
1512+ }
1513+ }
1514+
1515+ when {
1516+ c.origin == PLUS &&
1517+ (isFunction(" kotlin" , " Int" , " plus" ) || isFunction(" kotlin" , " String" , " plus" )) -> {
14191518 val id = tw.getFreshIdLabel<DbAddexpr >()
14201519 val type = useType(c.type)
1421- val locId = tw.getLocation(c)
14221520 tw.writeExprs_addexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
1423- tw.writeHasLocation(id, locId)
1424- tw.writeCallableEnclosingExpr(id, callable)
1521+ binopDisp(id)
14251522 id
14261523 }
1427- MINUS -> {
1524+ c.origin == MINUS && isFunction( " kotlin " , " Int " , " minus " ) -> {
14281525 val id = tw.getFreshIdLabel<DbSubexpr >()
14291526 val type = useType(c.type)
1430- val locId = tw.getLocation(c)
14311527 tw.writeExprs_subexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
1432- tw.writeHasLocation(id, locId)
1433- tw.writeCallableEnclosingExpr(id, callable)
1528+ binopDisp(id)
14341529 id
14351530 }
1436- DIV -> {
1531+ c.origin == DIV && isFunction( " kotlin " , " Int " , " div " ) -> {
14371532 val id = tw.getFreshIdLabel<DbDivexpr >()
14381533 val type = useType(c.type)
1439- val locId = tw.getLocation(c)
14401534 tw.writeExprs_divexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
1441- tw.writeHasLocation(id, locId)
1442- tw.writeCallableEnclosingExpr(id, callable)
1535+ binopDisp(id)
14431536 id
14441537 }
1445- PERC -> {
1538+ c.origin == PERC && isFunction( " kotlin " , " Int " , " rem " ) -> {
14461539 val id = tw.getFreshIdLabel<DbRemexpr >()
14471540 val type = useType(c.type)
1448- val locId = tw.getLocation(c)
14491541 tw.writeExprs_remexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
1450- tw.writeHasLocation(id, locId)
1451- tw.writeCallableEnclosingExpr(id, callable)
1542+ binopDisp(id)
14521543 id
14531544 }
1454- EQEQ -> {
1545+ c.origin == EQEQ && isFunction( " kotlin.internal.ir " , null , " EQEQ " ) -> {
14551546 val id = tw.getFreshIdLabel<DbEqexpr >()
14561547 val type = useType(c.type)
1457- val locId = tw.getLocation(c)
14581548 tw.writeExprs_eqexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
1459- tw.writeHasLocation(id, locId)
1460- tw.writeCallableEnclosingExpr(id, callable)
1549+ binop(id)
14611550 id
14621551 }
1463- EXCLEQ -> {
1552+ /*
1553+ TODO
1554+ c.origin == EXCLEQ -> {
14641555 val id = tw.getFreshIdLabel<DbNeexpr>()
14651556 val type = useType(c.type)
14661557 val locId = tw.getLocation(c)
@@ -1469,40 +1560,33 @@ open class KotlinFileExtractor(
14691560 tw.writeCallableEnclosingExpr(id, callable)
14701561 id
14711562 }
1472- LT -> {
1563+ */
1564+ c.origin == LT && isFunction(" kotlin.internal.ir" , null , " less" ) -> {
14731565 val id = tw.getFreshIdLabel<DbLtexpr >()
14741566 val type = useType(c.type)
1475- val locId = tw.getLocation(c)
14761567 tw.writeExprs_ltexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
1477- tw.writeHasLocation(id, locId)
1478- tw.writeCallableEnclosingExpr(id, callable)
1568+ binop(id)
14791569 id
14801570 }
1481- LTEQ -> {
1571+ c.origin == LTEQ && isFunction( " kotlin.internal.ir " , null , " lessOrEqual " ) -> {
14821572 val id = tw.getFreshIdLabel<DbLeexpr >()
14831573 val type = useType(c.type)
1484- val locId = tw.getLocation(c)
14851574 tw.writeExprs_leexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
1486- tw.writeHasLocation(id, locId)
1487- tw.writeCallableEnclosingExpr(id, callable)
1575+ binop(id)
14881576 id
14891577 }
1490- GT -> {
1578+ c.origin == GT && isFunction( " kotlin.internal.ir " , null , " greater " ) -> {
14911579 val id = tw.getFreshIdLabel<DbGtexpr >()
14921580 val type = useType(c.type)
1493- val locId = tw.getLocation(c)
14941581 tw.writeExprs_gtexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
1495- tw.writeHasLocation(id, locId)
1496- tw.writeCallableEnclosingExpr(id, callable)
1582+ binop(id)
14971583 id
14981584 }
1499- GTEQ -> {
1585+ c.origin == GTEQ && isFunction( " kotlin.internal.ir " , null , " greaterOrEqual " ) -> {
15001586 val id = tw.getFreshIdLabel<DbGeexpr >()
15011587 val type = useType(c.type)
1502- val locId = tw.getLocation(c)
15031588 tw.writeExprs_geexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
1504- tw.writeHasLocation(id, locId)
1505- tw.writeCallableEnclosingExpr(id, callable)
1589+ binop(id)
15061590 id
15071591 }
15081592 else -> {
@@ -1518,16 +1602,17 @@ open class KotlinFileExtractor(
15181602 // type arguments at index -2, -3, ...
15191603 extractTypeArguments(c, id, callable, - 2 , true )
15201604 id
1521- }
1522- }
1523- val dr = c.dispatchReceiver
1524- if (dr != null ) {
1525- extractExpressionExpr(dr, callable, exprId, - 1 )
1526- }
1527- for (i in 0 until c.valueArgumentsCount) {
1528- val arg = c.getValueArgument(i)
1529- if (arg != null ) {
1530- extractExpressionExpr(arg, callable, exprId, i)
1605+
1606+ val dr = c.dispatchReceiver
1607+ if (dr != null ) {
1608+ extractExpressionExpr(dr, callable, id, - 1 )
1609+ }
1610+ for (i in 0 until c.valueArgumentsCount) {
1611+ val arg = c.getValueArgument(i)
1612+ if (arg != null ) {
1613+ extractExpressionExpr(arg, callable, id, i)
1614+ }
1615+ }
15311616 }
15321617 }
15331618 }
0 commit comments