[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[dotgnu-pnet-commits] pnet ChangeLog codegen/cg_decls.tc codegen/cg_g...
From: |
Klaus Treichel |
Subject: |
[dotgnu-pnet-commits] pnet ChangeLog codegen/cg_decls.tc codegen/cg_g... |
Date: |
Thu, 16 Apr 2009 15:34:55 +0000 |
CVSROOT: /cvsroot/dotgnu-pnet
Module name: pnet
Changes by: Klaus Treichel <ktreichel> 09/04/16 15:34:55
Modified files:
. : ChangeLog
codegen : cg_decls.tc cg_gen.h cg_nodes.tc
cscc/csharp : cs_attrs.c cs_decls.tc cs_gather.c
cs_internal.h cs_grammar.y
include : il_program.h
Log message:
Add support for custom attributes attached to generic type parameters.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pnet/ChangeLog?cvsroot=dotgnu-pnet&r1=1.3615&r2=1.3616
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_decls.tc?cvsroot=dotgnu-pnet&r1=1.62&r2=1.63
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_gen.h?cvsroot=dotgnu-pnet&r1=1.52&r2=1.53
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_nodes.tc?cvsroot=dotgnu-pnet&r1=1.96&r2=1.97
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/csharp/cs_attrs.c?cvsroot=dotgnu-pnet&r1=1.31&r2=1.32
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/csharp/cs_decls.tc?cvsroot=dotgnu-pnet&r1=1.45&r2=1.46
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/csharp/cs_gather.c?cvsroot=dotgnu-pnet&r1=1.63&r2=1.64
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/csharp/cs_internal.h?cvsroot=dotgnu-pnet&r1=1.28&r2=1.29
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/csharp/cs_grammar.y?cvsroot=dotgnu-pnet&r1=1.91&r2=1.92
http://cvs.savannah.gnu.org/viewcvs/pnet/include/il_program.h?cvsroot=dotgnu-pnet&r1=1.66&r2=1.67
Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/ChangeLog,v
retrieving revision 1.3615
retrieving revision 1.3616
diff -u -b -r1.3615 -r1.3616
--- ChangeLog 15 Apr 2009 16:55:45 -0000 1.3615
+++ ChangeLog 16 Apr 2009 15:34:54 -0000 1.3616
@@ -1,3 +1,36 @@
+2009-04-16 Klaus Treichel <address@hidden>
+
+ * codegen/cg_decls.tc (ILGenOutputGenericParamAttributes): Add support
+ function to emit custom attributes arrached to a generic parameter.
+ (ILNode_GenDiscard(ILNode_ClassDefn)): Emit custom attributes attached
+ to generic parameters.
+ (MethodGenDiscard): likewise.
+
+ * codegen/cg_gen.h: Add prototype for ILGenOutputGenericParamAttributes.
+
+ * codegen/cg_nodes.tc (ILNode_GenericTypeParameter): Rename member attrs
+ to attributes for more consistency.
+
+ * cscc/csharp/cs_attrs.c: Change usages of CS_ATTR_* to
+ IL_ATTRIBUTE_TARGET_* to use the defines moved to il_program.h.
+
+ * cscc/csharp/cs_decls.tc: Change usages of CS_ATTR_* to
+ IL_ATTRIBUTE_TARGET_* to use the defines moved to il_program.h.
+ (ILNode_SemAnalysis(ILNode_ClassDefn)): Perform semantic analysis of the
+ generic type parameters later in the process and set the context
propperly.
+ (ILNode_SemAnalysis(ILNode_GenericTypeParameter)): Process the custom
+ attributes attached to the generic parameter.
+
+ * cscc/csharp/cs_gather.c (_AddTypeFormalWithCheck): Store the generic
+ parameter created in the ILNode_GenericTypeParameter.
+
+ * cscc/csharp/cs_internal.h: Remove the CS_ATTR_* definitions.
+
+ * cscc/csharp/cs_grammar.y: Allow and handle custom attributes in
+ TypeFormals.
+
+ * include/il_program.h: Add definition of the attribute targets.
+
2009-04-15 Klaus Treichel <address@hidden>
* cacc/csharp/cs_grammar.y (GetAccessorAttrs): Add function for handling
Index: codegen/cg_decls.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_decls.tc,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -b -r1.62 -r1.63
--- codegen/cg_decls.tc 16 Mar 2009 19:50:25 -0000 1.62
+++ codegen/cg_decls.tc 16 Apr 2009 15:34:54 -0000 1.63
@@ -106,6 +106,27 @@
}
/*
+ * Output the attributes attached to generic parameters of a program item.
+ */
+void ILGenOutputGenericParamAttributes(ILGenInfo *info, FILE *stream,
ILProgramItem *item)
+{
+ ILUInt32 numGenericParams = ILGenericParGetNumParams(item);
+ ILUInt32 current = 0;
+
+ for(current = 0; current < numGenericParams; current++)
+ {
+ ILGenericPar *genPar = ILGenericParGetFromOwner(item, current);
+
+ /* Check if the generic parameter has any attributes */
+ if(ILProgramItemNextAttribute(ILToProgramItem(genPar), 0) != 0)
+ {
+ fprintf(stream, ".param type [%X]\n", current + 1);
+ ILGenOutputAttributes(info, stream,
ILToProgramItem(genPar));
+ }
+ }
+}
+
+/*
* Determine if a class has no instance fields.
*/
static int ClassIsEmpty(ILClass *classInfo)
@@ -220,6 +241,12 @@
ILGenOutputAttributes
(info, info->asmOutput, (ILProgramItem *)classInfo);
+ #if IL_VERSION_MAJOR > 1
+ /* Output the attributes attached to generic parameters of the
class */
+ ILGenOutputGenericParamAttributes
+ (info, info->asmOutput, (ILProgramItem *)classInfo);
+ #endif /* IL_VERSION_MAJOR > 1 */
+
/* Output the class layout information */
if(layout)
{
@@ -808,6 +835,12 @@
/* Output the attributes that are attached to the field */
ILGenOutputAttributes(info, outstream, (ILProgramItem *)method);
+#if IL_VERSION_MAJOR > 1
+ /* Output the attributes attached to generic parameters of the method */
+ ILGenOutputGenericParamAttributes(info, outstream,
+
(ILProgramItem *)method);
+#endif /* IL_VERSION_MAJOR > 1 */
+
/* Output the attributes that are attached to the parameters */
param = 0;
while((param = ILMethodNextParam(method, param)) != 0)
@@ -1112,7 +1145,7 @@
#if IL_VERSION_MAJOR > 1
if (info->asmOutput)
{
- if(node->attrs)
+ if(node->attributes)
{
if(node->target == ILGenParamTarget_Class)
{
Index: codegen/cg_gen.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_gen.h,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -b -r1.52 -r1.53
--- codegen/cg_gen.h 14 Dec 2008 15:20:00 -0000 1.52
+++ codegen/cg_gen.h 16 Apr 2009 15:34:54 -0000 1.53
@@ -340,6 +340,12 @@
*/
void ILGenOutputAttributes(ILGenInfo *info, FILE *stream, ILProgramItem *item);
+/*
+ * Output the attributes attached to generic parameters of a program item.
+ */
+void ILGenOutputGenericParamAttributes(ILGenInfo *info, FILE *stream,
+
ILProgramItem *item);
+
#ifdef __cplusplus
};
#endif
Index: codegen/cg_nodes.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_nodes.tc,v
retrieving revision 1.96
retrieving revision 1.97
diff -u -b -r1.96 -r1.97
--- codegen/cg_nodes.tc 2 Jan 2009 14:33:06 -0000 1.96
+++ codegen/cg_nodes.tc 16 Apr 2009 15:34:54 -0000 1.97
@@ -991,7 +991,7 @@
const char *name;
ILUInt32 constraint;
ILNode_List *typeConstraints;
- %nocreate ILNode *attrs = {0};
+ %nocreate ILNode *attributes = {0};
%nocreate ILType *mainType = {0};
%nocreate ILGenericPar *genPar = {0};
%nocreate ILGenParamTarget target = {ILGenParamTarget_Class};
Index: cscc/csharp/cs_attrs.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_attrs.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -b -r1.31 -r1.32
--- cscc/csharp/cs_attrs.c 18 Nov 2008 20:06:04 -0000 1.31
+++ cscc/csharp/cs_attrs.c 16 Apr 2009 15:34:54 -0000 1.32
@@ -965,20 +965,20 @@
/* Assembly targets can be applied
anywhere */
item = (ILProgramItem
*)ILAssembly_FromToken
(ILProgramItem_Image(item),
IL_META_TOKEN_ASSEMBLY | 1);
- target = CS_ATTR_ASSEMBLY;
+ target = IL_ATTRIBUTE_TARGET_ASSEMBLY;
}
else if(!strcmp(targetName, "module"))
{
/* Module targets can be applied
anywhere */
item = (ILProgramItem
*)ILModule_FromToken
(ILProgramItem_Image(item),
IL_META_TOKEN_MODULE | 1);
- target = CS_ATTR_MODULE;
+ target = IL_ATTRIBUTE_TARGET_MODULE;
}
else if(!strcmp(targetName, "field"))
{
/* Field targets can apply to fields or
events */
item = GetFieldTarget(info, item);
- target = CS_ATTR_FIELD;
+ target = IL_ATTRIBUTE_TARGET_FIELD;
}
else if(!strcmp(targetName, "method"))
{
@@ -1001,7 +1001,7 @@
if(numParams == 1)
{
item =
GetParamTarget(info, method, 1);
- target =
CS_ATTR_PARAMETER;
+ target =
IL_ATTRIBUTE_TARGET_PARAMETER;
}
else
{
@@ -1094,7 +1094,7 @@
"in this context"));
continue;
}
- target = CS_ATTR_RETURNVALUE;
+ target = IL_ATTRIBUTE_TARGET_RETURNVALUE;
}
break;
}
@@ -1135,7 +1135,7 @@
}
/* Process the attributes for the parameter */
- return CSProcessAttrs(info, item, attributes, CS_ATTR_PARAMETER);
+ return CSProcessAttrs(info, item, attributes,
IL_ATTRIBUTE_TARGET_PARAMETER);
}
void CSAddDefaultMemberAttr(ILGenInfo *info, ILClass *classInfo,
Index: cscc/csharp/cs_decls.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_decls.tc,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -b -r1.45 -r1.46
--- cscc/csharp/cs_decls.tc 7 Nov 2007 16:39:41 -0000 1.45
+++ cscc/csharp/cs_decls.tc 16 Apr 2009 15:34:54 -0000 1.46
@@ -132,14 +132,6 @@
}
node->visited = ILVisitMode_Processing;
-#if IL_VERSION_MAJOR > 1
- /* perform the semantic analysis for the generic type parameters */
- if(node->typeFormals)
- {
- ILNode_SemAnalysis(node->typeFormals, info,
&(node->typeFormals));
- }
-#endif /* IL_VERSION_MAJOR > 1 */
-
/* Process the attributes for the class */
if(node->defaultMemberName)
{
@@ -147,23 +139,23 @@
}
if(ILClass_IsInterface(node->classInfo))
{
- target = CS_ATTR_INTERFACE;
+ target = IL_ATTRIBUTE_TARGET_INTERFACE;
}
else if(ILTypeIsEnum(ILType_FromValueType(node->classInfo)))
{
- target = CS_ATTR_ENUM;
+ target = IL_ATTRIBUTE_TARGET_ENUM;
}
else if(ILTypeIsDelegate(ILType_FromClass(node->classInfo)))
{
- target = CS_ATTR_DELEGATE;
+ target = IL_ATTRIBUTE_TARGET_DELEGATE;
}
else if(ILClassIsValueType(node->classInfo))
{
- target = CS_ATTR_STRUCT;
+ target = IL_ATTRIBUTE_TARGET_STRUCT;
}
else
{
- target = CS_ATTR_CLASS;
+ target = IL_ATTRIBUTE_TARGET_CLASS;
}
if(node->attributes)
{
@@ -180,6 +172,23 @@
info->currentMethod = savedMethod;
}
+#if IL_VERSION_MAJOR > 1
+ /* perform the semantic analysis for the generic type parameters */
+ if(node->typeFormals)
+ {
+ savedClass = info->currentClass;
+ savedNamespace = info->currentNamespace;
+ savedMethod = info->currentMethod;
+ info->currentClass = (ILNode *)node;
+ info->currentNamespace = node->namespaceNode;
+ info->currentMethod = NULL;
+ ILNode_SemAnalysis(node->typeFormals, info,
&(node->typeFormals));
+ info->currentClass = savedClass;
+ info->currentNamespace = savedNamespace;
+ info->currentMethod = savedMethod;
+ }
+#endif /* IL_VERSION_MAJOR > 1 */
+
/* Perform semantic analysis on the node */
hadStaticCtorsBefore = (node->staticCtors != 0);
if((node->modifiers & CS_SPECIALATTR_UNSAFE) != 0)
@@ -751,7 +760,7 @@
if(node->owner && node->fieldInfo)
{
CSProcessAttrs(info, ILToProgramItem(node->fieldInfo),
- node->owner->attributes,
CS_ATTR_FIELD);
+ node->owner->attributes,
IL_ATTRIBUTE_TARGET_FIELD);
/* Reset the attributes, in case there are multiple fields */
/* TODO: handle attrs for multiple fields in the same
declaration */
@@ -908,7 +917,7 @@
if(node->backLink)
{
CSProcessAttrs(info, ILToProgramItem(node->eventInfo),
- node->backLink->attributes,
CS_ATTR_EVENT);
+ node->backLink->attributes,
IL_ATTRIBUTE_TARGET_EVENT);
/* Reset the attributes, in case there are multiple events */
/* TODO: handle attrs for multiple events in the same
declaration */
@@ -968,7 +977,7 @@
ILMethod_IsStaticConstructor(node->methodInfo))
{
CSProcessAttrs(info, ILToProgramItem(node->methodInfo),
- node->attributes,
CS_ATTR_CONSTRUCTOR);
+ node->attributes,
IL_ATTRIBUTE_TARGET_CONSTRUCTOR);
if (ILClassIsValueType(((ILNode_ClassDefn
*)info->currentClass)->classInfo)
&& ILMethod_IsConstructor(node->methodInfo))
@@ -987,7 +996,7 @@
else
{
CSProcessAttrs(info, ILToProgramItem(node->methodInfo),
- node->attributes, CS_ATTR_METHOD);
+ node->attributes,
IL_ATTRIBUTE_TARGET_METHOD);
}
/* Record the current method that we are in */
@@ -1181,7 +1190,7 @@
/* Process attributes on the property */
CSProcessAttrs(info, ILToProgramItem(node->propertyInfo),
- node->attributes, CS_ATTR_PROPERTY);
+ node->attributes,
IL_ATTRIBUTE_TARGET_PROPERTY);
/* Enter an unsafe context for the property if necessary */
if((node->modifiers & CS_SPECIALATTR_UNSAFE) != 0)
@@ -1239,7 +1248,7 @@
/* Process attributes on the enumerated value */
CSProcessAttrs(info, ILToProgramItem(node->fieldInfo),
- node->attributes, CS_ATTR_FIELD);
+ node->attributes, IL_ATTRIBUTE_TARGET_FIELD);
/* Determine the type of the enumeration */
type = ILClassToType(defn->classInfo);
@@ -1437,7 +1446,7 @@
/* Perform semantic analysis on the attribute, relative to an assembly
*/
item = (ILProgramItem *)ILAssembly_FromToken
(CCCodeGen.image, IL_META_TOKEN_ASSEMBLY | 1);
- CSProcessAttrs(info, item, node->attributes, CS_ATTR_ASSEMBLY);
+ CSProcessAttrs(info, item, node->attributes,
IL_ATTRIBUTE_TARGET_ASSEMBLY);
/* Restore the previous context */
info->currentClass = savedClass;
@@ -1495,6 +1504,10 @@
constraintClass = ILClassImport(info->image,
constraintClass);
}
}
+ /* Process attributes on the generic type parameter */
+ CSProcessAttrs(info, ILToProgramItem(node->genPar),
+ node->attributes,
IL_ATTRIBUTE_TARGET_GENERICPAR);
+
node->visited = ILVisitMode_Done;
}
#endif /* IL_VERSION_MAJOR > 1 */
Index: cscc/csharp/cs_gather.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_gather.c,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -b -r1.63 -r1.64
--- cscc/csharp/cs_gather.c 15 Feb 2009 15:00:57 -0000 1.63
+++ cscc/csharp/cs_gather.c 16 Apr 2009 15:34:55 -0000 1.64
@@ -227,6 +227,7 @@
CCOutOfMemory();
}
ILGenericParSetFlags(genPar, IL_MAX_UINT32, genParam->constraint);
+ genParam->genPar = genPar;
/* Check for duplicate names */
for(current = 0; current < offset; current++)
Index: cscc/csharp/cs_internal.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_internal.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -b -r1.28 -r1.29
--- cscc/csharp/cs_internal.h 15 Apr 2009 16:55:45 -0000 1.28
+++ cscc/csharp/cs_internal.h 16 Apr 2009 15:34:55 -0000 1.29
@@ -288,24 +288,6 @@
void CSAddInitCtor(ILGenInfo *info, ILNode *stmt);
/*
- * Attribute target flags.
- */
-#define CS_ATTR_ASSEMBLY 0x0001
-#define CS_ATTR_MODULE 0x0002
-#define CS_ATTR_CLASS 0x0004
-#define CS_ATTR_STRUCT 0x0008
-#define CS_ATTR_ENUM 0x0010
-#define CS_ATTR_CONSTRUCTOR 0x0020
-#define CS_ATTR_METHOD 0x0040
-#define CS_ATTR_PROPERTY 0x0080
-#define CS_ATTR_FIELD 0x0100
-#define CS_ATTR_EVENT 0x0200
-#define CS_ATTR_INTERFACE 0x0400
-#define CS_ATTR_PARAMETER 0x0800
-#define CS_ATTR_DELEGATE 0x1000
-#define CS_ATTR_RETURNVALUE 0x2000
-
-/*
* Process the attributes on a program item.
*/
void CSProcessAttrs(ILGenInfo *info, ILProgramItem *item,
Index: cscc/csharp/cs_grammar.y
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_grammar.y,v
retrieving revision 1.91
retrieving revision 1.92
diff -u -b -r1.91 -r1.92
--- cscc/csharp/cs_grammar.y 15 Apr 2009 16:55:45 -0000 1.91
+++ cscc/csharp/cs_grammar.y 16 Apr 2009 15:34:55 -0000 1.92
@@ -3476,22 +3476,27 @@
;
TypeFormalList
- : IDENTIFIER {
+ : OptAttributes IDENTIFIER {
+ ILNode *node;
+ ILNode_GenericTypeParameter *genPar;
+ node = ILNode_GenericTypeParameter_create(0,
$2, 0, 0);
+ genPar = (ILNode_GenericTypeParameter *)node;
+ /* Set the custom attributes attached to the
generic parameter */
+ genPar->attributes = $1;
$$.count = 1;
- $$.list = (ILNode_List *)MakeList(0,
- (ILNode
*)ILNode_GenericTypeParameter_create(0,
-
$1,
-
0, 0));
+ $$.list = (ILNode_List *)MakeList(0, node);
}
- | TypeFormalList ',' IDENTIFIER {
+ | TypeFormalList ',' OptAttributes IDENTIFIER {
/* Check for duplicates in the list */
- const char *name = $3;
+ const char *name = $4;
ILNode_ListIter iter;
- ILNode_GenericTypeParameter *node;
+ ILNode *node;
+ ILNode_GenericTypeParameter *genPar;
ILNode_ListIter_Init(&iter, $1.list);
- while((node = (ILNode_GenericTypeParameter
*)ILNode_ListIter_Next(&iter)) != 0)
+ while((node = ILNode_ListIter_Next(&iter)) != 0)
{
- if(!strcmp(node->name, name))
+ genPar = (ILNode_GenericTypeParameter
*)node;
+ if(!strcmp(genPar->name, name))
{
CCErrorOnLine(yygetfilename($1.list), yygetlinenum($1.list),
"`%s' declared multiple times
in generic parameters",
@@ -3501,10 +3506,12 @@
}
/* Add the generic parameter to the list */
- $$.list = (ILNode_List *)MakeList((ILNode
*)($1.list),
- (ILNode
*)ILNode_GenericTypeParameter_create($1.count,
-
name,
-
0, 0));
+ node =
ILNode_GenericTypeParameter_create($1.count, name,
+
0, 0);
+ /* Set the custom attributes attached to the
generic parameter */
+ genPar = (ILNode_GenericTypeParameter *)node;
+ genPar->attributes = $3;
+ $$.list = (ILNode_List *)MakeList((ILNode
*)($1.list), node);
$$.count = $1.count + 1;
}
;
Index: include/il_program.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/include/il_program.h,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -b -r1.66 -r1.67
--- include/il_program.h 16 Mar 2009 19:50:30 -0000 1.66
+++ include/il_program.h 16 Apr 2009 15:34:55 -0000 1.67
@@ -193,6 +193,26 @@
(ILAttribute *)0) != 0)
/*
+ * Values for the attribute target
+ * They must be kept in sync with the System.AttributeTargets enumeration.
+ */
+#define IL_ATTRIBUTE_TARGET_ASSEMBLY 0x00000001
+#define IL_ATTRIBUTE_TARGET_MODULE 0x00000002
+#define IL_ATTRIBUTE_TARGET_CLASS 0x00000004
+#define IL_ATTRIBUTE_TARGET_STRUCT 0x00000008
+#define IL_ATTRIBUTE_TARGET_ENUM 0x00000010
+#define IL_ATTRIBUTE_TARGET_CONSTRUCTOR 0x00000020
+#define IL_ATTRIBUTE_TARGET_METHOD 0x00000040
+#define IL_ATTRIBUTE_TARGET_PROPERTY 0x00000080
+#define IL_ATTRIBUTE_TARGET_FIELD 0x00000100
+#define IL_ATTRIBUTE_TARGET_EVENT 0x00000200
+#define IL_ATTRIBUTE_TARGET_INTERFACE 0x00000400
+#define IL_ATTRIBUTE_TARGET_PARAMETER 0x00000800
+#define IL_ATTRIBUTE_TARGET_DELEGATE 0x00001000
+#define IL_ATTRIBUTE_TARGET_RETURNVALUE 0x00002000
+#define IL_ATTRIBUTE_TARGET_GENERICPAR 0x00004000
+
+/*
* Create a custom attribute within a specific image.
* Returns NULL if out of memory.
*/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [dotgnu-pnet-commits] pnet ChangeLog codegen/cg_decls.tc codegen/cg_g...,
Klaus Treichel <=