[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[dotgnu-pnet-commits] pnet ChangeLog image/class.c image/java_loader....
From: |
Klaus Treichel |
Subject: |
[dotgnu-pnet-commits] pnet ChangeLog image/class.c image/java_loader.... |
Date: |
Sat, 18 Apr 2009 19:18:20 +0000 |
CVSROOT: /cvsroot/dotgnu-pnet
Module name: pnet
Changes by: Klaus Treichel <ktreichel> 09/04/18 19:18:20
Modified files:
. : ChangeLog
image : class.c java_loader.c java_writer.c lib_attrs.c
program.h writer.c
include : il_program.h
Added files:
include : il_varargs.h
Log message:
Add support for caching deserialized attribute usage attributes.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pnet/ChangeLog?cvsroot=dotgnu-pnet&r1=1.3616&r2=1.3617
http://cvs.savannah.gnu.org/viewcvs/pnet/image/class.c?cvsroot=dotgnu-pnet&r1=1.45&r2=1.46
http://cvs.savannah.gnu.org/viewcvs/pnet/image/java_loader.c?cvsroot=dotgnu-pnet&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/pnet/image/java_writer.c?cvsroot=dotgnu-pnet&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/pnet/image/lib_attrs.c?cvsroot=dotgnu-pnet&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/pnet/image/program.h?cvsroot=dotgnu-pnet&r1=1.31&r2=1.32
http://cvs.savannah.gnu.org/viewcvs/pnet/image/writer.c?cvsroot=dotgnu-pnet&r1=1.19&r2=1.20
http://cvs.savannah.gnu.org/viewcvs/pnet/include/il_program.h?cvsroot=dotgnu-pnet&r1=1.67&r2=1.68
http://cvs.savannah.gnu.org/viewcvs/pnet/include/il_varargs.h?cvsroot=dotgnu-pnet&rev=1.1
Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/ChangeLog,v
retrieving revision 1.3616
retrieving revision 1.3617
diff -u -b -r1.3616 -r1.3617
--- ChangeLog 16 Apr 2009 15:34:54 -0000 1.3616
+++ ChangeLog 18 Apr 2009 19:18:18 -0000 1.3617
@@ -1,3 +1,25 @@
+2009-04-18 Klaus Treichel <address@hidden>
+
+ * image/class.c (_ILClassExtCreate): Add function to create class
+ extensions (cache or java strings).
+ (_ILClassExtFind): Add function to find the first cached entry of a
+ given kind.
+
+ * image/java_loader.c, image/java_writer.c, writer.c: Change to use
+ the new functions in class.c instead of accessing the ext member of
+ the class directly.
+
+ * image/lib_attrs.c: Add functions for deserializing an
+ AttributeUsageAttribute, caching the result and retrieving the members.
+
+ * include/il_program.h: Add opaque type ILAttributeUsageAttribute.
+ Add declarations for ILFindCustomAttribute, ILClassGetAttributeUsage,
+ ILAttributeUsageAttributeGetValidOn,
+ ILAttributeUsageAttributeGetAllowMultiple, and
+ ILAttributeUsageAttributeGetInherited.
+
+ * include/il_varargs.h: Add include file for general vararg handling.
+
2009-04-16 Klaus Treichel <address@hidden>
* codegen/cg_decls.tc (ILGenOutputGenericParamAttributes): Add support
Index: image/class.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/image/class.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -b -r1.45 -r1.46
--- image/class.c 26 Nov 2008 20:15:24 -0000 1.45
+++ image/class.c 18 Apr 2009 19:18:19 -0000 1.46
@@ -24,6 +24,38 @@
extern "C" {
#endif
+ILClassExt *_ILClassExtCreate(ILClass *info, ILUInt32 kind)
+{
+ ILClassExt *ext;
+
+ ext = ILMemStackAlloc(&(info->programItem.image->memStack), ILClassExt);
+ if(!ext)
+ {
+ return 0;
+ }
+ ext->kind = kind;
+ ext->next = info->ext;
+ info->ext = ext;
+
+ return ext;
+}
+
+ILClassExt *_ILClassExtFind(ILClass *info, ILUInt32 kind)
+{
+ ILClassExt *ext;
+
+ ext = info->ext;
+ while(ext)
+ {
+ if(ext->kind == kind)
+ {
+ return ext;
+ }
+ ext = ext->next;
+ }
+ return 0;
+}
+
ILClassName *_ILClassNameCreate(ILImage *image, ILToken token,
const char
*name, const char *namespace,
ILProgramItem
*scopeItem,
@@ -2154,7 +2186,7 @@
goto done;
}
}
- if(result && ILMethod_Owner(result) == parent)
+ if(result && _ILMethod_Owner(result) == parent)
{
/* We have a non-override method at this level */
break;
Index: image/java_loader.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/image/java_loader.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- image/java_loader.c 26 Nov 2008 20:15:25 -0000 1.13
+++ image/java_loader.c 18 Apr 2009 19:18:19 -0000 1.14
@@ -866,6 +866,7 @@
unsigned char floatBuf[8];
ILClass *classInfo;
ILClass *otherClass;
+ ILClassExt *ext;
int error = 0;
/* Skip the 8 bytes of header, which we have already parsed */
@@ -1303,13 +1304,13 @@
}
/* Attach the constant pool to the class */
- if((classInfo->ext = ILMemStackAlloc(&(image->memStack), ILClassExt))
== 0)
+ if((ext = _ILClassExtCreate(classInfo, _IL_EXT_JAVA_CONSTPOOL)) == 0)
{
error = IL_LOADERR_MEMORY;
goto cleanup;
}
- classInfo->ext->constPoolSize = constPoolEntries;
- classInfo->ext->constPool = constPool;
+ ext->un.javaConstPool.size = constPoolEntries;
+ ext->un.javaConstPool.entries = constPool;
/* Clean up and exit */
cleanup:
@@ -1498,6 +1499,35 @@
return 0;
}
+/*
+ * Get the java cost pool attached to a class.
+ * Returns o if there is no java const pool attached to the class.
+ */
+static JavaConstPool *JavaGetConstPool(ILClass *info)
+{
+ ILClassExt *ext;
+
+ if((ext = _ILClassExtFind(info, _IL_EXT_JAVA_CONSTPOOL)) != 0)
+ {
+ return &(ext->un.javaConstPool);
+ }
+ return 0;
+}
+
+static JavaConstEntry *JavaGetConstEntry(ILClass *info, ILUInt32 index)
+{
+ ILClassExt *ext;
+
+ if((ext = _ILClassExtFind(info, _IL_EXT_JAVA_CONSTPOOL)) != 0)
+ {
+ if(ext->un.javaConstPool.size > index)
+ {
+ return &(ext->un.javaConstPool.entries[index]);
+ }
+ }
+ return 0;
+}
+
int _ILImageJavaLoad(FILE *file, const char *filename, ILContext *context,
ILImage **image, int flags, char
*buffer)
{
@@ -1616,84 +1646,128 @@
int ILJavaGetConstType(ILClass *info, ILUInt32 index)
{
- if(info && info->ext && index < info->ext->constPoolSize)
+ if(info)
+ {
+ JavaConstEntry *entry;
+
+ entry = JavaGetConstEntry(info, index);
+ if(entry)
{
- return info->ext->constPool[index].type;
+ return entry->type;
+ }
}
return 0;
}
const char *ILJavaGetUTF8String(ILClass *info, ILUInt32 index, ILUInt32 *len)
{
- if(ILJavaGetConstType(info, index) != JAVA_CONST_UTF8)
+ JavaConstEntry *entry;
+
+ if(!info || (entry = JavaGetConstEntry(info, index)) == 0)
{
return 0;
}
- *len = info->ext->constPool[index].length;
- return info->ext->constPool[index].un.utf8String;
+ if(entry->type != JAVA_CONST_UTF8)
+ {
+ return 0;
+ }
+ *len = entry->length;
+ return entry->un.utf8String;
}
const char *ILJavaGetString(ILClass *info, ILUInt32 index, ILUInt32 *len)
{
- if(ILJavaGetConstType(info, index) != JAVA_CONST_STRING)
+ JavaConstEntry *entry;
+
+ if(!info || (entry = JavaGetConstEntry(info, index)) == 0)
+ {
+ return 0;
+ }
+ if(entry->type != JAVA_CONST_STRING)
{
return 0;
}
- index = info->ext->constPool[index].un.strValue;
+ index = entry->un.strValue;
return ILJavaGetUTF8String(info, index, len);
}
int ILJavaGetInteger(ILClass *info, ILUInt32 index, ILInt32 *value)
{
- if(ILJavaGetConstType(info, index) != JAVA_CONST_INTEGER)
+ JavaConstEntry *entry;
+
+ if(!info || (entry = JavaGetConstEntry(info, index)) == 0)
+ {
+ return 0;
+ }
+ if(entry->type != JAVA_CONST_INTEGER)
{
return 0;
}
- *value = info->ext->constPool[index].un.intValue;
+ *value = entry->un.intValue;
return 1;
}
int ILJavaGetLong(ILClass *info, ILUInt32 index, ILInt64 *value)
{
- if(ILJavaGetConstType(info, index) != JAVA_CONST_LONG)
+ JavaConstEntry *entry;
+
+ if(!info || (entry = JavaGetConstEntry(info, index)) == 0)
+ {
+ return 0;
+ }
+ if(entry->type != JAVA_CONST_LONG)
{
return 0;
}
- *value = info->ext->constPool[index].un.longValue;
+ *value = entry->un.longValue;
return 1;
}
int ILJavaGetFloat(ILClass *info, ILUInt32 index, ILFloat *value)
{
- if(ILJavaGetConstType(info, index) != JAVA_CONST_FLOAT)
+ JavaConstEntry *entry;
+
+ if(!info || (entry = JavaGetConstEntry(info, index)) == 0)
{
return 0;
}
- *value = info->ext->constPool[index].un.floatValue;
+ if(entry->type != JAVA_CONST_FLOAT)
+ {
+ return 0;
+ }
+ *value = entry->un.floatValue;
return 1;
}
int ILJavaGetDouble(ILClass *info, ILUInt32 index, ILDouble *value)
{
- if(ILJavaGetConstType(info, index) != JAVA_CONST_DOUBLE)
+ JavaConstEntry *entry;
+
+ if(!info || (entry = JavaGetConstEntry(info, index)) == 0)
+ {
+ return 0;
+ }
+ if(entry->type != JAVA_CONST_DOUBLE)
{
return 0;
}
- *value = info->ext->constPool[index].un.doubleValue;
+ *value = entry->un.doubleValue;
return 1;
}
ILClass *ILJavaGetClass(ILClass *info, ILUInt32 index, int refOnly)
{
+ JavaConstPool *constPool;
ILClass *classInfo;
int error;
- if(!info || !(info->ext))
+
+ if(!info || (constPool = JavaGetConstPool(info)) == 0)
{
return 0;
}
classInfo = ResolveJavaClass(info->programItem.image,
-
info->ext->constPool,
-
info->ext->constPoolSize,
+
constPool->entries,
+
constPool->size,
index, &error,
(refOnly ?
IL_LOADFLAG_NO_RESOLVE : 0));
if(classInfo && !refOnly && ILClassIsRef(classInfo))
@@ -1711,7 +1785,11 @@
const char **type,
ILUInt32 *typeLen)
{
JavaConstEntry *entry;
- entry = &(info->ext->constPool[index]);
+
+ if(!info || (entry = JavaGetConstEntry(info, index)) == 0)
+ {
+ return 0;
+ }
*name = ILJavaGetUTF8String(info, entry->un.nameAndType.name, nameLen);
*type = ILJavaGetUTF8String(info, entry->un.nameAndType.type, typeLen);
return (*name != 0 && *type != 0);
@@ -2250,12 +2328,16 @@
char *nameCopy;
/* Make sure that the entry is of an appropriate type */
- if((entryType = ILJavaGetConstType(info, index)) !=
JAVA_CONST_METHODREF &&
+ if(!info || (entry = JavaGetConstEntry(info, index)) == 0)
+ {
+ return 0;
+ }
+ entryType = entry->type;
+ if(entryType != JAVA_CONST_METHODREF &&
entryType != JAVA_CONST_INTERFACEMETHODREF)
{
return 0;
}
- entry = &(info->ext->constPool[index]);
/* Resolve the reference if necessary */
if(!(entry->un.refValue.item))
@@ -2345,11 +2427,14 @@
ILUInt32 typeLen;
/* Make sure that the entry is of an appropriate type */
- if(ILJavaGetConstType(info, index) != JAVA_CONST_FIELDREF)
+ if(!info || (entry = JavaGetConstEntry(info, index)) == 0)
+ {
+ return 0;
+ }
+ if(entry->type != JAVA_CONST_FIELDREF)
{
return 0;
}
- entry = &(info->ext->constPool[index]);
/* Resolve the reference if necessary */
if(!(entry->un.refValue.item))
Index: image/java_writer.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/image/java_writer.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- image/java_writer.c 26 Nov 2008 20:15:25 -0000 1.7
+++ image/java_writer.c 18 Apr 2009 19:18:19 -0000 1.8
@@ -47,31 +47,83 @@
void ILJavaInitPool(ILWriter *writer, ILClass *info)
{
- if(info->ext != 0)
+ ILClassExt *ext;
+
+ if(_ILClassExtFind(info, _IL_EXT_JAVA_CONSTPOOL) != 0)
return;
- info->ext = (ILClassExt*)ILMalloc(sizeof(ILClassExt));
- if(!info->ext)
+ ext = _ILClassExtCreate(info, _IL_EXT_JAVA_CONSTPOOL);
+ if(!ext)
{
writer->outOfMemory = 1;
return;
}
- info->ext->constPoolSize = 1;
- info->ext->constPool = ILMalloc(sizeof(JavaConstEntry));
- if(!info->ext->constPool)
+ ext->un.javaConstPool.size = 1;
+ ext->un.javaConstPool.entries = ILMalloc(sizeof(JavaConstEntry));
+ if(!ext->un.javaConstPool.entries)
{
writer->outOfMemory = 1;
return;
}
- info->ext->constPool[0].type = 0;
- info->ext->constPool[0].un.codeList = 0;
- info->ext->constPool[0].length = 0;
+ ext->un.javaConstPool.entries[0].type = 0;
+ ext->un.javaConstPool.entries[0].un.codeList = 0;
+ ext->un.javaConstPool.entries[0].length = 0;
+}
+
+/*
+ * Get the java cost pool attached to a class.
+ * Returns o if there is no java const pool attached to the class.
+ */
+static JavaConstPool *JavaGetConstPool(ILClass *info)
+{
+ ILClassExt *ext;
+
+ if((ext = _ILClassExtFind(info, _IL_EXT_JAVA_CONSTPOOL)) != 0)
+ {
+ return &(ext->un.javaConstPool);
+ }
+ return 0;
+}
+
+static JavaConstEntry *JavaGetConstEntry(ILClass *info, ILUInt32 index)
+{
+ ILClassExt *ext;
+
+ if((ext = _ILClassExtFind(info, _IL_EXT_JAVA_CONSTPOOL)) != 0)
+ {
+ if(ext->un.javaConstPool.size > index)
+ {
+ return &(ext->un.javaConstPool.entries[index]);
+ }
+ }
+ return 0;
+}
+
+/*
+ * Adds a pool entry to the end of the pool table
+ */
+static ILUInt32 ILJavaAddPool(ILWriter *writer, JavaConstPool *constPool,
+ JavaConstEntry *entry)
+{
+ ILUInt32 poolSize;
+
+ poolSize = constPool->size;
+ constPool->entries = ILRealloc(constPool->entries,
+
sizeof(JavaConstEntry) * (poolSize + 1));
+ if(!constPool->entries)
+ {
+ writer->outOfMemory = 1;
+ return 0;
+ }
+ constPool->entries[poolSize] = *entry;
+ (constPool->size)++;
+ return poolSize;
}
void ILJavaAppendCode(ILWriter *writer, ILClass *info, ILMethod *method,
const void *buffer, unsigned long size)
{
JavaCodeList *list;
- JavaConstEntry *entry = &(info->ext->constPool[0]);
+ JavaConstEntry *entry = JavaGetConstEntry(info, 0);
/* finds the corresponding class */
list = entry->un.codeList;
@@ -318,39 +370,28 @@
return 0;
}
-/*
- * Adds a pool entry to the end of the pool table
- */
-static ILUInt32 ILJavaAddPool(ILWriter *writer, ILClass *info,
- JavaConstEntry
*entry)
-{
- ILUInt32 poolSize = info->ext->constPoolSize;
-
- info->ext->constPool = ILRealloc(info->ext->constPool,
-
sizeof(JavaConstEntry) * (poolSize + 1));
- if(!info->ext->constPool)
- {
- writer->outOfMemory = 1;
- return 0;
- }
- info->ext->constPool[poolSize] = *entry;
- (info->ext->constPoolSize)++;
- return poolSize;
-}
-
ILUInt32 ILJavaSetUTF8String(ILWriter *writer, ILClass *info,
const char *value,
ILUInt32 len)
{
- ILUInt32 constPoolEntries = info->ext->constPoolSize;
- JavaConstEntry *constPool = info->ext->constPool;
+ JavaConstPool *constPool;
+ ILUInt32 constPoolEntries;
+ JavaConstEntry *entries;
JavaConstEntry *poolEntry;
int index;
+ constPool = JavaGetConstPool(info);
+ if(!constPool)
+ {
+ writer->outOfMemory = 1;
+ return 0;
+ }
+ constPoolEntries = constPool->size;
+ entries = constPool->entries;
for(index = 0; index < constPoolEntries; index++)
{
- if(constPool[index].type == JAVA_CONST_UTF8 &&
- constPool[index].length == len &&
- !ILMemCmp(constPool[index].un.utf8String, value, len))
+ if(entries[index].type == JAVA_CONST_UTF8 &&
+ entries[index].length == len &&
+ !ILMemCmp(entries[index].un.utf8String, value, len))
{
return index;
}
@@ -370,7 +411,7 @@
return 0;
}
ILMemCpy(poolEntry->un.utf8String, value, len);
- return ILJavaAddPool(writer, info, poolEntry);
+ return ILJavaAddPool(writer, constPool, poolEntry);
}
@@ -407,18 +448,25 @@
#define ADD_POOL(constName, unionName, fieldName1, fieldVal1, fieldName2,\
fieldVal2)\
-\
+ do { \
+ ILUInt32 constPoolEntries; \
+ JavaConstEntry *entries; \
+ JavaConstEntry *poolEntry; \
+ int index; \
+ \
+ constPoolEntries = constPool->size; \
+ entries = constPool->entries; \
for(index = 0; index < constPoolEntries; index++)\
{\
- if(constPool[index].type == JAVA_CONST_##constName &&\
- constPool[index].un.unionName.fieldName1 == (fieldVal1) &&\
- constPool[index].un.unionName.fieldName2 == (fieldVal2))\
+ if(entries[index].type == JAVA_CONST_##constName &&\
+ entries[index].un.unionName.fieldName1 == (fieldVal1) &&\
+ entries[index].un.unionName.fieldName2 == (fieldVal2))\
{\
return index;\
}\
}\
poolEntry = (JavaConstEntry*)ILMalloc(sizeof(JavaConstEntry));\
-\
+ \
if(!poolEntry)\
{\
writer->outOfMemory = 1;\
@@ -427,18 +475,22 @@
poolEntry->type = JAVA_CONST_##constName;\
poolEntry->un.unionName.fieldName1 = (fieldVal1);\
poolEntry->un.unionName.fieldName2 = (fieldVal2);\
-\
- return ILJavaAddPool(writer, info, poolEntry);
+ \
+ return ILJavaAddPool(writer, constPool, poolEntry);\
+ } while(0);
ILUInt32 ILJavaSetClass(ILWriter *writer, ILClass *info, ILClass *class)
{
- ILUInt32 constPoolEntries = info->ext->constPoolSize;
- JavaConstEntry *constPool = info->ext->constPool;
- JavaConstEntry *poolEntry;
- int index;
+ JavaConstPool *constPool;
ILUInt32 nameIndex;
char *name = JavaGetClassName(writer, class);
+ constPool = JavaGetConstPool(info);
+ if(!constPool)
+ {
+ writer->outOfMemory = 1;
+ return 0;
+ }
nameIndex = ILJavaSetUTF8String(writer, info, name, strlen(name));
if(!nameIndex)
return 0;
@@ -448,14 +500,16 @@
ILUInt32 ILJavaSetClassFromType(ILWriter *writer, ILClass *info, ILType *type)
{
- ILUInt32 constPoolEntries = info->ext->constPoolSize;
- JavaConstEntry *constPool = info->ext->constPool;
- JavaConstEntry *poolEntry;
-
- int index;
+ JavaConstPool *constPool;
ILUInt32 nameIndex;
char *name = 0;
+ constPool = JavaGetConstPool(info);
+ if(!constPool)
+ {
+ writer->outOfMemory = 1;
+ return 0;
+ }
WriteJavaType(writer, type, &name);
nameIndex = ILJavaSetUTF8String(writer, info, name, strlen(name));
@@ -468,12 +522,15 @@
ILUInt32 ILJavaSetClassFromName(ILWriter *writer, ILClass *info,
const char
*name)
{
- ILUInt32 constPoolEntries = info->ext->constPoolSize;
- JavaConstEntry *constPool = info->ext->constPool;
- JavaConstEntry *poolEntry;
- int index;
+ JavaConstPool *constPool;
ILUInt32 nameIndex;
+ constPool = JavaGetConstPool(info);
+ if(!constPool)
+ {
+ writer->outOfMemory = 1;
+ return 0;
+ }
nameIndex = ILJavaSetUTF8String(writer, info, name, strlen(name));
if(!nameIndex)
return 0;
@@ -484,26 +541,32 @@
ILUInt32 ILJavaSetNameAndType(ILWriter *writer, ILClass *info,
ILUInt32
nameIndex, ILUInt32 sigIndex)
{
- ILUInt32 constPoolEntries = info->ext->constPoolSize;
- JavaConstEntry *constPool = info->ext->constPool;
- JavaConstEntry *poolEntry;
- ILUInt32 index;
+ JavaConstPool *constPool;
+ constPool = JavaGetConstPool(info);
+ if(!constPool)
+ {
+ writer->outOfMemory = 1;
+ return 0;
+ }
ADD_POOL(NAMEANDTYPE, nameAndType, name, nameIndex, type, sigIndex);
}
ILUInt32 ILJavaSetref(ILWriter *writer, ILClass *info, int type,
ILClass *owner,char *name,
ILType *sig)
{
- ILUInt32 constPoolEntries = info->ext->constPoolSize;
- JavaConstEntry *constPool = info->ext->constPool;
- JavaConstEntry *poolEntry;
- ILUInt32 index;
+ JavaConstPool *constPool;
ILUInt32 nameIndex;
ILUInt32 sigIndex;
ILUInt32 classIndex;
ILUInt32 nameAndType;
+ constPool = JavaGetConstPool(info);
+ if(!constPool)
+ {
+ writer->outOfMemory = 1;
+ return 0;
+ }
classIndex = ILJavaSetClass(writer, info, owner);
name = ILMethodNameToJava(name);
nameIndex = ILJavaSetUTF8String(writer, info, name, strlen(name));
@@ -531,15 +594,18 @@
const char
*className, const char *refName,
const char *sigName)
{
- ILUInt32 constPoolEntries = info->ext->constPoolSize;
- JavaConstEntry *constPool = info->ext->constPool;
- JavaConstEntry *poolEntry;
- ILUInt32 index;
+ JavaConstPool *constPool;
ILUInt32 refIndex;
ILUInt32 sigIndex;
ILUInt32 classIndex;
ILUInt32 nameAndType;
+ constPool = JavaGetConstPool(info);
+ if(!constPool)
+ {
+ writer->outOfMemory = 1;
+ return 0;
+ }
classIndex = ILJavaSetClassFromName(writer, info, className);
refIndex = ILJavaSetUTF8String(writer, info, refName, strlen(refName));
sigIndex = ILJavaSetUTF8String(writer, info, sigName, strlen(sigName));
@@ -565,15 +631,24 @@
#define ILJAVA_SET(name, typeName, fieldName, constName)\
int ILJavaSet##name(ILWriter *writer, ILClass *info, typeName value)\
{\
- ILUInt32 constPoolEntries = info->ext->constPoolSize;\
- JavaConstEntry *constPool = info->ext->constPool;\
+ JavaConstPool *constPool;\
+ ILUInt32 constPoolEntries;\
+ JavaConstEntry *entries;\
JavaConstEntry *poolEntry;\
int index, index2;\
\
+ constPool = JavaGetConstPool(info);\
+ if(!constPool)\
+ {\
+ writer->outOfMemory = 1;\
+ return 0;\
+ }\
+ constPoolEntries = constPool->size;\
+ entries = constPool->entries;\
for(index = 0; index < constPoolEntries; index++)\
{\
- if(constPool[index].type == JAVA_CONST_##constName &&\
- constPool[index].un.fieldName == value)\
+ if(entries[index].type == JAVA_CONST_##constName &&\
+ entries[index].un.fieldName == value)\
{\
return index;\
}\
@@ -588,7 +663,7 @@
poolEntry->type = JAVA_CONST_##constName;\
poolEntry->un.fieldName = value;\
\
- index = ILJavaAddPool(writer, info, poolEntry);\
+ index = ILJavaAddPool(writer, constPool, poolEntry);\
/* add an empty pool entry */\
if(poolEntry->type == JAVA_CONST_LONG ||\
poolEntry->type == JAVA_CONST_DOUBLE)\
@@ -601,7 +676,7 @@
return 0;\
}\
emptyEntry->type = 0;\
- index2 = ILJavaAddPool(writer, info, emptyEntry);\
+ index2 = ILJavaAddPool(writer, constPool, emptyEntry);\
}\
return index;\
}
@@ -889,7 +964,7 @@
/* Write method attributes */
if(isMethod)
{
- JavaConstEntry *entry = &(class->ext->constPool[0]);
+ JavaConstEntry *entry = JavaGetConstEntry(class, 0);
JavaCodeList *list;
numMemberAttrs = 1; /* only code for the moment */
@@ -926,7 +1001,7 @@
*/
void WriteJavaClass(ILWriter *writer, ILClass *class)
{
-
+ JavaConstPool *constPool;
ILUInt32 accessFlags;
ILUInt32 javaAccessFlags;
ILUInt32 thisIndex;
@@ -1164,8 +1239,13 @@
numClassAttrs = 0;
OUT_UINT16(numClassAttrs);
- JavaWriteConstantPool(writer, class->ext->constPool,
- class->ext->constPoolSize);
+
+ constPool = JavaGetConstPool(class);
+ if(constPool)
+ {
+ JavaWriteConstantPool(writer, constPool->entries,
+ constPool->size);
+ }
ILWriterTextWrite(writer, buffer, offset);
cleanup:
Index: image/lib_attrs.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/image/lib_attrs.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- image/lib_attrs.c 18 Nov 2008 20:06:07 -0000 1.15
+++ image/lib_attrs.c 18 Apr 2009 19:18:19 -0000 1.16
@@ -1365,8 +1365,8 @@
{
return 0;
}
- name = ILClass_Name(ILMethod_Owner(ctor));
- namespace = ILClass_Namespace(ILMethod_Owner(ctor));
+ name = ILClass_Name(_ILMethod_Owner(ctor));
+ namespace = ILClass_Namespace(_ILMethod_Owner(ctor));
if(!namespace)
{
return 0;
@@ -1450,6 +1450,270 @@
return 1;
}
+/*
+ * Deserialize a System.AttributeUsageAttribute.
+ * Returns 1 on success and 0 on error.
+ */
+static int DeSerializeAttributeUsage(ILAttributeUsageAttribute *usage,
+
ILSerializeReader *reader)
+{
+ int type;
+ int numExtra;
+ const char *paramName;
+ int paramNameLen;
+ ILMember *member;
+
+ /* Get the first parameter, which should be int32 */
+ type = ILSerializeReaderGetParamType(reader);
+ if(type != IL_META_SERIALTYPE_I4)
+ {
+ return 0;
+ }
+ usage->validOn = (ILUInt32)(ILSerializeReaderGetInt32(reader, type));
+ /* There MUST not be a second ctor argument */
+ if(ILSerializeReaderGetParamType(reader) != 0)
+ {
+ return 0;
+ }
+ numExtra = ILSerializeReaderGetNumExtra(reader);
+ if(numExtra < 0)
+ {
+ return 0;
+ }
+ while(numExtra > 0)
+ {
+ type = ILSerializeReaderGetExtra(reader, &member, ¶mName,
+
¶mNameLen);
+ if(type == -1)
+ {
+ return 0;
+ }
+ if(IsParam("AllowMultiple", IL_META_SERIALTYPE_BOOLEAN))
+ {
+ usage->allowMultiple =
(ILSerializeReaderGetInt32(reader, type) != 0);
+ }
+ else if(IsParam("Inherited", IL_META_SERIALTYPE_BOOLEAN))
+ {
+ usage->inherited = (ILSerializeReaderGetInt32(reader,
type) != 0);
+ }
+ else
+ {
+ /* Unknown property */
+ return 0;
+ }
+
+ --numExtra;
+ }
+ return 1;
+}
+
+/*
+ * Search for cached attribute information for the class.
+ * Returns 0 if there is no cached attributeClass information is found.
+ */
+static ILCustomAttribute *FindCachedCustomAttribute(ILClass *info,
+
ILClass *attributeClass)
+{
+
+ ILClassExt *ext;
+
+ ext = _ILClassExtFind(info, _IL_EXT_CIL_CUSTOMATTR);
+ while(ext)
+ {
+ if(ext->kind == _IL_EXT_CIL_CUSTOMATTR)
+ {
+ if(ext->un.customAttribute.attributeClass ==
attributeClass)
+ {
+ return &(ext->un.customAttribute);
+ }
+ }
+ ext = ext->next;
+ }
+ /*
+ * If we get here no cached information for the custom attribute was
+ * found
+ */
+ return 0;
+}
+
+/*
+ * Look for a custom attribute attached to the class.
+ * Returns 0 if an attribute of this kind is not attached to the class.
+ */
+static ILAttribute *FindCustomAttribute(ILClass *info,
+
ILClass *attributeClass)
+{
+ ILAttribute *attr;
+ ILProgramItem *item;
+
+ item = _ILToProgramItem(info);
+ attr = 0;
+ while((attr = ILProgramItemNextAttribute(item, attr)) != 0)
+ {
+ ILMethod *ctor;
+
+ ctor = ILProgramItemToMethod(ILAttributeTypeAsItem(attr));
+ if(ctor)
+ {
+ ILClass *currentAttrClass;
+
+ currentAttrClass = _ILMethod_Owner(ctor);
+ currentAttrClass = ILClassResolve(currentAttrClass);
+ if(currentAttrClass == attributeClass)
+ {
+ return attr;
+ }
+ }
+ attr = ILProgramItemNextAttribute(item, attr);
+ }
+ /*
+ * If we get here the class as no attributeClass custopm attribute.
+ */
+ return 0;
+}
+
+static ILAttributeUsageAttribute *GetAttributeUsage(ILClass *attribute)
+{
+ ILClass *attributeUsage;
+
+ attributeUsage =
ILFindCustomAttribute(attribute->programItem.image->context,
+
"AttributeUsageAttribute", "System", 0);
+
+ if(attributeUsage)
+ {
+ ILCustomAttribute *customAttr;
+
+ /* First look for a cached attribute */
+ customAttr = FindCachedCustomAttribute(attribute,
attributeUsage);
+ if(customAttr)
+ {
+ return &(customAttr->un.attributeUsage);
+ }
+ else
+ {
+ /* Try it the hard way */
+ ILClassExt *ext;
+ ILAttribute *attr;
+ ILAttributeUsageAttribute *usage;
+
+ ext = _ILClassExtCreate(attribute,
_IL_EXT_CIL_CUSTOMATTR);
+ if(!ext)
+ {
+ /* Out of memory */
+ return 0;
+ }
+ ext->un.customAttribute.attributeClass = attributeUsage;
+ usage = &(ext->un.customAttribute.un.attributeUsage);
+ /* Set the defaults */
+ /* See ECMA Version 4 paragraph 10.6 */
+#if IL_VERSION_MAJOR > 1
+ usage->validOn = 0X7FFF;
+#else
+ usage->validOn = 0X3FFF;
+#endif
+ usage->allowMultiple = (ILBool)0;
+ usage->inherited = (ILBool)1;
+ attr = 0;
+ while(attribute && !attr)
+ {
+ /*
+ * The attribute usage is inherited from the
parent attribute
+ * class so look for it in the parents too.
+ */
+ attr = FindCustomAttribute(attribute,
attributeUsage);
+ if(!attr)
+ {
+ attribute =
ILClassGetUnderlyingParentClass(attribute);
+ }
+ }
+ if(attr)
+ {
+ ILMethod *ctor;
+
+ ctor =
ILProgramItemToMethod(ILAttributeTypeAsItem(attr));
+ if(ctor)
+ {
+ const void *blob;
+ unsigned long blobLen;
+ ILSerializeReader *reader;
+ int result;
+
+ /*
+ * Get the data blob from the attribute
and create a
+ * reader for it
+ */
+ blob = ILAttributeGetValue(attr,
&blobLen);
+ if(!blob)
+ {
+ return 0;
+ }
+ reader = ILSerializeReaderInit(ctor,
blob, blobLen);
+ if(!reader)
+ {
+ return 0;
+ }
+ result =
DeSerializeAttributeUsage(usage, reader);
+ ILSerializeReaderDestroy(reader);
+ if(!result)
+ {
+ return 0;
+ }
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ return usage;
+ }
+ }
+ return 0;
+}
+
+ILClass *ILFindCustomAttribute(ILContext *context, const char *name,
+ const char
*namespace,
+
ILAttributeUsageAttribute **usage)
+{
+ ILClass *attribute;
+
+ attribute = ILClassLookupGlobal(context, name, namespace);
+ if(attribute)
+ {
+ attribute = ILClassResolve(attribute);
+ if(attribute && usage)
+ {
+ /* Get the attribute usage information for the
attribute */
+ *usage = GetAttributeUsage(attribute);
+ }
+ return attribute;
+ }
+ return 0;
+}
+
+ILAttributeUsageAttribute *ILClassGetAttributeUsage(ILClass *attribute)
+{
+ if(attribute)
+ {
+ return GetAttributeUsage(attribute);
+ }
+ return 0;
+}
+
+ILUInt32 ILAttributeUsageAttributeGetValidOn(ILAttributeUsageAttribute *usage)
+{
+ return usage->validOn;
+}
+
+ILBool ILAttributeUsageAttributeGetAllowMultiple(ILAttributeUsageAttribute
*usage)
+{
+ return usage->allowMultiple;
+}
+
+ILBool ILAttributeUsageAttributeGetInherited(ILAttributeUsageAttribute *usage)
+{
+ return usage->inherited;
+}
+
#ifdef __cplusplus
};
#endif
Index: image/program.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/image/program.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -b -r1.31 -r1.32
--- image/program.h 26 Nov 2008 20:15:27 -0000 1.31
+++ image/program.h 18 Apr 2009 19:18:19 -0000 1.32
@@ -165,15 +165,62 @@
* Extension information that is only present in some circumstances
* (e.g. Java classes).
*/
-typedef struct _tagILClassExt ILClassExt;
+
+#define _IL_EXT_JAVA_CONSTPOOL 1
+#define _IL_EXT_CIL_CUSTOMATTR 2
+
typedef struct _tagJavaConstEntry JavaConstEntry;
+typedef struct _tagJavaConstPool JavaConstPool;
+struct _tagJavaConstPool
+{
+ ILUInt32 size; /* Java
constant pool size */
+ JavaConstEntry *entries; /* Constant pool
entries */
+};
+
+struct _tagILAttributeUsageAttribute
+{
+ ILUInt32 validOn;
+ ILBool inherited;
+ ILBool allowMultiple;
+};
+
+typedef struct _tagILCustomAttribute ILCustomAttribute;
+struct _tagILCustomAttribute
+{
+ ILClass *attributeClass;
+ union
+ {
+ struct _tagILAttributeUsageAttribute attributeUsage;
+ } un;
+};
+
+typedef struct _tagILClassExt ILClassExt;
struct _tagILClassExt
{
- ILUInt32 constPoolSize; /* Java constant pool
size */
- JavaConstEntry *constPool; /* Constant pool
entries */
+ ILUInt32 kind; /* Kind of the
class extension */
+ ILClassExt *next; /* Next entry
in the linked list */
+ union
+ {
+ JavaConstPool javaConstPool;
+ ILCustomAttribute customAttribute;
+ } un;
};
/*
+ * Allocate a class extension block and attach it to the class given.
+ * Returns 0 if out of memory.
+ */
+ILClassExt *_ILClassExtCreate(ILClass *info, ILUInt32 kind);
+
+/*
+ * Get the first class extension block of the given kind attached to the
+ * class.
+ * Returns 0 if there is no class extenstion block of the given kind is
+ * attached to the class.
+ */
+ILClassExt *_ILClassExtFind(ILClass *info, ILUInt32 kind);
+
+/*
* list of java method code
*/
typedef struct _tagILJavaCodeList JavaCodeList;
@@ -852,6 +899,8 @@
(((item)->token & IL_META_TOKEN_MASK) ==
IL_META_TOKEN_MODULE_REF)) ? \
(item) : 0)
+#define _ILToProgramItem(x) (&((x)->programItem))
+
/*
* Internal macros for accessing members in external opaque types
*/
@@ -859,6 +908,16 @@
#define _ILClass_Implements(info) ((info)->implements)
#define _ILImplements_NextImplements(impl) ((impl)->nextInterface)
#define _ILTypeSpec_Type(spec) ((spec)->type)
+#define _ILMember_Owner(member) ((member)->owner)
+#define _ILMethod_Owner(method) ((method)->member.owner)
+
+/*
+ * Misc internal macros
+ */
+#define _ILClass_IsInterface(info) \
+ (((info)->attributes &
IL_META_TYPEDEF_CLASS_SEMANTICS_MASK) \
+ == IL_META_TYPEDEF_INTERFACE)
+
#ifdef __cplusplus
};
Index: image/writer.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/image/writer.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- image/writer.c 20 Jul 2007 20:11:54 -0000 1.19
+++ image/writer.c 18 Apr 2009 19:18:19 -0000 1.20
@@ -363,6 +363,22 @@
}
}
+#ifdef IL_CONFIG_JAVA
+/*
+ * Check if the class has a java const pool.
+ */
+static ILBool JavaHasConstPool(ILClass *info)
+{
+ ILClassExt *ext;
+
+ if((ext = _ILClassExtFind(info, _IL_EXT_JAVA_CONSTPOOL)) != 0)
+ {
+ return (ext->un.javaConstPool.entries != 0);
+ }
+ return 0;
+}
+#endif
+
void ILWriterOutputMetadata(ILWriter *writer, ILImage *image)
{
unsigned long start;
@@ -394,7 +410,7 @@
if(!strcmp(ILClass_Name(class), "<Module>") ||
(!ILClass_IsPublic(class) &&
!ILClass_IsPrivate(class)) ||
- !class->ext || !class->ext->constPool)
+ !JavaHasConstPool(class))
{
continue;
}
@@ -414,7 +430,7 @@
if(!strcmp(ILClass_Name(class), "<Module>") ||
(!ILClass_IsPublic(class) &&
!ILClass_IsPrivate(class)) ||
- !class->ext || !class->ext->constPool)
+ !JavaHasConstPool(class))
{
continue;
}
Index: include/il_program.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/include/il_program.h,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -b -r1.67 -r1.68
--- include/il_program.h 16 Apr 2009 15:34:55 -0000 1.67
+++ include/il_program.h 18 Apr 2009 19:18:20 -0000 1.68
@@ -257,6 +257,34 @@
const void *ILAttributeGetValue(ILAttribute *attr, unsigned long *len);
/*
+ * Opaque type for accessing the attribute usage attribute.
+ */
+typedef struct _tagILAttributeUsageAttribute ILAttributeUsageAttribute;
+
+/*
+ * Find an Attribute class and retrieve the usage information.
+ * Returns 0 if the attribute could not be found.
+ */
+ILClass *ILFindCustomAttribute(ILContext *context, const char *name,
+ const char
*namespace,
+
ILAttributeUsageAttribute **usage);
+
+/*
+ * Get the attribute usage information for a custom attribute.
+ * If there is no attribute usage available for the attribute a default
+ * usage will be created.
+ * Returns 0 if attribute is 0.
+ */
+ILAttributeUsageAttribute *ILClassGetAttributeUsage(ILClass *attribute);
+
+/*
+ * Access the members of the attribute usage.
+ */
+ILUInt32 ILAttributeUsageAttributeGetValidOn(ILAttributeUsageAttribute *usage);
+ILBool ILAttributeUsageAttributeGetAllowMultiple(ILAttributeUsageAttribute
*usage);
+ILBool ILAttributeUsageAttributeGetInherited(ILAttributeUsageAttribute *usage);
+
+/*
* Helper macros for querying information about an attribute.
*/
#define ILAttribute_FromToken(image,token) \
Index: include/il_varargs.h
===================================================================
RCS file: include/il_varargs.h
diff -N include/il_varargs.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ include/il_varargs.h 18 Apr 2009 19:18:20 -0000 1.1
@@ -0,0 +1,66 @@
+/*
+ * il_varargs.h - variable argument handling declarations.
+ *
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef _IL_VARARGS_H
+#define _IL_VARARGS_H
+
+#include "il_config.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef HAVE_STDARG_H
+#include <stdarg.h>
+#define IL_VA_LIST va_list
+#define IL_VA_START(arg) va_list va; va_start(va, arg)
+#define IL_VA_END va_end(va)
+#define IL_VA_GET_LIST va
+#else
+#ifdef HAVE_VARARGS_H
+#include <varargs.h>
+#define IL_VA_LIST va_list
+#define IL_VA_START(arg) va_list va; va_start(va)
+#define IL_VA_END va_end(va)
+#define IL_VA_GET_LIST va
+#else
+#define IL_VA_LIST int
+#define IL_VA_START(arg)
+#define IL_VA_END
+#define IL_VA_GET_LIST 0
+#endif
+#endif
+
+/*
+ * Some gcc magic to make it check for correct printf
+ * arguments when using the error reporting functions.
+ */
+#if defined(__GNUC__)
+ #define IL_PRINTF(str,arg) \
+ __attribute__((__format__ (__printf__, str, arg)))
+#else
+ #define IL_PRINTF(str,arg)
+#endif
+
+#ifdef __cplusplus
+};
+#endif
+
+#endif /* _IL_VARARGS_H */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [dotgnu-pnet-commits] pnet ChangeLog image/class.c image/java_loader....,
Klaus Treichel <=