* Removed all Id tags.
[cacao.git] / src / vmcore / primitivecore.c
1 /* src/vmcore/primitivecore.c - core functions for primitive types
2
3    Copyright (C) 2007 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 */
26
27
28 #include "config.h"
29
30 #include <assert.h>
31 #include <stdint.h>
32
33 #include "vm/global.h"
34 #include "vm/primitive.h"
35
36 #include "vmcore/class.h"
37 #include "vmcore/utf8.h"
38
39
40 /* primitivetype_table *********************************************************
41
42    Structure for primitive classes: contains the class for wrapping
43    the primitive type, the primitive class, the name of the class for
44    wrapping, the one character type signature and the name of the
45    primitive class.
46  
47    CAUTION: Don't change the order of the types. This table is indexed
48    by the ARRAYTYPE_ constants (except ARRAYTYPE_OBJECT).
49
50 *******************************************************************************/
51
52 primitivetypeinfo primitivetype_table[PRIMITIVETYPE_COUNT] = {
53         { "int"     , NULL, NULL, NULL, "java/lang/Integer",   'I', "[I", NULL },
54         { "long"    , NULL, NULL, NULL, "java/lang/Long",      'J', "[J", NULL },
55         { "float"   , NULL, NULL, NULL, "java/lang/Float",     'F', "[F", NULL },
56         { "double"  , NULL, NULL, NULL, "java/lang/Double",    'D', "[D", NULL },
57         { NULL      , NULL, NULL, NULL, NULL,                   0 , NULL, NULL },
58         { "byte"    , NULL, NULL, NULL, "java/lang/Byte",      'B', "[B", NULL },
59         { "char"    , NULL, NULL, NULL, "java/lang/Character", 'C', "[C", NULL },
60         { "short"   , NULL, NULL, NULL, "java/lang/Short",     'S', "[S", NULL },
61         { "boolean" , NULL, NULL, NULL, "java/lang/Boolean",   'Z', "[Z", NULL },
62         { NULL      , NULL, NULL, NULL, NULL,                   0 , NULL, NULL },
63 #if defined(ENABLE_JAVASE)
64         { "void"    , NULL, NULL, NULL, "java/lang/Void",      'V', NULL, NULL }
65 #else
66         { NULL      , NULL, NULL, NULL, NULL,                   0 , NULL, NULL },
67 #endif
68 };
69
70
71 /* primitive_init **************************************************************
72
73    Create classes representing primitive types.
74
75 *******************************************************************************/
76
77 bool primitive_init(void)
78 {  
79         utf       *name;
80         classinfo *c;
81         utf       *u;
82         int        i;
83
84         for (i = 0; i < PRIMITIVETYPE_COUNT; i++) {
85                 /* skip dummies */
86
87                 if (primitivetype_table[i].cname == NULL)
88                         continue;
89
90                 /* create UTF-8 name */
91
92                 name = utf_new_char(primitivetype_table[i].cname);
93
94                 primitivetype_table[i].name = name;
95
96                 /* create primitive class */
97
98                 c = class_create_classinfo(name);
99
100                 /* primitive classes don't have a super class */
101
102                 c->super.any = NULL;
103
104                 /* set flags and mark it as primitive class */
105
106                 c->flags = ACC_PUBLIC | ACC_FINAL | ACC_ABSTRACT | ACC_CLASS_PRIMITIVE;
107                 
108                 /* prevent loader from loading primitive class */
109
110                 c->state |= CLASS_LOADED;
111
112                 /* INFO: don't put primitive classes into the classcache */
113
114                 if (!link_class(c))
115                         return false;
116
117                 primitivetype_table[i].class_primitive = c;
118
119                 /* create class for wrapping the primitive type */
120
121                 u = utf_new_char(primitivetype_table[i].wrapname);
122                 c = load_class_bootstrap(u);
123
124                 if (c == NULL)
125                         return false;
126
127                 primitivetype_table[i].class_wrap = c;
128
129                 /* create the primitive array class */
130
131                 if (primitivetype_table[i].arrayname) {
132                         u = utf_new_char(primitivetype_table[i].arrayname);
133                         c = class_create_classinfo(u);
134                         c = load_newly_created_array(c, NULL);
135
136                         if (c == NULL)
137                                 return false;
138
139                         primitivetype_table[i].arrayclass = c;
140
141                         assert(c->state & CLASS_LOADED);
142
143                         if (!(c->state & CLASS_LINKED))
144                                 if (!link_class(c))
145                                         return false;
146                 }
147         }
148
149         return true;
150 }
151
152
153 /*
154  * These are local overrides for various environment variables in Emacs.
155  * Please do not remove this and leave it at the end of the file, where
156  * Emacs will automagically detect them.
157  * ---------------------------------------------------------------------
158  * Local variables:
159  * mode: c
160  * indent-tabs-mode: t
161  * c-basic-offset: 4
162  * tab-width: 4
163  * End:
164  * vim:noexpandtab:sw=4:ts=4:
165  */