dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[dotgnu-pnet-commits] pnet ChangeLog engine/cvm.h engine/cvm_call.c e...


From: Ivan de Jesus Deras Tabora
Subject: [dotgnu-pnet-commits] pnet ChangeLog engine/cvm.h engine/cvm_call.c e...
Date: Fri, 14 Sep 2007 00:55:43 +0000

CVSROOT:        /sources/dotgnu-pnet
Module name:    pnet
Changes by:     Ivan de Jesus Deras Tabora <iderashn>   07/09/14 00:55:43

Modified files:
        .              : ChangeLog 
        engine         : cvm.h cvm_call.c cvmc.c cvmc_call.c layout.c 
                         lib_type.c verify.c verify_call.c verify_obj.c 
                         verify_ptr.c 
        image          : Makefile.am class.c generic.c member.c 
                         meta_types.c program.h 
        include        : il_program.h 

Log message:
        Initial generics support

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pnet/ChangeLog?cvsroot=dotgnu-pnet&r1=1.3495&r2=1.3496
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/cvm.h?cvsroot=dotgnu-pnet&r1=1.56&r2=1.57
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/cvm_call.c?cvsroot=dotgnu-pnet&r1=1.92&r2=1.93
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/cvmc.c?cvsroot=dotgnu-pnet&r1=1.56&r2=1.57
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/cvmc_call.c?cvsroot=dotgnu-pnet&r1=1.37&r2=1.38
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/layout.c?cvsroot=dotgnu-pnet&r1=1.45&r2=1.46
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/lib_type.c?cvsroot=dotgnu-pnet&r1=1.53&r2=1.54
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/verify.c?cvsroot=dotgnu-pnet&r1=1.52&r2=1.53
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/verify_call.c?cvsroot=dotgnu-pnet&r1=1.58&r2=1.59
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/verify_obj.c?cvsroot=dotgnu-pnet&r1=1.31&r2=1.32
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/verify_ptr.c?cvsroot=dotgnu-pnet&r1=1.22&r2=1.23
http://cvs.savannah.gnu.org/viewcvs/pnet/image/Makefile.am?cvsroot=dotgnu-pnet&r1=1.18&r2=1.19
http://cvs.savannah.gnu.org/viewcvs/pnet/image/class.c?cvsroot=dotgnu-pnet&r1=1.38&r2=1.39
http://cvs.savannah.gnu.org/viewcvs/pnet/image/generic.c?cvsroot=dotgnu-pnet&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/pnet/image/member.c?cvsroot=dotgnu-pnet&r1=1.32&r2=1.33
http://cvs.savannah.gnu.org/viewcvs/pnet/image/meta_types.c?cvsroot=dotgnu-pnet&r1=1.19&r2=1.20
http://cvs.savannah.gnu.org/viewcvs/pnet/image/program.h?cvsroot=dotgnu-pnet&r1=1.26&r2=1.27
http://cvs.savannah.gnu.org/viewcvs/pnet/include/il_program.h?cvsroot=dotgnu-pnet&r1=1.59&r2=1.60

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/ChangeLog,v
retrieving revision 1.3495
retrieving revision 1.3496
diff -u -b -r1.3495 -r1.3496
--- ChangeLog   13 Sep 2007 18:47:45 -0000      1.3495
+++ ChangeLog   14 Sep 2007 00:55:41 -0000      1.3496
@@ -1,4 +1,40 @@
 2007-09-11  Ivan de Jesus Deras Tabora  <address@hidden>
+       * engine/cvm.h: Define the new cvm opcode COP_PREFIX_CALL_VIRTGEN to
+       call a instance of a virtual generic method.
+       * engine/cvm_call.c Implementing the new opcode COP_PREFIX_CALL_VIRTGEN.
+       * engine/cvmc.c Added a new include il_program.h
+       * engine/cvmc_call.c CVMCoder_CallVirtual now handle virtual generic 
method instances.
+       * engine/layout.c LayoutClass now handles classes that inherits or 
implements generic 
+       classes or interfaces.
+       * engine/lib_type.c NameOutputClassName now handles generic instance 
classes.
+       * engine/verify.c Handling of generic local variables in methods.
+       * engine/verify_call.c GetMethodToken handles generic method references.
+       * engine/verify_obj.c GetFieldToken now handles generic field 
references.
+       * engine/verify_ptr.c GetClassToken now handles generic class 
references.
+       * image/class.c Set the class name when creating a wrapper.
+       * image/generic.c Split of the code into two different files: 
generic_member.c for
+       functions related to generic class members and generic_class.c for 
functions related to 
+       generic classes.
+       * image/generic_member.c New file for functions related to generic 
member classes.
+       * image/generic_class.c New file for functions related to generic 
classes.
+       * image/member.c ILMemberAccessible now handles generic members.
+       * image/meta_types.c ILGetEnumType now handles generic enum types.
+       * image/program.h Added a new define for the initial size of the method 
vtable.
+       Added two new structures ILMethodVTableItem and ILMethodVTable to 
support dynamic
+       vtables for virtual generic methods.
+       Added a new member to the ILMethod struct to support vtables in methods.
+       Added a new struct ILMethodInstance that represent a method instance.
+       * include/il_program.h Added a new typedef for ILMethodInstance.
+       ILClassInstantiate now receive the method type arguments as parameter.
+       Added function prototypes for the following functions: 
ILClassGetTypeArguments,
+       ILClassGetGenericDef, ILClassExpand, ILClassIsExpanded, 
ILClassResolveToInstance,
+       ILClassLookupMethodInstance, ILMemberResolveToInstance, 
ILMethodSpecToMethod,
+       ILMethodSetVirtualAncestor, ILMethodGetInstance, ILMethodAddInstance,
+       ILMethodGetClassTypeArguments, ILMethodGetMethodTypeArguments.
+       Added the following macros ILMember_IsGenericInstance, 
ILMethod_IsVirtualGeneric,
+       ILClass_IsGenericInstance
+       * image/Makefile.am added new source files generic_member.c and 
generic_class.c
+2007-09-11  Ivan de Jesus Deras Tabora  <address@hidden>
        * engine/cvm_stack.c Fixed CVM documentation for COP_PREFIX_REPL_WORD_N.
        * engine/verify_call.c Constrained callvirt for value types should be 
handled as
        a normal call (non virtual).

Index: engine/cvm.h
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/engine/cvm.h,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -b -r1.56 -r1.57
--- engine/cvm.h        17 Aug 2007 19:18:26 -0000      1.56
+++ engine/cvm.h        14 Sep 2007 00:55:42 -0000      1.57
@@ -582,6 +582,11 @@
 #define COP_PREFIX_REPL_WORD_N                 0x8D
 
 /*
+* Used to called an instance of a virtual generic method.
+*/
+#define COP_PREFIX_CALL_VIRTGEN                        0x8E
+
+/*
  * Definition of a CVM stack word which can hold
  * either 32-bit quantities or pointers.
  */

Index: engine/cvm_call.c
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/engine/cvm_call.c,v
retrieving revision 1.92
retrieving revision 1.93
diff -u -b -r1.92 -r1.93
--- engine/cvm_call.c   23 Dec 2005 15:11:11 -0000      1.92
+++ engine/cvm_call.c   14 Sep 2007 00:55:42 -0000      1.93
@@ -1905,6 +1905,116 @@
 VMBREAK(COP_PREFIX_TAIL_CALLINTF);
 
 /**
+ * <opcode name="call_virtual_generic" group="Call management instructions">
+ *   <operation>Call a virtual generic method instance</operation>
+ *
+ *   <format>call_virtual_generic<fsep/>N[1]<fsep/>M[1]</format>
+ *   <format>wide<fsep/>call_virtual_generic<fsep/>N[4]<fsep/>M[4]</format>
+ *   <dformat>{call_virtual_generic}<fsep/>N<fsep/>M</dformat>
+ *
+ *   <form name="call_virtual_generic" code="COP_PREFIX_CALL_VIRTGEN"/>
+ *
+ *   <description>The <i>call_virtual_generic</i> instruction effects a
+ *   virtual generic method instance call.  The value <i>N</i> indicates the
+ *   position of the <code>this</code> pointer on the stack:
+ *   1 indicates the top of stack, 2 indicates the stack word
+ *   just below the top-most stack word, etc.  The value <i>M</i>
+ *   is the offset into the generic method vtable for the method 
instance.</description>
+ *
+ *   <notes>See the description of the <i>call</i> instruction for
+ *   a full account of frame handling, argument handling, etc.</notes>
+ *
+ *   <exceptions>
+ *     <exception name="System.NullReferenceException">Raised if
+ *     the <code>this</code> pointer is <code>null</code>.</exception>
+ *     <exception name="System.Security.VerificationException">Raised if
+ *     the method could not be translated into CVM bytecode.</exception>
+ *   </exceptions>
+ * </opcode>
+ */
+VMCASE(COP_PREFIX_CALL_VIRTGEN):
+{
+       /* Call a virtual method */
+       tempptr = stacktop[-((ILInt32)CVM_ARG_DWIDE1_SMALL)].ptrValue;
+       BEGIN_NULL_CHECK(tempptr)
+       {
+               /* Locate the method to be called */
+               tempNum = CVM_ARG_DWIDE2_SMALL;
+               methodToCall = (GetObjectClassPrivate(tempptr))
+                                                       ->vtable[tempNum & 
0xFFFF];
+               if(methodToCall)
+               {
+                       methodToCall = ILMethodGetInstance(methodToCall, 
((tempNum >> 16) & 0xFFFF));
+                       if(!methodToCall)
+                       {
+                               MISSING_METHOD_EXCEPTION();
+                       }
+               }
+               else
+               {
+                       MISSING_METHOD_EXCEPTION();
+               }
+
+               /* Has the method already been converted? */
+               if(methodToCall->userData)
+               {
+                       /* It is converted: allocate a new call frame */
+                       ALLOC_CALL_FRAME();
+
+                       /* Fill in the call frame details */
+                       callFrame->method = method;
+                       callFrame->pc = CVM_ARG_CALLV_RETURN_SMALL(pc);
+                       callFrame->frame = frame;
+                       callFrame->exceptHeight = thread->exceptHeight;
+                       callFrame->permissions = 0;
+                       DO_PROFILE_START();
+
+                       /* Pass control to the new method */
+                       pc = (unsigned char *)(methodToCall->userData);
+                       method = methodToCall;
+                       CVM_OPTIMIZE_BLOCK();
+               }
+               else
+               {
+                       /* Copy the state back into the thread object */
+                       COPY_STATE_TO_THREAD();
+
+                       /* Convert the method */
+                       BEGIN_NATIVE_CALL();
+
+                       IL_CONVERT_METHOD(tempptr, thread, methodToCall);
+                       if(!tempptr)
+                       {
+                               END_NATIVE_CALL();
+
+                               CONVERT_FAILED_EXCEPTION();
+                       }
+
+                       END_NATIVE_CALL();
+
+                       /* Allocate a new call frame */
+                       ALLOC_CALL_FRAME();
+
+                       /* Fill in the call frame details */
+                       callFrame->method = method;
+                       callFrame->pc = CVM_ARG_CALLV_RETURN_SMALL(thread->pc);
+                       callFrame->frame = thread->frame;
+                       callFrame->exceptHeight = thread->exceptHeight;
+                       callFrame->permissions = 0;
+                       DO_PROFILE_START();
+
+                       /* Restore the state information and jump to the new 
method */
+                       RESTORE_STATE_FROM_THREAD();
+                       pc = (unsigned char *)tempptr;
+                       method = methodToCall;
+                       CVM_OPTIMIZE_BLOCK();
+               }
+       }
+       END_NULL_CHECK();
+}
+VMBREAK(COP_PREFIX_CALL_VIRTGEN);
+
+/**
  * <opcode name="ldftn" group="Call management instructions">
  *   <operation>Load the address of a function method onto the 
stack</operation>
  *

Index: engine/cvmc.c
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/engine/cvmc.c,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -b -r1.56 -r1.57
--- engine/cvmc.c       17 Aug 2007 19:18:26 -0000      1.56
+++ engine/cvmc.c       14 Sep 2007 00:55:42 -0000      1.57
@@ -22,6 +22,7 @@
 #include "il_coder.h"
 #include "il_opcodes.h"
 #include "il_utils.h"
+#include "il_program.h"
 #ifdef IL_DEBUGGER
 #include "debugger.h"
 #endif

Index: engine/cvmc_call.c
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/engine/cvmc_call.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -b -r1.37 -r1.38
--- engine/cvmc_call.c  11 Feb 2007 14:34:32 -0000      1.37
+++ engine/cvmc_call.c  14 Sep 2007 00:55:42 -0000      1.38
@@ -136,17 +136,37 @@
                                                                 ILMethod 
*methodInfo)
 {
        ILUInt32 argSize = ComputeStackSize(coder, info->args, 
info->numBaseArgs);
+       ILUInt32 index = methodInfo->index;
+       int isVirtualGenericCall = 0;
        if(info->hasParamArray)
        {
                ++argSize;
        }
+       if(ILMember_IsGenericInstance(methodInfo))
+       {
+               if(ILMethod_IsVirtualGeneric(methodInfo))
+               {
+                       ILMethodInstance *methodInst = (ILMethodInstance 
*)methodInfo;
+
+                       /* This is an instance of a virtual generic method. */
+                       index = (index << 16) | methodInst->genMethod->index;
+                       isVirtualGenericCall = 1;
+               }
+       }
+       if(isVirtualGenericCall)
+       {
+               CVMP_OUT_WORD2(COP_PREFIX_CALL_VIRTGEN, argSize, index);
+       }
+       else
+       {
        if(info->tailCall)
        {
-               CVMP_OUT_WORD2(COP_PREFIX_TAIL_CALLVIRT, argSize, 
methodInfo->index);
+                       CVMP_OUT_WORD2(COP_PREFIX_TAIL_CALLVIRT, argSize, 
index);
        }
        else
        {
-               CVM_OUT_DWIDE(COP_CALL_VIRTUAL, argSize, methodInfo->index);
+                       CVM_OUT_DWIDE(COP_CALL_VIRTUAL, argSize, index);
+               }
        }
        AdjustForCall(coder, info, returnItem);
 }

Index: engine/layout.c
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/engine/layout.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -b -r1.45 -r1.46
--- engine/layout.c     1 Jan 2007 17:09:40 -0000       1.45
+++ engine/layout.c     14 Sep 2007 00:55:42 -0000      1.46
@@ -1154,6 +1154,17 @@
        {
                /* Use "ILClassGetParent" to resolve cross-image links */
                parent = ILClassGetParent(info);
+               if(ILClassNeedsExpansion(parent))
+               {
+                       /* This can happen when a non-generic class inherits 
from a generic class */
+                       parent = ILClassExpand(ILClassToImage(info), parent, 
ILClassToType(parent), 0);
+                       if(!parent)
+                       {
+                               info->userData = 0;
+                               return 0;
+                       }
+                       info->parent = parent;
+               }
                if(!LayoutClass(process, parent, layout))
                {
                        info->userData = 0;
@@ -1184,7 +1195,25 @@
        implements = info->implements;
        while(implements != 0)
        {
-               if(!LayoutClass(process, ILClassResolve(implements->interface), 
&typeLayout))
+               ILClass *interface = implements->interface;
+
+               if(ILClassNeedsExpansion(interface))
+               {
+                       /* This can happen when a non-generic class implements 
a generic interface */
+                       interface = ILClassExpand(ILClassToImage(info), 
interface,
+                                                                         
ILClassToType(interface), 0);
+                       if(!interface)
+                       {
+                               info->userData = 0;
+                               return 0;
+                       }
+                       implements->interface = interface;
+               }
+               else
+               {
+                       interface = ILClassResolve(interface);
+               }
+               if(!LayoutClass(process, interface, &typeLayout))
                {
                        info->userData = 0;
                        return 0;
@@ -1455,11 +1484,22 @@
                        /* Allocate a vtable slot */
                        method->index = layout->vtableSize;
                        ++(layout->vtableSize);
+                       /* Initialize the metod vtable if this is a generic 
method */
+                       if(!ILMethodSetVirtualAncestor(method, ancestor))
+                       {
+                               info->userData = 0;
+                               return 0;
+                       }
                }
                else
                {
                        /* Find the method in an ancestor class that this one 
overrides */
                        ancestor = FindVirtualAncestor(info, parent, method);
+                       if(!ILMethodSetVirtualAncestor(method, ancestor))
+                       {
+                               info->userData = 0;
+                               return 0;
+                       }
                        if(ancestor)
                        {
                                /* Use the same index as the ancestor */

Index: engine/lib_type.c
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/engine/lib_type.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -b -r1.53 -r1.54
--- engine/lib_type.c   17 Dec 2006 10:31:32 -0000      1.53
+++ engine/lib_type.c   14 Sep 2007 00:55:42 -0000      1.54
@@ -1183,8 +1183,18 @@
                                                                   int 
fullyQualified)
 {
        ILClass *nestedParent;
+       ILClass *info;
        ILInt32 len;
        const char *namespace;
+       if(ILClass_IsGenericInstance(classInfo))
+       {
+               info = classInfo;
+               classInfo = ILClassGetGenericDef(classInfo);
+       }
+       else
+       {
+               info = 0;
+       }
        if(fullyQualified)
        {
                nestedParent = ILClass_NestedParent(classInfo);
@@ -1228,12 +1238,64 @@
        }
        if(buf != 0)
        {
-               return len + NameOutputString(buf + len, 
ILClass_Name(classInfo), 1);
+               len += NameOutputString(buf + len, ILClass_Name(classInfo), 1);
+       }
+       else
+       {
+               len += NameOutputString(0, ILClass_Name(classInfo), 1);
+       }
+       if(info)
+       {
+               int numParams, posn;
+               ILType *type;
+               ILType *subType;
+
+               type = ILClassGetTypeArguments(info);
+               if(buf != 0)
+               {
+                       buf[len++] = (ILUInt16)'[';
+               }
+               else
+               {
+                       ++len;
+               }
+               numParams = ILTypeNumWithParams(type);
+               for(posn = 1; posn <= numParams; posn++)
+               {
+                       if(posn != 1)
+                       {
+                               if(buf != 0)
+                               {
+                                       buf[len++] = (ILUInt16)',';
+                               }
+                               else
+                               {
+                                       ++len;
+                               }
+                       }
+                       subType = ILTypeGetWithParamWithPrefixes(type, posn);
+                       classInfo = ILClassFromType(ILClassToImage(info),
+                                                                               
0, subType, 0);
+                       if(buf != 0)
+                       {
+                               len += NameOutputClassName(buf + len, 
classInfo, fullyQualified);
        }
        else
        {
-               return len + NameOutputString(0, ILClass_Name(classInfo), 1);
+                               len += NameOutputClassName(0, classInfo, 
fullyQualified);
+                       }
        }
+               if(buf != 0)
+               {
+                       buf[len++] = (ILUInt16)']';
+               }
+               else
+               {
+                       ++len;
+               }               
+       }
+
+       return len;
 }
 
 /*

Index: engine/verify.c
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/engine/verify.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -b -r1.52 -r1.53
--- engine/verify.c     18 Aug 2007 12:29:32 -0000      1.52
+++ engine/verify.c     14 Sep 2007 00:55:42 -0000      1.53
@@ -1027,6 +1027,17 @@
        {
                localVars = ILStandAloneSigGetType(code->localVarSig);
                numLocals = ILTypeNumLocals(localVars);
+               if(ILTypeNeedsInstantiation(localVars) &&
+                  ILMember_IsGenericInstance(method))
+               {
+                       ILType *classTypeArgs = 
ILMethodGetClassTypeArguments(method);
+                       ILType *methodTypeArgs = 
ILMethodGetMethodTypeArguments(method);
+
+                       localVars = 
ILTypeInstantiate(ILImageToContext(ILProgramItem_Image(method)),
+                                                                               
  localVars,
+                                                                               
  classTypeArgs, 
+                                                                               
  methodTypeArgs);
+               }
        }
        else
        {

Index: engine/verify_call.c
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/engine/verify_call.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -b -r1.58 -r1.59
--- engine/verify_call.c        13 Sep 2007 18:47:45 -0000      1.58
+++ engine/verify_call.c        14 Sep 2007 00:55:42 -0000      1.59
@@ -380,6 +380,18 @@
                token = IL_READ_UINT32(pc + 2);
        }
 
+       if((token & IL_META_TOKEN_MASK) == IL_META_TOKEN_METHOD_SPEC)
+       {
+               ILMethodSpec *mspec = 
ILMethodSpec_FromToken(ILProgramItem_Image(method), token);
+
+               if(!mspec)
+               {
+                       return 0;
+               }
+               methodInfo = ILMethodSpecToMethod(mspec, method);
+       }
+       else
+       {
        /* Get the token and resolve it */
        methodInfo = ILProgramItemToMethod((ILProgramItem *)
                                                
ILImageTokenInfo(ILProgramItem_Image(method), token));
@@ -387,7 +399,12 @@
        {
                return 0;
        }
-       methodInfo = (ILMethod *)ILMemberResolve((ILMember *)methodInfo);
+               methodInfo = (ILMethod *)ILMemberResolveToInstance((ILMember 
*)methodInfo, method);
+       }
+       if(!methodInfo)
+       {
+               return 0;
+       }
 
        /* Make sure that the method's class has been laid out */
        if(!_ILLayoutClass(process, ILMethod_Owner(methodInfo)))

Index: engine/verify_obj.c
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/engine/verify_obj.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -b -r1.31 -r1.32
--- engine/verify_obj.c 13 Sep 2007 18:47:45 -0000      1.31
+++ engine/verify_obj.c 14 Sep 2007 00:55:42 -0000      1.32
@@ -45,7 +45,11 @@
        {
                return 0;
        }
-       fieldInfo = (ILField *)ILMemberResolve((ILMember *)fieldInfo);
+       fieldInfo = (ILField *)ILMemberResolveToInstance((ILMember *)fieldInfo, 
method);
+       if(!fieldInfo)
+       {
+               return 0;
+       }
 
        /* Check the accessibility of the field */
        if(!ILMemberAccessible((ILMember *)fieldInfo, ILMethod_Owner(method)))

Index: engine/verify_ptr.c
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/engine/verify_ptr.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- engine/verify_ptr.c 13 Sep 2007 18:47:46 -0000      1.22
+++ engine/verify_ptr.c 14 Sep 2007 00:55:42 -0000      1.23
@@ -204,13 +204,12 @@
                ((ILProgramItem *)ILImageTokenInfo(ILProgramItem_Image(method), 
token));
        if(classInfo)
        {
-               classInfo = ILClassResolve(classInfo);
+               classInfo = ILClassResolveToInstance(classInfo, method);
        }
        if(!classInfo || ILClassIsRef(classInfo))
        {
                return 0;
        }
-
        /* Check the accessibility of the class */
        if(!ILClassAccessible(classInfo, ILMethod_Owner(method)))
        {

Index: image/Makefile.am
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/image/Makefile.am,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- image/Makefile.am   21 Aug 2005 15:33:24 -0000      1.18
+++ image/Makefile.am   14 Sep 2007 00:55:42 -0000      1.19
@@ -16,6 +16,8 @@
                                           debug_writer.c \
                                           errors.c \
                                           generic.c \
+                                          generic_member.c \
+                                          generic_class.c \
                                           image.c \
                                           image.h \
                                           item.c \

Index: image/class.c
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/image/class.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -b -r1.38 -r1.39
--- image/class.c       10 Sep 2007 19:16:42 -0000      1.38
+++ image/class.c       14 Sep 2007 00:55:43 -0000      1.39
@@ -328,6 +328,17 @@
        /* Set the synthetic type */
        info->synthetic = type;
 
+       /* Set the class name */
+    if(ILType_IsWith(type))
+    {
+                       ILClass *classInfo = 
ILType_ToClass(ILTypeGetWithMainWithPrefixes(type));
+            info->className = classInfo->className;
+    }
+       else
+       {
+               info->className = 0;
+       }
+
        info->parent = 0;
        info->ext = 0;
 

Index: image/generic.c
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/image/generic.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- image/generic.c     13 Sep 2007 18:47:46 -0000      1.9
+++ image/generic.c     14 Sep 2007 00:55:43 -0000      1.10
@@ -481,7 +481,7 @@
                        }
                        else
                        {
-                               return 0;
+                               return type;
                        }
                }
                /* Not reached */
@@ -541,262 +541,6 @@
        return type;
 }
 
-/*
- * Expand a class reference.
- */
-static ILClass *ExpandClass(ILImage *image, ILClass *classInfo,
-                                                       ILType *classParams)
-{
-       ILType *type = ILClassToType(classInfo);
-       return ILClassInstantiate(image, type, classParams);
-}
-
-/*
- * Expand the instantiations in a class.  Returns zero if out of memory.
- */
-static int ExpandInstantiations(ILImage *image, ILClass *classInfo,
-                                                               ILType 
*classType, ILType *classParams)
-{
-       ILClass *origClass;
-       ILMember *member;
-       ILMethod *newMethod;
-       ILField *newField;
-       ILType *signature;
-       ILImplements *impl;
-       ILClass *tempInfo;
-
-       /* Mark this class as being expanded, to deal with circularities */
-       classInfo->attributes |= IL_META_TYPEDEF_CLASS_EXPANDED;
-
-       /* Bail out if not a "with" type, since the instantiation would
-          have already been taken care of by "ILClassFromType" */
-       if(!ILType_IsWith(classType))
-       {
-               return 1;
-       }
-
-       /* Find the original class underlying the type */
-       origClass = ILClassFromType(image, 0, ILTypeGetWithMain(classType), 0);
-       if(!origClass)
-       {
-               return 0;
-       }
-       origClass = ILClassResolve(origClass);
-
-       /* Remember the original class so we can find it again later */
-       classInfo->ext = (ILClassExt *)origClass;
-
-       /* Copy across the class attributes */
-       ILClassSetAttrs(classInfo, ~((ILUInt32)0), ILClass_Attrs(origClass));
-
-       /* Expand the parent class and interfaces */
-       if(origClass->parent)
-       {
-               classInfo->parent = ExpandClass
-                       (image, ILClass_Parent(origClass), classParams);
-               if(!(classInfo->parent))
-               {
-                       return 0;
-               }
-       }
-       impl = 0;
-       while((impl = ILClassNextImplements(origClass, impl)) != 0)
-       {
-               tempInfo = ILImplementsGetInterface(impl);
-               tempInfo = ExpandClass(image, tempInfo, classParams);
-               if(!tempInfo)
-               {
-                       return 0;
-               }
-               if(!ILClassAddImplements(classInfo, tempInfo, 0))
-               {
-                       return 0;
-               }
-       }
-
-       /* Expand the methods and fields */
-       member = 0;
-       while((member = ILClassNextMember(origClass, member)) != 0)
-       {
-               switch(ILMemberGetKind(member))
-               {
-                       case IL_META_MEMBERKIND_METHOD:
-                       {
-                               /* Skip static methods, which are shared */
-                               if(ILMethod_IsStatic((ILMethod *)member))
-                               {
-                                       break;
-                               }
-
-                               /* Create a new method */
-                               newMethod = ILMethodCreate(classInfo, 0,
-                                                                               
   ILMember_Name(member),
-                                                                               
   ILMember_Attrs(member));
-                               if(!newMethod)
-                               {
-                                       return 0;
-                               }
-
-                               /* Copy the original method's properties */
-                               signature = ILTypeInstantiate
-                                       (image->context, 
ILMember_Signature(member),
-                                        classParams, 0);
-                               if(!signature)
-                               {
-                                       return 0;
-                               }
-                               ILMethodSetImplAttrs
-                                       (newMethod, ~((ILUInt32)0),
-                                        ILMethod_ImplAttrs((ILMethod 
*)member));
-                               ILMethodSetCallConv
-                                       (newMethod, ILMethod_CallConv((ILMethod 
*)member));
-                               ILMethodSetRVA(newMethod, 
ILMethod_RVA((ILMethod *)member));
-
-                               /* Remember the mapping, so we can resolve 
method references */
-                               newMethod->userData = (void *)member;
-
-                               /* Copy the original method's parameter blocks 
*/
-                               /* TODO */
-                       }
-                       break;
-
-                       case IL_META_MEMBERKIND_FIELD:
-                       {
-                               /* Skip static fields, which are shared */
-                               if(ILField_IsStatic((ILField *)member))
-                               {
-                                       break;
-                               }
-
-                               /* Create a new field */
-                               newField = ILFieldCreate(classInfo, 0,
-                                                                               
 ILMember_Name(member),
-                                                                               
 ILMember_Attrs(member));
-                               if(!newField)
-                               {
-                                       return 0;
-                               }
-
-                               /* Copy the original field's properties */
-                               signature = ILTypeInstantiate
-                                       (image->context, 
ILMember_Signature(member),
-                                        classParams, 0);
-                               if(!signature)
-                               {
-                                       return 0;
-                               }
-                       }
-                       break;
-               }
-       }
-
-       /* Expand the properties, events, overrides, and pinvokes */
-       member = 0;
-       while((member = ILClassNextMember(origClass, member)) != 0)
-       {
-               switch(ILMemberGetKind(member))
-               {
-                       case IL_META_MEMBERKIND_PROPERTY:
-                       {
-                               /* TODO */
-                       }
-                       break;
-
-                       case IL_META_MEMBERKIND_EVENT:
-                       {
-                               /* TODO */
-                       }
-                       break;
-
-                       case IL_META_MEMBERKIND_OVERRIDE:
-                       {
-                               /* TODO */
-                       }
-                       break;
-
-                       case IL_META_MEMBERKIND_PINVOKE:
-                       {
-                               /* TODO */
-                       }
-                       break;
-               }
-       }
-
-       /* Clear the "userData" fields on the new methods, because
-          we don't need them any more */
-       member = 0;
-       while((member = ILClassNextMemberByKind
-                               (classInfo, member, IL_META_MEMBERKIND_METHOD)) 
!= 0)
-       {
-               ((ILMethod *)member)->userData = 0;
-       }
-
-       /* Done */
-       return 1;
-}
-
-ILClass *ILClassInstantiate(ILImage *image, ILType *classType,
-                                                       ILType *classParams)
-{
-       ILClass *classInfo;
-       ILType *type;
-
-       /* Bail out early if the type does not need instantiation */
-       if(!ILTypeNeedsInstantiation(classType))
-       {
-               return ILClassFromType(image, 0, classType, 0);
-       }
-
-       /* Search for a synthetic type that matches the expanded
-          form of the class type, in case we already instantiated
-          this class previously.  We do this in such a way that we
-          won't need to call "ILTypeInstantiate" unless necessary */
-       classInfo = _ILTypeToSyntheticInstantiation(image, classType, 
classParams, 0);
-       if(classInfo)
-       {
-               if((classInfo->attributes & IL_META_TYPEDEF_CLASS_EXPANDED) == 
0)
-               {
-                       if(!ExpandInstantiations(image, classInfo, classType, 
classParams))
-                       {
-                               return 0;
-                       }
-               }
-               return classInfo;
-       }
-
-       /* Instantiate the class type */
-       type = ILTypeInstantiate(image->context, classType, classParams, 0);
-       if(!type)
-       {
-               return 0;
-       }
-
-       /* Create a synthetic type for the expanded form */
-       classInfo = ILClassFromType(image, 0, type, 0);
-       if(!classInfo)
-       {
-               return 0;
-       }
-       if(!ExpandInstantiations(image, classInfo, type, classParams))
-       {
-               return 0;
-       }
-       return classInfo;
-}
-
-ILClass *ILClassGetUnderlying(ILClass *info)
-{
-       ILType *synType = info->synthetic;
-       if(ILType_IsWith(synType))
-       {
-               synType = ILTypeGetWithMain(synType);
-               return ILClassFromType(info->programItem.image, 0, synType, 0);
-       }
-       else
-       {
-               return info;
-       }
-}
 
 #ifdef __cplusplus
 };

Index: image/member.c
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/image/member.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -b -r1.32 -r1.33
--- image/member.c      10 Sep 2007 19:16:42 -0000      1.32
+++ image/member.c      14 Sep 2007 00:55:43 -0000      1.33
@@ -64,6 +64,16 @@
        ILClass *info = member->owner;
        ILMethod *accessor;
        scope = (ILClass *)(_ILProgramItemResolve(&(scope->programItem)));
+       /* FIXME: This is not really correct */
+       if (ILClass_IsGenericInstance(info))
+       {
+               info = ILClassGetGenericDef(info);
+       }
+       /* FIXME: This is not really correct */
+       if (ILClass_IsGenericInstance(scope))
+       {
+               scope = ILClassGetGenericDef(scope);
+       }
        if(!ILClassAccessible(info, scope))
        {
                return 0;
@@ -526,6 +536,7 @@
        method->callingConventions = 0;
        method->rva = 0;
        method->parameters = 0;
+       method->vtable = 0;
 
        /* Return the block to the caller */
        return method;

Index: image/meta_types.c
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/image/meta_types.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- image/meta_types.c  13 Sep 2007 18:47:46 -0000      1.19
+++ image/meta_types.c  14 Sep 2007 00:55:43 -0000      1.20
@@ -979,9 +979,29 @@
 
 ILType *ILTypeGetEnumType(ILType *type)
 {
-       if(ILType_IsValueType(type))
+       ILClass *classInfo = 0;
+
+       if(ILType_IsWith(type))
+       {               
+               ILType *valueType = ILTypeGetWithMain(type);
+
+               if(ILType_IsValueType(valueType))
+               {
+                       ILClass *genInfo = 
ILClassResolve(ILType_ToValueType(valueType));
+
+                       classInfo = ILClassInstantiate(ILClassToImage(genInfo), 
type, type, 0);
+                       if(!classInfo)
+                       {
+                               return 0;
+                       }
+               }
+       }
+       else if(ILType_IsValueType(type))
+       {
+               classInfo = ILClassResolve(ILType_ToValueType(type));
+       }
+       if(classInfo)
        {
-               ILClass *classInfo = ILClassResolve(ILType_ToValueType(type));
                ILClass *parent = ILClass_Parent(classInfo);
                if(parent)
                {

Index: image/program.h
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/image/program.h,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- image/program.h     15 Aug 2007 18:55:17 -0000      1.26
+++ image/program.h     14 Sep 2007 00:55:43 -0000      1.27
@@ -27,6 +27,8 @@
 extern "C" {
 #endif
 
+#define METHOD_VTABLE_ITEM_COUNT       4
+
 /*
  * Common fields for program items.
  */
@@ -342,6 +344,29 @@
 void _ILMemberSetSignatureIndex(ILMember *member, ILUInt32 index);
 
 /*
+ * Information about a generic method vtable item.
+ */
+typedef struct _tagILMethodVTableItem ILMethodVTableItem;
+struct _tagILMethodVTableItem
+{
+       ILMethod *data[METHOD_VTABLE_ITEM_COUNT];
+          ILMethodVTableItem *nextItem;
+};
+
+/*
+ * Information about a generic method vtable.
+ */
+typedef struct _tagILMethodVTable ILMethodVTable;
+struct _tagILMethodVTable
+{
+       ILMethod                        *virtualAncestor;       /* The virtual 
ancestor of the method. */
+       ILMethodVTableItem      firstItem;
+       ILMethodVTableItem      *lastItem;
+       int                                     numSlots;
+       int                                     numItems;
+};
+
+/*
  * Information about a method.
  */
 struct _tagILMethod
@@ -351,6 +376,7 @@
        ILUInt16                callingConventions;     /* Calling conventions 
for method */
        ILUInt32                rva;                            /* Address of 
the method's code */
        ILParameter    *parameters;                     /* Parameter 
definitions */
+       ILMethodVTable *vtable;                         /* VTable for generic 
methods. */
        void           *userData;                       /* User data for the 
runtime engine */
        ILUInt32                index;                          /* Data added 
by the runtime engine */
        ILUInt32                count;                          /* Profile 
count for the engine */
@@ -360,6 +386,17 @@
 };
 
 /*
+ * Information about a generic method instance.
+ */
+struct _tagILMethodInstance
+{
+       ILMethod                method;                                 /* 
Method fields */
+       ILMethod                *genMethod;                             /* 
Corresponding generic Method definition */
+       ILType                  *classTypeArguments;    /* Class type 
arguments.  */
+       ILType                  *methodTypeArguments;   /* Method type 
arguments. */
+};
+
+/*
  * Load the parameter definitions for a method token on demand.
  */
 void _ILMethodLoadParams(ILMethod *method);

Index: include/il_program.h
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/include/il_program.h,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -b -r1.59 -r1.60
--- include/il_program.h        10 Sep 2007 19:16:42 -0000      1.59
+++ include/il_program.h        14 Sep 2007 00:55:43 -0000      1.60
@@ -39,6 +39,7 @@
 typedef struct _tagILImplements                ILImplements;
 typedef struct _tagILMember                    ILMember;
 typedef struct _tagILMethod                    ILMethod;
+typedef struct _tagILMethodInstance    ILMethodInstance;
 typedef struct _tagILParameter         ILParameter;
 typedef struct _tagILField                     ILField;
 typedef struct _tagILEvent                     ILEvent;
@@ -821,7 +822,7 @@
  * if insufficient memory to perform the instantiation.
  */
 ILClass *ILClassInstantiate(ILImage *image, ILType *classType,
-                                                       ILType *classParams);
+                                                       ILType *classArgs, 
ILType *methodArgs);
 
 /*
  * Determine if a namespace is valid for a context.  A namespace
@@ -835,6 +836,76 @@
 ILClass *ILClassGetUnderlying(ILClass *info);
 
 /*
+ * Get the generic type parameters used to instantiate the class.
+ */
+ILType *ILClassGetTypeArguments(ILClass *info);
+
+/*
+ * Return the generic definition associated with the class instance.
+ * NULL is this is not a class instance.
+ */
+ILClass *ILClassGetGenericDef(ILClass *info);
+
+/*
+ * Expand a class instance.
+ */
+ILClass *ILClassExpand(ILImage *image, ILClass *classInfo,
+                                          ILType *classArgs, ILType 
*methodArgs);
+
+/*
+ * Return true is the generic class is already expanded.
+ */
+int ILClassIsExpanded(ILClass *info);
+
+/*
+ * Return a class instance corresponding to a class definition.
+ */
+ILClass *ILClassResolveToInstance(ILClass *classInfo, ILMethod *methodCaller);
+
+/*
+ * Lookup a method instance in a class instance. Return NULL if such an 
instance doesn't exist.
+ */
+ILMethod *ILClassLookupMethodInstance(ILClass *owner, const char *name,
+                                                                         
ILType *signature, ILType  *methodArgs);
+
+/*
+ * Resolve a member definition to the corresponding member instance.
+ */
+ILMember *ILMemberResolveToInstance(ILMember *member, ILMethod *methodCaller);
+
+/*
+ * Resolve a method spec to a method instance.
+ */
+ILMethod *ILMethodSpecToMethod(ILMethodSpec *mspec, ILMethod *methodCaller);
+
+/*
+ * Set the method virtual ancestor and initialize the vtable.
+ */
+int ILMethodSetVirtualAncestor(ILMethod *method, ILMethod *virtualAncestor);
+
+/*
+ * Return the corresponding method instance, or NULL if such instance doesn't 
exist.
+ */
+ILMethod *ILMethodGetInstance(ILMethod *method, int index);
+
+/*
+ * Add a method instance to the generic method vtable.
+ */
+int ILMethodAddInstance(ILMethod *method, ILMethod *instance);
+
+/*
+ * Return the class type params associated with the method instance. Return 
NULL if this
+ * isn't a generic method instance.
+ */
+ILType *ILMethodGetClassTypeArguments(ILMethod *method);
+
+/*
+ * Return the method type params associated with the method instance. Return 
NULL if this
+ * isn't a generic method instance.
+ */
+ILType *ILMethodGetMethodTypeArguments(ILMethod *method);
+
+/*
  * Helper macros for querying information about a class.
  */
 #define        ILClass_FromToken(image,token)  \
@@ -919,7 +990,8 @@
                        ((ILClassGetAttrs((info)) & IL_META_TYPEDEF_LATE_INIT) 
!= 0)
 #define        ILClass_HasRTSpecialName(info)  \
                        ((ILClassGetAttrs((info)) & 
IL_META_TYPEDEF_RT_SPECIAL_NAME) != 0)
-
+#define        ILClass_IsGenericInstance(info) \
+                       ILClassIsExpanded(info)
 /*
  * Member kinds.
  */
@@ -1015,6 +1087,8 @@
 #define        ILMember_Name(member)           (ILMemberGetName((ILMember 
*)(member)))
 #define        ILMember_Signature(member)      (ILMemberGetSignature((ILMember 
*)(member)))
 #define        ILMember_Attrs(member)          (ILMemberGetAttrs((ILMember 
*)(member)))
+#define        ILMember_IsGenericInstance(member)      \
+       ILMemberIsGenericInstance((ILMember *)(member))
 #define        ILMember_IsMethod(member)       \
        (ILMemberGetKind((ILMember *)(member)) == IL_META_MEMBERKIND_METHOD)
 #define        ILMember_IsField(member)        \
@@ -1279,7 +1353,9 @@
        ((ILMethodGetImplAttrs((method)) & IL_META_METHODIMPL_JAVA_FP_STRICT) 
!= 0)
 #define        ILMethod_IsJava(method) \
        ((ILMethodGetImplAttrs((method)) & IL_META_METHODIMPL_JAVA) != 0)
-
+#define ILMethod_IsVirtualGeneric(method) \
+       (((ILMethod_CallConv(method) & IL_META_CALLCONV_GENERIC) != 0) && \
+        ((ILMemberGetAttrs((ILMember *)(method)) & IL_META_METHODDEF_VIRTUAL) 
!= 0))
 /*
  * Create a new parameter and attach it to a method.
  * Returns NULL if out of memory.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]