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

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

[dotgnu-pnet-commits] pnet ChangeLog codegen/cg_scope.c codegen/cg_sc...


From: Klaus Treichel
Subject: [dotgnu-pnet-commits] pnet ChangeLog codegen/cg_scope.c codegen/cg_sc...
Date: Mon, 28 May 2007 15:28:37 +0000

CVSROOT:        /cvsroot/dotgnu-pnet
Module name:    pnet
Changes by:     Klaus Treichel <ktreichel>      07/05/28 15:28:37

Modified files:
        .              : ChangeLog 
        codegen        : cg_scope.c cg_scope.h 
        cscc/csharp    : cs_lookup.c 

Log message:
        Fix more type resolution problems and do some optimizations.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pnet/ChangeLog?cvsroot=dotgnu-pnet&r1=1.3460&r2=1.3461
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_scope.c?cvsroot=dotgnu-pnet&r1=1.21&r2=1.22
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_scope.h?cvsroot=dotgnu-pnet&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/csharp/cs_lookup.c?cvsroot=dotgnu-pnet&r1=1.32&r2=1.33

Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/ChangeLog,v
retrieving revision 1.3460
retrieving revision 1.3461
diff -u -b -r1.3460 -r1.3461
--- ChangeLog   28 May 2007 14:40:35 -0000      1.3460
+++ ChangeLog   28 May 2007 15:28:37 -0000      1.3461
@@ -4,6 +4,23 @@
        of an ILClass. We have to read the ILClass member directly because non
        system flags are masked out otherwise.
 
+       * codegen/cg_scope.c: Add the functions ILScopeGetNamespaceName and
+       ILScopeDataGetNamespaceName to get the fully qualified namespace name
+       attached to a scope or subscope of the scope data item.
+       Add attaching the namespace name to the scope in FindNamespaceScope for
+       new created namespace scopes. Add an additional argument for
+       FindNamespaceScope to specify if the namespace should be created if it
+       isn't found. Don't create the namespace scope if searching for a 
namespace
+       or or a member in a namespace.
+       
+       * codegen/cg_scope.c: Add the prototypes for ILScopeGetNamespaceName and
+       ILScopeDataGetNamespaceName.
+
+       * cscc/csharp/cs_lookup.c: Do the lookup for valid namespaces in
+       FindTypeInNamespace instead of after looking in all enclosing namespaces
+       only which is more ECMA compliant. Dont look for namespaces when 
resolving
+       with using namespace declarations.
+ 
 2007-05-26  Klaus Treichel  <address@hidden>
 
        * codegen/cg_scope.c: Change the cast in the assignment of data to 
*index

Index: codegen/cg_scope.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_scope.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- codegen/cg_scope.c  26 May 2007 07:23:19 -0000      1.21
+++ codegen/cg_scope.c  28 May 2007 15:28:37 -0000      1.22
@@ -60,7 +60,7 @@
        ILRBTree                nameTree;       /* Tree containing all names in 
the scope */
        ILScopeUsingInfo *using;        /* Using declarations for the scope */
        ILScope                 *aliases;       /* aliases lookup scope */
-       ILClass            *classInfo;  /* Data attached to the scope for 
searching */
+       void               *userData;   /* user data attached to the scope */
 
        /* Function for looking up an item within the scope */
        ILScopeData *(*lookup)(ILScope *scope, const char *name);
@@ -151,7 +151,7 @@
        ILRBTreeInit(&(scope->nameTree), NameCompare, 0);
        scope->using = 0;
        scope->aliases = 0;
-       scope->classInfo = 0;
+       scope->userData = 0;
        scope->lookup = NormalScope_Lookup;
        return scope;
 }
@@ -179,14 +179,17 @@
 
 /*
  * Find a namespace scope from a name.  If the namespace
- * scope does not exist, then create it.
+ * scope does not exist, then create it if addMissing is != 0.
  */
-static ILScope *FindNamespaceScope(ILScope *scope, const char *name)
+static ILScope *FindNamespaceScope(ILScope *scope,
+                                                                  const char 
*name,
+                                                                  int 
addIfMissing)
 {
        ILScopeData *data;
-       ILScope *newScope;
        int len;
-       const char *newName;
+       ILIntString newName;
+       int newNameNeedsIntern = 0;
+
        while(*name != '\0')
        {
                if(*name == '.')
@@ -201,13 +204,16 @@
                }
                if(name[len] == '\0')
                {
-                       newName = name;
+                       newName.string = name;
+                       newName.len = len;
+                       newNameNeedsIntern = 1;
                }
                else
                {
-                       newName = (ILInternString((char *)name, len)).string;
+                       newName = ILInternString(name, len);
+                       newNameNeedsIntern = 0;
                }
-               data = ILScopeLookup(scope, newName, 0);
+               data = ILScopeLookup(scope, newName.string, 0);
                if(data != 0)
                {
                        if(data->rbnode.kind == IL_SCOPE_SUBSCOPE)
@@ -224,10 +230,52 @@
                }
                else
                {
-                       newScope = ILScopeCreate(scope->info, scope);
-                       AddToScope(scope, newName, IL_SCOPE_SUBSCOPE, 0, 
newScope, 0);
+                       if(addIfMissing)
+                       {
+                               ILScope *newScope = ILScopeCreate(scope->info, 
scope);
+                               AddToScope(scope, newName.string, 
IL_SCOPE_SUBSCOPE, 0, newScope, 0);
+                               if(scope)
+                               {
+                                       if(scope->userData && (*(char 
*)(scope->userData) != '\0'))
+                                       {
+                                               ILIntString namespace;
+                                               ILIntString dot;
+
+                                               namespace.string = (const char 
*)(scope->userData);
+                                               namespace.len = 
strlen(namespace.string);
+                                               dot.string = ".";
+                                               dot.len = 1;
+                                               newScope->userData = 
+                                                       (void 
*)(ILInternStringConcat3(namespace,
+                                                                               
                                   dot,
+                                                                               
                                   newName).string);
+                                       }
+                                       else
+                                       {
+                                               if(newNameNeedsIntern)
+                                               {
+                                                       newName = 
ILInternString(newName.string,
+                                                                               
                         newName.len);
+                                               }
+                                               newScope->userData = (void 
*)newName.string;
+                                       }
+                               }
+                               else
+                               {
+                                       if(newNameNeedsIntern)
+                                       {
+                                               newName = 
ILInternString(newName.string, newName.len);
+                                       }
+                                       newScope->userData = (void 
*)newName.string;
+                               }
                        scope = newScope;
                }
+                       else
+                       {
+                               /* The Namespace couldn't be found so bail out. 
*/
+                               return (ILScope *)0;
+                       }
+               }
                name += len;
        }
        return scope;
@@ -257,7 +305,7 @@
        /* Create a new scope for the type */
        newScope = ILScopeCreate(scope->info, scope);
        newScope->lookup = TypeScope_Lookup;
-       newScope->classInfo = info;
+       newScope->userData = (void *)info;
 
        /* Add the new scope to the original scope, attached to the type name */
        AddToScope(scope, name, IL_SCOPE_IMPORTED_TYPE, 0, newScope, 0);
@@ -330,6 +378,12 @@
                        return 0;
                }
 
+               if(ILClassNamespaceIsValid(scope->info->context, namespace))
+               {
+                       return FindNamespaceScope(scope->info->globalScope,
+                                                                         
namespace, 1);
+               }
+
                while((image = ILContextNextImage(scope->info->context, image)) 
!= 0)
                {
                        unsigned long numTokens;
@@ -355,7 +409,8 @@
                                                        if((testLen == 
namespaceLen) ||
                                                           ((testLen > 
namespaceLen) && (namespaceTest[namespaceLen] == '.')))
                                                        {
-                                                               return 
FindNamespaceScope(scope->info->globalScope, namespace);
+                                                               return 
FindNamespaceScope(scope->info->globalScope,
+                                                                               
                                  namespace, 1);
                                                        }
                                                }
                                        }
@@ -416,7 +471,8 @@
                                     !strcmp(namespaceName, namespaceTest)))
                                {
                                        namespaceName = namespaceTest;
-                                       namespaceScope = 
FindNamespaceScope(scope, namespaceTest);
+                                       namespaceScope = 
FindNamespaceScope(scope,
+                                                                               
                                namespaceTest, 1);
                                }
                        }
                        else
@@ -442,7 +498,7 @@
 
 int ILScopeUsing(ILScope *scope, const char *identifier)
 {
-       ILScope *namespaceScope = FindNamespaceScope(scope, identifier);
+       ILScope *namespaceScope = FindNamespaceScope(scope, identifier, 1);
        ILScopeUsingInfo *using;
        if(!namespaceScope)
        {
@@ -508,7 +564,7 @@
        }
        else
        {
-               scope = FindNamespaceScope(globalScope, namespace);
+               scope = FindNamespaceScope(globalScope, namespace, 0);
                if(!scope)
                {
                        return 0;
@@ -528,14 +584,23 @@
        return (ILScopeData *)(ILRBTreeNext(&(data->rbnode)));
 }
 
+const char *ILScopeGetNamespaceName(ILScope *scope)
+{
+       if(scope)
+       {
+               return (const char *)(scope->userData);
+       }
+       return 0;
+}
+
 ILScope *ILScopeDeclareNamespace(ILScope *globalScope, const char *namespace)
 {
-       return FindNamespaceScope(globalScope, namespace);
+       return FindNamespaceScope(globalScope, namespace, 1);
 }
 
 ILScope *ILScopeFindNamespace(ILScope *globalScope, const char *namespace)
 {
-       return FindNamespaceScope(globalScope, namespace);
+       return FindNamespaceScope(globalScope, namespace, 0);
 }
 
 int ILScopeDeclareType(ILScope *scope, ILNode *node, const char *name,
@@ -550,7 +615,7 @@
        /* Find the scope that is associated with the namespace */
        if(namespace && *namespace != '\0')
        {
-               namespaceScope = FindNamespaceScope(scope, namespace);
+               namespaceScope = FindNamespaceScope(scope, namespace, 1);
                if(!namespaceScope)
                {
                        return IL_SCOPE_ERROR_CANT_CREATE_NAMESPACE;
@@ -674,7 +739,7 @@
        if(namespace && identifier &&
           yykind(identifier) == yykindof(ILNode_Identifier))
        {
-               namespaceScope = FindNamespaceScope(scope, namespace);
+               namespaceScope = FindNamespaceScope(scope, namespace, 0);
                if(namespaceScope)
                {
                        data = ILScopeLookup(namespaceScope,
@@ -689,7 +754,7 @@
                                }
                                else if(data->rbnode.kind == 
IL_SCOPE_IMPORTED_TYPE)
                                {
-                                       *classInfo = ((ILScope 
*)(data->data))->classInfo;
+                                       *classInfo = (ILClass *)((ILScope 
*)(data->data))->userData;
                                        *nodeInfo = 0;
                                        return 1;
                                }
@@ -713,7 +778,7 @@
                }
                else if(data->rbnode.kind == IL_SCOPE_IMPORTED_TYPE)
                {
-                       *classInfo = ((ILScope *)(data->data))->classInfo;
+                       *classInfo = (ILClass *)(((ILScope 
*)(data->data))->userData);
                        *nodeInfo = 0;
                        return 1;
                }
@@ -924,7 +989,7 @@
        }
        else if(data->rbnode.kind == IL_SCOPE_IMPORTED_TYPE)
        {
-               return ((ILScope *)(data->data))->classInfo;
+               return (ILClass *)(((ILScope *)(data->data))->userData);
        }
        else
        {
@@ -932,6 +997,18 @@
        }
 }
 
+const char *ILScopeDataGetNamespaceName(ILScopeData *data)
+{
+       if(data)
+       {
+               if(data->rbnode.kind == IL_SCOPE_SUBSCOPE)
+               {
+                       return (const char *)(((ILScope 
*)(data->data))->userData);
+               }
+       }
+       return 0;
+}
+
 ILScope *ILScopeDataGetSubScope(ILScopeData *data)
 {
        return (ILScope *)(data->data);

Index: codegen/cg_scope.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_scope.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- codegen/cg_scope.h  24 May 2007 13:51:14 -0000      1.16
+++ codegen/cg_scope.h  28 May 2007 15:28:37 -0000      1.17
@@ -124,6 +124,13 @@
 ILScope *ILScopeImportNamespace(ILScope *scope, const char *namespace);
 
 /*
+ * Get the fully qualified namespace name from the scope.
+ * The result is guaranteed to be valid only for scopes returned by
+ * ILScopeDeclareNamespace, ILScopeFindNamespace and ILScopeImportNamespace.
+ */
+const char *ILScopeGetNamespaceName(ILScope *scope);
+
+/*
  * Declare a type within a particular scope.  If the name
  * already exists, then an "IL_SCOPE_ERROR_xxx" code is
  * returned.  If there is a declaration for the type already,
@@ -184,6 +191,11 @@
 ILClass *ILScopeDataGetClass(ILScopeData *data);
 
 /*
+ * Get the fully qualified namespace name associated with a scope item.
+ */
+const char *ILScopeDataGetNamespaceName(ILScopeData *data);
+
+/*
  * Get the sub-scope structure associated with a scope item.
  */
 ILScope *ILScopeDataGetSubScope(ILScopeData *data);

Index: cscc/csharp/cs_lookup.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_lookup.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -b -r1.32 -r1.33
--- cscc/csharp/cs_lookup.c     24 May 2007 13:51:15 -0000      1.32
+++ cscc/csharp/cs_lookup.c     28 May 2007 15:28:37 -0000      1.33
@@ -895,10 +895,11 @@
 
 /*
  * Find the type with a specific name within a namespace.
+ * Restrict the resolution to types only if typesOnly is != 0.
  */
 static int FindTypeInNamespace(ILGenInfo *genInfo, const char *name,
                                                           const char 
*namespace, ILClass *accessedFrom,
-                                                          CSMemberLookupInfo 
*results)
+                                                          CSMemberLookupInfo 
*results, int typesOnly)
 {
        ILClass *type;
        ILScopeData *data;
@@ -926,20 +927,17 @@
                scopeKind = ILScopeDataGetKind(data);
                if(scopeKind == IL_SCOPE_SUBSCOPE)
                {
-                       if(namespace)
+                       if(typesOnly == 0)
                        {
-                               fullName = ILInternStringConcat3
-                                                               
(ILInternString(namespace, -1),
-                                                                
ILInternString(".", 1),
-                                                                
ILInternString(name, -1)).string;
+                               fullName = ILScopeDataGetNamespaceName(data);
+                               AddMember(results, (ILProgramItem *)fullName,
+                                                 0, CS_MEMBERKIND_NAMESPACE);
+                               return CS_SEMKIND_NAMESPACE;
                        }
                        else
                        {
-                               fullName = name;
+                               return CS_SEMKIND_VOID; 
                        }
-                       AddMember(results, (ILProgramItem *)fullName,
-                                         0, CS_MEMBERKIND_NAMESPACE);
-                       return CS_SEMKIND_NAMESPACE;
                }
                else if(scopeKind == IL_SCOPE_DECLARED_TYPE)
                {
@@ -973,6 +971,27 @@
                return CS_SEMKIND_TYPE;
        }
 
+       /* Now check if it's an existing namespace name */
+       if(typesOnly == 0)
+       {
+               if(namespace && (*namespace != '\0'))
+               {
+                       fullName = 
ILInternStringConcat3(ILInternString(namespace, -1),
+                                                                               
         ILInternString(".", 1),
+                                                                               
         ILInternString(name, -1)).string;
+               }
+               else
+               {
+                       fullName = name;
+               }
+               if(ILScopeImportNamespace(genInfo->globalScope, fullName) != 0)
+               {
+                       AddMember(results, (ILProgramItem *)fullName,
+                                         0, CS_MEMBERKIND_NAMESPACE);
+                       return CS_SEMKIND_NAMESPACE;
+               }
+       }
+
        /* Could not find a type or namespace with the specified name */
        return CS_SEMKIND_VOID;
 }
@@ -1298,7 +1317,7 @@
        {
                /* Look for the type in the current namespace */
                result = FindTypeInNamespace(genInfo, name, namespace->name,
-                                                                        
accessedFrom, &results);
+                                                                        
accessedFrom, &results, 0);
                if(result != CS_SEMKIND_VOID)
                {
                        /* We have to check if an alias with the same name is 
declared here too. */
@@ -1353,7 +1372,7 @@
                while(using != 0)
                {
                        FindTypeInNamespace(genInfo, name, using->name,
-                                                               accessedFrom, 
&results);
+                                                               accessedFrom, 
&results, 1);
                        using = using->next;
                }
 
@@ -1361,16 +1380,6 @@
                namespace = namespace->enclosing;
        }
 
-       /* We have to look in the ipmorted libraries now if the name is a valid 
namespace. */
-       if((result == CS_SEMKIND_VOID) && !(results.num))
-       {
-               if(ILScopeImportNamespace(genInfo->globalScope, name))
-               {
-                       CSSemSetNamespace(value, name);
-                       return value;
-               }
-       }
-
        /* We should have 0, 1, or many types at this point */
        if(results.num > 1 && reportErrors)
        {
@@ -1441,21 +1450,7 @@
        result = FindTypeInNamespace(genInfo, name,
                                                                 
CSSemGetNamespace(value),
                                                                 
ILClassResolve(CSGetAccessScope(genInfo, 1)),
-                                                                &results);
-
-       /* See if the namespace is valid, according to the loaded libraries */
-       if(result == CS_SEMKIND_VOID)
-       {
-               nspace = ILInternStringConcat3
-                       (ILInternString(CSSemGetNamespace(value), -1),
-                        ILInternString(".", 1),
-                        ILInternString((char *)name, -1));
-               if(ILScopeImportNamespace(genInfo->globalScope, nspace.string))
-               {
-                       CSSemSetNamespace(value, nspace.string);
-                       return value;
-               }
-       }
+                                                                &results, 0);
 
        /* Return the result to the caller */
        if(result == CS_SEMKIND_VOID)




reply via email to

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