From 23992437cf085c238ae88040913780dec1112d6e Mon Sep 17 00:00:00 2001 From: michelou Date: Wed, 23 Aug 2006 12:14:40 +0000 Subject: removed leading/trailing blanks/tabs in symtab/... removed leading/trailing blanks/tabs in symtab/*.scala --- .../scala/tools/nsc/symtab/InfoTransformers.scala | 41 +++-- src/compiler/scala/tools/nsc/symtab/Names.scala | 165 +++++++++++---------- src/compiler/scala/tools/nsc/symtab/Scopes.scala | 140 ++++++++--------- 3 files changed, 173 insertions(+), 173 deletions(-) diff --git a/src/compiler/scala/tools/nsc/symtab/InfoTransformers.scala b/src/compiler/scala/tools/nsc/symtab/InfoTransformers.scala index bf01d4419a..c5147f9cbb 100644 --- a/src/compiler/scala/tools/nsc/symtab/InfoTransformers.scala +++ b/src/compiler/scala/tools/nsc/symtab/InfoTransformers.scala @@ -1,45 +1,42 @@ -/* NSC -- new scala compiler - * Copyright 2005 LAMP/EPFL +/* NSC -- new Scala compiler + * Copyright 2005-2006 LAMP/EPFL * @author Martin Odersky */ // $Id$ -package scala.tools.nsc.symtab; + +package scala.tools.nsc.symtab trait InfoTransformers requires SymbolTable { abstract class InfoTransformer { - var prev: InfoTransformer = this; - var next: InfoTransformer = this; + var prev: InfoTransformer = this + var next: InfoTransformer = this - val pid: Phase#Id; - val changesBaseClasses: boolean; - def transform(sym: Symbol, tpe: Type): Type; + val pid: Phase#Id + val changesBaseClasses: Boolean + def transform(sym: Symbol, tpe: Type): Type def insert(that: InfoTransformer): unit = { - assert(this.pid != that.pid); + assert(this.pid != that.pid) if (that.pid < this.pid) { - prev insert that + prev insert that } else if (next.pid <= that.pid && next.pid != NoPhase.id) { - next insert that + next insert that } else { - that.next = next; - that.prev = this; - next.prev = that; - this.next = that + that.next = next + that.prev = this + next.prev = that + this.next = that } } def nextFrom(from: Phase#Id): InfoTransformer = if (from == this.pid) this else if (from < this.pid) - if (prev.pid < from) this - else prev.nextFrom(from); + if (prev.pid < from) this + else prev.nextFrom(from); else if (next.pid == NoPhase.id) next - else next.nextFrom(from); + else next.nextFrom(from) } } - - - - diff --git a/src/compiler/scala/tools/nsc/symtab/Names.scala b/src/compiler/scala/tools/nsc/symtab/Names.scala index 5fedb67ce4..e7f61614b8 100644 --- a/src/compiler/scala/tools/nsc/symtab/Names.scala +++ b/src/compiler/scala/tools/nsc/symtab/Names.scala @@ -1,35 +1,36 @@ -/* NSC -- new scala compiler - * Copyright 2005 LAMP/EPFL +/* NSC -- new Scala compiler + * Copyright 2005-2006 LAMP/EPFL * @author Martin Odersky */ // $Id$ -package scala.tools.nsc.symtab; -import scala.tools.util.UTF8Codec; -import scala.tools.nsc.util.NameTransformer; +package scala.tools.nsc.symtab + +import scala.tools.nsc.util.NameTransformer +import scala.tools.util.UTF8Codec class Names { // Operations ------------------------------------------------------------- - private val HASH_SIZE = 0x8000; - private val HASH_MASK = 0x7FFF; - private val NAME_SIZE = 0x20000; + private val HASH_SIZE = 0x8000 + private val HASH_MASK = 0x7FFF + private val NAME_SIZE = 0x20000 - final val nameDebug = false; + final val nameDebug = false /** memory to store all names sequentially */ - var chrs: Array[char] = new Array[char](NAME_SIZE); - private var nc = 0; + var chrs: Array[char] = new Array[char](NAME_SIZE) + private var nc = 0 /** hashtable for finding term names quickly */ - private val termHashtable = new Array[Name](HASH_SIZE); + private val termHashtable = new Array[Name](HASH_SIZE) /** hashtable for finding type names quickly */ - private val typeHashtable = new Array[Name](HASH_SIZE); + private val typeHashtable = new Array[Name](HASH_SIZE) /** the hashcode of a name */ @@ -45,7 +46,7 @@ class Names { * cs[offset..offset+len-1]? */ private def equals(index: int, cs: Array[char], offset: int, len: int): boolean = { - var i = 0; + var i = 0 while ((i < len) && (chrs(index + i) == cs(offset + i))) i = i + 1; i == len @@ -54,14 +55,14 @@ class Names { /** enter characters into chrs array */ private def enterChars(cs: Array[char], offset: int, len: int): unit = { - var i = 0; + var i = 0 while (i < len) { if (nc + i == chrs.length) { - val newchrs = new Array[char](chrs.length * 2); - System.arraycopy(chrs, 0, newchrs, 0, chrs.length); - chrs = newchrs; + val newchrs = new Array[char](chrs.length * 2) + System.arraycopy(chrs, 0, newchrs, 0, chrs.length) + chrs = newchrs } - chrs(nc + i) = cs(offset + i); + chrs(nc + i) = cs(offset + i) i = i + 1 } if (len == 0) nc = nc + 1 @@ -86,35 +87,35 @@ class Names { /** create a term name from string */ def newTermName(s: String): Name = - newTermName(s.toCharArray(), 0, s.length()); + newTermName(s.toCharArray(), 0, s.length()) /** create a term name from the UTF8 encoded bytes in bs[offset..offset+len-1]. */ def newTermName(bs: Array[byte], offset: int, len: int): Name = { - val cs = new Array[char](bs.length); - val nchrs = UTF8Codec.decode(bs, offset, cs, 0, len); + val cs = new Array[char](bs.length) + val nchrs = UTF8Codec.decode(bs, offset, cs, 0, len) newTermName(cs, 0, nchrs) } /** create a type name from the characters in cs[offset..offset+len-1]. */ def newTypeName(cs: Array[char], offset: int, len: int): Name = - newTermName(cs, offset, len).toTypeName; + newTermName(cs, offset, len).toTypeName /** create a type name from string */ def newTypeName(s: String): Name = - newTermName(s).toTypeName; + newTermName(s).toTypeName /** create a type name from the UTF8 encoded bytes in bs[offset..offset+len-1]. */ def newTypeName(bs: Array[byte], offset: int, len: int): Name = - newTermName(bs, offset, len).toTypeName; + newTermName(bs, offset, len).toTypeName - def nameChars: Array[char] = chrs; + def nameChars: Array[char] = chrs - implicit def view(s: String): Name = newTermName(s); + implicit def view(s: String): Name = newTermName(s) // Classes ---------------------------------------------------------------------- @@ -122,40 +123,40 @@ class Names { abstract class Name(index: int, len: int) extends Function1[int, char] { /** Index into name table */ - def start: int = index; + def start: int = index /** next name in the same hash bucket */ - var next: Name = null; + var next: Name = null /** return the length of this name */ - final def length: int = len; + final def length: int = len - final def isEmpty = length == 0; + final def isEmpty = length == 0 - def isTermName: boolean; - def isTypeName: boolean; - def toTermName: Name; - def toTypeName: Name; + def isTermName: boolean + def isTypeName: boolean + def toTermName: Name + def toTypeName: Name /** copy bytes of this name to buffer cs, starting at offset */ final def copyChars(cs: Array[char], offset: int) = - System.arraycopy(chrs, index, cs, offset, len); + System.arraycopy(chrs, index, cs, offset, len) /** return the ascii representation of this name */ final def toChars = { - val cs = new Array[char](len); - copyChars(cs, 0); + val cs = new Array[char](len) + copyChars(cs, 0) cs } /** return the string representation of this name */ - final override def toString(): String = new String(chrs, index, len); + final override def toString(): String = new String(chrs, index, len) /** Write to UTF8 representation of this name to given character array. * Start copying to index `to'. Return index of next free byte in array. @@ -163,26 +164,26 @@ class Names { * (i.e. maximally 3*length bytes). */ final def copyUTF8(bs: Array[byte], offset: int): int = - UTF8Codec.encode(chrs, index, bs, offset, len); + UTF8Codec.encode(chrs, index, bs, offset, len) /** return the hash value of this name */ - final override def hashCode(): int = index; + final override def hashCode(): int = index /** return the i'th char of this name */ - final def apply(i: int): char = chrs(index + i); + final def apply(i: int): char = chrs(index + i) /** return the index of first occurrence of char c in this name, length if not found */ - final def pos(c: char): int = pos(c, 0); + final def pos(c: char): int = pos(c, 0) /** return the index of first occurrence of char c in this name, length if not found */ - final def pos(s: String): int = pos(s, 0); + final def pos(s: String): int = pos(s, 0) /** return the index of first occurrence of char c in this name from `start', * length if not found */ final def pos(c: char, start: int): int = { - var i = start; + var i = start while (i < len && chrs(index + i) != c) i = i + 1; i } @@ -190,12 +191,12 @@ class Names { /** return the index of first occurrence of nonempty string s in this name from `start', * length if not found */ final def pos(s: String, start: int): int = { - var i = pos(s.charAt(0), start); + var i = pos(s.charAt(0), start) while (i + s.length() <= len) { - var j = 1; + var j = 1 while (s.charAt(j) == chrs(index + i + j)) { - j = j + 1; - if (j == s.length()) return i; + j = j + 1 + if (j == s.length()) return i } i = pos(s.charAt(0), i + 1) } @@ -204,15 +205,15 @@ class Names { /** return the index of last occurrence of char c in this name, -1 if not found. */ - final def lastPos(c: char): int = lastPos(c, len - 1); + final def lastPos(c: char): int = lastPos(c, len - 1) - final def lastPos(s: String): int = lastPos(s, len - s.length()); + final def lastPos(s: String): int = lastPos(s, len - s.length()) /** return the index of last occurrence of char c in this name from `start', * -1 if not found */ final def lastPos(c: char, start: int): int = { - var i = start; + var i = start while (i >= 0 && chrs(index + i) != c) i = i - 1; i } @@ -235,42 +236,44 @@ class Names { /** does this name start with prefix? */ - final def startsWith(prefix: Name): boolean = startsWith(prefix, 0); + final def startsWith(prefix: Name): boolean = startsWith(prefix, 0) /** does this name start with prefix at given start index? */ final def startsWith(prefix: Name, start: int): boolean = { - var i = 0; - while (i < prefix.length && start + i < len && chrs(index + start + i) == chrs(prefix.start + i)) + var i = 0 + while (i < prefix.length && start + i < len && + chrs(index + start + i) == chrs(prefix.start + i)) i = i + 1; i == prefix.length } /** does this name end with suffix? */ - final def endsWith(suffix: Name): boolean = endsWith(suffix, len); + final def endsWith(suffix: Name): boolean = endsWith(suffix, len) /** does this name end with suffix just before given end index? */ final def endsWith(suffix: Name, end: int): boolean = { var i = 1; - while (i <= suffix.length && i <= end && chrs(index + end - i) == chrs(suffix.start + suffix.length - i)) + while (i <= suffix.length && i <= end && + chrs(index + end - i) == chrs(suffix.start + suffix.length - i)) i = i + 1; i > suffix.length } /** the subname with characters from start to end-1 */ - def subName(from: int, to: int): Name; + def subName(from: int, to: int): Name /** replace all occurrences of `from' by `to' in name. * result is always a term name. */ def replace(from: char, to: char): Name = { - val cs = new Array[char](len); - var i = 0; + val cs = new Array[char](len) + var i = 0 while (i < len) { - val ch = this(i); + val ch = this(i) cs(i) = if (ch == from) to else ch; i = i + 1 } @@ -280,7 +283,7 @@ class Names { /** Replace operator symbols by corresponding "$op_name" */ def encode: Name = { val str = toString(); - val res = NameTransformer.encode(str); + val res = NameTransformer.encode(str) if (res == str) this else if (isTypeName) newTypeName(res) else newTermName(res) @@ -289,44 +292,44 @@ class Names { /** Replace $op_name by corresponding operator symbol */ def decode: String = ( NameTransformer.decode(toString()) + - (if (nameDebug && isTypeName) "!" else ""));//debug + (if (nameDebug && isTypeName) "!" else ""))//debug } private class TermName(index: int, len: int, hash: int) extends Name(index, len) { - next = termHashtable(hash); - termHashtable(hash) = this; - def isTermName: boolean = true; - def isTypeName: boolean = false; - def toTermName: Name = this; + next = termHashtable(hash) + termHashtable(hash) = this + def isTermName: boolean = true + def isTypeName: boolean = false + def toTermName: Name = this def toTypeName = { - val h = hashValue(chrs, index, len) & HASH_MASK; - var n = typeHashtable(h); + val h = hashValue(chrs, index, len) & HASH_MASK + var n = typeHashtable(h) while (n != null && n.start != index) n = n.next; if (n == null) - n = new TypeName(index, len, h); + n = new TypeName(index, len, h); n } def subName(from: int, to: int): Name = - newTermName(chrs, start + from, to - from); + newTermName(chrs, start + from, to - from) } private class TypeName(index: int, len: int, hash: int) extends Name(index, len) { - next = typeHashtable(hash); - typeHashtable(hash) = this; - def isTermName: boolean = false; - def isTypeName: boolean = true; + next = typeHashtable(hash) + typeHashtable(hash) = this + def isTermName: boolean = false + def isTypeName: boolean = true def toTermName: Name = { - val h = hashValue(chrs, index, len) & HASH_MASK; - var n = termHashtable(h); + val h = hashValue(chrs, index, len) & HASH_MASK + var n = termHashtable(h) while (n != null && n.start != index) n = n.next; if (n == null) - n = new TermName(index, len, h); + n = new TermName(index, len, h); n } - def toTypeName: Name = this; + def toTypeName: Name = this def subName(from: int, to: int): Name = - newTypeName(chrs, start + from, to - from); + newTypeName(chrs, start + from, to - from) } } diff --git a/src/compiler/scala/tools/nsc/symtab/Scopes.scala b/src/compiler/scala/tools/nsc/symtab/Scopes.scala index fd002c1f86..0f0ae7b877 100644 --- a/src/compiler/scala/tools/nsc/symtab/Scopes.scala +++ b/src/compiler/scala/tools/nsc/symtab/Scopes.scala @@ -1,9 +1,10 @@ -/* NSC -- new scala compiler - * Copyright 2005 LAMP/EPFL +/* NSC -- new Scala compiler + * Copyright 2005-2006 LAMP/EPFL * @author Martin Odersky */ // $Id$ -package scala.tools.nsc.symtab; + +package scala.tools.nsc.symtab trait Scopes requires SymbolTable { @@ -11,87 +12,87 @@ trait Scopes requires SymbolTable { /** the next entry in the hash bucket */ - var tail: ScopeEntry = _; + var tail: ScopeEntry = _ /** the next entry in this scope */ - var next: ScopeEntry = null; + var next: ScopeEntry = null - override def hashCode(): int = sym.name.start; - override def toString(): String = sym.toString(); + override def hashCode(): int = sym.name.start + override def toString(): String = sym.toString() } def newScopeEntry(sym: Symbol, owner: Scope): ScopeEntry = { - val e = new ScopeEntry(sym, owner); - e.next = owner.elems; - owner.elems = e; + val e = new ScopeEntry(sym, owner) + e.next = owner.elems + owner.elems = e e } - object NoScopeEntry extends ScopeEntry(NoSymbol, null); + object NoScopeEntry extends ScopeEntry(NoSymbol, null) class Scope(initElems: ScopeEntry) { - var elems: ScopeEntry = initElems; + var elems: ScopeEntry = initElems /** The number of times this scope is neted in another */ - private var nestinglevel = 0; + private var nestinglevel = 0 /** the hash table */ - private var hashtable: Array[ScopeEntry] = null; + private var hashtable: Array[ScopeEntry] = null /** a cache for all elements, to be used by symbol iterator. */ - private var elemsCache: List[Symbol] = null; + private var elemsCache: List[Symbol] = null /** size and mask of hash tables * todo: make hashtables grow? */ - private val HASHSIZE = 0x80; - private val HASHMASK = 0x7f; + private val HASHSIZE = 0x80 + private val HASHMASK = 0x7f /** the threshold number of entries from which a hashtable is constructed. */ - private val MIN_HASH = 8; + private val MIN_HASH = 8 - if (size >= MIN_HASH) createHash; + if (size >= MIN_HASH) createHash - def this() = this(null: ScopeEntry); + def this() = this(null: ScopeEntry) def this(base: Scope) = { - this(base.elems); + this(base.elems) /* if (base.hashtable != null) { - this.hashtable = new Array[ScopeEntry](HASHSIZE); - System.arraycopy(base.hashtable, 0, this.hashtable, 0, HASHSIZE); + this.hashtable = new Array[ScopeEntry](HASHSIZE) + System.arraycopy(base.hashtable, 0, this.hashtable, 0, HASHSIZE) } */ nestinglevel = base.nestinglevel + 1 } def this(decls: List[Symbol]) = { - this(); + this() decls foreach enter } /** Returns a new scope with the same content as this one. */ def cloneScope: Scope = { - val clone = new Scope(); - this.toList foreach clone.enter; + val clone = new Scope() + this.toList foreach clone.enter clone } /** is the scope empty? */ - def isEmpty: boolean = elems == null; + def isEmpty: boolean = elems == null /** the number of entries in this scope */ def size: int = { - var s = 0; - var e = elems; + var s = 0 + var e = elems while (e != null) { - s = s + 1; + s = s + 1 e = e.next } s @@ -100,58 +101,57 @@ trait Scopes requires SymbolTable { /** enter a scope entry */ def enter(e: ScopeEntry): unit = { - elemsCache = null; + elemsCache = null if (hashtable != null) { - val i = e.sym.name.start & HASHMASK; - elems.tail = hashtable(i); - hashtable(i) = elems; + val i = e.sym.name.start & HASHMASK + elems.tail = hashtable(i) + hashtable(i) = elems } else if (size >= MIN_HASH) { - createHash; + createHash } } /** enter a symbol */ - def enter(sym: Symbol): unit = enter(newScopeEntry(sym, this)); + def enter(sym: Symbol): unit = enter(newScopeEntry(sym, this)) /** enter a symbol, asserting that no symbol with same name exists in scope */ def enterUnique(sym: Symbol): unit = { - assert(lookup(sym.name) == NoSymbol); - enter(sym); + assert(lookup(sym.name) == NoSymbol) + enter(sym) } private def createHash: unit = { - hashtable = new Array[ScopeEntry](HASHSIZE); - enterInHash(elems); + hashtable = new Array[ScopeEntry](HASHSIZE) + enterInHash(elems) } - private def enterInHash(e: ScopeEntry): unit = { + private def enterInHash(e: ScopeEntry): unit = if (e != null) { - enterInHash(e.next); - val i = e.sym.name.start & HASHMASK; - e.tail = hashtable(i); - hashtable(i) = e; + enterInHash(e.next) + val i = e.sym.name.start & HASHMASK + e.tail = hashtable(i) + hashtable(i) = e } - } /** remove entry */ def unlink(e: ScopeEntry): unit = { if (elems == e) { - elems = e.next; + elems = e.next } else { - var e1 = elems; + var e1 = elems while (e1.next != e) e1 = e1.next; - e1.next = e.next; + e1.next = e.next } if (hashtable != null) { - var e1 = hashtable(e.sym.name.start & HASHMASK); + var e1 = hashtable(e.sym.name.start & HASHMASK) if (e1 == e) { - hashtable(e.sym.name.start & HASHMASK) = e.tail; + hashtable(e.sym.name.start & HASHMASK) = e.tail } else { while (e1.tail != e) e1 = e1.tail; - e1.tail = e.tail; + e1.tail = e.tail } } elemsCache = null @@ -159,7 +159,7 @@ trait Scopes requires SymbolTable { /** remove symbol */ def unlink(sym: Symbol): unit = { - var e = lookupEntry(sym.name); + var e = lookupEntry(sym.name) while (e != null) { if (e.sym == sym) unlink(e); e = lookupNextEntry(e) @@ -169,19 +169,19 @@ trait Scopes requires SymbolTable { /** lookup a symbol */ def lookup(name: Name): Symbol = { - val e = lookupEntry(name); - if (e == null) NoSymbol else e.sym; + val e = lookupEntry(name) + if (e == null) NoSymbol else e.sym } /** lookup a symbol entry matching given name */ def lookupEntry(name: Name): ScopeEntry = { - var e: ScopeEntry = null; + var e: ScopeEntry = null if (false & hashtable != null) { - e = hashtable(name.start & HASHMASK); + e = hashtable(name.start & HASHMASK) while (e != null && e.sym.name != name) e = e.tail; } else { - e = elems; + e = elems while (e != null && e.sym.name != name) e = e.next; } e @@ -189,7 +189,7 @@ trait Scopes requires SymbolTable { /** lookup next entry with same name as this one */ def lookupNextEntry(entry: ScopeEntry): ScopeEntry = { - var e = entry; + var e = entry if (hashtable != null) //debug do { e = e.tail } while (e != null && e.sym.name != entry.sym.name) else @@ -201,10 +201,10 @@ trait Scopes requires SymbolTable { */ def toList: List[Symbol] = { if (elemsCache == null) { - elemsCache = Nil; - var e = elems; + elemsCache = Nil + var e = elems while (e != null && e.owner == this) { - elemsCache = e.sym :: elemsCache; + elemsCache = e.sym :: elemsCache e = e.next } } @@ -213,38 +213,38 @@ trait Scopes requires SymbolTable { /** Return all symbols as an interator in the order they were entered in this scope. */ - def elements: Iterator[Symbol] = toList.elements; + def elements: Iterator[Symbol] = toList.elements def filter(p: Symbol => boolean): Scope = if (!(toList forall p)) new Scope(toList filter p) else this def mkString(start: String, sep: String, end: String) = - toList.map(.defString).mkString(start, sep, end); + toList.map(.defString).mkString(start, sep, end) - override def toString(): String = mkString("{\n ", ";\n ", "\n}"); + override def toString(): String = mkString("{\n ", ";\n ", "\n}") /** Return the nesting level of this scope, i.e. the number of times this scope * was nested in another */ - def nestingLevel = nestinglevel; + def nestingLevel = nestinglevel } /** The empty scope (immutable). */ object EmptyScope extends Scope { override def enter(e: ScopeEntry): unit = - throw new Error("EmptyScope.enter"); + throw new Error("EmptyScope.enter") } /** The error scope. */ class ErrorScope(owner: Symbol) extends Scope(null: ScopeEntry) { override def lookupEntry(name: Name): ScopeEntry = { - val e = super.lookupEntry(name); + val e = super.lookupEntry(name) if (e != NoSymbol) e else { enter(if (name.isTermName) owner.newErrorValue(name) - else owner.newErrorClass(name)); - super.lookupEntry(name); + else owner.newErrorClass(name)) + super.lookupEntry(name) } } } -- cgit v1.2.3