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_ainit.tc,NONE,1.1 Makefile.am,


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnet/cscc/c c_ainit.tc,NONE,1.1 Makefile.am,1.10,1.11 c_defs.tc,1.20,1.21 c_grammar.y,1.50,1.51 c_internal.h,1.9,1.10 c_lvalue.tc,1.13,1.14 c_oper.tc,1.28,1.29 c_stubs.tc,1.13,1.14 c_types.c,1.33,1.34 c_types.h,1.16,1.17
Date: Thu, 26 Jun 2003 03:05:50 -0400

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

Modified Files:
        Makefile.am c_defs.tc c_grammar.y c_internal.h c_lvalue.tc 
        c_oper.tc c_stubs.tc c_types.c c_types.h 
Added Files:
        c_ainit.tc 
Log Message:


Move the array initializer node types into "c_ainit.tc";
implement a better algorithm for calculating the size of an array initializer.


--- NEW FILE ---
/*
 * c_ainit.tc - Array initializer handling for C.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

%{

ILUInt32 CArrayInitializerSize(ILType *type, ILNode *init)
{
        ILType *elemType = CTypeGetElemType(type);
        ILNode *list = ((ILNode_CArrayInit *)init)->expr;
        ILNode_ListIter iter;
        ILUInt32 len = 0;
        ILUInt32 numElems;
        ILNode *node;

        /* Scan the list, skipping over elements as we find them */
        ILNode_ListIter_Init(&iter, list);
        while((node = ILNode_ListIter_Next(&iter)) != 0)
        {
                if(yyisa(node, ILNode_CArrayInit))
                {
                        /* Nested array dimension or struct value */
                        ++len;
                }
                else if(CTypeIsStruct(elemType))
                {
                        /* Struct value which is inline within its parent array 
*/
                        numElems = CTypeGetNumFields(elemType);
                        if(!numElems)
                        {
                                CCErrorOnLine(yygetfilename(node), 
yygetlinenum(node),
                                                          _("cannot initialize 
empty `struct' types"));
                                return 1;
                        }
                        while(numElems > 1 && node)
                        {
                                node = ILNode_ListIter_Next(&iter);
                                --numElems;
                        }
                        ++len;
                }
                else if(CTypeIsUnion(elemType))
                {
                        CCErrorOnLine(yygetfilename(node), yygetlinenum(node),
                                                  _("`union' initializers are 
not supported"));
                        return 1;
                }
                else if(CTypeIsArray(elemType))
                {
                        /* Nested array which is inline within its parent 
dimension */
                        numElems = CTypeGetNumElems(elemType);
                        while(numElems > 1 && node)
                        {
                                node = ILNode_ListIter_Next(&iter);
                                --numElems;
                        }
                        ++len;
                }
                else
                {
                        /* Ordinary array element */
                        ++len;
                }
        }

        /* Return the final length to the caller */
        return len;
}

%}

/*
 * Perform semantic analysis for an array initialization expression.
 */
ILNode_CSemAnalysis(ILNode_CArrayInit)
{
        /* TODO */
        return CSemValueError;
}

/*
 * Stub out code generation for array initializers.
 */
ILNode_GetType(ILNode_CArrayInit),
ILNode_GenValue(ILNode_CArrayInit),
JavaGenValue(ILNode_CArrayInit)
{
        return ILMachineType_Void;
}

Index: Makefile.am
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/Makefile.am,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** Makefile.am 4 Dec 2002 00:48:33 -0000       1.10
--- Makefile.am 26 Jun 2003 07:05:47 -0000      1.11
***************
*** 2,6 ****
  noinst_LIBRARIES = libILCLang.a
  
! TREECC_INPUTS = c_builtin.tc \
                                c_defs.tc \
                                c_const.tc \
--- 2,7 ----
  noinst_LIBRARIES = libILCLang.a
  
! TREECC_INPUTS = c_ainit.tc \
!                               c_builtin.tc \
                                c_defs.tc \
                                c_const.tc \

Index: c_defs.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_defs.tc,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -r1.20 -r1.21
*** c_defs.tc   23 Dec 2002 22:43:26 -0000      1.20
--- c_defs.tc   26 Jun 2003 07:05:47 -0000      1.21
***************
*** 410,413 ****
--- 410,414 ----
  }
  %node ILNode_CToCSharpString ILNode_UnaryExpression
+ %node ILNode_CArrayInit ILNode_UnaryExpression
  
  %output "c_semantics.c"
***************
*** 462,465 ****
--- 463,467 ----
   * Include C-specific definitions.
   */
+ %include "c_ainit.tc"
  %include "c_builtin.tc"
  %include "c_const.tc"

Index: c_grammar.y
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_grammar.y,v
retrieving revision 1.50
retrieving revision 1.51
diff -C2 -r1.50 -r1.51
*** c_grammar.y 26 Jun 2003 06:12:46 -0000      1.50
--- c_grammar.y 26 Jun 2003 07:05:47 -0000      1.51
***************
*** 299,303 ****
  
        /* TODO: this is a hack for missing array assignment - fix later */
!       if(yyisa(init, ILNode_ArrayInit))
        {
                return;
--- 299,303 ----
  
        /* TODO: this is a hack for missing array assignment - fix later */
!       if(yyisa(init, ILNode_CArrayInit))
        {
                return;
***************
*** 550,554 ****
  
        /* If this isn't an array initializer, then bail out */
!       if(!yyisa(init, ILNode_ArrayInit))
        {
                CCErrorOnLine(yygetfilename(init), yygetlinenum(init),
--- 550,554 ----
  
        /* If this isn't an array initializer, then bail out */
!       if(!yyisa(init, ILNode_CArrayInit))
        {
                CCErrorOnLine(yygetfilename(init), yygetlinenum(init),
***************
*** 557,562 ****
        }
  
!       /* TODO: handle arrays of structures that don't have nested bracketing 
*/
!       return ILNode_List_Length(((ILNode_ArrayInit *)init)->expr);
  }
  
--- 557,562 ----
        }
  
!       /* Calculate the size from the node, using the type as a guide */
!       return CArrayInitializerSize(type, init);
  }
  
***************
*** 2459,2464 ****
  Initializer
        : AssignmentExpression                          { $$ = $1; }
!       | '{' InitializerList '}'                       { $$ = 
ILNode_ArrayInit_create($2); }
!       | '{' InitializerList ',' '}'           { $$ = 
ILNode_ArrayInit_create($2); }
        ;
  
--- 2459,2464 ----
  Initializer
        : AssignmentExpression                          { $$ = $1; }
!       | '{' InitializerList '}'                       { $$ = 
ILNode_CArrayInit_create($2); }
!       | '{' InitializerList ',' '}'           { $$ = 
ILNode_CArrayInit_create($2); }
        ;
  

Index: c_internal.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_internal.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** c_internal.h        10 Aug 2002 02:16:42 -0000      1.9
--- c_internal.h        26 Jun 2003 07:05:47 -0000      1.10
***************
*** 102,105 ****
--- 102,111 ----
  void CGenSizeOf(ILGenInfo *info, ILType *type);
  
+ /*
+  * Get the size of an array initializer for a particular array or struct type.
+  * The "init" parameter is guaranteed to be a node of type 
"ILNode_CArrayInit".
+  */
+ ILUInt32 CArrayInitializerSize(ILType *type, ILNode *init);
+ 
  #ifdef        __cplusplus
  };

Index: c_lvalue.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_lvalue.tc,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -r1.13 -r1.14
*** c_lvalue.tc 26 Jun 2003 00:47:31 -0000      1.13
--- c_lvalue.tc 26 Jun 2003 07:05:47 -0000      1.14
***************
*** 1272,1281 ****
  }
  
- ILNode_CSemAnalysis(ILNode_ArrayInit)
- {
-       /* TODO */
-       return CSemValueError;
- }
- 
  /*
   * Perform semantic analysis for a pointer dereference node.
--- 1272,1275 ----

Index: c_oper.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_oper.tc,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -r1.28 -r1.29
*** c_oper.tc   25 Jun 2003 09:38:58 -0000      1.28
--- c_oper.tc   26 Jun 2003 07:05:47 -0000      1.29
***************
*** 1841,1845 ****
                }
        }
!       else if(yyisa(node->expr2, ILNode_ArrayInit))
        {
                /* TODO */
--- 1841,1845 ----
                }
        }
!       else if(yyisa(node->expr2, ILNode_CArrayInit))
        {
                /* TODO */

Index: c_stubs.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_stubs.tc,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -r1.13 -r1.14
*** c_stubs.tc  29 Nov 2002 21:58:12 -0000      1.13
--- c_stubs.tc  26 Jun 2003 07:05:47 -0000      1.14
***************
*** 119,123 ****
  ILNode_CSemAnalysis(ILNode_CAttributeValue),
  ILNode_CSemAnalysis(ILNode_CBitField),
! ILNode_CSemAnalysis(ILNode_ArrayLength)
  {
        /* Nothing to do here */
--- 119,124 ----
  ILNode_CSemAnalysis(ILNode_CAttributeValue),
  ILNode_CSemAnalysis(ILNode_CBitField),
! ILNode_CSemAnalysis(ILNode_ArrayLength),
! ILNode_CSemAnalysis(ILNode_ArrayInit)
  {
        /* Nothing to do here */

Index: c_types.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_types.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -C2 -r1.33 -r1.34
*** c_types.c   26 Jun 2003 06:12:46 -0000      1.33
--- c_types.c   26 Jun 2003 07:05:47 -0000      1.34
***************
*** 2001,2004 ****
--- 2001,2033 ----
  }
  
+ ILUInt32 CTypeGetNumFields(ILType *type)
+ {
+       ILClass *classInfo;
+       ILField *field;
+       ILUInt32 num;
+ 
+       type = ILTypeStripPrefixes(type);
+       if(CTypeIsStruct(type) || CTypeIsUnion(type))
+       {
+               classInfo = ILType_ToValueType(type);
+               field = 0;
+               num = 0;
+               while((field = (ILField *)ILClassNextMemberByKind
+                                       (classInfo, (ILMember *)field,
+                                        IL_META_MEMBERKIND_FIELD)) != 0)
+               {
+                       if(!ILField_IsStatic(field))
+                       {
+                               ++num;
+                       }
+               }
+               return num;
+       }
+       else
+       {
+               return 0;
+       }
+ }
+ 
  ILType *CTypeGetPtrRef(ILType *type)
  {

Index: c_types.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_types.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -r1.16 -r1.17
*** c_types.h   26 Jun 2003 06:12:46 -0000      1.16
--- c_types.h   26 Jun 2003 07:05:47 -0000      1.17
***************
*** 272,275 ****
--- 272,280 ----
  
  /*
+  * Get the number of fields in a struct or union type.
+  */
+ ILUInt32 CTypeGetNumFields(ILType *type);
+ 
+ /*
   * Get the type that is referenced by a pointer type.
   */





reply via email to

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