* Updated header: Added 2006. Changed address of FSF. Changed email
[cacao.git] / src / vm / resolve.h
1 /* vm/resolve.h - resolving classes/interfaces/fields/methods
2
3    Copyright (C) 1996-2005, 2006 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
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., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    Contact: cacao@cacaojvm.org
26
27    Authors: Edwin Steiner
28
29    Changes:
30
31    $Id: resolve.h 4357 2006-01-22 23:33:38Z twisti $
32
33 */
34
35
36 #ifndef _RESOLVE_H
37 #define _RESOLVE_H
38
39 /* forward declarations *******************************************************/
40
41 typedef struct unresolved_class unresolved_class;
42 typedef struct unresolved_field unresolved_field;
43 typedef struct unresolved_method unresolved_method;
44 typedef struct unresolved_subtype_set unresolved_subtype_set;
45
46
47 #include "config.h"
48 #include "vm/types.h"
49 #include "vm/global.h"
50 #include "vm/references.h"
51 #include "vm/jit/jit.h"
52
53
54 /* constants ******************************************************************/
55
56 #define RESOLVE_STATIC    0x0001  /* ref to static fields/methods             */
57 #define RESOLVE_PUTFIELD  0x0002  /* field ref inside a PUT{FIELD,STATIC}...  */
58 #define RESOLVE_SPECIAL   0x0004  /* method ref inside INVOKESPECIAL          */
59
60
61 /* enums **********************************************************************/
62
63 typedef enum {
64         resolveLazy,
65         resolveEager
66 } resolve_mode_t;
67
68
69 typedef enum {
70         resolveLinkageError,
71         resolveIllegalAccessError
72 } resolve_err_t;
73
74
75 /* structs ********************************************************************/
76
77 struct unresolved_subtype_set {
78         classref_or_classinfo *subtyperefs;     /* NULL terminated list */
79 };
80
81 struct unresolved_class {
82         constant_classref      *classref;
83         methodinfo                     *referermethod;
84         unresolved_subtype_set  subtypeconstraints;
85 };
86
87 /* XXX unify heads of unresolved_field and unresolved_method? */
88
89 struct unresolved_field {
90         constant_FMIref *fieldref;
91         methodinfo      *referermethod;
92         s4               flags;
93         
94         unresolved_subtype_set  instancetypes;
95         unresolved_subtype_set  valueconstraints;
96 };
97
98 struct unresolved_method {
99         constant_FMIref *methodref;
100         methodinfo      *referermethod;
101         s4               flags;
102         
103         unresolved_subtype_set  instancetypes;
104         unresolved_subtype_set *paramconstraints;
105 };
106
107 #define SUBTYPESET_IS_EMPTY(stset) \
108         ((stset).subtyperefs == NULL)
109
110 #define UNRESOLVED_SUBTYPE_SET_EMTPY(stset) \
111         do { (stset).subtyperefs = NULL; } while(0)
112
113 /* function prototypes ********************************************************/
114
115 bool resolve_class_from_name(classinfo* referer,methodinfo *refmethod,
116                                                 utf *classname,
117                                                 resolve_mode_t mode,
118                                                 bool checkaccess,
119                                                 bool link,
120                                                 classinfo **result);
121
122 bool resolve_classref(methodinfo *refmethod,
123                                  constant_classref *ref,
124                                  resolve_mode_t mode,
125                                  bool checkaccess,
126                              bool link,
127                                  classinfo **result);
128
129 bool resolve_classref_or_classinfo(methodinfo *refmethod,
130                                                           classref_or_classinfo cls,
131                                                           resolve_mode_t mode,
132                                                           bool checkaccess,
133                                                           bool link,
134                                                           classinfo **result);
135
136 bool resolve_class_from_typedesc(typedesc *d,bool checkaccess,bool link,classinfo **result);
137
138 #ifdef ENABLE_VERIFIER
139 bool resolve_class(unresolved_class *ref,
140                           resolve_mode_t mode,
141                           bool checkaccess,
142                           classinfo **result);
143
144 classinfo * resolve_class_eager(unresolved_class *ref);
145 #endif /* ENABLE_VERIFIER */
146
147 bool resolve_field(unresolved_field *ref,
148                           resolve_mode_t mode,
149                           fieldinfo **result);
150
151 bool resolve_method(unresolved_method *ref,
152                           resolve_mode_t mode,
153                            methodinfo **result);
154
155 classinfo * resolve_classref_eager(constant_classref *ref);
156 classinfo * resolve_classref_eager_nonabstract(constant_classref *ref);
157 fieldinfo * resolve_field_eager(unresolved_field *ref);
158 methodinfo * resolve_method_eager(unresolved_method *ref);
159
160 #ifdef ENABLE_VERIFIER
161 unresolved_class * create_unresolved_class(methodinfo *refmethod,
162                                                 constant_classref *classref,
163                                                 typeinfo *valuetype);
164 #endif
165
166 unresolved_field * create_unresolved_field(classinfo *referer,methodinfo *refmethod,
167                                                 instruction *iptr);
168
169 unresolved_method * create_unresolved_method(classinfo *referer,methodinfo *refmethod,
170                                                  instruction *iptr);
171
172 void unresolved_class_free(unresolved_class *ref);
173 void unresolved_field_free(unresolved_field *ref);
174 void unresolved_method_free(unresolved_method *ref);
175
176 #ifdef ENABLE_VERIFIER
177 bool constrain_unresolved_field(unresolved_field *ref,
178                                                    classinfo *referer,methodinfo *refmethod,
179                                                    instruction *iptr,
180                                                    stackelement *stack);
181
182 bool constrain_unresolved_method(unresolved_method *ref,
183                                                         classinfo *referer,methodinfo *refmethod,
184                                                         instruction *iptr,
185                                                         stackelement *stack);
186
187 bool resolve_and_check_subtype_set(classinfo *referer,methodinfo *refmethod,
188                                                           unresolved_subtype_set *ref,
189                                                           classref_or_classinfo type,
190                                                           bool reversed,
191                                                           resolve_mode_t mode,
192                                                           resolve_err_t error,
193                                                           bool *checked);
194 #endif
195
196 #ifndef NDEBUG
197 void unresolved_class_debug_dump(unresolved_class *ref,FILE *file);
198 void unresolved_field_debug_dump(unresolved_field *ref,FILE *file);
199 void unresolved_method_debug_dump(unresolved_method *ref,FILE *file);
200 void unresolved_subtype_set_debug_dump(unresolved_subtype_set *stset,FILE *file);
201 #endif
202         
203 #endif /* _RESOLVE_H */
204
205 /*
206  * These are local overrides for various environment variables in Emacs.
207  * Please do not remove this and leave it at the end of the file, where
208  * Emacs will automagically detect them.
209  * ---------------------------------------------------------------------
210  * Local variables:
211  * mode: c
212  * indent-tabs-mode: t
213  * c-basic-offset: 4
214  * tab-width: 4
215  * End:
216  * vim:noexpandtab:sw=4:ts=4:
217  */
218