aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/core/NameInfos.scala
blob: e8db88f84226f69406865d5c27d9b6ac5e0b5af4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package dotty.tools.dotc
package core

import Names._

/** Additional info associated with a name. At a minimum its kind and
 *  a way to turn it into a string.
 */
abstract class NameInfo extends util.DotClass {
  def kind: NameInfo.Kind
  def mkString(underlying: TermName): String
  def map(f: SimpleTermName => SimpleTermName): NameInfo = this
}

object NameInfo {

  type Kind = Int

  val TermNameKind = 0
  val QualifiedKind = 1
  val ModuleClassKind = 2

  def definesNewName(kind: Kind) = kind <= QualifiedKind

  /** TermNames have the lowest possible kind */
  val TermName = new NameInfo {
    def kind = TermNameKind
    def mkString(underlying: TermName) = underlying.toString // will cause an unsupported exception
  }

  case class Qualified(name: SimpleTermName, separator: String) extends NameInfo {
    def kind = QualifiedKind
    def mkString(underlying: TermName) = s"$underlying$separator$name"
    override def map(f: SimpleTermName => SimpleTermName): NameInfo = Qualified(f(name), separator)
    override def toString = s"Qualified($name, $separator)"
  }

  val ModuleClass = new NameInfo {
    def kind = ModuleClassKind
    def mkString(underlying: TermName) = underlying + "$"
    override def toString = "ModuleClass"
  }
}