mirror of
https://github.com/github/codeql.git
synced 2026-04-29 18:55:14 +02:00
Kotlin: Add more types
This commit is contained in:
@@ -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
|
||||
|
||||
10
java/ql/test/kotlin/library-tests/types/types.expected
Normal file
10
java/ql/test/kotlin/library-tests/types/types.expected
Normal 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 |
|
||||
34
java/ql/test/kotlin/library-tests/types/types.kt
Normal file
34
java/ql/test/kotlin/library-tests/types/types.kt
Normal 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)
|
||||
*/
|
||||
}
|
||||
|
||||
5
java/ql/test/kotlin/library-tests/types/types.ql
Normal file
5
java/ql/test/kotlin/library-tests/types/types.ql
Normal file
@@ -0,0 +1,5 @@
|
||||
import java
|
||||
|
||||
from Type t
|
||||
select t, concat(t.getAPrimaryQlClass(), ", ")
|
||||
|
||||
Reference in New Issue
Block a user