Merge pull request #13405 from geoffw0/swiftloc

Swift: Improve SummaryStats.ql
This commit is contained in:
Geoffrey White
2023-06-08 14:02:03 +01:00
committed by GitHub
4 changed files with 40 additions and 5 deletions

View File

@@ -1,8 +1,14 @@
private import codeql.swift.generated.Diagnostics
/**
* A compiler-generated error, warning, note or remark.
*/
class Diagnostics extends Generated::Diagnostics {
override string toString() { result = this.getSeverity() + ": " + this.getText() }
/**
* Gets a string representing the severity of this compiler diagnostic.
*/
string getSeverity() {
this.getKind() = 1 and result = "error"
or
@@ -14,18 +20,30 @@ class Diagnostics extends Generated::Diagnostics {
}
}
/**
* A compiler error message.
*/
class CompilerError extends Diagnostics {
CompilerError() { this.getSeverity() = "error" }
}
/**
* A compiler-generated warning.
*/
class CompilerWarning extends Diagnostics {
CompilerWarning() { this.getSeverity() = "warning" }
}
/**
* A compiler-generated note (typically attached to an error or warning).
*/
class CompilerNote extends Diagnostics {
CompilerNote() { this.getSeverity() = "note" }
}
/**
* A compiler-generated remark (milder than a warning, this does not indicate an issue).
*/
class CompilerRemark extends Diagnostics {
CompilerRemark() { this.getSeverity() = "remark" }
}

View File

@@ -1,4 +1,6 @@
private import codeql.swift.generated.File
private import codeql.swift.elements.Location
private import codeql.swift.elements.UnknownLocation
class File extends Generated::File {
/** toString */
@@ -17,4 +19,17 @@ class File extends Generated::File {
string getBaseName() {
result = this.getAbsolutePath().regexpCapture(".*/(([^/]*?)(?:\\.([^.]*))?)", 1)
}
/**
* Gets the number of lines containing code in this file. This value
* is approximate.
*/
int getNumberOfLinesOfCode() {
result =
count(int line |
exists(Location loc |
not loc instanceof UnknownLocation and loc.getFile() = this and loc.getStartLine() = line
)
)
}
}

View File

@@ -8,8 +8,4 @@
import swift
select count(File f, int line |
exists(Location loc |
not loc instanceof UnknownLocation and loc.getFile() = f and loc.getStartLine() = line
)
)
select sum(File f | | f.getNumberOfLinesOfCode())

View File

@@ -37,6 +37,12 @@ float taintReach() { result = (taintedNodesCount() * 1000000.0) / count(DataFlow
predicate statistic(string what, string value) {
what = "Files" and value = count(File f).toString()
or
what = "Lines of code" and value = sum(File f | | f.getNumberOfLinesOfCode()).toString()
or
what = "Compiler errors" and value = count(CompilerError d).toString()
or
what = "Compiler warnings" and value = count(CompilerWarning d).toString()
or
what = "Expressions" and value = count(Expr e | not e.getFile() instanceof UnknownFile).toString()
or
what = "Local flow sources" and value = count(LocalFlowSource s).toString()