@@ -82,17 +82,16 @@ object InlinedSourceMaps:
82
82
end Stratum
83
83
84
84
def sourceMapFor (cunit : CompilationUnit )(internalNameProvider : Symbol => String )(using Context ): InlinedSourceMap =
85
- val requests = mutable.ListBuffer .empty[Request ]
86
- var lastLine = cunit.tpdTree.sourcePos.endLine
85
+ val requests = mutable.ListBuffer .empty[(SourcePosition , SourcePosition )]
87
86
var internalNames = Map .empty[SourceFile , String ]
88
87
89
88
class RequestCollector (enclosingFile : SourceFile ) extends TreeTraverser :
90
89
override def traverse (tree : Tree )(using Context ): Unit =
91
90
if tree.source != enclosingFile && tree.source != cunit.source then
92
91
tree.getAttachment(InliningPosition ) match
93
92
case Some (InliningPosition (targetPos, cls)) =>
94
- val firstFakeLine = allocate( tree.sourcePos)
95
- requests += Request (targetPos, tree.sourcePos, firstFakeLine)
93
+ requests += (targetPos -> tree.sourcePos)
94
+
96
95
cls match
97
96
case Some (symbol) if ! internalNames.isDefinedAt(tree.source) =>
98
97
internalNames += (tree.source -> internalNameProvider(symbol))
@@ -108,13 +107,15 @@ object InlinedSourceMaps:
108
107
else traverseChildren(tree)
109
108
end RequestCollector
110
109
110
+ var lastLine = cunit.tpdTree.sourcePos.endLine
111
111
def allocate (origPos : SourcePosition ): Int =
112
112
val line = lastLine + 1
113
113
lastLine += origPos.lines.length
114
114
line
115
115
116
116
RequestCollector (cunit.source).traverse(cunit.tpdTree)
117
- InlinedSourceMap (cunit, requests.toList, internalNames)
117
+ val allocated = requests.sortBy(_._1.start).map(r => Request (r._1, r._2, allocate(r._2)))
118
+ InlinedSourceMap (cunit, allocated.toList, internalNames)
118
119
end sourceMapFor
119
120
120
121
class InlinedSourceMap private [InlinedSourceMaps ] (
0 commit comments