mirror of
https://github.com/github/codeql.git
synced 2025-12-18 09:43:15 +01:00
Kotlin: Towards 'this' qualifiers
This probably handles most cases well enough
This commit is contained in:
@@ -1174,26 +1174,6 @@ open class KotlinFileExtractor(
|
|||||||
return FieldResult(instanceId, instanceName)
|
return FieldResult(instanceId, instanceName)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isQualifiedThis(vp: IrValueParameter): Boolean {
|
|
||||||
return isQualifiedThisFunction(vp) ||
|
|
||||||
isQualifiedThisClass(vp)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun isQualifiedThisFunction(vp: IrValueParameter): Boolean {
|
|
||||||
val parent = vp.parent
|
|
||||||
return vp.index == -1 &&
|
|
||||||
parent is IrFunction &&
|
|
||||||
parent.dispatchReceiverParameter == vp &&
|
|
||||||
parent.extensionReceiverParameter != null
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun isQualifiedThisClass(vp: IrValueParameter): Boolean {
|
|
||||||
val parent = vp.parent
|
|
||||||
return vp.index == -1 &&
|
|
||||||
parent is IrClass &&
|
|
||||||
parent.thisReceiver == vp
|
|
||||||
}
|
|
||||||
|
|
||||||
fun extractValueParameter(vp: IrValueParameter, parent: Label<out DbCallable>, idx: Int) {
|
fun extractValueParameter(vp: IrValueParameter, parent: Label<out DbCallable>, idx: Int) {
|
||||||
val id = useValueParameter(vp)
|
val id = useValueParameter(vp)
|
||||||
val type = useType(vp.type)
|
val type = useType(vp.type)
|
||||||
@@ -1895,12 +1875,31 @@ open class KotlinFileExtractor(
|
|||||||
val type = useType(e.type)
|
val type = useType(e.type)
|
||||||
val locId = tw.getLocation(e)
|
val locId = tw.getLocation(e)
|
||||||
tw.writeExprs_thisaccess(id, type.javaResult.id, type.kotlinResult.id, exprParent.parent, exprParent.idx)
|
tw.writeExprs_thisaccess(id, type.javaResult.id, type.kotlinResult.id, exprParent.parent, exprParent.idx)
|
||||||
if (isQualifiedThis(owner)) {
|
|
||||||
// todo: add type access as child of 'id' at index 0
|
|
||||||
logger.warnElement(Severity.ErrorSevere, "TODO: Qualified this access found.", e)
|
|
||||||
}
|
|
||||||
tw.writeHasLocation(id, locId)
|
tw.writeHasLocation(id, locId)
|
||||||
tw.writeCallableEnclosingExpr(id, callable)
|
tw.writeCallableEnclosingExpr(id, callable)
|
||||||
|
|
||||||
|
val ownerParent = owner.parent
|
||||||
|
when(ownerParent) {
|
||||||
|
is IrFunction -> {
|
||||||
|
if (ownerParent.dispatchReceiverParameter == owner &&
|
||||||
|
ownerParent.extensionReceiverParameter != null) {
|
||||||
|
logger.warnElement(Severity.ErrorSevere, "Function-qualifier for this", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is IrClass -> {
|
||||||
|
if (ownerParent.thisReceiver == owner) {
|
||||||
|
val qualId = tw.getFreshIdLabel<DbUnannotatedtypeaccess>()
|
||||||
|
// TODO: Type arguments
|
||||||
|
val qualType = useSimpleTypeClass(ownerParent, listOf(), false)
|
||||||
|
tw.writeExprs_unannotatedtypeaccess(qualId, qualType.javaResult.id, qualType.kotlinResult.id, id, 0)
|
||||||
|
tw.writeHasLocation(qualId, locId)
|
||||||
|
tw.writeCallableEnclosingExpr(qualId, callable)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
logger.warnElement(Severity.ErrorSevere, "Unexpected owner parent for this access: " + ownerParent.javaClass, e)
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
val id = tw.getFreshIdLabel<DbVaraccess>()
|
val id = tw.getFreshIdLabel<DbVaraccess>()
|
||||||
val type = useType(e.type)
|
val type = useType(e.type)
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
| this.kt:5:29:5:32 | this | file://:0:0:0:0 | <none> |
|
| this.kt:5:29:5:32 | this | file://:0:0:0:0 | <none> |
|
||||||
| this.kt:6:29:6:38 | this | file://:0:0:0:0 | <none> |
|
| this.kt:6:29:6:38 | this | file://:0:0:0:0 | <none> |
|
||||||
| this.kt:7:29:7:38 | this | file://:0:0:0:0 | <none> |
|
| this.kt:7:29:7:38 | Outer.this | this.kt:7:29:7:38 | Outer |
|
||||||
| this.kt:29:38:29:41 | this | file://:0:0:0:0 | <none> |
|
| this.kt:29:38:29:41 | this | file://:0:0:0:0 | <none> |
|
||||||
| this.kt:30:29:30:38 | this | file://:0:0:0:0 | <none> |
|
| this.kt:30:29:30:38 | this | file://:0:0:0:0 | <none> |
|
||||||
| this.kt:31:29:31:38 | this | file://:0:0:0:0 | <none> |
|
| this.kt:31:29:31:38 | Outer.this | this.kt:31:29:31:38 | Outer |
|
||||||
| this.kt:32:38:32:54 | this | file://:0:0:0:0 | <none> |
|
| this.kt:32:38:32:54 | this | file://:0:0:0:0 | <none> |
|
||||||
| this.kt:37:13:37:22 | this | file://:0:0:0:0 | <none> |
|
| this.kt:37:13:37:22 | Outer.this | this.kt:37:13:37:22 | Outer |
|
||||||
| this.kt:38:13:38:22 | this | file://:0:0:0:0 | <none> |
|
| this.kt:38:13:38:22 | this | file://:0:0:0:0 | <none> |
|
||||||
| this.kt:39:13:39:30 | this | file://:0:0:0:0 | <none> |
|
| this.kt:39:13:39:30 | Outer.this | this.kt:39:13:39:30 | Outer |
|
||||||
| this.kt:40:13:40:30 | this | file://:0:0:0:0 | <none> |
|
| this.kt:40:13:40:30 | this | file://:0:0:0:0 | <none> |
|
||||||
| this.kt:41:13:41:27 | this | file://:0:0:0:0 | <none> |
|
| this.kt:41:13:41:27 | this | file://:0:0:0:0 | <none> |
|
||||||
| this.kt:42:13:42:35 | this | file://:0:0:0:0 | <none> |
|
| this.kt:42:13:42:35 | this | file://:0:0:0:0 | <none> |
|
||||||
|
|||||||
Reference in New Issue
Block a user