@@ -15,7 +15,6 @@ import reporters.{ Reporter, ConsoleReporter }
1515import util .{ Exceptional , ClassPath , MergedClassPath , StatisticsInfo , ScalaClassLoader , returning }
1616import scala .reflect .internal .util .{ NoPosition , SourceFile , NoSourceFile , BatchSourceFile , ScriptSourceFile }
1717import scala .reflect .internal .pickling .{ PickleBuffer , PickleFormat }
18- import settings .{ AestheticSettings }
1918import symtab .{ Flags , SymbolTable , SymbolLoaders , SymbolTrackers }
2019import symtab .classfile .Pickler
2120import dependencies .DependencyAnalysis
@@ -224,7 +223,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
224223 def globalError (msg : String ) = reporter.error(NoPosition , msg)
225224 def inform (msg : String ) = reporter.echo(msg)
226225 def warning (msg : String ) =
227- if (opt .fatalWarnings) globalError(msg)
226+ if (settings .fatalWarnings.value ) globalError(msg)
228227 else reporter.warning(NoPosition , msg)
229228
230229 // Getting in front of Predef's asserts to supplement with more info.
@@ -265,7 +264,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
265264 msg + " in " + (currentTime - start) + " ms"
266265
267266 def informComplete (msg : String ): Unit = reporter.withoutTruncating(inform(msg))
268- def informProgress (msg : String ) = if (opt .verbose) inform(" [" + msg + " ]" )
267+ def informProgress (msg : String ) = if (settings .verbose.value ) inform(" [" + msg + " ]" )
269268 def inform [T ](msg : String , value : T ): T = returning(value)(x => inform(msg + x))
270269 def informTime (msg : String , start : Long ) = informProgress(elapsedMessage(msg, start))
271270
@@ -310,7 +309,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
310309 None
311310 }
312311
313- val charset = opt .encoding flatMap loadCharset getOrElse {
312+ val charset = ( if (settings .encoding.isSetByUser) Some (settings.encoding.value) else None ) flatMap loadCharset getOrElse {
314313 settings.encoding.value = defaultEncoding // A mandatory charset
315314 Charset .forName(defaultEncoding)
316315 }
@@ -325,62 +324,20 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
325324 }
326325 }
327326
328- opt .sourceReader flatMap loadReader getOrElse {
327+ ( if (settings .sourceReader.isSetByUser) Some (settings.sourceReader.value) else None ) flatMap loadReader getOrElse {
329328 new SourceReader (charset.newDecoder(), reporter)
330329 }
331330 }
332331
333332 if (! dependencyAnalysis.off)
334333 dependencyAnalysis.loadDependencyAnalysis()
335334
336- if (opt .verbose || opt.logClasspath ) {
335+ if (settings .verbose.value || settings. Ylogcp .value ) {
337336 // Uses the "do not truncate" inform
338337 informComplete(" [search path for source files: " + classPath.sourcepaths.mkString(" ," ) + " ]" )
339338 informComplete(" [search path for class files: " + classPath.asClasspathString + " ]" )
340339 }
341340
342- object opt extends AestheticSettings {
343- def settings = Global .this .settings
344-
345- // protected implicit lazy val globalPhaseOrdering: Ordering[Phase] = Ordering[Int] on (_.id)
346- def isActive (ph : Settings # PhasesSetting ) = ph containsPhase globalPhase
347- def wasActive (ph : Settings # PhasesSetting ) = ph containsPhase globalPhase.prev
348-
349- // Allows for syntax like scalac -Xshow-class Random@erasure,typer
350- private def splitClassAndPhase (str : String , term : Boolean ): Name = {
351- def mkName (s : String ) = if (term) newTermName(s) else newTypeName(s)
352- (str indexOf '@' ) match {
353- case - 1 => mkName(str)
354- case idx =>
355- val phasePart = str drop (idx + 1 )
356- settings.Yshow .tryToSetColon(phasePart split ',' toList)
357- mkName(str take idx)
358- }
359- }
360-
361- // behavior
362-
363- // debugging
364- def checkPhase = wasActive(settings.check)
365- def logPhase = isActive(settings.log)
366-
367- // Write *.icode files right after GenICode when -Xprint-icode was given.
368- def writeICodeAtICode = settings.writeICode.isSetByUser && isActive(settings.writeICode)
369-
370- // showing/printing things
371- def browsePhase = isActive(settings.browse)
372- def echoFilenames = opt.debug && (opt.verbose || currentRun.size < 5 )
373- def noShow = settings.Yshow .isDefault
374- def printLate = settings.printLate.value
375- def printPhase = isActive(settings.Xprint )
376- def showNames = List (showClass, showObject).flatten
377- def showPhase = isActive(settings.Yshow )
378- def showSymbols = settings.Yshowsyms .value
379- def showTrees = settings.Xshowtrees .value || settings.XshowtreesCompact .value || settings.XshowtreesStringified .value
380- val showClass = optSetting[String ](settings.Xshowcls ) map (x => splitClassAndPhase(x, false ))
381- val showObject = optSetting[String ](settings.Xshowobj ) map (x => splitClassAndPhase(x, true ))
382- }
383-
384341 // The current division between scala.reflect.* and scala.tools.nsc.* is pretty
385342 // clunky. It is often difficult to have a setting influence something without having
386343 // to create it on that side. For this one my strategy is a constant def at the file
@@ -389,11 +346,8 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
389346 // Here comes another one...
390347 override protected val enableTypeVarExperimentals = settings.Xexperimental .value
391348
392- // True if -Xscript has been set, indicating a script run.
393- def isScriptRun = opt.script.isDefined
394-
395349 def getSourceFile (f : AbstractFile ): BatchSourceFile =
396- if (isScriptRun ) ScriptSourceFile (f, reader read f)
350+ if (settings.script.isSetByUser ) ScriptSourceFile (f, reader read f)
397351 else new BatchSourceFile (f, reader read f)
398352
399353 def getSourceFile (name : String ): SourceFile = {
@@ -448,7 +402,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
448402 if ((unit ne null ) && unit.exists)
449403 lastSeenSourceFile = unit.source
450404
451- if (opt.echoFilenames )
405+ if (settings.debug.value && (settings.verbose.value || currentRun.size < 5 ) )
452406 inform(" [running phase " + name + " on " + unit + " ]" )
453407
454408 val unit0 = currentUnit
@@ -1171,7 +1125,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
11711125 val info3 : List [String ] = (
11721126 ( List (" == Enclosing template or block ==" , nodePrinters.nodeToString(enclosing).trim) )
11731127 ++ ( if (tpe eq null ) Nil else List (" == Expanded type of tree ==" , typeDeconstruct.show(tpe)) )
1174- ++ ( if (! opt .debug) Nil else List (" == Current unit body ==" , nodePrinters.nodeToString(currentUnit.body)) )
1128+ ++ ( if (! settings .debug.value ) Nil else List (" == Current unit body ==" , nodePrinters.nodeToString(currentUnit.body)) )
11751129 ++ ( List (errorMessage) )
11761130 )
11771131
@@ -1185,7 +1139,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
11851139
11861140 def echoPhaseSummary (ph : Phase ) = {
11871141 /** Only output a summary message under debug if we aren't echoing each file. */
1188- if (opt .debug && ! opt.echoFilenames )
1142+ if (settings .debug.value && ! (settings.verbose.value || currentRun.size < 5 ) )
11891143 inform(" [running phase " + ph.name + " on " + currentRun.size + " compilation units]" )
11901144 }
11911145
@@ -1490,8 +1444,24 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
14901444 }
14911445 }
14921446
1493- private def showMembers () =
1494- opt.showNames foreach (x => showDef(x, opt.declsOnly, globalPhase))
1447+ private def showMembers () = {
1448+ // Allows for syntax like scalac -Xshow-class Random@erasure,typer
1449+ def splitClassAndPhase (str : String , term : Boolean ): Name = {
1450+ def mkName (s : String ) = if (term) newTermName(s) else newTypeName(s)
1451+ (str indexOf '@' ) match {
1452+ case - 1 => mkName(str)
1453+ case idx =>
1454+ val phasePart = str drop (idx + 1 )
1455+ settings.Yshow .tryToSetColon(phasePart split ',' toList)
1456+ mkName(str take idx)
1457+ }
1458+ }
1459+ if (settings.Xshowcls .isSetByUser)
1460+ showDef(splitClassAndPhase(settings.Xshowcls .value, false ), false , globalPhase)
1461+
1462+ if (settings.Xshowobj .isSetByUser)
1463+ showDef(splitClassAndPhase(settings.Xshowobj .value, true ), false , globalPhase)
1464+ }
14951465
14961466 // Similarly, this will only be created under -Yshow-syms.
14971467 object trackerFactory extends SymbolTrackers {
@@ -1576,37 +1546,40 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
15761546 // progress update
15771547 informTime(globalPhase.description, startTime)
15781548 phaseTimings(globalPhase) = currentTime - startTime
1579-
1580- if (opt.writeICodeAtICode || (opt.printPhase && runIsAtOptimiz)) {
1549+ val shouldWriteIcode = (
1550+ (settings.writeICode.isSetByUser && (settings.writeICode containsPhase globalPhase))
1551+ || (! settings.Xprint .doAllPhases && (settings.Xprint containsPhase globalPhase) && runIsAtOptimiz)
1552+ )
1553+ if (shouldWriteIcode) {
15811554 // Write *.icode files when -Xprint-icode or -Xprint:<some-optimiz-phase> was given.
15821555 writeICode()
1583- } else if (opt.printPhase || opt .printLate && runIsAt(cleanupPhase)) {
1556+ } else if ((settings. Xprint containsPhase globalPhase) || settings .printLate.value && runIsAt(cleanupPhase)) {
15841557 // print trees
1585- if (opt.showTrees ) nodePrinters.printAll()
1558+ if (settings. Xshowtrees .value || settings. XshowtreesCompact .value || settings. XshowtreesStringified .value ) nodePrinters.printAll()
15861559 else printAllUnits()
15871560 }
15881561
15891562 // print the symbols presently attached to AST nodes
1590- if (opt.showSymbols )
1563+ if (settings. Yshowsyms .value )
15911564 trackerFactory.snapshot()
15921565
15931566 // print members
1594- if (opt.showPhase )
1567+ if (settings. Yshow containsPhase globalPhase )
15951568 showMembers()
15961569
15971570 // browse trees with swing tree viewer
1598- if (opt.browsePhase )
1571+ if (settings.browse containsPhase globalPhase )
15991572 treeBrowser browse (phase.name, units)
16001573
16011574 // move the pointer
16021575 globalPhase = globalPhase.next
16031576
16041577 // run tree/icode checkers
1605- if (opt.checkPhase )
1578+ if (settings.check containsPhase globalPhase.prev )
16061579 runCheckers()
16071580
16081581 // output collected statistics
1609- if (opt.printStats )
1582+ if (settings. Ystatistics .value )
16101583 statistics.print(phase)
16111584
16121585 advancePhase
@@ -1616,7 +1589,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
16161589 units map (_.body) foreach (traceSymbols recordSymbolsInTree _)
16171590
16181591 // In case no phase was specified for -Xshow-class/object, show it now for sure.
1619- if (opt.noShow )
1592+ if (settings. Yshow .isDefault )
16201593 showMembers()
16211594
16221595 reportCompileErrors()
@@ -1648,7 +1621,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
16481621 def compile (filenames : List [String ]) {
16491622 try {
16501623 val sources : List [SourceFile ] =
1651- if (isScriptRun && filenames.size > 1 ) returning(Nil )(_ => globalError(" can only compile one script at a time" ))
1624+ if (settings.script.isSetByUser && filenames.size > 1 ) returning(Nil )(_ => globalError(" can only compile one script at a time" ))
16521625 else filenames map getSourceFile
16531626
16541627 compileSources(sources)
@@ -1795,7 +1768,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
17951768 informProgress(" wrote " + file)
17961769 } catch {
17971770 case ex : IOException =>
1798- if (opt .debug) ex.printStackTrace()
1771+ if (settings .debug.value ) ex.printStackTrace()
17991772 globalError(" could not write file " + file)
18001773 }
18011774 })
@@ -1806,8 +1779,8 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
18061779 // and forScaladoc default to onlyPresentation, which is the same as defaulting
18071780 // to false except in old code. The downside is that this leaves us calling a
18081781 // deprecated method: but I see no simple way out, so I leave it for now.
1809- def forJVM = opt. jvm
1810- override def forMSIL = opt. msil
1782+ def forJVM = settings.target.value startsWith " jvm"
1783+ override def forMSIL = settings.target.value startsWith " msil"
18111784 def forInteractive = onlyPresentation
18121785 def forScaladoc = onlyPresentation
18131786 def createJavadoc = false
0 commit comments