summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2006-01-20 15:50:55 +0000
committerMartin Odersky <odersky@gmail.com>2006-01-20 15:50:55 +0000
commit3ba2f2b49e0635255bbb40958e05cc5dccde0424 (patch)
treebafa0a461bae7046be9285146b326a7d2685483c
parent79fab589462c093512d1c5c37adc6fdc28cd86b0 (diff)
downloadscala-3ba2f2b49e0635255bbb40958e05cc5dccde0424.tar.gz
scala-3ba2f2b49e0635255bbb40958e05cc5dccde0424.tar.bz2
scala-3ba2f2b49e0635255bbb40958e05cc5dccde0424.zip
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreePrinters.scala18
-rw-r--r--src/compiler/scala/tools/nsc/symtab/StdNames.scala2
-rw-r--r--src/compiler/scala/tools/nsc/transform/Erasure.scala43
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala3
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala31
-rw-r--r--src/library/scala/CaseClass.scala2
-rw-r--r--src/library/scala/collection/mutable/BitSet.scala7
-rw-r--r--src/library/scala/runtime/ScalaRunTime.scala11
-rw-r--r--test/files/pos/context.scala.disabled (renamed from test/files/pos/context.scala)2
9 files changed, 77 insertions, 42 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala
index 53b1f7da6e..ba3eaf6fd7 100644
--- a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala
@@ -96,6 +96,14 @@ abstract class TreePrinters {
if (s.length() != 0) print(s + " ")
}
+ def printAttributes(attrs: List[AttrInfo]): unit = {
+ def attrToString(attr: AttrInfo): String = attr match {
+ case Pair(tp, List()) => tp.toString()
+ case Pair(tp, args) => tp.toString()+args.mkString("(", ",", ")")
+ }
+ if (!attrs.isEmpty) print(attrs.map(attrToString).mkString("[", ",", "]"))
+ }
+
def print(str: String): unit = out.print(str);
def print(name: Name): unit = print(name.toString());
@@ -105,6 +113,7 @@ abstract class TreePrinters {
print("<empty>");
case ClassDef(mods, name, tparams, tp, impl) =>
+ printAttributes(tree.symbol.attributes);
printModifiers(tree, mods);
print("class " + symName(tree, name));
printTypeParams(tparams);
@@ -114,10 +123,12 @@ abstract class TreePrinters {
print("package "); print(packaged); printColumn(stats, " {", ";", "}")
case ModuleDef(mods, name, impl) =>
+ printAttributes(tree.symbol.attributes);
printModifiers(tree, mods); print("object " + symName(tree, name));
print(" extends "); print(impl);
case ValDef(mods, name, tp, rhs) =>
+ printAttributes(tree.symbol.attributes);
printModifiers(tree, mods);
print(if (mods.hasFlag(MUTABLE)) "var " else "val ");
print(symName(tree, name));
@@ -128,15 +139,18 @@ abstract class TreePrinters {
}
case DefDef(mods, name, tparams, vparamss, tp, rhs) =>
+ printAttributes(tree.symbol.attributes);
printModifiers(tree, mods);
print("def " + symName(tree, name));
printTypeParams(tparams); vparamss foreach printValueParams;
printOpt(": ", tp); printOpt(" = ", rhs);
case AbsTypeDef(mods, name, lo, hi) =>
+ printAttributes(tree.symbol.attributes);
printModifiers(tree, mods); print("type "); printParam(tree);
case AliasTypeDef(mods, name, tparams, rhs) =>
+ printAttributes(tree.symbol.attributes);
printModifiers(tree, mods); print("type " + symName(tree, name));
printTypeParams(tparams); printOpt(" = ", rhs);
@@ -151,7 +165,9 @@ abstract class TreePrinters {
print(selectors.map(selectorToString).mkString(".{", ", ", "}"))
case Attributed(attr, definition) =>
- print("["); print(attr); print("]"); println; print(definition);
+ if (tree.symbol == NoSymbol) {
+ print("["); print(attr); print("]"); println; print(definition);
+ }
case DocDef(comment, definition) =>
print(comment); println; print(definition);
diff --git a/src/compiler/scala/tools/nsc/symtab/StdNames.scala b/src/compiler/scala/tools/nsc/symtab/StdNames.scala
index 8a4cc204df..26e941cd87 100644
--- a/src/compiler/scala/tools/nsc/symtab/StdNames.scala
+++ b/src/compiler/scala/tools/nsc/symtab/StdNames.scala
@@ -215,11 +215,13 @@ mixin class StdNames requires SymbolTable {
val While = newTermName("While");
val apply = newTermName("apply");
val array = newTermName("array");
+ val arrayValue = newTermName("arrayValue");
val arraycopy = newTermName("arraycopy");
val assert_ = newTermName("assert");
val assume_ = newTermName("assume");
val asInstanceOf = newTermName("asInstanceOf");
val asInstanceOfErased = newTermName("asInstanceOf$erased");
+ val booleanValue = newTermName("booleanValue");
val box = newTermName("box");
val caseArity = newTermName("caseArity");
val caseElement = newTermName("caseElement");
diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala
index 3555bee62b..bd84f6ed6f 100644
--- a/src/compiler/scala/tools/nsc/transform/Erasure.scala
+++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala
@@ -161,12 +161,16 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer {
}
/** The method-name xxxValue, where Xxx is a numeric value class name */
- def unboxOp(tp: Type) = {
+ def unboxOp(tp: Type): Name = {
val clazzName = tp.symbol.name.toString();
- (String.valueOf((clazzName.charAt(0) + ('a' - 'A')).asInstanceOf[char]) +
- clazzName.substring(1) + "Value")
+ newTermName(
+ String.valueOf((clazzName.charAt(0) + ('a' - 'A')).asInstanceOf[char]) +
+ clazzName.substring(1) + "Value")
}
+ private def runtimeCall(meth: Name, args: List[Tree]): Tree =
+ Apply(Select(gen.mkRef(ScalaRunTimeModule), meth), args);
+
/** Unbox `tree' of boxed type to expected type `pt' */
private def unbox(tree: Tree, pt: Type): Tree =
typed {
@@ -174,23 +178,24 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer {
if (pt.symbol == UnitClass) {
if (treeInfo.isPureExpr(tree)) Literal(())
else Block(List(tree), Literal(()))
- } else if (pt.symbol == BooleanClass) {
- val tree1 = adaptToType(tree, boxedClass(BooleanClass).tpe);
- Apply(Select(tree1, "booleanValue"), List())
- } else if (pt.symbol == ArrayClass) {
- val tree1 = adaptToType(tree, BoxedArrayClass.tpe);
- val elemClass = pt.typeArgs.head.symbol;
- val elemTag =
- if (isValueClass(elemClass))
- Apply(
- Select(gen.mkRef(ScalaRunTimeModule), newTermName(elemClass.name.toString() + "Tag")),
- List())
- else Literal(signature(pt.typeArgs.head));
- Apply(Select(tree1, "unbox"), List(elemTag))
} else {
- assert(isNumericValueClass(pt.symbol));
- val tree1 = adaptToType(tree, BoxedNumberClass.tpe);
- Apply(Select(tree1, unboxOp(pt)), List())
+ if (pt.symbol == BooleanClass) {
+ val tree1 = adaptToType(tree, boxedClass(BooleanClass).tpe);
+ runtimeCall(nme.booleanValue, List(tree1))
+ } else if (pt.symbol == ArrayClass) {
+ val tree1 = adaptToType(tree, BoxedArrayClass.tpe);
+ val elemClass = pt.typeArgs.head.symbol;
+ val elemTag =
+ if (isValueClass(elemClass))
+ runtimeCall(newTermName(elemClass.name.toString() + "Tag"), List())
+ else
+ Literal(signature(pt.typeArgs.head));
+ runtimeCall(nme.arrayValue, List(tree1, elemTag))
+ } else {
+ assert(isNumericValueClass(pt.symbol));
+ val tree1 = adaptToType(tree, BoxedNumberClass.tpe);
+ runtimeCall(unboxOp(pt), List(tree1))
+ }
}
}
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala
index 71b21084a0..28d36b2494 100644
--- a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala
@@ -88,12 +88,11 @@ mixin class SyntheticMethods requires Analyzer {
val SerializableAttr = definitions.SerializableAttr;
- def isSerializable(clazz: Symbol): Boolean = {
+ def isSerializable(clazz: Symbol): Boolean =
clazz.attributes.exists(p => p match {
case Pair(SerializableAttr, _) => true;
case _ => false
})
- }
def readResolveMethod: Tree = {
// !!! the synthetic method "readResolve" should be private,
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 7aa79333d9..cb83e6abbe 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -240,17 +240,6 @@ mixin class Typers requires Analyzer {
tparam.symbol.deSkolemize
}
- def attrInfo(attr: Tree): AttrInfo = attr match {
- case Apply(Select(New(tpt), nme.CONSTRUCTOR), args) =>
- Pair(tpt.tpe, args map {
- case Literal(value) =>
- value
- case arg =>
- error(arg.pos, "attribute argument needs to be a constant; found: "+arg)
- null
- })
- }
-
/** The qualifying class of a this or super with prefix `qual' */
def qualifyingClassContext(tree: Tree, qual: Name): Context = {
if (qual.isEmpty) {
@@ -1164,10 +1153,22 @@ mixin class Typers requires Analyzer {
case Attributed(attr, defn) =>
val attr1 = typed(attr, AttributeClass.tpe)
- val defn1 = typed(defn, mode, pt)
- val ai = attrInfo(attr1)
- if (ai != null) defn1.symbol.attributes = defn1.symbol.attributes ::: List(ai)
- defn1
+ val attrInfo = attr1 match {
+ case Apply(Select(New(tpt), nme.CONSTRUCTOR), args) =>
+ Pair(tpt.tpe, args map {
+ case Literal(value) =>
+ value
+ case arg =>
+ error(arg.pos, "attribute argument needs to be a constant; found: "+arg)
+ null
+ })
+ }
+ if (attrInfo != null) {
+ val attributed =
+ if (defn.symbol.isModule) defn.symbol.moduleClass else defn.symbol;
+ attributed.attributes = attributed.attributes ::: List(attrInfo)
+ }
+ typed(defn, mode, pt)
case DocDef(comment, defn) =>
typed(defn, mode, pt)
diff --git a/src/library/scala/CaseClass.scala b/src/library/scala/CaseClass.scala
index 07b766ede9..c899d7cff6 100644
--- a/src/library/scala/CaseClass.scala
+++ b/src/library/scala/CaseClass.scala
@@ -28,6 +28,6 @@ trait CaseClass extends AnyRef {
*/
def caseArity: Int ;
- def caseName: String = ""; // for now
+ def caseName: String ;
}
diff --git a/src/library/scala/collection/mutable/BitSet.scala b/src/library/scala/collection/mutable/BitSet.scala
index 40d0bf0529..fe4b5b5059 100644
--- a/src/library/scala/collection/mutable/BitSet.scala
+++ b/src/library/scala/collection/mutable/BitSet.scala
@@ -25,14 +25,15 @@ class BitSet(initSize: Int) extends scala.collection.BitSet {
class ByteArray extends AnyRef with ResizableArray[Int] {
final def ensureBits(nbits: Int): Unit = {
+ val l = array.length;
super[ResizableArray].ensureSize(memsize( nbits ));
}
- final def and(j: Int, mask:Int): Unit = {
- array.update( j, array(j) & mask );
- }
final def or(j: Int, mask:Int): Unit = {
array.update( j, array(j) | mask );
}
+ final def and(j: Int, mask:Int): Unit = {
+ array.update( j, array(j) & mask );
+ }
def get(j:Int, mask:Int):Boolean = {
(array(j) & mask) != 0;
}
diff --git a/src/library/scala/runtime/ScalaRunTime.scala b/src/library/scala/runtime/ScalaRunTime.scala
index 64bcbda839..827e4cc223 100644
--- a/src/library/scala/runtime/ScalaRunTime.scala
+++ b/src/library/scala/runtime/ScalaRunTime.scala
@@ -89,4 +89,15 @@ object ScalaRunTime {
}
def Seq[a](xs: a*): Seq[a] = null; // interpreted specially by new backend.
+
+ def booleanValue(x: BoxedBoolean): Boolean = if (x eq null) false else x.booleanValue();
+ def byteValue (x: BoxedNumber ): Byte = if (x eq null) 0 else x.byteValue();
+ def shortValue (x: BoxedNumber ): Short = if (x eq null) 0 else x.shortValue();
+ def charValue (x: BoxedNumber ): Char = if (x eq null) 0 else x.charValue();
+ def intValue (x: BoxedNumber ): Int = if (x eq null) 0 else x.intValue();
+ def longValue (x: BoxedNumber ): Long = if (x eq null) 0L else x.longValue();
+ def floatValue (x: BoxedNumber ): Float = if (x eq null) 0.0F else x.floatValue();
+ def doubleValue (x: BoxedNumber ): Double = if (x eq null) 0.0D else x.doubleValue();
+ def arrayValue (x: BoxedArray, elemTag: String): Object =
+ if (x eq null) null else x.unbox(elemTag);
}
diff --git a/test/files/pos/context.scala b/test/files/pos/context.scala.disabled
index 327f3261be..575df9a708 100644
--- a/test/files/pos/context.scala
+++ b/test/files/pos/context.scala.disabled
@@ -12,7 +12,7 @@ class Context {
abstract class SymbolWrapper {
val context: Context;
import context._;
-
+
class Symbols requires context.symbols.type {
abstract class Symbol {
def typ: types.Type;