summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-05-16 21:09:12 +0000
committerPaul Phillips <paulp@improving.org>2011-05-16 21:09:12 +0000
commite75142424c32d5c01a9df334b33a1b6387ada4f8 (patch)
treeb31e7a688e619189c9b1ea4df5fec43c0a691546 /src
parent9bab5cc04e90f2544710dcc5851c2a1fc9589f9e (diff)
downloadscala-e75142424c32d5c01a9df334b33a1b6387ada4f8.tar.gz
scala-e75142424c32d5c01a9df334b33a1b6387ada4f8.tar.bz2
scala-e75142424c32d5c01a9df334b33a1b6387ada4f8.zip
Switched nsc.util to point to reflect.util, no ...
Switched nsc.util to point to reflect.util, no review.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/compiler/scala/tools/nsc/util/Chars.scala94
-rw-r--r--src/compiler/scala/tools/nsc/util/FlagsUtil.scala4
-rw-r--r--src/compiler/scala/tools/nsc/util/HashSet.scala107
-rw-r--r--src/compiler/scala/tools/nsc/util/Set.scala30
-rw-r--r--src/compiler/scala/tools/nsc/util/ShowPickled.scala4
-rw-r--r--src/compiler/scala/tools/nsc/util/Statistics.scala126
-rw-r--r--src/compiler/scala/tools/nsc/util/package.scala5
7 files changed, 16 insertions, 354 deletions
diff --git a/src/compiler/scala/tools/nsc/util/Chars.scala b/src/compiler/scala/tools/nsc/util/Chars.scala
index 297afb8b1a..e69de29bb2 100755
--- a/src/compiler/scala/tools/nsc/util/Chars.scala
+++ b/src/compiler/scala/tools/nsc/util/Chars.scala
@@ -1,94 +0,0 @@
-/* NSC -- new Scala compiler
- * Copyright 2006-2011 LAMP/EPFL
- * @author Martin Odersky
- */
-
-package scala.tools.nsc
-package util
-
-import annotation.{ tailrec, switch }
-import java.lang.{ Character => JCharacter }
-
-/** Contains constants and classifier methods for characters */
-trait Chars {
- // Be very careful touching these.
- // Apparently trivial changes to the way you write these constants
- // will cause Scanners.scala to go from a nice efficient switch to
- // a ghastly nested if statement which will bring the type checker
- // to its knees. See ticket #1456
- // Martin: (this should be verified now that the pattern rules have been redesigned).
- final val LF = '\u000A'
- final val FF = '\u000C'
- final val CR = '\u000D'
- final val SU = '\u001A'
-
- /** Convert a character digit to an Int according to given base,
- * -1 if no success */
- def digit2int(ch: Char, base: Int): Int = {
- if ('0' <= ch && ch <= '9' && ch < '0' + base)
- ch - '0'
- else if ('A' <= ch && ch < 'A' + base - 10)
- ch - 'A' + 10
- else if ('a' <= ch && ch < 'a' + base - 10)
- ch - 'a' + 10
- else
- -1
- }
-
- /** Convert a character to a backslash-u escape */
- def char2uescape(c: Char): String = {
- var rest = c.toInt
- val buf = new StringBuilder
- for (i <- 1 to 4) {
- buf ++= (rest % 16).toHexString
- rest = rest / 16
- }
- "\\u" + buf.toString.reverse
- }
-
- /** Is character a line break? */
- @inline def isLineBreakChar(c: Char) = (c: @switch) match {
- case LF|FF|CR|SU => true
- case _ => false
- }
-
- /** Is character a whitespace character (but not a new line)? */
- def isWhitespace(c: Char) =
- c == ' ' || c == '\t' || c == CR
-
- /** Can character form part of a doc comment variable $xxx? */
- def isVarPart(c: Char) =
- '0' <= c && c <= '9' || 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z'
-
- /** Can character start an alphanumeric Scala identifier? */
- def isIdentifierStart(c: Char): Boolean =
- (c == '_') || (c == '$') || Character.isUnicodeIdentifierStart(c)
-
- /** Can character form part of an alphanumeric Scala identifier? */
- def isIdentifierPart(c: Char) =
- (c == '$') || Character.isUnicodeIdentifierPart(c)
-
- /** Is character a math or other symbol in Unicode? */
- def isSpecial(c: Char) = {
- val chtp = Character.getType(c)
- chtp == Character.MATH_SYMBOL.toInt || chtp == Character.OTHER_SYMBOL.toInt
- }
-
- private final val otherLetters = Set[Char]('\u0024', '\u005F') // '$' and '_'
- private final val letterGroups = {
- import JCharacter._
- Set[Byte](LOWERCASE_LETTER, UPPERCASE_LETTER, OTHER_LETTER, TITLECASE_LETTER, LETTER_NUMBER)
- }
- def isScalaLetter(ch: Char) = letterGroups(JCharacter.getType(ch).toByte) || otherLetters(ch)
-
- /** Can character form part of a Scala operator name? */
- def isOperatorPart(c : Char) : Boolean = (c: @switch) match {
- case '~' | '!' | '@' | '#' | '%' |
- '^' | '*' | '+' | '-' | '<' |
- '>' | '?' | ':' | '=' | '&' |
- '|' | '/' | '\\' => true
- case c => isSpecial(c)
- }
-}
-
-object Chars extends Chars { } \ No newline at end of file
diff --git a/src/compiler/scala/tools/nsc/util/FlagsUtil.scala b/src/compiler/scala/tools/nsc/util/FlagsUtil.scala
index eb3e8eae28..c12a919054 100644
--- a/src/compiler/scala/tools/nsc/util/FlagsUtil.scala
+++ b/src/compiler/scala/tools/nsc/util/FlagsUtil.scala
@@ -213,7 +213,7 @@ class FlagsUtil(flagsObject: AnyRef) {
}
object FlagsUtil {
- import reflect.generic.ModifierFlags
+ import reflect.common.ModifierFlags
trait MarkModifiers extends FlagsUtil {
lazy val isModifiersFlag = classOf[ModifierFlags].getMethods map (_.getName) filter isFlagName toSet
@@ -230,7 +230,7 @@ object FlagsUtilCompiler extends FlagsUtil(symtab.Flags) with FlagsUtil.MarkModi
def main(args: Array[String]): Unit = reflectiveAnalyzeFlags()
}
-object FlagsUtilLibrary extends FlagsUtil(reflect.generic.Flags) with FlagsUtil.MarkModifiers {
+object FlagsUtilLibrary extends FlagsUtil(reflect.common.Flags) with FlagsUtil.MarkModifiers {
def main(args: Array[String]): Unit = reflectiveAnalyzeFlags()
}
diff --git a/src/compiler/scala/tools/nsc/util/HashSet.scala b/src/compiler/scala/tools/nsc/util/HashSet.scala
index a17321696a..e69de29bb2 100644
--- a/src/compiler/scala/tools/nsc/util/HashSet.scala
+++ b/src/compiler/scala/tools/nsc/util/HashSet.scala
@@ -1,107 +0,0 @@
-/* NSC -- new Scala compiler
- * Copyright 2005-2011 LAMP/EPFL
- * @author Martin Odersky
- */
-
-package scala.tools.nsc
-package util
-
-object HashSet {
- def apply[T >: Null <: AnyRef](): HashSet[T] = this(16)
- def apply[T >: Null <: AnyRef](label: String): HashSet[T] = this(label, 16)
- def apply[T >: Null <: AnyRef](initialCapacity: Int): HashSet[T] = this("No Label", initialCapacity)
- def apply[T >: Null <: AnyRef](label: String, initialCapacity: Int): HashSet[T] =
- new HashSet[T](label, initialCapacity)
-}
-
-class HashSet[T >: Null <: AnyRef](val label: String, initialCapacity: Int) extends Set[T] {
- private var used = 0
- private var table = new Array[AnyRef](initialCapacity)
- private def index(x: Int): Int = math.abs(x % table.length)
-
- def size: Int = used
- def clear() {
- used = 0
- table = new Array[AnyRef](initialCapacity)
- }
-
- def findEntryOrUpdate(x: T): T = {
- var h = index(x.##)
- var entry = table(h)
- while (entry ne null) {
- if (x == entry)
- return entry.asInstanceOf[T]
-
- h = index(h + 1)
- entry = table(h)
- }
- table(h) = x
- used += 1
- if (used > (table.length >> 2)) growTable()
- x
- }
-
- def findEntry(x: T): T = {
- var h = index(x.##)
- var entry = table(h)
- while ((entry ne null) && x != entry) {
- h = index(h + 1)
- entry = table(h)
- }
- entry.asInstanceOf[T]
- }
-
- def addEntry(x: T) {
- var h = index(x.##)
- var entry = table(h)
- while (entry ne null) {
- if (x == entry) return
- h = index(h + 1)
- entry = table(h)
- }
- table(h) = x
- used += 1
- if (used > (table.length >> 2)) growTable()
- }
- def addEntries(xs: TraversableOnce[T]) {
- xs foreach addEntry
- }
-
- def iterator = new Iterator[T] {
- private var i = 0
- def hasNext: Boolean = {
- while (i < table.length && (table(i) eq null)) i += 1
- i < table.length
- }
- def next: T =
- if (hasNext) { i += 1; table(i - 1).asInstanceOf[T] }
- else null
- }
-
- private def addOldEntry(x: T) {
- var h = index(x.##)
- var entry = table(h)
- while (entry ne null) {
- h = index(h + 1)
- entry = table(h)
- }
- table(h) = x
- }
-
- private def growTable() {
- val oldtable = table
- val growthFactor =
- if (table.length <= initialCapacity) 8
- else if (table.length <= (initialCapacity * 8)) 4
- else 2
-
- table = new Array[AnyRef](table.length * growthFactor)
- var i = 0
- while (i < oldtable.length) {
- val entry = oldtable(i)
- if (entry ne null) addOldEntry(entry.asInstanceOf[T])
- i += 1
- }
- }
- override def toString() = "HashSet %s(%d / %d)".format(label, used, table.length)
-}
diff --git a/src/compiler/scala/tools/nsc/util/Set.scala b/src/compiler/scala/tools/nsc/util/Set.scala
index 2bc2526b16..e69de29bb2 100644
--- a/src/compiler/scala/tools/nsc/util/Set.scala
+++ b/src/compiler/scala/tools/nsc/util/Set.scala
@@ -1,30 +0,0 @@
-/* NSC -- new Scala compiler
- * Copyright 2005-2011 LAMP/EPFL
- * @author Martin Odersky
- */
-
-package scala.tools.nsc
-package util
-
-/** A common class for lightweight sets.
- */
-abstract class Set[T <: AnyRef] {
-
- def findEntry(x: T): T
-
- def addEntry(x: T): Unit
-
- def iterator: Iterator[T]
-
- def foreach[U](f: T => U): Unit = iterator foreach f
-
- def apply(x: T): Boolean = contains(x)
-
- @deprecated("use `iterator' instead", "2.9.0") def elements = iterator
-
- def contains(x: T): Boolean =
- findEntry(x) ne null
-
- def toList = iterator.toList
-
-}
diff --git a/src/compiler/scala/tools/nsc/util/ShowPickled.scala b/src/compiler/scala/tools/nsc/util/ShowPickled.scala
index a8499fc6a7..4acd8629bb 100644
--- a/src/compiler/scala/tools/nsc/util/ShowPickled.scala
+++ b/src/compiler/scala/tools/nsc/util/ShowPickled.scala
@@ -13,8 +13,8 @@ import java.lang.Float.intBitsToFloat
import java.lang.Double.longBitsToDouble
import cmd.program.Simple
-import symtab.{ Flags, Names }
-import scala.reflect.generic.{ PickleBuffer, PickleFormat }
+import scala.reflect.common.{Flags, Names}
+import scala.reflect.common.pickling.{ PickleBuffer, PickleFormat }
import interpreter.ByteCode.scalaSigBytesForPath
object ShowPickled extends Names {
diff --git a/src/compiler/scala/tools/nsc/util/Statistics.scala b/src/compiler/scala/tools/nsc/util/Statistics.scala
index b6e61a4014..8ef7d443ad 100644
--- a/src/compiler/scala/tools/nsc/util/Statistics.scala
+++ b/src/compiler/scala/tools/nsc/util/Statistics.scala
@@ -6,131 +6,15 @@
package scala.tools.nsc
package util
-object Statistics {
+class Statistics extends scala.reflect.common.util.Statistics {
- private var _enabled = false
-
- def enabled = _enabled
- def enabled_=(cond: Boolean) = {
- if (cond && !_enabled) {
- val test = new Timer()
- val start = System.nanoTime()
- var total = 0L
- for (i <- 1 to 10000) {
- val time = System.nanoTime()
- total += System.nanoTime() - time
- }
- val total2 = System.nanoTime() - start
- println("Enabling statistics, measuring overhead = "+
- total/10000.0+"ns to "+total2/10000.0+"ns per timer")
- _enabled = true
- }
- }
-
- var phasesShown = List("parser", "typer", "erasure", "cleanup")
-
- def currentTime() =
- if (_enabled) System.nanoTime() else 0L
-
- private def showPercent(x: Double, base: Double) =
- if (base == 0) "" else " ("+"%2.1f".format(x / base * 100)+"%)"
-
- def incCounter(c: Counter) {
- if (_enabled) c.value += 1
- }
-
- def incCounter(c: Counter, delta: Int) {
- if (_enabled) c.value += delta
- }
-
- def startCounter(sc: SubCounter): IntPair =
- if (_enabled) sc.start() else null
-
- def stopCounter(sc: SubCounter, start: IntPair) {
- if (_enabled) sc.stop(start)
- }
-
- def startTimer(tm: Timer): LongPair =
- if (_enabled) tm.start() else null
-
- def stopTimer(tm: Timer, start: LongPair) {
- if (_enabled) tm.stop(start)
- }
-
- case class IntPair(x: Int, y: Int)
- case class LongPair(x: Long, y: Long)
-
- class Counter {
- var value: Int = 0
- override def toString = value.toString
- }
-
- class SubCounter(c: Counter) {
- var value: Int = 0
- def start(): IntPair =
- if (_enabled) IntPair(value, c.value) else null
- def stop(prev: IntPair) {
- if (_enabled) {
- val IntPair(value0, cvalue0) = prev
- value = value0 + c.value - cvalue0
- }
- }
- override def toString =
- value+showPercent(value, c.value)
- }
-
- class Timer {
- var nanos: Long = 0
- var timings = 0
- def start(): LongPair =
- if (_enabled) {
- timings += 1
- LongPair(nanos, System.nanoTime())
- } else null
- def stop(prev: LongPair) {
- if (_enabled) {
- val LongPair(nanos0, start) = prev
- nanos = nanos0 + System.nanoTime() - start
- timings += 1
- }
- }
- override def toString = (timings/2)+" spans, "+nanos.toString+"ns"
- }
-
- class ClassCounts extends scala.collection.mutable.HashMap[Class[_], Int] {
- override def default(key: Class[_]) = 0
- }
-
- var nodeByType = new ClassCounts
+ var nodeByType = new ClassCounts
var microsByType = new ClassCounts
var visitsByType = new ClassCounts
var pendingTreeTypes: List[Class[_]] = List()
var typerTime: Long = 0L
- val singletonBaseTypeSeqCount = new Counter
- val compoundBaseTypeSeqCount = new Counter
- val typerefBaseTypeSeqCount = new Counter
- val findMemberCount = new Counter
- val noMemberCount = new Counter
- val multMemberCount = new Counter
- val findMemberNanos = new Timer
- val asSeenFromCount = new Counter
- val asSeenFromNanos = new Timer
- val subtypeCount = new Counter
- val subtypeNanos = new Timer
- val sametypeCount = new Counter
- val rawTypeCount = new Counter
- val rawTypeFailed = new SubCounter(rawTypeCount)
- val findMemberFailed = new SubCounter(findMemberCount)
- val subtypeFailed = new SubCounter(subtypeCount)
- val rawTypeImpl = new SubCounter(rawTypeCount)
- val findMemberImpl = new SubCounter(findMemberCount)
- val subtypeImpl = new SubCounter(subtypeCount)
- val baseTypeSeqCount = new Counter
- val baseTypeSeqLenTotal = new Counter
- val typeSymbolCount = new Counter
- val classSymbolCount = new Counter
val typedApplyCount = new Counter
val typedIdentCount = new Counter
val typedSelectCount = new Counter
@@ -174,13 +58,17 @@ object Statistics {
val timer2: Timer = new Timer
}
-abstract class Statistics {
+object Statistics extends Statistics
+
+abstract class StatisticsInfo {
import Statistics._
val global: Global
import global._
+ var phasesShown = List("parser", "typer", "erasure", "cleanup")
+
def countNodes(tree: Tree, counts: ClassCounts) {
for (t <- tree) counts(t.getClass) += 1
counts
diff --git a/src/compiler/scala/tools/nsc/util/package.scala b/src/compiler/scala/tools/nsc/util/package.scala
index facac563d9..fb18adb630 100644
--- a/src/compiler/scala/tools/nsc/util/package.scala
+++ b/src/compiler/scala/tools/nsc/util/package.scala
@@ -8,6 +8,11 @@ package scala.tools.nsc
import java.io.{ OutputStream, PrintStream, ByteArrayOutputStream, PrintWriter, StringWriter }
package object util {
+
+ type Set[T <: AnyRef] = scala.reflect.common.util.Set[T]
+ type HashSet[T >: Null <: AnyRef] = scala.reflect.common.util.HashSet[T]
+ val HashSet = scala.reflect.common.util.HashSet
+
def onull[T](value: T, orElse: => T): T = if (value == null) orElse else value
/** Apply a function and return the passed value */