1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
|
/* NSC -- new Scala compiler
* Copyright 2005-2011 LAMP/EPFL
* @author Martin Odersky
*/
package scala.reflect
package internal
import scala.collection.immutable
import NameTransformer.MODULE_SUFFIX_STRING
import annotation.switch
import language.implicitConversions
trait StdNames extends NameManglers { self: SymbolTable =>
def encode(str: String): TermName = newTermNameCached(NameTransformer.encode(str))
implicit def lowerTermNames(n: TermName): String = n.toString
// implicit def stringToTermName(s: String): TermName = newTermName(s)
/** This should be the first trait in the linearization. */
trait Keywords {
private var kws: Set[TermName] = Set()
private def kw(s: String): TermName = {
val result = newTermNameCached(s)
kws = kws + result
result
}
final val ABSTRACTkw: TermName = kw("abstract")
final val CASEkw: TermName = kw("case")
final val CLASSkw: TermName = kw("class")
final val CATCHkw: TermName = kw("catch")
final val DEFkw: TermName = kw("def")
final val DOkw: TermName = kw("do")
final val ELSEkw: TermName = kw("else")
final val EXTENDSkw: TermName = kw("extends")
final val FALSEkw: TermName = kw("false")
final val FINALkw: TermName = kw("final")
final val FINALLYkw: TermName = kw("finally")
final val FORkw: TermName = kw("for")
final val FORSOMEkw: TermName = kw("forSome")
final val IFkw: TermName = kw("if")
final val IMPLICITkw: TermName = kw("implicit")
final val IMPORTkw: TermName = kw("import")
final val LAZYkw: TermName = kw("lazy")
final val MACROkw: TermName = kw("macro")
final val MATCHkw: TermName = kw("match")
final val NEWkw: TermName = kw("new")
final val NULLkw: TermName = kw("null")
final val OBJECTkw: TermName = kw("object")
final val OVERRIDEkw: TermName = kw("override")
final val PACKAGEkw: TermName = kw("package")
final val PRIVATEkw: TermName = kw("private")
final val PROTECTEDkw: TermName = kw("protected")
final val RETURNkw: TermName = kw("return")
final val SEALEDkw: TermName = kw("sealed")
final val SUPERkw: TermName = kw("super")
final val THENkw: TermName = kw("then")
final val THISkw: TermName = kw("this")
final val THROWkw: TermName = kw("throw")
final val TRAITkw: TermName = kw("trait")
final val TRUEkw: TermName = kw("true")
final val TRYkw: TermName = kw("try")
final val TYPEkw: TermName = kw("type")
final val VALkw: TermName = kw("val")
final val VARkw: TermName = kw("var")
final val WITHkw: TermName = kw("with")
final val WHILEkw: TermName = kw("while")
final val YIELDkw: TermName = kw("yield")
final val DOTkw: TermName = kw(".")
final val USCOREkw: TermName = kw("_")
final val COLONkw: TermName = kw(":")
final val EQUALSkw: TermName = kw("=")
final val ARROWkw: TermName = kw("=>")
final val LARROWkw: TermName = kw("<-")
final val SUBTYPEkw: TermName = kw("<:")
final val VIEWBOUNDkw: TermName = kw("<%")
final val SUPERTYPEkw: TermName = kw(">:")
final val HASHkw: TermName = kw("#")
final val ATkw: TermName = kw("@")
final val keywords = {
val result = kws.toSet
kws = null
result
}
final val javaKeywords = new JavaKeywords()
}
trait CommonNames /*extends LibraryCommonNames*/ {
type NameType <: Name
protected implicit def createNameType(name: String): NameType
val EMPTY: NameType = ""
val ANON_FUN_NAME: NameType = "$anonfun"
val ANON_CLASS_NAME: NameType = "$anon"
val EMPTY_PACKAGE_NAME: NameType = "<empty>"
val IMPORT: NameType = "<import>"
val MODULE_VAR_SUFFIX: NameType = "$module"
val ROOT: NameType = "<root>"
val PACKAGE: NameType = "package"
val SPECIALIZED_SUFFIX: NameType = "$sp"
// value types (and AnyRef) are all used as terms as well
// as (at least) arguments to the @specialize annotation.
final val Boolean: NameType = "Boolean"
final val Byte: NameType = "Byte"
final val Char: NameType = "Char"
final val Double: NameType = "Double"
final val Float: NameType = "Float"
final val Int: NameType = "Int"
final val Long: NameType = "Long"
final val Short: NameType = "Short"
final val Unit: NameType = "Unit"
final val ScalaValueNames: scala.List[NameType] =
scala.List(Byte, Char, Short, Int, Long, Float, Double, Boolean, Unit)
// some types whose companions we utilize
final val AnyRef: NameType = "AnyRef"
final val Array: NameType = "Array"
final val List: NameType = "List"
final val Seq: NameType = "Seq"
final val Symbol: NameType = "Symbol"
final val ClassTag: NameType = "ClassTag"
final val TypeTag : NameType = "TypeTag"
final val ConcreteTypeTag: NameType = "ConcreteTypeTag"
// fictions we use as both types and terms
final val ERROR: NameType = "<error>"
final val NO_NAME: NameType = "<none>" // formerly NOSYMBOL
final val WILDCARD: NameType = "_"
}
trait TypeNames extends CommonNames {
final val BYNAME_PARAM_CLASS_NAME: NameType = "<byname>"
final val EQUALS_PATTERN_NAME: NameType = "<equals>"
final val JAVA_REPEATED_PARAM_CLASS_NAME: NameType = "<repeated...>"
final val LOCAL_CHILD: NameType = "<local child>"
final val REPEATED_PARAM_CLASS_NAME: NameType = "<repeated>"
final val WILDCARD_STAR: NameType = "_*"
final val Any: NameType = "Any"
final val AnyVal: NameType = "AnyVal"
final val Expr: NameType = "Expr"
final val Nothing: NameType = "Nothing"
final val Null: NameType = "Null"
final val Object: NameType = "Object"
final val PartialFunction: NameType = "PartialFunction"
final val PrefixType: NameType = "PrefixType"
final val Product: NameType = "Product"
final val Serializable: NameType = "Serializable"
final val Singleton: NameType = "Singleton"
final val String: NameType = "String"
final val Throwable: NameType = "Throwable"
final val Annotation: NameType = "Annotation"
final val ClassfileAnnotation: NameType = "ClassfileAnnotation"
final val Enum: NameType = "Enum"
final val Tree: NameType = "Tree"
final val TypeTree: NameType = "TypeTree"
// Annotation simple names, used in Namer
final val BeanPropertyAnnot: NameType = "BeanProperty"
final val BooleanBeanPropertyAnnot: NameType = "BooleanBeanProperty"
final val bridgeAnnot: NameType = "bridge"
// Classfile Attributes
final val AnnotationDefaultATTR: NameType = "AnnotationDefault"
final val BridgeATTR: NameType = "Bridge"
final val ClassfileAnnotationATTR: NameType = "RuntimeInvisibleAnnotations" // RetentionPolicy.CLASS. Currently not used (Apr 2009).
final val CodeATTR: NameType = "Code"
final val ConstantValueATTR: NameType = "ConstantValue"
final val DeprecatedATTR: NameType = "Deprecated"
final val ExceptionsATTR: NameType = "Exceptions"
final val InnerClassesATTR: NameType = "InnerClasses"
final val JacoMetaATTR: NameType = "JacoMeta"
final val LineNumberTableATTR: NameType = "LineNumberTable"
final val LocalVariableTableATTR: NameType = "LocalVariableTable"
final val RuntimeAnnotationATTR: NameType = "RuntimeVisibleAnnotations" // RetentionPolicy.RUNTIME
final val RuntimeParamAnnotationATTR: NameType = "RuntimeVisibleParameterAnnotations" // RetentionPolicy.RUNTIME (annotations on parameters)
final val ScalaATTR: NameType = "Scala"
final val ScalaSignatureATTR: NameType = "ScalaSig"
final val SignatureATTR: NameType = "Signature"
final val SourceFileATTR: NameType = "SourceFile"
final val SyntheticATTR: NameType = "Synthetic"
}
trait TermNames extends Keywords with CommonNames {
// Compiler internal names
val EXPAND_SEPARATOR_STRING = "$$"
val ANYNAME: NameType = "<anyname>"
val CONSTRUCTOR: NameType = "<init>"
val FAKE_LOCAL_THIS: NameType = "this$"
val INITIALIZER: NameType = CONSTRUCTOR // Is this buying us something?
val LAZY_LOCAL: NameType = "$lzy"
val LOCAL_SUFFIX_STRING = " "
val MIRROR_PREFIX: NameType = "$mr."
val MIRROR_SHORT: NameType = "$mr"
val MIRROR_FREE_PREFIX: NameType = "free$"
val MIRROR_FREE_THIS_SUFFIX: NameType = "$this"
val MIRROR_FREE_VALUE_SUFFIX: NameType = "$value"
val MIXIN_CONSTRUCTOR: NameType = "$init$"
val MODULE_INSTANCE_FIELD: NameType = NameTransformer.MODULE_INSTANCE_NAME // "MODULE$"
val OUTER: NameType = "$outer"
val OUTER_LOCAL: NameType = OUTER + LOCAL_SUFFIX_STRING // "$outer ", note the space
val OUTER_SYNTH: NameType = "<outer>" // emitted by virtual pattern matcher, replaced by outer accessor in explicitouter
val SELECTOR_DUMMY: NameType = "<unapply-selector>"
val SELF: NameType = "$this"
val SPECIALIZED_INSTANCE: NameType = "specInstance$"
val STAR: NameType = "*"
val THIS: NameType = "_$this"
final val Nil: NameType = "Nil"
final val Predef: NameType = "Predef"
final val ScalaRunTime: NameType = "ScalaRunTime"
final val Some: NameType = "Some"
val _1 : NameType = "_1"
val _2 : NameType = "_2"
val _3 : NameType = "_3"
val _4 : NameType = "_4"
val _5 : NameType = "_5"
val _6 : NameType = "_6"
val _7 : NameType = "_7"
val _8 : NameType = "_8"
val _9 : NameType = "_9"
val _10 : NameType = "_10"
val _11 : NameType = "_11"
val _12 : NameType = "_12"
val _13 : NameType = "_13"
val _14 : NameType = "_14"
val _15 : NameType = "_15"
val _16 : NameType = "_16"
val _17 : NameType = "_17"
val _18 : NameType = "_18"
val _19 : NameType = "_19"
val _20 : NameType = "_20"
val _21 : NameType = "_21"
val _22 : NameType = "_22"
val x_0 : NameType = "x$0"
val x_1 : NameType = "x$1"
val x_2 : NameType = "x$2"
val x_3 : NameType = "x$3"
val x_4 : NameType = "x$4"
val x_5 : NameType = "x$5"
val x_6 : NameType = "x$6"
val x_7 : NameType = "x$7"
val x_8 : NameType = "x$8"
val x_9 : NameType = "x$9"
@switch def syntheticParamName(i: Int): TermName = i match {
case 0 => nme.x_0
case 1 => nme.x_1
case 2 => nme.x_2
case 3 => nme.x_3
case 4 => nme.x_4
case 5 => nme.x_5
case 6 => nme.x_6
case 7 => nme.x_7
case 8 => nme.x_8
case 9 => nme.x_9
case _ => newTermName("x$" + i)
}
// [Eugene to Paul] see comments in StandardNames.scala to find out why's this here
val QQQ = ???
val ??? = encode("???")
val wrapRefArray: NameType = "wrapRefArray"
val wrapByteArray: NameType = "wrapByteArray"
val wrapShortArray: NameType = "wrapShortArray"
val wrapCharArray: NameType = "wrapCharArray"
val wrapIntArray: NameType = "wrapIntArray"
val wrapLongArray: NameType = "wrapLongArray"
val wrapFloatArray: NameType = "wrapFloatArray"
val wrapDoubleArray: NameType = "wrapDoubleArray"
val wrapBooleanArray: NameType = "wrapBooleanArray"
val wrapUnitArray: NameType = "wrapUnitArray"
val genericWrapArray: NameType = "genericWrapArray"
// Compiler utilized names
val AnnotatedType: NameType = "AnnotatedType"
val AnnotationInfo: NameType = "AnnotationInfo"
val Any: NameType = "Any"
val AnyVal: NameType = "AnyVal"
val Apply: NameType = "Apply"
val ArrayAnnotArg: NameType = "ArrayAnnotArg"
val ConstantType: NameType = "ConstantType"
val EmptyPackage: NameType = "EmptyPackage"
val EmptyPackageClass: NameType = "EmptyPackageClass"
val Expr: NameType = "Expr"
val Ident: NameType = "Ident"
val Import: NameType = "Import"
val Literal: NameType = "Literal"
val LiteralAnnotArg: NameType = "LiteralAnnotArg"
val NestedAnnotArg: NameType = "NestedAnnotArg"
val NoPrefix: NameType = "NoPrefix"
val NoSymbol: NameType = "NoSymbol"
val Nothing: NameType = "Nothing"
val NoType: NameType = "NoType"
val Null: NameType = "Null"
val Object: NameType = "Object"
val RootPackage: NameType = "RootPackage"
val RootClass: NameType = "RootClass"
val Select: NameType = "Select"
val StringContext: NameType = "StringContext"
val This: NameType = "This"
val Tree : NameType = "Tree"
val Tuple2: NameType = "Tuple2"
val TYPE_ : NameType = "TYPE"
val TypeApply: NameType = "TypeApply"
val TypeRef: NameType = "TypeRef"
val TypeTree: NameType = "TypeTree"
val UNIT : NameType = "UNIT"
val add_ : NameType = "add"
val annotation: NameType = "annotation"
val anyValClass: NameType = "anyValClass"
val append: NameType = "append"
val apply: NameType = "apply"
val applyDynamic: NameType = "applyDynamic"
val applyOrElse: NameType = "applyOrElse"
val args : NameType = "args"
val argv : NameType = "argv"
val arrayValue: NameType = "arrayValue"
val array_apply : NameType = "array_apply"
val array_clone : NameType = "array_clone"
val array_length : NameType = "array_length"
val array_update : NameType = "array_update"
val arraycopy: NameType = "arraycopy"
val asInstanceOf_ : NameType = "asInstanceOf"
val asInstanceOf_Ob : NameType = "$asInstanceOf"
val asTypeConstructor: NameType = "asTypeConstructor"
val assert_ : NameType = "assert"
val assume_ : NameType = "assume"
val box: NameType = "box"
val bytes: NameType = "bytes"
val canEqual_ : NameType = "canEqual"
val checkInitialized: NameType = "checkInitialized"
val classOf: NameType = "classOf"
val clone_ : NameType = if (forMSIL) "MemberwiseClone" else "clone" // sn.OClone causes checkinit failure
val conforms: NameType = "conforms"
val copy: NameType = "copy"
val definitions: NameType = "definitions"
val delayedInit: NameType = "delayedInit"
val delayedInitArg: NameType = "delayedInit$body"
val drop: NameType = "drop"
val elem: NameType = "elem"
val emptyValDef: NameType = "emptyValDef"
val ensureAccessible : NameType = "ensureAccessible"
val eq: NameType = "eq"
val equalsNumChar : NameType = "equalsNumChar"
val equalsNumNum : NameType = "equalsNumNum"
val equalsNumObject : NameType = "equalsNumObject"
val equals_ : NameType = if (forMSIL) "Equals" else "equals"
val erasure: NameType = "erasure"
val error: NameType = "error"
val eval: NameType = "eval"
val ex: NameType = "ex"
val false_ : NameType = "false"
val filter: NameType = "filter"
val finalize_ : NameType = if (forMSIL) "Finalize" else "finalize"
val find_ : NameType = "find"
val flatMap: NameType = "flatMap"
val foreach: NameType = "foreach"
val genericArrayOps: NameType = "genericArrayOps"
val get: NameType = "get"
val getOrElse: NameType = "getOrElse"
val hasNext: NameType = "hasNext"
val hashCode_ : NameType = if (forMSIL) "GetHashCode" else "hashCode"
val hash_ : NameType = "hash"
val head: NameType = "head"
val identity: NameType = "identity"
val info: NameType = "info"
val inlinedEquals: NameType = "inlinedEquals"
val isArray: NameType = "isArray"
val isDefinedAt: NameType = "isDefinedAt"
val isEmpty: NameType = "isEmpty"
val isInstanceOf_ : NameType = "isInstanceOf"
val isInstanceOf_Ob : NameType = "$isInstanceOf"
val java: NameType = "java"
val key: NameType = "key"
val lang: NameType = "lang"
val length: NameType = "length"
val lengthCompare: NameType = "lengthCompare"
val macroThis : NameType = "_this"
val macroContext : NameType = "c"
val main: NameType = "main"
val manifest: NameType = "manifest"
val map: NameType = "map"
val materializeClassTag: NameType = "materializeClassTag"
val materializeTypeTag: NameType = "materializeTypeTag"
val materializeConcreteTypeTag: NameType = "materializeConcreteTypeTag"
val mirror : NameType = "mirror"
val moduleClass : NameType = "moduleClass"
val name: NameType = "name"
val ne: NameType = "ne"
val newArray: NameType = "newArray"
val newFreeTerm: NameType = "newFreeTerm"
val newFreeType: NameType = "newFreeType"
val newNestedSymbol: NameType = "newNestedSymbol"
val newScopeWith: NameType = "newScopeWith"
val nmeNewTermName: NameType = "newTermName"
val nmeNewTypeName: NameType = "newTypeName"
val next: NameType = "next"
val notifyAll_ : NameType = "notifyAll"
val notify_ : NameType = "notify"
val null_ : NameType = "null"
val ofDim: NameType = "ofDim"
val origin: NameType = "origin"
val prefix : NameType = "prefix"
val productArity: NameType = "productArity"
val productElement: NameType = "productElement"
val productIterator: NameType = "productIterator"
val productPrefix: NameType = "productPrefix"
val readResolve: NameType = "readResolve"
val reflect : NameType = "reflect"
val reify : NameType = "reify"
val runOrElse: NameType = "runOrElse"
val runtime: NameType = "runtime"
val sameElements: NameType = "sameElements"
val scala_ : NameType = "scala"
val selectOverloadedMethod: NameType = "selectOverloadedMethod"
val selectTerm: NameType = "selectTerm"
val selectType: NameType = "selectType"
val self: NameType = "self"
val setAccessible: NameType = "setAccessible"
val setAnnotations: NameType = "setAnnotations"
val setSymbol: NameType = "setSymbol"
val setType: NameType = "setType"
val setTypeSignature: NameType = "setTypeSignature"
val staticClass : NameType = "staticClass"
val staticModule : NameType = "staticModule"
val synchronized_ : NameType = "synchronized"
val tail: NameType = "tail"
val thisModuleType: NameType = "thisModuleType"
val this_ : NameType = "this"
val throw_ : NameType = "throw"
val toArray: NameType = "toArray"
val toList: NameType = "toList"
val toObjectArray : NameType = "toObjectArray"
val toSeq: NameType = "toSeq"
val toString_ : NameType = if (forMSIL) "ToString" else "toString"
val tpe : NameType = "tpe"
val tree : NameType = "tree"
val true_ : NameType = "true"
val typedProductIterator: NameType = "typedProductIterator"
val unapply: NameType = "unapply"
val unapplySeq: NameType = "unapplySeq"
val unbox: NameType = "unbox"
val update: NameType = "update"
val value: NameType = "value"
val valueOf : NameType = "valueOf"
val values : NameType = "values"
val view_ : NameType = "view"
val wait_ : NameType = "wait"
val withFilter: NameType = "withFilter"
val zip: NameType = "zip"
val synthSwitch: NameType = "$synthSwitch"
// unencoded operators
object raw {
final val AMP : NameType = "&"
final val BANG : NameType = "!"
final val BAR : NameType = "|"
final val DOLLAR: NameType = "$"
final val GE: NameType = ">="
final val LE: NameType = "<="
final val MINUS: NameType = "-"
final val NE: NameType = "!="
final val PLUS : NameType = "+"
final val SLASH: NameType = "/"
final val STAR : NameType = "*"
final val TILDE: NameType = "~"
final val isUnary: Set[Name] = Set(MINUS, PLUS, TILDE, BANG)
}
// value-conversion methods
val toByte: NameType = "toByte"
val toShort: NameType = "toShort"
val toChar: NameType = "toChar"
val toInt: NameType = "toInt"
val toLong: NameType = "toLong"
val toFloat: NameType = "toFloat"
val toDouble: NameType = "toDouble"
// primitive operation methods for structual types mostly
// overlap with the above, but not for these two.
val toCharacter: NameType = "toCharacter"
val toInteger: NameType = "toInteger"
}
object tpnme extends AbsTypeNames with TypeNames /*with LibraryTypeNames*/ with TypeNameMangling {
type NameType = TypeName
protected implicit def createNameType(name: String): TypeName = newTypeNameCached(name)
val REFINE_CLASS_NAME: NameType = "<refinement>"
}
/** For fully qualified type names.
*/
object fulltpnme extends TypeNames {
type NameType = TypeName
protected implicit def createNameType(name: String): TypeName = newTypeNameCached(name)
val RuntimeNothing: NameType = "scala.runtime.Nothing$"
val RuntimeNull: NameType = "scala.runtime.Null$"
val JavaLangEnum: NameType = "java.lang.Enum"
}
/** Java binary names, like scala/runtime/Nothing$.
*/
object binarynme {
def toBinary(name: Name) = name mapName (_.replace('.', '/'))
val RuntimeNothing = toBinary(fulltpnme.RuntimeNothing).toTypeName
val RuntimeNull = toBinary(fulltpnme.RuntimeNull).toTypeName
}
object fullnme extends TermNames {
type NameType = TermName
protected implicit def createNameType(name: String): TermName = newTermNameCached(name)
val MirrorPackage: NameType = "scala.reflect.mirror"
}
val javanme = nme.javaKeywords
object nme extends AbsTermNames with TermNames /*with LibraryTermNames*/ with TermNameMangling {
type NameType = TermName
protected implicit def createNameType(name: String): TermName = newTermNameCached(name)
/** Translate a String into a list of simple TypeNames and TermNames.
* In all segments before the last, type/term is determined by whether
* the following separator char is '.' or '#'. In the last segment,
* the argument "assumeTerm" determines it. Examples:
*
* package foo {
* object Lorax { object Wog ; class Wog }
* class Lorax { object Zax ; class Zax }
* }
*
* f("foo.Lorax", true) == List("foo": Term, "Lorax": Term) // object Lorax
* f("foo.Lorax", false) == List("foo": Term, "Lorax": Type) // class Lorax
* f("Lorax.Wog", true) == List("Lorax": Term, "Wog": Term) // object Wog
* f("Lorax.Wog", false) == List("Lorax": Term, "Wog": Type) // class Wog
* f("Lorax#Zax", true) == List("Lorax": Type, "Zax": Term) // object Zax
* f("Lorax#Zax", false) == List("Lorax": Type, "Zax": Type) // class Zax
*
* Note that in actual scala syntax you cannot refer to object Zax without an
* instance of Lorax, so Lorax#Zax could only mean the type. One might think
* that Lorax#Zax.type would work, but this is not accepted by the parser.
* For the purposes of referencing that object, the syntax is allowed.
*/
def segments(name: String, assumeTerm: Boolean): List[Name] = {
def mkName(str: String, term: Boolean): Name =
if (term) newTermName(str) else newTypeName(str)
name.indexWhere(ch => ch == '.' || ch == '#') match {
// it's the last segment: the parameter tells us whether type or term
case -1 => if (name == "") scala.Nil else scala.List(mkName(name, assumeTerm))
// otherwise, we can tell based on whether '#' or '.' is the following char.
case idx =>
val (simple, div, rest) = (name take idx, name charAt idx, newTermName(name) drop (idx + 1))
mkName(simple, div == '.') :: segments(rest, assumeTerm)
}
}
def newBitmapName(bitmapPrefix: Name, n: Int) = bitmapPrefix append ("" + n)
val BITMAP_PREFIX: String = "bitmap$"
val BITMAP_NORMAL: NameType = BITMAP_PREFIX + "" // initialization bitmap for public/protected lazy vals
val BITMAP_TRANSIENT: NameType = BITMAP_PREFIX + "trans$" // initialization bitmap for transient lazy vals
val BITMAP_PRIVATE: NameType = BITMAP_PREFIX + "priv$" // initialization bitmap for private lazy vals
val BITMAP_CHECKINIT: NameType = BITMAP_PREFIX + "init$" // initialization bitmap for checkinit values
val BITMAP_CHECKINIT_TRANSIENT: NameType = BITMAP_PREFIX + "inittrans$" // initialization bitmap for transient checkinit values
/** The expanded name of `name` relative to this class `base` with given `separator`
*/
def expandedName(name: TermName, base: Symbol, separator: String = EXPAND_SEPARATOR_STRING): TermName =
newTermNameCached(base.fullName('$') + separator + name)
def isModuleVarName(name: Name): Boolean =
stripAnonNumberSuffix(name) endsWith MODULE_VAR_SUFFIX
def moduleVarName(name: TermName): TermName =
newTermNameCached("" + name + MODULE_VAR_SUFFIX)
val ROOTPKG: TermName = "_root_"
/** Base strings from which synthetic names are derived. */
val CHECK_IF_REFUTABLE_STRING = "check$ifrefutable$"
val DEFAULT_GETTER_STRING = "$default$"
val DO_WHILE_PREFIX = "doWhile$"
val EQEQ_LOCAL_VAR_STRING = "eqEqTemp$"
val EVIDENCE_PARAM_PREFIX = "evidence$"
val EXCEPTION_RESULT_PREFIX = "exceptionResult"
val INTERPRETER_IMPORT_WRAPPER = "$iw"
val INTERPRETER_LINE_PREFIX = "line"
val INTERPRETER_VAR_PREFIX = "res"
val INTERPRETER_WRAPPER_SUFFIX = "$object"
val WHILE_PREFIX = "while$"
val EQEQ_LOCAL_VAR: TermName = newTermName(EQEQ_LOCAL_VAR_STRING)
def getCause = sn.GetCause
def getClass_ = sn.GetClass
def getMethod_ = sn.GetMethod
def invoke_ = sn.Invoke
val ADD = encode("+")
val AND = encode("&")
val ASR = encode(">>")
val DIV = encode("/")
val EQ = encode("==")
val EQL = encode("=")
val GE = encode(">=")
val GT = encode(">")
val HASHHASH = encode("##")
val LE = encode("<=")
val LSL = encode("<<")
val LSR = encode(">>>")
val LT = encode("<")
val MINUS = encode("-")
val MOD = encode("%")
val MUL = encode("*")
val NE = encode("!=")
val OR = encode("|")
val PLUS = ADD // technically redundant, but ADD looks funny with MINUS
val SUB = MINUS // ... as does SUB with PLUS
val XOR = encode("^")
val ZAND = encode("&&")
val ZOR = encode("||")
// unary operators
// [Eugene to Paul] see comments in StandardNames.scala to find out why's this here
val UNARY_TILDE = UNARY_~
val UNARY_~ = encode("unary_~")
val UNARY_PLUS = UNARY_+
val UNARY_+ = encode("unary_+")
val UNARY_MINUS = UNARY_-
val UNARY_- = encode("unary_-")
val UNARY_NOT = UNARY_!
val UNARY_! = encode("unary_!")
// Grouped here so Cleanup knows what tests to perform.
val CommonOpNames = Set[Name](OR, XOR, AND, EQ, NE)
val ConversionNames = Set[Name](toByte, toChar, toDouble, toFloat, toInt, toLong, toShort)
val BooleanOpNames = Set[Name](ZOR, ZAND, UNARY_!) ++ CommonOpNames
val NumberOpNames = (
Set[Name](ADD, SUB, MUL, DIV, MOD, LSL, LSR, ASR, LT, LE, GE, GT)
++ Set(UNARY_+, UNARY_-, UNARY_!)
++ ConversionNames
++ CommonOpNames
)
val add: NameType = "add"
val complement: NameType = "complement"
val divide: NameType = "divide"
val multiply: NameType = "multiply"
val negate: NameType = "negate"
val positive: NameType = "positive"
val shiftLogicalRight: NameType = "shiftLogicalRight"
val shiftSignedLeft: NameType = "shiftSignedLeft"
val shiftSignedRight: NameType = "shiftSignedRight"
val subtract: NameType = "subtract"
val takeAnd: NameType = "takeAnd"
val takeConditionalAnd: NameType = "takeConditionalAnd"
val takeConditionalOr: NameType = "takeConditionalOr"
val takeModulo: NameType = "takeModulo"
val takeNot: NameType = "takeNot"
val takeOr: NameType = "takeOr"
val takeXor: NameType = "takeXor"
val testEqual: NameType = "testEqual"
val testGreaterOrEqualThan: NameType = "testGreaterOrEqualThan"
val testGreaterThan: NameType = "testGreaterThan"
val testLessOrEqualThan: NameType = "testLessOrEqualThan"
val testLessThan: NameType = "testLessThan"
val testNotEqual: NameType = "testNotEqual"
val isBoxedNumberOrBoolean: NameType = "isBoxedNumberOrBoolean"
val isBoxedNumber: NameType = "isBoxedNumber"
def toUnaryName(name: TermName): TermName = name match {
case raw.MINUS => UNARY_-
case raw.PLUS => UNARY_+
case raw.TILDE => UNARY_~
case raw.BANG => UNARY_!
case _ => name
}
/** The name of a method which stands in for a primitive operation
* during structural type dispatch.
*/
def primitiveInfixMethodName(name: Name): TermName = name match {
case OR => takeOr
case XOR => takeXor
case AND => takeAnd
case EQ => testEqual
case NE => testNotEqual
case ADD => add
case SUB => subtract
case MUL => multiply
case DIV => divide
case MOD => takeModulo
case LSL => shiftSignedLeft
case LSR => shiftLogicalRight
case ASR => shiftSignedRight
case LT => testLessThan
case LE => testLessOrEqualThan
case GE => testGreaterOrEqualThan
case GT => testGreaterThan
case ZOR => takeConditionalOr
case ZAND => takeConditionalAnd
case _ => NO_NAME
}
/** Postfix/prefix, really.
*/
def primitivePostfixMethodName(name: Name): TermName = name match {
case UNARY_! => takeNot
case UNARY_+ => positive
case UNARY_- => negate
case UNARY_~ => complement
case `toByte` => toByte
case `toShort` => toShort
case `toChar` => toCharacter
case `toInt` => toInteger
case `toLong` => toLong
case `toFloat` => toFloat
case `toDouble` => toDouble
case _ => NO_NAME
}
val reflPolyCacheName: NameType = "reflPoly$Cache"
val reflClassCacheName: NameType = "reflClass$Cache"
val reflParamsCacheName: NameType = "reflParams$Cache"
val reflMethodCacheName: NameType = "reflMethod$Cache"
val reflMethodName: NameType = "reflMethod$Method"
private val reflectionCacheNames = Set[NameType](
reflPolyCacheName,
reflClassCacheName,
reflParamsCacheName,
reflMethodCacheName,
reflMethodName
)
def isReflectionCacheName(name: Name) = reflectionCacheNames exists (name startsWith _)
@switch def productAccessorName(j: Int): TermName = j match {
case 1 => nme._1
case 2 => nme._2
case 3 => nme._3
case 4 => nme._4
case 5 => nme._5
case 6 => nme._6
case 7 => nme._7
case 8 => nme._8
case 9 => nme._9
case 10 => nme._10
case 11 => nme._11
case 12 => nme._12
case 13 => nme._13
case 14 => nme._14
case 15 => nme._15
case 16 => nme._16
case 17 => nme._17
case 18 => nme._18
case 19 => nme._19
case 20 => nme._20
case 21 => nme._21
case 22 => nme._22
case _ => newTermName("_" + j)
}
}
abstract class SymbolNames {
protected implicit def createNameType(s: String): TypeName = newTypeNameCached(s)
val BeanProperty : TypeName
val BooleanBeanProperty : TypeName
val BoxedBoolean : TypeName
val BoxedCharacter : TypeName
val BoxedNumber : TypeName
val Class : TypeName
val Delegate : TypeName
val IOOBException : TypeName // IndexOutOfBoundsException
val InvTargetException : TypeName // InvocationTargetException
val JavaSerializable : TypeName
val MethodAsObject : TypeName
val NPException : TypeName // NullPointerException
val Object : TypeName
val String : TypeName
val Throwable : TypeName
val ValueType : TypeName
val ForName : TermName
val GetCause : TermName
val GetClass : TermName
val GetMethod : TermName
val Invoke : TermName
val JavaLang : TermName
val Boxed: immutable.Map[TypeName, TypeName]
}
class JavaKeywords {
private var kws: Set[TermName] = Set()
private def kw(s: String): TermName = {
val result = newTermNameCached(s)
kws = kws + result
result
}
final val ABSTRACTkw: TermName = kw("abstract")
final val ASSERTkw: TermName = kw("assert")
final val BOOLEANkw: TermName = kw("boolean")
final val BREAKkw: TermName = kw("break")
final val BYTEkw: TermName = kw("byte")
final val CASEkw: TermName = kw("case")
final val CATCHkw: TermName = kw("catch")
final val CHARkw: TermName = kw("char")
final val CLASSkw: TermName = kw("class")
final val CONSTkw: TermName = kw("const")
final val CONTINUEkw: TermName = kw("continue")
final val DEFAULTkw: TermName = kw("default")
final val DOkw: TermName = kw("do")
final val DOUBLEkw: TermName = kw("double")
final val ELSEkw: TermName = kw("else")
final val ENUMkw: TermName = kw("enum")
final val EXTENDSkw: TermName = kw("extends")
final val FINALkw: TermName = kw("final")
final val FINALLYkw: TermName = kw("finally")
final val FLOATkw: TermName = kw("float")
final val FORkw: TermName = kw("for")
final val IFkw: TermName = kw("if")
final val GOTOkw: TermName = kw("goto")
final val IMPLEMENTSkw: TermName = kw("implements")
final val IMPORTkw: TermName = kw("import")
final val INSTANCEOFkw: TermName = kw("instanceof")
final val INTkw: TermName = kw("int")
final val INTERFACEkw: TermName = kw("interface")
final val LONGkw: TermName = kw("long")
final val NATIVEkw: TermName = kw("native")
final val NEWkw: TermName = kw("new")
final val PACKAGEkw: TermName = kw("package")
final val PRIVATEkw: TermName = kw("private")
final val PROTECTEDkw: TermName = kw("protected")
final val PUBLICkw: TermName = kw("public")
final val RETURNkw: TermName = kw("return")
final val SHORTkw: TermName = kw("short")
final val STATICkw: TermName = kw("static")
final val STRICTFPkw: TermName = kw("strictfp")
final val SUPERkw: TermName = kw("super")
final val SWITCHkw: TermName = kw("switch")
final val SYNCHRONIZEDkw: TermName = kw("synchronized")
final val THISkw: TermName = kw("this")
final val THROWkw: TermName = kw("throw")
final val THROWSkw: TermName = kw("throws")
final val TRANSIENTkw: TermName = kw("transient")
final val TRYkw: TermName = kw("try")
final val VOIDkw: TermName = kw("void")
final val VOLATILEkw: TermName = kw("volatile")
final val WHILEkw: TermName = kw("while")
final val keywords = {
val result = kws.toSet
kws = null
result
}
}
private abstract class JavaNames extends SymbolNames {
final val BoxedBoolean: TypeName = "java.lang.Boolean"
final val BoxedByte: TypeName = "java.lang.Byte"
final val BoxedCharacter: TypeName = "java.lang.Character"
final val BoxedDouble: TypeName = "java.lang.Double"
final val BoxedFloat: TypeName = "java.lang.Float"
final val BoxedInteger: TypeName = "java.lang.Integer"
final val BoxedLong: TypeName = "java.lang.Long"
final val BoxedNumber: TypeName = "java.lang.Number"
final val BoxedShort: TypeName = "java.lang.Short"
final val Class: TypeName = "java.lang.Class"
final val Delegate: TypeName = tpnme.NO_NAME
final val IOOBException: TypeName = "java.lang.IndexOutOfBoundsException"
final val InvTargetException: TypeName = "java.lang.reflect.InvocationTargetException"
final val MethodAsObject: TypeName = "java.lang.reflect.Method"
final val NPException: TypeName = "java.lang.NullPointerException"
final val Object: TypeName = "java.lang.Object"
final val String: TypeName = "java.lang.String"
final val Throwable: TypeName = "java.lang.Throwable"
final val ValueType: TypeName = tpnme.NO_NAME
final val ForName: TermName = newTermName("forName")
final val GetCause: TermName = newTermName("getCause")
final val GetClass: TermName = newTermName("getClass")
final val GetMethod: TermName = newTermName("getMethod")
final val Invoke: TermName = newTermName("invoke")
final val JavaLang: TermName = newTermName("java.lang")
val Boxed = immutable.Map[TypeName, TypeName](
tpnme.Boolean -> BoxedBoolean,
tpnme.Byte -> BoxedByte,
tpnme.Char -> BoxedCharacter,
tpnme.Short -> BoxedShort,
tpnme.Int -> BoxedInteger,
tpnme.Long -> BoxedLong,
tpnme.Float -> BoxedFloat,
tpnme.Double -> BoxedDouble
)
}
private class MSILNames extends SymbolNames {
final val BeanProperty: TypeName = tpnme.NO_NAME
final val BooleanBeanProperty: TypeName = tpnme.NO_NAME
final val BoxedBoolean: TypeName = "System.IConvertible"
final val BoxedCharacter: TypeName = "System.IConvertible"
final val BoxedNumber: TypeName = "System.IConvertible"
final val Class: TypeName = "System.Type"
final val Delegate: TypeName = "System.MulticastDelegate"
final val IOOBException: TypeName = "System.IndexOutOfRangeException"
final val InvTargetException: TypeName = "System.Reflection.TargetInvocationException"
final val JavaSerializable: TypeName = tpnme.NO_NAME
final val MethodAsObject: TypeName = "System.Reflection.MethodInfo"
final val NPException: TypeName = "System.NullReferenceException"
final val Object: TypeName = "System.Object"
final val String: TypeName = "System.String"
final val Throwable: TypeName = "System.Exception"
final val ValueType: TypeName = "System.ValueType"
final val ForName: TermName = newTermName("GetType")
final val GetCause: TermName = newTermName("InnerException") /* System.Reflection.TargetInvocationException.InnerException */
final val GetClass: TermName = newTermName("GetType")
final val GetMethod: TermName = newTermName("GetMethod")
final val Invoke: TermName = newTermName("Invoke")
final val JavaLang: TermName = newTermName("System")
val Boxed = immutable.Map[TypeName, TypeName](
tpnme.Boolean -> "System.Boolean",
tpnme.Byte -> "System.SByte", // a scala.Byte is signed and a System.SByte too (unlike a System.Byte)
tpnme.Char -> "System.Char",
tpnme.Short -> "System.Int16",
tpnme.Int -> "System.Int32",
tpnme.Long -> "System.Int64",
tpnme.Float -> "System.Single",
tpnme.Double -> "System.Double"
)
}
private class J2SENames extends JavaNames {
final val BeanProperty: TypeName = "scala.beans.BeanProperty"
final val BooleanBeanProperty: TypeName = "scala.beans.BooleanBeanProperty"
final val JavaSerializable: TypeName = "java.io.Serializable"
}
lazy val sn: SymbolNames =
if (forMSIL) new MSILNames
else new J2SENames
}
|