summaryrefslogtreecommitdiff
path: root/src/scalap/scala/tools/scalap/scalax/rules/scalasig/Symbol.scala
blob: dee1cf84ac23af3628579800d71bdce352e97680 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package scala.tools.scalap
package scalax
package rules
package scalasig

import ScalaSigEntryParsers._

trait Symbol extends Flags {
  def name : String
  def parent : Option[Symbol]
  def children : Seq[Symbol]

  def path : String = parent.map(_.path + ".").getOrElse("") + name
}

case object NoSymbol extends Symbol {
  def name = "<no symbol>"
  def parent = None
  def hasFlag(flag : Long) = false
  def children = Nil
}

abstract class ScalaSigSymbol extends Symbol {
  def applyRule[A](rule : EntryParser[A]) : A = expect(rule)(entry)
  def applyScalaSigRule[A](rule : ScalaSigParsers.Parser[A]) = ScalaSigParsers.expect(rule)(entry.scalaSig)

  def entry : ScalaSig#Entry
  def index = entry.index

  lazy val children : Seq[Symbol] = applyScalaSigRule(ScalaSigParsers.symbols) filter (_.parent == Some(this))
  lazy val attributes : Seq[AttributeInfo] = applyScalaSigRule(ScalaSigParsers.attributes) filter (_.symbol == this)
}

case class ExternalSymbol(name : String, parent : Option[Symbol], entry : ScalaSig#Entry) extends ScalaSigSymbol {
  override def toString = path
  def hasFlag(flag : Long) = false
}

case class SymbolInfo(name : String, owner : Symbol, flags : Int, privateWithin : Option[AnyRef], info : Int, entry : ScalaSig#Entry) {
  def symbolString(any : AnyRef) = any match {
    case sym : SymbolInfoSymbol => sym.index.toString
    case other => other.toString
  }

  override def toString = name + ", owner=" + symbolString(owner) + ", flags=" + flags.toHexString + ", info=" + info + (privateWithin match {
    case Some(any) => ", privateWithin=" + symbolString(any)
    case None => " "
  })
}

abstract class SymbolInfoSymbol extends ScalaSigSymbol {
  def symbolInfo : SymbolInfo

  def entry = symbolInfo.entry
  def name = symbolInfo.name
  def parent = Some(symbolInfo.owner)
  def hasFlag(flag : Long) = (symbolInfo.flags & flag) != 0L

  lazy val infoType = applyRule(parseEntry(typeEntry)(symbolInfo.info))
}

case class TypeSymbol(symbolInfo : SymbolInfo) extends SymbolInfoSymbol{
  override def path = name
}

case class AliasSymbol(symbolInfo : SymbolInfo) extends SymbolInfoSymbol{
  override def path = name
}
case class ClassSymbol(symbolInfo : SymbolInfo, thisTypeRef : Option[Int]) extends SymbolInfoSymbol {
  lazy val selfType = thisTypeRef.map{(x: Int) => applyRule(parseEntry(typeEntry)(x))}
}
case class ObjectSymbol(symbolInfo : SymbolInfo) extends SymbolInfoSymbol
case class MethodSymbol(symbolInfo : SymbolInfo, aliasRef : Option[Int]) extends SymbolInfoSymbol