-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathExtractorInformation.ql
More file actions
189 lines (157 loc) · 6.15 KB
/
ExtractorInformation.ql
File metadata and controls
189 lines (157 loc) · 6.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/**
* @name C# extraction information
* @description Information about the extraction for a C# database
* @kind metric
* @tags summary telemetry
* @id cs/telemetry/extraction-information
*/
import csharp
import semmle.code.csharp.commons.Diagnostics
import DatabaseQuality
predicate compilationInfo(string key, float value) {
not key.matches("Compiler diagnostic count for%") and
not key.matches("Extractor message count for group%") and
exists(Compilation c, string infoKey, string infoValue | infoValue = c.getInfo(infoKey) |
key = infoKey and
value = infoValue.toFloat()
or
not exists(infoValue.toFloat()) and
key = infoKey + ": " + infoValue and
value = 1
)
}
predicate compilerDiagnostics(string key, int value) {
key.matches("Compiler diagnostic count for%") and
strictsum(Compilation c | | c.getInfo(key).toInt()) = value
}
predicate extractorMessages(string key, int value) {
key.matches("Extractor message count for group%") and
strictsum(Compilation c | | c.getInfo(key).toInt()) = value
}
predicate fileCount(string key, int value) {
key = "Number of files" and
value = strictcount(File f)
}
predicate fileCountByExtension(string key, int value) {
exists(string extension |
key = "Number of files with extension " + extension and
value = strictcount(File f | f.getExtension() = extension)
)
}
predicate totalNumberOfLines(string key, int value) {
key = "Total number of lines" and
value = strictsum(File f | any() | f.getNumberOfLines())
}
predicate numberOfLinesOfCode(string key, int value) {
key = "Number of lines of code" and
value = strictsum(File f | any() | f.getNumberOfLinesOfCode())
}
predicate totalNumberOfLinesByExtension(string key, int value) {
exists(string extension |
key = "Total number of lines with extension " + extension and
value = strictsum(File f | f.getExtension() = extension | f.getNumberOfLines())
)
}
predicate numberOfLinesOfCodeByExtension(string key, int value) {
exists(string extension |
key = "Number of lines of code with extension " + extension and
value = strictsum(File f | f.getExtension() = extension | f.getNumberOfLinesOfCode())
)
}
predicate extractorDiagnostics(string key, int value) {
exists(int severity |
key = "Number of diagnostics with severity " + severity.toString() and
value = strictcount(Diagnostic d | d.getSeverity() = severity)
)
}
CompilerError getAmbiguityCompilerError() {
result.getSeverity() >= 3 and
result.getTag() = ["CS0101", "CS0104", "CS0111", "CS0121", "CS0229"]
}
predicate numberOfAmbiguityCompilerErrors(string key, int value) {
value = count(getAmbiguityCompilerError()) and
key = "Number of compiler reported ambiguity errors"
}
predicate numberOfDistinctAmbiguityCompilerErrorMessages(string key, int value) {
value = count(getAmbiguityCompilerError().getFullMessage()) and
key = "Number of compiler reported ambiguity error messages"
}
predicate extractionIsStandalone(string key, int value) {
(
value = 1 and
extractionIsStandalone()
or
value = 0 and
not extractionIsStandalone()
) and
key = "Is extracted with build-mode set to 'none'"
}
module TypeMentionTypeStats implements StatsSig {
int getNumberOfOk() { result = count(TypeMention t | not t.getType() instanceof UnknownType) }
int getNumberOfNotOk() { result = count(TypeMention t | t.getType() instanceof UnknownType) }
string getOkText() { result = "type mentions with known type" }
string getNotOkText() { result = "type mentions with unknown type" }
}
module AccessTargetStats implements StatsSig {
int getNumberOfOk() { result = count(Access a | exists(a.getTarget())) }
int getNumberOfNotOk() { result = count(Access a | not exists(a.getTarget())) }
string getOkText() { result = "access with target" }
string getNotOkText() { result = "access with missing target" }
}
module ExprStats implements StatsSig {
int getNumberOfOk() { result = count(Expr e | not e instanceof @unknown_expr) }
int getNumberOfNotOk() { result = count(Expr e | e instanceof @unknown_expr) }
string getOkText() { result = "expressions with known kind" }
string getNotOkText() { result = "expressions with unknown kind" }
}
module TypeMentionTypeStatsReport = ReportStats<TypeMentionTypeStats>;
module AccessTargetStatsReport = ReportStats<AccessTargetStats>;
module ExprStatsReport = ReportStats<ExprStats>;
predicate analyzerAssemblies(string key, float value) {
exists(Compilation c, string arg |
c.getExpandedArgument(_) = arg and
arg.indexOf("/analyzer:") = 0 and
key = "CSC analyzer: " + arg.substring(10, arg.length())
) and
value = 1.0
}
from string key, float value
where
(
compilationInfo(key, value) or
compilerDiagnostics(key, value) or
extractorMessages(key, value) or
fileCount(key, value) or
fileCountByExtension(key, value) or
totalNumberOfLines(key, value) or
numberOfLinesOfCode(key, value) or
totalNumberOfLinesByExtension(key, value) or
numberOfLinesOfCodeByExtension(key, value) or
extractorDiagnostics(key, value) or
numberOfAmbiguityCompilerErrors(key, value) or
numberOfDistinctAmbiguityCompilerErrorMessages(key, value) or
extractionIsStandalone(key, value) or
CallTargetStatsReport::numberOfOk(key, value) or
CallTargetStatsReport::numberOfNotOk(key, value) or
CallTargetStatsReport::percentageOfOk(key, value) or
ExprTypeStatsReport::numberOfOk(key, value) or
ExprTypeStatsReport::numberOfNotOk(key, value) or
ExprTypeStatsReport::percentageOfOk(key, value) or
TypeMentionTypeStatsReport::numberOfOk(key, value) or
TypeMentionTypeStatsReport::numberOfNotOk(key, value) or
TypeMentionTypeStatsReport::percentageOfOk(key, value) or
AccessTargetStatsReport::numberOfOk(key, value) or
AccessTargetStatsReport::numberOfNotOk(key, value) or
AccessTargetStatsReport::percentageOfOk(key, value) or
ExprStatsReport::numberOfOk(key, value) or
ExprStatsReport::numberOfNotOk(key, value) or
ExprStatsReport::percentageOfOk(key, value) or
analyzerAssemblies(key, value)
) and
/* Infinity */
value != 1.0 / 0.0 and
/* -Infinity */
value != -1.0 / 0.0 and
/* NaN */
value != 0.0 / 0.0
select key, value