📄 definitions.scala
字号:
val restype3 = if (clazz eq DoubleClass) doubletype else floattype addBinops(floatparam, restype3, false) addBinops(doubleparam, doubletype, false) } } initValueClass(ByteClass, true) initValueClass(ShortClass, true) initValueClass(CharClass, true) initValueClass(IntClass, true) initValueClass(LongClass, true) if (!forCLDC) { initValueClass(FloatClass, false) initValueClass(DoubleClass, false) } def addModuleMethod(clazz: Symbol, name: Name, value: Any) { val owner = clazz.linkedClassOfClass newParameterlessMethod(owner, name, mkConstantType(Constant(value))) } addModuleMethod(ByteClass, "MinValue", java.lang.Byte.MIN_VALUE) addModuleMethod(ByteClass, "MaxValue", java.lang.Byte.MAX_VALUE) addModuleMethod(ShortClass, "MinValue", java.lang.Short.MIN_VALUE) addModuleMethod(ShortClass, "MaxValue", java.lang.Short.MAX_VALUE) addModuleMethod(CharClass, "MinValue", java.lang.Character.MIN_VALUE) addModuleMethod(CharClass, "MaxValue", java.lang.Character.MAX_VALUE) addModuleMethod(IntClass, "MinValue", java.lang.Integer.MIN_VALUE) addModuleMethod(IntClass, "MaxValue", java.lang.Integer.MAX_VALUE) addModuleMethod(LongClass, "MinValue", java.lang.Long.MIN_VALUE) addModuleMethod(LongClass, "MaxValue", java.lang.Long.MAX_VALUE) if (!forCLDC) { addModuleMethod(FloatClass, "MinValue", -java.lang.Float.MAX_VALUE) addModuleMethod(FloatClass, "MaxValue", java.lang.Float.MAX_VALUE) addModuleMethod(FloatClass, "Epsilon", java.lang.Float.MIN_VALUE) addModuleMethod(FloatClass, "NaN", java.lang.Float.NaN) addModuleMethod(FloatClass, "PositiveInfinity", java.lang.Float.POSITIVE_INFINITY) addModuleMethod(FloatClass, "NegativeInfinity", java.lang.Float.NEGATIVE_INFINITY) addModuleMethod(DoubleClass, "MinValue", -java.lang.Double.MAX_VALUE) addModuleMethod(DoubleClass, "MaxValue", java.lang.Double.MAX_VALUE) addModuleMethod(DoubleClass, "Epsilon", java.lang.Double.MIN_VALUE) addModuleMethod(DoubleClass, "NaN", java.lang.Double.NaN) addModuleMethod(DoubleClass, "PositiveInfinity", java.lang.Double.POSITIVE_INFINITY) addModuleMethod(DoubleClass, "NegativeInfinity", java.lang.Double.NEGATIVE_INFINITY) } } /** Is symbol a value class? */ def isValueClass(sym: Symbol): Boolean = (sym eq UnitClass) || (boxedClass contains sym) /** Is symbol a value class? */ def isNumericValueClass(sym: Symbol): Boolean = (sym ne BooleanClass) && (boxedClass contains sym) def isValueType(sym: Symbol) = isValueClass(sym) || unboxMethod.contains(sym) /** Is symbol a value or array class? */ def isUnboxedClass(sym: Symbol): Boolean = isValueType(sym) || sym == ArrayClass def signature(tp: Type): String = { def erasure(tp: Type): Type = tp match { case st: SubType => erasure(st.supertype) case RefinedType(parents, _) => erasure(parents.head) case _ => tp } def flatNameString(sym: Symbol, separator: Char): String = if (sym.owner.isPackageClass) sym.fullNameString('.') else flatNameString(sym.owner, separator) + "$" + sym.simpleName; def signature1(etp: Type): String = { if (etp.typeSymbol == ArrayClass) "[" + signature1(erasure(etp.normalize.typeArgs.head)) else if (isValueClass(etp.typeSymbol)) abbrvTag(etp.typeSymbol).toString() else "L" + flatNameString(etp.typeSymbol, '/') + ";" } val etp = erasure(tp) if (etp.typeSymbol == ArrayClass) signature1(etp) else flatNameString(etp.typeSymbol, '.') } private var isInitialized = false def init { if (isInitialized) return isInitialized = true EmptyPackageClass.setInfo(ClassInfoType(List(), newClassScope(EmptyPackageClass), EmptyPackageClass)) EmptyPackage.setInfo(EmptyPackageClass.tpe) RootClass.info.decls.enter(EmptyPackage) RootClass.info.decls.enter(RootPackage) AnyClass = newClass(ScalaPackageClass, nme.Any, List()).setFlag(ABSTRACT) val anyparam = List(AnyClass.typeConstructor) AnyValClass = newClass(ScalaPackageClass, nme.AnyVal, anyparam) .setFlag(FINAL | SEALED) AnyRefClass = newAlias(ScalaPackageClass, nme.AnyRef, ObjectClass.typeConstructor) AllRefClass = newClass(ScalaPackageClass, nme.Null, anyrefparam) .setFlag(ABSTRACT | TRAIT | FINAL) AllClass = newClass(ScalaPackageClass, nme.Nothing, anyparam) .setFlag(ABSTRACT | TRAIT | FINAL) SingletonClass = newClass(ScalaPackageClass, nme.Singleton, anyparam) .setFlag(ABSTRACT | TRAIT | FINAL) UnitClass = newClass(ScalaPackageClass, nme.Unit, List(AnyValClass.typeConstructor)) .setFlag(ABSTRACT | FINAL) abbrvTag(UnitClass) = 'V' BooleanClass = newValueClass(nme.Boolean, 'Z') ByteClass = newValueClass(nme.Byte, 'B') ShortClass = newValueClass(nme.Short, 'S') CharClass = newValueClass(nme.Char, 'C') IntClass = newValueClass(nme.Int, 'I') LongClass = newValueClass(nme.Long, 'L') if (!forCLDC) { FloatClass = newValueClass(nme.Float, 'F') DoubleClass = newValueClass(nme.Double, 'D') } 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))) ByNameParamClass = newCovariantPolyClass( ScalaPackageClass, nme.BYNAME_PARAM_CLASS_NAME, tparam => AnyClass.typeConstructor) EqualsPatternClass = newClass(ScalaPackageClass, nme.EQUALS_PATTERN_NAME, List()); { val tparam = newTypeParam(EqualsPatternClass, 0); EqualsPatternClass.setInfo( PolyType( List(tparam), ClassInfoType(List(AnyClass.typeConstructor), newClassScope(EqualsPatternClass), EqualsPatternClass))) } /* <unapply> */ //UnsealedClass = getClass("scala.unsealed") //todo: remove once 2.4 is out. for (i <- 1 to MaxTupleArity) { TupleClass(i) = getClass( "scala.Tuple" + i) } for (i <- 1 to MaxProductArity) { ProductClass(i) = getClass("scala.Product" + i) } /* </unapply> */ for (i <- 0 to MaxFunctionArity) { FunctionClass(i) = getClass("scala.Function" + i) } initValueClasses() val booltype = BooleanClass.typeConstructor // members of class scala.Any Any_== = newMethod(AnyClass, nme.EQ, anyparam, booltype) setFlag FINAL Any_!= = newMethod(AnyClass, nme.NE, anyparam, booltype) setFlag FINAL Any_equals = newMethod(AnyClass, nme.equals_, anyparam, booltype) Any_hashCode = newMethod( AnyClass, nme.hashCode_, List(), IntClass.typeConstructor) Any_toString = newMethod( AnyClass, nme.toString_, List(), StringClass.typeConstructor) Any_isInstanceOf = newPolyMethod( AnyClass, nme.isInstanceOf_, tparam => booltype) setFlag FINAL Any_asInstanceOf = newPolyMethod( AnyClass, nme.asInstanceOf_, tparam => tparam.typeConstructor) setFlag FINAL Any_isInstanceOfErased = newPolyMethod( AnyClass, nme.isInstanceOfErased, tparam => booltype) setFlag FINAL //todo: do we need this? Any_asInstanceOfErased = newPolyMethod( AnyClass, nme.asInstanceOfErased, tparam => tparam.typeConstructor) setFlag FINAL // members of class java.lang.{Object, String} Object_== = newMethod(ObjectClass, nme.EQ, anyrefparam, booltype) setFlag FINAL Object_!= = newMethod(ObjectClass, nme.NE, anyrefparam, booltype) setFlag FINAL Object_eq = newMethod(ObjectClass, nme.eq, anyrefparam, booltype) setFlag FINAL Object_ne = newMethod(ObjectClass, "ne", anyrefparam, booltype) setFlag FINAL Object_synchronized = newPolyMethod( ObjectClass, nme.synchronized_, tparam => MethodType(List(tparam.typeConstructor), tparam.typeConstructor)) setFlag FINAL Object_isInstanceOf = newPolyMethod( ObjectClass, "$isInstanceOf", tparam => MethodType(List(), booltype)) setFlag FINAL Object_asInstanceOf = newPolyMethod( ObjectClass, "$asInstanceOf", tparam => MethodType(List(), tparam.typeConstructor)) setFlag FINAL String_+ = newMethod( StringClass, "+", anyparam, StringClass.typeConstructor) setFlag FINAL 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) // additional methods of Object newMethod(ObjectClass, "clone", List(), AnyRefClass.typeConstructor); newMethod(ObjectClass, "wait", List(), unitType); newMethod(ObjectClass, "wait", List(longType), unitType); newMethod(ObjectClass, "wait", List(longType, intType), unitType); newMethod(ObjectClass, "notify", List(), unitType); newMethod(ObjectClass, "notifyAll", List(), unitType); // additional methods of String newMethod(StringClass, "length", List(), intType); newMethod(StringClass, "compareTo", stringParam, intType); newMethod(StringClass, "charAt", intParam, charType); newMethod(StringClass, "concat", stringParam, stringType); newMethod(StringClass, "indexOf", intParam, intType); newMethod(StringClass, "indexOf", List(intType, intType), intType); newMethod(StringClass, "indexOf", stringParam, intType); newMethod(StringClass, "indexOf", List(stringType, intType), intType); newMethod(StringClass, "lastIndexOf", intParam, intType); newMethod(StringClass, "lastIndexOf", List(intType, intType), intType); newMethod(StringClass, "lastIndexOf", stringParam, intType); newMethod(StringClass, "lastIndexOf", List(stringType, intType), intType); newMethod(StringClass, "toLowerCase", List(), stringType); newMethod(StringClass, "toUpperCase", List(), stringType); newMethod(StringClass, "startsWith", stringParam, booltype); newMethod(StringClass, "endsWith", stringParam, booltype); newMethod(StringClass, "substring", intParam, stringType); newMethod(StringClass, "substring", List(intType, intType), stringType); newMethod(StringClass, "trim", List(), stringType); newMethod(StringClass, "intern", List(), stringType); newMethod(StringClass, "replace", List(charType, charType), stringType); newMethod(StringClass, "toCharArray", List(), appliedType(ArrayClass.typeConstructor, List(charType))); } AnnotationDefaultAttr = newClass(RootClass, nme.AnnotationDefaultATTR, List(AnnotationClass.typeConstructor)) //RemoteRefClasses = new HashMap[Symbol, Symbol] //for (clazz <- refClass.values) { // RemoteRefClasses(clazz) = getClass("scala.runtime.remoting.Remote" + clazz.name) //} //RemoteRefClasses(ObjectRefClass) = RemoteObjectRefClass } var nbScalaCallers: Int = 0 def newScalaCaller(delegateType: Type): Symbol = { assert(forMSIL, "scalaCallers can only be created if target is .NET") // object: reference to object on which to call (scala-)metod val paramTypes: List[Type] = List(ObjectClass.tpe) val name: String = "$scalaCaller$$" + nbScalaCallers // tparam => resultType, which is the resultType of PolyType, i.e. the result type after applying the // type parameter =-> a MethodType in this case // TODO: set type bounds manually (-> MulticastDelegate), see newTypeParam val newCaller = newMethod(DelegateClass, name, paramTypes, delegateType) setFlag (FINAL | STATIC) // val newCaller = newPolyMethod(DelegateClass, name, // tparam => MethodType(paramTypes, tparam.typeConstructor)) setFlag (FINAL | STATIC) Delegate_scalaCallers = Delegate_scalaCallers ::: List(newCaller) nbScalaCallers += 1 newCaller } // def addScalaCallerInfo(scalaCaller: Symbol, methSym: Symbol, delType: Type) { // assert(Delegate_scalaCallers contains scalaCaller) // Delegate_scalaCallerInfos += (scalaCaller -> (methSym, delType)) // } def addScalaCallerInfo(scalaCaller: Symbol, methSym: Symbol) { assert(Delegate_scalaCallers contains scalaCaller) Delegate_scalaCallerTargets += (scalaCaller -> methSym) } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -