Kotlin: Add more types

This commit is contained in:
Ian Lynagh
2021-08-11 17:28:52 +01:00
parent 1c39f001e5
commit 46add88bb5
4 changed files with 69 additions and 20 deletions

View File

@@ -156,28 +156,28 @@ class KotlinFileExtractor(val tw: TrapWriter) {
@Suppress("UNUSED_PARAMETER")
fun useSimpleType(s: IrSimpleType): Label<out DbType> {
fun primitiveType(name: String): Label<DbPrimitive> {
return tw.getLabelFor("@\"type;$name\"", {
tw.writePrimitives(it, name)
})
}
when {
s.isInt() -> {
val label = "@\"type;int\""
val id: Label<DbPrimitive> = tw.getLabelFor(label, {
tw.writePrimitives(it, "int")
})
return id
}
s.isBoolean() -> {
val label = "@\"type;boolean\""
val id: Label<DbPrimitive> = tw.getLabelFor(label, {
tw.writePrimitives(it, "boolean")
})
return id
}
s.isString() -> {
val label = "@\"type;string\""
val id: Label<DbPrimitive> = tw.getLabelFor(label, {
tw.writePrimitives(it, "string")
})
return id
s.isByte() -> return primitiveType("byte")
s.isShort() -> return primitiveType("short")
s.isInt() -> return primitiveType("int")
s.isLong() -> return primitiveType("long")
s.isUByte() || s.isUShort() || s.isUInt() || s.isULong() -> {
extractorBug("Unhandled unsigned type")
return Label(0)
}
s.isDouble() -> return primitiveType("double")
s.isFloat() -> return primitiveType("float")
s.isBoolean() -> return primitiveType("boolean")
s.isChar() -> return primitiveType("char")
s.isString() -> return primitiveType("string") // TODO: Wrong
s.classifier.owner is IrClass -> {
val classifier: IrClassifierSymbol = s.classifier
val cls: IrClass = classifier.owner as IrClass

View File

@@ -0,0 +1,10 @@
| file://:0:0:0:0 | boolean | PrimitiveType |
| file://:0:0:0:0 | byte | PrimitiveType |
| file://:0:0:0:0 | char | PrimitiveType |
| file://:0:0:0:0 | double | PrimitiveType |
| file://:0:0:0:0 | float | PrimitiveType |
| file://:0:0:0:0 | int | PrimitiveType |
| file://:0:0:0:0 | long | PrimitiveType |
| file://:0:0:0:0 | short | PrimitiveType |
| file://:0:0:0:0 | string | ??? |
| types.kt:2:1:33:1 | Foo | Class |

View File

@@ -0,0 +1,34 @@
class Foo {
val propByte: Byte = 1
val propShort: Short = 1
val propInt: Int = 1
val propLong: Long = 1
/*
TODO
val propUByte: UByte = 1u
val propUShort: UShort = 1u
val propUInt: UInt = 1u
val propULong: ULong = 1u
*/
val propFloat: Float = 1.0f
val propDouble: Double = 1.0
val propBoolean: Boolean = true
val propChar: Char = 'c'
val propString: String = "str"
/*
TODO
val propArray: Array<Int> = arrayOf(1, 2, 3)
val propByteArray: ByteArray = byteArrayOf(1, 2, 3)
val propShortArray: ShortArray = shortArrayOf(1, 2, 3)
val propIntArray: IntArray = intArrayOf(1, 2, 3)
val propLongArray: LongArray = longArrayOf(1, 2, 3)
*/
}

View File

@@ -0,0 +1,5 @@
import java
from Type t
select t, concat(t.getAPrimaryQlClass(), ", ")