aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Definitions.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-02-08 22:48:33 +0100
committerMartin Odersky <odersky@gmail.com>2013-02-08 22:48:33 +0100
commitfec107cc37e4b932346de892f7a3b35f171da8f9 (patch)
tree58fe4ad766460527e6e7f2d22e91e0d6828e8afa /src/dotty/tools/dotc/core/Definitions.scala
parente8366c0fe9b5c04ba471d9f3f572d9ea0c684fbb (diff)
downloaddotty-fec107cc37e4b932346de892f7a3b35f171da8f9.tar.gz
dotty-fec107cc37e4b932346de892f7a3b35f171da8f9.tar.bz2
dotty-fec107cc37e4b932346de892f7a3b35f171da8f9.zip
New stuff in Definitions.
Diffstat (limited to 'src/dotty/tools/dotc/core/Definitions.scala')
-rw-r--r--src/dotty/tools/dotc/core/Definitions.scala50
1 files changed, 48 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/core/Definitions.scala b/src/dotty/tools/dotc/core/Definitions.scala
index fc77c8384..769f108f7 100644
--- a/src/dotty/tools/dotc/core/Definitions.scala
+++ b/src/dotty/tools/dotc/core/Definitions.scala
@@ -7,19 +7,49 @@ package dotty.tools.dotc
package core
import Types._, Contexts._, Symbols._, SymDenotations._, StdNames._, Names._
-
+import Flags._, Scopes._, Decorators._, NameOps._
import scala.annotation.{ switch, meta }
import scala.collection.{ mutable, immutable }
-import Flags._
import PartialFunction._
import collection.mutable
import scala.reflect.api.{ Universe => ApiUniverse }
+object Definitions {
+ val MaxFunctionArity, MaxTupleArity = 22
+}
+
class Definitions(implicit ctx: Context) {
+ import Definitions._
def requiredPackage(str: String): TermSymbol = ???
def requiredClass(str: String): ClassSymbol = ???
def requiredModule(str: String): TermSymbol = ???
+ private def newSyntheticTypeParam(cls: ClassSymbol, scope: Scope, suffix: String = "T0") = {
+ val tname = suffix.toTypeName.expandedName(cls)
+ val tparam = ctx.newSymbol(cls, tname, TypeParamFlags, TypeBounds.empty)
+ scope.enter(tparam)
+ }
+
+ private def specialPolyClass(name: TypeName, flags: FlagSet, parentConstrs: Type*): ClassSymbol = {
+ def classDenot(cls: ClassSymbol) = {
+ val paramDecls = newScope
+ val typeParam = newSyntheticTypeParam(cls, paramDecls)
+ def instantiate(tpe: Type) =
+ if (tpe.typeParams.nonEmpty) tpe.appliedTo(typeParam.symbolicRef)
+ else tpe
+ val parents = parentConstrs.toList map instantiate
+ val parentRefs: List[TypeRef] = ctx.normalizeToRefs(parents, cls, paramDecls)
+ CompleteClassDenotation(cls, ScalaPackageClass, name, flags, parentRefs, decls = paramDecls)(ctx)
+ }
+ new ClassSymbol(classDenot)
+ }
+
+ private def mkArityArray(name: String, arity: Int, countFrom: Int): Array[ClassSymbol] = {
+ val arr = new Array[ClassSymbol](arity)
+ for (i <- countFrom to arity) arr(i) = requiredClass("scala." + name + i)
+ arr
+ }
+
lazy val RootClass: ClassSymbol = ctx.newLazyPackageSymbols(
NoSymbol, nme.ROOT, ctx.rootLoader)._2
lazy val RootPackage: TermSymbol = ctx.newSymbol(
@@ -46,7 +76,9 @@ class Definitions(implicit ctx: Context) {
lazy val PredefModule = requiredModule("scala.Predef")
+// lazy val FunctionClass: ClassSymbol = requiredClass("scala.Function")
lazy val SingletonClass: ClassSymbol = requiredClass("scala.Singleton")
+ lazy val SeqClass: ClassSymbol = requiredClass("scala.collection.Seq")
lazy val ArrayClass: ClassSymbol = requiredClass("scala.Array")
lazy val uncheckedStableClass: ClassSymbol = requiredClass("scala.annotation.unchecked.uncheckedStable")
@@ -70,6 +102,11 @@ class Definitions(implicit ctx: Context) {
lazy val BoxedFloatClass = requiredClass("java.lang.Float")
lazy val BoxedDoubleClass = requiredClass("java.lang.Double")
+ lazy val ByNameParamClass = specialPolyClass(tpnme.BYNAME_PARAM_CLASS, Covariant, AnyType)
+ lazy val EqualsPatternClass = specialPolyClass(tpnme.EQUALS_PATTERN, EmptyFlags, AnyType)
+ lazy val JavaRepeatedParamClass = specialPolyClass(tpnme.JAVA_REPEATED_PARAM_CLASS, Contravariant, AnyRefType, ArrayType)
+ lazy val RepeatedParamClass = specialPolyClass(tpnme.REPEATED_PARAM_CLASS, Covariant, AnyRefType, SeqType)
+
lazy val AnyType = AnyClass.typeConstructor
lazy val AnyValType = AnyValClass.typeConstructor
lazy val ObjectType = ObjectClass.typeConstructor
@@ -77,6 +114,9 @@ class Definitions(implicit ctx: Context) {
lazy val NotNullType = NotNullClass.typeConstructor
lazy val NothingType = NothingClass.typeConstructor
lazy val NullType = NullClass.typeConstructor
+ lazy val SeqType = SeqClass.typeConstructor
+ lazy val ArrayType = ArrayClass.typeConstructor
+
lazy val BoxedNumberClass = requiredClass("java.lang.Number")
lazy val JavaSerializableClass = requiredClass("java.lang.Serializable")
@@ -84,6 +124,12 @@ class Definitions(implicit ctx: Context) {
// ----- Class sets ---------------------------------------------------
+ lazy val FunctionClass = mkArityArray("Function", MaxFunctionArity, 0)
+ lazy val TupleClass = mkArityArray("Tuple", MaxTupleArity, 2)
+
+ lazy val FunctionClasses: Set[Symbol] = FunctionClass.toSet
+ lazy val TupleClasses: Set[Symbol] = TupleClass.toSet
+
/** Modules whose members are in the default namespace */
lazy val UnqualifiedModules: Set[TermSymbol] = Set(PredefModule, ScalaPackageVal, JavaLangPackageVal)