Skip to content

Commit 0a6edd3

Browse files
authored
Merge pull request #13405 from geoffw0/swiftloc
Swift: Improve SummaryStats.ql
2 parents 65a68f5 + 5727d49 commit 0a6edd3

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

swift/ql/lib/codeql/swift/elements/Diagnostics.qll

+18
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
private import codeql.swift.generated.Diagnostics
22

3+
/**
4+
* A compiler-generated error, warning, note or remark.
5+
*/
36
class Diagnostics extends Generated::Diagnostics {
47
override string toString() { result = this.getSeverity() + ": " + this.getText() }
58

9+
/**
10+
* Gets a string representing the severity of this compiler diagnostic.
11+
*/
612
string getSeverity() {
713
this.getKind() = 1 and result = "error"
814
or
@@ -14,18 +20,30 @@ class Diagnostics extends Generated::Diagnostics {
1420
}
1521
}
1622

23+
/**
24+
* A compiler error message.
25+
*/
1726
class CompilerError extends Diagnostics {
1827
CompilerError() { this.getSeverity() = "error" }
1928
}
2029

30+
/**
31+
* A compiler-generated warning.
32+
*/
2133
class CompilerWarning extends Diagnostics {
2234
CompilerWarning() { this.getSeverity() = "warning" }
2335
}
2436

37+
/**
38+
* A compiler-generated note (typically attached to an error or warning).
39+
*/
2540
class CompilerNote extends Diagnostics {
2641
CompilerNote() { this.getSeverity() = "note" }
2742
}
2843

44+
/**
45+
* A compiler-generated remark (milder than a warning, this does not indicate an issue).
46+
*/
2947
class CompilerRemark extends Diagnostics {
3048
CompilerRemark() { this.getSeverity() = "remark" }
3149
}

swift/ql/lib/codeql/swift/elements/File.qll

+15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
private import codeql.swift.generated.File
2+
private import codeql.swift.elements.Location
3+
private import codeql.swift.elements.UnknownLocation
24

35
class File extends Generated::File {
46
/** toString */
@@ -17,4 +19,17 @@ class File extends Generated::File {
1719
string getBaseName() {
1820
result = this.getAbsolutePath().regexpCapture(".*/(([^/]*?)(?:\\.([^.]*))?)", 1)
1921
}
22+
23+
/**
24+
* Gets the number of lines containing code in this file. This value
25+
* is approximate.
26+
*/
27+
int getNumberOfLinesOfCode() {
28+
result =
29+
count(int line |
30+
exists(Location loc |
31+
not loc instanceof UnknownLocation and loc.getFile() = this and loc.getStartLine() = line
32+
)
33+
)
34+
}
2035
}

swift/ql/src/diagnostics/SuccessfullyExtractedLines.ql

+1-5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,4 @@
88

99
import swift
1010

11-
select count(File f, int line |
12-
exists(Location loc |
13-
not loc instanceof UnknownLocation and loc.getFile() = f and loc.getStartLine() = line
14-
)
15-
)
11+
select sum(File f | | f.getNumberOfLinesOfCode())

swift/ql/src/queries/Summary/SummaryStats.ql

+6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ float taintReach() { result = (taintedNodesCount() * 1000000.0) / count(DataFlow
3737
predicate statistic(string what, string value) {
3838
what = "Files" and value = count(File f).toString()
3939
or
40+
what = "Lines of code" and value = sum(File f | | f.getNumberOfLinesOfCode()).toString()
41+
or
42+
what = "Compiler errors" and value = count(CompilerError d).toString()
43+
or
44+
what = "Compiler warnings" and value = count(CompilerWarning d).toString()
45+
or
4046
what = "Expressions" and value = count(Expr e | not e.getFile() instanceof UnknownFile).toString()
4147
or
4248
what = "Local flow sources" and value = count(LocalFlowSource s).toString()

0 commit comments

Comments
 (0)