Dotty Documentation

0.15.0-bin-SNAPSHOT

abstract class Tree [ -T ]
extends Positioned with Product with Container with Showable

Trees take a parameter indicating what the type of their tpe field is. Two choices: Type or Untyped. Untyped trees have type Tree[Untyped].

Tree typing uses a copy-on-write implementation:

  • You can never observe a tpe which is null (throws an exception)
  • So when creating a typed tree with withType we can re-use the existing tree transparently, assigning its tpe field, provided it was null before.
  • It is impossible to embed untyped trees in typed ones.
  • Typed trees can be embedded in untyped ones provided they are rooted in a TypedSplice node.
  • Type checking an untyped tree should remove all embedded TypedSplice nodes.

[-] Constructors

Tree ( )
Tree ( implicit src: SourceFile )

[-] Members

[+] type ThisTree = Nothing <: Tree [ T ]

The type constructor at the root of the tree

[+] protected var myTpe : T
[+] @constructorOnly private implicit val src : SourceFile
[+] private def checkChildrenTyped ( it: Iterator [ Any ] ) ( implicit ctx: Context ) : Unit

Check that typed trees don't refer to untyped ones, except if - the parent tree is an import, or - the child tree is an identifier, or - errors were reported

[+] def denot ( implicit ctx: Context ) : Denotation

The denotation referred to by this tree. Defined for DenotingTrees and ProxyTrees, NoDenotation for other kinds of trees

[+] override def equals ( that: Any ) : Boolean
[+] def foreachInThicket ( op: Tree [ T ] => Unit ) : Unit

If this is a thicket, perform op on each of its trees otherwise, perform op ion tree itself.

[+] final def hasType : Boolean

Does the tree have its type field set? Note: this operation is not referentially transparent, because it can observe the withType modifications. Should be used only in special circumstances (we need it for printing trees with optional type info).

[+] override def hashCode ( ) : Int
[+] def isDef : Boolean

Does this tree define a new symbol that is not defined elsewhere?

[+] def isEmpty : Boolean

Is this tree either the empty tree or the empty ValDef or an empty type ident?

[+] def isPattern : Boolean

Is this a legal part of a pattern which is not at the same time a term?

[+] def isTerm : Boolean

Does this tree represent a term?

[+] def isType : Boolean

Does this tree represent a type?

[+] protected def myTpe_= ( x$1: T ) : Unit
[+] def orElse ( that: => Tree [ U ] ) : Tree [ U ]

if this tree is the empty tree, the alternative, else this tree

[+] def overwriteType ( tpe: T ) : Unit

Destructively set the type of the tree. This should be called only when it is known that it is safe under sharing to do so. One use-case is in the withType method below which implements copy-on-write. Another use-case is in method interpolateAndAdapt in Typer, where we overwrite with a simplified version of the type itself.

[+] final def posd : Positioned

This tree, widened to Positioned. Used to make clear we only need the position, typically for error reporting.

[+] def sameTree ( that: Tree [ Nothing <: Any ] ) : Boolean
[+] final def symbol ( implicit ctx: Context ) : Symbol

Shorthand for denot.symbol.

[+] def toList : List [ Tree [ T ] ]

Convert tree to a list. Gives a singleton list, except for thickets which return their element trees.

[+] override def toText ( printer: Printer ) : Text

The text representation of this showable element. This normally dispatches to a pattern matching method in Printers.

[+] final def tpe : T

The type of the tree. In case of an untyped tree, an UnAssignedTypeException is thrown. (Overridden by empty trees)

[+] def treeSize : Int

The number of nodes in this tree

[+] final def typeOpt : Type
[+] def withType ( tpe: Type ) ( implicit ctx: Context ) : ThisTree [ Type ]

Return a typed tree that's isomorphic to this tree, but has given type. (Overridden by empty trees)

[+] def withTypeUnchecked ( tpe: Type ) : ThisTree [ Type ]