mirror of
https://github.com/github/codeql.git
synced 2026-05-24 16:17:07 +02:00
KE2: Start working on KtTypes
This commit is contained in:
@@ -9,8 +9,13 @@ private fun KotlinUsesExtractor.useClassType(
|
||||
c: KaClassType
|
||||
): TypeResults {
|
||||
// TODO: this cast is unsafe; .symbol is actually a KaClassLikeSymbol
|
||||
val javaResult = TypeResult(addClassLabel(c.symbol as KaClassSymbol) /* , TODO, TODO */)
|
||||
val kotlinResult = TypeResult(fakeKotlinType() /* , "TODO", "TODO" */)
|
||||
val classId = addClassLabel(c.symbol as KaClassSymbol)
|
||||
val javaResult = TypeResult(classId /* , TODO, TODO */)
|
||||
val kotlinTypeId =
|
||||
tw.getLabelFor<DbKt_class_type>("@\"kt_class{$classId}\"") {
|
||||
tw.writeKt_class_types(it, classId)
|
||||
}
|
||||
val kotlinResult = TypeResult(kotlinTypeId /* , "TODO", "TODO" */)
|
||||
return TypeResults(javaResult, kotlinResult)
|
||||
}
|
||||
|
||||
@@ -44,8 +49,8 @@ private fun KotlinUsesExtractor.extractJavaErrorType(): TypeResult<DbErrortype>
|
||||
private fun KotlinUsesExtractor.extractErrorType(): TypeResults {
|
||||
val javaResult = extractJavaErrorType()
|
||||
val kotlinTypeId =
|
||||
tw.getLabelFor<DbKt_nullable_type>("@\"errorKotlinType\"") {
|
||||
tw.writeKt_nullable_types(it, javaResult.id)
|
||||
tw.getLabelFor<DbKt_error_type>("@\"errorKotlinType\"") {
|
||||
tw.writeKt_error_types(it)
|
||||
}
|
||||
return TypeResults(
|
||||
javaResult,
|
||||
@@ -53,23 +58,6 @@ private fun KotlinUsesExtractor.extractErrorType(): TypeResults {
|
||||
)
|
||||
}
|
||||
|
||||
// TODO
|
||||
fun KotlinUsesExtractor.fakeKotlinType(): Label<out DbKt_type> {
|
||||
val fakeKotlinPackageId: Label<DbPackage> =
|
||||
tw.getLabelFor("@\"FakeKotlinPackage\"", { tw.writePackages(it, "fake.kotlin") })
|
||||
val fakeKotlinClassId: Label<DbClassorinterface> =
|
||||
tw.getLabelFor(
|
||||
"@\"FakeKotlinClass\"",
|
||||
{ tw.writeClasses_or_interfaces(it, "FakeKotlinClass", fakeKotlinPackageId, it) }
|
||||
)
|
||||
val fakeKotlinTypeId: Label<DbKt_nullable_type> =
|
||||
tw.getLabelFor(
|
||||
"@\"FakeKotlinType\"",
|
||||
{ tw.writeKt_nullable_types(it, fakeKotlinClassId) }
|
||||
)
|
||||
return fakeKotlinTypeId
|
||||
}
|
||||
|
||||
/*
|
||||
OLD: KE1
|
||||
// `args` can be null to describe a raw generic type.
|
||||
|
||||
@@ -461,23 +461,41 @@ type_companion_object(
|
||||
unique int companion_object: @classorinterface ref
|
||||
);
|
||||
|
||||
/**
|
||||
* `id` is the Kotlin type for the non-nullable class type `classid`.
|
||||
*/
|
||||
kt_class_types(
|
||||
unique int id: @kt_class_type,
|
||||
int classid: @reftype ref
|
||||
)
|
||||
|
||||
/**
|
||||
* `id` is the Kotlin type that is the same as `kttypeid`, but is nullable.
|
||||
*/
|
||||
kt_nullable_types(
|
||||
unique int id: @kt_nullable_type,
|
||||
int classid: @reftype ref
|
||||
)
|
||||
|
||||
kt_notnull_types(
|
||||
unique int id: @kt_notnull_type,
|
||||
int classid: @reftype ref
|
||||
int kttypeid: @kt_type ref
|
||||
)
|
||||
|
||||
/**
|
||||
* `id` is the Kotlin type that is the alias called `name` of `kttypeid`.
|
||||
* That is, it has been defined by `typealias name = kttypeid`.
|
||||
*/
|
||||
kt_type_alias(
|
||||
unique int id: @kt_type_alias,
|
||||
string name: string ref,
|
||||
int kttypeid: @kt_type ref
|
||||
)
|
||||
|
||||
@kt_type = @kt_nullable_type | @kt_notnull_type
|
||||
/**
|
||||
* A `kt_error_type` is used when the extractor is unable to extract a type
|
||||
* correctly for some reason.
|
||||
*/
|
||||
kt_error_types(
|
||||
unique int id: @kt_error_type
|
||||
)
|
||||
|
||||
@kt_type = @kt_class_type | @kt_nullable_type | @kt_type_alias | @kt_error_type
|
||||
|
||||
/**
|
||||
* This holds if `id` is an `interface`, rather than a `class`.
|
||||
|
||||
@@ -8,28 +8,31 @@ class KotlinType extends Element, @kt_type { }
|
||||
|
||||
class KotlinNullableType extends KotlinType, @kt_nullable_type {
|
||||
override string toString() {
|
||||
exists(RefType javaType |
|
||||
kt_nullable_types(this, javaType) and
|
||||
result = "Kotlin nullable " + javaType.toString()
|
||||
exists(KotlinType ktType |
|
||||
kt_nullable_types(this, ktType) and
|
||||
result = ktType.toString() + "?"
|
||||
)
|
||||
}
|
||||
|
||||
override string getAPrimaryQlClass() { result = "KotlinNullableType" }
|
||||
}
|
||||
|
||||
class KotlinNotnullType extends KotlinType, @kt_notnull_type {
|
||||
override string toString() {
|
||||
exists(RefType javaType |
|
||||
kt_notnull_types(this, javaType) and
|
||||
result = "Kotlin not-null " + javaType.toString()
|
||||
)
|
||||
}
|
||||
class KotlinClassType extends KotlinType, @kt_class_type {
|
||||
override string toString() { result = this.getClass().toString() }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "KotlinNotnullType" }
|
||||
|
||||
RefType getClass() { kt_class_types(this, result) }
|
||||
}
|
||||
|
||||
class KotlinTypeAlias extends Element, @kt_type_alias {
|
||||
class KotlinTypeAlias extends KotlinType, @kt_type_alias {
|
||||
override string getAPrimaryQlClass() { result = "KotlinTypeAlias" }
|
||||
|
||||
override string toString() {
|
||||
result = "{" + this.getKotlinType().toString() + "}" + this.getName()
|
||||
}
|
||||
|
||||
override string getName() { kt_type_alias(this, result, _) }
|
||||
|
||||
KotlinType getKotlinType() { kt_type_alias(this, _, result) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user