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/csharp cs_defs.tc,1.11,1.12 cs_gra


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnet/cscc/csharp cs_defs.tc,1.11,1.12 cs_grammar.y,1.51,1.52 cs_internal.h,1.14,1.15 cs_types.tc,1.7,1.8
Date: Sat, 22 Feb 2003 01:14:37 -0500

Update of /cvsroot/dotgnu-pnet/pnet/cscc/csharp
In directory subversions:/tmp/cvs-serv29826/cscc/csharp

Modified Files:
        cs_defs.tc cs_grammar.y cs_internal.h cs_types.tc 
Log Message:


Build generic type references during the parse; rearrange expression trees
to insert generic type parameters into the correct location.


Index: cs_defs.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_defs.tc,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -r1.11 -r1.12
*** cs_defs.tc  21 Feb 2003 04:30:03 -0000      1.11
--- cs_defs.tc  22 Feb 2003 06:14:33 -0000      1.12
***************
*** 88,91 ****
--- 88,101 ----
        ILNode *suffixes;
  }
+ %node ILNode_TypeActuals ILNode_Dummy =
+ {
+       ILNode *left;
+       ILNode *right;
+ }
+ %node ILNode_GenericReference ILNode_Dummy =
+ {
+       ILNode *type;
+       ILNode *actuals;
+ }
  
  /*

Index: cs_grammar.y
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_grammar.y,v
retrieving revision 1.51
retrieving revision 1.52
diff -C2 -r1.51 -r1.52
*** cs_grammar.y        21 Feb 2003 06:03:25 -0000      1.51
--- cs_grammar.y        22 Feb 2003 06:14:33 -0000      1.52
***************
*** 909,912 ****
--- 909,913 ----
  %type <node>          OptArrayInitializer ArrayInitializer
  %type <node>          OptVariableInitializerList VariableInitializerList
+ %type <node>          TypeActuals
  %type <indexer>               IndexerDeclarator
  %type <catchinfo>     CatchNameInfo
***************
*** 1056,1060 ****
  QualifiedIdentifierPart
        : Identifier                                                    { $$ = 
$1; }
!       | Identifier '<' TypeActuals '>'                { $$ = $1; /* TODO */ }
        ;
  
--- 1057,1063 ----
  QualifiedIdentifierPart
        : Identifier                                                    { $$ = 
$1; }
!       | Identifier '<' TypeActuals '>'                {
!                               MakeBinary(GenericReference, $1, $3);
!                       }
        ;
  
***************
*** 1240,1245 ****
                        }
        | Type '<' TypeActuals '>'      {
!                               /* TODO: generic type references */
!                               $$ = $1;
                        }
        ;
--- 1243,1247 ----
                        }
        | Type '<' TypeActuals '>'      {
!                               MakeBinary(GenericReference, $1, $3);
                        }
        ;
***************
*** 1257,1268 ****
                        }
        | NonExpressionType '<' TypeActuals '>' {
!                               /* TODO: generic type references */
!                               $$ = $1;
                        }
        ;
  
  TypeActuals
!       : Type                                          { /* TODO */ }
!       | TypeActuals ',' Type          { /* TODO */ }
        ;
  
--- 1259,1269 ----
                        }
        | NonExpressionType '<' TypeActuals '>' {
!                               MakeBinary(GenericReference, $1, $3);
                        }
        ;
  
  TypeActuals
!       : Type                                          { $$ = $1; }
!       | TypeActuals ',' Type          { MakeBinary(TypeActuals, $1, $3); }
        ;
  
***************
*** 1277,1282 ****
                        }
        | PrimaryExpression '<' TypeActuals '>' TypeSuffixes    {
!                               /* TODO: generic type declarations */
!                               MakeBinary(LocalVariableType, $1, $5);
                        }
        | BuiltinType TypeSuffixes                      {
--- 1278,1283 ----
                        }
        | PrimaryExpression '<' TypeActuals '>' TypeSuffixes    {
!                               ILNode *type = 
ILNode_GenericReference_create($1, $3);
!                               MakeBinary(LocalVariableType, type, $5);
                        }
        | BuiltinType TypeSuffixes                      {
***************
*** 1646,1649 ****
--- 1647,1657 ----
   * We have to put them here instead of in the more logical place
   * of "PrimaryExpression" to prevent reduce/reduce conflicts.
+  *
+  * This has some odd consequences.  An expression such as "A + B<C>"
+  * will be parsed as "(A + B)<C>" instead of "A + (B<C>)".  To get
+  * around this, we insert the generic type parameters into the
+  * right-most part of the sub-expression, which should put the
+  * parameters back where they belong.  A similar problem happens
+  * with method invocations that involve generic method parameters.
   */
  RelationalExpression
***************
*** 1671,1675 ****
                        }
        | GenericReference '(' OptArgumentList ')'              {
!                               MakeBinary(InvocationExpression, $1, $3); 
                        }
        ;
--- 1679,1683 ----
                        }
        | GenericReference '(' OptArgumentList ')'              {
!                               $$ = CSInsertMethodInvocation($1, $3);
                        }
        ;
***************
*** 1677,1703 ****
  GenericReference
        : RelationalExpression '<' ShiftExpression '>'          {
!                               /* TODO: generic type reference */
!                               $$ = $1;
                        }
        | RelationalExpression '<' ShiftExpression TypeSuffixList '>'   {
!                               /* TODO: generic type reference */
!                               $$ = $1;
                        }
        | RelationalExpression '<' ShiftExpression ',' TypeActuals '>'  {
!                               /* TODO: generic type reference */
!                               $$ = $1;
                        }
        | RelationalExpression '<' ShiftExpression TypeSuffixList ',' 
                        TypeActuals '>'         {
!                               /* TODO: generic type reference */
!                               $$ = $1;
                        }
        | RelationalExpression '<' BuiltinType TypeSuffixes '>' {
!                               /* TODO: generic type reference */
!                               $$ = $1;
                        }
        | RelationalExpression '<' BuiltinType TypeSuffixes ',' TypeActuals '>' 
{
!                               /* TODO: generic type reference */
!                               $$ = $1;
                        }
        ;
--- 1685,1712 ----
  GenericReference
        : RelationalExpression '<' ShiftExpression '>'          {
!                               $$ = CSInsertGenericReference($1, $3);
                        }
        | RelationalExpression '<' ShiftExpression TypeSuffixList '>'   {
!                               $$ = CSInsertGenericReference
!                                       ($1, 
ILNode_LocalVariableType_create($3, $4));
                        }
        | RelationalExpression '<' ShiftExpression ',' TypeActuals '>'  {
!                               $$ = CSInsertGenericReference
!                                       ($1, ILNode_TypeActuals_create($3, $5));
                        }
        | RelationalExpression '<' ShiftExpression TypeSuffixList ',' 
                        TypeActuals '>'         {
!                               $$ = CSInsertGenericReference
!                                       ($1, CSInsertTypeActuals
!                                               
(ILNode_LocalVariableType_create($3, $4), $6));
                        }
        | RelationalExpression '<' BuiltinType TypeSuffixes '>' {
!                               $$ = CSInsertGenericReference
!                                       ($1, 
ILNode_LocalVariableType_create($3, $4));
                        }
        | RelationalExpression '<' BuiltinType TypeSuffixes ',' TypeActuals '>' 
{
!                               $$ = CSInsertGenericReference
!                                       ($1, CSInsertTypeActuals
!                                               
(ILNode_LocalVariableType_create($3, $4), $6));
                        }
        ;
***************
*** 2627,2631 ****
        ;
  
! /* TODO: general parameter formal parameter list */
  TypeFormals
        : /* empty */
--- 2636,2640 ----
        ;
  
! /* TODO: generic formal parameter list */
  TypeFormals
        : /* empty */

Index: cs_internal.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_internal.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -r1.14 -r1.15
*** cs_internal.h       21 Nov 2002 05:25:38 -0000      1.14
--- cs_internal.h       22 Feb 2003 06:14:33 -0000      1.15
***************
*** 259,262 ****
--- 259,279 ----
                                                        const char *name);
  
+ /*
+  * Insert generic type actuals into an expression node at
+  * the right-most position.
+  */
+ ILNode *CSInsertGenericReference(ILNode *mainNode, ILNode *actuals);
+ 
+ /*
+  * Insert a type at the beginning of a type actuals list.
+  */
+ ILNode *CSInsertTypeActuals(ILNode *type, ILNode *actuals);
+ 
+ /*
+  * Insert a method invocation into an expression node at the
+  * right-most position, just after a generic type reference.
+  */
+ ILNode *CSInsertMethodInvocation(ILNode *mainNode, ILNode *parameters);
+ 
  #ifdef        __cplusplus
  };

Index: cs_types.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_types.tc,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** cs_types.tc 8 Dec 2002 02:54:46 -0000       1.7
--- cs_types.tc 22 Feb 2003 06:14:33 -0000      1.8
***************
*** 301,302 ****
--- 301,375 ----
  }
  
+ 
+ /*
+  * Perform semantic analysis for generic type actual parameters.
+  */
+ ILNode_SemAnalysis(ILNode_TypeActuals)
+ {
+       /* TODO */
+       return CSSemValueDefault;
+ }
+ 
+ /*
+  * Perform semantic analysis for a generic type or method reference.
+  */
+ ILNode_SemAnalysis(ILNode_GenericReference)
+ {
+       /* TODO */
+       return ILNode_SemAnalysis(node->type, info, &(node->type));
+ }
+ 
+ %end %{
+ 
+ /*
+  * Find the position to insert a generic type reference,
+  * to re-arrange an expression that was parsed by the
+  * "GenericReference" production in the grammar.
+  */
+ static ILNode **FindGenericInsertPosition(ILNode *node, ILNode **parent)
+ {
+       if(yyisa(node, ILNode_BinaryExpression))
+       {
+               ILNode_BinaryExpression *binary = (ILNode_BinaryExpression 
*)node;
+               return FindGenericInsertPosition(binary->expr2, 
&(binary->expr2));
+       }
+       else if(yyisa(node, ILNode_UnaryExpression))
+       {
+               ILNode_UnaryExpression *unary = (ILNode_UnaryExpression *)node;
+               return FindGenericInsertPosition(unary->expr, &(unary->expr));
+       }
+       else
+       {
+               return parent;
+       }
+ }
+ 
+ ILNode *CSInsertGenericReference(ILNode *mainNode, ILNode *actuals)
+ {
+       ILNode **parent = FindGenericInsertPosition(mainNode, &mainNode);
+       *parent = ILNode_GenericReference_create(*parent, actuals);
+       return mainNode;
+ }
+ 
+ ILNode *CSInsertTypeActuals(ILNode *type, ILNode *actuals)
+ {
+       if(yyisa(actuals, ILNode_TypeActuals))
+       {
+               ((ILNode_TypeActuals *)actuals)->left =
+                       CSInsertTypeActuals(type, ((ILNode_TypeActuals 
*)actuals)->left);
+               return actuals;
+       }
+       else
+       {
+               return ILNode_TypeActuals_create(type, actuals);
+       }
+ }
+ 
+ ILNode *CSInsertMethodInvocation(ILNode *mainNode, ILNode *parameters)
+ {
+       ILNode **parent = FindGenericInsertPosition(mainNode, &mainNode);
+       *parent = ILNode_InvocationExpression_create(*parent, parameters);
+       return mainNode;
+ }
+ 
+ %}





reply via email to

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