Skip to content

Commit

Permalink
[nomaster] Revert "DummyTree => CannotHaveAttrs"
Browse files Browse the repository at this point in the history
This reverts commit 838cbe6.

Conflicts:
	src/reflect/scala/reflect/api/Trees.scala
  • Loading branch information
xeno-by committed Feb 5, 2013
1 parent 4d7982b commit c720531
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/ast/Positions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ trait Positions extends scala.reflect.internal.Positions {
// When we prune due to encountering a position, traverse the
// pruned children so we can warn about those lacking positions.
t.children foreach { c =>
if (!c.canHaveAttrs) ()
if (c.isDummy) ()
else if (c.pos == NoPosition) {
reporter.warning(t.pos, " Positioned tree has unpositioned child in phase " + globalPhase)
inform("parent: " + treeSymStatus(t))
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ trait Trees extends scala.reflect.internal.Trees { self: Global =>
else
super.transform {
tree match {
case tree if !tree.canHaveAttrs =>
case tree if tree.isDummy =>
tree
case tpt: TypeTree =>
if (tpt.original != null)
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2764,7 +2764,7 @@ self =>
if (in.token == LBRACE) {
// @S: pre template body cannot stub like post body can!
val (self, body) = templateBody(isPre = true)
if (in.token == WITH && (self eq emptyValDef)) {
if (in.token == WITH && self.isEmpty) {
val earlyDefs: List[Tree] = body flatMap {
case vdef @ ValDef(mods, _, _, _) if !mods.isDeferred =>
List(copyValDef(vdef)(mods = mods | Flags.PRESUPER))
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/scala/tools/nsc/interactive/RangePositions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ self: scala.tools.nsc.Global =>
*/
private def setChildrenPos(pos: Position, trees: List[Tree]): Unit = try {
for (tree <- trees) {
if (!tree.isEmpty && tree.canHaveAttrs && tree.pos == NoPosition) {
if (!tree.isEmpty && tree.pos == NoPosition) {
val children = tree.children
if (children.isEmpty) {
tree setPos pos.focus
Expand All @@ -165,7 +165,7 @@ self: scala.tools.nsc.Global =>
*/
override def atPos[T <: Tree](pos: Position)(tree: T): T = {
if (pos.isOpaqueRange) {
if (!tree.isEmpty && tree.canHaveAttrs && tree.pos == NoPosition) {
if (!tree.isEmpty && tree.pos == NoPosition) {
tree.setPos(pos)
val children = tree.children
if (children.nonEmpty) {
Expand Down Expand Up @@ -203,7 +203,7 @@ self: scala.tools.nsc.Global =>

def validate(tree: Tree, encltree: Tree): Unit = {

if (!tree.isEmpty && tree.canHaveAttrs) {
if (!tree.isEmpty) {
if (settings.Yposdebug.value && (settings.verbose.value || settings.Yrangepos.value))
println("[%10s] %s".format("validate", treeStatus(tree, encltree)))

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/typechecker/Typers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ trait Typers extends Modes with Adaptations with Tags {

object UnTyper extends Traverser {
override def traverse(tree: Tree) = {
if (tree.canHaveAttrs) {
if (!tree.isDummy) {
tree.tpe = null
if (tree.hasSymbol) tree.symbol = NoSymbol
}
Expand Down
10 changes: 1 addition & 9 deletions src/reflect/scala/reflect/api/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,8 @@ trait Trees { self: Universe =>
def isDef: Boolean

/** Is this tree one of the empty trees?
*
* Empty trees are: the `EmptyTree` null object, `TypeTree` instances that don't carry a type
* and the special `emptyValDef` singleton.
*
* In the compiler the `isEmpty` check and the derived `orElse` method are mostly used
* as a check for a tree being a null object (`EmptyTree` for term trees and empty TypeTree for type trees).
*
* Unfortunately `emptyValDef` is also considered to be `isEmpty`, but this is deemed to be
* a conceptual mistake pending a fix in https://issues.scala-lang.org/browse/SI-6762.
*/
def isEmpty: Boolean

Expand Down Expand Up @@ -2923,8 +2916,7 @@ trait Trees { self: Universe =>
trees mapConserve (tree => transform(tree).asInstanceOf[TypeDef])
/** Transforms a `ValDef`. */
def transformValDef(tree: ValDef): ValDef =
if (tree eq emptyValDef) tree
else transform(tree).asInstanceOf[ValDef]
if (tree.isEmpty) tree else transform(tree).asInstanceOf[ValDef]
/** Transforms a list of `ValDef` nodes. */
def transformValDefs(trees: List[ValDef]): List[ValDef] =
trees mapConserve (transformValDef(_))
Expand Down
2 changes: 1 addition & 1 deletion src/reflect/scala/reflect/internal/Positions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ trait Positions extends api.Positions { self: SymbolTable =>
protected class DefaultPosAssigner extends PosAssigner {
var pos: Position = _
override def traverse(t: Tree) {
if (!t.canHaveAttrs) ()
if (t.isDummy) ()
else if (t.pos == NoPosition) {
t.setPos(pos)
super.traverse(t) // TODO: bug? shouldn't the traverse be outside of the if?
Expand Down
2 changes: 1 addition & 1 deletion src/reflect/scala/reflect/internal/Printers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ trait Printers extends api.Printers { self: SymbolTable =>
case tree =>
xprintTree(this, tree)
}
if (printTypes && tree.isTerm && tree.canHaveAttrs) {
if (printTypes && tree.isTerm && !tree.isEmpty) {
print("{", if (tree.tpe eq null) "<null>" else tree.tpe.toString, "}")
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/reflect/scala/reflect/internal/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ trait Trees extends api.Trees { self: SymbolTable =>
def isDef = false

def isEmpty = false
def canHaveAttrs = true
def isDummy = false

/** The canonical way to test if a Tree represents a term.
*/
Expand Down Expand Up @@ -955,8 +955,9 @@ trait Trees extends api.Trees { self: SymbolTable =>

def ValDef(sym: Symbol): ValDef = ValDef(sym, EmptyTree)

trait CannotHaveAttrs extends Tree {
override def canHaveAttrs = false
trait DummyTree extends Tree {
override def isEmpty = true
override def isDummy = true

private def unsupported(what: String, args: Any*) =
throw new UnsupportedOperationException(s"$what($args) inapplicable for "+self.toString)
Expand All @@ -968,9 +969,9 @@ trait Trees extends api.Trees { self: SymbolTable =>
override def tpe_=(t: Type) = if (t != NoType) unsupported("tpe_=", t)
}

case object EmptyTree extends TermTree with CannotHaveAttrs { override def isEmpty = true; val asList = List(this) }
object emptyValDef extends ValDef(Modifiers(PRIVATE), nme.WILDCARD, TypeTree(NoType), EmptyTree) with CannotHaveAttrs
object pendingSuperCall extends Apply(Select(Super(This(tpnme.EMPTY), tpnme.EMPTY), nme.CONSTRUCTOR), List()) with CannotHaveAttrs
case object EmptyTree extends TermTree with DummyTree { val asList = List(this) }
object emptyValDef extends ValDef(Modifiers(PRIVATE), nme.WILDCARD, TypeTree(NoType), EmptyTree) with DummyTree
object pendingSuperCall extends Apply(Select(Super(This(tpnme.EMPTY), tpnme.EMPTY), nme.CONSTRUCTOR), List()) with DummyTree

def DefDef(sym: Symbol, mods: Modifiers, vparamss: List[List[ValDef]], rhs: Tree): DefDef =
atPos(sym.pos) {
Expand Down Expand Up @@ -1122,7 +1123,7 @@ trait Trees extends api.Trees { self: SymbolTable =>
traverse(annot); traverse(arg)
case Template(parents, self, body) =>
traverseTrees(parents)
if (self ne emptyValDef) traverse(self)
if (!self.isEmpty) traverse(self)
traverseStats(body, tree.symbol)
case Block(stats, expr) =>
traverseTrees(stats); traverse(expr)
Expand Down

0 comments on commit c720531

Please sign in to comment.