[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnet/cscc/c c_ainit.tc,1.2,1.3 c_defs.tc,1.2
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnet/cscc/c c_ainit.tc,1.2,1.3 c_defs.tc,1.21,1.22 c_grammar.y,1.51,1.52 c_oper.tc,1.29,1.30 |
Date: |
Thu, 26 Jun 2003 22:04:49 -0400 |
Update of /cvsroot/dotgnu-pnet/pnet/cscc/c
In directory subversions:/tmp/cvs-serv22228/cscc/c
Modified Files:
c_ainit.tc c_defs.tc c_grammar.y c_oper.tc
Log Message:
Rearrange the array initialization code so that all code generation and
semantic analysis is in "c_ainit.tc".
Index: c_ainit.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_ainit.tc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** c_ainit.tc 27 Jun 2003 01:15:54 -0000 1.2
--- c_ainit.tc 27 Jun 2003 02:04:47 -0000 1.3
***************
*** 162,170 ****
/*
* Perform semantic analysis for an array initialization expression.
*/
ILNode_CSemAnalysis(ILNode_CArrayInit)
{
! /* Not used - semantic analysis for initializers is handled elsewhere */
! return CSemValueError;
}
--- 162,187 ----
/*
* Perform semantic analysis for an array initialization expression.
+ *
+ * This is only called when used in a statement like "int x = {y};"
+ * which is semantically equivalent to "int x = y;". It is never
+ * called for regular arrays and structures.
*/
ILNode_CSemAnalysis(ILNode_CArrayInit)
{
! ILNode_ListIter iter;
! ILNode *expr;
!
! /* Replace the array initializer with its first element */
! ILNode_ListIter_Init(&iter, node->expr);
! expr = ILNode_ListIter_Next(&iter);
! if(ILNode_ListIter_Next(&iter) != 0)
! {
! CCWarningOnLine(yygetfilename(node), yygetlinenum(node),
! _("excess elements in scalar
initializer"));
! }
! *parent = expr;
!
! /* Perform semantic analysis on the first element */
! return ILNode_CSemAnalysis(expr, info, parent, stmtLevel);
}
***************
*** 178,179 ****
--- 195,295 ----
return ILMachineType_Void;
}
+
+ /*
+ * Perform semantic analysis for the array assignment statement.
+ */
+ ILNode_CSemAnalysis(ILNode_CAssignArray)
+ {
+ CSemValue value1;
+ ILType *elemType;
+ ILUInt32 arraySize;
+ ILUInt32 initSize;
+
+ /* Perform semantic analysis on the destination expression.
+ We expect it to be either an l-value or a decayed r-value */
+ value1 = ILNode_CSemAnalysis(node->expr1, info, &(node->expr1), 0);
+ if(CSemIsDecayed(value1))
+ {
+ /* Un-decay the array type */
+ CSemSetLValue(value1, CSemGetDecayedType(value1));
+ }
+ else if(!CSemIsLValue(value1))
+ {
+ if(!CSemIsError(value1))
+ {
+ CCErrorOnLine(yygetfilename(node), yygetlinenum(node),
+ _("invalid lvalue in
assignment"));
+ }
+ return CSemValueError;
+ }
+
+ /* Determine the type of assignment based on the r-value */
+ if(yyisa(node->expr2, ILNode_CString))
+ {
+ /* Assign the contents of a string */
+ elemType =
CTypeWithoutQuals(CTypeGetElemType(CSemGetType(value1)));
+ if(elemType != ILType_Int8 && elemType != ILType_UInt8)
+ {
+ CCErrorOnLine(yygetfilename(node), yygetlinenum(node),
+ _("invalid initializer"));
+ return CSemValueError;
+ }
+ arraySize = CTypeGetNumElems(CSemGetType(value1));
+ initSize = (ILUInt32)(((ILNode_CString *)(node->expr2))->len);
+ if(initSize > arraySize)
+ {
+ CCWarningOnLine(yygetfilename(node), yygetlinenum(node),
+ _("initializer-string for array of chars is
too long"));
+ }
+ }
+ else if(yyisa(node->expr2, ILNode_CArrayInit))
+ {
+ /* TODO */
+ #if 0
+ CCErrorOnLine(yygetfilename(node), yygetlinenum(node),
+ _("array/structure assignment is not
implemented yet"));
+ #endif
+ }
+ else
+ {
+ /* The grammar already reported an error for this case */
+ return CSemValueError;
+ }
+
+ /* Array assignment is used at the statement level of a function */
+ return CSemValueDefault;
+ }
+
+ /*
+ * Perform semantic analysis for the struct assignment statement.
+ */
+ ILNode_CSemAnalysis(ILNode_CAssignStruct)
+ {
+ /* TODO */
+ return CSemValueError;
+ }
+
+ /*
+ * Generate discard code for an array assignment statement.
+ */
+ ILNode_GenDiscard(ILNode_CAssignArray)
+ {
+ /* TODO */
+ }
+ JavaGenDiscard(ILNode_CAssignArray)
+ {
+ /* Nothing to do here */
+ }
+
+ /*
+ * Generate discard code for the struct assignment statement.
+ */
+ ILNode_GenDiscard(ILNode_CAssignStruct)
+ {
+ /* TODO */
+ }
+ JavaGenDiscard(ILNode_CAssignStruct)
+ {
+ /* Nothing to do here */
+ }
+
Index: c_defs.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_defs.tc,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -r1.21 -r1.22
*** c_defs.tc 26 Jun 2003 07:05:47 -0000 1.21
--- c_defs.tc 27 Jun 2003 02:04:47 -0000 1.22
***************
*** 409,412 ****
--- 409,417 ----
ILNode *expr2;
}
+ %node ILNode_CAssignStruct ILNode_Statement =
+ {
+ ILNode *expr1;
+ ILNode *expr2;
+ }
%node ILNode_CToCSharpString ILNode_UnaryExpression
%node ILNode_CArrayInit ILNode_UnaryExpression
Index: c_grammar.y
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_grammar.y,v
retrieving revision 1.51
retrieving revision 1.52
diff -C2 -r1.51 -r1.52
*** c_grammar.y 26 Jun 2003 07:05:47 -0000 1.51
--- c_grammar.y 27 Jun 2003 02:04:47 -0000 1.52
***************
*** 292,318 ****
/*
! * Add a global initializer statement to the pending list.
*/
! static void AddInitializer(char *name, ILNode *node, ILType *type, ILNode
*init)
{
ILNode *stmt;
- /* TODO: this is a hack for missing array assignment - fix later */
if(yyisa(init, ILNode_CArrayInit))
{
! return;
}
!
! /* Build the initialization statement */
! stmt = ILNode_CGlobalVar_create(name, type, CTypeDecay(&CCCodeGen,
type));
! CGenCloneLine(stmt, node);
! if(CTypeIsArray(type))
{
! stmt = ILNode_CAssignArray_create(stmt, init);
}
else
{
! stmt = ILNode_Assign_create(stmt, init);
}
CGenCloneLine(stmt, init);
--- 292,339 ----
/*
! * Build an appropriate assignment statement for initializing a variable.
*/
! static ILNode *BuildAssignInit(ILNode *var, ILNode *init, ILType *type)
{
ILNode *stmt;
if(yyisa(init, ILNode_CArrayInit))
{
! if(CTypeIsArray(type))
! {
! stmt = ILNode_CAssignArray_create(var, init);
! }
! else if(CTypeIsStruct(type))
! {
! stmt = ILNode_CAssignStruct_create(var, init);
! }
! else
! {
! stmt = ILNode_Assign_create(var, init);
! }
}
! else if(CTypeIsArray(type) && yyisa(init, ILNode_CString))
{
! stmt = ILNode_CAssignArray_create(var, init);
}
else
{
! stmt = ILNode_Assign_create(var, init);
}
+
+ return stmt;
+ }
+
+ /*
+ * Add a global initializer statement to the pending list.
+ */
+ static void AddInitializer(char *name, ILNode *node, ILType *type, ILNode
*init)
+ {
+ ILNode *stmt;
+
+ /* Build the initialization statement */
+ stmt = ILNode_CGlobalVar_create(name, type, CTypeDecay(&CCCodeGen,
type));
+ CGenCloneLine(stmt, node);
+ stmt = BuildAssignInit(stmt, init, type);
CGenCloneLine(stmt, init);
***************
*** 777,788 ****
CTypeDecay(&CCCodeGen, type));
CGenCloneLine(assign, decl.node);
! if(CTypeIsArray(type))
! {
! assign =
ILNode_CAssignArray_create(assign, init);
! }
! else
! {
! assign = ILNode_Assign_create(assign,
init);
! }
CGenCloneLine(assign, init);
ILNode_List_Add(*list, assign);
--- 798,802 ----
CTypeDecay(&CCCodeGen, type));
CGenCloneLine(assign, decl.node);
! assign = BuildAssignInit(assign, init, type);
CGenCloneLine(assign, init);
ILNode_List_Add(*list, assign);
Index: c_oper.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_oper.tc,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -r1.29 -r1.30
*** c_oper.tc 26 Jun 2003 07:05:47 -0000 1.29
--- c_oper.tc 27 Jun 2003 02:04:47 -0000 1.30
***************
*** 1795,1873 ****
/*
- * Perform semantic analysis for the array assignment statement.
- */
- ILNode_CSemAnalysis(ILNode_CAssignArray)
- {
- CSemValue value1;
- ILType *elemType;
- ILUInt32 arraySize;
- ILUInt32 initSize;
-
- /* Perform semantic analysis on the destination expression.
- We expect it to be either an l-value or a decayed r-value */
- value1 = ILNode_CSemAnalysis(node->expr1, info, &(node->expr1), 0);
- if(CSemIsDecayed(value1))
- {
- /* Un-decay the array type */
- CSemSetLValue(value1, CSemGetDecayedType(value1));
- }
- else if(!CSemIsLValue(value1))
- {
- if(!CSemIsError(value1))
- {
- CCErrorOnLine(yygetfilename(node), yygetlinenum(node),
- _("invalid lvalue in
assignment"));
- }
- return CSemValueError;
- }
-
- /* Determine the type of assignment based on the r-value */
- if(yyisa(node->expr2, ILNode_CString))
- {
- /* Assign the contents of a string */
- elemType =
CTypeWithoutQuals(CTypeGetElemType(CSemGetType(value1)));
- if(elemType != ILType_Int8 && elemType != ILType_UInt8)
- {
- CCErrorOnLine(yygetfilename(node), yygetlinenum(node),
- _("invalid initializer"));
- return CSemValueError;
- }
- arraySize = CTypeGetNumElems(CSemGetType(value1));
- initSize = (ILUInt32)(((ILNode_CString *)(node->expr2))->len);
- if(initSize > arraySize)
- {
- CCWarningOnLine(yygetfilename(node), yygetlinenum(node),
- _("initializer-string for array of chars is
too long"));
- }
- }
- else if(yyisa(node->expr2, ILNode_CArrayInit))
- {
- /* TODO */
- CCErrorOnLine(yygetfilename(node), yygetlinenum(node),
- _("array/structure assignment is not
implemented yet"));
- }
- else
- {
- /* The grammar already reported an error for this case */
- return CSemValueError;
- }
-
- /* Array assignment is used at the statement level of a function */
- return CSemValueDefault;
- }
-
- /*
- * Generate discard code for an array assignment statement.
- */
- ILNode_GenDiscard(ILNode_CAssignArray)
- {
- /* TODO */
- }
- JavaGenDiscard(ILNode_CAssignArray)
- {
- /* Nothing to do here */
- }
-
- /*
* Perform semantic analysis for the pre-increment expression.
*/
--- 1795,1798 ----
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnet/cscc/c c_ainit.tc,1.2,1.3 c_defs.tc,1.21,1.22 c_grammar.y,1.51,1.52 c_oper.tc,1.29,1.30,
Rhys Weatherley <address@hidden> <=
- Prev by Date:
[Dotgnu-pnet-commits] CVS: pnet ChangeLog,1.2473,1.2474
- Next by Date:
[Dotgnu-pnet-commits] CVS: pnet/cscc/c c_function.c,1.20,1.21 c_function.h,1.5,1.6 c_grammar.y,1.52,1.53
- Previous by thread:
[Dotgnu-pnet-commits] CVS: pnet ChangeLog,1.2473,1.2474
- Next by thread:
[Dotgnu-pnet-commits] CVS: pnet/cscc/c c_function.c,1.20,1.21 c_function.h,1.5,1.6 c_grammar.y,1.52,1.53
- Index(es):