diff options
author | Per Bothner <per@bothner.com> | 2004-09-30 16:35:07 -0700 |
---|---|---|
committer | Per Bothner <bothner@gcc.gnu.org> | 2004-09-30 16:35:07 -0700 |
commit | 9ec819d49ca815551b3fd8cd4e1202e898bac8d5 (patch) | |
tree | d3e8024e8ba3df366d03490e5511ea3378e8ed60 /gcc/java/jcf-parse.c | |
parent | cb3a14307a07a4f9d719f229caff8c47aed42624 (diff) | |
download | gcc-9ec819d49ca815551b3fd8cd4e1202e898bac8d5.zip gcc-9ec819d49ca815551b3fd8cd4e1202e898bac8d5.tar.gz gcc-9ec819d49ca815551b3fd8cd4e1202e898bac8d5.tar.bz2 |
Simplify lexer. Implement --enable-mapped-location support.
* jcf-parse.c (parse_class_file): Use linemap_line_start.
(parse_source_file_1): Pass filename as extra parameter, so we can call
linemap_add and set input_location here, rather than in both callers.
(read_class): Pass copied filename to parse_source_file_1.
Don't initialize wfl_operator - only needed for source compilation.
(read_class, jcf_parse): Call linemap_add with LC_LEAVE.
* lex.h: Remove a bunch of debugging macros.
* lex.h (struct_java_line, struct java_error): Remove types.
(JAVA_COLUMN_DELTA): Remove - use java_lexer.next_colums instead.
(struct java_lc_s): Remove prev_col field.
(struct java_lexer): New fields next_unicode, next_columns, and
avail_unicode. New position field, and maybe token_start field.
Don't need hit_eof field - use next_unicode == -1 instead.
(JAVA_INTEGERAL_RANGE_ERROR): Rename to JAVA_RANGE_ERROR.
(JAVA_RANGE_ERROR, JAVA_FLOAT_ANGE_ERROR): Update accordingly.
* parse.h: Various changes for USE_MAPPED_LOCATION.
(EXPR_WFL_EMIT_LINE_NOTE): XXX
(BUILD_EXPR_WFL, EXPR_WFL_ADD_COL): Remove no-longer-used macros.
(struct parser_ctxt): New file_start_location field.
Remove p_line, c_line fields since we no longer save lines.
Remove elc, lineno, and current_jcf fields - no longer used.
* parse.y: Updates for USE_MAPPED_LOCATION and new lexer.
Don't use EXPR_WFL_ADD_COL since that isn't trivial with
source_location and is probably not needed anymore anyway.
Use new expr_add_Location function.
(SET_EXPR_LOCATION_FROM_TOKEN): New convenience macro.
(java_pop_parser_context): Minor cleanup.
(java_parser_context_save_global, java_parser_context_restore_global,
java_pop_parser_context): Save/restore input_location as a unit.
(issue_warning_error_from_context): If USE_MAPPED_LOCATION take
a source_location instead of a wfl context node.
(check_class_interface_creation): input_filename is not addressable.
(create_artificial_method): Calling java_parser_context_save_global
and java_parser_context_restore_global is overkill. Instead,
temporarily set input_location from class decl.
(java_layout_seen_class_methods): Set input_location from method decl.
(fix_constructors): Make more robust if no EXPR_WITH_FILE_LOCATION.
(finish_loop_body): Likewise.
* lex.c: Updates for USE_MAPPED_LOCATION. Use build_unknwon_wfl.
(java_sprint_unicode): Take a character, not index in line.
(java_sneak_uncode): Replaced by java_peek_unicode.
(java_unget_unicode): No longer used.
(java_allocate_new_line. java_store_unicode): Removed, since we
no longer remember "lines".
(java_new_lexer): Update for new data structures.
(java_read_char): Move unget_value checking to java_read_unicode.
(java_get_unicode, java_peek_unicode, java_next_unicode): New more
efficient functions that are used directly when lexing.
(java_read_unicode_collapsing_terminators): No longer needed.
(java_parse_end_comment, java_parse_escape_sequence, do_java_lex):
Re-organize to use java_peek_unicode to avoid java_unget_unicode.
(java_parse_escape_sequence): Rewrite to be simpler / more efficient.
(do_java_lex): Lots of movings around to avoid java_unget_unicode,
combine switch branches, and test for common token kinds earlier.
(java_lex_error): Rewrite.
* jv-scan.c (expand_location): New function, copied from tree.c.
(main): Set ctxp->filename instead of setting input_filename directly.
From-SVN: r88367
Diffstat (limited to 'gcc/java/jcf-parse.c')
-rw-r--r-- | gcc/java/jcf-parse.c | 64 |
1 files changed, 44 insertions, 20 deletions
diff --git a/gcc/java/jcf-parse.c b/gcc/java/jcf-parse.c index 031cedc..74f45de 100644 --- a/gcc/java/jcf-parse.c +++ b/gcc/java/jcf-parse.c @@ -98,7 +98,7 @@ static char *compute_class_name (struct ZipDirectory *zdir); static int classify_zip_file (struct ZipDirectory *zdir); static void parse_zip_file_entries (void); static void process_zip_dir (FILE *); -static void parse_source_file_1 (tree, FILE *); +static void parse_source_file_1 (tree, const char *, FILE *); static void parse_source_file_2 (void); static void parse_source_file_3 (void); static void parse_class_file (void); @@ -544,27 +544,27 @@ read_class (tree name) java_push_parser_context (); given_file = get_identifier (filename); + filename = IDENTIFIER_POINTER (given_file); real_file = get_identifier (lrealpath (filename)); generate = IS_A_COMMAND_LINE_FILENAME_P (given_file); - if (wfl_operator == NULL_TREE) - wfl_operator = build_expr_wfl (NULL_TREE, NULL, 0, 0); - EXPR_WFL_FILENAME_NODE (wfl_operator) = given_file; - input_filename = ggc_strdup (filename); output_class = current_class = NULL_TREE; current_function_decl = NULL_TREE; if (! HAS_BEEN_ALREADY_PARSED_P (real_file)) { - if (! (finput = fopen (input_filename, "r"))) - fatal_error ("can't reopen %s: %m", input_filename); + if (! (finput = fopen (filename, "r"))) + fatal_error ("can't reopen %s: %m", filename); - parse_source_file_1 (real_file, finput); + parse_source_file_1 (real_file, filename, finput); parse_source_file_2 (); parse_source_file_3 (); if (fclose (finput)) fatal_error ("can't close %s: %m", input_filename); +#ifdef USE_MAPPED_LOCATION + linemap_add (&line_table, LC_LEAVE, false, NULL, 0); +#endif } JCF_FINISH (current_jcf); java_pop_parser_context (generate); @@ -577,7 +577,7 @@ read_class (tree name) java_parser_context_save_global (); java_push_parser_context (); output_class = current_class = class; - input_filename = current_jcf->filename; + ctxp->save_location = input_location; if (JCF_SEEN_IN_ZIP (current_jcf)) read_zip_member(current_jcf, current_jcf->zipd, current_jcf->zipd->zipf); @@ -710,6 +710,9 @@ jcf_parse (JCF* jcf) code = jcf_parse_final_attributes (jcf); if (code != 0) fatal_error ("error while parsing final attributes"); +#ifdef USE_MAPPED_LOCATION + linemap_add (&line_table, LC_LEAVE, false, NULL, 0); +#endif /* The fields of class_type_node are already in correct order. */ if (current_class != class_type_node && current_class != object_type_node) @@ -804,10 +807,11 @@ parse_class_file (void) continue; } - input_line = 0; + input_location = file_start_location; if (DECL_LINENUMBERS_OFFSET (method)) { int i; + int min_line = 0; unsigned char *ptr; JCF_SEEK (jcf, DECL_LINENUMBERS_OFFSET (method)); linenumber_count = i = JCF_readu2 (jcf); @@ -818,9 +822,16 @@ parse_class_file (void) int line = GET_u2 (ptr); /* Set initial input_line to smallest linenumber. * Needs to be set before init_function_start. */ - if (input_line == 0 || line < input_line) - input_line = line; - } + if (min_line == 0 || line < min_line) + min_line = line; + } +#ifdef USE_MAPPED_LOCATION + if (min_line != 0) + input_location = linemap_line_start (&line_table, min_line, 1); +#else + if (min_line != 0) + input_line = min_line; +#endif } else { @@ -845,22 +856,20 @@ parse_class_file (void) finish_class (); - (*debug_hooks->end_source_file) (save_location.line); + (*debug_hooks->end_source_file) (LOCATION_LINE (save_location)); input_location = save_location; } /* Parse a source file, as pointed by the current value of INPUT_FILENAME. */ static void -parse_source_file_1 (tree real_file, FILE *finput) +parse_source_file_1 (tree real_file, const char *filename, FILE *finput) { int save_error_count = java_error_count; /* Mark the file as parsed. */ HAS_BEEN_ALREADY_PARSED_P (real_file) = 1; - jcf_dependency_add_file (input_filename, 0); - lang_init_source (1); /* Error msgs have no method prototypes */ /* There's no point in trying to find the current encoding unless we @@ -874,6 +883,18 @@ parse_source_file_1 (tree real_file, FILE *finput) if (current_encoding == NULL || *current_encoding == '\0') current_encoding = DEFAULT_ENCODING; +#ifdef USE_MAPPED_LOCATION + linemap_add (&line_table, LC_ENTER, false, filename, 0); + input_location = linemap_line_start (&line_table, 0, 125); +#else + input_filename = filename; + input_line = 0; +#endif + ctxp->file_start_location = input_location; + ctxp->filename = filename; + + jcf_dependency_add_file (input_filename, 0); + /* Initialize the parser */ java_init_lex (finput, current_encoding); java_parse_abort_on_error (); @@ -1147,21 +1168,24 @@ java_parse_file (int set_yydebug ATTRIBUTE_UNUSED) java_push_parser_context (); java_parser_context_save_global (); - parse_source_file_1 (real_file, finput); + parse_source_file_1 (real_file, filename, finput); java_parser_context_restore_global (); java_pop_parser_context (1); +#ifdef USE_MAPPED_LOCATION + linemap_add (&line_table, LC_LEAVE, false, NULL, 0); +#endif } } for (ctxp = ctxp_for_generation; ctxp; ctxp = ctxp->next) { - input_filename = ctxp->filename; + input_location = ctxp->file_start_location; parse_source_file_2 (); } for (ctxp = ctxp_for_generation; ctxp; ctxp = ctxp->next) { - input_filename = ctxp->filename; + input_location = ctxp->file_start_location; parse_source_file_3 (); } |