1 /* vm/descriptor.h - checking and parsing of field / method descriptors
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
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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Edwin Steiner
31 $Id: descriptor.h 2112 2005-03-29 21:29:08Z twisti $
39 /* forward typedefs ***********************************************************/
41 typedef struct descriptor_pool descriptor_pool;
42 typedef struct typedesc typedesc;
43 typedef struct methoddesc methoddesc;
44 typedef union parseddesc parseddesc;
49 #include "vm/global.h"
50 #include "vm/tables.h"
54 /* data structures ************************************************************/
56 /*----------------------------------------------------------------------------*/
57 /* Descriptor Pools */
59 /* A descriptor_pool is a temporary data structure used during loading of */
60 /* a class. The descriptor_pool is used to allocate the table of */
61 /* constant_classrefs the class uses, and for parsing the field and method */
62 /* descriptors which occurr within the class. The inner workings of */
63 /* descriptor_pool are not important for outside code. */
65 /* You use a descriptor_pool as follows: */
67 /* 1. create one with descriptor_pool_new */
68 /* 2. add all explicit class references with descriptor_pool_add_class */
69 /* 3. add all field/method descriptors with descriptor_pool_add */
70 /* 4. call descriptor_pool_create_classrefs */
71 /* You can now lookup classrefs with descriptor_pool_lookup_classref */
72 /* 5. call descriptor_pool_alloc_parsed_descriptors */
73 /* 6. for each field descriptor call descriptor_pool_parse_field_descriptor */
74 /* for each method descriptor call descriptor_pool_parse_method_descriptor */
75 /* 7. call descriptor_pool_get_parsed_descriptors */
77 /* IMPORTANT: The descriptor_pool functions use DNEW and DMNEW for allocating */
78 /* memory which can be thrown away when the steps above have been */
80 /*----------------------------------------------------------------------------*/
82 struct descriptor_pool {
90 hashtable descriptorhash;
91 constant_classref *classrefs;
92 hashtable classrefhash;
93 u1 *descriptor_kind; /* useful for debugging */
94 u1 *descriptor_kind_next; /* useful for debugging */
98 /* data structures for parsed field/method descriptors ************************/
101 constant_classref *classref; /* class reference for TYPE_ADR types */
102 u1 type; /* TYPE_??? constant */
103 u1 arraydim; /* array dimension (0 if no array) */
107 s2 paramcount; /* number of parameters */
108 s2 paramslots; /* like above but LONG,DOUBLE count twice */
109 typedesc returntype; /* parsed descriptor of the return type */
110 typedesc paramtypes[1]; /* parameter types, variable length! */
114 typedesc *fd; /* parsed field descriptor */
115 methoddesc *md; /* parsed method descriptor */
116 void *any; /* used for simple test against NULL */
120 /* function prototypes ********************************************************/
122 /* descriptor_debug_print_typedesc *********************************************
124 Print the given typedesc to the given stream
127 file.............stream to print to
128 d................the parsed descriptor
130 *******************************************************************************/
132 void descriptor_debug_print_typedesc(FILE *file,typedesc *d);
134 /* descriptor_debug_print_methoddesc *******************************************
136 Print the given methoddesc to the given stream
139 file.............stream to print to
140 d................the parsed descriptor
142 *******************************************************************************/
144 void descriptor_debug_print_methoddesc(FILE *file,methoddesc *d);
146 /* descriptor_pool_new *********************************************************
148 Allocate a new descriptor_pool
151 referer..........class for which to create the pool
154 a pointer to the new descriptor_pool
156 *******************************************************************************/
158 descriptor_pool * descriptor_pool_new(classinfo *referer);
160 /* descriptor_pool_add_class ***************************************************
162 Add the given class reference to the pool
165 pool.............the descriptor_pool
166 name.............the class reference to add
169 true.............reference has been added
170 false............an exception has been thrown
172 *******************************************************************************/
174 bool descriptor_pool_add_class(descriptor_pool *pool,utf *name);
176 /* descriptor_pool_add *********************************************************
178 Check the given descriptor and add it to the pool
181 pool.............the descriptor_pool
182 desc.............the descriptor to add. Maybe a field or method desc.
185 true.............descriptor has been added
186 false............an exception has been thrown
188 *******************************************************************************/
190 bool descriptor_pool_add(descriptor_pool *pool,utf *desc);
192 /* descriptor_pool_create_classrefs ********************************************
194 Create a table containing all the classrefs which were added to the pool
197 pool.............the descriptor_pool
200 *count...........if count is non-NULL, this is set to the number
201 of classrefs in the table
204 a pointer to the constant_classref table
206 *******************************************************************************/
208 constant_classref * descriptor_pool_create_classrefs(descriptor_pool *pool,
211 /* descriptor_pool_lookup_classref *********************************************
213 Return the constant_classref for the given class name
216 pool.............the descriptor_pool
217 classname........name of the class to look up
220 a pointer to the constant_classref, or
221 NULL if an exception has been thrown
223 *******************************************************************************/
225 constant_classref * descriptor_pool_lookup_classref(descriptor_pool *pool,utf *classname);
227 /* descriptor_pool_alloc_parsed_descriptors ************************************
229 Allocate space for the parsed descriptors
232 pool.............the descriptor_pool
235 This function must be called after all descriptors have been added
236 with descriptor_pool_add.
238 *******************************************************************************/
240 void descriptor_pool_alloc_parsed_descriptors(descriptor_pool *pool);
242 /* descriptor_pool_parse_field_descriptor **************************************
244 Parse the given field descriptor
247 pool.............the descriptor_pool
248 desc.............the field descriptor
251 a pointer to the parsed field descriptor, or
252 NULL if an exception has been thrown
255 descriptor_pool_alloc_parsed_descriptors must be called (once) before this
258 *******************************************************************************/
260 typedesc * descriptor_pool_parse_field_descriptor(descriptor_pool *pool,utf *desc);
262 /* descriptor_pool_parse_method_descriptor *************************************
264 Parse the given method descriptor
267 pool.............the descriptor_pool
268 desc.............the method descriptor
271 a pointer to the parsed method descriptor, or
272 NULL if an exception has been thrown
275 descriptor_pool_alloc_parsed_descriptors must be called (once) before this
278 *******************************************************************************/
280 methoddesc * descriptor_pool_parse_method_descriptor(descriptor_pool *pool,utf *desc);
282 /* descriptor_pool_get_parsed_descriptors **************************************
284 Return a pointer to the block of parsed descriptors
287 pool.............the descriptor_pool
290 *size............if size is non-NULL, this is set to the size of the
291 parsed descriptor block (in u1)
294 a pointer to the block of parsed descriptors,
295 NULL if there are no descriptors in the pool
298 descriptor_pool_alloc_parsed_descriptors must be called (once) before this
301 *******************************************************************************/
303 void * descriptor_pool_get_parsed_descriptors(descriptor_pool *pool,
306 /* descriptor_pool_get_sizes ***************************************************
308 Get the sizes of the class reference table and the parsed descriptors
311 pool.............the descriptor_pool
314 *classrefsize....set to size of the class reference table
315 *descsize........set to size of the parsed descriptors
318 This function may only be called after both
319 descriptor_pool_create_classrefs, and
320 descriptor_pool_alloc_parsed_descriptors
323 *******************************************************************************/
325 void descriptor_pool_get_sizes(descriptor_pool *pool,
326 u4 *classrefsize,u4 *descsize);
328 /* descriptor_debug_print_typedesc *********************************************
330 Print the given typedesc to the given stream
333 file.............stream to print to
334 d................the parsed descriptor
336 *******************************************************************************/
338 void descriptor_debug_print_typedesc(FILE *file,typedesc *d);
340 /* descriptor_debug_print_methoddesc *******************************************
342 Print the given methoddesc to the given stream
345 file.............stream to print to
346 d................the parsed descriptor
348 *******************************************************************************/
350 void descriptor_debug_print_methoddesc(FILE *file,methoddesc *d);
352 /* descriptor_pool_debug_dump **************************************************
354 Print the state of the descriptor_pool to the given stream
357 pool.............the descriptor_pool
358 file.............stream to print to
360 *******************************************************************************/
362 void descriptor_pool_debug_dump(descriptor_pool *pool,FILE *file);
364 #endif /* _DESCRIPTOR_H */
368 * These are local overrides for various environment variables in Emacs.
369 * Please do not remove this and leave it at the end of the file, where
370 * Emacs will automagically detect them.
371 * ---------------------------------------------------------------------
374 * indent-tabs-mode: t
378 * vim:noexpandtab:sw=4:ts=4: