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

« back to all changes in this revision

Viewing changes to src/reflect/scala/reflect/internal/StdNames.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
/* NSC -- new Scala compiler
 
2
 * Copyright 2005-2013 LAMP/EPFL
 
3
 * @author  Martin Odersky
 
4
 */
 
5
 
 
6
package scala.reflect
 
7
package internal
 
8
 
 
9
import java.security.MessageDigest
 
10
import Chars.isOperatorPart
 
11
import scala.annotation.switch
 
12
import scala.language.implicitConversions
 
13
import scala.collection.immutable
 
14
import scala.io.Codec
 
15
 
 
16
trait StdNames {
 
17
  self: SymbolTable =>
 
18
 
 
19
  def encode(str: String): TermName = newTermNameCached(NameTransformer.encode(str))
 
20
 
 
21
  implicit def lowerTermNames(n: TermName): String = n.toString
 
22
 
 
23
  /** Tensions: would like the keywords to be the very first names entered into the names
 
24
   *  storage so their ids count from 0, which simplifies the parser. Switched to abstract
 
25
   *  classes to avoid all the indirection which is generated with implementation-containing
 
26
   *  traits. Since all these classes use eager vals, that means the constructor with the
 
27
   *  keywords must run first. If it's the top in the superclass chain, then CommonNames
 
28
   *  must inherit from it, which means TypeNames would inherit keywords as well.
 
29
   *
 
30
   *  Solution: Keywords extends CommonNames and uses early defs to beat the
 
31
   *  CommonNames constructor out of the starting gate.  This is its builder.
 
32
   */
 
33
  private class KeywordSetBuilder {
 
34
    private var kws: Set[TermName] = Set()
 
35
    def apply(s: String): TermName = {
 
36
      val result = newTermNameCached(s)
 
37
      kws = kws + result
 
38
      result
 
39
    }
 
40
    def result: Set[TermName] = {
 
41
      val result = kws
 
42
      kws = null
 
43
      result
 
44
    }
 
45
  }
 
46
 
 
47
  private[reflect] def compactifyName(orig: String): String = compactify(orig)
 
48
  private final object compactify extends (String => String) {
 
49
    val md5 = MessageDigest.getInstance("MD5")
 
50
 
 
51
    /**
 
52
     * COMPACTIFY
 
53
     *
 
54
     * The hashed name has the form (prefix + marker + md5 + marker + suffix), where
 
55
     *   - prefix/suffix.length = MaxNameLength / 4
 
56
     *   - md5.length = 32
 
57
     *
 
58
     * We obtain the formula:
 
59
     *
 
60
     *   FileNameLength = 2*(MaxNameLength / 4) + 2.marker.length + 32 + 6
 
61
     *
 
62
     * (+6 for ".class"). MaxNameLength can therefore be computed as follows:
 
63
     */
 
64
    val marker = "$$$$"
 
65
    val MaxNameLength = math.min(
 
66
      settings.maxClassfileName.value - 6,
 
67
      2 * (settings.maxClassfileName.value - 6 - 2*marker.length - 32)
 
68
    )
 
69
    def toMD5(s: String, edge: Int): String = {
 
70
      val prefix = s take edge
 
71
      val suffix = s takeRight edge
 
72
 
 
73
      val cs = s.toArray
 
74
      val bytes = Codec toUTF8 cs
 
75
      md5 update bytes
 
76
      val md5chars = (md5.digest() map (b => (b & 0xFF).toHexString)).mkString
 
77
 
 
78
      prefix + marker + md5chars + marker + suffix
 
79
    }
 
80
    def apply(s: String): String = (
 
81
      if (s.length <= MaxNameLength) s
 
82
      else toMD5(s, MaxNameLength / 4)
 
83
    )
 
84
  }
 
85
 
 
86
  abstract class CommonNames extends NamesApi {
 
87
    type NameType >: Null <: Name
 
88
    // Masking some implicits so as to allow our targeted => NameType.
 
89
    protected val stringToTermName = null
 
90
    protected val stringToTypeName = null
 
91
    protected implicit def createNameType(name: String): NameType
 
92
 
 
93
    def flattenedName(segments: Name*): NameType =
 
94
      compactify(segments mkString NAME_JOIN_STRING)
 
95
 
 
96
    val MODULE_SUFFIX_STRING: String = NameTransformer.MODULE_SUFFIX_STRING
 
97
    val NAME_JOIN_STRING: String     = NameTransformer.NAME_JOIN_STRING
 
98
    val SINGLETON_SUFFIX: String     = ".type"
 
99
 
 
100
    val ANON_CLASS_NAME: NameType    = "$anon"
 
101
    val ANON_FUN_NAME: NameType      = "$anonfun"
 
102
    val EMPTY: NameType              = ""
 
103
    val EMPTY_PACKAGE_NAME: NameType = "<empty>"
 
104
    val IMPL_CLASS_SUFFIX            = "$class"
 
105
    val IMPORT: NameType             = "<import>"
 
106
    val MODULE_SUFFIX_NAME: NameType = MODULE_SUFFIX_STRING
 
107
    val MODULE_VAR_SUFFIX: NameType  = "$module"
 
108
    val NAME_JOIN_NAME: NameType     = NAME_JOIN_STRING
 
109
    val PACKAGE: NameType            = "package"
 
110
    val ROOT: NameType               = "<root>"
 
111
    val SPECIALIZED_SUFFIX: NameType = "$sp"
 
112
 
 
113
    // value types (and AnyRef) are all used as terms as well
 
114
    // as (at least) arguments to the @specialize annotation.
 
115
    final val Boolean: NameType = "Boolean"
 
116
    final val Byte: NameType    = "Byte"
 
117
    final val Char: NameType    = "Char"
 
118
    final val Double: NameType  = "Double"
 
119
    final val Float: NameType   = "Float"
 
120
    final val Int: NameType     = "Int"
 
121
    final val Long: NameType    = "Long"
 
122
    final val Short: NameType   = "Short"
 
123
    final val Unit: NameType    = "Unit"
 
124
 
 
125
    final val ScalaValueNames: scala.List[NameType] =
 
126
      scala.List(Byte, Char, Short, Int, Long, Float, Double, Boolean, Unit)
 
127
 
 
128
    // some types whose companions we utilize
 
129
    final val AnyRef: NameType     = "AnyRef"
 
130
    final val Array: NameType      = "Array"
 
131
    final val List: NameType       = "List"
 
132
    final val Seq: NameType        = "Seq"
 
133
    final val Symbol: NameType     = "Symbol"
 
134
    final val ClassTag: NameType   = "ClassTag"
 
135
    final val WeakTypeTag: NameType = "WeakTypeTag"
 
136
    final val TypeTag : NameType   = "TypeTag"
 
137
    final val Expr: NameType       = "Expr"
 
138
    final val String: NameType     = "String"
 
139
 
 
140
    // fictions we use as both types and terms
 
141
    final val ERROR: NameType    = "<error>"
 
142
    final val NO_NAME: NameType  = "<none>"  // formerly NOSYMBOL
 
143
    final val WILDCARD: NameType = "_"
 
144
  }
 
145
 
 
146
  /** This should be the first trait in the linearization. */
 
147
  // abstract class Keywords extends CommonNames {
 
148
  abstract class Keywords extends {
 
149
    private val kw = new KeywordSetBuilder
 
150
 
 
151
    final val ABSTRACTkw: TermName  = kw("abstract")
 
152
    final val CASEkw: TermName      = kw("case")
 
153
    final val CLASSkw: TermName     = kw("class")
 
154
    final val CATCHkw: TermName     = kw("catch")
 
155
    final val DEFkw: TermName       = kw("def")
 
156
    final val DOkw: TermName        = kw("do")
 
157
    final val ELSEkw: TermName      = kw("else")
 
158
    final val EXTENDSkw: TermName   = kw("extends")
 
159
    final val FALSEkw: TermName     = kw("false")
 
160
    final val FINALkw: TermName     = kw("final")
 
161
    final val FINALLYkw: TermName   = kw("finally")
 
162
    final val FORkw: TermName       = kw("for")
 
163
    final val FORSOMEkw: TermName   = kw("forSome")
 
164
    final val IFkw: TermName        = kw("if")
 
165
    final val IMPLICITkw: TermName  = kw("implicit")
 
166
    final val IMPORTkw: TermName    = kw("import")
 
167
    final val LAZYkw: TermName      = kw("lazy")
 
168
    final val MACROkw: TermName     = kw("macro")
 
169
    final val MATCHkw: TermName     = kw("match")
 
170
    final val NEWkw: TermName       = kw("new")
 
171
    final val NULLkw: TermName      = kw("null")
 
172
    final val OBJECTkw: TermName    = kw("object")
 
173
    final val OVERRIDEkw: TermName  = kw("override")
 
174
    final val PACKAGEkw: TermName   = kw("package")
 
175
    final val PRIVATEkw: TermName   = kw("private")
 
176
    final val PROTECTEDkw: TermName = kw("protected")
 
177
    final val RETURNkw: TermName    = kw("return")
 
178
    final val SEALEDkw: TermName    = kw("sealed")
 
179
    final val SUPERkw: TermName     = kw("super")
 
180
    final val THENkw: TermName      = kw("then")
 
181
    final val THISkw: TermName      = kw("this")
 
182
    final val THROWkw: TermName     = kw("throw")
 
183
    final val TRAITkw: TermName     = kw("trait")
 
184
    final val TRUEkw: TermName      = kw("true")
 
185
    final val TRYkw: TermName       = kw("try")
 
186
    final val TYPEkw: TermName      = kw("type")
 
187
    final val VALkw: TermName       = kw("val")
 
188
    final val VARkw: TermName       = kw("var")
 
189
    final val WITHkw: TermName      = kw("with")
 
190
    final val WHILEkw: TermName     = kw("while")
 
191
    final val YIELDkw: TermName     = kw("yield")
 
192
    final val DOTkw: TermName       = kw(".")
 
193
    final val USCOREkw: TermName    = kw("_")
 
194
    final val COLONkw: TermName     = kw(":")
 
195
    final val EQUALSkw: TermName    = kw("=")
 
196
    final val ARROWkw: TermName     = kw("=>")
 
197
    final val LARROWkw: TermName    = kw("<-")
 
198
    final val SUBTYPEkw: TermName   = kw("<:")
 
199
    final val VIEWBOUNDkw: TermName = kw("<%")
 
200
    final val SUPERTYPEkw: TermName = kw(">:")
 
201
    final val HASHkw: TermName      = kw("#")
 
202
    final val ATkw: TermName        = kw("@")
 
203
 
 
204
    final val keywords = kw.result
 
205
  } with CommonNames {
 
206
    final val javaKeywords = new JavaKeywords()
 
207
  }
 
208
 
 
209
  abstract class TypeNames extends Keywords with TypeNamesApi {
 
210
    protected implicit def createNameType(name: String): TypeName = newTypeNameCached(name)
 
211
 
 
212
    final val BYNAME_PARAM_CLASS_NAME: NameType        = "<byname>"
 
213
    final val EQUALS_PATTERN_NAME: NameType            = "<equals>"
 
214
    final val JAVA_REPEATED_PARAM_CLASS_NAME: NameType = "<repeated...>"
 
215
    final val LOCAL_CHILD: NameType                    = "<local child>"
 
216
    final val REFINE_CLASS_NAME: NameType              = "<refinement>"
 
217
    final val REPEATED_PARAM_CLASS_NAME: NameType      = "<repeated>"
 
218
    final val WILDCARD_STAR: NameType                  = "_*"
 
219
    final val REIFY_TREECREATOR_PREFIX: NameType       = "$treecreator"
 
220
    final val REIFY_TYPECREATOR_PREFIX: NameType       = "$typecreator"
 
221
 
 
222
    final val Any: NameType             = "Any"
 
223
    final val AnyVal: NameType          = "AnyVal"
 
224
    final val ExprApi: NameType         = "ExprApi"
 
225
    final val Mirror: NameType          = "Mirror"
 
226
    final val Nothing: NameType         = "Nothing"
 
227
    final val Null: NameType            = "Null"
 
228
    final val Object: NameType          = "Object"
 
229
    final val PartialFunction: NameType = "PartialFunction"
 
230
    final val PrefixType: NameType      = "PrefixType"
 
231
    final val Product: NameType         = "Product"
 
232
    final val Serializable: NameType    = "Serializable"
 
233
    final val Singleton: NameType       = "Singleton"
 
234
    final val Throwable: NameType       = "Throwable"
 
235
 
 
236
    final val Annotation: NameType          = "Annotation"
 
237
    final val ClassfileAnnotation: NameType = "ClassfileAnnotation"
 
238
    final val ClassManifest: NameType       = "ClassManifest"
 
239
    final val Enum: NameType                = "Enum"
 
240
    final val Group: NameType               = "Group"
 
241
    final val Tree: NameType                = "Tree"
 
242
    final val Type : NameType               = "Type"
 
243
    final val TypeTree: NameType            = "TypeTree"
 
244
 
 
245
    // Annotation simple names, used in Namer
 
246
    final val BeanPropertyAnnot: NameType = "BeanProperty"
 
247
    final val BooleanBeanPropertyAnnot: NameType = "BooleanBeanProperty"
 
248
    final val bridgeAnnot: NameType = "bridge"
 
249
 
 
250
    // Classfile Attributes
 
251
    final val AnnotationDefaultATTR: NameType      = "AnnotationDefault"
 
252
    final val BridgeATTR: NameType                 = "Bridge"
 
253
    final val ClassfileAnnotationATTR: NameType    = "RuntimeInvisibleAnnotations" // RetentionPolicy.CLASS. Currently not used (Apr 2009).
 
254
    final val CodeATTR: NameType                   = "Code"
 
255
    final val ConstantValueATTR: NameType          = "ConstantValue"
 
256
    final val DeprecatedATTR: NameType             = "Deprecated"
 
257
    final val ExceptionsATTR: NameType             = "Exceptions"
 
258
    final val InnerClassesATTR: NameType           = "InnerClasses"
 
259
    final val LineNumberTableATTR: NameType        = "LineNumberTable"
 
260
    final val LocalVariableTableATTR: NameType     = "LocalVariableTable"
 
261
    final val RuntimeAnnotationATTR: NameType      = "RuntimeVisibleAnnotations"   // RetentionPolicy.RUNTIME
 
262
    final val RuntimeParamAnnotationATTR: NameType = "RuntimeVisibleParameterAnnotations" // RetentionPolicy.RUNTIME (annotations on parameters)
 
263
    final val ScalaATTR: NameType                  = "Scala"
 
264
    final val ScalaSignatureATTR: NameType         = "ScalaSig"
 
265
    final val SignatureATTR: NameType              = "Signature"
 
266
    final val SourceFileATTR: NameType             = "SourceFile"
 
267
    final val SyntheticATTR: NameType              = "Synthetic"
 
268
 
 
269
    def dropSingletonName(name: Name): TypeName = (name dropRight SINGLETON_SUFFIX.length).toTypeName
 
270
    def singletonName(name: Name): TypeName     = (name append SINGLETON_SUFFIX).toTypeName
 
271
    def implClassName(name: Name): TypeName     = (name append IMPL_CLASS_SUFFIX).toTypeName
 
272
    def interfaceName(implname: Name): TypeName = (implname dropRight IMPL_CLASS_SUFFIX.length).toTypeName
 
273
  }
 
274
 
 
275
  abstract class TermNames extends Keywords with TermNamesApi {
 
276
    protected implicit def createNameType(name: String): TermName = newTermNameCached(name)
 
277
 
 
278
    /** Base strings from which synthetic names are derived. */
 
279
    val BITMAP_PREFIX                 = "bitmap$"
 
280
    val CHECK_IF_REFUTABLE_STRING     = "check$ifrefutable$"
 
281
    val DEFAULT_GETTER_STRING         = "$default$"
 
282
    val DEFAULT_GETTER_INIT_STRING    = "$lessinit$greater" // CONSTRUCTOR.encoded, less is more
 
283
    val DO_WHILE_PREFIX               = "doWhile$"
 
284
    val EVIDENCE_PARAM_PREFIX         = "evidence$"
 
285
    val EXCEPTION_RESULT_PREFIX       = "exceptionResult"
 
286
    val EXPAND_SEPARATOR_STRING       = "$$"
 
287
    val INTERPRETER_IMPORT_WRAPPER    = "$iw"
 
288
    val INTERPRETER_LINE_PREFIX       = "line"
 
289
    val INTERPRETER_VAR_PREFIX        = "res"
 
290
    val INTERPRETER_WRAPPER_SUFFIX    = "$object"
 
291
    val LOCALDUMMY_PREFIX             = "<local "       // owner of local blocks
 
292
    val PROTECTED_PREFIX              = "protected$"
 
293
    val PROTECTED_SET_PREFIX          = PROTECTED_PREFIX + "set"
 
294
    val SUPER_PREFIX_STRING           = "super$"
 
295
    val TRAIT_SETTER_SEPARATOR_STRING = "$_setter_$"
 
296
    val WHILE_PREFIX                  = "while$"
 
297
 
 
298
    // Compiler internal names
 
299
    val ANYname: NameType                  = "<anyname>"
 
300
    val CONSTRUCTOR: NameType              = "<init>"
 
301
    val DEFAULT_CASE: NameType             = "defaultCase$"
 
302
    val EQEQ_LOCAL_VAR: NameType           = "eqEqTemp$"
 
303
    val FAKE_LOCAL_THIS: NameType          = "this$"
 
304
    val INITIALIZER: NameType              = CONSTRUCTOR // Is this buying us something?
 
305
    val LAZY_LOCAL: NameType               = "$lzy"
 
306
    val LAZY_SLOW_SUFFIX: NameType         = "$lzycompute"
 
307
    val LOCAL_SUFFIX_STRING                = " "
 
308
    val UNIVERSE_BUILD_PREFIX: NameType    = "$u.build."
 
309
    val UNIVERSE_BUILD: NameType           = "$u.build"
 
310
    val UNIVERSE_PREFIX: NameType          = "$u."
 
311
    val UNIVERSE_SHORT: NameType           = "$u"
 
312
    val MIRROR_PREFIX: NameType            = "$m."
 
313
    val MIRROR_SHORT: NameType             = "$m"
 
314
    val MIRROR_UNTYPED: NameType           = "$m$untyped"
 
315
    val REIFY_FREE_PREFIX: NameType        = "free$"
 
316
    val REIFY_FREE_THIS_SUFFIX: NameType   = "$this"
 
317
    val REIFY_FREE_VALUE_SUFFIX: NameType  = "$value"
 
318
    val REIFY_SYMDEF_PREFIX: NameType      = "symdef$"
 
319
    val MIXIN_CONSTRUCTOR: NameType        = "$init$"
 
320
    val MODULE_INSTANCE_FIELD: NameType    = NameTransformer.MODULE_INSTANCE_NAME  // "MODULE$"
 
321
    val OUTER: NameType                    = "$outer"
 
322
    val OUTER_LOCAL: NameType              = OUTER + LOCAL_SUFFIX_STRING // "$outer ", note the space
 
323
    val OUTER_SYNTH: NameType              = "<outer>" // emitted by virtual pattern matcher, replaced by outer accessor in explicitouter
 
324
    val ROOTPKG: NameType                  = "_root_"
 
325
    val SELECTOR_DUMMY: NameType           = "<unapply-selector>"
 
326
    val SELF: NameType                     = "$this"
 
327
    val SETTER_SUFFIX: NameType            = encode("_=")
 
328
    val SPECIALIZED_INSTANCE: NameType     = "specInstance$"
 
329
    val STAR: NameType                     = "*"
 
330
    val THIS: NameType                     = "_$this"
 
331
 
 
332
    @deprecated("Use SPECIALIZED_SUFFIX", "2.10.0")
 
333
    def SPECIALIZED_SUFFIX_STRING = SPECIALIZED_SUFFIX.toString
 
334
    @deprecated("Use SPECIALIZED_SUFFIX", "2.10.0")
 
335
    def SPECIALIZED_SUFFIX_NAME: TermName = SPECIALIZED_SUFFIX.toTermName
 
336
 
 
337
    def isConstructorName(name: Name)       = name == CONSTRUCTOR || name == MIXIN_CONSTRUCTOR
 
338
    def isExceptionResultName(name: Name)   = name startsWith EXCEPTION_RESULT_PREFIX
 
339
    def isImplClassName(name: Name)         = name endsWith IMPL_CLASS_SUFFIX
 
340
    def isLocalDummyName(name: Name)        = name startsWith LOCALDUMMY_PREFIX
 
341
    def isLocalName(name: Name)             = name endsWith LOCAL_SUFFIX_STRING
 
342
    def isLoopHeaderLabel(name: Name)       = (name startsWith WHILE_PREFIX) || (name startsWith DO_WHILE_PREFIX)
 
343
    def isProtectedAccessorName(name: Name) = name startsWith PROTECTED_PREFIX
 
344
    def isSuperAccessorName(name: Name)     = name startsWith SUPER_PREFIX_STRING
 
345
    def isReplWrapperName(name: Name)       = name containsName INTERPRETER_IMPORT_WRAPPER
 
346
    def isSetterName(name: Name)            = name endsWith SETTER_SUFFIX
 
347
    def isTraitSetterName(name: Name)       = isSetterName(name) && (name containsName TRAIT_SETTER_SEPARATOR_STRING)
 
348
    def isSingletonName(name: Name)         = name endsWith SINGLETON_SUFFIX
 
349
    def isModuleName(name: Name)            = name endsWith MODULE_SUFFIX_NAME
 
350
 
 
351
    /** Is name a variable name? */
 
352
    def isVariableName(name: Name): Boolean = {
 
353
      val first = name.startChar
 
354
      (    ((first.isLower && first.isLetter) || first == '_')
 
355
        && (name != nme.false_)
 
356
        && (name != nme.true_)
 
357
        && (name != nme.null_)
 
358
      )
 
359
    }
 
360
 
 
361
    def isDeprecatedIdentifierName(name: Name) = name.toTermName match {
 
362
      case nme.`then` | nme.`macro` => true
 
363
      case _                        => false
 
364
    }
 
365
 
 
366
    def isOpAssignmentName(name: Name) = name match {
 
367
      case raw.NE | raw.LE | raw.GE | EMPTY => false
 
368
      case _                                =>
 
369
      name.endChar == '=' && name.startChar != '=' && isOperatorPart(name.startChar)
 
370
    }
 
371
 
 
372
    /** The expanded name of `name` relative to this class `base` with given `separator`
 
373
     */
 
374
    def expandedName(name: TermName, base: Symbol, separator: String = EXPAND_SEPARATOR_STRING): TermName =
 
375
      newTermNameCached(base.fullName('$') + separator + name)
 
376
 
 
377
    /** The expanded setter name of `name` relative to this class `base`
 
378
    */
 
379
    def expandedSetterName(name: TermName, base: Symbol): TermName =
 
380
      expandedName(name, base, separator = TRAIT_SETTER_SEPARATOR_STRING)
 
381
 
 
382
    /** If `name` is an expandedName name, the original name.
 
383
    *  Otherwise `name` itself.
 
384
    */
 
385
    def originalName(name: Name): Name = name.toString lastIndexOf "$$" match {
 
386
      case -1 | 0 => name
 
387
      case idx0 =>
 
388
        // Sketchville - We've found $$ but if it's part of $$$ or $$$$
 
389
        // or something we need to keep the bonus dollars, so e.g. foo$$$outer
 
390
        // has an original name of $outer.
 
391
        var idx = idx0
 
392
        while (idx > 0 && name.charAt(idx - 1) == '$')
 
393
          idx -= 1
 
394
        name drop idx + 2
 
395
    }
 
396
 
 
397
    def unspecializedName(name: Name): Name = (
 
398
      if (name endsWith SPECIALIZED_SUFFIX)
 
399
      name.subName(0, name.lastIndexOf('m') - 1)
 
400
      else name
 
401
    )
 
402
 
 
403
    /*
 
404
    def anonNumberSuffix(name: Name): Name = {
 
405
      ("" + name) lastIndexOf '$' match {
 
406
        case -1   => nme.EMPTY
 
407
        case idx  =>
 
408
          val s = name drop idx
 
409
          if (s.toString forall (_.isDigit)) s
 
410
          else nme.EMPTY
 
411
      }
 
412
    }
 
413
    */
 
414
 
 
415
    /** Return the original name and the types on which this name
 
416
    *  is specialized. For example,
 
417
    *  {{{
 
418
    *     splitSpecializedName("foo$mIcD$sp") == ('foo', "I", "D")
 
419
    *  }}}
 
420
    *  `foo$mIcD$sp` is the name of a method specialized on two type
 
421
    *  parameters, the first one belonging to the method itself, on Int,
 
422
    *  and another one belonging to the enclosing class, on Double.
 
423
    */
 
424
    def splitSpecializedName(name: Name): (Name, String, String) =
 
425
    if (name endsWith SPECIALIZED_SUFFIX) {
 
426
      val name1 = name dropRight SPECIALIZED_SUFFIX.length
 
427
      val idxC  = name1 lastIndexOf 'c'
 
428
      val idxM  = name1 lastIndexOf 'm'
 
429
 
 
430
      (name1.subName(0, idxM - 1),
 
431
      name1.subName(idxC + 1, name1.length).toString,
 
432
      name1.subName(idxM + 1, idxC).toString)
 
433
    } else
 
434
    (name, "", "")
 
435
 
 
436
    def getterName(name: TermName): TermName     = if (isLocalName(name)) localToGetter(name) else name
 
437
    def getterToLocal(name: TermName): TermName  = name append LOCAL_SUFFIX_STRING
 
438
    def getterToSetter(name: TermName): TermName = name append SETTER_SUFFIX
 
439
    def localToGetter(name: TermName): TermName  = name dropRight LOCAL_SUFFIX_STRING.length
 
440
 
 
441
    def dropLocalSuffix(name: Name): Name  = if (name endsWith ' ') name dropRight 1 else name
 
442
 
 
443
    def setterToGetter(name: TermName): TermName = {
 
444
      val p = name.pos(TRAIT_SETTER_SEPARATOR_STRING)
 
445
      if (p < name.length)
 
446
      setterToGetter(name drop (p + TRAIT_SETTER_SEPARATOR_STRING.length))
 
447
      else
 
448
      name.subName(0, name.length - SETTER_SUFFIX.length)
 
449
    }
 
450
 
 
451
    // Nominally, name$default$N, encoded for <init>
 
452
    def defaultGetterName(name: Name, pos: Int): TermName = {
 
453
      val prefix = if (isConstructorName(name)) DEFAULT_GETTER_INIT_STRING else name
 
454
      newTermName(prefix + DEFAULT_GETTER_STRING + pos)
 
455
    }
 
456
    // Nominally, name from name$default$N, CONSTRUCTOR for <init>
 
457
    def defaultGetterToMethod(name: Name): TermName = {
 
458
      val p = name.pos(DEFAULT_GETTER_STRING)
 
459
      if (p < name.length) {
 
460
        val q = name.toTermName.subName(0, p)
 
461
        // i.e., if (q.decoded == CONSTRUCTOR.toString) CONSTRUCTOR else q
 
462
        if (q.toString == DEFAULT_GETTER_INIT_STRING) CONSTRUCTOR else q
 
463
      } else name.toTermName
 
464
    }
 
465
 
 
466
    // If the name ends with $nn where nn are
 
467
    // all digits, strip the $ and the digits.
 
468
    // Otherwise return the argument.
 
469
    def stripAnonNumberSuffix(name: Name): Name = {
 
470
      var pos = name.length
 
471
      while (pos > 0 && name.charAt(pos - 1).isDigit)
 
472
      pos -= 1
 
473
 
 
474
      if (pos <= 0 || pos == name.length || name.charAt(pos - 1) != '$') name
 
475
      else name.subName(0, pos - 1)
 
476
    }
 
477
 
 
478
    def stripModuleSuffix(name: Name): Name = (
 
479
      if (isModuleName(name)) name dropRight MODULE_SUFFIX_STRING.length else name
 
480
    )
 
481
    def localDummyName(clazz: Symbol): TermName = newTermName(LOCALDUMMY_PREFIX + clazz.name + ">")
 
482
    def superName(name: Name): TermName         = newTermName(SUPER_PREFIX_STRING + name)
 
483
 
 
484
    /** The name of an accessor for protected symbols. */
 
485
    def protName(name: Name): TermName = newTermName(PROTECTED_PREFIX + name)
 
486
 
 
487
    /** The name of a setter for protected symbols. Used for inherited Java fields. */
 
488
    def protSetterName(name: Name): TermName = newTermName(PROTECTED_SET_PREFIX + name)
 
489
 
 
490
    final val Nil: NameType                 = "Nil"
 
491
    final val Predef: NameType              = "Predef"
 
492
    final val ScalaRunTime: NameType        = "ScalaRunTime"
 
493
    final val Some: NameType                = "Some"
 
494
 
 
495
    val _1 : NameType  = "_1"
 
496
    val _2 : NameType  = "_2"
 
497
    val _3 : NameType  = "_3"
 
498
    val _4 : NameType  = "_4"
 
499
    val _5 : NameType  = "_5"
 
500
    val _6 : NameType  = "_6"
 
501
    val _7 : NameType  = "_7"
 
502
    val _8 : NameType  = "_8"
 
503
    val _9 : NameType  = "_9"
 
504
    val _10 : NameType = "_10"
 
505
    val _11 : NameType = "_11"
 
506
    val _12 : NameType = "_12"
 
507
    val _13 : NameType = "_13"
 
508
    val _14 : NameType = "_14"
 
509
    val _15 : NameType = "_15"
 
510
    val _16 : NameType = "_16"
 
511
    val _17 : NameType = "_17"
 
512
    val _18 : NameType = "_18"
 
513
    val _19 : NameType = "_19"
 
514
    val _20 : NameType = "_20"
 
515
    val _21 : NameType = "_21"
 
516
    val _22 : NameType = "_22"
 
517
 
 
518
    val x_0 : NameType  = "x$0"
 
519
    val x_1 : NameType  = "x$1"
 
520
    val x_2 : NameType  = "x$2"
 
521
    val x_3 : NameType  = "x$3"
 
522
    val x_4 : NameType  = "x$4"
 
523
    val x_5 : NameType  = "x$5"
 
524
    val x_6 : NameType  = "x$6"
 
525
    val x_7 : NameType  = "x$7"
 
526
    val x_8 : NameType  = "x$8"
 
527
    val x_9 : NameType  = "x$9"
 
528
 
 
529
    @switch def syntheticParamName(i: Int): TermName = i match {
 
530
      case 0  => nme.x_0
 
531
      case 1  => nme.x_1
 
532
      case 2  => nme.x_2
 
533
      case 3  => nme.x_3
 
534
      case 4  => nme.x_4
 
535
      case 5  => nme.x_5
 
536
      case 6  => nme.x_6
 
537
      case 7  => nme.x_7
 
538
      case 8  => nme.x_8
 
539
      case 9  => nme.x_9
 
540
      case _  => newTermName("x$" + i)
 
541
    }
 
542
 
 
543
    @switch def productAccessorName(j: Int): TermName = j match {
 
544
      case 1  => nme._1
 
545
      case 2  => nme._2
 
546
      case 3  => nme._3
 
547
      case 4  => nme._4
 
548
      case 5  => nme._5
 
549
      case 6  => nme._6
 
550
      case 7  => nme._7
 
551
      case 8  => nme._8
 
552
      case 9  => nme._9
 
553
      case 10 => nme._10
 
554
      case 11 => nme._11
 
555
      case 12 => nme._12
 
556
      case 13 => nme._13
 
557
      case 14 => nme._14
 
558
      case 15 => nme._15
 
559
      case 16 => nme._16
 
560
      case 17 => nme._17
 
561
      case 18 => nme._18
 
562
      case 19 => nme._19
 
563
      case 20 => nme._20
 
564
      case 21 => nme._21
 
565
      case 22 => nme._22
 
566
      case _  => newTermName("_" + j)
 
567
    }
 
568
 
 
569
    val ??? = encode("???")
 
570
 
 
571
    val wrapRefArray: NameType     = "wrapRefArray"
 
572
    val wrapByteArray: NameType    = "wrapByteArray"
 
573
    val wrapShortArray: NameType   = "wrapShortArray"
 
574
    val wrapCharArray: NameType    = "wrapCharArray"
 
575
    val wrapIntArray: NameType     = "wrapIntArray"
 
576
    val wrapLongArray: NameType    = "wrapLongArray"
 
577
    val wrapFloatArray: NameType   = "wrapFloatArray"
 
578
    val wrapDoubleArray: NameType  = "wrapDoubleArray"
 
579
    val wrapBooleanArray: NameType = "wrapBooleanArray"
 
580
    val wrapUnitArray: NameType    = "wrapUnitArray"
 
581
    val genericWrapArray: NameType = "genericWrapArray"
 
582
 
 
583
    // Compiler utilized names
 
584
 
 
585
    val AnnotatedType: NameType        = "AnnotatedType"
 
586
    val Annotation: NameType           = "Annotation"
 
587
    val Any: NameType                  = "Any"
 
588
    val AnyVal: NameType               = "AnyVal"
 
589
    val AppliedTypeTree: NameType      = "AppliedTypeTree"
 
590
    val Apply: NameType                = "Apply"
 
591
    val ArrayAnnotArg: NameType        = "ArrayAnnotArg"
 
592
    val Constant: NameType             = "Constant"
 
593
    val ConstantType: NameType         = "ConstantType"
 
594
    val EmptyPackage: NameType         = "EmptyPackage"
 
595
    val EmptyPackageClass: NameType    = "EmptyPackageClass"
 
596
    val ExistentialTypeTree: NameType  = "ExistentialTypeTree"
 
597
    val Flag : NameType                = "Flag"
 
598
    val Ident: NameType                = "Ident"
 
599
    val Import: NameType               = "Import"
 
600
    val Literal: NameType              = "Literal"
 
601
    val LiteralAnnotArg: NameType      = "LiteralAnnotArg"
 
602
    val Modifiers: NameType            = "Modifiers"
 
603
    val NestedAnnotArg: NameType       = "NestedAnnotArg"
 
604
    val NoFlags: NameType              = "NoFlags"
 
605
    val NoPrefix: NameType             = "NoPrefix"
 
606
    val NoSymbol: NameType             = "NoSymbol"
 
607
    val Nothing: NameType              = "Nothing"
 
608
    val NoType: NameType               = "NoType"
 
609
    val Null: NameType                 = "Null"
 
610
    val Object: NameType               = "Object"
 
611
    val RootPackage: NameType          = "RootPackage"
 
612
    val RootClass: NameType            = "RootClass"
 
613
    val Select: NameType               = "Select"
 
614
    val SelectFromTypeTree: NameType   = "SelectFromTypeTree"
 
615
    val StringContext: NameType        = "StringContext"
 
616
    val This: NameType                 = "This"
 
617
    val ThisType: NameType             = "ThisType"
 
618
    val Tree : NameType                = "Tree"
 
619
    val Tuple2: NameType               = "Tuple2"
 
620
    val TYPE_ : NameType               = "TYPE"
 
621
    val TypeApply: NameType            = "TypeApply"
 
622
    val TypeRef: NameType              = "TypeRef"
 
623
    val TypeTree: NameType             = "TypeTree"
 
624
    val UNIT : NameType                = "UNIT"
 
625
    val add_ : NameType                = "add"
 
626
    val annotation: NameType           = "annotation"
 
627
    val anyValClass: NameType          = "anyValClass"
 
628
    val append: NameType               = "append"
 
629
    val apply: NameType                = "apply"
 
630
    val applyDynamic: NameType         = "applyDynamic"
 
631
    val applyDynamicNamed: NameType    = "applyDynamicNamed"
 
632
    val applyOrElse: NameType          = "applyOrElse"
 
633
    val args : NameType                = "args"
 
634
    val argv : NameType                = "argv"
 
635
    val arrayClass: NameType           = "arrayClass"
 
636
    val arrayElementClass: NameType    = "arrayElementClass"
 
637
    val arrayValue: NameType           = "arrayValue"
 
638
    val array_apply : NameType         = "array_apply"
 
639
    val array_clone : NameType         = "array_clone"
 
640
    val array_length : NameType        = "array_length"
 
641
    val array_update : NameType        = "array_update"
 
642
    val arraycopy: NameType            = "arraycopy"
 
643
    val asTerm: NameType               = "asTerm"
 
644
    val asModule: NameType             = "asModule"
 
645
    val asMethod: NameType             = "asMethod"
 
646
    val asType: NameType               = "asType"
 
647
    val asClass: NameType              = "asClass"
 
648
    val asInstanceOf_ : NameType       = "asInstanceOf"
 
649
    val asInstanceOf_Ob : NameType     = "$asInstanceOf"
 
650
    val assert_ : NameType             = "assert"
 
651
    val assume_ : NameType             = "assume"
 
652
    val box: NameType                  = "box"
 
653
    val build : NameType               = "build"
 
654
    val bytes: NameType                = "bytes"
 
655
    val canEqual_ : NameType           = "canEqual"
 
656
    val checkInitialized: NameType     = "checkInitialized"
 
657
    val ClassManifestFactory: NameType = "ClassManifestFactory"
 
658
    val classOf: NameType              = "classOf"
 
659
    val clone_ : NameType              = if (forMSIL) "MemberwiseClone" else "clone" // sn.OClone causes checkinit failure
 
660
    val conforms: NameType             = "conforms"
 
661
    val copy: NameType                 = "copy"
 
662
    val currentMirror: NameType        = "currentMirror"
 
663
    val definitions: NameType          = "definitions"
 
664
    val delayedInit: NameType          = "delayedInit"
 
665
    val delayedInitArg: NameType       = "delayedInit$body"
 
666
    val drop: NameType                 = "drop"
 
667
    val elem: NameType                 = "elem"
 
668
    val emptyValDef: NameType          = "emptyValDef"
 
669
    val ensureAccessible : NameType    = "ensureAccessible"
 
670
    val eq: NameType                   = "eq"
 
671
    val equalsNumChar : NameType       = "equalsNumChar"
 
672
    val equalsNumNum : NameType        = "equalsNumNum"
 
673
    val equalsNumObject : NameType     = "equalsNumObject"
 
674
    val equals_ : NameType             = if (forMSIL) "Equals" else "equals"
 
675
    val error: NameType                = "error"
 
676
    val eval: NameType                 = "eval"
 
677
    val ex: NameType                   = "ex"
 
678
    val experimental: NameType         = "experimental"
 
679
    val f: NameType                    = "f"
 
680
    val false_ : NameType              = "false"
 
681
    val filter: NameType               = "filter"
 
682
    val finalize_ : NameType           = if (forMSIL) "Finalize" else "finalize"
 
683
    val find_ : NameType               = "find"
 
684
    val flagsFromBits : NameType       = "flagsFromBits"
 
685
    val flatMap: NameType              = "flatMap"
 
686
    val foreach: NameType              = "foreach"
 
687
    val genericArrayOps: NameType      = "genericArrayOps"
 
688
    val get: NameType                  = "get"
 
689
    val getOrElse: NameType            = "getOrElse"
 
690
    val hasNext: NameType              = "hasNext"
 
691
    val hashCode_ : NameType           = if (forMSIL) "GetHashCode" else "hashCode"
 
692
    val hash_ : NameType               = "hash"
 
693
    val head: NameType                 = "head"
 
694
    val identity: NameType             = "identity"
 
695
    val implicitly: NameType           = "implicitly"
 
696
    val in: NameType                   = "in"
 
697
    val info: NameType                 = "info"
 
698
    val inlinedEquals: NameType        = "inlinedEquals"
 
699
    val isArray: NameType              = "isArray"
 
700
    val isDefinedAt: NameType          = "isDefinedAt"
 
701
    val isEmpty: NameType              = "isEmpty"
 
702
    val isInstanceOf_ : NameType       = "isInstanceOf"
 
703
    val isInstanceOf_Ob : NameType     = "$isInstanceOf"
 
704
    val java: NameType                 = "java"
 
705
    val key: NameType                  = "key"
 
706
    val lang: NameType                 = "lang"
 
707
    val length: NameType               = "length"
 
708
    val lengthCompare: NameType        = "lengthCompare"
 
709
    val liftedTree: NameType           = "liftedTree"
 
710
    val `macro` : NameType             = "macro"
 
711
    val macroThis : NameType           = "_this"
 
712
    val macroContext : NameType        = "c"
 
713
    val main: NameType                 = "main"
 
714
    val manifest: NameType             = "manifest"
 
715
    val ManifestFactory: NameType      = "ManifestFactory"
 
716
    val manifestToTypeTag: NameType    = "manifestToTypeTag"
 
717
    val map: NameType                  = "map"
 
718
    val materializeClassTag: NameType  = "materializeClassTag"
 
719
    val materializeWeakTypeTag: NameType = "materializeWeakTypeTag"
 
720
    val materializeTypeTag: NameType   = "materializeTypeTag"
 
721
    val mirror : NameType              = "mirror"
 
722
    val moduleClass : NameType         = "moduleClass"
 
723
    val name: NameType                 = "name"
 
724
    val ne: NameType                   = "ne"
 
725
    val newArray: NameType             = "newArray"
 
726
    val newFreeTerm: NameType          = "newFreeTerm"
 
727
    val newFreeType: NameType          = "newFreeType"
 
728
    val newNestedSymbol: NameType      = "newNestedSymbol"
 
729
    val newScopeWith: NameType         = "newScopeWith"
 
730
    val next: NameType                 = "next"
 
731
    val nmeNewTermName: NameType       = "newTermName"
 
732
    val nmeNewTypeName: NameType       = "newTypeName"
 
733
    val normalize: NameType            = "normalize"
 
734
    val notifyAll_ : NameType          = "notifyAll"
 
735
    val notify_ : NameType             = "notify"
 
736
    val null_ : NameType               = "null"
 
737
    val ofDim: NameType                = "ofDim"
 
738
    val origin: NameType               = "origin"
 
739
    val prefix : NameType              = "prefix"
 
740
    val productArity: NameType         = "productArity"
 
741
    val productElement: NameType       = "productElement"
 
742
    val productIterator: NameType      = "productIterator"
 
743
    val productPrefix: NameType        = "productPrefix"
 
744
    val readResolve: NameType          = "readResolve"
 
745
    val reflect : NameType             = "reflect"
 
746
    val reify : NameType               = "reify"
 
747
    val rootMirror : NameType          = "rootMirror"
 
748
    val runOrElse: NameType            = "runOrElse"
 
749
    val runtime: NameType              = "runtime"
 
750
    val runtimeClass: NameType         = "runtimeClass"
 
751
    val runtimeMirror: NameType        = "runtimeMirror"
 
752
    val sameElements: NameType         = "sameElements"
 
753
    val scala_ : NameType              = "scala"
 
754
    val selectDynamic: NameType        = "selectDynamic"
 
755
    val selectOverloadedMethod: NameType = "selectOverloadedMethod"
 
756
    val selectTerm: NameType           = "selectTerm"
 
757
    val selectType: NameType           = "selectType"
 
758
    val self: NameType                 = "self"
 
759
    val setAccessible: NameType        = "setAccessible"
 
760
    val setAnnotations: NameType       = "setAnnotations"
 
761
    val setSymbol: NameType            = "setSymbol"
 
762
    val setType: NameType              = "setType"
 
763
    val setTypeSignature: NameType     = "setTypeSignature"
 
764
    val splice: NameType               = "splice"
 
765
    val staticClass : NameType         = "staticClass"
 
766
    val staticModule : NameType        = "staticModule"
 
767
    val staticPackage : NameType       = "staticPackage"
 
768
    val synchronized_ : NameType       = "synchronized"
 
769
    val tail: NameType                 = "tail"
 
770
    val `then` : NameType              = "then"
 
771
    val this_ : NameType               = "this"
 
772
    val thisPrefix : NameType          = "thisPrefix"
 
773
    val throw_ : NameType              = "throw"
 
774
    val toArray: NameType              = "toArray"
 
775
    val toList: NameType               = "toList"
 
776
    val toObjectArray : NameType       = "toObjectArray"
 
777
    val toSeq: NameType                = "toSeq"
 
778
    val toString_ : NameType           = if (forMSIL) "ToString" else "toString"
 
779
    val toTypeConstructor: NameType    = "toTypeConstructor"
 
780
    val tpe : NameType                 = "tpe"
 
781
    val tree : NameType                = "tree"
 
782
    val true_ : NameType               = "true"
 
783
    val typedProductIterator: NameType = "typedProductIterator"
 
784
    val typeTagToManifest: NameType    = "typeTagToManifest"
 
785
    val unapply: NameType              = "unapply"
 
786
    val unapplySeq: NameType           = "unapplySeq"
 
787
    val unbox: NameType                = "unbox"
 
788
    val universe: NameType             = "universe"
 
789
    val update: NameType               = "update"
 
790
    val updateDynamic: NameType        = "updateDynamic"
 
791
    val value: NameType                = "value"
 
792
    val valueOf : NameType             = "valueOf"
 
793
    val values : NameType              = "values"
 
794
    val view_ : NameType               = "view"
 
795
    val wait_ : NameType               = "wait"
 
796
    val withFilter: NameType           = "withFilter"
 
797
    val wrap: NameType                 = "wrap"
 
798
    val zip: NameType                  = "zip"
 
799
 
 
800
    val synthSwitch: NameType          = "$synthSwitch"
 
801
 
 
802
    // unencoded operators
 
803
    object raw {
 
804
      final val AMP  : NameType  = "&"
 
805
      final val BANG : NameType  = "!"
 
806
      final val BAR  : NameType  = "|"
 
807
      final val DOLLAR: NameType = "$"
 
808
      final val GE: NameType     = ">="
 
809
      final val LE: NameType     = "<="
 
810
      final val MINUS: NameType  = "-"
 
811
      final val NE: NameType     = "!="
 
812
      final val PLUS : NameType  = "+"
 
813
      final val SLASH: NameType  = "/"
 
814
      final val STAR : NameType  = "*"
 
815
      final val TILDE: NameType  = "~"
 
816
 
 
817
      final val isUnary: Set[Name] = Set(MINUS, PLUS, TILDE, BANG)
 
818
    }
 
819
 
 
820
    // value-conversion methods
 
821
    val toByte: NameType   = "toByte"
 
822
    val toShort: NameType  = "toShort"
 
823
    val toChar: NameType   = "toChar"
 
824
    val toInt: NameType    = "toInt"
 
825
    val toLong: NameType   = "toLong"
 
826
    val toFloat: NameType  = "toFloat"
 
827
    val toDouble: NameType = "toDouble"
 
828
 
 
829
    // primitive operation methods for structual types mostly
 
830
    // overlap with the above, but not for these two.
 
831
    val toCharacter: NameType = "toCharacter"
 
832
    val toInteger: NameType   = "toInteger"
 
833
 
 
834
    def newLazyValSlowComputeName(lzyValName: Name) = lzyValName append LAZY_SLOW_SUFFIX
 
835
 
 
836
    // ASCII names for operators
 
837
    val ADD      = encode("+")
 
838
    val AND      = encode("&")
 
839
    val ASR      = encode(">>")
 
840
    val DIV      = encode("/")
 
841
    val EQ       = encode("==")
 
842
    val EQL      = encode("=")
 
843
    val GE       = encode(">=")
 
844
    val GT       = encode(">")
 
845
    val HASHHASH = encode("##")
 
846
    val LE       = encode("<=")
 
847
    val LSL      = encode("<<")
 
848
    val LSR      = encode(">>>")
 
849
    val LT       = encode("<")
 
850
    val MINUS    = encode("-")
 
851
    val MOD      = encode("%")
 
852
    val MUL      = encode("*")
 
853
    val NE       = encode("!=")
 
854
    val OR       = encode("|")
 
855
    val PLUS     = ADD    // technically redundant, but ADD looks funny with MINUS
 
856
    val SUB      = MINUS  // ... as does SUB with PLUS
 
857
    val XOR      = encode("^")
 
858
    val ZAND     = encode("&&")
 
859
    val ZOR      = encode("||")
 
860
 
 
861
    // unary operators
 
862
    val UNARY_~ = encode("unary_~")
 
863
    val UNARY_+ = encode("unary_+")
 
864
    val UNARY_- = encode("unary_-")
 
865
    val UNARY_! = encode("unary_!")
 
866
 
 
867
    // Grouped here so Cleanup knows what tests to perform.
 
868
    val CommonOpNames   = Set[Name](OR, XOR, AND, EQ, NE)
 
869
    val ConversionNames = Set[Name](toByte, toChar, toDouble, toFloat, toInt, toLong, toShort)
 
870
    val BooleanOpNames  = Set[Name](ZOR, ZAND, UNARY_!) ++ CommonOpNames
 
871
    val NumberOpNames   = (
 
872
         Set[Name](ADD, SUB, MUL, DIV, MOD, LSL, LSR, ASR, LT, LE, GE, GT)
 
873
      ++ Set(UNARY_+, UNARY_-, UNARY_!)
 
874
      ++ ConversionNames
 
875
      ++ CommonOpNames
 
876
    )
 
877
 
 
878
    val add: NameType                    = "add"
 
879
    val complement: NameType             = "complement"
 
880
    val divide: NameType                 = "divide"
 
881
    val multiply: NameType               = "multiply"
 
882
    val negate: NameType                 = "negate"
 
883
    val positive: NameType               = "positive"
 
884
    val shiftLogicalRight: NameType      = "shiftLogicalRight"
 
885
    val shiftSignedLeft: NameType        = "shiftSignedLeft"
 
886
    val shiftSignedRight: NameType       = "shiftSignedRight"
 
887
    val subtract: NameType               = "subtract"
 
888
    val takeAnd: NameType                = "takeAnd"
 
889
    val takeConditionalAnd: NameType     = "takeConditionalAnd"
 
890
    val takeConditionalOr: NameType      = "takeConditionalOr"
 
891
    val takeModulo: NameType             = "takeModulo"
 
892
    val takeNot: NameType                = "takeNot"
 
893
    val takeOr: NameType                 = "takeOr"
 
894
    val takeXor: NameType                = "takeXor"
 
895
    val testEqual: NameType              = "testEqual"
 
896
    val testGreaterOrEqualThan: NameType = "testGreaterOrEqualThan"
 
897
    val testGreaterThan: NameType        = "testGreaterThan"
 
898
    val testLessOrEqualThan: NameType    = "testLessOrEqualThan"
 
899
    val testLessThan: NameType           = "testLessThan"
 
900
    val testNotEqual: NameType           = "testNotEqual"
 
901
 
 
902
    def toUnaryName(name: TermName): TermName = name match {
 
903
      case raw.MINUS => UNARY_-
 
904
      case raw.PLUS  => UNARY_+
 
905
      case raw.TILDE => UNARY_~
 
906
      case raw.BANG  => UNARY_!
 
907
      case _         => name
 
908
    }
 
909
    /** The name of a method which stands in for a primitive operation
 
910
     *  during structural type dispatch.
 
911
     */
 
912
    def primitiveInfixMethodName(name: Name): TermName = name match {
 
913
      case OR   => takeOr
 
914
      case XOR  => takeXor
 
915
      case AND  => takeAnd
 
916
      case EQ   => testEqual
 
917
      case NE   => testNotEqual
 
918
      case ADD  => add
 
919
      case SUB  => subtract
 
920
      case MUL  => multiply
 
921
      case DIV  => divide
 
922
      case MOD  => takeModulo
 
923
      case LSL  => shiftSignedLeft
 
924
      case LSR  => shiftLogicalRight
 
925
      case ASR  => shiftSignedRight
 
926
      case LT   => testLessThan
 
927
      case LE   => testLessOrEqualThan
 
928
      case GE   => testGreaterOrEqualThan
 
929
      case GT   => testGreaterThan
 
930
      case ZOR  => takeConditionalOr
 
931
      case ZAND => takeConditionalAnd
 
932
      case _    => NO_NAME
 
933
    }
 
934
    /** Postfix/prefix, really.
 
935
     */
 
936
    def primitivePostfixMethodName(name: Name): TermName = name match {
 
937
      case UNARY_!    => takeNot
 
938
      case UNARY_+    => positive
 
939
      case UNARY_-    => negate
 
940
      case UNARY_~    => complement
 
941
      case `toByte`   => toByte
 
942
      case `toShort`  => toShort
 
943
      case `toChar`   => toCharacter
 
944
      case `toInt`    => toInteger
 
945
      case `toLong`   => toLong
 
946
      case `toFloat`  => toFloat
 
947
      case `toDouble` => toDouble
 
948
      case _          => NO_NAME
 
949
    }
 
950
 
 
951
    def primitiveMethodName(name: Name): TermName =
 
952
      primitiveInfixMethodName(name) match {
 
953
        case NO_NAME => primitivePostfixMethodName(name)
 
954
        case name => name
 
955
      }
 
956
 
 
957
    /** Translate a String into a list of simple TypeNames and TermNames.
 
958
     *  In all segments before the last, type/term is determined by whether
 
959
     *  the following separator char is '.' or '#'.  In the last segment,
 
960
     *  the argument "assumeTerm" determines it.  Examples:
 
961
     *
 
962
     *  package foo {
 
963
     *    object Lorax { object Wog ; class Wog }
 
964
     *    class Lorax  { object Zax ; class Zax }
 
965
     *  }
 
966
     *
 
967
     *  f("foo.Lorax", true)   == List("foo": Term, "Lorax": Term) // object Lorax
 
968
     *  f("foo.Lorax", false)  == List("foo": Term, "Lorax": Type) // class Lorax
 
969
     *  f("Lorax.Wog", true)   == List("Lorax": Term, "Wog": Term) // object Wog
 
970
     *  f("Lorax.Wog", false)  == List("Lorax": Term, "Wog": Type) // class Wog
 
971
     *  f("Lorax#Zax", true)   == List("Lorax": Type, "Zax": Term) // object Zax
 
972
     *  f("Lorax#Zax", false)  == List("Lorax": Type, "Zax": Type) // class Zax
 
973
     *
 
974
     *  Note that in actual scala syntax you cannot refer to object Zax without an
 
975
     *  instance of Lorax, so Lorax#Zax could only mean the type.  One might think
 
976
     *  that Lorax#Zax.type would work, but this is not accepted by the parser.
 
977
     *  For the purposes of referencing that object, the syntax is allowed.
 
978
     */
 
979
    def segments(name: String, assumeTerm: Boolean): List[Name] = {
 
980
      def mkName(str: String, term: Boolean): Name =
 
981
        if (term) newTermName(str) else newTypeName(str)
 
982
 
 
983
      name.indexWhere(ch => ch == '.' || ch == '#') match {
 
984
        // it's the last segment: the parameter tells us whether type or term
 
985
        case -1     => if (name == "") scala.Nil else scala.List(mkName(name, assumeTerm))
 
986
        // otherwise, we can tell based on whether '#' or '.' is the following char.
 
987
        case idx    =>
 
988
          val (simple, div, rest) = (name take idx, name charAt idx, name drop idx + 1)
 
989
          mkName(simple, div == '.') :: segments(rest, assumeTerm)
 
990
      }
 
991
    }
 
992
 
 
993
    def newBitmapName(bitmapPrefix: Name, n: Int) = bitmapPrefix append ("" + n)
 
994
 
 
995
    val BITMAP_NORMAL: NameType              = BITMAP_PREFIX + ""           // initialization bitmap for public/protected lazy vals
 
996
    val BITMAP_TRANSIENT: NameType           = BITMAP_PREFIX + "trans$"     // initialization bitmap for transient lazy vals
 
997
    val BITMAP_CHECKINIT: NameType           = BITMAP_PREFIX + "init$"      // initialization bitmap for checkinit values
 
998
    val BITMAP_CHECKINIT_TRANSIENT: NameType = BITMAP_PREFIX + "inittrans$" // initialization bitmap for transient checkinit values
 
999
  }
 
1000
 
 
1001
  object tpnme extends TypeNames { }
 
1002
 
 
1003
  /** For fully qualified type names.
 
1004
   */
 
1005
  object fulltpnme extends TypeNames {
 
1006
    val RuntimeNothing: NameType = "scala.runtime.Nothing$"
 
1007
    val RuntimeNull: NameType    = "scala.runtime.Null$"
 
1008
    val JavaLangEnum: NameType   = "java.lang.Enum"
 
1009
  }
 
1010
 
 
1011
  /** Java binary names, like scala/runtime/Nothing$.
 
1012
   */
 
1013
  object binarynme {
 
1014
    def toBinary(name: Name) = name mapName (_.replace('.', '/'))
 
1015
 
 
1016
    val RuntimeNothing = toBinary(fulltpnme.RuntimeNothing).toTypeName
 
1017
    val RuntimeNull    = toBinary(fulltpnme.RuntimeNull).toTypeName
 
1018
  }
 
1019
 
 
1020
  val javanme = nme.javaKeywords
 
1021
 
 
1022
  object nme extends TermNames {
 
1023
 
 
1024
    def isModuleVarName(name: Name): Boolean =
 
1025
      stripAnonNumberSuffix(name) endsWith MODULE_VAR_SUFFIX
 
1026
 
 
1027
    def moduleVarName(name: TermName): TermName =
 
1028
      newTermNameCached("" + name + MODULE_VAR_SUFFIX)
 
1029
 
 
1030
    def getCause         = sn.GetCause
 
1031
    def getClass_        = sn.GetClass
 
1032
    def getComponentType = sn.GetComponentType
 
1033
    def getMethod_       = sn.GetMethod
 
1034
    def invoke_          = sn.Invoke
 
1035
 
 
1036
    val isBoxedNumberOrBoolean: NameType = "isBoxedNumberOrBoolean"
 
1037
    val isBoxedNumber: NameType = "isBoxedNumber"
 
1038
 
 
1039
    val reflPolyCacheName: NameType   = "reflPoly$Cache"
 
1040
    val reflClassCacheName: NameType  = "reflClass$Cache"
 
1041
    val reflParamsCacheName: NameType = "reflParams$Cache"
 
1042
    val reflMethodCacheName: NameType = "reflMethod$Cache"
 
1043
    val reflMethodName: NameType      = "reflMethod$Method"
 
1044
 
 
1045
    private val reflectionCacheNames = Set[NameType](
 
1046
      reflPolyCacheName,
 
1047
      reflClassCacheName,
 
1048
      reflParamsCacheName,
 
1049
      reflMethodCacheName,
 
1050
      reflMethodName
 
1051
    )
 
1052
    def isReflectionCacheName(name: Name) = reflectionCacheNames exists (name startsWith _)
 
1053
 
 
1054
    @deprecated("Use a method in tpnme", "2.10.0") def dropSingletonName(name: Name): TypeName = tpnme.dropSingletonName(name)
 
1055
    @deprecated("Use a method in tpnme", "2.10.0") def singletonName(name: Name): TypeName     = tpnme.singletonName(name)
 
1056
    @deprecated("Use a method in tpnme", "2.10.0") def implClassName(name: Name): TypeName     = tpnme.implClassName(name)
 
1057
    @deprecated("Use a method in tpnme", "2.10.0") def interfaceName(implname: Name): TypeName = tpnme.interfaceName(implname)
 
1058
  }
 
1059
 
 
1060
  abstract class SymbolNames {
 
1061
    protected val stringToTermName = null
 
1062
    protected val stringToTypeName = null
 
1063
    protected implicit def createNameType(s: String): TypeName = newTypeNameCached(s)
 
1064
 
 
1065
    val BeanProperty        : TypeName
 
1066
    val BooleanBeanProperty : TypeName
 
1067
    val BoxedBoolean        : TypeName
 
1068
    val BoxedCharacter      : TypeName
 
1069
    val BoxedNumber         : TypeName
 
1070
    val Class               : TypeName
 
1071
    val Delegate            : TypeName
 
1072
    val IOOBException       : TypeName // IndexOutOfBoundsException
 
1073
    val InvTargetException  : TypeName // InvocationTargetException
 
1074
    val JavaSerializable    : TypeName
 
1075
    val MethodAsObject      : TypeName
 
1076
    val NPException         : TypeName // NullPointerException
 
1077
    val Object              : TypeName
 
1078
    val String              : TypeName
 
1079
    val Throwable           : TypeName
 
1080
    val ValueType           : TypeName
 
1081
 
 
1082
    val ForName             : TermName
 
1083
    val GetCause            : TermName
 
1084
    val GetClass            : TermName
 
1085
    val GetClassLoader      : TermName
 
1086
    val GetComponentType    : TermName
 
1087
    val GetMethod           : TermName
 
1088
    val Invoke              : TermName
 
1089
    val JavaLang            : TermName
 
1090
 
 
1091
    val Boxed: immutable.Map[TypeName, TypeName]
 
1092
  }
 
1093
 
 
1094
  class JavaKeywords {
 
1095
    private val kw = new KeywordSetBuilder
 
1096
 
 
1097
    final val ABSTRACTkw: TermName     = kw("abstract")
 
1098
    final val ASSERTkw: TermName       = kw("assert")
 
1099
    final val BOOLEANkw: TermName      = kw("boolean")
 
1100
    final val BREAKkw: TermName        = kw("break")
 
1101
    final val BYTEkw: TermName         = kw("byte")
 
1102
    final val CASEkw: TermName         = kw("case")
 
1103
    final val CATCHkw: TermName        = kw("catch")
 
1104
    final val CHARkw: TermName         = kw("char")
 
1105
    final val CLASSkw: TermName        = kw("class")
 
1106
    final val CONSTkw: TermName        = kw("const")
 
1107
    final val CONTINUEkw: TermName     = kw("continue")
 
1108
    final val DEFAULTkw: TermName      = kw("default")
 
1109
    final val DOkw: TermName           = kw("do")
 
1110
    final val DOUBLEkw: TermName       = kw("double")
 
1111
    final val ELSEkw: TermName         = kw("else")
 
1112
    final val ENUMkw: TermName         = kw("enum")
 
1113
    final val EXTENDSkw: TermName      = kw("extends")
 
1114
    final val FINALkw: TermName        = kw("final")
 
1115
    final val FINALLYkw: TermName      = kw("finally")
 
1116
    final val FLOATkw: TermName        = kw("float")
 
1117
    final val FORkw: TermName          = kw("for")
 
1118
    final val IFkw: TermName           = kw("if")
 
1119
    final val GOTOkw: TermName         = kw("goto")
 
1120
    final val IMPLEMENTSkw: TermName   = kw("implements")
 
1121
    final val IMPORTkw: TermName       = kw("import")
 
1122
    final val INSTANCEOFkw: TermName   = kw("instanceof")
 
1123
    final val INTkw: TermName          = kw("int")
 
1124
    final val INTERFACEkw: TermName    = kw("interface")
 
1125
    final val LONGkw: TermName         = kw("long")
 
1126
    final val NATIVEkw: TermName       = kw("native")
 
1127
    final val NEWkw: TermName          = kw("new")
 
1128
    final val PACKAGEkw: TermName      = kw("package")
 
1129
    final val PRIVATEkw: TermName      = kw("private")
 
1130
    final val PROTECTEDkw: TermName    = kw("protected")
 
1131
    final val PUBLICkw: TermName       = kw("public")
 
1132
    final val RETURNkw: TermName       = kw("return")
 
1133
    final val SHORTkw: TermName        = kw("short")
 
1134
    final val STATICkw: TermName       = kw("static")
 
1135
    final val STRICTFPkw: TermName     = kw("strictfp")
 
1136
    final val SUPERkw: TermName        = kw("super")
 
1137
    final val SWITCHkw: TermName       = kw("switch")
 
1138
    final val SYNCHRONIZEDkw: TermName = kw("synchronized")
 
1139
    final val THISkw: TermName         = kw("this")
 
1140
    final val THROWkw: TermName        = kw("throw")
 
1141
    final val THROWSkw: TermName       = kw("throws")
 
1142
    final val TRANSIENTkw: TermName    = kw("transient")
 
1143
    final val TRYkw: TermName          = kw("try")
 
1144
    final val VOIDkw: TermName         = kw("void")
 
1145
    final val VOLATILEkw: TermName     = kw("volatile")
 
1146
    final val WHILEkw: TermName        = kw("while")
 
1147
 
 
1148
    final val keywords = kw.result
 
1149
  }
 
1150
 
 
1151
  private abstract class JavaNames extends SymbolNames {
 
1152
    final val BoxedBoolean: TypeName       = "java.lang.Boolean"
 
1153
    final val BoxedByte: TypeName          = "java.lang.Byte"
 
1154
    final val BoxedCharacter: TypeName     = "java.lang.Character"
 
1155
    final val BoxedDouble: TypeName        = "java.lang.Double"
 
1156
    final val BoxedFloat: TypeName         = "java.lang.Float"
 
1157
    final val BoxedInteger: TypeName       = "java.lang.Integer"
 
1158
    final val BoxedLong: TypeName          = "java.lang.Long"
 
1159
    final val BoxedNumber: TypeName        = "java.lang.Number"
 
1160
    final val BoxedShort: TypeName         = "java.lang.Short"
 
1161
    final val Class: TypeName              = "java.lang.Class"
 
1162
    final val Delegate: TypeName           = tpnme.NO_NAME
 
1163
    final val IOOBException: TypeName      = "java.lang.IndexOutOfBoundsException"
 
1164
    final val InvTargetException: TypeName = "java.lang.reflect.InvocationTargetException"
 
1165
    final val MethodAsObject: TypeName     = "java.lang.reflect.Method"
 
1166
    final val NPException: TypeName        = "java.lang.NullPointerException"
 
1167
    final val Object: TypeName             = "java.lang.Object"
 
1168
    final val String: TypeName             = "java.lang.String"
 
1169
    final val Throwable: TypeName          = "java.lang.Throwable"
 
1170
    final val ValueType: TypeName          = tpnme.NO_NAME
 
1171
 
 
1172
    final val ForName: TermName          = newTermName("forName")
 
1173
    final val GetCause: TermName         = newTermName("getCause")
 
1174
    final val GetClass: TermName         = newTermName("getClass")
 
1175
    final val GetClassLoader: TermName   = newTermName("getClassLoader")
 
1176
    final val GetComponentType: TermName = newTermName("getComponentType")
 
1177
    final val GetMethod: TermName        = newTermName("getMethod")
 
1178
    final val Invoke: TermName           = newTermName("invoke")
 
1179
    final val JavaLang: TermName         = newTermName("java.lang")
 
1180
 
 
1181
    val Boxed = immutable.Map[TypeName, TypeName](
 
1182
      tpnme.Boolean -> BoxedBoolean,
 
1183
      tpnme.Byte    -> BoxedByte,
 
1184
      tpnme.Char    -> BoxedCharacter,
 
1185
      tpnme.Short   -> BoxedShort,
 
1186
      tpnme.Int     -> BoxedInteger,
 
1187
      tpnme.Long    -> BoxedLong,
 
1188
      tpnme.Float   -> BoxedFloat,
 
1189
      tpnme.Double  -> BoxedDouble
 
1190
    )
 
1191
  }
 
1192
 
 
1193
  private class MSILNames extends SymbolNames {
 
1194
    final val BeanProperty: TypeName        = tpnme.NO_NAME
 
1195
    final val BooleanBeanProperty: TypeName = tpnme.NO_NAME
 
1196
    final val BoxedBoolean: TypeName        = "System.IConvertible"
 
1197
    final val BoxedCharacter: TypeName      = "System.IConvertible"
 
1198
    final val BoxedNumber: TypeName         = "System.IConvertible"
 
1199
    final val Class: TypeName               = "System.Type"
 
1200
    final val Delegate: TypeName            = "System.MulticastDelegate"
 
1201
    final val IOOBException: TypeName       = "System.IndexOutOfRangeException"
 
1202
    final val InvTargetException: TypeName  = "System.Reflection.TargetInvocationException"
 
1203
    final val JavaSerializable: TypeName    = tpnme.NO_NAME
 
1204
    final val MethodAsObject: TypeName      = "System.Reflection.MethodInfo"
 
1205
    final val NPException: TypeName         = "System.NullReferenceException"
 
1206
    final val Object: TypeName              = "System.Object"
 
1207
    final val String: TypeName              = "System.String"
 
1208
    final val Throwable: TypeName           = "System.Exception"
 
1209
    final val ValueType: TypeName           = "System.ValueType"
 
1210
 
 
1211
    final val ForName: TermName          = newTermName("GetType")
 
1212
    final val GetCause: TermName         = newTermName("InnerException") /* System.Reflection.TargetInvocationException.InnerException */
 
1213
    final val GetClass: TermName         = newTermName("GetType")
 
1214
    final lazy val GetClassLoader: TermName   = throw new UnsupportedOperationException("Scala reflection is not supported on this platform");
 
1215
    final val GetComponentType: TermName = newTermName("GetElementType")
 
1216
    final val GetMethod: TermName        = newTermName("GetMethod")
 
1217
    final val Invoke: TermName           = newTermName("Invoke")
 
1218
    final val JavaLang: TermName         = newTermName("System")
 
1219
 
 
1220
    val Boxed = immutable.Map[TypeName, TypeName](
 
1221
      tpnme.Boolean -> "System.Boolean",
 
1222
      tpnme.Byte    -> "System.SByte", // a scala.Byte is signed and a System.SByte too (unlike a System.Byte)
 
1223
      tpnme.Char    -> "System.Char",
 
1224
      tpnme.Short   -> "System.Int16",
 
1225
      tpnme.Int     -> "System.Int32",
 
1226
      tpnme.Long    -> "System.Int64",
 
1227
      tpnme.Float   -> "System.Single",
 
1228
      tpnme.Double  -> "System.Double"
 
1229
    )
 
1230
  }
 
1231
 
 
1232
  private class J2SENames extends JavaNames {
 
1233
    final val BeanProperty: TypeName        = "scala.beans.BeanProperty"
 
1234
    final val BooleanBeanProperty: TypeName = "scala.beans.BooleanBeanProperty"
 
1235
    final val JavaSerializable: TypeName    = "java.io.Serializable"
 
1236
  }
 
1237
 
 
1238
  lazy val sn: SymbolNames =
 
1239
    if (forMSIL) new MSILNames
 
1240
    else new J2SENames
 
1241
}