From bb085c4f7552614a8b00d77a7ceeea3fd1bef1af Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Tue, 30 Jun 2009 12:32:05 +0000 Subject: Eliminating some unnecessary code duplication. --- src/compiler/scala/tools/nsc/ast/TreeGen.scala | 21 +++++++++----------- .../scala/tools/nsc/ast/parser/TreeBuilder.scala | 23 ++++++++-------------- .../scala/tools/nsc/javac/JavaParsers.scala | 6 +----- 3 files changed, 18 insertions(+), 32 deletions(-) diff --git a/src/compiler/scala/tools/nsc/ast/TreeGen.scala b/src/compiler/scala/tools/nsc/ast/TreeGen.scala index ed3c842201..557b365974 100644 --- a/src/compiler/scala/tools/nsc/ast/TreeGen.scala +++ b/src/compiler/scala/tools/nsc/ast/TreeGen.scala @@ -13,23 +13,20 @@ import symtab.SymbolTable /** XXX to resolve: TreeGen only assumes global is a SymbolTable, but * TreeDSL at the moment expects a Global. Can we get by with SymbolTable? */ -abstract class TreeGen { - +abstract class TreeGen +{ val global: SymbolTable import global._ import definitions._ - def scalaDot(name: Name): Tree = - Select(Ident(nme.scala_) setSymbol ScalaPackage, name) - def scalaAnyRefConstr: Tree = - scalaDot(nme.AnyRef.toTypeName) - def scalaUnitConstr: Tree = - scalaDot(nme.Unit.toTypeName) - def scalaScalaObjectConstr: Tree = - scalaDot(nme.ScalaObject.toTypeName) - def productConstr: Tree = - scalaDot(nme.Product.toTypeName) + def rootId(name: Name) = Select(Ident(nme.ROOTPKG), name) + def rootScalaDot(name: Name) = Select(rootId(nme.scala_) setSymbol ScalaPackage, name) + def scalaDot(name: Name) = Select(Ident(nme.scala_) setSymbol ScalaPackage, name) + def scalaAnyRefConstr = scalaDot(nme.AnyRef.toTypeName) + def scalaUnitConstr = scalaDot(nme.Unit.toTypeName) + def scalaScalaObjectConstr = scalaDot(nme.ScalaObject.toTypeName) + def productConstr = scalaDot(nme.Product.toTypeName) def scalaFunctionConstr(argtpes: List[Tree], restpe: Tree): Tree = AppliedTypeTree( diff --git a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala index 37c90324da..a1949cc424 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala @@ -19,19 +19,13 @@ abstract class TreeBuilder extends TreeDSL def freshName(prefix: String): Name def freshName(): Name = freshName("x$") - def rootId(name: Name) = Select(Ident(nme.ROOTPKG), name) - def rootScalaDot(name: Name): Tree = Select(rootId(nme.scala_) setSymbol definitions.ScalaPackage, name) - - def scalaDot(name: Name): Tree = - Select(Ident(nme.scala_) setSymbol definitions.ScalaPackage, name) - def scalaAnyRefConstr: Tree = - scalaDot(nme.AnyRef.toTypeName) - def scalaUnitConstr: Tree = - scalaDot(nme.Unit.toTypeName) - def scalaScalaObjectConstr: Tree = - scalaDot(nme.ScalaObject.toTypeName) - def productConstr: Tree = - scalaDot(nme.Product.toTypeName) + lazy val rootId = gen.rootId _ + lazy val rootScalaDot = gen.rootScalaDot _ + lazy val scalaDot = gen.scalaDot _ + lazy val scalaAnyRefConstr = gen.scalaAnyRefConstr + lazy val scalaUnitConstr = gen.scalaUnitConstr + lazy val scalaScalaObjectConstr = gen.scalaScalaObjectConstr + lazy val productConstr = gen.productConstr /** Convert all occurrences of (lower-case) variables in a pattern as follows: * x becomes x @ _ @@ -434,8 +428,7 @@ abstract class TreeBuilder extends TreeDSL } /** Create a tree representing the function type (argtpes) => restpe */ - def makeFunctionTypeTree(argtpes: List[Tree], restpe: Tree): Tree = - AppliedTypeTree(rootScalaDot(newTypeName("Function" + argtpes.length)), argtpes ::: List(restpe)) + val makeFunctionTypeTree = gen.scalaFunctionConstr _ /** Append implicit view section if for `implicitViews' if nonempty */ def addImplicitViews(owner: Name, vparamss: List[List[ValDef]], implicitViews: List[Tree]): List[List[ValDef]] = { diff --git a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala index 5508585678..5cfee91651 100755 --- a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala +++ b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala @@ -98,11 +98,7 @@ trait JavaParsers extends JavaScanners { // --------- tree building ----------------------------- - def rootId(name: Name) = - Select(Ident(nme.ROOTPKG), name) - - def scalaDot(name: Name): Tree = - Select(rootId(nme.scala_) setSymbol ScalaPackage, name) + import gen.{ rootId, scalaDot } def javaDot(name: Name): Tree = Select(rootId(nme.java), name) -- cgit v1.2.3