GNU header update.
[cacao.git] / src / vm / loader.h
1 /* vm/loader.h - class loader header
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: Reinhard Grafl
28
29    $Id: loader.h 1735 2004-12-07 14:33:27Z twisti $
30 */
31
32
33 #ifndef _LOADER_H
34 #define _LOADER_H
35
36 #include <stdio.h>
37
38 #if defined(USE_ZLIB)
39 # include "vm/unzip.h"
40 #endif
41
42
43 /* datastruture from a classfile */
44
45 typedef struct classbuffer {
46         classinfo *class;                   /* pointer to classinfo structure     */
47         u1 *data;                           /* pointer to byte code               */
48         s4 size;                            /* size of the byte code              */
49         u1 *pos;                            /* current read position              */
50 } classbuffer;
51
52
53 /* export variables */
54
55 #ifdef USE_THREADS
56 extern int blockInts;
57 #endif
58
59
60 /* references to some system classes ******************************************/
61
62 extern classinfo *class_java_lang_Object;
63 extern classinfo *class_java_lang_String;
64 extern classinfo *class_java_lang_Cloneable;
65 extern classinfo *class_java_io_Serializable;
66 extern utf *utf_fillInStackTrace_name;
67 extern utf *utf_fillInStackTrace_desc;
68
69 /* pseudo classes for the type checker ****************************************/
70
71 /*
72  * pseudo_class_Arraystub
73  *     (extends Object implements Cloneable, java.io.Serializable)
74  *
75  *     If two arrays of incompatible component types are merged,
76  *     the resulting reference has no accessible components.
77  *     The result does, however, implement the interfaces Cloneable
78  *     and java.io.Serializable. This pseudo class is used internally
79  *     to represent such results. (They are *not* considered arrays!)
80  *
81  * pseudo_class_Null
82  *
83  *     This pseudo class is used internally to represent the
84  *     null type.
85  *
86  * pseudo_class_New
87  *
88  *     This pseudo class is used internally to represent the
89  *     the 'uninitialized object' type.
90  */
91
92 extern classinfo *pseudo_class_Arraystub;
93 extern classinfo *pseudo_class_Null;
94 extern classinfo *pseudo_class_New;
95 extern vftbl_t *pseudo_class_Arraystub_vftbl;
96
97 extern utf *array_packagename;
98
99
100 /************************ prototypes ******************************************/
101
102 /* initialize laoder, load important systemclasses */
103 void loader_init();
104
105 void suck_init(char *cpath);
106 void create_all_classes();
107 void suck_stop(classbuffer *cb);
108
109 /* free resources */
110 void loader_close();
111
112 void loader_compute_subclasses();
113
114 /* retrieve constantpool element */
115 voidptr class_getconstant(classinfo *class, u4 pos, u4 ctype);
116
117 /* determine type of a constantpool element */
118 u4 class_constanttype(classinfo *class, u4 pos);
119
120 s4 class_findmethodIndex(classinfo *c, utf *name, utf *desc);
121
122 /* search class for a field */
123 fieldinfo *class_findfield(classinfo *c, utf *name, utf *desc);
124 fieldinfo *class_resolvefield(classinfo *c, utf *name, utf *desc, classinfo *referer, bool except);
125
126 /* search for a method with a specified name and descriptor */
127 methodinfo *class_findmethod(classinfo *c, utf *name, utf *desc);
128 methodinfo *class_fetchmethod(classinfo *c, utf *name, utf *desc);
129 methodinfo *class_findmethod_w(classinfo *c, utf *name, utf *desc, char*);
130 methodinfo *class_resolvemethod(classinfo *c, utf *name, utf *dest);
131 methodinfo *class_resolveclassmethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool except);
132 methodinfo *class_resolveinterfacemethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool except);
133
134 /* search for a method with specified name and arguments (returntype ignored) */
135 methodinfo *class_findmethod_approx(classinfo *c, utf *name, utf *desc);
136 methodinfo *class_resolvemethod_approx(classinfo *c, utf *name, utf *dest);
137
138 bool class_issubclass(classinfo *sub, classinfo *super);
139
140 /* call initializer of class */
141 classinfo *class_init(classinfo *c);
142
143 void class_showconstanti(classinfo *c, int ii);
144
145 /* debug purposes */
146 void class_showmethods(classinfo *c);
147 void class_showconstantpool(classinfo *c);
148 void print_arraydescriptor(FILE *file, arraydescriptor *desc);
149
150 /* return the primitive class inidicated by the given signature character */
151 classinfo *class_primitive_from_sig(char sig);
152
153
154 /* return the class indicated by the given descriptor */
155 /* (see loader.c for documentation) */
156 #define CLASSLOAD_NEW           0      /* default */
157 #define CLASSLOAD_LOAD          0x0001
158 #define CLASSLOAD_SKIP          0x0002
159 #define CLASSLOAD_PANIC         0      /* default */
160 #define CLASSLOAD_NOPANIC       0x0010
161 #define CLASSLOAD_PRIMITIVE     0      /* default */
162 #define CLASSLOAD_NULLPRIMITIVE 0x0020
163 #define CLASSLOAD_VOID          0      /* default */
164 #define CLASSLOAD_NOVOID        0x0040
165 #define CLASSLOAD_NOCHECKEND    0      /* default */
166 #define CLASSLOAD_CHECKEND      0x1000
167
168 classinfo *class_from_descriptor(char *utf_ptr,char *end_ptr,char **next,int mode);
169 int type_from_descriptor(classinfo **cls,char *utf_ptr,char *end_ptr,char **next,int mode);
170
171 /* (used by class_new, don't use directly) */
172 void class_new_array(classinfo *c);
173
174 #define LAZYLOADING(class) { \
175         if (!class->loaded) \
176             if (!class_load(class)) \
177                 return 0; \
178         if (!class->linked) \
179             if (!class_link(class)) \
180                 return 0; }
181
182
183 classinfo *class_load(classinfo *c);
184 classinfo *class_load_intern(classbuffer *cb);
185 classinfo *class_link(classinfo *c);
186 void class_free(classinfo *c);
187
188 void field_display(fieldinfo *f);
189
190 void method_display(methodinfo *m);
191 void method_display_w_class(methodinfo *m);
192
193 utf* clinit_desc();
194 utf* clinit_name();
195
196
197 /******************************** CLASSPATH handling *******************/
198 #define CLASSPATH_MAXFILENAME 1000                /* maximum length of a filename           */
199 #define CLASSPATH_PATH 0
200 #define CLASSPATH_ARCHIVE 1
201
202 typedef union classpath_info {
203         struct {
204                 s4                    type;
205                 union classpath_info *next;
206                 char                 *path;
207                 s4                    pathlen;
208         } filepath;
209 #if defined(USE_ZLIB)
210         struct {
211                 s4                    type;
212                 union classpath_info *next;
213                 unzFile               uf;
214         } archive;
215 #endif  
216 } classpath_info;
217
218 #endif /* _LOADER_H */
219
220
221 /*
222  * These are local overrides for various environment variables in Emacs.
223  * Please do not remove this and leave it at the end of the file, where
224  * Emacs will automagically detect them.
225  * ---------------------------------------------------------------------
226  * Local variables:
227  * mode: c
228  * indent-tabs-mode: t
229  * c-basic-offset: 4
230  * tab-width: 4
231  * End:
232  */