@@ -178,6 +178,11 @@ object Contexts {
178
178
_typeComparer
179
179
}
180
180
181
+ /** The current source file */
182
+ private [this ] var _source : SourceFile = _
183
+ protected def source_= (source : SourceFile ): Unit = _source = source
184
+ def source : SourceFile = _source
185
+
181
186
/** A map in which more contextual properties can be stored
182
187
* Typically used for attributes that are read and written only in special situations.
183
188
*/
@@ -418,12 +423,6 @@ object Contexts {
418
423
ctx.fresh.setImportInfo(new ImportInfo (implicit ctx => sym, imp.selectors, impNameOpt))
419
424
}
420
425
421
- /** The current source file; will be derived from current
422
- * compilation unit.
423
- */
424
- def source : SourceFile =
425
- if (compilationUnit == null ) NoSource else compilationUnit.source
426
-
427
426
/** Does current phase use an erased types interpretation? */
428
427
def erasedTypes : Boolean = phase.erasedTypes
429
428
@@ -453,6 +452,9 @@ object Contexts {
453
452
final def withOwner (owner : Symbol ): Context =
454
453
if (owner ne this .owner) fresh.setOwner(owner) else this
455
454
455
+ final def withSource (source : SourceFile ): Context =
456
+ if (source ne this .source) fresh.setSource(source) else this
457
+
456
458
final def withProperty [T ](key : Key [T ], value : Option [T ]): Context =
457
459
if (property(key) == value) this
458
460
else value match {
@@ -521,16 +523,21 @@ object Contexts {
521
523
def setGadt (gadt : GADTMap ): this .type = { this .gadt = gadt; this }
522
524
def setFreshGADTBounds : this .type = setGadt(gadt.fresh)
523
525
def setSearchHistory (searchHistory : SearchHistory ): this .type = { this .searchHistory = searchHistory; this }
526
+ def setSource (source : SourceFile ): this .type = { this .source = source; this }
524
527
def setTypeComparerFn (tcfn : Context => TypeComparer ): this .type = { this .typeComparer = tcfn(this ); this }
525
528
private def setMoreProperties (moreProperties : Map [Key [Any ], Any ]): this .type = { this .moreProperties = moreProperties; this }
526
529
private def setStore (store : Store ): this .type = { this .store = store; this }
527
530
def setImplicits (implicits : ContextualImplicits ): this .type = { this .implicitsCache = implicits; this }
528
531
532
+ def setCompilationUnit (compilationUnit : CompilationUnit ): this .type = {
533
+ setSource(compilationUnit.source)
534
+ updateStore(compilationUnitLoc, compilationUnit)
535
+ }
536
+
529
537
def setCompilerCallback (callback : CompilerCallback ): this .type = updateStore(compilerCallbackLoc, callback)
530
538
def setSbtCallback (callback : AnalysisCallback ): this .type = updateStore(sbtCallbackLoc, callback)
531
539
def setPrinterFn (printer : Context => Printer ): this .type = updateStore(printerFnLoc, printer)
532
540
def setSettings (settingsState : SettingsState ): this .type = updateStore(settingsStateLoc, settingsState)
533
- def setCompilationUnit (compilationUnit : CompilationUnit ): this .type = updateStore(compilationUnitLoc, compilationUnit)
534
541
def setRun (run : Run ): this .type = updateStore(runLoc, run)
535
542
def setProfiler (profiler : Profiler ): this .type = updateStore(profilerLoc, profiler)
536
543
def setFreshNames (freshNames : FreshNameCreator ): this .type = updateStore(freshNamesLoc, freshNames)
@@ -592,6 +599,7 @@ object Contexts {
592
599
tree = untpd.EmptyTree
593
600
typeAssigner = TypeAssigner
594
601
moreProperties = Map .empty
602
+ source = NoSource
595
603
store = initialStore.updated(settingsStateLoc, settingsGroup.defaultState)
596
604
typeComparer = new TypeComparer (this )
597
605
searchHistory = new SearchRoot
@@ -659,11 +667,12 @@ object Contexts {
659
667
// Symbols state
660
668
661
669
/** Counters for unique ids */
662
- private [core ] var _nextSymId : Int = 0
670
+ private [this ] var _nextSymId : Int = 0
663
671
def nextSymId : Int = { _nextSymId += 1 ; _nextSymId }
664
672
665
673
private [core] var nextTreeIdBySource = new mutable.HashMap [SourceFile , Int ]
666
674
private [core] var sourceOfChunk = mutable.ArrayBuffer [SourceFile ](NoSource )
675
+ // first element reserved for GlobalTreeIds
667
676
668
677
/** Sources that were loaded */
669
678
val sources : mutable.HashMap [AbstractFile , SourceFile ] = new mutable.HashMap [AbstractFile , SourceFile ]
0 commit comments