Commit Graph

1420 Commits

Author SHA1 Message Date
Ian Lynagh
af7d809b8a Kotlin: Log to a file, not stdout
We shouldn't interfere with a build's stdout
2022-05-10 19:51:20 +01:00
Ian Lynagh
a112e9ab5c Kotlin: Add conditional dumping 2022-05-10 19:51:20 +01:00
Chris Smowton
789fe971e4 Fix locations and enclosing statement/callable for assignments 2022-05-10 19:51:20 +01:00
Ian Lynagh
cc0f5d8700 Kotlin: KotlinExtractorExtension tweaks
Added/fixed a load of comments.
Adjusted some function visibilities.
2022-05-10 19:51:20 +01:00
Tamas Vajk
67be6a18de Fix generic callable bindings inside invoke methods 2022-05-10 19:51:20 +01:00
Tamas Vajk
6742496fe3 Get type arguments for property/function references 2022-05-10 19:51:20 +01:00
Tamas Vajk
18812c810c Add PropertyRefExpr QL class, change extraction to use it, and add tests 2022-05-10 19:51:19 +01:00
Tamas Vajk
5fea49a3c9 Merge function and property reference extraction logic in helper class 2022-05-10 19:51:19 +01:00
Tamas Vajk
b4b1976bc4 Add get/set method extraction for property references 2022-05-10 19:51:19 +01:00
Tamas Vajk
4ce813a720 Extract anonymous class for property references (class, constructor, call to constructor, optional parameters) 2022-05-10 19:51:19 +01:00
Chris Smowton
f3b92e7549 Explain why there is no syntheticToRealPropertyMap 2022-05-10 19:51:19 +01:00
Chris Smowton
110a2c7b87 Try our best to fix up the truncated class graph exposed by the Kotlin Android extensions plugin 2022-05-10 19:51:19 +01:00
Chris Smowton
5fe65ed983 Extract no-when-branch-found calls
These are extracted as "throw new kotlin.NoWhenBranchFoundException();", which is the Java lowering of the intrinsic.

In the process, amend the control-flow graph to let when branches propagate `throw`s outwards, and similarly statement expressions.
2022-05-10 19:51:19 +01:00
Ian Lynagh
f8673d86b5 Kotlin: Don't double-escape TRAP strings
The TrapWriter.write* functions are going to escape them for us.
2022-05-10 19:51:19 +01:00
Ian Lynagh
dc7f8a6a5a Kotlin: Refactor TrapWriter/Logger
It's now Tpossible for TrapWriter to log warnings. This required a
little juggling to break the dependency loop between the two classes.
2022-05-10 19:51:18 +01:00
Chris Smowton
7cb6e19e44 Extract array update operations
These are of the form arrExpr[indexExpr] op= rhs
2022-05-10 19:51:18 +01:00
Tamas Vajk
ff5bbee75a Change extracted base type of function references 2022-05-10 19:51:18 +01:00
Tamas Vajk
42803a161c WIP: add test for reflective calls 2022-05-10 19:51:18 +01:00
Chris Smowton
8af0f26411 Extract simple in-place operators
Complex in-place operators (someFieldOrArrayCell += e) get a harder-to-parse lowering which needs to be intercepted at the IrBlock level
2022-05-10 19:51:18 +01:00
Chris Smowton
2fb54de269 Extract ordinary array get and set operations as ArrayAccesses, not calls 2022-05-10 19:51:18 +01:00
Tamas Vajk
387e8db161 Minor code quality improvements 2022-05-10 19:51:18 +01:00
Tamas Vajk
6154c2be18 Change arguments of big arity invoke call 2022-05-10 19:51:18 +01:00
Tamas Vajk
3f2c275e5f Fix functional interface selection 2022-05-10 19:51:18 +01:00
Tamas Vajk
8ab4335562 Add some error handling 2022-05-10 19:51:17 +01:00
Tamas Vajk
a598c7fc0c Rework SAM conversion extraction (handle arbitrary expression that's being converted) 2022-05-10 19:51:17 +01:00
Tamas Vajk
34ae00fa62 Extract SAM lambda conversion 2022-05-10 19:51:17 +01:00
Chris Smowton
377a0f91f0 Add missing times operator 2022-05-10 19:51:17 +01:00
Chris Smowton
96f3ea460f Make varargs extraction more Java-like:
* Extract varargs as if they are ordinary positional arguments
* Adapt the QL that distinguishes varargs from ordinary arguments to account for Kotlin's varargs which can occur in the middle of the arg list
* Add a test checking dataflow through varargs which doesn't work yet due to array-get and array-set not being extracted as IndexExprs
* Extract the special case arrayOf(*x) as a clone call, which is (equivalent to) the Java lowering of that operation
2022-05-10 19:51:17 +01:00
Chris Smowton
7368b49b16 Implement Any?.String using java.lang.String.valueOf
This is how kotlinc does it, and doesn't involve an unchecked null deref like the existing use of Object.toString.
2022-05-10 19:51:17 +01:00
Tamas Vajk
616f20fa52 Handle more cases of qualified this references 2022-05-10 19:51:17 +01:00
Chris Smowton
7fe260c1a2 Convert type-parameter-out-of-scope warning into consistency query
The warning in the extractor is inaccurate due to references to enclosing types' type parameters. A consistency query can check that the type parameter is indeed in scope exploiting broader knowledge of the enclosing types.
2022-05-10 19:51:17 +01:00
Chris Smowton
36356c2937 Make IntelliJ parse block TODO properly 2022-05-10 19:51:17 +01:00
Chris Smowton
2a6afff8ba Remove TODO for method source-declarations
This was resolved when method type arguments were implemented.
2022-05-10 19:51:17 +01:00
Chris Smowton
1ecbf8e84b Clean up and document erase function 2022-05-10 19:51:17 +01:00
Chris Smowton
65f3016a13 Note class-labelling todos resolved
Type arguments: yes outer classes can have arguments; they are appended after the full name.

String concatenation: this used to be worse before this unquoted version of the function existed; I think that's what the comment was complaining about.
2022-05-10 19:51:17 +01:00
Chris Smowton
7389e5d687 Note array type signatures are correctly extracted 2022-05-10 19:51:17 +01:00
Chris Smowton
38ad86f850 Note type substitution TODO done
`getUnquotedClassLabel` uses `useType` on its args to get their labels; consequently they get substituted for Java types as required.
2022-05-10 19:51:17 +01:00
Chris Smowton
d103bf65bd Remove inapplicable TODO re: K<->J type substitution
Turns out the two use cases the TODO worried about are already taken care of: `Unit` is replaced with `void` only in contexts where primitives can be used, and `List` and similar only have incompatible extension methods, which are declared by `CollectionsKt` not `List`. This is likely deliberate to enable the Kotlin <-> Java substitution to be implemented simply by kotlinc.
2022-05-10 19:51:17 +01:00
Chris Smowton
d593185a8c Quieten errors relating to generic type aliases
Turns out type aliases are always substituted by the compiler, with the `IrSimpleType.abbreviation` field indicating what the original alias was if any. Therefore we're already extracting the right types. This commit simply omits extracting a kt_type for a type alias that uses type parameters as this certainly won't work at present because we don't have IrTypes for the type parameters declared by the alias and used in its RHS.
2022-05-10 19:51:17 +01:00
Chris Smowton
1d47ea30eb Remove unused function 2022-05-10 19:51:17 +01:00
Chris Smowton
f95effcf82 Always extract ValueEQ/NEExpr for Kotlin ==/!=
I introduce AnyEqualsExpr for either reference or value equality and AnyEqualityTest for the same concept including not-equals operators, and use them wherever the written QL clearly doesn't care about the difference between reference and value comparison, typically because it is concerned with testing against null or against a primitive constant.
2022-05-10 19:51:17 +01:00
Chris Smowton
a120fab9f7 Complete implementation of equality tests
- Create a new operator representing an infix value [in]equality test, equivalent to Objects.equals(lhs, rhs)
- Continue to use simple equality where it is clearly possible at the callsite
- Note that ieee754equals is the same as Java's == and != operators
2022-05-10 19:51:17 +01:00
Ian Lynagh
97793b58cd Kotlin: Tweak diagnostic writing
In particular, we now write full exception information, so we can
diagnose problems.

We were using `warn` to log errors in some cases, and generally using
lower-level functions than necessary. We now use the appropriate
functions. I've lost the distinction between e.g. ErrorHigh and ErrorSevere
in this, but we can add it back if it's important.
2022-05-10 19:51:16 +01:00
Ian Lynagh
48c4438a78 Kotlin: Rename the final warn function to diagnostic 2022-05-10 19:51:16 +01:00
Ian Lynagh
ee9f9bb07e Kotlin: Move a function 2022-05-10 19:51:16 +01:00
Ian Lynagh
79f80e6541 Kotlin: Rename CODEQL_EXTRACTOR_KOTLIN_WARNING_LIMIT to CODEQL_EXTRACTOR_KOTLIN_DIAGNOSTIC_LIMIT 2022-05-10 19:51:16 +01:00
Ian Lynagh
a25b411dd0 Kotlin: Rename "warning" to "diagnostic" a lot 2022-05-10 19:51:16 +01:00
Ian Lynagh
9296bf3079 Kotlin: Write extractor name to TRAP file metadata 2022-05-10 19:51:16 +01:00
Chris Smowton
629af664c6 Explicitly specify whether a dispatch or an extension receiver is intended 2022-05-10 19:51:16 +01:00
Chris Smowton
377bd8f2e9 Extract String?.plus as either an AddExpr or a call to an intrinsic
If it is used by the compiler to implement the infix plus operator, resugar it and extract a `+` as Java would. If it is literally called by the user (e.g. `(if (x) then "not null" else null).plus(something)`), then extract a call to the real method Intrinsics.stringPlus (a two-arg static method).
2022-05-10 19:51:16 +01:00