aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Namer.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-02-11 14:42:45 +0100
committerMartin Odersky <odersky@gmail.com>2014-02-11 14:42:56 +0100
commit459d78dccc40c94dd7da8b5b29762a494595778b (patch)
tree2d678de090302dab70d7079730f8ed4cc258b667 /src/dotty/tools/dotc/typer/Namer.scala
parente895249de8f59e5a5c4175b428193fa4c5ea90af (diff)
downloaddotty-459d78dccc40c94dd7da8b5b29762a494595778b.tar.gz
dotty-459d78dccc40c94dd7da8b5b29762a494595778b.tar.bz2
dotty-459d78dccc40c94dd7da8b5b29762a494595778b.zip
New scheme for attachments.
Added general way to put attachments on some base type (which needs to inherit from Attachment.Container). Used it to turn typedTree map into an attachment. Also, moved DotClass to dotc.util.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Namer.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Namer.scala25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala
index 776d59542..da90a0ab3 100644
--- a/src/dotty/tools/dotc/typer/Namer.scala
+++ b/src/dotty/tools/dotc/typer/Namer.scala
@@ -9,7 +9,7 @@ import Contexts._, Symbols._, Types._, SymDenotations._, Names._, NameOps._, Fla
import ast.desugar, ast.desugar._
import Inferencing._
import util.Positions._
-import util.SourcePosition
+import util.{Attachment, SourcePosition, DotClass}
import collection.mutable
import annotation.tailrec
import ErrorReporting._
@@ -96,10 +96,15 @@ class Namer { typer: Typer =>
import untpd._
+ val TypedAhead = new Attachment.Key[tpd.Tree]
+ val ExpandedTree = new Attachment.Key[Tree]
+ val SymOfTree = new Attachment.Key[Symbol]
+
/** A partial map from unexpanded member and pattern defs and to their expansions.
* Populated during enterSyms, emptied during typer.
*/
- lazy val expandedTree = new mutable.AnyRefMap[DefTree, Tree] /*{
+ lazy val expandedTree = new mutable.AnyRefMap[DefTree, Tree]
+ /*{
override def default(tree: DefTree) = tree // can't have defaults on AnyRefMaps :-(
}*/
@@ -113,7 +118,7 @@ class Namer { typer: Typer =>
/** A map from expanded trees to their typed versions.
* Populated when trees are typechecked during completion (using method typedAhead).
*/
- lazy val typedTree = new mutable.AnyRefMap[Tree, tpd.Tree]
+ // lazy val typedTree = new mutable.AnyRefMap[Tree, tpd.Tree]
/** A map from method symbols to nested typers.
* Populated when methods are completed. Emptied when they are typechecked.
@@ -133,9 +138,9 @@ class Namer { typer: Typer =>
/** The symbol of the given expanded tree. */
def symbolOfTree(tree: Tree)(implicit ctx: Context): Symbol = {
val xtree = expanded(tree)
- typedTree get xtree match {
- case Some(ttree) => ttree.denot.symbol
- case _ => symOfTree(xtree)
+ xtree.getAttachment(TypedAhead) match {
+ case Some(ttree) => ttree.symbol
+ case none => symOfTree(xtree)
}
}
@@ -249,12 +254,14 @@ class Namer { typer: Typer =>
val expanded = desugar.defTree(mdef)
typr.println(i"Expansion: $mdef expands to $expanded")
if (expanded ne mdef) expandedTree(mdef) = expanded
+ // if (expanded ne mdef) mdef.pushAttachment(ExpandedTree(expanded))
case _ =>
}
/** The expanded version of this tree, or tree itself if not expanded */
def expanded(tree: Tree)(implicit ctx: Context): Tree = tree match {
case ddef: DefTree => expandedTree.getOrElse(ddef, ddef)
+ //ddef.getAttachment(ExpandedTreeKey).orElse(ddef).asInstanceOf[Tree]
case _ => tree
}
@@ -445,15 +452,13 @@ class Namer { typer: Typer =>
/** Typecheck tree during completion, and remember result in typedtree map */
private def typedAheadImpl(tree: Tree, pt: Type)(implicit ctx: Context): tpd.Tree = {
val xtree = expanded(tree)
- typedTree.get(xtree) match {
+ xtree.getAttachment(TypedAhead) match {
case Some(ttree) => ttree
case none =>
val ttree = typer.typed(tree, pt)
- typedTree(xtree) = ttree
+ xtree.pushAttachment(TypedAhead, ttree)
ttree
}
- // was: typedTree.getOrElseUpdate(expanded(tree), typer.typed(tree, pt))
- // but this fails for AnyRefMap with an ArrayIndexOutOfBounds exception in getOrElseUpdate
}
def typedAheadType(tree: Tree, pt: Type = WildcardType)(implicit ctx: Context): tpd.Tree =