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

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

[Dotgnu-pnet-commits] CVS: pnet/cscc/c c_coerce.c,1.5,1.6 c_defs.tc,1.1


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnet/cscc/c c_coerce.c,1.5,1.6 c_defs.tc,1.19,1.20 c_invoke.tc,1.8,1.9 c_oper.tc,1.24,1.25
Date: Mon, 23 Dec 2002 17:43:29 -0500

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

Modified Files:
        c_coerce.c c_defs.tc c_invoke.tc c_oper.tc 
Log Message:


Improvements to C# method invocation in the C compiler; implement
implicit C to C# string conversion.


Index: c_coerce.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_coerce.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** c_coerce.c  14 Sep 2002 01:11:31 -0000      1.5
--- c_coerce.c  23 Dec 2002 22:43:26 -0000      1.6
***************
*** 36,39 ****
--- 36,40 ----
  #define       C_COERCE_NULL_PTR                       (1<<5)
  #define       C_COERCE_SIMPLE                         (1<<6)
+ #define       C_COERCE_C_TO_CS_STRING         (1<<7)
  
  /*
***************
*** 269,272 ****
--- 270,287 ----
        }
  
+       /* Deal with coercions between C and C# strings */
+       if(CTypeIsPointer(fromType) &&
+          ILTypeStripPrefixes(CTypeGetPtrRef(fromType)) == ILType_Int8 &&
+          ILTypeIsStringClass(toType))
+       {
+               return C_COERCE_C_TO_CS_STRING;
+       }
+ 
+       /* We allow identical C# types to be coerced */
+       if(ILTypeIdentical(fromType, toType))
+       {
+               return C_COERCE_OK;
+       }
+ 
        /* We will get here if we don't have a C type or we have
           a completely invalid combination of C types */
***************
*** 419,422 ****
--- 434,455 ----
                        CSemSetRValue(fromValue, toType);
                }
+       }
+       else if((rules & C_COERCE_C_TO_CS_STRING) != 0)
+       {
+               /* Convert a C string into a C# string */
+               if(yyisa(node, ILNode_CString))
+               {
+                       /* The argument is a constant, so merely change its 
node type */
+                       *parent = ILNode_String_create
+                               (((ILNode_CString *)node)->str, 
((ILNode_CString *)node)->len);
+                       CGenCloneLine(*parent, node);
+               }
+               else
+               {
+                       /* We need to call "PtrToStringAnsi" to convert the 
string */
+                       *parent = ILNode_CToCSharpString_create(node);
+                       CGenCloneLine(*parent, node);
+               }
+               CSemSetRValue(fromValue, toType);
        }
        else

Index: c_defs.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_defs.tc,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -r1.19 -r1.20
*** c_defs.tc   9 Dec 2002 00:28:19 -0000       1.19
--- c_defs.tc   23 Dec 2002 22:43:26 -0000      1.20
***************
*** 409,412 ****
--- 409,413 ----
        ILNode *expr2;
  }
+ %node ILNode_CToCSharpString ILNode_UnaryExpression
  
  %output "c_semantics.c"

Index: c_invoke.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_invoke.tc,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** c_invoke.tc 16 Nov 2002 02:45:32 -0000      1.8
--- c_invoke.tc 23 Dec 2002 22:43:26 -0000      1.9
***************
*** 479,482 ****
--- 479,588 ----
  }
  
+ %{
+ 
+ /*
+  * Internal worker function for locating static C# methods.
+  */
+ static ILMethod *ResolveCSMethod(ILGenInfo *info, ILClass *classInfo,
+                                                            ILClass 
*callScope, const char *name,
+                                                            ILType **args, int 
numArgs)
+ {
+       ILMember *member;
+       ILMethod *method;
+       ILMethod *closestMatch = 0;
+       ILType *signature;
+       ILType *argType;
+       int arg, same;
+ 
+       while(classInfo != 0)
+       {
+               classInfo = ILClassResolve(classInfo);
+               member = 0;
+               while((member = ILClassNextMemberByKind
+                                       (classInfo, member, 
IL_META_MEMBERKIND_METHOD)) != 0)
+               {
+                       /* Filter out members that aren't interesting */
+                       method = (ILMethod *)member;
+                       if(strcmp(ILMethod_Name(method), name) != 0 ||
+                          !ILMethod_IsStatic(method))
+                       {
+                               continue;
+                       }
+ 
+                       /* Check that this is the signature we are interested 
in */
+                       signature = ILMethod_Signature(method);
+                       if(!ILType_IsMethod(signature))
+                       {
+                               continue;
+                       }
+                       if(numArgs != (int)(ILTypeNumParams(signature)))
+                       {
+                               continue;
+                       }
+                       same = 1;
+                       for(arg = 1; arg <= numArgs; ++arg)
+                       {
+                               argType = ILTypeGetParam(signature, arg);
+                               if(!ILTypeIdentical(argType, args[arg - 1]))
+                               {
+                                       if(!CCanCoerce(args[arg - 1], argType))
+                                       {
+                                               break;
+                                       }
+                                       same = 0;
+                               }
+                       }
+                       if(arg <= numArgs)
+                       {
+                               continue;
+                       }
+ 
+                       /* Check the method's access level against the call 
scope */
+                       if(!ILMemberAccessible(member, callScope))
+                       {
+                               continue;
+                       }
+ 
+                       /* We've found a candidate method */
+                       if(same)
+                       {
+                               /* We have an exact match, so return that */
+                               return method;
+                       }
+                       else if(!closestMatch)
+                       {
+                               /* This match is close, but try to find a 
better one */
+                               closestMatch = method;
+                       }
+               }
+ 
+               /* Move up to the parent class */
+               if(ILClass_IsInterface(classInfo))
+               {
+                       /* Scan the parents of this interface */
+                       ILImplements *impl = 0;
+                       while((impl = ILClassNextImplements(classInfo, impl)) 
!= 0)
+                       {
+                               method = ResolveCSMethod(info, 
ILImplementsGetInterface(impl),
+                                                                            
callScope, name, args, numArgs);
+                               if(method)
+                               {
+                                       return method;
+                               }
+                       }
+                       classInfo = 0;
+               }
+               else
+               {
+                       classInfo = ILClass_Parent(classInfo);
+               }
+       }
+ 
+       /* Return the closest match if we didn't find an exact match */
+       return closestMatch;
+ }
+ 
+ %}
+ 
  /*
   * Perform semantic analysis for C# invocation expressions.
***************
*** 530,535 ****
        if(classInfo)
        {
!               method = ILResolveStaticMethod(info, classInfo, callScope,
!                                                                          
node->name, typeArray, (int)numArgs);
        }
        else
--- 636,641 ----
        if(classInfo)
        {
!               method = ResolveCSMethod(info, classInfo, callScope,
!                                                                node->name, 
typeArray, (int)numArgs);
        }
        else
***************
*** 552,563 ****
        }
  
!       /* Coerce the arguments to the method's actual parameter types,
!          using C#-style coercion rules rather than C-style rules */
        signature = ILMethod_Signature(method);
        for(argNum = 0; argNum < numArgs; ++argNum)
        {
!               ILCoerce(info, argTypes[argNum].node, argTypes[argNum].parent,
!                                
ILTypeStripPrefixes(CSemGetType(argTypes[argNum].value)),
!                                ILTypeGetParam(signature, argNum + 1),1);
        }
  
--- 658,668 ----
        }
  
!       /* Coerce the arguments to the method's actual parameter types */
        signature = ILMethod_Signature(method);
        for(argNum = 0; argNum < numArgs; ++argNum)
        {
!               CCoerceNode(info, argTypes[argNum].node,
!                                       argTypes[argNum].parent, 
argTypes[argNum].value,
!                                   ILTypeGetParam(signature, argNum + 1));
        }
  

Index: c_oper.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_oper.tc,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -r1.24 -r1.25
*** c_oper.tc   9 Dec 2002 00:28:19 -0000       1.24
--- c_oper.tc   23 Dec 2002 22:43:26 -0000      1.25
***************
*** 2080,2083 ****
--- 2080,2122 ----
  }
  
+ /*
+  * Perform semantic analysis for C to C# string conversion.
+  */
+ ILNode_CSemAnalysis(ILNode_CToCSharpString)
+ {
+       /* Not used, so nothing to do here */
+       return CSemValueDefault;
+ }
+ 
+ /*
+  * Get the type of a C to C# string conversion.
+  */
+ ILNode_GetType(ILNode_CToCSharpString)
+ {
+       return ILMachineType_ObjectRef;
+ }
+ 
+ /*
+  * Generate value code for a C to C# string conversion.
+  */
+ ILNode_GenValue(ILNode_CToCSharpString)
+ {
+       /* Evaluate the C version of the string */
+       ILNode_GenValue(node->expr, info);
+ 
+       /* Use "Marshal.PtrToStringAnsi" to convert the string */
+       ILGenCallByName(info, "instance [.library]System.String "
+                                                 
"[.library]System.Runtime.InteropServices.Marshal::"
+                                                 "PtrToStringAnsi(native 
int)");
+ 
+       /* The result is always an object reference */
+       return ILMachineType_ObjectRef;
+ }
+ JavaGenValue(ILNode_CToCSharpString)
+ {
+       /* Java output is not supported */
+       return ILMachineType_ObjectRef;
+ }
+ 
  %{
  




reply via email to

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