@@ -20,6 +20,8 @@ import config.Settings._
20
20
import config .Config
21
21
import reporting ._
22
22
import reporting .diagnostic .Message
23
+ import io .AbstractFile
24
+ import scala .io .Codec
23
25
import collection .mutable
24
26
import printing ._
25
27
import config .{JavaPlatform , SJSPlatform , Platform , ScalaSettings }
@@ -224,6 +226,10 @@ object Contexts {
224
226
implicitsCache
225
227
}
226
228
229
+ /** Sourcefile corresponding to given abstract file, memoized */
230
+ def getSource (file : AbstractFile , codec : => Codec = Codec (settings.encoding.value)) =
231
+ base.sources.getOrElseUpdate(file, new SourceFile (file, codec))
232
+
227
233
/** Those fields are used to cache phases created in withPhase.
228
234
* phasedCtx is first phase with altered phase ever requested.
229
235
* phasedCtxs is array that uses phaseId's as indexes,
@@ -624,6 +630,9 @@ object Contexts {
624
630
625
631
def nextId : Int = { _nextId += 1 ; _nextId }
626
632
633
+ /** Sources that were loaded */
634
+ val sources : mutable.HashMap [AbstractFile , SourceFile ] = new mutable.HashMap [AbstractFile , SourceFile ]
635
+
627
636
// Types state
628
637
/** A table for hash consing unique types */
629
638
private [core] val uniques : util.HashSet [Type ] = new util.HashSet [Type ](Config .initialUniquesCapacity) {
@@ -696,6 +705,7 @@ object Contexts {
696
705
def reset (): Unit = {
697
706
for ((_, set) <- uniqueSets) set.clear()
698
707
errorTypeMsg.clear()
708
+ sources.clear()
699
709
}
700
710
701
711
// Test that access is single threaded
0 commit comments