Skip to content
Snippets Groups Projects
Commit dc01ccda authored by Etienne Kneuss's avatar Etienne Kneuss
Browse files

Specify ids with per-name counters

parent 7f9a3874
Branches
Tags
No related merge requests found
...@@ -6,14 +6,14 @@ object Common { ...@@ -6,14 +6,14 @@ object Common {
import TypeTrees.Typed import TypeTrees.Typed
// the type is left blank (Untyped) for Identifiers that are not variables // the type is left blank (Untyped) for Identifiers that are not variables
class Identifier private[Common](val name: String, val id: Int, alwaysShowUniqueID: Boolean = false) extends Typed { class Identifier private[Common](val name: String, private val globalId: Int, val id: Int, alwaysShowUniqueID: Boolean = false) extends Typed {
self : Serializable => self : Serializable =>
override def equals(other: Any): Boolean = { override def equals(other: Any): Boolean = {
if(other == null || !other.isInstanceOf[Identifier]) if(other == null || !other.isInstanceOf[Identifier])
false false
else else
other.asInstanceOf[Identifier].id == this.id other.asInstanceOf[Identifier].globalId == this.globalId
} }
override def hashCode: Int = id override def hashCode: Int = id
...@@ -23,7 +23,7 @@ object Common { ...@@ -23,7 +23,7 @@ object Common {
// angle brackets: name + "\u3008" + id + "\u3009" // angle brackets: name + "\u3008" + id + "\u3009"
name + "[" + id + "]" name + "[" + id + "]"
} else if(alwaysShowUniqueID) { } else if(alwaysShowUniqueID) {
name + id name + (if(id > 0) id else "")
} else { } else {
name name
} }
...@@ -39,28 +39,22 @@ object Common { ...@@ -39,28 +39,22 @@ object Common {
} }
private object UniqueCounter { private object UniqueCounter {
private var soFar: Int = -1 private var globalId = -1
private var nameIds = Map[String, Int]().withDefaultValue(-1)
def next: Int = { def next(name: String): Int = {
soFar = soFar + 1 nameIds += name -> (1+nameIds(name))
soFar nameIds(name)
} }
def last: Int = { def nextGlobal = {
soFar globalId += 1
globalId
} }
} }
object FreshIdentifier { object FreshIdentifier {
def forceSkip(i : Int) : Unit = { def apply(name: String, alwaysShowUniqueID: Boolean = false) : Identifier = new Identifier(name, UniqueCounter.nextGlobal, UniqueCounter.next(name), alwaysShowUniqueID)
while(UniqueCounter.last < i) {
UniqueCounter.next
}
}
def last: Int = UniqueCounter.last
def apply(name: String, alwaysShowUniqueID: Boolean = false) : Identifier = new Identifier(name, UniqueCounter.next, alwaysShowUniqueID)
} }
trait ScalacPositional { trait ScalacPositional {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment