mirror of
https://github.com/github/codeql.git
synced 2025-12-18 09:43:15 +01:00
Kotlin: Handle zero-width locations for generated elements
This commit is contained in:
@@ -78,13 +78,19 @@ class FileTrapWriter (
|
|||||||
return getLocation(e.startOffset, e.endOffset)
|
return getLocation(e.startOffset, e.endOffset)
|
||||||
}
|
}
|
||||||
fun getLocation(startOffset: Int, endOffset: Int): Label<DbLocation> {
|
fun getLocation(startOffset: Int, endOffset: Int): Label<DbLocation> {
|
||||||
|
// If the compiler doesn't have a location, then start and end are both -1
|
||||||
val unknownLoc = startOffset == -1 && endOffset == -1
|
val unknownLoc = startOffset == -1 && endOffset == -1
|
||||||
|
// If this is the location for a compiler-generated element, then it will
|
||||||
|
// be a zero-width location. QL doesn't support these, so we translate it
|
||||||
|
// into a one-width location.
|
||||||
|
val zeroWidthLoc = !unknownLoc && startOffset == endOffset
|
||||||
val startLine = if(unknownLoc) 0 else fileEntry.getLineNumber(startOffset) + 1
|
val startLine = if(unknownLoc) 0 else fileEntry.getLineNumber(startOffset) + 1
|
||||||
val startColumn = if(unknownLoc) 0 else fileEntry.getColumnNumber(startOffset) + 1
|
val startColumn = if(unknownLoc) 0 else fileEntry.getColumnNumber(startOffset) + 1
|
||||||
val endLine = if(unknownLoc) 0 else fileEntry.getLineNumber(endOffset) + 1
|
val endLine = if(unknownLoc) 0 else fileEntry.getLineNumber(endOffset) + 1
|
||||||
val endColumn = if(unknownLoc) 0 else fileEntry.getColumnNumber(endOffset)
|
val endColumn = if(unknownLoc) 0 else fileEntry.getColumnNumber(endOffset)
|
||||||
|
val endColumn2 = if(zeroWidthLoc) endColumn + 1 else endColumn
|
||||||
val locFileId: Label<DbFile> = if (unknownLoc) unknownFileId else fileId
|
val locFileId: Label<DbFile> = if (unknownLoc) unknownFileId else fileId
|
||||||
return getLocation(locFileId, startLine, startColumn, endLine, endColumn)
|
return getLocation(locFileId, startLine, startColumn, endLine, endColumn2)
|
||||||
}
|
}
|
||||||
fun getLocationString(e: IrElement): String {
|
fun getLocationString(e: IrElement): String {
|
||||||
val path = irFile.path
|
val path = irFile.path
|
||||||
|
|||||||
@@ -7,4 +7,4 @@ superCall
|
|||||||
| classes.kt:12:23:12:34 | super(...) |
|
| classes.kt:12:23:12:34 | super(...) |
|
||||||
| classes.kt:17:18:17:28 | super(...) |
|
| classes.kt:17:18:17:28 | super(...) |
|
||||||
| classes.kt:28:19:28:29 | super(...) |
|
| classes.kt:28:19:28:29 | super(...) |
|
||||||
| classes.kt:35:27:35:26 | super(...) |
|
| classes.kt:35:27:35:27 | super(...) |
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ varAcc
|
|||||||
| variables.kt:16:11:16:18 | o |
|
| variables.kt:16:11:16:18 | o |
|
||||||
instAcc
|
instAcc
|
||||||
| variables.kt:21:11:21:15 | this |
|
| variables.kt:21:11:21:15 | this |
|
||||||
| variables.kt:24:9:24:8 | this |
|
| variables.kt:24:9:24:9 | this |
|
||||||
| variables.kt:25:9:25:8 | this |
|
| variables.kt:25:9:25:9 | this |
|
||||||
| variables.kt:26:9:26:12 | this |
|
| variables.kt:26:9:26:12 | this |
|
||||||
| variables.kt:27:9:27:12 | this |
|
| variables.kt:27:9:27:12 | this |
|
||||||
| variables.kt:28:9:28:12 | this |
|
| variables.kt:28:9:28:12 | this |
|
||||||
|
|||||||
Reference in New Issue
Block a user