* src/vm/resolve.c (resolve_field_verifier_checks): Removed dependence
[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 5723 2006-10-09 15:42:02Z edwin $
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 #include "vm/jit/reg.h"
53 #include "vm/jit/verify/typeinfo.h"
54
55
56 /* constants ******************************************************************/
57
58 #define RESOLVE_STATIC    0x0001  /* ref to static fields/methods             */
59 #define RESOLVE_PUTFIELD  0x0002  /* field ref inside a PUT{FIELD,STATIC}...  */
60 #define RESOLVE_SPECIAL   0x0004  /* method ref inside INVOKESPECIAL          */
61
62
63 /* enums **********************************************************************/
64
65 typedef enum {
66         resolveLazy,
67         resolveEager
68 } resolve_mode_t;
69
70 typedef enum {
71         resolveLinkageError,
72         resolveIllegalAccessError
73 } resolve_err_t;
74
75 typedef enum {
76         resolveFailed = false,  /* this must be a false value */
77         resolveDeferred = true, /* this must be a true value  */
78         resolveSucceeded
79 } resolve_result_t;
80
81 /* structs ********************************************************************/
82
83 struct unresolved_subtype_set {
84         classref_or_classinfo *subtyperefs;     /* NULL terminated list */
85 };
86
87 struct unresolved_class {
88         constant_classref      *classref;
89         methodinfo                     *referermethod;
90         unresolved_subtype_set  subtypeconstraints;
91 };
92
93 /* XXX unify heads of unresolved_field and unresolved_method? */
94
95 struct unresolved_field {
96         constant_FMIref *fieldref;
97         methodinfo      *referermethod;
98         s4               flags;
99         
100         unresolved_subtype_set  instancetypes;
101         unresolved_subtype_set  valueconstraints;
102 };
103
104 struct unresolved_method {
105         constant_FMIref *methodref;
106         methodinfo      *referermethod;
107         s4               flags;
108         
109         unresolved_subtype_set  instancetypes;
110         unresolved_subtype_set *paramconstraints;
111 };
112
113 #define SUBTYPESET_IS_EMPTY(stset) \
114         ((stset).subtyperefs == NULL)
115
116 #define UNRESOLVED_SUBTYPE_SET_EMTPY(stset) \
117         do { (stset).subtyperefs = NULL; } while(0)
118
119 /* function prototypes ********************************************************/
120
121 bool resolve_class_from_name(classinfo* referer,methodinfo *refmethod,
122                                                 utf *classname,
123                                                 resolve_mode_t mode,
124                                                 bool checkaccess,
125                                                 bool link,
126                                                 classinfo **result);
127
128 bool resolve_classref(methodinfo *refmethod,
129                                  constant_classref *ref,
130                                  resolve_mode_t mode,
131                                  bool checkaccess,
132                              bool link,
133                                  classinfo **result);
134
135 bool resolve_classref_or_classinfo(methodinfo *refmethod,
136                                                           classref_or_classinfo cls,
137                                                           resolve_mode_t mode,
138                                                           bool checkaccess,
139                                                           bool link,
140                                                           classinfo **result);
141
142 bool resolve_class_from_typedesc(typedesc *d,bool checkaccess,bool link,classinfo **result);
143
144 #ifdef ENABLE_VERIFIER
145 bool resolve_class(unresolved_class *ref,
146                           resolve_mode_t mode,
147                           bool checkaccess,
148                           classinfo **result);
149
150 classinfo * resolve_class_eager(unresolved_class *ref);
151 #endif /* ENABLE_VERIFIER */
152
153 bool resolve_field(unresolved_field *ref,
154                           resolve_mode_t mode,
155                           fieldinfo **result);
156
157 bool resolve_method(unresolved_method *ref,
158                           resolve_mode_t mode,
159                            methodinfo **result);
160
161 classinfo * resolve_classref_eager(constant_classref *ref);
162 classinfo * resolve_classref_eager_nonabstract(constant_classref *ref);
163 fieldinfo * resolve_field_eager(unresolved_field *ref);
164 methodinfo * resolve_method_eager(unresolved_method *ref);
165
166 #ifdef ENABLE_VERIFIER
167 unresolved_class * create_unresolved_class(methodinfo *refmethod,
168                                                 constant_classref *classref,
169                                                 typeinfo *valuetype);
170 #endif
171
172 unresolved_field *resolve_create_unresolved_field(classinfo *referer,
173                                                                                           methodinfo *refmethod,
174                                                                                           instruction *iptr);
175
176 unresolved_method *create_unresolved_method(classinfo *referer,
177                                                                                                 methodinfo *refmethod,
178                                                                                                 instruction *iptr);
179
180 void unresolved_class_free(unresolved_class *ref);
181 void unresolved_field_free(unresolved_field *ref);
182 void unresolved_method_free(unresolved_method *ref);
183
184 resolve_result_t resolve_method_lazy(jitdata *jd,
185                                                                                  instruction *iptr,
186                                                                                  methodinfo *refmethod);
187
188 resolve_result_t resolve_field_lazy(methodinfo *refmethod,
189                                                                         constant_FMIref *fieldref);
190
191 #ifdef ENABLE_VERIFIER
192 resolve_result_t resolve_field_verifier_checks(methodinfo *refmethod,
193                                                                                            constant_FMIref *fieldref,
194                                                                                            classinfo *container,
195                                                                                            fieldinfo *fi,
196                                                                                            typeinfo *instanceti,
197                                                                                            typeinfo *valueti,
198                                                                                            bool isstatic,
199                                                                                            bool isput);
200
201 bool resolve_constrain_unresolved_field(unresolved_field *ref,
202                                                                                 classinfo *referer, 
203                                                                                 methodinfo *refmethod,
204                                                                             typeinfo *instanceti,
205                                                                             typeinfo *valueti);
206
207 bool constrain_unresolved_method(jitdata *jd,
208                                                                          unresolved_method *ref, classinfo *referer,
209                                                                          methodinfo *refmethod, instruction *iptr);
210
211 #endif
212
213 #ifndef NDEBUG
214 void unresolved_class_debug_dump(unresolved_class *ref,FILE *file);
215 void unresolved_field_debug_dump(unresolved_field *ref,FILE *file);
216 void unresolved_method_debug_dump(unresolved_method *ref,FILE *file);
217 void unresolved_subtype_set_debug_dump(unresolved_subtype_set *stset,FILE *file);
218 #endif
219         
220 #endif /* _RESOLVE_H */
221
222 /*
223  * These are local overrides for various environment variables in Emacs.
224  * Please do not remove this and leave it at the end of the file, where
225  * Emacs will automagically detect them.
226  * ---------------------------------------------------------------------
227  * Local variables:
228  * mode: c
229  * indent-tabs-mode: t
230  * c-basic-offset: 4
231  * tab-width: 4
232  * End:
233  * vim:noexpandtab:sw=4:ts=4:
234  */
235