|
| 1 | +/** |
| 2 | + * Provides database quality statistics that are reported by csharp/telemetry/extractor-information |
| 3 | + * and perhaps warned about by csharp/diagnostics/database-quality. |
| 4 | + */ |
| 5 | + |
| 6 | +import csharp |
| 7 | + |
| 8 | +signature module StatsSig { |
| 9 | + int getNumberOfOk(); |
| 10 | + |
| 11 | + int getNumberOfNotOk(); |
| 12 | + |
| 13 | + string getOkText(); |
| 14 | + |
| 15 | + string getNotOkText(); |
| 16 | +} |
| 17 | + |
| 18 | +module ReportStats<StatsSig Stats> { |
| 19 | + predicate numberOfOk(string key, int value) { |
| 20 | + value = Stats::getNumberOfOk() and |
| 21 | + key = "Number of " + Stats::getOkText() |
| 22 | + } |
| 23 | + |
| 24 | + predicate numberOfNotOk(string key, int value) { |
| 25 | + value = Stats::getNumberOfNotOk() and |
| 26 | + key = "Number of " + Stats::getNotOkText() |
| 27 | + } |
| 28 | + |
| 29 | + predicate percentageOfOk(string key, float value) { |
| 30 | + value = Stats::getNumberOfOk() * 100.0 / (Stats::getNumberOfOk() + Stats::getNumberOfNotOk()) and |
| 31 | + key = "Percentage of " + Stats::getOkText() |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +module CallTargetStats implements StatsSig { |
| 36 | + int getNumberOfOk() { result = count(Call c | exists(c.getTarget())) } |
| 37 | + |
| 38 | + int getNumberOfNotOk() { |
| 39 | + result = |
| 40 | + count(Call c | |
| 41 | + not exists(c.getTarget()) and |
| 42 | + not c instanceof DelegateCall and |
| 43 | + not c instanceof DynamicExpr |
| 44 | + ) |
| 45 | + } |
| 46 | + |
| 47 | + string getOkText() { result = "calls with call target" } |
| 48 | + |
| 49 | + string getNotOkText() { result = "calls with missing call target" } |
| 50 | +} |
| 51 | + |
| 52 | +private class SourceExpr extends Expr { |
| 53 | + SourceExpr() { this.getFile().fromSource() } |
| 54 | +} |
| 55 | + |
| 56 | +private predicate hasGoodType(Expr e) { |
| 57 | + exists(e.getType()) and not e.getType() instanceof UnknownType |
| 58 | +} |
| 59 | + |
| 60 | +module ExprTypeStats implements StatsSig { |
| 61 | + int getNumberOfOk() { result = count(SourceExpr e | hasGoodType(e)) } |
| 62 | + |
| 63 | + int getNumberOfNotOk() { result = count(SourceExpr e | not hasGoodType(e)) } |
| 64 | + |
| 65 | + string getOkText() { result = "expressions with known type" } |
| 66 | + |
| 67 | + string getNotOkText() { result = "expressions with unknown type" } |
| 68 | +} |
| 69 | + |
| 70 | +module CallTargetStatsReport = ReportStats<CallTargetStats>; |
| 71 | + |
| 72 | +module ExprTypeStatsReport = ReportStats<ExprTypeStats>; |
0 commit comments