added loging functions, made kaffe tests run
[cacao.git] / src / native / vm / Constructor.c
1 /* class: java/lang/reflect/Constructor */
2
3
4 #include "jni.h"
5 #include "builtin.h"
6 #include "loader.h"
7 #include "native.h"
8 #include "tables.h"
9 #include "asmpart.h"
10 #include "java_lang_Class.h"
11 #include "java_lang_reflect_Constructor.h"
12
13
14 /*
15  * Class:     java/lang/reflect/Constructor
16  * Method:    newInstance
17  * Signature: ([Ljava/lang/Object;)Ljava/lang/Object;
18  */
19 JNIEXPORT struct java_lang_Object* JNICALL Java_java_lang_reflect_Constructor_constructNative( JNIEnv *env ,  struct java_lang_reflect_Constructor* this, 
20         java_objectarray* parameters,struct java_lang_Class* clazz, s4 par3)
21 {
22
23 #warning fix me for parameters float/double and long long  parameters
24
25         methodinfo *m;
26         java_objectheader *o;
27
28         
29 /*      log_text("Java_java_lang_reflect_Constructor_constructNative called");
30         log_plain_utf(((struct classinfo*)clazz)->name);*/
31         log_plain("\n");
32
33         /* find initializer */
34
35         if (!parameters) {
36                 if (this->parameterTypes->header.size!=0) {
37                         log_text("Parameter count mismatch in Java_java_lang_reflect_Constructor_constructNative(1)");
38 #warning throw an exception here
39                         return 0;
40                 }
41         } else
42         if (this->parameterTypes->header.size!=parameters->header.size) {
43                 log_text("Parameter count mismatch in Java_java_lang_reflect_Constructor_constructNative(2)");
44 #warning throw an exception here
45                 return 0;
46         }
47
48         if (this->slot>=((classinfo*)clazz)->methodscount) {
49                 log_text("illegal index in methods table");
50                 return 0;
51         }
52
53         o = builtin_new (clazz);         /*          create object */
54         if (!o) {
55                 log_text("Objet instance could not be created");
56                 return NULL;
57         }
58         
59 /*      log_text("o!=NULL\n");*/
60
61
62         m = &((classinfo*)clazz)->methods[this->slot];
63         if (!((m->name == utf_new_char("<init>"))))
64 /* && 
65                   (m->descriptor == create_methodsig(this->parameterTypes,"V"))))*/
66         {
67                 if (verbose) {
68                                                 char logtext[MAXLOGTEXT];
69                         sprintf(logtext, "Warning: class has no instance-initializer of specified type: ");
70                         utf_sprint(logtext + strlen(logtext), ((struct classinfo*)clazz)->name);
71                         dolog(logtext);
72                         log_plain_utf( create_methodsig(this->parameterTypes,"V"));
73                         log_plain("\n");
74                         class_showconstantpool(clazz);
75                         }
76 #warning throw an exception here, although this should never happen
77                 return o;
78                 }
79
80 /*      log_text("calling initializer");*/
81         /* call initializer */
82 #if 0
83         switch (this->parameterTypes->header.size) {
84                 case 0: exceptionptr=asm_calljavamethod (m, o, NULL, NULL, NULL);
85                         break;
86                 case 1: exceptionptr=asm_calljavamethod (m, o, parameters->data[0], NULL, NULL);
87                         break;
88                 case 2: exceptionptr=asm_calljavamethod (m, o, parameters->data[0], parameters->data[1], NULL);
89                         break;
90                 case 3: exceptionptr=asm_calljavamethod (m, o, parameters->data[0], parameters->data[1], 
91                                 parameters->data[2]);
92                         break;
93                 default:
94                         log_text("Not supported number of arguments in Java_java_lang_reflect_Constructor");
95         }
96 #endif
97                 /*log_plain_utf(m->descriptor);
98                 log_text("calling constructor");*/
99                 (void) jni_method_invokeNativeHelper(env, m ,o, parameters); 
100
101         return o;
102 }
103
104 /*
105  * Class:     java_lang_reflect_Constructor
106  * Method:    getModifiers
107  * Signature: ()I
108  */
109 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Constructor_getModifiers (JNIEnv *env ,  struct java_lang_reflect_Constructor* this ) {
110 /*      log_text("Java_java_lang_reflect_Constructor_getModifiers called");*/
111         classinfo *c=(classinfo*)(this->clazz);
112         if ((this->slot<0) || (this->slot>=c->methodscount))
113                 panic("error illegal slot for method in class (getReturnType)");
114         return (c->methods[this->slot]).flags & (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED);
115 }
116
117
118 /*
119  * These are local overrides for various environment variables in Emacs.
120  * Please do not remove this and leave it at the end of the file, where
121  * Emacs will automagically detect them.
122  * ---------------------------------------------------------------------
123  * Local variables:
124  * mode: c
125  * indent-tabs-mode: t
126  * c-basic-offset: 4
127  * tab-width: 4
128  * End:
129  */