modified escapedStringValue and cleaned up comments

git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@8891 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
michelou 2006-10-08 21:07:23 +00:00
parent 3dc934425b
commit 7404b3bd64
28 changed files with 552 additions and 315 deletions

View File

@ -14,7 +14,7 @@ object Loop extends Application {
}
}
for (val i <- List.range(0, 10)) {
for (val i <- 0 until 10) {
a ! A
}
}

View File

@ -1,23 +1,33 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2005-2006, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id: $
package scala.actors
import scala.collection.mutable.HashSet
/**
This object provides functions for the definition of actors and
reactors, as well as all actor operations, such as
<code>receive</code>, <code>react</code>, <code>reply</code>,
etc.
@author Philipp Haller
* This object provides functions for the definition of actors and
* reactors, as well as all actor operations, such as
* <code>receive</code>, <code>react</code>, <code>reply</code>,
* etc.
*
* @author Philipp Haller
*/
object Actor {
private[actors] val selfs = new java.util.WeakHashMap(16, 0.5f)
/**
Returns the currently executing actor. Should be used instead
of <code>this</code> in all blocks of code executed by
actors.
* Returns the currently executing actor. Should be used instead
* of <code>this</code> in all blocks of code executed by
* actors.
*/
def self: Actor = synchronized {
val t = Thread.currentThread()
@ -34,8 +44,8 @@ object Actor {
}
/**
Creates an instance of a thread-based actor executing <code>body</code>,
and starts it.
* Creates an instance of a thread-based actor executing <code>body</code>,
* and starts it.
*/
def actor(body: => Unit): ActorThread = synchronized {
val actor = new ActorThread {
@ -46,9 +56,9 @@ object Actor {
}
/**
Creates an instance of a thread-based actor specifying a
channel which can be used for typed communication with other
actors.
* Creates an instance of a thread-based actor specifying a
* channel which can be used for typed communication with other
* actors.
*/
def actor[a](ch: Channel[a])(body: => Unit): ActorThread = synchronized {
val actor = new ActorThread {
@ -60,8 +70,8 @@ object Actor {
}
/**
Creates an instance of an event-based reactor executing
<code>body</code>, and starts it.
* Creates an instance of an event-based reactor executing
* <code>body</code>, and starts it.
*/
def reactor(body: => Unit): Reactor = synchronized {
val reactor = new Reactor {
@ -72,12 +82,12 @@ object Actor {
}
/**
Receives a message from the mailbox of
<code>self</code>. Blocks if no message matching any of the
cases of <code>f</code> can be received.
Only (thread-based) actors may call this method. It fails at
runtime if executed by a reactor.
* Receives a message from the mailbox of
* <code>self</code>. Blocks if no message matching any of the
* cases of <code>f</code> can be received.
*
* Only (thread-based) actors may call this method. It fails at
* runtime if executed by a reactor.
*/
def receive[a](f: PartialFunction[Any, a]): a =
self.in.receive(f)
@ -244,10 +254,10 @@ object Actor {
}
/**
This trait defines commonalities between thread-based and
event-based actors.
@author Philipp Haller
* This trait defines commonalities between thread-based and
* event-based actors.
*
* @author Philipp Haller
*/
trait Actor {
@ -269,21 +279,21 @@ trait Actor {
}
/**
The behavior of an actor is specified by implementing this
abstract method. Note that the preferred way to create actors
is through the <code>actor</code> and <code>reactor</code>
methods defined in object <code>Actor</code>.
* The behavior of an actor is specified by implementing this
* abstract method. Note that the preferred way to create actors
* is through the <code>actor</code> and <code>reactor</code>
* methods defined in object <code>Actor</code>.
*/
def act(): Unit
/**
Sends <code>msg</code> to this actor (asynchronous).
* Sends <code>msg</code> to this actor (asynchronous).
*/
def !(msg: Any): Unit = in ! msg
/**
Sends <code>msg</code> to this actor and awaits reply
(synchronous).
* Sends <code>msg</code> to this actor and awaits reply
* (synchronous).
*/
def !?(msg: Any): Any = in !? msg
@ -397,25 +407,25 @@ trait Actor {
}
/**
Messages of this type are sent to each actor <code>a</code>
that is linked to an actor <code>b</code> whenever
<code>b</code> terminates and <code>a</code> has
<code>trapExit</code> set to <code>true</code>.
@author Philipp Haller
* Messages of this type are sent to each actor <code>a</code>
* that is linked to an actor <code>b</code> whenever
* <code>b</code> terminates and <code>a</code> has
* <code>trapExit</code> set to <code>true</code>.
*
* @author Philipp Haller
*/
case class Exit(from: Actor, reason: String)
/**
This class provides an implementation for actors based on
threads. To be able to create instances of this class, the
inherited abstract method <code>act()</code> has to be
implemented. Note that the preferred way of creating
thread-based actors is through the <code>actor</code> method
defined in object <code>Actor</code>.
@author Philipp Haller
* This class provides an implementation for actors based on
* threads. To be able to create instances of this class, the
* inherited abstract method <code>act()</code> has to be
* implemented. Note that the preferred way of creating
* thread-based actors is through the <code>actor</code> method
* defined in object <code>Actor</code>.
*
* @author Philipp Haller
*/
abstract class ActorThread extends Thread with ThreadedActor {
override def run(): Unit = {
@ -456,10 +466,10 @@ abstract class ActorThread extends Thread with ThreadedActor {
}
/**
This class provides a dynamic actor proxy for normal Java
threads.
@author Philipp Haller
* This class provides a dynamic actor proxy for normal Java
* threads.
*
* @author Philipp Haller
*/
private[actors] class ActorProxy(t: Thread) extends ThreadedActor {
def act(): Unit = {}
@ -502,7 +512,7 @@ private[actors] class ActorProxy(t: Thread) extends ThreadedActor {
<pre>
actor {
// ...
val c = select(TcpNode("127.0.0.1", 9010), 'myName)
<b>val</b> c = select(TcpNode("127.0.0.1", 9010), 'myName)
c ! msg
// ...
}
@ -517,8 +527,8 @@ object RemoteActor {
private val kernels = new scala.collection.mutable.HashMap[Actor, NetKernel]
/**
Makes <code>self</code> remotely accessible on TCP port
<code>port</code>.
* Makes <code>self</code> remotely accessible on TCP port
* <code>port</code>.
*/
def alive(port: int): Unit = {
val serv = new TcpService(port)
@ -527,8 +537,8 @@ object RemoteActor {
}
/**
Registers <code>a</code> under <code>name</code> on this
node.
* Registers <code>a</code> under <code>name</code> on this
* node.
*/
def register(name: Symbol, a: Actor): Unit = {
val kernel = kernels.get(Actor.self) match {
@ -544,8 +554,8 @@ object RemoteActor {
}
/**
Returns (a proxy for) the actor registered under
<code>name</code> on <code>node</code>.
* Returns (a proxy for) the actor registered under
* <code>name</code> on <code>node</code>.
*/
def select(node: Node, name: Symbol): Actor =
new Reactor {
@ -575,16 +585,24 @@ object RemoteActor {
/**
This class represents a machine node on a TCP network.
@author Philipp Haller
* This class represents a machine node on a TCP network.
*
* @author Philipp Haller
*/
case class Node(address: String, port: Int)
/**
This class is used by our efficient message queue
implementation.
* <p>
* This class is used by our efficient message queue
* implementation.
* </p>
* <dl class="subclasses">
* <dt><b>Direct Known Subclasses:</b></dt>
* <dd>
* <a href="MessageQueue.html" target="contentFrame">MessageQueue</a>
* </dd>
* </dl>
*/
private[actors] abstract class MessageQueueResult[Msg] {
def msg: Msg
@ -592,12 +610,12 @@ private[actors] abstract class MessageQueueResult[Msg] {
}
/**
The class <code>MessageQueue</code> provides an efficient
implementation of a message queue specialized for this actor
library. Classes in this package are supposed to be the only
clients of this class.
@author Martin Odersky, Philipp Haller
* The class <code>MessageQueue</code> provides an efficient
* implementation of a message queue specialized for this actor
* library. Classes in this package are supposed to be the only
* clients of this class.
*
* @author Martin Odersky, Philipp Haller
*/
private[actors] class MessageQueue[Msg] extends MessageQueueResult[Msg] {
var msg: Msg = _

View File

@ -1,3 +1,13 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2005-2006, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id: $
package scala.actors
import Actor._
@ -6,8 +16,8 @@ case object TIMEOUT
class SuspendActorException extends Throwable {
/*
For efficiency reasons we do not fill in
the execution stack trace.
* For efficiency reasons we do not fill in
* the execution stack trace.
*/
override def fillInStackTrace(): Throwable = {
this
@ -15,11 +25,11 @@ class SuspendActorException extends Throwable {
}
/**
This class provides a means for typed communication among
actors. Only the actor creating an instance of a
<code>Channel</code> may receive from it.
@author Philipp Haller
* This class provides a means for typed communication among
* actors. Only the actor creating an instance of a
* <code>Channel</code> may receive from it.
*
* @author Philipp Haller
*/
class Channel[Msg] {
@ -65,13 +75,13 @@ class Channel[Msg] {
}
/**
Sends <code>msg</code> to this <code>Channel</code>.
* Sends <code>msg</code> to this <code>Channel</code>.
*/
def !(msg: Msg): unit = send(msg, self)
/**
Sends <code>msg</code> to this <code>Channel</code> and
awaits reply.
* Sends <code>msg</code> to this <code>Channel</code> and
* awaits reply.
*/
def !?(msg: Msg): Any = {
self.freshReply()
@ -82,13 +92,13 @@ class Channel[Msg] {
}
/**
Forwards <code>msg</code> to <code>this</code> keeping the
last sender as sender instead of <code>self</code>.
* Forwards <code>msg</code> to <code>this</code> keeping the
* last sender as sender instead of <code>self</code>.
*/
def forward(msg: Msg): unit = send(msg, receiver.sender)
/**
Receives a message from this <code>Channel</code>.
* Receives a message from this <code>Channel</code>.
*/
def receive[R](f: PartialFunction[Msg, R]): R = {
assert(self == receiver, "receive from channel belonging to other actor")
@ -137,10 +147,10 @@ class Channel[Msg] {
}
/**
Receives a message from this <code>Channel</code>. If no
message could be received before <code>msec</code>
milliseconds elapsed, the <code>TIMEOUT</code> action is
executed if specified.
* Receives a message from this <code>Channel</code>. If no
* message could be received before <code>msec</code>
* milliseconds elapsed, the <code>TIMEOUT</code> action is
* executed if specified.
*/
def receiveWithin[R](msec: long)(f: PartialFunction[Any, R]): R = {
assert(self == receiver, "receive from channel belonging to other actor")
@ -172,7 +182,7 @@ class Channel[Msg] {
}
/**
<code>receive</code> for reactors.
* <code>receive</code> for reactors.
*/
def react(f: PartialFunction[Any, Unit]): Nothing = {
assert(self == receiver, "react on channel belonging to other actor")
@ -193,7 +203,7 @@ class Channel[Msg] {
}
/**
<code>receiveWithin</code> for reactors.
* <code>receiveWithin</code> for reactors.
*/
def reactWithin(msec: long)(f: PartialFunction[Any, Unit]): Nothing = {
assert(self == receiver, "react on channel belonging to other actor")

View File

@ -1,13 +1,23 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2005-2006, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id: $
package scala.actors
/**
This class provides (together with <code>Channel</code>) an
implementation of event-based actors (aka reactors).
The main ideas of our approach are explained in the paper<br>
<b>Event-Based Programming without Inversion of Control</b>, Philipp Haller, Martin Odersky <i>Proc. JMLC 2006</i>
@author Philipp Haller
* This class provides (together with <code>Channel</code>) an
* implementation of event-based actors (aka reactors).
*
* The main ideas of our approach are explained in the paper<br>
* <b>Event-Based Programming without Inversion of Control</b>, Philipp Haller, Martin Odersky <i>Proc. JMLC 2006</i>
*
* @author Philipp Haller
*/
trait Reactor extends Actor {
private var lastSender: Actor = null
@ -20,7 +30,7 @@ trait Reactor extends Actor {
private[actors] var continuation: PartialFunction[Any, Unit] = null
private[actors] var timeoutPending = false
private[actors] def scheduleActor(f: PartialFunction[Any, Unit], msg: Any) = {
private[actors] def scheduleActor(f: PartialFunction[Any, Unit], msg: Any) =
if (f == null && continuation == null) {
// do nothing (timeout is handled instead)
}
@ -30,7 +40,6 @@ trait Reactor extends Actor {
msg)
Scheduler.execute(task)
}
}
private[actors] def defaultDetachActor: PartialFunction[Any, Unit] => Unit =
(f: PartialFunction[Any, Unit]) => {
@ -48,15 +57,14 @@ trait Reactor extends Actor {
resetActor()
/**
Starts this reactor.
* Starts this reactor.
*/
def start(): Unit = {
def start(): Unit =
Scheduler.execute(new StartTask(this))
}
/**
Terminates this reactor, thereby influencing linked actors
(see Actor.exit).
* Terminates this reactor, thereby influencing linked actors
* (see Actor.exit).
*/
def exit(reason: String): Unit = {
exitReason = reason
@ -65,23 +73,23 @@ trait Reactor extends Actor {
}
/**
The abstract class <code>Reaction</code> associates an instance
of a <code>Reactor</code> with a
<code>java.lang.Runnable</code>. It is also the super class of
the different kinds of tasks used for the execution of
<code>Reactor</code>s.
@author Philipp Haller
* The abstract class <code>Reaction</code> associates an instance
* of a <code>Reactor</code> with a
* <code>java.lang.Runnable</code>. It is also the super class of
* the different kinds of tasks used for the execution of
* <code>Reactor</code>s.
*
* @author Philipp Haller
*/
private[actors] abstract class Reaction extends Runnable {
def actor: Reactor
}
/**
This class represents task items used to start the execution
of <code>Reactor</code>s.
@author Philipp Haller
* This class represents task items used to start the execution
* of <code>Reactor</code>s.
*
* @author Philipp Haller
*/
private[actors] class StartTask(a: Reactor) extends Reaction {
def actor = a
@ -100,16 +108,13 @@ private[actors] class StartTask(a: Reactor) extends Reaction {
a.exit("normal")
}
catch {
case _: InterruptedException => {
case _: InterruptedException =>
a.exitLinked()
}
case d: SuspendActorException => {
case d: SuspendActorException =>
// do nothing (continuation is already saved)
}
case t: Throwable => {
case t: Throwable =>
a.exit(t.toString())
}
}
finally {
Actor.selfs.put(t, saved)
}
@ -117,11 +122,11 @@ private[actors] class StartTask(a: Reactor) extends Reaction {
}
/**
This class represents task items used to execute actions
specified in arguments of <code>react</code> and
<code>reactWithin</code>.
@author Philipp Haller
* This class represents task items used to execute actions
* specified in arguments of <code>react</code> and
* <code>reactWithin</code>.
*
* @author Philipp Haller
*/
private[actors] class ActorTask(a: Reactor,
f: PartialFunction[Any, Unit],
@ -142,14 +147,13 @@ private[actors] class ActorTask(a: Reactor,
a.exit("normal")
}
catch {
case _: InterruptedException => a.exitLinked()
case d: SuspendActorException => {
case _: InterruptedException =>
a.exitLinked()
case d: SuspendActorException =>
// do nothing (continuation is already saved)
}
case t: Throwable => {
case t: Throwable =>
a.exit(t.toString())
}
}
finally {
Actor.selfs.put(t, saved)
}

View File

@ -1,13 +1,23 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2005-2006, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id: $
package scala.actors
import scala.collection.mutable.{Queue,Buffer,ArrayBuffer}
import scala.collection.mutable.{ArrayBuffer, Buffer, Queue}
/**
The <code>Scheduler</code> object is used by
<code>Reactor</code> to execute tasks of an execution of a
reactor.
@author Philipp Haller
* The <code>Scheduler</code> object is used by
* <code>Reactor</code> to execute tasks of an execution of a
* reactor.
*
* @author Philipp Haller
*/
object Scheduler {
private var sched: IScheduler =
@ -22,18 +32,16 @@ object Scheduler {
sched.execute(task)
}
def tick(a: Reactor) = {
sched.tick(a)
}
def tick(a: Reactor) = sched.tick(a)
def shutdown(): Unit = sched.shutdown()
}
/**
This abstract class provides a common interface for all
schedulers used to execute reactors.
@author Philipp Haller
* This abstract class provides a common interface for all
* schedulers used to execute reactors.
*
* @author Philipp Haller
*/
abstract class IScheduler {
def execute(task: Reaction): Unit
@ -50,10 +58,10 @@ abstract class IScheduler {
}
/**
This scheduler executes the tasks of a reactor on a single
thread (the current thread).
@author Philipp Haller
* This scheduler executes the tasks of a reactor on a single
* thread (the current thread).
*
* @author Philipp Haller
*/
class SingleThreadedScheduler extends IScheduler {
def execute(task: Reaction): Unit = {
@ -69,10 +77,10 @@ class SingleThreadedScheduler extends IScheduler {
}
/**
This scheduler creates additional threads whenever there is no
idle thread available.
@author Philipp Haller
* This scheduler creates additional threads whenever there is no
* idle thread available.
*
* @author Philipp Haller
*/
class SpareWorkerScheduler extends IScheduler {
private val tasks = new Queue[Reaction]
@ -82,7 +90,7 @@ class SpareWorkerScheduler extends IScheduler {
private var maxWorkers = 2
def init() = {
for (val i <- List.range(0, 2)) {
for (val i <- 0 until 2) {
val worker = new WorkerThread(this)
workers += worker
worker.start()
@ -121,7 +129,7 @@ class SpareWorkerScheduler extends IScheduler {
def shutdown(): Unit = synchronized {
terminating = true
val numNonIdle = workers.length - idle.length
for (val i <- List.range(0, numNonIdle))
for (val i <- 0 until numNonIdle)
tasks += QUIT_TASK
val idleThreads = idle.elements
while (idleThreads.hasNext) {
@ -133,10 +141,10 @@ class SpareWorkerScheduler extends IScheduler {
}
/**
This class is used by schedulers to execute reactor tasks on
multiple threads.
@author Philipp Haller
* This class is used by schedulers to execute reactor tasks on
* multiple threads.
*
* @author Philipp Haller
*/
class WorkerThread(sched: IScheduler) extends Thread {
private var task: Runnable = null
@ -150,9 +158,7 @@ class WorkerThread(sched: IScheduler) extends Thread {
override def run(): Unit = synchronized {
try {
while (running) {
if (task != null) {
task.run()
}
if (task != null) task.run()
task = sched.getTask(this)
if (task == sched.QUIT_TASK) {
running = false

View File

@ -1,3 +1,13 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2005-2006, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id: $
package scala.actors
/**

View File

@ -1,9 +1,19 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2005-2006, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id: $
package scala.actors
/**
* This class allows the (local) sending of a message to an actor after
* a timeout. Used by the library to build receiveWithin(time: long).
* Note that the library deletes non-received TIMEOUT message if a
* a timeout. Used by the library to build <code>receiveWithin(time: long)</code>.
* Note that the library deletes non-received <code>TIMEOUT</code> message if a
* message is received before the time-out occurs.
*
* @author Sebastien Noir

View File

@ -1,3 +1,13 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2005-2006, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id: $
package scala.actors.remote
object FreshNameCreator {

View File

@ -1,8 +1,20 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2005-2006, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id: $
package scala.actors.remote
import java.io.{ByteArrayInputStream,ByteArrayOutputStream,ObjectInputStream,ObjectOutputStream}
import java.io.{ByteArrayInputStream, ByteArrayOutputStream,
ObjectInputStream, ObjectOutputStream}
class JavaSerializer(serv: Service) extends Serializer(serv) {
def serialize(o: AnyRef): Array[Byte] = {
val bos = new ByteArrayOutputStream()
val out = new ObjectOutputStream(bos)

View File

@ -1,7 +1,15 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2005-2006, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id: $
package scala.actors.remote
import java.io.{IOException,StringReader,StringWriter}
import java.net.UnknownHostException
import scala.collection.mutable.{HashMap, HashSet}
case class NamedSend(senderName: Symbol, receiver: Symbol, data: Array[Byte])
@ -25,7 +33,8 @@ class NetKernel(service: Service) {
register(freshName, Actor.self)
freshName
}
case Some(name) => name
case Some(name) =>
name
}
namedSend(node, senderName, name, msg)
}
@ -40,17 +49,17 @@ class NetKernel(service: Service) {
def act() = { a ! msg }
override def !(msg: Any): Unit = {
msg match {
case refmsg: AnyRef => {
case refmsg: AnyRef =>
namedSend(senderNode, receiver, senderName, refmsg)
}
}
}
override def !?(msg: Any): Any =
error("!? not implemented for remote actors.")
}
senderProxy.start()
}
case None => // message is lost
case None =>
// message is lost
}
}
}

View File

@ -1,3 +1,13 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2005-2006, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id: $
package scala.actors.remote
import java.io.{DataInputStream, DataOutputStream, EOFException, IOException}

View File

@ -1,3 +1,13 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2005-2006, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id: $
package scala.actors.remote
trait Service {

View File

@ -1,7 +1,18 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2005-2006, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id: $
package scala.actors.remote
import java.io.{DataInputStream,DataOutputStream,BufferedReader,PrintWriter,
IOException,InputStreamReader,OutputStreamWriter}
import java.io.{BufferedReader, DataInputStream, DataOutputStream,
IOException, InputStreamReader, OutputStreamWriter,
PrintWriter}
import java.net.{InetAddress, ServerSocket, Socket, UnknownHostException}
object TcpService {

View File

@ -1,29 +1,40 @@
/* NSC -- new scala compiler
* Copyright 2005 LAMP/EPFL
/* NSC -- new Scala compiler
* Copyright 2005-2006 LAMP/EPFL
* @author Martin Odersky
*/
// $Id$
package scala.tools.nsc;
/** An nsc sub-component.
package scala.tools.nsc
/** <p>
* An nsc sub-component.
* </p>
* <dl class="subclasses">
* <dt><b>Direct Known Subclasses:</b></dt>
* <dd>
* <a href="transform/Transform.html" target="contentFrame">Transform</a>
* </dd>
* </dl>
*
* @author Martin Odersky
*/
abstract class SubComponent {
/** The global environment; overridden by instantiation in Global. */
val global: Global;
val global: Global
/** The name of the phase */
val phaseName: String;
val phaseName: String
/** New flags defined by the phase which are not valid before */
def phaseNewFlags: long = 0;
def phaseNewFlags: long = 0
/** The phase factory */
def newPhase(prev: Phase): Phase;
def newPhase(prev: Phase): Phase
/** A standard phase template */
abstract class StdPhase(prev: Phase) extends global.GlobalPhase(prev) {
def name = phaseName;
override def newFlags = phaseNewFlags;
def name = phaseName
override def newFlags = phaseNewFlags
}
}

View File

@ -111,7 +111,7 @@ abstract class TreePrinters {
case Triple(tp, args, nvPairs) =>
str.append(tp.toString())
if (!args.isEmpty)
str.append(args.mkString("(", ",", ")"))
str.append(args.map(.escapedStringValue).mkString("(", ",", ")"))
if (!nvPairs.isEmpty)
for (val Pair(Pair(name, value), index) <- nvPairs.zipWithIndex) {
if (index > 0)

View File

@ -1,98 +1,99 @@
/* NSC -- new scala compiler
* Copyright 2005 LAMP/EPFL
/* NSC -- new Scala compiler
* Copyright 2005-2006 LAMP/EPFL
* @author Martin Odersky
*/
// $Id$
package scala.tools.nsc.ast.parser;
package scala.tools.nsc.ast.parser
object Tokens {
/** special tokens */
final val EMPTY = -3;
final val UNDEF = -2;
final val ERROR = -1;
final val EOF = 0;
final val EMPTY = -3
final val UNDEF = -2
final val ERROR = -1
final val EOF = 0
/** literals */
final val CHARLIT = 1;
final val INTLIT = 2;
final val LONGLIT = 3;
final val FLOATLIT = 4;
final val DOUBLELIT = 5;
final val STRINGLIT = 6;
final val SYMBOLLIT = 7;
final val CHARLIT = 1
final val INTLIT = 2
final val LONGLIT = 3
final val FLOATLIT = 4
final val DOUBLELIT = 5
final val STRINGLIT = 6
final val SYMBOLLIT = 7
/** identifiers */
final val IDENTIFIER = 10;
final val BACKQUOTED_IDENT = 11;
final val IDENTIFIER = 10
final val BACKQUOTED_IDENT = 11
/** keywords */
final val IF = 20;
final val FOR = 21;
final val ELSE = 22;
final val THIS = 23;
final val NULL = 24;
final val NEW = 25;
final val WITH = 26;
final val SUPER = 27;
final val CASE = 28;
final val CASECLASS = 29;
final val CASEOBJECT = 30;
final val VAL = 31;
final val ABSTRACT = 32;
final val FINAL = 33;
final val PRIVATE = 34;
final val PROTECTED = 35;
final val OVERRIDE = 36;
final val IMPLICIT = 37;
final val VAR = 38;
final val DEF = 39;
final val TYPE = 40;
final val EXTENDS = 41;
final val TRUE = 42;
final val FALSE = 43;
final val OBJECT = 44;
final val CLASS = 45;
final val IF = 20
final val FOR = 21
final val ELSE = 22
final val THIS = 23
final val NULL = 24
final val NEW = 25
final val WITH = 26
final val SUPER = 27
final val CASE = 28
final val CASECLASS = 29
final val CASEOBJECT = 30
final val VAL = 31
final val ABSTRACT = 32
final val FINAL = 33
final val PRIVATE = 34
final val PROTECTED = 35
final val OVERRIDE = 36
final val IMPLICIT = 37
final val VAR = 38
final val DEF = 39
final val TYPE = 40
final val EXTENDS = 41
final val TRUE = 42
final val FALSE = 43
final val OBJECT = 44
final val CLASS = 45
final val IMPORT = 46;
final val PACKAGE = 47;
final val YIELD = 48;
final val DO = 49;
final val TRAIT = 50;
final val SEALED = 51;
final val THROW = 52;
final val TRY = 53;
final val CATCH = 54;
final val FINALLY = 55;
final val WHILE = 56;
final val RETURN = 57;
final val MATCH = 58;
final val REQUIRES = 59;
final val IMPORT = 46
final val PACKAGE = 47
final val YIELD = 48
final val DO = 49
final val TRAIT = 50
final val SEALED = 51
final val THROW = 52
final val TRY = 53
final val CATCH = 54
final val FINALLY = 55
final val WHILE = 56
final val RETURN = 57
final val MATCH = 58
final val REQUIRES = 59
/** special symbols */
final val COMMA = 61;
final val SEMI = 62;
final val DOT = 63;
final val USCORE = 64;
final val COLON = 65;
final val EQUALS = 66;
final val LARROW = 67;
final val ARROW = 68;
final val NEWLINE = 69;
final val SUBTYPE = 70;
final val SUPERTYPE = 71;
final val HASH = 72;
final val AT = 73;
final val VIEWBOUND = 74;
final val COMMA = 61
final val SEMI = 62
final val DOT = 63
final val USCORE = 64
final val COLON = 65
final val EQUALS = 66
final val LARROW = 67
final val ARROW = 68
final val NEWLINE = 69
final val SUBTYPE = 70
final val SUPERTYPE = 71
final val HASH = 72
final val AT = 73
final val VIEWBOUND = 74
/** parenthesis */
final val LPAREN = 90;
final val RPAREN = 91;
final val LBRACKET = 92;
final val RBRACKET = 93;
final val LBRACE = 94;
final val RBRACE = 95;
final val LPAREN = 90
final val RPAREN = 91
final val LBRACKET = 92
final val RBRACKET = 93
final val LBRACE = 94
final val RBRACE = 95
/** XML mode */
final val XMLSTART = 96;
final val XMLSTART = 96
}

View File

@ -251,7 +251,7 @@ abstract class DocGenerator extends Models {
val Triple(tpe, args, nvPairs) = attr
val name = aref(urlFor(tpe.symbol), contentFrame, tpe.toString)
if (!args.isEmpty)
buf.append(args.mkString("(", ",", ")"))
buf.append(args.map(.escapedStringValue).mkString("(", ",", ")"))
if (!nvPairs.isEmpty)
for (val Pair(Pair(name, value), index) <- nvPairs.zipWithIndex) {
if (index > 0)
@ -263,7 +263,7 @@ abstract class DocGenerator extends Models {
var res: NodeSeq = Text("[")
val attrs = tree.symbol.attributes
for (val i <- attrs.indices) {
if (i > 0) res = res.concat(Text(","))
if (i > 0) res = res.concat(Text("," + LINE_SEPARATOR))
res = res.concat(attrFor(attrs(i)))
}
br(res.concat(Text("]")))

View File

@ -40,6 +40,14 @@ div.page-title {
text-align: center;
}
dl.subclasses {
margin:0 0 0 -20px;
}
dl.subclasses dd {
margin:0 0 0 20px;
}
span.entity {
color: #ff6666;
}

View File

@ -205,7 +205,7 @@ trait Constants requires SymbolTable {
tag match {
case NullTag => "null"
case StringTag => "\"" + escape(stringValue) + "\""
case ClassTag => signature(typeValue) + ".class"
case ClassTag => "classOf[" + signature(typeValue) + "]"
case CharTag => escape("\'" + charValue + "\'")
case LongTag => longValue.toString() + "L"
case _ => value.toString()

View File

@ -9,6 +9,16 @@ package scala.tools.nsc.symtab
import scala.tools.nsc.util.NameTransformer
import scala.tools.util.UTF8Codec
/** <p>
* The class <code>Names</code> ...
* </p>
* <dl class="subclasses">
* <dt><b>Direct Known Subclasses:</b></dt>
* <dd>
* <a href="SymbolTable.html" target="contentFrame">SymbolTable</a>
* </dd>
* </dl>
*/
class Names {
// Operations -------------------------------------------------------------
@ -119,7 +129,7 @@ class Names {
// Classes ----------------------------------------------------------------------
/** The name class */
/** The name class. */
abstract class Name(index: int, len: int) extends Function1[int, char] {
/** Index into name table */

View File

@ -6,8 +6,21 @@
package scala.tools.nsc.transform
/** A base class for transforms.
/** <p>
* A base class for transforms.
* A transform contains a compiler phase which applies a tree transformer.
* </p>
* <dl class="subclasses">
* <dt><b>Direct Known Subclasses:</b></dt>
* <dd>
* <a href="AddInterfaces.html" target="contentFrame">AddInterfaces</a>,
* <a href="ExplicitOuter.html" target="contentFrame">ExplicitOuter</a>,
* <a href="Flatten.html" target="contentFrame">Flatten</a>,
* <a href="LambdaLift.html" target="contentFrame">LambdaLift</a>,
* <a href="Mixin.html" target="contentFrame">Mixin</a>,
* <a href="UnCurry.html" target="contentFrame">UnCurry</a>
* </dd>
* </dl>
*/
abstract class InfoTransform extends Transform {
import global.{Symbol, Type, InfoTransformer, infoTransformers}

View File

@ -6,8 +6,21 @@
package scala.tools.nsc.transform;
/** A base class for transforms.
/** <p>
* A base class for transforms.
* A transform contains a compiler phase which applies a tree transformer.
* </p>
* <dl class="subclasses">
* <dt><b>Direct Known Subclasses:</b></dt>
* <dd>
* <a href="InfoTransform.html" target="contentFrame">CleanUp</a>,
* <a href="CleanUp.html" target="contentFrame">Constructors</a>,
* <a href="InfoTransform.html" target="contentFrame">InfoTransform</a>,
* <a href="LiftCode.html" target="contentFrame">LiftCode</a>,
* <a href="SampleTransform.html" target="contentFrame">SampleTransform</a>,
* <a href="TailCalls.html" target="contentFrame">TailCalls</a>
* </dd>
* </dl>
*
* @author Martin Odersky
* @version 1.0

View File

@ -1,6 +1,6 @@
/* NSC -- new Scala compiler
* Copyright 2005-2006 LAMP/EPFL
* @author
* @author Martin Odersky
*/
// $Id$
@ -10,20 +10,34 @@ import symtab.Flags._
import util.FreshNameCreator
import scala.collection.mutable.ListBuffer
/**
* - caseArity, caseElement implementations added to case classes
* - equals, and hashCode and toString methods are added to case classes,
* unless they are defined in the class or a baseclass
* different from java.lang.Object
* - toString method is added to case objects,
* unless they are defined in the class or a baseclass
* different from java.lang.Object
/** <ul>
* <li>
* <code>caseArity</code>, <code>caseElement</code> implementations added
* to case classes
* </li>
* <li>
* <code>equals</code>, <code>hashCode</code> and </code>toString</code>
* methods are added to case classes, unless they are defined in the
* class or a baseclass different from <code>java.lang.Object</code>
* </li>
* <li>
* <code>toString</code> method is added to case objects, unless they
* are defined in the class or a baseclass different from
* <code>java.lang.Object</code>
* </li>
* </ul>
*/
trait SyntheticMethods requires Analyzer {
import global._ // the global environment
import definitions._ // standard classes and methods
import typer.{typed} // methods to type trees
/**
* @param templ ...
* @param clazz ...
* @param unit ...
* @return ...
*/
def addSyntheticMethods(templ: Template, clazz: Symbol, unit: CompilationUnit): Template = {
def hasImplementation(name: Name): Boolean = {

View File

@ -6,7 +6,15 @@
package scala.tools.nsc.util
/** A common class for lightweight sets.
/** <p>
* A common class for lightweight sets.
* </p>
* <dl class="subclasses">
* <dt><b>Direct Known Subclasses:</b></dt>
* <dd>
* <a href="HashSet.html" target="contentFrame">HashSet</a>
* </dd>
* </dl>
*/
abstract class Set[T <: AnyRef] {

View File

@ -13,11 +13,6 @@ package scala.tools.nsc.util
import scala.tools.nsc.io.{AbstractFile, VirtualFile}
/** Uses positions that are offsets rather than line/column pairs.
*
* @author Sean McDirmid
* @version 1.0
*/
object SourceFile {
val LF: Char = 0x0A
val FF: Char = 0x0C
@ -26,7 +21,20 @@ object SourceFile {
def isLineBreak(c: Char) = c == LF || c == FF || c == CR || c == SU
}
/** <p>
* Uses positions that are offsets rather than line/column pairs.
* </p>
* <dl class="subclasses">
* <dt><b>Direct Known Subclasses:</b></dt>
* <dd>
* <a href="CompoundSourceFile.html" target="contentFrame">CompoundSourceFile</a>,
* <a href="SourceFileFragment.html" target="contentFrame">SourceFileFragment</a>
* </dd>
* </dl>
*
* @author Sean McDirmid
* @version 1.0
*/
class SourceFile(val file: AbstractFile, _content: Array[Char]) {
import SourceFile._
@ -53,7 +61,8 @@ class SourceFile(val file: AbstractFile, _content: Array[Char]) {
new Position(this, lineToOffset(line) + column)
/** Map a position to a position in the underlying source file.
* For regular source files, simply return the argument. */
* For regular source files, simply return the argument.
*/
def positionInUltimateSource(position: Position) = position
// constants
@ -141,7 +150,11 @@ class SourceFile(val file: AbstractFile, _content: Array[Char]) {
}
}
/** A source file composed of multiple other source files. */
/** A source file composed of multiple other source files.
*
* @author Sean McDirmid
* @version 1.0
*/
class CompoundSourceFile(
name: String,
components: List[SourceFile],
@ -149,7 +162,11 @@ class CompoundSourceFile(
extends SourceFile(name, contents)
{
/** The usual constructor. Specify a name for the compound file and
* a list of component sources */
* a list of component sources.
*
* @param name ...
* @param components ...
*/
def this(name: String, components: SourceFile*) = {
/* Note that the contents leaves off the final SU character
* of all components */

View File

@ -12,10 +12,17 @@
package scala.collection
/**
/** <p>
* The class <code>BitSet</code> provides the interface for a space-efficient
* implementation of dense integer sets represented as bits in array of
* integers. Bit indices are between 0..(capacity-1) inclusive.
* </p>
* <dl class="subclasses">
* <dt><b>Direct Known Subclasses:</b></dt>
* <dd>
* <a href="immutable/BitSet.html" target="contentFrame">BitSet</a>
* </dd>
* </dl>
*
* @author Burak Emir, Stephane Micheloud, Nikolay Mihaylov
* @version 1.1

View File

@ -16,10 +16,12 @@ package scala.collection.immutable
* int array. Instances can conveniently be created from instances of
* Bit indices are between 0..(capacity-1) inclusive
*
* @param <code>size</code> represents the number of relevant bits
* @param <code>ba</code> array of ints of length <code>n</code>&gt;&gt;&gt;5
* @param <code>copy</code> if yes, then <code>ba</code> is copied and updates will
* not affect this bitset
* @param size <code>size</code> represents the number of relevant bits
* @param capacity ...
* @param ba <code>ba</code> array of ints of length
* <code>n&gt;&gt;&gt;5</code>
* @param copy <code>copy</code> if yes, then <code>ba</code> is copied
* and updates will not affect this bitset
*
* @author Burak Emir, Nikolay Mihaylov
* @version 1.0

View File

@ -13,23 +13,36 @@ package scala.io
import compat.StringBuilder
/** convenience methods to encode line and column number in one
* single integer. The encode line (column)
* numbers range from 0 to LINE_MASK (COLUMN_MASK), where 0 indicates
* that the line (column) is the undefined and 1 represents the first
* line (column). Line (Column) numbers greater than LINE_MASK
* (COLUMN_MASK) are replaced by LINE_MASK (COLUMN_MASK). Furthermore,
* if the encoded line number is LINE_MASK, the column number is
* always set to 0.
/** <p>
* The object <code>Position</code> provides convenience methods to encode
* line and column number in one single integer. The encode line (column)
* numbers range from 0 to <code>LINE_MASK</code>
* (<code>COLUMN_MASK</code>), where 0 indicates that the line (column) is
* the undefined and 1 represents the first line (column). Line (Column)
* numbers greater than <code>LINE_MASK</code>
* (<code>COLUMN_MASK</code>) are replaced by <code>LINE_MASK</code>
* (<code>COLUMN_MASK</code>). Furthermore, if the encoded line number is
* <code>LINE_MASK</code>, the column number is always set to 0.
* </p>
* <p>
* The following properties hold:
* - the undefined position is 0: encode(0,0) == 0
* - encodings are non-negative : encode(line,column) >= 0
* - position order is preserved:
* (line1 &lt; line2) || (line1 == line2 &amp;&amp; column1 &lt; column2)
* implies
* encode(line1,column1) &lt;= encode(line2,column2)
* @author Burak Emir (translated from work by Matthias Zengers and others)
* </p>
* <ul>
* <li>
* the undefined position is 0: <code>encode(0,0) == 0</code>
* </li>
* <li>
* encodings are non-negative : <code>encode(line,column) >= 0</code>
* </li>
* <li>
* position order is preserved:
* <code>(line1 &lt; line2) || (line1 == line2 &amp;&amp; column1 &lt; column2)</code>
* <div>implies</div>
* <code>encode(line1,column1) &lt;= encode(line2,column2)</code>
* </li>
* </ul>
*
* @author Burak Emir (translated from work by Matthias Zenger and others)
*/
object Position {