⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 definitions.scala

📁 JAVA 语言的函数式编程扩展
💻 SCALA
📖 第 1 页 / 共 3 页
字号:
    // members of class java.lang.{Object, String}    var Object_eq          : Symbol = _    var Object_ne          : Symbol = _    var Object_==          : Symbol = _    var Object_!=          : Symbol = _    var Object_synchronized: Symbol = _    var Object_isInstanceOf: Symbol = _    var Object_asInstanceOf: Symbol = _    def Object_equals   = getMember(ObjectClass, nme.equals_)    def Object_hashCode = getMember(ObjectClass, nme.hashCode_)    def Object_toString = getMember(ObjectClass, nme.toString_)    var String_+           : Symbol = _    // members of class scala.Iterator    var Iterator_next      : Symbol = _    var Iterator_hasNext   : Symbol = _    // pattern wildcard    var PatternWildcard: Symbol = _    // boxed classes    lazy val BoxesRunTimeClass = getModule("scala.runtime.BoxesRunTime")    lazy val BoxedArrayClass = getClass("scala.runtime.BoxedArray")    lazy val BoxedAnyArrayClass = getClass("scala.runtime.BoxedAnyArray")    lazy val BoxedObjectArrayClass = getClass("scala.runtime.BoxedObjectArray")    lazy val BoxedUnitClass = getClass("scala.runtime.BoxedUnit")    lazy val BoxedNumberClass = getClass(sn.BoxedNumber)    lazy val BoxedCharacterClass = getClass(sn.BoxedCharacter)    lazy val BoxedBooleanClass = getClass(sn.BoxedBoolean)    lazy val BoxedUnitModule = getModule("scala.runtime.BoxedUnit")      def BoxedUnit_UNIT = getMember(BoxedUnitModule, "UNIT")    lazy val ObjectRefClass = getClass("scala.runtime.ObjectRef")    // special attributes    lazy val SerializableAttr: Symbol = getClass("scala.serializable")    lazy val DeprecatedAttr: Symbol = getClass("scala.deprecated")    lazy val BeanPropertyAttr: Symbol = getClass(sn.BeanProperty)    var AnnotationDefaultAttr: Symbol = _    lazy val NativeAttr: Symbol = getClass("scala.native")    lazy val VolatileAttr: Symbol = getClass("scala.volatile")    def getModule(fullname: Name): Symbol = getModuleOrClass(fullname, true)    def getClass(fullname: Name): Symbol = getModuleOrClass(fullname, false)    def getMember(owner: Symbol, name: Name): Symbol = {      if (owner == NoSymbol) return NoSymbol      val result = owner.info.nonPrivateMember(name)      if (result == NoSymbol) {        throw new FatalError(owner.toString() + " does not have a member " + name)      }      result    }    private def getModuleOrClass(fullname: Name, module: Boolean): Symbol = {      if (fullname == nme.NOSYMBOL) return NoSymbol      var sym = RootClass      var i = 0      var j = fullname.pos('.', i)      while (j < fullname.length) {        sym = sym.info.member(fullname.subName(i, j))        i = j + 1        j = fullname.pos('.', i)      }      val result =        if (module) sym.info.member(fullname.subName(i, j)).suchThat(_ hasFlag MODULE)        else sym.info.member(fullname.subName(i, j).toTypeName)      if (result == NoSymbol) {        if (settings.debug.value)          { Console.println(sym.info); Console.println(sym.info.members) }//debug        throw new FatalError((if (module) "object " else "class ") + fullname + " not found.")      }      result    }    private def newClass(owner: Symbol, name: Name, parents: List[Type]): Symbol = {      val clazz = owner.newClass(NoPosition, name.toTypeName)      clazz.setInfo(ClassInfoType(parents, newClassScope(clazz), clazz))      owner.info.decls.enter(clazz)       clazz    }    private def newCovariantPolyClass(owner: Symbol, name: Name, parent: Symbol => Type): Symbol = {      val clazz = newClass(owner, name, List())      val tparam = newTypeParam(clazz, 0) setFlag COVARIANT      clazz.setInfo(        PolyType(          List(tparam),          ClassInfoType(List(parent(tparam)), newClassScope(clazz), clazz)))    }    private def newAlias(owner: Symbol, name: Name, alias: Type): Symbol = {      val tpsym = owner.newAliasType(NoPosition, name.toTypeName)      tpsym.setInfo(alias)      owner.info.decls.enter(tpsym)      tpsym    }    private def newMethod(owner: Symbol, name: Name): Symbol = {      val msym = owner.newMethod(NoPosition, name.encode)      owner.info.decls.enter(msym)      msym    }    private def newMethod(owner: Symbol, name: Name, formals: List[Type], restpe: Type): Symbol =      newMethod(owner, name).setInfo(MethodType(formals, restpe))    private def newPolyMethod(owner: Symbol, name: Name, tcon: Symbol => Type): Symbol = {      val msym = newMethod(owner, name)      val tparam = newTypeParam(msym, 0)      msym.setInfo(PolyType(List(tparam), tcon(tparam)))    }    private def newParameterlessMethod(owner: Symbol, name: Name, restpe: Type) =      newMethod(owner, name).setInfo(PolyType(List(),restpe))    private def newTypeParam(owner: Symbol, index: Int): Symbol =      owner.newTypeParameter(NoPosition, "T" + index)        .setInfo(mkTypeBounds(AllClass.typeConstructor, AnyClass.typeConstructor))    val boxedClass = new HashMap[Symbol, Symbol]    val unboxMethod = new HashMap[Symbol, Symbol] // Type -> Method    val boxMethod = new HashMap[Symbol, Symbol] // Type -> Method    val boxedArrayClass = new HashMap[Symbol, Symbol]    def isUnbox(m: Symbol) = m.name == nme.unbox && {      m.tpe match {        case MethodType(_, restpe) => (unboxMethod get restpe.typeSymbol) match {          case Some(`m`) => true          case _ => false        }        case _ => false      }    }    /** Test whether a method symbol is that of a boxing method. */    def isBox(m: Symbol) = (boxMethod.values contains m) && {      m.tpe match {        case MethodType(List(argtpe), _) => (boxMethod get argtpe.typeSymbol) match {          case Some(`m`) => true          case _ => false        }        case _ => false      }    }    val refClass = new HashMap[Symbol, Symbol]    private val abbrvTag = new HashMap[Symbol, Char]    private def newValueClass(name: Name, tag: Char): Symbol = {      val boxedName = sn.Boxed(name)      val clazz =        newClass(ScalaPackageClass, name, List(AnyValClass.typeConstructor))        .setFlag(ABSTRACT | FINAL)      boxedClass(clazz) = getClass(boxedName)      boxedArrayClass(clazz) = getClass("scala.runtime.Boxed" + name + "Array")      refClass(clazz) = getClass("scala.runtime." + name + "Ref")      abbrvTag(clazz) = tag      val module = ScalaPackageClass.newModule(NoPosition, name)      ScalaPackageClass.info.decls.enter(module)      val mclass = module.moduleClass      mclass.setInfo(ClassInfoType(List(), newClassScope(mclass), mclass))      module.setInfo(mclass.tpe)      val box = newMethod(mclass, nme.box, List(clazz.typeConstructor),                          ObjectClass.typeConstructor)      boxMethod(clazz) = box      val unbox = newMethod(mclass, nme.unbox, List(ObjectClass.typeConstructor),                            clazz.typeConstructor)      unboxMethod(clazz) = unbox      clazz    }    /** 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() {      val booltype = BooleanClass.typeConstructor      val boolparam = List(booltype)      val bytetype = ByteClass.typeConstructor      val byteparam = List(bytetype)      val chartype = CharClass.typeConstructor      val charparam = List(chartype)      val shorttype = ShortClass.typeConstructor      val shortparam = List(shorttype)      val inttype = IntClass.typeConstructor      val intparam = List(inttype)      val longtype = LongClass.typeConstructor      val longparam = List(longtype)      val floattype = if (forCLDC) null else FloatClass.typeConstructor      val floatparam = if (forCLDC) null else List(floattype)      val doubletype = if (forCLDC) null else DoubleClass.typeConstructor      val doubleparam = if (forCLDC) null else List(doubletype)      val stringtype = StringClass.typeConstructor      // init scala.Boolean      newParameterlessMethod(BooleanClass, nme.UNARY_!, booltype)      newMethod(BooleanClass, nme.EQ,   boolparam, booltype)      newMethod(BooleanClass, nme.NE,   boolparam, booltype)      newMethod(BooleanClass, nme.ZOR,  boolparam, booltype)      newMethod(BooleanClass, nme.ZAND, boolparam, booltype)      newMethod(BooleanClass, nme.OR,   boolparam, booltype)      newMethod(BooleanClass, nme.AND,  boolparam, booltype)      newMethod(BooleanClass, nme.XOR,  boolparam, booltype)      def initValueClass(clazz: Symbol, isCardinal: Boolean) {        assert (clazz ne null)        def addBinops(params: List[Type], restype: Type, isCardinal: Boolean) = {          newMethod(clazz, nme.EQ,  params, booltype)          newMethod(clazz, nme.NE,  params, booltype)          newMethod(clazz, nme.LT,  params, booltype)          newMethod(clazz, nme.LE,  params, booltype)          newMethod(clazz, nme.GT,  params, booltype)          newMethod(clazz, nme.GE,  params, booltype)          newMethod(clazz, nme.ADD, params, restype)          newMethod(clazz, nme.SUB, params, restype)          newMethod(clazz, nme.MUL, params, restype)          newMethod(clazz, nme.DIV, params, restype)          newMethod(clazz, nme.MOD, params, restype)          if (isCardinal) {            newMethod(clazz, nme.OR, params, restype)            newMethod(clazz, nme.AND, params, restype)            newMethod(clazz, nme.XOR, params, restype)          }        }        // conversion methods        newParameterlessMethod(clazz, nme.toByte,   bytetype)        newParameterlessMethod(clazz, nme.toShort,  shorttype)        newParameterlessMethod(clazz, nme.toChar,   chartype)        newParameterlessMethod(clazz, nme.toInt,    inttype)        newParameterlessMethod(clazz, nme.toLong,   longtype)        if (!forCLDC) {          newParameterlessMethod(clazz, nme.toFloat,  floattype)          newParameterlessMethod(clazz, nme.toDouble, doubletype)        }        // def +(s: String): String        newMethod(clazz, nme.ADD, List(stringtype), stringtype)        val restype =          if ((clazz eq LongClass) ||              (clazz eq FloatClass) ||              (clazz eq DoubleClass))            clazz.typeConstructor          else inttype        // shift operations        if (isCardinal) {          newMethod(clazz, nme.LSL, intparam,  restype)          newMethod(clazz, nme.LSL, longparam, restype)          newMethod(clazz, nme.LSR, intparam,  restype)          newMethod(clazz, nme.LSR, longparam, restype)          newMethod(clazz, nme.ASR, intparam,  restype)          newMethod(clazz, nme.ASR, longparam, restype)        }        // unary operations        newParameterlessMethod(clazz, nme.UNARY_+, restype)        newParameterlessMethod(clazz, nme.UNARY_-, restype)        if (isCardinal) {          newParameterlessMethod(clazz, nme.UNARY_~, restype)        }        // binary operations        val restype2 = if (isCardinal) longtype else restype        addBinops(byteparam,   restype,    isCardinal)        addBinops(shortparam,  restype,    isCardinal)        addBinops(charparam,   restype,    isCardinal)        addBinops(intparam,    restype,    isCardinal)        addBinops(longparam,   restype2,   isCardinal)        if (!forCLDC) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -