org.bitbucket.inkytonik.kiama.relation

Tree

class Tree[T <: Product, +R <: T] extends AnyRef

Relational representations of trees built out of hierarchical Product instances. Typically, the nodes are instances of case classes.

The type T is the common base type of the tree nodes. The type R is a sub-type of T that is the type of the root node.

The originalRoot value should be the root of a finite, acyclic structure that contains only Product instances of type T (unless they are skipped, see below).

The shape argument governs how the structure referred to by originalRoot is treated. If shape is LeaveAlone (the default) then the structure is used without change. If shape is CheckTree then a check is run before the structure is used to make sure that it is a tree (i.e., no node sharing nor cycles). A runtime error occurs if this is not the case. If shape is EnsureTree then shared parts of the structure are cloned to ensure that it is a tree before it is used.

If you are confident that your structure is a tree (e.g., it comes from a parser) then the default shape should be fine. If you prefer a bit more safety, then use CheckTree so that a non-tree structure cannot be missed. Finally, use EnsureTree if you know that your structure may contain sharing (e.g., it is produced by a term rewriting process).

The child relation of a tree is defined to skip certain nodes. Specifically, if a node of type T is wrapped in a Some of an option, a Left or Right of an Either, a tuple up to size four, or a TraversableOnce, then those wrappers are ignored. E.g., if t1 is Some (t2) where both t1 and t2 are of type T, then t1 will be t2's parent, not the Some value.

Thanks to Len Hamey for the idea to use lazy cloning to restore the tree structure instead of requiring that the input trees contain no sharing.

Self Type
Tree[T, R]
Source
Tree.scala
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Tree
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Tree(originalRoot: R, shape: TreeShape = LeaveAlone)

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def bottomupNoBridges(s: Strategy): Strategy

    A version of bottomup that doesn't traverse bridges.

  8. lazy val child: TreeRelation[T]

    The basic relations between a node and its children.

    The basic relations between a node and its children. All of the other relations are derived from child. If this tree's shape argument is CheckTree then a check will be performed that the structure is actually a tree. A runtime error will be thrown if it's not a tree.

  9. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  10. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  11. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  12. def everywherebuNoBridges(s: Strategy): Strategy

    A version of everywherebu that doesn't traverse bridges.

  13. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  14. lazy val firstChild: TreeRelation[T]

    A relation that relates a node to its first child.

  15. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  16. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  17. def index(t: T): Int

    Return the first index of t in the children of t's parent node.

    Return the first index of t in the children of t's parent node. Counts from zero. Is zero for root.

  18. def indexFromEnd(t: T): Int

    Return the last index of t in the children of t's parent node.

    Return the last index of t in the children of t's parent node. Counts from zero. Is zero for root.

  19. def isFirst(t: T): Boolean

    Return whether or not t is a first child.

    Return whether or not t is a first child. True for root.

  20. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  21. def isLast(t: T): Boolean

    Return whether or not t is a last child.

    Return whether or not t is a last child. True for root.

  22. def isRoot(t: T): Boolean

    Return whether or not t is the root of this tree.

  23. lazy val lastChild: TreeRelation[T]

    A relation that relates a node to its last child.

  24. def mapChild(f: (Vector[T]) ⇒ Vector[T]): TreeRelation[T]

    Map the function f over the images of this tree's child relation and use the resulting graph to make a new tree relation.

  25. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  26. lazy val next: TreeRelation[T]

    A relation that relates a node to its next sibling.

    A relation that relates a node to its next sibling. Inverse of the prev relation.

  27. lazy val nodes: Vector[T]

    The nodes that occur in this tree.

    The nodes that occur in this tree. Mostly useful if you want to iterate to look at every node.

  28. final def notify(): Unit

    Definition Classes
    AnyRef
  29. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  30. val originalRoot: R

  31. lazy val parent: TreeRelation[T]

    The parent relation for this tree (inverse of child relation).

  32. lazy val prev: TreeRelation[T]

    A relation that relates a node to its previous sibling.

    A relation that relates a node to its previous sibling. Inverse of the next relation.

  33. lazy val root: R

    The root node of the tree.

    The root node of the tree. If this tree's shape argument is EnsureTree the root node will be different from the original root if any nodes in the original tree are shared, since they will be cloned as necessary to yield a proper tree structure. If there is no sharing or EnsureTree is not specified then root will be same as originalRoot.

    Bridges to other structures will not be traversed. This behaviour means that you can have references to other structures while still processing this structure as a tree in its own right.

  34. lazy val sibling: TreeRelation[T]

    A relation that relates a node to its siblings, including itself.

  35. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  36. def toString(): String

    Definition Classes
    AnyRef → Any
  37. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  38. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  39. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  40. def whenContains[V](t: T, v: ⇒ V): V

    If the tree contains node u return v, otherwise throw a NodeNotInTreeException.

    If the tree contains node u return v, otherwise throw a NodeNotInTreeException. v is only evaluated if necessary.

Inherited from AnyRef

Inherited from Any

Ungrouped