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

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

[Dotgnu-pnet-commits] CVS: pnet/engine lib_reflect.c,1.25,1.26


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnet/engine lib_reflect.c,1.25,1.26
Date: Sat, 04 Jan 2003 06:29:41 -0500

Update of /cvsroot/dotgnu-pnet/pnet/engine
In directory subversions:/tmp/cvs-serv29060/engine

Modified Files:
        lib_reflect.c 
Log Message:


Implement "GetValue" and "SetValue" for fields in the reflection code.


Index: lib_reflect.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/lib_reflect.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -r1.25 -r1.26
*** lib_reflect.c       4 Jan 2003 01:43:19 -0000       1.25
--- lib_reflect.c       4 Jan 2003 11:29:37 -0000       1.26
***************
*** 30,33 ****
--- 30,41 ----
  
  /*
+  * Throw a target exception.
+  */
+ static void ThrowTargetException(ILExecThread *thread)
+ {
+       ILExecThreadThrowSystem(thread, "System.Reflection.TargetException", 0);
+ }
+ 
+ /*
   * Determine if we have an attribute type match.
   */
***************
*** 1352,1413 ****
                                                                ILObject *obj)
  {
-       unsigned long len;
-       ILProgramItem *item;
        ILField *field;
!       ILConstant *constant;
!       ILInt32 intValue;
!       ILUInt32 uintValue;
!       ILInt64 longValue;
!       ILUInt64 ulongValue;
!       ILFloat floatValue;
!       ILDouble doubleValue;
!       const char* strValue;
!       
!       item = (ILProgramItem *)_ILClrFromObject(thread, _this);
!       if(!item)return 0;
!       field = ILProgramItemToField(item);
!       if(!field)return 0;
!       constant = ILConstantGetFromOwner(item);
!               
!       if(!constant)return 0;
!       switch(ILConstantGetElemType(constant))
!       {
!               case IL_META_ELEMTYPE_BOOLEAN:
!               case IL_META_ELEMTYPE_CHAR:
!               case IL_META_ELEMTYPE_I1:
!               case IL_META_ELEMTYPE_I2:       
!               case IL_META_ELEMTYPE_I4:
!                       intValue = 
*((ILInt32*)(ILConstantGetValue(constant,&(len))));
!                       return 
ILExecThreadBox(thread,ILField_Type(field),&(intValue));
!                       break;
!               case IL_META_ELEMTYPE_U1:
!               case IL_META_ELEMTYPE_U2:
!               case IL_META_ELEMTYPE_U4:
!                       uintValue = 
*((ILUInt32*)(ILConstantGetValue(constant,&(len))));
!                       return 
ILExecThreadBox(thread,ILField_Type(field),&(uintValue));
!                       break;
!               case IL_META_ELEMTYPE_I8:
!                       longValue = 
*((ILInt64*)(ILConstantGetValue(constant,&(len))));
!                       return 
ILExecThreadBox(thread,ILField_Type(field),&(longValue));
!                       break;
!               case IL_META_ELEMTYPE_U8:
!                       ulongValue = 
*((ILInt64*)(ILConstantGetValue(constant,&(len))));
!                       return 
ILExecThreadBox(thread,ILField_Type(field),&(ulongValue));
!                       break;
!               case IL_META_ELEMTYPE_R4:
!                       floatValue =  
*((ILFloat*)(ILConstantGetValue(constant,&(len))));
!                       return 
ILExecThreadBox(thread,ILField_Type(field),&(floatValue));
!                       break;
!               case IL_META_ELEMTYPE_R8:       
!                       doubleValue =  
*((ILDouble*)(ILConstantGetValue(constant,&(len))));
!                       return 
ILExecThreadBox(thread,ILField_Type(field),&(doubleValue));
!                       break;
!               case IL_META_ELEMTYPE_STRING:
!                       strValue = (const char *)(ILConstantGetValue(constant, 
&len));
!                       return 
(ILObject*)((System_String*)ILStringCreateLen(thread,
!                                                                       
strValue,len));
!               /* TODO : implement the object cases for the GetValue */
        }
-       return 0;
  }
  
--- 1360,1416 ----
                                                                ILObject *obj)
  {
        ILField *field;
!       ILType *type;
!       void *ptr;
! 
!       /* Get the program item for the field reference */
!       field = _ILClrFromObject(thread, _this);
!       if(!field)
!       {
!               return 0;
!       }
! 
!       /* Check that we have sufficient access credentials for the field */
!       if(!_ILClrCheckAccess(thread, 0, (ILMember *)field))
!       {
!               ILExecThreadThrowSystem
!                       (thread, "System.Security.SecurityException", 0);
!               return 0;
!       }
! 
!       /* Is the field literla, static or instance? */
!       if(ILField_IsLiteral(field))
!       {
!               /* TODO: unpack the constant and return it */
!               return 0;
!       }
!       else if(ILField_IsStatic(field))
!       {
!               /* TODO */
!               return 0;
!       }
!       else
!       {
!               /* We must have a target, and it must be of the right class */
!               if(!obj || !ILClassInheritsFrom(GetObjectClass(obj),
!                                                                           
ILClassResolve(ILField_Owner(obj))))
!               {
!                       ThrowTargetException(thread);
!               }
! 
!               /* Get the field's type and a pointer to it */
!               type = ILField_Type(field);
!               ptr = (void *)(((unsigned char *)obj) + field->offset);
!       }
! 
!       /* Fetch the value, box it, and return */
!       if(ILTypeIsReference(type))
!       {
!               return *((ILObject **)ptr);
!       }
!       else
!       {
!               return ILExecThreadBox(thread, type, ptr);
        }
  }
  
***************
*** 1422,1426 ****
                                                   ILObject *culture)
  {
!       /* TODO */
  }
  
--- 1425,1481 ----
                                                   ILObject *culture)
  {
!       ILField *field;
!       ILType *type;
!       void *ptr;
! 
!       /* Get the program item for the field reference */
!       field = _ILClrFromObject(thread, _this);
!       if(!field)
!       {
!               return;
!       }
! 
!       /* Check that we have sufficient access credentials for the field */
!       if(!_ILClrCheckAccess(thread, 0, (ILMember *)field))
!       {
!               ILExecThreadThrowSystem
!                       (thread, "System.Security.SecurityException", 0);
!               return;
!       }
! 
!       /* Is the field literla, static or instance? */
!       if(ILField_IsLiteral(field))
!       {
!               /* Cannot set literal fields */
!               return;
!       }
!       else if(ILField_IsStatic(field))
!       {
!               /* TODO */
!               return;
!       }
!       else
!       {
!               /* We must have a target, and it must be of the right class */
!               if(!obj || !ILClassInheritsFrom(GetObjectClass(obj),
!                                                                           
ILClassResolve(ILField_Owner(obj))))
!               {
!                       ThrowTargetException(thread);
!               }
! 
!               /* Get the field's type and a pointer to it */
!               type = ILField_Type(field);
!               ptr = (void *)(((unsigned char *)obj) + field->offset);
!       }
! 
!       /* Fetch the value, box it, and return */
!       if(ILTypeIsReference(type))
!       {
!               *((ILObject **)ptr) = value;
!       }
!       else
!       {
!               ILExecThreadUnbox(thread, type, value, ptr);
!       }
  }
  
***************
*** 1767,1778 ****
        /* Invoke the constructor method */
        return InvokeMethod(thread, method, signature, 0, parameters, 1);
- }
- 
- /*
-  * Throw a target exception.
-  */
- static void ThrowTargetException(ILExecThread *thread)
- {
-       ILExecThreadThrowSystem(thread, "System.Reflection.TargetException", 0);
  }
  
--- 1822,1825 ----





reply via email to

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