summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/Global.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2006-06-01 14:27:39 +0000
committerMartin Odersky <odersky@gmail.com>2006-06-01 14:27:39 +0000
commit4150f7e6fc64cd8d78d48cf275955b90d5c8b475 (patch)
tree0c601da1530d5eb0c1afcfa6ea7cd3f41daeff65 /src/compiler/scala/tools/nsc/Global.scala
parentc49cb64a8af13b608fb5c974b377086b19b16e9e (diff)
downloadscala-4150f7e6fc64cd8d78d48cf275955b90d5c8b475.tar.gz
scala-4150f7e6fc64cd8d78d48cf275955b90d5c8b475.tar.bz2
scala-4150f7e6fc64cd8d78d48cf275955b90d5c8b475.zip
some changes to plug space leaks
Diffstat (limited to 'src/compiler/scala/tools/nsc/Global.scala')
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala216
1 files changed, 115 insertions, 101 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index 12c1a80f02..d6b650c27c 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -39,12 +39,12 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
object treePrinters extends TreePrinters {
val global: Global.this.type = Global.this
}
- val treePrinter = treePrinters.create();
+ val treePrinter = treePrinters.create()
object treeBrowsers extends TreeBrowsers {
val global: Global.this.type = Global.this
}
- val treeBrowser = treeBrowsers.create();
+ val treeBrowser = treeBrowsers.create()
object treeInfo extends TreeInfo {
val global: Global.this.type = Global.this
@@ -67,11 +67,11 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
}
object analysis extends TypeFlowAnalysis {
- val global: Global.this.type = Global.this;
+ val global: Global.this.type = Global.this
}
object copyPropagation extends CopyPropagation {
- val global: Global.this.type = Global.this;
+ val global: Global.this.type = Global.this
}
object checkers extends Checkers {
@@ -86,11 +86,11 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
val global: Global.this.type = Global.this
}
- val copy = new LazyTreeCopier();
+ val copy = new LazyTreeCopier()
val comments =
- if (onlyPresentation) new HashMap[Symbol,String];
- else null;
+ if (onlyPresentation) new HashMap[Symbol,String]
+ else null
// reporting -------------------------------------------------------
@@ -99,7 +99,8 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
def inform(msg: String) = System.err.println(msg)
def inform[T](msg: String, value: T): T = { inform(msg+value); value }
- //reporter.info(null, msg, true);
+ //reporter.info(null, msg, true)
+
def informProgress(msg: String) =
if (settings.verbose.value) inform("[" + msg + "]")
@@ -123,7 +124,7 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
body
} catch {
case e : ErrorWithPosition =>
- logError("POS: " + source.dbg(e.pos), e);
+ logError("POS: " + source.dbg(e.pos), e)
throw e.error
}
@@ -149,7 +150,7 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
error("unsupported charset '" + settings.encoding.value + "'")
stdCharset
}
- new SourceReader(charset.newDecoder());
+ new SourceReader(charset.newDecoder())
}
val classPath0 = new ClassPath(onlyPresentation)
@@ -159,7 +160,7 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
settings.sourcepath.value,
settings.outdir.value,
settings.bootclasspath.value,
- settings.extdirs.value);
+ settings.extdirs.value)
if (settings.verbose.value) {
System.err.println("classpath = " + classPath)
@@ -171,14 +172,14 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
def getSourceFile(name: String): SourceFile = {
val f = AbstractFile.getFile(name)
if (f == null) throw new FileNotFoundException(
- "source file '" + name + "' could not be found");
+ "source file '" + name + "' could not be found")
getSourceFile(f)
}
def getSourceFile(clazz: Symbol): SourceFile = {
val ret = classPath.root.find(clazz.fullNameString(File.separatorChar), false)
if (!ret.isSourceFile) throw new FileNotFoundException(
- "source file for " + clazz + " could not be found");
+ "source file for " + clazz + " could not be found")
getSourceFile(ret.sourceFile)
}
@@ -188,7 +189,7 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
def rootLoader: LazyType = new loaders.PackageLoader(classPath.root /* getRoot() */)
- val migrateMsg = "migration problem when moving from Scala version 1.0 to version 2.0:\n";
+ val migrateMsg = "migration problem when moving from Scala version 1.0 to version 2.0:\n"
// Phases ------------------------------------------------------------
@@ -196,29 +197,34 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
val MaxPhases = 64
- val phaseWithId = new Array[Phase](MaxPhases);
+ val phaseWithId = new Array[Phase](MaxPhases)
{ for (val i <- List.range(0, MaxPhases)) phaseWithId(i) = NoPhase }
abstract class GlobalPhase(prev: Phase) extends Phase(prev) {
phaseWithId(id) = this
- def run: unit = currentRun.units foreach applyPhase;
+ def run: unit = currentRun.units foreach applyPhase
- def apply(unit: CompilationUnit): unit;
- private val isErased = prev.name == "erasure" || prev.erasedTypes;
- override def erasedTypes: boolean = isErased;
- private val isFlat = prev.name == "flatten" || prev.flatClasses;
- override def flatClasses: boolean = isFlat;
+ def apply(unit: CompilationUnit): unit
+ private val isErased = prev.name == "erasure" || prev.erasedTypes
+ override def erasedTypes: boolean = isErased
+ private val isFlat = prev.name == "flatten" || prev.flatClasses
+ override def flatClasses: boolean = isFlat
final def applyPhase(unit: CompilationUnit): unit = {
- if (settings.debug.value) inform("[running phase " + name + " on " + unit + "]");
- val unit0 = currentRun.currentUnit;
- currentRun.currentUnit = unit;
- apply(unit);
- currentRun.advanceUnit;
- assert(currentRun.currentUnit == unit);
- currentRun.currentUnit = unit0;
+ if (settings.debug.value) inform("[running phase " + name + " on " + unit + "]")
+ val unit0 = currentRun.currentUnit
+ currentRun.currentUnit = unit
+ apply(unit)
+ currentRun.advanceUnit
+ assert(currentRun.currentUnit == unit)
+ currentRun.currentUnit = unit0
}
}
+ class TerminalPhase(prev: Phase) extends GlobalPhase(prev) {
+ def name = "terminal"
+ def apply(unit: CompilationUnit): unit = {}
+ }
+
object syntaxAnalyzer extends SyntaxAnalyzer {
val global: Global.this.type = Global.this
}
@@ -351,34 +357,41 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
closureElimination,
deadCode,
genJVM,
- sampleTransform);
+ sampleTransform)
protected def insertBefore(c: SubComponent, cs: List[SubComponent], before: SubComponent): List[SubComponent] = cs match {
case List() => List(c)
case c1 :: cs1 => if (c1 == before) c :: cs else c1 :: insertBefore(c, cs1, before)
}
- private var curRun: Run = NoRun
- override def currentRun: Run = curRun
+ private var curRun: Run = null
+ def currentRun: Run = curRun
+ override def currentRunId: RunId = if (curRun == null) NoRunId else curRun.id
- def onlyPresentation = settings.doc.value
+ private var runCount = 0;
- def forCLDC: Boolean = settings.target.value == "cldc"
+ class Run {
+ runCount = runCount + 1
+ if (settings.statistics.value) Console.println("creating run: "+runCount)
+ override def finalize() = {
+ runCount = runCount - 1
+ if (settings.statistics.value) Console.println("collecting run: "+runCount)
+ }
- class Run extends CompilerRun {
+ val id = new RunId
var currentUnit: CompilationUnit = _
curRun = this
- override val firstPhase = syntaxAnalyzer.newPhase(NoPhase);
- phase = firstPhase;
+ val firstPhase = syntaxAnalyzer.newPhase(NoPhase)
+ phase = firstPhase
definitions.init; // needs firstPhase and phase to be defined != NoPhase,
// that's why it is placed here.
- icodes.init;
+ icodes.init
private var p: Phase = firstPhase
private var stopped = false
for (val pd <- phaseDescriptors) {
if (!stopped) {
- if (!(settings.skip contains pd.phaseName)) p = pd.newPhase(p);
+ if (!(settings.skip contains pd.phaseName)) p = pd.newPhase(p)
stopped = settings.stop contains pd.phaseName
}
}
@@ -398,33 +411,30 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
}
private def refreshProgress = if (fileset.size > 0)
progress((phasec * fileset.size) + unitc,
- (phaseDescriptors.length+1) * fileset.size);
+ (phaseDescriptors.length+1) * fileset.size)
- override def phaseNamed(name: String): Phase = {
+ def phaseNamed(name: String): Phase = {
var p: Phase = firstPhase
- while (p.next != p && p.name != name) p = p.next;
+ while (p.next != p && p.name != name) p = p.next
if (p.name != name) NoPhase else p
}
- override val namerPhase = phaseNamed("namer")
- override val typerPhase = phaseNamed("typer")
- override val refchecksPhase = phaseNamed("refchecks")
+ val namerPhase = phaseNamed("namer")
+ val typerPhase = phaseNamed("typer")
+ val refchecksPhase = phaseNamed("refchecks")
- override val explicitOuterPhase = phaseNamed("explicitouter")
- override val erasurePhase = phaseNamed("erasure")
- override val flattenPhase = phaseNamed("flatten")
- override val mixinPhase = phaseNamed("mixin")
- override val icodePhase = phaseNamed("icode")
+ val explicitOuterPhase = phaseNamed("explicitouter")
+ val erasurePhase = phaseNamed("erasure")
+ val flattenPhase = phaseNamed("flatten")
+ val mixinPhase = phaseNamed("mixin")
+ val icodePhase = phaseNamed("icode")
- private var unitbuf = new ListBuffer[CompilationUnit];
- private var fileset = new HashSet[AbstractFile];
+ private var unitbuf = new ListBuffer[CompilationUnit]
+ private var fileset = new HashSet[AbstractFile]
- override val terminalPhase : Phase =
+ val terminalPhase : Phase =
if (onlyPresentation) typerPhase.next.next
- else /* new GlobalPhase(p) {
- def name = "terminal"
- def apply(unit: CompilationUnit): unit = {}
- }*/ p;
+ else new TerminalPhase(p)
private def addUnit(unit: CompilationUnit): unit = {
unitbuf += unit
@@ -445,64 +455,66 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
else if (symSource.isDefinedAt(sym)) true
else if (!sym.owner.isPackageClass) compiles(sym.toplevelClass)
else if (sym.isModuleClass) compiles(sym.sourceModule)
- else false;
+ else false
def compileSources(sources: List[SourceFile]): unit = {
- val startTime = System.currentTimeMillis();
+ val startTime = System.currentTimeMillis()
reporter.reset
for (val source <- sources)
- addUnit(new CompilationUnit(source));
+ addUnit(new CompilationUnit(source))
globalPhase = firstPhase
while (globalPhase != terminalPhase && reporter.errors == 0) {
- val startTime = System.currentTimeMillis();
- phase = globalPhase;
- globalPhase.run;
+ val startTime = System.currentTimeMillis()
+ phase = globalPhase
+ globalPhase.run
if (settings.print contains globalPhase.name)
if (globalPhase.id >= icodePhase.id) writeICode()
- else treePrinter.printAll();
- if (settings.browse contains globalPhase.name) treeBrowser.browse(units);
- informTime(globalPhase.description, startTime);
- globalPhase = globalPhase.next;
+ else treePrinter.printAll()
+ if (settings.browse contains globalPhase.name) treeBrowser.browse(units)
+ informTime(globalPhase.description, startTime)
+ globalPhase = globalPhase.next
if (settings.check contains globalPhase.name) {
- phase = globalPhase;
- if (globalPhase.id >= icodePhase.id) icodeChecker.checkICodes;
- else checker.checkTrees;
+ phase = globalPhase
+ if (globalPhase.id >= icodePhase.id) icodeChecker.checkICodes
+ else checker.checkTrees
}
- if (settings.statistics.value) statistics.print(phase);
+ if (settings.statistics.value) statistics.print(phase)
advancePhase
}
- if (settings.Xshowcls.value != "") showDef(newTermName(settings.Xshowcls.value), false);
- if (settings.Xshowobj.value != "") showDef(newTermName(settings.Xshowobj.value), true);
+ if (settings.Xshowcls.value != "") showDef(newTermName(settings.Xshowcls.value), false)
+ if (settings.Xshowobj.value != "") showDef(newTermName(settings.Xshowobj.value), true)
if (reporter.errors == 0) {
- assert(stopped || symData.isEmpty, symData.elements.toList);
+ assert(stopped || symData.isEmpty, symData.elements.toList)
} else {
for (val Pair(sym, file) <- symSource.elements) {
sym.reset(new loaders.SourcefileLoader(file));
- if (sym.isTerm) sym.moduleClass.reset(loaders.moduleClassLoader);
+ if (sym.isTerm) sym.moduleClass.reset(loaders.moduleClassLoader)
}
}
- for (val Pair(sym, file) <- symSource.elements) resetPackageClass(sym.owner);
+ for (val Pair(sym, file) <- symSource.elements) resetPackageClass(sym.owner)
+ //units foreach (.clear())
informTime("total", startTime)
+ curRun = null
}
def compileLate(file: AbstractFile): unit =
if (fileset == null) {
val msg = "No class file for " + file +
- " was found\n(This file cannot be loaded as a source file)";
+ " was found\n(This file cannot be loaded as a source file)"
System.err.println(msg)
throw new FatalError(msg)
}
else if (!(fileset contains file)) {
- val unit = new CompilationUnit(getSourceFile(file));
- addUnit(unit);
- var localPhase = firstPhase.asInstanceOf[GlobalPhase];
+ val unit = new CompilationUnit(getSourceFile(file))
+ addUnit(unit)
+ var localPhase = firstPhase.asInstanceOf[GlobalPhase]
while ((localPhase.id < globalPhase.id || localPhase.id <= namerPhase.id) &&
reporter.errors == 0) {
- atPhase(localPhase)(localPhase.applyPhase(unit));
- localPhase = localPhase.next.asInstanceOf[GlobalPhase];
+ atPhase(localPhase)(localPhase.applyPhase(unit))
+ localPhase = localPhase.next.asInstanceOf[GlobalPhase]
}
refreshProgress
}
@@ -522,7 +534,7 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
}
private def resetPackageClass(pclazz: Symbol): unit = {
- assert(pclazz.isPackageClass, pclazz);
+ assert(pclazz.isPackageClass, pclazz)
atPhase(firstPhase) {
pclazz.setInfo(atPhase(typerPhase)(pclazz.info))
}
@@ -543,7 +555,7 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
root.info.member(selector)
}
}
- val sym = getSym(name, module);
+ val sym = getSym(name, module)
System.err.println("" + sym.name + ":" +
(if (module) sym.tpe.symbol.info else sym.info))
}
@@ -556,9 +568,9 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
var start = 0
var end = filename.indexOf('.', start)
while (end >= start) {
- outdir = new File(outdir, filename.substring(start, end));
- if (!outdir.exists()) outdir.mkdir();
- start = end + 1;
+ outdir = new File(outdir, filename.substring(start, end))
+ if (!outdir.exists()) outdir.mkdir()
+ start = end + 1
end = filename.indexOf('.', start)
}
new File(outdir, filename.substring(start) + suffix)
@@ -567,35 +579,37 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
private def writeSymblFile(clazz: Symbol, pickled: PickleBuffer) = {
val file = getFile(clazz, ".symbl")
try {
- val stream = new FileOutputStream(file);
- stream.write(pickled.bytes, 0, pickled.writeIndex);
- stream.close();
+ val stream = new FileOutputStream(file)
+ stream.write(pickled.bytes, 0, pickled.writeIndex)
+ stream.close()
informProgress("wrote " + file)
} catch {
case ex: IOException =>
- if (settings.debug.value) ex.printStackTrace();
+ if (settings.debug.value) ex.printStackTrace()
error("could not write file " + file)
}
}
private def writeICode(): Unit = {
- val printer = new icodePrinter.TextPrinter(null, icodes.linearizer);
+ val printer = new icodePrinter.TextPrinter(null, icodes.linearizer)
icodes.classes.values.foreach((cls) => {
- val suffix = if (cls.symbol.hasFlag(Flags.MODULE)) "$.icode" else ".icode";
- var file = getFile(cls.symbol, suffix);
+ val suffix = if (cls.symbol.hasFlag(Flags.MODULE)) "$.icode" else ".icode"
+ var file = getFile(cls.symbol, suffix)
// if (file.exists())
-// file = new File(file.getParentFile(), file.getName() + "1");
+// file = new File(file.getParentFile(), file.getName() + "1")
try {
- val stream = new FileOutputStream(file);
- printer.setWriter(new PrintWriter(stream, true));
- printer.printClass(cls);
- informProgress("wrote " + file);
+ val stream = new FileOutputStream(file)
+ printer.setWriter(new PrintWriter(stream, true))
+ printer.printClass(cls)
+ informProgress("wrote " + file)
} catch {
case ex: IOException =>
- if (settings.debug.value) ex.printStackTrace();
- error("could not write file " + file);
+ if (settings.debug.value) ex.printStackTrace()
+ error("could not write file " + file)
}
- });
+ })
}
+ def forCLDC: Boolean = settings.target.value == "cldc"
+ def onlyPresentation = settings.doc.value
}