Merge pull request #10672 from tamasvajk/kotlin-unary-op

Kotlin: extract unary plus and minus operators
This commit is contained in:
Tamás Vajk
2022-10-05 13:30:21 +02:00
committed by GitHub
6 changed files with 235 additions and 4 deletions

View File

@@ -2101,7 +2101,7 @@ open class KotlinFileExtractor(
id id
} }
else -> { else -> {
logger.errorElement("Unhandled target name: $targetName", c) logger.errorElement("Unhandled binary target name: $targetName", c)
return return
} }
} }
@@ -2137,10 +2137,29 @@ open class KotlinFileExtractor(
tw.writeExprsKotlinType(id, type.kotlinResult.id) tw.writeExprsKotlinType(id, type.kotlinResult.id)
unaryopDisp(id) unaryopDisp(id)
} }
isNumericFunction(target, "inv") -> { isNumericFunction(target, listOf("inv", "unaryMinus", "unaryPlus")) -> {
val id = tw.getFreshIdLabel<DbBitnotexpr>()
val type = useType(c.type) val type = useType(c.type)
tw.writeExprs_bitnotexpr(id, type.javaResult.id, parent, idx) val id: Label<out DbExpr> = when (val targetName = target.name.asString()) {
"inv" -> {
val id = tw.getFreshIdLabel<DbBitnotexpr>()
tw.writeExprs_bitnotexpr(id, type.javaResult.id, parent, idx)
id
}
"unaryMinus" -> {
val id = tw.getFreshIdLabel<DbMinusexpr>()
tw.writeExprs_minusexpr(id, type.javaResult.id, parent, idx)
id
}
"unaryPlus" -> {
val id = tw.getFreshIdLabel<DbPlusexpr>()
tw.writeExprs_plusexpr(id, type.javaResult.id, parent, idx)
id
}
else -> {
logger.errorElement("Unhandled unary target name: $targetName", c)
return
}
}
tw.writeExprsKotlinType(id, type.kotlinResult.id) tw.writeExprsKotlinType(id, type.kotlinResult.id)
unaryopDisp(id) unaryopDisp(id)
} }

View File

@@ -11,6 +11,14 @@
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Byte.toInt in java.lang.Byte | | file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Byte.toInt in java.lang.Byte |
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Byte.toInt in java.lang.Byte | | file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Byte.toInt in java.lang.Byte |
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Int.dec in java.lang.Integer | | file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Int.dec in java.lang.Integer |
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Int.dec in java.lang.Integer |
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Int.dec in java.lang.Integer |
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Int.dec in java.lang.Integer |
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Int.dec in java.lang.Integer |
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Int.inc in java.lang.Integer |
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Int.inc in java.lang.Integer |
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Int.inc in java.lang.Integer |
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Int.inc in java.lang.Integer |
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Int.rangeTo in java.lang.Integer | | file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Int.rangeTo in java.lang.Integer |
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Int.rangeTo in java.lang.Integer | | file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Int.rangeTo in java.lang.Integer |
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Short.toInt in java.lang.Short | | file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Short.toInt in java.lang.Short |

View File

@@ -2855,6 +2855,114 @@ exprs.kt:
# 276| 1: [MethodAccess] getEnumValues(...) # 276| 1: [MethodAccess] getEnumValues(...)
# 276| -2: [TypeAccess] Color # 276| -2: [TypeAccess] Color
# 276| -1: [TypeAccess] ExprsKt # 276| -1: [TypeAccess] ExprsKt
# 279| 14: [Method] unaryExprs
# 279| 3: [TypeAccess] Unit
#-----| 4: (Parameters)
# 279| 0: [Parameter] i
# 279| 0: [TypeAccess] int
# 279| 1: [Parameter] d
# 279| 0: [TypeAccess] double
# 279| 5: [BlockStmt] { ... }
# 280| 0: [ExprStmt] <Expr>;
# 280| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
# 280| 0: [TypeAccess] Unit
# 280| 1: [MinusExpr] -...
# 280| 0: [VarAccess] i
# 281| 1: [ExprStmt] <Expr>;
# 281| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
# 281| 0: [TypeAccess] Unit
# 281| 1: [PlusExpr] +...
# 281| 0: [VarAccess] i
# 282| 2: [ExprStmt] <Expr>;
# 282| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
# 282| 0: [TypeAccess] Unit
# 282| 1: [MinusExpr] -...
# 282| 0: [VarAccess] d
# 283| 3: [ExprStmt] <Expr>;
# 283| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
# 283| 0: [TypeAccess] Unit
# 283| 1: [PlusExpr] +...
# 283| 0: [VarAccess] d
# 284| 4: [LocalVariableDeclStmt] var ...;
# 284| 1: [LocalVariableDeclExpr] i0
# 284| 0: [IntegerLiteral] 1
# 285| 5: [LocalVariableDeclStmt] var ...;
# 285| 1: [LocalVariableDeclExpr] i1
# 285| 0: [IntegerLiteral] 1
# 286| 6: [ExprStmt] <Expr>;
# 286| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
# 286| 0: [TypeAccess] Unit
# 286| 1: [StmtExpr] <Stmt>
# 286| 0: [BlockStmt] { ... }
# 286| 0: [LocalVariableDeclStmt] var ...;
# 286| 1: [LocalVariableDeclExpr] tmp0
# 286| 0: [VarAccess] i0
# 286| 1: [ExprStmt] <Expr>;
# 286| 0: [AssignExpr] ...=...
# 286| 0: [VarAccess] i0
# 286| 1: [MethodAccess] inc(...)
# 286| -1: [VarAccess] tmp0
# 286| 2: [ExprStmt] <Expr>;
# 286| 0: [VarAccess] tmp0
# 287| 7: [ExprStmt] <Expr>;
# 287| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
# 287| 0: [TypeAccess] Unit
# 287| 1: [StmtExpr] <Stmt>
# 287| 0: [BlockStmt] { ... }
# 287| 0: [ExprStmt] <Expr>;
# 287| 0: [AssignExpr] ...=...
# 287| 0: [VarAccess] i0
# 287| 1: [MethodAccess] inc(...)
# 287| -1: [VarAccess] i0
# 287| 1: [ExprStmt] <Expr>;
# 287| 0: [VarAccess] i0
# 288| 8: [ExprStmt] <Expr>;
# 288| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
# 288| 0: [TypeAccess] Unit
# 288| 1: [StmtExpr] <Stmt>
# 288| 0: [BlockStmt] { ... }
# 288| 0: [LocalVariableDeclStmt] var ...;
# 288| 1: [LocalVariableDeclExpr] tmp1
# 288| 0: [VarAccess] i0
# 288| 1: [ExprStmt] <Expr>;
# 288| 0: [AssignExpr] ...=...
# 288| 0: [VarAccess] i0
# 288| 1: [MethodAccess] dec(...)
# 288| -1: [VarAccess] tmp1
# 288| 2: [ExprStmt] <Expr>;
# 288| 0: [VarAccess] tmp1
# 289| 9: [ExprStmt] <Expr>;
# 289| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
# 289| 0: [TypeAccess] Unit
# 289| 1: [StmtExpr] <Stmt>
# 289| 0: [BlockStmt] { ... }
# 289| 0: [ExprStmt] <Expr>;
# 289| 0: [AssignExpr] ...=...
# 289| 0: [VarAccess] i0
# 289| 1: [MethodAccess] dec(...)
# 289| -1: [VarAccess] i0
# 289| 1: [ExprStmt] <Expr>;
# 289| 0: [VarAccess] i0
# 290| 10: [ExprStmt] <Expr>;
# 290| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
# 290| 0: [TypeAccess] Unit
# 290| 1: [MethodAccess] inc(...)
# 290| -1: [VarAccess] i0
# 291| 11: [ExprStmt] <Expr>;
# 291| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
# 291| 0: [TypeAccess] Unit
# 291| 1: [MethodAccess] dec(...)
# 291| -1: [VarAccess] i0
# 292| 12: [ExprStmt] <Expr>;
# 292| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
# 292| 0: [TypeAccess] Unit
# 292| 1: [MethodAccess] inc(...)
# 292| -1: [VarAccess] i1
# 293| 13: [ExprStmt] <Expr>;
# 293| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
# 293| 0: [TypeAccess] Unit
# 293| 1: [MethodAccess] dec(...)
# 293| -1: [VarAccess] i1
# 142| 2: [Class] C # 142| 2: [Class] C
# 142| 1: [Constructor] C # 142| 1: [Constructor] C
#-----| 4: (Parameters) #-----| 4: (Parameters)

View File

@@ -1738,6 +1738,81 @@
| exprs.kt:276:5:276:26 | ExprsKt | exprs.kt:274:1:277:1 | callToEnumValues | TypeAccess | | exprs.kt:276:5:276:26 | ExprsKt | exprs.kt:274:1:277:1 | callToEnumValues | TypeAccess |
| exprs.kt:276:5:276:26 | Unit | exprs.kt:274:1:277:1 | callToEnumValues | TypeAccess | | exprs.kt:276:5:276:26 | Unit | exprs.kt:274:1:277:1 | callToEnumValues | TypeAccess |
| exprs.kt:276:5:276:26 | getEnumValues(...) | exprs.kt:274:1:277:1 | callToEnumValues | MethodAccess | | exprs.kt:276:5:276:26 | getEnumValues(...) | exprs.kt:274:1:277:1 | callToEnumValues | MethodAccess |
| exprs.kt:279:1:294:1 | Unit | file://:0:0:0:0 | <none> | TypeAccess |
| exprs.kt:279:16:279:21 | int | file://:0:0:0:0 | <none> | TypeAccess |
| exprs.kt:279:24:279:32 | double | file://:0:0:0:0 | <none> | TypeAccess |
| exprs.kt:280:5:280:6 | -... | exprs.kt:279:1:294:1 | unaryExprs | MinusExpr |
| exprs.kt:280:5:280:6 | <implicit coercion to unit> | exprs.kt:279:1:294:1 | unaryExprs | ImplicitCoercionToUnitExpr |
| exprs.kt:280:5:280:6 | Unit | exprs.kt:279:1:294:1 | unaryExprs | TypeAccess |
| exprs.kt:280:6:280:6 | i | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
| exprs.kt:281:5:281:6 | +... | exprs.kt:279:1:294:1 | unaryExprs | PlusExpr |
| exprs.kt:281:5:281:6 | <implicit coercion to unit> | exprs.kt:279:1:294:1 | unaryExprs | ImplicitCoercionToUnitExpr |
| exprs.kt:281:5:281:6 | Unit | exprs.kt:279:1:294:1 | unaryExprs | TypeAccess |
| exprs.kt:281:6:281:6 | i | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
| exprs.kt:282:5:282:6 | -... | exprs.kt:279:1:294:1 | unaryExprs | MinusExpr |
| exprs.kt:282:5:282:6 | <implicit coercion to unit> | exprs.kt:279:1:294:1 | unaryExprs | ImplicitCoercionToUnitExpr |
| exprs.kt:282:5:282:6 | Unit | exprs.kt:279:1:294:1 | unaryExprs | TypeAccess |
| exprs.kt:282:6:282:6 | d | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
| exprs.kt:283:5:283:6 | +... | exprs.kt:279:1:294:1 | unaryExprs | PlusExpr |
| exprs.kt:283:5:283:6 | <implicit coercion to unit> | exprs.kt:279:1:294:1 | unaryExprs | ImplicitCoercionToUnitExpr |
| exprs.kt:283:5:283:6 | Unit | exprs.kt:279:1:294:1 | unaryExprs | TypeAccess |
| exprs.kt:283:6:283:6 | d | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
| exprs.kt:284:5:284:14 | i0 | exprs.kt:279:1:294:1 | unaryExprs | LocalVariableDeclExpr |
| exprs.kt:284:14:284:14 | 1 | exprs.kt:279:1:294:1 | unaryExprs | IntegerLiteral |
| exprs.kt:285:5:285:14 | i1 | exprs.kt:279:1:294:1 | unaryExprs | LocalVariableDeclExpr |
| exprs.kt:285:14:285:14 | 1 | exprs.kt:279:1:294:1 | unaryExprs | IntegerLiteral |
| exprs.kt:286:5:286:6 | i0 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
| exprs.kt:286:5:286:6 | i0 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
| exprs.kt:286:5:286:8 | ...=... | exprs.kt:279:1:294:1 | unaryExprs | AssignExpr |
| exprs.kt:286:5:286:8 | <Stmt> | exprs.kt:279:1:294:1 | unaryExprs | StmtExpr |
| exprs.kt:286:5:286:8 | <implicit coercion to unit> | exprs.kt:279:1:294:1 | unaryExprs | ImplicitCoercionToUnitExpr |
| exprs.kt:286:5:286:8 | Unit | exprs.kt:279:1:294:1 | unaryExprs | TypeAccess |
| exprs.kt:286:5:286:8 | inc(...) | exprs.kt:279:1:294:1 | unaryExprs | MethodAccess |
| exprs.kt:286:5:286:8 | tmp0 | exprs.kt:279:1:294:1 | unaryExprs | LocalVariableDeclExpr |
| exprs.kt:286:5:286:8 | tmp0 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
| exprs.kt:286:5:286:8 | tmp0 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
| exprs.kt:287:5:287:8 | <Stmt> | exprs.kt:279:1:294:1 | unaryExprs | StmtExpr |
| exprs.kt:287:5:287:8 | <implicit coercion to unit> | exprs.kt:279:1:294:1 | unaryExprs | ImplicitCoercionToUnitExpr |
| exprs.kt:287:5:287:8 | Unit | exprs.kt:279:1:294:1 | unaryExprs | TypeAccess |
| exprs.kt:287:5:287:8 | inc(...) | exprs.kt:279:1:294:1 | unaryExprs | MethodAccess |
| exprs.kt:287:7:287:8 | ...=... | exprs.kt:279:1:294:1 | unaryExprs | AssignExpr |
| exprs.kt:287:7:287:8 | i0 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
| exprs.kt:287:7:287:8 | i0 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
| exprs.kt:287:7:287:8 | i0 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
| exprs.kt:288:5:288:6 | i0 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
| exprs.kt:288:5:288:6 | i0 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
| exprs.kt:288:5:288:8 | ...=... | exprs.kt:279:1:294:1 | unaryExprs | AssignExpr |
| exprs.kt:288:5:288:8 | <Stmt> | exprs.kt:279:1:294:1 | unaryExprs | StmtExpr |
| exprs.kt:288:5:288:8 | <implicit coercion to unit> | exprs.kt:279:1:294:1 | unaryExprs | ImplicitCoercionToUnitExpr |
| exprs.kt:288:5:288:8 | Unit | exprs.kt:279:1:294:1 | unaryExprs | TypeAccess |
| exprs.kt:288:5:288:8 | dec(...) | exprs.kt:279:1:294:1 | unaryExprs | MethodAccess |
| exprs.kt:288:5:288:8 | tmp1 | exprs.kt:279:1:294:1 | unaryExprs | LocalVariableDeclExpr |
| exprs.kt:288:5:288:8 | tmp1 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
| exprs.kt:288:5:288:8 | tmp1 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
| exprs.kt:289:5:289:8 | <Stmt> | exprs.kt:279:1:294:1 | unaryExprs | StmtExpr |
| exprs.kt:289:5:289:8 | <implicit coercion to unit> | exprs.kt:279:1:294:1 | unaryExprs | ImplicitCoercionToUnitExpr |
| exprs.kt:289:5:289:8 | Unit | exprs.kt:279:1:294:1 | unaryExprs | TypeAccess |
| exprs.kt:289:5:289:8 | dec(...) | exprs.kt:279:1:294:1 | unaryExprs | MethodAccess |
| exprs.kt:289:7:289:8 | ...=... | exprs.kt:279:1:294:1 | unaryExprs | AssignExpr |
| exprs.kt:289:7:289:8 | i0 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
| exprs.kt:289:7:289:8 | i0 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
| exprs.kt:289:7:289:8 | i0 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
| exprs.kt:290:5:290:6 | i0 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
| exprs.kt:290:8:290:12 | <implicit coercion to unit> | exprs.kt:279:1:294:1 | unaryExprs | ImplicitCoercionToUnitExpr |
| exprs.kt:290:8:290:12 | Unit | exprs.kt:279:1:294:1 | unaryExprs | TypeAccess |
| exprs.kt:290:8:290:12 | inc(...) | exprs.kt:279:1:294:1 | unaryExprs | MethodAccess |
| exprs.kt:291:5:291:6 | i0 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
| exprs.kt:291:8:291:12 | <implicit coercion to unit> | exprs.kt:279:1:294:1 | unaryExprs | ImplicitCoercionToUnitExpr |
| exprs.kt:291:8:291:12 | Unit | exprs.kt:279:1:294:1 | unaryExprs | TypeAccess |
| exprs.kt:291:8:291:12 | dec(...) | exprs.kt:279:1:294:1 | unaryExprs | MethodAccess |
| exprs.kt:292:5:292:6 | i1 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
| exprs.kt:292:8:292:12 | <implicit coercion to unit> | exprs.kt:279:1:294:1 | unaryExprs | ImplicitCoercionToUnitExpr |
| exprs.kt:292:8:292:12 | Unit | exprs.kt:279:1:294:1 | unaryExprs | TypeAccess |
| exprs.kt:292:8:292:12 | inc(...) | exprs.kt:279:1:294:1 | unaryExprs | MethodAccess |
| exprs.kt:293:5:293:6 | i1 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
| exprs.kt:293:8:293:12 | <implicit coercion to unit> | exprs.kt:279:1:294:1 | unaryExprs | ImplicitCoercionToUnitExpr |
| exprs.kt:293:8:293:12 | Unit | exprs.kt:279:1:294:1 | unaryExprs | TypeAccess |
| exprs.kt:293:8:293:12 | dec(...) | exprs.kt:279:1:294:1 | unaryExprs | MethodAccess |
| funcExprs.kt:1:1:1:46 | Unit | file://:0:0:0:0 | <none> | TypeAccess | | funcExprs.kt:1:1:1:46 | Unit | file://:0:0:0:0 | <none> | TypeAccess |
| funcExprs.kt:1:26:1:37 | Function0<Integer> | file://:0:0:0:0 | <none> | TypeAccess | | funcExprs.kt:1:26:1:37 | Function0<Integer> | file://:0:0:0:0 | <none> | TypeAccess |
| funcExprs.kt:1:26:1:37 | Integer | file://:0:0:0:0 | <none> | TypeAccess | | funcExprs.kt:1:26:1:37 | Integer | file://:0:0:0:0 | <none> | TypeAccess |

View File

@@ -275,3 +275,20 @@ fun callToEnumValues() {
enumValues<Color>() enumValues<Color>()
getEnumValues<Color>() getEnumValues<Color>()
} }
fun unaryExprs(i: Int, d: Double) {
-i
+i
-d
+d
var i0 = 1
val i1 = 1
i0++
++i0
i0--
--i0
i0.inc()
i0.dec()
i1.inc()
i1.dec()
}

View File

@@ -5,3 +5,7 @@
| exprs.kt:196:19:196:20 | ...!! | exprs.kt:196:18:196:18 | x | | exprs.kt:196:19:196:20 | ...!! | exprs.kt:196:18:196:18 | x |
| exprs.kt:205:20:205:21 | ...!! | exprs.kt:205:19:205:19 | s | | exprs.kt:205:20:205:21 | ...!! | exprs.kt:205:19:205:19 | s |
| exprs.kt:206:20:206:21 | ...!! | exprs.kt:206:19:206:19 | s | | exprs.kt:206:20:206:21 | ...!! | exprs.kt:206:19:206:19 | s |
| exprs.kt:280:5:280:6 | -... | exprs.kt:280:6:280:6 | i |
| exprs.kt:281:5:281:6 | +... | exprs.kt:281:6:281:6 | i |
| exprs.kt:282:5:282:6 | -... | exprs.kt:282:6:282:6 | d |
| exprs.kt:283:5:283:6 | +... | exprs.kt:283:6:283:6 | d |