@@ -544,37 +544,63 @@ open class KotlinFileExtractor(
544544 return true
545545 }
546546
547- fun binop (id : Label <out DbExpr >, c : IrCall , callable : Label <out DbCallable >) {
547+ private fun unaryOp (id : Label <out DbExpr >, c : IrCall , callable : Label <out DbCallable >) {
548548 val locId = tw.getLocation(c)
549549 tw.writeHasLocation(id, locId)
550550 tw.writeCallableEnclosingExpr(id, callable)
551551
552552 val dr = c.dispatchReceiver
553- if (dr != null ) {
553+ if (dr != null ) {
554+ logger.warnElement(Severity .ErrorSevere , " Unexpected dispatch receiver found" , c)
555+ }
556+
557+ if (c.valueArgumentsCount < 1 ) {
558+ logger.warnElement(Severity .ErrorSevere , " No arguments found" , c)
559+ return
560+ }
561+
562+ extractArgument(id, c, callable, 0 , " Operand null" )
563+
564+ if (c.valueArgumentsCount > 1 ) {
565+ logger.warnElement(Severity .ErrorSevere , " Extra arguments found" , c)
566+ }
567+ }
568+
569+ private fun binOp (id : Label <out DbExpr >, c : IrCall , callable : Label <out DbCallable >) {
570+ val locId = tw.getLocation(c)
571+ tw.writeHasLocation(id, locId)
572+ tw.writeCallableEnclosingExpr(id, callable)
573+
574+ val dr = c.dispatchReceiver
575+ if (dr != null ) {
554576 logger.warnElement(Severity .ErrorSevere , " Unexpected dispatch receiver found" , c)
555577 }
556- if (c.valueArgumentsCount < 1 ) {
578+
579+ if (c.valueArgumentsCount < 1 ) {
557580 logger.warnElement(Severity .ErrorSevere , " No arguments found" , c)
581+ return
582+ }
583+
584+ extractArgument(id, c, callable, 0 , " LHS null" )
585+
586+ if (c.valueArgumentsCount < 2 ) {
587+ logger.warnElement(Severity .ErrorSevere , " No RHS found" , c)
588+ return
589+ }
590+
591+ extractArgument(id, c, callable, 1 , " RHS null" )
592+
593+ if (c.valueArgumentsCount > 2 ) {
594+ logger.warnElement(Severity .ErrorSevere , " Extra arguments found" , c)
595+ }
596+ }
597+
598+ private fun extractArgument (id : Label <out DbExpr >, c : IrCall , callable : Label <out DbCallable >, idx : Int , msg : String ) {
599+ val op = c.getValueArgument(idx)
600+ if (op == null ) {
601+ logger.warnElement(Severity .ErrorSevere , msg, c)
558602 } else {
559- val lhs = c.getValueArgument(0 )
560- if (lhs == null ) {
561- logger.warnElement(Severity .ErrorSevere , " LHS null" , c)
562- } else {
563- extractExpressionExpr(lhs, callable, id, 0 )
564- }
565- if (c.valueArgumentsCount < 2 ) {
566- logger.warnElement(Severity .ErrorSevere , " No RHS found" , c)
567- } else {
568- val rhs = c.getValueArgument(1 )
569- if (rhs == null ) {
570- logger.warnElement(Severity .ErrorSevere , " RHS null" , c)
571- } else {
572- extractExpressionExpr(rhs, callable, id, 1 )
573- }
574- }
575- if (c.valueArgumentsCount > 2 ) {
576- logger.warnElement(Severity .ErrorSevere , " Extra arguments found" , c)
577- }
603+ extractExpressionExpr(op, callable, id, idx)
578604 }
579605 }
580606
@@ -681,20 +707,20 @@ open class KotlinFileExtractor(
681707 val id = tw.getFreshIdLabel<DbNeexpr >()
682708 val type = useType(c.type)
683709 tw.writeExprs_neexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
684- binop (id, dr, callable)
710+ binOp (id, dr, callable)
685711 }
686712 c.origin == IrStatementOrigin .EXCLEQEQ && isFunction(" kotlin" , " Boolean" , " not" ) && c.valueArgumentsCount == 0 && dr != null && dr is IrCall && isBuiltinCall(dr, " EQEQEQ" ) -> {
687713 val id = tw.getFreshIdLabel<DbNeexpr >()
688714 val type = useType(c.type)
689715 tw.writeExprs_neexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
690- binop (id, dr, callable)
716+ binOp (id, dr, callable)
691717 }
692718 c.origin == IrStatementOrigin .EXCLEQ && isFunction(" kotlin" , " Boolean" , " not" ) && c.valueArgumentsCount == 0 && dr != null && dr is IrCall && isBuiltinCall(dr, " ieee754equals" ) -> {
693719 val id = tw.getFreshIdLabel<DbNeexpr >()
694720 val type = useType(c.type)
695721 // TODO: Is this consistent with Java?
696722 tw.writeExprs_neexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
697- binop (id, dr, callable)
723+ binOp (id, dr, callable)
698724 }
699725 // We need to handle all the builtin operators defines in BuiltInOperatorNames in
700726 // compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/IrBuiltIns.kt
@@ -706,7 +732,7 @@ open class KotlinFileExtractor(
706732 val id = tw.getFreshIdLabel<DbLtexpr >()
707733 val type = useType(c.type)
708734 tw.writeExprs_ltexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
709- binop (id, c, callable)
735+ binOp (id, c, callable)
710736 }
711737 isBuiltinCall(c, " lessOrEqual" ) -> {
712738 if (c.origin != IrStatementOrigin .LTEQ ) {
@@ -715,7 +741,7 @@ open class KotlinFileExtractor(
715741 val id = tw.getFreshIdLabel<DbLeexpr >()
716742 val type = useType(c.type)
717743 tw.writeExprs_leexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
718- binop (id, c, callable)
744+ binOp (id, c, callable)
719745 }
720746 isBuiltinCall(c, " greater" ) -> {
721747 if (c.origin != IrStatementOrigin .GT ) {
@@ -724,7 +750,7 @@ open class KotlinFileExtractor(
724750 val id = tw.getFreshIdLabel<DbGtexpr >()
725751 val type = useType(c.type)
726752 tw.writeExprs_gtexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
727- binop (id, c, callable)
753+ binOp (id, c, callable)
728754 }
729755 isBuiltinCall(c, " greaterOrEqual" ) -> {
730756 if (c.origin != IrStatementOrigin .GTEQ ) {
@@ -733,7 +759,7 @@ open class KotlinFileExtractor(
733759 val id = tw.getFreshIdLabel<DbGeexpr >()
734760 val type = useType(c.type)
735761 tw.writeExprs_geexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
736- binop (id, c, callable)
762+ binOp (id, c, callable)
737763 }
738764 isBuiltinCall(c, " EQEQ" ) -> {
739765 if (c.origin != IrStatementOrigin .EQEQ ) {
@@ -743,7 +769,7 @@ open class KotlinFileExtractor(
743769 val id = tw.getFreshIdLabel<DbEqexpr >()
744770 val type = useType(c.type)
745771 tw.writeExprs_eqexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
746- binop (id, c, callable)
772+ binOp (id, c, callable)
747773 }
748774 isBuiltinCall(c, " EQEQEQ" ) -> {
749775 if (c.origin != IrStatementOrigin .EQEQEQ ) {
@@ -752,7 +778,7 @@ open class KotlinFileExtractor(
752778 val id = tw.getFreshIdLabel<DbEqexpr >()
753779 val type = useType(c.type)
754780 tw.writeExprs_eqexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
755- binop (id, c, callable)
781+ binOp (id, c, callable)
756782 }
757783 isBuiltinCall(c, " ieee754equals" ) -> {
758784 if (c.origin != IrStatementOrigin .EQEQ ) {
@@ -762,7 +788,17 @@ open class KotlinFileExtractor(
762788 val id = tw.getFreshIdLabel<DbEqexpr >()
763789 val type = useType(c.type)
764790 tw.writeExprs_eqexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
765- binop(id, c, callable)
791+ binOp(id, c, callable)
792+ }
793+ isBuiltinCall(c, " CHECK_NOT_NULL" ) -> {
794+ if (c.origin != IrStatementOrigin .EXCLEXCL ) {
795+ logger.warnElement(Severity .ErrorSevere , " Unexpected origin for CHECK_NOT_NULL: ${c.origin} " , c)
796+ }
797+
798+ val id = tw.getFreshIdLabel<DbNotnullexpr >()
799+ val type = useType(c.type)
800+ tw.writeExprs_notnullexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
801+ unaryOp(id, c, callable)
766802 }
767803 isBuiltinCall(c, " THROW_CCE" ) -> {
768804 // TODO
0 commit comments