@@ -85,6 +85,8 @@ object InlinedSourceMaps:
85
85
val requests = mutable.ListBuffer .empty[(SourcePosition , SourcePosition )]
86
86
var internalNames = Map .empty[SourceFile , String ]
87
87
88
+ // Collect all inlined calls in the compilation unit
89
+
88
90
class RequestCollector (enclosingFile : SourceFile ) extends TreeTraverser :
89
91
override def traverse (tree : Tree )(using Context ): Unit =
90
92
if tree.source != enclosingFile && tree.source != cunit.source then
@@ -95,6 +97,7 @@ object InlinedSourceMaps:
95
97
cls match
96
98
case Some (symbol) if ! internalNames.isDefinedAt(tree.source) =>
97
99
internalNames += (tree.source -> internalNameProvider(symbol))
100
+ // println(s"Internal name for ${tree.source} is ${internalNames(tree.source)}")
98
101
// We are skipping any internal name info if we already have one stored in our map
99
102
// because a debugger will use internal name only to localize matching source.
100
103
// Both old and new internal names are associated with the same source file
@@ -107,17 +110,30 @@ object InlinedSourceMaps:
107
110
else traverseChildren(tree)
108
111
end RequestCollector
109
112
113
+ // Create the mapping from the real source files to the real and virtual lines
114
+
110
115
// Don't generate mappings for the quotes compiled at runtime by the staging compiler
111
116
if cunit.source.file.isVirtual then InlinedSourceMap (cunit, Nil , Map .empty[SourceFile , String ])
112
117
else
113
- var lastLine = cunit.tpdTree.sourcePos.endLine
118
+ var lastLine = cunit.tpdTree.sourcePos.endLine // Last line of the source file
119
+ // println(s"lastLine = $lastLine")
114
120
def allocate (origPos : SourcePosition ): Int =
115
- val line = lastLine + 1
121
+ val line = lastLine + 1 // Add an empty line. Why ?
116
122
lastLine += origPos.lines.length
123
+ // println(s"LastLine = $lastLine, line = $line")
117
124
line
118
125
119
126
RequestCollector (cunit.source).traverse(cunit.tpdTree)
120
127
val allocated = requests.sortBy(_._1.start).map(r => Request (r._1, r._2, allocate(r._2)))
128
+ // targetPos.startLine is the line in the source file where the inlined call is located
129
+ // origPos.startLine is the line in the source file where the inlined is defined
130
+ // firstFakeLine is the first virtual line of the inline
131
+ /* allocated.foreach { case Request(targetPos, origPos, firstFakeLine) =>
132
+ println(s"targetPos = ${targetPos.startLine}, origPos = ${origPos.startLine}, firstFakeLine = $firstFakeLine")
133
+ }*/
134
+ // internalNames is a map from source file to the internal name of the class that contains the inlined code
135
+ // Map(local/Macro_1.scala -> Macro_1$package$)
136
+ // println(s"internalNames = $internalNames")
121
137
InlinedSourceMap (cunit, allocated.toList, internalNames)
122
138
end sourceMapFor
123
139
@@ -126,10 +142,13 @@ object InlinedSourceMaps:
126
142
requests : List [Request ],
127
143
internalNames : Map [SourceFile , String ])(using Context ):
128
144
145
+ // Generate the Scala Stratum and the ScalaDebug Stratum from the map created in sourceMapFor
146
+
129
147
def debugExtension : Option [String ] = Option .when(requests.nonEmpty) {
130
148
val scalaStratum =
131
149
val files = cunit.source :: requests.map(_.origPos.source).distinct.filter(_ != cunit.source)
132
150
val mappings = requests.map { case Request (_, origPos, firstFakeLine) =>
151
+ // println(s" origPos = ${origPos.startLine}, files.indexOf(origPos.source) + 1 = ${files.indexOf(origPos.source) + 1}, origPos.lines.length = ${origPos.lines.length}, firstFakeLine = $firstFakeLine")
133
152
Mapping (origPos.startLine, files.indexOf(origPos.source) + 1 , origPos.lines.length, firstFakeLine, 1 )
134
153
}
135
154
Stratum (" Scala" ,
0 commit comments