Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 76ca0b2

Browse files
committed
Kotlin: Pull Kotlin type for localvars out into its own table
1 parent 7862229 commit 76ca0b2

6 files changed

Lines changed: 19 additions & 13 deletions

File tree

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,8 @@ open class KotlinFileExtractor(
801801
val exprId = tw.getFreshIdLabel<DbLocalvariabledeclexpr>()
802802
val locId = tw.getLocation(getVariableLocationProvider(v))
803803
val type = useType(v.type)
804-
tw.writeLocalvars(varId, v.name.asString(), type.javaResult.id, type.kotlinResult.id, exprId)
804+
tw.writeLocalvars(varId, v.name.asString(), type.javaResult.id, exprId)
805+
tw.writeLocalvarsKotlinType(varId, type.kotlinResult.id)
805806
tw.writeHasLocation(varId, locId)
806807
tw.writeExprs_localvariabledeclexpr(exprId, type.javaResult.id, parent, idx)
807808
tw.writeExprsKotlinType(exprId, type.kotlinResult.id)

java/ql/consistency-queries/kotlinTypes.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import java
22

33
predicate badKotlinType(Element e, int i) {
44
e = any(Expr expr | count(expr.getKotlinType()) = i) or
5+
e = any(LocalVariableDecl lvd | count(lvd.getKotlinType()) = i) or
56
e = any(Parameter p | count(p.getKotlinType()) = i) or
67
e = any(Constructor c | count(c.getReturnKotlinType()) = i) or
78
e = any(Method m | count(m.getReturnKotlinType()) = i) or

java/ql/lib/config/semmlecode.dbscheme

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ fields(
406406
fieldsKotlinType(
407407
unique int id: @field ref,
408408
int kttypeid: @kt_type ref
409-
)
409+
);
410410

411411
constrs(
412412
unique int id: @constructor,
@@ -420,7 +420,7 @@ constrs(
420420
constrsKotlinType(
421421
unique int id: @constructor ref,
422422
int kttypeid: @kt_type ref
423-
)
423+
);
424424

425425
methods(
426426
unique int id: @method,
@@ -434,7 +434,7 @@ methods(
434434
methodsKotlinType(
435435
unique int id: @method ref,
436436
int kttypeid: @kt_type ref
437-
)
437+
);
438438

439439
#keyset[parentid,pos]
440440
params(
@@ -448,7 +448,7 @@ params(
448448
paramsKotlinType(
449449
unique int id: @param ref,
450450
int kttypeid: @kt_type ref
451-
)
451+
);
452452

453453
paramName(
454454
unique int id: @param ref,
@@ -644,7 +644,7 @@ exprs(
644644
exprsKotlinType(
645645
unique int id: @expr ref,
646646
int kttypeid: @kt_type ref
647-
)
647+
);
648648

649649
callableEnclosingExpr(
650650
unique int id: @expr ref,
@@ -856,10 +856,14 @@ localvars(
856856
unique int id: @localvar,
857857
string nodeName: string ref,
858858
int typeid: @type ref,
859-
int kttypeid: @kt_type ref,
860859
int parentid: @localvariabledeclexpr ref
861860
);
862861

862+
localvarsKotlinType(
863+
unique int id: @localvar ref,
864+
int kttypeid: @kt_type ref
865+
);
866+
863867
@namedexprorstmt = @breakstmt
864868
| @continuestmt
865869
| @labeledstmt

java/ql/lib/semmle/code/Location.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ predicate hasName(Element e, string name) {
3434
name = "p" + pos
3535
)
3636
or
37-
localvars(e, name, _, _, _)
37+
localvars(e, name, _, _)
3838
or
3939
typeVars(e, name, _, _, _)
4040
or

java/ql/lib/semmle/code/java/Expr.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,7 @@ class LocalVariableDeclExpr extends Expr, @localvariabledeclexpr {
15291529
VarAccess getAnAccess() { variableBinding(result, this.getVariable()) }
15301530

15311531
/** Gets the local variable declared by this local variable declaration expression. */
1532-
LocalVariableDecl getVariable() { localvars(result, _, _, _, this) }
1532+
LocalVariableDecl getVariable() { localvars(result, _, _, this) }
15331533

15341534
/** Gets the type access of this local variable declaration expression. */
15351535
Expr getTypeAccess() {

java/ql/lib/semmle/code/java/Variable.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ class LocalScopeVariable extends Variable, @localscopevariable {
3838
/** A local variable declaration */
3939
class LocalVariableDecl extends @localvar, LocalScopeVariable {
4040
/** Gets the type of this local variable. */
41-
override Type getType() { localvars(this, _, result, _, _) }
41+
override Type getType() { localvars(this, _, result, _) }
4242

4343
/** Gets the Kotlin type of this local variable. */
44-
override KotlinType getKotlinType() { localvars(this, _, _, result, _) }
44+
override KotlinType getKotlinType() { localvarsKotlinType(this, result) }
4545

4646
/** Gets the expression declaring this variable. */
47-
LocalVariableDeclExpr getDeclExpr() { localvars(this, _, _, _, result) }
47+
LocalVariableDeclExpr getDeclExpr() { localvars(this, _, _, result) }
4848

4949
/** Gets the parent of this declaration. */
50-
Expr getParent() { localvars(this, _, _, _, result) }
50+
Expr getParent() { localvars(this, _, _, result) }
5151

5252
/** Gets the callable in which this declaration occurs. */
5353
override Callable getCallable() { result = this.getParent().getEnclosingCallable() }

0 commit comments

Comments
 (0)