Skip to content

Commit f08fea4

Browse files
committed
Added SMAP string builder
1 parent f742d28 commit f08fea4

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

compiler/src/dotty/tools/backend/jvm/InlinedSourceMaps.scala

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ object InlinedSourceMaps:
110110
if cunit.source.file.isVirtual then InlinedSourceMap(cunit, Nil, Map.empty[SourceFile, String])
111111
else
112112
var lastLine = cunit.tpdTree.sourcePos.endLine
113-
// returns the first fake line (starting from 0)
113+
// returns the first fake line (starting from 0)
114114
def allocate(origPos: SourcePosition): Int =
115115
val line = lastLine + 1
116116
lastLine += origPos.lines.length
@@ -128,7 +128,35 @@ object InlinedSourceMaps:
128128
requests: List[Request],
129129
internalNames: Map[SourceFile, String])(using Context):
130130

131-
def debugExtension: Option[String] = Some("TODO")
131+
def debugExtension: Option[String] = Option.when(requests.nonEmpty) {
132+
val scalaStratum =
133+
val files = cunit.source :: requests.map(_.inline.expansion.source).distinct.filter(_ != cunit.source)
134+
val mappings = requests.map { case Request(inline, firstFakeLine) =>
135+
Mapping(inline.expansion.sourcePos.startLine,
136+
files.indexOf(inline.expansion.source) + 1,
137+
inline.expansion.sourcePos.lines.length,
138+
firstFakeLine, 1)
139+
}
140+
Stratum("Scala",
141+
files.zipWithIndex.map { case (f, n) => File(n + 1, f.name, internalNames.get(f)) },
142+
Mapping(0, 1, cunit.tpdTree.sourcePos.lines.length, 0, 1) +: mappings
143+
)
144+
145+
val debugStratum =
146+
val mappings = requests.map { case Request(inline, firstFakeLine) =>
147+
Mapping(inline.sourcePos.startLine, 1, 1, firstFakeLine, inline.expansion.sourcePos.lines.length)
148+
}
149+
Stratum("ScalaDebug", File(1, cunit.source.name, None) :: Nil, mappings)
150+
151+
val b = new StringBuilder
152+
b ++= "SMAP\n"
153+
b ++= cunit.source.name
154+
b += '\n'
155+
b ++= "Scala\n"
156+
scalaStratum.write(b)
157+
debugStratum.write(b)
158+
b.toString
159+
}
132160

133161
def lineFor(tree: Tree): Option[Int] =
134162

0 commit comments

Comments
 (0)