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

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

[Dotgnu-pnet-commits] CVS: pnet/image generic.c,1.2,1.3 image.h,1.20,1.2


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnet/image generic.c,1.2,1.3 image.h,1.20,1.21 program.h,1.13,1.14 synthetic.c,1.9,1.10
Date: Thu, 20 Feb 2003 17:35:23 -0500

Update of /cvsroot/dotgnu-pnet/pnet/image
In directory subversions:/tmp/cvs-serv24811/image

Modified Files:
        generic.c image.h program.h synthetic.c 
Log Message:


Implement the basic parts of "ILClassInstantiate", to turn a generic class
declaration into a particular instance.


Index: generic.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/image/generic.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** generic.c   19 Feb 2003 09:48:10 -0000      1.2
--- generic.c   20 Feb 2003 22:35:21 -0000      1.3
***************
*** 482,485 ****
--- 482,728 ----
  }
  
+ /*
+  * 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);
+       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;
+ }
+ 
  #ifdef        __cplusplus
  };

Index: image.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/image/image.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -r1.20 -r1.21
*** image.h     18 Feb 2003 05:25:08 -0000      1.20
--- image.h     20 Feb 2003 22:35:21 -0000      1.21
***************
*** 503,506 ****
--- 503,513 ----
  
  /*
+  * Look up a synthetic class for an instantiated type.
+  * Returns NULL if not possible, or out of memory.
+  */
+ ILClass *_ILTypeToSyntheticInstantiation
+               (ILImage *image, ILType *type, ILType *classParams);
+ 
+ /*
   * Compact all type and member references in an image to
   * remove tokens that have been replaced with definitions.

Index: program.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/image/program.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -r1.13 -r1.14
*** program.h   18 Feb 2003 05:25:08 -0000      1.13
--- program.h   20 Feb 2003 22:35:21 -0000      1.14
***************
*** 247,251 ****
  #define       IL_META_TYPEDEF_CCTOR_ONCE              0x20000000      /* 
.cctor already done */
  #define       IL_META_TYPEDEF_GENERIC_PARS    0x10000000      /* Has generic 
parameters */
! #define       IL_META_TYPEDEF_SYSTEM_MASK             0xF0000000      /* 
System flags */
  
  /*
--- 247,252 ----
  #define       IL_META_TYPEDEF_CCTOR_ONCE              0x20000000      /* 
.cctor already done */
  #define       IL_META_TYPEDEF_GENERIC_PARS    0x10000000      /* Has generic 
parameters */
! #define       IL_META_TYPEDEF_CLASS_EXPANDED  0x08000000      /* Generics 
expanded */
! #define       IL_META_TYPEDEF_SYSTEM_MASK             0xF8000000      /* 
System flags */
  
  /*

Index: synthetic.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/image/synthetic.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** synthetic.c 19 Feb 2003 06:21:40 -0000      1.9
--- synthetic.c 20 Feb 2003 22:35:21 -0000      1.10
***************
*** 540,543 ****
--- 540,555 ----
  }
  
+ ILClass *_ILTypeToSyntheticInstantiation
+               (ILImage *image, ILType *type, ILType *classParams)
+ {
+       /* TODO: do this without calling ILTypeInstantiate */
+       type = ILTypeInstantiate(image->context, type, classParams, 0);
+       if(!type)
+       {
+               return 0;
+       }
+       return ILHashFindType(image->context->syntheticHash, type, ILClass);
+ }
+ 
  #ifdef        __cplusplus
  };





reply via email to

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