[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnet/cscc/csharp cs_attrs.c,1.11,1.12 cs_decl
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnet/cscc/csharp cs_attrs.c,1.11,1.12 cs_decls.tc,1.26,1.27 cs_gather.c,1.28,1.29 cs_internal.h,1.13,1.14 |
Date: |
Thu, 21 Nov 2002 00:25:40 -0500 |
Update of /cvsroot/dotgnu-pnet/pnet/cscc/csharp
In directory subversions:/tmp/cvs-serv7632/cscc/csharp
Modified Files:
cs_attrs.c cs_decls.tc cs_gather.c cs_internal.h
Log Message:
Add the "DefaultMember" attribute to classes that have indexers.
Index: cs_attrs.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_attrs.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -r1.11 -r1.12
*** cs_attrs.c 16 Nov 2002 02:45:32 -0000 1.11
--- cs_attrs.c 21 Nov 2002 05:25:38 -0000 1.12
***************
*** 27,52 ****
#endif
- #if 0
-
- static void AddDllImport(ILProgramItem *item, const char *dllName)
- {
- ILModule *module;
- module = ILModuleRefCreateUnique(ILProgramItem_Image(item), dllName);
- if(!module)
- {
- CCOutOfMemory();
- }
- if(ILPInvokeCreate((ILMethod *)item, 0,
- IL_META_PINVOKE_CALL_CONV_CDECL,
module, 0) == 0)
- {
- CCOutOfMemory();
- }
- ILMemberSetAttrs((ILMember *)item,
- IL_META_METHODDEF_PINVOKE_IMPL,
- IL_META_METHODDEF_PINVOKE_IMPL);
- }
-
- #endif
-
/*
* Get the "field" target for a program item.
--- 27,30 ----
***************
*** 772,812 ****
ILSerializeWriterDestroy(writer);
}
-
- #if 0
- /* Quick and dirty hack: recognise the "DllImport" attribute */
- if(target == CS_ATTR_METHOD)
- {
- ILNode_ListIter iter3;
- ILNode *args, *arg;
- CSSemValue value;
- ILEvalValue evalValue;
- char *name;
-
- name = ILQualIdentName(((ILNode_Attribute *)attr)->name, 0);
- if(!strcmp(name, "DllImport") ||
- !strcmp(name, "DllImportAttribute"))
- {
- args = ((ILNode_AttrArgs *)
- (((ILNode_Attribute
*)attr)->args))
- ->positionalArgs;
- ILNode_ListIter_Init(&iter3, args);
- while((arg = ILNode_ListIter_Next(&iter3)) != 0)
- {
- if(CSSemExpectValue(arg, info, &arg, &value) &&
- ILTypeIsStringClass(CSSemGetType(value)))
- {
- if(ILNode_EvalConst(arg, info,
&evalValue) &&
- evalValue.valueType ==
ILMachineType_String)
- {
- AddDllImport(item,
-
ILInternString(evalValue.un.strValue.str,
-
evalValue.un.strValue.len)
- .string);
- }
- }
- }
- }
- }
- #endif
}
--- 750,753 ----
***************
*** 1023,1026 ****
--- 964,1032 ----
/* Process the attributes for the parameter */
return CSProcessAttrs(info, item, attributes, CS_ATTR_PARAMETER);
+ }
+
+ void CSAddDefaultMemberAttr(ILGenInfo *info, ILClass *classInfo,
+ const char *name)
+ {
+ ILType *type;
+ ILClass *typeInfo;
+ ILMethod *ctor;
+ ILType *args[1];
+ ILSerializeWriter *writer;
+ const void *blob;
+ unsigned long blobLen;
+ ILAttribute *attribute;
+
+ /* Find the constructor for "DefaultMemberAttribute" */
+ type = ILFindNonSystemType(info, "DefaultMemberAttribute",
+ "System.Reflection");
+ if(!type || !ILType_IsClass(type))
+ {
+ return;
+ }
+ typeInfo = ILClassResolve(ILType_ToClass(type));
+ args[0] = ILFindSystemType(info, "String");
+ ctor = ILResolveConstructor(info, typeInfo, classInfo, args, 1);
+ if(!ctor)
+ {
+ return;
+ }
+
+ /* Import the constructor method into this image */
+ ctor = (ILMethod *)ILMemberImport(info->image, (ILMember *)ctor);
+ if(!ctor)
+ {
+ CCOutOfMemory();
+ }
+
+ /* Build the attribute value blob */
+ writer = ILSerializeWriterInit();
+ if(!writer)
+ {
+ CCOutOfMemory();
+ }
+ ILSerializeWriterSetString(writer, name, strlen(name));
+ ILSerializeWriterSetNumExtra(writer, 0);
+ blob = ILSerializeWriterGetBlob(writer, &blobLen);
+ if(!blob)
+ {
+ CCOutOfMemory();
+ }
+
+ /* Attach the attribute to the class */
+ attribute = ILAttributeCreate(info->image, 0);
+ if(!attribute)
+ {
+ CCOutOfMemory();
+ }
+ ILAttributeSetType(attribute, ILToProgramItem(ctor));
+ if(!ILAttributeSetValue(attribute, blob, blobLen))
+ {
+ CCOutOfMemory();
+ }
+ ILProgramItemAddAttribute(ILToProgramItem(classInfo), attribute);
+
+ /* Clean up and exit */
+ ILSerializeWriterDestroy(writer);
}
Index: cs_decls.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_decls.tc,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -r1.26 -r1.27
*** cs_decls.tc 17 Nov 2002 01:04:57 -0000 1.26
--- cs_decls.tc 21 Nov 2002 05:25:38 -0000 1.27
***************
*** 83,86 ****
--- 83,90 ----
/* Process the attributes for the class */
+ if(node->defaultMemberName)
+ {
+ CSAddDefaultMemberAttr(info, node->classInfo,
node->defaultMemberName);
+ }
if(ILClass_IsInterface(node->classInfo))
{
Index: cs_gather.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_gather.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -r1.28 -r1.29
*** cs_gather.c 21 Nov 2002 00:59:53 -0000 1.28
--- cs_gather.c 21 Nov 2002 05:25:38 -0000 1.29
***************
*** 1220,1224 ****
*/
static void CreateProperty(ILGenInfo *info, ILClass *classInfo,
! ILNode_PropertyDeclaration
*property)
{
char *name;
--- 1220,1225 ----
*/
static void CreateProperty(ILGenInfo *info, ILClass *classInfo,
! ILNode_PropertyDeclaration
*property,
! char **defaultMemberName)
{
char *name;
***************
*** 1252,1255 ****
--- 1253,1257 ----
/* Simple property name */
name = ILQualIdentName(property->name, 0);
+ basicName = name;
interfaceOverride = 0;
}
***************
*** 1323,1326 ****
--- 1325,1336 ----
}
+ /* Return the name of this indexer for use in the
+ "DefaultMember" attribute on the containing class */
+ if((property->modifiers & IL_META_METHODDEF_MEMBER_ACCESS_MASK)
+ != IL_META_METHODDEF_PRIVATE)
+ {
+ *defaultMemberName = basicName;
+ }
+
/* Move on to the next parameter */
++paramNum;
***************
*** 1705,1708 ****
--- 1715,1719 ----
ILNode_ListIter iterator;
ILNode *member;
+ char *defaultMemberName;
/* Get the class information block, and bail out if not defined */
***************
*** 1735,1738 ****
--- 1746,1750 ----
/* Iterate over the member definitions in the class body */
+ defaultMemberName = 0;
ILNode_ListIter_Init(&iterator, body);
while((member = ILNode_ListIter_Next(&iterator)) != 0)
***************
*** 1755,1759 ****
{
CreateProperty(info, classInfo,
! (ILNode_PropertyDeclaration
*)member);
}
else if(yykind(member) == yykindof(ILNode_EventDeclaration))
--- 1767,1772 ----
{
CreateProperty(info, classInfo,
! (ILNode_PropertyDeclaration
*)member,
! &defaultMemberName);
}
else if(yykind(member) == yykindof(ILNode_EventDeclaration))
***************
*** 1776,1779 ****
--- 1789,1798 ----
"internal error - do not know how to declare
this member");
}
+ }
+
+ /* Add the "DefaultMember" attribute to the class if necessary */
+ if(defaultMemberName)
+ {
+ ((ILNode_ClassDefn *)classNode)->defaultMemberName =
defaultMemberName;
}
Index: cs_internal.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_internal.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -r1.13 -r1.14
*** cs_internal.h 15 Nov 2002 12:50:57 -0000 1.13
--- cs_internal.h 21 Nov 2002 05:25:38 -0000 1.14
***************
*** 253,256 ****
--- 253,262 ----
ILNode *attributes);
+ /*
+ * Add the "DefaultMember" attribute to a class.
+ */
+ void CSAddDefaultMemberAttr(ILGenInfo *info, ILClass *classInfo,
+ const char *name);
+
#ifdef __cplusplus
};
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnet/cscc/csharp cs_attrs.c,1.11,1.12 cs_decls.tc,1.26,1.27 cs_gather.c,1.28,1.29 cs_internal.h,1.13,1.14,
Rhys Weatherley <address@hidden> <=
- Prev by Date:
[Dotgnu-pnet-commits] CVS: pnetlib/System.Xml NodeList.cs,1.2,1.3 XmlNodeList.cs,1.3,1.4
- Next by Date:
[Dotgnu-pnet-commits] CVS: pnet ChangeLog,1.1873,1.1874
- Previous by thread:
[Dotgnu-pnet-commits] CVS: pnetlib/System.Xml NodeList.cs,1.2,1.3 XmlNodeList.cs,1.3,1.4
- Next by thread:
[Dotgnu-pnet-commits] CVS: pnet ChangeLog,1.1873,1.1874
- Index(es):