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

« back to all changes in this revision

Viewing changes to src/compiler/scala/tools/nsc/backend/icode/TypeKinds.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
 
26
26
trait TypeKinds { self: ICodes =>
27
27
  import global._
28
28
  import definitions.{ ArrayClass, AnyRefClass, ObjectClass, NullClass, NothingClass, arrayType }
29
 
  import icodes.{ checkerDebug, NothingReference, NullReference }
30
29
 
31
30
  /** A map from scala primitive Types to ICode TypeKinds */
32
31
  lazy val primitiveTypeMap: Map[Symbol, TypeKind] = {
45
44
  }
46
45
  /** Reverse map for toType */
47
46
  private lazy val reversePrimitiveMap: Map[TypeKind, Symbol] =
48
 
    primitiveTypeMap map (_.swap) toMap
 
47
    (primitiveTypeMap map (_.swap)).toMap
49
48
 
50
49
  /** This class represents a type kind. Type kinds
51
50
   * represent the types that the VM know (or the ICode
75
74
      case _                                                => false
76
75
    }
77
76
 
78
 
    /** On the JVM, these types are like Ints for the
79
 
     *  purposes of calculating the lub.
 
77
    /** On the JVM,
 
78
     *    BOOL, BYTE, CHAR, SHORT, and INT
 
79
     *  are like Ints for the purposes of calculating the lub.
80
80
     */
81
 
    def isIntSizedType: Boolean = this match {
82
 
      case BOOL | CHAR | BYTE | SHORT | INT => true
83
 
      case _                                => false
84
 
    }
85
 
    def isIntegralType: Boolean = this match {
86
 
      case BYTE | SHORT | INT | LONG | CHAR => true
87
 
      case _                                => false
88
 
    }
89
 
    def isRealType: Boolean = this match {
90
 
      case FLOAT | DOUBLE => true
91
 
      case _              => false
92
 
    }
93
 
    def isNumericType: Boolean = isIntegralType | isRealType
 
81
    def isIntSizedType: Boolean = false
 
82
 
 
83
    /** On the JVM, similar to isIntSizedType except that BOOL isn't integral while LONG is. */
 
84
    def isIntegralType: Boolean = false
 
85
 
 
86
    /** On the JVM, FLOAT and DOUBLE. */
 
87
    def isRealType: Boolean = false
 
88
 
 
89
    final def isNumericType: Boolean = isIntegralType | isRealType
94
90
 
95
91
    /** Simple subtyping check */
96
92
    def <:<(other: TypeKind): Boolean = (this eq other) || (this match {
98
94
      case _                          => this eq other
99
95
    })
100
96
 
101
 
    /** Is this type a category 2 type in JVM terms? */
102
 
    def isWideType: Boolean = this match {
103
 
      case DOUBLE | LONG  => true
104
 
      case _              => false
105
 
    }
 
97
    /** Is this type a category 2 type in JVM terms? (ie, is it LONG or DOUBLE?) */
 
98
    def isWideType: Boolean = false
106
99
 
107
100
    /** The number of dimensions for array types. */
108
101
    def dimensions: Int = 0
146
139
     *  Here we make the adjustment by rewinding to a pre-erasure state and
147
140
     *  sifting through the parents for a class type.
148
141
     */
149
 
    def lub0(tk1: TypeKind, tk2: TypeKind): Type = atPhase(currentRun.uncurryPhase) {
 
142
    def lub0(tk1: TypeKind, tk2: TypeKind): Type = beforeUncurry {
150
143
      import definitions._
151
144
      val tp = global.lub(List(tk1.toType, tk2.toType))
152
 
      val (front, rest) = tp.parents span (_.typeSymbol.hasTraitFlag)
 
145
      val (front, rest) = tp.parents span (_.typeSymbol.isTrait)
153
146
 
154
 
      if (front.isEmpty) tp
155
 
      else if (rest.isEmpty) front.head   // all parents are interfaces
156
 
      else rest.head match {
157
 
        case AnyRefClass | ObjectClass  => tp
158
 
        case x                          => x
159
 
      }
 
147
      if (front.isEmpty || rest.isEmpty || rest.head.typeSymbol == ObjectClass) tp
 
148
      else rest.head
160
149
    }
161
150
 
162
151
    def isIntLub = (
187
176
 
188
177
  /** A boolean value */
189
178
  case object BOOL extends ValueTypeKind {
 
179
    override def isIntSizedType = true
190
180
    def maxType(other: TypeKind) = other match {
191
181
      case BOOL | REFERENCE(NothingClass)   => BOOL
192
182
      case _                                => uncomparable(other)
200
190
 
201
191
  /** A 1-byte signed integer */
202
192
  case object BYTE extends ValueTypeKind {
 
193
    override def isIntSizedType = true
 
194
    override def isIntegralType = true
203
195
    def maxType(other: TypeKind) = {
204
196
      if (other == BYTE || other.isNothingType) BYTE
205
197
      else if (other == CHAR) INT
210
202
 
211
203
  /** A 2-byte signed integer */
212
204
  case object SHORT extends ValueTypeKind {
 
205
    override def isIntSizedType = true
 
206
    override def isIntegralType = true
213
207
    override def maxType(other: TypeKind) = other match {
214
208
      case BYTE | SHORT | REFERENCE(NothingClass) => SHORT
215
209
      case CHAR                                   => INT
220
214
 
221
215
  /** A 2-byte UNSIGNED integer */
222
216
  case object CHAR extends ValueTypeKind {
 
217
    override def isIntSizedType = true
 
218
    override def isIntegralType = true
223
219
    override def maxType(other: TypeKind) = other match {
224
220
      case CHAR | REFERENCE(NothingClass) => CHAR
225
221
      case BYTE | SHORT                   => INT
230
226
 
231
227
  /** A 4-byte signed integer */
232
228
  case object INT extends ValueTypeKind {
 
229
    override def isIntSizedType = true
 
230
    override def isIntegralType = true
233
231
    override def maxType(other: TypeKind) = other match {
234
232
      case BYTE | SHORT | CHAR | INT | REFERENCE(NothingClass)  => INT
235
233
      case LONG | FLOAT | DOUBLE                                => other
239
237
 
240
238
  /** An 8-byte signed integer */
241
239
  case object LONG extends ValueTypeKind {
 
240
    override def isIntegralType = true
 
241
    override def isWideType = true
242
242
    override def maxType(other: TypeKind): TypeKind =
243
243
      if (other.isIntegralType || other.isNothingType) LONG
244
244
      else if (other.isRealType) DOUBLE
247
247
 
248
248
  /** A 4-byte floating point number */
249
249
  case object FLOAT extends ValueTypeKind {
 
250
    override def isRealType = true
250
251
    override def maxType(other: TypeKind): TypeKind =
251
252
      if (other == DOUBLE) DOUBLE
252
253
      else if (other.isNumericType || other.isNothingType) FLOAT
255
256
 
256
257
  /** An 8-byte floating point number */
257
258
  case object DOUBLE extends ValueTypeKind {
 
259
    override def isRealType = true
 
260
    override def isWideType = true
258
261
    override def maxType(other: TypeKind): TypeKind =
259
262
      if (other.isNumericType || other.isNothingType) DOUBLE
260
263
      else uncomparable(other)
271
274
           "REFERENCE to NoSymbol not allowed!")
272
275
 
273
276
    /**
274
 
     * Approximate `lub'. The common type of two references is
 
277
     * Approximate `lub`. The common type of two references is
275
278
     * always AnyRef. For 'real' least upper bound wrt to subclassing
276
279
     * use method 'lub'.
277
280
     */
307
310
    }
308
311
 
309
312
    /**
310
 
     * Approximate `lub'. The common type of two references is
 
313
     * Approximate `lub`. The common type of two references is
311
314
     * always AnyRef. For 'real' least upper bound wrt to subclassing
312
315
     * use method 'lub'.
313
316
     */
352
355
    override def toString = "ConcatClass"
353
356
 
354
357
    /**
355
 
     * Approximate `lub'. The common type of two references is
 
358
     * Approximate `lub`. The common type of two references is
356
359
     * always AnyRef. For 'real' least upper bound wrt to subclassing
357
360
     * use method 'lub'.
358
361
     */
380
383
    case TypeRef(_, sym, args)           => primitiveOrClassType(sym, args)
381
384
    case ClassInfoType(_, _, ArrayClass) => abort("ClassInfoType to ArrayClass!")
382
385
    case ClassInfoType(_, _, sym)        => primitiveOrRefType(sym)
 
386
 
 
387
    // !!! Iulian says types which make no sense after erasure should not reach here,
 
388
    // which includes the ExistentialType, AnnotatedType, RefinedType.  I don't know
 
389
    // if the first two cases exist because they do or as a defensive measure, but
 
390
    // at the time I added it, RefinedTypes were indeed reaching here.
383
391
    case ExistentialType(_, t)           => toTypeKind(t)
384
392
    case AnnotatedType(_, t, _)          => toTypeKind(t)
385
 
    // PP to ID: I added RefinedType here, is this OK or should they never be
386
 
    // allowed to reach here?
387
393
    case RefinedType(parents, _)         => parents map toTypeKind reduceLeft lub
388
 
    // bq: useful hack when wildcard types come here
 
394
    // For sure WildcardTypes shouldn't reach here either, but when
 
395
    // debugging such situations this may come in handy.
389
396
    // case WildcardType                    => REFERENCE(ObjectClass)
390
397
    case norm => abort(
391
398
      "Unknown type: %s, %s [%s, %s] TypeRef? %s".format(
413
420
    // between "object PackratParsers$class" and "trait PackratParsers"
414
421
    if (sym.isImplClass) {
415
422
      // pos/spec-List.scala is the sole failure if we don't check for NoSymbol
416
 
      val traitSym = sym.owner.info.decl(nme.interfaceName(sym.name))
 
423
      val traitSym = sym.owner.info.decl(tpnme.interfaceName(sym.name))
417
424
      if (traitSym != NoSymbol)
418
425
        return REFERENCE(traitSym)
419
426
    }