[kaffe] CVS kaffe (jserv): Corrected and clarified copyright notice.
Kaffe CVS
cvs-commits at kaffe.org
Sat May 7 09:25:18 PDT 2005
PatchSet 6450
Date: 2005/05/07 16:20:05
Author: jserv
Branch: HEAD
Tag: (none)
Log:
Corrected and clarified copyright notice.
2005-05-08 Jim Huang <jserv at kaffe.org>
* kaffe/kaffeh/main.c,
kaffe/kaffeh/support.c,
kaffe/kaffevm/baseClasses.c,
kaffe/kaffevm/code.c,
kaffe/kaffevm/exception.c,
kaffe/kaffevm/gcFuncs.c,
kaffe/kaffevm/itypes.c,
kaffe/kaffevm/object.c,
kaffe/kaffevm/object.h,
kaffe/kaffevm/soft.c,
kaffe/kaffevm/stackTrace.c,
kaffe/kaffevm/stats.c,
kaffe/kaffevm/stats.h,
kaffe/kaffevm/utf8const.c,
kaffe/kaffevm/intrp/methodcalls.c,
kaffe/kaffevm/intrp/native-wrapper.c,
kaffe/kaffevm/intrp/native-wrapper.h,
kaffe/kaffevm/jit/methodcalls.c,
kaffe/kaffevm/jit/native-wrapper.c,
kaffe/kaffevm/jit/native-wrapper.h,
kaffe/kaffevm/jit3/machine.c,
kaffe/kaffevm/jit3/machine.h,
kaffe/kaffevm/jit3/native-wrapper.c,
kaffe/kaffevm/jni/jni-arrays.c,
kaffe/kaffevm/jni/jni-base.c,
kaffe/kaffevm/jni/jni-callmethod.c,
kaffe/kaffevm/jni/jni-fields.c,
kaffe/kaffevm/jni/jni-helpers.c,
kaffe/kaffevm/jni/jni-string.c,
kaffe/kaffevm/jni/jni.c,
kaffe/kaffevm/kaffe-gc/gc-incremental.c,
include/native.h:
Corrected and clarified copyright notice.
Members:
ChangeLog:1.3978->1.3979
include/native.h:INITIAL->1.19
kaffe/kaffeh/main.c:1.15->1.16
kaffe/kaffeh/support.c:INITIAL->1.49
kaffe/kaffevm/baseClasses.c:1.63->1.64
kaffe/kaffevm/code.c:INITIAL->1.20
kaffe/kaffevm/exception.c:1.98->1.99
kaffe/kaffevm/gcFuncs.c:1.72->1.73
kaffe/kaffevm/itypes.c:1.36->1.37
kaffe/kaffevm/object.c:INITIAL->1.34
kaffe/kaffevm/object.h:INITIAL->1.8
kaffe/kaffevm/soft.c:INITIAL->1.77
kaffe/kaffevm/stackTrace.c:1.46->1.47
kaffe/kaffevm/stats.c:INITIAL->1.8
kaffe/kaffevm/stats.h:INITIAL->1.3
kaffe/kaffevm/utf8const.c:1.49->1.50
kaffe/kaffevm/intrp/methodcalls.c:1.8->1.9
kaffe/kaffevm/intrp/native-wrapper.c:1.5->1.6
kaffe/kaffevm/intrp/native-wrapper.h:1.2->1.3
kaffe/kaffevm/jit/methodcalls.c:1.9->1.10
kaffe/kaffevm/jit/native-wrapper.c:1.8->1.9
kaffe/kaffevm/jit/native-wrapper.h:1.2->1.3
kaffe/kaffevm/jit3/machine.c:1.75->1.76
kaffe/kaffevm/jit3/machine.h:INITIAL->1.25
kaffe/kaffevm/jit3/native-wrapper.c:1.2->1.3
kaffe/kaffevm/jni/jni-arrays.c:1.5->1.6
kaffe/kaffevm/jni/jni-base.c:1.18->1.19
kaffe/kaffevm/jni/jni-callmethod.c:1.6->1.7
kaffe/kaffevm/jni/jni-fields.c:1.3->1.4
kaffe/kaffevm/jni/jni-helpers.c:1.5->1.6
kaffe/kaffevm/jni/jni-string.c:1.9->1.10
kaffe/kaffevm/jni/jni.c:1.25->1.26
kaffe/kaffevm/kaffe-gc/gc-incremental.c:1.28->1.29
Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.3978 kaffe/ChangeLog:1.3979
--- kaffe/ChangeLog:1.3978 Sat May 7 10:35:14 2005
+++ kaffe/ChangeLog Sat May 7 16:20:05 2005
@@ -1,3 +1,39 @@
+2005-05-08 Jim Huang <jserv at kaffe.org>
+
+ * kaffe/kaffeh/main.c,
+ kaffe/kaffeh/support.c,
+ kaffe/kaffevm/baseClasses.c,
+ kaffe/kaffevm/code.c,
+ kaffe/kaffevm/exception.c,
+ kaffe/kaffevm/gcFuncs.c,
+ kaffe/kaffevm/itypes.c,
+ kaffe/kaffevm/object.c,
+ kaffe/kaffevm/object.h,
+ kaffe/kaffevm/soft.c,
+ kaffe/kaffevm/stackTrace.c,
+ kaffe/kaffevm/stats.c,
+ kaffe/kaffevm/stats.h,
+ kaffe/kaffevm/utf8const.c,
+ kaffe/kaffevm/intrp/methodcalls.c,
+ kaffe/kaffevm/intrp/native-wrapper.c,
+ kaffe/kaffevm/intrp/native-wrapper.h,
+ kaffe/kaffevm/jit/methodcalls.c,
+ kaffe/kaffevm/jit/native-wrapper.c,
+ kaffe/kaffevm/jit/native-wrapper.h,
+ kaffe/kaffevm/jit3/machine.c,
+ kaffe/kaffevm/jit3/machine.h,
+ kaffe/kaffevm/jit3/native-wrapper.c,
+ kaffe/kaffevm/jni/jni-arrays.c,
+ kaffe/kaffevm/jni/jni-base.c,
+ kaffe/kaffevm/jni/jni-callmethod.c,
+ kaffe/kaffevm/jni/jni-fields.c,
+ kaffe/kaffevm/jni/jni-helpers.c,
+ kaffe/kaffevm/jni/jni-string.c,
+ kaffe/kaffevm/jni/jni.c,
+ kaffe/kaffevm/kaffe-gc/gc-incremental.c,
+ include/native.h:
+ Corrected and clarified copyright notice.
+
2005-05-07 Guilhem Lavaux <guilhem at kaffe.org>
* kaffe/kaffevm/hashtab.c
===================================================================
Checking out kaffe/include/native.h
RCS: /home/cvs/kaffe/kaffe/include/native.h,v
VERS: 1.19
***************
--- /dev/null Sun Aug 4 19:57:58 2002
+++ kaffe/include/native.h Sat May 7 16:25:18 2005
@@ -0,0 +1,93 @@
+/*
+ * native.h
+ * Native method support.
+ *
+ * Copyright (c) 1996, 1997
+ * Transvirtual Technologies, Inc. All rights reserved.
+ *
+ * Copyright (c) 2004
+ * Kaffe.org contributors. See ChangeLog for details. All rights reserved.
+ *
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file.
+ */
+
+#ifndef __native_h
+#define __native_h
+
+#include "stddef.h"
+#include <jni.h>
+
+struct _methods;
+struct Hjava_lang_Class;
+struct Hjava_lang_ClassLoader;
+struct _strconst;
+
+#if !defined(__DEFINED_METHOD)
+#define __DEFINED_METHOD
+typedef struct _methods Method;
+#endif
+#if !defined(__DEFINED_UTF8CONST)
+#define __DEFINED_UTF8CONST
+typedef struct _strconst Utf8Const;
+#endif
+#if !defined(__DEFINED_CLASS)
+#define __DEFINED_CLASS
+typedef struct Hjava_lang_Class Hjava_lang_Class;
+#endif
+
+struct _dispatchTable;
+struct _iLock;
+
+
+
+typedef struct Hjava_lang_Object {
+ struct _dispatchTable* vtable;
+ struct _iLock* lock;
+ /* This pointer contains the VM function which should be called
+ * to handle object finalization.
+ */
+ void* finalizer_call;
+ /* Data follows on immediately */
+} Hjava_lang_Object;
+
+/* Turn a handle into the real thing */
+#define unhand(o) (o)
+
+/* Include array types */
+#include "Arrays.h"
+
+/* Get the strings */
+#include <java_lang_String.h>
+
+/* Some internal machine object conversions to "standard" types. */
+typedef Hjava_lang_Class HClass;
+typedef Hjava_lang_Object HObject;
+typedef Hjava_lang_String HString;
+
+extern char* stringJava2CBuf(const HString*, char*, int);
+extern char* stringJava2C(const HString*);
+extern HString* stringC2Java(const char*);
+
+extern int utf8ConstEqualJavaString(const Utf8Const*, const HString*);
+
+extern HObject* AllocObject(const char*, struct Hjava_lang_ClassLoader*);
+extern HObject* AllocArray(jsize len, int type);
+extern HObject* AllocObjectArray(int, const char*, struct Hjava_lang_ClassLoader*);
+
+/*
+ * Define KMALLOC, KFREE, etc.
+ */
+#include "kaffe/jmalloc.h"
+
+/* Pick up errorInfo, postOutOfMemory, throwError, and checkPtr */
+#include "errors.h"
+
+/*
+ * Functions needed protect calls to non-reentrant functions when a
+ * user-level threading package such as jthread is used.
+ */
+void enterUnsafeRegion(void);
+void leaveUnsafeRegion(void);
+
+#endif
Index: kaffe/kaffe/kaffeh/main.c
diff -u kaffe/kaffe/kaffeh/main.c:1.15 kaffe/kaffe/kaffeh/main.c:1.16
--- kaffe/kaffe/kaffeh/main.c:1.15 Fri Mar 26 22:58:40 2004
+++ kaffe/kaffe/kaffeh/main.c Sat May 7 16:20:08 2005
@@ -2,9 +2,12 @@
* main.c
* Generate native code stubs from .class files.
*
- * Copyright (c) 1996, 1997, 2004
+ * Copyright (c) 1996, 1997
* Transvirtual Technologies, Inc. All rights reserved.
*
+ * Copyright (c) 2004
+ * Kaffe.org contributors. See ChangeLog for details. All rights reserved.
+ *
* See the file "license.terms" for information on usage and redistribution
* of this file.
*/
===================================================================
Checking out kaffe/kaffe/kaffeh/support.c
RCS: /home/cvs/kaffe/kaffe/kaffe/kaffeh/support.c,v
VERS: 1.49
***************
--- /dev/null Sun Aug 4 19:57:58 2002
+++ kaffe/kaffe/kaffeh/support.c Sat May 7 16:25:18 2005
@@ -0,0 +1,943 @@
+/*
+ * support.c
+ *
+ * Copyright (c) 1996, 1997
+ * Transvirtual Technologies, Inc. All rights reserved.
+ *
+ * Copyright (c) 2004
+ * Kaffe.org contributors. See ChangeLog for details. All rights reserved.
+ *
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file.
+ */
+
+#include "config.h"
+#include "config-std.h"
+#include "config-io.h"
+#include "debug.h"
+#include "kaffe/jni_md.h"
+#include "jsyscall.h"
+#include "gtypes.h"
+#include "gc.h"
+#include "constants.h"
+#include "file.h"
+#include "files.h"
+#include "access.h"
+#include "classMethod.h"
+#include "readClass.h"
+#include "jar.h"
+#include "kaffeh-support.h"
+#include "utf8const.h"
+
+#if defined(__WIN32__) || defined (__amigaos__)
+#define PATHSEP ';'
+#else
+#define PATHSEP ':'
+#endif
+
+extern char realClassPath[];
+extern char className[];
+extern FILE* include;
+extern FILE* jni_include;
+extern int flag_jni;
+
+static int objectDepth = -1;
+static int outputField = 1; /* Output object fields? Only skipped on java.lang.Class and java.lang.Object */
+
+struct _Collector;
+
+static inline int
+binary_open(const char *file, int mode, int perm, int *);
+
+/* circular list containing all native methods of the class that's currently being processed (sorted by name) */
+struct _methodRing {
+ struct _methodRing* next;
+ struct _methodRing* prev;
+
+ const char* name;
+ const char* sig;
+ u2 access_flags;
+ bool needs_mangled_sig;
+} *methodRing;
+
+static int
+kread(int fd, void *buf, size_t len, ssize_t *out)
+{
+ *out = read(fd, buf, len);
+ return (*out == -1) ? errno : 0;
+}
+
+static int
+kwrite(int fd, const void *buf, size_t len, ssize_t *out)
+{
+ *out = write(fd, buf, len);
+ return (*out == -1) ? errno : 0;
+}
+
+static int
+klseek(int fd, off_t off, int whence, off_t *out)
+{
+ *out = lseek(fd, off, whence);
+ return (*out == -1) ? errno : 0;
+}
+
+/* With Tru64, stat and fstat() are silly macros, convert them to functions. */
+#if defined(stat)
+static int
+kstat (const char *file_name, struct stat *buf)
+{
+ return stat (file_name, buf);
+}
+#else
+#define kstat stat
+#endif
+
+#if defined(fstat)
+static int
+kfstat (int fd, struct stat *buf)
+{
+ return fstat (fd, buf);
+}
+#else
+#define kfstat fstat
+#endif
+
+
+/*
+ * We use a very simple 'fake' threads subsystem
+ */
+
+SystemCallInterface Kaffe_SystemCallInterface =
+{
+ binary_open,
+ kread,
+ kwrite,
+ klseek,
+ close,
+ kfstat,
+ kstat,
+
+ NULL, /* truncate */
+ NULL, /* fsync */
+ NULL, /* mkdir */
+ NULL, /* rmdir */
+ NULL, /* rename */
+ NULL, /* remove */
+ NULL, /* socket */
+ NULL, /* connect */
+ NULL, /* bind */
+ NULL, /* listen */
+ NULL, /* accept */
+ NULL, /* sockread */
+ NULL, /* recvfrom */
+ NULL, /* sockwrite */
+ NULL, /* sendto */
+ NULL, /* setsockopt */
+ NULL, /* getsockopt */
+ NULL, /* getsockname */
+ NULL, /* getpeername */
+ NULL, /* sockclose */
+ NULL, /* gethostbyname */
+ NULL, /* gethostbyaddr */
+ NULL, /* select */
+ NULL, /* forkexec */
+ NULL, /* waitpid */
+ NULL, /* kill */
+ NULL, /* mmap */
+ NULL, /* munmap */
+ NULL, /* msync */
+ NULL, /* pipecreate */
+ NULL, /* piperead */
+ NULL /* pipewrite */
+};
+
+
+/*
+ * Ensure that files are opened in binary mode; the MS-Windows port
+ * depends on this.
+ */
+static inline int
+binary_open(const char *file, int mode, int perm, int *out) {
+ *out = open(file, mode | O_BINARY, perm);
+ return *out == -1 ? errno : 0;
+}
+
+/*
+ * Init include file.
+ */
+void
+initInclude(void)
+{
+ if (include == NULL) {
+ return;
+ }
+
+ fprintf(include, "/* DO NOT EDIT THIS FILE - it is machine generated */\n");
+ fprintf(include, "#include <native.h>\n");
+ fprintf(include, "\n");
+ fprintf(include, "#ifndef _Included_%s\n", className);
+ fprintf(include, "#define _Included_%s\n", className);
+ fprintf(include, "\n");
+ fprintf(include, "#ifdef __cplusplus\n");
+ fprintf(include, "extern \"C\" {\n");
+ fprintf(include, "#endif\n");
+}
+
+/*
+ * Start include file.
+ */
+void
+startInclude(void)
+{
+ if (include == NULL) {
+ return;
+ }
+
+ fprintf(include, "\n");
+ fprintf(include, "/* Header for class %s */\n", className);
+ fprintf(include, "\n");
+ if ((strcmp (className, "java_lang_Object") == 0) ||
+ (strcmp (className, "java_lang_Class") == 0)) {
+ outputField = 0;
+ }
+ else {
+ outputField = 1;
+ fprintf(include, "typedef struct H%s {\n", className);
+ fprintf(include, " /* Fields from java/lang/Object: */\n");
+ fprintf(include, " Hjava_lang_Object base;\n");
+ }
+}
+
+/*
+ * End include file.
+ */
+void
+endInclude(void)
+{
+ if (include == NULL) {
+ return;
+ }
+
+ fprintf(include, "\n");
+ fprintf(include, "#ifdef __cplusplus\n");
+ fprintf(include, "}\n");
+ fprintf(include, "#endif\n");
+ fprintf(include, "\n");
+ fprintf(include, "#endif\n");
+}
+
+void
+initJniInclude(void)
+{
+ if (jni_include == NULL) {
+ return;
+ }
+
+ fprintf(jni_include, "/* DO NOT EDIT THIS FILE - it is machine generated */\n");
+ fprintf(jni_include, "#include <jni.h>\n");
+ fprintf(jni_include, "\n");
+ fprintf(jni_include, "#ifndef _Included_%s\n", className);
+ fprintf(jni_include, "#define _Included_%s\n", className);
+ fprintf(jni_include, "\n");
+ fprintf(jni_include, "#ifdef __cplusplus\n");
+ fprintf(jni_include, "extern \"C\" {\n");
+ fprintf(jni_include, "#endif\n");
+ fprintf(jni_include, "\n");
+}
+
+void
+startJniInclude(void)
+{
+}
+
+void
+endJniInclude(void)
+{
+ if (jni_include == NULL) {
+ return;
+ }
+
+ fprintf(jni_include, "\n");
+ fprintf(jni_include, "#ifdef __cplusplus\n");
+ fprintf(jni_include, "}\n");
+ fprintf(jni_include, "#endif\n");
+ fprintf(jni_include, "\n");
+ fprintf(jni_include, "#endif\n");
+}
+
+
+bool
+addSourceFile(Hjava_lang_Class* c UNUSED, int idx UNUSED, errorInfo *einfo UNUSED)
+{
+ return true;
+}
+
+bool
+addInnerClasses(Hjava_lang_Class* c UNUSED, size_t len, classFile* fp,
+ errorInfo *einfo UNUSED)
+{
+ /* checkBufSize() done in caller. */
+ seekm(fp, len);
+ return true;
+}
+
+/*
+ * Return the JNI type
+ */
+static const char *
+jniType(const char *sig)
+{
+ switch (sig[0]) {
+ case '[':
+ switch (sig[1]) {
+ case 'Z':
+ return "jbooleanArray";
+ case 'B':
+ return "jbyteArray";
+ case 'C':
+ return "jcharArray";
+ case 'S':
+ return "jshortArray";
+ case 'I':
+ return "jintArray";
+ case 'J':
+ return "jlongArray";
+ case 'F':
+ return "jfloatArray";
+ case 'D':
+ return "jdoubleArray";
+ case 'L':
+ case '[':
+ return "jobjectArray";
+ default:
+ dprintf("bogus array type `%c'", sig[1]);
+ exit(EXIT_FAILURE);
+ }
+ case 'L':
+ if (strncmp(sig, "Ljava/lang/Class;", 17) == 0)
+ return "jclass";
+ if (strncmp(sig, "Ljava/lang/String;", 18) == 0)
+ return "jstring";
+ return "jobject";
+ case 'I':
+ return "jint";
+ case 'Z':
+ return "jboolean";
+ case 'S':
+ return "jshort";
+ case 'B':
+ return "jbyte";
+ case 'C':
+ return "jchar";
+ case 'F':
+ return "jfloat";
+ case 'J':
+ return "jlong";
+ case 'D':
+ return "jdouble";
+ case 'V':
+ return "void";
+ default:
+ dprintf("bogus signature type `%c'", sig[0]);
+ exit(EXIT_FAILURE);
+ }
+}
+
+/*
+ * Print a properly mangled method name or argument signature.
+ */
+static void
+fprintfJni (FILE *f, const char *s)
+{
+ while (*s != '\0' && *s != ')')
+ {
+ switch (*s)
+ {
+ case '/':
+ fprintf (f, "_");
+ break;
+
+ case '_':
+ fprintf (f, "_1");
+ break;
+
+ case ';':
+ fprintf (f, "_2");
+ break;
+
+ case '[':
+ fprintf (f, "_3");
+ break;
+
+ case '$':
+ fprintf (f, "_00024");
+ break;
+
+ default:
+ fprintf (f, "%c", *s);
+ break;
+ }
+ s++;
+ }
+}
+
+int
+startFields(Hjava_lang_Class* this, u2 fct, errorInfo *einfo UNUSED)
+{
+ this->fields = malloc(fct * sizeof(Field));
+ CLASS_NFIELDS(this) = 0; /* incremented by addField() */
+ return true;
+}
+
+Field*
+addField(Hjava_lang_Class* this,
+ u2 access_flags, u2 name_index, u2 signature_index,
+ struct _errorInfo* einfo UNUSED)
+{
+ Field* f;
+
+ if (CLASS_CONST_TAG(this, name_index) != CONSTANT_Utf8) {
+ dprintf("addField(): no method name.\n"); /* XXX */
+ return (NULL);
+ }
+ if (CLASS_CONST_TAG(this, signature_index) != CONSTANT_Utf8) {
+ dprintf("addField(): no signature name.\n"); /* XXX */
+ return (NULL);
+ }
+
+ DBG(CLASSFILE,
+ dprintf("addField(%s.%s)\n",
+ CLASS_CNAME(this), CLASS_CONST_UTF8(this, name_index)->data);
+ );
+
+ f = &(this->fields[CLASS_NFIELDS(this)++]);
+
+ /*
+ * Store enough info for the field attribute "ConstantValue" handler (setFieldValue)
+ * to print the field name/signature/access.
+ */
+ f->name = CLASS_CONST_UTF8(this, name_index);
+ f->type = (Hjava_lang_Class*)CLASS_CONST_UTF8(this, signature_index);
+ f->accflags = access_flags;
+ f->bsize = 0; /* not used by kaffeh */
+ f->info.idx = 0; /* not used by kaffeh */
+
+ if (include != NULL) {
+ /*
+ * Non-static fields are represented in the struct.
+ */
+ if ((!(access_flags & ACC_STATIC)
+ && outputField)) {
+ const char* arg;
+ int argsize = 0;
+
+ arg = translateSig(CLASS_CONST_UTF8(this, signature_index)->data,
+ NULL, &argsize);
+ fprintf(include, " %s %s;\n",
+ arg, CLASS_CONST_UTF8(this, name_index)->data);
+ }
+ }
+
+ return f;
+}
+
+
+static void
+constValueToString(Hjava_lang_Class* this, u2 idx,
+ char *cval)
+{
+ /* XXX use snprintf() */
+
+ /* Pull the constant value for this field out of the constant pool */
+ switch (CLASS_CONST_TAG(this, idx)) {
+ case CONSTANT_Integer:
+ sprintf(cval, "%d", (int)CLASS_CONST_DATA(this, idx));
+ break;
+ case CONSTANT_Float:
+ sprintf(cval, "%.7e", *(float*)&CLASS_CONST_DATA(this,idx));
+ break;
+ case CONSTANT_Long:
+#if SIZEOF_VOID_P == 8
+ sprintf(cval, "0x%016lx", CLASS_CONST_DATA(this,idx));
+#else
+#if defined(WORDS_BIGENDIAN)
+ sprintf(cval, "0x%08x%08x", CLASS_CONST_DATA(this,idx), CLASS_CONST_DATA(this,idx+1));
+#else
+ sprintf(cval, "0x%08x%08x", CLASS_CONST_DATA(this,idx+1), CLASS_CONST_DATA(this,idx));
+#endif
+#endif
+ break;
+ case CONSTANT_Double:
+ {
+ union { jint i[2]; jdouble d; } u;
+ u.i[0] = CLASS_CONST_DATA(this,idx);
+ u.i[1] = CLASS_CONST_DATA(this,idx+1);
+ sprintf(cval, "%.16e", u.d);
+ break;
+ }
+ case CONSTANT_String:
+ /* Note, readConstantPool() puts the Utf8 pointer right into the constant pool for us. */
+ sprintf(cval, "\"%s\"", CLASS_CONST_UTF8(this, idx)->data);
+ break;
+ default:
+ sprintf(cval, "?unsupported type tag %d?", CLASS_CONST_TAG(this, idx));
+ }
+}
+
+
+void
+setFieldValue(Hjava_lang_Class* this, Field* f, u2 idx)
+{
+ assert(f != NULL);
+
+ if ((f->accflags & (ACC_STATIC|ACC_PUBLIC|ACC_FINAL)) == (ACC_STATIC|ACC_PUBLIC|ACC_FINAL)) {
+ char cval[512];
+
+ constValueToString(this, idx, cval);
+
+ if (cval[0] != '\0') {
+ if (include != NULL) {
+ fprintf(include, "#define %s_%s %s\n",
+ className, f->name->data, cval);
+ }
+ if (jni_include != NULL) {
+ fprintf(jni_include, "#define %s_%s %s\n",
+ className, f->name->data, cval);
+ }
+ }
+ }
+}
+
+void
+finishFields(Hjava_lang_Class* this UNUSED)
+{
+ if (include == NULL) {
+ return;
+ }
+
+ if (objectDepth == 0) {
+ if (outputField) {
+ fprintf(include, "} H%s;\n\n", className);
+ }
+ }
+}
+
+int
+startMethods(Hjava_lang_Class* this UNUSED, u2 mct UNUSED,
+ errorInfo *einfo UNUSED)
+{
+ return true;
+}
+
+Method*
+addMethod(Hjava_lang_Class* this,
+ u2 access_flags, u2 name_index, u2 signature_index,
+ struct _errorInfo* einfo)
+{
+ constants* cpool;
+ const char* name;
+ const char* sig;
+ struct _methodRing* list;
+ struct _methodRing* i;
+
+ /* If we shouldn't generate method prototypes, quit now */
+ if (objectDepth > 0) {
+ /* XXX set einfo */
+ return NULL;
+ }
+
+ assert(this != NULL);
+ assert(einfo != NULL);
+
+ cpool = CLASS_CONSTANTS(this);
+
+ if (cpool->tags[name_index] != CONSTANT_Utf8) {
+ dprintf("addMethod(): no method name.\n"); /* XXX */
+ return (NULL);
+ }
+ if (cpool->tags[signature_index] != CONSTANT_Utf8) {
+ dprintf("addMethod(): no signature name.\n"); /* XXX */
+ return (NULL);
+ }
+
+ name = WORD2UTF(cpool->data[name_index])->data;
+ sig = WORD2UTF(cpool->data[signature_index])->data;
+
+ DBG(CLASSFILE,
+ dprintf("addMethod: %s%s%s\n", name, sig,
+ (access_flags & ACC_NATIVE) ? " (native)" : "");
+ );
+
+ /* Only generate stubs for native methods */
+ if (!(access_flags & ACC_NATIVE)) {
+ /* Return "success"... */
+ return (Method*)1;
+ }
+
+ /* add the method into the list of native methods of this class */
+ list = (struct _methodRing *)malloc (sizeof (struct _methodRing));
+
+ list->name = name;
+ list->sig = sig;
+ list->access_flags = access_flags;
+ list->needs_mangled_sig = false;
+
+ if (methodRing == NULL) {
+ methodRing = list;
+
+ list->next = list->prev = list;
+ } else {
+ i = methodRing;
+
+ do {
+
+ if (!strcmp (list->name, i->name)) {
+ /* iff the names are equal, both need a mangled sig */
+ list->needs_mangled_sig = true;
+ i->needs_mangled_sig = true;
+
+ /* insert list */
+ i->next->prev = list;
+ list->next = i->next;
+
+ i->next = list;
+ list->prev = i;
+
+ /* return success */
+ return (Method*)1;
+ }
+
+ i = i->next;
+
+ } while (i != methodRing);
+
+ /* if we didn't find a suitable place, add it at the end of the list */
+ i->prev->next = list;
+ list->prev = i->prev;
+
+ i->prev = list;
+ list->next = i;
+ }
+
+ return (Method*)1;
+}
+
+void
+finishMethods (Hjava_lang_Class *this UNUSED)
+{
+ const char *str;
+ const char *tsig;
+ struct _methodRing* i;
+ struct _methodRing* tmp;
+
+ /* don't do anything if there aren't any methods */
+ if (methodRing == NULL) {
+ return;
+ }
+
+ i = methodRing;
+ do {
+ int args = 0;
+ char* ret;
+
+ /* Generate method prototype */
+ ret = strchr(i->sig,')');
+ ret++;
+
+ if (include != NULL) {
+ fprintf(include, "extern %s", translateSig(ret, 0, 0));
+ fprintf(include, " %s_%s(", className, i->name);
+ if (!(i->access_flags & ACC_STATIC)) {
+ fprintf(include, "struct H%s*", className);
+ if (i->sig[1] != ')') {
+ fprintf(include, ", ");
+ }
+ } else if (i->sig[1] == ')') {
+ fprintf(include, "void");
+ }
+ }
+
+ if (jni_include != NULL) {
+ fprintf(jni_include, "JNIEXPORT %s JNICALL Java_%s_",
+ jniType(ret), className);
+
+ fprintfJni(jni_include, i->name);
+
+ /* append mangled sig if necessary */
+ if (i->needs_mangled_sig) {
+ fprintf(jni_include, "__");
+
+ fprintfJni(jni_include, i->sig+1);
+ }
+
+ fprintf(jni_include, "(JNIEnv*");
+
+ if ((i->access_flags & ACC_STATIC)) {
+ fprintf(jni_include, ", jclass");
+ }
+ else {
+ fprintf(jni_include, ", jobject");
+ }
+ }
+
+ str = i->sig + 1;
+ args++;
+ while (str[0] != ')') {
+ if (jni_include != NULL)
+ fprintf(jni_include, ", %s", jniType(str));
+ tsig = translateSig(str, &str, &args);
+ if (include != NULL) {
+ fprintf(include, "%s", tsig);
+ if (str[0] != ')') {
+ fprintf(include, ", ");
+ }
+ }
+ }
+ if (include != NULL) {
+ fprintf(include, ");\n");
+ }
+ if (jni_include != NULL) {
+ fprintf(jni_include, ");\n");
+ }
+
+ /* move to next method */
+ tmp = i;
+ i = i->next;
+
+ /* free old one */
+ free (tmp);
+
+ } while (i != methodRing);
+
+ /* we don't have any methods any more */
+ methodRing = NULL;
+}
+
+bool
+addCode(Method* m, size_t len, classFile* fp, errorInfo *einfo UNUSED)
+{
+ /* Don't try dereferencing m! */
+ assert(m == (Method*)1);
+
+ /* checkBufSize() done in caller. */
+ seekm(fp, len);
+ return true;
+}
+
+bool
+addLineNumbers(Method* m, size_t len, classFile* fp, errorInfo *info UNUSED)
+{
+ /* Don't try dereferencing m! */
+ assert(m == (Method*)1);
+
+ /* checkBufSize() done in caller. */
+ seekm(fp, len);
+ return true;
+}
+
+bool
+addLocalVariables(Method* m, size_t len, classFile* fp, errorInfo *info UNUSED)
+{
+ /* Don't try dereferencing m! */
+ assert(m == (Method*)1);
+
+ /* checkBufSize() done in caller. */
+ seekm(fp, len);
+ return true;
+}
+
+bool
+addCheckedExceptions(Method* m, size_t len, classFile* fp,
*** Patch too long, truncated ***
More information about the kaffe
mailing list