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

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

[Dotgnu-pnet-commits] CVS: pnet/codegen cg_coerce.c,1.19,1.20


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnet/codegen cg_coerce.c,1.19,1.20
Date: Wed, 26 Feb 2003 05:33:10 -0500

Update of /cvsroot/dotgnu-pnet/pnet/codegen
In directory subversions:/tmp/cvs-serv20444/codegen

Modified Files:
        cg_coerce.c 
Log Message:


Implement missing unsafe pointer coercions.


Index: cg_coerce.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_coerce.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -r1.19 -r1.20
*** cg_coerce.c 15 Feb 2003 02:14:52 -0000      1.19
--- cg_coerce.c 26 Feb 2003 10:33:08 -0000      1.20
***************
*** 46,49 ****
--- 46,52 ----
        const ILConversion *builtin;
  
+       /* Coerce "null" to a pointer type */
+       int                     pointerNull;
+ 
  } ConvertRules;
  
***************
*** 326,329 ****
--- 329,339 ----
  
  /*
+  * Determine if a type is pointer-based.
+  */
+ #define       ILType_IsPointer(type)  \
+                       ((type) != 0 && ILType_IsComplex((type)) && \
+                        ILType_Kind((type)) == IL_TYPE_COMPLEX_PTR)
+ 
+ /*
   * Get the rules to be used inside of an unsafe block.
   */
***************
*** 332,371 ****
  {
        const ILConversion *conv;
!       /* TODO : Handle the rest of the cases */
!       /*  Numeric/pointer casts  */
!       if (explicit)
        {
!               /*  Numeric -> pointer conversion  */
!               if ( ILIsBuiltinNumeric(toType) && ILType_IsComplex(fromType) )
                {
!                       if (ILType_Kind(fromType) == IL_TYPE_COMPLEX_PTR)
!                       {
!                               conv = ILFindConversion(fromType, toType, 
explicit,1);
!                               if(conv)
!                               {
!                                       rules->builtin = conv;
!                                       return 1;
!                               }
!                       }
                }
  
!               if ( ILType_IsComplex(toType) && ILIsBuiltinNumeric(fromType) )
                {
!                       if (ILType_Kind(toType) == IL_TYPE_COMPLEX_PTR)
                        {
                                return 1;
                        }
                }
  
!               if ( ILType_IsComplex(toType) && ILType_IsComplex(fromType) )
                {
!                       if (ILType_Kind(toType) == IL_TYPE_COMPLEX_PTR
!                                       && ILType_Kind(fromType) == 
IL_TYPE_COMPLEX_PTR)
!                       {
!                               return 1;
!                       }
                }
        }
  
        return 0;
  }
--- 342,388 ----
  {
        const ILConversion *conv;
! 
!       /* Handle pointer/pointer casts */
!       if(ILType_IsPointer(toType) && ILType_IsPointer(fromType))
        {
!               /* Can always cast between pointer types if explicit */
!               if(explicit)
                {
!                       return 1;
                }
  
!               /* Otherwise can only cast implicitly to "void *" */
!               return (ILType_Ref(toType) == ILType_Void);
!       }
! 
!       /* Can cast implicitly from "null" to any pointer type */
!       if(ILType_IsPointer(toType) && fromType == ILType_Null)
!       {
!               rules->pointerNull = 1;
!               return 1;
!       }
! 
!       /* Handle explicit numeric/pointer casts */
!       if(explicit)
!       {
!               /* Pointer to numeric conversion */
!               if(ILIsBuiltinNumeric(toType) && ILType_IsPointer(fromType))
                {
!                       conv = ILFindConversion(fromType, toType, explicit, 1);
!                       if(conv)
                        {
+                               rules->builtin = conv;
                                return 1;
                        }
                }
  
!               /* Numberic to pointer conversion */
!               if(ILType_IsPointer(toType) && ILIsBuiltinNumeric(fromType))
                {
!                       return 1;
                }
        }
  
+       /* Could not find an appropriate conversion */
        return 0;
  }
***************
*** 389,392 ****
--- 406,410 ----
        rules->castType = 0;
        rules->builtin = 0;
+       rules->pointerNull = 0;
  
        /* Strip type prefixes before we start */
***************
*** 406,414 ****
        }
  
!       /* If "fromType" is null, then "toType" must be a reference type */
        if(fromType == ILType_Null)
        {
                if((kinds & IL_CONVERT_REFERENCE) != 0)
                {
                        return ILTypeIsReference(toType);
                }
--- 424,437 ----
        }
  
!       /* If "fromType" is null, then "toType" must be a reference or pointer 
*/
        if(fromType == ILType_Null)
        {
                if((kinds & IL_CONVERT_REFERENCE) != 0)
                {
+                       if(ILType_IsPointer(toType) && info->unsafeLevel > 0)
+                       {
+                               rules->pointerNull = 1;
+                               return 1;
+                       }
                        return ILTypeIsReference(toType);
                }
***************
*** 786,789 ****
--- 809,820 ----
        {
                *parent = ILNode_CastType_create(node, rules->castType);
+               yysetfilename(*parent, yygetfilename(node));
+               yysetlinenum(*parent, yygetlinenum(node));
+       }
+ 
+       /* Convert the object reference "null" into a pointer "null" */
+       if(rules->pointerNull)
+       {
+               *parent = ILNode_NullPtr_create();
                yysetfilename(*parent, yygetfilename(node));
                yysetlinenum(*parent, yygetlinenum(node));





reply via email to

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