diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/TreeInfo.scala | 44 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Definitions.scala | 104 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/SymbolTable.scala | 84 |
3 files changed, 148 insertions, 84 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreeInfo.scala b/src/compiler/scala/tools/nsc/ast/TreeInfo.scala index 50911a5923..77247576ad 100644 --- a/src/compiler/scala/tools/nsc/ast/TreeInfo.scala +++ b/src/compiler/scala/tools/nsc/ast/TreeInfo.scala @@ -19,10 +19,10 @@ abstract class TreeInfo { val global: Global import global._ - def isTerm(tree: Tree): boolean = tree.isTerm - def isType(tree: Tree): boolean = tree.isType + def isTerm(tree: Tree): Boolean = tree.isTerm + def isType(tree: Tree): Boolean = tree.isType - def isOwnerDefinition(tree: Tree): boolean = tree match { + def isOwnerDefinition(tree: Tree): Boolean = tree match { case PackageDef(_, _) | ClassDef(_, _, _, _) | ModuleDef(_, _, _) @@ -31,9 +31,9 @@ abstract class TreeInfo { case _ => false } - def isDefinition(tree: Tree): boolean = tree.isDef + def isDefinition(tree: Tree): Boolean = tree.isDef - def isDeclaration(tree: Tree): boolean = tree match { + def isDeclaration(tree: Tree): Boolean = tree match { case DefDef(_, _, _, _, _, EmptyTree) | ValDef(_, _, _, EmptyTree) | TypeDef(_, _, _, _) => true @@ -42,7 +42,7 @@ abstract class TreeInfo { /** Is tree legal as a member definition of an interface? */ - def isInterfaceMember(tree: Tree): boolean = tree match { + def isInterfaceMember(tree: Tree): Boolean = tree match { case EmptyTree => true case Import(_, _) => true case TypeDef(_, _, _, _) => true @@ -54,7 +54,7 @@ abstract class TreeInfo { /** Is tree a pure (i.e. non-side-effecting) definition? */ - def isPureDef(tree: Tree): boolean = tree match { + def isPureDef(tree: Tree): Boolean = tree match { case EmptyTree | ClassDef(_, _, _, _) | TypeDef(_, _, _, _) @@ -71,7 +71,7 @@ abstract class TreeInfo { /** Is tree a stable and pure expression? */ - def isPureExpr(tree: Tree): boolean = tree match { + def isPureExpr(tree: Tree): Boolean = tree match { case EmptyTree | This(_) | Super(_, _) @@ -114,18 +114,18 @@ abstract class TreeInfo { /** Is tree a self constructor call? */ - def isSelfConstrCall(tree: Tree): boolean = methPart(tree) match { + def isSelfConstrCall(tree: Tree): Boolean = methPart(tree) match { case Ident(nme.CONSTRUCTOR) | Select(This(_), nme.CONSTRUCTOR) => true case _ => false } - def isSuperConstrCall(tree: Tree): boolean = methPart(tree) match { + def isSuperConstrCall(tree: Tree): Boolean = methPart(tree) match { case Select(Super(_, _), nme.CONSTRUCTOR) => true case _ => false } - def isSelfOrSuperConstrCall(tree: Tree): boolean = methPart(tree) match { + def isSelfOrSuperConstrCall(tree: Tree): Boolean = methPart(tree) match { case Ident(nme.CONSTRUCTOR) | Select(This(_), nme.CONSTRUCTOR) | Select(Super(_, _), nme.CONSTRUCTOR) => true @@ -133,7 +133,7 @@ abstract class TreeInfo { } /** Is tree a variable pattern */ - def isVarPattern(pat: Tree): boolean = pat match { + def isVarPattern(pat: Tree): Boolean = pat match { case Ident(name) => isVariableName(name) && !pat.isInstanceOf[BackQuotedIdent] case _ => false } @@ -155,9 +155,8 @@ abstract class TreeInfo { case _ => false } - /** Is name a left-associative operator? */ - def isLeftAssoc(operator: Name): boolean = + def isLeftAssoc(operator: Name): Boolean = operator.length > 0 && operator(operator.length - 1) != ':' private val reserved = new HashSet[Name] @@ -175,19 +174,19 @@ abstract class TreeInfo { reserved addEntry newTypeName("unit") /** Is name a variable name? */ - def isVariableName(name: Name): boolean = { + def isVariableName(name: Name): Boolean = { val first = name(0) (('a' <= first && first <= 'z') || first == '_') && !(reserved contains name) } /** Is tree a this node which belongs to `enclClass'? */ - def isSelf(tree: Tree, enclClass: Symbol): boolean = tree match { + def isSelf(tree: Tree, enclClass: Symbol): Boolean = tree match { case This(_) => tree.symbol == enclClass case _ => false } /** can this type be a type pattern */ - def mayBeTypePat(tree: Tree): boolean = tree match { + def mayBeTypePat(tree: Tree): Boolean = tree match { case CompoundTypeTree(Template(tps, _, List())) => tps exists mayBeTypePat case Annotated(_, tp) => mayBeTypePat(tp) case AppliedTypeTree(constr, args) => @@ -213,7 +212,7 @@ abstract class TreeInfo { isDefaultCase(cdef) } - private def isSimpleThrowable(tp: Type): boolean = tp match { + private def isSimpleThrowable(tp: Type): Boolean = tp match { case TypeRef(pre, sym, args) => (pre == NoPrefix || pre.widen.typeSymbol.isStatic) && (sym isNonBottomSubClass definitions.ThrowableClass) @@ -235,7 +234,7 @@ abstract class TreeInfo { */ /** Is this pattern node a sequence-valued pattern? */ - def isSequenceValued(tree: Tree): boolean = tree match { + def isSequenceValued(tree: Tree): Boolean = tree match { case Bind(_, body) => isSequenceValued(body) case Sequence(_) => true case ArrayValue(_, _) => true @@ -247,7 +246,7 @@ abstract class TreeInfo { /** is this pattern of the form S(...) where S is a subclass of Seq * and S is not a case class? The pattern might be wrapped in binds or alternatives. */ - def isSequencePattern(tree: Tree): boolean = tree match { + def isSequencePattern(tree: Tree): Boolean = tree match { case Apply(fn, _) => (fn.symbol ne null) && !fn.symbol.hasFlag(CASE) && @@ -277,9 +276,10 @@ abstract class TreeInfo { EmptyTree } - /** Top-level definition sequence contains a leading import of Predef or scala.Predef + /** Top-level definition sequence contains a leading import of + * <code>Predef</code> or <code>scala.Predef</code>. */ - def containsLeadingPredefImport(defs: List[Tree]): boolean = defs match { + def containsLeadingPredefImport(defs: List[Tree]): Boolean = defs match { case List(PackageDef(_, defs1)) => containsLeadingPredefImport(defs1) case Import(Ident(nme.Predef), _) :: _ => diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala index b4e0aca5e1..c0ae8720cf 100644 --- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala +++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala @@ -30,14 +30,14 @@ trait Definitions { var emptypackagescope: Scope = null //debug - lazy val JavaLangPackage: Symbol = getModule(if (forMSIL) "System" else "java.lang") + lazy val JavaLangPackage: Symbol = getModule(sn.JavaLang) lazy val ScalaPackage: Symbol = getModule("scala") lazy val ScalaPackageClass: Symbol = ScalaPackage.tpe.typeSymbol var AnyClass: Symbol = _ var AnyValClass: Symbol = _ var AnyRefClass: Symbol = _ - lazy val ObjectClass: Symbol = getClass(if (forMSIL) "System.Object" else "java.lang.Object") + lazy val ObjectClass: Symbol = getClass(sn.Object) lazy val anyrefparam = List(AnyRefClass.typeConstructor) @@ -45,19 +45,16 @@ trait Definitions { var AllClass: Symbol = _ var SingletonClass: Symbol = _ - lazy val ClassClass: Symbol = getClass(if (forMSIL) "System.Type" else "java.lang.Class") - lazy val StringClass: Symbol = getClass(if (forMSIL) "System.String" else "java.lang.String") - lazy val ThrowableClass: Symbol = getClass(if (forMSIL) "System.Exception" else "java.lang.Throwable") - lazy val NullPointerExceptionClass: Symbol = - getClass(if (forMSIL) "System.NullReferenceException" - else "java.lang.NullPointerException") - lazy val NonLocalReturnExceptionClass: Symbol = - getClass("scala.runtime.NonLocalReturnException") + lazy val ClassClass: Symbol = getClass(sn.Class) + lazy val StringClass: Symbol = getClass(sn.String) + lazy val ThrowableClass: Symbol = getClass(sn.Throwable) + lazy val NullPointerExceptionClass: Symbol = getClass(sn.NPException) + lazy val NonLocalReturnExceptionClass: Symbol = getClass(sn.NLRException) // System.ValueType - lazy val ValueTypeClass: Symbol = if (forMSIL) getClass("System.ValueType") else null + lazy val ValueTypeClass: Symbol = getClass(sn.ValueType) // System.MulticastDelegate - lazy val DelegateClass: Symbol = if (forMSIL) getClass("System.MulticastDelegate") else null + lazy val DelegateClass: Symbol = getClass(sn.Delegate) var Delegate_scalaCallers: List[Symbol] = List() // Symbol -> (Symbol, Type): scalaCaller -> (scalaMethodSym, DelegateType) // var Delegate_scalaCallerInfos: HashMap[Symbol, (Symbol, Type)] = _ @@ -81,16 +78,19 @@ trait Definitions { var FloatClass: Symbol = _ var DoubleClass: Symbol = _ + // remote classes + //lazy val ChannelClass = getClass("scala.distributed.Channel") + //lazy val RemoteRefClass = getClass("scala.runtime.RemoteRef") + //lazy val RemoteRefModule = getModule("scala.runtime.RemoteRef") + //lazy val RemoteObjectRefClass = getClass("scala.runtime.distributed.RemoteObjectRef") + //var RemoteRefClasses: HashMap[Symbol, Symbol] = _ + // the scala reference classes lazy val ScalaObjectClass: Symbol = getClass("scala.ScalaObject") def ScalaObjectClass_tag = getMember(ScalaObjectClass, nme.tag) lazy val AnnotationClass: Symbol = getClass("scala.Annotation") lazy val ClassfileAnnotationClass: Symbol = getClass("scala.ClassfileAnnotation") lazy val StaticAnnotationClass: Symbol = getClass("scala.StaticAnnotation") - //var ChannelClass: Symbol = _ - // def Channel_send = getMember(ChannelClass, nme.send) - // def Channel_receive = getMember(ChannelClass, nme.receive) - //var RemoteRefClass: Symbol = _ var CodeClass: Symbol = _ var CodeModule: Symbol = _ def Code_lift = getMember(CodeModule, nme.lift_) @@ -111,7 +111,7 @@ trait Definitions { lazy val ArrayClass: Symbol = getClass("scala.Array") def Array_apply = getMember(ArrayClass, nme.apply) lazy val ArrayModule: Symbol = getModule("scala.Array") - lazy val SerializableClass: Symbol = if (forMSIL || forCLDC) null else getClass("java.io.Serializable") + lazy val SerializableClass: Symbol = getClass(sn.Serializable) lazy val PredefModule: Symbol = getModule("scala.Predef") def Predef_classOf = getMember(PredefModule, nme.classOf) def Predef_identity = getMember(PredefModule, nme.identity) @@ -121,9 +121,7 @@ trait Definitions { //var MatchErrorModule: Symbol = _ // def MatchError_fail = getMember(MatchErrorModule, nme.fail) // def MatchError_report = getMember(MatchErrorModule, nme.report) - lazy val IndexOutOfBoundsExceptionClass: Symbol = - getClass(if (forMSIL) "System.IndexOutOfRangeException" - else "java.lang.IndexOutOfBoundsException") + lazy val IndexOutOfBoundsExceptionClass: Symbol = getClass(sn.IOOBException) lazy val ScalaRunTimeModule: Symbol = getModule("scala.runtime.ScalaRunTime") def SeqFactory = getMember(ScalaRunTimeModule, nme.Seq); def checkDefinedMethod = getMember(ScalaRunTimeModule, "checkDefined") @@ -376,8 +374,7 @@ trait Definitions { lazy val BoxedAnyArrayClass = getClass("scala.runtime.BoxedAnyArray") lazy val BoxedObjectArrayClass = getClass("scala.runtime.BoxedObjectArray") lazy val BoxedUnitClass = getClass("scala.runtime.BoxedUnit") - lazy val BoxedNumberClass = if (forMSIL) getClass("System.IConvertible") - else getClass("java.lang.Number") + lazy val BoxedNumberClass = getClass(sn.BoxedNumber) lazy val BoxedUnitModule = getModule("scala.runtime.BoxedUnit") def BoxedUnit_UNIT = getMember(BoxedUnitModule, "UNIT") lazy val ObjectRefClass = getClass("scala.runtime.ObjectRef") @@ -385,7 +382,7 @@ trait Definitions { // special attributes lazy val SerializableAttr: Symbol = getClass("scala.serializable") lazy val DeprecatedAttr: Symbol = getClass("scala.deprecated") - lazy val BeanPropertyAttr: Symbol = if (forCLDC || forMSIL) null else getClass("scala.reflect.BeanProperty") + lazy val BeanPropertyAttr: Symbol = getClass(sn.BeanProperty) var AnnotationDefaultAttr: Symbol = _ lazy val NativeAttr: Symbol = getClass("scala.native") lazy val VolatileAttr: Symbol = getClass("scala.volatile") @@ -394,7 +391,8 @@ trait Definitions { def getClass(fullname: Name): Symbol = getModuleOrClass(fullname, false) - def getMember(owner: Symbol, name: Name) = { + def getMember(owner: Symbol, name: Name): Symbol = { + if (owner == null) return null val result = owner.info.nonPrivateMember(name) if (result == NoSymbol) { Console.println(owner.infosString) @@ -405,6 +403,7 @@ trait Definitions { } private def getModuleOrClass(fullname: Name, module: Boolean): Symbol = { + if (fullname == nme.NOSYMBOL) return null var sym = RootClass var i = 0 var j = fullname.pos('.', i) @@ -499,27 +498,7 @@ trait Definitions { private val abbrvTag = new HashMap[Symbol, Char] private def newValueClass(name: Name, tag: Char): Symbol = { - val boxedName = - if (!forMSIL) "java.lang." + (name match { - case nme.Boolean => "Boolean" - case nme.Byte => "Byte" - case nme.Char => "Character" - case nme.Short => "Short" - case nme.Int => "Integer" - case nme.Long => "Long" - case nme.Float => "Float" - case nme.Double => "Double" - }) - else "System." + (name match { - case nme.Boolean => "Boolean" - case nme.Byte => "Byte" - case nme.Char => "Char" - case nme.Short => "Int16" - case nme.Int => "Int32" - case nme.Long => "Int64" - case nme.Float => "Single" - case nme.Double => "Double" - }) + val boxedName = sn.Boxed(name) val clazz = newClass(ScalaPackageClass, name, List(AnyValClass.typeConstructor)) @@ -547,7 +526,7 @@ trait Definitions { /** Sets-up symbols etc. for value classes, and their boxed versions. This * method is called once from within the body of init. */ - private def initValueClasses: Unit = { + private def initValueClasses() { val booltype = BooleanClass.typeConstructor val boolparam = List(booltype) val bytetype = ByteClass.typeConstructor @@ -578,7 +557,7 @@ trait Definitions { newMethod(BooleanClass, nme.AND, boolparam, booltype) newMethod(BooleanClass, nme.XOR, boolparam, booltype) - def initValueClass(clazz: Symbol, isCardinal: Boolean): Unit = { + def initValueClass(clazz: Symbol, isCardinal: Boolean) { assert (clazz ne null) def addBinops(params: List[Type], restype: Type, isCardinal: Boolean) = { @@ -772,13 +751,8 @@ trait Definitions { DoubleClass = newValueClass(nme.Double, 'D') } - // the scala reference classes - //ChannelClass = getClass("scala.distributed.Channel") - //RemoteRefClass = getClass("scala.distributed.RemoteRef") - if (!forCLDC && ! forMSIL) { - CodeClass = getClass("scala.reflect.Code") - CodeModule = getModule("scala.reflect.Code") - } + CodeClass = getClass(sn.Code) + CodeModule = getModule(sn.Code) RepeatedParamClass = newCovariantPolyClass( ScalaPackageClass, nme.REPEATED_PARAM_CLASS_NAME, tparam => typeRef(SeqClass.typeConstructor.prefix, SeqClass, List(tparam.typeConstructor))) @@ -798,7 +772,7 @@ trait Definitions { for (i <- 0 to MaxFunctionArity) { FunctionClass(i) = getClass("scala.Function" + i) } - initValueClasses + initValueClasses() val booltype = BooleanClass.typeConstructor // members of class scala.Any @@ -840,13 +814,13 @@ trait Definitions { PatternWildcard = NoSymbol.newValue(NoPosition, "_").setInfo(AllClass.typeConstructor) if (forMSIL) { - val intType = IntClass.typeConstructor; - val intParam = List(intType); - val longType = LongClass.typeConstructor; - val charType = CharClass.typeConstructor; - val unitType = UnitClass.typeConstructor; - val stringType = StringClass.typeConstructor; - val stringParam = List(stringType); + val intType = IntClass.typeConstructor + val intParam = List(intType) + val longType = LongClass.typeConstructor + val charType = CharClass.typeConstructor + val unitType = UnitClass.typeConstructor + val stringType = StringClass.typeConstructor + val stringParam = List(stringType) // additional methods of Object newMethod(ObjectClass, "clone", List(), AnyRefClass.typeConstructor); @@ -888,6 +862,12 @@ trait Definitions { AnnotationDefaultAttr = newClass(RootClass, nme.AnnotationDefaultATTR, List(AnnotationClass.typeConstructor)) + + //RemoteRefClasses = new HashMap[Symbol, Symbol] + //for (clazz <- refClass.values) { + // RemoteRefClasses(clazz) = getClass("scala.runtime.distributed.Remote" + clazz.name) + //} + //RemoteRefClasses(ObjectRefClass) = RemoteObjectRefClass } var nbScalaCallers: Int = 0 diff --git a/src/compiler/scala/tools/nsc/symtab/SymbolTable.scala b/src/compiler/scala/tools/nsc/symtab/SymbolTable.scala index 3f01544107..ae380f6210 100644 --- a/src/compiler/scala/tools/nsc/symtab/SymbolTable.scala +++ b/src/compiler/scala/tools/nsc/symtab/SymbolTable.scala @@ -97,4 +97,88 @@ 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 + + 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") + + 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") + + 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 = // symbol names + if (forMSIL) new MSILNames + else if (forCLDC) new CLDCNames + else new J2SENames + } |