diff options
Diffstat (limited to 'gcc/java/jcf-parse.c')
-rw-r--r-- | gcc/java/jcf-parse.c | 131 |
1 files changed, 73 insertions, 58 deletions
diff --git a/gcc/java/jcf-parse.c b/gcc/java/jcf-parse.c index b7a4c0b..84f2688 100644 --- a/gcc/java/jcf-parse.c +++ b/gcc/java/jcf-parse.c @@ -81,9 +81,11 @@ static tree parse_roots[3] = { NULL_TREE, NULL_TREE, NULL_TREE }; /* A list of file names. */ #define current_file_list parse_roots[2] -/* The Java .class file that provides main_class; the main input file. */ +/* The Java archive that provides main_class; the main input file. */ static struct JCF main_jcf[1]; +static struct ZipFile *localToFile; + /* Declarations of some functions used here. */ static void handle_innerclass_attribute PARAMS ((int count, JCF *)); static tree give_name_to_class PARAMS ((JCF *jcf, int index)); @@ -92,11 +94,12 @@ static void process_zip_dir PARAMS ((FILE *)); static void parse_source_file_1 PARAMS ((tree, FILE *)); static void parse_source_file_2 PARAMS ((void)); static void jcf_parse_source PARAMS ((void)); -static int jcf_figure_file_type PARAMS ((JCF *)); static void parse_class_file PARAMS ((void)); static void set_source_filename PARAMS ((JCF *, int)); static int predefined_filename_p PARAMS ((tree)); static void ggc_mark_jcf PARAMS ((void**)); +static void jcf_parse PARAMS ((struct JCF*)); +static void load_inner_classes PARAMS ((tree)); /* Mark (for garbage collection) all the tree nodes that are referenced from JCF's constant pool table. */ @@ -576,9 +579,11 @@ read_class (name) java_parser_context_save_global (); java_push_parser_context (); input_filename = current_jcf->filename; + current_class = class; if (JCF_SEEN_IN_ZIP (current_jcf)) read_zip_member(current_jcf, current_jcf->zipd, current_jcf->zipd->zipf); jcf_parse (current_jcf); + load_inner_classes (current_class); java_pop_parser_context (0); java_parser_context_restore_global (); } @@ -708,11 +713,17 @@ jcf_parse (jcf) if (current_class == object_type_node) layout_class_methods (object_type_node); else - all_class_list = tree_cons (NULL_TREE, + all_class_list = tree_cons (NULL_TREE, TYPE_NAME (current_class), all_class_list ); +} - /* And if we came across inner classes, load them now. */ - for (current = DECL_INNER_CLASS_LIST (TYPE_NAME (current_class)); current; +/* If we came across inner classes, load them now. */ +static void +load_inner_classes (cur_class) + tree cur_class; +{ + tree current; + for (current = DECL_INNER_CLASS_LIST (TYPE_NAME (cur_class)); current; current = TREE_CHAIN (current)) { tree name = DECL_NAME (TREE_PURPOSE (current)); @@ -889,7 +900,7 @@ yyparse () int filename_count = 0; char *list, *next; tree node; - FILE *finput; + FILE *finput = NULL; if (flag_filelist_file) { @@ -923,6 +934,7 @@ yyparse () next += count; } fclose (finput); + finput = NULL; } else list = xstrdup (input_filename); @@ -931,7 +943,7 @@ yyparse () { for (next = list; ; ) { - char *ch = *next; + char ch = *next; if (ch == '\n' || ch == '\r' || ch == '\t' || ch == ' ' || ch == '&' /* FIXME */) { @@ -1017,6 +1029,8 @@ yyparse () current_file_list = nreverse (current_file_list); for (node = current_file_list; node; node = TREE_CHAIN (node)) { + unsigned char magic_string[4]; + uint32 magic; tree name = TREE_VALUE (node); /* Skip already parsed files */ @@ -1024,41 +1038,62 @@ yyparse () continue; /* Close previous descriptor, if any */ - if (main_jcf->read_state && fclose (main_jcf->read_state)) - fatal_io_error ("can't close %s", - main_jcf->filename ? main_jcf->filename : "<unknown>"); + if (finput && fclose (finput)) + fatal_io_error ("can't close input file %s", main_input_filename); - /* Set jcf up and open a new file */ - JCF_ZERO (main_jcf); - main_jcf->read_state = fopen (IDENTIFIER_POINTER (name), "rb"); - if (main_jcf->read_state == NULL) + finput = fopen (IDENTIFIER_POINTER (name), "rb"); + if (finput == NULL) fatal_io_error ("can't open %s", IDENTIFIER_POINTER (name)); - /* Set new input_filename and finput */ - finput = main_jcf->read_state; #ifdef IO_BUFFER_SIZE setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE); #endif input_filename = IDENTIFIER_POINTER (name); - main_jcf->filbuf = jcf_filbuf_from_stdio; - switch (jcf_figure_file_type (current_jcf)) + /* Figure what kind of file we're dealing with */ + if (fread (magic_string, 1, 4, finput) != 4) + fatal_io_error ("Premature end of input file %s", + IDENTIFIER_POINTER (name)); + fseek (finput, 0L, SEEK_SET); + magic = GET_u4 (magic_string); + if (magic == 0xcafebabe) { - case JCF_ZIP: - parse_zip_file_entries (); - break; - case JCF_CLASS: + CLASS_FILE_P (node) = 1; + current_jcf = ALLOC (sizeof (JCF)); + JCF_ZERO (current_jcf); + current_jcf->read_state = finput; + current_jcf->filbuf = jcf_filbuf_from_stdio; jcf_parse (current_jcf); - parse_class_file (); - break; - case JCF_SOURCE: + TYPE_JCF (current_class) = current_jcf; + CLASS_FROM_CURRENTLY_COMPILED_P (current_class) = 1; + TREE_PURPOSE (node) = current_class; + } + else if (magic == (JCF_u4)ZIPMAGIC) + { + ZIP_FILE_P (node) = 1; + JCF_ZERO (main_jcf); + main_jcf->read_state = finput; + main_jcf->filbuf = jcf_filbuf_from_stdio; + if (open_in_zip (main_jcf, input_filename, NULL, 0) < 0) + fatal_error ("bad zip/jar file %s", IDENTIFIER_POINTER (name)); + localToFile = SeenZipFiles; + /* Register all the class defined there. */ + process_zip_dir (main_jcf->read_state); + parse_zip_file_entries (); + /* + for (each entry) + CLASS_FROM_CURRENTLY_COMPILED_P (current_class) = 1; + */ + } + else + { + JAVA_FILE_P (node) = 1; java_push_parser_context (); java_parser_context_save_global (); parse_source_file_1 (name, finput); java_parser_context_restore_global (); java_pop_parser_context (1); - break; } } @@ -1067,6 +1102,17 @@ yyparse () input_filename = ctxp->filename; parse_source_file_2 (); } + for (node = current_file_list; node; node = TREE_CHAIN (node)) + { + input_filename = IDENTIFIER_POINTER (TREE_VALUE (node)); + if (CLASS_FILE_P (node)) + { + current_class = TREE_PURPOSE (node); + current_jcf = TYPE_JCF (current_class); + load_inner_classes (current_class); + parse_class_file (); + } + } input_filename = main_input_filename; java_expand_classes (); @@ -1075,8 +1121,6 @@ yyparse () return 0; } -static struct ZipFile *localToFile; - /* Process all class entries found in the zip file. */ static void parse_zip_file_entries (void) @@ -1101,6 +1145,7 @@ parse_zip_file_entries (void) { read_zip_member(current_jcf, zdir, localToFile); jcf_parse (current_jcf); + load_inner_classes (current_class); } if (TYPE_SIZE (current_class) != error_mark_node) @@ -1175,36 +1220,6 @@ process_zip_dir (FILE *finput) } } -/* Figure what kind of file we're dealing with */ -static int -DEFUN(jcf_figure_file_type, (jcf), - JCF *jcf) -{ - unsigned char magic_string[4]; - uint32 magic; - - if (fread (magic_string, 1, 4, jcf->read_state) != 4) - jcf_unexpected_eof (jcf, 4); - - fseek (jcf->read_state, 0L, SEEK_SET); - magic = GET_u4 (magic_string); - - if (magic == 0xcafebabe) - return JCF_CLASS; - - /* FIXME: is it a system file? */ - if (magic == (JCF_u4)ZIPMAGIC - && !open_in_zip (jcf, input_filename, NULL, 0)) - { - localToFile = SeenZipFiles; - /* Register all the class defined there. */ - process_zip_dir (jcf->read_state); - return JCF_ZIP; - } - - return JCF_SOURCE; -} - /* Initialization. */ void |