From 1324218fd520c7a2e326b7c40c7bbb1a1dbb4803 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 20 Jun 2008 16:00:28 +0000 Subject: use early initialization instead of relying on ... use early initialization instead of relying on compiler moving valdefs in front of constructors. --- src/compiler/scala/tools/nsc/Global.scala | 154 +++++++++++---------- src/compiler/scala/tools/nsc/ast/Trees.scala | 9 +- .../scala/tools/nsc/symtab/AnnotationInfos.scala | 4 +- src/compiler/scala/tools/nsc/symtab/Types.scala | 5 +- 4 files changed, 88 insertions(+), 84 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index dd0ca0da10..e3f6bf85db 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -53,47 +53,49 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable } val nodeToString = nodePrinters.nodeToString - object gen extends TreeGen { + object gen extends { val global: Global.this.type = Global.this + } with TreeGen { def mkAttributedCast(tree: Tree, pt: Type): Tree = typer.typed(mkAttributedCastUntyped(tree, pt)) } - object constfold extends ConstantFolder { + object constfold extends { val global: Global.this.type = Global.this - } + } with ConstantFolder - object checker extends TreeCheckers { + object checker extends { val global: Global.this.type = Global.this - } + } with TreeCheckers - object icodes extends ICodes { + object icodes extends { val global: Global.this.type = Global.this - } + } with ICodes - object analysis extends TypeFlowAnalysis { + object analysis extends { val global: Global.this.type = Global.this - } + } with TypeFlowAnalysis - object copyPropagation extends CopyPropagation { + object copyPropagation extends { val global: Global.this.type = Global.this - } + } with CopyPropagation - object checkers extends Checkers { + object checkers extends { val global: Global.this.type = Global.this - } + } with Checkers - object statistics extends Statistics { + object statistics extends { val global: Global.this.type = Global.this - } + } with Statistics - object overridingPairs extends OverridingPairs { + object overridingPairs extends { val global: Global.this.type = Global.this - } + } with OverridingPairs - object treeBrowsers extends TreeBrowsers { + object treeBrowsers extends { val global: Global.this.type = Global.this - } + } with TreeBrowsers + val treeBrowser = treeBrowsers.create() @@ -221,7 +223,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable getSourceFile(ret.sourceFile) } - val loaders : SymbolLoaders { val global : Global.this.type } = new SymbolLoaders { + val loaders : SymbolLoaders { val global : Global.this.type } = new SymbolLoaders {//change? lazy val global: Global.this.type = Global.this } @@ -273,122 +275,122 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable def apply(unit: CompilationUnit) {} } - object syntaxAnalyzer extends SyntaxAnalyzer { + object syntaxAnalyzer extends { val global: Global.this.type = Global.this - } + } with SyntaxAnalyzer - object analyzer extends Analyzer { + object analyzer extends { val global: Global.this.type = Global.this - } + } with Analyzer - object superAccessors extends SuperAccessors { + object superAccessors extends { val global: Global.this.type = Global.this - } + } with SuperAccessors - object pickler extends Pickler { + object pickler extends { val global: Global.this.type = Global.this - } + } with Pickler - object refchecks extends RefChecks { + object refchecks extends { val global: Global.this.type = Global.this - } + } with RefChecks /* - object devirtualize extends DeVirtualize { + object devirtualize extends { val global: Global.this.type = Global.this - } + } with DeVirtualize */ - object liftcode extends LiftCode { + object liftcode extends { val global: Global.this.type = Global.this - } + } with LiftCode - object uncurry extends UnCurry { + object uncurry extends { val global: Global.this.type = Global.this - } + } with UnCurry - object tailCalls extends TailCalls { + object tailCalls extends { val global: Global.this.type = Global.this - } + } with TailCalls - //object transMatcher extends TransMatcher { + //object transMatcher extends { // val global: Global.this.type = Global.this - //} + //} with TransMatcher -// object checkDefined extends CheckDefined { +// object checkDefined extends { // val global: Global.this.type = Global.this -// } +// } with CheckDefined - object explicitOuter extends ExplicitOuter { + object explicitOuter extends { val global: Global.this.type = Global.this - } + } with ExplicitOuter - object erasure extends Erasure { + object erasure extends { val global: Global.this.type = Global.this - } + } with Erasure - object lazyVals extends LazyVals { + object lazyVals extends { val global: Global.this.type = Global.this final val FLAGS_PER_WORD = 32 - } + } with LazyVals - object lambdaLift extends LambdaLift { + object lambdaLift extends { val global: Global.this.type = Global.this - } + } with LambdaLift - object constructors extends Constructors { + object constructors extends { val global: Global.this.type = Global.this - } + } with Constructors - object flatten extends Flatten { + object flatten extends { val global: Global.this.type = Global.this - } + } with Flatten /* - object detach extends Detach { + object detach extends { val global: Global.this.type = Global.this - } + } with Detach */ - object mixer extends Mixin { + object mixer extends { val global: Global.this.type = Global.this - } + } with Mixin - object cleanup extends CleanUp { + object cleanup extends { val global: Global.this.type = Global.this - } + } with CleanUp - object sampleTransform extends SampleTransform { + object sampleTransform extends { val global: Global.this.type = Global.this - } + } with SampleTransform - object genicode extends GenICode { + object genicode extends { val global: Global.this.type = Global.this - } + } with GenICode /* object icodePrinter extends backend.icode.Printers { val global: Global.this.type = Global.this } */ - object scalaPrimitives extends ScalaPrimitives { + object scalaPrimitives extends { val global: Global.this.type = Global.this - } + } with ScalaPrimitives - object inliner extends Inliners { + object inliner extends { val global: Global.this.type = Global.this - } + } with Inliners - object closureElimination extends ClosureElimination { + object closureElimination extends { val global: Global.this.type = Global.this - } + } with ClosureElimination - object deadCode extends DeadCodeElimination { + object deadCode extends { val global: Global.this.type = Global.this - } + } with DeadCodeElimination - object genJVM extends GenJVM { + object genJVM extends { val global: Global.this.type = Global.this - } + } with GenJVM - object genMSIL extends GenMSIL { + object genMSIL extends { val global: Global.this.type = Global.this - } + } with GenMSIL object icodeChecker extends checkers.ICodeChecker() diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala index c3d1cb92b8..85ced9d301 100644 --- a/src/compiler/scala/tools/nsc/ast/Trees.scala +++ b/src/compiler/scala/tools/nsc/ast/Trees.scala @@ -31,14 +31,15 @@ trait Trees { // sub-components -------------------------------------------------- - object treePrinters extends TreePrinters { + object treePrinters extends { val trees: Trees.this.type = Trees.this - } + } with TreePrinters + val treePrinter = treePrinters.create() - object treeInfo extends TreeInfo { + object treeInfo extends { val trees: Trees.this.type = Trees.this - } + } with TreeInfo val copy = new LazyTreeCopier() diff --git a/src/compiler/scala/tools/nsc/symtab/AnnotationInfos.scala b/src/compiler/scala/tools/nsc/symtab/AnnotationInfos.scala index 5f9d67dfae..96547cdb80 100644 --- a/src/compiler/scala/tools/nsc/symtab/AnnotationInfos.scala +++ b/src/compiler/scala/tools/nsc/symtab/AnnotationInfos.scala @@ -62,9 +62,9 @@ trait AnnotationInfos { @deprecated lazy val tree = { - object reifiers extends Reifiers { + object reifiers extends { val symbols: AnnotationInfos.this.type = AnnotationInfos.this - } + } with Reifiers reifiers.reify(intTree) } diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index 3221fa8601..768b072447 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -98,9 +98,10 @@ trait Types { */ var intersectionWitness = new HashMap[List[Type], Type] - private object gen extends TreeGen { + private object gen extends { val global : Types.this.type = Types.this - } + } with TreeGen + import gen._ // @M toString that is safe during debugging (does not normalize, ...) -- cgit v1.2.3