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

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

[dotgnu-pnet-commits] [SCM] DotGNU Portable.NET engine, compilers and to


From: Klaus Treichel
Subject: [dotgnu-pnet-commits] [SCM] DotGNU Portable.NET engine, compilers and tools (pnet) branch, master, updated. bbe244d80c0d5f2e49558f5537e6db009832a1a8
Date: Sat, 01 Aug 2009 09:53:46 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "DotGNU Portable.NET engine, compilers and tools (pnet)".

The branch, master has been updated
       via  bbe244d80c0d5f2e49558f5537e6db009832a1a8 (commit)
      from  05eb1cc85637a8c48bf942442f407d2a985fddef (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/pnet.git/commit/?id=bbe244d80c0d5f2e49558f5537e6db009832a1a8

commit bbe244d80c0d5f2e49558f5537e6db009832a1a8
Author: Klaus Treichel <address@hidden>
Date:   Sat Aug 1 11:47:33 2009 +0200

    Add support for partial type declarations.

diff --git a/ChangeLog b/ChangeLog
index bcc902d..1ac303a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,52 @@
+2009-08-01  Klaus Treichel  <address@hidden>
+
+       * codegen/cs_decls.tc (DumpClassMembers): Add helper function for 
dumping
+       class members which hadles partial types.
+       (ILNode_GenDiscard(ILNode_ClassDefn)): Do nothing for additional part
+       declarations for a type and use DumpClassMembers for dumping the 
members.
+
+       * codegen/cg_nodes.tc: Add additional members to ILNode_ClassDefn for
+       partial type handling.
+
+       * cscc/csharp/cs_attrs.c (CollectAttributes): Added to collect the
+       attributes from one attribute tree. (Moved from CSProcessAttrs to here).
+       (CSProcessAttrs): Use CollectAttributes for collecting the attributes 
now.
+       (CSProcessAttrsForClass): Added for processing the attributes for a 
class
+       node including it's additional parts.
+
+       * cscc/csharp/cs_decls.tc (HandleStaticCtor): Add handling of the
+       additional partial declarations of a type.
+       (ILNode_SemAnalysis(ILNode_ClassDefn)): Call CSProcessAttrsForClass
+       instead of CSProcessAttrs for processing the attributes of all partial
+       declarations of a type in one run. Perform semantic analysis on
+       additional partial declarations prior to semanalyzing the main part.
+       (CSAddInitCtor): Make sure the pseudo .init method on the main part is
+       used.
+
+       * cscc/csharp/cs_gather.c (NumBases): Add helper function to get the
+       number of base classes and interfaces for all partial definitions of one
+       type.
+       (FlagTypeToName): Add helper function.
+       (DeclareTypePart): Added to handle the declaration of additional parial
+       declarations of a type.
+       (AddBaseClasses): Handle the base classes and implemented interfaces of
+       all partial declarations for a type.
+       (CreateType): Create types only for non partial declarations and the 
main
+       part of a partial type declaration. For additional partial declarations
+       handle only the nested typed of that part.
+       (CreateField, CreateProperty): Use the modifiers of the main part to
+       determine if the owner class is static.
+       (CreateMembers): Create the members of additional partial declerations 
of
+       a type too.
+       (DeclareTypes): Add handling of partial type declarations.
+
+       * cscc/csharp/cs_grammar.y: Add handling of the 2.x partial type 
modifier.
+
+       * cscc/csharp/cs_internal.h: Add the CS_MODIFIER_PARTIAL modifier flag.
+
 2009-07-30  Klaus Treichel  <address@hidden>
 
-       * cscc/csharp/cs_cast.tc (CSCastMethod): Use CS_MODIGIER_STATIC instead
+       * cscc/csharp/cs_cast.tc (CSCastMethod): Use CS_MODIFIER_STATIC instead
        of IL_META_METHODDEF_STATIC with the modifiers now.
 
        * cscc/csharp/cs_decls.tc (AppendStaticCtor): Guard the initialization
diff --git a/codegen/cg_decls.tc b/codegen/cg_decls.tc
index aa64d01..0c32212 100644
--- a/codegen/cg_decls.tc
+++ b/codegen/cg_decls.tc
@@ -144,6 +144,48 @@ static int ClassIsEmpty(ILClass *classInfo)
        return 1;
 }
 
+/*
+ * Dump the members of the current class definition node and all it's other
+ * partial declarations.
+ */
+static void DumpClassMembers(ILGenInfo *info, ILNode_ClassDefn *node)
+{
+       /* First dump the members of this class */
+       if(info->outputIsJava)
+       {
+               JavaGenDiscard(node->body, info);
+       }
+       else
+       {
+               ILNode_GenDiscard(node->body, info);
+       }
+#if IL_VERSION_MAJOR > 1
+       if(node->otherParts)
+       {
+               ILNode_ListIter iter;
+               ILNode *part;
+               ILNode *prevClass;
+
+               prevClass = info->currentClass;
+               ILNode_ListIter_Init(&iter, node->otherParts);
+               while((part = ILNode_ListIter_Next(&iter)) != 0)
+               {
+                       info->currentClass = part;
+
+                       if(info->outputIsJava)
+                       {
+                               JavaGenDiscard(((ILNode_ClassDefn 
*)part)->body, info);
+                       }
+                       else
+                       {
+                               ILNode_GenDiscard(((ILNode_ClassDefn 
*)part)->body, info);
+                       }
+               }
+               info->currentClass = prevClass;
+       }
+#endif /* IL_VERSION_MAJOR > 1 */
+}
+
 %}
 
 /*
@@ -158,6 +200,17 @@ ILNode_GenDiscard(ILNode_ClassDefn)
        int isModule = (!strcmp(node->name, "<Module>"));
        ILClassLayout *layout;
 
+#if IL_VERSION_MAJOR > 1
+       /*
+        * If this is an additional part skip it here because it's contents is
+        * handled in DumpClassMembers.
+        */
+       if(node->partialParent)
+       {
+               return;
+       }
+#endif /* IL_VERSION_MAJOR > 1 */
+
        /* Get the class information structure */
        classInfo = node->classInfo;
        if(!classInfo || classInfo == ((ILClass *)1))
@@ -269,14 +322,7 @@ ILNode_GenDiscard(ILNode_ClassDefn)
        }
 
        /* Output the class members */
-       if(info->outputIsJava)
-       {
-               JavaGenDiscard(node->body, info);
-       }
-       else
-       {
-               ILNode_GenDiscard(node->body, info);
-       }
+       DumpClassMembers(info, node);
 
        /* Output the static constructor for the class */
        if(node->staticCtorsMethod && info->asmOutput)
diff --git a/codegen/cg_nodes.tc b/codegen/cg_nodes.tc
index ce14970..30784b3 100644
--- a/codegen/cg_nodes.tc
+++ b/codegen/cg_nodes.tc
@@ -874,6 +874,8 @@ struct _tagILSwitchValue
        %nocreate ILNode *nestedClasses = {0};
        %nocreate ILVisitMode visited = {ILVisitMode_NotVisited};
        %nocreate const char *defaultMemberName = {0};
+       %nocreate ILNode_ClassDefn *partialParent = {0};
+       %nocreate ILNode *otherParts = {0};
 
 }
 %node ILNode_ScopeChange ILNode_Declaration =
diff --git a/cscc/csharp/cs_attrs.c b/cscc/csharp/cs_attrs.c
index 4b264f0..816bebb 100644
--- a/cscc/csharp/cs_attrs.c
+++ b/cscc/csharp/cs_attrs.c
@@ -600,36 +600,28 @@ cleanup:
        }
 }
 
-void CSProcessAttrs(ILGenInfo *info, ILProgramItem *mainItem,
-                                       ILNode *attributes, int mainTarget)
+static void CollectAttributes(ILGenInfo *info,
+                                                         CGAttributeInfos 
*attributeInfos,
+                                                         ILNode_AttributeTree 
*attributes,
+                                                         ILProgramItem 
*mainItem, int mainTarget)
 {
-       CGAttributeInfos attributeInfos;
-       ILProgramItem *item;
-       int target;
-       ILNode_ListIter iter;
-       ILNode_ListIter iter2;
        ILNode_AttributeSection *section;
-       ILNode_Attribute *attr;
-       const char *targetName;
-       ILClass *classInfo;
-       ILMethod *method;
-       unsigned long numParams;
-
-       /* Bail out if we don't have any attributes */
-       if(!attributes)
-       {
-               return;
-       }
-
-       /* Initislize the attribute infos. */
-       CGAttributeInfosInit(info, &attributeInfos);
+       ILNode_ListIter iter;
 
        /* Scan through the attribute sections */
-       ILNode_ListIter_Init(&iter, ((ILNode_AttributeTree *)attributes)
-                                                                               
->sections);
+       ILNode_ListIter_Init(&iter, attributes->sections);
        while((section = (ILNode_AttributeSection *)
                                ILNode_ListIter_Next(&iter)) != 0)
        {
+               ILProgramItem *item;
+               int target;
+               ILNode_Attribute *attr;
+               ILNode_ListIter iter2;
+               const char *targetName;
+               ILClass *classInfo;
+               ILMethod *method;
+               unsigned long numParams;
+
                /* Skip documentation comments, if present */
                if(yyisa(section, ILNode_DocComment))
                {
@@ -796,7 +788,7 @@ void CSProcessAttrs(ILGenInfo *info, ILProgramItem 
*mainItem,
                ILNode_ListIter_Init(&iter2, section->attrs);
                while((attr = (ILNode_Attribute *)ILNode_ListIter_Next(&iter2)) 
!= 0)
                {
-                       ProcessAttr(info, &attributeInfos, item, target, attr);
+                       ProcessAttr(info, attributeInfos, item, target, attr);
                }
 
                /* Convert system library attributes into metadata structures */
@@ -805,7 +797,111 @@ void CSProcessAttrs(ILGenInfo *info, ILProgramItem 
*mainItem,
                        CCOutOfMemory();
                }
        }
-       /* Process tha collected attributes */
+}
+
+void CSProcessAttrs(ILGenInfo *info, ILProgramItem *mainItem,
+                                       ILNode *attributes, int mainTarget)
+{
+       CGAttributeInfos attributeInfos;
+
+       /* Bail out if we don't have any attributes */
+       if(!attributes)
+       {
+               return;
+       }
+
+       /* Initialize the attribute infos. */
+       CGAttributeInfosInit(info, &attributeInfos);
+
+       /* Collect the attributes */
+       CollectAttributes(info, &attributeInfos,
+                                         (ILNode_AttributeTree *)attributes,
+                                         mainItem, mainTarget);
+
+       /* Process the collected attributes */
+       CGAttributeInfosProcess(&attributeInfos);
+
+       /* Destroy the attribute infos. */
+       CGAttributeInfosDestroy(&attributeInfos);
+}
+
+void CSProcessAttrsForClass(ILGenInfo *info, ILNode_ClassDefn *defn,
+                                                       int mainTarget)
+{
+       CGAttributeInfos attributeInfos;
+       ILProgramItem *item;
+
+#if IL_VERSION_MAJOR == 1
+       /* Bail out if we don't have any attributes */
+       if(!defn || !(defn->attributes))
+       {
+               return;
+       }
+#else
+       /*
+        * Bail out if this is an additional part for a type or this is no
+        * partial type fefinition and we have no attributes.
+        */
+       if(!defn || (defn->partialParent != 0) ||
+          (((defn->modifiers & CS_MODIFIER_PARTIAL) == 0) && 
!(defn->attributes)))
+       {
+               return;
+       }
+#endif /* IL_VERSION_MAJOR == 1 */
+
+       /* Get the item */
+       item = ILToProgramItem(defn->classInfo);
+
+       /* Initialize the attribute infos. */
+       CGAttributeInfosInit(info, &attributeInfos);
+
+       if(defn->attributes)
+       {
+               /* Collect the attributes */
+               CollectAttributes(info, &attributeInfos,
+                                                 (ILNode_AttributeTree 
*)(defn->attributes),
+                                                 item, mainTarget);
+       }
+
+#if IL_VERSION_MAJOR > 1
+       /* Collect the attributes from the additional parts too */
+       if(defn->otherParts)
+       {
+               ILNode_ListIter iter;
+               ILNode *partNode;
+
+               ILNode_ListIter_Init(&iter, defn->otherParts);
+               while((partNode = ILNode_ListIter_Next(&iter)) != 0)
+               {
+                       ILNode_ClassDefn *partDefn;
+
+                       partDefn = (ILNode_ClassDefn *)partNode;
+                       if(partDefn->attributes)
+                       {
+                               ILNode *savedClass;
+                               ILNode *savedNamespace;
+                               ILNode *savedMethod;
+
+                               savedClass = info->currentClass;
+                               savedNamespace = info->currentNamespace;
+                               savedMethod = info->currentMethod;
+                               info->currentClass = (ILNode *)partDefn;
+                               info->currentNamespace = 
partDefn->namespaceNode;
+                               info->currentMethod = NULL;
+
+                               CollectAttributes(info, &attributeInfos,
+                                                                 
(ILNode_AttributeTree *)(partDefn->attributes),
+                                                                 item, 
mainTarget);
+
+                               info->currentClass = savedClass;
+                               info->currentNamespace = savedNamespace;
+                               info->currentMethod = savedMethod;
+                       }
+               }
+       }
+#endif /* IL_VERSION_MAJOR > 1 */
+
+       /* Process the collected attributes */
        CGAttributeInfosProcess(&attributeInfos);
 
        /* Destroy the attribute infos. */
diff --git a/cscc/csharp/cs_decls.tc b/cscc/csharp/cs_decls.tc
index f71736a..351f0dc 100644
--- a/cscc/csharp/cs_decls.tc
+++ b/cscc/csharp/cs_decls.tc
@@ -189,11 +189,84 @@ static void HandleStaticCtor(ILGenInfo *info, 
ILNode_ClassDefn *node)
                staticCtor = node->staticCtors;
                ctorDefn = node;
        }
+#if IL_VERSION_MAJOR > 1
+       if(node->otherParts)
+       {
+               ILNode_ListIter iter;
+               ILNode *part;
+
+               ILNode_ListIter_Init(&iter, node->otherParts);
+               while((part = ILNode_ListIter_Next(&iter)) != NULL)
+               {
+                       ILNode_ClassDefn *partDefn;
+
+                       partDefn = (ILNode_ClassDefn *)part;
+                       if(partDefn->staticCtors)
+                       {
+                               CheckStaticCtor(node->staticCtors, (staticCtor 
!= 0));
+                               if(!staticCtor)
+                               {
+                                       staticCtor = partDefn->staticCtors;
+                                       ctorDefn = partDefn;
+                               }
+                       }
+               }
+       }
+#endif /* IL_VERSION_MAJOR > 1 */
 
        /* Now collect the static fields with initialization */
        staticInitList = ILNode_List_create();
        ILNode_Declaration_GatherStaticCtor((ILNode_Declaration *)node->body,
                                                                                
(ILNode_List *)staticInitList);
+#if IL_VERSION_MAJOR > 1
+       if(node->otherParts)
+       {
+               ILNode_ListIter iter;
+               ILNode *part;
+
+               ILNode_ListIter_Init(&iter, node->otherParts);
+               while((part = ILNode_ListIter_Next(&iter)) != NULL)
+               {
+                       ILNode_ClassDefn *partDefn;
+                       ILNode *partInitList;
+
+                       partDefn = (ILNode_ClassDefn *)part;
+                       partInitList = ILNode_List_create();
+                       ILNode_Declaration_GatherStaticCtor((ILNode_Declaration 
*)partDefn->body,
+                                                                               
                (ILNode_List *)partInitList);
+
+                       if(ILNode_List_Length(partInitList) > 0)
+                       {
+                               /* Perform semantic analysis on this part */
+                               ILNode *savedClass;
+                               ILNode *savedNamespace;
+                               ILNode *savedMethod;
+
+                               if(staticCtorsMethod == 0)
+                               {
+                                       staticCtorsMethod = 
CreateStaticCtorMethod(info, partDefn->classInfo);
+                               }
+
+                               savedClass = info->currentClass;
+                               savedNamespace = info->currentNamespace;
+                               savedMethod = info->currentMethod;
+                               info->currentClass = (ILNode *)partDefn;
+                               info->currentNamespace = 
partDefn->namespaceNode;
+                               info->currentMethod = staticCtorsMethod;
+
+                               ILNode_SemAnalysis(partInitList, info, 
&partInitList);
+
+                               info->currentClass = savedClass;
+                               info->currentNamespace = savedNamespace;
+                               info->currentMethod = savedMethod;
+
+                               /* Append the list of this part to the main 
list */
+                               AppendStaticCtor((ILNode_List*)staticInitList,
+                                                                 
(ILNode_List*)partInitList, 1);
+                       }
+               }
+       }
+#endif /* IL_VERSION_MAJOR > 1 */
 
        /* append the explicit static constructors to the end of the 
           gathered list */
@@ -320,8 +393,7 @@ ILNode_SemAnalysis(ILNode_ClassDefn)
                info->currentClass = (ILNode *)node;
                info->currentNamespace = node->namespaceNode;
                info->currentMethod = NULL;
-               CSProcessAttrs(info, ILToProgramItem(node->classInfo),
-                                          node->attributes, target);
+               CSProcessAttrsForClass(info, node, target);
                info->currentClass = savedClass;
                info->currentNamespace = savedNamespace;
                info->currentMethod = savedMethod;
@@ -358,6 +430,26 @@ ILNode_SemAnalysis(ILNode_ClassDefn)
                info->currentNamespace = node->namespaceNode;
                info->currentMethod = NULL;
                value = ILNode_SemAnalysis(node->body, info, &(node->body));
+               info->currentClass = savedClass;
+               info->currentNamespace = savedNamespace;
+               info->currentMethod = savedMethod;
+       }
+
+#if IL_VERSION_MAJOR > 1
+       if(node->otherParts)
+       {
+               ILNode_SemAnalysis(node->otherParts, info, &(node->otherParts));
+       }
+       if(!(node->partialParent))
+       {
+#endif /* IL_VERSION_MAJOR > 1 */
+               savedClass = info->currentClass;
+               savedNamespace = info->currentNamespace;
+               savedMethod = info->currentMethod;
+               info->currentClass = (ILNode *)node;
+               info->currentNamespace = node->namespaceNode;
+               info->currentMethod = NULL;
+
                if(node->initCtorsMethod)
                {
                        /* Perform semantic analysis on the non-static 
initializers */
@@ -372,17 +464,18 @@ ILNode_SemAnalysis(ILNode_ClassDefn)
                info->currentNamespace = savedNamespace;
                info->currentMethod = savedMethod;
 
+               if(node->classInfo && !ILClass_IsInterface(node->classInfo))
+               {
+                       /* Check that the class implements all of its 
interfaces */
+                       ILGenImplementsAllInterfaces(info, (ILNode *)node,
+                                                                               
 node->classInfo,
+                                                                               
 InterfaceErrorFunc,
+                                                                               
 InterfaceProxyFunc);
+               }
+#if IL_VERSION_MAJOR > 1
        }
-       else
-       {
-               CSSemSetRValue(value, ILType_Int32);
-       }
-       if(node->classInfo && !ILClass_IsInterface(node->classInfo))
-       {
-               /* Check that the class implements all of its interfaces */
-               ILGenImplementsAllInterfaces(info, (ILNode *)node, 
node->classInfo,
-                                                                        
InterfaceErrorFunc, InterfaceProxyFunc);
-       }
+#endif /* IL_VERSION_MAJOR > 1 */
+
        if((node->modifiers & CS_MODIFIER_UNSAFE) != 0)
        {
                CCUnsafeLeave(info);
@@ -703,6 +796,12 @@ void CSAddInitCtor(ILGenInfo *info, ILNode *stmt)
                CSSemValue value;
                ILNode *savedMethod;
 
+       #if IL_VERSION_MAJOR > 1
+               if(defn->partialParent)
+               {
+                       defn = defn->partialParent;
+               }
+       #endif /* IL_VERSION_MAJOR > 1 */
                /* Construct the method declaration for ".init" if necessary.
                   Note: the ".init" method is a pseudo method to collect up
                   all non-static field initializers.  It isn't output into
diff --git a/cscc/csharp/cs_gather.c b/cscc/csharp/cs_gather.c
index 6493df3..2af9fb5 100644
--- a/cscc/csharp/cs_gather.c
+++ b/cscc/csharp/cs_gather.c
@@ -72,6 +72,34 @@ static int CountBaseClasses(ILNode *node)
 }
 
 /*
+ * Get the total number of base classes for a class definition
+ */
+static int NumBases(ILNode_ClassDefn *defn)
+{
+       int count;
+
+       count = CountBaseClasses(defn->baseClass);
+#if IL_VERSION_MAJOR > 1
+       if(defn->otherParts)
+       {
+               ILNode *otherPart;
+               ILNode_ListIter iter;
+
+               ILNode_ListIter_Init(&iter, defn->otherParts);
+               while((otherPart = ILNode_ListIter_Next(&iter)) != 0)
+               {
+                       if(yyisa(otherPart, ILNode_ClassDefn))
+                       {
+                               count += CountBaseClasses(((ILNode_ClassDefn 
*)otherPart)->baseClass);
+                       }
+               }
+       }
+#endif /* IL_VERSION_MAJOR > 1 */
+
+       return count;
+}
+
+/*
  * Convert a class definition node into an ILClass value.
  */
 static ILClass *NodeToClass(ILNode *node)
@@ -684,12 +712,20 @@ static void AddBaseClasses(ILGenInfo *info,
 {
        ILClass *classInfo = classNode->classInfo;
 
+#if IL_VERSION_MAJOR > 1
+       if(classNode->partialParent)
+       {
+               /* This is handled by the main part of the partial class */
+               return;
+       }
+#endif /* IL_VERSION_MAJOR > 1 */
+
        if(classInfo && (classInfo != (ILClass *)1) &&
                                        (classInfo != (ILClass *)2))
        {
                int baseClassAllowed;
                ILProgramItem *parent = 0;
-               ILUInt32 numBases = CountBaseClasses(classNode->baseClass);
+               ILUInt32 numBases = NumBases(classNode);
 
                /* Only classes can have an explicit  base class */
                baseClassAllowed = ((classNode->modifiers & 
CS_MODIFIER_TYPE_MASK) ==
@@ -718,6 +754,58 @@ static void AddBaseClasses(ILGenInfo *info,
                                                                   &numBases, 
baseClassAllowed);
                        }
 
+               #if IL_VERSION_MAJOR > 1
+                       if(classNode->otherParts)
+                       {
+                               ILUInt32 numPartBases;
+                               ILNode_ListIter iter;
+                               ILNode *part;
+
+                               ILNode_ListIter_Init(&iter, 
classNode->otherParts);
+                               while((part = ILNode_ListIter_Next(&iter)) != 0)
+                               {
+                                       if(yykind(part) == 
yykindof(ILNode_ClassDefn))
+                                       {
+                                               ILNode_ClassDefn *partDefn;
+
+                                               partDefn = (ILNode_ClassDefn 
*)part;
+                                               numPartBases = 
CountBaseClasses(partDefn->baseClass);
+                                               if(numPartBases > 0)
+                                               {
+                                                       ILProgramItem 
*partParent;
+                                                       ILProgramItem 
*partBaseList[numPartBases];
+
+                                                       partParent = 0;
+                                                       ILMemZero(partBaseList,
+                                                                         
numPartBases * sizeof(ILClass *));
+
+                                                       
CollectBaseClasses(info, partDefn, &partParent,
+                                                                               
           partBaseList, &numPartBases,
+                                                                               
           baseClassAllowed);
+                                                       if(!parent)
+                                                       {
+                                                               parent = 
partParent;
+                                                       }
+                                                       else
+                                                       {
+                                                               if(partParent 
&& (partParent != parent))
+                                                               {
+                                                                       
CCErrorOnLine(yygetfilename(partDefn),
+                                                                               
                  yygetlinenum(partDefn),
+                                                                       "Base 
class mismatch in partial class");
+                                                               }
+                                                       }
+
+                                                       /* Add the interfaces 
to the main part list */
+                                                       for(base = 0; base < 
numPartBases; ++base)
+                                                       {
+                                                               
baseList[numBases++] = partBaseList[base];
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               #endif /* IL_VERSION_MAJOR > 1 */
                        if(parent)
                        {
                                if(ILClass_IsInterface(classInfo))
@@ -1050,6 +1138,35 @@ static void CreateType(ILGenInfo *info, ILScope 
*globalScope,
                return;
        }
 
+#if IL_VERSION_MAJOR > 1
+       if(defn->partialParent)
+       {
+               /* This is an additional part of a partial type declaration */
+               if(defn->partialParent->classInfo == 0)
+               {
+                       /* This should not happen but i'm kindof paranoid here 
*/
+                       CreateType(info, globalScope, list,
+                                  systemObjectName, (ILNode 
*)(defn->partialParent));
+               }
+               /*
+                * Get the classInfo of the partial parent and use this one for 
this
+                * part too since this one is for the same class.
+                */
+               defn->classInfo = defn->partialParent->classInfo;
+
+               /* Process the nested types */
+               CreateNestedTypes(info, globalScope, list, systemObjectName, 
defn);
+
+               /* Add the type to the list of nested classes in the nested 
parent if it's a nested type */
+               if(defn->nestedParent)
+               {
+                       AddTypeToList(list, defn);
+               }
+
+               return;
+       }
+#endif /* IL_VERSION_MAJOR > 1 */
+
        /* Mark this type as already seen so that we can detect recursion */
        defn->classInfo = (ILClass *)2;
 
@@ -1477,7 +1594,17 @@ static void CreateField(ILGenInfo *info, 
ILNode_ClassDefn *classNode,
        ILUInt32 fieldAttrs;
 
 #if IL_VERSION_MAJOR > 1
-       if((classNode->modifiers & CS_MODIFIER_STATIC) != 0)
+       ILUInt32 classModifiers;
+
+       if(classNode->partialParent)
+       {
+               classModifiers = classNode->partialParent->modifiers;
+       }
+       else
+       {
+               classModifiers = classNode->modifiers;
+       }
+       if((classModifiers & CS_MODIFIER_STATIC) != 0)
        {
                /* Constants are static by default */
                if((field->modifiers & CS_MODIFIER_FIELD_CONST) == 0)
@@ -1954,8 +2081,17 @@ static void CreateMethod(ILGenInfo *info, 
ILNode_ClassDefn *classNode,
        ILClass *classInfo;
 #if IL_VERSION_MAJOR > 1
        ILNode *savedMethod;
+       ILUInt32 classModifiers;
 
-       if((classNode->modifiers & CS_MODIFIER_STATIC) != 0)
+       if(classNode->partialParent)
+       {
+               classModifiers = classNode->partialParent->modifiers;
+       }
+       else
+       {
+               classModifiers = classNode->modifiers;
+       }
+       if((classModifiers & CS_MODIFIER_STATIC) != 0)
        {
                /* Only static methods are allowed */
                if((method->modifiers & CS_MODIFIER_STATIC) == 0)
@@ -2512,7 +2648,17 @@ static void CreateProperty(ILGenInfo *info, 
ILNode_ClassDefn *classNode,
        ILClass *classInfo;
 
 #if IL_VERSION_MAJOR > 1
-       if((classNode->modifiers & CS_MODIFIER_STATIC) != 0)
+       ILUInt32 classModifiers;
+
+       if(classNode->partialParent)
+       {
+               classModifiers = classNode->partialParent->modifiers;
+       }
+       else
+       {
+               classModifiers = classNode->modifiers;
+       }
+       if((classModifiers & CS_MODIFIER_STATIC) != 0)
        {
                /* Only static methods are allowed */
                if((property->modifiers & CS_MODIFIER_STATIC) == 0)
@@ -2962,7 +3108,17 @@ static void CreateEventDecl(ILGenInfo *info, 
ILNode_ClassDefn *classNode,
        ILClass *classInfo;
 
 #if IL_VERSION_MAJOR > 1
-       if((classNode->modifiers & CS_MODIFIER_STATIC) != 0)
+       ILUInt32 classModifiers;
+
+       if(classNode->partialParent)
+       {
+               classModifiers = classNode->partialParent->modifiers;
+       }
+       else
+       {
+               classModifiers = classNode->modifiers;
+       }
+       if((classModifiers & CS_MODIFIER_STATIC) != 0)
        {
                /* Only static fields or constants are allowed */
                if((event->modifiers & CS_MODIFIER_STATIC) == 0)
@@ -3668,6 +3824,21 @@ static void CreateMembers(ILGenInfo *info, ILScope 
*globalScope,
                }
        }
 
+#if IL_VERSION_MAJOR > 1
+       /* If this is a top level class create the members for the other parts 
too */
+       if(!(classNode->nestedParent) && (classNode->otherParts))
+       {
+               ILNode_ListIter_Init(&iterator, classNode->otherParts);
+               while((member = ILNode_ListIter_Next(&iterator)) != 0)
+               {
+                       if(yykind(member) == yykindof(ILNode_ClassDefn))
+                       {
+                               CreateMembers(info, globalScope, 
(ILNode_ClassDefn *)member);
+                       }
+               }
+       }
+#endif /* IL_VERSION_MAJOR > 1 */
+
        /* Add the "DefaultMember" attribute to the class if necessary */
        if(defaultMemberName)
        {
@@ -3691,6 +3862,175 @@ static void CreateMembers(ILGenInfo *info, ILScope 
*globalScope,
        info->currentNamespace = savedNamespace;
 }
 
+#if IL_VERSION_MAJOR > 1
+static void DeclareTypes(ILGenInfo *info, ILScope *parentScope,
+                                                ILNode *tree, ILNode_List 
*list,
+                                                ILNode_ClassDefn 
*nestedParent);
+
+static const char *FlagTypeToName(ILUInt32 modifiers)
+{
+       switch(modifiers & CS_MODIFIER_TYPE_MASK)
+       {
+               case CS_MODIFIER_TYPE_CLASS:
+               {
+                       return "class";
+               }
+               break;
+
+               case CS_MODIFIER_TYPE_STRUCT:
+               {
+                       return "struct";
+               }
+               break;
+
+               case CS_MODIFIER_TYPE_INTERFACE:
+               {
+                       return "interface";
+               }
+               break;
+
+               case CS_MODIFIER_TYPE_ENUM:
+               {
+                       return "enum";
+               }
+               break;
+
+               case CS_MODIFIER_TYPE_DELEGATE:
+               {
+                       return "delegate";
+               }
+               break;
+
+               case CS_MODIFIER_TYPE_MODULE:
+               {
+                       return "module";
+               }
+               break;
+       }
+       return "Unknown";
+}
+/*
+ * Handle partial class declarations
+ */
+static void DeclareTypePart(ILGenInfo *info, ILNode_List *list,
+                                                       ILScope *scope, 
ILNode_ClassDefn *defn,
+                                                       ILNode_ClassDefn 
*existingDefn,
+                                                       ILNode_ClassDefn 
*nestedParent,
+                                                       const char *name, const 
char *namespace)
+{
+       if((defn->modifiers & CS_MODIFIER_PARTIAL) != 0)
+       {
+               if((existingDefn->modifiers & CS_MODIFIER_PARTIAL) == 0)
+               {
+                       CCErrorOnLine(yygetfilename(defn), yygetlinenum(defn),
+                                                 "`%s%s%s' already declared 
not partial",
+                                                 (namespace ? namespace : ""),
+                                                 (namespace ? "." : ""), name);
+                       CCErrorOnLine(yygetfilename(existingDefn),
+                                                 yygetlinenum(existingDefn),
+                                                 "the declaration was here");
+                       return;
+               }
+
+               if((existingDefn->modifiers & CS_MODIFIER_TYPE_MASK) !=
+                  (defn->modifiers & CS_MODIFIER_TYPE_MASK))
+               {
+                       /* class, struct or interface mismatch */
+                       CCErrorOnLine(yygetfilename(defn), yygetlinenum(defn),
+                                                 "partial `%s' is already 
declared as partial `%s'",
+                                                 
FlagTypeToName(defn->modifiers),
+                                                 
FlagTypeToName(existingDefn->modifiers));
+                       CCErrorOnLine(yygetfilename(existingDefn),
+                                                 yygetlinenum(existingDefn),
+                                                 "the partial `%s' declaration 
was here",
+                                                 
FlagTypeToName(existingDefn->modifiers));
+               }
+
+               if((defn->modifiers & CS_MODIFIER_ACCESS_MASK) == 0)
+               {
+                       /* OK */
+               }
+               else if((existingDefn->modifiers & CS_MODIFIER_ACCESS_MASK) == 
0)
+               {
+                       /*
+                        * The first part has no accessibility defined so set 
the
+                        * accessibility of the first part to the same 
definition as
+                        * this part.
+                        */
+                       existingDefn->modifiers |= (defn->modifiers & 
CS_MODIFIER_ACCESS_MASK);
+               }
+               else if((existingDefn->modifiers & CS_MODIFIER_ACCESS_MASK) !=
+                               (defn->modifiers & CS_MODIFIER_ACCESS_MASK))
+               {
+                       /* accessibility mismatch */
+                       CCErrorOnLine(yygetfilename(defn), yygetlinenum(defn),
+                                                 "accessibility mismatch with 
an other part of the %s",
+                                                 
FlagTypeToName(defn->modifiers));
+                       CCErrorOnLine(yygetfilename(existingDefn),
+                                                 yygetlinenum(existingDefn),
+                                                 "the other declaration was 
here");
+               }
+
+               if((defn->modifiers & CS_MODIFIER_ABSTRACT) != 0)
+               {
+                       existingDefn->modifiers |= CS_MODIFIER_ABSTRACT;
+               }
+
+               if((defn->modifiers & CS_MODIFIER_SEALED) != 0)
+               {
+                       existingDefn->modifiers |= CS_MODIFIER_SEALED;
+               }
+
+               if((defn->modifiers & CS_MODIFIER_STATIC) != 0)
+               {
+                       existingDefn->modifiers |= CS_MODIFIER_STATIC;
+               }
+
+               /*
+                * set the flag if a default ctor is defined in the first part
+                * if there is one in any other part so that no default ctor is
+                * created automatically for classes.
+                */
+               if((defn->modifiers & CS_MODIFIER_CTOR_DEFINED) != 0)
+               {
+                       existingDefn->modifiers |= CS_MODIFIER_CTOR_DEFINED;
+               }
+
+               /* Remember the first declared partial declaration */
+               defn->partialParent = existingDefn;
+
+               /* Add this part to the list of other parts in the main part */
+               if(!(existingDefn->otherParts))
+               {
+                       existingDefn->otherParts = ILNode_List_create();
+               }
+               ILNode_List_Add(existingDefn->otherParts, (ILNode *)defn);
+
+               /* Declare nested types in this part */
+               DeclareTypes(info, scope, defn->body, list, existingDefn);
+
+               /* Replace the class body with a scoped body */
+               defn->body = ILNode_ScopeChange_create(scope, defn->body);
+
+               /* Add the type to the end of the new top-level list */
+               if(!nestedParent)
+               {
+                       ILNode_List_Add(list, (ILNode *)defn);
+               }
+       }
+       else
+       {
+               CCErrorOnLine(yygetfilename(defn), yygetlinenum(defn),
+                                         "`%s%s%s' already declared",
+                                         (namespace ? namespace : ""),
+                                         (namespace ? "." : ""), name);
+               CCErrorOnLine(yygetfilename(existingDefn),
+                                         yygetlinenum(existingDefn),
+                                         "previous declaration here");
+       }
+}
+#endif /* IL_VERSION_MAJOR > 1 */
+
 /*
  * Scan all types and their nested children to declare them.
  */
@@ -3763,6 +4103,11 @@ static void DeclareTypes(ILGenInfo *info, ILScope 
*parentScope,
 
                                        case IL_SCOPE_ERROR_REDECLARED:
                                        {
+                                       #if IL_VERSION_MAJOR > 1
+                                               DeclareTypePart(info, list, 
scope, defn,
+                                                                               
(ILNode_ClassDefn *)origDefn,
+                                                                               
nestedParent, name, namespace);
+                                       #else  /* IL_VERSION_MAJOR == 1 */
                                                
CCErrorOnLine(yygetfilename(child), yygetlinenum(child),
                                                                "`%s%s%s' 
already declared",
                                                                (namespace ? 
namespace : ""),
@@ -3770,6 +4115,7 @@ static void DeclareTypes(ILGenInfo *info, ILScope 
*parentScope,
                                                
CCErrorOnLine(yygetfilename(origDefn),
                                                                          
yygetlinenum(origDefn),
                                                                          
"previous declaration here");
+                                       #endif /* IL_VERSION_MAJOR == 1 */
                                        }
                                        break;
 
diff --git a/cscc/csharp/cs_grammar.y b/cscc/csharp/cs_grammar.y
index c574dc3..c9b9881 100644
--- a/cscc/csharp/cs_grammar.y
+++ b/cscc/csharp/cs_grammar.y
@@ -960,13 +960,11 @@ static ILNode_GenericTypeParameters 
*TypeActualsToTypeFormals(ILNode *typeArgume
        {
                ILNode             *attributes;
                ILUInt32                modifiers;
-               ILUInt32                partial;
        }                               typeHeader;
        struct
        {
                ILNode             *attributes;
                ILUInt32                modifiers;
-               ILUInt32                partial;
                ILNode             *identifier;
                ILNode             *classBase;
                ILNode_GenericTypeParameters *typeFormals;
@@ -3204,8 +3202,7 @@ AttributesAndModifiers
 OptTypeDeclarationHeader
        : OptAttributesAndModifiers OptPartial  {
                                $$.attributes = $1.attributes;
-                               $$.modifiers = $1.modifiers;
-                               $$.partial = $2;
+                               $$.modifiers = $1.modifiers | $2;
                        }
        ;
 
@@ -3216,7 +3213,6 @@ ClassHeader
        : OptTypeDeclarationHeader CLASS Identifier ClassBase   {
                                $$.attributes = $1.attributes;
                                $$.modifiers = $1.modifiers;
-                               $$.partial = $1.partial;
                                $$.identifier = $3;
                                $$.classBase = $4;
                                $$.typeFormals = 0;
@@ -3226,7 +3222,6 @@ ClassHeader
 #if IL_VERSION_MAJOR > 1
                                $$.attributes = $1.attributes;
                                $$.modifiers = $1.modifiers;
-                               $$.partial = $1.partial;
                                $$.identifier = $3;
                                $$.classBase = $5;
                                $$.typeFormals = $4;
@@ -3236,7 +3231,6 @@ ClassHeader
                                                          "generics are not 
supported in this version");
                                $$.attributes = $1.attributes;
                                $$.modifiers = $1.modifiers;
-                               $$.partial = $1.partial;
                                $$.identifier = $3;
                                $$.classBase = $5;
                                $$.typeFormals = 0;
@@ -3537,8 +3531,12 @@ ClassMemberDeclaration
 OptPartial
        : /* empty */                           { $$ = 0; }
        | PARTIAL                                       {
-                               $$ = 1;
-                               CCError(_("partial types are not yet 
supported"));
+#if IL_VERSION_MAJOR > 1
+                               $$ = CS_MODIFIER_PARTIAL;
+#else /* IL_VERSION_MAJOR == 1 */
+                               $$ = 0;
+                               CCError(_("partial types are not supported in 
this version"));
+#endif /* IL_VERSION_MAJOR == 1 */
                        }
        ;
 
@@ -4317,7 +4315,6 @@ StructHeader
        : OptTypeDeclarationHeader STRUCT Identifier StructInterfaces   {
                                $$.attributes = $1.attributes;
                                $$.modifiers = $1.modifiers;
-                               $$.partial = $1.partial;
                                $$.identifier = $3;
                                $$.classBase = $4;
                                $$.typeFormals = 0;
@@ -4327,7 +4324,6 @@ StructHeader
 #if IL_VERSION_MAJOR > 1
                                $$.attributes = $1.attributes;
                                $$.modifiers = $1.modifiers;
-                               $$.partial = $1.partial;
                                $$.identifier = $3;
                                $$.classBase = $5;
                                $$.typeFormals = $4;
@@ -4337,7 +4333,6 @@ StructHeader
                                                          "generics are not 
supported in this version");
                                $$.attributes = $1.attributes;
                                $$.modifiers = $1.modifiers;
-                               $$.partial = $1.partial;
                                $$.identifier = $3;
                                $$.classBase = $5;
                                $$.typeFormals = 0;
@@ -4402,7 +4397,6 @@ InterfaceHeader
        : OptTypeDeclarationHeader INTERFACE Identifier InterfaceBase   {
                                $$.attributes = $1.attributes;
                                $$.modifiers = $1.modifiers;
-                               $$.partial = $1.partial;
                                $$.identifier = $3;
                                $$.classBase = $4;
                                $$.typeFormals = 0;
@@ -4412,7 +4406,6 @@ InterfaceHeader
 #if IL_VERSION_MAJOR > 1
                                $$.attributes = $1.attributes;
                                $$.modifiers = $1.modifiers;
-                               $$.partial = $1.partial;
                                $$.identifier = $3;
                                $$.classBase = $5;
                                $$.typeFormals = $4;
@@ -4422,7 +4415,6 @@ InterfaceHeader
                                                          "generics are not 
supported in this version");
                                $$.attributes = $1.attributes;
                                $$.modifiers = $1.modifiers;
-                               $$.partial = $1.partial;
                                $$.identifier = $3;
                                $$.classBase = $5;
                                $$.typeFormals = 0;
diff --git a/cscc/csharp/cs_internal.h b/cscc/csharp/cs_internal.h
index f9e61ed..ac7b4c3 100644
--- a/cscc/csharp/cs_internal.h
+++ b/cscc/csharp/cs_internal.h
@@ -104,6 +104,9 @@ struct PropertyAccessors
 #define        CS_MODIFIER_EXTERN                      (1<<11)
 #define        CS_MODIFIER_UNSAFE                      (1<<12)
 #define        CS_MODIFIER_VOLATILE            (1<<13)
+#if IL_VERSION_MAJOR > 1
+#define        CS_MODIFIER_PARTIAL                     (1<<14)
+#endif /* IL_VERSION_MAJOR > 1 */
 #define        CS_MODIFIER_MASK                        (0x0000FFFF)
 
 /* Type specific modifier flags */

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog                 |   48 ++++++-
 codegen/cg_decls.tc       |   62 +++++++-
 codegen/cg_nodes.tc       |    2 +
 cscc/csharp/cs_attrs.c    |  146 +++++++++++++++---
 cscc/csharp/cs_decls.tc   |  123 ++++++++++++++--
 cscc/csharp/cs_gather.c   |  356 ++++++++++++++++++++++++++++++++++++++++++++-
 cscc/csharp/cs_grammar.y  |   22 +--
 cscc/csharp/cs_internal.h |    3 +
 8 files changed, 696 insertions(+), 66 deletions(-)


hooks/post-receive
-- 
DotGNU Portable.NET engine, compilers and tools (pnet)




reply via email to

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