[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[dotgnu-pnet-commits] pnet ChangeLog codegen/cg_gen.c codegen/cg_gen....
From: |
Klaus Treichel |
Subject: |
[dotgnu-pnet-commits] pnet ChangeLog codegen/cg_gen.c codegen/cg_gen.... |
Date: |
Tue, 30 Oct 2007 17:35:24 +0000 |
CVSROOT: /cvsroot/dotgnu-pnet
Module name: pnet
Changes by: Klaus Treichel <ktreichel> 07/10/30 17:35:24
Modified files:
. : ChangeLog
codegen : cg_gen.c cg_gen.h
cscc/csharp : cs_decls.tc cs_gather.c cs_lookup.c
cs_lvalue.tc cs_semantics.tc cs_types.tc
image : class.c meta_types.c program.h
include : il_program.h il_types.h
Log message:
Add some work for generics and fix a bug in member access processing.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pnet/ChangeLog?cvsroot=dotgnu-pnet&r1=1.3512&r2=1.3513
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_gen.c?cvsroot=dotgnu-pnet&r1=1.51&r2=1.52
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_gen.h?cvsroot=dotgnu-pnet&r1=1.49&r2=1.50
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/csharp/cs_decls.tc?cvsroot=dotgnu-pnet&r1=1.43&r2=1.44
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/csharp/cs_gather.c?cvsroot=dotgnu-pnet&r1=1.57&r2=1.58
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/csharp/cs_lookup.c?cvsroot=dotgnu-pnet&r1=1.38&r2=1.39
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/csharp/cs_lvalue.tc?cvsroot=dotgnu-pnet&r1=1.64&r2=1.65
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/csharp/cs_semantics.tc?cvsroot=dotgnu-pnet&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/csharp/cs_types.tc?cvsroot=dotgnu-pnet&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/pnet/image/class.c?cvsroot=dotgnu-pnet&r1=1.40&r2=1.41
http://cvs.savannah.gnu.org/viewcvs/pnet/image/meta_types.c?cvsroot=dotgnu-pnet&r1=1.20&r2=1.21
http://cvs.savannah.gnu.org/viewcvs/pnet/image/program.h?cvsroot=dotgnu-pnet&r1=1.27&r2=1.28
http://cvs.savannah.gnu.org/viewcvs/pnet/include/il_program.h?cvsroot=dotgnu-pnet&r1=1.60&r2=1.61
http://cvs.savannah.gnu.org/viewcvs/pnet/include/il_types.h?cvsroot=dotgnu-pnet&r1=1.28&r2=1.29
Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/ChangeLog,v
retrieving revision 1.3512
retrieving revision 1.3513
diff -u -b -r1.3512 -r1.3513
--- ChangeLog 23 Oct 2007 18:32:20 -0000 1.3512
+++ ChangeLog 30 Oct 2007 17:35:22 -0000 1.3513
@@ -1,3 +1,62 @@
+2007-10-30 Klaus Treichel <address@hidden>
+
+ * codegen/cg_gen.c: Add handling of with types in ILTypeToClass.
+ Initialize the new member accessCheck with ILClassAccessible.
+
+ * codegen/cg_gen.h: Add the member accessCheck to the geninfo struct
+ to hold the function to use for checking if a class is accessible /
+ can be inherited by an other class.
+
+ * cscc/csharp/cs_decls.tc: Remove the accesses to the currentTypeFormals
+ because they are not needed anymore.
+
+ * cscc/csharp/cs_gather.c: Split the type creation into two parts
+ (Step 1: creation of the ILClass records and Step 2: setting the parent
+ class and adding the implemented interfaces) to allow nested types to be
+ used in generic types.
+ Check the if the underlying base class is an interface instead of the
+ base class which might be a TypeSpec.
+ Remove the accesses to the currentTypeFormals member of the geninfo
+ structure.
+
+ * cscc/csharp/cs_lookup.c: Use the new geninfo member accessCheck to
check
+ if a class is accessible in the current scope.
+
+ * cscc/csharp/cs_lvalue.tc: Remove the scortcut with resolving the
member
+ with namespace and name directly in
+ ILNode_SemanalysisType(ILNode_MemberAccess) because that leads to wrong
+ resolved classes if the an other class could be resolved by the normal
+ member access processing.
+
+ * cscc/csharp/cs_semantics.tc, cscc/csharp/cs_types.tc: Move the
function
+ SemWithType from cs_types.tc to CSSemWithType in cs_semanalysis.tc and
+ change the existing calls to that function accordingly.
+
+ * cscc/csharp/cs_semantics.tc: Change the accessCheck to
+ ILClassInheritable in CSSemBaseType before semanalyzing the type and
+ restore the value afterwards.
+
+ * image/class.c: Initialize the new ILClass member numGenericPars to -1
+ in ILClassCreate and 0 in ILClassCreateWrapper.
+ Add the function ILClassInheritable to check if a class might be used as
+ parent or an implemented interface. This is different from
+ ILClassAccessible because the family (protected) case can not be checked
+ in this case and should be handled like the public case.
+ Add the function ILClassGetNumGerericPars and ILClassSetNumGenericPars
+ to cache a previous value in the ILClass struct.
+
+ * image/meta_types.c: Add the function ILTypeSetWithMain.
+
+ * image/program.h: Add the member numGenericPars to the ILClass struct
+ for caching metadata lookups because the value will be used very often
+ with generics.
+
+ * include/il_program.h: Add the declarations for the new functions
+ ILClassInheritable, ILClassGetNumGenericPars and
ILClassSetNumGenericPars.
+
+ * include/il_types.h: Add the element type ILType_String.
+ Add the declaration of the new function ILTypeSetWithMain.
+
2007-10-23 Klaus Treichel <address@hidden>
* cscc/csharp/cs_defs.c: Replace the type node with a left and an
Index: codegen/cg_gen.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_gen.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -b -r1.51 -r1.52
--- codegen/cg_gen.c 1 Jun 2007 11:08:50 -0000 1.51
+++ codegen/cg_gen.c 30 Oct 2007 17:35:23 -0000 1.52
@@ -140,9 +140,12 @@
info->currentNamespace = 0;
info->arrayInit = 0;
info->itemHash = 0;
+#if IL_VERSION_MAJOR > 1
info->currentTypeFormals = 0;
info->currentMethodFormals = 0;
+#endif /* IL_VERSION_MAJOR > 1 */
info->gotoPtrLabel = ILLabel_Undefined;
+ info->accessCheck = ILClassAccessible;
if(useBuiltinLibrary)
{
ILGenMakeLibrary(info);
@@ -293,7 +296,29 @@
ILClass *ILTypeToClass(ILGenInfo *info, ILType *type)
{
+#if IL_VERSION_MAJOR > 1
+ if(ILType_IsWith(type))
+ {
+ ILClass *classInfo;
+ ILTypeSpec *typeSpec;
+
+ typeSpec = ILTypeSpecCreate(info->image, 0, type);
+ if(!typeSpec)
+ {
+ ILGenOutOfMemory(info);
+ }
+ classInfo = ILTypeSpecGetClassWrapper(typeSpec);
+ if(!classInfo)
+ {
+ ILGenOutOfMemory(info);
+ }
+ return classInfo;
+ }
+ else
+#endif /* IL_VERSION_MAJOR > 1 */
+ {
return ILClassFromType(info->image, info, type, TypeResolver);
+ }
}
ILMachineType ILTypeToMachineType(ILType *type)
Index: codegen/cg_gen.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_gen.h,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -b -r1.49 -r1.50
--- codegen/cg_gen.h 20 Sep 2007 20:04:15 -0000 1.49
+++ codegen/cg_gen.h 30 Oct 2007 17:35:23 -0000 1.50
@@ -86,6 +86,11 @@
typedef struct _tagILJavaGenInfo ILJavaGenInfo;
/*
+ * Access/Inheritance check function.
+ */
+typedef int (*ILClassAccessCheck)(ILClass *info, ILClass *scope);
+
+/*
* Structure of the code generation context.
*/
struct _tagILGenInfo
@@ -153,7 +158,7 @@
ILNode *currentMethodFormals; /* Current generic method
formals */
#endif /* IL_VERSION_MAJOR > 1 */
ILLabel gotoPtrLabel; /* Label for "goto *"
operations */
-
+ ILClassAccessCheck accessCheck; /* Function for checking access
permissions. */
};
/*
Index: cscc/csharp/cs_decls.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_decls.tc,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -b -r1.43 -r1.44
--- cscc/csharp/cs_decls.tc 20 Sep 2007 20:04:16 -0000 1.43
+++ cscc/csharp/cs_decls.tc 30 Oct 2007 17:35:23 -0000 1.44
@@ -114,9 +114,6 @@
ILNode *savedNamespace;
ILNode *savedMethod;
ILNode *staticCtorList=NULL;
-#if IL_VERSION_MAJOR > 1
- ILNode *savedTypeFormals;
-#endif /* IL_VERSION_MAJOR > 1 */
ILNode_ListIter iter;
ILNode *staticCtor;
int hadStaticCtorsBefore;
@@ -186,15 +183,9 @@
savedClass = info->currentClass;
savedNamespace = info->currentNamespace;
savedMethod = info->currentMethod;
- #if IL_VERSION_MAJOR > 1
- savedTypeFormals = info->currentTypeFormals;
- #endif /* IL_VERSION_MAJOR > 1 */
info->currentClass = (ILNode *)node;
info->currentNamespace = node->namespaceNode;
info->currentMethod = NULL;
- #if IL_VERSION_MAJOR > 1
- info->currentTypeFormals = node->typeFormals;
- #endif /* IL_VERSION_MAJOR > 1 */
value = ILNode_SemAnalysis(node->body, info, &(node->body));
if(node->initCtorsMethod)
{
@@ -281,9 +272,6 @@
info->currentClass = savedClass;
info->currentNamespace = savedNamespace;
info->currentMethod = savedMethod;
- #if IL_VERSION_MAJOR > 1
- info->currentTypeFormals = savedTypeFormals;
- #endif /* IL_VERSION_MAJOR > 1 */
}
else
{
Index: cscc/csharp/cs_gather.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_gather.c,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -b -r1.57 -r1.58
--- cscc/csharp/cs_gather.c 23 Oct 2007 18:32:20 -0000 1.57
+++ cscc/csharp/cs_gather.c 30 Oct 2007 17:35:23 -0000 1.58
@@ -335,10 +335,247 @@
/* Restore the previous values. */
info->currentClass = savedClass;
info->currentNamespace = savedNamespace;
+
+ /* process the nested classes */
+ if(defn->nestedClasses)
+ {
+ ILNode *child;
+ ILNode_ListIter iter;
+
+ ILNode_ListIter_Init(&iter, defn->nestedClasses);
+ while((child = ILNode_ListIter_Next(&iter)) != 0)
+ {
+ AddGenericParametersToClass(info, child);
+ }
+ }
}
}
#endif /* IL_VERSION_MAJOR > 1 */
+static void AddBaseClasses(ILGenInfo *info,
+ ILNode_ClassDefn *classNode,
+ ILNode *systemObjectName)
+{
+ ILNode *savedNamespace;
+ ILNode *savedClass;
+ ILClass *classInfo = classNode->classInfo;
+
+ /* Set the namespace and class to use for resolving type names */
+ savedNamespace = info->currentNamespace;
+ info->currentNamespace = classNode->namespaceNode;
+ savedClass = info->currentClass;
+ info->currentClass = (ILNode *)classNode;
+
+ if(classInfo && (classInfo != (ILClass *)1) &&
+ (classInfo != (ILClass *)2))
+ {
+ ILClass *parent = 0;
+ int numBases = CountBaseClasses(classNode->baseClass);
+
+ if(numBases > 0)
+ {
+ int base;
+ ILNode *baseNode;
+ ILNode *baseNodeList;
+ int errorReported = 0;
+ ILClass *baseList[numBases];
+
+ ILMemZero(baseList, numBases * sizeof(ILClass *));
+
+ baseNodeList = classNode->baseClass;
+ for(base = 0; base < numBases; ++base)
+ {
+ ILNode *baseTypeNode;
+
+ /* Get the name of the class to be inherited or
implemented */
+ if(yykind(baseNodeList) ==
yykindof(ILNode_ArgList))
+ {
+ baseNode = ((ILNode_ArgList
*)baseNodeList)->expr2;
+ baseNodeList = ((ILNode_ArgList
*)baseNodeList)->expr1;
+ }
+ else
+ {
+ baseNode = baseNodeList;
+ }
+
+ /* Look in the scope for the base class */
+ if(CSSemBaseType(baseNode, info, &baseNode,
+ &baseTypeNode,
&(baseList[base])))
+ {
+ /* All class nodes should have a valid
classinfo at
+ this point. */
+ if(baseList[base] == 0)
+ {
+ baseList[base] =
NodeToClass(baseTypeNode);
+
+ if(baseList[base] == 0)
+ {
+ /* This is not a valid
base class specification */
+
CCErrorOnLine(yygetfilename(baseNode), yygetlinenum(baseNode),
+
"invalid base type");
+ }
+ }
+
+ if(baseList[base])
+ {
+ #if IL_VERSION_MAJOR > 1
+ ILClass *underlying =
ILClassGetUnderlying(baseList[base]);
+
+ if(!underlying)
+ {
+ CCOutOfMemory();
+ }
+
if(!ILClass_IsInterface(underlying))
+ #else /* IL_VERSION_MAJOR == 1 */
+
if(!ILClass_IsInterface(baseList[base]))
+ #endif /* IL_VERSION_MAJOR == 1 */
+ {
+ if(parent)
+ {
+
if(!errorReported)
+ {
+
CCErrorOnLine(yygetfilename(classNode),
+
yygetlinenum(classNode),
+
"class inherits from two or more non-interface classes");
+
errorReported = 1;
+ }
+ }
+ else
+ {
+ parent =
baseList[base];
+ }
+ baseList[base] = 0;
+ }
+ }
+ }
+ else
+ {
+ /* This is not a valid base class
specification */
+ CCErrorOnLine(yygetfilename(baseNode),
yygetlinenum(baseNode),
+ "invalid base
type");
+ }
+ }
+
+ /* Test for interfaces, or find "System.Object" if no
parent yet */
+ if(ILClass_IsInterface(classInfo))
+ {
+ if(parent)
+ {
+ CCErrorOnLine(yygetfilename(classNode),
yygetlinenum(classNode),
+ "interface
inherits from non-interface class");
+ parent = 0;
+ }
+ }
+ else if(!parent)
+ {
+ /* Use the builtin library's "System.Object" */
+ parent = ILType_ToClass(ILFindSystemType(info,
"Object"));
+ if(!parent)
+ {
+ ILNode *baseTypeNode;
+
+ /* Compiling something else that
inherits "System.Object" */
+ if(CSSemBaseType(systemObjectName,
info, &systemObjectName,
+
&baseTypeNode, &parent))
+ {
+ if(!parent)
+ {
+ parent =
NodeToClass(baseTypeNode);
+ }
+ }
+ }
+ if(!parent)
+ {
+ CCErrorOnLine(yygetfilename(classNode),
yygetlinenum(classNode),
+ "could not
resolve System.Object");
+ }
+ else
+ {
+ if(ILClassResolve(parent) ==
ILClassResolve(classInfo))
+ {
+ /* Compiling System.Object so
don't set the parent. */
+ parent = 0;
+ }
+ }
+ }
+ else
+ {
+ /* Output an error if attempting to inherit
from a sealed class */
+ ILClass *underlying =
ILClassGetUnderlying(parent);
+ if(!underlying)
+ {
+ CCOutOfMemory();
+ }
+ if(underlying && ILClass_IsSealed(underlying))
+ {
+ CCErrorOnLine(yygetfilename(classNode),
yygetlinenum(classNode),
+ "inheriting
from a sealed parent class");
+ }
+ }
+
+ /* Set the calass parent */
+ if(strcmp(ILClass_Name(classInfo), "<Module>") != 0)
+ {
+ if(parent && !ILClass_IsInterface(classInfo))
+ {
+ ILClassSetParent(classInfo, parent);
+ }
+ }
+
+ /* Add the interfaces to the class */
+ for(base = 0; base < numBases; ++base)
+ {
+ if(baseList[base])
+ {
+ if(!ILClassAddImplements(classInfo,
baseList[base], 0))
+ {
+ CCOutOfMemory();
+ }
+ }
+ }
+ }
+ else if(!ILClass_IsInterface(classInfo))
+ {
+ ILClass *parent;
+
+ /* Use the builtin library's "System.Object" as parent
class */
+ parent = ILType_ToClass(ILFindSystemType(info,
"Object"));
+
+ if(ILClassResolve(classInfo) != ILClassResolve(parent))
+ {
+ ILClassSetParent(classInfo, parent);
+ }
+ }
+ }
+ else
+ {
+ CCErrorOnLine(yygetfilename(classNode), yygetlinenum(classNode),
+ "class not completely layed out");
+ }
+
+ /* Restore the namespace, class, and type formals */
+ info->currentNamespace = savedNamespace;
+ info->currentClass = savedClass;
+
+ /* Now process the nested classes */
+ if(classNode->nestedClasses)
+ {
+ ILNode *child;
+ ILNode_ListIter iter;
+
+ ILNode_ListIter_Init(&iter, classNode->nestedClasses);
+ while((child = ILNode_ListIter_Next(&iter)) != 0)
+ {
+ if(yykind(child) == yykindof(ILNode_ClassDefn))
+ {
+ AddBaseClasses(info,
+
(ILNode_ClassDefn*)child,
+ systemObjectName);
+ }
+ }
+ }
+}
+
/*
* Create the program structure for a type and all of its base types.
* Returns the new end of the top-level type list.
@@ -349,25 +586,17 @@
{
const char *name;
const char *namespace;
- int numBases;
- ILClass **baseList;
- int base;
ILNode *baseNodeList;
ILNode *baseNode;
ILNode *baseTypeNode;
ILClass *parent;
ILClass *classInfo;
- int errorReported;
ILNode_ClassDefn *defn;
ILNode *savedNamespace;
ILNode *savedClass;
-#if IL_VERSION_MAJOR > 1
- ILNode *savedTypeFormals;
-#endif /* IL_VERSION_MAJOR > 1 */
ILProgramItem *nestedScope;
ILNode *node;
ILNode_ListIter iter;
- ILClass *underlying;
/* Get the name and namespace for the type, for error reporting */
defn = (ILNode_ClassDefn *)type;
@@ -425,28 +654,13 @@
info->currentNamespace = defn->namespaceNode;
savedClass = info->currentClass;
info->currentClass = (ILNode *)defn;
-#if IL_VERSION_MAJOR > 1
- savedTypeFormals = info->currentTypeFormals;
- info->currentTypeFormals = defn->typeFormals;
-#endif /* IL_VERSION_MAJOR > 1 */
- /* Create all of the base classes */
- numBases = CountBaseClasses(defn->baseClass);
- if(numBases > 0)
- {
- baseList = (ILClass **)ILCalloc(numBases, sizeof(ILClass *));
- if(!baseList)
- {
- CCOutOfMemory();
- }
- }
- else
- {
- baseList = 0;
- }
+ parent = 0;
baseNodeList = defn->baseClass;
- for(base = 0; base < numBases; ++base)
+ while(baseNodeList)
{
+ ILClass *baseClass = 0;
+
/* Get the name of the class to be inherited or implemented */
if(yykind(baseNodeList) == yykindof(ILNode_ArgList))
{
@@ -456,54 +670,63 @@
else
{
baseNode = baseNodeList;
+ baseNodeList = 0;
}
/* Look in the scope for the base class */
if(CSSemBaseType(baseNode, info, &baseNode,
- &baseTypeNode,
&(baseList[base])))
+ &baseTypeNode, &baseClass))
{
- if(baseList[base] == 0)
+ if(baseClass == 0)
{
- baseList[base] = NodeToClass(baseTypeNode);
- if(baseList[base] == 0)
+ baseClass = NodeToClass(baseTypeNode);
+ if(baseClass == 0)
{
CreateType(info, globalScope, list,
systemObjectName,
baseTypeNode);
- baseList[base] =
NodeToClass(baseTypeNode);
+ baseClass = NodeToClass(baseTypeNode);
}
}
- }
- else
+ if(baseClass)
{
- /* This is not a valid base class specification */
- CCErrorOnLine(yygetfilename(baseNode),
yygetlinenum(baseNode),
- "invalid base type");
- }
- }
+ #if IL_VERSION_MAJOR > 1
+ ILClass *underlying =
ILClassGetUnderlying(baseClass);
- /* Find the parent class within the base list */
- parent = 0;
- errorReported = 0;
- for(base = 0; base < numBases; ++base)
- {
- if(baseList[base] && !ILClass_IsInterface(baseList[base]))
- {
- if(parent)
+ if(!underlying)
{
- if(!errorReported)
+ CCOutOfMemory();
+ }
+ if(!ILClass_IsInterface(underlying))
+ #else /* IL_VERSION_MAJOR == 1 */
+ if(!ILClass_IsInterface(baseClass))
+ #endif /* IL_VERSION_MAJOR == 1 */
{
- CCErrorOnLine(yygetfilename(type),
yygetlinenum(type),
- "class inherits from two or more
non-interface classes");
- errorReported = 1;
+ parent = baseClass;
+ }
}
}
else
{
- parent = baseList[base];
- }
+ /* If we get here the base type might be a member of a
+ nested parent that is not fully qualified (including
+ all nested parents).
+ The right gathering order is preserved because the
+ nested parent creates it's base types first
including their
+ nested children.
+ The case that the base class does not exist is
handled in
+ AddBaseClasses then. */
}
}
+ /* Test for interfaces, or find "System.Object" if no parent yet */
+ if(!parent && (defn->modifiers & IL_META_TYPEDEF_INTERFACE) == 0)
+ {
+ /* Compiling something else that inherits "System.Object" */
+ /* Use the builtin library's "System.Object" as parent class */
+ parent = ILType_ToClass(ILFindSystemType(info, "Object"));
+
+ if(!parent)
+ {
/* Change to the global namespace to resolve "System.Object" */
while(((ILNode_Namespace *)(info->currentNamespace))->enclosing != 0)
{
@@ -511,32 +734,13 @@
((ILNode_Namespace
*)(info->currentNamespace))->enclosing;
}
- /* Test for interfaces, or find "System.Object" if no parent yet */
- if((defn->modifiers & IL_META_TYPEDEF_CLASS_SEMANTICS_MASK)
- == IL_META_TYPEDEF_INTERFACE)
- {
- if(parent)
- {
- CCErrorOnLine(yygetfilename(type), yygetlinenum(type),
- "interface inherits from
non-interface class");
- parent = 0;
- }
- }
- else if(!parent)
- {
- if(!strcmp(name, "Object") && namespace != 0 &&
- !strcmp(namespace, "System"))
- {
- /* Special case: we are compiling "System.Object"
itself */
- parent = 0;
- }
- else
- {
- /* Compiling something else that inherits
"System.Object" */
if(CSSemBaseType(systemObjectName, info,
&systemObjectName,
&baseTypeNode,
&parent))
{
- if(!parent)
+ /* check if the parent is not yet created and
if the resolved
+ baseTypeNode is not equal to the just
processed classNode
+ what means we are currently processing
System.Object itself. */
+ if(!parent && (baseTypeNode != type))
{
parent = NodeToClass(baseTypeNode);
if(!parent)
@@ -547,44 +751,13 @@
}
}
}
- else
- {
- /* Use the builtin library's "System.Object" */
- parent = ILType_ToClass(ILFindSystemType(info,
"Object"));
- }
- }
- }
-
- /* Restore the namespace, class, and type formals */
- info->currentNamespace = savedNamespace;
- info->currentClass = savedClass;
-#if IL_VERSION_MAJOR > 1
- info->currentTypeFormals = savedTypeFormals;
-#endif /* IL_VERSION_MAJOR > 1 */
-
- /* 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),
- "inheriting from a sealed parent
class");
}
/* Create the class information block */
if(strcmp(name, "<Module>") != 0)
{
- classInfo = ILClassCreate(nestedScope, 0, name, namespace,
parent);
+ classInfo = ILClassCreate(nestedScope, 0, name, namespace, 0);
if(!classInfo)
{
CCOutOfMemory();
@@ -598,23 +771,9 @@
}
defn->classInfo = classInfo;
- /* Add the interfaces to the class */
- for(base = 0; base < numBases; ++base)
- {
- if(baseList[base] && ILClass_IsInterface(baseList[base]))
- {
- if(!ILClassAddImplements(classInfo, baseList[base], 0))
- {
- CCOutOfMemory();
- }
- }
- }
-
- /* Clean up */
- if(baseList)
- {
- ILFree(baseList);
- }
+ /* Restore the namespace, class, and type formals */
+ info->currentNamespace = savedNamespace;
+ info->currentClass = savedClass;
/* Record the node on the class as user data */
ILSetProgramItemMapping(info, (ILNode *)defn);
@@ -2797,33 +2956,24 @@
CreateType(info, globalScope, list, systemObject, child);
}
+ info->typeGather = 0;
+
#if IL_VERSION_MAJOR > 1
/* Add the generic type parameters to each class */
ILNode_ListIter_Init(&iterator, list);
while((child = ILNode_ListIter_Next(&iterator)) != 0)
{
- if(yykind(child) == yykindof(ILNode_ClassDefn))
- {
AddGenericParametersToClass(info, child);
+ }
+#endif /* IL_VERSION_MAJOR > 1 */
- /* process the nested classes */
- if(((ILNode_ClassDefn*)child)->nestedClasses)
- {
- ILNode_ListIter iterator2;
-
- ILNode_ListIter_Init(&iterator2,
-
((ILNode_ClassDefn*)child)->nestedClasses);
- while((child =
ILNode_ListIter_Next(&iterator2)) != 0)
- {
- if(yykind(child) ==
yykindof(ILNode_ClassDefn))
+ ILNode_ListIter_Init(&iterator, list);
+ while((child = ILNode_ListIter_Next(&iterator)) != 0)
{
-
AddGenericParametersToClass(info, child);
- }
+ AddBaseClasses(info,
+ (ILNode_ClassDefn*)child,
+ systemObject);
}
- }
- }
- }
-#endif /* IL_VERSION_MAJOR > 1 */
/* Create the class members within each type */
ILNode_ListIter_Init(&iterator, list);
Index: cscc/csharp/cs_lookup.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_lookup.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -b -r1.38 -r1.39
--- cscc/csharp/cs_lookup.c 23 Oct 2007 18:32:21 -0000 1.38
+++ cscc/csharp/cs_lookup.c 30 Oct 2007 17:35:23 -0000 1.39
@@ -229,7 +229,7 @@
{
nestedChild = ILNestedInfoGetChild(nested);
if(!strcmp(ILClass_Name(nestedChild), name) &&
- ILClassAccessible(nestedChild, accessedFrom))
+ ((genInfo->accessCheck)(nestedChild,
accessedFrom)))
{
AddMember(results, (ILProgramItem
*)nestedChild,
info,
CS_MEMBERKIND_TYPE);
@@ -750,7 +750,7 @@
{
type = ILClassResolve(type);
}
- if(type && ILClassAccessible(type, accessedFrom))
+ if(type && (genInfo->accessCheck)(type, accessedFrom))
{
AddMember(results, (ILProgramItem *)type, 0,
CS_MEMBERKIND_TYPE);
return CS_SEMKIND_TYPE;
@@ -801,7 +801,7 @@
{
type = ILClassResolve(type);
}
- if(type && ILClassAccessible(type, accessedFrom))
+ if(type && (genInfo->accessCheck)(type, accessedFrom))
{
AddMember(results, (ILProgramItem *)type, 0,
CS_MEMBERKIND_TYPE);
return CS_SEMKIND_TYPE;
@@ -1099,8 +1099,10 @@
int result;
ILNode_ClassDefn *nestedParent;
ILNode *child;
+#if IL_VERSION_MAJOR > 1
ILNode_ListIter iter;
ILType *formalType;
+#endif /* IL_VERSION_MAJOR > 1 */
CSSemValue value;
ILMethod *caller;
int switchToStatics;
Index: cscc/csharp/cs_lvalue.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_lvalue.tc,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -b -r1.64 -r1.65
--- cscc/csharp/cs_lvalue.tc 23 Sep 2007 14:40:20 -0000 1.64
+++ cscc/csharp/cs_lvalue.tc 30 Oct 2007 17:35:23 -0000 1.65
@@ -1419,21 +1419,10 @@
CSSemValue value;
int savedState = info->inSemType;
const char *name;
- const char *ns;
-
- /* convert the first subexpression into a namespace */
- ns = ILMemberAccessName(node->expr1);
/* Convert the second subexpression into a name */
name = ILQualIdentName(node->expr2, 0);
- value = GetFullyQualifiedType(info, ns, name);
-
- if(CSSemGetKind(value) == CS_SEMKIND_TYPE)
- {
- return value;
- }
-
info->inSemType = -1;
/* Get the semantic value for the left part of the identifier */
value = ILNode_SemAnalysisType(node->expr1, info, &(node->expr1));
Index: cscc/csharp/cs_semantics.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_semantics.tc,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- cscc/csharp/cs_semantics.tc 24 May 2007 13:51:15 -0000 1.14
+++ cscc/csharp/cs_semantics.tc 30 Oct 2007 17:35:23 -0000 1.15
@@ -116,6 +116,13 @@
*/
void CSSemProgramItem(ILGenInfo *info, ILProgramItem *item);
+/*
+ * Perform semantic analysis on a set of type actuals
+ * and add them to a "with" type.
+ */
+void CSSemWithType(ILNode *actuals, ILGenInfo *info,
+ ILNode **parent, ILType *withType);
+
%}
%{
@@ -218,9 +225,12 @@
{
CSSemValue value;
int save = info->inSemType;
- info->inSemType = info->typeGather;
+ ILClassAccessCheck saveAccessCheck = info->accessCheck;
+ info->inSemType = -1;
+ info->accessCheck = ILClassInheritable;
value = ILNode_SemAnalysisType(type, info, parent);
info->inSemType = save;
+ info->accessCheck = saveAccessCheck;
if(CSSemIsType(value))
{
*baseNode = 0;
@@ -258,4 +268,34 @@
}
}
+/*
+ * Perform semantic analysis on a set of type actuals
+ * and add them to a "with" type.
+ */
+void CSSemWithType(ILNode *actuals, ILGenInfo *info, ILNode **parent,
+ ILType *withType)
+{
+ ILNode_ListIter iter;
+ ILNode *child;
+
+ ILNode_ListIter_Init(&iter, actuals);
+ while((child = ILNode_ListIter_Next(&iter)) != 0)
+ {
+ CSSemValue value;
+
+ value = ILNode_SemAnalysisType(child, info, &child);
+
+ if(!CSSemIsType(value))
+ {
+ CCErrorOnLine(yygetfilename(actuals),
yygetlinenum(actuals),
+ "type name expected in generic
type argument");
+ CSSemSetType(value, ILType_Int32);
+ }
+ if(!ILTypeAddWithParam(info->context, withType,
CSSemGetType(value)))
+ {
+ CCOutOfMemory();
+ }
+ }
+}
+
%}
Index: cscc/csharp/cs_types.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_types.tc,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- cscc/csharp/cs_types.tc 23 Oct 2007 18:32:21 -0000 1.12
+++ cscc/csharp/cs_types.tc 30 Oct 2007 17:35:23 -0000 1.13
@@ -310,40 +310,6 @@
return CSSemValueDefault;
}
-%{
-
-/*
- * 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)
-{
- ILNode_ListIter iter;
- ILNode *child;
-
- ILNode_ListIter_Init(&iter, actuals);
- while((child = ILNode_ListIter_Next(&iter)) != 0)
- {
- CSSemValue value;
-
- value = ILNode_SemAnalysisType(child, info, &child);
-
- if(!CSSemIsType(value))
- {
- CCErrorOnLine(yygetfilename(actuals),
yygetlinenum(actuals),
- "type name expected in generic
type argument");
- CSSemSetType(value, ILType_Int32);
- }
- if(!ILTypeAddWithParam(info->context, withType,
CSSemGetType(value)))
- {
- CCOutOfMemory();
- }
- }
-}
-
-%}
-
/*
* Perform semantic analysis for a generic type or method reference
* with a bias to returning Type objects.
@@ -391,7 +357,8 @@
{
CCOutOfMemory();
}
- SemWithType(info, withType, node->typeArguments,
&(node->typeArguments));
+ CSSemWithType(node->typeArguments, info, &(node->typeArguments),
+ withType);
CSSemSetType(value, withType);
/* Convert the result into an l-value or r-value and return it
*/
@@ -470,7 +437,7 @@
{
CCOutOfMemory();
}
- SemWithType(info, withType, node->typeArguments,
&(node->typeArguments));
+ CSSemWithType(node->typeArguments, info, &(node->typeArguments),
withType);
CSSemSetType(value, withType);
return value;
}
Index: image/class.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/image/class.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -b -r1.40 -r1.41
--- image/class.c 20 Sep 2007 20:04:18 -0000 1.40
+++ image/class.c 30 Oct 2007 17:35:23 -0000 1.41
@@ -242,6 +242,9 @@
info->programItem.image = image;
info->parent = parent;
info->ext = 0;
+#if IL_VERSION_MAJOR > 1
+ info->numGenericPars = -1;
+#endif
/* Get the name of the scope if it is a nesting parent */
scopeClass = ILProgramItemToClass(scope);
@@ -341,6 +344,10 @@
info->parent = 0;
info->ext = 0;
+#if IL_VERSION_MAJOR > 1
+ /* Wrapper classes never have generic parameters */
+ info->numGenericPars = 0;
+#endif
return info;
}
@@ -1364,6 +1371,82 @@
return 0;
}
+int ILClassInheritable(ILClass *info, ILClass *scope)
+{
+ if(!info)
+ {
+ return 0;
+ }
+ info = (ILClass *)(_ILProgramItemResolve(&(info->programItem)));
+ if(scope)
+ {
+ scope = (ILClass
*)(_ILProgramItemResolve(&(scope->programItem)));
+ }
+ if(info == scope)
+ {
+ /* A class is always accessible to itself */
+ return 1;
+ }
+ switch(info->attributes & IL_META_TYPEDEF_VISIBILITY_MASK)
+ {
+ case IL_META_TYPEDEF_NOT_PUBLIC:
+ case IL_META_TYPEDEF_NESTED_ASSEMBLY:
+ {
+ /* The class must be in the same assembly as the scope
*/
+ if(scope && ILClassToImage(info) ==
ILClassToImage(scope))
+ {
+ return 1;
+ }
+ }
+ break;
+
+ case IL_META_TYPEDEF_PUBLIC:
+ {
+ return 1;
+ }
+ /* Not reached */
+
+ case IL_META_TYPEDEF_NESTED_PUBLIC:
+ {
+ /* The parent must be inheritable */
+ return ILClassInheritable(ILClassGetNestedParent(info),
scope);
+ }
+ /* Not reached */
+
+ case IL_META_TYPEDEF_NESTED_PRIVATE:
+ {
+ /* Nested class accessible from parent, siblings, or
children */
+ return AccessibleNestedPrivate(info, scope);
+ }
+ /* Not reached */
+
+ case IL_META_TYPEDEF_NESTED_FAMILY:
+ {
+ /* Accessible to private or inherited scopes */
+ return 1;
+ }
+ /* Not reached */
+
+ case IL_META_TYPEDEF_NESTED_FAM_AND_ASSEM:
+ {
+ /* Must have both family access and be in the same
assembly */
+ if(scope && ILClassToImage(info) ==
ILClassToImage(scope))
+ {
+ return 1;
+ }
+ }
+ break;
+
+ case IL_META_TYPEDEF_NESTED_FAM_OR_ASSEM:
+ {
+ /* Must have family access or be in the same assembly */
+ return 1;
+ }
+ break;
+ }
+ return 0;
+}
+
ILMember *ILClassNextMember(ILClass *info, ILMember *last)
{
if(last)
@@ -1994,6 +2077,26 @@
}
}
+ILUInt32 ILClassGetNumGenericPars(ILClass *info)
+{
+#if IL_VERSION_MAJOR > 1
+ if(info->numGenericPars < 0)
+ {
+ info->numGenericPars =
ILGenericParGetNumParams(ILToProgramItem(info));
+ }
+ return info->numGenericPars;
+#else /* IL_VERSION_MAJOR == 1 */
+ return 0;
+#endif
+}
+
+void ILClassSetNumGenericPars(ILClass *info, ILUInt32 numGenericPars)
+{
+#if IL_VERSION_MAJOR > 1
+ info->numGenericPars = numGenericPars;
+#endif
+}
+
#ifdef __cplusplus
};
#endif
Index: image/meta_types.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/image/meta_types.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- image/meta_types.c 14 Sep 2007 00:55:43 -0000 1.20
+++ image/meta_types.c 30 Oct 2007 17:35:23 -0000 1.21
@@ -1676,6 +1676,14 @@
return ILTypeGetReturnWithPrefixes(type);
}
+void ILTypeSetWithMain(ILType *type, ILType *mainType)
+{
+ if(ILType_IsWith(type))
+ {
+ type->un.method__.retType__ = mainType;
+ }
+}
+
#ifdef __cplusplus
};
#endif
Index: image/program.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/image/program.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -b -r1.27 -r1.28
--- image/program.h 14 Sep 2007 00:55:43 -0000 1.27
+++ image/program.h 30 Oct 2007 17:35:23 -0000 1.28
@@ -280,6 +280,9 @@
ILType *synthetic; /* Synthetic type for
this class */
ILClassExt *ext; /* Extension
information */
void *userData; /* Data added by the
runtime engine */
+#if IL_VERSION_MAJOR > 1
+ ILInt32 numGenericPars; /* Number of generic
parameters */
+#endif
};
Index: include/il_program.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/include/il_program.h,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -b -r1.60 -r1.61
--- include/il_program.h 14 Sep 2007 00:55:43 -0000 1.60
+++ include/il_program.h 30 Oct 2007 17:35:24 -0000 1.61
@@ -709,6 +709,12 @@
int ILClassAccessible(ILClass *info, ILClass *scope);
/*
+ * Determine if a class might be extended or an interface might
+ * be implemented in a specific scope.
+ */
+int ILClassInheritable(ILClass *info, ILClass *scope);
+
+/*
* Iterate over the members that are associated with a class.
*/
ILMember *ILClassNextMember(ILClass *info, ILMember *last);
@@ -836,6 +842,16 @@
ILClass *ILClassGetUnderlying(ILClass *info);
/*
+ * Get the number of generic parameters for the class.
+ */
+ILUInt32 ILClassGetNumGenericPars(ILClass *info);
+
+/*
+ * Set the number of generic parameters for the class.
+ */
+void ILClassSetNumGenericPars(ILClass *info, ILUInt32 numGenericPars);
+
+/*
* Get the generic type parameters used to instantiate the class.
*/
ILType *ILClassGetTypeArguments(ILClass *info);
Index: include/il_types.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/include/il_types.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -b -r1.28 -r1.29
--- include/il_types.h 24 Sep 2004 04:30:29 -0000 1.28
+++ include/il_types.h 30 Oct 2007 17:35:24 -0000 1.29
@@ -88,6 +88,7 @@
#define ILType_UInt64 ILType_FromElement(IL_META_ELEMTYPE_U8)
#define ILType_Float32 ILType_FromElement(IL_META_ELEMTYPE_R4)
#define ILType_Float64 ILType_FromElement(IL_META_ELEMTYPE_R8)
+#define ILType_String
ILType_FromElement(IL_META_ELEMTYPE_STRING)
#define ILType_Int
ILType_FromElement(IL_META_ELEMTYPE_I)
#define ILType_UInt
ILType_FromElement(IL_META_ELEMTYPE_U)
#define ILType_Float ILType_FromElement(IL_META_ELEMTYPE_R)
@@ -652,6 +653,11 @@
ILType *ILTypeGetWithMainWithPrefixes(ILType *type);
/*
+ * Set the main "with" type for a generic reference
+ */
+void ILTypeSetWithMain(ILType *type, ILType *mainType);
+
+/*
* Determine if a type needs to be instantiated because it involves
* generic parameter references.
*/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [dotgnu-pnet-commits] pnet ChangeLog codegen/cg_gen.c codegen/cg_gen....,
Klaus Treichel <=