summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala')
-rw-r--r--src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala43
1 files changed, 30 insertions, 13 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala b/src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala
index 975b6bfc49..cf2b7f6b8e 100644
--- a/src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala
+++ b/src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala
@@ -65,6 +65,10 @@ abstract class TypeParser {
busy = false
}
+ class TypeParamsType(override val typeParams: List[Symbol]) extends LazyType {
+ override def complete(sym: Symbol) { throw new AssertionError("cyclic type dereferencing") }
+ }
+
/* the names `classTParams' and `newTParams' stem from the forJVM version (ClassfileParser.sigToType())
* but there are differences that should be kept in mind.
* forMSIL, a nested class knows nothing about any type-params in the nesting class,
@@ -162,7 +166,7 @@ abstract class TypeParser {
clazzMgdPtr.setInfo(classInfoMgdPtr)
}
-/* TODO CLR generics
+/* START CLR generics (snippet 1) */
// first pass
for (tvarCILDef <- typ.getSortedTVars() ) {
val tpname = newTypeName(tvarCILDef.Name.replaceAll("!", "")) // TODO are really all type-params named in all assemblies out there? (NO)
@@ -177,16 +181,16 @@ abstract class TypeParser {
val tpsym = classTParams(tvarCILDef.Number)
tpsym.setInfo(sig2typeBounds(tvarCILDef)) // we never skip bounds unlike in forJVM
}
-*/
+/* END CLR generics (snippet 1) */
val ownTypeParams = newTParams.toList
-/* TODO CLR generics
+/* START CLR generics (snippet 2) */
if (!ownTypeParams.isEmpty) {
clazz.setInfo(new TypeParamsType(ownTypeParams))
if(typ.IsValueType && !typ.IsEnum) {
clazzBoxed.setInfo(new TypeParamsType(ownTypeParams))
}
}
-*/
+/* END CLR generics (snippet 2) */
instanceDefs = new Scope
staticDefs = new Scope
@@ -461,18 +465,22 @@ abstract class TypeParser {
val flags = translateAttributes(method);
val owner = if (method.IsStatic()) statics else clazz;
val methodSym = owner.newMethod(NoPosition, getName(method)).setFlag(flags)
- // TODO CLR generics val newMethodTParams = populateMethodTParams(method, methodSym)
+ /* START CLR generics (snippet 3) */
+ val newMethodTParams = populateMethodTParams(method, methodSym)
+ /* END CLR generics (snippet 3) */
val rettype = if (method.IsConstructor()) clazz.tpe
else getCLSType(method.asInstanceOf[MethodInfo].ReturnType);
if (rettype == null) return;
val mtype = methodType(method, rettype);
if (mtype == null) return;
-/* TODO CLR generics
+/* START CLR generics (snippet 4) */
val mInfo = if (method.IsGeneric) polyType(newMethodTParams, mtype(methodSym))
else mtype(methodSym)
-*/
+/* END CLR generics (snippet 4) */
+/* START CLR non-generics (snippet 4)
val mInfo = mtype(methodSym)
+ END CLR non-generics (snippet 4) */
methodSym.setInfo(mInfo)
(if (method.IsStatic()) staticDefs else instanceDefs).enter(methodSym);
if (method.IsConstructor())
@@ -647,7 +655,12 @@ abstract class TypeParser {
private def getCLSType(typ: MSILType): Type = { // getCLS returns non-null for types GenMSIL can handle, be they CLS-compliant or not
if (typ.IsTMVarUsage())
- null // TODO after generics: getCLRType(typ)
+ /* START CLR generics (snippet 5) */
+ getCLRType(typ)
+ /* END CLR generics (snippet 5) */
+ /* START CLR non-generics (snippet 5)
+ null
+ END CLR non-generics (snippet 5) */
else if ( /* TODO hack if UBYE, uncommented, "ambiguous reference to overloaded definition" ensues, for example for System.Math.Max(x, y) */
typ == clrTypes.USHORT || typ == clrTypes.UINT || typ == clrTypes.ULONG
/* || typ == clrTypes.UBYTE */
@@ -694,19 +707,23 @@ abstract class TypeParser {
if (res != null) res
else if (tMSIL.isInstanceOf[ConstructedType]) {
val ct = tMSIL.asInstanceOf[ConstructedType]
- /* TODO CLR generics: uncomment next two lines and comment out the hack after them
+ /* START CLR generics (snippet 6) */
val cttpArgs = ct.typeArgs.map(tmsil => getCLRType(tmsil)).toList
appliedType(getCLRType(ct.instantiatedType), cttpArgs)
- */
+ /* END CLR generics (snippet 6) */
+ /* START CLR non-generics (snippet 6)
getCLRType(ct.instantiatedType)
+ END CLR non-generics (snippet 6) */
} else if (tMSIL.isInstanceOf[TMVarUsage]) {
- /* TODO CLR generics: uncomment next lines and comment out the hack after them
+ /* START CLR generics (snippet 7) */
val tVarUsage = tMSIL.asInstanceOf[TMVarUsage]
val tVarNumber = tVarUsage.Number
if (tVarUsage.isTVar) classTParams(tVarNumber).typeConstructor // shouldn't fail, just return definitions.AnyClass.tpe at worst
else methodTParams(tVarNumber).typeConstructor // shouldn't fail, just return definitions.AnyClass.tpe at worst
- */
+ /* END CLR generics (snippet 7) */
+ /* START CLR non-generics (snippet 7)
null // definitions.ObjectClass.tpe
+ END CLR non-generics (snippet 7) */
} else if (tMSIL.IsArray()) {
var elemtp = getCLRType(tMSIL.GetElementType())
// cut&pasted from ClassfileParser
@@ -803,7 +820,7 @@ abstract class TypeParser {
flags = flags | Flags.PRIVATE;
else if (field.IsFamily() || field.IsFamilyOrAssembly())
flags = flags | Flags.PROTECTED;
- if (field.IsInitOnly())
+ if (field.IsInitOnly() || field.IsLiteral())
flags = flags | Flags.FINAL;
else
flags = flags | Flags.MUTABLE;