Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion swift/ql/lib/codeql/swift/elements/Diagnostics.qll
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
private import codeql.swift.generated.Diagnostics

class Diagnostics extends Generated::Diagnostics {
override string toString() { result = getText() }
override string toString() { result = this.getSeverity() + ": " + this.getText() }

string getSeverity() {
this.getKind() = 1 and result = "error"
or
this.getKind() = 2 and result = "warning"
or
this.getKind() = 3 and result = "note"
or
this.getKind() = 4 and result = "remark"
}
}

class CompilerError extends Diagnostics {
CompilerError() { this.getSeverity() = "error" }
}

class CompilerWarning extends Diagnostics {
CompilerWarning() { this.getSeverity() = "warning" }
}

class CompilerNote extends Diagnostics {
CompilerNote() { this.getSeverity() = "note" }
}

class CompilerRemark extends Diagnostics {
CompilerRemark() { this.getSeverity() = "remark" }
}
11 changes: 11 additions & 0 deletions swift/ql/src/diagnostics/internal/ExtractionErrors.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @name Compiler errors
* @description List all compiler errors for files in the source code directory.
* @kind diagnostic
* @id swift/diagnostics/extraction-errors
*/

import swift

from CompilerError error
select error, "Compiler error in " + error.getFile() + " with error message " + error.getText()
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
| diags.swift:1:10:1:10 | Hello, warning | getText: | Hello, warning | getKind: | 2 |
| error.swift:2:14:2:14 | cannot convert value of type 'String' to specified type 'Int' | getText: | cannot convert value of type 'String' to specified type 'Int' | getKind: | 1 |
| import-error.swift:2:8:2:8 | no such module 'FooBar' | getText: | no such module 'FooBar' | getKind: | 1 |
| diags.swift:1:10:1:10 | warning: Hello, warning | getText: | Hello, warning | getKind: | 2 |
| error.swift:2:14:2:14 | error: cannot convert value of type 'String' to specified type 'Int' | getText: | cannot convert value of type 'String' to specified type 'Int' | getKind: | 1 |
| import-error.swift:2:8:2:8 | error: no such module 'FooBar' | getText: | no such module 'FooBar' | getKind: | 1 |