- removed unused class_java_lang_Throwable
[cacao.git] / src / vm / 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 1088 2004-05-26 21:32:34Z twisti $
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
67
68 /* pseudo classes for the type checker ****************************************/
69
70 /*
71  * pseudo_class_Arraystub
72  *     (extends Object implements Cloneable, java.io.Serializable)
73  *
74  *     If two arrays of incompatible component types are merged,
75  *     the resulting reference has no accessible components.
76  *     The result does, however, implement the interfaces Cloneable
77  *     and java.io.Serializable. This pseudo class is used internally
78  *     to represent such results. (They are *not* considered arrays!)
79  *
80  * pseudo_class_Null
81  *
82  *     This pseudo class is used internally to represent the
83  *     null type.
84  *
85  * pseudo_class_New
86  *
87  *     This pseudo class is used internally to represent the
88  *     the 'uninitialized object' type.
89  */
90
91 extern classinfo *pseudo_class_Arraystub;
92 extern classinfo *pseudo_class_Null;
93 extern classinfo *pseudo_class_New;
94 extern vftbl *pseudo_class_Arraystub_vftbl;
95
96 extern utf *array_packagename;
97
98
99 /************************ prototypes ******************************************/
100
101 /* initialize laoder, load important systemclasses */
102 void loader_init();
103
104 void suck_init(char *cpath);
105 void create_all_classes();
106 void suck_stop(classbuffer *cb);
107
108 /* free resources */
109 void loader_close();
110
111 void loader_compute_subclasses();
112
113 /* retrieve constantpool element */
114 voidptr class_getconstant(classinfo *class, u4 pos, u4 ctype);
115
116 /* determine type of a constantpool element */
117 u4 class_constanttype(classinfo *class, u4 pos);
118
119 s4 class_findmethodIndex(classinfo *c, utf *name, utf *desc);
120
121 /* search class for a field */
122 fieldinfo *class_findfield(classinfo *c, utf *name, utf *desc);
123 fieldinfo *class_resolvefield(classinfo *c, utf *name, utf *desc, classinfo *referer, bool except);
124
125 /* search for a method with a specified name and descriptor */
126 methodinfo *class_findmethod(classinfo *c, utf *name, utf *desc);
127 methodinfo *class_fetchmethod(classinfo *c, utf *name, utf *desc);
128 methodinfo *class_findmethod_w(classinfo *c, utf *name, utf *desc, char*);
129 methodinfo *class_resolvemethod(classinfo *c, utf *name, utf *dest);
130 methodinfo *class_resolveclassmethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool except);
131 methodinfo *class_resolveinterfacemethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool except);
132
133 /* search for a method with specified name and arguments (returntype ignored) */
134 methodinfo *class_findmethod_approx(classinfo *c, utf *name, utf *desc);
135 methodinfo *class_resolvemethod_approx(classinfo *c, utf *name, utf *dest);
136
137 bool class_issubclass(classinfo *sub, classinfo *super);
138
139 /* call initializer of class */
140 classinfo *class_init(classinfo *c);
141
142 void class_showconstanti(classinfo *c, int ii);
143
144 /* debug purposes */
145 void class_showmethods(classinfo *c);
146 void class_showconstantpool(classinfo *c);
147 void print_arraydescriptor(FILE *file, arraydescriptor *desc);
148
149 /* return the primitive class inidicated by the given signature character */
150 classinfo *class_primitive_from_sig(char sig);
151
152
153 /* return the class indicated by the given descriptor */
154 /* (see loader.c for documentation) */
155 #define CLASSLOAD_NEW           0      /* default */
156 #define CLASSLOAD_LOAD          0x0001
157 #define CLASSLOAD_SKIP          0x0002
158 #define CLASSLOAD_PANIC         0      /* default */
159 #define CLASSLOAD_NOPANIC       0x0010
160 #define CLASSLOAD_PRIMITIVE     0      /* default */
161 #define CLASSLOAD_NULLPRIMITIVE 0x0020
162 #define CLASSLOAD_VOID          0      /* default */
163 #define CLASSLOAD_NOVOID        0x0040
164 #define CLASSLOAD_NOCHECKEND    0      /* default */
165 #define CLASSLOAD_CHECKEND      0x1000
166
167 classinfo *class_from_descriptor(char *utf_ptr,char *end_ptr,char **next,int mode);
168 int type_from_descriptor(classinfo **cls,char *utf_ptr,char *end_ptr,char **next,int mode);
169
170 /* (used by class_new, don't use directly) */
171 void class_new_array(classinfo *c);
172
173 classinfo *class_load(classinfo *c);
174 classinfo *class_load_intern(classbuffer *cb);
175 classinfo *class_link(classinfo *c);
176
177 void field_display(fieldinfo *f);
178
179 void method_display(methodinfo *m);
180
181 utf* clinit_desc();
182 utf* clinit_name();
183
184
185 /******************************** CLASSPATH handling *******************/
186 #define CLASSPATH_MAXFILENAME 1000                /* maximum length of a filename           */
187 #define CLASSPATH_PATH 0
188 #define CLASSPATH_ARCHIVE 1
189
190 typedef union classpath_info {
191         struct {
192                 int type;
193                 union classpath_info *next;
194                 char *filename;
195                 int pathlen; } filepath;
196 #ifdef USE_ZLIB
197         struct {
198                 int type;
199                 union classpath_info *next;
200                 unzFile uf;
201         } archive;
202 #endif  
203 } classpath_info;
204
205 #endif /* _LOADER_H */
206
207
208 /*
209  * These are local overrides for various environment variables in Emacs.
210  * Please do not remove this and leave it at the end of the file, where
211  * Emacs will automagically detect them.
212  * ---------------------------------------------------------------------
213  * Local variables:
214  * mode: c
215  * indent-tabs-mode: t
216  * c-basic-offset: 4
217  * tab-width: 4
218  * End:
219  */