aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/ast/untpd.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-03-12 15:06:17 +0100
committerTobias Schlatter <tobias@meisch.ch>2014-03-20 20:25:05 +0100
commita4516eac1be98830c99ea48e9baedf022dfcb9f7 (patch)
tree8e0e62943160fb948bf338ace7b01bd0990ad2bc /src/dotty/tools/dotc/ast/untpd.scala
parent5b687fbee23060fbed285f090e3592f2b8cb6beb (diff)
downloaddotty-a4516eac1be98830c99ea48e9baedf022dfcb9f7.tar.gz
dotty-a4516eac1be98830c99ea48e9baedf022dfcb9f7.tar.bz2
dotty-a4516eac1be98830c99ea48e9baedf022dfcb9f7.zip
Hygienic desugaring
Made desugaring hygienic. Trees that are derived from some other tree are no longer stored as simple untyped Ident trees, but as TypeTrees that know how to derive their types from some other type. Test cases in pos: hygiene.scala, t0054.scala and t0085.scala. The comment in hygiene.scala points to the difficulties we are facing. In particular, we need type trees that can rebind some references of a source type to local occurrences with the same name. t0054.scala is similar to hygiene.scala. t0085.scala is trickier, but also related. Essentially the problem there is that we have a class that inherits its outer class. In this case it is important to resolve an identifier in the right context. The identifier added to the copy method of a case class must be resolved outside the class (just like the same identifier in the constructor of that case class).
Diffstat (limited to 'src/dotty/tools/dotc/ast/untpd.scala')
-rw-r--r--src/dotty/tools/dotc/ast/untpd.scala44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/ast/untpd.scala b/src/dotty/tools/dotc/ast/untpd.scala
index 4e55fe868..44f340932 100644
--- a/src/dotty/tools/dotc/ast/untpd.scala
+++ b/src/dotty/tools/dotc/ast/untpd.scala
@@ -6,12 +6,13 @@ import core._
import util.Positions._, Types._, Contexts._, Constants._, Names._, NameOps._, Flags._
import Denotations._, SymDenotations._, Symbols._, StdNames._, Annotations._, Trees._
import Decorators._
+import util.Attachment
import language.higherKinds
import collection.mutable.ListBuffer
object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
-// ----- Tree cases that exist in untyped form only ------------------
+ // ----- Tree cases that exist in untyped form only ------------------
trait OpTree extends Tree {
def op: Name
@@ -61,6 +62,47 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
override def withName(name: Name)(implicit ctx: Context) = cpy.PolyTypeDef(this, mods, name.toTypeName, tparams, rhs)
}
+ // ----- TypeTrees that refer to other tree's symbols -------------------
+
+ /** A type tree that gets its type from some other tree's symbol. Enters the
+ * type tree in the References attachment of the `from` tree as a side effect.
+ */
+ abstract class DerivedTypeTree extends TypeTree(EmptyTree) {
+
+ private var myWatched: Tree = EmptyTree
+
+ /** The watched tree; used only for printing */
+ def watched: Tree = myWatched
+
+ /** Install the derived type tree as a dependency on `original` */
+ def watching(original: DefTree): this.type = {
+ myWatched = original
+ val existing = original.attachmentOrElse(References, Nil)
+ original.putAttachment(References, this :: existing)
+ this
+ }
+
+ /** A hook to ensure that all necessary symbols are completed so that
+ * OriginalSymbol attachments are propagated to this tree
+ */
+ def ensureCompletions(implicit ctx: Context): Unit = ()
+
+ /** The method that computes the type of this tree */
+ def derivedType(originalSym: Symbol)(implicit ctx: Context): Type
+ }
+
+ /** Attachment key containing TypeTrees whose type is computed
+ * from the symbol in this type. These type trees have marker trees
+ * TypeRefOfSym or InfoOfSym as their originals.
+ */
+ val References = new Attachment.Key[List[Tree]]
+
+ /** Attachment key for TypeTrees marked with TypeRefOfSym or InfoOfSym
+ * which contains the symbol of the original tree from which this
+ * TypeTree is derived.
+ */
+ val OriginalSymbol = new Attachment.Key[Symbol]
+
// ------ Creation methods for untyped only -----------------
def Ident(name: Name): Ident = new Ident(name)