From 96d7374b9bfd9c4917793a55149ac227fabbc3f3 Mon Sep 17 00:00:00 2001 From: michelou Date: Thu, 31 May 2007 18:43:38 +0000 Subject: Capitalized type params in Predef, fixed bug in... Capitalized type params in Predef, fixed bug in URLZipArchive --- src/compiler/scala/tools/nsc/io/AbstractFile.scala | 27 ++- src/compiler/scala/tools/nsc/io/PlainFile.scala | 2 +- src/compiler/scala/tools/nsc/io/VirtualFile.scala | 2 +- src/compiler/scala/tools/nsc/io/ZipArchive.scala | 40 ++-- .../scala/tools/nsc/symtab/SymbolLoaders.scala | 47 ++-- .../nsc/symtab/classfile/AbstractFileReader.scala | 27 +-- .../nsc/symtab/classfile/ClassfileParser.scala | 47 ++-- src/library/scala/Predef.scala | 240 ++++++++++----------- .../scala/runtime/NonLocalReturnException.scala | 4 +- 9 files changed, 230 insertions(+), 206 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/io/AbstractFile.scala b/src/compiler/scala/tools/nsc/io/AbstractFile.scala index 1cb30f4714..8c084c8266 100644 --- a/src/compiler/scala/tools/nsc/io/AbstractFile.scala +++ b/src/compiler/scala/tools/nsc/io/AbstractFile.scala @@ -7,9 +7,15 @@ package scala.tools.nsc.io -import java.io.{DataInputStream, File, IOException, InputStream} +import java.io.{File, IOException, InputStream} import java.net.URL +import scala.collection.mutable.ArrayBuffer + +/** + * @author Philippe Altherr + * @version 1.0, 23/03/2004 + */ object AbstractFile { /** Returns "getFile(new File(path))". */ @@ -96,7 +102,7 @@ abstract class AbstractFile extends AnyRef with Iterable[AbstractFile] { /** Returns the path of this abstract file. */ def path: String - /** Returns the underlying File if any and null otherwise. */ + /** Returns the underlying File if any and null otherwise. */ def file: File /** Is this abstract file a directory? */ @@ -106,25 +112,28 @@ abstract class AbstractFile extends AnyRef with Iterable[AbstractFile] { def lastModified: Long /** returns an input stream so the file can be read */ - def read: InputStream + def input: InputStream - /** size of this file if it is a concrete file */ + /** size of this file if it is a concrete file. */ def size: Option[Int] = None /** returns contents of file (if applicable) in a byte array. - * warning: use Global.getSourceFile() to use the proper - * encoding when converting to the char array + * warning: use Global.getSourceFile() to use the proper + * encoding when converting to the char array . + * * @throws java.io.IOException */ final def toCharArray = new String(toByteArray).toCharArray - /** returns contents of file (if applicable) in a byte array + /** returns contents of file (if applicable) in a byte array. + * * @throws java.io.IOException */ + @throws(classOf[IOException]) final def toByteArray: Array[Byte] = { - val in = read + val in = input var rest = size.get - val arr = new Array[Byte](rest) + val arr = new Array[Byte](rest) while (rest > 0) { val res = in.read(arr, arr.length - rest, rest) if (res == -1) diff --git a/src/compiler/scala/tools/nsc/io/PlainFile.scala b/src/compiler/scala/tools/nsc/io/PlainFile.scala index 21e3e8b6ce..ff4f6126d5 100644 --- a/src/compiler/scala/tools/nsc/io/PlainFile.scala +++ b/src/compiler/scala/tools/nsc/io/PlainFile.scala @@ -37,7 +37,7 @@ class PlainFile(val file: File) extends AbstractFile { /** Returns the path of this abstract file. */ def path = file.getPath() - override def read = new FileInputStream(file) + override def input = new FileInputStream(file) override def size = Some(file.length.toInt) diff --git a/src/compiler/scala/tools/nsc/io/VirtualFile.scala b/src/compiler/scala/tools/nsc/io/VirtualFile.scala index c9a15e90c1..c1a49067e8 100644 --- a/src/compiler/scala/tools/nsc/io/VirtualFile.scala +++ b/src/compiler/scala/tools/nsc/io/VirtualFile.scala @@ -38,7 +38,7 @@ class VirtualFile(val name: String, _path: String) extends AbstractFile { /** Returns null. */ final def file: File = null - def read: InputStream = throw new Error("not suported") + def input: InputStream = throw new Error("not supported") /** Is this abstract file a directory? */ def isDirectory: Boolean = false diff --git a/src/compiler/scala/tools/nsc/io/ZipArchive.scala b/src/compiler/scala/tools/nsc/io/ZipArchive.scala index 8fcb553ba3..575e2ec854 100644 --- a/src/compiler/scala/tools/nsc/io/ZipArchive.scala +++ b/src/compiler/scala/tools/nsc/io/ZipArchive.scala @@ -108,7 +108,7 @@ final class ZipArchive(file: File, val archive: ZipFile) extends PlainFile(file) private def load() { this.root = new DirEntry("", "/") // A path to DirEntry map - val dirs: Map[String,DirEntry] = new HashMap() + val dirs: Map[String, DirEntry] = new HashMap() dirs.update("/", root) val entries = archive.entries() while (entries.hasMoreElements()) { @@ -169,12 +169,12 @@ final class ZipArchive(file: File, val archive: ZipFile) extends PlainFile(file) extends Entry(name, path) { - val entries: Map[String,Entry] = new HashMap() + val entries: Map[String, Entry] = new HashMap() var entry: ZipEntry = _ override def isDirectory = true - override def read = throw new Error("cannot read directories") + override def input = throw new Error("cannot read directories") override def lastModified: Long = if (entry ne null) entry.getTime() else super.lastModified @@ -196,7 +196,7 @@ final class ZipArchive(file: File, val archive: ZipFile) extends PlainFile(file) extends Entry(name, path) { def archive = ZipArchive.this.archive override def lastModified: Long = entry.getTime() - override def read = archive.getInputStream(entry) + override def input = archive.getInputStream(entry) override def size = Some(entry.getSize().toInt) } } @@ -225,7 +225,7 @@ final class URLZipArchive(url: URL) extends AbstractFile { try { url.openConnection().getLastModified() } catch { case _ => 0 } - def read: InputStream = url.openStream() + def input: InputStream = url.openStream() override def elements: Iterator[AbstractFile] = { if (root eq null) load() @@ -238,11 +238,21 @@ final class URLZipArchive(url: URL) extends AbstractFile { } private def load() { + def getEntryInputStream(in: InputStream): InputStream = { + val buf = new scala.collection.mutable.ArrayBuffer[Byte] + val data = new Array[Byte](1024) + var n = in.read(data) + while (n > 0) { + buf.++=(data, 0, n) + n = in.read(data) + } + new java.io.ByteArrayInputStream(buf.toArray) + } this.root = new DirEntry("", "/") // A path to DirEntry map val dirs: Map[String, DirEntry] = new HashMap() dirs.update("/", root) - val zis = new ZipInputStream(read) + val zis = new ZipInputStream(input) var entry = zis.getNextEntry() while (entry ne null) { val path = entry.getName() @@ -258,11 +268,12 @@ final class URLZipArchive(url: URL) extends AbstractFile { val home = if (index < 0) "/" else path.substring(0, index + 1) val parent: DirEntry = getDir(dirs, home) assert(!parent.entries.contains(path), this.toString() + " - " + path) - parent.entries.update(name, new FileEntry(name, path, zis)) + val in = getEntryInputStream(zis) + parent.entries.update(name, new FileEntry(name, path, entry, in)) } + zis.closeEntry() entry = zis.getNextEntry() } - zis.close } private def getDir(dirs: Map[String, DirEntry], path: String): DirEntry = @@ -294,7 +305,7 @@ final class URLZipArchive(url: URL) extends AbstractFile { var entry: ZipEntry = _ override def isDirectory = true - override def read = throw new Error("cannot read directories"); + override def input = throw new Error("cannot read directories") override def lastModified: Long = if (entry ne null) entry.getTime() else super.lastModified @@ -308,10 +319,11 @@ final class URLZipArchive(url: URL) extends AbstractFile { } } - final class FileEntry(name: String, path: String, val zis: ZipInputStream) - extends Entry(name, path) { - override def lastModified: Long = 0 - override def read = zis - override def size = Some(0) + final class FileEntry(name: String, path: String, + val entry: ZipEntry, val in: InputStream) + extends Entry(name, path) { + override def lastModified: Long = entry.getTime() + override def input = in + override def size = Some(entry.getSize().toInt) } } diff --git a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala index 931060a594..230c92afbd 100644 --- a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala +++ b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala @@ -10,8 +10,8 @@ import compat.Platform.currentTime import java.io.{File, IOException} import scala.collection.mutable.{HashMap, HashSet} import scala.tools.nsc.io.AbstractFile -import scala.tools.nsc.util.{ClassPath, NameTransformer, Position, NoPosition} -import classfile.{ClassfileParser, SymblfileParser} +import scala.tools.nsc.util.{Position, NoPosition} +import classfile.ClassfileParser import Flags._ import ch.epfl.lamp.compiler.msil.{Type => MSILType, Attribute => MSILAttribute} @@ -26,6 +26,7 @@ abstract class SymbolLoaders { /** A lazy type that completes itself by calling parameter doComplete. * Any linked modules/classes or module classes are also initialized. + * * @param doComplete The type completion procedure to be run. * It takes symbol to compkete as parameter and returns * name of file loaded for completion as a result. @@ -40,16 +41,11 @@ abstract class SymbolLoaders { protected def kindString: String private var ok = false -/* - private def setSource(sym: Symbol, sourceFile0: AbstractFile): unit = sym match { - case clazz: ClassSymbol => if (sourceFile0 ne null) clazz.sourceFile = sourceFile0; - case _ => if (sourceFile0 ne null) if (false) System.err.println("YYY: " + sym + " " + sourceFile0); - } -*/ - def sourceFile : AbstractFile = null - protected def sourceString : String - override def complete(root: Symbol): unit = { + def sourceFile: AbstractFile = null + protected def sourceString: String + + override def complete(root: Symbol) { try { val start = currentTime val currentphase = phase @@ -63,7 +59,7 @@ abstract class SymbolLoaders { } catch { case ex: IOException => ok = false - if (settings.debug.value) ex.printStackTrace(); + if (settings.debug.value) ex.printStackTrace() val msg = ex.getMessage() error( if (msg eq null) "i/o error while loading " + root.name @@ -73,9 +69,9 @@ abstract class SymbolLoaders { if (!root.isPackageClass) initRoot(root.linkedSym) } - override def load(root: Symbol): unit = complete(root) + override def load(root: Symbol) { complete(root) } - private def initRoot(root: Symbol): unit = { + private def initRoot(root: Symbol) { if (root.rawInfo == this) { def markAbsent(sym: Symbol) = if (sym != NoSymbol) sym.setInfo(if (ok) NoType else ErrorType); @@ -96,11 +92,11 @@ abstract class SymbolLoaders { protected def newPackageLoader(dir: global.classPath0.Context): PackageLoader = new PackageLoader(dir) - protected def checkSource(name: String, source: AbstractFile): Boolean = true; + protected def checkSource(name: String, source: AbstractFile): Boolean = true protected var root: Symbol = _ - def enterPackage(name: String, completer: SymbolLoader): unit = { + def enterPackage(name: String, completer: SymbolLoader) { val pkg = root.newPackage(NoPosition, newTermName(name)) pkg.moduleClass.setInfo(completer) pkg.setInfo(pkg.moduleClass.tpe) @@ -129,7 +125,7 @@ abstract class SymbolLoaders { clazz } - protected def doComplete(root: Symbol): unit = { + protected def doComplete(root: Symbol) { assert(root.isPackageClass, root) this.root = root val scope = newScope @@ -199,21 +195,20 @@ abstract class SymbolLoaders { override protected def kindString: String = "namespace " + namespace - override protected def sourceString = ""; + override protected def sourceString = "" override def newPackageLoader(dir: global.classPath0.Context): PackageLoader = - new NamespaceLoader(dir); + new NamespaceLoader(dir) - val types = new HashMap[String,MSILType](); + val types = new HashMap[String,MSILType]() - val namespaces = new HashSet[String](); + val namespaces = new HashSet[String]() - def namespace: String = if (root.isRoot) "" else root.fullNameString; + def namespace: String = if (root.isRoot) "" else root.fullNameString // TODO: Add check whether the source is newer than the assembly - override protected def checkSource(name: String, source: AbstractFile): Boolean = { + override protected def checkSource(name: String, source: AbstractFile): Boolean = !types.contains(name) - } override protected def doComplete(root: Symbol) { clrTypes.collectMembers(root, types, namespaces) @@ -261,7 +256,7 @@ abstract class SymbolLoaders { val global: SymbolLoaders.this.global.type = SymbolLoaders.this.global override def sourcePath = sourcePath0 /* could be null */ } - protected def doComplete(root: Symbol): unit = { + protected def doComplete(root: Symbol) { classfileParser.parse(classFile, root) if (sourceFile ne null) root match { case clazz : ClassSymbol => clazz.sourceFile = sourceFile @@ -285,7 +280,7 @@ abstract class SymbolLoaders { } object moduleClassLoader extends SymbolLoader { - protected def doComplete(root: Symbol): unit = root.sourceModule.initialize + protected def doComplete(root: Symbol) { root.sourceModule.initialize } protected def kindString: String = "" protected def sourceString = "" } diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/AbstractFileReader.scala b/src/compiler/scala/tools/nsc/symtab/classfile/AbstractFileReader.scala index acf1d5fea5..7c30456a34 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/AbstractFileReader.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/AbstractFileReader.scala @@ -1,21 +1,22 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002-2006, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - +/* NSC -- new Scala compiler + * Copyright 2005-2007 LAMP/EPFL + * @author Martin Odersky + */ // $Id$ package scala.tools.nsc.symtab.classfile -import scala.tools.nsc.io.{AbstractFile, PlainFile, ZipArchive} - import java.lang.Float.intBitsToFloat import java.lang.Double.longBitsToDouble -import java.io.{File, FileInputStream, IOException} -/** this class reads files byte per byte. Only used by ClassFileParser +import scala.tools.nsc.io.AbstractFile + +/** + * This class reads files byte per byte. Only used by ClassFileParser + * + * @author Philippe Altherr + * @version 1.0, 23/03/2004 */ class AbstractFileReader(val file: AbstractFile) { @@ -29,10 +30,12 @@ class AbstractFileReader(val file: AbstractFile) { /** return byte at offset 'pos' */ - def byteAt(pos: Int): Byte = return buf(pos) + @throws(classOf[IndexOutOfBoundsException]) + def byteAt(pos: Int): Byte = buf(pos) /** read a byte */ + @throws(classOf[IndexOutOfBoundsException]) def nextByte: Byte = { val b = buf(bp) bp = bp + 1 @@ -85,6 +88,6 @@ class AbstractFileReader(val file: AbstractFile) { /** skip next 'n' bytes */ - def skip(n: Int): Unit = bp = bp + n + def skip(n: Int) { bp += n } } diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index 63a6f1151a..153c0a88d8 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -22,7 +22,7 @@ import java.lang.Integer.toHexString import scala.collection.immutable.{Map, ListMap} import scala.collection.mutable.{ListBuffer, ArrayBuffer} import scala.tools.nsc.io.AbstractFile -import scala.tools.nsc.util.{Position,NoPosition} +import scala.tools.nsc.util.{FreshNameCreator, Position, NoPosition} /** This abstract class implements a class file parser. @@ -49,7 +49,7 @@ abstract class ClassfileParser { protected var hasMeta: boolean = _ // does class file contain jaco meta attribute?s protected var busy: boolean = false // lock to detect recursive reads protected var classTParams = Map[Name,Symbol]() - protected val fresh = new scala.tools.nsc.util.FreshNameCreator + protected val fresh = new FreshNameCreator private object metaParser extends MetaParser { val global: ClassfileParser.this.global.type = ClassfileParser.this.global @@ -59,9 +59,9 @@ abstract class ClassfileParser { val global: ClassfileParser.this.global.type = ClassfileParser.this.global } - def parse(file: AbstractFile, root: Symbol): unit = { + def parse(file: AbstractFile, root: Symbol) { def handleError(e: Exception) = { - if (settings.debug.value) e.printStackTrace();//debug + if (settings.debug.value) e.printStackTrace() //debug throw new IOException("class file '" + in.file + "' is broken\n(" + { if (e.getMessage() != null) e.getMessage() else e.getClass.toString @@ -70,10 +70,12 @@ abstract class ClassfileParser { assert(!busy) busy = true root match { - case cs : ClassSymbol => cs.classFile = file; - case ms : ModuleSymbol => ms.moduleClass.asInstanceOf[ClassSymbol].classFile = file; + case cs: ClassSymbol => + cs.classFile = file + case ms: ModuleSymbol => + ms.moduleClass.asInstanceOf[ClassSymbol].classFile = file case _ => - Console.println("Skipping class: " + root + ": " + root.getClass); + Console.println("Skipping class: " + root + ": " + root.getClass) } this.in = new AbstractFileReader(file) @@ -99,7 +101,7 @@ abstract class ClassfileParser { protected def statics: Symbol = staticModule.moduleClass - private def parseHeader: unit = { + private def parseHeader { val magic = in.nextInt if (magic != JAVA_MAGIC) throw new IOException("class file '" + in.file + "' " @@ -121,7 +123,8 @@ abstract class ClassfileParser { private val len = in.nextChar private val starts = new Array[int](len) private val values = new Array[AnyRef](len) - private val internalized = new Array[Name](len); + private val internalized = new Array[Name](len) + { var i = 1 while (i < starts.length) { starts(i) = in.bp @@ -242,6 +245,7 @@ abstract class ClassfileParser { } p } + /** Return the type of a class constant entry. Since * arrays are considered to be class types, they might * appear as entries in 'newarray' or 'cast' opcodes. @@ -308,11 +312,11 @@ abstract class ClassfileParser { } /** Throws an exception signaling a bad constant index. */ - private def errorBadIndex(index: int) = + private def errorBadIndex(index: Int) = throw new RuntimeException("bad constant pool index: " + index + " at pos: " + in.bp) /** Throws an exception signaling a bad tag at given address. */ - private def errorBadTag(start: int) = + private def errorBadTag(start: Int) = throw new RuntimeException("bad constant pool tag " + in.buf(start) + " at byte " + start) } @@ -323,10 +327,10 @@ abstract class ClassfileParser { if (!global.phase.erasedTypes && tp.symbol == definitions.ObjectClass) definitions.AnyClass.tpe else tp def paramsigs2types: List[Type] = - if (name(index) == ')') { index = index + 1; List() } + if (name(index) == ')') { index += 1; List() } else objToAny(sig2type) :: paramsigs2types def sig2type: Type = { - val tag = name(index); index = index + 1 + val tag = name(index); index += 1 tag match { case BYTE_TAG => definitions.ByteClass.tpe case CHAR_TAG => definitions.CharClass.tpe @@ -339,12 +343,12 @@ abstract class ClassfileParser { case BOOL_TAG => definitions.BooleanClass.tpe case 'L' => val start = index - while (name(index) != ';') { index = index + 1 } + while (name(index) != ';') index += 1 val end = index - index = index + 1 + index += 1 classNameToSymbol(name.subName(start, end)).tpe case ARRAY_TAG => - while ('0' <= name(index) && name(index) <= '9') index = index + 1 + while ('0' <= name(index) && name(index) <= '9') index += 1 appliedType(definitions.ArrayClass.tpe, List(sig2type)) case '(' => JavaMethodType(paramsigs2types, sig2type) @@ -363,7 +367,7 @@ abstract class ClassfileParser { var sawPrivateConstructor = false - def parseClass(): unit = { + def parseClass() { val jflags = in.nextChar val isAnnotation = (jflags & JAVA_ACC_ANNOTATION) != 0 var sflags = transFlags(jflags) @@ -756,13 +760,13 @@ abstract class ClassfileParser { } } - protected def getOwner(flags: int): Symbol = + protected def getOwner(flags: Int): Symbol = if ((flags & JAVA_ACC_STATIC) != 0) statics else clazz - protected def getScope(flags: int): Scope = + protected def getScope(flags: Int): Scope = if ((flags & JAVA_ACC_STATIC) != 0) staticDefs else instanceDefs - protected def transFlags(flags: int): long = { + protected def transFlags(flags: Int): Long = { var res = 0l if ((flags & JAVA_ACC_PRIVATE) != 0) res = res | PRIVATE @@ -782,7 +786,8 @@ abstract class ClassfileParser { res | JAVA } - private def setPrivateWithin(sym: Symbol, jflags: int): unit = + private def setPrivateWithin(sym: Symbol, jflags: Int) { if ((jflags & (JAVA_ACC_PRIVATE | JAVA_ACC_PROTECTED | JAVA_ACC_PUBLIC)) == 0) sym.privateWithin = sym.toplevelClass.owner + } } diff --git a/src/library/scala/Predef.scala b/src/library/scala/Predef.scala index c2fd61a124..233b11cc3d 100644 --- a/src/library/scala/Predef.scala +++ b/src/library/scala/Predef.scala @@ -18,57 +18,57 @@ package scala */ object Predef { - // classOf dummy ------------------------------------------------- + // classOf dummy ------------------------------------------------------ /** Return the runtime representation of a class type. */ def classOf[T]: Class = null - // aliases ------------------------------------------------------- + // aliases ------------------------------------------------------------ - type byte = scala.Byte - type short = scala.Short - type char = scala.Char - type int = scala.Int - type long = scala.Long - type float = scala.Float - type double = scala.Double + type byte = scala.Byte + type short = scala.Short + type char = scala.Char + type int = scala.Int + type long = scala.Long + type float = scala.Float + type double = scala.Double type boolean = scala.Boolean - type unit = scala.Unit + type unit = scala.Unit - type All = Nothing + type All = Nothing type AllRef = Null - type String = java.lang.String + type String = java.lang.String type StringBuilder = compat.StringBuilder - type Class = java.lang.Class - type Runnable = java.lang.Runnable + type Class = java.lang.Class + type Runnable = java.lang.Runnable type Throwable = java.lang.Throwable type Exception = java.lang.Exception - type Error = java.lang.Error - type RuntimeException = java.lang.RuntimeException - type NullPointerException = java.lang.NullPointerException - type ClassCastException = java.lang.ClassCastException - type IndexOutOfBoundsException = java.lang.IndexOutOfBoundsException + type Error = java.lang.Error + + type RuntimeException = java.lang.RuntimeException + type NullPointerException = java.lang.NullPointerException + type ClassCastException = java.lang.ClassCastException + type IndexOutOfBoundsException = java.lang.IndexOutOfBoundsException type ArrayIndexOutOfBoundsException = java.lang.ArrayIndexOutOfBoundsException - type UnsupportedOperationException = java.lang.UnsupportedOperationException - type IllegalArgumentException = java.lang.IllegalArgumentException - type NoSuchElementException = java.util.NoSuchElementException - type NumberFormatException = java.lang.NumberFormatException + type UnsupportedOperationException = java.lang.UnsupportedOperationException + type IllegalArgumentException = java.lang.IllegalArgumentException + type NoSuchElementException = java.util.NoSuchElementException + type NumberFormatException = java.lang.NumberFormatException - // --- Miscelleaneous ----------------------------------------------- + // miscelleaneous ----------------------------------------------------- val $scope = scala.xml.TopScope - type Function[-a,+b] = Function1[a,b] + type Function[-A, +B] = Function1[A, B] - type Map[a, b] = collection.immutable.Map[a, b] - type Set[a] = collection.immutable.Set[a] + type Map[A, B] = collection.immutable.Map[A, B] + type Set[A] = collection.immutable.Set[A] val Map = collection.immutable.Map val Set = collection.immutable.Set - // errors and asserts ------------------------------------------------- def error(message: String): Nothing = throw new Error(message) @@ -100,36 +100,36 @@ object Predef { throw new Error("assumption failed: " + message) } - // --- Tupling ---------------------------------------------- + // tupling ------------------------------------------------------------ - type Pair[+a, +b] = Tuple2[a, b] + type Pair[+A, +B] = Tuple2[A, B] object Pair { - def apply[a, b](x: a, y: b) = Tuple2(x, y) - def unapply[a, b](x: Tuple2[a, b]): Option[Tuple2[a, b]] = Some(x) + def apply[A, B](x: A, y: B) = Tuple2(x, y) + def unapply[A, B](x: Tuple2[A, B]): Option[Tuple2[A, B]] = Some(x) } - type Triple[+a, +b, +c] = Tuple3[a, b, c] + type Triple[+A, +B, +C] = Tuple3[A, B, C] object Triple { - def apply[a, b, c](x: a, y: b, z: c) = Tuple3(x, y, z) - def unapply[a, b, c](x: Tuple3[a, b, c]): Option[Tuple3[a, b, c]] = Some(x) + def apply[A, B, C](x: A, y: B, z: C) = Tuple3(x, y, z) + def unapply[A, B, C](x: Tuple3[A, B, C]): Option[Tuple3[A, B, C]] = Some(x) } - class ArrowAssoc[a](x: a) { - def -> [b](y: b): Tuple2[a, b] = Tuple2(x, y) + class ArrowAssoc[A](x: A) { + def -> [B](y: B): Tuple2[A, B] = Tuple2(x, y) } - implicit def any2ArrowAssoc[a](x: a): ArrowAssoc[a] = new ArrowAssoc(x) + implicit def any2ArrowAssoc[A](x: A): ArrowAssoc[A] = new ArrowAssoc(x) - def Tuple[a1](x1: a1) = Tuple1(x1) - def Tuple[a1, a2](x1: a1, x2: a2) = Tuple2(x1, x2) - def Tuple[a1, a2, a3](x1: a1, x2: a2, x3: a3) = Tuple3(x1, x2, x3) - def Tuple[a1, a2, a3, a4](x1: a1, x2: a2, x3: a3, x4: a4) = Tuple4(x1, x2, x3, x4) - def Tuple[a1, a2, a3, a4, a5](x1: a1, x2: a2, x3: a3, x4: a4, x5: a5) = Tuple5(x1, x2, x3, x4, x5) - def Tuple[a1, a2, a3, a4, a5, a6](x1: a1, x2: a2, x3: a3, x4: a4, x5: a5, x6: a6) = Tuple6(x1, x2, x3, x4, x5, x6) - def Tuple[a1, a2, a3, a4, a5, a6, a7](x1: a1, x2: a2, x3: a3, x4: a4, x5: a5, x6: a6, x7: a7) = Tuple7(x1, x2, x3, x4, x5, x6, x7) - def Tuple[a1, a2, a3, a4, a5, a6, a7, a8](x1: a1, x2: a2, x3: a3, x4: a4, x5: a5, x6: a6, x7: a7, x8: a8) = Tuple8(x1, x2, x3, x4, x5, x6, x7, x8) - def Tuple[a1, a2, a3, a4, a5, a6, a7, a8, a9](x1: a1, x2: a2, x3: a3, x4: a4, x5: a5, x6: a6, x7: a7, x8: a8, x9: a9) = Tuple9(x1, x2, x3, x4, x5, x6, x7, x8, x9) + def Tuple[A1](x1: A1) = Tuple1(x1) + def Tuple[A1, A2](x1: A1, x2: A2) = Tuple2(x1, x2) + def Tuple[A1, A2, A3](x1: A1, x2: A2, x3: A3) = Tuple3(x1, x2, x3) + def Tuple[A1, A2, A3, A4](x1: A1, x2: A2, x3: A3, x4: A4) = Tuple4(x1, x2, x3, x4) + def Tuple[A1, A2, A3, A4, A5](x1: A1, x2: A2, x3: A3, x4: A4, x5: A5) = Tuple5(x1, x2, x3, x4, x5) + def Tuple[A1, A2, A3, A4, A5, A6](x1: A1, x2: A2, x3: A3, x4: A4, x5: A5, x6: A6) = Tuple6(x1, x2, x3, x4, x5, x6) + def Tuple[A1, A2, A3, A4, A5, A6, A7](x1: A1, x2: A2, x3: A3, x4: A4, x5: A5, x6: A6, x7: A7) = Tuple7(x1, x2, x3, x4, x5, x6, x7) + def Tuple[A1, A2, A3, A4, A5, A6, A7, A8](x1: A1, x2: A2, x3: A3, x4: A4, x5: A5, x6: A6, x7: A7, x8: A8) = Tuple8(x1, x2, x3, x4, x5, x6, x7, x8) + def Tuple[A1, A2, A3, A4, A5, A6, A7, A8, A9](x1: A1, x2: A2, x3: A3, x4: A4, x5: A5, x6: A6, x7: A7, x8: A8, x9: A9) = Tuple9(x1, x2, x3, x4, x5, x6, x7, x8, x9) - // printing and reading ---------------------------------------------- + // printing and reading ----------------------------------------------- def print(x: Any) = Console.print(x) def println() = Console.println() @@ -152,19 +152,19 @@ object Predef { def readf2(format: String) = Console.readf2(format) def readf3(format: String) = Console.readf3(format) - // views ------------------------------------------------------------- + // views -------------------------------------------------------------- - implicit def identity[a](x: a): a = x + implicit def identity[A](x: A): A = x - implicit def byteWrapper(x: byte) = new runtime.RichByte(x) - implicit def shortWrapper(x: short) = new runtime.RichShort(x) - implicit def intWrapper(x: int) = new runtime.RichInt(x) - implicit def charWrapper(c: char) = new runtime.RichChar(c) - implicit def longWrapper(x: long) = new runtime.RichLong(x) - implicit def floatWrapper(x: float) = new runtime.RichFloat(x) - implicit def doubleWrapper(x: double) = new runtime.RichDouble(x) + implicit def byteWrapper(x: Byte) = new runtime.RichByte(x) + implicit def shortWrapper(x: Short) = new runtime.RichShort(x) + implicit def intWrapper(x: Int) = new runtime.RichInt(x) + implicit def charWrapper(c: Char) = new runtime.RichChar(c) + implicit def longWrapper(x: Long) = new runtime.RichLong(x) + implicit def floatWrapper(x: Float) = new runtime.RichFloat(x) + implicit def doubleWrapper(x: Double) = new runtime.RichDouble(x) - implicit def booleanWrapper(x: boolean) = new runtime.RichBoolean(x) + implicit def booleanWrapper(x: Boolean) = new runtime.RichBoolean(x) implicit def stringWrapper(x: String) = new runtime.RichString(x) @@ -172,15 +172,15 @@ object Predef { implicit def exceptionWrapper(exc: Throwable) = new runtime.RichException(exc) - implicit def unit2ordered(x: unit): Ordered[unit] = new Ordered[unit] with Proxy { + implicit def unit2ordered(x: Unit): Ordered[Unit] = new Ordered[Unit] with Proxy { def self: Any = x - def compare (y: unit): int = 0 + def compare(y: Unit): Int = 0 } - implicit def iterable2ordered[a <% Ordered[a]](xs: Iterable[a]): Ordered[Iterable[a]] = - new Ordered[Iterable[a]] with Proxy { + implicit def iterable2ordered[A <% Ordered[A]](xs: Iterable[A]): Ordered[Iterable[A]] = + new Ordered[Iterable[A]] with Proxy { val self = xs - def compare (that: Iterable[a]) = { + def compare(that: Iterable[A]): Int = { var res = 0 val these = xs.elements val those = that.elements @@ -190,119 +190,119 @@ object Predef { } } - implicit def tuple22ordered[a1 <% Ordered[a1], a2 <% Ordered[a2]](x: Tuple2[a1, a2]): Ordered[Tuple2[a1, a2]] = - new Ordered[Tuple2[a1, a2]] with Proxy { + implicit def tuple22ordered[A1 <% Ordered[A1], A2 <% Ordered[A2]](x: Tuple2[A1, A2]): Ordered[Tuple2[A1, A2]] = + new Ordered[Tuple2[A1, A2]] with Proxy { val self = x - def compare (y: Tuple2[a1, a2]): Int = { + def compare(y: Tuple2[A1, A2]): Int = { val res = x._1 compare y._1 if (res == 0) x._2 compare y._2 else res } } - implicit def tuple32ordered[a1 <% Ordered[a1], a2 <% Ordered[a2], a3 <% Ordered[a3]](x: Tuple3[a1, a2, a3]): Ordered[Tuple3[a1, a2, a3]] = - new Ordered[Tuple3[a1, a2, a3]] with Proxy { + implicit def tuple32ordered[A1 <% Ordered[A1], A2 <% Ordered[A2], A3 <% Ordered[A3]](x: Tuple3[A1, A2, A3]): Ordered[Tuple3[A1, A2, A3]] = + new Ordered[Tuple3[A1, A2, A3]] with Proxy { val self = x - def compare (y: Tuple3[a1, a2, a3]): Int = { + def compare(y: Tuple3[A1, A2, A3]): Int = { val res = x._1 compare y._1 if (res == 0) Tuple2(x._2, x._3) compare Tuple2(y._2, y._3) else res } } - implicit def tuple42ordered[a1 <% Ordered[a1], a2 <% Ordered[a2], a3 <% Ordered[a3], a4 <% Ordered[a4]](x: Tuple4[a1, a2, a3, a4]): Ordered[Tuple4[a1, a2, a3, a4]] = - new Ordered[Tuple4[a1, a2, a3, a4]] with Proxy { + implicit def tuple42ordered[A1 <% Ordered[A1], A2 <% Ordered[A2], A3 <% Ordered[A3], A4 <% Ordered[A4]](x: Tuple4[A1, A2, A3, A4]): Ordered[Tuple4[A1, A2, A3, A4]] = + new Ordered[Tuple4[A1, A2, A3, A4]] with Proxy { val self = x - def compare (y: Tuple4[a1, a2, a3, a4]): Int = { + def compare(y: Tuple4[A1, A2, A3, A4]): Int = { val res = x._1 compare y._1 if (res == 0) Tuple3(x._2, x._3, x._4) compare Tuple3(y._2, y._3, y._4) else res } } - implicit def tuple52ordered[a1 <% Ordered[a1], a2 <% Ordered[a2], a3 <% Ordered[a3], a4 <% Ordered[a4], a5 <% Ordered[a5]](x: Tuple5[a1, a2, a3, a4, a5]): Ordered[Tuple5[a1, a2, a3, a4, a5]] = - new Ordered[Tuple5[a1, a2, a3, a4, a5]] with Proxy { + implicit def tuple52ordered[A1 <% Ordered[A1], A2 <% Ordered[A2], A3 <% Ordered[A3], A4 <% Ordered[A4], A5 <% Ordered[A5]](x: Tuple5[A1, A2, A3, A4, A5]): Ordered[Tuple5[A1, A2, A3, A4, A5]] = + new Ordered[Tuple5[A1, A2, A3, A4, A5]] with Proxy { val self = x - def compare (y: Tuple5[a1, a2, a3, a4, a5]): Int = { + def compare(y: Tuple5[A1, A2, A3, A4, A5]): Int = { val res = x._1 compare y._1 if (res == 0) Tuple4(x._2, x._3, x._4, x._5) compare Tuple4(y._2, y._3, y._4, y._5) else res } } - implicit def tuple62ordered[a1 <% Ordered[a1], a2 <% Ordered[a2], a3 <% Ordered[a3], a4 <% Ordered[a4], a5 <% Ordered[a5], a6 <% Ordered[a6]](x: Tuple6[a1, a2, a3, a4, a5, a6]): Ordered[Tuple6[a1, a2, a3, a4, a5, a6]] = - new Ordered[Tuple6[a1, a2, a3, a4, a5, a6]] with Proxy { + implicit def tuple62ordered[A1 <% Ordered[A1], A2 <% Ordered[A2], A3 <% Ordered[A3], A4 <% Ordered[A4], A5 <% Ordered[A5], A6 <% Ordered[A6]](x: Tuple6[A1, A2, A3, A4, A5, A6]): Ordered[Tuple6[A1, A2, A3, A4, A5, A6]] = + new Ordered[Tuple6[A1, A2, A3, A4, A5, A6]] with Proxy { val self = x - def compare (y: Tuple6[a1, a2, a3, a4, a5, a6]): Int = { + def compare(y: Tuple6[A1, A2, A3, A4, A5, A6]): Int = { val res = x._1 compare y._1 if (res == 0) Tuple5(x._2, x._3, x._4, x._5, x._6) compare Tuple5(y._2, y._3, y._4, y._5, y._6) else res } } - implicit def tuple72ordered[a1 <% Ordered[a1], a2 <% Ordered[a2], a3 <% Ordered[a3], a4 <% Ordered[a4], a5 <% Ordered[a5], a6 <% Ordered[a6], a7 <% Ordered[a7]](x: Tuple7[a1, a2, a3, a4, a5, a6, a7]): Ordered[Tuple7[a1, a2, a3, a4, a5, a6, a7]] = - new Ordered[Tuple7[a1, a2, a3, a4, a5, a6, a7]] with Proxy { + implicit def tuple72ordered[A1 <% Ordered[A1], A2 <% Ordered[A2], A3 <% Ordered[A3], A4 <% Ordered[A4], A5 <% Ordered[A5], A6 <% Ordered[A6], A7 <% Ordered[A7]](x: Tuple7[A1, A2, A3, A4, A5, A6, A7]): Ordered[Tuple7[A1, A2, A3, A4, A5, A6, A7]] = + new Ordered[Tuple7[A1, A2, A3, A4, A5, A6, A7]] with Proxy { val self = x - def compare (y: Tuple7[a1, a2, a3, a4, a5, a6, a7]): Int = { + def compare(y: Tuple7[A1, A2, A3, A4, A5, A6, A7]): Int = { val res = x._1 compare y._1 if (res == 0) Tuple6(x._2, x._3, x._4, x._5, x._6, x._7) compare Tuple6(y._2, y._3, y._4, y._5, y._6, y._7) else res } } - implicit def tuple82ordered[a1 <% Ordered[a1], a2 <% Ordered[a2], a3 <% Ordered[a3], a4 <% Ordered[a4], a5 <% Ordered[a5], a6 <% Ordered[a6], a7 <% Ordered[a7], a8 <% Ordered[a8]](x: Tuple8[a1, a2, a3, a4, a5, a6, a7, a8]): Ordered[Tuple8[a1, a2, a3, a4, a5, a6, a7, a8]] = - new Ordered[Tuple8[a1, a2, a3, a4, a5, a6, a7, a8]] with Proxy { + implicit def tuple82ordered[A1 <% Ordered[A1], A2 <% Ordered[A2], A3 <% Ordered[A3], A4 <% Ordered[A4], A5 <% Ordered[A5], A6 <% Ordered[A6], A7 <% Ordered[A7], A8 <% Ordered[A8]](x: Tuple8[A1, A2, A3, A4, A5, A6, A7, A8]): Ordered[Tuple8[A1, A2, A3, A4, A5, A6, A7, A8]] = + new Ordered[Tuple8[A1, A2, A3, A4, A5, A6, A7, A8]] with Proxy { val self = x - def compare (y: Tuple8[a1, a2, a3, a4, a5, a6, a7, a8]): Int = { + def compare(y: Tuple8[A1, A2, A3, A4, A5, A6, A7, A8]): Int = { val res = x._1 compare y._1 if (res == 0) Tuple7(x._2, x._3, x._4, x._5, x._6, x._7, x._8) compare Tuple7(y._2, y._3, y._4, y._5, y._6, y._7, y._8) else res } } - implicit def tuple92ordered[a1 <% Ordered[a1], a2 <% Ordered[a2], a3 <% Ordered[a3], a4 <% Ordered[a4], a5 <% Ordered[a5], a6 <% Ordered[a6], a7 <% Ordered[a7], a8 <% Ordered[a8], a9 <% Ordered[a9]](x: Tuple9[a1, a2, a3, a4, a5, a6, a7, a8, a9]): Ordered[Tuple9[a1, a2, a3, a4, a5, a6, a7, a8, a9]] = - new Ordered[Tuple9[a1, a2, a3, a4, a5, a6, a7, a8, a9]] with Proxy { + implicit def tuple92ordered[A1 <% Ordered[A1], A2 <% Ordered[A2], A3 <% Ordered[A3], A4 <% Ordered[A4], A5 <% Ordered[A5], A6 <% Ordered[A6], A7 <% Ordered[A7], A8 <% Ordered[A8], A9 <% Ordered[A9]](x: Tuple9[A1, A2, A3, A4, A5, A6, A7, A8, A9]): Ordered[Tuple9[A1, A2, A3, A4, A5, A6, A7, A8, A9]] = + new Ordered[Tuple9[A1, A2, A3, A4, A5, A6, A7, A8, A9]] with Proxy { val self = x - def compare (y: Tuple9[a1, a2, a3, a4, a5, a6, a7, a8, a9]): Int = { + def compare(y: Tuple9[A1, A2, A3, A4, A5, A6, A7, A8, A9]): Int = { val res = x._1 compare y._1 if (res == 0) Tuple8(x._2, x._3, x._4, x._5, x._6, x._7, x._8, x._9) compare Tuple8(y._2, y._3, y._4, y._5, y._6, y._7, y._8, y._9) else res } } - implicit def byte2short(x: byte): short = x.toShort - implicit def byte2int(x: byte): int = x.toInt - implicit def byte2long(x: byte): long = x.toLong - implicit def byte2float(x: byte): float = x.toFloat - implicit def byte2double(x: byte): double = x.toDouble - - implicit def short2int(x: short): int = x.toInt - implicit def short2long(x: short): long = x.toLong - implicit def short2float(x: short): float = x.toFloat - implicit def short2double(x: short): double = x.toDouble - - implicit def char2int(x: char): int = x.toInt - implicit def char2long(x: char): long = x.toLong - implicit def char2float(x: char): float = x.toFloat - implicit def char2double(x: char): double = x.toDouble - - implicit def int2long(x: int): long = x.toLong - implicit def int2float(x: int): float = x.toFloat - implicit def int2double(x: int): double = x.toDouble - - implicit def long2float(x: long): float = x.toFloat - implicit def long2double(x: long): double = x.toDouble - - implicit def float2double(x: float): double = x.toDouble - - implicit def byte2Byte(x: byte) = new java.lang.Byte(x) - implicit def short2Short(x: short) = new java.lang.Short(x) - implicit def char2Character(x: char) = new java.lang.Character(x) - implicit def int2Integer(x: int) = new java.lang.Integer(x) - implicit def long2Long(x: long) = new java.lang.Long(x) - implicit def float2Float(x: float) = new java.lang.Float(x) - implicit def double2Double(x: double) = new java.lang.Double(x) - implicit def boolean2Boolean(x: boolean) = new java.lang.Boolean(x) + implicit def byte2short(x: Byte): Short = x.toShort + implicit def byte2int(x: Byte): Int = x.toInt + implicit def byte2long(x: Byte): Long = x.toLong + implicit def byte2float(x: Byte): Float = x.toFloat + implicit def byte2double(x: Byte): Double = x.toDouble + + implicit def short2int(x: Short): Int = x.toInt + implicit def short2long(x: Short): Long = x.toLong + implicit def short2float(x: Short): Float = x.toFloat + implicit def short2double(x: Short): Double = x.toDouble + + implicit def char2int(x: Char): Int = x.toInt + implicit def char2long(x: Char): Long = x.toLong + implicit def char2float(x: Char): Float = x.toFloat + implicit def char2double(x: Char): Double = x.toDouble + + implicit def int2long(x: Int): Long = x.toLong + implicit def int2float(x: Int): Float = x.toFloat + implicit def int2double(x: Int): Double = x.toDouble + + implicit def long2float(x: Long): Float = x.toFloat + implicit def long2double(x: Long): Double = x.toDouble + + implicit def float2double(x: Float): Double = x.toDouble + + implicit def byte2Byte(x: Byte) = new java.lang.Byte(x) + implicit def short2Short(x: Short) = new java.lang.Short(x) + implicit def char2Character(x: Char) = new java.lang.Character(x) + implicit def int2Integer(x: Int) = new java.lang.Integer(x) + implicit def long2Long(x: Long) = new java.lang.Long(x) + implicit def float2Float(x: Float) = new java.lang.Float(x) + implicit def double2Double(x: Double) = new java.lang.Double(x) + implicit def boolean2Boolean(x: Boolean) = new java.lang.Boolean(x) def currentThread = java.lang.Thread.currentThread() diff --git a/src/library/scala/runtime/NonLocalReturnException.scala b/src/library/scala/runtime/NonLocalReturnException.scala index ee3125f424..d21627d417 100644 --- a/src/library/scala/runtime/NonLocalReturnException.scala +++ b/src/library/scala/runtime/NonLocalReturnException.scala @@ -1,7 +1,7 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2006, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** +** / __/ __// _ | / / / _ | (c) 2002-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ -- cgit v1.2.3