1 /* src/vmcore/descriptor.h - checking and parsing of field / method descriptors
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA
25 $Id: descriptor.h 7456 2007-03-05 16:13:11Z tbfg $
33 /* forward typedefs ***********************************************************/
35 typedef struct descriptor_pool descriptor_pool;
36 typedef struct typedesc typedesc;
37 typedef struct paramdesc paramdesc;
38 typedef struct methoddesc methoddesc;
44 #include "toolbox/hashtable.h"
46 #include "vm/global.h"
48 #include "vmcore/class.h"
49 #include "vmcore/method.h"
50 #include "vmcore/references.h"
51 #include "vmcore/utf8.h"
53 #include "arch.h" /* needed for HAS_ADDRESS_REGISTER_FILE */
55 /* data structures ************************************************************/
57 /*----------------------------------------------------------------------------*/
58 /* Descriptor Pools */
60 /* A descriptor_pool is a temporary data structure used during loading of */
61 /* a class. The descriptor_pool is used to allocate the table of */
62 /* constant_classrefs the class uses, and for parsing the field and method */
63 /* descriptors which occurr within the class. The inner workings of */
64 /* descriptor_pool are not important for outside code. */
66 /* You use a descriptor_pool as follows: */
68 /* 1. create one with descriptor_pool_new */
69 /* 2. add all explicit class references with descriptor_pool_add_class */
70 /* 3. add all field/method descriptors with descriptor_pool_add */
71 /* 4. call descriptor_pool_create_classrefs */
72 /* You can now lookup classrefs with descriptor_pool_lookup_classref */
73 /* 5. call descriptor_pool_alloc_parsed_descriptors */
74 /* 6. for each field descriptor call descriptor_pool_parse_field_descriptor */
75 /* for each method descriptor call descriptor_pool_parse_method_descriptor */
76 /* 7. call descriptor_pool_get_parsed_descriptors */
78 /* IMPORTANT: The descriptor_pool functions use DNEW and DMNEW for allocating */
79 /* memory which can be thrown away when the steps above have been */
81 /*----------------------------------------------------------------------------*/
83 struct descriptor_pool {
91 hashtable descriptorhash;
92 constant_classref *classrefs;
93 hashtable classrefhash;
94 u1 *descriptor_kind; /* useful for debugging */
95 u1 *descriptor_kind_next; /* useful for debugging */
99 /* data structures for parsed field/method descriptors ************************/
102 constant_classref *classref; /* class reference for TYPE_ADR types */
103 u1 type; /* TYPE_??? constant [1] */
104 u1 decltype; /* (PRIMITIVE)TYPE_??? constant [2] */
105 u1 arraydim; /* array dimension (0 if no array) */
108 /* [1]...the type field contains the basic type used within the VM. So ints, */
109 /* shorts, chars, bytes, booleans all have TYPE_INT. */
110 /* [2]...the decltype field contains the declared type. */
111 /* So short is PRIMITIVETYPE_SHORT, char is PRIMITIVETYPE_CHAR. */
112 /* For non-primitive types decltype is TYPE_ADR. */
115 #if defined(__MIPS__)
116 u1 type; /* TYPE_??? of the register allocated */
118 bool inmemory; /* argument in register or on stack */
119 s4 regoff; /* register index or stack offset */
123 s2 paramcount; /* number of parameters */
124 s2 paramslots; /* like above but LONG,DOUBLE count twice */
125 s4 argintreguse; /* number of used integer argument registers */
126 s4 argfltreguse; /* number of used float argument registers */
127 #if defined(HAS_ADDRESS_REGISTER_FILE)
128 s4 argadrreguse; /* number of used address registers */
130 s4 memuse; /* number of stack slots used */
131 paramdesc *params; /* allocated parameter descriptions [3] */
132 typedesc returntype; /* parsed descriptor of the return type */
133 typedesc paramtypes[1]; /* parameter types, variable length! */
136 /* [3]...If params is NULL, the parameter descriptions have not yet been */
137 /* allocated. In this case ___the possible 'this' pointer of the method */
138 /* is NOT counted in paramcount/paramslots and it is NOT included in */
139 /* the paramtypes array___. */
140 /* If params != NULL, the parameter descriptions have been */
141 /* allocated, and the 'this' pointer of the method, if any, IS included.*/
142 /* In case the method has no parameters at all, the special value */
143 /* METHODDESC_NO_PARAMS is used (see below). */
145 /* METHODDESC_NO_PARAMS is a special value for the methoddesc.params field */
146 /* indicating that the method is a static method without any parameters. */
147 /* This special value must be != NULL and it may only be set if */
148 /* md->paramcount == 0. */
150 #define METHODDESC_NOPARAMS ((paramdesc*)1)
152 /* function prototypes ********************************************************/
154 descriptor_pool * descriptor_pool_new(classinfo *referer);
156 bool descriptor_pool_add_class(descriptor_pool *pool,utf *name);
157 bool descriptor_pool_add(descriptor_pool *pool,utf *desc,int *paramslots);
159 u2 descriptor_to_basic_type(utf *desc);
160 u2 descriptor_typesize(typedesc *td);
162 constant_classref * descriptor_pool_create_classrefs(descriptor_pool *pool,
164 constant_classref * descriptor_pool_lookup_classref(descriptor_pool *pool,utf *classname);
166 void descriptor_pool_alloc_parsed_descriptors(descriptor_pool *pool);
168 typedesc *descriptor_pool_parse_field_descriptor(descriptor_pool *pool, utf *desc);
169 methoddesc *descriptor_pool_parse_method_descriptor(descriptor_pool *pool, utf *desc, s4 mflags,
170 constant_classref *thisclass);
172 bool descriptor_params_from_paramtypes(methoddesc *md, s4 mflags);
174 void *descriptor_pool_get_parsed_descriptors(descriptor_pool *pool, s4 *size);
175 void descriptor_pool_get_sizes(descriptor_pool *pool, u4 *classrefsize,
179 void descriptor_debug_print_typedesc(FILE *file,typedesc *d);
180 void descriptor_debug_print_methoddesc(FILE *file,methoddesc *d);
181 void descriptor_debug_print_paramdesc(FILE *file,paramdesc *d);
182 void descriptor_pool_debug_dump(descriptor_pool *pool, FILE *file);
183 #endif /* !defined(NDEBUG) */
185 #endif /* _DESCRIPTOR_H */
189 * These are local overrides for various environment variables in Emacs.
190 * Please do not remove this and leave it at the end of the file, where
191 * Emacs will automagically detect them.
192 * ---------------------------------------------------------------------
195 * indent-tabs-mode: t
199 * vim:noexpandtab:sw=4:ts=4: