GNU header update.
[cacao.git] / src / native / vm / Constructor.c
1 /* native/vm/Constructor.c - java/lang/reflect/Constructor
2
3    Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4    R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5    C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6    Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Roman Obermaiser
28
29    Changes: Joseph Wenninger
30
31    $Id: Constructor.c 1735 2004-12-07 14:33:27Z twisti $
32
33 */
34
35
36 #include <string.h>
37
38 #include "native/jni.h"
39 #include "native/native.h"
40 #include "native/include/java_lang_Class.h"
41 #include "native/include/java_lang_Object.h"
42 #include "native/include/java_lang_reflect_Constructor.h"
43 #include "toolbox/logging.h"
44 #include "vm/builtin.h"
45 #include "vm/exceptions.h"
46 #include "vm/loader.h"
47 #include "vm/options.h"
48 #include "vm/tables.h"
49 #include "vm/jit/asmpart.h"
50
51
52 /*
53  * Class:     java/lang/reflect/Constructor
54  * Method:    newInstance
55  * Signature: ([Ljava/lang/Object;)Ljava/lang/Object;
56  */
57 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Constructor_constructNative(JNIEnv *env, java_lang_reflect_Constructor *this, java_objectarray *parameters, java_lang_Class *clazz, s4 par3)
58 {
59
60 #if defined(__GNUC__)
61 #warning fix me for parameters float/double and long long  parameters
62 #endif
63
64         methodinfo *m;
65         java_objectheader *o;
66
67         /* find initializer */
68
69         if (!parameters) {
70                 if (this->parameterTypes->header.size != 0) {
71                         *exceptionptr =
72                                 new_exception_message(string_java_lang_IllegalArgumentException,
73                                                                           "wrong number of arguments");
74                         return 0;
75                 }
76
77         } else {
78                 if (this->parameterTypes->header.size != parameters->header.size) {
79                         *exceptionptr =
80                                 new_exception_message(string_java_lang_IllegalArgumentException,
81                                                                           "wrong number of arguments");
82                         return 0;
83                 }
84         }
85
86         if (this->slot >= ((classinfo *) clazz)->methodscount) {
87                 log_text("illegal index in methods table");
88                 return 0;
89         }
90
91         o = builtin_new((classinfo *) clazz);         /*          create object */
92         if (!o) {
93                 log_text("Objet instance could not be created");
94                 return NULL;
95         }
96         
97         /*      log_text("o!=NULL\n");*/
98
99
100         m = &((classinfo *)clazz)->methods[this->slot];
101         if (!((m->name == utf_new_char("<init>"))))
102                 /* && 
103                    (m->descriptor == create_methodsig(this->parameterTypes,"V"))))*/
104                 {
105                         if (opt_verbose) {
106                                 char logtext[MAXLOGTEXT];
107                                 sprintf(logtext, "Warning: class has no instance-initializer of specified type: ");
108                                 utf_sprint(logtext + strlen(logtext), ((classinfo *) clazz)->name);
109                                 log_text(logtext);
110                                 log_plain_utf( create_methodsig(this->parameterTypes,"V"));
111                                 log_plain("\n");
112                                 class_showconstantpool((classinfo *) clazz);
113                         }
114 #if defined(__GNUC__)
115 #warning throw an exception here, although this should never happen
116 #endif
117                         return (java_lang_Object *) o;
118                 }
119
120         /*      log_text("calling initializer");*/
121         /* call initializer */
122 #if 0
123         switch (this->parameterTypes->header.size) {
124         case 0: exceptionptr=asm_calljavamethod (m, o, NULL, NULL, NULL);
125                 break;
126         case 1: exceptionptr=asm_calljavamethod (m, o, parameters->data[0], NULL, NULL);
127                 break;
128         case 2: exceptionptr=asm_calljavamethod (m, o, parameters->data[0], parameters->data[1], NULL);
129                 break;
130         case 3: exceptionptr=asm_calljavamethod (m, o, parameters->data[0], parameters->data[1], 
131                                                                                          parameters->data[2]);
132         break;
133         default:
134                 log_text("Not supported number of arguments in Java_java_lang_reflect_Constructor");
135         }
136 #endif
137
138         (void) jni_method_invokeNativeHelper(env, m ,o, parameters); 
139
140         return (java_lang_Object *) o;
141 }
142
143
144 /*
145  * Class:     java_lang_reflect_Constructor
146  * Method:    getModifiers
147  * Signature: ()I
148  */
149 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Constructor_getModifiers(JNIEnv *env, java_lang_reflect_Constructor *this)
150 {
151         classinfo *c = (classinfo *) (this->clazz);
152
153         if ((this->slot < 0) || (this->slot >= c->methodscount))
154                 panic("error illegal slot for constructor in class (getModifiers)");
155
156         return (c->methods[this->slot]).flags & (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED);
157 }
158
159
160 /*
161  * These are local overrides for various environment variables in Emacs.
162  * Please do not remove this and leave it at the end of the file, where
163  * Emacs will automagically detect them.
164  * ---------------------------------------------------------------------
165  * Local variables:
166  * mode: c
167  * indent-tabs-mode: t
168  * c-basic-offset: 4
169  * tab-width: 4
170  * End:
171  */