@@ -20,6 +20,8 @@ import config.Settings._
2020import config .Config
2121import reporting ._
2222import reporting .diagnostic .Message
23+ import io .AbstractFile
24+ import scala .io .Codec
2325import collection .mutable
2426import printing ._
2527import config .{JavaPlatform , SJSPlatform , Platform , ScalaSettings }
@@ -224,6 +226,10 @@ object Contexts {
224226 implicitsCache
225227 }
226228
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+
227233 /** Those fields are used to cache phases created in withPhase.
228234 * phasedCtx is first phase with altered phase ever requested.
229235 * phasedCtxs is array that uses phaseId's as indexes,
@@ -624,6 +630,9 @@ object Contexts {
624630
625631 def nextId : Int = { _nextId += 1 ; _nextId }
626632
633+ /** Sources that were loaded */
634+ val sources : mutable.HashMap [AbstractFile , SourceFile ] = new mutable.HashMap [AbstractFile , SourceFile ]
635+
627636 // Types state
628637 /** A table for hash consing unique types */
629638 private [core] val uniques : util.HashSet [Type ] = new util.HashSet [Type ](Config .initialUniquesCapacity) {
@@ -696,6 +705,7 @@ object Contexts {
696705 def reset (): Unit = {
697706 for ((_, set) <- uniqueSets) set.clear()
698707 errorTypeMsg.clear()
708+ sources.clear()
699709 }
700710
701711 // Test that access is single threaded
0 commit comments