mirror of
https://github.com/github/codeql.git
synced 2026-05-04 13:15:21 +02:00
Merge pull request #20954 from hvitved/rust/stats-more-calls
Rust: Include more calls in DB quality metrics
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
/**
|
||||
* Provides database quality statistics that are reported by
|
||||
* `rust/telemetry/extractor-information`
|
||||
* and perhaps warned about by `rust/diagnostics/database-quality`.
|
||||
* and perhaps warned about by `rust/diagnostic/database-quality`.
|
||||
*/
|
||||
|
||||
import rust
|
||||
import codeql.util.ReportStats
|
||||
import codeql.rust.elements.internal.CallExprImpl::Impl as CallExprImpl
|
||||
import codeql.rust.internal.TypeInference as TypeInference
|
||||
import codeql.rust.internal.Type
|
||||
|
||||
/**
|
||||
* A file that is included in the quality statistics.
|
||||
@@ -20,25 +21,26 @@ private class RelevantFile extends File {
|
||||
}
|
||||
|
||||
module CallTargetStats implements StatsSig {
|
||||
// TODO: Take other calls into account
|
||||
abstract private class CallExprBase extends InvocationExpr { }
|
||||
|
||||
private class CallExprCallExprBase extends CallExpr, CallExprBase { }
|
||||
|
||||
private class MethodCallExprCallExprBase extends MethodCallExpr, CallExprBase { }
|
||||
|
||||
int getNumberOfOk() {
|
||||
result =
|
||||
count(CallExprBase c | c.getFile() instanceof RelevantFile and exists(c.getResolvedTarget()))
|
||||
/**
|
||||
* A call-like expression that is relevant for call target statistics.
|
||||
*
|
||||
* Note that this also includes tuple struct instantiations and tuple
|
||||
* variant instantiations.
|
||||
*/
|
||||
private class RelevantInvocationExpr extends InvocationExpr {
|
||||
RelevantInvocationExpr() {
|
||||
this.getFile() instanceof RelevantFile and
|
||||
not this instanceof CallExprImpl::DynamicCallExpr and
|
||||
not this = any(Operation o | not o.isOverloaded(_, _, _)) and
|
||||
not this = any(DerefExpr de | TypeInference::inferType(de.getExpr()) instanceof PtrType)
|
||||
}
|
||||
}
|
||||
|
||||
additional predicate isNotOkCall(CallExprBase c) {
|
||||
c.getFile() instanceof RelevantFile and
|
||||
not exists(c.getResolvedTarget()) and
|
||||
not c instanceof CallExprImpl::DynamicCallExpr
|
||||
}
|
||||
int getNumberOfOk() { result = count(RelevantInvocationExpr e | exists(e.getResolvedTarget())) }
|
||||
|
||||
int getNumberOfNotOk() { result = count(CallExprBase c | isNotOkCall(c)) }
|
||||
additional predicate isNotOkCall(RelevantInvocationExpr e) { not exists(e.getResolvedTarget()) }
|
||||
|
||||
int getNumberOfNotOk() { result = count(RelevantInvocationExpr e | isNotOkCall(e)) }
|
||||
|
||||
string getOkText() { result = "calls with call target" }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user