loader.tex
[cacao.git] / loader.h
1 /* loader.h - class loader header
2
3    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4    R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
5    M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
6    P. Tomsich, J. Wenninger
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 1296 2004-07-10 17:02:15Z stefan $
30 */
31
32
33 #ifndef _LOADER_H
34 #define _LOADER_H
35
36 #include <stdio.h>
37
38 #ifdef USE_ZLIB
39 #include "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 classinfo *class_load(classinfo *c);
175 classinfo *class_load_intern(classbuffer *cb);
176 classinfo *class_link(classinfo *c);
177 void class_free(classinfo *c);
178
179 void field_display(fieldinfo *f);
180
181 void method_display(methodinfo *m);
182
183 utf* clinit_desc();
184 utf* clinit_name();
185
186
187 /******************************** CLASSPATH handling *******************/
188 #define CLASSPATH_MAXFILENAME 1000                /* maximum length of a filename           */
189 #define CLASSPATH_PATH 0
190 #define CLASSPATH_ARCHIVE 1
191
192 typedef union classpath_info {
193         struct {
194                 int type;
195                 union classpath_info *next;
196                 char *filename;
197                 int pathlen; } filepath;
198 #ifdef USE_ZLIB
199         struct {
200                 int type;
201                 union classpath_info *next;
202                 unzFile uf;
203         } archive;
204 #endif  
205 } classpath_info;
206
207 #endif /* _LOADER_H */
208
209
210 /*
211  * These are local overrides for various environment variables in Emacs.
212  * Please do not remove this and leave it at the end of the file, where
213  * Emacs will automagically detect them.
214  * ---------------------------------------------------------------------
215  * Local variables:
216  * mode: c
217  * indent-tabs-mode: t
218  * c-basic-offset: 4
219  * tab-width: 4
220  * End:
221  */