aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-08-18 15:50:54 +0200
committerMartin Odersky <odersky@gmail.com>2014-08-18 16:26:36 +0200
commitf366f867853be9879b9d17af832de2ad00f7f06b (patch)
treee726e60642babbbc9a0643b522d317519c70f697 /src/dotty/tools/dotc/core
parentb53a03f1183c062bed0120257e0519eb81e7619e (diff)
downloaddotty-f366f867853be9879b9d17af832de2ad00f7f06b.tar.gz
dotty-f366f867853be9879b9d17af832de2ad00f7f06b.tar.bz2
dotty-f366f867853be9879b9d17af832de2ad00f7f06b.zip
Refactored TreeTypeMap
Goes into a separate source files. Several simplifying refactorings.
Diffstat (limited to 'src/dotty/tools/dotc/core')
-rw-r--r--src/dotty/tools/dotc/core/Symbols.scala32
-rw-r--r--src/dotty/tools/dotc/core/Types.scala12
2 files changed, 19 insertions, 25 deletions
diff --git a/src/dotty/tools/dotc/core/Symbols.scala b/src/dotty/tools/dotc/core/Symbols.scala
index 4156d59d1..96819f627 100644
--- a/src/dotty/tools/dotc/core/Symbols.scala
+++ b/src/dotty/tools/dotc/core/Symbols.scala
@@ -19,7 +19,8 @@ import util.Positions._
import DenotTransformers._
import StdNames._
import NameOps._
-import ast.tpd.{TreeTypeMap, Tree}
+import ast.tpd.Tree
+import ast.TreeTypeMap
import Denotations.{ Denotation, SingleDenotation, MultiDenotation }
import collection.mutable
import io.AbstractFile
@@ -261,22 +262,14 @@ trait Symbols { this: Context =>
newSymbol(owner, name, SyntheticArtifact,
if (name.isTypeName) TypeAlias(ErrorType) else ErrorType)
- /** Map given symbols, subjecting all types to given type map and owner map,
- * as well as to the substition [substFrom := substTo].
+ /** Map given symbols, subjecting their attributes to the mappings
+ * defined in the given TreeTypeMap `ttmap`.
* Cross symbol references are brought over from originals to copies.
* Do not copy any symbols if all attributes of all symbols stay the same.
*/
- def mapSymbols(
- originals: List[Symbol],
- typeMap: Type => Type = IdentityTypeMap,
- ownerMap: Symbol => Symbol = identity,
- substFrom: List[Symbol] = Nil,
- substTo: List[Symbol] = Nil)
- =
+ def mapSymbols(originals: List[Symbol], ttmap: TreeTypeMap) =
if (originals forall (sym =>
- (typeMap(sym.info) eq sym.info) &&
- (sym.info.substSym(substFrom, substTo) eq sym.info) &&
- (ownerMap(sym.owner) eq sym.owner)))
+ (ttmap.mapType(sym.info) eq sym.info) && (ttmap.ownerMap(sym.owner) eq sym.owner)))
originals
else {
val copies: List[Symbol] = for (original <- originals) yield
@@ -286,19 +279,18 @@ trait Symbols { this: Context =>
case _ =>
newNakedSymbol[original.ThisName](original.coord)
}
- val treeMap = new TreeTypeMap(typeMap, ownerMap, substFrom = substFrom, substTo = substTo)
- .withSubstitution(originals, copies)
+ val ttmap1 = ttmap.withSubstitution(originals, copies)
(originals, copies).zipped foreach {(original, copy) =>
- copy.denot = original.denot // preliminar denotation, so that we can access symbols in subsequent transform
+ copy.denot = original.denot // preliminary denotation, so that we can access symbols in subsequent transform
}
(originals, copies).zipped foreach {(original, copy) =>
val odenot = original.denot
copy.denot = odenot.copySymDenotation(
symbol = copy,
- owner = treeMap.ownerMap(odenot.owner),
- info = treeMap.mapType(odenot.info),
- privateWithin = ownerMap(odenot.privateWithin), // since this refers to outer symbols, need not include copies (from->to) in ownermap here.
- annotations = odenot.annotations.mapConserve(treeMap.apply))
+ owner = ttmap1.ownerMap(odenot.owner),
+ info = ttmap1.mapType(odenot.info),
+ privateWithin = ttmap1.ownerMap(odenot.privateWithin), // since this refers to outer symbols, need not include copies (from->to) in ownermap here.
+ annotations = odenot.annotations.mapConserve(ttmap1.apply))
}
copies
}
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index 82b2fc71a..17e7f4fb5 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -17,7 +17,9 @@ import Periods._
import util.Positions.Position
import util.Stats._
import util.{DotClass, SimpleMap}
-import ast.tpd._, printing.Texts._
+import ast.tpd._
+import ast.TreeTypeMap
+import printing.Texts._
import ast.untpd
import transform.Erasure
import printing.Printer
@@ -2474,8 +2476,9 @@ object Types {
}
}
- def mapOver(syms: List[Symbol]): List[Symbol] =
- ctx.mapSymbols(syms, typeMap = this)
+ private def treeTypeMap = new TreeTypeMap(typeMap = this)
+
+ def mapOver(syms: List[Symbol]): List[Symbol] = ctx.mapSymbols(syms, treeTypeMap)
def mapOver(scope: Scope): Scope = {
val elems = scope.toList
@@ -2487,8 +2490,7 @@ object Types {
def mapOver(annot: Annotation): Annotation =
annot.derivedAnnotation(mapOver(annot.tree))
- def mapOver(tree: Tree): Tree =
- new TreeTypeMap(typeMap = this).apply(tree)
+ def mapOver(tree: Tree): Tree = treeTypeMap(tree)
/** Can be overridden. By default, only the prefix is mapped. */
protected def mapClassInfo(tp: ClassInfo): ClassInfo =