From 93409b8c457d6b10875aff1931f57a099da88544 Mon Sep 17 00:00:00 2001 From: Per Bothner Date: Wed, 30 Jun 2004 11:23:35 -0700 Subject: [PATCH] Conditionally compile support for --enable-mapped_location. * decl.c (pop_label): Handle (imperfectly) USE_MAPPED_LOCATION case. * decl2.c: If USE_MAPPED_LOCATION, don't do some line number adjustments - which I don't understand. * error.c (dump_decl): Rename "" to "". * error.c: Use LOCATION_FILE and EXPR_LOCATION macros. (print_instantiation_partial_context): Use expand_location. * decl.c (duplicate_decl): Use new DECL_IS_BUILTIN macro. * name-lookup.c: Likewise. * lex.c (cxx_init): Likewise. Also use BUILTINS_LOCATION. * name-lookup.c: Use input_line macro. * parser.c (cp_lexer_get_preprocessor_token): Use UNKNOWN_LOCATION. (cp_parser_statement): Rename locaal variable statement_locus to statement_location and use SET_EXPR_LOCATION macro. * pt.c: Handle USE_MAPPED_LOCATION case. Use new macros. * tree.c (cp_walk_subtrees): Likewise. From-SVN: r83923 --- gcc/cp/ChangeLog | 19 +++++++++++++++++++ gcc/cp/decl.c | 6 +++++- gcc/cp/decl2.c | 12 ++++++++++++ gcc/cp/error.c | 24 ++++++++++++++---------- gcc/cp/lex.c | 6 +++++- gcc/cp/name-lookup.c | 10 +++++----- gcc/cp/parser.c | 12 ++++-------- gcc/cp/pt.c | 12 ++++++++---- gcc/cp/tree.c | 4 ++-- 9 files changed, 74 insertions(+), 31 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 26dedfc6886..8ff420081de 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,22 @@ +2004-06-30 Per Bothner + + Conditionally compile support for --enable-mapped_location. + * decl.c (pop_label): Handle (imperfectly) USE_MAPPED_LOCATION case. + * decl2.c: If USE_MAPPED_LOCATION, don't do some line number + adjustments - which I don't understand. + * error.c (dump_decl): Rename "" to "". + * error.c: Use LOCATION_FILE and EXPR_LOCATION macros. + (print_instantiation_partial_context): Use expand_location. + * decl.c (duplicate_decl): Use new DECL_IS_BUILTIN macro. + * name-lookup.c: Likewise. + * lex.c (cxx_init): Likewise. Also use BUILTINS_LOCATION. + * name-lookup.c: Use input_line macro. + * parser.c (cp_lexer_get_preprocessor_token): Use UNKNOWN_LOCATION. + (cp_parser_statement): Rename locaal variable statement_locus to + statement_location and use SET_EXPR_LOCATION macro. + * pt.c: Handle USE_MAPPED_LOCATION case. Use new macros. + * tree.c (cp_walk_subtrees): Likewise. + 2004-06-29 Per Bothner * tree.c (build_min_nt, build_min, build_min_non_dep): diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 11616c02dfc..dced875564a 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -363,8 +363,12 @@ pop_label (tree label, tree old_value) location_t location; cp_error_at ("label `%D' used but not defined", label); +#ifdef USE_MAPPED_LOCATION + location = input_location; /* FIXME want (input_filename, (line)0) */ +#else location.file = input_filename; location.line = 0; +#endif /* Avoid crashing later. */ define_label (location, DECL_NAME (label)); } @@ -1635,7 +1639,7 @@ duplicate_decls (tree newdecl, tree olddecl) TYPE_RAISES_EXCEPTIONS (oldtype)); if ((pedantic || ! DECL_IN_SYSTEM_HEADER (olddecl)) - && DECL_SOURCE_LINE (olddecl) != 0 + && ! DECL_IS_BUILTIN (olddecl) && flag_exceptions && !comp_except_specs (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)), TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl)), 1)) diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 2214e8d3656..f3ecc3e5dcc 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -2419,7 +2419,11 @@ generate_ctor_or_dtor_function (bool constructor_p, int priority, size_t i; input_location = *locus; +#ifdef USE_MAPPED_LOCATION + /* ??? */ +#else locus->line++; +#endif /* We use `I' to indicate initialization and `D' to indicate destruction. */ @@ -2556,9 +2560,13 @@ finish_file (void) if (pch_file) c_common_write_pch (); +#ifdef USE_MAPPED_LOCATION + /* FIXME - huh? */ +#else /* Otherwise, GDB can get confused, because in only knows about source for LINENO-1 lines. */ input_line -= 1; +#endif interface_unknown = 1; interface_only = 0; @@ -2714,7 +2722,11 @@ finish_file (void) instantiations, etc. */ reconsider = true; ssdf_count++; +#ifdef USE_MAPPED_LOCATION + /* ??? */ +#else locus.line++; +#endif } for (i = 0; i < deferred_fns_used; ++i) diff --git a/gcc/cp/error.c b/gcc/cp/error.c index 2c34e667838..e345793f3c7 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -835,7 +835,7 @@ dump_decl (tree t, int flags) if (DECL_GLOBAL_CTOR_P (t) || DECL_GLOBAL_DTOR_P (t)) dump_global_iord (t); else if (! DECL_LANG_SPECIFIC (t)) - pp_identifier (cxx_pp, ""); + pp_identifier (cxx_pp, ""); else dump_function_decl (t, flags); break; @@ -2145,9 +2145,8 @@ cp_print_error_function (diagnostic_context *context, if (diagnostic_last_function_changed (context)) { const char *old_prefix = context->printer->prefix; - char *new_prefix = diagnostic->location.file - ? file_name_as_prefix (diagnostic->location.file) - : NULL; + const char *file = LOCATION_FILE (diagnostic->location); + char *new_prefix = file ? file_name_as_prefix (file) : NULL; pp_base_set_prefix (context->printer, new_prefix); @@ -2208,11 +2207,12 @@ print_instantiation_full_context (diagnostic_context *context) /* Avoid redundancy with the the "In function" line. */; else pp_verbatim (context->printer, - "%s: In instantiation of `%s':\n", location.file, + "%s: In instantiation of `%s':\n", + LOCATION_FILE (location), decl_as_string (TINST_DECL (p), TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE)); - location = *EXPR_LOCUS (p); + location = EXPR_LOCATION (p); p = TREE_CHAIN (p); } } @@ -2225,16 +2225,20 @@ static void print_instantiation_partial_context (diagnostic_context *context, tree t, location_t loc) { - for (; t; t = TREE_CHAIN (t)) + expanded_location xloc; + for (; ; t = TREE_CHAIN (t)) { + xloc = expand_location (loc); + if (t == NULL_TREE) + break; pp_verbatim (context->printer, "%s:%d: instantiated from `%s'\n", - loc.file, loc.line, + xloc.file, xloc.line, decl_as_string (TINST_DECL (t), TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE)); - loc = *EXPR_LOCUS (t); + loc = EXPR_LOCATION (t); } pp_verbatim (context->printer, "%s:%d: instantiated from here\n", - loc.file, loc.line); + xloc.file, xloc.line); } /* Called from cp_thing to print the template context for an error. */ diff --git a/gcc/cp/lex.c b/gcc/cp/lex.c index 1daa1fc6ec9..f47aa931ce5 100644 --- a/gcc/cp/lex.c +++ b/gcc/cp/lex.c @@ -336,7 +336,11 @@ cxx_init (void) /* We cannot just assign to input_filename because it has already been initialized and will be used later as an N_BINCL for stabs+ debugging. */ - push_srcloc ("", 0); +#ifdef USE_MAPPED_LOCATION + push_srcloc (BUILTINS_LOCATION); +#else + push_srcloc ("", 0); +#endif init_reswords (); init_tree (); diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index b650d7443d1..899a2ead9f4 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -781,7 +781,7 @@ pushdecl (tree x) if (TREE_CODE (x) == TYPE_DECL) { tree type = TREE_TYPE (x); - if (DECL_SOURCE_LINE (x) == 0) + if (DECL_IS_BUILTIN (x)) { if (TYPE_NAME (type) == 0) TYPE_NAME (type) = x; @@ -1328,7 +1328,7 @@ begin_scope (scope_kind kind, tree entity) { scope->binding_depth = binding_depth; indent (binding_depth); - cxx_scope_debug (scope, input_location.line, "push"); + cxx_scope_debug (scope, input_line, "push"); is_class_level = 0; binding_depth++; } @@ -1354,7 +1354,7 @@ leave_scope (void) if (ENABLE_SCOPE_CHECKING) { indent (--binding_depth); - cxx_scope_debug (scope, input_location.line, "leave"); + cxx_scope_debug (scope, input_line, "leave"); if (is_class_level != (scope == class_binding_level)) { indent (binding_depth); @@ -1407,7 +1407,7 @@ resume_scope (struct cp_binding_level* b) { b->binding_depth = binding_depth; indent (binding_depth); - cxx_scope_debug (b, input_location.line, "resume"); + cxx_scope_debug (b, input_line, "resume"); is_class_level = 0; binding_depth++; } @@ -1600,7 +1600,7 @@ print_binding_level (struct cp_binding_level* lvl) continue; if (no_print_builtins && (TREE_CODE (t) == TYPE_DECL) - && (!strcmp (DECL_SOURCE_FILE (t),""))) + && DECL_IS_BUILTIN (t)) continue; /* Function decls tend to have longer names. */ diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index ca2b0a995d2..e3b97369cfd 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -597,8 +597,7 @@ cp_lexer_get_preprocessor_token (cp_lexer *lexer ATTRIBUTE_UNUSED , if (lexer != NULL && !lexer->main_lexer_p) { token->type = CPP_EOF; - token->location.line = 0; - token->location.file = NULL; + token->location = UNKNOWN_LOCATION; token->value = NULL_TREE; token->keyword = RID_MAX; @@ -5890,14 +5889,14 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr) { tree statement; cp_token *token; - location_t statement_locus; + location_t statement_location; /* There is no statement yet. */ statement = NULL_TREE; /* Peek at the next token. */ token = cp_lexer_peek_token (parser->lexer); /* Remember the location of the first token in the statement. */ - statement_locus = token->location; + statement_location = token->location; /* If this is a keyword, then that will often determine what kind of statement we have. */ if (token->type == CPP_KEYWORD) @@ -5973,10 +5972,7 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr) /* Set the line number for the statement. */ if (statement && STATEMENT_CODE_P (TREE_CODE (statement))) - { - SET_EXPR_LOCUS (statement, NULL); - annotate_with_locus (statement, statement_locus); - } + SET_EXPR_LOCATION (statement, statement_location); } /* Parse a labeled-statement. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index a1142f3b358..e7a598bc38b 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -4871,7 +4871,7 @@ push_tinst_level (tree d) } new = make_node (TINST_LEVEL); - annotate_with_locus (new, input_location); + SET_EXPR_LOCATION (new, input_location); TINST_DECL (new) = d; TREE_CHAIN (new) = current_tinst_level; current_tinst_level = new; @@ -4896,7 +4896,7 @@ pop_tinst_level (void) /* Restore the filename and line number stashed away when we started this instantiation. */ - input_location = *EXPR_LOCUS (old); + input_location = EXPR_LOCATION (old); extract_interface_info (); current_tinst_level = TREE_CHAIN (old); @@ -6930,8 +6930,12 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) message to avoid spewing a ton of messages during a single bad template instantiation. */ if (complain & tf_error +#ifdef USE_MAPPED_LOCATION + && last_loc != input_location) +#else && (last_loc.line != input_line || last_loc.file != input_filename)) +#endif { if (TREE_CODE (type) == VOID_TYPE) error ("forming reference to void"); @@ -7713,8 +7717,8 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl) if (t == NULL_TREE || t == error_mark_node) return t; - if (EXPR_LOCUS (t)) - input_location = *EXPR_LOCUS (t); + if (EXPR_HAS_LOCATION (t)) + input_location = EXPR_LOCATION (t); if (STATEMENT_CODE_P (TREE_CODE (t))) current_stmt_tree ()->stmts_are_full_exprs_p = STMT_IS_FULL_EXPR_P (t); diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 35712d10a2d..fb08095f94c 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -1973,8 +1973,8 @@ cp_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func, /* Set input_location here so we get the right instantiation context if we call instantiate_decl from inlinable_function_p. */ save_locus = input_location; - if (EXPR_LOCUS (*tp)) - input_location = *EXPR_LOCUS (*tp); + if (EXPR_HAS_LOCATION (*tp)) + input_location = EXPR_LOCATION (*tp); /* Not one of the easy cases. We must explicitly go through the children. */ -- 2.30.2