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

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

[dotgnu-pnet-commits] pnet ChangeLog cscc/csharp/cs_grammar.y cscc/cs...


From: Klaus Treichel
Subject: [dotgnu-pnet-commits] pnet ChangeLog cscc/csharp/cs_grammar.y cscc/cs...
Date: Sun, 14 Oct 2007 19:48:16 +0000

CVSROOT:        /cvsroot/dotgnu-pnet
Module name:    pnet
Changes by:     Klaus Treichel <ktreichel>      07/10/14 19:48:16

Modified files:
        .              : ChangeLog 
        cscc/csharp    : cs_grammar.y cs_internal.h cs_misc.tc 

Log message:
        Fix a bug with incorrect order of arrays of arrays. Do some preoaration 
for
        doing the generic references correctly.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pnet/ChangeLog?cvsroot=dotgnu-pnet&r1=1.3507&r2=1.3508
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/csharp/cs_grammar.y?cvsroot=dotgnu-pnet&r1=1.81&r2=1.82
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/csharp/cs_internal.h?cvsroot=dotgnu-pnet&r1=1.24&r2=1.25
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/csharp/cs_misc.tc?cvsroot=dotgnu-pnet&r1=1.18&r2=1.19

Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/ChangeLog,v
retrieving revision 1.3507
retrieving revision 1.3508
diff -u -b -r1.3507 -r1.3508
--- ChangeLog   13 Oct 2007 09:54:06 -0000      1.3507
+++ ChangeLog   14 Oct 2007 19:48:15 -0000      1.3508
@@ -1,3 +1,17 @@
+2007-10-14  Klaus Treichel  <address@hidden>
+
+       * cscc/csharp/cs_grammar.y: Redo the creation of extended types like
+       pointer- and array types. Layout array types in the reverse order as
+       specified in the ECMA specs.  Remove the GenericReference because that
+       has to be done differently. Prepare some Expressions to be able to 
handle
+       the generic references.
+
+       * cscc/csharp/cs_internal.h: Add the structures to collect array ranks
+       and the array type.
+
+       * cscc/csharp/cs_misc.c: Change the semantic analysis for the new
+       expression to handle arrays of arrays correctly.
+
 2007-10-13  Klaus Treichel  <address@hidden>
 
        * support/read_float.c, support/write_float.c: Extend the number of 
bytes

Index: cscc/csharp/cs_grammar.y
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_grammar.y,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -b -r1.81 -r1.82
--- cscc/csharp/cs_grammar.y    23 Sep 2007 14:40:20 -0000      1.81
+++ cscc/csharp/cs_grammar.y    14 Oct 2007 19:48:15 -0000      1.82
@@ -312,6 +312,142 @@
 }
 
 /*
+ * Setup a fresh array rank.
+ */
+static void ArrayRanksInit(struct ArrayRanks *ranks,
+                                                  ILUInt32 rank)
+{
+       ranks->numRanks =1;
+       ranks->rankList = 0;
+       ranks->ranks[0] = rank;
+       ranks->ranks[1] = 0;
+       ranks->ranks[2] = 0;
+       ranks->ranks[3] = 0;
+}
+
+/*
+ * Add a new rank to the array ranks.
+ */
+static void ArrayRanksAddRank(struct ArrayRanks *destRanks,
+                                                         struct ArrayRanks 
*srcRanks,
+                                                         ILUInt32 rank)
+{
+       if(srcRanks->numRanks > 4)
+       {
+               destRanks->numRanks = srcRanks->numRanks + 1;
+               ILNode_List_Add(srcRanks->rankList,
+                                               (ILNode *)(ILNativeUInt)rank);
+               destRanks->rankList = srcRanks->rankList;
+               destRanks->ranks[0] = 0;
+               destRanks->ranks[1] = 0;
+               destRanks->ranks[2] = 0;
+               destRanks->ranks[3] = 0;
+       }
+       else if(srcRanks->numRanks == 4)
+       {
+               destRanks->numRanks = srcRanks->numRanks + 1;
+               destRanks->rankList = MakeList(0, (ILNode 
*)(ILNativeUInt)(srcRanks->ranks[0]));
+               ILNode_List_Add(destRanks->rankList,
+                                               (ILNode 
*)(ILNativeUInt)(srcRanks->ranks[1]));
+               ILNode_List_Add(destRanks->rankList,
+                                               (ILNode 
*)(ILNativeUInt)(srcRanks->ranks[2]));
+               ILNode_List_Add(destRanks->rankList,
+                                               (ILNode 
*)(ILNativeUInt)(srcRanks->ranks[3]));
+               ILNode_List_Add(destRanks->rankList,
+                                               (ILNode *)(ILNativeUInt)rank);
+               destRanks->ranks[0] = 0;
+               destRanks->ranks[1] = 0;
+               destRanks->ranks[2] = 0;
+               destRanks->ranks[3] = 0;
+       }
+       else
+       {
+               destRanks->numRanks = srcRanks->numRanks + 1;
+               destRanks->rankList = 0;
+               destRanks->ranks[0] = srcRanks->ranks[0];
+               destRanks->ranks[1] = srcRanks->ranks[1];
+               destRanks->ranks[2] = srcRanks->ranks[2];
+               destRanks->ranks[3] = srcRanks->ranks[3];
+               destRanks->ranks[srcRanks->numRanks] = rank;
+       }
+}
+
+/*
+ * Setup a fresh array type.
+ */
+static void ArrayTypeInit(struct ArrayType *arrayType,
+                                                 ILNode *type,
+                                                 ILUInt32 rank)
+{
+       arrayType->type = type;
+       ArrayRanksInit(&(arrayType->ranks), rank);
+}
+
+/*
+ * Inner worker function for creating the array types if the ranks are
+ * stored in the list.
+ */
+static ILNode *ArrayTypeCreateInner(ILNode *type, ILNode_ListIter *iter)
+{
+       ILNode *node;
+
+       if((node = ILNode_ListIter_Next(iter)) != 0)
+       {
+               ILNode *arrayType = ArrayTypeCreateInner(type, iter);
+               ILNode *currentArrayType;
+
+               currentArrayType = ILNode_ArrayType_create(arrayType,
+                                                                               
                   (ILUInt32)(ILNativeUInt)node);
+               CloneLine(currentArrayType, type);
+               return currentArrayType;
+       }
+       else
+       {
+               return type;
+       }
+}
+
+/*
+ * Create the array types needed for the type specified ranks.
+ */
+static ILNode *ArrayTypeCreate(ILNode *type,
+                                                          struct ArrayRanks 
*ranks)
+{
+       if(ranks->numRanks < 5)
+       {
+               /* The ranks are stored inside the structure */
+               ILUInt32 currentLevel = ranks->numRanks;
+               ILNode *currentArrayType = type;
+
+               while(currentLevel > 0)
+               {
+                       --currentLevel;
+
+                       currentArrayType = 
ILNode_ArrayType_create(currentArrayType,
+                                                                               
                           ranks->ranks[currentLevel]);
+                       CloneLine(currentArrayType, type);
+               }
+               return currentArrayType;
+       }
+       else
+       {
+               /* The ranks are stored inside the rankList */
+               ILNode_ListIter iter;
+
+               ILNode_ListIter_Init(&iter, ranks->rankList);
+               return ArrayTypeCreateInner(type, &iter);
+       }
+}
+
+static void ArrayTypeAddRank(struct ArrayType *destType,
+                                                        struct ArrayType 
*srcType,
+                                                        ILUInt32 rank)
+{
+       destType->type = srcType->type;
+       ArrayRanksAddRank(&(destType->ranks), &(srcType->ranks), rank);
+}
+
+/*
  * Modify an attribute name so that it ends in "Attribute".
  */
 static void ModifyAttrName(ILNode *node,int force)
@@ -814,6 +950,12 @@
                ILUInt32                count;
                ILNode_List        *list;
        }                                       countList;
+       struct
+       {
+               ILNode             *identifier;
+               ILUInt32                numTypeArgs;
+               ILNode_List        *typeArgs;
+       }                                       memberName;
        ILNode_GenericTypeParameters *genericTypeParameters;
        struct
        {
@@ -838,6 +980,8 @@
                ILNode_List        *args;
                ILNode_GenericTypeParameters *typeFormals;
        }                                       memberHeader;
+       struct ArrayRanks       arrayRanks;
+       struct ArrayType        arrayType;
 }
 
 /*
@@ -1001,13 +1145,30 @@
 %type <decimal>                DECIMAL_CONSTANT
 %type <string>         STRING_LITERAL DOC_COMMENT NamespaceIdentifier
 %type <count>          DimensionSeparators DimensionSeparatorList
+%type <count>          RankSpecifier
+%type <arrayRanks>     RankSpecifiers 
 %type <mask>           OptModifiers Modifiers Modifier
 %type <partial>                OptPartial
 
-%type <node>           Identifier QualifiedIdentifier BuiltinType
-%type <node>           QualifiedIdentifierPart
+%type <node>           Identifier QualifiedIdentifier
+%type <memberName>     QualifiedIdentifierPart
 
-%type <node>           Type NonExpressionType LocalVariableType
+%type <node>           BuiltinType
+%type <node>           NonArrayType ArrayType
+%type <node>           PointerType
+%type <node>           ArrayTypeStart
+%type <arrayType>      ArrayTypeContinue
+%type <node>           Type
+%type <node>           PrimaryTypeExpression
+%type <node>           PrimaryMemberAccessExpression
+%type <node>           PrimaryMemberAccessStart
+%type <node>           PrimaryTypeExpressionPart
+%type <node>           LocalVariableType
+%type <node>           LocalVariableSimplePointerType LocalVariablePointerType
+%type <node>           LocalVariableNonArrayType
+%type <node>           LocalVariableArrayTypeStart
+%type <arrayType>      LocalVariableArrayTypeContinue
+%type <node>           LocalVariableArrayType
 
 %type <node>           TypeDeclaration ClassDeclaration ClassBase TypeList
 %type <member>         ClassBody OptClassMemberDeclarations
@@ -1015,17 +1176,30 @@
 %type <member>         StructBody
 %type <node>           StructDeclaration StructInterfaces ModuleDeclaration
 
-%type <node>           PrimaryExpression UnaryExpression Expression
-%type <node>           MultiplicativeExpression AdditiveExpression
-%type <node>           ShiftExpression RelationalExpression EqualityExpression
+%type <node>           ElementAccess
+%type <node>           PrimaryArrayCreationExpression
+%type <node>           PrimaryNonTypeExpression
+%type <node>           PrimarySimpleExpression
+%type <node>           PrimaryExpression
+%type <node>           SimpleCastExpression CastExpression
+%type <node>           Expression
+%type <node>           UnaryExpression UnaryNonTypeExpression
+%type <node>           MultiplicativeExpression MultiplicativeNonTypeExpression
+%type <node>           AdditiveExpression AdditiveNonTypeExpression
+%type <node>           ShiftExpression ShiftNonTypeExpression
+%type <node>           RelationalExpression RelationalNonTypeExpression
+%type <node>           EqualityExpression EqualityNonTypeExpression
 %type <node>           AndExpression XorExpression OrExpression
 %type <node>           LogicalAndExpression LogicalOrExpression
 %type <node>           ConditionalExpression AssignmentExpression
 %type <node>           ParenExpression ConstantExpression BooleanExpression
 %type <node>           ParenBooleanExpression LiteralExpression
 %type <node>           InvocationExpression ExpressionList
-%type <node>           ObjectCreationExpression OptArgumentList ArgumentList
-%type <node>           Argument PrefixedUnaryExpression GenericReference
+%type <node>           ObjectCreationExpression
+%type <node>           PreIncrementExpression PreDecrementExpression
+%type <node>           PostIncrementExpression PostDecrementExpression
+%type <node>           OptArgumentList ArgumentList
+%type <node>           Argument PrefixedUnaryExpression 
PrefixedUnaryNonTypeExpression
 %type <node>           AnonymousMethod
 
 %type <node>           Statement EmbeddedStatement Block OptStatementList
@@ -1080,13 +1254,11 @@
 %type <node>           OperatorDeclaration NormalOperatorDeclaration
 %type <node>           ConversionOperatorDeclaration
 %type <opName>         OverloadableOperator
-%type <node>           TypeSuffix TypeSuffixList TypeSuffixes
 %type <node>           OptAttributes AttributeSections AttributeSection
 %type <node>           AttributeList Attribute AttributeArguments
 %type <node>           NonOptAttributes
 %type <node>           PositionalArgumentList PositionalArgument 
NamedArgumentList
 %type <node>           NamedArgument AttributeArgumentExpression
-%type <node>           RankSpecifiers RankSpecifierList 
 %type <node>           OptArrayInitializer ArrayInitializer
 %type <node>           OptVariableInitializerList VariableInitializerList
 %type <countList>      TypeActuals
@@ -1103,7 +1275,7 @@
 %type <catchinfo>      CatchNameInfo
 %type <target>         AttributeTarget
 
-%expect 34
+%expect 27
 
 %start CompilationUnit
 %%
@@ -1252,7 +1424,7 @@
        ;
 
 IDENTIFIER
-       : IDENTIFIER_LEXICAL    { $$ = $1; }
+       : IDENTIFIER_LEXICAL    { $$ = ILInternString($1, strlen($1)).string; }
        | GET                                   { $$ = ILInternString("get", 
3).string; }
        | SET                                   { $$ = ILInternString("set", 
3).string; }
        | ADD                                   { $$ = ILInternString("add", 
3).string; }
@@ -1263,19 +1435,52 @@
        ;
 
 QualifiedIdentifier
-       : QualifiedIdentifierPart                                               
        { $$ = $1; }
+       : QualifiedIdentifierPart                                               
        { 
+                               if($1.numTypeArgs > 0)
+                               {
+                                       MakeTernary(GenericReference,
+                                                               $1.identifier,
+                                                               $1.numTypeArgs,
+                                                               (ILNode 
*)$1.typeArgs);
+                               }
+                               else
+                               {
+                                       $$ = $1.identifier;
+                               }
+                        }
        | QualifiedIdentifier '.' QualifiedIdentifierPart       {
-                               MakeBinary(QualIdent, $1, $3);
+                               if($3.numTypeArgs > 0)
+                               {
+                                       ILNode *node;
+
+                                       node = ILNode_QualIdent_create($1, 
$3.identifier);
+                                       MakeTernary(GenericReference,
+                                                               node,
+                                                               $3.numTypeArgs,
+                                                               (ILNode 
*)$3.typeArgs);
+                               }
+                               else
+                               {
+                                       MakeBinary(QualIdent, $1, 
$3.identifier);
+                               }
                        }
        ;
 
 QualifiedIdentifierPart
-       : Identifier                                                    { $$ = 
$1; }
-       | Identifier '<' TypeActuals '>'                {
-                               MakeTernary(GenericReference, $1, $3.count, 
(ILNode *)$3.list);
-                       }
-       | Identifier GENERIC_LT TypeActuals '>'         {
-                               MakeTernary(GenericReference, $1, $3.count, 
(ILNode *)$3.list);
+       : Identifier                                                    { 
+                               $$.identifier = $1;
+                               $$.numTypeArgs = 0;
+                               $$.typeArgs = 0;
+                        }
+       | IDENTIFIER '<' TypeActuals '>'                {
+                               $$.identifier = ILQualIdentSimple($1);;
+                               $$.numTypeArgs = $3.count;
+                               $$.typeArgs = $3.list;
+                       }
+       | IDENTIFIER GENERIC_LT TypeActuals '>' {
+                               $$.identifier = ILQualIdentSimple($1);;
+                               $$.numTypeArgs = $3.count;
+                               $$.typeArgs = $3.list;
                        }
        ;
 
@@ -1439,47 +1644,58 @@
  * Types.
  */
 
-Type
-       : QualifiedIdentifier   { $$ = $1; }
-       | BuiltinType                   { $$ = $1; }
-       | Type '[' DimensionSeparators ']'      {
-                               MakeBinary(ArrayType, $1, $3);
-                       }
-       | Type '*'                      {
-                               MakeUnary(PtrType, $1);
+NonArrayType
+       : BuiltinType                           { $$ = $1; }
+       | QualifiedIdentifier           { $$ = $1; }
+       | PointerType                           { $$ = $1; }
+       ;
+
+ArrayTypeStart
+       : NonArrayType '['                      { $$ = $1; }
+       ;
+
+ArrayTypeContinue
+       : ArrayTypeStart ']'            {
+                               ArrayTypeInit(&($$), $1, 1);
                        }
-       | Type '<' TypeActuals '>'      {
-                               MakeTernary(GenericReference, $1, $3.count, 
(ILNode *)$3.list);
+       |  ArrayTypeStart DimensionSeparatorList ']' {
+                               ArrayTypeInit(&($$), $1, $2);
                        }
-       | Type GENERIC_LT TypeActuals '>'       {
-                               MakeTernary(GenericReference, $1, $3.count, 
(ILNode *)$3.list);
+       | ArrayTypeContinue RankSpecifier       {
+                               ArrayTypeAddRank(&($$), &($1), $2);
                        }
        ;
 
-NonExpressionType
-       : BuiltinType                   { $$ = $1; }
-       | NonExpressionType '[' DimensionSeparators ']' {
-                               MakeBinary(ArrayType, $1, $3);
-                       }
-       | NonExpressionType '*' {
-                               MakeUnary(PtrType, $1);
+ArrayType
+       : ArrayTypeContinue     {
+                               $$ = ArrayTypeCreate($1.type, &($1.ranks));
                        }
-       | Expression '*'                { 
-                               MakeUnary(PtrType, $1);
-                       }
-       | MultiplicativeExpression '*'          { 
-                               /* Needed becuase of shift issues that won't be 
picked
-                                  up by the "Expression *" case above */
+       ;
+
+PointerType
+       : Type '*'                                      {
                                MakeUnary(PtrType, $1);
                        }
-       | NonExpressionType '<' TypeActuals '>' {
-                               MakeTernary(GenericReference, $1, $3.count, 
(ILNode *)$3.list);
+       ;
+
+Type
+       : NonArrayType                          { $$ = $1; }
+       | ArrayType                                     { $$ = $1; }
+       ;
+
+RankSpecifiers
+       : RankSpecifier                         {
+                               ArrayRanksInit(&($$), $1);
                        }
-       | NonExpressionType GENERIC_LT TypeActuals '>'  {
-                               MakeTernary(GenericReference, $1, $3.count, 
(ILNode *)$3.list);
+       | RankSpecifiers RankSpecifier {
+                               ArrayRanksAddRank(&($$), &($1), $2);
                        }
        ;
 
+RankSpecifier
+       : '[' DimensionSeparators ']'   { $$ = $2; }
+       ;
+
 TypeActuals
        : Type                                          {
                                 $$.count = 1;
@@ -1496,42 +1712,92 @@
  * expressions to prevent reduce/reduce errors in the grammar.
  * The expressions are converted into types during semantic analysis.
  */
+
+PrimaryTypeExpression
+       : PrimaryTypeExpressionPart             { $$ = $1; }
+       | PrimaryMemberAccessExpression { $$ = $1; }
+       ;
+
+PrimaryMemberAccessStart
+       : BuiltinType '.'                               { $$ = $1; }
+       | PrimaryTypeExpressionPart '.' { $$ = $1; }
+       | PrimaryMemberAccessExpression '.'     { $$ = $1; }
+       ;
+
+PrimaryTypeExpressionPart
+       : Identifier                                    { $$ = $1; }
+       ;
+
+PrimaryMemberAccessExpression
+       : PrimaryMemberAccessStart PrimaryTypeExpressionPart {
+                               MakeBinary(MemberAccess, $1, $2);
+                       }
+       ;
+
 LocalVariableType
-       : PrimaryExpression TypeSuffixes        {
-                               MakeBinary(LocalVariableType, $1, $2);
+       : LocalVariableNonArrayType             { $$ = $1; }
+       | LocalVariableArrayType                { $$ = $1; }
+       ;
+
+LocalVariableNonArrayType
+       : BuiltinType                                   { $$ = $1; }
+       | PrimaryTypeExpression                 { $$ = $1; }
+       | LocalVariablePointerType              { $$ = $1; }
+       ;
+
+/*
+ * This is needed to fix reduce/reduce errors between the array type 
+ * declaration and the element access expression.
+ */
+LocalVariableArrayTypeStart
+       : PrimaryTypeExpression '['             { $$ = $1; }
+       ;
+
+LocalVariableArrayTypeContinue
+       : BuiltinType RankSpecifier                             {
+                               ArrayTypeInit(&($$), $1, $2);
+                        }
+       | LocalVariablePointerType RankSpecifier {
+                               ArrayTypeInit(&($$), $1, $2);
                        }
-       | PrimaryExpression '<' TypeActuals '>' TypeSuffixes    {
-                               ILNode *type = 
ILNode_GenericReference_create($1, $3.count, (ILNode *)$3.list);
-                               MakeBinary(LocalVariableType, type, $5);
+       | LocalVariableArrayTypeStart ']'               {
+                               ArrayTypeInit(&($$), $1, 1);
                        }
-       | PrimaryExpression GENERIC_LT TypeActuals '>' TypeSuffixes     {
-                               ILNode *type = 
ILNode_GenericReference_create($1, $3.count, (ILNode *)$3.list);
-                               MakeBinary(LocalVariableType, type, $5);
+       | LocalVariableArrayTypeStart DimensionSeparatorList ']' {
+                               ArrayTypeInit(&($$), $1, $2);
                        }
-       | BuiltinType TypeSuffixes                      {
-                               MakeBinary(LocalVariableType, $1, $2);
+       | LocalVariableArrayTypeContinue RankSpecifier  {
+                               ArrayTypeAddRank(&($$), &($1), $2);
                        }
        ;
 
-TypeSuffixes
-       : /* empty */           { $$ = 0; }
-       | TypeSuffixList        { $$ = $1; }
+LocalVariableArrayType
+       : LocalVariableArrayTypeContinue        {
+                               $$ = ArrayTypeCreate($1.type, &($1.ranks));
+                       }
        ;
 
-TypeSuffixList
-       : TypeSuffix                                            {
-                               $$ = ILNode_List_create();
-                               ILNode_List_Add($$, $1);
-                       }
-       | TypeSuffixList TypeSuffix                     {
-                               ILNode_List_Add($1, $2);
-                               $$ = $1;
-                       }
+/*
+ * This one is needed to fix a shift/reduce conflict with the
+ * multiplication expression.
+ */
+LocalVariableSimplePointerType
+       : PrimaryTypeExpression '*'                     { $$ = $1; }
        ;
 
-TypeSuffix
-       : '[' DimensionSeparators ']'   { MakeUnary(TypeSuffix, $2); }
-       | '*'                                                   { 
MakeUnary(TypeSuffix, 0); }
+LocalVariablePointerType
+       : BuiltinType '*'                                       {
+                               MakeUnary(PtrType, $1);
+                       }
+       | LocalVariableSimplePointerType        {
+                               MakeUnary(PtrType, $1);
+                       } 
+       | LocalVariableArrayType '*'            {
+                               MakeUnary(PtrType, $1);
+                       }
+       | LocalVariablePointerType '*'          {
+                               MakeUnary(PtrType, $1);
+                       } 
        ;
 
 DimensionSeparators
@@ -1574,43 +1840,51 @@
  * Expressions.
  */
 
-PrimaryExpression
-       : LiteralExpression                             { $$ = $1; }
-       | Identifier                                    { $$ = $1; }
-       | '(' Expression ')'                    { $$ = $2; }
-       | PrimaryExpression '.' Identifier      { MakeBinary(MemberAccess, $1, 
$3); }
-       | BuiltinType '.' Identifier    { MakeBinary(MemberAccess, $1, $3); }
-       | InvocationExpression                  { $$ = $1; }
-       | PrimaryExpression '[' ExpressionList ']'      {
+PrimaryArrayCreationExpression
+       : NEW ArrayTypeStart ExpressionList ']' OptArrayInitializer     {
+                               $$ = ILNode_NewExpression_create($2, $3, 0, $5);
+                       }
+       | NEW ArrayTypeStart ExpressionList ']' RankSpecifiers 
OptArrayInitializer      {
+                               ILNode *arrayType;
+
+                               arrayType = ArrayTypeCreate($2, &($5));
+                               $$ = ILNode_NewExpression_create(arrayType, $3, 
0, $6);
+                       }
+       | NEW ArrayType ArrayInitializer                {
+                               $$ = ILNode_NewExpression_create($2, 0, 0, $3);
+                       }
+       ;
+
+ElementAccess
+       : BASE '[' ExpressionList ']'   { MakeUnary(BaseElement, $3); }
+       | LocalVariableArrayTypeStart ExpressionList ']' {
+                               MakeBinary(ArrayAccess, $1, $2);
+                       }
+       | PrimaryNonTypeExpression '[' ExpressionList ']' {
                                MakeBinary(ArrayAccess, $1, $3);
                        }
-       | PrimaryExpression '[' ']'             {
-                               /*
-                                * This is actually a type, but we have to 
recognise
-                                * it here to avoid shift/reduce conflicts in 
the
-                                * definition of casts in UnaryExpression.  We 
would
-                                * like to handle this in NonExpressionType, 
but then it
-                                * creates problems for casts to array types 
like "A[]".
-                                */
-                               MakeBinary(ArrayType, $1, 1);
-                       }
-       | PrimaryExpression '[' DimensionSeparatorList ']'              {
-                               /* This is also a type */
-                               MakeBinary(ArrayType, $1, $3);
+       ;
+
+PrimaryNonTypeExpression
+       : PrimarySimpleExpression                       { $$ = $1; }
+       | PrimaryArrayCreationExpression        { $$ = $1; }
+       ;
+
+PrimarySimpleExpression
+       : LiteralExpression                             { $$ = $1; }
+       | PrimaryNonTypeExpression '.' PrimaryTypeExpressionPart {
+                               MakeBinary(MemberAccess, $1, $3);
                        }
+       | '(' Expression ')'                    { $$ = $2; }
+       | SimpleCastExpression                  { $$ = $1; }
+       | InvocationExpression                  { $$ = $1; }
+       | ElementAccess                                 { $$ = $1; }
        | ARGLIST                                               { 
MakeSimple(VarArgList); }
        | THIS                                                  { 
MakeSimple(This); }
        | BASE '.' Identifier                   { MakeUnary(BaseAccess, $3); }
-       | BASE '[' ExpressionList ']'   { MakeUnary(BaseElement, $3); }
-       | PrimaryExpression INC_OP              { MakeUnary(PostInc, $1); }
-       | PrimaryExpression DEC_OP              { MakeUnary(PostDec, $1); }
+       | PostIncrementExpression               { $$ = $1; }
+       | PostDecrementExpression               { $$ = $1; }
        | ObjectCreationExpression              { $$ = $1; }
-       | NEW Type '[' ExpressionList ']' RankSpecifiers OptArrayInitializer    
{
-                               $$ = ILNode_NewExpression_create($2, $4, $6, 
$7);
-                       }
-       | NEW Type ArrayInitializer             {
-                               $$ = ILNode_NewExpression_create($2, 0, 0, $3);
-                       }
        | TYPEOF '(' Type ')'                   { MakeUnary(TypeOf, $3); }
        | SIZEOF '(' Type ')'                   {
                                /*
@@ -1640,15 +1914,17 @@
        | REFVALUE '(' Expression ',' Type ')'  { MakeBinary(RefValue, $3, $5); 
}
        | MODULE                        { $$ = ILQualIdentSimple("<Module>"); }
        | DELEGATE AnonymousMethod                              { $$ = $2; }
-       | PrimaryExpression '.' DEFAULT                 {
-                               $$ = ILNode_DefaultConstructor_create($1, 0, 0);
-                       }
-       | BuiltinType '.' DEFAULT                       {
+       | PrimaryMemberAccessStart  DEFAULT                     {
                                $$ = ILNode_DefaultConstructor_create($1, 0, 0);
                        }
        | DefaultValueExpression                        { $$ = $1; }
        ;
 
+PrimaryExpression
+       : PrimaryNonTypeExpression                      { $$ = $1; }
+       | PrimaryTypeExpression                         { $$ = $1; }
+       ;
+
 LiteralExpression
        : TRUE                                          { MakeSimple(True); }
        | FALSE                                         { MakeSimple(False); }
@@ -1728,6 +2004,23 @@
                        }
        ;
 
+PreIncrementExpression
+       : INC_OP PrefixedUnaryExpression        { MakeUnary(PreInc, $2); }
+       ;
+
+PreDecrementExpression
+       : DEC_OP PrefixedUnaryExpression        { MakeUnary(PreDec, $2); }
+       ;
+
+PostIncrementExpression
+       : PrimaryExpression INC_OP              { MakeUnary(PostInc, $1); }
+       ;
+
+PostDecrementExpression
+       : PrimaryExpression DEC_OP              { MakeUnary(PostDec, $1); }
+       ;
+
+
 OptArgumentList
        : /* empty */                                           { $$ = 0; }
        | ArgumentList                                          { $$ = $1; }
@@ -1749,22 +2042,6 @@
        | ExpressionList ',' Expression         { MakeBinary(ArgList, $1, $3); }
        ;
 
-RankSpecifiers
-       : /* empty */                   { $$ = 0;}
-       | RankSpecifierList             { $$ = $1;}
-       ;
-
-RankSpecifierList
-       : '[' DimensionSeparators ']'                   {
-                                       $$ = ILNode_List_create();
-                                       ILNode_List_Add($$, 
ILNode_TypeSuffix_create($2));
-                               }
-       | RankSpecifierList '[' DimensionSeparators ']' {
-                                       ILNode_List_Add($1, 
ILNode_TypeSuffix_create($3));
-                                       $$ = $1;
-                               }
-       ;
-
 /*
  * There is a slight ambiguity in the obvious definition of
  * UnaryExpression that creates shift/reduce conflicts when
@@ -1797,32 +2074,47 @@
  * the compiler does not know if an identifier is a type or not
  * until later.
  */
-UnaryExpression
-       : PrimaryExpression                                     { $$ = $1; }
-       | '!' PrefixedUnaryExpression           { 
-                               MakeUnary(LogicalNot,ILNode_ToBool_create($2)); 
+
+SimpleCastExpression
+       : '(' PrimaryTypeExpression ')'          { $$ = $2; }
+       ;
+
+CastExpression
+       : '(' BuiltinType ')' PrefixedUnaryExpression   {
+                               MakeBinary(UserCast, $2, $4);
        }
-       | '~' PrefixedUnaryExpression           { MakeUnary(Not, $2); }
-       | '(' Expression ')' UnaryExpression    {
-                               /*
-                                * Note: we need to use a full "Expression" for 
the type,
-                                * so that we don't get a reduce/reduce 
conflict with the
-                                * rule "PrimaryExpression: '(' Expression 
')'".  We later
-                                * filter out expressions that aren't really 
types.
-                                */
+       | '(' LocalVariablePointerType ')' PrefixedUnaryExpression      {
                                MakeBinary(UserCast, $2, $4);
                        }
-       | '(' NonExpressionType ')' PrefixedUnaryExpression     {
-                               /*
-                                * This rule recognizes types that involve 
non-expression
-                                * identifiers such as "int", "bool", "string", 
etc.
-                                */
+       | '(' LocalVariableArrayType ')' PrefixedUnaryExpression        {
                                MakeBinary(UserCast, $2, $4);
                        }
+       | SimpleCastExpression UnaryExpression  {
+                               MakeBinary(UserCast, $1, $2);
+                       }
+       ;
+
+UnaryExpression
+       : UnaryNonTypeExpression                        { $$ = $1; }
+       | PrimaryTypeExpression                         { $$ = $1; }
+       ;
+
+UnaryNonTypeExpression
+       : PrimaryNonTypeExpression                      { $$ = $1; }
+       | '!' PrefixedUnaryExpression           { 
+                               MakeUnary(LogicalNot,ILNode_ToBool_create($2)); 
+       }
+       | '~' PrefixedUnaryExpression           { MakeUnary(Not, $2); }
+       | CastExpression                                        { $$ = $1; }
        ;
 
 PrefixedUnaryExpression
-       : UnaryExpression                               { $$ = $1; }
+       : PrefixedUnaryNonTypeExpression        { $$ = $1; }
+       | PrimaryTypeExpression                         { $$ = $1; }
+       ;
+
+PrefixedUnaryNonTypeExpression
+       : UnaryNonTypeExpression                        { $$ = $1; }
        | '+' PrefixedUnaryExpression   { MakeUnary(UnaryPlus, $2); } %prec 
UN_PLUS
        | '-' PrefixedUnaryExpression                   {
                                /* We create negate nodes carefully so that 
integer
@@ -1848,17 +2140,27 @@
                                        MakeUnary(Neg, $2);
                                }
                        }  %prec UN_MINUS
-       | INC_OP PrefixedUnaryExpression        { MakeUnary(PreInc, $2); }
-       | DEC_OP PrefixedUnaryExpression        { MakeUnary(PreDec, $2); }
+       | PreIncrementExpression                        { $$ = $1; }
+       | PreDecrementExpression                        { $$ = $1; }
        | '*' PrefixedUnaryExpression           { MakeBinary(Deref, $2, 0); }
        | '&' PrefixedUnaryExpression           { MakeUnary(AddressOf, $2); } 
%prec ADDRESS_OF
        ;
 
 MultiplicativeExpression
-       : PrefixedUnaryExpression                               { $$ = $1; }
-       | MultiplicativeExpression '*' PrefixedUnaryExpression  {
+       : MultiplicativeNonTypeExpression       { $$ = $1; }
+       | PrimaryTypeExpression                         { $$ = $1; }
+       ;
+
+MultiplicativeNonTypeExpression
+       : PrefixedUnaryNonTypeExpression        { $$ = $1; }
+       | MultiplicativeNonTypeExpression '*' PrefixedUnaryExpression   {
                                MakeBinary(Mul, $1, $3);
                        }
+       | LocalVariableSimplePointerType PrefixedUnaryExpression        {
+                               /* This one is to pick up the cases where the 
first part is
+                                  a PrimaryTypeExpression. */
+                               MakeBinary(Mul, $1, $2);
+                       }
        | MultiplicativeExpression '/' PrefixedUnaryExpression  {
                                MakeBinary(Div, $1, $3);
                        }
@@ -1868,7 +2170,12 @@
        ;
 
 AdditiveExpression
-       : MultiplicativeExpression              { $$ = $1; }
+       : AdditiveNonTypeExpression             { $$ = $1; }
+       | PrimaryTypeExpression                 { $$ = $1; }
+       ;
+
+AdditiveNonTypeExpression
+       : MultiplicativeNonTypeExpression       { $$ = $1; }
        | AdditiveExpression '+' MultiplicativeExpression       {
                                MakeBinary(Add, $1, $3);
                        }
@@ -1878,7 +2185,12 @@
        ;
 
 ShiftExpression
-       : AdditiveExpression                    { $$ = $1; }
+       : ShiftNonTypeExpression                { $$ = $1; }
+       | PrimaryTypeExpression                 { $$ = $1; }
+       ;
+
+ShiftNonTypeExpression
+       : AdditiveNonTypeExpression             { $$ = $1; }
        | ShiftExpression LEFT_OP AdditiveExpression    {
                                MakeBinary(Shl, $1, $3);
                        }
@@ -1888,6 +2200,10 @@
        ;
 
 /*
+ * Removed the part with the generic references for now.
+ * TODO: Readd the generic reference detection in relational
+ * expressions. (Klaus)
+ *
  * Relational expressions also recognise generic type references.
  * We have to put them here instead of in the more logical place
  * of "PrimaryExpression" to prevent reduce/reduce conflicts.
@@ -1900,7 +2216,12 @@
  * with method invocations that involve generic method parameters.
  */
 RelationalExpression
-       : ShiftExpression                               { $$ = $1; }
+       : RelationalNonTypeExpression   { $$ = $1; }
+       | PrimaryTypeExpression                 { $$ = $1; }
+       ;
+
+RelationalNonTypeExpression
+       : ShiftNonTypeExpression                { $$ = $1; }
        | RelationalExpression '<' ShiftExpression              {
                                MakeBinary(Lt, $1, $3);
                        }
@@ -1919,49 +2240,15 @@
        | RelationalExpression AS Type                                  {
                                MakeBinary(AsUntyped, $1, $3);
                        }
-       | GenericReference                                                      
        {
-                               $$ = $1;
-                       }
-       | GenericReference '(' OptArgumentList ')'              {
-                               $$ = CSInsertMethodInvocation($1, $3);
-                       }
        ;
 
-/*
- * TODO: This needs a rework after the type stuff is done.
- */
-GenericReference
-       : RelationalExpression GENERIC_LT ShiftExpression '>'           {
-                               $$ = CSInsertGenericReference($1, 1, 
MakeList(0, $3));
-                       }
-       | RelationalExpression GENERIC_LT ShiftExpression TypeSuffixList '>'    
{
-                               $$ = CSInsertGenericReference
-                                       ($1, 1, MakeList(0, 
ILNode_LocalVariableType_create($3, $4)));
-                       }
-       | RelationalExpression GENERIC_LT ShiftExpression ',' TypeActuals '>'   
{
-                               $$ = CSInsertGenericReference
-                                       ($1, $5.count + 1, MakeList(MakeList(0, 
$3), (ILNode *)($5.list)));
-                       }
-       | RelationalExpression GENERIC_LT ShiftExpression TypeSuffixList ',' 
-                       TypeActuals '>'         {
-                               $$ = CSInsertGenericReference
-                                       ($1, $6.count + 1, CSInsertTypeActuals
-                                               
(ILNode_LocalVariableType_create($3, $4), (ILNode *)($6.list)));
-                       }
-       | RelationalExpression GENERIC_LT BuiltinType TypeSuffixes '>'  {
-                               $$ = CSInsertGenericReference
-                                       ($1, 1, MakeList(0, 
ILNode_LocalVariableType_create($3, $4)));
-                       }
-       | RelationalExpression GENERIC_LT BuiltinType TypeSuffixes ','
-                       TypeActuals '>' {
-                               $$ = CSInsertGenericReference
-                                       ($1, $6.count + 1, CSInsertTypeActuals
-                                               
(ILNode_LocalVariableType_create($3, $4), (ILNode *)($6.list)));
-                       }
+EqualityExpression
+       : EqualityNonTypeExpression             { $$ = $1; }
+       | PrimaryTypeExpression                 { $$ = $1; }
        ;
 
-EqualityExpression
-       : RelationalExpression                  { $$ = $1; }
+EqualityNonTypeExpression
+       : RelationalNonTypeExpression   { $$ = $1; }
        | EqualityExpression EQ_OP RelationalExpression {
                                MakeBinary(Eq, $1, $3);
                        }
@@ -2325,10 +2612,10 @@
        : InvocationExpression                          { $$ = $1; }
        | ObjectCreationExpression                      { $$ = $1; }
        | AssignmentExpression                          { $$ = $1; }
-       | PrimaryExpression INC_OP                      { MakeUnary(PostInc, 
$1); }
-       | PrimaryExpression DEC_OP                      { MakeUnary(PostDec, 
$1); }
-       | INC_OP PrefixedUnaryExpression        { MakeUnary(PreInc, $2); }
-       | DEC_OP PrefixedUnaryExpression        { MakeUnary(PreDec, $2); }
+       | PostIncrementExpression                       { $$ = $1; }
+       | PostDecrementExpression                       { $$ = $1; }
+       | PreIncrementExpression                        { $$ = $1; }
+       | PreDecrementExpression                        { $$ = $1; }
        ;
 
 SelectionStatement
@@ -3811,7 +4098,7 @@
  */
 
 ConstructorDeclaration
-       : OptAttributes OptModifiers QualifiedIdentifierPart
+       : OptAttributes OptModifiers Identifier
                        '(' OptFormalParameterList ')' ConstructorInitializer 
MethodBody {
                                ILUInt32 attrs = 
CSModifiersToConstructorAttrs($3, $2);
                                ILNode *ctorName;
@@ -3913,7 +4200,7 @@
        ;
 
 DestructorDeclaration
-       : OptAttributes OptModifiers '~' QualifiedIdentifierPart '(' ')' Block  
        {
+       : OptAttributes OptModifiers '~' Identifier '(' ')' Block               
{
                                ILUInt32 attrs;
                                ILNode *dtorName;
                                ILNode *name;

Index: cscc/csharp/cs_internal.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_internal.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- cscc/csharp/cs_internal.h   20 Sep 2007 20:04:16 -0000      1.24
+++ cscc/csharp/cs_internal.h   14 Oct 2007 19:48:15 -0000      1.25
@@ -31,6 +31,24 @@
 #endif
 
 /*
+ * Structure to hold up to 4 following array ranks.
+ * If the number of ranks exceeds 4 an ILNode_List that holds all ranks
+ * for the arrays is created.
+ */
+struct ArrayRanks
+{
+       ILUInt32        numRanks;
+       ILNode     *rankList;
+       ILUInt32        ranks[4];
+};
+
+struct ArrayType
+{
+       ILNode                     *type;
+       struct ArrayRanks       ranks;
+};
+
+/*
  * Modifier mask bits.
  */
 #define        CS_MODIFIER_PUBLIC                      (1<<0)

Index: cscc/csharp/cs_misc.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_misc.tc,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- cscc/csharp/cs_misc.tc      19 Oct 2005 18:30:09 -0000      1.18
+++ cscc/csharp/cs_misc.tc      14 Oct 2007 19:48:15 -0000      1.19
@@ -337,14 +337,17 @@
        /* Determine if the array creation is normal or initializer-based */
        if(node->indexes)
        {
-               /* Build the full type node, by combining the element
-                  type, indexed dimensions, and the rank specifiers */
                if(yyisa(node->type, ILNode_ArrayType))
                {
-                       /* Cannot use array types in this context */
-                       CCErrorOnLine(yygetfilename(node->type), 
yygetlinenum(node->type),
-                                                 "invalid array element type");
+                       /* Create the final array type with the rank specified 
by the
+                          number of expressions. */
+                       node->type =
+                               ILNode_ArrayType_create(node->type, 
CountArgList(node->indexes));
                }
+               else
+               {
+                       /* Build the full type node, by combining the element
+                          type, indexed dimensions, and the rank specifiers */
                node->type =
                        ILNode_ArrayType_create(node->type, 
CountArgList(node->indexes));
                ILNode_ListIter_Init(&iter, node->rank);
@@ -354,6 +357,8 @@
                                (node->type, ((ILNode_TypeSuffix 
*)child)->count);
                }
 
+               }
+
                /* Perform semantic analysis on the array type */
                node->arrayType = CSSemType(node->type, info, &(node->type));
 




reply via email to

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