Removed fields from classinfo and related functions from descriptor pool.
[cacao.git] / src / vm / descriptor.hpp
1 /* src/vm/descriptor.h - checking and parsing of field / method descriptors
2
3    Copyright (C) 1996-2011
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #ifndef _DESCRIPTOR_H
27 #define _DESCRIPTOR_H
28
29 /* forward typedefs ***********************************************************/
30
31 typedef struct descriptor_pool descriptor_pool;
32 typedef struct typedesc        typedesc;
33 typedef struct paramdesc       paramdesc;
34 typedef struct methoddesc      methoddesc;
35
36
37 #include "config.h"
38
39 #include <stdint.h>
40
41 #include "vm/types.h"
42
43 #include "toolbox/hashtable.h"
44
45 #include "vm/class.hpp"
46 #include "vm/global.h"
47 #include "vm/method.hpp"
48 #include "vm/references.h"
49 #include "vm/utf8.h"
50
51 #include "arch.h"               /* needed for HAS_ADDRESS_REGISTER_FILE */
52
53
54 /* data structures ************************************************************/
55
56 /*----------------------------------------------------------------------------*/
57 /* Descriptor Pools                                                           */
58 /*                                                                            */
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.                        */
64 /*                                                                            */
65 /* You use a descriptor_pool as follows:                                      */
66 /*                                                                            */
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 /*                                                                            */
76 /* IMPORTANT: The descriptor_pool functions use DNEW and DMNEW for allocating */
77 /*            memory which can be thrown away when the steps above have been  */
78 /*            done.                                                           */
79 /*----------------------------------------------------------------------------*/
80
81 struct descriptor_pool {
82         classinfo         *referer;
83         u4                 fieldcount;
84         u4                 methodcount;
85         u4                 paramcount;
86         u4                 descriptorsize;
87         u1                *descriptors;
88         u1                *descriptors_next;
89         hashtable          descriptorhash;
90         constant_classref *classrefs;
91         hashtable          classrefhash;
92         u1                *descriptor_kind;       /* useful for debugging */
93         u1                *descriptor_kind_next;  /* useful for debugging */
94 };
95
96
97 /* data structures for parsed field/method descriptors ************************/
98
99 struct typedesc {
100         constant_classref *classref;      /* class reference for TYPE_ADR types   */
101         u1                 type;          /* TYPE_??? constant [1]                */
102         u1                 primitivetype; /* (PRIMITIVE)TYPE_??? constant [2]     */
103         u1                 arraydim;      /* array dimension (0 if no array)      */
104 };
105
106 /* [1]...the type field contains the basic type used within the VM. So ints,  */
107 /*       shorts, chars, bytes, booleans all have TYPE_INT.                    */
108 /* [2]...the primitivetype field contains the declared type.                  */
109 /*       So short is PRIMITIVETYPE_SHORT, char is PRIMITIVETYPE_CHAR.         */
110 /*       For non-primitive types primitivetype is TYPE_ADR.                   */
111
112 struct paramdesc {
113 #if defined(__MIPS__)
114         u1   type;                  /* TYPE_??? of the register allocated         */
115 #endif
116         bool     inmemory;          /* argument in register or on stack           */
117         uint32_t index;             /* index into argument register array         */
118         uint32_t regoff;            /* register index or stack offset             */
119 };
120
121 struct methoddesc {
122         s2         paramcount;      /* number of parameters                       */
123         s2         paramslots;      /* like above but LONG,DOUBLE count twice     */
124         s4         argintreguse;    /* number of used integer argument registers  */
125         s4         argfltreguse;    /* number of used float argument registers    */
126 #if defined(HAS_ADDRESS_REGISTER_FILE)
127         s4         argadrreguse;    /* number of used address registers */
128 #endif
129         s4         memuse;          /* number of stack slots used                 */
130         paramdesc *params;          /* allocated parameter descriptions [3]       */
131         typedesc   returntype;      /* parsed descriptor of the return type       */
132         typedesc   paramtypes[1];   /* parameter types, variable length!          */
133 };
134
135 /* [3]...If params is NULL, the parameter descriptions have not yet been      */
136 /*       allocated. In this case ___the possible 'this' pointer of the method */
137 /*       is NOT counted in paramcount/paramslots and it is NOT included in    */
138 /*       the paramtypes array___.                                             */
139 /*       If params != NULL, the parameter descriptions have been              */
140 /*       allocated, and the 'this' pointer of the method, if any, IS included.*/
141 /*       In case the method has no parameters at all, the special value       */
142 /*       METHODDESC_NO_PARAMS is used (see below).                            */
143
144 /* METHODDESC_NO_PARAMS is a special value for the methoddesc.params field    */
145 /* indicating that the method is a static method without any parameters.      */
146 /* This special value must be != NULL and it may only be set if               */
147 /* md->paramcount == 0.                                                       */
148
149 #define METHODDESC_NOPARAMS  ((paramdesc*)1)
150
151 /* function prototypes ********************************************************/
152
153 #ifdef __cplusplus
154 extern "C" {
155 #endif
156
157 descriptor_pool * descriptor_pool_new(classinfo *referer);
158
159 bool descriptor_pool_add_class(descriptor_pool *pool,utf *name);
160 bool descriptor_pool_add(descriptor_pool *pool,utf *desc,int *paramslots);
161
162 int  descriptor_to_basic_type(utf *desc);
163 int  descriptor_typesize(typedesc *td);
164
165 constant_classref * descriptor_pool_create_classrefs(descriptor_pool *pool,
166                                                                                                          s4 *count);
167 constant_classref * descriptor_pool_lookup_classref(descriptor_pool *pool,utf *classname);
168
169 void descriptor_pool_alloc_parsed_descriptors(descriptor_pool *pool);
170
171 typedesc *descriptor_pool_parse_field_descriptor(descriptor_pool *pool, utf *desc);
172 methoddesc *descriptor_pool_parse_method_descriptor(descriptor_pool *pool, utf *desc, s4 mflags,
173                                                                                                         constant_classref *thisclass);
174
175 bool descriptor_params_from_paramtypes(methoddesc *md, s4 mflags);
176
177 void descriptor_pool_get_sizes(descriptor_pool *pool, u4 *classrefsize,
178                                                            u4 *descsize);
179
180 #ifndef NDEBUG
181 void descriptor_debug_print_typedesc(FILE *file,typedesc *d);
182 void descriptor_debug_print_methoddesc(FILE *file,methoddesc *d);
183 void descriptor_debug_print_paramdesc(FILE *file,paramdesc *d);
184 void descriptor_pool_debug_dump(descriptor_pool *pool, FILE *file);
185 #endif /* !defined(NDEBUG) */
186
187 #ifdef __cplusplus
188 }
189 #endif
190
191 #endif /* _DESCRIPTOR_H */
192
193
194 /*
195  * These are local overrides for various environment variables in Emacs.
196  * Please do not remove this and leave it at the end of the file, where
197  * Emacs will automagically detect them.
198  * ---------------------------------------------------------------------
199  * Local variables:
200  * mode: c
201  * indent-tabs-mode: t
202  * c-basic-offset: 4
203  * tab-width: 4
204  * End:
205  * vim:noexpandtab:sw=4:ts=4:
206  */