Kotlin: Handle zero-width locations for generated elements

This commit is contained in:
Ian Lynagh
2021-09-30 16:12:44 +01:00
parent 76fd386055
commit 088e7adf8c
3 changed files with 10 additions and 4 deletions

View File

@@ -78,13 +78,19 @@ class FileTrapWriter (
return getLocation(e.startOffset, e.endOffset)
}
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
// 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 startColumn = if(unknownLoc) 0 else fileEntry.getColumnNumber(startOffset) + 1
val endLine = if(unknownLoc) 0 else fileEntry.getLineNumber(endOffset) + 1
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
return getLocation(locFileId, startLine, startColumn, endLine, endColumn)
return getLocation(locFileId, startLine, startColumn, endLine, endColumn2)
}
fun getLocationString(e: IrElement): String {
val path = irFile.path

View File

@@ -7,4 +7,4 @@ superCall
| classes.kt:12:23:12:34 | super(...) |
| classes.kt:17:18:17:28 | super(...) |
| classes.kt:28:19:28:29 | super(...) |
| classes.kt:35:27:35:26 | super(...) |
| classes.kt:35:27:35:27 | super(...) |

View File

@@ -4,8 +4,8 @@ varAcc
| variables.kt:16:11:16:18 | o |
instAcc
| variables.kt:21:11:21:15 | this |
| variables.kt:24:9:24:8 | this |
| variables.kt:25:9:25:8 | this |
| variables.kt:24:9:24:9 | this |
| variables.kt:25:9:25:9 | this |
| variables.kt:26:9:26:12 | this |
| variables.kt:27:9:27:12 | this |
| variables.kt:28:9:28:12 | this |