b53b6489e77b8ed5ffae7a42b0d22298ee12ac21
1 /*
2 * @(#)file.c 1.40 02/09/27
3 *
4 * Copyright 1995-1998 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: Operations on class files.
19 * FILE: file.c
20 * OVERVIEW: Routines for outputing the internal class file.
21 *
22 * AUTHOR(s): Original implementation,
23 * Sheng Liang, Sun Microsystems, Inc.
24 *
25 * Modifications for JAR support, debug support, CLDC compliance,
26 * Tasneem Sayeed, Sun Microsystems
27 *
28 * Added support for inner classes, fixes for stack maps, etc.
29 * Frank Yellin, Sun Microsystems
30 *=======================================================================*/
32 /*=========================================================================
33 * Include files
34 *=======================================================================*/
36 #include <sys/types.h>
37 #include <fcntl.h>
38 #include <sys/stat.h>
39 #include <stdio.h>
40 #include <string.h>
41 #include <stdlib.h>
42 #include <stddef.h>
44 #ifdef UNIX
45 #include <unistd.h>
46 #endif
54 #ifdef WIN32
55 #include <direct.h>
56 #endif
58 /* initialize opnames[256]; */
62 /*=========================================================================
63 * Globals and extern declarations
64 *=======================================================================*/
84 #define INIT_CLASS_BUF_SIZE 256
87 {
91 }
92 }
94 }
97 {
100 }
103 {
107 }
110 {
116 }
119 {
124 }
125 }
128 {
140 }
141 }
145 }
146 }
150 }
154 {
163 }
167 }
168 }
169 // panic("class expected to be in constant pool: %s", name);
171 }
174 {
183 }
184 }
186 }
189 {
198 /* The maximum number of new utf8 entries we'll need is one
199 * for "StackMap", plus one for each of the new class entries.
200 * However, we bump the number to 2 in case we need to add another
201 * entry for the SourceFile attribute.
202 */
207 /* Put sure we have all the Utf8 entries that we need, so that
208 * we'll know the final size of the constant pool.
209 */
213 }
221 }
222 }
223 /* At this, we should not add have to create any more utf8 entries.
224 * We find the value of unhand(cb)->n_new_utf8_entries, and complain
225 * later if this value has changed.
226 */
240 }
273 i++;
276 // default:
277 // panic("bad constant pool entry type: %d", type_table[i]);
278 }
280 /* Write extra CONSTANT_Class entries created by the stackmaps */
285 }
286 }
287 }
288 /* Write extra CONSTANT_Utf8 entries created by the stackmaps */
296 }
297 }
299 // panic("New utf8 entries have been added???");
300 }
302 }
305 {
310 }
311 }
314 {
322 /* Number of attributes we're about to output.
323 * Each item in the following sum is a boolean that returns 1 or 0.
324 */
332 }
336 }
340 }
341 }
342 }
345 {
352 }
354 /* This is ugly
355 * Non-negative entries refer to classes
356 * in the original constant pool.
357 * Negative entries, ~(entry->info) is the entry's index
358 * in the list of additional constant pool entries.
359 */
364 }
365 }
366 }
367 }
370 {
378 }
379 }
381 }
384 {
393 /* Attribute count
394 * Each item in the following sum is a boolean that returns 1 or 0.
395 */
417 }
418 }
420 /* attribute_name_index for "Code" attribute */
423 /* calculate the size of the line_number_table attribute */
424 /* Attribute length for line_number_table
425 * sizeof line_number_table(4) * no. of table entries + 8
426 * 8 bytes = 2 bytes for attr_name_index +
427 * 4 bytes for attr_length +
428 * 2 bytes for line_number_table_length
429 */
432 }
434 /* calculate the size of the localvar_table attribute */
435 /* Attribute length for localvar_table
436 * sizeof localvar_table (10) * no. of table entries + 8
437 * 8 bytes = 2 bytes for attr_name_index +
438 * 4 bytes for attr_length +
439 * 2 bytes for line_number_table_length
440 */
443 }
445 /* Attribute Length */
448 + stack_map_attr_length
449 + line_no_attr_length
456 }
463 }
465 /* Attributes count for Code attribute */
468 /* check if we have a valid line_number_table entries and
469 * if so, write out the pc and line_number entries.
470 */
473 /* line_number_table attribute exists */
474 /* attribute_name_index for "LineNumberTable" */
476 /* Attribute length for line_number_table
477 * (exclude initial 6 bytes = 2 bytes for attr_name_index +
478 * 4 bytes for attr_length)
479 */
481 /* Length of line_number_table */
483 /* write out the line_number_table entries */
488 }
489 }
490 }
492 /* check if we have a valid localvar_table entries and
493 * if so, write out its entries
494 */
497 /* localvar_table attribute exists */
498 /* attribute_name_index for "LocalVariableTable" */
501 /* Attribute length for localvar_table
502 * (exclude initial 6 bytes = 2 bytes for attr_name_index +
503 * 4 bytes for attr_length)
504 */
507 /* Length of localvar_table */
510 /* write out the localvar_table entries */
518 }
519 }
520 }
534 }
535 }
536 }
544 }
545 }
549 }
553 }
554 }
555 }
558 {
564 }
570 }
573 // jio_fprintf(stderr, "Creating output directory [%s]\n", dir);
574 }
575 #ifdef WIN32
577 #endif
578 #ifdef UNIX
580 #endif
581 }
583 }
586 {
591 #ifdef WIN32
593 #endif
594 #ifdef UNIX
596 #endif
597 // panic("%s is write protected\n", dir);
598 }
600 // panic("%s is not a directory\n", dir);
601 }
602 }
606 void
608 {
616 // panic("out of memory");
617 }
638 /* Output number of attributes
639 * Each item in the following sum is a boolean that returns 1 or 0.
640 */
647 );
649 /* write the source file attribute used for debugging purposes */
652 /* CP entry containing the source name */
654 }
656 /* write the source file attribute used for debugging purposes */
660 }
666 }
670 }
674 }
689 }
690 }
692 /* Conversion for Japanese filenames */
695 // if (JARfile) {
696 /* classes need to be put in a JAR file */
697 // sprintf(fname, "%s/%s.class", tmp_dir, nativeName);
698 // } else {
700 // }
702 {
711 }
713 }
715 #ifdef UNIX
717 #endif
718 #ifdef WIN32
720 #endif
723 // panic("failed to open %s", fname);
724 }
731 }
733 void
735 {
736 /* If this is the first class, we'll run into problems if loading the
737 * class forces Object to be loaded, when then forces this class to
738 * be loaded. To prohibit such problems, we force Object to be loaded
739 */
742 {
748 // jio_fprintf(stderr, "Error loading class %s\n", class_name);
751 /* Check for native methods in classes */
758 // panic("native methods should not appear");
759 }
760 }
761 }
766 }
767 }
768 }
771 {
776 /* Convert all slashes in the classname to periods */
779 }
782 {
784 // fprintf(stderr, "Error preverifying class %s\n ",
785 // PrintableClassname(current_class_name));
786 }
787 }