[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnet/cscc/csharp cs_grammar.y,1.54,1.55 cs_l
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnet/cscc/csharp cs_grammar.y,1.54,1.55 cs_lvalue.tc,1.37,1.38 cs_oper.tc,1.36,1.37 |
Date: |
Wed, 26 Feb 2003 21:57:46 -0500 |
Update of /cvsroot/dotgnu-pnet/pnet/cscc/csharp
In directory subversions:/tmp/cvs-serv1959/cscc/csharp
Modified Files:
cs_grammar.y cs_lvalue.tc cs_oper.tc
Log Message:
Implement array access operations on pointer types.
Index: cs_grammar.y
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_grammar.y,v
retrieving revision 1.54
retrieving revision 1.55
diff -C2 -r1.54 -r1.55
*** cs_grammar.y 22 Feb 2003 11:21:01 -0000 1.54
--- cs_grammar.y 27 Feb 2003 02:57:43 -0000 1.55
***************
*** 1606,1610 ****
| INC_OP PrefixedUnaryExpression { MakeUnary(PreInc, $2); }
| DEC_OP PrefixedUnaryExpression { MakeUnary(PreDec, $2); }
! | '*' PrefixedUnaryExpression { MakeUnary(Deref, $2); }
| '&' PrefixedUnaryExpression { MakeUnary(AddressOf, $2); }
;
--- 1606,1610 ----
| INC_OP PrefixedUnaryExpression { MakeUnary(PreInc, $2); }
| DEC_OP PrefixedUnaryExpression { MakeUnary(PreDec, $2); }
! | '*' PrefixedUnaryExpression { MakeBinary(Deref, $2, 0); }
| '&' PrefixedUnaryExpression { MakeUnary(AddressOf, $2); }
;
Index: cs_lvalue.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_lvalue.tc,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -r1.37 -r1.38
*** cs_lvalue.tc 26 Feb 2003 23:03:19 -0000 1.37
--- cs_lvalue.tc 27 Feb 2003 02:57:43 -0000 1.38
***************
*** 1232,1239 ****
*/
static ILNode *ArrayIndexToInt(ILGenInfo *info, ILNode *node,
! ILNode **parent,
ILType *currentType)
{
ILNode *result;
! if(info->overflowInsns)
{
/* We are already in overflow mode, so just wrap it */
--- 1232,1252 ----
*/
static ILNode *ArrayIndexToInt(ILGenInfo *info, ILNode *node,
! ILNode **parent,
ILType *currentType,
! int pointerAccess)
{
ILNode *result;
! if(pointerAccess)
! {
! /* Cast to a native integer if accessing by pointer */
! if(currentType == ILType_Int32 || currentType == ILType_Int64)
! {
! result = ILNode_CastSimple_create(node,
ILMachineType_NativeInt);
! }
! else
! {
! result = ILNode_CastSimple_create(node,
ILMachineType_NativeUInt);
! }
! }
! else if(info->overflowInsns)
{
/* We are already in overflow mode, so just wrap it */
***************
*** 1252,1255 ****
--- 1265,1303 ----
}
+ /*
+ * Coerce an array index to "int", "uint", "long", or "ulong".
+ */
+ static void CoerceArrayIndex(ILGenInfo *info, ILNode **node,
+ ILNode **parent,
ILType *type,
+ int pointerAccess)
+ {
+ if(ILCoerce(info, *node, parent, type, ILType_Int32, 1))
+ {
+ *node = ArrayIndexToInt
+ (info, *parent, parent, ILType_Int32, pointerAccess);
+ }
+ else if(ILCoerce(info, *node, parent, type, ILType_UInt32, 1))
+ {
+ *node = ArrayIndexToInt
+ (info, *parent, parent, ILType_UInt32, pointerAccess);
+ }
+ else if(ILCoerce(info, *node, parent, type, ILType_Int64, 1))
+ {
+ *node = ArrayIndexToInt
+ (info, *parent, parent, ILType_Int64, pointerAccess);
+ }
+ else if(ILCoerce(info, *node, parent, type, ILType_UInt64, 1))
+ {
+ *node = ArrayIndexToInt
+ (info, *parent, parent, ILType_Int64, pointerAccess);
+ }
+ else
+ {
+ CCErrorOnLine(yygetfilename(*node), yygetlinenum(*node),
+ "no conversion from `%s' to `int'",
+ CSTypeToName(type));
+ }
+ }
+
%}
***************
*** 1269,1272 ****
--- 1317,1321 ----
ILMethod *setMethod;
ILType *objectType;
+ ILNode *tempNode;
/* Perform semantic analysis on the array expression */
***************
*** 1294,1330 ****
for(argNum = 0; argNum < numArgs; ++argNum)
{
! if(ILCoerce(info, args[argNum].node,
args[argNum].parent,
! args[argNum].type, ILType_Int32,1))
! {
! args[argNum].node = *(args[argNum].parent);
! }
! else if(ILCoerce(info, args[argNum].node,
args[argNum].parent,
! args[argNum].type, ILType_UInt32,1))
! {
! args[argNum].node =
! ArrayIndexToInt(info,
*(args[argNum].parent),
!
args[argNum].parent, ILType_UInt32);
! }
! else if(ILCoerce(info, args[argNum].node,
args[argNum].parent,
! args[argNum].type, ILType_Int64,1))
! {
! args[argNum].node =
! ArrayIndexToInt(info,
*(args[argNum].parent),
!
args[argNum].parent, ILType_Int64);
! }
! else if(ILCoerce(info, args[argNum].node,
args[argNum].parent,
! args[argNum].type, ILType_UInt64,1))
! {
! args[argNum].node =
! ArrayIndexToInt(info,
*(args[argNum].parent),
!
args[argNum].parent, ILType_UInt64);
! }
! else
! {
! CCErrorOnLine(yygetfilename(args[argNum].node),
!
yygetlinenum(args[argNum].node),
! "no conversion from
`%s' to `int'",
!
CSTypeToName(args[argNum].type));
! }
}
--- 1343,1348 ----
for(argNum = 0; argNum < numArgs; ++argNum)
{
! CoerceArrayIndex(info, &(args[argNum].node),
args[argNum].parent,
! args[argNum].type, 0);
}
***************
*** 1344,1347 ****
--- 1362,1408 ----
/* Construct the semantic value for the element type */
CSSemSetLValue(value, node->elemType);
+ }
+ else if(ILType_IsPointer(CSSemGetType(value)))
+ {
+ /* Access to an array defined by a pointer */
+ CCUnsafeMessage(info, (ILNode *)node,
+ "unsafe pointer-based array
access");
+ objectType = CSSemGetType(value);
+ if(numArgs != 1)
+ {
+ CCErrorOnLine(yygetfilename(node->indices),
+ yygetlinenum(node->indices),
+ "incorrect number of indices
for `%s'",
+ CSTypeToName(objectType));
+ }
+ objectType = ILTypeStripPrefixes(ILType_Ref(objectType));
+ if(objectType == ILType_Void)
+ {
+ CCErrorOnLine(yygetfilename(node), yygetlinenum(node),
+ "`void *' cannot be used for
an array access");
+ objectType = ILType_UInt8;
+ }
+ CoerceArrayIndex(info, &(args[0].node), args[0].parent,
+ args[0].type, 1);
+ if(objectType == ILType_Int8 || objectType == ILType_UInt8 ||
+ objectType == ILType_Boolean)
+ {
+ tempNode = ILNode_Add_create(node->array, args[0].node);
+ }
+ else
+ {
+ tempNode = ILNode_SizeOf_create(0);
+ ((ILNode_SizeOf *)tempNode)->type = objectType;
+ tempNode = ILNode_CastSimple_create
+ (tempNode, ILMachineType_NativeInt);
+ tempNode = ILNode_Add_create(node->array,
+ ILNode_Mul_create(args[0].node, tempNode));
+ }
+ yysetfilename(tempNode, yygetfilename(node));
+ yysetlinenum(tempNode, yygetlinenum(node));
+ *parent = ILNode_Deref_create(tempNode, objectType);
+ yysetfilename(*parent, yygetfilename(node));
+ yysetlinenum(*parent, yygetlinenum(node));
+ CSSemSetLValue(value, objectType);
}
else if(ILType_IsClass(CSSemGetType(value)) ||
Index: cs_oper.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_oper.tc,v
retrieving revision 1.36
retrieving revision 1.37
diff -C2 -r1.36 -r1.37
*** cs_oper.tc 26 Feb 2003 06:34:20 -0000 1.36
--- cs_oper.tc 27 Feb 2003 02:57:43 -0000 1.37
***************
*** 1923,1929 ****
}
type=CSSemGetType(value);
! if(ILType_IsComplex(type) && (ILType_Kind(type) == IL_TYPE_COMPLEX_PTR))
{
! CSSemSetLValue(value,ILType_Ref(CSSemGetType(value)));
return value;
}
--- 1923,1930 ----
}
type=CSSemGetType(value);
! if(ILType_IsPointer(type) && ILType_Ref(type) != ILType_Void)
{
! node->elemType = ILType_Ref(type);
! CSSemSetLValue(value, node->elemType);
return value;
}
***************
*** 1931,1935 ****
{
CCErrorOnLine(yygetfilename(node->expr),yygetlinenum(node->expr),
! "cannot deference '%s'
type",CSTypeToName(CSSemGetType(value)));
}
CSSemSetLValue(value, ILType_Int32);
--- 1932,1936 ----
{
CCErrorOnLine(yygetfilename(node->expr),yygetlinenum(node->expr),
! "cannot dereference
'%s'",CSTypeToName(CSSemGetType(value)));
}
CSSemSetLValue(value, ILType_Int32);
***************
*** 1951,1954 ****
--- 1952,1961 ----
CSSemSetRValue(value,ILType_Int32);
return value;
+ }
+ if(yyisa(node->expr, ILNode_Deref))
+ {
+ /* If the argument is a pointer dereference, then remove the
+ extra layer and use the pointer directly as the address */
+ *parent = ((ILNode_Deref *)(node->expr))->expr;
}
CSSemSetRValue(value,ILTypeCreateRef(info->context,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnet/cscc/csharp cs_grammar.y,1.54,1.55 cs_lvalue.tc,1.37,1.38 cs_oper.tc,1.36,1.37,
Rhys Weatherley <address@hidden> <=