made descriptor parsing safer + array classes fix
[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 723 2003-12-08 19:51:32Z edwin $
30 */
31
32
33 #ifndef _LOADER_H
34 #define _LOADER_H
35
36 #include <stdio.h>
37
38
39 /************************* program switches ***********************************/
40
41 extern bool loadverbose;         /* Print debug messages during loading */
42 extern bool linkverbose;
43 extern bool initverbose;         /* Log class initialization */ 
44 extern bool makeinitializations; /* Initialize classes automatically */
45
46 extern bool getloadingtime;
47 extern long int loadingtime;     /* CPU time for class loading */
48
49 extern list unlinkedclasses;     /* List containing all unlinked classes */
50 extern list linkedclasses;       /* List containing all linked classes */
51
52 #ifdef USE_THREADS
53 extern int blockInts;
54 #endif
55
56
57 /************************ prototypes ******************************************/
58
59 /* initialize laoder, load important systemclasses */
60 void loader_init();
61
62 void suck_init(char *cpath);
63
64 /* free resources */
65 void loader_close();
66
67 /* load a class and all referenced classes */
68 classinfo *loader_load(utf *topname);
69
70 /* initializes all loaded classes */
71 void loader_initclasses();
72
73 void loader_compute_subclasses();
74
75 /* retrieve constantpool element */
76 voidptr class_getconstant(classinfo *class, u4 pos, u4 ctype);
77
78 /* determine type of a constantpool element */
79 u4 class_constanttype(classinfo *class, u4 pos);
80
81 s4 class_findmethodIndex(classinfo *c, utf *name, utf *desc);
82
83 /* search class for a field */
84 fieldinfo *class_findfield(classinfo *c, utf *name, utf *desc);
85
86 /* search for a method with a specified name and descriptor */
87 methodinfo *class_findmethod(classinfo *c, utf *name, utf *desc);
88 methodinfo *class_resolvemethod(classinfo *c, utf *name, utf *dest);
89
90 /* search for a method with specified name and arguments (returntype ignored) */
91 methodinfo *class_findmethod_approx(classinfo *c, utf *name, utf *desc);
92 methodinfo *class_resolvemethod_approx(classinfo *c, utf *name, utf *dest);
93
94 bool class_issubclass(classinfo *sub, classinfo *super);
95
96 /* call initializer of class */
97 void class_init(classinfo *c);
98
99 void class_showconstanti(classinfo *c, int ii);
100
101 /* debug purposes */
102 void class_showmethods(classinfo *c);
103 void class_showconstantpool(classinfo *c);
104 void print_arraydescriptor(FILE *file, arraydescriptor *desc);
105
106 classinfo *loader_load(utf *topname);
107
108 /* set buffer for reading classdata */
109 void classload_buffer(u1 *buf, int len);
110
111 /* return the primitive class inidicated by the given signature character */
112 classinfo *class_primitive_from_sig(char sig);
113
114
115 /* return the class indicated by the given descriptor */
116 /* (see loader.c for documentation) */
117 #define CLASSLOAD_NEW           0      /* default */
118 #define CLASSLOAD_LOAD          0x0001
119 #define CLASSLOAD_SKIP          0x0002
120 #define CLASSLOAD_PANIC         0      /* default */
121 #define CLASSLOAD_NOPANIC       0x0010
122 #define CLASSLOAD_PRIMITIVE     0      /* default */
123 #define CLASSLOAD_NULLPRIMITIVE 0x0020
124 #define CLASSLOAD_VOID          0      /* default */
125 #define CLASSLOAD_NOVOID        0x0040
126 #define CLASSLOAD_NOCHECKEND    0      /* default */
127 #define CLASSLOAD_CHECKEND      0x1000
128
129 classinfo *class_from_descriptor(char *utf_ptr,char *end_ptr,char **next,int mode);
130 int type_from_descriptor(classinfo **cls,char *utf_ptr,char *end_ptr,char **next,int mode);
131
132 /* (used by class_new, don't use directly) */
133 void class_new_array(classinfo *c);
134
135 void class_link(classinfo *c);
136
137 void field_display(fieldinfo *f);
138
139 void method_display(methodinfo *m);
140
141 utf* clinit_desc();
142 utf* clinit_name();
143
144 #endif /* _LOADER_H */
145
146
147 /*
148  * These are local overrides for various environment variables in Emacs.
149  * Please do not remove this and leave it at the end of the file, where
150  * Emacs will automagically detect them.
151  * ---------------------------------------------------------------------
152  * Local variables:
153  * mode: c
154  * indent-tabs-mode: t
155  * c-basic-offset: 4
156  * tab-width: 4
157  * End:
158  */