Commit b351b287 by Alexandre Petit-Bianco Committed by Alexandre Petit-Bianco

class.c (is_compiled_class): New local variable seen_in_zip.

Tue Oct 20 09:15:38 1998  Alexandre Petit-Bianco  <apbianco@cygnus.com>
	* class.c (is_compiled_class): New local variable
 	seen_in_zip. Identify classes found in currently compiled source
 	file(s).
	* decl.c (complete_start_java_method): Fixed typo.
	* java-tree.h (CLASS_FROM_CURRENTLY_COMPILED_SOURCE_P,
 	HAS_BEEN_ALREADY_PARSED_P, IS_A_COMMAND_LINE_FILENAME_P): New macros.
	(CLASS_P): Moved around.
	(java_parse_abort_on_error): Macro moved from jcf-parse.c
	* jcf-parse.c (java_parse_abort_on_error): Macro moved to
 	java-parse.h
	(jcf_parse_source): Changed leading comment. Removed unnecessary
 	fclose and CLASS_FROM_SOURCE_P marking.
	(parse_source_file): New local variables remember_for_generation
 	and filename. Mark parsed file name identifier node. Removed block
 	executed when parse_only was null. Set remember_for_generation.
	Use it as an argument to java_pop_parser_context.
	(yyparse): New local variables several_files, list, next node and
 	current_file_list. Split ampersand separated file names into
 	current_file_list. Iterate through the list and parse accordingly.
	* parse.h (java_pop_parser_context): New function prototype.
	* parse.y (ctxp_for_generation): New static global variable.
	(java_pop_parser_context): New argument generate. Link popped ctxp
 	to ctxp_for_generation list accordingly.
	(java_complete_expand_methods): Fixed indentation.
	(java_expand_classes): New function.
Add support for the use of `&' as a file separator on the jc1 command
line.

From-SVN: r23201
parent 2331d640
Tue Oct 20 09:15:38 1998 Alexandre Petit-Bianco <apbianco@cygnus.com>
* class.c (is_compiled_class): New local variable
seen_in_zip. Identify classes found in currently compiled source
file(s).
* decl.c (complete_start_java_method): Fixed typo.
* java-tree.h (CLASS_FROM_CURRENTLY_COMPILED_SOURCE_P,
HAS_BEEN_ALREADY_PARSED_P, IS_A_COMMAND_LINE_FILENAME_P): New macros.
(CLASS_P): Moved around.
(java_parse_abort_on_error): Macro moved from jcf-parse.c
* jcf-parse.c (java_parse_abort_on_error): Macro moved to
java-parse.h
(jcf_parse_source): Changed leading comment. Removed unnecessary
fclose and CLASS_FROM_SOURCE_P marking.
(parse_source_file): New local variables remember_for_generation
and filename. Mark parsed file name identifier node. Removed block
executed when parse_only was null. Set remember_for_generation.
Use it as an argument to java_pop_parser_context.
(yyparse): New local variables several_files, list, next node and
current_file_list. Split ampersand separated file names into
current_file_list. Iterate through the list and parse accordingly.
* parse.h (java_pop_parser_context): New function prototype.
* parse.y (ctxp_for_generation): New static global variable.
(java_pop_parser_context): New argument generate. Link popped ctxp
to ctxp_for_generation list accordingly.
(java_complete_expand_methods): Fixed indentation.
(java_expand_classes): New function.
Sat Oct 17 11:25:21 1998 Per Bothner <bothner@cygnus.com> Sat Oct 17 11:25:21 1998 Per Bothner <bothner@cygnus.com>
* Makefile.in: Link with libiberty.a instead of memmove.o. * Makefile.in: Link with libiberty.a instead of memmove.o.
......
...@@ -1131,6 +1131,7 @@ int ...@@ -1131,6 +1131,7 @@ int
is_compiled_class (class) is_compiled_class (class)
tree class; tree class;
{ {
int seen_in_zip;
if (TREE_CODE (class) == POINTER_TYPE) if (TREE_CODE (class) == POINTER_TYPE)
class = TREE_TYPE (class); class = TREE_TYPE (class);
if (TREE_CODE (class) != RECORD_TYPE) /* Primitive types are static. */ if (TREE_CODE (class) != RECORD_TYPE) /* Primitive types are static. */
...@@ -1139,18 +1140,21 @@ is_compiled_class (class) ...@@ -1139,18 +1140,21 @@ is_compiled_class (class)
return 0; return 0;
if (class == current_class) if (class == current_class)
return 2; return 2;
if ((TYPE_LANG_SPECIFIC (class) && TYPE_LANG_SPECIFIC (class)->jcf &&
TYPE_LANG_SPECIFIC (class)->jcf->seen_in_zip)) seen_in_zip = (TYPE_LANG_SPECIFIC (class) && TYPE_LANG_SPECIFIC (class)->jcf
&& TYPE_LANG_SPECIFIC (class)->jcf->seen_in_zip);
if (CLASS_FROM_CURRENTLY_COMPILED_SOURCE_P (class) || seen_in_zip)
{ {
/* The class was seen in the current ZIP file and will be /* The class was seen in the current ZIP file and will be
available as a compiled class in the future but may not have available as a compiled class in the future but may not have
been loaded already. Load it if necessary. This prevent been loaded already. Load it if necessary. This prevent
build_class_ref () from crashing. This should take into build_class_ref () from crashing. */
consideration class specified in a multiple class file
command line. FIXME if necessary. */
if (!CLASS_LOADED_P (class)) if (seen_in_zip && !CLASS_LOADED_P (class))
load_class (class, 1); load_class (class, 1);
/* We return 2 for class seen in ZIP and class from files
belonging to the same compilation unit */
return 2; return 2;
} }
......
...@@ -1507,7 +1507,6 @@ complete_start_java_method (fndecl) ...@@ -1507,7 +1507,6 @@ complete_start_java_method (fndecl)
using a different local variables management, and for them, using a different local variables management, and for them,
pushlevel shouldn't be called from here. */ pushlevel shouldn't be called from here. */
if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl))) if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl)))
{ {
pushlevel (2); pushlevel (2);
if (! flag_emit_class_files) if (! flag_emit_class_files)
......
...@@ -49,8 +49,10 @@ struct JCF; ...@@ -49,8 +49,10 @@ struct JCF;
MODIFY_EXPR_FROM_INITIALIZATION_P (in MODIFY_EXPR) MODIFY_EXPR_FROM_INITIALIZATION_P (in MODIFY_EXPR)
3: IS_AN_IMPORT_ON_DEMAND_P (in IDENTIFIER_NODE) 3: IS_AN_IMPORT_ON_DEMAND_P (in IDENTIFIER_NODE)
RESOLVE_PACKAGE_NAME_P (in EXPR_WITH_FILE_LOCATION) RESOLVE_PACKAGE_NAME_P (in EXPR_WITH_FILE_LOCATION)
4: RESOLVE_TYPE_NAME_P (in EXPR_WITH_FILE_LOCATION) 4: IS_A_COMMAND_LINE_FILENAME_P (in IDENTIFIER_NODE)
5: IS_BREAK_STMT_P (in EXPR_WITH_FILE_LOCATION) RESOLVE_TYPE_NAME_P (in EXPR_WITH_FILE_LOCATION)
5: HAS_BEEN_ALREADY_PARSED_P (in IDENTIFIER_NODE)
IS_BREAK_STMT_P (in EXPR_WITH_FILE_LOCATION)
IS_CRAFTED_STRING_BUFFER_P (in CALL_EXPR) IS_CRAFTED_STRING_BUFFER_P (in CALL_EXPR)
Usage of TYPE_LANG_FLAG_?: Usage of TYPE_LANG_FLAG_?:
...@@ -58,6 +60,7 @@ struct JCF; ...@@ -58,6 +60,7 @@ struct JCF;
2: CLASS_LOADED_P (in RECORD_TYPE). 2: CLASS_LOADED_P (in RECORD_TYPE).
3: CLASS_FROM_SOURCE_P (in RECORD_TYPE). 3: CLASS_FROM_SOURCE_P (in RECORD_TYPE).
4: CLASS_P (in RECORD_TYPE). 4: CLASS_P (in RECORD_TYPE).
5: CLASS_FROM_CURRENTLY_COMPILED_SOURCE_P (in RECORD_TYPE)
Usage of DECL_LANG_FLAG_?: Usage of DECL_LANG_FLAG_?:
1: METHOD_PUBLIC (in FUNCTION_DECL). 1: METHOD_PUBLIC (in FUNCTION_DECL).
...@@ -521,6 +524,8 @@ extern void init_outgoing_cpool PROTO (()); ...@@ -521,6 +524,8 @@ extern void init_outgoing_cpool PROTO (());
extern void make_class_data PROTO ((tree)); extern void make_class_data PROTO ((tree));
extern void register_class PROTO (()); extern void register_class PROTO (());
extern int alloc_name_constant PROTO ((int, tree)); extern int alloc_name_constant PROTO ((int, tree));
extern void emit_register_class PROTO (());
extern void lang_init_source PROTO ((int));
/* Access flags etc for a method (a FUNCTION_DECL): */ /* Access flags etc for a method (a FUNCTION_DECL): */
...@@ -567,8 +572,6 @@ extern int alloc_name_constant PROTO ((int, tree)); ...@@ -567,8 +572,6 @@ extern int alloc_name_constant PROTO ((int, tree));
virtual methods. */ virtual methods. */
#define TYPE_VTABLE(TYPE) TYPE_BINFO_VTABLE(TYPE) #define TYPE_VTABLE(TYPE) TYPE_BINFO_VTABLE(TYPE)
/* True of a RECORD_TYPE of a class/interface type (not array type) */
#define CLASS_P(TYPE) TYPE_LANG_FLAG_4 (TYPE)
/* Use CLASS_LOADED_P? FIXME */ /* Use CLASS_LOADED_P? FIXME */
#define CLASS_COMPLETE_P(DECL) DECL_LANG_FLAG_2 (DECL) #define CLASS_COMPLETE_P(DECL) DECL_LANG_FLAG_2 (DECL)
...@@ -653,6 +656,13 @@ extern tree *type_map; ...@@ -653,6 +656,13 @@ extern tree *type_map;
/* True if class TYPE was defined in Java source code. */ /* True if class TYPE was defined in Java source code. */
#define CLASS_FROM_SOURCE_P(TYPE) TYPE_LANG_FLAG_3 (TYPE) #define CLASS_FROM_SOURCE_P(TYPE) TYPE_LANG_FLAG_3 (TYPE)
/* 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) \
TYPE_LANG_FLAG_5 (TYPE)
/* True if identifier ID was seen while processing a single type import stmt */ /* True if identifier ID was seen while processing a single type import stmt */
#define IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P(ID) TREE_LANG_FLAG_0 (ID) #define IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P(ID) TREE_LANG_FLAG_0 (ID)
...@@ -665,6 +675,12 @@ extern tree *type_map; ...@@ -665,6 +675,12 @@ extern tree *type_map;
/* True if ID is an already processed import on demand */ /* True if ID is an already processed import on demand */
#define IS_AN_IMPORT_ON_DEMAND_P(ID) TREE_LANG_FLAG_3 (ID) #define IS_AN_IMPORT_ON_DEMAND_P(ID) TREE_LANG_FLAG_3 (ID)
/* True if ID is a command-line specified filename */
#define IS_A_COMMAND_LINE_FILENAME_P(ID) TREE_LANG_FLAG_4 (ID)
/* True if filename ID has already been parsed */
#define HAS_BEEN_ALREADY_PARSED_P(ID) TREE_LANG_FLAG_5 (ID)
/* True if EXPR is RHS sub-tree of a compound assign expression */ /* True if EXPR is RHS sub-tree of a compound assign expression */
#define COMPOUND_ASSIGN_P(EXPR) TREE_LANG_FLAG_1 (EXPR) #define COMPOUND_ASSIGN_P(EXPR) TREE_LANG_FLAG_1 (EXPR)
...@@ -754,3 +770,16 @@ extern tree *type_map; ...@@ -754,3 +770,16 @@ extern tree *type_map;
#define IS_UNCHECKED_EXPRESSION_P(TYPE) \ #define IS_UNCHECKED_EXPRESSION_P(TYPE) \
(inherits_from_p ((TYPE), runtime_exception_type_node) \ (inherits_from_p ((TYPE), runtime_exception_type_node) \
|| inherits_from_p ((TYPE), error_exception_type_node)) || inherits_from_p ((TYPE), error_exception_type_node))
/* Make the current function where this macro is invoked report error
messages and and return, if any */
#define java_parse_abort_on_error() \
{ \
extern int java_error_count; \
if (java_error_count) \
{ \
java_report_errors (); \
java_pop_parser_context (0); \
return; \
} \
}
...@@ -73,16 +73,6 @@ void process_zip_dir(); ...@@ -73,16 +73,6 @@ void process_zip_dir();
/* Source file compilation declarations */ /* Source file compilation declarations */
static void parse_source_file (); static void parse_source_file ();
extern int java_error_count;
#define java_parse_abort_on_error() \
{ \
if (java_error_count) \
{ \
java_report_errors (); \
java_pop_parser_context (); \
return; \
} \
}
/* Handle "SourceFile" attribute. */ /* Handle "SourceFile" attribute. */
...@@ -525,8 +515,7 @@ load_class (class_or_name, verbose) ...@@ -525,8 +515,7 @@ load_class (class_or_name, verbose)
fseek (current_jcf->read_state, saved_pos, SEEK_SET); fseek (current_jcf->read_state, saved_pos, SEEK_SET);
} }
/* Parse a source file when JCF refers to a source file. This piece /* Parse a source file when JCF refers to a source file. */
needs further work as far as error handling and report. */
int int
jcf_parse_source (jcf) jcf_parse_source (jcf)
...@@ -538,12 +527,7 @@ jcf_parse_source (jcf) ...@@ -538,12 +527,7 @@ jcf_parse_source (jcf)
if (!(finput = fopen (input_filename, "r"))) if (!(finput = fopen (input_filename, "r")))
fatal ("input file `%s' just disappeared - jcf_parse_source", fatal ("input file `%s' just disappeared - jcf_parse_source",
input_filename); input_filename);
parse_source_file (1); /* Parse only */ parse_source_file (1); /* Parse only */
if (current_class && TREE_TYPE (current_class))
CLASS_FROM_SOURCE_P (TREE_TYPE (current_class)) = 1;
fclose (finput);
java_parser_context_restore_global (); java_parser_context_restore_global ();
} }
...@@ -696,6 +680,12 @@ static void ...@@ -696,6 +680,12 @@ static void
parse_source_file (parse_only) parse_source_file (parse_only)
int parse_only; int parse_only;
{ {
int remember_for_generation;
tree filename = get_identifier (input_filename);
/* Mark the file as parsed */
HAS_BEEN_ALREADY_PARSED_P (filename) = 1;
lang_init_source (1); /* Error msgs have no method prototypes */ lang_init_source (1); /* Error msgs have no method prototypes */
java_push_parser_context (); java_push_parser_context ();
java_init_lex (); /* Initialize the parser */ java_init_lex (); /* Initialize the parser */
...@@ -710,45 +700,96 @@ parse_source_file (parse_only) ...@@ -710,45 +700,96 @@ parse_source_file (parse_only)
java_parse_abort_on_error (); java_parse_abort_on_error ();
java_layout_classes (); java_layout_classes ();
java_parse_abort_on_error (); java_parse_abort_on_error ();
if (!parse_only)
{
lang_init_source (2); /* Error msgs have method prototypes */
java_complete_expand_methods (); /* Complete and expand method bodies */
java_parse_abort_on_error ();
java_expand_finals (); /* Expand and check the finals */
java_parse_abort_on_error ();
java_check_final (); /* Check unitialized final */
java_parse_abort_on_error ();
if (! flag_emit_class_files)
emit_register_class ();
java_report_errors (); /* Final step for this file */
}
if (flag_emit_class_files) if (flag_emit_class_files)
write_classfile (current_class); write_classfile (current_class);
java_pop_parser_context ();
/* If only parsing, make sure that the currently parsed file isn't
also present in the argument list. If it's the case, remember
that we should generate it. */
remember_for_generation = !parse_only
|| IS_A_COMMAND_LINE_FILENAME_P (filename);
java_pop_parser_context (remember_for_generation);
} }
int int
yyparse () yyparse ()
{ {
/* Everything migh be enclosed within a loop processing each file after int several_files = 0;
the other one. */ char *list = strdup (input_filename), *next;
tree node, current_file_list = NULL_TREE;
switch (jcf_figure_file_type (current_jcf)) do
{ {
case JCF_ZIP: next = strchr (list, '&');
parse_zip_file_entries (); if (next)
emit_register_class (); {
break; *next++ = '\0';
case JCF_CLASS: several_files = 1;
jcf_parse (current_jcf); }
parse_class_file ();
emit_register_class (); if (list[0])
break; {
case JCF_SOURCE: char *value;
parse_source_file (0); /* Parse and generate */
break; if (*list != '/' && several_files)
obstack_grow (&temporary_obstack, "./", 2);
obstack_grow0 (&temporary_obstack, list, strlen (list));
value = obstack_finish (&temporary_obstack);
node = get_identifier (value);
IS_A_COMMAND_LINE_FILENAME_P (node) = 1;
current_file_list = tree_cons (NULL_TREE, node, current_file_list);
}
list = next;
}
while (next);
current_file_list = nreverse (current_file_list);
for (node = current_file_list; node; node = TREE_CHAIN (node))
{
/* Don't substitute if INPUT_FILENAME doesn't feature the &
separator: we have only one file to deal with, we're fine */
if (several_files)
{
tree name = TREE_VALUE (node);
/* Skip already parsed files */
if (HAS_BEEN_ALREADY_PARSED_P (name))
continue;
/* Close previous descriptor, if any */
if (main_jcf->read_state && fclose (main_jcf->read_state))
fatal ("failed to close input file `%s' - yyparse",
(main_jcf->filename ? main_jcf->filename : "<unknown>"));
/* Open new file */
main_jcf->read_state = fopen (IDENTIFIER_POINTER (name), "r");
if (main_jcf->read_state == NULL)
pfatal_with_name (IDENTIFIER_POINTER (name));
/* Set new input_filename and finput */
input_filename = IDENTIFIER_POINTER (name);
finput = main_jcf->read_state;
}
switch (jcf_figure_file_type (current_jcf))
{
case JCF_ZIP:
parse_zip_file_entries ();
emit_register_class ();
break;
case JCF_CLASS:
jcf_parse (current_jcf);
parse_class_file ();
emit_register_class ();
break;
case JCF_SOURCE:
parse_source_file (0); /* Parse and generate */
break;
}
} }
java_expand_classes ();
return 0; return 0;
} }
......
...@@ -720,6 +720,7 @@ tree java_get_catch_block PROTO ((tree, int)); ...@@ -720,6 +720,7 @@ tree java_get_catch_block PROTO ((tree, int));
/* Always in use, no matter what you compile */ /* Always in use, no matter what you compile */
void java_push_parser_context PROTO ((void)); void java_push_parser_context PROTO ((void));
void java_pop_parser_context PROTO ((int));
void java_init_lex PROTO ((void)); void java_init_lex PROTO ((void));
int yyparse PROTO ((void)); int yyparse PROTO ((void));
int yylex (); int yylex ();
......
...@@ -77,6 +77,9 @@ int java_warning_count; ...@@ -77,6 +77,9 @@ int java_warning_count;
/* The current parser context */ /* The current parser context */
static struct parser_ctxt *ctxp; static struct parser_ctxt *ctxp;
/* List of things that were anlyzed for which code will be generated */
static struct parser_ctxt *ctxp_for_generation = NULL;
/* binop_lookup maps token to tree_code. It is used where binary /* binop_lookup maps token to tree_code. It is used where binary
operations are involved and required by the parser. RDIV_EXPR operations are involved and required by the parser. RDIV_EXPR
covers both integral/floating point division. The code is changed covers both integral/floating point division. The code is changed
...@@ -2097,7 +2100,8 @@ java_parser_context_restore_global () ...@@ -2097,7 +2100,8 @@ java_parser_context_restore_global ()
} }
void void
java_pop_parser_context () java_pop_parser_context (generate)
int generate;
{ {
tree current; tree current;
struct parser_ctxt *toFree = ctxp; struct parser_ctxt *toFree = ctxp;
...@@ -2121,7 +2125,13 @@ java_pop_parser_context () ...@@ -2121,7 +2125,13 @@ java_pop_parser_context ()
for (current = ctxp->import_list; current; current = TREE_CHAIN (current)) for (current = ctxp->import_list; current; current = TREE_CHAIN (current))
IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (TREE_PURPOSE (current)) = 1; IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (TREE_PURPOSE (current)) = 1;
free (toFree); if (generate)
{
toFree->next = ctxp_for_generation;
ctxp_for_generation = toFree;
}
else
free (toFree);
} }
/* Reporting JDK1.1 features not implemented */ /* Reporting JDK1.1 features not implemented */
...@@ -2522,6 +2532,8 @@ maybe_create_class_interface_decl (decl, qualified_name, cl) ...@@ -2522,6 +2532,8 @@ maybe_create_class_interface_decl (decl, qualified_name, cl)
DECL_SOURCE_FILE (decl) = EXPR_WFL_FILENAME (cl); DECL_SOURCE_FILE (decl) = EXPR_WFL_FILENAME (cl);
DECL_SOURCE_LINE (decl) = EXPR_WFL_LINENO (cl); DECL_SOURCE_LINE (decl) = EXPR_WFL_LINENO (cl);
CLASS_FROM_SOURCE_P (TREE_TYPE (decl)) = 1; CLASS_FROM_SOURCE_P (TREE_TYPE (decl)) = 1;
CLASS_FROM_CURRENTLY_COMPILED_SOURCE_P (TREE_TYPE (decl)) =
IS_A_COMMAND_LINE_FILENAME_P (EXPR_WFL_FILENAME_NODE (cl));
ctxp->current_parsed_class = decl; ctxp->current_parsed_class = decl;
...@@ -4815,7 +4827,8 @@ java_complete_expand_methods () ...@@ -4815,7 +4827,8 @@ java_complete_expand_methods ()
{ {
make_class_data (current_class); make_class_data (current_class);
register_class (); register_class ();
rest_of_decl_compilation (TYPE_NAME (current_class), (char*) 0, 1, 0); rest_of_decl_compilation (TYPE_NAME (current_class),
(char*) 0, 1, 0);
} }
} }
} }
...@@ -4910,6 +4923,26 @@ java_expand_finals () ...@@ -4910,6 +4923,26 @@ java_expand_finals ()
{ {
} }
/* Generate code for all context remembered for code generation */
void
java_expand_classes ()
{
for (; ctxp_for_generation; ctxp_for_generation = ctxp_for_generation->next)
{
ctxp = ctxp_for_generation;
lang_init_source (2); /* Error msgs have method prototypes */
java_complete_expand_methods (); /* Complete and expand method bodies */
java_parse_abort_on_error ();
java_expand_finals (); /* Expand and check the finals */
java_parse_abort_on_error ();
java_check_final (); /* Check unitialized final */
java_parse_abort_on_error ();
}
if (! flag_emit_class_files)
emit_register_class ();
}
/* Wrap non WFL PRIMARY around a WFL and set EXPR_WFL_QUALIFICATION to /* Wrap non WFL PRIMARY around a WFL and set EXPR_WFL_QUALIFICATION to
a tree list node containing RIGHT. Fore coming RIGHTs will be a tree list node containing RIGHT. Fore coming RIGHTs will be
chained to this hook. LOCATION contains the location of the chained to this hook. LOCATION contains the location of the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment