diff options
author | Martin Odersky <odersky@gmail.com> | 2008-03-10 12:00:03 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2008-03-10 12:00:03 +0000 |
commit | 83d3f475da9ab4db3bb35613639e55008b39b495 (patch) | |
tree | 9af5d7b4b8d8ffc79344599026a988caf7becaef /src/compiler/scala | |
parent | 82953600481e3fa2238b897adb20d3fa7503c108 (diff) | |
download | scala-83d3f475da9ab4db3bb35613639e55008b39b495.tar.gz scala-83d3f475da9ab4db3bb35613639e55008b39b495.tar.bz2 scala-83d3f475da9ab4db3bb35613639e55008b39b495.zip |
1.
2. Added * operator to RichString
3. changed zip in Array to accept arrays of different length
4. changed takeWhile/dropWhile in Array to yield Projections
5. Added Manifest types
Diffstat (limited to 'src/compiler/scala')
6 files changed, 146 insertions, 96 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreeGen.scala b/src/compiler/scala/tools/nsc/ast/TreeGen.scala index f37a34ae74..772fdd59b4 100644 --- a/src/compiler/scala/tools/nsc/ast/TreeGen.scala +++ b/src/compiler/scala/tools/nsc/ast/TreeGen.scala @@ -199,6 +199,9 @@ abstract class TreeGen { def mkAsInstanceOf(value: Tree, tpe: Type): Tree = mkAsInstanceOf(value, tpe, global.phase.erasedTypes) + def mkClassOf(tp: Type): Tree = + Literal(Constant(tp)) setType Predef_classOfType(tp) + def mkCheckInit(tree: Tree): Tree = { var tpe = tree.tpe if (tpe == null && tree.hasSymbol) tpe = tree.symbol.tpe diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala index 2528181e0e..153f81d1c5 100644 --- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala +++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala @@ -94,6 +94,8 @@ trait Definitions { lazy val ClassfileAnnotationClass: Symbol = getClass("scala.ClassfileAnnotation") lazy val StaticAnnotationClass: Symbol = getClass("scala.StaticAnnotation") lazy val TypeConstraintClass: Symbol = getClass("scala.TypeConstraint") + lazy val ManifestClass: Symbol = getClass("scala.reflect.Manifest") + lazy val ManifestModule: Symbol = getModule("scala.reflect.Manifest") var CodeClass: Symbol = _ var CodeModule: Symbol = _ @@ -110,7 +112,6 @@ trait Definitions { lazy val RandomAccessSeqMutableClass: Symbol = getMember(getModule("scala.RandomAccessSeq"), nme.Mutable) def Seq_length = getMember(SeqClass, nme.length) - lazy val ListClass: Symbol = getClass("scala.List") def List_isEmpty = getMember(ListClass, nme.isEmpty) def List_head = getMember(ListClass, nme.head) diff --git a/src/compiler/scala/tools/nsc/symtab/StdNames.scala b/src/compiler/scala/tools/nsc/symtab/StdNames.scala index 69b7448bf1..9caa664097 100644 --- a/src/compiler/scala/tools/nsc/symtab/StdNames.scala +++ b/src/compiler/scala/tools/nsc/symtab/StdNames.scala @@ -403,4 +403,94 @@ trait StdNames { } def encode(str: String): Name = newTermName(NameTransformer.encode(str)) + + abstract class SymbolNames { + val JavaLang : Name + val Object : Name + val Class : Name + val String : Name + val Throwable : Name + val NPException : Name // NullPointerException + val NLRException : Name = newTermName("scala.runtime.NonLocalReturnException") + val ValueType : Name + val Serializable : Name + val BeanProperty : Name + val Delegate : Name + val IOOBException: Name // IndexOutOfBoundsException + val Code : Name + val BoxedNumber : Name + val BoxedCharacter : Name + val BoxedBoolean : Name + + import scala.collection.mutable.HashMap + val Boxed = new HashMap[Name, Name] + } + + private abstract class JavaNames extends SymbolNames { + final val JavaLang = newTermName("java.lang") + final val Object = newTermName("java.lang.Object") + final val Class = newTermName("java.lang.Class") + final val String = newTermName("java.lang.String") + final val Throwable = newTermName("java.lang.Throwable") + final val NPException = newTermName("java.lang.NullPointerException") + final val ValueType = nme.NOSYMBOL + final val Delegate = nme.NOSYMBOL + final val IOOBException = newTermName("java.lang.IndexOutOfBoundsException") + final val BoxedNumber = newTermName("java.lang.Number") + final val BoxedCharacter = newTermName("java.lang.Character") + final val BoxedBoolean = newTermName("java.lang.Boolean") + + Boxed += (nme.Boolean -> newTermName("java.lang.Boolean")) + Boxed += (nme.Byte -> newTermName("java.lang.Byte")) + Boxed += (nme.Char -> newTermName("java.lang.Character")) + Boxed += (nme.Short -> newTermName("java.lang.Short")) + Boxed += (nme.Int -> newTermName("java.lang.Integer")) + Boxed += (nme.Long -> newTermName("java.lang.Long")) + Boxed += (nme.Float -> newTermName("java.lang.Float")) + Boxed += (nme.Double -> newTermName("java.lang.Double")) + } + + private class MSILNames extends SymbolNames { + final val JavaLang = newTermName("System") + final val Object = newTermName("System.Object") + final val Class = newTermName("System.Type") + final val String = newTermName("System.String") + final val Throwable = newTermName("System.Exception") + final val NPException = newTermName("System.NullReferenceException") + final val ValueType = newTermName("System.ValueType") + final val Serializable = nme.NOSYMBOL + final val BeanProperty = nme.NOSYMBOL + final val Delegate = newTermName("System.MulticastDelegate") + final val IOOBException = newTermName("System.IndexOutOfRangeException") + final val Code = nme.NOSYMBOL + final val BoxedNumber = newTermName("System.IConvertible") + final val BoxedCharacter = newTermName("System.IConvertible") + final val BoxedBoolean = newTermName("System.IConvertible") + + Boxed += (nme.Boolean -> newTermName("System.Boolean")) + Boxed += (nme.Byte -> newTermName("System.Byte")) + Boxed += (nme.Char -> newTermName("System.Char")) + Boxed += (nme.Short -> newTermName("System.Int16")) + Boxed += (nme.Int -> newTermName("System.Int32")) + Boxed += (nme.Long -> newTermName("System.Int64")) + Boxed += (nme.Float -> newTermName("System.Single")) + Boxed += (nme.Double -> newTermName("System.Double")) + } + + private class J2SENames extends JavaNames { + final val Serializable = newTermName("java.io.Serializable") + final val BeanProperty = newTermName("scala.reflect.BeanProperty") + final val Code = newTermName("scala.reflect.Code") + } + + private class CLDCNames extends JavaNames { + final val Serializable = nme.NOSYMBOL + final val BeanProperty = nme.NOSYMBOL + final val Code = nme.NOSYMBOL + } + + val sn: SymbolNames = + if (forMSIL) new MSILNames + else if (forCLDC) new CLDCNames + else new J2SENames } diff --git a/src/compiler/scala/tools/nsc/symtab/SymbolTable.scala b/src/compiler/scala/tools/nsc/symtab/SymbolTable.scala index 1e3dd8aaa9..efc270db6f 100644 --- a/src/compiler/scala/tools/nsc/symtab/SymbolTable.scala +++ b/src/compiler/scala/tools/nsc/symtab/SymbolTable.scala @@ -116,95 +116,4 @@ abstract class SymbolTable extends Names /** The phase which has given index as identifier */ val phaseWithId: Array[Phase] - - abstract class SymbolNames { - val JavaLang : Name - val Object : Name - val Class : Name - val String : Name - val Throwable : Name - val NPException : Name // NullPointerException - val NLRException : Name = newTermName("scala.runtime.NonLocalReturnException") - val ValueType : Name - val Serializable : Name - val BeanProperty : Name - val Delegate : Name - val IOOBException: Name // IndexOutOfBoundsException - val Code : Name - val BoxedNumber : Name - val BoxedCharacter : Name - val BoxedBoolean : Name - - import scala.collection.mutable.HashMap - val Boxed = new HashMap[Name, Name] - } - - private abstract class JavaNames extends SymbolNames { - final val JavaLang = newTermName("java.lang") - final val Object = newTermName("java.lang.Object") - final val Class = newTermName("java.lang.Class") - final val String = newTermName("java.lang.String") - final val Throwable = newTermName("java.lang.Throwable") - final val NPException = newTermName("java.lang.NullPointerException") - final val ValueType = nme.NOSYMBOL - final val Delegate = nme.NOSYMBOL - final val IOOBException = newTermName("java.lang.IndexOutOfBoundsException") - final val BoxedNumber = newTermName("java.lang.Number") - final val BoxedCharacter = newTermName("java.lang.Character") - final val BoxedBoolean = newTermName("java.lang.Boolean") - - Boxed += (nme.Boolean -> newTermName("java.lang.Boolean")) - Boxed += (nme.Byte -> newTermName("java.lang.Byte")) - Boxed += (nme.Char -> newTermName("java.lang.Character")) - Boxed += (nme.Short -> newTermName("java.lang.Short")) - Boxed += (nme.Int -> newTermName("java.lang.Integer")) - Boxed += (nme.Long -> newTermName("java.lang.Long")) - Boxed += (nme.Float -> newTermName("java.lang.Float")) - Boxed += (nme.Double -> newTermName("java.lang.Double")) - } - - private class MSILNames extends SymbolNames { - final val JavaLang = newTermName("System") - final val Object = newTermName("System.Object") - final val Class = newTermName("System.Type") - final val String = newTermName("System.String") - final val Throwable = newTermName("System.Exception") - final val NPException = newTermName("System.NullReferenceException") - final val ValueType = newTermName("System.ValueType") - final val Serializable = nme.NOSYMBOL - final val BeanProperty = nme.NOSYMBOL - final val Delegate = newTermName("System.MulticastDelegate") - final val IOOBException = newTermName("System.IndexOutOfRangeException") - final val Code = nme.NOSYMBOL - final val BoxedNumber = newTermName("System.IConvertible") - final val BoxedCharacter = newTermName("System.IConvertible") - final val BoxedBoolean = newTermName("System.IConvertible") - - Boxed += (nme.Boolean -> newTermName("System.Boolean")) - Boxed += (nme.Byte -> newTermName("System.Byte")) - Boxed += (nme.Char -> newTermName("System.Char")) - Boxed += (nme.Short -> newTermName("System.Int16")) - Boxed += (nme.Int -> newTermName("System.Int32")) - Boxed += (nme.Long -> newTermName("System.Int64")) - Boxed += (nme.Float -> newTermName("System.Single")) - Boxed += (nme.Double -> newTermName("System.Double")) - } - - private class J2SENames extends JavaNames { - final val Serializable = newTermName("java.io.Serializable") - final val BeanProperty = newTermName("scala.reflect.BeanProperty") - final val Code = newTermName("scala.reflect.Code") - } - - private class CLDCNames extends JavaNames { - final val Serializable = nme.NOSYMBOL - final val BeanProperty = nme.NOSYMBOL - final val Code = nme.NOSYMBOL - } - - val sn: SymbolNames = - if (forMSIL) new MSILNames - else if (forCLDC) new CLDCNames - else new J2SENames - } diff --git a/src/compiler/scala/tools/nsc/typechecker/Analyzer.scala b/src/compiler/scala/tools/nsc/typechecker/Analyzer.scala index 4ede3dec3b..50fbc23c3d 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Analyzer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Analyzer.scala @@ -16,8 +16,8 @@ trait Analyzer extends AnyRef with Variances with EtaExpansion with SyntheticMethods - with Unapplies { - + with Unapplies +{ val global : Global import global._ diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index e7d18f5c6e..b5a39f3c8d 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -2385,8 +2385,7 @@ trait Typers { self: Analyzer => checkBounds(tree.pos, NoPrefix, NoSymbol, tparams, targs, "") if (fun.symbol == Predef_classOf) { checkClassType(args.head, true) - Literal(Constant(targs.head)) setPos tree.pos setType Predef_classOfType(targs.head) - // @M: targs.head.normalize is not necessary --> toTypeKind eventually normalizes the type + atPos(tree.pos) { gen.mkClassOf(targs.head) } } else { if (phase.id <= currentRun.typerPhase.id && fun.symbol == Any_isInstanceOf && !targs.isEmpty) @@ -3475,13 +3474,61 @@ trait Typers { self: Analyzer => List() } + def implicitManifest(pt: Type): Tree = pt match { + case TypeRef(_, ManifestClass, List(arg)) => manifestOfType(pos, arg) + case _ => EmptyTree + } + var tree = searchImplicit(context.implicitss, true) if (tree == EmptyTree) tree = searchImplicit(implicitsOfType(pt), false) + if (tree == EmptyTree) tree = implicitManifest(pt) if (util.Statistics.enabled) impltime = impltime + currentTime - startTime tree } + def manifestOfType(pos: Position, tp: Type): Tree = { + def mkManifest(name: String, args: Tree*): Tree = + if (args contains EmptyTree) EmptyTree + else + typed { + atPos(pos) { + val fn = TypeApply( + Select(gen.mkAttributedRef(ManifestModule), name), + List(TypeTree(tp))) + if (args.isEmpty) fn else Apply(fn, args.toList) + } + } + def findManifest(tp: Type): Tree = + inferImplicit(pos, appliedType(ManifestClass.typeConstructor, List(tp)), true) + tp.normalize match { + case ThisType(_) | SingleType(_, _) => + mkManifest("singleType", gen.mkAttributedQualifier(tp)) + case ConstantType(value) => + findManifest(tp.deconst) + case TypeRef(pre, sym, args) => + if (sym.isClass) { + val suffix = gen.mkClassOf(tp) :: (args map findManifest) + mkManifest( + "classType", + (if ((pre eq NoPrefix) || pre.typeSymbol.isStaticOwner) suffix + else findManifest(pre) :: suffix): _*) + } else if (sym.isTypeParameterOrSkolem) { + EmptyTree // a manifest should have been found by normal searchImplicit + } else { + mkManifest( + "abstractType", + findManifest(pre) :: Literal(sym.name.toString) :: (args map findManifest): _*) + } + case RefinedType(parents, decls) => + // refinement is not generated yet + if (parents.length == 1) findManifest(parents.head) + else mkManifest("intersectionType", parents map findManifest: _*) + case _ => + EmptyTree + } + } + def applyImplicitArgs(tree: Tree): Tree = tree.tpe match { case MethodType(formals, _) => def implicitArg(pt: Type) = { |