mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Merge pull request #10857 from geoffw0/locationstring
Swift: Give Location a useful toString
This commit is contained in:
@@ -1,11 +1,28 @@
|
||||
private import codeql.swift.generated.Location
|
||||
|
||||
/**
|
||||
* A location of a program element.
|
||||
*/
|
||||
class Location extends LocationBase {
|
||||
predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
|
||||
path = getFile().getFullName() and
|
||||
sl = getStartLine() and
|
||||
sc = getStartColumn() and
|
||||
el = getEndLine() and
|
||||
ec = getEndColumn()
|
||||
/**
|
||||
* Holds if this location is described by `path`, `startLine`, `startColumn`, `endLine` and `endColumn`.
|
||||
*/
|
||||
predicate hasLocationInfo(string path, int startLine, int startColumn, int endLine, int endColumn) {
|
||||
path = this.getFile().getFullName() and
|
||||
startLine = this.getStartLine() and
|
||||
startColumn = this.getStartColumn() and
|
||||
endLine = this.getEndLine() and
|
||||
endColumn = this.getEndColumn()
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a textual representation of this location.
|
||||
*/
|
||||
override string toString() {
|
||||
exists(string filePath, int startLine, int startColumn, int endLine, int endColumn |
|
||||
this.hasLocationInfo(filePath, startLine, startColumn, endLine, endColumn)
|
||||
|
|
||||
toUrl(filePath, startLine, startColumn, endLine, endColumn, result)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@ private import codeql.swift.generated.UnknownLocation
|
||||
private import codeql.swift.elements.UnknownFile
|
||||
private import codeql.swift.elements.File
|
||||
|
||||
/**
|
||||
* A `Location` that is given to something that is not associated with any position in the source code.
|
||||
*/
|
||||
class UnknownLocation extends UnknownLocationBase {
|
||||
override File getImmediateFile() { result instanceof UnknownFile }
|
||||
|
||||
@@ -12,4 +15,6 @@ class UnknownLocation extends UnknownLocationBase {
|
||||
override int getEndLine() { result = 0 }
|
||||
|
||||
override int getEndColumn() { result = 0 }
|
||||
|
||||
override string toString() { result = "UnknownLocation" }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
| file://:0:0:0:0 | UnknownLocation |
|
||||
| location.swift:2:1:3:1 | location.swift:2:1:3:1 |
|
||||
| location.swift:2:11:2:14 | location.swift:2:11:2:14 |
|
||||
| location.swift:2:19:3:1 | location.swift:2:19:3:1 |
|
||||
@@ -0,0 +1,4 @@
|
||||
import swift
|
||||
|
||||
from Location l
|
||||
select l
|
||||
@@ -0,0 +1,3 @@
|
||||
|
||||
func test(x: Int) {
|
||||
}
|
||||
Reference in New Issue
Block a user