summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-06-02 20:01:35 +0000
committerPaul Phillips <paulp@improving.org>2009-06-02 20:01:35 +0000
commit02ec6b9c108283f3657f4d1c3f33827da573dc03 (patch)
tree848776fbfab137848805e4c9365f9e4178eaf779 /src/compiler
parenta431dc606a6aff37e3cbc3d425426a3d451ec3bf (diff)
downloadscala-02ec6b9c108283f3657f4d1c3f33827da573dc03.tar.gz
scala-02ec6b9c108283f3657f4d1c3f33827da573dc03.tar.bz2
scala-02ec6b9c108283f3657f4d1c3f33827da573dc03.zip
Moved NameTransformer from the compiler to the ...
Moved NameTransformer from the compiler to the library because I need access to the logic for reflection.
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/Interpreter.scala5
-rw-r--r--src/compiler/scala/tools/nsc/doc/ModelFrames.scala2
-rw-r--r--src/compiler/scala/tools/nsc/models/SemanticTokens.scala3
-rw-r--r--src/compiler/scala/tools/nsc/models/Signatures.scala3
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Names.scala2
-rw-r--r--src/compiler/scala/tools/nsc/symtab/StdNames.scala2
-rw-r--r--src/compiler/scala/tools/nsc/util/NameTransformer.scala147
7 files changed, 10 insertions, 154 deletions
diff --git a/src/compiler/scala/tools/nsc/Interpreter.scala b/src/compiler/scala/tools/nsc/Interpreter.scala
index 6173753c6d..1beeeb2529 100644
--- a/src/compiler/scala/tools/nsc/Interpreter.scala
+++ b/src/compiler/scala/tools/nsc/Interpreter.scala
@@ -21,7 +21,8 @@ import scala.util.control.Exception.{ Catcher, catching, ultimately, unwrapping
import io.{ PlainFile, VirtualDirectory }
import reporters.{ ConsoleReporter, Reporter }
import symtab.{ Flags, Names }
-import util.{ SourceFile, BatchSourceFile, ClassPath, NameTransformer }
+import util.{ SourceFile, BatchSourceFile, ClassPath }
+import scala.util.NameTransformer
import nsc.{ InterpreterResults => IR }
import nsc.interpreter._
import Interpreter._
@@ -857,7 +858,7 @@ class Interpreter(val settings: Settings, out: PrintWriter)
*/
def membersOfIdentifier(line: String): List[String] = {
import Completion.{ isValidCompletion }
- import scala.tools.nsc.util.NameTransformer.{ decode, encode } // e.g. $plus$plus => ++
+ import NameTransformer.{ decode, encode } // e.g. $plus$plus => ++
val res = beQuietDuring {
for (name <- nameOfIdent(line) ; req <- requestForName(name)) yield {
diff --git a/src/compiler/scala/tools/nsc/doc/ModelFrames.scala b/src/compiler/scala/tools/nsc/doc/ModelFrames.scala
index 5bda711f12..1f0453db6e 100644
--- a/src/compiler/scala/tools/nsc/doc/ModelFrames.scala
+++ b/src/compiler/scala/tools/nsc/doc/ModelFrames.scala
@@ -7,7 +7,7 @@
package scala.tools.nsc.doc
import java.io.{File, FileWriter}
-import util.NameTransformer
+import scala.util.NameTransformer
import scala.collection.mutable
import scala.compat.Platform.{EOL => LINE_SEPARATOR}
import scala.xml.{NodeSeq, Text, Unparsed, Utility}
diff --git a/src/compiler/scala/tools/nsc/models/SemanticTokens.scala b/src/compiler/scala/tools/nsc/models/SemanticTokens.scala
index 56e80cf5bf..58d69b9628 100644
--- a/src/compiler/scala/tools/nsc/models/SemanticTokens.scala
+++ b/src/compiler/scala/tools/nsc/models/SemanticTokens.scala
@@ -13,7 +13,8 @@ import scala.collection.mutable.{HashMap, HashSet}
import scala.tools.nsc.Global
import scala.tools.nsc.symtab.{Flags, Names}
import scala.tools.nsc.symtab.Flags.DEFERRED
-import scala.tools.nsc.util.{BatchSourceFile, NameTransformer, NoPosition, Position, SourceFile}
+import scala.tools.nsc.util.{BatchSourceFile, NoPosition, Position, SourceFile}
+import scala.util.NameTransformer
class SemanticTokens(val compiler: Global) {
import compiler._
diff --git a/src/compiler/scala/tools/nsc/models/Signatures.scala b/src/compiler/scala/tools/nsc/models/Signatures.scala
index a6e7391f2c..05fffe58e1 100644
--- a/src/compiler/scala/tools/nsc/models/Signatures.scala
+++ b/src/compiler/scala/tools/nsc/models/Signatures.scala
@@ -9,7 +9,8 @@ package scala.tools.nsc.models
import scala.collection.mutable.{HashMap, HashSet}
import scala.tools.nsc.{Global => Compiler}
import scala.tools.nsc.symtab.{Flags, Names}
-import scala.tools.nsc.util.{NameTransformer, Position, SourceFile}
+import scala.tools.nsc.util.{ Position, SourceFile }
+import scala.util.NameTransformer
/** This class ...
*
diff --git a/src/compiler/scala/tools/nsc/symtab/Names.scala b/src/compiler/scala/tools/nsc/symtab/Names.scala
index 492198e081..70612c2a85 100644
--- a/src/compiler/scala/tools/nsc/symtab/Names.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Names.scala
@@ -6,7 +6,7 @@
package scala.tools.nsc.symtab
-import scala.tools.nsc.util.NameTransformer
+import scala.util.NameTransformer
import scala.io.UTF8Codec
import java.security.MessageDigest
diff --git a/src/compiler/scala/tools/nsc/symtab/StdNames.scala b/src/compiler/scala/tools/nsc/symtab/StdNames.scala
index b97f55f9b3..ae2f3a39c7 100644
--- a/src/compiler/scala/tools/nsc/symtab/StdNames.scala
+++ b/src/compiler/scala/tools/nsc/symtab/StdNames.scala
@@ -6,7 +6,7 @@
package scala.tools.nsc.symtab
-import scala.tools.nsc.util.NameTransformer
+import scala.util.NameTransformer
trait StdNames {
self: SymbolTable =>
diff --git a/src/compiler/scala/tools/nsc/util/NameTransformer.scala b/src/compiler/scala/tools/nsc/util/NameTransformer.scala
deleted file mode 100644
index 0292e1c68a..0000000000
--- a/src/compiler/scala/tools/nsc/util/NameTransformer.scala
+++ /dev/null
@@ -1,147 +0,0 @@
-/* NSC -- new Scala compiler
- * Copyright 2005-2009 LAMP/EPFL
- * @author Martin Odersky
- */
-// $Id$
-
-package scala.tools.nsc.util
-
-object NameTransformer {
- private val nops = 128
- private val ncodes = 26 * 26
-
- private class OpCodes(val op: Char, val code: String, val next: OpCodes)
-
- private val op2code = new Array[String](nops)
- private val code2op = new Array[OpCodes](ncodes)
-
- private def enterOp(op: Char, code: String) = {
- op2code(op) = code
- val c = (code.charAt(1) - 'a') * 26 + code.charAt(2) - 'a'
- code2op(c) = new OpCodes(op, code, code2op(c))
- }
-
- /* Note: decoding assumes opcodes are only ever lowercase. */
- enterOp('~', "$tilde")
- enterOp('=', "$eq")
- enterOp('<', "$less")
- enterOp('>', "$greater")
- enterOp('!', "$bang")
- enterOp('#', "$hash")
- enterOp('%', "$percent")
- enterOp('^', "$up")
- enterOp('&', "$amp")
- enterOp('|', "$bar")
- enterOp('*', "$times")
- enterOp('/', "$div")
- enterOp('+', "$plus")
- enterOp('-', "$minus")
- enterOp(':', "$colon")
- enterOp('\\', "$bslash")
- enterOp('?', "$qmark")
- enterOp('@', "$at")
-
- /** Replace operator symbols by corresponding "<code>$op_name</code>".
- *
- * @param name ...
- * @return ...
- */
- def encode(name: String): String = {
- var buf: StringBuilder = null
- val len = name.length()
- var i = 0
- while (i < len) {
- val c = name charAt i
- if (c < nops && (op2code(c) ne null)) {
- if (buf eq null) {
- buf = new StringBuilder()
- buf.append(name.substring(0, i))
- }
- buf.append(op2code(c))
- /* Handle glyphs that are not valid Java/JVM identifiers */
- }
- else if (!Character.isJavaIdentifierPart(c)) {
- if (buf eq null) {
- buf = new StringBuilder()
- buf.append(name.substring(0, i))
- }
- buf.append("$u%04X".format(c.toInt))
- }
- else if (buf ne null) {
- buf.append(c)
- }
- i += 1
- }
- if (buf eq null) name else buf.toString()
- }
-
- /** Replace <code>$op_name</code> by corresponding operator symbol.
- *
- * @param name0 ...
- * @return ...
- */
- def decode(name0: String): String = {
- //System.out.println("decode: " + name);//DEBUG
- val name = if (name0.endsWith("<init>")) name0.substring(0, name0.length() - ("<init>").length()) + "this"
- else name0;
- var buf: StringBuilder = null
- val len = name.length()
- var i = 0
- while (i < len) {
- var ops: OpCodes = null
- var unicode = false
- val c = name charAt i
- if (c == '$' && i + 2 < len) {
- val ch1 = name.charAt(i+1)
- if ('a' <= ch1 && ch1 <= 'z') {
- val ch2 = name.charAt(i+2)
- if ('a' <= ch2 && ch2 <= 'z') {
- ops = code2op((ch1 - 'a') * 26 + ch2 - 'a')
- while ((ops ne null) && !name.startsWith(ops.code, i)) ops = ops.next
- if (ops ne null) {
- if (buf eq null) {
- buf = new StringBuilder()
- buf.append(name.substring(0, i))
- }
- buf.append(ops.op)
- i += ops.code.length()
- }
- /* Handle the decoding of Unicode glyphs that are
- * not valid Java/JVM identifiers */
- } else if ((len - i) >= 6 && // Check that there are enough characters left
- ch1 == 'u' &&
- ((Character.isDigit(ch2)) ||
- ('A' <= ch2 && ch2 <= 'F'))) {
- /* Skip past "$u", next four should be hexadecimal */
- val hex = name.substring(i+2, i+6)
- try {
- val str = Integer.parseInt(hex, 16).toChar
- if (buf eq null) {
- buf = new StringBuilder()
- buf.append(name.substring(0, i))
- }
- buf.append(str)
- /* 2 for "$u", 4 for hexadecimal number */
- i += 6
- unicode = true
- } catch {
- case _:NumberFormatException =>
- /* <code>hex</code> did not decode to a hexadecimal number, so
- * do nothing. */
- }
- }
- }
- }
- /* If we didn't see an opcode or encoded Unicode glyph, and the
- buffer is non-empty, write the current character and advance
- one */
- if ((ops eq null) && !unicode) {
- if (buf ne null)
- buf.append(c)
- i += 1
- }
- }
- //System.out.println("= " + (if (buf == null) name else buf.toString()));//DEBUG
- if (buf eq null) name else buf.toString()
- }
-}