d127a398983d958e642112037959839477bfa948
[cacao.git] / src / vm / resolve.h
1 /* vm/resolve.h - resolving classes/interfaces/fields/methods
2
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
7
8    This file is part of CACAO.
9
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.
14
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.
19
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
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Edwin Steiner
28
29    Changes:
30
31    $Id: resolve.h 2182 2005-04-01 20:56:33Z edwin $
32
33 */
34
35
36 #ifndef _RESOLVE_H
37 #define _RESOLVE_H
38
39 /* forward declarations *******************************************************/
40
41 typedef struct unresolved_field unresolved_field;
42 typedef struct unresolved_method unresolved_method;
43 typedef struct unresolved_subtype_set unresolved_subtype_set;
44
45
46 #include "vm/global.h"
47 #include "vm/references.h"
48 #include "vm/jit/jit.h"
49
50
51 /* constants ******************************************************************/
52
53 #define RESOLVE_STATIC    0x0001
54 #define RESOLVE_PUTFIELD  0x0002
55
56
57 /* enums **********************************************************************/
58
59 typedef enum {
60         resolveLazy,
61         resolveEager
62 } resolve_mode_t;
63
64
65 typedef enum {
66         resolveLinkageError,
67         resolveIllegalAccessError
68 } resolve_err_t;
69
70
71 /* structs ********************************************************************/
72
73 struct unresolved_subtype_set {
74         classref_or_classinfo *subtyperefs;     /* NULL terminated list */
75 };
76
77
78 /* XXX unify heads of unresolved_field and unresolved_method? */
79
80 struct unresolved_field {
81         constant_FMIref *fieldref;
82         methodinfo      *referermethod;
83         s4               flags;
84         
85         unresolved_subtype_set  instancetypes;
86         unresolved_subtype_set  valueconstraints;
87 };
88
89 struct unresolved_method {
90         constant_FMIref *methodref;
91         methodinfo      *referermethod;
92         s4               flags;
93         
94         unresolved_subtype_set  instancetypes;
95         unresolved_subtype_set *paramconstraints;
96 };
97
98 #define SUBTYPESET_IS_EMPTY(stset) \
99         ((stset).subtyperefs == NULL)
100
101 #define UNRESOLVED_SUBTYPE_SET_EMTPY(stset) \
102         do { (stset).subtyperefs = NULL; } while(0)
103
104 /* function prototypes ********************************************************/
105
106 /* resolve_class ***************************************************************
107  
108    Resolve a symbolic class reference
109   
110    IN:
111        referer..........the class containing the reference
112        refmethod........the method from which resolution was triggered
113                         (may be NULL if not applicable)
114        classname........class name to resolve
115        mode.............mode of resolution:
116                             resolveLazy...only resolve if it does not
117                                           require loading classes
118                             resolveEager..load classes if necessary
119   
120    OUT:
121        *result..........set to result of resolution, or to NULL if
122                         the reference has not been resolved
123                         In the case of an exception, *result is
124                         guaranteed to be set to NULL.
125   
126    RETURN VALUE:
127        true.............everything ok 
128                         (*result may still be NULL for resolveLazy)
129        false............an exception has been thrown
130
131    NOTE:
132        The returned class is *not* guaranteed to be linked!
133            (It is guaranteed to be loaded, though.)
134    
135 *******************************************************************************/
136
137 bool
138 resolve_class(classinfo *referer,methodinfo *refmethod,
139                           utf *classname,
140                           resolve_mode_t mode,
141                           classinfo **result);
142
143 /* resolve_classref_or_classinfo ***********************************************
144  
145    Resolve a symbolic class reference if necessary
146   
147    IN:
148        refmethod........the method from which resolution was triggered
149                         (may be NULL if not applicable)
150        cls..............class reference or classinfo
151        mode.............mode of resolution:
152                             resolveLazy...only resolve if it does not
153                                           require loading classes
154                             resolveEager..load classes if necessary
155            link.............if true, guarantee that the returned class, if any,
156                             has been linked
157   
158    OUT:
159        *result..........set to result of resolution, or to NULL if
160                         the reference has not been resolved
161                         In the case of an exception, *result is
162                         guaranteed to be set to NULL.
163   
164    RETURN VALUE:
165        true.............everything ok 
166                         (*result may still be NULL for resolveLazy)
167        false............an exception has been thrown
168    
169 *******************************************************************************/
170
171 bool
172 resolve_classref_or_classinfo(methodinfo *refmethod,
173                                                           classref_or_classinfo cls,
174                                                           resolve_mode_t mode,
175                                                           bool link,
176                                                           classinfo **result);
177
178 /* resolve_class_from_typedesc *************************************************
179  
180    Return a classinfo * for the given type descriptor
181   
182    IN:
183        d................type descriptor
184            link.............if true, guarantee that the returned class, if any,
185                             has been linked
186    OUT:
187        *result..........set to result of resolution, or to NULL if
188                         the reference has not been resolved
189                         In the case of an exception, *result is
190                         guaranteed to be set to NULL.
191   
192    RETURN VALUE:
193        true.............everything ok 
194        false............an exception has been thrown
195
196    NOTE:
197        This function always resolved eagerly.
198    
199 *******************************************************************************/
200
201 bool resolve_class_from_typedesc(typedesc *d,bool link,classinfo **result);
202
203 /* resolve_field ***************************************************************
204  
205    Resolve an unresolved field reference
206   
207    IN:
208        ref..............struct containing the reference
209        mode.............mode of resolution:
210                             resolveLazy...only resolve if it does not
211                                           require loading classes
212                             resolveEager..load classes if necessary
213   
214    OUT:
215        *result..........set to the result of resolution, or to NULL if
216                         the reference has not been resolved
217                         In the case of an exception, *result is
218                         guaranteed to be set to NULL.
219   
220    RETURN VALUE:
221        true.............everything ok 
222                         (*result may still be NULL for resolveLazy) XXX implement
223        false............an exception has been thrown
224    
225 *******************************************************************************/
226
227 bool
228 resolve_field(unresolved_field *ref,
229                           resolve_mode_t mode,
230                           fieldinfo **result);
231
232 /* resolve_method **************************************************************
233  
234    Resolve an unresolved method reference
235   
236    IN:
237        ref..............struct containing the reference
238        mode.............mode of resolution:
239                             resolveLazy...only resolve if it does not
240                                           require loading classes
241                             resolveEager..load classes if necessary
242   
243    OUT:
244        *result..........set to the result of resolution, or to NULL if
245                         the reference has not been resolved
246                         In the case of an exception, *result is
247                         guaranteed to be set to NULL.
248   
249    RETURN VALUE:
250        true.............everything ok 
251                         (*result may still be NULL for resolveLazy) XXX implement
252        false............an exception has been thrown
253    
254 *******************************************************************************/
255
256 bool
257 resolve_method(unresolved_method *ref,
258                           resolve_mode_t mode,
259                            methodinfo **result);
260
261 /* resolve_and_check_subtype_set ***********************************************
262  
263    Resolve the references in the given set and test subtype relationships
264   
265    IN:
266        referer..........the class containing the references
267        refmethod........the method triggering the resolution
268        ref..............a set of class/interface references
269                         (may be empty)
270        type.............the type to test against the set
271        reversed.........if true, test if type is a subtype of
272                         the set members, instead of the other
273                         way round
274        mode.............mode of resolution:
275                             resolveLazy...only resolve if it does not
276                                           require loading classes
277                             resolveEager..load classes if necessary
278        error............which type of exception to throw if
279                         the test fails. May be:
280                             resolveLinkageError, or
281                             resolveIllegalAccessError
282
283    OUT:
284        *checked.........set to true if all checks were performed,
285                             otherwise set to false
286                             (This is guaranteed to be true if mode was
287                                                 resolveEager and no exception occured.)
288                                                 If checked == NULL, this parameter is not used.
289   
290    RETURN VALUE:
291        true.............the check succeeded
292        false............the check failed. An exception has been
293                         thrown.
294    
295    NOTE:
296        The references in the set are resolved first, so any
297        exception which may occurr during resolution may
298        be thrown by this function.
299    
300 *******************************************************************************/
301
302 bool
303 resolve_and_check_subtype_set(classinfo *referer,methodinfo *refmethod,
304                                                           unresolved_subtype_set *ref,
305                                                           classref_or_classinfo type,
306                                                           bool reversed,
307                                                           resolve_mode_t mode,
308                                                           resolve_err_t error,
309                                                           bool *checked);
310
311 /* create_unresolved_field *****************************************************
312  
313    Create an unresolved_field struct for the given field access instruction
314   
315    IN:
316        referer..........the class containing the reference
317            refmethod........the method triggering the resolution (if any)
318            iptr.............the {GET,PUT}{FIELD,STATIC}{,CONST} instruction
319            stack............the input stack of the instruction
320
321    RETURN VALUE:
322        a pointer to a new unresolved_field struct
323
324 *******************************************************************************/
325
326 unresolved_field *
327 create_unresolved_field(classinfo *referer,methodinfo *refmethod,
328                                                 instruction *iptr,
329                                                 stackelement *stack);
330
331 /* create_unresolved_method ****************************************************
332  
333    Create an unresolved_method struct for the given method invocation
334   
335    IN:
336        referer..........the class containing the reference
337            refmethod........the method triggering the resolution (if any)
338            iptr.............the INVOKE* instruction
339            stack............the input stack of the instruction
340
341    RETURN VALUE:
342        a pointer to a new unresolved_method struct
343
344 *******************************************************************************/
345
346 unresolved_method *
347 create_unresolved_method(classinfo *referer,methodinfo *refmethod,
348                                                  instruction *iptr,
349                                                  stackelement *stack);
350
351 /* unresolved_field_free *******************************************************
352  
353    Free the memory used by an unresolved_field
354   
355    IN:
356        ref..............the unresolved_field
357
358 *******************************************************************************/
359
360 void unresolved_field_free(unresolved_field *ref);
361
362 /* unresolved_method_free ******************************************************
363  
364    Free the memory used by an unresolved_method
365   
366    IN:
367        ref..............the unresolved_method
368
369 *******************************************************************************/
370
371 void unresolved_method_free(unresolved_method *ref);
372
373 /* unresolved_field_debug_dump *************************************************
374  
375    Print debug info for unresolved_field to stream
376   
377    IN:
378        ref..............the unresolved_field
379            file.............the stream
380
381 *******************************************************************************/
382
383 void unresolved_field_debug_dump(unresolved_field *ref,FILE *file);
384
385 /* unresolved_method_debug_dump ************************************************
386  
387    Print debug info for unresolved_method to stream
388   
389    IN:
390        ref..............the unresolved_method
391            file.............the stream
392
393 *******************************************************************************/
394
395 void unresolved_method_debug_dump(unresolved_method *ref,FILE *file);
396
397 /* unresolved_subtype_set_debug_dump *******************************************
398  
399    Print debug info for unresolved_subtype_set to stream
400   
401    IN:
402        stset............the unresolved_subtype_set
403            file.............the stream
404
405 *******************************************************************************/
406
407 void unresolved_subtype_set_debug_dump(unresolved_subtype_set *stset,FILE *file);
408         
409 #endif /* _RESOLVE_H */
410
411 /*
412  * These are local overrides for various environment variables in Emacs.
413  * Please do not remove this and leave it at the end of the file, where
414  * Emacs will automagically detect them.
415  * ---------------------------------------------------------------------
416  * Local variables:
417  * mode: c
418  * indent-tabs-mode: t
419  * c-basic-offset: 4
420  * tab-width: 4
421  * End:
422  * vim:noexpandtab:sw=4:ts=4:
423  */
424