summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorGilles Dubochet <gilles.dubochet@epfl.ch>2005-12-18 18:25:04 +0000
committerGilles Dubochet <gilles.dubochet@epfl.ch>2005-12-18 18:25:04 +0000
commit0e82079908655682e5140ad521cef0572cb6d2a4 (patch)
treeca0f7e94ca15642ce44171db397e8457d04d4040 /sources
parent7afcf99c5acf461fad579194467cce580febdf7c (diff)
downloadscala-0e82079908655682e5140ad521cef0572cb6d2a4.tar.gz
scala-0e82079908655682e5140ad521cef0572cb6d2a4.tar.bz2
scala-0e82079908655682e5140ad521cef0572cb6d2a4.zip
Moved Scalap and Scalatest to their own modules.
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/tools/scalap/Arguments.scala200
-rw-r--r--sources/scala/tools/scalap/ByteArrayReader.scala155
-rw-r--r--sources/scala/tools/scalap/Classfile.scala125
-rw-r--r--sources/scala/tools/scalap/Classfiles.scala55
-rw-r--r--sources/scala/tools/scalap/CodeWriter.scala139
-rw-r--r--sources/scala/tools/scalap/Entity.scala168
-rw-r--r--sources/scala/tools/scalap/EntityTable.scala176
-rw-r--r--sources/scala/tools/scalap/Flags.scala81
-rw-r--r--sources/scala/tools/scalap/JavaWriter.scala232
-rw-r--r--sources/scala/tools/scalap/Main.scala163
-rw-r--r--sources/scala/tools/scalap/MetaParser.scala193
-rw-r--r--sources/scala/tools/scalap/Names.scala95
-rw-r--r--sources/scala/tools/scalap/ScalaAttribute.scala167
-rw-r--r--sources/scala/tools/scalap/ScalaWriter.scala301
-rw-r--r--sources/scala/tools/scalatest/Command.java105
-rw-r--r--sources/scala/tools/scalatest/Console.java170
-rw-r--r--sources/scala/tools/scalatest/Diff.java894
-rw-r--r--sources/scala/tools/scalatest/Diff.txt16
-rw-r--r--sources/scala/tools/scalatest/DiffPrint.java578
-rw-r--r--sources/scala/tools/scalatest/FileUtils.java91
-rw-r--r--sources/scala/tools/scalatest/Main.java673
-rw-r--r--sources/scala/tools/scalatest/Test.java54
22 files changed, 0 insertions, 4831 deletions
diff --git a/sources/scala/tools/scalap/Arguments.scala b/sources/scala/tools/scalap/Arguments.scala
deleted file mode 100644
index bc579ee850..0000000000
--- a/sources/scala/tools/scalap/Arguments.scala
+++ /dev/null
@@ -1,200 +0,0 @@
-/* ___ ____ ___ __ ___ ___
-** / _// __// _ | / / / _ | / _ \ Scala classfile decoder
-** __\ \/ /__/ __ |/ /__/ __ |/ ___/ (c) 2003, LAMP/EPFL
-** /____/\___/_/ |_/____/_/ |_/_/
-**
-** $Id$
-*/
-
-package scala.tools.scalap;
-
-import scala.collection.mutable._;
-
-
-object Arguments {
-
- case class Parser(optionPrefix: Char) {
-
- val options: Set[String] = new HashSet;
- val prefixes: Set[String] = new HashSet;
- val optionalArgs: Set[String] = new HashSet;
- val prefixedBindings: Map[String, Char] = new HashMap;
- val optionalBindings: Map[String, Char] = new HashMap;
-
- def error(message: String): Unit = Console.println(message);
-
- def withOption(option: String): Parser = {
- options += option;
- this
- }
-
- def withOptionalArg(option: String): Parser = {
- optionalArgs += option;
- this
- }
-
- def withOptionalBinding(option: String, separator: Char): Parser = {
- optionalBindings(option) = separator;
- this
- }
-
- def withPrefixedArg(prefix: String): Parser = {
- prefixes += prefix;
- this
- }
-
- def withPrefixedBinding(prefix: String, separator: Char): Parser = {
- prefixedBindings(prefix) = separator;
- this
- }
-
- def parseBinding(str: String, separator: Char): Pair[String, String] = {
- val eqls = str.indexOf(separator);
- if (eqls < 0) {
- error("missing '" + separator + "' in binding '" + str + "'");
- Pair("", "")
- } else
- Pair(str.substring(0, eqls).trim(),
- str.substring(eqls + 1).trim());
- }
-
- def parse(args: Array[String]): Arguments = {
- val res = new Arguments;
- parse(args, res);
- res
- }
-
- def parse(args: Array[String], res: Arguments): Unit = {
- if (args != null) {
- var i = 0;
- while (i < args.length)
- if ((args(i) == null) || (args(i).length() == 0))
- i = i + 1;
- else if (args(i).charAt(0) != optionPrefix) {
- res.addOther(args(i));
- i = i + 1;
- } else if (options contains args(i)) {
- res.addOption(args(i));
- i = i + 1;
- } else if (optionalArgs contains args(i)) {
- if ((i + 1) == args.length) {
- error("missing argument for '" + args(i) + "'");
- i = i + 1;
- } else {
- res.addArgument(args(i), args(i + 1));
- i = i + 2;
- }
- } else if (optionalBindings contains args(i)) {
- if ((i + 1) == args.length) {
- error("missing argument for '" + args(i) + "'");
- i = i + 1;
- } else {
- res.addBinding(args(i),
- parseBinding(args(i + 1), optionalBindings(args(i))));
- i = i + 2;
- }
- } else {
- var iter = prefixes.elements;
- val j = i;
- while ((i == j) && iter.hasNext) {
- val prefix = iter.next;
- if (args(i) startsWith prefix) {
- res.addPrefixed(prefix, args(i).substring(prefix.length()).trim());
- i = i + 1;
- }
- }
- if (i == j) {
- val iter = prefixedBindings.keys;
- while ((i == j) && iter.hasNext) {
- val prefix = iter.next;
- if (args(i) startsWith prefix) {
- val arg = args(i).substring(prefix.length()).trim();
- i = i + 1;
- res.addBinding(prefix,
- parseBinding(arg, prefixedBindings(prefix)));
- }
- }
- if (i == j) {
- error("unknown option '" + args(i) + "'");
- i = i + 1;
- }
- }
- }
- }
- }
- }
-
- def parse(options: String*)(args: Array[String]): Arguments = {
- val parser = new Parser('-');
- val iter = options.elements;
- while (iter.hasNext)
- parser withOption iter.next;
- parser.parse(args)
- }
-}
-
-class Arguments {
-
- private val options: Set[String] = new HashSet;
- private val arguments: Map[String, String] = new HashMap;
- private val prefixes: Map[String, Set[String]] = new HashMap;
- private val bindings: Map[String, Map[String, String]] = new HashMap;
- private val others: Buffer[String] = new ListBuffer;
-
- def addOption(option: String): Unit = options += option;
-
- def addArgument(option: String, arg: String): Unit = arguments(option) = arg;
-
- def addPrefixed(prefix: String, arg: String): Unit =
- if (prefixes isDefinedAt prefix)
- prefixes(prefix) += arg;
- else {
- prefixes(prefix) = new HashSet;
- prefixes(prefix) += arg;
- };
-
- def addBinding(tag: String, key: String, value: String): Unit =
- if (key.length() > 0) {
- if (bindings isDefinedAt tag)
- bindings(tag)(key) = value;
- else {
- bindings(tag) = new HashMap;
- bindings(tag)(key) = value;
- }
- };
-
- def addBinding(tag: String, binding: Pair[String, String]): Unit =
- addBinding(tag, binding._1, binding._2);
-
- def addOther(arg: String): Unit = others += arg;
-
- def contains(option: String): Boolean = options contains option;
-
- def getArgument(option: String): Option[String] = arguments get option;
-
- def getSuffixes(prefix: String): Set[String] =
- prefixes.get(prefix) match {
- case None => new HashSet;
- case Some(set) => set
- }
-
- def containsSuffix(prefix: String, suffix: String): Boolean =
- prefixes.get(prefix) match {
- case None => false
- case Some(set) => set contains suffix
- };
-
- def getBindings(tag: String): Map[String, String] =
- bindings.get(tag) match {
- case None => new HashMap;
- case Some(map) => map
- }
-
- def getBinding(option: String, key: String): Option[String] =
- bindings.get(option) match {
- case None => None
- case Some(map) => map get key
- };
-
- def getOthers: List[String] = others.toList;
-}
diff --git a/sources/scala/tools/scalap/ByteArrayReader.scala b/sources/scala/tools/scalap/ByteArrayReader.scala
deleted file mode 100644
index 5a88a2333b..0000000000
--- a/sources/scala/tools/scalap/ByteArrayReader.scala
+++ /dev/null
@@ -1,155 +0,0 @@
-/* ___ ____ ___ __ ___ ___
-** / _// __// _ | / / / _ | / _ \ Scala classfile decoder
-** __\ \/ /__/ __ |/ /__/ __ |/ ___/ (c) 2003, LAMP/EPFL
-** /____/\___/_/ |_/____/_/ |_/_/
-**
-** $Id$
-*/
-
-package scala.tools.scalap;
-
-
-class ByteArrayReader(content: Array[Byte]) {
- import java.io._;
-
- /** the buffer containing the file
- */
- val buf: Array[Byte] = content;
-
- /** the current input pointer
- */
- var bp: Int = 0;
-
- /** return byte at offset 'pos'
- */
- def byteAt(pos: Int): Byte = buf(pos);
-
- /** read a byte
- */
- def nextByte: Byte = {
- bp = bp + 1;
- buf(bp - 1)
- }
-
- /** read some bytes
- */
- def nextBytes(len: Int): Array[Byte] = {
- val res = new Array[Byte](len);
- System.arraycopy(buf, bp, res, 0, len);
- bp = bp + len;
- res
- }
-
- /** read a character
- */
- def nextChar: Char = {
- bp = bp + 2;
- (((buf(bp - 2) & 0xff) << 8) + (buf(bp - 1) & 0xff)).asInstanceOf[Char];
- }
-
- /** read an integer
- */
- def nextInt: Int = {
- bp = bp + 4;
- ((buf(bp - 4) & 0xff) << 24) +
- ((buf(bp - 3) & 0xff) << 16) +
- ((buf(bp - 2) & 0xff) << 8) +
- (buf(bp - 1) & 0xff);
- }
-
- /** read a long
- */
- def nextLong: Long =
- (nextInt.asInstanceOf[Long] << 32) + (nextInt.asInstanceOf[Long] & 0xffffffffL);
-
- /** read a float
- */
- def nextFloat: Float = java.lang.Float.intBitsToFloat(nextInt);
-
- /** read a double
- */
- def nextDouble: Double = java.lang.Double.longBitsToDouble(nextLong);
-
- /** read the next integer number
- */
- def nextNat: Int = {
- var x = 0;
- var b: Byte = 0;
- do {
- b = buf(bp);
- bp = bp + 1;
- x = (x << 7) + (b & 0x7f);
- } while ((b & 0x80) != 0);
- x
- }
-
- /** read the next signed number in big endian format
- */
- def nextNum(n: Int): Long = {
- var x: Long = 0;
- var i: Int = 0;
- while (i < n) {
- x = (x << 8) + (nextByte & 0xff);
- i = i + 1;
- }
- val leading: Int = 64 - (n * 8);
- x << leading >> leading;
- }
-
- /** read an UTF8 encoded string
- */
- def nextUTF8(len: Int): String = {
- val cs: Array[Char] = new Array(len);
- var i = bp;
- var j = 0;
- bp = bp + len;
- while (i < bp) {
- var b: Int = buf(i) & 0xFF;
- i = i + 1;
- if (b >= 0xE0) {
- b = ((b & 0x0F) << 12) | (buf(i) & 0x3F) << 6;
- i = i + 1;
- b = b | (buf(i) & 0x3F);
- i = i + 1;
- } else if (b >= 0xC0) {
- b = ((b & 0x1F) << 6) | (buf(i) & 0x3F);
- i = i + 1;
- }
- cs(j) = b.asInstanceOf[Char];
- j = j + 1;
- }
- new String(cs, 0, j)
- }
-
- /** extract a character at position bp from buf
- */
- def getChar(bp: Int): Char =
- (((buf(bp) & 0xff) << 8) + (buf(bp + 1) & 0xff)).asInstanceOf[Char];
-
- /** extract an integer at position bp from buf
- */
- def getInt(bp: Int): Int =
- ((buf(bp ) & 0xff) << 24) +
- ((buf(bp + 1) & 0xff) << 16) +
- ((buf(bp + 2) & 0xff) << 8) +
- (buf(bp + 3) & 0xff);
-
- /** extract a long integer at position bp from buf
- */
- def getLong(bp: Int): Long =
- (getInt(bp).asInstanceOf[Long] << 32) + (getInt(bp + 4).asInstanceOf[Long] & 0xffffffffL);
-
- /** extract a float at position bp from buf
- */
- def getFloat(bp: Int): Float = java.lang.Float.intBitsToFloat(getInt(bp));
-
- /** extract a double at position bp from buf
- */
- def getDouble(bp: Int): Double = java.lang.Double.longBitsToDouble(getLong(bp));
-
- /** skip next 'n' bytes
- */
- def skip(n: Int): Unit = {
- bp = bp + n;
- }
-}
diff --git a/sources/scala/tools/scalap/Classfile.scala b/sources/scala/tools/scalap/Classfile.scala
deleted file mode 100644
index 9bb5ae672c..0000000000
--- a/sources/scala/tools/scalap/Classfile.scala
+++ /dev/null
@@ -1,125 +0,0 @@
-/* ___ ____ ___ __ ___ ___
-** / _// __// _ | / / / _ | / _ \ Scala classfile decoder
-** __\ \/ /__/ __ |/ /__/ __ |/ ___/ (c) 2003, LAMP/EPFL
-** /____/\___/_/ |_/____/_/ |_/_/
-**
-** $Id$
-*/
-
-package scala.tools.scalap;
-
-
-class Classfile(in: ByteArrayReader) {
- import Classfiles._;
-
- assert(in.nextInt == JAVA_MAGIC);
- val minorVersion = in.nextChar;
- val majorVersion = in.nextChar;
- val pool = readPool;
- val flags = in.nextChar;
- val classname = in.nextChar;
- val superclass = in.nextChar;
- val interfaces = readInterfaces;
- val fields = readMembers(true);
- val methods = readMembers(false);
- val attribs = readAttribs;
-
- def readAttribs = {
- val n = in.nextChar;
- var attribs: List[Attribute] = Nil;
- var i = 0;
- while (i < n) {
- attribs = Attribute(in.nextChar, in.nextBytes(in.nextInt)) :: attribs;
- i = i + 1;
- }
- attribs
- }
-
- def readMembers(field: Boolean) = {
- val n = in.nextChar;
- var members: List[Member] = Nil;
- var i = 0;
- while (i < n) {
- members = Member(field, in.nextChar, in.nextChar, in.nextChar, readAttribs) :: members;
- i = i + 1;
- }
- members
- }
-
- def readInterfaces = {
- val n = in.nextChar;
- var intfs: List[Int] = Nil;
- var i = 0;
- while (i < n) {
- intfs = in.nextChar :: intfs;
- i = i + 1;
- }
- intfs
- }
-
- def readPool = {
- val pool = new Array[PoolEntry](in.nextChar);
- var i = 1;
- while (i < pool.length) {
- val tag: Int = in.nextByte;
- tag match {
- case CONSTANT_UTF8 =>
- pool(i) = UTF8(in.nextUTF8(in.nextChar));
- case CONSTANT_UNICODE =>
- in.skip(in.nextChar);
- pool(i) = Empty();
- case CONSTANT_CLASS =>
- pool(i) = ClassRef(in.nextChar);
- case CONSTANT_STRING =>
- pool(i) = StringConst(in.nextChar);
- case CONSTANT_FIELDREF =>
- pool(i) = FieldRef(in.nextChar, in.nextChar);
- case CONSTANT_METHODREF =>
- pool(i) = MethodRef(in.nextChar, in.nextChar);
- case CONSTANT_INTFMETHODREF =>
- pool(i) = IntfMethodRef(in.nextChar, in.nextChar);
- case CONSTANT_NAMEANDTYPE =>
- pool(i) = NameAndType(in.nextChar, in.nextChar);
- case CONSTANT_INTEGER =>
- pool(i) = IntegerConst(in.nextInt);
- case CONSTANT_FLOAT =>
- pool(i) = FloatConst(in.nextFloat);
- case CONSTANT_LONG =>
- pool(i) = LongConst(in.nextLong);
- i = i + 1;
- pool(i) = Empty();
- case CONSTANT_DOUBLE =>
- pool(i) = DoubleConst(in.nextDouble);
- i = i + 1;
- pool(i) = Empty();
- }
- i = i + 1;
- }
- pool
- }
-
- class PoolEntry;
- case class UTF8(str: String) extends PoolEntry;
- case class ClassRef(classId: Int) extends PoolEntry;
- case class FieldRef(classId: Int, memberId: Int) extends PoolEntry;
- case class MethodRef(classId: Int, memberId: Int) extends PoolEntry;
- case class IntfMethodRef(classId: Int, memberId: Int) extends PoolEntry;
- case class StringConst(strId: Int) extends PoolEntry;
- case class IntegerConst(x: Int) extends PoolEntry;
- case class FloatConst(x: Float) extends PoolEntry;
- case class LongConst(x: Long) extends PoolEntry;
- case class DoubleConst(x: Double) extends PoolEntry;
- case class NameAndType(nameId: Int, typeId: Int) extends PoolEntry;
- case class Empty() extends PoolEntry;
-
- case class Member(field: Boolean, flags: Int, name: Int, tpe: Int, attribs: List[Attribute]);
- case class Attribute(name: Int, data: Array[Byte]) {
-
- override def toString(): String = pool(name) match {
- case UTF8(str: String) => str
- }
-
- def reader: ByteArrayReader = new ByteArrayReader(data);
- }
-
-}
diff --git a/sources/scala/tools/scalap/Classfiles.scala b/sources/scala/tools/scalap/Classfiles.scala
deleted file mode 100644
index 20f4f8f72a..0000000000
--- a/sources/scala/tools/scalap/Classfiles.scala
+++ /dev/null
@@ -1,55 +0,0 @@
-/* ___ ____ ___ __ ___ ___
-** / _// __// _ | / / / _ | / _ \ Scala classfile decoder
-** __\ \/ /__/ __ |/ /__/ __ |/ ___/ (c) 2003, LAMP/EPFL
-** /____/\___/_/ |_/____/_/ |_/_/
-**
-** $Id$
-*/
-
-package scala.tools.scalap;
-
-
-object Classfiles {
- final val JAVA_MAGIC = 0xCAFEBABE;
- final val JAVA_MAJOR_VERSION = 45;
- final val JAVA_MINOR_VERSION = 3;
-
- final val CONSTANT_UTF8 = 1;
- final val CONSTANT_UNICODE = 2;
- final val CONSTANT_INTEGER = 3;
- final val CONSTANT_FLOAT = 4;
- final val CONSTANT_LONG = 5;
- final val CONSTANT_DOUBLE = 6;
- final val CONSTANT_CLASS = 7;
- final val CONSTANT_STRING = 8;
- final val CONSTANT_FIELDREF = 9;
- final val CONSTANT_METHODREF = 10;
- final val CONSTANT_INTFMETHODREF = 11;
- final val CONSTANT_NAMEANDTYPE = 12;
-
- final val BAD_ATTR = 0x00000;
- final val SOURCEFILE_ATTR = 0x00001;
- final val SYNTHETIC_ATTR = 0x00002;
- final val DEPRECATED_ATTR = 0x00004;
- final val CODE_ATTR = 0x00008;
- final val EXCEPTIONS_ATTR = 0x00010;
- final val CONSTANT_VALUE_ATTR = 0x00020;
- final val LINE_NUM_TABLE_ATTR = 0x00040;
- final val LOCAL_VAR_TABLE_ATTR = 0x00080;
- final val INNERCLASSES_ATTR = 0x08000;
- final val META_ATTR = 0x10000;
- final val SCALA_ATTR = 0x20000;
-
- final val SOURCEFILE_N = "SourceFile";
- final val SYNTHETIC_N = "Synthetic";
- final val DEPRECATED_N = "Deprecated";
- final val CODE_N = "Code";
- final val EXCEPTIONS_N = "Exceptions";
- final val CONSTANT_VALUE_N = "ConstantValue";
- final val LINE_NUM_TABLE_N = "LineNumberTable";
- final val LOCAL_VAR_TABLE_N = "LocalVariableTable";
- final val INNERCLASSES_N = "InnerClasses";
- final val META_N = "JacoMeta";
- final val SCALA_N = "ScalaSignature";
- final val CONSTR_N = "<init>";
-}
diff --git a/sources/scala/tools/scalap/CodeWriter.scala b/sources/scala/tools/scalap/CodeWriter.scala
deleted file mode 100644
index c529678886..0000000000
--- a/sources/scala/tools/scalap/CodeWriter.scala
+++ /dev/null
@@ -1,139 +0,0 @@
-/* ___ ____ ___ __ ___ ___
-** / _// __// _ | / / / _ | / _ \ Scala classfile decoder
-** __\ \/ /__/ __ |/ /__/ __ |/ ___/ (c) 2003, LAMP/EPFL
-** /____/\___/_/ |_/____/_/ |_/_/
-**
-** $Id$
-*/
-
-package scala.tools.scalap;
-
-import java.io._;
-
-
-class CodeWriter(writer: Writer) {
-
- private val nl = System.getProperty("line.separator");
- private var step = " ";
- private var level = 0;
- private var align = false;
- private var space = false;
- private var line = false;
-
- def getWriter = writer;
-
- def getIndentLevel = level;
-
- def setIndentLevel(level: Int): CodeWriter = {
- this.level = level;
- this
- }
-
- def getIndentWidth = if (step == null) -1 else step.length();
-
- def setIndentWidth(width: Int): CodeWriter = {
- val buffer = new StringBuffer(width);
- var i = 0;
- while (i < width)
- buffer.append(' ');
- setIndentString(buffer.toString())
- }
-
- def getIndentString = step;
-
- def setIndentString(step: String): CodeWriter = {
- this.step = step;
- this
- }
-
- def indent: CodeWriter = {
- level = level + 1;
- this
- }
-
- def undent: CodeWriter = {
- level = level - 1;
- this
- }
-
- def newline: CodeWriter = {
- if (step == null)
- newspace;
- else if (!line) {
- try {
- writer.write(nl);
- } catch {
- case e => error("IO error")
- }
- line = align;
- align = true;
- space = false;
- this
- } else
- this
- }
-
- def newspace: CodeWriter = {
- space = !align;
- this
- }
-
- def * : Unit = {}
-
- def println: CodeWriter = newline;
-
- def println(value: Boolean): CodeWriter = print(value).newline;
-
- def println(value: Byte): CodeWriter = print(value).newline;
-
- def println(value: Short): CodeWriter = print(value).newline;
-
- def println(value: Char): CodeWriter = print(value).newline;
-
- def println(value: Int): CodeWriter = print(value).newline;
-
- def println(value: Long): CodeWriter = print(value).newline;
-
- def println(value: Float): CodeWriter = print(value).newline;
-
- def println(value: Double): CodeWriter = print(value).newline;
-
- def println(value: String): CodeWriter = print(value).newline;
-
- def print(value: Boolean): CodeWriter = print(String.valueOf(value));
-
- def print(value: Byte): CodeWriter = print(String.valueOf(value));
-
- def print(value: Short): CodeWriter = print(String.valueOf(value));
-
- def print(value: Char): CodeWriter = print(String.valueOf(value));
-
- def print(value: Int): CodeWriter = print(String.valueOf(value));
-
- def print(value: Long): CodeWriter = print(String.valueOf(value));
-
- def print(value: Float): CodeWriter = print(String.valueOf(value));
-
- def print(value: Double): CodeWriter = print(String.valueOf(value));
-
- def print(value: String): CodeWriter = try {
- if (align) {
- var i = 0;
- while (i < level) {
- writer.write(step);
- i = i + 1;
- }
- }
- if (space)
- writer.write(" ");
- writer.write(value);
- align = false;
- space = false;
- line = false;
- this
- } catch {
- case e => error("IO error")
- }
-
- override def toString(): String = writer.toString();
-}
diff --git a/sources/scala/tools/scalap/Entity.scala b/sources/scala/tools/scalap/Entity.scala
deleted file mode 100644
index 01e20f8b04..0000000000
--- a/sources/scala/tools/scalap/Entity.scala
+++ /dev/null
@@ -1,168 +0,0 @@
-/* ___ ____ ___ __ ___ ___
-** / _// __// _ | / / / _ | / _ \ Scala classfile decoder
-** __\ \/ /__/ __ |/ /__/ __ |/ ___/ (c) 2003, LAMP/EPFL
-** /____/\___/_/ |_/____/_/ |_/_/
-**
-** $Id$
-*/
-
-package scala.tools.scalap;
-
-import java.io._;
-import scala.collection.mutable._;
-
-
-/** Entities are either text, symbols, or types.
- */
-trait Entity {
- def isText: Boolean = false;
- def isType: Boolean = false;
- def isSymbol: Boolean = false;
- def isValue: Boolean = false;
- def toSource: String = toString();
-}
-
-/** Text refers to a single string.
- */
-case class Text(str: String) extends Entity {
- override def isText: Boolean = true;
- override def toString(): String = str;
-}
-
-/** Value refers to a constant.
- */
-class Value extends Entity {
- override def isValue: Boolean = true;
-}
-
-case class SimpleValue(tag: Value.Value) extends Value {
- import Value._;
- override def toString(): String = tag match {
- case UNIT => "()"
- case NULL => "null"
- case ZERO => "0"
- }
-}
-
-case class NumberValue(tag: Value.Value, value: Long) extends Value {
- import Value._;
- override def toString(): String = tag match {
- case BOOLEAN => if (value == 0) "false" else "true"
- case BYTE | SHORT | CHAR | INT | LONG => value.toString()
- case FLOAT => java.lang.Float.intBitsToFloat(value.asInstanceOf[Int]).toString()
- case DOUBLE => java.lang.Double.longBitsToDouble(value).toString()
- }
-}
-
-case class StringValue(str: String) extends Value {
- override def toString(): String = "\"" + str + "\"";
-}
-
-object Value extends Enumeration {
- val UNIT, BOOLEAN, BYTE, SHORT, CHAR, INT, LONG, FLOAT, DOUBLE,
- NULL, ZERO = Value;
-}
-
-/** Types
- */
-trait Type extends Entity {
- override def isType: Boolean = true;
- override def toSource: String = {
- val writer = new ScalaWriter(null, new StringWriter());
- writer.setIndentString(null)*;
- writer.printType(this);
- writer.toString()
- }
-}
-
-case object NoType extends Type;
-
-case class ThisType(sym: Symbol) extends Type;
-
-case class SingletonType(tpe: Type, sym: Symbol) extends Type;
-
-case class TypeRef(tpe: Type, sym: Symbol, args: List[Type]) extends Type;
-
-case class CompoundType(clazz: Symbol, components: List[Type]) extends Type;
-
-case class MethodType(argtpe: List[Type], restpe: Type) extends Type;
-
-case class PolyType(tpe: Type, tvars: List[Symbol]) extends Type;
-
-case class OverloadedType(members: List[Symbol], tpes: List[Type]) extends Type;
-
-case class ConstantType(base: Type, value: Entity) extends Type;
-
-case class TypeFlag(tpe: Type, flags: Int) extends Type;
-
-/** Symbols
- */
-abstract case class Symbol(name: String, flags: Int) extends Entity {
- var tpe: Type = NoType;
- var owner: Symbol = NoSymbol;
- def fullname: String = owner match {
- case s: ClassSymbol => {
- val prefix = s.fullname;
- if (prefix.length() == 0) name else (prefix + "." + name)
- }
- case s: ExternalSymbol => {
- val prefix = s.fullname;
- if (prefix.length() == 0) name else (prefix + "." + name)
- }
- case _ => name
- }
- def fix(tpe: Type, owner: Symbol): Unit = {
- this.tpe = tpe;
- this.owner = owner;
- owner.enter(this);
- }
- override def isSymbol: Boolean = true;
- override def toString(): String = name;
- def fix(tpe: Type): Unit = {}
- def fix(sym: Symbol): Unit = {}
- def enter(sym: Symbol): Unit = {}
- def members: Buffer[Symbol] = error("symbol does not have members");
-}
-
-object NoSymbol extends Symbol("<nosymbol>", 0) {
- override def fix(tpe: Type, owner: Symbol): Unit = {}
-}
-
-class TypeSymbol(name: String, flags: Int) extends Symbol(name, flags) {
- var lower: Type = NoType;
- override def fix(tpe: Type): Unit = {
- lower = tpe;
- }
-}
-
-class AliasSymbol(name: String, flags: Int) extends Symbol(name, flags) {
- var constr: Symbol = NoSymbol;
- override def fix(sym: Symbol): Unit = {
- constr = sym;
- }
-}
-
-class ClassSymbol(name: String, flags: Int) extends Symbol(name, flags) {
- var thistpe: Type = NoType;
- var constr: Symbol = NoSymbol;
- var scope: Buffer[Symbol] = new ListBuffer;
- override def fix(tpe: Type): Unit = {
- thistpe = tpe;
- }
- override def fix(sym: Symbol): Unit = {
- constr = sym;
- }
- override def enter(sym: Symbol): Unit = scope.prepend(sym);
- override def members: Buffer[Symbol] = scope;
-}
-
-class ValSymbol(name: String, flags: Int) extends Symbol(name, flags) {
- var clazz: Symbol = NoSymbol;
- override def fix(sym: Symbol): Unit = {
- clazz = sym;
- }
-}
-
-class ExternalSymbol(name: String, mod: Boolean) extends Symbol(name, 0) {
- override def fix(sym: Symbol): Unit = { owner = sym; }
-}
diff --git a/sources/scala/tools/scalap/EntityTable.scala b/sources/scala/tools/scalap/EntityTable.scala
deleted file mode 100644
index 90bf758781..0000000000
--- a/sources/scala/tools/scalap/EntityTable.scala
+++ /dev/null
@@ -1,176 +0,0 @@
-/* ___ ____ ___ __ ___ ___
-** / _// __// _ | / / / _ | / _ \ Scala classfile decoder
-** __\ \/ /__/ __ |/ /__/ __ |/ ___/ (c) 2003, LAMP/EPFL
-** /____/\___/_/ |_/____/_/ |_/_/
-**
-** $Id$
-*/
-
-package scala.tools.scalap;
-
-import scala.collection.mutable._;
-
-
-class EntityTable(attrib: ScalaAttribute) {
- import attrib._;
-
- val table: Array[Entity] = new Array(attrib.table.length);
- var root: Buffer[Symbol] = new ListBuffer;
-
- {
- //Console.println("created table");
- var i = 0;
- while (i < attrib.table.length) {
- table(i) = attrib.table(i) match {
- case TermName(str) => Text(Names.decode(str));
- case TypeName(str) => Text(Names.decode(str));
- case Number(x) => NumberValue(Value.LONG, x);
- case _ => null;
- }
- i = i + 1;
- }
- //Console.println("decoded names");
- i = 0;
- var fixupIds: List[Int] = Nil;
- while (i < attrib.table.length) {
- table(i) = attrib.table(i) match {
- case NoneSym() =>
- NoSymbol
- case TypeSym(SymbolInfo(nameId, _, flags, _), _) =>
- fixupIds = i :: fixupIds;
- new TypeSymbol(getText(nameId), flags)
- case AliasSym(SymbolInfo(nameId, _, flags, _), _) =>
- fixupIds = i :: fixupIds;
- new AliasSymbol(getText(nameId), flags)
- case ClassSym(SymbolInfo(nameId, _, flags, _), _, _) =>
- fixupIds = i :: fixupIds;
- new ClassSymbol(getText(nameId), flags)
- case ValSym(SymbolInfo(nameId, _, flags, _), _) =>
- fixupIds = i :: fixupIds;
- new ValSymbol(getText(nameId), flags)
- case ExtRef(mod, nameId, _) =>
- fixupIds = i :: fixupIds;
- new ExternalSymbol(getText(nameId), mod)
- case Literal(UNIT_LIT, _) =>
- SimpleValue(Value.UNIT)
- case Literal(NULL_LIT, _) =>
- SimpleValue(Value.NULL)
- case Literal(ZERO_LIT, _) =>
- SimpleValue(Value.ZERO)
- case Literal(BOOL_LIT, data) =>
- NumberValue(Value.BOOLEAN, data)
- case Literal(BYTE_LIT, data) =>
- NumberValue(Value.BYTE, data)
- case Literal(SHORT_LIT, data) =>
- NumberValue(Value.SHORT, data)
- case Literal(CHAR_LIT, data) =>
- NumberValue(Value.CHAR, data)
- case Literal(INT_LIT, data) =>
- NumberValue(Value.INT, data)
- case Literal(LONG_LIT, data) =>
- NumberValue(Value.LONG, data)
- case Literal(FLOAT_LIT, data) =>
- NumberValue(Value.FLOAT, data)
- case Literal(DOUBLE_LIT, data) =>
- NumberValue(Value.DOUBLE, data)
- case Literal(STRING_LIT, data) =>
- StringValue(getText(data.asInstanceOf[Int]))
- case _ =>
- table(i)
- }
- i = i + 1;
- }
- //Console.println("created symbols");
- i = 0;
- while (i < attrib.table.length) {
- val x = getType(i);
- i = i + 1;
- }
- //Console.println("created types");
- def fix(i: Int, info: SymbolInfo): Symbol = {
- val sym = getSymbol(i);
- sym.fix(getType(info.info), getSymbol(info.owner));
- sym
- }
- fixupIds foreach {
- i => attrib.table(i) match {
- case TypeSym(info, loId) =>
- fix(i, info).fix(getType(loId));
- case AliasSym(info, constrId) =>
- fix(i, info).fix(getSymbol(constrId));
- case ClassSym(info, typeId, constrId) =>
- val sym = fix(i, info);
- sym.fix(getType(typeId));
- sym.fix(getSymbol(constrId));
- sym.owner match {
- case x: ExternalSymbol => root += sym;
- case _ =>
- }
- case ValSym(info, classId) =>
- fix(i, info).fix(getSymbol(classId));
- case ExtRef(_, _, ownerId) =>
- getSymbol(i).fix(getSymbol(ownerId));
- }
- }
- }
-
- def getText(i: Int): String = table(i) match {
- case Text(str) => str;
- }
-
- def getSymbol(i: Int): Symbol =
- if (i < 0) NoSymbol else table(i).asInstanceOf[Symbol];
-
- def getSymbols(is: List[Int]): List[Symbol] = is map getSymbol;
-
- def getType(i: Int): Type = {
- if (i < 0)
- NoType
- else if (table(i) != null) {
- if (table(i).isInstanceOf[Type])
- table(i).asInstanceOf[Type]
- else
- NoType
- } else {
- val res: Type = attrib.table(i) match {
- case NoneType() =>
- NoType
- case SelfType(symId) =>
- ThisType(getSymbol(symId))
- case SingleType(typeId, symId) =>
- SingletonType(getType(typeId), getSymbol(symId))
- case TypeReference(typeId, symId, argIds) =>
- TypeRef(getType(typeId), getSymbol(symId), getTypes(argIds))
- case CompoundTypeRef(symId, typeIds) =>
- CompoundType(getSymbol(symId), getTypes(typeIds))
- case MethodTypeRef(restypeId, argtypeIds) =>
- MethodType(getTypes(argtypeIds), getType(restypeId))
- case PolyTypeRef(typeId, symIds) =>
- PolyType(getType(typeId), getSymbols(symIds))
- case OverloadedTypeRef(ids) =>
- val Pair(symIds, typeIds) = ids partition {
- i => (table(i) != null) && table(i).isSymbol
- }
- OverloadedType(getSymbols(symIds), getTypes(typeIds))
- case ConstantTypeRef(baseId, valId) =>
- ConstantType(getType(baseId), table(valId))
- case FlaggedType(flags, typeId) =>
- TypeFlag(getType(typeId), flags)
- }
- table(i) = res;
- res
- }
- }
-
- def getTypes(is: List[Int]): List[Type] = is map {i => getType(i)};
-
- def print: Unit = {
- Console.println("ROOT = " + root);
- var i = 0;
- while (i < table.length) {
- Console.println("" + i + ": " + table(i).toSource);
- Console.println(" " + table(i));
- i = i + 1;
- }
- }
-}
diff --git a/sources/scala/tools/scalap/Flags.scala b/sources/scala/tools/scalap/Flags.scala
deleted file mode 100644
index 7d5a2fd48f..0000000000
--- a/sources/scala/tools/scalap/Flags.scala
+++ /dev/null
@@ -1,81 +0,0 @@
-/* ___ ____ ___ __ ___ ___
-** / _// __// _ | / / / _ | / _ \ Scala classfile decoder
-** __\ \/ /__/ __ |/ /__/ __ |/ ___/ (c) 2003, LAMP/EPFL
-** /____/\___/_/ |_/____/_/ |_/_/
-**
-** $Id$
-*/
-
-package scala.tools.scalap;
-
-
-/** Encoding of modifiers for Scala definitions.
- *
- * @author Matthias Zenger
- * @version 1.0, 10/02/2004
- */
-object Flags {
-
- final val DEFERRED = 0x00000001; // non-concrete definition
- final val FINAL = 0x00000002; // final definition
- final val PRIVATE = 0x00000004; // private definition
- final val PROTECTED = 0x00000008; // protected definition
- final val SEALED = 0x00000010; // sealed class
- final val OVERRIDE = 0x00000020; // definition overrides other definition
- final val CASE = 0x00000040; // case class
- final val ABSTRACT = 0x00000080; // abstract class
-
- final val DEF = 0x00000100; // a def parameter
- final val REPEATED = 0x00000200; // a repeated parameter
-
- final val SYNTHETIC = 0x00000400; // a synthetic definition
- final val DEPRECATED = 0x00000800; // a deprecated definition
-
- final val JAVA = 0x00001000; // defined by a Java class
- final val OBJECT = 0x00002000; // a singleton object
- final val MUTABLE = 0x00004000; // a mutable variable
- final val VIEWBOUND = 0x00004000; // a type variable is bound by a view
- final val PARAM = 0x00008000; // a (type) parameter of a method
- final val PACKAGE = 0x00100000; // a java package
-
- final val PARAMACCESSOR= 0x02000000; // for methods: is an access method for a val parameter
- // for parameters: is a val parameter
- final val ACCESSOR = 0x04000000; // an access function for a value/variable
- final val BRIDGE = 0x08000000; // a bridge method.
-
- final val INTERFACE = 0x10000000; // a Java interface
- final val TRAIT = 0x20000000; // a trait
-
- final val COVAR = 0x40000000; // a covariant type variable
- final val CONTRAVAR = 0x80000000; // a contravariant type variable
-
- final val TF_STAR = 4; // a repeated type
- final val TF_DEF = 8; // a 'def' type
-
- /** Check if a flag is present in the given flag set.
- */
- def is(flag: Int, flagset: Int): Boolean = (flag & flagset) != 0;
-
- /** Convert a set of modifiers into a readable string.
- */
- def toString(flags: Int): String = {
- val buffer = new StringBuffer();
- if (is(PRIVATE, flags))
- buffer.append("private ");
- if (is(PROTECTED, flags))
- buffer.append("protected ");
- if (is(ABSTRACT, flags) && !is(TRAIT, flags))
- buffer.append("abstract ");
- if (is(FINAL, flags) && !is(OBJECT, flags))
- buffer.append("final ");
- if (is(SEALED, flags))
- buffer.append("sealed ");
- if (is(CASE, flags))
- buffer.append("case ");
- if (is(DEF, flags))
- buffer.append("def ");
- if (is(OVERRIDE, flags))
- buffer.append("override ");
- buffer.toString()
- }
-}
diff --git a/sources/scala/tools/scalap/JavaWriter.scala b/sources/scala/tools/scalap/JavaWriter.scala
deleted file mode 100644
index 38afed674f..0000000000
--- a/sources/scala/tools/scalap/JavaWriter.scala
+++ /dev/null
@@ -1,232 +0,0 @@
-/* ___ ____ ___ __ ___ ___
-** / _// __// _ | / / / _ | / _ \ Scala classfile decoder
-** __\ \/ /__/ __ |/ /__/ __ |/ ___/ (c) 2003, LAMP/EPFL
-** /____/\___/_/ |_/____/_/ |_/_/
-**
-** $Id$
-*/
-
-package scala.tools.scalap;
-
-import java.io._;
-
-
-class JavaWriter(classfile: Classfile, writer: Writer) extends CodeWriter(writer) {
-
- val cf = classfile;
-
- def flagsToStr(clazz: Boolean, flags: Int) = {
- val buffer = new StringBuffer();
- var x: StringBuffer = buffer;
- if (((flags & 0x0007) == 0) &&
- ((flags & 0x0002) != 0))
- x = buffer.append("private ");
- if ((flags & 0x0004) != 0)
- x = buffer.append("protected ");
- if ((flags & 0x0010) != 0)
- x = buffer.append("final ");
- if ((flags & 0x0400) != 0)
- x = if (clazz) buffer.append("abstract ")
- else buffer.append("/*deferred*/ ");
- buffer.toString()
- }
-
- def nameToClass(str: String) = {
- val res = Names.decode(str.replace('/', '.'));
- if (res == "java.lang.Object") "scala.Any" else res
- }
-
- def nameToClass0(str: String) = {
- val res = Names.decode(str.replace('/', '.'));
- if (res == "java.lang.Object") "scala.AnyRef" else res
- }
-
- def nameToSimpleClass(str: String) =
- Names.decode(str.substring(str.lastIndexOf('/') + 1));
-
- def nameToPackage(str: String) = {
- val inx = str.lastIndexOf('/');
- val name = if (inx == -1) str else str.substring(0, inx).replace('/', '.');
- Names.decode(name)
- }
-
- def sigToType(str: String): String =
- sigToType(str, 0)._1;
-
- def sigToType(str: String, i: Int): Pair[String, Int] = str.charAt(i) match {
- case 'B' => Pair("scala.Byte", i + 1)
- case 'C' => Pair("scala.Char", i + 1)
- case 'D' => Pair("scala.Double", i + 1)
- case 'F' => Pair("scala.Float", i + 1)
- case 'I' => Pair("scala.Int", i + 1)
- case 'J' => Pair("scala.Long", i + 1)
- case 'S' => Pair("scala.Short", i + 1)
- case 'V' => Pair("scala.Unit", i + 1)
- case 'Z' => Pair("scala.Boolean", i + 1)
- case 'L' => val j = str.indexOf(';', i);
- Pair(nameToClass(str.substring(i + 1, j)), j + 1)
- case '[' => val Pair(tpe, j) = sigToType(str, i + 1);
- Pair("scala.Array[" + tpe + "]", j)
- case '(' => val Pair(tpe, j) = sigToType0(str, i + 1);
- Pair("(" + tpe, j)
- case ')' => val Pair(tpe, j) = sigToType(str, i + 1);
- Pair("): " + tpe, j)
- }
-
- def sigToType0(str: String, i: Int): Pair[String, Int] =
- if (str.charAt(i) == ')')
- sigToType(str, i)
- else {
- val Pair(tpe, j) = sigToType(str, i);
- if (str.charAt(j) == ')') {
- val Pair(rest, k) = sigToType(str, j);
- Pair(tpe + rest, k)
- } else {
- val Pair(rest, k) = sigToType0(str, j);
- Pair(tpe + ", " + rest, k)
- }
- };
-
- def getName(n: Int): String = cf.pool(n) match {
- case cf.UTF8(str) => str;
- case cf.StringConst(m) => getName(m);
- case cf.ClassRef(m) => getName(m);
- case x => "<error>"
- }
-
- def getClassName(n: Int): String = nameToClass(getName(n));
-
- def getSimpleClassName(n: Int): String = nameToSimpleClass(getName(n));
-
- def getPackage(n: Int): String = nameToPackage(getName(n));
-
- def getType(n: Int): String = sigToType(getName(n));
-
- def isStatic(flags: Int) = (flags & 0x0008) != 0;
-
- def isInterface(flags: Int) = (flags & 0x0200) != 0;
-
- def isConstr(name: String) = (name == "<init>");
-
- def printField(flags: Int, name: Int, tpe: Int, attribs: List[cf.Attribute]) = {
- print(flagsToStr(false, flags));
- if ((flags & 0x0010) != 0)
- print("val " + Names.decode(getName(name)));
- else
- print("final var " + Names.decode(getName(name)));
- print(": " + getType(tpe) + ";").newline;
- }
-
- def printMethod(flags: Int, name: Int, tpe: Int, attribs: List[cf.Attribute]) = {
- if (getName(name) == "<init>")
- print(flagsToStr(false, flags));
- attribs find {
- case cf.Attribute(name, _) => getName(name) == "JacoMeta"
- } match {
- case Some(cf.Attribute(_, data)) =>
- val mp = new MetaParser(getName(
- ((data(0) & 0xff) << 8) + (data(1) & 0xff)).trim());
- mp.parse match {
- case None =>
- if (getName(name) == "<init>") {
- print("def this" + getType(tpe) + ";").newline;
- } else {
- print("def " + Names.decode(getName(name)));
- print(getType(tpe) + ";").newline;
- }
- case Some(str) =>
- if (getName(name) == "<init>")
- print("def this" + str + ";").newline;
- else
- print("def " + Names.decode(getName(name)) + str + ";").newline;
- }
- case None =>
- if (getName(name) == "<init>") {
- print("def this" + getType(tpe) + ";").newline;
- } else {
- print("def " + Names.decode(getName(name)));
- print(getType(tpe) + ";").newline;
- }
- }
- attribs find {
- case cf.Attribute(name, _) => getName(name) == "Exceptions"
- } match {
- case Some(cf.Attribute(_, data)) =>
- val n = ((data(0) & 0xff) << 8) + (data(1) & 0xff);
- indent.print("throws ");
- for (val i <- Iterator.range(0, n) map {x => 2 * (x + 1)}) {
- val inx = ((data(i) & 0xff) << 8) + (data(i+1) & 0xff);
- if (i > 2) print(", ");
- print(getClassName(inx).trim());
- }
- undent.newline;
- case None =>
- }
- }
-
- def printClassHeader = {
- if (isInterface(cf.flags)) {
- print("trait " + getSimpleClassName(cf.classname));
- } else {
- print("class " + getSimpleClassName(cf.classname));
- if (cf.pool(cf.superclass) != null)
- print(" extends " + nameToClass0(getName(cf.superclass)));
- }
- cf.interfaces foreach {
- n => print(" with " + getClassName(n));
- }
- }
-
- def printClass = {
- val pck = getPackage(cf.classname);
- if (pck.length() > 0)
- println("package " + pck + ";");
- print(flagsToStr(true, cf.flags));
- cf.attribs find {
- case cf.Attribute(name, _) => getName(name) == "JacoMeta"
- } match {
- case None =>
- printClassHeader;
- case Some(cf.Attribute(_, data)) =>
- val mp = new MetaParser(getName(
- ((data(0) & 0xff) << 8) + (data(1) & 0xff)).trim());
- mp.parse match {
- case None => printClassHeader;
- case Some(str) =>
- if (isInterface(cf.flags))
- print("trait " + getSimpleClassName(cf.classname) + str);
- else
- print("class " + getSimpleClassName(cf.classname) + str);
- }
- }
- var statics: List[cf.Member] = Nil;
- print(" {").indent.newline;
- cf.fields foreach {
- case m@cf.Member(_, flags, name, tpe, attribs) =>
- if (isStatic(flags))
- statics = m :: statics;
- else
- printField(flags, name, tpe, attribs)
- }
- cf.methods foreach {
- case m@cf.Member(_, flags, name, tpe, attribs) =>
- if (isStatic(flags))
- statics = m :: statics;
- else
- printMethod(flags, name, tpe, attribs)
- }
- undent.print("}").newline;
- if (!statics.isEmpty) {
- print("object " + getSimpleClassName(cf.classname) + " {");
- indent.newline;
- statics foreach {
- case cf.Member(true, flags, name, tpe, attribs) =>
- printField(flags, name, tpe, attribs)
- case cf.Member(false, flags, name, tpe, attribs) =>
- if (getName(name) != "<clinit>")
- printMethod(flags, name, tpe, attribs)
- }
- undent.print("}").newline
- }
- }
-}
diff --git a/sources/scala/tools/scalap/Main.scala b/sources/scala/tools/scalap/Main.scala
deleted file mode 100644
index 3598ff13e4..0000000000
--- a/sources/scala/tools/scalap/Main.scala
+++ /dev/null
@@ -1,163 +0,0 @@
-/* ___ ____ ___ __ ___ ___
-** / _// __// _ | / / / _ | / _ \ Scala classfile decoder
-** __\ \/ /__/ __ |/ /__/ __ |/ ___/ (c) 2003, LAMP/EPFL
-** /____/\___/_/ |_/____/_/ |_/_/
-**
-** $Id$
-*/
-
-package scala.tools.scalap;
-
-import java.io._;
-
-import scala.tools.util.ClassPath;
-
-
-/** The main object used to execute scalap on the command-line.
- *
- * @author Matthias Zenger
- * @version 1.0, 10/02/2004
- */
-object Main {
-
- /** The version number.
- */
- val VERSION = "1.1.0";
-
- /** Verbose program run?
- */
- var verbose = false;
-
- /** Prints usage information for scalap.
- */
- def usage: Unit = {
- Console.println("usage: scalap {<option>} <name>");
- Console.println("where <option> is");
- Console.println(" -private print private definitions");
- Console.println(" -verbose print out additional information");
- Console.println(" -version print out the version number of scalap");
- Console.println(" -help display this usage message");
- Console.println(" -classpath <pathlist> specify where to find user class files");
- Console.println(" -cp <pathlist> specify where to find user class files");
- }
-
- /** Processes the given scala attribute. */
- def processScalaAttribute(args: Arguments, reader: ByteArrayReader): Unit = {
- val info = new ScalaAttribute(reader);
- val symtab = new EntityTable(info);
- // construct a new output stream writer
- val out = new OutputStreamWriter(System.out);
- val writer = new ScalaWriter(args, out);
- // output all elements of the scope
- symtab.root.elements foreach (
- sym => { writer.printSymbol(sym); writer.println*; });
- out.flush();
- }
-
- /** Processes the given classfile. */
- def processJavaClassFile(clazz: Classfile): Unit = {
- // construct a new output stream writer
- val out = new OutputStreamWriter(System.out);
- val writer = new JavaWriter(clazz, out);
- // print the class
- writer.printClass;
- out.flush();
- }
-
- /** Executes scalap with the given arguments and classpath for the
- * class denoted by 'classname'.
- */
- def process(args: Arguments, path: ClassPath)(classname: String): Unit = {
- // find the classfile
- val filename = Names.encode(
- if (classname == "scala.AnyRef") "java.lang.Object"
- else classname).replace('.', File.separatorChar);
- val sfile = path.getRoot().lookupPath(filename + ".symbl", false);
- val cfile = path.getRoot().lookupPath(filename + ".class", false);
- if (sfile != null) {
- processScalaAttribute(args, new ByteArrayReader(sfile.read()));
- // if the classfile exists...
- } else if (cfile != null) {
- if (verbose)
- Console.println(Console.BOLD + "FILENAME" + Console.RESET +
- " = " + cfile.getPath);
- // construct a reader for the classfile content
- val reader = new ByteArrayReader(cfile.read());
- // parse the classfile
- val clazz = new Classfile(reader);
- // check if there is a Scala signature attribute
- val attrib = clazz.attribs.find(a => a.toString() == "ScalaSignature");
- attrib match {
- // if the attribute is found, we have to extract the scope
- // from the attribute
- case Some(a) =>
- processScalaAttribute(args, a.reader);
- // It must be a Java class
- case None =>
- processJavaClassFile(clazz);
- }
- // if the class corresponds to the artificial class scala.Any...
- } else if (classname == "scala.Any") {
- Console.println("package scala;");
- Console.println("class Any {");
- Console.println(" def eq(scala.Any): scala.Boolean;");
- Console.println(" final def ==(scala.Any): scala.Boolean;");
- Console.println(" final def !=(scala.Any): scala.Boolean;");
- Console.println(" def equals(scala.Any): scala.Boolean;");
- Console.println(" def hashCode(): scala.Int;");
- Console.println(" def toString(): java.lang.String;");
- Console.println(" final def isInstanceOf[T]: scala.Boolean;");
- Console.println(" final def asInstanceOf[T]: T;");
- Console.println(" def match[S, T](f: S => T): T;");
- Console.println("}");
- // explain that scala.All cannot be printed...
- } else if (classname == "scala.All") {
- Console.println("Type scala.All is artificial; " +
- "it is a subtype of all types.");
- // explain that scala.AllRef cannot be printed...
- } else if (classname == "scala.AllRef") {
- Console.println("Type scala.AllRef is artificial; it is a " +
- "subtype of all subtypes of scala.AnyRef.");
- // at this point we are sure that the classfile is not available...
- } else
- Console.println("class/object not found.");
- }
-
- /** The main method of this object.
- */
- def main(args: Array[String]) = {
- // print usage information if there is no command-line argument
- if (args.length == 0)
- usage;
- // otherwise parse the arguments...
- else {
- val arguments = Arguments.Parser('-')
- .withOption("-private")
- .withOption("-verbose")
- .withOption("-version")
- .withOption("-help")
- .withOptionalArg("-classpath")
- .withOptionalArg("-cp")
- .parse(args);
- if (arguments contains "-version")
- Console.println("scalap " + VERSION);
- if (arguments contains "-help")
- usage;
- verbose = arguments contains "-verbose";
- // construct a custom class path
- val path = arguments.getArgument("-classpath") match {
- case None => arguments.getArgument("-cp") match {
- case None => new ClassPath()
- case Some(path) => new ClassPath(path)
- }
- case Some(path) => new ClassPath(path)
- }
- // print the classpath if output is verbose
- if (verbose)
- Console.println(Console.BOLD + "CLASSPATH" + Console.RESET +
- " = " + path);
- // process all given classes
- arguments.getOthers.foreach(process(arguments, path));
- }
- }
-}
diff --git a/sources/scala/tools/scalap/MetaParser.scala b/sources/scala/tools/scalap/MetaParser.scala
deleted file mode 100644
index cd691b1991..0000000000
--- a/sources/scala/tools/scalap/MetaParser.scala
+++ /dev/null
@@ -1,193 +0,0 @@
-/* ___ ____ ___ __ ___ ___
-** / _// __// _ | / / / _ | / _ \ Scala classfile decoder
-** __\ \/ /__/ __ |/ /__/ __ |/ ___/ (c) 2003, LAMP/EPFL
-** /____/\___/_/ |_/____/_/ |_/_/
-**
-** $Id$
-*/
-
-package scala.tools.scalap;
-
-import java.io._;
-import java.util._;
-
-
-/** a parser class for parsing meta type information in classfiles
- * generated by pico.
- */
-class MetaParser(meta: String) {
- val scanner = new StringTokenizer(meta, "()[], \t<;", true);
- var token: String = _;
- val res = new StringBuffer;
-
- private def nextToken: String = {
- do {
- token = scanner.nextToken().trim();
- } while (token.length() == 0);
- token
- }
-
- protected def parseType: Unit = {
- if (token.startsWith("?"))
- res.append(token.substring(1));
- else
- res.append(token);
- nextToken;
- if (token == "[") {
- do {
- if (token == ",")
- res.append(", ");
- else
- res.append("[");
- nextToken;
- parseType;
- } while (token == ",");
- nextToken;
- res.append("]");
- }
- }
-
- def parse: Option[String] =
- if (scanner.hasMoreTokens()) {
- nextToken;
- try {
- if (!scanner.hasMoreTokens())
- None
- else if (token == "class")
- Some(parseMetaClass);
- else if (token == "method")
- Some(parseMetaMethod);
- else if (token == "field")
- Some(parseMetaField);
- else if (token == "constr")
- Some(parseConstrField);
- else
- None;
- } catch { case _ =>
- None;
- }
- } else
- None;
-
- protected def parseMetaClass: String = {
- nextToken;
- if (token == "[") {
- do {
- if (token == "[")
- res.append('[');
- else
- res.append(", ");
- nextToken;
- if (token == "+") {
- nextToken;
- res.append('+');
- } else if (token == "-") {
- nextToken;
- res.append('-');
- }
- res.append(token.substring(1));
- nextToken;
- if (token == "<") {
- nextToken;
- res.append(" <: ");
- parseType;
- }
- } while (token == ",");
- nextToken;
- res.append("]");
- }
- if (token == "extends") {
- do {
- if (token == "extends")
- res.append(" extends ");
- else
- res.append(" with ");
- nextToken;
- parseType;
- } while (token == "with");
- }
- res.toString();
- }
-
- protected def parseMetaMethod: String = {
- nextToken;
- if (token == "[") {
- nextToken;
- if (token == "]") {
- nextToken;
- } else {
- var loop = true;
- res.append("[");
- while (loop) {
- res.append(token.substring(1));
- nextToken;
- if (token == "<") {
- nextToken;
- res.append(" <: ");
- parseType;
- }
- if (token == ",") {
- nextToken;
- res.append(", ");
- } else
- loop = false;
- }
- nextToken;
- res.append("]");
- }
- }
- if (token == "(") {
- do {
- if (token == ",") {
- nextToken;
- if (token != ")")
- res.append(", ");
- } else {
- nextToken;
- res.append("(");
- }
- if (token != ")") {
- if (token == "def") {
- nextToken;
- res.append("def ");
- }
- parseType;
- }
- } while (token == ",");
- nextToken;
- res.append("): ");
- parseType;
- } else {
- res.append(": ");
- parseType;
- }
- res.toString();
- }
-
- protected def parseMetaField: String = {
- nextToken;
- res.append(": ");
- parseType;
- res.toString();
- }
-
- protected def parseConstrField: String = {
- nextToken;
- if (token == "(") {
- do {
- if (token == "(")
- res.append("(");
- else
- res.append(", ");
- nextToken;
- if (token != ")")
- parseType;
- } while (token == ",");
- nextToken;
- res.append(")");
- } else {
-
- }
- res.toString();
- }
-}
diff --git a/sources/scala/tools/scalap/Names.scala b/sources/scala/tools/scalap/Names.scala
deleted file mode 100644
index d77132470a..0000000000
--- a/sources/scala/tools/scalap/Names.scala
+++ /dev/null
@@ -1,95 +0,0 @@
-/* ___ ____ ___ __ ___ ___
-** / _// __// _ | / / / _ | / _ \ Scala classfile decoder
-** __\ \/ /__/ __ |/ /__/ __ |/ ___/ (c) 2003, LAMP/EPFL
-** /____/\___/_/ |_/____/_/ |_/_/
-**
-** $Id$
-*/
-
-package scala.tools.scalap;
-
-
-object Names {
-
- val operatorName = new Array[String](128);
- operatorName('$') = "$";
- operatorName('~') = "$tilde";
- operatorName('=') = "$eq";
- operatorName('<') = "$less";
- operatorName('>') = "$greater";
- operatorName('!') = "$bang";
- operatorName('#') = "$hash";
- operatorName('%') = "$percent";
- operatorName('^') = "$up";
- operatorName('&') = "$amp";
- operatorName('|') = "$bar";
- operatorName('*') = "$times";
- operatorName('/') = "$div";
- operatorName('\\') = "$bslash";
- operatorName('+') = "$plus";
- operatorName('-') = "$minus";
- operatorName(':') = "$colon";
-
- /** Replace operator symbols by corresponding "$op_name" in names.
- */
- def encode(name: String): String = {
- var i = 0;
- val len = name.length();
- val res = new StringBuffer();
- while (i < len) {
- val c = name.charAt(i);
- if (c < 128) {
- val nop = operatorName(c);
- if (nop == null)
- res.append(c);
- else
- res.append(nop);
- } else
- res.append(c);
- i = i + 1;
- }
- res.toString()
- }
-
- /** Replace "$op_name" by corresponding operator symbols in names.
- */
- def decode(name: String): String = {
- var i = 0;
- val len = name.length();
- val res = new StringBuffer();
- while (i < len) {
- val c = name.charAt(i);
- if (c == '$') {
- var j = len;
- while (j > i) {
- val prefix = name.substring(i, j);
- val c = lookup(prefix);
- if (c != null) {
- i = j;
- res.append(c);
- } else
- j = j - 1;
- }
- } else {
- i = i + 1;
- res.append(c);
- }
- }
- res.toString()
- }
-
- /** Looks up the array entry for the operator name.
- */
- def lookup(string: String): String = {
- var i = 0;
- var res: String = null;
- while (i < 128) {
- if (string.equals(operatorName(i))) {
- res = String.valueOf(i.asInstanceOf[Char]);
- i = 128;
- }
- i = i + 1;
- }
- res
- }
-}
diff --git a/sources/scala/tools/scalap/ScalaAttribute.scala b/sources/scala/tools/scalap/ScalaAttribute.scala
deleted file mode 100644
index 1f165cc53e..0000000000
--- a/sources/scala/tools/scalap/ScalaAttribute.scala
+++ /dev/null
@@ -1,167 +0,0 @@
-/* ___ ____ ___ __ ___ ___
-** / _// __// _ | / / / _ | / _ \ Scala classfile decoder
-** __\ \/ /__/ __ |/ /__/ __ |/ ___/ (c) 2003, LAMP/EPFL
-** /____/\___/_/ |_/____/_/ |_/_/
-**
-** $Id$
-*/
-
-package scala.tools.scalap;
-
-import scala.collection.mutable._;
-
-
-class ScalaAttribute(in: ByteArrayReader) {
-
- final val TERM_NAME = 1;
- final val TYPE_NAME = 2;
- final val NUMBER = 3;
- final val NONE_SYM = 4;
- final val TYPE_SYM = 5;
- final val ALIAS_SYM = 6;
- final val CLASS_SYM = 7;
- final val VAL_SYM = 8;
- final val EXT_REF = 9;
- final val EXTMODCLASS_REF = 10;
- final val NO_TYPE = 11;
- final val THIS_TYPE = 12;
- final val SINGLE_TYPE = 13;
- final val CONSTANT_TYPE = 14;
- final val REF_TYPE = 15;
- final val COMPOUND_TYPE = 16;
- final val METHOD_TYPE = 17;
- final val POLY_TYPE = 18;
- final val OVERLOADED_TYPE = 19;
- final val UNBOXED_TYPE = 20;
- final val UNBOXEDARRAY_TYPE = 21;
- final val FLAGGED_TYPE = 22;
- final val ERROR_TYPE = 23;
- final val UNIT_LIT = 24;
- final val BOOL_LIT = 25;
- final val BYTE_LIT = 26;
- final val SHORT_LIT = 27;
- final val CHAR_LIT = 28;
- final val INT_LIT = 29;
- final val LONG_LIT = 30;
- final val FLOAT_LIT = 31;
- final val DOUBLE_LIT = 32;
- final val STRING_LIT = 33;
- final val NULL_LIT = 34;
- final val ZERO_LIT = 35;
-
- val table = readTable;
-
- def readTable: Array[AttribEntry] = {
- val res = new Array[AttribEntry](in.nextNat);
- var i = 0;
- while (i < res.length) {
- res(i) = readTableEntry;
- i = i + 1;
- }
- res
- }
-
- def readTableEntry: AttribEntry = {
- val tag = in.nextByte;
- //Console.println("tag = " + tag);
- val len = in.nextNat;
- val end = in.bp + len;
- tag match {
- case TERM_NAME =>
- TermName(in.nextUTF8(len))
- case TYPE_NAME =>
- TypeName(in.nextUTF8(len))
- case NUMBER =>
- Number(in.nextNum(len))
- case NONE_SYM =>
- NoneSym()
- case TYPE_SYM =>
- TypeSym(readSymInfo, in.nextNat)
- case ALIAS_SYM =>
- AliasSym(readSymInfo, in.nextNat)
- case CLASS_SYM =>
- val info = readSymInfo;
- if (Flags.is(info.flags, Flags.OBJECT)) in.nextNat;
- ClassSym(info, in.nextNat, in.nextNat)
- case VAL_SYM =>
- ValSym(readSymInfo, if (in.bp < end) in.nextNat else -1)
- case EXT_REF =>
- ExtRef(false, in.nextNat, if (in.bp < end) in.nextNat else -1)
- case EXTMODCLASS_REF =>
- ExtRef(true, in.nextNat, if (in.bp < end) in.nextNat else -1)
- case NO_TYPE =>
- NoneType()
- case THIS_TYPE =>
- SelfType(in.nextNat)
- case SINGLE_TYPE =>
- SingleType(in.nextNat, in.nextNat)
- case CONSTANT_TYPE =>
- ConstantTypeRef(in.nextNat, in.nextNat)
- case REF_TYPE =>
- TypeReference(in.nextNat, in.nextNat, readRefs(end))
- case COMPOUND_TYPE =>
- if (in.nextByte != 0) in.nextNat;
- CompoundTypeRef(in.nextNat, readRefs(end))
- case METHOD_TYPE =>
- MethodTypeRef(in.nextNat, readRefs(end))
- case POLY_TYPE =>
- PolyTypeRef(in.nextNat, readRefs(end))
- case OVERLOADED_TYPE =>
- OverloadedTypeRef(readRefs(end))
- case FLAGGED_TYPE =>
- FlaggedType(in.nextNat, in.nextNat)
- case UNIT_LIT |
- NULL_LIT |
- ZERO_LIT =>
- Literal(tag, 0)
- case BOOL_LIT =>
- Literal(tag, in.nextByte)
- case STRING_LIT =>
- Literal(tag, in.nextNat)
- case BYTE_LIT |
- CHAR_LIT |
- SHORT_LIT |
- INT_LIT |
- LONG_LIT |
- FLOAT_LIT |
- DOUBLE_LIT =>
- Literal(tag, in.nextNum(len))
- case _ =>
- error("unknown meta data tag: " + tag);
- }
- }
-
- def readSymInfo: SymbolInfo =
- SymbolInfo(in.nextNat, in.nextNat, in.nextNat, in.nextNat);
-
- def readRefs(end: Int): List[Int] = {
- var res = new ListBuffer[Int];
- while (in.bp < end)
- res += in.nextNat;
- res.toList
- }
-
- class AttribEntry;
- case class TermName(name: String) extends AttribEntry;
- case class TypeName(name: String) extends AttribEntry;
- case class Number(value: Long) extends AttribEntry;
- case class NoneSym() extends AttribEntry;
- case class TypeSym(info: SymbolInfo, lobound: Int) extends AttribEntry;
- case class AliasSym(info: SymbolInfo, constr: Int) extends AttribEntry;
- case class ClassSym(info: SymbolInfo, thistpe: Int, constr: Int) extends AttribEntry;
- case class ValSym(info: SymbolInfo, classsym: Int) extends AttribEntry;
- case class ExtRef(mod: Boolean, name: Int, owner: Int) extends AttribEntry;
- case class NoneType() extends AttribEntry;
- case class SelfType(sym: Int) extends AttribEntry;
- case class SingleType(typeref: Int, sym: Int) extends AttribEntry;
- case class TypeReference(typeref: Int, sym: Int, args: List[Int]) extends AttribEntry;
- case class CompoundTypeRef(sym: Int, components: List[Int]) extends AttribEntry;
- case class MethodTypeRef(res: Int, args: List[Int]) extends AttribEntry;
- case class PolyTypeRef(tpe: Int, sym: List[Int]) extends AttribEntry;
- case class OverloadedTypeRef(symandtpe: List[Int]) extends AttribEntry;
- case class ConstantTypeRef(baseref: Int, numref: Int) extends AttribEntry;
- case class FlaggedType(flags: Int, tpe: Int) extends AttribEntry;
- case class Literal(tag: Int, data: Long) extends AttribEntry;
-
- case class SymbolInfo(name: Int, owner: Int, flags: Int, info: Int);
-}
diff --git a/sources/scala/tools/scalap/ScalaWriter.scala b/sources/scala/tools/scalap/ScalaWriter.scala
deleted file mode 100644
index 5ff8ea6277..0000000000
--- a/sources/scala/tools/scalap/ScalaWriter.scala
+++ /dev/null
@@ -1,301 +0,0 @@
-/* ___ ____ ___ __ ___ ___
-** / _// __// _ | / / / _ | / _ \ Scala classfile decoder
-** __\ \/ /__/ __ |/ /__/ __ |/ ___/ (c) 2003, LAMP/EPFL
-** /____/\___/_/ |_/____/_/ |_/_/
-**
-** $Id$
-*/
-
-package scala.tools.scalap;
-
-import java.io.Writer;
-import scala.collection.mutable.Buffer;
-
-
-class ScalaWriter(args: Arguments, writer: Writer) extends CodeWriter(writer) {
-
- def printSymbol(sym: Symbol): Unit = sym match {
- case NoSymbol =>
- print("<nosymbol>")
- case s: TypeSymbol =>
- printFlags(s);
- print("type ");
- printTVar(s);
- case s: AliasSymbol =>
- printFlags(s);
- print("type " + s.name + " = ");
- printType(s.tpe);
- case s: ClassSymbol =>
- printFlags(s);
- if (Flags.is(Flags.DEFERRED, s.flags))
- print("/*deferred*/ ");
- if (Flags.is(Flags.OBJECT, s.flags))
- print("object " + s.name);
- else if (Flags.is(Flags.TRAIT, s.flags)) {
- print("trait " + s.name);
- printConstr(s.constr);
- } else {
- print("class " + s.name);
- printConstr(s.constr);
- }
- print(" extends ");
- printType(s.tpe);
- case s: ValSymbol =>
- s.tpe match {
- case PolyType(tpe, Nil) =>
- printFlags(s);
- print("def " + s.name + ": ");
- printType(tpe);
- case PolyType(_, _) =>
- printFlags(s);
- print("def " + s.name);
- printType(s.tpe);
- case MethodType(_, _) =>
- printFlags(s);
- print("def " + s.name);
- printType(s.tpe);
- case _ =>
- printFlags(s);
- print("val " + s.name + ": ");
- printType(s.tpe);
- }
- case s: ExternalSymbol =>
- print("<externalsymbol: " + s.fullname + ">")
- }
-
- def printConstr(sym: Symbol): Unit = sym match {
- case s: ValSymbol =>
- s.tpe match {
- case PolyType(MethodType(argtpes, _), tvars) =>
- print("[");
- if (!tvars.isEmpty) {
- printTVar(tvars.head);
- tvars.tail foreach { sym =>
- print(", ");
- printTVar(sym);
- }
- }
- print("]");
- printParameterTypes(argtpes, "(", ", ", ")", false);
- case MethodType(argtpes, _) =>
- printParameterTypes(argtpes, "(", ", ", ")", false);
- case _ =>
- }
- }
-
- def printScope(scope: Buffer[Symbol]): Unit = {
- var first = true;
- scope.elements foreach (
- sym => { sym match {
- case s: ValSymbol if
- (s.tpe.isInstanceOf[OverloadedType] ||
- (Flags.is(Flags.PARAMACCESSOR, s.flags) &&
- !s.tpe.isInstanceOf[PolyType])) =>
- case _ =>
- if (!ignoreDef(sym)) {
- if (first) print(" {").indent else print(";");
- first = false;
- newline;
- printSymbol(sym);
- }
- }});
- if (!first)
- newline.undent.print("}")
- }
-
- def printParameterType(tpe: Type, basic: Boolean): Unit = tpe match {
- case TypeRef(SingletonType(ThisType(root), top), sym, args) =>
- if ((root.name.equals("<root>") || root.name.equals("")) &&
- top.name.equals("scala") &&
- sym.name.startsWith("Function")) {
- if ((args.length == 2) && !isFunctionType(args.head)) {
- printType(args.head);
- print(" => ");
- printParameterType(args.tail.head, basic);
- } else {
- printParameterTypes(args.take(args.length - 1), "(", ", ", ")", basic);
- print(" => ");
- printParameterType(args.last, basic);
- }
- } else if (basic)
- printType0(tpe);
- else
- printType(tpe);
- case _ => if (basic) printType0(tpe); else printType(tpe);
- }
-
- def printParameterTypes(tpes: List[Type], begin: String, infix: String,
- end: String, basic: Boolean): Unit = {
- print(begin);
- if (!tpes.isEmpty) {
- printParameterType(tpes.head, basic);
- tpes.tail foreach (t => { print(infix); printParameterType(t, basic) });
- }
- print(end);
- }
-
- def printType(tpe: Type): Unit = {
- printType0(tpe);
- tpe match {
- case ThisType(_) => print(".type")
- case SingletonType(_, _) => print(".type")
- case _ =>
- }
- }
-
- def printTypes(tpes: List[Type], begin: String, infix: String, end: String): Unit = {
- if (!tpes.isEmpty)
- printTypes0(tpes, begin, infix, end);
- }
-
- def printType0(tpe: Type): Unit = tpe match {
- case NoType =>
- case ThisType(sym) => sym match {
- case x: ExternalSymbol => print(sym.fullname)
- case NoSymbol => print("this")
- case _ => print(sym.fullname).print(".this")
- }
- case SingletonType(tpe, sym) =>
- printPrefix(tpe);
- print(sym.name)
- case TypeRef(pre, sym, args) =>
- if (isJavaRoot(tpe))
- print("scala.AnyRef");
- else {
- printPrefix(pre);
- print(sym.name);
- printTypes(args, "[", ", ", "]");
- }
- case CompoundType(clazz, components) =>
- printTypes(components, "", " with ", "");
- if (clazz != NoSymbol)
- printScope(clazz.members);
- case MethodType(_, _) =>
- var tpe0 = tpe;
- while (tpe0.isInstanceOf[MethodType]) {
- tpe0 match {
- case MethodType(argtpes, restpe) =>
- printParameterTypes(argtpes, "(", ", ", ")", true);
- tpe0 = restpe;
- }
- }
- print(":").newspace;
- printType(tpe0);
- case PolyType(tpe, tvars) =>
- print("[");
- if (!tvars.isEmpty) {
- printTVar(tvars.head);
- tvars.tail foreach (sym => {print(", "); printTVar(sym);});
- }
- print("]");
- printType(tpe);
- case OverloadedType(_, tpes) =>
- printTypes(tpes, "", " <and> ", "");
- case ConstantType(base, num) =>
- printType(base);
- print("(" + num + ")");
- case TypeFlag(TypeRef(_, _, List(tpe0)), flags) =>
- if (Flags.is(Flags.TF_DEF, flags))
- print("def ");
- printType(tpe0);
- if (Flags.is(Flags.TF_STAR, flags))
- print("*");
- case TypeFlag(tpe0, flags) =>
- if (Flags.is(Flags.TF_DEF, flags))
- print("def ");
- printType(tpe0);
- case _ => print("<unknown type>");
- }
-
- def printTypes0(tpes: List[Type], begin: String, infix: String, end: String): Unit = {
- print(begin);
- if (!tpes.isEmpty) {
- printType(tpes.head);
- tpes.tail foreach (t => { print(infix); printType(t) });
- }
- print(end);
- }
-
- def printPrefix(tpe: Type): Unit = tpe match {
- case NoType =>
- case ThisType(NoSymbol) =>
- case ThisType(sym) =>
- if ((sym.name.length() != 0) &&
- ("<root>" != sym.name)) {
- printType0(tpe);
- print(".")
- }
- case SingletonType(_, sym) =>
- if ((sym.name.length() != 0) &&
- ("<root>" != sym.name)) {
- printType0(tpe);
- print(".")
- }
- case TypeRef(_, _, _) =>
- printType0(tpe);
- print("#")
- case _ =>
- Console.println(tpe.getClass());
- printType0(tpe);
- print(".")
- }
-
- def printTVar(tvar: Symbol): Unit = tvar match {
- case sym: TypeSymbol =>
- if (Flags.is(Flags.COVAR, sym.flags))
- print("+" + sym.name)
- else if (Flags.is(Flags.CONTRAVAR, sym.flags))
- print("-" + sym.name);
- else
- print(sym.name);
- if (!isExternalType(sym.tpe, "Any")) {
- if (Flags.is(Flags.VIEWBOUND, sym.flags))
- print(" <% ");
- else
- print(" <: ");
- printType(sym.tpe);
- }
- if (!isExternalType(sym.lower, "All")) {
- print(" >: ");
- printType(sym.lower);
- }
- }
-
- def printFlags(sym: Symbol) = print(Flags.toString(sym.flags));
-
- def isExternalType(tpe: Type, name: String): Boolean = tpe match {
- case TypeRef(SingletonType(ThisType(root), pck), sym, Nil) =>
- root.name.equals("<root>") &&
- pck.name.equals("scala") &&
- sym.name.equals(name)
- case _ => false
- }
-
- def isJavaRoot(tpe: Type): Boolean = tpe match {
- case TypeRef(SingletonType(SingletonType(ThisType(root), top), mid), sym, Nil) =>
- (root.name.equals("<root>") || root.name.equals("")) &&
- top.name.equals("java") &&
- mid.name.equals("lang") &&
- sym.name.equals("Object")
- case _ => false
- }
-
- def isFunctionType(tpe: Type): Boolean = tpe match {
- case TypeRef(SingletonType(ThisType(root), top), sym, Nil) =>
- (root.name.equals("<root>") || root.name.equals("")) &&
- top.name.equals("scala") &&
- sym.name.startsWith("Function")
- case _ => false
- }
-
- def ignoreDef(s: Symbol) =
- (Flags.is(Flags.PRIVATE, s.flags) &&
- !((args != null) && (args contains "-private"))) ||
- (s.name == "<init>") ||
- Flags.is(Flags.PARAMACCESSOR, s.flags) ||
- (Flags.is(Flags.CASE, s.flags) &&
- (s match {
- case sym: ValSymbol => true
- case _ => false
- }))
-}
diff --git a/sources/scala/tools/scalatest/Command.java b/sources/scala/tools/scalatest/Command.java
deleted file mode 100644
index f254dc694c..0000000000
--- a/sources/scala/tools/scalatest/Command.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/* ___ ____ ___ __ ___ _____
-** / _// __// _ | / / / _ |/_ _/ Scala test
-** __\ \/ /__/ __ |/ /__/ __ | / / (c) 2003, LAMP/EPFL
-** /____/\___/_/ |_/____/_/ |_//_/
-**
-** $Id$
-*/
-
-package scala.tools.scalatest;
-
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-
-
-public abstract class Command {
-
- private Console console;
-
- Command(Console console) {
- this.console = console;
- }
-
- /**
- * Redirects the standard output/error streams of the process into files.
- * (see http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps_p.html)
- */
- private class StreamGobbler extends Thread {
- private InputStream is;
- private OutputStream os;
-
- public StreamGobbler(InputStream is) {
- // this(is, null); // Pico bug (mics/14.10.2003)
- this.is = is;
- this.os = null;
- }
-
- public StreamGobbler(InputStream is, OutputStream os) {
- this.is = is;
- this.os = os;
- }
-
- public void run() {
- try {
- BufferedReader rd =
- new BufferedReader(new InputStreamReader(is));
- String s = rd.readLine();
- if (s != null) {
- if (os == null)
- do {
- console.println(s);
- } while ((s = rd.readLine()) != null);
- else {
- PrintWriter pw = new PrintWriter(os);
- do {
- pw.println(s);
- } while ((s = rd.readLine()) != null);
- pw.flush();
- }
- }
- } catch (Exception e) {
- System.err.println(e.getMessage());
- System.exit(-1);
- }
- }
- }
-
- protected int execute(String cmdline, OutputStream out, OutputStream err) {
- int exitValue = -1;
- try {
- Process p = Runtime.getRuntime().exec(cmdline);
- StreamGobbler outputGobbler = new StreamGobbler(p.getInputStream(), out);
- StreamGobbler errorGobbler = new StreamGobbler(p.getErrorStream(), err);
-
- // read any output from the attempted command
- outputGobbler.start();
-
- // read any errors from the attempted command
- errorGobbler.start();
-
- exitValue = p.waitFor();
-
- if (out != null)
- out.flush();
- if (err != null)
- err.flush();
- } catch (Exception e) {
- System.err.println(e.getMessage());
- }
- return exitValue;
- }
-
- protected int execute(String cmdline, OutputStream out) {
- return execute(cmdline, out, out);
- }
-
- protected int execute(String cmdline) {
- return execute(cmdline, null, null);
- }
-
- public abstract boolean run(String arg);
-
-}
diff --git a/sources/scala/tools/scalatest/Console.java b/sources/scala/tools/scalatest/Console.java
deleted file mode 100644
index 53ec7db224..0000000000
--- a/sources/scala/tools/scalatest/Console.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/* ___ ____ ___ __ ___ _____
-** / _// __// _ | / / / _ |/_ _/ Scala test
-** __\ \/ /__/ __ |/ /__/ __ | / / (c) 2003, LAMP/EPFL
-** /____/\___/_/ |_/____/_/ |_//_/
-**
-** $Id$
-*/
-
-package scala.tools.scalatest;
-
-import java.io.*;
-import java.text.*;
-
-
-class Console {
-
- // ANSI colors foreground
- public final static String BLACK = "\033[30m";
- public final static String RED = "\033[31m";
- public final static String GREEN = "\033[32m";
- public final static String YELLOW = "\033[33m";
- public final static String BLUE = "\033[34m";
- public final static String MAGENTA = "\033[35m";
- public final static String CYAN = "\033[36m";
- public final static String WHITE = "\033[37m";
- public final static String COLOR38 = "\033[38m";
- public final static String COLOR39 = "\033[39m";
-
- // ANSI colors background
- public final static String BLACK_B = "\033[40m";
- public final static String RED_B = "\033[41m";
- public final static String GREEN_B = "\033[42m";
- public final static String YELLOW_B = "\033[43m";
- public final static String BLUE_B = "\033[44m";
- public final static String MAGENTA_B = "\033[45m";
- public final static String CYAN_B = "\033[46m";
- public final static String WHITE_B = "\033[47m";
-
- // ANSI styles
- public final static String RESET = "\033[0m";
- public final static String BOLD = "\033[1m";
- public final static String UNDERLINED = "\033[4m";
- public final static String BLINK = "\033[5m";
- public final static String REVERSED = "\033[7m";
- public final static String INVISIBLE = "\033[8m";
-
- private PrintStream out = System.out;
- private BufferedReader in =
- new BufferedReader(new InputStreamReader(System.in));
-
- /** Set the default output stream.
- *
- * @param out the new output stream.
- */
- public void setOut(PrintStream out) {
- this.out = out;
- }
-
- /** Set the default input stream.
- *
- * @param in the new input stream.
- */
- public void setIn(InputStream in) {
- this.in = new BufferedReader(new InputStreamReader(in));
- }
-
- /** Set the default input stream.
- *
- * @param reader specifies the new input stream.
- */
- public void setIn(Reader reader) {
- this.in = new BufferedReader(reader);
- }
-
- /** Print an object on the terminal.
- *
- * @param obj the object to print.
- */
- public void print(Object obj) {
- out.print((obj == null) ? "null" : obj.toString());
- }
-
- /** Flush the output stream. This function is required when partial
- * output (i.e. output not terminated by a new line character) has
- * to be made visible on the terminal.
- */
- public void flush() { out.flush(); }
-
- /** Print a new line character on the terminal.
- */
- public void println() {
- out.println();
- }
-
- /** Print out an object followed by a new line character.
- *
- * @param x the object to print.
- */
- public void println(Object x) {
- out.println(x);
- }
-
- /** Format and print out some text (in a fashion similar to printf in C).
- * The format of the text to print is specified by the parameter
- * <code>text</code>. The arguments that are inserted into specific
- * locations in <code>text</code> are provided with parameter
- * <code>args</code>. See class <code>java.text.MessageFormat</code>
- * for a full specification of the format syntax.
- *
- * @param text the format of the text to print out.
- * @param args the parameters used to instantiate the format.
- */
- public void printf(String text, Object[] args) {
- if (text == null)
- out.print("null");
- else
- out.print(MessageFormat.format(text, args));
- }
-
- /** Read a full line from the terminal.
- *
- * @return the string read from the terminal.
- */
- public String readLine() throws IOException { return in.readLine(); }
-
- /** Read a boolean value from the terminal.
- *
- * @return the boolean value read from the terminal.
- */
- public boolean readBoolean() throws IOException {
- String value = in.readLine().toLowerCase();
- return "true".equals(value) || "t".equals(value)
- || "yes".equals(value) || "y".equals(value);
- }
-
- /** Read a byte value from the terminal.
- */
- public byte readByte() throws IOException {
- return java.lang.Byte.decode(in.readLine()).byteValue();
- }
-
- /** Read a short value from the terminal.
- */
- public short readShort() throws IOException {
- return java.lang.Short.decode(in.readLine()).shortValue();
- }
-
- /** Read a char value from the terminal.
- */
- public char readChar() throws IOException {
- return in.readLine().charAt(0);
- }
-
- /** Read an int value from the terminal.
- */
- public int readInt() throws IOException {
- return java.lang.Integer.decode(in.readLine()).intValue();
- }
-
- /** Read a float value from the terminal.
- */
- public float readFloat() throws IOException { return java.lang.Float.parseFloat(in.readLine()); }
-
- /** Read a double value from the terminal.
- */
- public double readDouble() throws IOException {
- return java.lang.Double.parseDouble(in.readLine());
- }
-
-}
diff --git a/sources/scala/tools/scalatest/Diff.java b/sources/scala/tools/scalatest/Diff.java
deleted file mode 100644
index a0345914f4..0000000000
--- a/sources/scala/tools/scalatest/Diff.java
+++ /dev/null
@@ -1,894 +0,0 @@
-/*
- * $Log$
- * Revision 1.1 2003/10/13 16:00:03 michelou
- * - Java implementation of GNU diff (GPL licence)
- *
- * Revision 1.6 2003/03/06 22:51:32 stuart
- * Convert to CVS
- *
- * Revision 1.5 2002/07/19 19:14:40 stuart
- * fix reverseScript, make change ctor public, update docs
- *
- * Revision 1.4 2002/04/09 17:53:39 stuart
- * More flexible interface for diff() function.
- *
- * Revision 1.3 2000/03/03 21:58:03 stuart
- * move discard_confusing_lines and shift_boundaries to class file_data
- *
- * Revision 1.2 2000/03/02 16:37:38 stuart
- * Add GPL and copyright
- *
- */
-//package bmsi.util;
-package scala.tools.scalatest;
-
-import java.util.Hashtable;
-
-/** A class to compare vectors of objects. The result of comparison
- is a list of <code>change</code> objects which form an
- edit script. The objects compared are traditionally lines
- of text from two files. Comparison options such as "ignore
- whitespace" are implemented by modifying the <code>equals</code>
- and <code>hashcode</code> methods for the objects compared.
-<p>
- The basic algorithm is described in: </br>
- "An O(ND) Difference Algorithm and its Variations", Eugene Myers,
- Algorithmica Vol. 1 No. 2, 1986, p 251.
-<p>
- This class outputs different results from GNU diff 1.15 on some
- inputs. Our results are actually better (smaller change list, smaller
- total size of changes), but it would be nice to know why. Perhaps
- there is a memory overwrite bug in GNU diff 1.15.
-
- @author Stuart D. Gathman, translated from GNU diff 1.15
- Copyright (C) 2000 Business Management Systems, Inc.
-<p>
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 1, or (at your option)
- any later version.
-<p>
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-<p>
- You should have received a copy of the <a href=COPYING.txt>
- GNU General Public License</a>
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- */
-
-public class Diff {
-
- /** Prepare to find differences between two arrays. Each element of
- the arrays is translated to an "equivalence number" based on
- the result of <code>equals</code>. The original Object arrays
- are no longer needed for computing the differences. They will
- be needed again later to print the results of the comparison as
- an edit script, if desired.
- */
- public Diff(Object[] a,Object[] b) {
- Hashtable h = new Hashtable(a.length + b.length);
- filevec[0] = new file_data(a,h);
- filevec[1] = new file_data(b,h);
- }
-
- /** 1 more than the maximum equivalence value used for this or its
- sibling file. */
- private int equiv_max = 1;
-
- /** When set to true, the comparison uses a heuristic to speed it up.
- With this heuristic, for files with a constant small density
- of changes, the algorithm is linear in the file size. */
- public boolean heuristic = false;
-
- /** When set to true, the algorithm returns a guarranteed minimal
- set of changes. This makes things slower, sometimes much slower. */
- public boolean no_discards = false;
-
- private int[] xvec, yvec; /* Vectors being compared. */
- private int[] fdiag; /* Vector, indexed by diagonal, containing
- the X coordinate of the point furthest
- along the given diagonal in the forward
- search of the edit matrix. */
- private int[] bdiag; /* Vector, indexed by diagonal, containing
- the X coordinate of the point furthest
- along the given diagonal in the backward
- search of the edit matrix. */
- private int fdiagoff, bdiagoff;
- private final file_data[] filevec = new file_data[2];
- private int cost;
-
- /** Find the midpoint of the shortest edit script for a specified
- portion of the two files.
-
- We scan from the beginnings of the files, and simultaneously from the ends,
- doing a breadth-first search through the space of edit-sequence.
- When the two searches meet, we have found the midpoint of the shortest
- edit sequence.
-
- The value returned is the number of the diagonal on which the midpoint lies.
- The diagonal number equals the number of inserted lines minus the number
- of deleted lines (counting only lines before the midpoint).
- The edit cost is stored into COST; this is the total number of
- lines inserted or deleted (counting only lines before the midpoint).
-
- This function assumes that the first lines of the specified portions
- of the two files do not match, and likewise that the last lines do not
- match. The caller must trim matching lines from the beginning and end
- of the portions it is going to specify.
-
- Note that if we return the "wrong" diagonal value, or if
- the value of bdiag at that diagonal is "wrong",
- the worst this can do is cause suboptimal diff output.
- It cannot cause incorrect diff output. */
-
- private int diag (int xoff, int xlim, int yoff, int ylim) {
- final int[] fd = fdiag; // Give the compiler a chance.
- final int[] bd = bdiag; // Additional help for the compiler.
- final int[] xv = xvec; // Still more help for the compiler.
- final int[] yv = yvec; // And more and more . . .
- final int dmin = xoff - ylim; // Minimum valid diagonal.
- final int dmax = xlim - yoff; // Maximum valid diagonal.
- final int fmid = xoff - yoff; // Center diagonal of top-down search.
- final int bmid = xlim - ylim; // Center diagonal of bottom-up search.
- int fmin = fmid, fmax = fmid; // Limits of top-down search.
- int bmin = bmid, bmax = bmid; // Limits of bottom-up search.
- /* True if southeast corner is on an odd
- diagonal with respect to the northwest. */
- final boolean odd = (fmid - bmid & 1) != 0;
-
- fd[fdiagoff + fmid] = xoff;
- bd[bdiagoff + bmid] = xlim;
-
- for (int c = 1;; ++c)
- {
- int d; /* Active diagonal. */
- boolean big_snake = false;
-
- /* Extend the top-down search by an edit step in each diagonal. */
- if (fmin > dmin)
- fd[fdiagoff + --fmin - 1] = -1;
- else
- ++fmin;
- if (fmax < dmax)
- fd[fdiagoff + ++fmax + 1] = -1;
- else
- --fmax;
- for (d = fmax; d >= fmin; d -= 2)
- {
- int x, y, oldx, tlo = fd[fdiagoff + d - 1], thi = fd[fdiagoff + d + 1];
-
- if (tlo >= thi)
- x = tlo + 1;
- else
- x = thi;
- oldx = x;
- y = x - d;
- while (x < xlim && y < ylim && xv[x] == yv[y]) {
- ++x; ++y;
- }
- if (x - oldx > 20)
- big_snake = true;
- fd[fdiagoff + d] = x;
- if (odd && bmin <= d && d <= bmax && bd[bdiagoff + d] <= fd[fdiagoff + d])
- {
- cost = 2 * c - 1;
- return d;
- }
- }
-
- /* Similar extend the bottom-up search. */
- if (bmin > dmin)
- bd[bdiagoff + --bmin - 1] = Integer.MAX_VALUE;
- else
- ++bmin;
- if (bmax < dmax)
- bd[bdiagoff + ++bmax + 1] = Integer.MAX_VALUE;
- else
- --bmax;
- for (d = bmax; d >= bmin; d -= 2)
- {
- int x, y, oldx, tlo = bd[bdiagoff + d - 1], thi = bd[bdiagoff + d + 1];
-
- if (tlo < thi)
- x = tlo;
- else
- x = thi - 1;
- oldx = x;
- y = x - d;
- while (x > xoff && y > yoff && xv[x - 1] == yv[y - 1]) {
- --x; --y;
- }
- if (oldx - x > 20)
- big_snake = true;
- bd[bdiagoff + d] = x;
- if (!odd && fmin <= d && d <= fmax && bd[bdiagoff + d] <= fd[fdiagoff + d])
- {
- cost = 2 * c;
- return d;
- }
- }
-
- /* Heuristic: check occasionally for a diagonal that has made
- lots of progress compared with the edit distance.
- If we have any such, find the one that has made the most
- progress and return it as if it had succeeded.
-
- With this heuristic, for files with a constant small density
- of changes, the algorithm is linear in the file size. */
-
- if (c > 200 && big_snake && heuristic)
- {
- int best = 0;
- int bestpos = -1;
-
- for (d = fmax; d >= fmin; d -= 2)
- {
- int dd = d - fmid;
- if ((fd[fdiagoff + d] - xoff)*2 - dd > 12 * (c + (dd > 0 ? dd : -dd)))
- {
- if (fd[fdiagoff + d] * 2 - dd > best
- && fd[fdiagoff + d] - xoff > 20
- && fd[fdiagoff + d] - d - yoff > 20)
- {
- int k;
- int x = fd[fdiagoff + d];
-
- /* We have a good enough best diagonal;
- now insist that it end with a significant snake. */
- for (k = 1; k <= 20; k++)
- if (xvec[x - k] != yvec[x - d - k])
- break;
-
- if (k == 21)
- {
- best = fd[fdiagoff + d] * 2 - dd;
- bestpos = d;
- }
- }
- }
- }
- if (best > 0)
- {
- cost = 2 * c - 1;
- return bestpos;
- }
-
- best = 0;
- for (d = bmax; d >= bmin; d -= 2)
- {
- int dd = d - bmid;
- if ((xlim - bd[bdiagoff + d])*2 + dd > 12 * (c + (dd > 0 ? dd : -dd)))
- {
- if ((xlim - bd[bdiagoff + d]) * 2 + dd > best
- && xlim - bd[bdiagoff + d] > 20
- && ylim - (bd[bdiagoff + d] - d) > 20)
- {
- /* We have a good enough best diagonal;
- now insist that it end with a significant snake. */
- int k;
- int x = bd[bdiagoff + d];
-
- for (k = 0; k < 20; k++)
- if (xvec[x + k] != yvec[x - d + k])
- break;
- if (k == 20)
- {
- best = (xlim - bd[bdiagoff + d]) * 2 + dd;
- bestpos = d;
- }
- }
- }
- }
- if (best > 0)
- {
- cost = 2 * c - 1;
- return bestpos;
- }
- }
- }
- }
-
- /** Compare in detail contiguous subsequences of the two files
- which are known, as a whole, to match each other.
-
- The results are recorded in the vectors filevec[N].changed_flag, by
- storing a 1 in the element for each line that is an insertion or deletion.
-
- The subsequence of file 0 is [XOFF, XLIM) and likewise for file 1.
-
- Note that XLIM, YLIM are exclusive bounds.
- All line numbers are origin-0 and discarded lines are not counted. */
-
- private void compareseq (int xoff, int xlim, int yoff, int ylim) {
- /* Slide down the bottom initial diagonal. */
- while (xoff < xlim && yoff < ylim && xvec[xoff] == yvec[yoff]) {
- ++xoff; ++yoff;
- }
- /* Slide up the top initial diagonal. */
- while (xlim > xoff && ylim > yoff && xvec[xlim - 1] == yvec[ylim - 1]) {
- --xlim; --ylim;
- }
-
- /* Handle simple cases. */
- if (xoff == xlim)
- while (yoff < ylim)
- filevec[1].changed_flag[1+filevec[1].realindexes[yoff++]] = true;
- else if (yoff == ylim)
- while (xoff < xlim)
- filevec[0].changed_flag[1+filevec[0].realindexes[xoff++]] = true;
- else
- {
- /* Find a point of correspondence in the middle of the files. */
-
- int d = diag (xoff, xlim, yoff, ylim);
- int c = cost;
- int f = fdiag[fdiagoff + d];
- int b = bdiag[bdiagoff + d];
-
- if (c == 1)
- {
- /* This should be impossible, because it implies that
- one of the two subsequences is empty,
- and that case was handled above without calling `diag'.
- Let's verify that this is true. */
- throw new IllegalArgumentException("Empty subsequence");
- }
- else
- {
- /* Use that point to split this problem into two subproblems. */
- compareseq (xoff, b, yoff, b - d);
- /* This used to use f instead of b,
- but that is incorrect!
- It is not necessarily the case that diagonal d
- has a snake from b to f. */
- compareseq (b, xlim, b - d, ylim);
- }
- }
- }
-
- /** Discard lines from one file that have no matches in the other file.
- */
-
- private void discard_confusing_lines() {
- filevec[0].discard_confusing_lines(filevec[1]);
- filevec[1].discard_confusing_lines(filevec[0]);
- }
-
- private boolean inhibit = false;
-
- /** Adjust inserts/deletes of blank lines to join changes
- as much as possible.
- */
-
- private void shift_boundaries() {
- if (inhibit)
- return;
- filevec[0].shift_boundaries(filevec[1]);
- filevec[1].shift_boundaries(filevec[0]);
- }
-
- public interface ScriptBuilder {
- /** Scan the tables of which lines are inserted and deleted,
- producing an edit script.
- @param changed0 true for lines in first file which do not match 2nd
- @param len0 number of lines in first file
- @param changed1 true for lines in 2nd file which do not match 1st
- @param len1 number of lines in 2nd file
- @return a linked list of changes - or null
- */
- public change build_script(
- boolean[] changed0,int len0,
- boolean[] changed1,int len1
- );
- }
-
- /** Scan the tables of which lines are inserted and deleted,
- producing an edit script in reverse order. */
-
- static class ReverseScript implements ScriptBuilder {
- public change build_script(
- final boolean[] changed0,int len0,
- final boolean[] changed1,int len1)
- {
- change script = null;
- int i0 = 0, i1 = 0;
- while (i0 < len0 || i1 < len1) {
- if (changed0[1+i0] || changed1[1+i1]) {
- int line0 = i0, line1 = i1;
-
- /* Find # lines changed here in each file. */
- while (changed0[1+i0]) ++i0;
- while (changed1[1+i1]) ++i1;
-
- /* Record this change. */
- script = new change(line0, line1, i0 - line0, i1 - line1, script);
- }
-
- /* We have reached lines in the two files that match each other. */
- i0++; i1++;
- }
-
- return script;
- }
- }
-
- static class ForwardScript implements ScriptBuilder {
- /** Scan the tables of which lines are inserted and deleted,
- producing an edit script in forward order. */
- public change build_script(
- final boolean[] changed0,int len0,
- final boolean[] changed1,int len1)
- {
- change script = null;
- int i0 = len0, i1 = len1;
-
- while (i0 >= 0 || i1 >= 0)
- {
- if (changed0[i0] || changed1[i1])
- {
- int line0 = i0, line1 = i1;
-
- /* Find # lines changed here in each file. */
- while (changed0[i0]) --i0;
- while (changed1[i1]) --i1;
-
- /* Record this change. */
- script = new change(i0, i1, line0 - i0, line1 - i1, script);
- }
-
- /* We have reached lines in the two files that match each other. */
- i0--; i1--;
- }
-
- return script;
- }
- }
-
- /** Standard ScriptBuilders. */
- public final static ScriptBuilder
- forwardScript = new ForwardScript(),
- reverseScript = new ReverseScript();
-
- /* Report the differences of two files. DEPTH is the current directory
- depth. */
- public final change diff_2(final boolean reverse) {
- return diff(reverse ? reverseScript : forwardScript);
- }
-
- /** Get the results of comparison as an edit script. The script
- is described by a list of changes. The standard ScriptBuilder
- implementations provide for forward and reverse edit scripts.
- Alternate implementations could, for instance, list common elements
- instead of differences.
- @param bld an object to build the script from change flags
- @return the head of a list of changes
- */
- public change diff(final ScriptBuilder bld) {
-
- /* Some lines are obviously insertions or deletions
- because they don't match anything. Detect them now,
- and avoid even thinking about them in the main comparison algorithm. */
-
- discard_confusing_lines ();
-
- /* Now do the main comparison algorithm, considering just the
- undiscarded lines. */
-
- xvec = filevec[0].undiscarded;
- yvec = filevec[1].undiscarded;
-
- int diags =
- filevec[0].nondiscarded_lines + filevec[1].nondiscarded_lines + 3;
- fdiag = new int[diags];
- fdiagoff = filevec[1].nondiscarded_lines + 1;
- bdiag = new int[diags];
- bdiagoff = filevec[1].nondiscarded_lines + 1;
-
- compareseq (0, filevec[0].nondiscarded_lines,
- 0, filevec[1].nondiscarded_lines);
- fdiag = null;
- bdiag = null;
-
- /* Modify the results slightly to make them prettier
- in cases where that can validly be done. */
-
- shift_boundaries ();
-
- /* Get the results of comparison in the form of a chain
- of `struct change's -- an edit script. */
- return bld.build_script(
- filevec[0].changed_flag,
- filevec[0].buffered_lines,
- filevec[1].changed_flag,
- filevec[1].buffered_lines
- );
-
- }
-
- /** The result of comparison is an "edit script": a chain of change objects.
- Each change represents one place where some lines are deleted
- and some are inserted.
-
- LINE0 and LINE1 are the first affected lines in the two files (origin 0).
- DELETED is the number of lines deleted here from file 0.
- INSERTED is the number of lines inserted here in file 1.
-
- If DELETED is 0 then LINE0 is the number of the line before
- which the insertion was done; vice versa for INSERTED and LINE1. */
-
- public static class change {
- /** Previous or next edit command. */
- public change link;
- /** # lines of file 1 changed here. */
- public final int inserted;
- /** # lines of file 0 changed here. */
- public final int deleted;
- /** Line number of 1st deleted line. */
- public final int line0;
- /** Line number of 1st inserted line. */
- public final int line1;
-
- /** Cons an additional entry onto the front of an edit script OLD.
- LINE0 and LINE1 are the first affected lines in the two files (origin 0).
- DELETED is the number of lines deleted here from file 0.
- INSERTED is the number of lines inserted here in file 1.
-
- If DELETED is 0 then LINE0 is the number of the line before
- which the insertion was done; vice versa for INSERTED and LINE1. */
- public change(int line0, int line1, int deleted, int inserted, change old) {
- this.line0 = line0;
- this.line1 = line1;
- this.inserted = inserted;
- this.deleted = deleted;
- this.link = old;
- //System.err.println(line0+","+line1+","+inserted+","+deleted);
- }
- }
-
- /** Data on one input file being compared.
- */
-
- class file_data {
-
- /** Allocate changed array for the results of comparison. */
- void clear() {
- /* Allocate a flag for each line of each file, saying whether that line
- is an insertion or deletion.
- Allocate an extra element, always zero, at each end of each vector.
- */
- changed_flag = new boolean[buffered_lines + 2];
- }
-
- /** Return equiv_count[I] as the number of lines in this file
- that fall in equivalence class I.
- @return the array of equivalence class counts.
- */
- int[] equivCount() {
- int[] equiv_count = new int[equiv_max];
- for (int i = 0; i < buffered_lines; ++i)
- ++equiv_count[equivs[i]];
- return equiv_count;
- }
-
- /** Discard lines that have no matches in another file.
-
- A line which is discarded will not be considered by the actual
- comparison algorithm; it will be as if that line were not in the file.
- The file's `realindexes' table maps virtual line numbers
- (which don't count the discarded lines) into real line numbers;
- this is how the actual comparison algorithm produces results
- that are comprehensible when the discarded lines are counted.
-<p>
- When we discard a line, we also mark it as a deletion or insertion
- so that it will be printed in the output.
- @param f the other file
- */
- void discard_confusing_lines(file_data f) {
- clear();
- /* Set up table of which lines are going to be discarded. */
- final byte[] discarded = discardable(f.equivCount());
-
- /* Don't really discard the provisional lines except when they occur
- in a run of discardables, with nonprovisionals at the beginning
- and end. */
- filterDiscards(discarded);
-
- /* Actually discard the lines. */
- discard(discarded);
- }
-
- /** Mark to be discarded each line that matches no line of another file.
- If a line matches many lines, mark it as provisionally discardable.
- @see equivCount()
- @param counts The count of each equivalence number for the other file.
- @return 0=nondiscardable, 1=discardable or 2=provisionally discardable
- for each line
- */
-
- private byte[] discardable(final int[] counts) {
- final int end = buffered_lines;
- final byte[] discards = new byte[end];
- final int[] equivs = this.equivs;
- int many = 5;
- int tem = end / 64;
-
- /* Multiply MANY by approximate square root of number of lines.
- That is the threshold for provisionally discardable lines. */
- while ((tem = tem >> 2) > 0)
- many *= 2;
-
- for (int i = 0; i < end; i++)
- {
- int nmatch;
- if (equivs[i] == 0)
- continue;
- nmatch = counts[equivs[i]];
- if (nmatch == 0)
- discards[i] = 1;
- else if (nmatch > many)
- discards[i] = 2;
- }
- return discards;
- }
-
- /** Don't really discard the provisional lines except when they occur
- in a run of discardables, with nonprovisionals at the beginning
- and end. */
-
- private void filterDiscards(final byte[] discards) {
- final int end = buffered_lines;
-
- for (int i = 0; i < end; i++)
- {
- /* Cancel provisional discards not in middle of run of discards. */
- if (discards[i] == 2)
- discards[i] = 0;
- else if (discards[i] != 0)
- {
- /* We have found a nonprovisional discard. */
- int j;
- int length;
- int provisional = 0;
-
- /* Find end of this run of discardable lines.
- Count how many are provisionally discardable. */
- for (j = i; j < end; j++)
- {
- if (discards[j] == 0)
- break;
- if (discards[j] == 2)
- ++provisional;
- }
-
- /* Cancel provisional discards at end, and shrink the run. */
- while (j > i && discards[j - 1] == 2) {
- discards[--j] = 0; --provisional;
- }
-
- /* Now we have the length of a run of discardable lines
- whose first and last are not provisional. */
- length = j - i;
-
- /* If 1/4 of the lines in the run are provisional,
- cancel discarding of all provisional lines in the run. */
- if (provisional * 4 > length)
- {
- while (j > i)
- if (discards[--j] == 2)
- discards[j] = 0;
- }
- else
- {
- int consec;
- int minimum = 1;
- int tem = length / 4;
-
- /* MINIMUM is approximate square root of LENGTH/4.
- A subrun of two or more provisionals can stand
- when LENGTH is at least 16.
- A subrun of 4 or more can stand when LENGTH >= 64. */
- while ((tem = tem >> 2) > 0)
- minimum *= 2;
- minimum++;
-
- /* Cancel any subrun of MINIMUM or more provisionals
- within the larger run. */
- for (j = 0, consec = 0; j < length; j++)
- if (discards[i + j] != 2)
- consec = 0;
- else if (minimum == ++consec)
- /* Back up to start of subrun, to cancel it all. */
- j -= consec;
- else if (minimum < consec)
- discards[i + j] = 0;
-
- /* Scan from beginning of run
- until we find 3 or more nonprovisionals in a row
- or until the first nonprovisional at least 8 lines in.
- Until that point, cancel any provisionals. */
- for (j = 0, consec = 0; j < length; j++)
- {
- if (j >= 8 && discards[i + j] == 1)
- break;
- if (discards[i + j] == 2) {
- consec = 0; discards[i + j] = 0;
- }
- else if (discards[i + j] == 0)
- consec = 0;
- else
- consec++;
- if (consec == 3)
- break;
- }
-
- /* I advances to the last line of the run. */
- i += length - 1;
-
- /* Same thing, from end. */
- for (j = 0, consec = 0; j < length; j++)
- {
- if (j >= 8 && discards[i - j] == 1)
- break;
- if (discards[i - j] == 2) {
- consec = 0; discards[i - j] = 0;
- }
- else if (discards[i - j] == 0)
- consec = 0;
- else
- consec++;
- if (consec == 3)
- break;
- }
- }
- }
- }
- }
-
- /** Actually discard the lines.
- @param discards flags lines to be discarded
- */
- private void discard(final byte[] discards) {
- final int end = buffered_lines;
- int j = 0;
- for (int i = 0; i < end; ++i)
- if (no_discards || discards[i] == 0)
- {
- undiscarded[j] = equivs[i];
- realindexes[j++] = i;
- }
- else
- changed_flag[1+i] = true;
- nondiscarded_lines = j;
- }
-
- file_data(Object[] data,Hashtable h) {
- buffered_lines = data.length;
-
- equivs = new int[buffered_lines];
- undiscarded = new int[buffered_lines];
- realindexes = new int[buffered_lines];
-
- for (int i = 0; i < data.length; ++i) {
- Integer ir = (Integer)h.get(data[i]);
- if (ir == null)
- h.put(data[i],new Integer(equivs[i] = equiv_max++));
- else
- equivs[i] = ir.intValue();
- }
- }
-
- /** Adjust inserts/deletes of blank lines to join changes
- as much as possible.
-
- We do something when a run of changed lines include a blank
- line at one end and have an excluded blank line at the other.
- We are free to choose which blank line is included.
- `compareseq' always chooses the one at the beginning,
- but usually it is cleaner to consider the following blank line
- to be the "change". The only exception is if the preceding blank line
- would join this change to other changes.
- @param f the file being compared against
- */
-
- void shift_boundaries(file_data f) {
- final boolean[] changed = changed_flag;
- final boolean[] other_changed = f.changed_flag;
- int i = 0;
- int j = 0;
- int i_end = buffered_lines;
- int preceding = -1;
- int other_preceding = -1;
-
- for (;;)
- {
- int start, end, other_start;
-
- /* Scan forwards to find beginning of another run of changes.
- Also keep track of the corresponding point in the other file. */
-
- while (i < i_end && !changed[1+i])
- {
- while (other_changed[1+j++])
- /* Non-corresponding lines in the other file
- will count as the preceding batch of changes. */
- other_preceding = j;
- i++;
- }
-
- if (i == i_end)
- break;
-
- start = i;
- other_start = j;
-
- for (;;)
- {
- /* Now find the end of this run of changes. */
-
- while (i < i_end && changed[1+i]) i++;
- end = i;
-
- /* If the first changed line matches the following unchanged one,
- and this run does not follow right after a previous run,
- and there are no lines deleted from the other file here,
- then classify the first changed line as unchanged
- and the following line as changed in its place. */
-
- /* You might ask, how could this run follow right after another?
- Only because the previous run was shifted here. */
-
- if (end != i_end
- && equivs[start] == equivs[end]
- && !other_changed[1+j]
- && end != i_end
- && !((preceding >= 0 && start == preceding)
- || (other_preceding >= 0
- && other_start == other_preceding)))
- {
- changed[1+end++] = true;
- changed[1+start++] = false;
- ++i;
- /* Since one line-that-matches is now before this run
- instead of after, we must advance in the other file
- to keep in synch. */
- ++j;
- }
- else
- break;
- }
-
- preceding = i;
- other_preceding = j;
- }
- }
-
- /** Number of elements (lines) in this file. */
- final int buffered_lines;
-
- /** Vector, indexed by line number, containing an equivalence code for
- each line. It is this vector that is actually compared with that
- of another file to generate differences. */
- private final int[] equivs;
-
- /** Vector, like the previous one except that
- the elements for discarded lines have been squeezed out. */
- final int[] undiscarded;
-
- /** Vector mapping virtual line numbers (not counting discarded lines)
- to real ones (counting those lines). Both are origin-0. */
- final int[] realindexes;
-
- /** Total number of nondiscarded lines. */
- int nondiscarded_lines;
-
- /** Array, indexed by real origin-1 line number,
- containing true for a line that is an insertion or a deletion.
- The results of comparison are stored here. */
- boolean[] changed_flag;
-
- }
-}
diff --git a/sources/scala/tools/scalatest/Diff.txt b/sources/scala/tools/scalatest/Diff.txt
deleted file mode 100644
index 0f475ada1d..0000000000
--- a/sources/scala/tools/scalatest/Diff.txt
+++ /dev/null
@@ -1,16 +0,0 @@
-
-GNU Diff for Java
-
-I have translated the GNU Diff algorithm to a Java class. The Diff class computes the differences between two Object arrays as a list of changes. This is very general purpose. Any of the options to GNU diff can be efficiently implemented as variations on how Object.equals() is implemented and how the change list is printed.
-
-Many people have asked me to change the license to LGPL. My port is based on GNU Diff, which is GPL. Until someone convinces me otherwise, I don't believe that I have the right to change the license. I have corresponded with the copyright holders of GNU Diff, and they are unwilling to change the license. Their position is that the GPL helps force companies to GPL more code in order to use existing GPL code.
-
-The GPL restrictions do not apply to purely dynamically loaded code (otherwise, you would be unable to run GNU diff on a proprietary OS). When I get some time, I (or anyone who beats me to it) will create a plugin API so that applications can compile against an LGPL interface, and load the GPL implementation at runtime. This will also make comparing the performance of diff algorithms very convenient. While all Java classes are dynamically loaded at runtime, directly referenced classes are also used at compile time, and thus might be considered in violation of the GPL.
-# Diff.java The Diff algorithm
-# DiffPrint.java A base class for printing the change list in 'ed' style to test the algorithm. Could form the basis for a complete Java implementation of all the GNU diff comparison and output options.
-TODO
-Publish the revised interface that simplifies doing things with elements that are the same (as opposed to the usual requirement of dealing with just those that are different).
-
-Stuart D. Gathman
-
-[Source: http://www.bmsi.com/java/#diff]
diff --git a/sources/scala/tools/scalatest/DiffPrint.java b/sources/scala/tools/scalatest/DiffPrint.java
deleted file mode 100644
index 5cd9e22c6e..0000000000
--- a/sources/scala/tools/scalatest/DiffPrint.java
+++ /dev/null
@@ -1,578 +0,0 @@
-/* $Log$
- * Revision 1.1 2003/10/13 16:00:11 michelou
- * - Java implementation of GNU diff (GPL licence)
- *
- * Revision 1.4 2003/04/22 01:50:47 stuart
- * add Unified format diff
- *
- * Revision 1.3 2003/04/22 01:00:32 stuart
- * added context diff format
- *
- * Revision 1.2 2000/03/02 16:59:54 stuart
- * add GPL
- *
- */
-
-//package bmsi.util;
-package scala.tools.scalatest;
-
-import java.io.*;
-import java.util.Vector;
-import java.util.Date;
-//import bmsi.util.Diff;
-//import com.objectspace.jgl.predicates.UnaryPredicate;
-
-interface UnaryPredicate {
- boolean execute(Object obj);
-}
-
-/** A simple framework for printing change lists produced by <code>Diff</code>.
- @see bmsi.util.Diff
- @author Stuart D. Gathman
- Copyright (C) 2000 Business Management Systems, Inc.
-<p>
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 1, or (at your option)
- any later version.
-<p>
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-<p>
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-public class DiffPrint {
- /** A Base class for printing edit scripts produced by Diff.
- This class divides the change list into "hunks", and calls
- <code>print_hunk</code> for each hunk. Various utility methods
- are provided as well.
- */
- public static abstract class Base {
- protected Base(Object[] a,Object[] b) {
- outfile = new PrintWriter(new OutputStreamWriter(System.out));
- file0 = a;
- file1 = b;
- }
- /** Set to ignore certain kinds of lines when printing
- an edit script. For example, ignoring blank lines or comments.
- */
- protected UnaryPredicate ignore = null;
-
- /** Set to the lines of the files being compared.
- */
- protected Object[] file0, file1;
-
- /** Divide SCRIPT into pieces by calling HUNKFUN and
- print each piece with PRINTFUN.
- Both functions take one arg, an edit script.
-
- PRINTFUN takes a subscript which belongs together (with a null
- link at the end) and prints it. */
- public void print_script(Diff.change script) {
- Diff.change next = script;
-
- while (next != null)
- {
- Diff.change t, end;
-
- /* Find a set of changes that belong together. */
- t = next;
- end = hunkfun(next);
-
- /* Disconnect them from the rest of the changes,
- making them a hunk, and remember the rest for next iteration. */
- next = end.link;
- end.link = null;
- //if (DEBUG)
- // debug_script(t);
-
- /* Print this hunk. */
- print_hunk(t);
-
- /* Reconnect the script so it will all be freed properly. */
- end.link = next;
- }
- outfile.flush();
- }
-
- /** Called with the tail of the script
- and returns the last link that belongs together with the start
- of the tail. */
-
- protected Diff.change hunkfun(Diff.change hunk) {
- return hunk;
- }
-
- protected int first0, last0, first1, last1, deletes, inserts;
- protected PrintWriter outfile;
-
- /** Look at a hunk of edit script and report the range of lines in each file
- that it applies to. HUNK is the start of the hunk, which is a chain
- of `struct change'. The first and last line numbers of file 0 are stored
- in *FIRST0 and *LAST0, and likewise for file 1 in *FIRST1 and *LAST1.
- Note that these are internal line numbers that count from 0.
-
- If no lines from file 0 are deleted, then FIRST0 is LAST0+1.
-
- Also set *DELETES nonzero if any lines of file 0 are deleted
- and set *INSERTS nonzero if any lines of file 1 are inserted.
- If only ignorable lines are inserted or deleted, both are
- set to 0. */
-
- protected void analyze_hunk(Diff.change hunk) {
- int f0, l0 = 0, f1, l1 = 0, show_from = 0, show_to = 0;
- int i;
- Diff.change next;
- boolean nontrivial = (ignore == null);
-
- show_from = show_to = 0;
-
- f0 = hunk.line0;
- f1 = hunk.line1;
-
- for (next = hunk; next != null; next = next.link)
- {
- l0 = next.line0 + next.deleted - 1;
- l1 = next.line1 + next.inserted - 1;
- show_from += next.deleted;
- show_to += next.inserted;
- for (i = next.line0; i <= l0 && ! nontrivial; i++)
- if (!ignore.execute(file0[i]))
- nontrivial = true;
- for (i = next.line1; i <= l1 && ! nontrivial; i++)
- if (!ignore.execute(file1[i]))
- nontrivial = true;
- }
-
- first0 = f0;
- last0 = l0;
- first1 = f1;
- last1 = l1;
-
- /* If all inserted or deleted lines are ignorable,
- tell the caller to ignore this hunk. */
-
- if (!nontrivial)
- show_from = show_to = 0;
-
- deletes = show_from;
- inserts = show_to;
- }
-
- /** Print the script header which identifies the files compared. */
- protected void print_header(String filea, String fileb) { }
-
- protected abstract void print_hunk(Diff.change hunk);
-
- protected void print_1_line(String pre,Object linbuf) {
- outfile.println(pre + linbuf.toString());
- }
-
- /** Print a pair of line numbers with SEPCHAR, translated for file FILE.
- If the two numbers are identical, print just one number.
-
- Args A and B are internal line numbers.
- We print the translated (real) line numbers. */
-
- protected void print_number_range (char sepchar, int a, int b) {
- /* Note: we can have B < A in the case of a range of no lines.
- In this case, we should print the line number before the range,
- which is B. */
- if (++b > ++a)
- outfile.print("" + a + sepchar + b);
- else
- outfile.print(b);
- }
-
- public static char change_letter(int inserts, int deletes) {
- if (inserts == 0)
- return 'd';
- else if (deletes == 0)
- return 'a';
- else
- return 'c';
- }
- }
-
- /** Print a change list in the standard diff format.
- */
- public static class NormalPrint extends Base {
-
- public NormalPrint(Object[] a,Object[] b) {
- super(a,b);
- }
-
- /** Print a hunk of a normal diff.
- This is a contiguous portion of a complete edit script,
- describing changes in consecutive lines. */
-
- protected void print_hunk (Diff.change hunk) {
-
- /* Determine range of line numbers involved in each file. */
- analyze_hunk(hunk);
- if (deletes == 0 && inserts == 0)
- return;
-
- /* Print out the line number header for this hunk */
- print_number_range (',', first0, last0);
- outfile.print(change_letter(inserts, deletes));
- print_number_range (',', first1, last1);
- outfile.println();
-
- /* Print the lines that the first file has. */
- if (deletes != 0)
- for (int i = first0; i <= last0; i++)
- print_1_line ("< ", file0[i]);
-
- if (inserts != 0 && deletes != 0)
- outfile.println("---");
-
- /* Print the lines that the second file has. */
- if (inserts != 0)
- for (int i = first1; i <= last1; i++)
- print_1_line ("> ", file1[i]);
- }
- }
-
- /** Prints an edit script in a format suitable for input to <code>ed</code>.
- The edit script must be generated with the reverse option to
- be useful as actual <code>ed</code> input.
- */
- public static class EdPrint extends Base {
-
- public EdPrint(Object[] a,Object[] b) {
- super(a,b);
- }
-
- /** Print a hunk of an ed diff */
- protected void print_hunk(Diff.change hunk) {
-
- /* Determine range of line numbers involved in each file. */
- analyze_hunk (hunk);
- if (deletes == 0 && inserts == 0)
- return;
-
- /* Print out the line number header for this hunk */
- print_number_range (',', first0, last0);
- outfile.println(change_letter(inserts, deletes));
-
- /* Print new/changed lines from second file, if needed */
- if (inserts != 0)
- {
- boolean inserting = true;
- for (int i = first1; i <= last1; i++)
- {
- /* Resume the insert, if we stopped. */
- if (! inserting)
- outfile.println(i - first1 + first0 + "a");
- inserting = true;
-
- /* If the file's line is just a dot, it would confuse `ed'.
- So output it with a double dot, and set the flag LEADING_DOT
- so that we will output another ed-command later
- to change the double dot into a single dot. */
-
- if (".".equals(file1[i]))
- {
- outfile.println("..");
- outfile.println(".");
- /* Now change that double dot to the desired single dot. */
- outfile.println(i - first1 + first0 + 1 + "s/^\\.\\././");
- inserting = false;
- }
- else
- /* Line is not `.', so output it unmodified. */
- print_1_line ("", file1[i]);
- }
-
- /* End insert mode, if we are still in it. */
- if (inserting)
- outfile.println(".");
- }
- }
- }
-
- /** Prints an edit script in context diff format. This and its
- 'unified' variation is used for source code patches.
- */
- public static class ContextPrint extends Base {
-
- protected int context = 3;
-
- public ContextPrint(Object[] a,Object[] b) {
- super(a,b);
- }
-
- protected void print_context_label (String mark, File inf, String label) {
- if (label != null)
- outfile.println(mark + ' ' + label);
- else if (inf.lastModified() > 0)
- // FIXME: use DateFormat to get precise format needed.
- outfile.println(
- mark + ' ' + inf.getPath() + '\t' + new Date(inf.lastModified())
- );
- else
- /* Don't pretend that standard input is ancient. */
- outfile.println(mark + ' ' + inf.getPath());
- }
-
- public void print_header(String filea,String fileb) {
- print_context_label ("***", new File(filea), filea);
- print_context_label ("---", new File(fileb), fileb);
- }
-
- /** If function_regexp defined, search for start of function. */
- private String find_function(Object[] lines, int start) {
- return null;
- }
-
- protected void print_function(Object[] file,int start) {
- String function = find_function (file0, first0);
- if (function != null) {
- outfile.print(" ");
- outfile.print(
- (function.length() < 40) ? function : function.substring(0,40)
- );
- }
- }
-
- protected void print_hunk(Diff.change hunk) {
-
- /* Determine range of line numbers involved in each file. */
-
- analyze_hunk (hunk);
-
- if (deletes == 0 && inserts == 0)
- return;
-
- /* Include a context's width before and after. */
-
- first0 = Math.max(first0 - context, 0);
- first1 = Math.max(first1 - context, 0);
- last0 = Math.min(last0 + context, file0.length - 1);
- last1 = Math.min(last1 + context, file1.length - 1);
-
-
- outfile.print("***************");
-
- /* If we looked for and found a function this is part of,
- include its name in the header of the diff section. */
- print_function (file0, first0);
-
- outfile.println();
- outfile.print("*** ");
- print_number_range (',', first0, last0);
- outfile.println(" ****");
-
- if (deletes != 0) {
- Diff.change next = hunk;
-
- for (int i = first0; i <= last0; i++) {
- /* Skip past changes that apply (in file 0)
- only to lines before line I. */
-
- while (next != null && next.line0 + next.deleted <= i)
- next = next.link;
-
- /* Compute the marking for line I. */
-
- String prefix = " ";
- if (next != null && next.line0 <= i)
- /* The change NEXT covers this line.
- If lines were inserted here in file 1, this is "changed".
- Otherwise it is "deleted". */
- prefix = (next.inserted > 0) ? "!" : "-";
-
- print_1_line (prefix, file0[i]);
- }
- }
-
- outfile.print("--- ");
- print_number_range (',', first1, last1);
- outfile.println(" ----");
-
- if (inserts != 0) {
- Diff.change next = hunk;
-
- for (int i = first1; i <= last1; i++) {
- /* Skip past changes that apply (in file 1)
- only to lines before line I. */
-
- while (next != null && next.line1 + next.inserted <= i)
- next = next.link;
-
- /* Compute the marking for line I. */
-
- String prefix = " ";
- if (next != null && next.line1 <= i)
- /* The change NEXT covers this line.
- If lines were deleted here in file 0, this is "changed".
- Otherwise it is "inserted". */
- prefix = (next.deleted > 0) ? "!" : "+";
-
- print_1_line (prefix, file1[i]);
- }
- }
- }
- }
-
- /** Prints an edit script in context diff format. This and its
- 'unified' variation is used for source code patches.
- */
- public static class UnifiedPrint extends ContextPrint {
-
- public UnifiedPrint(Object[] a,Object[] b) {
- super(a,b);
- }
-
- public void print_header(String filea,String fileb) {
- print_context_label ("---", new File(filea), filea);
- print_context_label ("+++", new File(fileb), fileb);
- }
-
- private void print_number_range (int a, int b) {
- //translate_range (file, a, b, &trans_a, &trans_b);
-
- /* Note: we can have B < A in the case of a range of no lines.
- In this case, we should print the line number before the range,
- which is B. */
- if (b < a)
- outfile.print(b + ",0");
- else
- super.print_number_range(',',a,b);
- }
-
- protected void print_hunk(Diff.change hunk) {
- /* Determine range of line numbers involved in each file. */
- analyze_hunk (hunk);
-
- if (deletes == 0 && inserts == 0)
- return;
-
- /* Include a context's width before and after. */
-
- first0 = Math.max(first0 - context, 0);
- first1 = Math.max(first1 - context, 0);
- last0 = Math.min(last0 + context, file0.length - 1);
- last1 = Math.min(last1 + context, file1.length - 1);
-
-
-
- outfile.print("@@ -");
- print_number_range (first0, last0);
- outfile.print(" +");
- print_number_range (first1, last1);
- outfile.print(" @@");
-
- /* If we looked for and found a function this is part of,
- include its name in the header of the diff section. */
- print_function(file0,first0);
-
- outfile.println();
-
- Diff.change next = hunk;
- int i = first0;
- int j = first1;
-
- while (i <= last0 || j <= last1) {
-
- /* If the line isn't a difference, output the context from file 0. */
-
- if (next == null || i < next.line0) {
- outfile.print(' ');
- print_1_line ("", file0[i++]);
- j++;
- }
- else {
- /* For each difference, first output the deleted part. */
-
- int k = next.deleted;
- while (k-- > 0) {
- outfile.print('-');
- print_1_line ("", file0[i++]);
- }
-
- /* Then output the inserted part. */
-
- k = next.inserted;
- while (k-- > 0) {
- outfile.print('+');
- print_1_line ("", file1[j++]);
- }
-
- /* We're done with this hunk, so on to the next! */
-
- next = next.link;
- }
- }
- }
- }
-
-
- /** Read a text file into an array of String. This provides basic diff
- functionality. A more advanced diff utility will use specialized
- objects to represent the text lines, with options to, for example,
- convert sequences of whitespace to a single space for comparison
- purposes.
- */
- static String[] slurp(String file) throws IOException {
- BufferedReader rdr = new BufferedReader(new FileReader(file));
- Vector s = new Vector();
- for (;;) {
- String line = rdr.readLine();
- if (line == null) break;
- s.addElement(line);
- }
- String[] a = new String[s.size()];
- s.copyInto(a);
- return a;
- }
-
- public static void main(String[] argv) throws IOException {
- String filea = argv[argv.length - 2];
- String fileb = argv[argv.length - 1];
- String[] a = slurp(filea);
- String[] b = slurp(fileb);
- Diff d = new Diff(a,b);
- char style = 'n';
- for (int i = 0; i < argv.length - 2; ++i) {
- String f = argv[i];
- if (f.startsWith("-")) {
- for (int j = 1; j < f.length(); ++j) {
- switch (f.charAt(j)) {
- case 'e': // Ed style
- style = 'e'; break;
- case 'c': // Context diff
- style = 'c'; break;
- case 'u':
- style = 'u'; break;
- }
- }
- }
- }
- boolean reverse = style == 'e';
- Diff.change script = d.diff_2(reverse);
- if (script == null)
- System.err.println("No differences");
- else {
- Base p;
- switch (style) {
- case 'e':
- p = new EdPrint(a,b); break;
- case 'c':
- p = new ContextPrint(a,b); break;
- case 'u':
- p = new UnifiedPrint(a,b); break;
- default:
- p = new NormalPrint(a,b);
- }
- p.print_header(filea,fileb);
- p.print_script(script);
- }
- }
-
-}
diff --git a/sources/scala/tools/scalatest/FileUtils.java b/sources/scala/tools/scalatest/FileUtils.java
deleted file mode 100644
index f0437ad658..0000000000
--- a/sources/scala/tools/scalatest/FileUtils.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/* ___ ____ ___ __ ___ _____
-** / _// __// _ | / / / _ |/_ _/ Scala test
-** __\ \/ /__/ __ |/ /__/ __ | / / (c) 2003, LAMP/EPFL
-** /____/\___/_/ |_/____/_/ |_//_/
-**
-** $Id$
-*/
-
-package scala.tools.scalatest;
-
-import java.io.BufferedOutputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.PrintStream;
-
-
-class FileUtils {
-
- public final static String FILE_SEP = System.getProperty("file.separator");
- public final static String PATH_SEP = System.getProperty("path.separator");
-
- /**
- * Creates a new directory.
- * If id
- */
- public static boolean createDir(File dir) {
- deleteDir(dir);
- return dir.mkdirs();
- }
-
- /**
- * Deletes all files and subdirectories under <code>dir</code>.
- * Returns <code>true</code> if all deletions were successful.
- * If a deletion fails, the method stops attempting to delete and returns false.
- * (see http://javaalmanac.com/egs/java.io/DeleteDir.html)
- */
- public static boolean deleteDir(File dir) {
- if (dir.isDirectory()) {
- String[] children = dir.list();
- for (int i = 0; i < children.length; i++) {
- boolean success = deleteDir(new File(dir, children[i]));
- if (!success) {
- return false;
- }
- }
- }
-
- // The directory is now empty so delete it
- return dir.delete();
- }
-
- /**
- * Returns the default temporary-file directory.
- */
- public static File getTempDir() {
- File dir = null;
- try {
- File dummy = File.createTempFile("dummy", null);
- dir = dummy.getParentFile();
- dummy.delete();
- } catch (IOException e) {}
- return dir;
- }
-
- /**
- * Compares two files using a Java implementation of the GNU diff
- * available at http://www.bmsi.com/java/#diff.
- *
- * @param f1
- * @param f2
- */
- public static String compareFiles(File f1, File f2) {
- String res = null;
- try {
- ByteArrayOutputStream diffStream = new ByteArrayOutputStream();
- PrintStream diffOutput = new PrintStream(
- new BufferedOutputStream(diffStream), true);
- System.setOut(diffOutput);
- System.setErr(diffOutput);
- DiffPrint.main(new String[]{ f1.getCanonicalPath(), f2.getCanonicalPath() });
- System.setOut(System.out);
- System.setErr(System.err);
- res = diffStream.toString();
- if (res.startsWith("No"))
- res = "";
- } catch (IOException e) {}
- return res;
- }
-
-}
diff --git a/sources/scala/tools/scalatest/Main.java b/sources/scala/tools/scalatest/Main.java
deleted file mode 100644
index b2e9267609..0000000000
--- a/sources/scala/tools/scalatest/Main.java
+++ /dev/null
@@ -1,673 +0,0 @@
-/* ___ ____ ___ __ ___ _____
-** / _// __// _ | / / / _ |/_ _/ Scala test
-** __\ \/ /__/ __ |/ /__/ __ | / / (c) 2003, LAMP/EPFL
-** /____/\___/_/ |_/____/_/ |_//_/
-**
-** $Id$
-*/
-
-package scala.tools.scalatest;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FilenameFilter;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.InputStreamReader;
-import java.io.IOException;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.ListIterator;
-
-
-/**
- *
- */
-public class Main {
-
- //########################################################################
- // Private Constants
-
- private final static String PRODUCT = "scalatest";
- private final static String VERSION = "1.02";
- private final static String COPYRIGHT = "(c) 2002-03 LAMP/EPFL";
- private final static String AUTHORS =
- "Philippe Altherr & Stephane Micheloud";
-
- private static String SCALA_HOME =
- System.getProperty("scala.home");
- private static String SCALA_BINPATH = SCALA_HOME + "/bin";
- private static String SCALA_TESTPATH = SCALA_HOME + "/test";
-
- private final static String NAME_DTDFILE = "dtd";
-
- private final static String SUFFIX_OBJDIR = "-obj";
- private final static String SUFFIX_CHECKFILE = ".check";
- private final static String SUFFIX_DTDFILE = ".dtd";
- private final static String SUFFIX_LOGFILE = ".log";
- private final static String SUFFIX_SCALAFILE = ".scala";
- private final static String SUFFIX_XMLFILE = ".xml";
-
- private final static String HEADER_TESTING = "testing: ";
- private final static String HEADER_VERBOSE = "debug: ";
-
- /**
- * Color modes
- */
- private final int NONE = 0;
- private final int SOME = 1;
- private final int MANY = 2;
-
- /**
- * Test types
- */
- private final int AUTO = 0;
- private final int RUN = 1;
- private final int INT = 2;
- private final int JVM = 3;
- private final int XML = 4;
- private final int POS = 5;
- private final int NEG = 6;
-
- //########################################################################
- // Private Variables
-
- private boolean noRun = false;
- private boolean showLog = false;
- private boolean showDiff = false;
- private boolean failed = false;
- private int verbose = 0;
- private int errors = 0;
-// private int successCount = 0;
-
- private boolean testAll = true;
- private int testType = AUTO;
-
- /**
- * Test files grouped by type
- */
- private List/*String*/ filesRUN = new ArrayList();
- private List/*String*/ filesINT = new ArrayList();
- private List/*String*/ filesJVM = new ArrayList();
- private List/*String*/ filesXML = new ArrayList();
- private List/*String*/ filesPOS = new ArrayList();
- private List/*String*/ filesNEG = new ArrayList();
-
- /**
- * Used to format output
- */
- private Console console = new Console();
- private StringBuffer blanks = new StringBuffer(" ");
-
- private String colorOutline;
- private String colorSuccess;
- private String colorFailure;
- private String colorWarning;
- private String colorNormal;
-
- private String statusSuccess = " OK ";
- private String statusFailed = "FAILED";
-
- /**
- * Test paths
- */
- private String objDir = getTempDirectory(SCALA_TESTPATH);
-
- private final String filesDir = "files" + FileUtils.FILE_SEP;
- private final String runDir = filesDir + "run" + FileUtils.FILE_SEP;
- private final String jvmDir = filesDir + "jvm" + FileUtils.FILE_SEP;
- private final String xmlDir = filesDir + "xml" + FileUtils.FILE_SEP;
- private final String posDir = "pos" + FileUtils.FILE_SEP;
- private final String coursDir = "cours" + FileUtils.FILE_SEP;
- private final String negDir = "neg" + FileUtils.FILE_SEP;
-
- /**
- * Scala tools
- */
- private String scala = getExecutable("scala");
- private String scalac = getExecutable("scalac");
- private String scalarun = getExecutable("scalarun");
- private String dtd2scala = getExecutable("dtd2scala");
-// private String scalainfo = getExecutable("scala-info");
-
- /**
- * Command lines executed in the tests
- */
- private MessageFormat scalaCmdLine;
- private MessageFormat scalacCmdLine;
- private MessageFormat scalarunCmdLine;
- private MessageFormat dtd2scalaCmdLine;
-
- /**
- * Test options
- */
- private String flags = "";
- private int color = MANY;
-
- //########################################################################
- // Private Static Functions
-
- private static String getExecutable(String name) {
- return SCALA_BINPATH + FileUtils.FILE_SEP + name;
- }
-
- private static String getTempDirectory(String defaultDir) {
- String tempDir = defaultDir;
- File dir = FileUtils.getTempDir();
- if (dir != null) {
- dir = new File(dir, PRODUCT);
- try {
- dir.mkdir();
- tempDir = dir.getCanonicalPath() + FileUtils.FILE_SEP;
- } catch (Exception e) {}
- }
- return tempDir;
- }
-
- //########################################################################
- // Private Functions
-
- private void abort(String message) {
- console.println(message);
- System.exit(1);
- }
-
- private void printUsage() {
- console.println("Usage: " + PRODUCT + " [OPTION]...");
- }
-
- private void printHelp() {
- printUsage();
- console.println();
- console.println("--auto use filenames to select the test to run");
- console.println("--run next files test the interpreter and all backends");
- console.println("--int next files test the interpreter");
- console.println("--jvm next files test the jvm backend");
- console.println("--xml next files test the dtd2scala tool");
- console.println("--pos next files test a compilation success");
- console.println("--neg next files test a compilation failure");
- console.println("--no-run run no test, use results of last run");
- console.println("--show-log show output of failed tests");
- console.println("--show-diff show differences between actual and expected output");
- console.println("--failed test only files that failed last time");
- console.println("--verbose=LEVEL display debug information (LEVEL=0|1|2)");
- console.println("--errors=<int> specify the number of expected errors");
- console.println("--flags=<flags> specify flags to pass on to the executable");
- console.println("--color=USAGE control the color usage (USAGE=none|some|many)");
- console.println("--objdir=<dir> specify where to place generated files");
- console.println("--help, -? display this help and exit");
- console.println("--version output version information and exit");
- }
-
- private void printVersion() {
- console.println(PRODUCT + " " + VERSION + ", " + COPYRIGHT);
- console.println("Written by " + AUTHORS);
- }
-
- private void printOutline(String s) {
- console.print(colorOutline + s + colorNormal);
- }
-
- private void printSuccess(String s) {
- console.print(colorSuccess + s + colorNormal);
- }
-
- private void printFailure(String s) {
- console.print(colorFailure + s + colorNormal);
- }
-
- private void printStatus(String message, boolean success) {
- int n = 70 - message.length();
- while (blanks.length() < n) blanks.append(" ");
- if (n > 0)
- console.print(blanks.substring(blanks.length() - n));
- console.println((success) ? statusSuccess : statusFailed);
- }
-
- private void printLog(File log) {
- try {
- BufferedReader rd = new BufferedReader(new FileReader(log));
- String s;
- while ((s = rd.readLine()) != null)
- console.println(s);
- } catch (Exception e) {
- // FileNotFoundException or IOException
- }
- }
-
- private String getDiff(File logFile, String name) {
- String diff = "";
- File checkFile =
- new File(SCALA_TESTPATH, name + SUFFIX_CHECKFILE);
- if (checkFile.isFile()) {
- diff = FileUtils.compareFiles(logFile, checkFile);
- }
- return diff;
- }
-
- private abstract class TestCommand extends Command {
- private String message;
- protected boolean success;
- protected String name;
- protected File logFile;
- protected File outDir;
-
- TestCommand(Console console) { super(console); }
-
- protected void pre(String arg, boolean create) {
- int inx = arg.lastIndexOf('.');
- name = (inx < 0) ? arg : arg.substring(0, inx);
- if (testAll)
- name = SCALA_TESTPATH + FileUtils.FILE_SEP + name;
- if (verbose > 1)
- console.println(HEADER_VERBOSE + "diff "
- + objDir + name + SUFFIX_LOGFILE + " "
- + name + SUFFIX_CHECKFILE);
- message = HEADER_TESTING + arg;
- outDir = new File(objDir, name + SUFFIX_OBJDIR);
- FileUtils.createDir(outDir);
- logFile = new File(objDir, name + SUFFIX_LOGFILE);
- success = false;
- }
-
- protected void printMessage() {
- assert message != null;
- printOutline(message);
- }
-
- protected void post() {
- assert message != null;
- String diff = "";
- if (success) {
- diff = getDiff(logFile, name);
- success = diff.length() == 0;
- }
- printStatus(message, success);
- if (! success) {
- if (showLog)
- printLog(logFile);
- if (showDiff)
- console.println(diff);
- }
- if (outDir != null)
- FileUtils.deleteDir(outDir);
- }
- }
-
- private String makeCmdLine(MessageFormat f, Object[] objs) {
- String cmdLine = f.format(objs);
- if (verbose > 0)
- console.println(HEADER_VERBOSE + cmdLine);
- return cmdLine;
- }
-
- private class InterpretationCommand extends TestCommand {
- InterpretationCommand(Console console) { super(console); }
-
- public boolean run(String arg) {
- pre(arg, false);
-
- String cmdLine =
- makeCmdLine(scalarunCmdLine, new Object[]{ flags, arg });
-
- printMessage();
- try {
- success = execute(cmdLine, new FileOutputStream(logFile)) >= 0;
- } catch (FileNotFoundException e) {}
-
- post();
- return success;
- }
- }
-
- private class InterpretationTest extends Test {
- InterpretationTest(List[] groups) {
- super("Testing interpreter", groups);
- }
- public int run() {
- return filesCount - run(new InterpretationCommand(console));
- }
- }
-
- private class CompilationCommand extends TestCommand {
- CompilationCommand(Console console) { super(console); }
-
- public boolean run(String arg) {
- pre(arg, true);
-
- String outpath = objDir + name + SUFFIX_OBJDIR;
- String cmdLine1 = makeCmdLine(
- scalacCmdLine,
- new Object[]{ outpath , flags, "", name + SUFFIX_SCALAFILE });
- String cmdLine2 = makeCmdLine(
- scalaCmdLine,
- new Object[]{ outpath, "" });
-
- printMessage();
- try {
- success = execute(cmdLine1) >= 0 &&
- execute(cmdLine2, new FileOutputStream(logFile)) >= 0;
- } catch (FileNotFoundException e) {}
-
- post();
- return success;
- }
- }
-
- private class CompilationTest extends Test {
- CompilationTest(List[] groups) {
- super("Testing jvm backend", groups);
- }
- public int run() {
- return filesCount - run(new CompilationCommand(console));
- }
- }
-
- private class XMLCommand extends TestCommand {
- XMLCommand(Console console) { super(console); }
-
- public boolean run(String arg) {
- pre(arg, true);
-
- String outpath = objDir + name + SUFFIX_OBJDIR;
- String dtdFile = name + SUFFIX_DTDFILE;
- String objFile = outpath + FileUtils.FILE_SEP
- + NAME_DTDFILE + SUFFIX_SCALAFILE;
- String xmlFile = SCALA_TESTPATH + FileUtils.FILE_SEP
- + name + SUFFIX_XMLFILE;
- String cmdLine1 = makeCmdLine(
- dtd2scalaCmdLine,
- new Object[]{ outpath, dtdFile });
- String cmdLine2 = makeCmdLine(
- scalacCmdLine,
- new Object[]{ outpath, flags, objFile, name + SUFFIX_SCALAFILE });
- String cmdLine3 = makeCmdLine(
- scalaCmdLine,
- new Object[]{ outpath, xmlFile });
-
- printMessage();
- try {
- success = execute(cmdLine1) >= 0
- && execute(cmdLine2) >= 0
- && execute(cmdLine3, new FileOutputStream(logFile)) >= 0;
- } catch (FileNotFoundException e) {}
-
- post();
- return success;
- }
- }
-
- private class XMLTest extends Test {
- XMLTest(List/*String*/ files) {
- super("Testing dtd2scala", new List[]{ files });
- }
- public int run() {
- return filesCount - run(new XMLCommand(console));
- }
- }
-
- private class SuccessCommand extends TestCommand {
- SuccessCommand(Console console) { super(console); }
-
- public boolean run(String arg) {
- pre(arg, true);
-
- String outpath = objDir + name + SUFFIX_OBJDIR;
- String cmdLine = makeCmdLine(
- scalacCmdLine,
- new Object[]{ outpath, flags, "", name + SUFFIX_SCALAFILE });
-
- printMessage();
- try {
- success = execute(cmdLine, new FileOutputStream(logFile)) >= 0;
- } catch (FileNotFoundException e) {}
-
- post();
- return success;
- }
- }
-
- private class SuccessTest extends Test {
- SuccessTest(List/*String*/ files) {
- super("Testing compiler "
- + "(on files whose compilation should succeed)",
- new List[]{ files });
- }
- public int run() {
- return filesCount - run(new SuccessCommand(console));
- }
- }
-
- private class FailureCommand extends TestCommand {
- FailureCommand(Console console) { super(console); }
-
- public boolean run(String arg) {
- pre(arg, true);
-
- String outpath = objDir + name + SUFFIX_OBJDIR;
- String cmdLine = makeCmdLine(
- scalacCmdLine,
- new Object[]{ outpath, flags, "", name + SUFFIX_SCALAFILE });
-
- printMessage();
- try {
- success = execute(cmdLine, new FileOutputStream(logFile)) >= 0;
- } catch (FileNotFoundException e) {}
-
- post();
- return success;
- }
- }
-
- private class FailureTest extends Test {
- FailureTest(List/*String*/ files) {
- super("Testing compiler "
- + "(on files whose compilation should fail)",
- new List[]{ files });
- }
- public int run() {
- return filesCount - run(new FailureCommand(console));
- }
- }
-
- private void testAll() {
- console.println("Test configuration");
- console.println("scalac executable: " + scalac);
- console.println("scala executable: " + scala);
- console.println("scalarun executable: " + scalarun);
-
- Test.setConsole(console);
-
- int failure = 0;
- failure += new InterpretationTest(new List[]{ filesRUN, filesINT}).run();
- failure += new CompilationTest(new List[]{ filesRUN, filesJVM}).run();
- failure += new XMLTest(filesXML).run();
- failure += new SuccessTest(filesPOS).run();
- failure += new FailureTest(filesNEG).run();
-
- console.println();
- if (failure == 0)
- printSuccess("All tests were successful");
- else if (failure == 1)
- printFailure("There was 1 test that failed");
- else
- printFailure("There were " + failure + " tests that failed");
- console.println();
- }
-
- private void addFile(String name) {
- testAll = false;
- if (! new File(name).isFile())
- abort("File \"" + name + "\" doesn't exist");
-
- switch (testType) {
- case AUTO: break;
- case RUN: filesRUN.add(name); break;
- case INT: filesINT.add(name); break;
- case JVM: filesJVM.add(name); break;
- case XML: filesXML.add(name); break;
- case POS: filesPOS.add(name); break;
- case NEG: filesNEG.add(name); break;
- default: abort("unknown test type " + testType);
- }
- }
-
- private void addFiles(List/*String*/ fileList, String subDir) {
- File f = new File(SCALA_TESTPATH, subDir);
- if (f.isDirectory()) {
- String[] files = f.list(new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return name.endsWith(SUFFIX_SCALAFILE);
- }
- });
- for (int i = 0; i < files.length; i++)
- fileList.add(subDir + files[i]);
- }
- }
-
- private void addFiles(List/*String*/ fileList, String[] subDirs) {
- for (int i = 0; i < subDirs.length; i++)
- addFiles(fileList, subDirs[i]);
- }
-
- private String getOptionValue(String option, String regex) {
- int inx = option.indexOf('=');
- assert inx > 0;
- String name = option.substring(0, inx);
- String value = option.substring(inx + 1);
- if (value.length() == 0)
- abort("illegal empty value for option --" + name);
- else if (! (regex == null || value.matches(regex)))
- abort("unknown value for option --" + name + ": " + value);
- return value;
- }
-
- private int getColorOption(String option, String regex) {
- String value = getOptionValue(option, regex);
- return "nsm".indexOf(value.charAt(0)); // hack !
- }
-
- private String getPathOption(String option, String regex) {
- String value = getOptionValue(option, regex);
- File dir = new File(value);
- if (! dir.isDirectory())
- abort("Could not access directory '" + value + "'");
- return value;
- }
-
- private void initializeColors() {
- switch (color) {
- case MANY:
- colorOutline = Console.COLOR39;
- colorSuccess = Console.GREEN;
- colorFailure = Console.RED;
- colorWarning = Console.YELLOW;
- colorNormal = Console.RESET;
- break;
- case SOME:
- colorOutline = Console.BOLD;
- colorSuccess = Console.RESET;
- colorFailure = Console.BOLD;
- colorWarning = Console.BOLD;
- colorNormal = Console.RESET;
- break;
- default:
- colorOutline = "";
- colorSuccess = "";
- colorFailure = "";
- colorWarning = "";
- colorNormal = "";
- }
- statusSuccess = "[" + colorSuccess + statusSuccess + colorNormal + "]";
- statusFailed = "[" + colorFailure + statusFailed + colorNormal + "]";
- }
-
- public Main(String[] args) {
- console.setOut(System.out);
-
- for (int i = 0; i < args.length; i++) {
- String opt = null, arg = null;
- if (args[i].matches("--[a-z]+(-[a-z]*)?(=.*)?"))
- opt = args[i].substring(2);
- else if (args[i].equals("-?"))
- opt = "help";
- else if (! args[i].startsWith("-"))
- arg = args[i];
- else
- abort("illegal argument " + args[i]);
-
- if (opt == null) addFile(arg);
- else if (opt.equals("auto")) testType = AUTO;
- else if (opt.equals("run")) testType = RUN;
- else if (opt.equals("int")) testType = INT;
- else if (opt.equals("jvm")) testType = JVM;
- else if (opt.equals("xml")) testType = XML;
- else if (opt.equals("pos")) testType = POS;
- else if (opt.equals("neg")) testType = NEG;
-
- else if (opt.equals("no-run")) noRun = true;
- else if (opt.equals("show-log")) showLog = true;
- else if (opt.equals("show-diff")) showDiff = true;
- else if (opt.equals("failed")) failed = true;
-
- else if (opt.startsWith("verbose="))
- verbose = Integer.parseInt(getOptionValue(opt, "(0|1|2)"));
- else if (opt.startsWith("errors="))
- errors = Integer.parseInt(getOptionValue(opt, "[0-9]*"));
- else if (opt.startsWith("flags="))
- flags = getOptionValue(opt, null);
- else if (opt.startsWith("color="))
- color = getColorOption(opt, "(none|some|many)");
- else if (opt.startsWith("objdir="))
- objDir = getPathOption(opt, null);
- else if (opt.equals("help")) {
- printHelp();
- System.exit(0);
- }
- else if (opt.equals("version")) {
- printVersion();
- System.exit(0);
- }
- else
- abort("unknown option " + opt);
- }
-
- initializeColors();
-
- scalacCmdLine = /* 0:outpath, 1:flags, 2:objfile, 3:arg */
- new MessageFormat(scalac + " -Xshortname -d {0} {1} {2} {3}");
-
- scalarunCmdLine = /* 0:flags, 1:arg */
- new MessageFormat(scalarun + " {0} "
- + SCALA_TESTPATH + FileUtils.FILE_SEP + "{1} -- Test");
-
- dtd2scalaCmdLine = /* 0:outpath, 1:arg */
- new MessageFormat(dtd2scala + " -d {0} {1} " + NAME_DTDFILE);
-
- scalaCmdLine = /* 0:outpath, 1:arg */
- new MessageFormat(scala + " -classpath {0} Test {1}");
-
- if (testAll) {
- if (testType == RUN)
- addFiles(filesRUN, runDir);
- if (testType == AUTO || testType == INT)
- addFiles(filesINT, runDir);
- if (testType == AUTO || testType == JVM)
- addFiles(filesJVM, new String[]{ runDir, jvmDir });
- if (testType == AUTO || testType == XML)
- addFiles(filesXML, xmlDir);
- if (testType == AUTO || testType == POS)
- addFiles(filesPOS, new String[]{ posDir, coursDir });
- if (testType == AUTO || testType == NEG)
- addFiles(filesNEG, negDir);
- }
- }
-
- public static void main(String[] args) {
- new Main(args).testAll();
- }
-
-}
diff --git a/sources/scala/tools/scalatest/Test.java b/sources/scala/tools/scalatest/Test.java
deleted file mode 100644
index b2d2bfa65a..0000000000
--- a/sources/scala/tools/scalatest/Test.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/* ___ ____ ___ __ ___ _____
-** / _// __// _ | / / / _ |/_ _/ Scala test
-** __\ \/ /__/ __ |/ /__/ __ | / / (c) 2003, LAMP/EPFL
-** /____/\___/_/ |_/____/_/ |_//_/
-**
-** $Id$
-*/
-
-package scala.tools.scalatest;
-
-import java.util.List;
-import java.util.ListIterator;
-
-
-public abstract class Test {
-
- private List/*String*/[] groups;
-
- protected static Console console;
- protected String description;
- protected int filesCount;
-
- Test(String description, List[] groups) {
- this.description = description;
- this.groups = groups;
- for (int i = 0; i < groups.length; i++)
- filesCount += groups[i].size();
- }
-
- Test(String description, List group) {
- this(description, new List[]{ group });
- }
-
- protected int run(Command cmd) {
- int successCount = 0;
- if (filesCount > 0) {
- console.println();
- console.println(description);
- for (int i = 0; i < groups.length; i++)
- for (ListIterator it = groups[i].listIterator(); it.hasNext();) {
- boolean success = cmd.run((String) it.next());
- if (success) ++successCount;
- }
- }
- return successCount;
- }
-
- public abstract int run();
-
- public static void setConsole(Console con) {
- console = con;
- }
-
-}