summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@epfl.ch>2008-06-09 13:17:59 +0000
committerLukas Rytz <lukas.rytz@epfl.ch>2008-06-09 13:17:59 +0000
commitabe9ec9859709f93a3258d0769a4b3e3c52d0cb5 (patch)
tree8527fc608f58eec5626f135d9ae867fa66586b0b /src/compiler
parentd6b6402e4cfc42757df3113beb1302e400c6cb26 (diff)
downloadscala-abe9ec9859709f93a3258d0769a4b3e3c52d0cb5.tar.gz
scala-abe9ec9859709f93a3258d0769a4b3e3c52d0cb5.tar.bz2
scala-abe9ec9859709f93a3258d0769a4b3e3c52d0cb5.zip
now actually removing plugin.quick
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/ant/Scalac.scala8
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala7
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala3
-rw-r--r--src/compiler/scala/tools/nsc/symtab/AnnotationInfos.scala26
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Constants.scala16
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Symbols.scala1
-rw-r--r--src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala31
-rw-r--r--src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala15
-rw-r--r--src/compiler/scala/tools/nsc/transform/InfoTransform.scala1
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala2
10 files changed, 85 insertions, 25 deletions
diff --git a/src/compiler/scala/tools/ant/Scalac.scala b/src/compiler/scala/tools/ant/Scalac.scala
index 4965071581..267ddaed74 100644
--- a/src/compiler/scala/tools/ant/Scalac.scala
+++ b/src/compiler/scala/tools/ant/Scalac.scala
@@ -451,6 +451,10 @@ class Scalac extends MatchingTask {
\*============================================================================*/
protected val sourceEnding = ".scala"
+ protected def binaryEnding = backend match {
+ case Some("msil") => ".msil"
+ case _ => ".class"
+ }
protected def newSettings(error: String=>Unit): Settings =
new Settings(error)
protected def newGlobal(settings: Settings, reporter: Reporter) =
@@ -470,8 +474,10 @@ class Scalac extends MatchingTask {
error("Attribute 'destdir' does not refer to an existing directory.")
if (destination.isEmpty) destination = Some(getOrigin.head)
+ // TODO msil: map packages (will be in filename for .msil files). Use
+ // RegexppatternMapper (?)
val mapper = new GlobPatternMapper()
- mapper.setTo("*.class")
+ mapper.setTo("*" + binaryEnding)
mapper.setFrom("*" + sourceEnding)
// Scans source directories to build up a compile lists.
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index c2e1bd1e7e..6c67ec2973 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -1595,7 +1595,12 @@ trait Parsers extends NewScanners with MarkupParsers {
accept(VAL)
val aname = ident()
accept(EQUALS)
- val rhs = stripParens(prefixExpr())
+ val rhs =
+ if (inToken == AT) {
+ inNextToken
+ annotationExpr()
+ } else
+ stripParens(prefixExpr())
atPos(pos) { ValDef(NoMods, aname, TypeTree(), rhs) }
}
val pos = inCurrentPos
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
index 06106c6d03..0d56743603 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
@@ -362,6 +362,9 @@ abstract class GenJVM extends SubComponent {
val arr = const.arrayValue
buf.putShort(arr.length.toShort)
for (val elem <- arr) emitElement(elem)
+ case AnnotationTag =>
+ // TODO: implement
+ ()
}
var nattr = 0
diff --git a/src/compiler/scala/tools/nsc/symtab/AnnotationInfos.scala b/src/compiler/scala/tools/nsc/symtab/AnnotationInfos.scala
index 5f9d67dfae..a0c8ec73c7 100644
--- a/src/compiler/scala/tools/nsc/symtab/AnnotationInfos.scala
+++ b/src/compiler/scala/tools/nsc/symtab/AnnotationInfos.scala
@@ -33,6 +33,14 @@ trait AnnotationInfos {
case Typed(t, _) => tree2cons(t)
+ case Annotation(constr, elements) =>
+/* val annotInfo = typer.tpyedAnnotation(tree)
+ if (annotInfo isConstant)
+ Some(new AnnotationConstant(annotInfo))
+ else */
+ println("getting annotation: "+ tree)
+ None
+
case tree =>
//println("could not convert: " + tree);
None
@@ -56,9 +64,25 @@ trait AnnotationInfos {
* and it includes a compile-time constant for the tree if possible.
*/
class AnnotationArgument(val intTree: Tree) {
- def this(cons: Constant) = this(
+
+ /** This constructor is also used to create an AnnotationArgument
+ * containing a ArrayConstant, when an array of constants is seen
+ * in a parsed classfile (ClassfileParser.parseTaggedConstant).
+ * I.E. for Arrays of constants, intTree looks like:
+ * <ul>
+ * <li> Apply(ArrayModule_apply, members) if the AnnotationArgument
+ * is part of an Annotation in Scala source </li>
+ * <li> Literal(ArrayConstant(constants, tpe)) if the the argument
+ * was created when parsing a java annotation in a classfile</li>
+ * </ul>
+ */
+ def this(cons: Constant) {
+ this(
Literal(cons).setType(cons.tpe))
+ println("AnnotationArgument constructor with constant: "+ cons)
+ }
+ //def this(annTree: Annotation, annConst: AnnotationConstant)
@deprecated
lazy val tree = {
diff --git a/src/compiler/scala/tools/nsc/symtab/Constants.scala b/src/compiler/scala/tools/nsc/symtab/Constants.scala
index ec6f5dbc8c..3fea633b38 100644
--- a/src/compiler/scala/tools/nsc/symtab/Constants.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Constants.scala
@@ -51,6 +51,7 @@ trait Constants {
else if (value.isInstanceOf[Type]) ClassTag
else if (value.isInstanceOf[Symbol]) EnumTag
else if (value.isInstanceOf[Array[Constant]]) ArrayTag
+ else if (value.isInstanceOf[AnnotationInfo]) AnnotationTag
else if (value == null) NullTag
else throw new Error("bad constant value: " + value)
@@ -68,7 +69,9 @@ trait Constants {
case NullTag => AllRefClass.tpe
case ClassTag => Predef_classOfType(value.asInstanceOf[Type])
case EnumTag => symbolValue.owner.linkedClassOfClass.tpe
- case AnnotationTag => AnnotationClass.tpe // what should it be?
+ // ArrayTag not required; method tpe is overwritten in ArrayConstant
+ case AnnotationTag => annotationInfoValue.atp
+ //AnnotationClass.tpe // what should it be?
}
/** We need the equals method to take account of tags as well as values.
@@ -222,6 +225,9 @@ trait Constants {
def symbolValue: Symbol = value.asInstanceOf[Symbol]
+ def annotationInfoValue: AnnotationInfo =
+ throw new Error("value " + value + " is not an array")
+
def arrayValue: Array[Constant] =
throw new Error("value " + value + " is not an array")
@@ -235,10 +241,8 @@ trait Constants {
override def toString() = arrayValue.mkString("Constant(", "," , ")")
}
- /** A place-holder for annotation constants. The contents of
- * the constant are not read. */
- class AnnotationConstant()
- extends Constant(null) {
- override val tag = AnnotationTag
+ class AnnotationConstant(override val annotationInfoValue: AnnotationInfo)
+ extends Constant(annotationInfoValue) {
+ assert(annotationInfoValue.isConstant, annotationInfoValue)
}
}
diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
index d72a484a35..4775554ea5 100644
--- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
@@ -573,6 +573,7 @@ trait Symbols {
if (validTo < curPeriod) {
var itr = infoTransformers.nextFrom(phaseId(validTo))
infoTransformers = itr; // caching optimization
+ //println("running info transformer: "+ itr)
while (itr.pid != NoPhase.id && itr.pid < current.id) {
phase = phaseWithId(itr.pid)
val info1 = itr.transform(this, infos.info)
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
index 3cf8b8f25a..33f6f0d974 100644
--- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
+++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
@@ -663,10 +663,16 @@ abstract class ClassfileParser {
staticModule.moduleClass.sourceFile = clazz.sourceFile
}
}
+ // Methods of a java annotation class wear this annotation when they
+ // provide a default value. The actual value does not need to be known
+ // in order to compile other classes
case nme.AnnotationDefaultATTR =>
sym.attributes =
AnnotationInfo(definitions.AnnotationDefaultAttr.tpe, List(), List()) :: sym.attributes
in.skip(attrLen)
+ // Java annotatinos present in classfiles (when the java annotation class is
+ // itself annotated with @Renention(RetentionPolicy.RUNTIME) or .CLASS) are
+ // stored in a "RuntimeVisibleAnnotation" (i.e. nme.RuntimeAnnotationATTR)
case nme.RuntimeAnnotationATTR =>
parseAnnotations(attrLen)
if (settings.debug.value)
@@ -704,8 +710,8 @@ abstract class ClassfileParser {
new ArrayConstant(arr.toArray,
appliedType(definitions.ArrayClass.typeConstructor, List(arr(0).tpe)))
case ANNOTATION_TAG =>
- parseAnnotation(index) // skip it
- new AnnotationConstant()
+ val info = parseAnnotation(index)
+ new AnnotationConstant(info)
}
}
@@ -713,7 +719,7 @@ abstract class ClassfileParser {
* throw an exception. If it contains a nested annotation,
* return None.
*/
- def parseAnnotation(attrNameIndex: Char): Option[AnnotationInfo] = {
+ def parseAnnotation(attrNameIndex: Char): /* Option[ */ AnnotationInfo /*]*/ = {
val attrType = pool.getType(attrNameIndex)
val nargs = in.nextChar
val nvpairs = new ListBuffer[(Name,AnnotationArgument)]
@@ -722,16 +728,16 @@ abstract class ClassfileParser {
for (i <- 0 until nargs) {
val name = pool.getName(in.nextChar)
val argConst = parseTaggedConstant
- if (argConst.tag == AnnotationTag)
- nestedAnnot = true
- else
+ //if (argConst.tag == AnnotationTag)
+ //nestedAnnot = true
+ //else
nvpairs += ((name, new AnnotationArgument(argConst)))
}
- if (nestedAnnot)
- None
- else
- Some(AnnotationInfo(attrType, List(), nvpairs.toList))
+ //if (nestedAnnot)
+ //None
+ //else
+ AnnotationInfo(attrType, List(), nvpairs.toList)
}
/** Parse a sequence of annotations and attach them to the
@@ -740,7 +746,7 @@ abstract class ClassfileParser {
def parseAnnotations(len: Int) {
val nAttr = in.nextChar
for (n <- 0 until nAttr)
- parseAnnotation(in.nextChar) match {
+/* parseAnnotation(in.nextChar) match {
case None =>
if (settings.debug.value)
global.inform("dropping annotation on " +
@@ -748,7 +754,8 @@ abstract class ClassfileParser {
" that has a nested annotation")
case Some(annot) =>
sym.attributes = annot :: sym.attributes
- }
+ }*/
+ sym.attributes = parseAnnotation(in.nextChar) :: sym.attributes
}
def makeInnerAlias(outer: Symbol, name: Name, iclazz: Symbol, scope: Scope): Symbol = {
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala b/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala
index 09799d4412..8a319228bb 100644
--- a/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala
+++ b/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala
@@ -138,6 +138,7 @@ abstract class Pickler extends SubComponent {
putChildren(sym, children.sort((x, y) => x isLess y))
}
for (attr <- sym.attributes.reverse) {
+ println("put annot? "+ attr +", "+ (attr.atp.typeSymbol isNonBottomSubClass definitions.StaticAnnotationClass))
if (attr.atp.typeSymbol isNonBottomSubClass definitions.StaticAnnotationClass)
putAnnotation(sym, attr)
}
@@ -290,6 +291,7 @@ abstract class Pickler extends SubComponent {
putTrees(args)
case ArrayValue(elemtpt, trees) =>
+ println("putting array value: "+ trees)
putTree(elemtpt)
putTrees(trees)
@@ -397,17 +399,19 @@ abstract class Pickler extends SubComponent {
private def putMods(mods: Modifiers) = if (putEntry(mods)) {
val Modifiers(flags, privateWithin, annotations) = mods
putEntry(privateWithin)
+ println("putting annotation trees: "+ annotations)
putTrees(annotations)
}
/** Store a constant in map <code>index</code> along with
* anything it references.
*/
- private def putConstant(c: Constant) =
+ private def putConstant(c: Constant) = {
if (putEntry(c)) {
if (c.tag == StringTag) putEntry(newTermName(c.stringValue))
else if (c.tag == ClassTag) putEntry(c.typeValue)
}
+ }
private def putChildren(sym: Symbol, children: List[Symbol]) {
assert(putEntry((sym, children)))
@@ -415,6 +419,7 @@ abstract class Pickler extends SubComponent {
}
private def putAnnotation(sym: Symbol, annot: AnnotationInfo) {
+ println("putting annotation: "+ annot)
assert(putEntry((sym, annot)))
val AnnotationInfo(atp, args, assocs) = annot
putType(atp)
@@ -432,10 +437,11 @@ abstract class Pickler extends SubComponent {
}
private def putAnnotationArg(arg: AnnotationArgument) {
+ println("putting annotation arg: "+ arg)
if (putEntry(arg)) {
arg.constant match {
- case Some(c) => putConstant(c)
- case _ => putTree(arg.intTree)
+ case Some(c) => println(" const: "+ c); putConstant(c)
+ case _ => println(" tree: "+ arg.intTree); putTree(arg.intTree)
}
}
}
@@ -534,6 +540,7 @@ abstract class Pickler extends SubComponent {
case DeBruijnIndex(l, i) =>
writeNat(l); writeNat(i); DEBRUIJNINDEXtpe
case c @ Constant(_) =>
+ println("putting constant with tag: "+ c.tag)
if (c.tag == BooleanTag) writeLong(if (c.booleanValue) 1 else 0)
else if (ByteTag <= c.tag && c.tag <= LongTag) writeLong(c.longValue)
else if (c.tag == FloatTag) writeLong(Float.floatToIntBits(c.floatValue))
@@ -729,6 +736,7 @@ abstract class Pickler extends SubComponent {
TREE
case tree@ArrayValue(elemtpt, trees) =>
+ println("arrayValue tree: "+ trees)
writeNat(ARRAYVALUEtree)
writeRef(tree.tpe)
writeRef(elemtpt)
@@ -929,6 +937,7 @@ abstract class Pickler extends SubComponent {
ANNOTINFO
case arg:AnnotationArgument =>
+ println("writing AnnotationArgument: "+ arg)
arg.constant match {
case Some(c) => writeBody(c)
case None => writeBody(arg.intTree)
diff --git a/src/compiler/scala/tools/nsc/transform/InfoTransform.scala b/src/compiler/scala/tools/nsc/transform/InfoTransform.scala
index d130abb336..e5b3e87458 100644
--- a/src/compiler/scala/tools/nsc/transform/InfoTransform.scala
+++ b/src/compiler/scala/tools/nsc/transform/InfoTransform.scala
@@ -30,6 +30,7 @@ trait InfoTransform extends Transform {
val pid = id
val changesBaseClasses = InfoTransform.this.changesBaseClasses
def transform(sym: Symbol, tpe: Type): Type = transformInfo(sym, tpe)
+ override def toString() = InfoTransform.this.toString()
}
infoTransformers.insert(infoTransformer)
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index dbcc130e03..5d9c131571 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -1987,7 +1987,7 @@ trait Typers { self: Analyzer =>
} else {
names -= sym
val annArg =
- annotArg(
+ annotArg( // also checks that rhs is constant
typed(rhs, EXPRmode, sym.tpe.resultType))
(sym.name, annArg)
}