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.13,1.14 cg_coerce.


From: Gopal.V <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnet/codegen cg_coerce.c,1.13,1.14 cg_coerce.h,1.14,1.15
Date: Fri, 15 Nov 2002 20:02:34 -0500

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

Modified Files:
        cg_coerce.c cg_coerce.h 
Log Message:
Multiple step coercions using user defined operations


Index: cg_coerce.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_coerce.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -r1.13 -r1.14
*** cg_coerce.c 1 Nov 2002 14:10:35 -0000       1.13
--- cg_coerce.c 16 Nov 2002 01:02:30 -0000      1.14
***************
*** 525,528 ****
--- 525,633 ----
  
  /*
+  * Attributes that are indicate the type of method.
+  */
+ #define       METHOD_TYPE_ATTRS       (IL_META_METHODDEF_STATIC | \
+                                                        
IL_META_METHODDEF_SPECIAL_NAME | \
+                                                        
IL_META_METHODDEF_RT_SPECIAL_NAME)
+ 
+ int GetIndirectConvertRules(ILGenInfo *info, ILType *fromType,
+                                                  ILType *toType, int explicit,
+                                                  int kinds, ConvertRules 
*rules1,
+                                                  ConvertRules *rules2,
+                                                  ILType **itype1,ILType 
**itype2)
+ {
+       ILMethod *method;
+       ILMember *member;
+       ILType *signature;
+       ILClass *arg1Class = ILTypeToClass(info, fromType);
+       ILClass *arg2Class = ILTypeToClass(info, toType);       
+       ILType *argType;
+       ILType *returnType;
+       
+       while(arg1Class != 0)
+       {
+               arg1Class= ILClassResolve(arg1Class);
+               member=0;
+               while((member = ILClassNextMemberByKind
+                                       (arg1Class, member, 
IL_META_MEMBERKIND_METHOD)) != 0)
+               {
+                       /* Filter out members that aren't interesting */
+                       if(strcmp(ILMember_Name(member), "op_Implicit") != 0 ||
+                          (ILMember_Attrs(member) & METHOD_TYPE_ATTRS) !=
+                       (IL_META_METHODDEF_STATIC 
|IL_META_METHODDEF_SPECIAL_NAME))
+                       {
+                               continue;
+                       }
+                       method = (ILMethod *)member;
+                       /* Check that this is the signature we are interested 
in */
+                       signature = ILMethod_Signature(method);
+                       if(!ILType_IsMethod(signature))
+                       {
+                               continue;
+                       }
+                       returnType=ILTypeGetReturn(signature);
+                       if(ILTypeNumParams(signature)!=1)
+                       {
+                               continue;
+                       }
+                       argType=ILTypeGetParam(signature,1);
+ 
+                       if(ILCanCoerce(info,returnType,toType,0) && 
+                               ILCanCoerce(info,fromType,argType,0))
+                       {
+                               if(itype1)(*itype1)=argType;
+                               if(itype2)(*itype2)=returnType;
+                               
GetConvertRules(info,fromType,argType,explicit,kinds,rules1);
+                               
GetConvertRules(info,returnType,toType,explicit,kinds,rules2);
+                               return 1;
+                       }
+               }
+               arg1Class = ILClass_Parent(arg1Class);
+       }
+ 
+       while(arg2Class != 0)
+       {
+               arg2Class= ILClassResolve(arg2Class);
+               member=0;
+               while((member = ILClassNextMemberByKind
+                                       (arg2Class, member, 
IL_META_MEMBERKIND_METHOD)) != 0)
+               {
+                       /* Filter out members that aren't interesting */
+                       if(strcmp(ILMember_Name(member), "op_Implicit") != 0 ||
+                          (ILMember_Attrs(member) & METHOD_TYPE_ATTRS) !=
+                       (IL_META_METHODDEF_STATIC 
|IL_META_METHODDEF_SPECIAL_NAME))
+                       {
+                               continue;
+                       }
+                       method = (ILMethod *)member;
+                       /* Check that this is the signature we are interested 
in */
+                       signature = ILMethod_Signature(method);
+                       if(!ILType_IsMethod(signature))
+                       {
+                               continue;
+                       }
+                       returnType=ILTypeGetReturn(signature);
+                       if(ILTypeNumParams(signature)!=1)
+                       {
+                               continue;
+                       }
+                       argType=ILTypeGetParam(signature,1);
+ 
+                       if(ILCanCoerce(info,returnType,toType,0) && 
+                               ILCanCoerce(info,fromType,argType,0))
+                       {
+                               if(itype1)(*itype1)=argType;
+                               if(itype2)(*itype2)=returnType;
+                               
GetConvertRules(info,fromType,argType,explicit,kinds,rules1);
+                               
GetConvertRules(info,returnType,toType,explicit,kinds,rules2);
+                               return 1;
+                       }
+               }
+               arg2Class = ILClass_Parent(arg2Class);
+       }
+       return 0;
+ }
+ 
+ /*
   * Apply a set of conversion rules to a node.
   */
***************
*** 679,686 ****
  }
  
! int ILCanCoerce(ILGenInfo *info, ILType *fromType, ILType *toType)
  {
        ConvertRules rules;
!       return GetConvertRules(info, fromType, toType, 0, IL_CONVERT_ALL, 
&rules);
  }
  
--- 784,801 ----
  }
  
! int ILCanCoerce(ILGenInfo *info, ILType *fromType, ILType *toType,int 
indirect)
  {
        ConvertRules rules;
!       ConvertRules rules2;
!       if(GetConvertRules(info, fromType, toType, 0, IL_CONVERT_ALL, &rules))
!       {
!               return 1;
!       }
!       else if(indirect && GetIndirectConvertRules(info,fromType,toType, 
!                                                       0, 
IL_CONVERT_ALL,&rules,&rules2,NULL,NULL))
!       {
!               return 1;
!       }
!       return 0;
  }
  
***************
*** 689,693 ****
  {
        ConvertRules rules;
!       return GetConvertRules(info, fromType, toType, 0, kinds, &rules);
  }
  
--- 804,818 ----
  {
        ConvertRules rules;
!       ConvertRules rules2;
!       if(GetConvertRules(info, fromType, toType, 0, kinds, &rules))
!       {
!               return 1;
!       }
!       else if(GetIndirectConvertRules(info,fromType,toType,0, 
!                                                       
kinds,&rules,&rules2,NULL,NULL))
!       {
!               return 1;
!       }
!       return 0;
  }
  
***************
*** 696,699 ****
--- 821,825 ----
  {
        ConvertRules rules;
+       ConvertRules rules2;
        if(GetConvertRules(info, fromType, toType, 0, IL_CONVERT_ALL, &rules))
        {
***************
*** 704,707 ****
--- 830,838 ----
                return 1;
        }
+       else if(GetIndirectConvertRules(info,fromType,toType,0, 
+                                                       
IL_CONVERT_ALL,&rules,&rules2,NULL,NULL))
+       {
+               return 1;
+       }
        else
        {
***************
*** 714,717 ****
--- 845,849 ----
  {
        ConvertRules rules;
+       ConvertRules rules2;
        if(GetConvertRules(info, fromType, toType, 0, kinds, &rules))
        {
***************
*** 723,726 ****
--- 855,863 ----
                return 1;
        }
+       else if(GetIndirectConvertRules(info,fromType,toType,0, 
+                                                       
kinds,&rules,&rules2,NULL,NULL))
+       {
+               return 1;
+       }
        else
        {
***************
*** 733,736 ****
--- 870,875 ----
  {
        ConvertRules rules;
+       ConvertRules rules2;
+       ILType *t1,*t2;
        ILMachineType constType;
        if(GetConvertRules(info, fromType, toType, 0, IL_CONVERT_ALL, &rules))
***************
*** 745,748 ****
--- 884,895 ----
                return 1;
        }
+       else if(GetIndirectConvertRules(info,fromType,toType,0, 
+                                                       
IL_CONVERT_ALL,&rules,&rules2,&t1,&t2))
+       {
+               ApplyRules(info, node, parent, &rules, t1);
+               ILCoerce(info,*parent,parent,t1,t2);
+               ApplyRules(info, *parent, parent, &rules2, toType);
+               return 1;
+       }
        else
        {
***************
*** 755,759 ****
--- 902,908 ----
  {
        ConvertRules rules;
+       ConvertRules rules2;
        ILMachineType constType;
+       ILType *t1,*t2;
        if(GetConvertRules(info, fromType, toType, 0, kinds, &rules))
        {
***************
*** 768,771 ****
--- 917,928 ----
                return 1;
        }
+       else if(GetIndirectConvertRules(info,fromType,toType,0, 
+                                                               
kinds,&rules,&rules2,&t1,&t2))
+       {
+               ApplyRules(info, node, parent, &rules, t1);
+               ILCoerceKind(info,*parent,parent,t1,t2,kinds);
+               ApplyRules(info, *parent, parent, &rules, toType);
+               return 1;
+       }
        else
        {
***************
*** 777,781 ****
  {
        ConvertRules rules;
!       return GetConvertRules(info, fromType, toType, 1, IL_CONVERT_ALL, 
&rules);
  }
  
--- 934,948 ----
  {
        ConvertRules rules;
!       ConvertRules rules2;
!       if(GetConvertRules(info, fromType, toType, 1, IL_CONVERT_ALL, &rules))
!       {
!               return 1;
!       }
!       else if(GetIndirectConvertRules(info,fromType,toType,0, 
!                                                       
IL_CONVERT_ALL,&rules,&rules2,NULL,NULL))
!       {
!               return 1;
!       }
!       return 0;
  }
  
***************
*** 784,788 ****
  {
        ConvertRules rules;
!       return GetConvertRules(info, fromType, toType, 1, kinds, &rules);
  }
  
--- 951,965 ----
  {
        ConvertRules rules;
!       ConvertRules rules2;
!       if(GetConvertRules(info, fromType, toType, 1, kinds, &rules))
!       {
!               return 1;
!       }
!       else if(GetIndirectConvertRules(info,fromType,toType,0, 
!                                                                       
kinds,&rules,&rules2,NULL,NULL))
!       {
!               return 1;
!       }
!       return 0;
  }
  
***************
*** 791,794 ****
--- 968,973 ----
  {
        ConvertRules rules;
+       ConvertRules rules2;
+       ILType *t1,*t2;
        if(GetConvertRules(info, fromType, toType, 1, IL_CONVERT_ALL, &rules))
        {
***************
*** 796,799 ****
--- 975,986 ----
                return 1;
        }
+       else if(GetIndirectConvertRules(info,fromType,toType,0, 
+                                                       
IL_CONVERT_ALL,&rules,&rules2,&t1,&t2))
+       {
+               ApplyRules(info, node, parent, &rules, t1);
+               ILCast(info,*parent,parent,t1,t2);
+               ApplyRules(info, *parent, parent, &rules2, toType);
+               return 1;
+       }
        else
        {
***************
*** 806,809 ****
--- 993,998 ----
  {
        ConvertRules rules;
+       ConvertRules rules2;
+       ILType *t1,*t2;
        if(GetConvertRules(info, fromType, toType, 1, kinds, &rules))
        {
***************
*** 811,814 ****
--- 1000,1011 ----
                return 1;
        }
+       else if(GetIndirectConvertRules(info,fromType,toType,0, 
+                                                                       
kinds,&rules,&rules2,&t1,&t2))
+       {
+               ApplyRules(info, node, parent, &rules, t1);
+               ILCastKind(info,*parent,parent,t1,t2,kinds);
+               ApplyRules(info, *parent, parent, &rules, toType);
+               return 1;
+       }
        else
        {
***************
*** 857,867 ****
                return IL_BETTER_T2;
        }
!       else if(ILCanCoerce(info, t1Type, t2Type) &&
!               !ILCanCoerce(info, t2Type, t1Type))
        {
                return IL_BETTER_T1;
        }
!       else if(ILCanCoerce(info, t2Type, t1Type) &&
!               !ILCanCoerce(info, t1Type, t2Type))
        {
                return IL_BETTER_T2;
--- 1054,1064 ----
                return IL_BETTER_T2;
        }
!       else if(ILCanCoerce(info, t1Type, t2Type,0) &&
!               !ILCanCoerce(info, t2Type, t1Type,0))
        {
                return IL_BETTER_T1;
        }
!       else if(ILCanCoerce(info, t2Type, t1Type,0) &&
!               !ILCanCoerce(info, t1Type, t2Type,0))
        {
                return IL_BETTER_T2;

Index: cg_coerce.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_coerce.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -r1.14 -r1.15
*** cg_coerce.h 1 Nov 2002 14:10:35 -0000       1.14
--- cg_coerce.h 16 Nov 2002 01:02:30 -0000      1.15
***************
*** 116,120 ****
   * from one type to another.
   */
! int ILCanCoerce(ILGenInfo *info, ILType *fromType, ILType *toType);
  
  /*
--- 116,120 ----
   * from one type to another.
   */
! int ILCanCoerce(ILGenInfo *info, ILType *fromType, ILType *toType,int 
indirect);
  
  /*





reply via email to

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