Skip to content

Commit

Permalink
SI-7624 Fix -feature warnings in scala/tools/scalap
Browse files Browse the repository at this point in the history
... and move scalap.scala.tools.scalap.scalax.rules to
scalap.scala.tools.scalap.rules now that all the Monad/Functor/
Applicatve/... stuff has been removed.
  • Loading branch information
soc committed Aug 15, 2013
1 parent 6056f7e commit f2de2c4
Show file tree
Hide file tree
Showing 25 changed files with 98 additions and 174 deletions.
2 changes: 1 addition & 1 deletion src/partest/scala/tools/partest/nest/Runner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import scala.tools.nsc.{ Settings, CompilerCommand, Global }
import scala.tools.nsc.reporters.ConsoleReporter
import scala.tools.nsc.util.{ Exceptional, ScalaClassLoader, stackTraceString }
import scala.tools.scalap.Main.decompileScala
import scala.tools.scalap.scalax.rules.scalasig.ByteCode
import scala.tools.scalap.scalasig.ByteCode
import scala.util.{ Try, Success, Failure }
import ClassPath.{ join, split }
import PartestDefaults.{ javaCmd, javacCmd }
Expand Down
1 change: 0 additions & 1 deletion src/scalap/scala/tools/scalap/Arguments.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
**
*/


package scala.tools.scalap

import scala.collection.mutable
Expand Down
12 changes: 3 additions & 9 deletions src/scalap/scala/tools/scalap/ByteArrayReader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
**
*/


package scala
package tools.scalap

package scala.tools.scalap

class ByteArrayReader(content: Array[Byte]) {

Expand Down Expand Up @@ -104,9 +101,6 @@ class ByteArrayReader(content: Array[Byte]) {
def getDouble(bp: Int): Double = java.lang.Double.longBitsToDouble(getLong(bp))

/** skip next 'n' bytes
*/
def skip(n: Int) {
bp += n
}

*/
def skip(n: Int): Unit = bp += n
}
2 changes: 0 additions & 2 deletions src/scalap/scala/tools/scalap/Classfile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
**
*/


package scala.tools.scalap


class Classfile(in: ByteArrayReader) {
import Classfiles._

Expand Down
2 changes: 0 additions & 2 deletions src/scalap/scala/tools/scalap/Classfiles.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
**
*/


package scala.tools.scalap


object Classfiles {
final val JAVA_MAGIC = 0xCAFEBABE
final val JAVA_MAJOR_VERSION = 45
Expand Down
8 changes: 2 additions & 6 deletions src/scalap/scala/tools/scalap/CodeWriter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@
*/


package scala
package tools.scalap
package scala.tools.scalap

import java.io._


class CodeWriter(writer: Writer) {
class CodeWriter(writer: java.io.Writer) {

private val nl = scala.compat.Platform.EOL
private var step = " "
Expand Down
30 changes: 12 additions & 18 deletions src/scalap/scala/tools/scalap/Decode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
**
*/

// $Id$

package scala.tools.scalap

import scala.tools.scalap.scalax.rules.scalasig._
import scala.tools.nsc.util.ScalaClassLoader
import scala.tools.nsc.util.ScalaClassLoader.appLoader
import scala.tools.scalap.scalasig._

import scala.reflect.internal.util.ScalaClassLoader
import scala.reflect.internal.pickling.ByteCodecs

import ClassFileParser.{ ConstValueIndex, Annotation }
import Main.{ SCALA_SIG, SCALA_SIG_ANNOTATION, BYTES_VALUE }

/** Temporary decoder. This would be better off in the scala.tools.nsc
* but right now the compiler won't acknowledge scala.tools.scalap
Expand All @@ -31,25 +28,24 @@ object Decode {
/** Return the classfile bytes representing the scala sig classfile attribute.
* This has been obsoleted by the switch to annotations.
*/
def scalaSigBytes(name: String): Option[Array[Byte]] = scalaSigBytes(name, appLoader)
def scalaSigBytes(name: String): Option[Array[Byte]] = scalaSigBytes(name, ScalaClassLoader.appLoader)
def scalaSigBytes(name: String, classLoader: ScalaClassLoader): Option[Array[Byte]] = {
val bytes = classLoader.classBytes(name)
val reader = new ByteArrayReader(bytes)
val cf = new Classfile(reader)
cf.scalaSigAttribute map (_.data)
}

/** Return the bytes representing the annotation
*/
def scalaSigAnnotationBytes(name: String): Option[Array[Byte]] = scalaSigAnnotationBytes(name, appLoader)
/** Return the bytes representing the annotation. */
def scalaSigAnnotationBytes(name: String): Option[Array[Byte]] = scalaSigAnnotationBytes(name, ScalaClassLoader.appLoader)
def scalaSigAnnotationBytes(name: String, classLoader: ScalaClassLoader): Option[Array[Byte]] = {
val bytes = classLoader.classBytes(name)
val byteCode = ByteCode(bytes)
val classFile = ClassFileParser.parse(byteCode)
import classFile._

classFile annotation SCALA_SIG_ANNOTATION map { case Annotation(_, els) =>
val bytesElem = els find (x => constant(x.elementNameIndex) == BYTES_VALUE) getOrElse null
classFile annotation Main.SCALA_SIG_ANNOTATION map { case Annotation(_, els) =>
val bytesElem = els find (x => constant(x.elementNameIndex) == Main.BYTES_VALUE) getOrElse null
val _bytes = bytesElem.elementValue match { case ConstValueIndex(x) => constantWrapped(x) }
val bytes = _bytes.asInstanceOf[StringBytesPair].bytes
val length = ByteCodecs.decode(bytes)
Expand All @@ -58,16 +54,15 @@ object Decode {
}
}

/** private[scala] so nobody gets the idea this is a supported interface.
*/
/** private[scala] so nobody gets the idea this is a supported interface. */
private[scala] def caseParamNames(path: String): Option[List[String]] = {
val (outer, inner) = (path indexOf '$') match {
case -1 => (path, "")
case x => (path take x, path drop (x + 1))
}

for {
clazz <- appLoader.tryToLoadClass[AnyRef](outer)
clazz <- ScalaClassLoader.appLoader.tryToLoadClass[AnyRef](outer)
ssig <- ScalaSigParser.parse(clazz)
}
yield {
Expand All @@ -85,11 +80,10 @@ object Decode {
}
}

/** Returns a map of Alias -> Type for the given package.
*/
/** Returns a map of Alias -> Type for the given package. */
private[scala] def typeAliases(pkg: String) = {
for {
clazz <- appLoader.tryToLoadClass[AnyRef](pkg + ".package")
clazz <- ScalaClassLoader.appLoader.tryToLoadClass[AnyRef](pkg + ".package")
ssig <- ScalaSigParser.parse(clazz)
}
yield {
Expand Down
4 changes: 1 addition & 3 deletions src/scalap/scala/tools/scalap/JavaWriter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
**
*/


package scala.tools.scalap

import java.io._
import scala.reflect.NameTransformer

class JavaWriter(classfile: Classfile, writer: Writer) extends CodeWriter(writer) {
class JavaWriter(classfile: Classfile, writer: java.io.Writer) extends CodeWriter(writer) {

val cf = classfile

Expand Down
16 changes: 8 additions & 8 deletions src/scalap/scala/tools/scalap/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
**
*/

package scala
package tools.scalap
package scala.tools.scalap

import java.io.{ PrintStream, OutputStreamWriter, ByteArrayOutputStream }
import scala.reflect.NameTransformer
import scalax.rules.scalasig._

import scala.tools.nsc.util.{ ClassPath, JavaClassPath }
import scala.tools.util.PathResolver
import ClassPath.DefaultJavaContext
import scala.tools.nsc.util.ClassPath.DefaultJavaContext
import scala.tools.nsc.io.AbstractFile

import scala.tools.scalap.scalasig._


/**The main object used to execute scalap on the command-line.
*
* @author Matthias Zenger, Stephane Micheloud, Burak Emir, Ilya Sergey
Expand Down Expand Up @@ -104,7 +104,7 @@ class Main {
// we have to encode every fragment of a name separately, otherwise the NameTransformer
// will encode using unicode escaping dot separators as well
// we can afford allocations because this is not a performance critical code
classname.split('.').map(NameTransformer.encode).mkString(".")
classname.split('.').map(scala.reflect.NameTransformer.encode).mkString(".")
}
val cls = path.findClass(encName)
if (cls.isDefined && cls.get.binary.isDefined) {
Expand Down Expand Up @@ -185,7 +185,7 @@ object Main extends Main {
val cparg = List("-classpath", "-cp") map (arguments getArgument _) reduceLeft (_ orElse _)
val path = cparg match {
case Some(cp) => new JavaClassPath(DefaultJavaContext.classesInExpandedPath(cp), DefaultJavaContext)
case _ => PathResolver.fromPathString(".") // include '.' in the default classpath SI-6669
case _ => scala.tools.util.PathResolver.fromPathString(".") // include '.' in the default classpath SI-6669
}
// print the classpath if output is verbose
if (verbose)
Expand Down
6 changes: 2 additions & 4 deletions src/scalap/scala/tools/scalap/MetaParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@
*/


package scala
package tools.scalap
package scala.tools.scalap

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)
val scanner = new java.util.StringTokenizer(meta, "()[], \t<;", true)
var token: String = _
val res = new StringBuffer

Expand Down
3 changes: 1 addition & 2 deletions src/scalap/scala/tools/scalap/Properties.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
package scala.tools.scalap

/** Loads decoder.properties from the jar. */
object Properties extends scala.util.PropertiesTrait
{
object Properties extends scala.util.PropertiesTrait {
protected def propCategory = "decoder"
protected def pickJarBasedOn = classOf[Classfile]
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
//
// -----------------------------------------------------------------------------

package scala.tools.scalap
package scalax
package rules
package scala.tools.scalap.rules

import scala.collection.mutable

Expand All @@ -22,7 +20,7 @@ trait MemoisableRules extends Rules {
from[In] { in => in.memo(key, rule(in)) }
}

override def ruleWithName[In, Out, A, X](name : String, f : In => rules.Result[Out, A, X]) = super.ruleWithName(name, (in : In) => in match {
override def ruleWithName[In, Out, A, X](name : String, f : In => Result[Out, A, X]) = super.ruleWithName(name, (in : In) => in match {
case s : Memoisable => s.memo(name, f(in))
case _ => f(in)
})
Expand Down Expand Up @@ -56,6 +54,3 @@ trait DefaultMemoisable extends Memoisable {
if(DefaultMemoisable.debug) println(key + " -> " + t + " (" + out + ")")
}
}



Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
//
// -----------------------------------------------------------------------------

package scala.tools.scalap
package scalax
package rules;
package scala.tools.scalap.rules;

/** Represents the combined value of two rules applied in sequence.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
//
// -----------------------------------------------------------------------------

package scala.tools.scalap
package scalax
package rules
package scala.tools.scalap.rules

/** A Rule is a function from some input to a Result. The result may be:
* <ul>
Expand Down Expand Up @@ -91,11 +89,11 @@ trait Rule[-In, +Out, +A, +X] extends (In => Result[Out, A, X]) {
/** Apply the result of this rule to the function returned by the previous rule */
def <~:[InPrev, B, X2 >: X](prev : => Rule[InPrev, In, A => B, X2]) = for (fa2b <- prev; a <- this) yield fa2b(a)

def ~![Out2, B, X2 >: X](next : => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next orError) yield new ~(a, b)
def ~![Out2, B, X2 >: X](next : => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next.orError) yield new ~(a, b)

def ~-![Out2, B, X2 >: X](next : => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next orError) yield a
def ~-![Out2, B, X2 >: X](next : => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next.orError) yield a

def -~![Out2, B, X2 >: X](next : => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next orError) yield b
def -~![Out2, B, X2 >: X](next : => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next.orError) yield b

def -[In2 <: In](exclude : => Rule[In2, Any, Any, Any]) = !exclude -~ this

Expand Down Expand Up @@ -172,6 +170,3 @@ trait Choice[-In, +Out, +A, +X] extends Rule[In, Out, A, X] {
lazy val choices = Choice.this.choices ::: other :: Nil
}
}



Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// -----------------------------------------------------------------------------

package scala.tools.scalap
package scalax
package rules

trait Name {
Expand All @@ -26,12 +25,17 @@ trait Name {
* Inspired by the Scala parser combinator.
*/
trait Rules {
implicit def rule[In, Out, A, X](f : In => Result[Out, A, X]) : Rule[In, Out, A, X] = new DefaultRule(f)

import scala.language.implicitConversions
implicit def rule[In, Out, A, X](f : In => Result[Out, A, X]) : Rule[In, Out, A, X] = new DefaultRule(f)
implicit def inRule[In, Out, A, X](rule : Rule[In, Out, A, X]) : InRule[In, Out, A, X] = new InRule(rule)
implicit def seqRule[In, A, X](rule : Rule[In, In, A, X]) : SeqRule[In, A, X] = new SeqRule(rule)

def from[In] = new {
trait FromRule[In] {
def apply[Out, A, X](f : In => Result[Out, A, X]): Rule[In, Out, A, X]
}

def from[In] = new FromRule[In] {
def apply[Out, A, X](f : In => Result[Out, A, X]) = rule(f)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
//
// -----------------------------------------------------------------------------

package scala.tools.scalap
package scalax
package rules
package scala.tools.scalap.rules

/**
* A workaround for the difficulties of dealing with
Expand Down Expand Up @@ -49,7 +47,7 @@ class SeqRule[S, +A, +X](rule : Rule[S, S, A, X]) {

/** Creates a rule that always succeeds with a Boolean value.
* Value is 'true' if this rule succeeds, 'false' otherwise */
def -? = ? map { _ isDefined }
def -? = ? map { _.isDefined }

def * = from[S] {
// tail-recursive function with reverse list accumulator
Expand Down Expand Up @@ -98,4 +96,3 @@ class SeqRule[S, +A, +X](rule : Rule[S, S, A, X]) {
in => rep(0, in)
}
}

6 changes: 6 additions & 0 deletions src/scalap/scala/tools/scalap/rules/package.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package scala.tools.scalap

package object rules {
// make some language features in this package compile without warning
implicit def postfixOps = scala.language.postfixOps
}

0 comments on commit f2de2c4

Please sign in to comment.