aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/ast/Trees.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-09-28 09:33:32 +0200
committerMartin Odersky <odersky@gmail.com>2016-09-28 09:33:32 +0200
commit992c72ee5f2f105d587de20efd3858824fc7e7c8 (patch)
tree8e62d279d4e9ae61849256fe0b06d0f2bd0abb12 /src/dotty/tools/dotc/ast/Trees.scala
parent517aafc8e42f7204debdd2d9bff30c9fb90fab98 (diff)
downloaddotty-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.
Diffstat (limited to 'src/dotty/tools/dotc/ast/Trees.scala')
-rw-r--r--src/dotty/tools/dotc/ast/Trees.scala68
1 files changed, 8 insertions, 60 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)