1 /********************************************************************
3 constant_pool.c - methods for handling constant pool
5 Niksa Orlic, 2004-06-11
7 ********************************************************************/
9 #include <stdlib.h>
10 #include <string.h>
11 #include <stdio.h>
14 //#include "../util/message.h"
31 /*
32 Insert a utf8 string into the constant pool table and return its index in the table.
33 */
35 {
40 /* check if the string already exists in the table */
42 {
45 {
47 }
48 }
50 /* create a new entry */
54 /* calculate the needeed size for the string */
57 {
58 /* if ((unsigned char)str[i] > 127)
59 size += 2;
60 else*/
61 size ++;
62 }
71 {
72 /* if ((unsigned char)str[i] <= 127)
73 {*/
75 j++;
76 /* }
77 else
78 {
79 entry->data[j] = (char)0xC2 | (str[i]>>7)&0x01;
80 j++;
81 entry->data[j] = (str[i] & 0x3F) | 0x80;
82 j++;
83 }*/
84 }
89 }
91 /*
92 Add a string entry into the constant pool.
93 */
95 {
99 /* first add the utf8 constant */
102 /* search if the same string already exists */
104 {
107 {
109 }
110 }
112 /* create the new entry */
118 }
120 /*
121 Add an integer into the constant pool.
122 */
124 {
128 /* check if the string already exists in the table */
130 {
132 {
137 }
138 }
140 /* create a new entry */
151 }
153 /*
154 Add a long constant into the constant pool
155 */
157 {
161 }
163 /*
164 Add a float constant into the constant pool
165 */
167 {
171 }
173 /*
174 Add a double constant into the constant pool
175 */
177 {
181 /* check if the string already exists in the table */
183 {
185 {
190 }
191 }
193 /* create a new entry */
204 }
207 /*
208 Adds a class information into the constants pool
209 */
211 {
215 /* first add the utf8 constant */
218 /* search if the same string already exists */
220 {
223 {
225 }
226 }
228 /* create the new entry */
234 }
236 /*
237 Add name and type entry into the constant pool
238 */
240 {
246 /* first add the utf8 constant */
250 /* search if the same string already exists */
252 {
256 {
258 }
259 }
261 /* create the new entry */
268 }
270 /*
271 Adds the fieldref entry into the constant pool
272 */
274 {
280 /* first add the utf8 constant */
284 /* search if the same string already exists */
286 {
290 {
292 }
293 }
295 /* create the new entry */
302 }
304 /*
305 Add the fieldref entry into the constant pool
306 */
308 {
314 /* first add the utf8 constant */
318 /* search if the same string already exists */
320 {
324 {
326 }
327 }
329 /* create the new entry */
336 }
338 /*
339 Add the interface entry into the constant pool
340 */
342 {
347 /* first add the utf8 constant */
350 /* search if the same string already exists */
352 {
353 if ((constants[i].tag == 10) && (constants[i].param1 == class_index) && (constants[i].param2 == nameandtype_index))
355 }
356 /* create the new entry */
362 }
364 /*
365 Creates a new entry in the constant pool.
366 */
368 {
369 constant_pool_size ++;
373 else
381 }
383 /*
384 Writes the constant pool to the disk
385 */
387 {
390 /* write the constant pool count */
393 /* write the constant pool entries */
395 {
396 /* write the tag */
402 {
404 {
406 }
412 {
415 }
419 {
421 }
425 {
427 }
431 {
435 }
439 {
442 }
447 }
448 }
449 }