mirror of
https://github.com/github/codeql.git
synced 2026-04-29 18:55:14 +02:00
Kotlin: Pull Kotlin type for fields out into its own table
This commit is contained in:
@@ -346,7 +346,8 @@ open class KotlinFileExtractor(
|
||||
// here.
|
||||
val instance = useObjectClassInstance(c)
|
||||
val type = useSimpleTypeClass(c, emptyList(), false)
|
||||
tw.writeFields(instance.id, instance.name, type.javaResult.id, type.kotlinResult.id, id, instance.id)
|
||||
tw.writeFields(instance.id, instance.name, type.javaResult.id, id, instance.id)
|
||||
tw.writeFieldsKotlinType(instance.id, type.kotlinResult.id)
|
||||
tw.writeHasLocation(instance.id, locId)
|
||||
addModifiers(instance.id, "public", "static", "final")
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@@ -382,7 +383,8 @@ open class KotlinFileExtractor(
|
||||
val instance = useCompanionObjectClassInstance(innerClass)
|
||||
if(instance != null) {
|
||||
val type = useSimpleTypeClass(innerClass, emptyList(), false)
|
||||
tw.writeFields(instance.id, instance.name, type.javaResult.id, type.kotlinResult.id, innerId, instance.id)
|
||||
tw.writeFields(instance.id, instance.name, type.javaResult.id, innerId, instance.id)
|
||||
tw.writeFieldsKotlinType(instance.id, type.kotlinResult.id)
|
||||
tw.writeHasLocation(instance.id, innerLocId)
|
||||
addModifiers(instance.id, "public", "static", "final")
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@@ -614,7 +616,8 @@ open class KotlinFileExtractor(
|
||||
|
||||
private fun extractField(id: Label<out DbField>, name: String, type: IrType, parentId: Label<out DbReftype>, locId: Label<DbLocation>, visibility: DescriptorVisibility, errorElement: IrElement, isExternalDeclaration: Boolean): Label<out DbField> {
|
||||
val t = useType(type)
|
||||
tw.writeFields(id, name, t.javaResult.id, t.kotlinResult.id, parentId, id)
|
||||
tw.writeFields(id, name, t.javaResult.id, parentId, id)
|
||||
tw.writeFieldsKotlinType(id, t.kotlinResult.id)
|
||||
tw.writeHasLocation(id, locId)
|
||||
|
||||
extractVisibility(errorElement, id, visibility)
|
||||
@@ -694,7 +697,8 @@ open class KotlinFileExtractor(
|
||||
logger.warnElement(Severity.ErrorSevere, "Enum entry parent class has type parameters: " + parent.name, ee)
|
||||
} else {
|
||||
val type = useSimpleTypeClass(parent, emptyList(), false)
|
||||
tw.writeFields(id, ee.name.asString(), type.javaResult.id, type.kotlinResult.id, parentId, id)
|
||||
tw.writeFields(id, ee.name.asString(), type.javaResult.id, parentId, id)
|
||||
tw.writeFieldsKotlinType(id, type.kotlinResult.id)
|
||||
val locId = tw.getLocation(ee)
|
||||
tw.writeHasLocation(id, locId)
|
||||
}
|
||||
|
||||
@@ -392,7 +392,8 @@ open class KotlinUsesExtractor(
|
||||
// array.length
|
||||
val length = tw.getLabelFor<DbField>("@\"field;{$it};length\"")
|
||||
val intTypeIds = useType(pluginContext.irBuiltIns.intType)
|
||||
tw.writeFields(length, "length", intTypeIds.javaResult.id, intTypeIds.kotlinResult.id, it, length)
|
||||
tw.writeFields(length, "length", intTypeIds.javaResult.id, it, length)
|
||||
tw.writeFieldsKotlinType(length, intTypeIds.kotlinResult.id)
|
||||
addModifiers(length, "public", "final")
|
||||
|
||||
// Note we will only emit one `clone()` method per Java array type, so we choose `Array<C?>` as its Kotlin
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import java
|
||||
|
||||
predicate badKotlinType(Element e, int i) {
|
||||
e = any(Expr expr | count(expr.getKotlinType()) = i)
|
||||
e = any(Expr expr | count(expr.getKotlinType()) = i) or
|
||||
e = any(Field f | count(f.getKotlinType()) = i)
|
||||
}
|
||||
|
||||
from Element e, int i
|
||||
|
||||
@@ -399,11 +399,15 @@ fields(
|
||||
unique int id: @field,
|
||||
string nodeName: string ref,
|
||||
int typeid: @type ref,
|
||||
int kttypeid: @kt_type ref,
|
||||
int parentid: @reftype ref,
|
||||
int sourceid: @field ref
|
||||
);
|
||||
|
||||
fieldsKotlinType(
|
||||
unique int id: @field ref,
|
||||
int kttypeid: @kt_type ref
|
||||
)
|
||||
|
||||
constrs(
|
||||
unique int id: @constructor,
|
||||
string nodeName: string ref,
|
||||
|
||||
@@ -20,7 +20,7 @@ predicate hasName(Element e, string name) {
|
||||
or
|
||||
methods(e, name, _, _, _, _, _)
|
||||
or
|
||||
fields(e, name, _, _, _, _)
|
||||
fields(e, name, _, _, _)
|
||||
or
|
||||
packages(e, name)
|
||||
or
|
||||
|
||||
@@ -63,7 +63,7 @@ private predicate hasChildElement(Element parent, Element e) {
|
||||
or
|
||||
params(e, _, _, _, parent, _)
|
||||
or
|
||||
fields(e, _, _, _, parent, _)
|
||||
fields(e, _, _, parent, _)
|
||||
or
|
||||
typeVars(e, _, _, _, parent)
|
||||
}
|
||||
|
||||
@@ -613,13 +613,13 @@ class FieldDeclaration extends ExprParent, @fielddecl, Annotatable {
|
||||
/** A class or instance field. */
|
||||
class Field extends Member, ExprParent, @field, Variable {
|
||||
/** Gets the declared type of this field. */
|
||||
override Type getType() { fields(this, _, result, _, _, _) }
|
||||
override Type getType() { fields(this, _, result, _, _) }
|
||||
|
||||
/** Gets the Kotlin type of this field. */
|
||||
override KotlinType getKotlinType() { fields(this, _, _, result, _, _) }
|
||||
override KotlinType getKotlinType() { fieldsKotlinType(this, result) }
|
||||
|
||||
/** Gets the type in which this field is declared. */
|
||||
override RefType getDeclaringType() { fields(this, _, _, _, result, _) }
|
||||
override RefType getDeclaringType() { fields(this, _, _, result, _) }
|
||||
|
||||
/**
|
||||
* Gets the field declaration in which this field is declared.
|
||||
@@ -649,7 +649,7 @@ class Field extends Member, ExprParent, @field, Variable {
|
||||
*
|
||||
* For all other fields, the source declaration is the field itself.
|
||||
*/
|
||||
Field getSourceDeclaration() { fields(this, _, _, _, _, result) }
|
||||
Field getSourceDeclaration() { fields(this, _, _, _, result) }
|
||||
|
||||
/** Holds if this field is the same as its source declaration. */
|
||||
predicate isSourceDeclaration() { this.getSourceDeclaration() = this }
|
||||
|
||||
@@ -319,7 +319,7 @@ predicate declaresMember(Type t, @member m) {
|
||||
or
|
||||
constrs(m, _, _, _, _, t, _)
|
||||
or
|
||||
fields(m, _, _, _, t, _)
|
||||
fields(m, _, _, t, _)
|
||||
or
|
||||
enclInReftype(m, t) and
|
||||
// Since the type `@member` in the dbscheme includes all `@reftype`s,
|
||||
@@ -1136,11 +1136,11 @@ class EnumType extends Class {
|
||||
|
||||
/** Gets the enum constant with the specified name. */
|
||||
EnumConstant getEnumConstant(string name) {
|
||||
fields(result, _, _, _, this, _) and result.hasName(name)
|
||||
fields(result, _, _, this, _) and result.hasName(name)
|
||||
}
|
||||
|
||||
/** Gets an enum constant declared in this enum type. */
|
||||
EnumConstant getAnEnumConstant() { fields(result, _, _, _, this, _) }
|
||||
EnumConstant getAnEnumConstant() { fields(result, _, _, this, _) }
|
||||
|
||||
override predicate isFinal() {
|
||||
// JLS 8.9: An enum declaration is implicitly `final` unless it contains
|
||||
|
||||
Reference in New Issue
Block a user