+2001-03-19 Per Bothner <per@bothner.com>
+
+ Fixes to process to command-line .class files in two passes.
+ * java-tree.h (JAVA_FILE_P, CLASS_FILE_P, ZIP_FILE_P): New flags.
+ (CLASS_FROM_CURRENTLY_COMPILED_SOURCE_P): Rename to ..
+ (CLASS_FROM_CURRENTLY_COMPILED_P): ... because it is more general now.
+ * class.c (is_compiled_class): Fix for renamed flag.
+ * parse.y (maybe_create_class_interface_decl): Likewise.
+ * jcf-parse.c (yyparse): Also set if compiling .class files.
+ * jcf-parse.c (read_class); Read current_class.
+ (jcf_parse): Make static.
+ (load_inner_classes): New function, with code moved from jcf_parse,
+ because we need to inner classes after the command-line files are read.
+ (yyparse): Set finput to NULL when it doesn't need to be closed.
+ Reduce use of main_jcf (basically only for archive) and
+ use finput instead of main_jcf->read_state.
+ Inline jcf_figure_file_type into yyparse.
+ Set JAVA_FILE_P, CLASS_FILE_P, or ZIP_FILE_P on filename list name.
+ Defer load_inner_classes and parse_class_file to a second pass,
+ after we've correctly mapped command-line .clas fiels to classes.
+ (jcf_figure_file_type): Removed.
+ * jcf.h (JCF_ZIP, JCF_CLASS, JCF_SOURCE): Removed flags.
+ (JCF_ZERO): Also clear zipd field.
+ * zipfile.h: Conditionalize on JCF_H insread of JCF_ZIP.
+
+2001-03-18 Matt Kraai <kraai@alumni.carnegiemellon.edu>
+
+ * jcf-parse.c (yyparse): Change ch from char * to char.
+
2001-03-19 Per Bothner <per@bothner.com>
* jvspec.c (lang_specific_driver): Check for .zip and .jar files.
Add constructed filelist-file at end, following -xjava. Thus any .o
and library files are not affected by the -xjava. Also wrap
- explicut @FILE with -xjava and -xnone.
+ explicit @FILE with -xjava and -xnone.
2001-03-19 Andrew Haley <aph@cambridge.redhat.com>
COMPOUND_ASSIGN_P (in EXPR (binop_*))
LOCAL_CLASS_P (in RECORD_TYPE)
BLOCK_IS_IMPLICIT (in BLOCK)
+ JAVA_FILE_P (in TREE_LIST in current_file_list)
2: RETURN_MAP_ADJUSTED (in TREE_VEC).
QUALIFIED_P (in IDENTIFIER_NODE)
PRIMARY_P (in EXPR_WITH_FILE_LOCATION)
MODIFY_EXPR_FROM_INITIALIZATION_P (in MODIFY_EXPR)
CLASS_METHOD_CHECKED_P (in RECORD_TYPE)
+ CLASS_FILE_P (in TREE_LIST in current_file_list)
3: IS_AN_IMPORT_ON_DEMAND_P (in IDENTIFIER_NODE)
RESOLVE_PACKAGE_NAME_P (in EXPR_WITH_FILE_LOCATION)
SWITCH_HAS_DEFAULT (in SWITCH_EXPR)
+ ZIP_FILE_P (in TREE_LIST in current_file_list)
4: IS_A_COMMAND_LINE_FILENAME_P (in IDENTIFIER_NODE)
RESOLVE_TYPE_NAME_P (in EXPR_WITH_FILE_LOCATION)
CALL_USING_SUPER (in CALL_EXPR)
extern tree get_name_constant PARAMS ((struct JCF*, int));
extern tree get_class_constant PARAMS ((struct JCF*, int));
extern tree parse_signature PARAMS ((struct JCF *jcf, int sig_index));
-extern void jcf_parse PARAMS ((struct JCF*));
extern tree add_field PARAMS ((tree, tree, tree, int));
extern tree add_method PARAMS ((tree, int, tree, tree));
extern tree add_method_1 PARAMS ((tree, int, tree, tree));
#define METHOD_ABSTRACT(DECL) DECL_LANG_FLAG_5 (DECL)
#define METHOD_TRANSIENT(DECL) DECL_LANG_FLAG_6 (DECL)
+#define JAVA_FILE_P(NODE) TREE_LANG_FLAG_2 (NODE)
+#define CLASS_FILE_P(NODE) TREE_LANG_FLAG_3 (NODE)
+#define ZIP_FILE_P(NODE) TREE_LANG_FLAG_4 (NODE)
+
/* Other predicates on method decls */
#define DECL_CONSTRUCTOR_P(DECL) DECL_LANG_FLAG_7(DECL)
/* True of a RECORD_TYPE of a class/interface type (not array type) */
#define CLASS_P(TYPE) TYPE_LANG_FLAG_4 (TYPE)
-/* True if class TYPE was defined in a Java source file compiled. */
-#define CLASS_FROM_CURRENTLY_COMPILED_SOURCE_P(TYPE) \
+/* True if class TYPE was requested (on command line) to be compiled.*/
+#define CLASS_FROM_CURRENTLY_COMPILED_P(TYPE) \
TYPE_LANG_FLAG_5 (TYPE)
/* True if class TYPE is currently being laid out. Helps in detection
/* 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));
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. */
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 ();
}
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));
int filename_count = 0;
char *list, *next;
tree node;
- FILE *finput;
+ FILE *finput = NULL;
if (flag_filelist_file)
{
next += count;
}
fclose (finput);
+ finput = NULL;
}
else
list = xstrdup (input_filename);
{
for (next = list; ; )
{
- char *ch = *next;
+ char ch = *next;
if (ch == '\n' || ch == '\r' || ch == '\t' || ch == ' '
|| ch == '&' /* FIXME */)
{
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 */
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;
}
}
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 ();
return 0;
}
-static struct ZipFile *localToFile;
-
/* Process all class entries found in the zip file. */
static void
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)
}
}
-/* 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