[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[dotgnu-pnet-commits] pnet ChangeLog codegen/cg_defs.h codegen/cg_gen...
From: |
Klaus Treichel |
Subject: |
[dotgnu-pnet-commits] pnet ChangeLog codegen/cg_defs.h codegen/cg_gen... |
Date: |
Thu, 24 May 2007 13:51:16 +0000 |
CVSROOT: /cvsroot/dotgnu-pnet
Module name: pnet
Changes by: Klaus Treichel <ktreichel> 07/05/24 13:51:16
Modified files:
. : ChangeLog
codegen : cg_defs.h cg_gen.c cg_gen.h cg_nodes.tc
cg_scope.c cg_scope.h
cscc : csdoc.c cs_main.c java_main.c vb_main.c
cscc/common : cc_main.h cc_main.c
cscc/csharp : cs_defs.tc cs_grammar.y cs_lookup.c
cs_lvalue.tc cs_semantics.tc
cscc/vb : vb_grammar.y
cscc/java : java_grammar.y java_lookup.c java_semantics.tc
Log message:
Fix type resolution in the C# compiler.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pnet/ChangeLog?cvsroot=dotgnu-pnet&r1=1.3455&r2=1.3456
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_defs.h?cvsroot=dotgnu-pnet&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_gen.c?cvsroot=dotgnu-pnet&r1=1.49&r2=1.50
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_gen.h?cvsroot=dotgnu-pnet&r1=1.47&r2=1.48
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_nodes.tc?cvsroot=dotgnu-pnet&r1=1.87&r2=1.88
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_scope.c?cvsroot=dotgnu-pnet&r1=1.19&r2=1.20
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_scope.h?cvsroot=dotgnu-pnet&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/csdoc.c?cvsroot=dotgnu-pnet&r1=1.24&r2=1.25
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/cs_main.c?cvsroot=dotgnu-pnet&r1=1.22&r2=1.23
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/java_main.c?cvsroot=dotgnu-pnet&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/vb_main.c?cvsroot=dotgnu-pnet&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/common/cc_main.h?cvsroot=dotgnu-pnet&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/common/cc_main.c?cvsroot=dotgnu-pnet&r1=1.37&r2=1.38
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/csharp/cs_defs.tc?cvsroot=dotgnu-pnet&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/csharp/cs_grammar.y?cvsroot=dotgnu-pnet&r1=1.78&r2=1.79
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/csharp/cs_lookup.c?cvsroot=dotgnu-pnet&r1=1.31&r2=1.32
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/csharp/cs_lvalue.tc?cvsroot=dotgnu-pnet&r1=1.60&r2=1.61
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/csharp/cs_semantics.tc?cvsroot=dotgnu-pnet&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/vb/vb_grammar.y?cvsroot=dotgnu-pnet&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/java/java_grammar.y?cvsroot=dotgnu-pnet&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/java/java_lookup.c?cvsroot=dotgnu-pnet&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/java/java_semantics.tc?cvsroot=dotgnu-pnet&r1=1.2&r2=1.3
Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/ChangeLog,v
retrieving revision 1.3455
retrieving revision 1.3456
diff -u -b -r1.3455 -r1.3456
--- ChangeLog 17 May 2007 09:45:02 -0000 1.3455
+++ ChangeLog 24 May 2007 13:51:13 -0000 1.3456
@@ -1,3 +1,53 @@
+2007-05-24 Klaus Treichel <address@hidden>
+
+ * codegen/cg_defs.h, codegen/cg_scope.h: Move the opaque declaration of
+ ILScopeData from cg_scope.h to cg_defs.h.
+
+ * codegen/cg_gen.h, codegen/cg_gen.c: Add the member globalScope to the
+ generator type which replaces the global variable CCGlobalScope.
+
+ * codegen/cg_nodes.tc: Add the abstract node type ILNode_alias to hold
+ the UsingAlias (and ExternalAlias in the future).
+
+ * codegen/cg_scope.c, codegen/cg_scope.h: Add the function
+ ILScopeImportNamespace to check if a namespace occures in one of the
+ import libraries and declare it in the scope then. Change
+ ILScopeDeclareNamespace so that the namespace scope is returned.
+
+ * cscc/csdoc.c, cscc/cs_main.c, cscc/java_main.c, cscc/vb_main.c:
Replace
+ CCGlobalScope with CCCodeGen.globalScope.
+
+ * cscc/common/cc_main.c, cscc/common/cc_main.h: Remove the declaration
of
+ CCGlobalScope.
+
+ * cscc/csharp/cs_defs.tc: Change the definition of ILNode_UsingAlias so
+ that the ILNode_Alias is used. Add functions for managing using
namespace
+ and using alias declarations.
+
+ * cscc/csharp/cs_grammar.y: Remove the default using namespace
declaration
+ for the System namespace. Change the localScope in the namespace node so
+ that it points to the corresponding namespace scope in the global scope.
+ The using scopes are no longer used now by the csharp compiler.
+
+ * cscc/csharp/cs_lookup.c: Handle the aliases now when resolving a
simple
+ name. Use ILScopeImportNamespace instead of ILClassNamespaceIsValid now
+ because the later one told that a namespace is invalid if there are no
+ types declared in that namespace but subnamespaces exist.
+
+ * cscc/csharp/cs_lvalue.tc: Remove the handling of aliases because they
are
+ handled in cs_lookup.c now.
+
+ * cscc/csharp/cs_semantics.c: Declare a dummy function to semanalyze the
+ new alias node and replace CCGlobalScope by CCCodeGen.globalScope.
+
+ * cscc/vb/vb_grammar.y: Replace the CCGlobalScope by
CCCodeGen.globalScope,
+ remove the default import of the System namespace and adjust the alias
+ declaration.
+
+ * cscc/java/java_grammar.y, cscc/java/java_lookup.c,
+ cscc/java/java_semantics.tc: Replace the CCGlobalScope by
+ CCCodeGen.globalScope.
+
2007-05-17 Klaus Treichel <address@hidden>
* engine/lib_string.c: Check the new string builder capacity prior to
Index: codegen/cg_defs.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_defs.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- codegen/cg_defs.h 7 Nov 2003 01:23:55 -0000 1.3
+++ codegen/cg_defs.h 24 May 2007 13:51:14 -0000 1.4
@@ -36,6 +36,7 @@
typedef struct _tagILGenInfo ILGenInfo;
typedef struct _tagILScope ILScope;
+typedef struct _tagILScopeData ILScopeData;
typedef struct _tagILSwitchValue ILSwitchValue;
typedef unsigned long ILLabel;
#define ILLabel_Undefined ((ILLabel)0)
Index: codegen/cg_gen.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_gen.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -b -r1.49 -r1.50
--- codegen/cg_gen.c 16 Feb 2004 02:57:32 -0000 1.49
+++ codegen/cg_gen.c 24 May 2007 13:51:14 -0000 1.50
@@ -128,6 +128,7 @@
info->maxTempVars = 0;
info->tempLocalBase = 0;
info->currentScope = 0;
+ info->globalScope = 0;
info->javaInfo = 0;
info->unsafeLevel = 0;
info->contextStack = 0;
Index: codegen/cg_gen.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_gen.h,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -b -r1.47 -r1.48
--- codegen/cg_gen.h 5 May 2007 15:56:41 -0000 1.47
+++ codegen/cg_gen.h 24 May 2007 13:51:14 -0000 1.48
@@ -132,6 +132,7 @@
unsigned tempLocalBase; /* Base for temporary local
variables */
int createLocalsScope; /* Non-zero to
create scope for local variables */
ILScope *currentScope; /* Current scope for
declarations */
+ ILScope *globalScope; /* The global scope of
the image built. */
ILJavaGenInfo *javaInfo; /* Java-specific
information */
long unsafeLevel; /* Number of unsafe
contexts */
int *contextStack; /* Statement
context stack */
Index: codegen/cg_nodes.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_nodes.tc,v
retrieving revision 1.87
retrieving revision 1.88
diff -u -b -r1.87 -r1.88
--- codegen/cg_nodes.tc 5 May 2007 15:56:41 -0000 1.87
+++ codegen/cg_nodes.tc 24 May 2007 13:51:14 -0000 1.88
@@ -168,6 +168,11 @@
*/
%node ILNode_Dummy ILNode %abstract
%node ILNode_Expression ILNode %abstract
+%node ILNode_Alias ILNode_Dummy %abstract =
+{
+ const char *name;
+ %nocreate ILNode_Alias *next = {0};
+}
%node ILNode_Constant ILNode_Expression %abstract
%node ILNode_LValue ILNode_Expression %abstract
%node ILNode_LValueNoRef ILNode_LValue %abstract
Index: codegen/cg_scope.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_scope.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- codegen/cg_scope.c 21 Mar 2007 08:37:04 -0000 1.19
+++ codegen/cg_scope.c 24 May 2007 13:51:14 -0000 1.20
@@ -318,6 +318,54 @@
}
}
+ILScope *ILScopeImportNamespace(ILScope *scope, const char *namespace)
+{
+ if(scope && namespace)
+ {
+ ILImage *image = 0;
+ int namespaceLen = strlen(namespace);
+
+ if(namespaceLen == 0)
+ {
+ return 0;
+ }
+
+ while((image = ILContextNextImage(scope->info->context, image))
!= 0)
+ {
+ unsigned long numTokens;
+ unsigned long token;
+ ILClass *info;
+ const char *namespaceTest = 0;
+
+ numTokens = ILImageNumTokens(image,
IL_META_TOKEN_TYPE_DEF);
+ for(token = 1; token <= numTokens; ++token)
+ {
+ info = (ILClass *)(ILImageTokenInfo
+ (image, token |
IL_META_TOKEN_TYPE_DEF));
+
+ if(info && (namespaceTest !=
ILClass_Namespace(info)))
+ {
+ namespaceTest = ILClass_Namespace(info);
+ if(namespaceTest)
+ {
+ int testLen =
strlen(namespaceTest);
+
+ if(!strncmp(namespace,
namespaceTest, namespaceLen))
+ {
+ if((testLen ==
namespaceLen) ||
+ ((testLen >
namespaceLen) && (namespaceTest[namespaceLen] == '.')))
+ {
+ return
FindNamespaceScope(scope->info->globalScope, namespace);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return 0;
+}
+
void ILScopeImport(ILScope *scope, ILImage *image)
{
unsigned long numTokens;
@@ -480,9 +528,9 @@
return (ILScopeData *)(ILRBTreeNext(&(data->rbnode)));
}
-void ILScopeDeclareNamespace(ILScope *globalScope, const char *namespace)
+ILScope *ILScopeDeclareNamespace(ILScope *globalScope, const char *namespace)
{
- FindNamespaceScope(globalScope, namespace);
+ return FindNamespaceScope(globalScope, namespace);
}
ILScope *ILScopeFindNamespace(ILScope *globalScope, const char *namespace)
Index: codegen/cg_scope.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_scope.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- codegen/cg_scope.h 21 Mar 2007 08:37:04 -0000 1.15
+++ codegen/cg_scope.h 24 May 2007 13:51:14 -0000 1.16
@@ -26,11 +26,6 @@
#endif
/*
- * Opaque types used by the scope routines.
- */
-typedef struct _tagILScopeData ILScopeData;
-
-/*
* Kinds of items that may appear in a scope attached to a name.
*/
#define IL_SCOPE_SUBSCOPE 1 /* Named sub-scope */
@@ -112,9 +107,10 @@
ILNode *node, void *data1, void
*data2);
/*
- * Declare a namespace within a scope.
+ * Declare a namespace within a scope and return the scope associated with
+ * that namespace.
*/
-void ILScopeDeclareNamespace(ILScope *globalScope, const char *namespace);
+ILScope *ILScopeDeclareNamespace(ILScope *globalScope, const char *namespace);
/*
* Find the scope associated with a namespace.
@@ -122,6 +118,12 @@
ILScope *ILScopeFindNamespace(ILScope *globalScope, const char *namespace);
/*
+ * Find a namespace in the imported libraries and declare the namespace
+ * in the global scope if present.
+ */
+ILScope *ILScopeImportNamespace(ILScope *scope, const char *namespace);
+
+/*
* 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,
Index: cscc/csdoc.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csdoc.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- cscc/csdoc.c 5 May 2007 17:35:41 -0000 1.24
+++ cscc/csdoc.c 24 May 2007 13:51:14 -0000 1.25
@@ -91,7 +91,7 @@
{
/* Perform type gathering */
CCCodeGen.typeGather = 1;
- CCParseTree = CSTypeGather(&CCCodeGen, CCGlobalScope, CCParseTree);
+ CCParseTree = CSTypeGather(&CCCodeGen, CCCodeGen.globalScope,
CCParseTree);
CCCodeGen.typeGather = 0;
/* Perform semantic analysis */
Index: cscc/cs_main.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/cs_main.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- cscc/cs_main.c 19 Jul 2004 01:42:23 -0000 1.22
+++ cscc/cs_main.c 24 May 2007 13:51:14 -0000 1.23
@@ -110,7 +110,7 @@
{
/* Perform type gathering */
CCCodeGen.typeGather = 1;
- CCParseTree = CSTypeGather(&CCCodeGen, CCGlobalScope, CCParseTree);
+ CCParseTree = CSTypeGather(&CCCodeGen, CCCodeGen.globalScope,
CCParseTree);
CCCodeGen.typeGather = 0;
/* Perform semantic analysis */
Index: cscc/java_main.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/java_main.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- cscc/java_main.c 17 May 2003 07:04:35 -0000 1.1
+++ cscc/java_main.c 24 May 2007 13:51:15 -0000 1.2
@@ -67,7 +67,7 @@
{
/* Perform type gathering */
CCCodeGen.typeGather = 1;
- CCParseTree = JavaTypeGather(&CCCodeGen, CCGlobalScope, CCParseTree);
+ CCParseTree = JavaTypeGather(&CCCodeGen, CCCodeGen.globalScope,
CCParseTree);
CCCodeGen.typeGather = 0;
/* Perform semantic analysis */
Index: cscc/vb_main.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/vb_main.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- cscc/vb_main.c 16 May 2003 05:02:02 -0000 1.1
+++ cscc/vb_main.c 24 May 2007 13:51:15 -0000 1.2
@@ -69,7 +69,7 @@
{
/* Perform type gathering */
CCCodeGen.typeGather = 1;
- CCParseTree = CSTypeGather(&CCCodeGen, CCGlobalScope, CCParseTree);
+ CCParseTree = CSTypeGather(&CCCodeGen, CCCodeGen.globalScope,
CCParseTree);
CCCodeGen.typeGather = 0;
/* Perform semantic analysis */
Index: cscc/common/cc_main.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/common/cc_main.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- cscc/common/cc_main.h 7 Jul 2004 23:47:37 -0000 1.8
+++ cscc/common/cc_main.h 24 May 2007 13:51:15 -0000 1.9
@@ -130,11 +130,6 @@
extern ILNode *CCStandaloneAttrsEnd;
/*
- * Global definition scope.
- */
-extern ILScope *CCGlobalScope;
-
-/*
* Pre-processor stream.
*/
CCPreProc CCPreProcessorStream;
Index: cscc/common/cc_main.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/common/cc_main.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -b -r1.37 -r1.38
--- cscc/common/cc_main.c 5 May 2007 15:56:41 -0000 1.37
+++ cscc/common/cc_main.c 24 May 2007 13:51:15 -0000 1.38
@@ -67,7 +67,6 @@
ILNode *CCParseTreeEnd;
ILNode *CCStandaloneAttrs;
ILNode *CCStandaloneAttrsEnd;
-ILScope *CCGlobalScope;
/*
* Forward declarations.
Index: cscc/csharp/cs_defs.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_defs.tc,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- cscc/csharp/cs_defs.tc 5 May 2007 16:03:58 -0000 1.16
+++ cscc/csharp/cs_defs.tc 24 May 2007 13:51:15 -0000 1.17
@@ -180,13 +180,12 @@
const char *name;
ILNode_Namespace *enclosing;
%nocreate ILNode_UsingNamespace *using = {0};
+ %nocreate ILNode_Alias *alias = {0};
%nocreate ILScope *localScope={0};
}
-%node ILNode_UsingAlias ILNode_DummySem =
+%node ILNode_UsingAlias ILNode_Alias =
{
- const char *name;
- const char *ref;
- %nocreate ILVisitMode visited = {ILVisitMode_NotVisited};
+ ILNode *ref;
}
%node ILNode_UsingNamespace ILNode_DummySem =
{
@@ -217,3 +216,94 @@
%include "cs_oper.tc"
%include "cs_stmt.tc"
%include "cs_types.tc"
+
+/*
+ * Declare operations that manage namespaces.
+ */
+%decls %end %{
+
+/*
+ * Add an alias to a namespace body.
+ * If the namespace has no enclosing namespace then this is the
+ * global / compilation unit scope.
+ */
+void ILNamespaceAddAlias(ILNode_Namespace *namespace, ILNode_Alias *node);
+
+/*
+ * Resolve an alias in the namspace and the enclosing namespaces if up is != 0.
+ */
+ILNode *ILNamespaceResolveAlias(ILNode_Namespace *namespace, const char
*alias, int up);
+
+/*
+ * Add a using namespace declaration to the namespace.
+ */
+void ILNamespaceAddUsing(ILNode_Namespace *namespace,
+ ILNode_UsingNamespace *using);
+
+/*
+ * Get the last using-namespace declared in this namespace.
+ */
+ILNode_UsingNamespace *ILNamespaceGetUsing(ILNode_Namespace *namespace);
+
+%}
+
+/*
+ * Implement the namespace operations.
+ */
+%end %{
+
+void ILNamespaceAddAlias(ILNode_Namespace *namespace, ILNode_Alias *node)
+{
+ if(namespace && node)
+ {
+ node->next = namespace->alias;
+ namespace->alias = node;
+ }
+}
+
+ILNode *ILNamespaceResolveAlias(ILNode_Namespace *namespace, const char
*alias, int up)
+{
+ while(namespace)
+ {
+ ILNode_Alias *next = namespace->alias;
+
+ while(next)
+ {
+ if(next->name == alias)
+ {
+ return (ILNode *)next;
+ }
+ next = next->next;
+ }
+ if(up)
+ {
+ namespace = namespace->enclosing;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ return 0;
+}
+
+void ILNamespaceAddUsing(ILNode_Namespace *namespace,
+ ILNode_UsingNamespace *using)
+{
+ if(namespace && using)
+ {
+ using->next = namespace->using;
+ namespace->using = using;
+ }
+}
+
+ILNode_UsingNamespace *ILNamespaceGetUsing(ILNode_Namespace *namespace)
+{
+ if(namespace)
+ {
+ return namespace->using;
+ }
+ return 0;
+}
+
+%}
Index: cscc/csharp/cs_grammar.y
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_grammar.y,v
retrieving revision 1.78
retrieving revision 1.79
diff -u -b -r1.78 -r1.79
--- cscc/csharp/cs_grammar.y 5 May 2007 15:56:41 -0000 1.78
+++ cscc/csharp/cs_grammar.y 24 May 2007 13:51:15 -0000 1.79
@@ -65,55 +65,33 @@
static unsigned long NestingLevel = 0;
static ILIntString CurrNamespace = {"", 0};
static ILNode_Namespace *CurrNamespaceNode = 0;
-static ILScope* localScope = 0;
static int HaveDecls = 0;
/*
- * Initialize the global namespace, if necessary.
- */
-static void InitGlobalNamespace(void)
-{
- if(!CurrNamespaceNode)
- {
- ILNode_UsingNamespace *using;
- CurrNamespaceNode = (ILNode_Namespace
*)ILNode_Namespace_create(0, 0);
- using = (ILNode_UsingNamespace
*)ILNode_UsingNamespace_create("System");
- using->next = CurrNamespaceNode->using;
- CurrNamespaceNode->using = using;
- }
-}
-
-/*
* Get the global scope.
*/
static ILScope *GlobalScope(void)
{
- if(CCGlobalScope)
+ if(CCCodeGen.globalScope)
{
- return CCGlobalScope;
+ return CCCodeGen.globalScope;
}
else
{
- CCGlobalScope = ILScopeCreate(&CCCodeGen, 0);
- ILScopeDeclareNamespace(CCGlobalScope, "System");
- ILScopeUsing(CCGlobalScope, "System");
- return CCGlobalScope;
+ CCCodeGen.globalScope = ILScopeCreate(&CCCodeGen, 0);
+ return CCCodeGen.globalScope;
}
}
/*
- * Get the local scope
+ * Initialize the global namespace, if necessary.
*/
-static ILScope *LocalScope(void)
+static void InitGlobalNamespace(void)
{
- if(localScope)
- {
- return localScope;
- }
- else
+ if(!CurrNamespaceNode)
{
- localScope = ILScopeCreate(&CCCodeGen, CCGlobalScope);
- return localScope;
+ CurrNamespaceNode = (ILNode_Namespace
*)ILNode_Namespace_create(0, 0);
+ CurrNamespaceNode->localScope = GlobalScope();
}
}
@@ -126,28 +104,9 @@
CurrNamespace = ILInternString("", 0);
CurrNamespaceNode = 0;
HaveDecls = 0;
- localScope = 0;
ILScopeClearUsing(GlobalScope());
}
-/*
- * Determine if the current namespace already has a "using"
- * declaration for a particular namespace.
- */
-static int HaveUsingNamespace(const char *name)
-{
- ILNode_UsingNamespace *using = CurrNamespaceNode->using;
- while(using != 0)
- {
- if(!strcmp(using->name, name))
- {
- return 1;
- }
- using = using->next;
- }
- return 0;
-}
-
static void yyerror(char *msg)
{
CCPluginParseError(msg, cs_text);
@@ -1204,11 +1163,13 @@
NamespaceDeclaration
: OptAttributes NAMESPACE NamespaceIdentifier {
int posn, len;
- ILScope *oldLocalScope;
+
+ /* Initialize the global Namespace
(CompilationUnit) */
+ InitGlobalNamespace();
+
posn = 0;
if($1)
{
- InitGlobalNamespace();
CCPluginAddStandaloneAttrs
(ILNode_StandaloneAttr_create
((ILNode*)CurrNamespaceNode, $1));
@@ -1242,21 +1203,12 @@
CurrNamespace =
ILInternString($3.string + posn, len);
}
- /* Create the namespace node */
- InitGlobalNamespace();
-
- oldLocalScope=LocalScope();
-
+ /* Create a namespace node for the new
entered namespace. */
CurrNamespaceNode = (ILNode_Namespace *)
ILNode_Namespace_create(CurrNamespace.string,
CurrNamespaceNode);
- /* Preserve compilation unit specific
local scopes
- * or maybe I need to create a new
scope as child of
- * this scope (fix when I find a test
case) */
-
CurrNamespaceNode->localScope=oldLocalScope;
-
- /* Declare the namespace within the
global scope */
+ CurrNamespaceNode->localScope =
ILScopeDeclareNamespace(GlobalScope(),
CurrNamespace.string);
@@ -1307,39 +1259,28 @@
UsingDirective
: USING IDENTIFIER '=' QualifiedIdentifier ';' {
- ILScope *globalScope = GlobalScope();
- ILScope *scope = LocalScope();
+ const char *internedAliasName;
ILNode *alias;
- if(ILScopeLookup(globalScope, $2, 1))
+
+ InitGlobalNamespace();
+ internedAliasName = ILInternString($2,
strlen($2)).string;
+ alias =
ILNamespaceResolveAlias(CurrNamespaceNode, internedAliasName, 0);
+ if(alias)
{
- CCError("`%s' is already declared", $2);
+ CCError("the alias `%s' is already
declared", $2);
}
- else if(ILScopeLookup(localScope, $2, 1))
+ else
{
- CCError("`%s' is already declared", $2);
- }
- alias = ILNode_UsingAlias_create($2,
ILQualIdentName($4,0));
+ alias =
ILNode_UsingAlias_create(internedAliasName, $4);
/* NOTE: CSSemGuard is not needed as
ILNode_UsingAlias is
never Semanalyzed */
- InitGlobalNamespace();
- ILScopeDeclareAlias(scope, $2,alias,$4);
- CurrNamespaceNode->localScope=scope;
+ ILNamespaceAddAlias(CurrNamespaceNode,
(ILNode_Alias *)alias);
}
- | USING NamespaceIdentifier ';' {
- ILScope *globalScope = GlobalScope();
- ILNode_UsingNamespace *using;
- if(!ILScopeUsing(globalScope, $2.string))
- {
- CCError("`%s' is not a namespace",
$2.string);
}
+ | USING NamespaceIdentifier ';' {
InitGlobalNamespace();
- if(!HaveUsingNamespace($2.string))
- {
- using = (ILNode_UsingNamespace *)
-
ILNode_UsingNamespace_create($2.string);
- using->next = CurrNamespaceNode->using;
- CurrNamespaceNode->using = using;
- }
+ ILNamespaceAddUsing(CurrNamespaceNode,
+ (ILNode_UsingNamespace
*)ILNode_UsingNamespace_create($2.string));
}
;
Index: cscc/csharp/cs_lookup.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_lookup.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -b -r1.31 -r1.32
--- cscc/csharp/cs_lookup.c 5 May 2007 15:56:41 -0000 1.31
+++ cscc/csharp/cs_lookup.c 24 May 2007 13:51:15 -0000 1.32
@@ -920,7 +920,7 @@
}
/* Look in the global scope for a declared type */
- data = ILScopeLookupInNamespace(CCGlobalScope, namespace, name);
+ data = ILScopeLookupInNamespace(genInfo->globalScope, namespace, name);
if(data)
{
scopeKind = ILScopeDataGetKind(data);
@@ -1184,6 +1184,7 @@
CSSemValue value;
ILMethod *caller;
int switchToStatics;
+ ILNode *aliasNode;
/* If we are within type gathering, then search the nesting
parents for a nested type that matches our requirements */
@@ -1300,10 +1301,54 @@
accessedFrom, &results);
if(result != CS_SEMKIND_VOID)
{
+ /* We have to check if an alias with the same name is
declared here too. */
+ aliasNode = ILNamespaceResolveAlias(namespace, name, 0);
+
+ if(aliasNode)
+ {
+ CCErrorOnLine(yygetfilename(node),
yygetlinenum(node),
+ "`%s' is defined
ambiguously because an alias exists with the same name", name);
+ }
break;
}
- /* Find the types in all using namespaces */
+ if(!(genInfo->resolvingAlias))
+ {
+ /* Check the aliases here. */
+ aliasNode = ILNamespaceResolveAlias(namespace, name, 0);
+ if(aliasNode)
+ {
+ if(yykind(aliasNode) ==
yykindof(ILNode_UsingAlias))
+ {
+ ILNode *alias = ((ILNode_UsingAlias
*)aliasNode)->ref;
+ int savedState = genInfo->inSemType;
+
+ genInfo->resolvingAlias = 1;
+ genInfo->inSemType = 1;
+ value = ILNode_SemAnalysis(alias,
genInfo, &aliasNode);
+ genInfo->inSemType = savedState;
+ genInfo->resolvingAlias = 0;
+
+ /* Now check if the alias resolves to a
type or namespace. */
+ if((CSSemGetKind(value) ==
CS_SEMKIND_TYPE) ||
+ (CSSemGetKind(value) ==
CS_SEMKIND_NAMESPACE))
+ {
+ return value;
+ }
+ else
+ {
+ if(reportErrors)
+ {
+
CCErrorOnLine(yygetfilename(alias), yygetlinenum(alias),
+ "the alias `%s'
does not refere to a type or namespace.",
+
ILQualIdentName(alias, 0));
+ }
+ return CSSemValueDefault;
+ }
+ }
+ }
+ }
+
using = namespace->using;
while(using != 0)
{
@@ -1316,6 +1361,16 @@
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)
{
@@ -1391,12 +1446,11 @@
/* See if the namespace is valid, according to the loaded libraries */
if(result == CS_SEMKIND_VOID)
{
- nspace = ILInternAppendedString
+ nspace = ILInternStringConcat3
(ILInternString(CSSemGetNamespace(value), -1),
- ILInternString(".", 1));
- nspace = ILInternAppendedString
- (nspace, ILInternString((char *)name, -1));
- if(ILClassNamespaceIsValid(genInfo->context, nspace.string))
+ ILInternString(".", 1),
+ ILInternString((char *)name, -1));
+ if(ILScopeImportNamespace(genInfo->globalScope, nspace.string))
{
CSSemSetNamespace(value, nspace.string);
return value;
Index: cscc/csharp/cs_lvalue.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_lvalue.tc,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -b -r1.60 -r1.61
--- cscc/csharp/cs_lvalue.tc 5 May 2007 15:56:41 -0000 1.60
+++ cscc/csharp/cs_lvalue.tc 24 May 2007 13:51:15 -0000 1.61
@@ -877,7 +877,6 @@
ILNode_MethodDeclaration *method;
ILParameterModifier paramMod;
ILNode_SemGuard *constVar;
- ILNode_UsingAlias *alias;
ILType *type;
ILEvalValue evalValue;
@@ -972,8 +971,9 @@
return value;
}
- /* Resolve the simple name quietly so that we can check for aliases
- if & only if this fails */
+ /* Resolve the simple name now. */
+ /* This two step stuff is pretty ugly but the static filtering is only
*/
+ /* done in the quiet mode. */
value = CSResolveSimpleNameQuiet(info, (ILNode *)node, node->name, 0);
if (CSSemGetKind(value) != CS_SEMKIND_VOID)
@@ -983,31 +983,6 @@
value, node->name, 0,
0);
}
- if(data && ILScopeDataGetKind(data) == IL_SCOPE_ALIAS)
- {
- alias=(ILNode_UsingAlias*)ILScopeDataGetNode(data);
- if(alias->visited==ILVisitMode_Processing)
- {
- CCErrorOnLine(yygetfilename(alias), yygetlinenum(alias),
- "circularity detected in `using' declaration");
- CSSemSetLValue(value, ILType_Int32);
- return value;
- }
- alias->visited=ILVisitMode_Processing;
- *parent = (ILNode*)ILScopeDataGetData1(data);
- if(info->resolvingAlias)
- {
- CCErrorOnLine(yygetfilename(alias), yygetlinenum(alias),
- "using aliases may not refer
to other aliases");
- }
- info->resolvingAlias = 1;
- value = ILNode_SemAnalysis(*parent,info,parent);
- info->resolvingAlias = 0;
- alias->visited=ILVisitMode_Done;
- return value;
- }
-
- /* This time around dump the errors */
value = CSResolveSimpleName(info, (ILNode *)node, node->name, 0);
/* Convert the result into an l-value or r-value and return it */
@@ -1021,8 +996,6 @@
ILNode_SemAnalysisType(ILNode_Identifier)
{
CSSemValue value;
- ILNode_UsingAlias *alias;
- ILScopeData *data;
int savedState=info->inSemType;
info->inSemType=1;
@@ -1037,36 +1010,6 @@
value, node->name, 0,
0);
}
- data =
ILScopeLookup(((ILNode_Namespace*)info->currentNamespace)->localScope,
node->name, 1);
-
- if(data && ILScopeDataGetKind(data) == IL_SCOPE_ALIAS &&
- !(info->resolvingAlias))
- {
- alias=(ILNode_UsingAlias*)ILScopeDataGetNode(data);
- if(alias->visited==ILVisitMode_Processing)
- {
- CCErrorOnLine(yygetfilename(alias), yygetlinenum(alias),
- "circularity detected in `using' declaration");
- CSSemSetLValue(value, ILType_Int32);
- return value;
- }
- alias->visited=ILVisitMode_Processing;
- *parent = (ILNode*)ILScopeDataGetData1(data);
- if(info->resolvingAlias)
- {
- CCErrorOnLine(yygetfilename(alias), yygetlinenum(alias),
- "using aliases may not refer
to other aliases");
- }
- info->resolvingAlias = 1;
- savedState=info->inSemType;
- info->inSemType=1;
- value = ILNode_SemAnalysis(*parent,info,parent);
- info->inSemType=savedState;
- info->resolvingAlias = 0;
- alias->visited=ILVisitMode_Done;
- return value;
- }
-
return CSSemValueDefault;
}
@@ -1077,9 +1020,8 @@
ILNode_SemAnalysisType(ILNode_AttrIdentifier)
{
CSSemValue value;
- ILNode_UsingAlias *alias;
- ILScopeData *data;
int savedState=info->inSemType;
+ int savedAliasState;
const char *name;
/* Resolve the simple name */
@@ -1097,50 +1039,26 @@
}
/* Try again, this time with "Attribute" appended */
+ /* but don't allow alias resolution in this case. */
name = ILInternAppendedString
(ILInternString(node->name, strlen(node->name)),
ILInternString("Attribute", 9)).string;
info->inSemType=1;
+ savedAliasState = info->resolvingAlias;
+ info->resolvingAlias = 1;
value = CSResolveSimpleNameQuiet(info, (ILNode *)node, name, 1);
+ info->resolvingAlias = savedAliasState;
info->inSemType=savedState;
- if (CSSemGetKind(value) == CS_SEMKIND_TYPE)
+ if (CSSemGetKind(value) == CS_SEMKIND_TYPE &&
+ ILTypeAssignCompatible(info->image, CSSemGetType(value),
+ ILFindSystemType(info,
"Attribute")))
{
/* Convert the result into an l-value or r-value and return it
*/
return SemToLRValue((ILNode *)node, info, parent,
value, node->name, 0,
0);
}
- data = ILScopeLookup(info->currentScope, node->name, 1);
-
- if(data && ILScopeDataGetKind(data) == IL_SCOPE_ALIAS &&
- !(info->resolvingAlias))
- {
- alias=(ILNode_UsingAlias*)ILScopeDataGetNode(data);
- if(alias->visited==ILVisitMode_Processing)
- {
- CCErrorOnLine(yygetfilename(alias), yygetlinenum(alias),
- "circularity detected in `using' declaration");
- CSSemSetLValue(value, ILType_Int32);
- return value;
- }
- alias->visited=ILVisitMode_Processing;
- *parent = (ILNode*)ILScopeDataGetData1(data);
- if(info->resolvingAlias)
- {
- CCErrorOnLine(yygetfilename(alias), yygetlinenum(alias),
- "using aliases may not refer
to other aliases");
- }
- info->resolvingAlias = 1;
- savedState=info->inSemType;
- info->inSemType=1;
- value = ILNode_SemAnalysis(*parent,info,parent);
- info->inSemType=savedState;
- info->resolvingAlias = 0;
- alias->visited=ILVisitMode_Done;
- return value;
- }
-
return CSSemValueDefault;
}
Index: cscc/csharp/cs_semantics.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_semantics.tc,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- cscc/csharp/cs_semantics.tc 19 Apr 2004 13:00:33 -0000 1.13
+++ cscc/csharp/cs_semantics.tc 24 May 2007 13:51:15 -0000 1.14
@@ -52,6 +52,11 @@
return ILNode_SemAnalysis(node, info, parent);
}
+ILNode_SemAnalysis(ILNode_Alias)
+{
+ return CSSemValueDefault;
+}
+
%decls %end %{
/*
@@ -245,7 +250,7 @@
{
ILGenItemContext context;
ILNode *node;
- node = ILEnterProgramItemContext(info, item, CCGlobalScope, &context);
+ node = ILEnterProgramItemContext(info, item, info->globalScope,
&context);
if(node)
{
ILNode_SemAnalysis(node, info, &node);
Index: cscc/vb/vb_grammar.y
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/vb/vb_grammar.y,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- cscc/vb/vb_grammar.y 5 May 2007 15:56:42 -0000 1.4
+++ cscc/vb/vb_grammar.y 24 May 2007 13:51:15 -0000 1.5
@@ -69,16 +69,14 @@
*/
static ILScope *GlobalScope(void)
{
- if(CCGlobalScope)
+ if(CCCodeGen.globalScope)
{
- return CCGlobalScope;
+ return CCCodeGen.globalScope;
}
else
{
- CCGlobalScope = ILScopeCreate(&CCCodeGen, 0);
- ILScopeDeclareNamespace(CCGlobalScope, "System");
- ILScopeUsing(CCGlobalScope, "System");
- return CCGlobalScope;
+ CCCodeGen.globalScope = ILScopeCreate(&CCCodeGen, 0);
+ return CCCodeGen.globalScope;
}
}
@@ -93,7 +91,7 @@
}
else
{
- localScope = ILScopeCreate(&CCCodeGen, CCGlobalScope);
+ localScope = ILScopeCreate(&CCCodeGen, GlobalScope());
return localScope;
}
}
@@ -106,14 +104,13 @@
{
if(!CurrNamespaceNode)
{
- ILNode_UsingNamespace *using;
char *root;
/* Create the global namespace node */
CurrNamespaceNode = (ILNode_Namespace
*)ILNode_Namespace_create(0, 0);
- using = (ILNode_UsingNamespace
*)ILNode_UsingNamespace_create("System");
- using->next = CurrNamespaceNode->using;
- CurrNamespaceNode->using = using;
+ CurrNamespaceNode->localScope = GlobalScope();
+ ILNamespaceAddUsing(CurrNamespaceNode,
+ (ILNode_UsingNamespace
*)ILNode_UsingNamespace_create("System"));
GlobalNamespaceNode = CurrNamespaceNode;
/* Set the default options on the global namespace */
@@ -807,22 +804,20 @@
}
}
| Identifier '=' QualifiedIdentifier {
- ILScope *globalScope = GlobalScope();
- ILScope *scope = LocalScope();
ILNode *alias;
- const char *name = ILQualIdentName($1, 0);
- if(ILScopeLookup(globalScope, name, 1))
+ const char *name;
+
+ InitGlobalNamespace();
+ name = ILInternString(ILQualIdentName($1, 0),
-1).string;
+ if((alias =
ILNamespaceResolveAlias(CurrNamespaceNode, name, 0)))
{
- CCError("`%s' is already declared",
name);
+ CCError("the alias `%s' is already
declared", name);
}
- else if(ILScopeLookup(localScope, name, 1))
+ else
{
- CCError("`%s' is already declared",
name);
+ alias = ILNode_UsingAlias_create(name,
$3);
+ ILNamespaceAddAlias(CurrNamespaceNode,
(ILNode_Alias *)alias);
}
- alias = ILNode_UsingAlias_create(name,
ILQualIdentName($3, 0));
- InitGlobalNamespace();
- ILScopeDeclareAlias(scope, name, alias, $3);
- CurrNamespaceNode->localScope = scope;
}
;
Index: cscc/java/java_grammar.y
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/java/java_grammar.y,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- cscc/java/java_grammar.y 5 May 2007 15:56:42 -0000 1.5
+++ cscc/java/java_grammar.y 24 May 2007 13:51:15 -0000 1.6
@@ -197,16 +197,16 @@
*/
static ILScope *GlobalScope(void)
{
- if(CCGlobalScope)
+ if(CCCodeGen.globalScope)
{
- return CCGlobalScope;
+ return CCCodeGen.globalScope;
}
else
{
- CCGlobalScope = ILScopeCreate(&CCCodeGen, 0);
- ILScopeDeclareNamespace(CCGlobalScope, "java.lang");
- ILScopeUsing(CCGlobalScope, "java.lang");
- return CCGlobalScope;
+ CCCodeGen.globalScope = ILScopeCreate(&CCCodeGen, 0);
+ ILScopeDeclareNamespace(CCCodeGen.globalScope, "java.lang");
+ ILScopeUsing(CCCodeGen.globalScope, "java.lang");
+ return CCCodeGen.globalScope;
}
}
Index: cscc/java/java_lookup.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/java/java_lookup.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- cscc/java/java_lookup.c 5 May 2007 15:56:42 -0000 1.2
+++ cscc/java/java_lookup.c 24 May 2007 13:51:16 -0000 1.3
@@ -621,7 +621,7 @@
}
/* Look in the global scope for a declared type */
- data = ILScopeLookupInNamespace(CCGlobalScope, namespace, name);
+ data = ILScopeLookupInNamespace(CCCodeGen.globalScope, namespace, name);
if(data)
{
scopeKind = ILScopeDataGetKind(data);
Index: cscc/java/java_semantics.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/java/java_semantics.tc,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- cscc/java/java_semantics.tc 21 May 2003 10:40:19 -0000 1.2
+++ cscc/java/java_semantics.tc 24 May 2007 13:51:16 -0000 1.3
@@ -222,7 +222,7 @@
{
ILGenItemContext context;
ILNode *node;
- node = ILEnterProgramItemContext(info, item, CCGlobalScope, &context);
+ node = ILEnterProgramItemContext(info, item, CCCodeGen.globalScope,
&context);
if(node)
{
ILNode_JSemAnalysis(node, info, &node);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [dotgnu-pnet-commits] pnet ChangeLog codegen/cg_defs.h codegen/cg_gen...,
Klaus Treichel <=