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

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

[dotgnu-pnet-commits] pnet ChangeLog codegen/cg_coerce.c codegen/cg_m...


From: Klaus Treichel
Subject: [dotgnu-pnet-commits] pnet ChangeLog codegen/cg_coerce.c codegen/cg_m...
Date: Sun, 14 Dec 2008 13:03:35 +0000

CVSROOT:        /cvsroot/dotgnu-pnet
Module name:    pnet
Changes by:     Klaus Treichel <ktreichel>      08/12/14 13:03:35

Modified files:
        .              : ChangeLog 
        codegen        : cg_coerce.c cg_misc.tc cg_nodes.tc jv_misc.tc 
        cscc/c         : c_name.tc c_oper.tc 
        cscc/csharp    : cs_oper.tc 

Log message:
        Add support for converting an array to a pointer to the array's element 
type.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pnet/ChangeLog?cvsroot=dotgnu-pnet&r1=1.3590&r2=1.3591
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_coerce.c?cvsroot=dotgnu-pnet&r1=1.29&r2=1.30
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_misc.tc?cvsroot=dotgnu-pnet&r1=1.52&r2=1.53
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_nodes.tc?cvsroot=dotgnu-pnet&r1=1.93&r2=1.94
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/jv_misc.tc?cvsroot=dotgnu-pnet&r1=1.32&r2=1.33
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/c/c_name.tc?cvsroot=dotgnu-pnet&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/c/c_oper.tc?cvsroot=dotgnu-pnet&r1=1.45&r2=1.46
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/csharp/cs_oper.tc?cvsroot=dotgnu-pnet&r1=1.52&r2=1.53

Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/ChangeLog,v
retrieving revision 1.3590
retrieving revision 1.3591
diff -u -b -r1.3590 -r1.3591
--- ChangeLog   12 Dec 2008 19:38:07 -0000      1.3590
+++ ChangeLog   14 Dec 2008 13:03:33 -0000      1.3591
@@ -1,3 +1,20 @@
+2008-12-14  Klaus Treichel  <address@hidden>
+
+       * codegen/cg_coerce.c (GetUnsafeConvertRules): Handle cast from an array
+       to a pointer to the array's element type.
+       (ApplyRules): Handle the array to element type pointer conversion.
+
+       * codegen/cg_misc.tc: Add the codegen functions for the new node type
+       ILNode_CastArrayToElementPtr.
+
+       * codegen/cg_nodes.tc: Add the new node type 
ILNode_CastArrayToElementPtr.
+
+       * codegen/jv_misc.tc: Add stubbs for the java codegen functions for the
+       new node type ILNode_CastArrayToElementPtr.
+
+       * cscc/c/c_name.tc, cscc/c/c_oper.tc, cscc/csharp/cs_oper.tc: Add the
+       functions to handle the new node type ILNode_CastArrayToElementPtr.
+
 2008-12-12  Klaus Treichel  <address@hidden>
 
        * codegen/cg_misc.tc (ILNode_GenValue(ILNode_CastStringToCharPtr)): Add

Index: codegen/cg_coerce.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_coerce.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- codegen/cg_coerce.c 9 Dec 2008 21:18:20 -0000       1.29
+++ codegen/cg_coerce.c 14 Dec 2008 13:03:34 -0000      1.30
@@ -48,8 +48,11 @@
        /* Coerce "null" to a pointer type */
        int                     pointerNull;
 
-       /* Explicit cast from System.String to a pointer to System.Char */
+       /* Cast from System.String to a pointer to System.Char */
        int                     stringCharPtr;
+
+       /* Cast from a managed array to a pointer to the element type */
+       int                     arrayElementPtr;
 } ConvertRules;
 
 /*
@@ -398,16 +401,45 @@
                        }
                }
 
-               /* String to char * conversion */
+               /* String to char * or void * conversion */
                if((ILTypeToMachineType(fromType) == ILMachineType_String) &&
-                  (ILType_IsPointer(toType) && 
-                       ILTypeToMachineType(ILType_Ref(toType)) == 
ILMachineType_Char))
+                  ILType_IsPointer(toType))
+               {
+                       ILMachineType machineType;
+
+                       machineType = ILTypeToMachineType(ILType_Ref(toType));
+                       if((machineType == ILMachineType_Char) ||
+                          (machineType == ILMachineType_Void))
                {
                        rules->stringCharPtr = 1;
                        return 1;
                }
        }
 
+               /* Array to element pointer conversion */
+               if(ILType_IsArray(fromType) && ILType_IsPointer(toType))
+               {
+                       ILType *elementType;
+
+                       /* We can implicitely cast every pointer to void * */
+                       if(ILTypeToMachineType(ILType_Ref(toType)) == 
ILMachineType_Void)
+                       {
+                               rules->arrayElementPtr = 1;
+                               return 1;
+                       }
+
+                       elementType = ILTypeGetElemType(fromType);
+                       if(elementType)
+                       {
+                               if(ILTypeIdentical(elementType, 
ILType_Ref(toType)))
+                               {
+                                       rules->arrayElementPtr = 1;
+                                       return 1;
+                               }
+                       }
+               }
+       }
+
        /* Could not find an appropriate conversion */
        return 0;
 }
@@ -432,6 +464,7 @@
        rules->builtin = 0;
        rules->pointerNull = 0;
        rules->stringCharPtr = 0;
+       rules->arrayElementPtr = 0;
 
        /* Strip type prefixes before we start */
        fromType = ILTypeStripPrefixes(fromType);
@@ -950,6 +983,15 @@
                yysetfilename(*parent, yygetfilename(node));
                yysetlinenum(*parent, yygetlinenum(node));
        }
+
+       /* Cast a managed array to a pointer to the element type */
+       if(rules->arrayElementPtr)
+       {
+               *parent = ILNode_CastArrayToElementPtr_create(node,
+                                                                               
        ILTypeStripPrefixes(fromType));
+               yysetfilename(*parent, yygetfilename(node));
+               yysetlinenum(*parent, yygetlinenum(node));
+       }
 }
 
 /*

Index: codegen/cg_misc.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_misc.tc,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -b -r1.52 -r1.53
--- codegen/cg_misc.tc  12 Dec 2008 19:38:07 -0000      1.52
+++ codegen/cg_misc.tc  14 Dec 2008 13:03:34 -0000      1.53
@@ -109,6 +109,10 @@
 {
        return ILMachineType_UnmanagedPtr;
 }
+ILNode_GetType(ILNode_CastArrayToElementPtr)
+{
+       return ILMachineType_UnmanagedPtr;
+}
 
 /*
  * Get the type associated with a user-defined conversion.
@@ -696,6 +700,104 @@
        return ILMachineType_UnmanagedPtr;
 }
 
+%{
+
+/*
+ * Push the low bounds of an Array on the stack
+ * Returns the number of low bounds pushed on the stack.
+ */
+static int ILGenPushArrayLowBounds(ILGenInfo *info, ILType *arrayType)
+{
+       int bounds = 0;
+
+       if(arrayType && ILType_IsComplex(arrayType))
+       {
+               if(arrayType->kind__ == IL_TYPE_COMPLEX_ARRAY_CONTINUE)
+               {
+                       bounds = ILGenPushArrayLowBounds(info, 
ILType_ElemType(arrayType));
+                       ILGenInt32(info, ILType_LowBound(arrayType));
+                       ++bounds;
+               }
+               else if(arrayType->kind__ == IL_TYPE_COMPLEX_ARRAY)
+               {
+                       ILGenInt32(info, ILType_LowBound(arrayType));
+                       ++bounds;
+               }
+       }
+       return bounds;
+}
+
+%}
+
+ILNode_GenValue(ILNode_CastArrayToElementPtr)
+{
+       ILLabel doneLabel = ILLabel_Undefined;
+       ILLabel nullLabel = ILLabel_Undefined;
+       ILLabel length0Label = ILLabel_Undefined;
+       ILType *elementType;
+       int stackUsed = 1;
+
+       elementType = ILTypeGetElemType(node->arrayType);
+       ILNode_GenValue(node->expr, info);
+       ILGenSimple(info, IL_OP_DUP);
+       ILGenJump(info, IL_OP_BRFALSE, &nullLabel);
+       ILGenSimple(info, IL_OP_DUP);
+       if(ILType_IsSimpleArray(node->arrayType))
+       {
+               ILGenSimple(info, IL_OP_LDLEN);
+       }
+       else
+       {
+               ILGenCallVirtual(info, "int32 "
+                                               
"[.library]System.Array::get_Length()");        
+       }
+       ILGenJump(info, IL_OP_BRFALSE, &length0Label);
+       if(ILType_IsSimpleArray(node->arrayType))
+       {               
+               ILGenSimple(info, IL_OP_LDC_I4_0);
+               ++stackUsed;
+               ILGenTypeToken(info, IL_OP_LDELEMA, elementType);
+       }
+       else
+       {
+               ILType *arrayType = node->arrayType;
+               int rank;
+
+               rank = ILTypeGetRank(arrayType);
+               if(rank > 0)
+               {
+                       ILClass *classInfo;
+                       ILMethod *method = 0;
+
+                       classInfo = ILClassResolve(ILTypeToClass(info, 
arrayType));
+                       method = (ILMethod *)ILClassNextMemberMatch(classInfo, 
0,
+                                                                
IL_META_MEMBERKIND_METHOD, "Address", 0);
+
+                       /* Push the low bounds on the stack for the Address 
call */
+                       ILGenPushArrayLowBounds(info, arrayType);
+                       ILGenCallByMethod(info, method);
+                       stackUsed += rank;
+               }
+               else
+               {
+                       /* Looks like arrayType is no array */
+                       ILGenSimple(info, IL_OP_POP);
+                       ILGenSimple(info, IL_OP_LDNULL);
+               }
+       }
+       ILGenSimple(info, IL_OP_CONV_I);
+       ILGenJump(info, IL_OP_BR, &doneLabel);
+       ILGenLabel(info, &length0Label);
+       ILGenSimple(info, IL_OP_POP);
+       ILGenSimple(info, IL_OP_LDNULL);
+       ILGenLabel(info, &nullLabel);
+       ILGenSimple(info, IL_OP_CONV_I);
+       ILGenLabel(info, &doneLabel);
+       ILGenExtend(info, stackUsed);
+
+       return ILMachineType_UnmanagedPtr;
+}
+
 /*
  * Generate value code for a user conversion expression.
  */

Index: codegen/cg_nodes.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_nodes.tc,v
retrieving revision 1.93
retrieving revision 1.94
diff -u -b -r1.93 -r1.94
--- codegen/cg_nodes.tc 9 Dec 2008 21:18:21 -0000       1.93
+++ codegen/cg_nodes.tc 14 Dec 2008 13:03:35 -0000      1.94
@@ -408,6 +408,10 @@
 %node ILNode_CastStringToCharPtr ILNode_UnaryExpression =
 {
 }
+%node ILNode_CastArrayToElementPtr ILNode_UnaryExpression =
+{
+       ILType *arrayType;
+}
 %node ILNode_Conditional ILNode_TernaryExpression
 %node ILNode_Deref ILNode_LValueNoRef =
 {

Index: codegen/jv_misc.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/jv_misc.tc,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -b -r1.32 -r1.33
--- codegen/jv_misc.tc  9 Dec 2008 21:18:21 -0000       1.32
+++ codegen/jv_misc.tc  14 Dec 2008 13:03:35 -0000      1.33
@@ -292,6 +292,13 @@
        JavaGenSimple(info, JAVA_OP_ICONST_0);
        return ILMachineType_UnmanagedPtr;
 }
+JavaGenValue(ILNode_CastArrayToElementPtr)
+{
+       JavaGenValue(node->expr, info);
+       JavaGenSimple(info, JAVA_OP_POP);
+       JavaGenSimple(info, JAVA_OP_ICONST_0);
+       return ILMachineType_UnmanagedPtr;
+}
 
 /*
  * Generate value code for a user conversion expression.

Index: cscc/c/c_name.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_name.tc,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- cscc/c/c_name.tc    9 Dec 2008 21:18:21 -0000       1.3
+++ cscc/c/c_name.tc    14 Dec 2008 13:03:35 -0000      1.4
@@ -507,6 +507,12 @@
        return CNameCreateUnaryBracketed
                ("(__wchar__ *)", ILNode_CName(node->expr), C_PREC_UNARY);
 }
+ILNode_CName(ILNode_CastArrayToElementPtr)
+{
+       /* TODO */
+       return CNameCreateUnaryBracketed
+               ("(? *)", ILNode_CName(node->expr), C_PREC_UNARY);
+}
 ILNode_CName(ILNode_Conditional)
 {
        CName name1 = ILNode_CName(node->expr1);

Index: cscc/c/c_oper.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_oper.tc,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -b -r1.45 -r1.46
--- cscc/c/c_oper.tc    9 Dec 2008 21:18:22 -0000       1.45
+++ cscc/c/c_oper.tc    14 Dec 2008 13:03:35 -0000      1.46
@@ -2175,6 +2175,17 @@
 }
 
 /*
+ * Perform semantic analysis for the cast from C# Array to a C pointer to
+ * the array's element type.
+ */
+ILNode_CSemAnalysis(ILNode_CastArrayToElementPtr)
+{
+       /* This will never be called, as the grammar uses "CastType" instead */
+       return CSemValueError;
+}
+
+
+/*
  * Perform semantic analysis for C to C# string conversion.
  */
 ILNode_CSemAnalysis(ILNode_CToCSharpString)

Index: cscc/csharp/cs_oper.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_oper.tc,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -b -r1.52 -r1.53
--- cscc/csharp/cs_oper.tc      9 Dec 2008 21:18:22 -0000       1.52
+++ cscc/csharp/cs_oper.tc      14 Dec 2008 13:03:35 -0000      1.53
@@ -2640,6 +2640,10 @@
 {
        return CSSemValueDefault;
 }
+ILNode_SemAnalysis(ILNode_CastArrayToElementPtr)
+{
+       return CSSemValueDefault;
+}
 
 /*
  * Perform semantic analysis for the user-defined logical AND operator.




reply via email to

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