~ubuntu-branches/debian/sid/scala/sid

« back to all changes in this revision

Viewing changes to src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg, Mehdi Dogguy, Lucas Satabin, Frank S. Thomas, Emmanuel Bourg
  • Date: 2015-06-05 23:52:59 UTC
  • mfrom: (1.2.11)
  • Revision ID: package-import@ubuntu.com-20150605235259-wk00vgk83dh8o19g
Tags: 2.10.5-1
* Team upload.

[ Mehdi Dogguy ]
* New upstream release (Closes: #744278).

[ Lucas Satabin ]
* Update patches
* Update the clean target
* Update paths of elements to install
* Update watch file

[ Frank S. Thomas ]
* Remove myself from Uploaders.

[ Emmanuel Bourg ]
* The package has been adopted by the Java Team (Closes: #754935)
* Patched the build to avoid downloading libraries from the Internet
* Replaced the minified JavaScript files with unobfuscated ones
* No longer build scala-partest.jar until diffutils is packaged or replaced
* debian/watch: Fixed the versions matched (x.y.z instead of x.y.z..z)
* debian/rules:
  - Added the missing get-orig-source target (Closes: #724704)
  - Improved the clean target
* debian/control:
  - Build depend on scala (>= 2.10) and bnd
  - Use canonical URLs for the Vcs-* fields
  - Standards-Version updated to 3.9.6 (no changes)
* Switch to debhelper level 9

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* NSC -- new Scala compiler
2
 
 * Copyright 2005-2011 LAMP/EPFL
 
2
 * Copyright 2005-2013 LAMP/EPFL
3
3
 * @author  Martin Odersky
4
4
 */
5
5
 
10
10
import java.lang.Float.floatToIntBits
11
11
import java.lang.Double.doubleToLongBits
12
12
import scala.io.Codec
13
 
import reflect.generic.{ PickleBuffer, PickleFormat }
 
13
import scala.reflect.internal.pickling.{ PickleBuffer, PickleFormat }
14
14
import scala.collection.mutable.LinkedHashMap
15
15
import PickleFormat._
16
16
import Flags._
30
30
 
31
31
  val phaseName = "pickler"
32
32
 
 
33
  currentRun
 
34
 
33
35
  def newPhase(prev: Phase): StdPhase = new PicklePhase(prev)
34
36
 
35
37
  class PicklePhase(prev: Phase) extends StdPhase(prev) {
37
39
      def pickle(tree: Tree) {
38
40
        def add(sym: Symbol, pickle: Pickle) = {
39
41
          if (currentRun.compiles(sym) && !currentRun.symData.contains(sym)) {
40
 
            if (settings.debug.value) log("pickling " + sym)
 
42
            debuglog("pickling " + sym)
41
43
            pickle putSymbol sym
42
44
            currentRun.symData(sym) = pickle
43
45
          }
57
59
        }
58
60
      }
59
61
      // If there are any erroneous types in the tree, then we will crash
60
 
      // when we pickle it: so let's report an erorr instead.  We know next
 
62
      // when we pickle it: so let's report an error instead.  We know next
61
63
      // to nothing about what happened, but our supposition is a lot better
62
64
      // than "bad type: <error>" in terms of explanatory power.
63
 
      for (t <- unit.body ; if t.isErroneous) {
64
 
        unit.error(t.pos, "erroneous or inaccessible type")
65
 
        return
 
65
      for (t <- unit.body) {
 
66
        if (t.isErroneous) {
 
67
          unit.error(t.pos, "erroneous or inaccessible type")
 
68
          return
 
69
        }
 
70
 
 
71
        if (!t.isDef && t.hasSymbol && t.symbol.isTermMacro) {
 
72
          unit.error(t.pos, "macro has not been expanded")
 
73
          return
 
74
        }
66
75
      }
67
76
 
68
77
      pickle(unit.body)
75
84
    private var entries   = new Array[AnyRef](256)
76
85
    private var ep        = 0
77
86
    private val index     = new LinkedHashMap[AnyRef, Int]
78
 
    private lazy val nonClassRoot = root.ownersIterator.find(! _.isClass) getOrElse NoSymbol
 
87
    private lazy val nonClassRoot = findOrElse(root.ownersIterator)(!_.isClass)(NoSymbol)
79
88
 
80
89
    private def isRootSym(sym: Symbol) =
81
90
      sym.name.toTermName == rootName && sym.owner == rootOwner
104
113
       sym.isParameter ||
105
114
       isLocal(sym.owner))
106
115
 
107
 
    private def staticAnnotations(annots: List[AnnotationInfo]) =
108
 
      annots filter(ann =>
109
 
        ann.atp.typeSymbol isNonBottomSubClass definitions.StaticAnnotationClass)
110
 
 
111
116
    // Phase 1 methods: Populate entries/index ------------------------------------
112
117
 
113
118
    /** Store entry e in index at next available position unless
144
149
            putType(sym.typeOfThis);
145
150
          putSymbol(sym.alias)
146
151
          if (!sym.children.isEmpty) {
147
 
            val (locals, globals) = sym.children.toList.partition(_.isLocalClass)
 
152
            val (locals, globals) = sym.children partition (_.isLocalClass)
148
153
            val children =
149
154
              if (locals.isEmpty) globals
150
 
              else {
151
 
                val localChildDummy = sym.newClass(sym.pos, tpnme.LOCAL_CHILD)
152
 
                localChildDummy.setInfo(ClassInfoType(List(sym.tpe), EmptyScope, localChildDummy))
153
 
                localChildDummy :: globals
154
 
              }
155
 
            putChildren(sym, children sortBy (_.sealedSortName))
 
155
              else globals + sym.newClassWithInfo(tpnme.LOCAL_CHILD, List(sym.tpe), EmptyScope, pos = sym.pos)
 
156
 
 
157
            putChildren(sym, children.toList sortBy (_.sealedSortName))
156
158
          }
157
 
          for (annot <- staticAnnotations(sym.annotations.reverse))
 
159
          for (annot <- (sym.annotations filter (ann => ann.isStatic && !ann.isErroneous)).reverse)
158
160
            putAnnotation(sym, annot)
159
 
        } else if (sym != NoSymbol) {
 
161
        }
 
162
        else if (sym != NoSymbol) {
160
163
          putEntry(if (sym.isModuleClass) sym.name.toTermName else sym.name)
161
164
          if (!sym.owner.isRoot) putSymbol(sym.owner)
162
165
        }
191
194
        case RefinedType(parents, decls) =>
192
195
          val rclazz = tp.typeSymbol
193
196
          for (m <- decls.iterator)
194
 
            if (m.owner != rclazz) assert(false, "bad refinement member "+m+" of "+tp+", owner = "+m.owner)
 
197
            if (m.owner != rclazz) abort("bad refinement member "+m+" of "+tp+", owner = "+m.owner)
195
198
          putSymbol(rclazz); putTypes(parents); putSymbols(decls.toList)
196
199
        case ClassInfoType(parents, decls, clazz) =>
197
200
          putSymbol(clazz); putTypes(parents); putSymbols(decls.toList)
218
221
        case AnnotatedType(annotations, underlying, selfsym) =>
219
222
          putType(underlying)
220
223
          if (settings.selfInAnnots.value) putSymbol(selfsym)
221
 
          putAnnotations(staticAnnotations(annotations))
 
224
          putAnnotations(annotations filter (_.isStatic))
222
225
        case _ =>
223
226
          throw new FatalError("bad type: " + tp + "(" + tp.getClass + ")")
224
227
      }
286
289
          putTree(definition)
287
290
*/
288
291
        case Template(parents, self, body) =>
289
 
          writeNat(parents.length)
290
292
          putTrees(parents)
291
293
          putTree(self)
292
294
          putTrees(body)
420
422
     *  argument of some Annotation */
421
423
    private def putMods(mods: Modifiers) = if (putEntry(mods)) {
422
424
      // annotations in Modifiers are removed by the typechecker
423
 
      val Modifiers(flags, privateWithin, Nil, _) = mods
 
425
      val Modifiers(flags, privateWithin, Nil) = mods
424
426
      putEntry(privateWithin)
425
427
    }
426
428
 
429
431
    private def putConstant(c: Constant) {
430
432
      if (putEntry(c)) {
431
433
        if (c.tag == StringTag) putEntry(newTermName(c.stringValue))
432
 
        else if (c.tag == ClassTag) putType(c.typeValue)
 
434
        else if (c.tag == ClazzTag) putType(c.typeValue)
433
435
        else if (c.tag == EnumTag) putSymbol(c.symbolValue)
434
436
      }
435
437
    }
500
502
    private def writeSymInfo(sym: Symbol) {
501
503
      writeRef(sym.name)
502
504
      writeRef(localizedOwner(sym))
503
 
      writeLongNat((rawFlagsToPickled(sym.flags & PickledFlags)))
 
505
      writeLongNat((rawToPickledFlags(sym.flags & PickledFlags)))
504
506
      if (sym.hasAccessBoundary) writeRef(sym.privateWithin)
505
507
      writeRef(sym.info)
506
508
    }
509
511
    private def writeName(name: Name) {
510
512
      ensureCapacity(name.length * 3)
511
513
      val utfBytes = Codec toUTF8 name.toString
512
 
      compat.Platform.arraycopy(utfBytes, 0, bytes, writeIndex, utfBytes.length)
 
514
      scala.compat.Platform.arraycopy(utfBytes, 0, bytes, writeIndex, utfBytes.length)
513
515
      writeIndex += utfBytes.length
514
516
    }
515
517
 
610
612
          else if (c.tag == FloatTag) writeLong(floatToIntBits(c.floatValue))
611
613
          else if (c.tag == DoubleTag) writeLong(doubleToLongBits(c.doubleValue))
612
614
          else if (c.tag == StringTag) writeRef(newTermName(c.stringValue))
613
 
          else if (c.tag == ClassTag) writeRef(c.typeValue)
 
615
          else if (c.tag == ClazzTag) writeRef(c.typeValue)
614
616
          else if (c.tag == EnumTag) writeRef(c.symbolValue)
615
617
          LITERAL + c.tag // also treats UnitTag, NullTag; no value required
616
618
        case AnnotatedType(annotations, tp, selfsym) =>
617
 
          val staticAnnots = staticAnnotations(annotations)
618
 
          if (staticAnnots isEmpty) {
619
 
            writeBody(tp) // write the underlying type if there are no annotations
620
 
          } else {
621
 
            if (settings.selfInAnnots.value && selfsym != NoSymbol)
622
 
              writeRef(selfsym)
623
 
            writeRef(tp)
624
 
            writeRefs(staticAnnots)
625
 
            ANNOTATEDtpe
 
619
          annotations filter (_.isStatic) match {
 
620
            case Nil          => writeBody(tp) // write the underlying type if there are no annotations
 
621
            case staticAnnots =>
 
622
              if (settings.selfInAnnots.value && selfsym != NoSymbol)
 
623
                writeRef(selfsym)
 
624
              writeRef(tp)
 
625
              writeRefs(staticAnnots)
 
626
              ANNOTATEDtpe
626
627
          }
627
 
 
628
628
        // annotations attached to a symbol (i.e. annots on terms)
629
629
        case (target: Symbol, annot@AnnotationInfo(_, _, _)) =>
630
630
          writeRef(target)
964
964
          writeRefs(whereClauses)
965
965
          TREE
966
966
 
967
 
        case Modifiers(flags, privateWithin, _, _) =>
968
 
          val pflags = rawFlagsToPickled(flags)
 
967
        case Modifiers(flags, privateWithin, _) =>
 
968
          val pflags = rawToPickledFlags(flags)
969
969
          writeNat((pflags >> 32).toInt)
970
970
          writeNat((pflags & 0xFFFFFFFF).toInt)
971
971
          writeRef(privateWithin)
1065
1065
          else if (c.tag == FloatTag) print("Float "+c.floatValue)
1066
1066
          else if (c.tag == DoubleTag) print("Double "+c.doubleValue)
1067
1067
          else if (c.tag == StringTag) { print("String "); printRef(newTermName(c.stringValue)) }
1068
 
          else if (c.tag == ClassTag) { print("Class "); printRef(c.typeValue) }
 
1068
          else if (c.tag == ClazzTag) { print("Class "); printRef(c.typeValue) }
1069
1069
          else if (c.tag == EnumTag) { print("Enum "); printRef(c.symbolValue) }
1070
1070
        case AnnotatedType(annots, tp, selfsym) =>
1071
1071
          if (settings.selfInAnnots.value) {