1 /*
2 * @(#)util.c 1.7 02/09/27
3 *
4 * Copyright 1995-1999 by Sun Microsystems, Inc.,
5 * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
6 * All rights reserved.
7 *
8 * This software is the confidential and proprietary information
9 * of Sun Microsystems, Inc. ("Confidential Information"). You
10 * shall not disclose such Confidential Information and shall use
11 * it only in accordance with the terms of the license agreement
12 * you entered into with Sun.
13 * Use is subject to license terms.
14 */
16 /*=========================================================================
17 * SYSTEM: Verifier
18 * SUBSYSTEM: Utility functions.
19 * FILE: util.c
20 * OVERVIEW: Utility routines needed by both the compiler and the interpreter.
21 *
22 * AUTHOR: Sheng Liang, Sun Microsystems, Inc.
23 * Edited by Tasneem Sayeed, Sun Microsystems
24 *=======================================================================*/
26 /*=========================================================================
27 * Include files
28 *=======================================================================*/
30 #include <stdio.h>
31 #include <string.h>
32 #include <ctype.h>
33 #include <stddef.h>
40 /*=========================================================================
41 * Globals and extern declarations
42 *=======================================================================*/
47 unicode *
49 {
56 }
58 void
60 {
64 }
67 int
69 {
78 }
80 int
82 {
91 }
93 int
95 {
97 }
100 /*
101 * Print s null terminated C-style character string.
102 */
103 void
105 {
107 }
111 #define HTOVERFLOWPOINT(h) (h->size * 4 / 5)
113 /*
114 * We store most of the result of the hash in hash_bits to quickly
115 * reject impossible matches because strcmp() is fairly expensive,
116 * especially when many strings will have common prefixes.
117 */
136 /* Hash a string into a primary and secondary hash value */
137 static void
139 {
147 }
149 /* Create a hash table of the specified size */
152 {
160 }
162 }
164 /*
165 * Given a string, return a unique 16 bit id number.
166 * If param isn't null, we also set up an array of void * for holding info
167 * about each object. The address of this void * is stored into param
168 * If CopyNeeded is true, then the name argument "s" must be dup'ed, since
169 * the current item is allocated on the stack.
170 *
171 * Note about returning 0 in the case of out of memory errors: 0 is *not*
172 * a valid ID! The out of memory error should be thrown by the calling code.
173 */
174 unsigned short
177 {
178 /*
179 * The database is a hash table. When the hash table overflows, a new
180 * hashtable is created chained onto the previous one. This is done so
181 * that we can use the hashtable slot index as the ID, without worrying
182 * about having the IDs change when the hashtable grows.
183 */
194 /* Create the hash values */
203 /* See if the new hash table has a different hash function */
208 }
216 }
217 /* Not found in this table. Try the next table. */
221 }
223 not_found:
224 /* Either the hash table is empty, or the item isn't yet found. */
226 /* Need to create a new bucket */
230 }
233 /* Calling code should signal OutOfMemoryError */
235 }
237 /* Create a new table */
244 }
249 }
251 }
255 /* Calling code should signal OutOfMemoryError */
257 }
260 }
265 found_it:
266 /* We have found or created slot "i" in hash bucket "h" */
271 /* Calling code should signal OutOfMemoryError */
273 }
274 }
276 }
278 }
280 /* Free an StrIDhash table and all the entries in it */
282 {
292 }
297 }
299 }
301 /*
302 * Call the callback function on every entry in the table. This
303 * should only be invoked holding the string hash table lock.
304 */
306 {
317 }
318 }
320 }
321 }
323 /*
324 * Returns NULL in the case of an error.
325 */
328 {
333 }
339 /* Calling code should signal OutOfMemoryError */
341 }
342 }
344 }
346 }
350 {
354 s++;
355 }
357 }
362 #define CSTRLEN 40
372 else
395 /* Should not be possible to overflow, truncate if so */
399 }
405 }
407 /*
408 * WARNING: out_of_memory() aborts the runtime! It should not be used
409 * except in the case of out of memory situations that are clearly not
410 * survivable, like running out of memory before the runtime is initialized.
411 * If the runtime has finished initializing and you run out of memory, you
412 * should throw an OutOfMemoryError instead.
413 */
414 void
416 {
419 }
421 void
423 {
430 /* If buffer overflow, quietly truncate */
436 }
446 }
447 }
450 }
457 #define ERROR_RETVAL -1
458 #undef SUCCESS
459 #define SUCCESS 0
460 #undef CheckRet
461 #define CheckRet(x) { if ((x) == ERROR_RETVAL) return ERROR_RETVAL; }
463 static int
465 {
470 }
472 }
475 }
478 }
480 static int
483 {
489 }
495 }
502 }
503 }
507 }
513 }
514 }
516 }
518 #define MAX_DIGITS 32
520 static int
523 {
548 }
556 }
557 }
563 }
564 place++;
568 }
575 }
582 }
586 }
591 }
592 }
593 }
596 }
600 }
606 }
607 }
609 }
611 int
613 {
622 }
635 next_char:
653 }
684 }
687 }
688 }
691 }
693 int
695 {
703 }
705 /* Return true if the two classes are in the same class package */
707 bool_t
709 {
718 /* One of the two doesn't have a package. Only return true
719 * if the other one also doesn't have a package. */
726 /* Something is terribly wrong. Shouldn't be here */
728 }
729 name1++;
730 }
734 /* Something is terribly wrong. Shouldn't be here */
736 }
737 name2++;
738 }
743 }
744 }
745 }