diff options
author | Martin Odersky <odersky@gmail.com> | 2016-09-28 09:33:32 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-09-28 09:33:32 +0200 |
commit | 992c72ee5f2f105d587de20efd3858824fc7e7c8 (patch) | |
tree | 8e62d279d4e9ae61849256fe0b06d0f2bd0abb12 | |
parent | 517aafc8e42f7204debdd2d9bff30c9fb90fab98 (diff) | |
download | dotty-992c72ee5f2f105d587de20efd3858824fc7e7c8.tar.gz dotty-992c72ee5f2f105d587de20efd3858824fc7e7c8.tar.bz2 dotty-992c72ee5f2f105d587de20efd3858824fc7e7c8.zip |
Make Modifiers untyped only.
The typed variant is no longer needed. This means modifiers can safely be
ignored in typed trees if we so choose.
-rw-r--r-- | src/dotty/tools/dotc/ast/Trees.scala | 68 | ||||
-rw-r--r-- | src/dotty/tools/dotc/ast/untpd.scala | 46 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala | 4 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala | 3 |
4 files changed, 58 insertions, 63 deletions
diff --git a/src/dotty/tools/dotc/ast/Trees.scala b/src/dotty/tools/dotc/ast/Trees.scala index 061a0c019..619ac36e5 100644 --- a/src/dotty/tools/dotc/ast/Trees.scala +++ b/src/dotty/tools/dotc/ast/Trees.scala @@ -33,51 +33,7 @@ object Trees { /** Attachment key for trees with documentation strings attached */ val DocComment = new Attachment.Key[Comment] - /** Modifiers and annotations for definitions - * @param flags The set flags - * @param privateWithin If a private or protected has is followed by a - * qualifier [q], the name q, "" as a typename otherwise. - * @param annotations The annotations preceding the modifiers - */ - case class Modifiers[-T >: Untyped] ( - flags: FlagSet = EmptyFlags, - privateWithin: TypeName = tpnme.EMPTY, - annotations: List[Tree[T]] = Nil) extends Positioned with Cloneable { - - def is(fs: FlagSet): Boolean = flags is fs - def is(fc: FlagConjunction): Boolean = flags is fc - - def | (fs: FlagSet): Modifiers[T] = withFlags(flags | fs) - def & (fs: FlagSet): Modifiers[T] = withFlags(flags & fs) - def &~(fs: FlagSet): Modifiers[T] = withFlags(flags &~ fs) - - def toTypeFlags: Modifiers[T] = withFlags(flags.toTypeFlags) - def toTermFlags: Modifiers[T] = withFlags(flags.toTermFlags) - - def withFlags(flags: FlagSet) = - if (this.flags == flags) this - else copy(flags = flags) - - def withAddedAnnotation[U >: Untyped <: T](annot: Tree[U]): Modifiers[U] = - if (annotations.exists(_ eq annot)) this - else withAnnotations(annotations :+ annot) - - def withAnnotations[U >: Untyped <: T](annots: List[Tree[U]]): Modifiers[U] = - if (annots eq annotations) this - else copy(annotations = annots) - - def withPrivateWithin(pw: TypeName) = - if (pw.isEmpty) this - else copy(privateWithin = pw) - - def hasFlags = flags != EmptyFlags - def hasAnnotations = annotations.nonEmpty - def hasPrivateWithin = privateWithin != tpnme.EMPTY - - def tokenPos: Seq[(Token, Position)] = ??? - } - - @sharable private var nextId = 0 // for debugging + @sharable private var nextId = 0 // for debugging type LazyTree = AnyRef /* really: Tree | Lazy[Tree] */ type LazyTreeList = AnyRef /* really: List[Tree] | Lazy[List[Tree]] */ @@ -320,27 +276,27 @@ object Trees { abstract class MemberDef[-T >: Untyped] extends NameTree[T] with DefTree[T] { type ThisTree[-T >: Untyped] <: MemberDef[T] - private[this] var myMods: Modifiers[T] = null + private[this] var myMods: untpd.Modifiers = null - private[dotc] def rawMods: Modifiers[T] = - if (myMods == null) genericEmptyModifiers else myMods + private[dotc] def rawMods: untpd.Modifiers = + if (myMods == null) untpd.EmptyModifiers else myMods def rawComment: Option[Comment] = getAttachment(DocComment) - def withMods(mods: Modifiers[Untyped]): ThisTree[Untyped] = { + def withMods(mods: untpd.Modifiers): ThisTree[Untyped] = { val tree = if (myMods == null || (myMods == mods)) this else clone.asInstanceOf[MemberDef[Untyped]] tree.setMods(mods) tree.asInstanceOf[ThisTree[Untyped]] } - def withFlags(flags: FlagSet): ThisTree[Untyped] = withMods(Modifiers(flags)) + def withFlags(flags: FlagSet): ThisTree[Untyped] = withMods(untpd.Modifiers(flags)) def setComment(comment: Option[Comment]): ThisTree[Untyped] = { comment.map(putAttachment(DocComment, _)) asInstanceOf[ThisTree[Untyped]] } - protected def setMods(mods: Modifiers[T @uncheckedVariance]) = myMods = mods + protected def setMods(mods: untpd.Modifiers) = myMods = mods } /** A ValDef or DefDef tree */ @@ -727,16 +683,14 @@ object Trees { class EmptyValDef[T >: Untyped] extends ValDef[T]( nme.WILDCARD, genericEmptyTree[T], genericEmptyTree[T]) with WithoutTypeOrPos[T] { override def isEmpty: Boolean = true - setMods(Modifiers[T](PrivateLocal)) + setMods(untpd.Modifiers(PrivateLocal)) } @sharable val theEmptyTree: Thicket[Type] = Thicket(Nil) @sharable val theEmptyValDef = new EmptyValDef[Type] - @sharable val theEmptyModifiers = new Modifiers() def genericEmptyValDef[T >: Untyped]: ValDef[T] = theEmptyValDef.asInstanceOf[ValDef[T]] def genericEmptyTree[T >: Untyped]: Thicket[T] = theEmptyTree.asInstanceOf[Thicket[T]] - def genericEmptyModifiers[T >: Untyped]: Modifiers[T] = theEmptyModifiers.asInstanceOf[Modifiers[T]] def flatten[T >: Untyped](trees: List[Tree[T]]): List[Tree[T]] = { var buf: ListBuffer[Tree[T]] = null @@ -795,7 +749,6 @@ object Trees { abstract class Instance[T >: Untyped <: Type] extends DotClass { inst => - type Modifiers = Trees.Modifiers[T] type Tree = Trees.Tree[T] type TypTree = Trees.TypTree[T] type TermTree = Trees.TermTree[T] @@ -853,14 +806,9 @@ object Trees { @sharable val EmptyTree: Thicket = genericEmptyTree @sharable val EmptyValDef: ValDef = genericEmptyValDef - @sharable val EmptyModifiers: Modifiers = genericEmptyModifiers // ----- Auxiliary creation methods ------------------ - def Modifiers(flags: FlagSet = EmptyFlags, - privateWithin: TypeName = tpnme.EMPTY, - annotations: List[Tree] = Nil) = new Modifiers(flags, privateWithin, annotations) - def Thicket(trees: List[Tree]): Thicket = new Thicket(trees) def Thicket(): Thicket = EmptyTree def Thicket(x1: Tree, x2: Tree): Thicket = Thicket(x1 :: x2 :: Nil) diff --git a/src/dotty/tools/dotc/ast/untpd.scala b/src/dotty/tools/dotc/ast/untpd.scala index 102ee2e4e..61c3a79a4 100644 --- a/src/dotty/tools/dotc/ast/untpd.scala +++ b/src/dotty/tools/dotc/ast/untpd.scala @@ -86,6 +86,52 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { */ class InfixOpBlock(leftOperand: Tree, rightOp: Tree) extends Block(leftOperand :: Nil, rightOp) + // ----- Modifiers ----------------------------------------------------- + + /** Modifiers and annotations for definitions + * @param flags The set flags + * @param privateWithin If a private or protected has is followed by a + * qualifier [q], the name q, "" as a typename otherwise. + * @param annotations The annotations preceding the modifiers + */ + case class Modifiers ( + flags: FlagSet = EmptyFlags, + privateWithin: TypeName = tpnme.EMPTY, + annotations: List[Tree] = Nil) extends Positioned with Cloneable { + + def is(fs: FlagSet): Boolean = flags is fs + def is(fc: FlagConjunction): Boolean = flags is fc + + def | (fs: FlagSet): Modifiers = withFlags(flags | fs) + def & (fs: FlagSet): Modifiers = withFlags(flags & fs) + def &~(fs: FlagSet): Modifiers = withFlags(flags &~ fs) + + def toTypeFlags: Modifiers = withFlags(flags.toTypeFlags) + def toTermFlags: Modifiers = withFlags(flags.toTermFlags) + + def withFlags(flags: FlagSet) = + if (this.flags == flags) this + else copy(flags = flags) + + def withAddedAnnotation(annot: Tree): Modifiers = + if (annotations.exists(_ eq annot)) this + else withAnnotations(annotations :+ annot) + + def withAnnotations(annots: List[Tree]): Modifiers = + if (annots eq annotations) this + else copy(annotations = annots) + + def withPrivateWithin(pw: TypeName) = + if (pw.isEmpty) this + else copy(privateWithin = pw) + + def hasFlags = flags != EmptyFlags + def hasAnnotations = annotations.nonEmpty + def hasPrivateWithin = privateWithin != tpnme.EMPTY + } + + @sharable val EmptyModifiers: Modifiers = new Modifiers() + // ----- TypeTrees that refer to other tree's symbols ------------------- /** A type tree that gets its type from some other tree's symbol. Enters the diff --git a/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index f7363e72b..9d070e777 100644 --- a/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -729,8 +729,8 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) { } } val mods = - if (sym.annotations.isEmpty) EmptyModifiers - else Modifiers(annotations = sym.annotations.map(_.tree)) + if (sym.annotations.isEmpty) untpd.EmptyModifiers + else untpd.Modifiers(annotations = sym.annotations.map(_.tree)) tree.withMods(mods) // record annotations in tree so that tree positions can be filled in. goto(end) setPos(start, tree) diff --git a/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index d278fdef1..70148b3e2 100644 --- a/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -12,6 +12,7 @@ import StdNames._, Denotations._, NameOps._, Flags._, Constants._, Annotations._ import dotty.tools.dotc.typer.ProtoTypes.{FunProtoTyped, FunProto} import util.Positions._ import dotty.tools.dotc.ast.{tpd, Trees, untpd}, ast.tpd._ +import ast.untpd.Modifiers import printing.Texts._ import printing.Printer import io.AbstractFile @@ -1236,7 +1237,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas val pflags = (pflagsHi.toLong << 32) + pflagsLo val flags = unpickleScalaFlags(pflags, isType) val privateWithin = readNameRef().asTypeName - Trees.Modifiers[Type](flags, privateWithin, Nil) + Modifiers(flags, privateWithin, Nil) } protected def readTemplateRef()(implicit ctx: Context): Template = |