Kotlin: Pull Kotlin type for params out into its own table

This commit is contained in:
Ian Lynagh
2022-01-27 14:42:20 +00:00
parent dc26abe341
commit 7862229807
7 changed files with 18 additions and 12 deletions

View File

@@ -440,7 +440,8 @@ open class KotlinFileExtractor(
private fun extractValueParameter(id: Label<out DbParam>, t: IrType, name: String, locId: Label<DbLocation>, parent: Label<out DbCallable>, idx: Int, typeSubstitution: TypeSubstitution?, paramSourceDeclaration: Label<out DbParam>): TypeResults {
val substitutedType = typeSubstitution?.let { it(t, TypeContext.OTHER, pluginContext) } ?: t
val type = useType(substitutedType)
tw.writeParams(id, type.javaResult.id, type.kotlinResult.id, idx, parent, paramSourceDeclaration)
tw.writeParams(id, type.javaResult.id, idx, parent, paramSourceDeclaration)
tw.writeParamsKotlinType(id, type.kotlinResult.id)
tw.writeHasLocation(id, locId)
tw.writeParamName(id, name)
return type

View File

@@ -2,6 +2,7 @@ import java
predicate badKotlinType(Element e, int i) {
e = any(Expr expr | count(expr.getKotlinType()) = i) or
e = any(Parameter p | count(p.getKotlinType()) = i) or
e = any(Constructor c | count(c.getReturnKotlinType()) = i) or
e = any(Method m | count(m.getReturnKotlinType()) = i) or
e = any(Field f | count(f.getKotlinType()) = i)

View File

@@ -440,12 +440,16 @@ methodsKotlinType(
params(
unique int id: @param,
int typeid: @type ref,
int kttypeid: @kt_type ref,
int pos: int ref,
int parentid: @callable ref,
int sourceid: @param ref
);
paramsKotlinType(
unique int id: @param ref,
int kttypeid: @kt_type ref
)
paramName(
unique int id: @param ref,
string nodeName: string ref

View File

@@ -29,7 +29,7 @@ predicate hasName(Element e, string name) {
paramName(e, name)
or
exists(int pos |
params(e, _, _, pos, _, _) and
params(e, _, pos, _, _) and
not paramName(e, _) and
name = "p" + pos
)

View File

@@ -61,7 +61,7 @@ private predicate hasChildElement(Element parent, Element e) {
or
constrs(e, _, _, _, parent, _)
or
params(e, _, _, _, parent, _)
params(e, _, _, parent, _)
or
fields(e, _, _, parent, _)
or

View File

@@ -186,13 +186,13 @@ class Callable extends StmtParent, Member, @callable {
Parameter getAParameter() { result.getCallable() = this }
/** Gets the formal parameter at the specified (zero-based) position. */
Parameter getParameter(int n) { params(result, _, _, n, this, _) }
Parameter getParameter(int n) { params(result, _, n, this, _) }
/** Gets the type of the formal parameter at the specified (zero-based) position. */
Type getParameterType(int n) { params(_, result, _, n, this, _) }
Type getParameterType(int n) { params(_, result, n, this, _) }
/** Gets the type of the formal parameter at the specified (zero-based) position. */
KotlinType getParameterKotlinType(int n) { params(_, _, result, n, this, _) }
KotlinType getParameterKotlinType(int n) { paramsKotlinType(this.getParameter(n), result) }
/**
* Gets the signature of this callable, including its name and the types of all

View File

@@ -66,22 +66,22 @@ class LocalVariableDecl extends @localvar, LocalScopeVariable {
/** A formal parameter of a callable. */
class Parameter extends Element, @param, LocalScopeVariable {
/** Gets the type of this formal parameter. */
override Type getType() { params(this, result, _, _, _, _) }
override Type getType() { params(this, result, _, _, _) }
/** Gets the Kotlin type of this formal parameter. */
override KotlinType getKotlinType() { params(this, _, result, _, _, _) }
override KotlinType getKotlinType() { paramsKotlinType(this, result) }
/** Holds if the parameter is never assigned a value in the body of the callable. */
predicate isEffectivelyFinal() { not exists(this.getAnAssignedValue()) }
/** Gets the (zero-based) index of this formal parameter. */
int getPosition() { params(this, _, _, result, _, _) }
int getPosition() { params(this, _, result, _, _) }
/** Gets the callable that declares this formal parameter. */
override Callable getCallable() { params(this, _, _, _, result, _) }
override Callable getCallable() { params(this, _, _, result, _) }
/** Gets the source declaration of this formal parameter. */
Parameter getSourceDeclaration() { params(this, _, _, _, _, result) }
Parameter getSourceDeclaration() { params(this, _, _, _, result) }
/** Holds if this formal parameter is the same as its source declaration. */
predicate isSourceDeclaration() { this.getSourceDeclaration() = this }