+2006-01-10 Ankit Jain <jankit@novell.com>
+
+ * TypeDef.cs (TypeDef.TypeParameters): New.
+ (TypeDef.ResolveGenParams): New. Resolve any gen param refs in
+ constraints, base class ref or implemented interfaces.
+ * MethodDef.cs (MethodDef.ResolveGenParams): Update to use new Resolve
+ overloads and ResolveConstraints for GenericParameters.
+
+ * GenericTypeInst.cs (GenericTypeInst.Resolve): Resolve generic args.
+ * GenericParamRef.cs (GenericParamRef.Resolve): Implement.
+ * GenericParameters.cs (GenericParameter.ResolveConstraints): New.
+ (GenericParameters.ResolveConstraints): New.
+ * GenericArguments.cs (GenericArguments.Resolve): New.
+
+ * TypeRef.cs (TypeRef.GetGenericTypeInst): Don't cache.
+ * ExternTypeRef.cs (ExternTypeRef.GetGenericTypeInst): Likewise.
+
2006-01-09 Ankit Jain <jankit@novell.com>
* GenericArguments.cs (GenericArguments.is_resolved): New.
private Hashtable nestedclass_table;
private Hashtable method_table;
private Hashtable field_table;
- private Hashtable genericinst_table;
private Hashtable p_genericinst_table;
public ExternTypeRef (IScope extern_ref, string full_name, bool is_valuetype)
public GenericTypeInst GetGenericTypeInst (GenericArguments gen_args)
{
- string sig = gen_args.ToString ();
- GenericTypeInst gti = null;
-
- if (genericinst_table == null)
- genericinst_table = new Hashtable ();
- else
- gti = genericinst_table [sig] as GenericTypeInst;
-
- if (gti == null) {
- gti = new GenericTypeInst (this, gen_args, is_valuetype);
- genericinst_table [sig] = gti;
- }
-
- return gti;
+ return new GenericTypeInst (this, gen_args, is_valuetype);
}
public PEAPI.Type ResolveInstance (CodeGen code_gen, GenericArguments gen_args)
return p_type_list;
}
+ public void Resolve (GenericParameters type_gen_params, GenericParameters method_gen_params)
+ {
+ foreach (ITypeRef type in type_list) {
+ IGenericTypeRef gtr = type as IGenericTypeRef;
+ if (gtr != null)
+ gtr.Resolve (type_gen_params, method_gen_params);
+ }
+ /* Reset, might have changed (think GenericParamRef) */
+ type_str = null;
+ }
+
private void MakeString ()
{
//Build full_name (foo < , >)
public void Resolve (GenericParameters type_gen_params, GenericParameters method_gen_params)
{
- throw new Exception ("Not implemented yet");
+ if (param.Name == "") {
+ /* Name wasn't specified */
+ return;
+ }
+
+ if (param.Type == PEAPI.GenParamType.MVar && method_gen_params != null)
+ param.Index = method_gen_params.GetGenericParamNum (param.Name);
+ else if (type_gen_params != null)
+ param.Index = type_gen_params.GetGenericParamNum (param.Name);
+
+ if (param.Index < 0)
+ /* TODO: Report error */
+ throw new Exception (String.Format ("Invalid {0}type parameter '{1}'",
+ (param.Type == PEAPI.GenParamType.MVar ? "method " : ""),
+ param.Name));
}
public IMethodRef GetMethodRef (ITypeRef ret_type, PEAPI.CallConv call_conv,
ResolveConstraints (code_gen, gp);
}
+ public void ResolveConstraints (GenericParameters type_gen_params, GenericParameters method_gen_params)
+ {
+ if (constraintsList == null)
+ return;
+
+ foreach (ITypeRef constraint in constraintsList) {
+ IGenericTypeRef gtr = constraint as IGenericTypeRef;
+ if (gtr != null)
+ gtr.Resolve (type_gen_params, method_gen_params);
+ }
+ }
+
public void ResolveConstraints (CodeGen code_gen, PEAPI.GenericParameter gp)
{
if (constraintsList == null)
param.Resolve (code_gen, methoddef);
}
+ public void ResolveConstraints (GenericParameters type_gen_params, GenericParameters method_gen_params)
+ {
+ foreach (GenericParameter param in param_list)
+ param.ResolveConstraints (type_gen_params, method_gen_params);
+ param_str = null;
+ }
+
private void MakeString ()
{
//Build full_name (foo < , >)
public void Resolve (GenericParameters type_gen_params, GenericParameters method_gen_params)
{
- throw new Exception ("Not implemented yet");
+ gen_args.Resolve (type_gen_params, method_gen_params);
}
public IMethodRef GetMethodRef (ITypeRef ret_type, PEAPI.CallConv call_conv,
public void ResolveGenParams ()
{
- GenericParamRef gtr = ret_type as GenericParamRef;
+ GenericParameters type_params = (type_def != null) ? type_def.TypeParameters : null;
+
+ if (gen_params == null && type_params == null)
+ return;
+
+ if (gen_params != null)
+ gen_params.ResolveConstraints (type_params, gen_params);
+
+ IGenericTypeRef gtr = ret_type as IGenericTypeRef;
if (gtr != null)
- ResolveGenParam ((PEAPI.GenParam) gtr.PeapiType);
+ gtr.Resolve (type_params, gen_params);
if (param_list == null)
return;
foreach (ParamDef param in param_list) {
- gtr = param.Type as GenericParamRef;
- if (gtr != null)
- ResolveGenParam ((PEAPI.GenParam) gtr.PeapiType);
- }
+ gtr = param.Type as IGenericTypeRef;
+ if (gtr != null)
+ gtr.Resolve (type_params, gen_params);
+ }
}
public PEAPI.MethodDef Resolve (CodeGen code_gen)
is_value_class = false;
is_enum_class = false;
+ ResolveGenParams ();
int lastdot = name.LastIndexOf ('.');
if (lastdot >= 0) {
get { return (attr & PEAPI.TypeAttr.Interface) != 0; }
}
+ public GenericParameters TypeParameters {
+ get { return gen_params; }
+ }
+
public void AddOverride (MethodDef body, ITypeRef parent, string name)
{
if (override_list == null)
return gen_params.GetGenericParamNum (id);
}
+ /* Resolve any GenParams in constraints, parent & impl_list */
+ private void ResolveGenParams ()
+ {
+ if (gen_params == null)
+ return;
+
+ gen_params.ResolveConstraints (gen_params, null);
+
+ IGenericTypeRef gtr = parent as IGenericTypeRef;
+ if (gtr != null)
+ gtr.Resolve (gen_params, null);
+
+ if (impl_list == null)
+ return;
+
+ foreach (IClassRef impl in impl_list) {
+ gtr = impl as IGenericTypeRef;
+ if (gtr != null)
+ gtr.Resolve (gen_params, null);
+ }
+ }
+
public void Define (CodeGen code_gen)
{
if (is_defined)
private string sig_mod;
private PEAPI.Type type;
private bool is_valuetype;
- private Hashtable genericinst_table;
private Hashtable p_genericinst_table;
private bool is_resolved;
public GenericTypeInst GetGenericTypeInst (GenericArguments gen_args)
{
- string sig = gen_args.ToString ();
- GenericTypeInst gtri = null;
-
- if (genericinst_table == null)
- genericinst_table = new Hashtable ();
- else
- gtri = genericinst_table [sig] as GenericTypeInst;
-
- if (gtri == null) {
- gtri = new GenericTypeInst (this, gen_args, is_valuetype);
- genericinst_table [sig] = gtri;
- }
-
- return gtri;
+ return new GenericTypeInst (this, gen_args, is_valuetype);
}
public PEAPI.Type ResolveInstance (CodeGen code_gen, GenericArguments gen_args)
+2006-01-10 Ankit Jain <jankit@novell.com>
+
+ * gen-meth1.il: New. Test for use of VAR/MVAR by name (!!A)
+ * gen-meth2.il: New. Test for using VAR/MVAR as class ref.
+
2006-01-09 Ankit Jain <jankit@novell.com>
* gen-recur.il: New. Test for a class implementing a generic interface
implements class IGen`1<!0>, class IFen`1<!1>, ISimple {
}
+
+ /* Inherits a generic base class and implements generic interfaces,
+ but uses !A (type param name) instead of index */
+ .class private auto ansi beforefieldinit badname`2<A,B>
+ extends class cbase`1<!B>
+ implements class IGen`1<!A>, class IFen`1<!B>, ISimple {
+
+ }
implements class [one]If1`1<!0>, class [one]If2`1<!1>, ISimple, [one]If3 {
}
+
+ .class private auto ansi beforefieldinit badname`2<A,B>
+ extends class [one]gen`1<!A>
+ implements class [one]If1`1<!A>, class [one]If2`1<!B>, ISimple, [one]If3 {
+
+ }
--- /dev/null
+// Test: Use of !!A, gen param ref by name in method signature,
+// or in constraints
+
+.assembly extern mscorlib
+{
+ .ver 2:0:0:0
+}
+.assembly 'gen-meth1'
+{
+ .custom instance void class [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = (
+ 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx
+ 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows.
+
+ .ver 0:0:0:0
+}
+.module meth1.dll
+
+ .class interface private auto ansi abstract IFoo`1<A>
+ {
+ }
+
+ .class private auto ansi beforefieldinit g`1<T>
+ extends [mscorlib]System.Object
+ {
+
+ .method public hidebysig specialname rtspecialname
+ instance default void .ctor () cil managed
+ {
+ .maxstack 8
+ IL_0000: ldarg.0
+ IL_0001: call instance void object::.ctor()
+ IL_0006: ret
+ }
+
+ .method public static hidebysig
+ default !!A foo<(class g`1<!!B>)A,B> (!!B _b, !T _t, !!A _a) cil managed
+ {
+ .maxstack 1
+ .locals init (
+ !!A V_0)
+ IL_0000: ldloca.s 0
+ IL_0002: initobj !!0
+ IL_0008: ldloc.0
+ IL_0009: ret
+ }
+
+ .method public static hidebysig
+ default void meth1 () cil managed
+ {
+ .maxstack 4
+ .locals init (
+ !T V_0,
+ !T[] V_1)
+ IL_0000: ldtoken !T
+ IL_0005: call class [mscorlib]System.Type class [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
+ IL_000a: call object class [mscorlib]System.Activator::CreateInstance(class [mscorlib]System.Type)
+ IL_000f: unbox.any !0
+ IL_0014: stloc.0
+ IL_0015: ldc.i4.5
+ IL_0016: newarr !0
+ IL_001b: stloc.1
+ IL_001c: ret
+ }
+ }
+
--- /dev/null
+// Test : Using VAR/MVAR as class ref
+// Eg. !!B as a constraint
+
+.assembly extern mscorlib
+{
+ .ver 2:0:0:0
+}
+.assembly 'gen-meth2'
+{
+ .custom instance void class [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = (
+ 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx
+ 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows.
+
+ .ver 0:0:0:0
+}
+.module meth2.dll
+
+
+ /* Incorrect, meaning-less code, but this is just to
+ check support for using VAR/MVAR as class refs */
+ .class private auto ansi beforefieldinit g`1<T>
+ extends !T
+ implements !T
+ {
+
+ .method public hidebysig specialname rtspecialname
+ instance default void .ctor () cil managed
+ {
+ .maxstack 8
+ IL_0000: ldarg.0
+ IL_0001: call instance void object::.ctor()
+ IL_0006: ret
+ }
+
+ /* Using !!B as a constraint */
+ .method public static hidebysig
+ default !!A foo< (!!B) A,B> (!!B _b, !T _t, !!A _a) cil managed
+ {
+ .maxstack 1
+ .locals init (
+ !!A V_0)
+ IL_0000: ldloca.s 0
+ IL_0002: initobj !!0
+ IL_0008: ldloc.0
+ IL_0009: ret
+ }
+
+ }
+