Skip to content

Commit

Permalink
Merge pull request #3588 from adriaanm/rebase-3587
Browse files Browse the repository at this point in the history
Revert "SI-7624 Fix -feature warnings in scala/tools/scalap"
  • Loading branch information
adriaanm committed Feb 27, 2014
2 parents 8b95e11 + 7bb1f41 commit 59bcf6b
Show file tree
Hide file tree
Showing 26 changed files with 163 additions and 83 deletions.
2 changes: 2 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ TODO:
</artifact:dependencies>


<artifact:remoteRepository id="sonatype-release" url="https://oss.sonatype.org/content/repositories/releases"/>
<artifact:remoteRepository id="extra-repo" url="${extra.repo.url}"/>

<!-- prepare, for each of the names below, the property "@{name}.cross", set to the
Expand All @@ -293,6 +294,7 @@ TODO:
<!-- so we don't have to wait for artifacts to synch to maven central
(we don't distribute partest with Scala, so the risk of sonatype and maven being out of synch is irrelevant):
-->
<artifact:remoteRepository refid="sonatype-release"/>
<artifact:remoteRepository refid="extra-repo"/>
<dependency groupId="org.scala-lang.modules" artifactId="scala-partest${partest.cross}" version="${partest.version.number}" />
</artifact:dependencies>
Expand Down
1 change: 1 addition & 0 deletions src/scalap/scala/tools/scalap/Arguments.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
**
*/


package scala.tools.scalap

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

package scala.tools.scalap

package scala
package tools.scalap


class ByteArrayReader(content: Array[Byte]) {

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

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

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


package scala.tools.scalap


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

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


package scala.tools.scalap


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


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

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


class CodeWriter(writer: Writer) {

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

package scala.tools.scalap
// $Id$

import scala.tools.scalap.scalasig._
package scala.tools.scalap

import scala.reflect.internal.util.ScalaClassLoader
import scala.tools.scalap.scalax.rules.scalasig._
import scala.tools.nsc.util.ScalaClassLoader
import scala.tools.nsc.util.ScalaClassLoader.appLoader
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 @@ -28,24 +31,25 @@ 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, ScalaClassLoader.appLoader)
def scalaSigBytes(name: String): Option[Array[Byte]] = scalaSigBytes(name, 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, ScalaClassLoader.appLoader)
/** Return the bytes representing the annotation
*/
def scalaSigAnnotationBytes(name: String): Option[Array[Byte]] = scalaSigAnnotationBytes(name, 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 Main.SCALA_SIG_ANNOTATION map { case Annotation(_, els) =>
val bytesElem = els find (x => constant(x.elementNameIndex) == Main.BYTES_VALUE) getOrElse null
classFile annotation SCALA_SIG_ANNOTATION map { case Annotation(_, els) =>
val bytesElem = els find (x => constant(x.elementNameIndex) == 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 @@ -54,15 +58,16 @@ 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 <- ScalaClassLoader.appLoader.tryToLoadClass[AnyRef](outer)
clazz <- appLoader.tryToLoadClass[AnyRef](outer)
ssig <- ScalaSigParser.parse(clazz)
}
yield {
Expand All @@ -80,10 +85,11 @@ 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 <- ScalaClassLoader.appLoader.tryToLoadClass[AnyRef](pkg + ".package")
clazz <- appLoader.tryToLoadClass[AnyRef](pkg + ".package")
ssig <- ScalaSigParser.parse(clazz)
}
yield {
Expand Down
4 changes: 3 additions & 1 deletion src/scalap/scala/tools/scalap/JavaWriter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
**
*/


package scala.tools.scalap

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

class JavaWriter(classfile: Classfile, writer: java.io.Writer) extends CodeWriter(writer) {
class JavaWriter(classfile: Classfile, writer: 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.tools.scalap
package scala
package 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.nsc.util.ClassPath.DefaultJavaContext
import scala.tools.util.PathResolver
import 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(scala.reflect.NameTransformer.encode).mkString(".")
classname.split('.').map(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 _ => scala.tools.util.PathResolver.fromPathString(".") // include '.' in the default classpath SI-6669
case _ => PathResolver.fromPathString(".") // include '.' in the default classpath SI-6669
}
// print the classpath if output is verbose
if (verbose)
Expand Down
6 changes: 4 additions & 2 deletions src/scalap/scala/tools/scalap/MetaParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
*/


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

Expand Down
3 changes: 2 additions & 1 deletion src/scalap/scala/tools/scalap/Properties.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
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]
}
6 changes: 0 additions & 6 deletions src/scalap/scala/tools/scalap/rules/package.scala

This file was deleted.

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

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

import scala.collection.mutable

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

override def ruleWithName[In, Out, A, X](name: String, f: In => Result[Out, A, X]) = super.ruleWithName(name, (in: In) => in match {
override def ruleWithName[In, Out, A, X](name: String, f: In => rules.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 @@ -54,3 +56,6 @@ trait DefaultMemoisable extends Memoisable {
if(DefaultMemoisable.debug) println(key + " -> " + t + " (" + out + ")")
}
}



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

package scala.tools.scalap.rules;
package scala.tools.scalap
package scalax
package 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,7 +10,9 @@
//
// -----------------------------------------------------------------------------

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

/** A Rule is a function from some input to a Result. The result may be:
* <ul>
Expand Down Expand Up @@ -170,3 +172,6 @@ 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,8 +11,11 @@
// -----------------------------------------------------------------------------

package scala.tools.scalap
package scalax
package rules

import language.postfixOps

trait Name {
def name: String
override def toString = name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
//
// -----------------------------------------------------------------------------

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

import language.postfixOps

/**
* A workaround for the difficulties of dealing with
Expand Down Expand Up @@ -47,7 +51,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 @@ -96,3 +100,4 @@ class SeqRule[S, +A, +X](rule: Rule[S, S, A, X]) {
in => rep(0, in)
}
}

0 comments on commit 59bcf6b

Please sign in to comment.