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

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

[Dotgnu-pnet-commits] pnet/cscc/c c_coerce.c,1.7,1.8


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] pnet/cscc/c c_coerce.c,1.7,1.8
Date: Fri, 03 Oct 2003 00:31:53 +0000

Update of /cvsroot/dotgnu-pnet/pnet/cscc/c
In directory subversions:/tmp/cvs-serv11257/cscc/c

Modified Files:
        c_coerce.c 
Log Message:


GetCoerceRules: allow function pointer types to be coerced if they have
the same basic "shape", even if some of the parameters differ in const
or pointer types.


Index: c_coerce.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_coerce.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** c_coerce.c  2 Oct 2003 23:26:18 -0000       1.7
--- c_coerce.c  3 Oct 2003 00:31:51 -0000       1.8
***************
*** 165,168 ****
--- 165,219 ----
  
  /*
+  * Determine if two function signatures have the same "shape".
+  * This is needed to handle cases like "qsort", where the prototype
+  * of the comparison function may not be identical to that of the
+  * parameter prototype, but it is compatible enough to use in an
+  * indirect function call.
+  */
+ static int SameShape(ILType *type1, ILType *type2)
+ {
+       unsigned long numParams;
+       unsigned long param;
+       type1 = ILTypeStripPrefixes(type1);
+       type2 = ILTypeStripPrefixes(type2);
+       if(type1 && type2 && ILType_IsComplex(type1) && ILType_IsComplex(type2) 
&&
+          ILType_Kind(type1) == ILType_Kind(type2))
+       {
+               if(ILType_Kind(type1) == IL_TYPE_COMPLEX_PTR)
+               {
+                       /* Pointer types always have the same shape */
+                       return 1;
+               }
+               else if((ILType_Kind(type1) & IL_TYPE_COMPLEX_METHOD) != 0)
+               {
+                       /* Check the return type and parameters in method 
signatures */
+                       if(!SameShape(ILTypeGetReturn(type1), 
ILTypeGetReturn(type2)))
+                       {
+                               return 0;
+                       }
+                       if(ILType_CallConv(type1) != ILType_CallConv(type2))
+                       {
+                               return 0;
+                       }
+                       numParams = ILTypeNumParams(type1);
+                       if(ILTypeNumParams(type2) != numParams)
+                       {
+                               return 0;
+                       }
+                       for(param = 1; param <= numParams; ++param)
+                       {
+                               if(!SameShape(ILTypeGetParam(type1, param),
+                                                         ILTypeGetParam(type2, 
param)))
+                               {
+                                       return 0;
+                               }
+                       }
+                       return 1;
+               }
+       }
+       return ILTypeIdentical(type1, type2);
+ }
+ 
+ /*
   * Determine the coercion rules for coercing "fromType" to "toType".
   */
***************
*** 267,270 ****
--- 318,328 ----
                {
                        return C_COERCE_OK;
+               }
+ 
+               /* We can coerce with a warning if the two function pointers
+                  have identical "shape" */
+               if(SameShape(fromType, toType))
+               {
+                       return C_COERCE_OK | C_COERCE_PTR_TO_PTR;
                }
        }





reply via email to

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