@@ -7,19 +7,49 @@ package dotty.tools.dotc
7
7
package core
8
8
9
9
import Types ._ , Contexts ._ , Symbols ._ , SymDenotations ._ , StdNames ._ , Names ._
10
-
10
+ import Flags . _ , Scopes . _ , Decorators . _ , NameOps . _
11
11
import scala .annotation .{ switch , meta }
12
12
import scala .collection .{ mutable , immutable }
13
- import Flags ._
14
13
import PartialFunction ._
15
14
import collection .mutable
16
15
import scala .reflect .api .{ Universe => ApiUniverse }
17
16
17
+ object Definitions {
18
+ val MaxFunctionArity, MaxTupleArity = 22
19
+ }
20
+
18
21
class Definitions (implicit ctx : Context ) {
22
+ import Definitions ._
19
23
def requiredPackage (str : String ): TermSymbol = ???
20
24
def requiredClass (str : String ): ClassSymbol = ???
21
25
def requiredModule (str : String ): TermSymbol = ???
22
26
27
+ private def newSyntheticTypeParam (cls : ClassSymbol , scope : Scope , suffix : String = " T0" ) = {
28
+ val tname = suffix.toTypeName.expandedName(cls)
29
+ val tparam = ctx.newSymbol(cls, tname, TypeParamFlags , TypeBounds .empty)
30
+ scope.enter(tparam)
31
+ }
32
+
33
+ private def specialPolyClass (name : TypeName , flags : FlagSet , parentConstrs : Type * ): ClassSymbol = {
34
+ def classDenot (cls : ClassSymbol ) = {
35
+ val paramDecls = newScope
36
+ val typeParam = newSyntheticTypeParam(cls, paramDecls)
37
+ def instantiate (tpe : Type ) =
38
+ if (tpe.typeParams.nonEmpty) tpe.appliedTo(typeParam.symbolicRef)
39
+ else tpe
40
+ val parents = parentConstrs.toList map instantiate
41
+ val parentRefs : List [TypeRef ] = ctx.normalizeToRefs(parents, cls, paramDecls)
42
+ CompleteClassDenotation (cls, ScalaPackageClass , name, flags, parentRefs, decls = paramDecls)(ctx)
43
+ }
44
+ new ClassSymbol (classDenot)
45
+ }
46
+
47
+ private def mkArityArray (name : String , arity : Int , countFrom : Int ): Array [ClassSymbol ] = {
48
+ val arr = new Array [ClassSymbol ](arity)
49
+ for (i <- countFrom to arity) arr(i) = requiredClass(" scala." + name + i)
50
+ arr
51
+ }
52
+
23
53
lazy val RootClass : ClassSymbol = ctx.newLazyPackageSymbols(
24
54
NoSymbol , nme.ROOT , ctx.rootLoader)._2
25
55
lazy val RootPackage : TermSymbol = ctx.newSymbol(
@@ -46,7 +76,9 @@ class Definitions(implicit ctx: Context) {
46
76
47
77
lazy val PredefModule = requiredModule(" scala.Predef" )
48
78
79
+ // lazy val FunctionClass: ClassSymbol = requiredClass("scala.Function")
49
80
lazy val SingletonClass : ClassSymbol = requiredClass(" scala.Singleton" )
81
+ lazy val SeqClass : ClassSymbol = requiredClass(" scala.collection.Seq" )
50
82
lazy val ArrayClass : ClassSymbol = requiredClass(" scala.Array" )
51
83
lazy val uncheckedStableClass : ClassSymbol = requiredClass(" scala.annotation.unchecked.uncheckedStable" )
52
84
@@ -70,20 +102,34 @@ class Definitions(implicit ctx: Context) {
70
102
lazy val BoxedFloatClass = requiredClass(" java.lang.Float" )
71
103
lazy val BoxedDoubleClass = requiredClass(" java.lang.Double" )
72
104
105
+ lazy val ByNameParamClass = specialPolyClass(tpnme.BYNAME_PARAM_CLASS , Covariant , AnyType )
106
+ lazy val EqualsPatternClass = specialPolyClass(tpnme.EQUALS_PATTERN , EmptyFlags , AnyType )
107
+ lazy val JavaRepeatedParamClass = specialPolyClass(tpnme.JAVA_REPEATED_PARAM_CLASS , Contravariant , AnyRefType , ArrayType )
108
+ lazy val RepeatedParamClass = specialPolyClass(tpnme.REPEATED_PARAM_CLASS , Covariant , AnyRefType , SeqType )
109
+
73
110
lazy val AnyType = AnyClass .typeConstructor
74
111
lazy val AnyValType = AnyValClass .typeConstructor
75
112
lazy val ObjectType = ObjectClass .typeConstructor
76
113
lazy val AnyRefType = AnyRefAlias .typeConstructor
77
114
lazy val NotNullType = NotNullClass .typeConstructor
78
115
lazy val NothingType = NothingClass .typeConstructor
79
116
lazy val NullType = NullClass .typeConstructor
117
+ lazy val SeqType = SeqClass .typeConstructor
118
+ lazy val ArrayType = ArrayClass .typeConstructor
119
+
80
120
81
121
lazy val BoxedNumberClass = requiredClass(" java.lang.Number" )
82
122
lazy val JavaSerializableClass = requiredClass(" java.lang.Serializable" )
83
123
lazy val ComparableClass = requiredClass(" java.lang.Comparable" )
84
124
85
125
// ----- Class sets ---------------------------------------------------
86
126
127
+ lazy val FunctionClass = mkArityArray(" Function" , MaxFunctionArity , 0 )
128
+ lazy val TupleClass = mkArityArray(" Tuple" , MaxTupleArity , 2 )
129
+
130
+ lazy val FunctionClasses : Set [Symbol ] = FunctionClass .toSet
131
+ lazy val TupleClasses : Set [Symbol ] = TupleClass .toSet
132
+
87
133
/** Modules whose members are in the default namespace */
88
134
lazy val UnqualifiedModules : Set [TermSymbol ] = Set (PredefModule , ScalaPackageVal , JavaLangPackageVal )
89
135
0 commit comments