GNU header update.
[cacao.git] / src / native / vm / Constructor.c
index d8826e01a55e627d2684b4fd6b5e345429673a7c..cf26f54af17b0b802f63395d4a499a7279d56b06 100644 (file)
@@ -1,14 +1,52 @@
-/* class: java/lang/reflect/Constructor */
+/* native/vm/Constructor.c - java/lang/reflect/Constructor
 
+   Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
+   R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
+   C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
+   Institut f. Computersprachen - TU Wien
 
-#include "jni.h"
-#include "builtin.h"
-#include "loader.h"
-#include "native.h"
-#include "tables.h"
-#include "asmpart.h"
-#include "java_lang_Class.h"
-#include "java_lang_reflect_Constructor.h"
+   This file is part of CACAO.
+
+   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, 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.
+
+   Contact: cacao@complang.tuwien.ac.at
+
+   Authors: Roman Obermaiser
+
+   Changes: Joseph Wenninger
+
+   $Id: Constructor.c 1735 2004-12-07 14:33:27Z twisti $
+
+*/
+
+
+#include <string.h>
+
+#include "native/jni.h"
+#include "native/native.h"
+#include "native/include/java_lang_Class.h"
+#include "native/include/java_lang_Object.h"
+#include "native/include/java_lang_reflect_Constructor.h"
+#include "toolbox/logging.h"
+#include "vm/builtin.h"
+#include "vm/exceptions.h"
+#include "vm/loader.h"
+#include "vm/options.h"
+#include "vm/tables.h"
+#include "vm/jit/asmpart.h"
 
 
 /*
  * Method:    newInstance
  * Signature: ([Ljava/lang/Object;)Ljava/lang/Object;
  */
-JNIEXPORT struct java_lang_Object* JNICALL Java_java_lang_reflect_Constructor_constructNative( JNIEnv *env ,  struct java_lang_reflect_Constructor* this, 
-       java_objectarray* parameters,struct java_lang_Class* clazz, s4 par3)
+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)
 {
 
+#if defined(__GNUC__)
 #warning fix me for parameters float/double and long long  parameters
+#endif
 
        methodinfo *m;
-        java_objectheader *o;
+       java_objectheader *o;
 
-        
-/*     log_text("Java_java_lang_reflect_Constructor_constructNative called");
-        utf_display(((struct classinfo*)clazz)->name);*/
-        printf("\n");
-
-        /* find initializer */
+       /* find initializer */
 
        if (!parameters) {
-               if (this->parameterTypes->header.size!=0) {
-                       log_text("Parameter count mismatch in Java_java_lang_reflect_Constructor_constructNative(1)");
-#warning throw an exception here
+               if (this->parameterTypes->header.size != 0) {
+                       *exceptionptr =
+                               new_exception_message(string_java_lang_IllegalArgumentException,
+                                                                         "wrong number of arguments");
+                       return 0;
+               }
+
+       } else {
+               if (this->parameterTypes->header.size != parameters->header.size) {
+                       *exceptionptr =
+                               new_exception_message(string_java_lang_IllegalArgumentException,
+                                                                         "wrong number of arguments");
                        return 0;
                }
-       } else
-       if (this->parameterTypes->header.size!=parameters->header.size) {
-               log_text("Parameter count mismatch in Java_java_lang_reflect_Constructor_constructNative(2)");
-#warning throw an exception here
-               return 0;
        }
 
-       if (this->slot>=((classinfo*)clazz)->methodscount) {
+       if (this->slot >= ((classinfo *) clazz)->methodscount) {
                log_text("illegal index in methods table");
                return 0;
        }
 
-       o = builtin_new (clazz);         /*          create object */
-        if (!o) {
+       o = builtin_new((classinfo *) clazz);         /*          create object */
+       if (!o) {
                log_text("Objet instance could not be created");
                return NULL;
        }
         
-/*     log_text("o!=NULL\n");*/
+       /*      log_text("o!=NULL\n");*/
 
 
-        m = &((classinfo*)clazz)->methods[this->slot];
+       m = &((classinfo *)clazz)->methods[this->slot];
        if (!((m->name == utf_new_char("<init>"))))
-/* && 
-                  (m->descriptor == create_methodsig(this->parameterTypes,"V"))))*/
-       {
-                if (verbose) {
-                        sprintf(logtext, "Warning: class has no instance-initializer of specified type: ");
-                        utf_sprint(logtext + strlen(logtext), ((struct classinfo*)clazz)->name);
-                        dolog();
-                       utf_display( create_methodsig(this->parameterTypes,"V"));
-                       printf("\n");
-                       class_showconstantpool(clazz);
-                        }
+               /* && 
+                  (m->descriptor == create_methodsig(this->parameterTypes,"V"))))*/
+               {
+                       if (opt_verbose) {
+                               char logtext[MAXLOGTEXT];
+                               sprintf(logtext, "Warning: class has no instance-initializer of specified type: ");
+                               utf_sprint(logtext + strlen(logtext), ((classinfo *) clazz)->name);
+                               log_text(logtext);
+                               log_plain_utf( create_methodsig(this->parameterTypes,"V"));
+                               log_plain("\n");
+                               class_showconstantpool((classinfo *) clazz);
+                       }
+#if defined(__GNUC__)
 #warning throw an exception here, although this should never happen
-                return o;
-                }
+#endif
+                       return (java_lang_Object *) o;
+               }
 
-/*     log_text("calling initializer");*/
-        /* call initializer */
+       /*      log_text("calling initializer");*/
+       /* call initializer */
 #if 0
        switch (this->parameterTypes->header.size) {
-               case 0: exceptionptr=asm_calljavamethod (m, o, NULL, NULL, NULL);
-                       break;
-               case 1: exceptionptr=asm_calljavamethod (m, o, parameters->data[0], NULL, NULL);
-                       break;
-               case 2: exceptionptr=asm_calljavamethod (m, o, parameters->data[0], parameters->data[1], NULL);
-                       break;
-               case 3: exceptionptr=asm_calljavamethod (m, o, parameters->data[0], parameters->data[1], 
-                               parameters->data[2]);
-                       break;
-               default:
-                       log_text("Not supported number of arguments in Java_java_lang_reflect_Constructor");
+       case 0: exceptionptr=asm_calljavamethod (m, o, NULL, NULL, NULL);
+               break;
+       case 1: exceptionptr=asm_calljavamethod (m, o, parameters->data[0], NULL, NULL);
+               break;
+       case 2: exceptionptr=asm_calljavamethod (m, o, parameters->data[0], parameters->data[1], NULL);
+               break;
+       case 3: exceptionptr=asm_calljavamethod (m, o, parameters->data[0], parameters->data[1], 
+                                                                                        parameters->data[2]);
+       break;
+       default:
+               log_text("Not supported number of arguments in Java_java_lang_reflect_Constructor");
        }
 #endif
-               /*utf_display(m->descriptor);
-               log_text("calling constructor");*/
-               (void) jni_method_invokeNativeHelper(env, m ,o, parameters); 
 
-        return o;
+       (void) jni_method_invokeNativeHelper(env, m ,o, parameters); 
+
+       return (java_lang_Object *) o;
 }
 
+
 /*
  * Class:     java_lang_reflect_Constructor
  * Method:    getModifiers
  * Signature: ()I
  */
-JNIEXPORT s4 JNICALL Java_java_lang_reflect_Constructor_getModifiers (JNIEnv *env ,  struct java_lang_reflect_Constructor* this ) {
-/*     log_text("Java_java_lang_reflect_Constructor_getModifiers called");*/
-        classinfo *c=(classinfo*)(this->clazz);
-        if ((this->slot<0) || (this->slot>=c->methodscount))
-                panic("error illegal slot for method in class (getReturnType)");
-        return (c->methods[this->slot]).flags & (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED);
+JNIEXPORT s4 JNICALL Java_java_lang_reflect_Constructor_getModifiers(JNIEnv *env, java_lang_reflect_Constructor *this)
+{
+       classinfo *c = (classinfo *) (this->clazz);
+
+       if ((this->slot < 0) || (this->slot >= c->methodscount))
+               panic("error illegal slot for constructor in class (getModifiers)");
+
+       return (c->methods[this->slot]).flags & (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED);
 }