* src/vm/linker.cpp,
[cacao.git] / src / vm / descriptor.h
index c62d72e650414a35d3ea810335c652e4a33038e3..bf6c69efb458d7d3360f72bf23170af3b75a18a7 100644 (file)
@@ -1,9 +1,7 @@
-/* vm/descriptor.h - checking and parsing of field / method descriptors
+/* src/vm/descriptor.h - checking and parsing of field / method descriptors
 
-   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
+   Copyright (C) 1996-2005, 2006, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
 
    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: Edwin Steiner
-
-   Changes:
-
-   $Id: descriptor.h 2112 2005-03-29 21:29:08Z twisti $
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
 
 */
 
 /* forward typedefs ***********************************************************/
 
 typedef struct descriptor_pool descriptor_pool;
-typedef struct typedesc typedesc;
-typedef struct methoddesc methoddesc;
-typedef union parseddesc parseddesc;
+typedef struct typedesc        typedesc;
+typedef struct paramdesc       paramdesc;
+typedef struct methoddesc      methoddesc;
+
 
+#include "config.h"
 
-#include "types.h"
-#include "vm/class.h"
+#include <stdint.h>
+
+#include "vm/types.h"
+
+#include "toolbox/hashtable.h"
+
+#include "vm/class.hpp"
 #include "vm/global.h"
-#include "vm/tables.h"
+#include "vm/method.hpp"
+#include "vm/references.h"
 #include "vm/utf8.h"
 
+#include "arch.h"              /* needed for HAS_ADDRESS_REGISTER_FILE */
 
-/* data structures ************************************************************/ 
+
+/* data structures ************************************************************/
 
 /*----------------------------------------------------------------------------*/
 /* Descriptor Pools                                                           */
@@ -98,268 +98,97 @@ struct descriptor_pool {
 /* data structures for parsed field/method descriptors ************************/
 
 struct typedesc {
-       constant_classref *classref;   /* class reference for TYPE_ADR types      */
-       u1                 type;       /* TYPE_??? constant                       */
-       u1                 arraydim;   /* array dimension (0 if no array)         */
+       constant_classref *classref;      /* class reference for TYPE_ADR types   */
+       u1                 type;          /* TYPE_??? constant [1]                */
+       u1                 primitivetype; /* (PRIMITIVE)TYPE_??? constant [2]     */
+       u1                 arraydim;      /* array dimension (0 if no array)      */
 };
 
-struct methoddesc {
-       s2                 paramcount; /* number of parameters                    */
-       s2                 paramslots; /* like above but LONG,DOUBLE count twice  */
-       typedesc           returntype; /* parsed descriptor of the return type    */
-       typedesc           paramtypes[1]; /* parameter types, variable length!    */
+/* [1]...the type field contains the basic type used within the VM. So ints,  */
+/*       shorts, chars, bytes, booleans all have TYPE_INT.                    */
+/* [2]...the primitivetype field contains the declared type.                  */
+/*       So short is PRIMITIVETYPE_SHORT, char is PRIMITIVETYPE_CHAR.         */
+/*       For non-primitive types primitivetype is TYPE_ADR.                   */
+
+struct paramdesc {
+#if defined(__MIPS__)
+       u1   type;                  /* TYPE_??? of the register allocated         */
+#endif
+       bool     inmemory;          /* argument in register or on stack           */
+       uint32_t index;             /* index into argument register array         */
+       uint32_t regoff;            /* register index or stack offset             */
 };
 
-union parseddesc {
-       typedesc          *fd;        /* parsed field descriptor                  */
-       methoddesc        *md;        /* parsed method descriptor                 */
-       void              *any;       /* used for simple test against NULL        */
+struct methoddesc {
+       s2         paramcount;      /* number of parameters                       */
+       s2         paramslots;      /* like above but LONG,DOUBLE count twice     */
+       s4         argintreguse;    /* number of used integer argument registers  */
+       s4         argfltreguse;    /* number of used float argument registers    */
+#if defined(HAS_ADDRESS_REGISTER_FILE)
+       s4         argadrreguse;    /* number of used address registers */
+#endif
+       s4         memuse;          /* number of stack slots used                 */
+       paramdesc *params;          /* allocated parameter descriptions [3]       */
+       typedesc   returntype;      /* parsed descriptor of the return type       */
+       typedesc   paramtypes[1];   /* parameter types, variable length!          */
 };
 
+/* [3]...If params is NULL, the parameter descriptions have not yet been      */
+/*       allocated. In this case ___the possible 'this' pointer of the method */
+/*       is NOT counted in paramcount/paramslots and it is NOT included in    */
+/*       the paramtypes array___.                                             */
+/*       If params != NULL, the parameter descriptions have been              */
+/*       allocated, and the 'this' pointer of the method, if any, IS included.*/
+/*       In case the method has no parameters at all, the special value       */
+/*       METHODDESC_NO_PARAMS is used (see below).                            */
 
-/* function prototypes ********************************************************/
-
-/* descriptor_debug_print_typedesc *********************************************
-   Print the given typedesc to the given stream
-
-   IN:
-          file.............stream to print to
-          d................the parsed descriptor
-
-*******************************************************************************/
+/* METHODDESC_NO_PARAMS is a special value for the methoddesc.params field    */
+/* indicating that the method is a static method without any parameters.      */
+/* This special value must be != NULL and it may only be set if               */
+/* md->paramcount == 0.                                                       */
 
-void descriptor_debug_print_typedesc(FILE *file,typedesc *d);
-
-/* descriptor_debug_print_methoddesc *******************************************
-   Print the given methoddesc to the given stream
-
-   IN:
-          file.............stream to print to
-          d................the parsed descriptor
+#define METHODDESC_NOPARAMS  ((paramdesc*)1)
 
-*******************************************************************************/
-
-void descriptor_debug_print_methoddesc(FILE *file,methoddesc *d);
-
-/* descriptor_pool_new *********************************************************
-   Allocate a new descriptor_pool
-
-   IN:
-       referer..........class for which to create the pool
-
-   RETURN VALUE:
-       a pointer to the new descriptor_pool
+/* function prototypes ********************************************************/
 
-*******************************************************************************/
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 descriptor_pool * descriptor_pool_new(classinfo *referer);
 
-/* descriptor_pool_add_class ***************************************************
-   Add the given class reference to the pool
-
-   IN:
-       pool.............the descriptor_pool
-          name.............the class reference to add
-
-   RETURN VALUE:
-       true.............reference has been added
-          false............an exception has been thrown
-
-*******************************************************************************/
-
 bool descriptor_pool_add_class(descriptor_pool *pool,utf *name);
+bool descriptor_pool_add(descriptor_pool *pool,utf *desc,int *paramslots);
 
-/* descriptor_pool_add *********************************************************
-   Check the given descriptor and add it to the pool
-
-   IN:
-       pool.............the descriptor_pool
-          desc.............the descriptor to add. Maybe a field or method desc.
-
-   RETURN VALUE:
-       true.............descriptor has been added
-          false............an exception has been thrown
-
-*******************************************************************************/
-
-bool descriptor_pool_add(descriptor_pool *pool,utf *desc);
-
-/* descriptor_pool_create_classrefs ********************************************
-   Create a table containing all the classrefs which were added to the pool
-
-   IN:
-       pool.............the descriptor_pool
-
-   OUT:
-       *count...........if count is non-NULL, this is set to the number
-                           of classrefs in the table
-
-   RETURN VALUE:
-       a pointer to the constant_classref table
-
-*******************************************************************************/
+int  descriptor_to_basic_type(utf *desc);
+int  descriptor_typesize(typedesc *td);
 
 constant_classref * descriptor_pool_create_classrefs(descriptor_pool *pool,
                                                                                                         s4 *count);
-
-/* descriptor_pool_lookup_classref *********************************************
-   Return the constant_classref for the given class name
-
-   IN:
-       pool.............the descriptor_pool
-          classname........name of the class to look up
-
-   RETURN VALUE:
-       a pointer to the constant_classref, or
-          NULL if an exception has been thrown
-
-*******************************************************************************/
-
 constant_classref * descriptor_pool_lookup_classref(descriptor_pool *pool,utf *classname);
 
-/* descriptor_pool_alloc_parsed_descriptors ************************************
-   Allocate space for the parsed descriptors
-
-   IN:
-       pool.............the descriptor_pool
-
-   NOTE:
-       This function must be called after all descriptors have been added
-          with descriptor_pool_add.
-
-*******************************************************************************/
-
 void descriptor_pool_alloc_parsed_descriptors(descriptor_pool *pool);
 
-/* descriptor_pool_parse_field_descriptor **************************************
-   Parse the given field descriptor
-
-   IN:
-       pool.............the descriptor_pool
-          desc.............the field descriptor
-
-   RETURN VALUE:
-       a pointer to the parsed field descriptor, or
-          NULL if an exception has been thrown
-
-   NOTE:
-       descriptor_pool_alloc_parsed_descriptors must be called (once) before this
-          function is used.
-
-*******************************************************************************/
-
-typedesc * descriptor_pool_parse_field_descriptor(descriptor_pool *pool,utf *desc);
-
-/* descriptor_pool_parse_method_descriptor *************************************
-   Parse the given method descriptor
-
-   IN:
-       pool.............the descriptor_pool
-          desc.............the method descriptor
-
-   RETURN VALUE:
-       a pointer to the parsed method descriptor, or
-          NULL if an exception has been thrown
-
-   NOTE:
-       descriptor_pool_alloc_parsed_descriptors must be called (once) before this
-          function is used.
-
-*******************************************************************************/
-
-methoddesc * descriptor_pool_parse_method_descriptor(descriptor_pool *pool,utf *desc);
-
-/* descriptor_pool_get_parsed_descriptors **************************************
-   Return a pointer to the block of parsed descriptors
-
-   IN:
-       pool.............the descriptor_pool
+typedesc *descriptor_pool_parse_field_descriptor(descriptor_pool *pool, utf *desc);
+methoddesc *descriptor_pool_parse_method_descriptor(descriptor_pool *pool, utf *desc, s4 mflags,
+                                                                                                       constant_classref *thisclass);
 
-   OUT:
-          *size............if size is non-NULL, this is set to the size of the
-                           parsed descriptor block (in u1)
+bool descriptor_params_from_paramtypes(methoddesc *md, s4 mflags);
 
-   RETURN VALUE:
-       a pointer to the block of parsed descriptors,
-          NULL if there are no descriptors in the pool
-
-   NOTE:
-       descriptor_pool_alloc_parsed_descriptors must be called (once) before this
-          function is used.
-
-*******************************************************************************/
-
-void * descriptor_pool_get_parsed_descriptors(descriptor_pool *pool,
-                                                                                         s4 *size);
-
-/* descriptor_pool_get_sizes ***************************************************
-   Get the sizes of the class reference table and the parsed descriptors
-
-   IN:
-       pool.............the descriptor_pool
-
-   OUT:
-       *classrefsize....set to size of the class reference table
-          *descsize........set to size of the parsed descriptors
-
-   NOTE:
-       This function may only be called after both
-              descriptor_pool_create_classrefs, and
-                  descriptor_pool_alloc_parsed_descriptors
-          have been called.
-
-*******************************************************************************/
-
-void descriptor_pool_get_sizes(descriptor_pool *pool,
-                                                          u4 *classrefsize,u4 *descsize);
-
-/* descriptor_debug_print_typedesc *********************************************
-   Print the given typedesc to the given stream
-
-   IN:
-          file.............stream to print to
-          d................the parsed descriptor
-
-*******************************************************************************/
+void *descriptor_pool_get_parsed_descriptors(descriptor_pool *pool, s4 *size);
+void descriptor_pool_get_sizes(descriptor_pool *pool, u4 *classrefsize,
+                                                          u4 *descsize);
 
+#ifndef NDEBUG
 void descriptor_debug_print_typedesc(FILE *file,typedesc *d);
-
-/* descriptor_debug_print_methoddesc *******************************************
-   Print the given methoddesc to the given stream
-
-   IN:
-          file.............stream to print to
-          d................the parsed descriptor
-
-*******************************************************************************/
-
 void descriptor_debug_print_methoddesc(FILE *file,methoddesc *d);
+void descriptor_debug_print_paramdesc(FILE *file,paramdesc *d);
+void descriptor_pool_debug_dump(descriptor_pool *pool, FILE *file);
+#endif /* !defined(NDEBUG) */
 
-/* descriptor_pool_debug_dump **************************************************
-   Print the state of the descriptor_pool to the given stream
-
-   IN:
-       pool.............the descriptor_pool
-          file.............stream to print to
-
-*******************************************************************************/
-
-void descriptor_pool_debug_dump(descriptor_pool *pool,FILE *file);
+#ifdef __cplusplus
+}
+#endif
 
 #endif /* _DESCRIPTOR_H */