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.22,1.23 cg_coerce


From: Gopal.V <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnet/codegen cg_coerce.c,1.22,1.23 cg_coerce.h,1.17,1.18
Date: Thu, 08 May 2003 16:22:42 -0400

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

Modified Files:
        cg_coerce.c cg_coerce.h 
Log Message:
Allow indirect coercions to use the best type conversions available.


Index: cg_coerce.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_coerce.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -r1.22 -r1.23
*** cg_coerce.c 26 Feb 2003 12:02:47 -0000      1.22
--- cg_coerce.c 8 May 2003 20:22:40 -0000       1.23
***************
*** 552,555 ****
--- 552,625 ----
                                                         
IL_META_METHODDEF_RT_SPECIAL_NAME)
  
+ static int ILBetterIndirectConversion(ILGenInfo *info, ILType *from ,
+                                               ILType *to ,
+                                               ILType *conversion1,
+                                               ILType *conversion2)
+ {
+       switch(ILBetterConversion(info,from, ILTypeGetParam(conversion1,1), 
+                                                         
ILTypeGetParam(conversion2,1)))
+       {
+               case IL_BETTER_S1:
+               {
+                       switch(ILBetterConversionFrom(info, 
ILTypeGetReturn(conversion1), 
+                                                                               
ILTypeGetReturn(conversion2),to))
+                       {
+                               case IL_BETTER_S1:
+                               case IL_BETTER_NEITHER:
+                               {
+                                       return IL_BETTER_S1;
+                               }
+                               break;
+                               
+                               case IL_BETTER_S2:
+                               {
+                                       return IL_BETTER_NEITHER;
+                               }
+                               break;
+                       }
+               }
+               break;
+               
+               case IL_BETTER_S2:
+               {
+                       switch(ILBetterConversionFrom(info, 
ILTypeGetReturn(conversion1), 
+                                                                               
ILTypeGetReturn(conversion2),to))
+                       {
+                               case IL_BETTER_S1:
+                               {
+                                       return IL_BETTER_NEITHER;
+                               }
+                               break;
+                               case IL_BETTER_S2:
+                               case IL_BETTER_NEITHER:
+                               {
+                                       return IL_BETTER_S2;
+                               }
+                               break;
+                       }
+               }
+               break;
+               
+               case IL_BETTER_NEITHER:
+               {
+                       switch(ILBetterConversionFrom(info, 
ILTypeGetReturn(conversion1), 
+                                                                               
ILTypeGetReturn(conversion2),to))
+                       {
+                               case IL_BETTER_S1:
+                               {
+                                       return IL_BETTER_S1;
+                               }
+                               case IL_BETTER_S2:
+                               {
+                                       return IL_BETTER_S2;
+                               }
+                       }
+               }
+               break;
+               
+       }
+       return IL_BETTER_NEITHER;
+ }
+ 
  /*
   * multiple convert rules are checked here . I have implemented only
***************
*** 566,569 ****
--- 636,640 ----
        ILMethod *method;
        ILMember *member;
+       ILMember *bestMember = 0;
        ILType *signature;
        ILClass *arg1Class = ILTypeToClass(info, fromType);
***************
*** 610,618 ****
                                kinds,0) && 
ILCanCastKind(info,fromType,argType,kinds,0))))
                        {
!                               if(itype1)(*itype1)=argType;
!                               if(itype2)(*itype2)=returnType;
!                               
GetConvertRules(info,fromType,argType,0,kinds,rules1);
!                               
GetConvertRules(info,returnType,toType,0,kinds,rules2);
!                               return 1;
                        }
                }
--- 681,689 ----
                                kinds,0) && 
ILCanCastKind(info,fromType,argType,kinds,0))))
                        {
!                               if(bestMember == NULL || 
(ILBetterIndirectConversion(info,
!                                       fromType, toType, 
ILMethod_Signature(member),                                                     
              ILMethod_Signature(bestMember)) == IL_BETTER_S1))
!                               {
!                                       bestMember = member;
!                               }
                        }
                }
***************
*** 653,665 ****
                                kinds,0) && 
ILCanCastKind(info,fromType,argType,kinds,0))))
                        {
!                               if(itype1)(*itype1)=argType;
!                               if(itype2)(*itype2)=returnType;
!                               
GetConvertRules(info,fromType,argType,0,kinds,rules1);
!                               
GetConvertRules(info,returnType,toType,0,kinds,rules2);
!                               return 1;
                        }
                }
                arg2Class = ILClass_Parent(arg2Class);
        }
  
        if(!explicit)return 0;
--- 724,748 ----
                                kinds,0) && 
ILCanCastKind(info,fromType,argType,kinds,0))))
                        {
!                               if(bestMember == NULL || 
(ILBetterIndirectConversion(info,
!                                       fromType, toType, 
ILMethod_Signature(member),                                                     
              ILMethod_Signature(bestMember)) == IL_BETTER_S1))
!                               {
!                                       bestMember = member;
!                               }
                        }
                }
                arg2Class = ILClass_Parent(arg2Class);
        }
+       
+       if(bestMember)
+       {
+               signature = ILMethod_Signature(bestMember);
+               argType = ILTypeGetParam(signature, 1);
+               returnType = ILTypeGetReturn(signature);
+               if(itype1)(*itype1)=argType;
+               if(itype2)(*itype2)=returnType;
+               GetConvertRules(info,fromType,argType,0,kinds,rules1);
+               GetConvertRules(info,returnType,toType,0,kinds,rules2);
+               return 1;
+       }
  
        if(!explicit)return 0;
***************
*** 702,710 ****
                                ILCanCastKind(info,fromType,argType,kinds,0))
                        {
!                               if(itype1)(*itype1)=argType;
!                               if(itype2)(*itype2)=returnType;
!                               
GetConvertRules(info,fromType,argType,1,kinds,rules1);
!                               
GetConvertRules(info,returnType,toType,1,kinds,rules2);
!                               return 1;
                        }
                }
--- 785,793 ----
                                ILCanCastKind(info,fromType,argType,kinds,0))
                        {
!                               if(bestMember == NULL || 
(ILBetterIndirectConversion(info,
!                                       fromType, toType, 
ILMethod_Signature(member),                                                     
              ILMethod_Signature(bestMember)) == IL_BETTER_S1))
!                               {
!                                       bestMember = member;
!                               }
                        }
                }
***************
*** 743,755 ****
                                ILCanCastKind(info,fromType,argType,kinds,0))
                        {
!                               if(itype1)(*itype1)=argType;
!                               if(itype2)(*itype2)=returnType;
!                               
GetConvertRules(info,fromType,argType,0,kinds,rules1);
!                               
GetConvertRules(info,returnType,toType,1,kinds,rules2);
!                               return 1;
                        }
                }
                arg2Class = ILClass_Parent(arg2Class);
        }
        return 0;
  }
--- 826,851 ----
                                ILCanCastKind(info,fromType,argType,kinds,0))
                        {
!                               if(bestMember == NULL || 
(ILBetterIndirectConversion(info,
!                                       fromType, toType, 
ILMethod_Signature(member),                                                     
              ILMethod_Signature(bestMember)) == IL_BETTER_S1))
!                               {
!                                       bestMember = member;
!                               }
                        }
                }
                arg2Class = ILClass_Parent(arg2Class);
        }
+ 
+       if(bestMember)
+       {
+               signature = ILMethod_Signature(bestMember);
+               argType = ILTypeGetParam(signature, 1);
+               returnType = ILTypeGetReturn(signature);
+               if(itype1)(*itype1)=argType;
+               if(itype2)(*itype2)=returnType;
+               GetConvertRules(info,fromType,argType,0,kinds,rules1);
+               GetConvertRules(info,returnType,toType,0,kinds,rules2);
+               return 1;
+       }
+ 
        return 0;
  }
***************
*** 1249,1252 ****
--- 1345,1434 ----
        {
                return IL_BETTER_T2;
+       }
+       else
+       {
+               return IL_BETTER_NEITHER;
+       }
+ }
+ 
+ 
+ /* TODO : Figure out the actual conversion rules before using
+  *              this in the rest of the code . But it's a reasonably
+  *              good approximation of what I understand about the spec */
+ 
+ int ILBetterConversionFrom(ILGenInfo *info, ILType *s1Type,
+                                          ILType *s2Type, ILType *tType)
+ {
+       if(ILTypeIdentical(s1Type, s2Type))
+       {
+               return IL_BETTER_NEITHER;
+       }
+       else if(ILTypeIdentical(s1Type, tType))
+       {
+               return IL_BETTER_S1;
+       }
+       else if(ILTypeIdentical(s2Type, tType))
+       {
+               return IL_BETTER_S2;
+       }
+       else if(ILCanCoerce(info, s1Type, s2Type,0) &&
+               !ILCanCoerce(info, s2Type, s1Type,0))
+       {
+               return IL_BETTER_S2;
+       }
+       else if(ILCanCoerce(info, s2Type, s1Type,0) &&
+               !ILCanCoerce(info, s1Type, s2Type,0))
+       {
+               return IL_BETTER_S1;
+       }
+       else if(s1Type == ILType_Int8 &&
+               (s2Type == ILType_UInt8 ||
+                        s2Type == ILType_UInt16 ||
+                        s2Type == ILType_UInt32 ||
+                        s2Type == ILType_UInt64))
+       {
+               return IL_BETTER_S1;
+       }
+       else if(s2Type == ILType_Int8 &&
+               (s1Type == ILType_UInt8 ||
+                        s1Type == ILType_UInt16 ||
+                        s1Type == ILType_UInt32 ||
+                        s1Type == ILType_UInt64))
+       {
+               return IL_BETTER_S2;
+       }
+       else if(s1Type == ILType_Int16 &&
+                       (s2Type == ILType_UInt16 ||
+                        s2Type == ILType_UInt32 ||
+                        s2Type == ILType_UInt64))
+       {
+               return IL_BETTER_S1;
+       }
+       else if(s2Type == ILType_Int16 &&
+                       (s1Type == ILType_UInt16 ||
+                        s1Type == ILType_UInt32 ||
+                        s1Type == ILType_UInt64))
+       {
+               return IL_BETTER_S2;
+       }
+       else if(s1Type == ILType_Int32 &&
+                       (s2Type == ILType_UInt32 ||
+                        s2Type == ILType_UInt16))
+       {
+               return IL_BETTER_S1;
+       }
+       else if(s2Type == ILType_Int32 &&
+                       (s1Type == ILType_UInt32 ||
+                        s1Type == ILType_UInt16))
+       {
+               return IL_BETTER_S2;
+       }
+       else if(s1Type == ILType_Int64 && s2Type == ILType_UInt64)
+       {
+               return IL_BETTER_S1;
+       }
+       else if(s2Type == ILType_Int64 && s1Type == ILType_UInt64)
+       {
+               return IL_BETTER_S2;
        }
        else

Index: cg_coerce.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_coerce.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -r1.17 -r1.18
*** cg_coerce.h 2 Apr 2003 16:28:22 -0000       1.17
--- cg_coerce.h 8 May 2003 20:22:40 -0000       1.18
***************
*** 203,209 ****
--- 203,216 ----
  int ILBetterConversion(ILGenInfo *info, ILType *sType,
                                           ILType *t1Type, ILType *t2Type);
+ 
+ int ILBetterConversionFrom(ILGenInfo *info, ILType *s1Type,
+                                          ILType *s2Type, ILType *tType);
+ 
  #define       IL_BETTER_NEITHER               0
  #define       IL_BETTER_T1                    1
  #define       IL_BETTER_T2                    2
+ 
+ #define       IL_BETTER_S1                    IL_BETTER_T1
+ #define       IL_BETTER_S2                    IL_BETTER_T2
  
  /*





reply via email to

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