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_decls.tc,1.33,1.34 cs_ga


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnet/cscc/csharp cs_decls.tc,1.33,1.34 cs_gather.c,1.37,1.38 cs_lookup.c,1.20,1.21 cs_types.tc,1.8,1.9
Date: Tue, 25 Feb 2003 19:07:28 -0500

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

Modified Files:
        cs_decls.tc cs_gather.c cs_lookup.c cs_types.tc 
Log Message:


Begin implementing type gathering for generic types.


Index: cs_decls.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_decls.tc,v
retrieving revision 1.33
retrieving revision 1.34
diff -C2 -r1.33 -r1.34
*** cs_decls.tc 17 Feb 2003 06:04:26 -0000      1.33
--- cs_decls.tc 26 Feb 2003 00:07:25 -0000      1.34
***************
*** 89,92 ****
--- 89,93 ----
        ILNode *savedMethod;
        ILNode *staticCtorList=NULL;
+       ILNode *savedTypeFormals;
        int hadStaticCtorsBefore;
        int target;
***************
*** 156,162 ****
--- 157,165 ----
                savedNamespace = info->currentNamespace;
                savedMethod = info->currentMethod;
+               savedTypeFormals = info->currentTypeFormals;
                info->currentClass = (ILNode *)node;
                info->currentNamespace = node->namespaceNode;
                info->currentMethod = NULL;
+               info->currentTypeFormals = node->typeFormals;
                value = ILNode_SemAnalysis(node->body, info, &(node->body));
                if(node->initCtorsMethod)
***************
*** 232,235 ****
--- 235,239 ----
                info->currentNamespace = savedNamespace;
                info->currentMethod = savedMethod;
+               info->currentTypeFormals = savedTypeFormals;
        }
        else

Index: cs_gather.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_gather.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -r1.37 -r1.38
*** cs_gather.c 21 Feb 2003 12:18:49 -0000      1.37
--- cs_gather.c 26 Feb 2003 00:07:25 -0000      1.38
***************
*** 103,109 ****
--- 103,113 ----
        ILNode *savedNamespace;
        ILNode *savedClass;
+       ILNode *savedTypeFormals;
        ILProgramItem *nestedScope;
        ILNode *node;
        ILNode_ListIter iter;
+       ILUInt32 formalNum;
+       ILGenericPar *genPar;
+       ILClass *underlying;
  
        /* Get the name and namespace for the type, for error reporting */
***************
*** 163,166 ****
--- 167,172 ----
        savedClass = info->currentClass;
        info->currentClass = (ILNode *)(defn->nestedParent);
+       savedTypeFormals = info->currentTypeFormals;
+       info->currentTypeFormals = defn->typeFormals;
  
        /* Create all of the base classes */
***************
*** 303,312 ****
        }
  
!       /* Restore the namespace and class */
        info->currentNamespace = savedNamespace;
        info->currentClass = savedClass;
  
        /* Output an error if attempting to inherit from a sealed class */
!       if(parent && ILClass_IsSealed(parent))
        {
                CCErrorOnLine(yygetfilename(type), yygetlinenum(type),
--- 309,331 ----
        }
  
!       /* Restore the namespace, class, and type formals */
        info->currentNamespace = savedNamespace;
        info->currentClass = savedClass;
+       info->currentTypeFormals = savedTypeFormals;
  
        /* Output an error if attempting to inherit from a sealed class */
!       if(parent)
!       {
!               underlying = ILClassGetUnderlying(parent);
!               if(!underlying)
!               {
!                       CCOutOfMemory();
!               }
!       }
!       else
!       {
!               underlying = 0;
!       }
!       if(underlying && ILClass_IsSealed(underlying))
        {
                CCErrorOnLine(yygetfilename(type), yygetlinenum(type),
***************
*** 341,344 ****
--- 360,381 ----
                        }
                }
+       }
+ 
+       /* Add the type formals to the class definition */
+       ILNode_ListIter_Init(&iter, defn->typeFormals);
+       formalNum = 0;
+       while((node = ILNode_ListIter_Next(&iter)) != 0)
+       {
+               genPar = ILGenericParCreate
+                       (info->image, 0, ILToProgramItem(classInfo), formalNum);
+               if(!genPar)
+               {
+                       CCOutOfMemory();
+               }
+               if(!ILGenericParSetName(genPar, ILQualIdentName(node, 0)))
+               {
+                       CCOutOfMemory();
+               }
+               ++formalNum;
        }
  

Index: cs_lookup.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_lookup.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -r1.20 -r1.21
*** cs_lookup.c 23 Feb 2003 02:28:19 -0000      1.20
--- cs_lookup.c 26 Feb 2003 00:07:25 -0000      1.21
***************
*** 961,966 ****
  }
  
! CSSemValue CSResolveSimpleName(ILGenInfo *genInfo, ILNode *node,
!                                                                               
const char *name, int literalType)
  {
        ILClass *startType;
--- 961,970 ----
  }
  
! /*
!  * Inner version of CSResolveSimpleName and CSResolveSimpleNameQuiet.
!  */
! static CSSemValue ResolveSimpleName(ILGenInfo *genInfo, ILNode *node,
!                                                                       const 
char *name, int literalType,
!                                                                       int 
reportErrors)
  {
        ILClass *startType;
***************
*** 972,975 ****
--- 976,983 ----
        ILNode_ClassDefn *nestedParent;
        ILNode *child;
+       ILNode_ListIter iter;
+       int formalNum;
+       ILType *formalType;
+       CSSemValue value;
  
        /* If we are within type gathering, then search the nesting
***************
*** 983,987 ****
                        if(child)
                        {
-                               CSSemValue value;
                                CSSemSetTypeNode(value, child);
                                return value;
--- 991,994 ----
***************
*** 991,1111 ****
        }
  
!       /* Find the type to start looking at and the scope to use for accesses 
*/
!       startType = CSGetAccessScope(genInfo, 0);
!       accessedFrom = ILClassResolve(CSGetAccessScope(genInfo, 1));
! 
!       /* Scan the start type and its nested parents */
!       while(startType != 0)
!       {
!               /* Resolve cross-image references */
!               startType = ILClassResolve(startType);
! 
!               /* Look for members */
!               result = MemberLookup(genInfo, startType, name,
!                                                         accessedFrom, 
&results, 1, 0, literalType);
!               if(result != CS_SEMKIND_VOID)
!               {
!                       return LookupToSem(node, name, &results, result);
!               }
! 
!               /* Move up to the nested parent */
!               startType = ILClass_NestedParent(startType);
!       }
! 
!       /* Clear the results buffer */
!       InitMembers(&results);
! 
!       /* Scan all namespaces that enclose the current context */
!       namespace = (ILNode_Namespace *)(genInfo->currentNamespace);
!       while(namespace != 0 && !(results.num))
!       {
!               /* Look for the type in the current namespace */
!               result = FindTypeInNamespace(genInfo, name, namespace->name,
!                                                                        
accessedFrom, &results);
!               if(result != CS_SEMKIND_VOID)
!               {
!                       break;
!               }
!       
!               /* Find the types in all using namespaces */
!               using = namespace->using;
!               while(using != 0)
!               {
!                       FindTypeInNamespace(genInfo, name, using->name,
!                                                               accessedFrom, 
&results);
!                       using = using->next;
!               }
! 
!               /* Move up to the enclosing namespace */
!               namespace = namespace->enclosing;
!       }
! 
!       /* We should have 0, 1, or many types at this point */
!       if(results.num > 1)
!       {
!               /* The result is ambiguous */
!               AmbiguousError(node, name, &results);
!       }
!       if(results.num != 0)
!       {
!               /* Return the first type in the results list */
!               if(results.members->kind == CS_MEMBERKIND_TYPE)
!               {
!                       return LookupToSem(node, name, &results, 
CS_SEMKIND_TYPE);
!               }
!               else if(results.members->kind == CS_MEMBERKIND_TYPE_NODE)
!               {
!                       return LookupToSem(node, name, &results, 
CS_SEMKIND_TYPE_NODE);
!               }
!               else
!               {
!                       return LookupToSem(node, name, &results, 
CS_SEMKIND_NAMESPACE);
!               }
!       }
!       FreeMembers(&results);
! 
!       /* Could not resolve the name */
!       CCErrorOnLine(yygetfilename(node), yygetlinenum(node),
!                                 "`%s' is not declared in the current scope", 
name);
! 
!       if (literalType)
!       {
!               /* Resolve it cleanly if a type was not found */
!               return CSResolveSimpleName(genInfo, node, name, 0);
!       }
!       else
!       {
!               return CSSemValueDefault;
!       }
! }
! 
! CSSemValue CSResolveSimpleNameQuiet(ILGenInfo *genInfo, ILNode *node,
!                                                                               
const char *name, int literalType)
! {
!       ILClass *startType;
!       ILClass *accessedFrom;
!       CSMemberLookupInfo results;
!       ILNode_Namespace *namespace;
!       ILNode_UsingNamespace *using;
!       int result;
!       ILNode_ClassDefn *nestedParent;
!       ILNode *child;
! 
!       /* If we are within type gathering, then search the nesting
!          parents for a nested type that matches our requirements */
!       if(genInfo->typeGather)
!       {
!               nestedParent = (ILNode_ClassDefn *)(genInfo->currentClass);
!               while(nestedParent != 0)
!               {
!                       child = FindNestedClass(0, nestedParent, name);
!                       if(child)
                        {
!                               CSSemValue value;
!                               CSSemSetTypeNode(value, child);
!                               return value;
                        }
!                       nestedParent = nestedParent->nestedParent;
                }
        }
  
--- 998,1018 ----
        }
  
!       /* Scan the method formals for a match */
!       ILNode_ListIter_Init(&iter, genInfo->currentMethodFormals);
!       formalNum = 0;
!       while((child = ILNode_ListIter_Next(&iter)) != 0)
!       {
!               if(!strcmp(ILQualIdentName(child, 0), name))
!               {
!                       formalType = ILTypeCreateVarNum
!                               (genInfo->context, IL_TYPE_COMPLEX_MVAR, 
formalNum);
!                       if(!formalType)
                        {
!                               CCOutOfMemory();
                        }
!                       CSSemSetType(value, formalType);
!                       return value;
                }
+               ++formalNum;
        }
  
***************
*** 1135,1138 ****
--- 1042,1064 ----
        InitMembers(&results);
  
+       /* Scan the type formals for a match */
+       ILNode_ListIter_Init(&iter, genInfo->currentTypeFormals);
+       formalNum = 0;
+       while((child = ILNode_ListIter_Next(&iter)) != 0)
+       {
+               if(!strcmp(ILQualIdentName(child, 0), name))
+               {
+                       formalType = ILTypeCreateVarNum
+                               (genInfo->context, IL_TYPE_COMPLEX_VAR, 
formalNum);
+                       if(!formalType)
+                       {
+                               CCOutOfMemory();
+                       }
+                       CSSemSetType(value, formalType);
+                       return value;
+               }
+               ++formalNum;
+       }
+ 
        /* Scan all namespaces that enclose the current context */
        namespace = (ILNode_Namespace *)(genInfo->currentNamespace);
***************
*** 1184,1191 ****
        FreeMembers(&results);
  
        if (literalType)
        {
                /* Resolve it cleanly if a type was not found */
!               return CSResolveSimpleNameQuiet(genInfo, node, name, 0);
        }
        else
--- 1110,1123 ----
        FreeMembers(&results);
  
+       /* Could not resolve the name */
+       if(reportErrors)
+       {
+               CCErrorOnLine(yygetfilename(node), yygetlinenum(node),
+                                         "`%s' is not declared in the current 
scope", name);
+       }
        if (literalType)
        {
                /* Resolve it cleanly if a type was not found */
!               return ResolveSimpleName(genInfo, node, name, 0, reportErrors);
        }
        else
***************
*** 1194,1197 ****
--- 1126,1142 ----
        }
  }
+ 
+ CSSemValue CSResolveSimpleName(ILGenInfo *genInfo, ILNode *node,
+                                                          const char *name, 
int literalType)
+ {
+       return ResolveSimpleName(genInfo, node, name, literalType, 1);
+ }
+ 
+ CSSemValue CSResolveSimpleNameQuiet(ILGenInfo *genInfo, ILNode *node,
+                                                                       const 
char *name, int literalType)
+ {
+       return ResolveSimpleName(genInfo, node, name, literalType, 0);
+ }
+ 
  /*
   * Filter a member lookup results list to include only static entries.

Index: cs_types.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_types.tc,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** cs_types.tc 22 Feb 2003 06:14:33 -0000      1.8
--- cs_types.tc 26 Feb 2003 00:07:25 -0000      1.9
***************
*** 311,314 ****
--- 311,349 ----
  }
  
+ %{
+ 
+ /*
+  * Perform semantic analysis on a set of type actuals
+  * and add them to a "with" type.
+  */
+ static void SemWithType(ILGenInfo *info, ILType *withType,
+                                           ILNode *actuals, ILNode **parent)
+ {
+       CSSemValue value;
+       if(yyisa(actuals, ILNode_TypeActuals))
+       {
+               SemWithType(info, withType, ((ILNode_TypeActuals 
*)actuals)->left,
+                                       &(((ILNode_TypeActuals 
*)actuals)->left));
+               SemWithType(info, withType, ((ILNode_TypeActuals 
*)actuals)->right,
+                                       &(((ILNode_TypeActuals 
*)actuals)->right));
+       }
+       else
+       {
+               value = ILNode_SemAnalysisType(actuals, info, parent);
+               if(!CSSemIsType(value))
+               {
+                       CCErrorOnLine(yygetfilename(actuals), 
yygetlinenum(actuals),
+                                             "type name expected in generic 
type parameter");
+                       CSSemSetType(value, ILType_Int32);
+               }
+               if(!ILTypeAddWithParam(info->context, withType, 
CSSemGetType(value)))
+               {
+                       CCOutOfMemory();
+               }
+       }
+ }
+ 
+ %}
+ 
  /*
   * Perform semantic analysis for a generic type or method reference.
***************
*** 316,321 ****
  ILNode_SemAnalysis(ILNode_GenericReference)
  {
!       /* TODO */
!       return ILNode_SemAnalysis(node->type, info, &(node->type));
  }
  
--- 351,402 ----
  ILNode_SemAnalysis(ILNode_GenericReference)
  {
!       CSSemValue value;
!       ILClass *classInfo;
!       ILUInt32 numFormals;
!       ILUInt32 numActuals;
!       ILNode *actuals;
!       ILType *withType;
! 
!       /* Perform semantic analysis on the main part of the type */
!       value = ILNode_SemAnalysisType(node->type, info, &(node->type));
!       if(!CSSemIsType(value))
!       {
!               CCErrorOnLine(yygetfilename(node->type), 
yygetlinenum(node->type),
!                                         "type name expected in generic type 
reference");
!               return value;
!       }
! 
!       /* Find the number of generic parameters that we expect */
!       classInfo = ILClassResolve(ILTypeToClass(info, CSSemGetType(value)));
!       numFormals = ILGenericParGetNumParams(ILToProgramItem(classInfo));
! 
!       /* Count the number of actual parameters that we were given */
!       numActuals = 1;
!       actuals = node->actuals;
!       while(yyisa(actuals, ILNode_TypeActuals))
!       {
!               ++numActuals;
!               actuals = ((ILNode_TypeActuals *)actuals)->left;
!       }
! 
!       /* Check the counts for consistency */
!       if(numFormals != numActuals)
!       {
!               CCErrorOnLine(yygetfilename(node), yygetlinenum(node),
!                                         "incorrect number of generic 
parameters supplied to "
!                                         "`%s'; was %d but should be %d",
!                                         CSTypeToName(CSSemGetType(value)),
!                                         (int)numActuals, (int)numFormals);
!       }
! 
!       /* Build the "with" type and return it */
!       withType = ILTypeCreateWith(info->context, CSSemGetType(value));
!       if(!withType)
!       {
!               CCOutOfMemory();
!       }
!       SemWithType(info, withType, node->actuals, &(node->actuals));
!       CSSemSetType(value, withType);
!       return value;
  }
  





reply via email to

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