Makefile.in (error.o): Depends on diagnostic.h

* Makefile.in (error.o): Depends on diagnostic.h

	* cp-tree.h (problematic_instantiation_changed,
	record_last_problematic_instantiation, current_instantiation,
	print_instantiation_context): Declare.
	(maybe_print_template_context): Remove.

	* decl.c (init_decl_processing): Set print_error_function to NULL.
	(lang_print_error_function): Remove, since we're using a new
	machinery.

	* error.c: #include diagnostic.h
	(function_category): New function.
	(cp_diagnostic_starter): Likewise.
	(cp_diagnostic_finalizer): Likewise.
	(cp_print_error_function): Likewise.
	(maybe_print_instantiation_context): Likewise.
	(print_instantiation_full_context): Likewise.
	(print_instantiation_partial_context): Likewise.
	(print_instantiation_context): Define.
	(init_error): Initialize diagnostic pager and finalizer.

	* pt.c (problematic_instantiation_changed): Define.
	(record_last_problematic_instantiation): Likewise.
	(current_instantiation): Likewise.
	(maybe_print_template_context): Remove.
	(print_template_context): Likewise.
	(current_tinst_level): Make static to reflect Brendan Kehoe's
	change of 1995-04-13.
	(push_tinst_level): Call print_instantiation_context.

From-SVN: r35893
This commit is contained in:
Gabriel Dos Reis 2000-08-22 20:26:41 +00:00 committed by Gabriel Dos Reis
parent 1eb994b78b
commit cb753e4921
6 changed files with 232 additions and 77 deletions

View File

@ -1,3 +1,37 @@
2000-08-22 Gabriel Dos Reis <gdr@codesourcery.com>
* Makefile.in (error.o): Depends on diagnostic.h
* cp-tree.h (problematic_instantiation_changed,
record_last_problematic_instantiation, current_instantiation,
print_instantiation_context): Declare.
(maybe_print_template_context): Remove.
* decl.c (init_decl_processing): Set print_error_function to NULL.
(lang_print_error_function): Remove, since we're using a new
machinery.
* error.c: #include diagnostic.h
(function_category): New function.
(cp_diagnostic_starter): Likewise.
(cp_diagnostic_finalizer): Likewise.
(cp_print_error_function): Likewise.
(maybe_print_instantiation_context): Likewise.
(print_instantiation_full_context): Likewise.
(print_instantiation_partial_context): Likewise.
(print_instantiation_context): Define.
(init_error): Initialize diagnostic pager and finalizer.
* pt.c (problematic_instantiation_changed): Define.
(record_last_problematic_instantiation): Likewise.
(current_instantiation): Likewise.
(maybe_print_template_context): Remove.
(print_template_context): Likewise.
(current_tinst_level): Make static to reflect Brendan Kehoe's
change of 1995-04-13.
(push_tinst_level): Call print_instantiation_context.
2000-08-21 Nix <nix@esperi.demon.co.uk>
* lang-specs.h: Do not process -o or run the assembler if

View File

@ -301,7 +301,7 @@ pt.o : pt.c $(CXX_TREE_H) decl.h $(PARSE_H) lex.h \
$(srcdir)/../toplev.h $(GGC_H) $(RTL_H) \
$(srcdir)/../except.h $(HTAB_H)
error.o : error.c $(CXX_TREE_H) \
$(srcdir)/../toplev.h
$(srcdir)/../toplev.h $(srcdir)/../diagnostic.h
errfn.o : errfn.c $(CXX_TREE_H) \
$(srcdir)/../toplev.h
repo.o : repo.c $(CXX_TREE_H) \

View File

@ -3322,8 +3322,6 @@ typedef enum unification_kind_t {
#define TINST_LINE(NODE) EXPR_WFL_LINENO (NODE)
#define TINST_FILE(NODE) EXPR_WFL_FILENAME (NODE)
extern void maybe_print_template_context PARAMS ((void));
/* in class.c */
extern int current_class_depth;
@ -4112,6 +4110,7 @@ extern const char *lang_decl_name PARAMS ((tree, int));
extern const char *cp_file_of PARAMS ((tree));
extern int cp_line_of PARAMS ((tree));
extern const char *language_to_string PARAMS ((enum languages, int));
extern void print_instantiation_context PARAMS ((void));
/* in except.c */
extern void init_exception_processing PARAMS ((void));
@ -4295,6 +4294,9 @@ extern int instantiate_pending_templates PARAMS ((void));
extern tree tsubst_default_argument PARAMS ((tree, tree, tree));
extern tree most_general_template PARAMS ((tree));
extern tree get_mostly_instantiated_function_type PARAMS ((tree, tree *, tree *));
extern int problematic_instantiation_changed PARAMS ((void));
extern void record_last_problematic_instantiation PARAMS ((void));
extern tree current_instantiation PARAMS ((void));
extern int processing_template_parmlist;
/* in repo.c */

View File

@ -129,7 +129,6 @@ static tree build_library_fn_1 PARAMS ((tree, enum tree_code, tree));
static int member_function_or_else PARAMS ((tree, tree, enum overload_flags));
static void bad_specifiers PARAMS ((tree, const char *, int, int, int, int,
int));
static void lang_print_error_function PARAMS ((const char *));
static tree maybe_process_template_type_declaration PARAMS ((tree, int, struct binding_level*));
static void check_for_uninitialized_const_var PARAMS ((tree));
static unsigned long typename_hash PARAMS ((hash_table_key));
@ -6652,7 +6651,7 @@ init_decl_processing ()
/* Show we use EH for cleanups. */
using_eh_for_cleanups ();
print_error_function = lang_print_error_function;
print_error_function = NULL;
valid_lang_attribute = cp_valid_lang_attribute;
/* Maintain consistency. Perhaps we should just complain if they
@ -6746,16 +6745,6 @@ cp_make_fname_decl (id, name, type_dep)
return decl;
}
/* Function to print any language-specific context for an error message. */
static void
lang_print_error_function (file)
const char *file;
{
default_print_error_function (file);
maybe_print_template_context ();
}
/* Entry point for the benefit of c_common_nodes_and_builtins.
Make a definition for a builtin function named NAME and whose data type

View File

@ -25,6 +25,7 @@ Boston, MA 02111-1307, USA. */
#include "cp-tree.h"
#include "obstack.h"
#include "toplev.h"
#include "diagnostic.h"
typedef const char *cp_printer ();
@ -95,6 +96,19 @@ static void dump_template_bindings PARAMS ((tree, tree));
static void dump_scope PARAMS ((tree, enum tree_string_flags));
static void dump_template_parms PARAMS ((tree, int, enum tree_string_flags));
static const char *function_category PARAMS ((tree));
static void maybe_print_instantiation_context PARAMS ((output_buffer *));
static void print_instantiation_full_context PARAMS ((output_buffer *));
static void print_instantiation_partial_context PARAMS ((output_buffer *, tree,
const char *, int));
static void cp_diagnostic_starter PARAMS ((output_buffer *,
diagnostic_context *));
static void cp_diagnostic_finalizer PARAMS ((output_buffer *,
diagnostic_context *));
static void cp_print_error_function PARAMS ((output_buffer *,
diagnostic_context *));
#define A args_to_string
#define C code_to_string
#define D decl_to_string
@ -137,6 +151,9 @@ init_error ()
{
gcc_obstack_init (&scratch_obstack);
scratch_firstobj = (char *)obstack_alloc (&scratch_obstack, 0);
lang_diagnostic_starter = cp_diagnostic_starter;
lang_diagnostic_finalizer = cp_diagnostic_finalizer;
}
/* Dump a scope, if deemed necessary. */
@ -2413,3 +2430,155 @@ cv_to_string (p, v)
return (char *)obstack_base (&scratch_obstack);
}
static void
cp_diagnostic_starter (buffer, dc)
output_buffer *buffer;
diagnostic_context *dc;
{
report_problematic_module (buffer);
cp_print_error_function (buffer, dc);
maybe_print_instantiation_context (buffer);
output_set_prefix (buffer,
context_as_prefix (diagnostic_file_location (dc),
diagnostic_line_location (dc),
diagnostic_is_warning (dc)));
}
static void
cp_diagnostic_finalizer (buffer, dc)
output_buffer *buffer;
diagnostic_context *dc __attribute__ ((__unused__));
{
output_destroy_prefix (buffer);
}
/* Print current function onto BUFFER, in the process of reporting
a diagnostic message. Called from cp_diagnostic_starter. */
static void
cp_print_error_function (buffer, dc)
output_buffer *buffer;
diagnostic_context *dc;
{
if (error_function_changed ())
{
char *prefix = diagnostic_file_location (dc)
? file_name_as_prefix (diagnostic_file_location (dc))
: NULL;
output_state os;
os = output_buffer_state (buffer);
output_set_prefix (buffer, prefix);
if (current_function_decl == NULL)
{
output_add_string (buffer, "At global scope:");
output_add_newline (buffer);
}
else
output_printf
(buffer, "In %s `%s':\n", function_category (current_function_decl),
(*decl_printable_name) (current_function_decl, 2));
record_last_error_function ();
output_destroy_prefix (buffer);
output_buffer_state (buffer) = os;
}
}
/* Returns a description of FUNCTION using standard terminology. */
static const char *
function_category (fn)
tree fn;
{
if (DECL_FUNCTION_MEMBER_P (fn))
{
if (DECL_STATIC_FUNCTION_P (fn))
return "static member function";
else if (DECL_COPY_CONSTRUCTOR_P (fn))
return "copy constructor";
else if (DECL_CONSTRUCTOR_P (fn))
return "constructor";
else if (DECL_DESTRUCTOR_P (fn))
return "destructor";
else
return "member function";
}
else
return "function";
}
/* Report the full context of a current template instantiation,
onto BUFFER. */
static void
print_instantiation_full_context (buffer)
output_buffer *buffer;
{
tree p = current_instantiation ();
int line = lineno;
const char *file = input_filename;
if (p)
{
if (current_function_decl != TINST_DECL (p)
&& current_function_decl != NULL_TREE)
/* We can get here during the processing of some synthesized
method. Then, TINST_DECL (p) will be the function that's causing
the synthesis. */
;
else
{
if (current_function_decl == TINST_DECL (p))
/* Avoid redundancy with the the "In function" line. */;
else
output_verbatim (buffer, "%s: In instantiation of `%s':\n", file,
decl_as_string (TINST_DECL (p),
TS_DECL_TYPE | TS_FUNC_NORETURN));
line = TINST_LINE (p);
file = TINST_FILE (p);
p = TREE_CHAIN (p);
}
}
print_instantiation_partial_context (buffer, p, file, line);
}
/* Same as above but less verbose. */
static void
print_instantiation_partial_context (buffer, t, file, line)
output_buffer *buffer;
tree t;
const char *file;
int line;
{
for (; t; t = TREE_CHAIN (t))
{
output_verbatim
(buffer, "%s:%d: instantiated from `%s'\n", file, line,
decl_as_string (TINST_DECL (t), TS_DECL_TYPE | TS_FUNC_NORETURN));
line = TINST_LINE (t);
file = TINST_FILE (t);
}
output_verbatim (buffer, "%s:%d: instantiated from here\n", file, line);
}
/* Called from cp_thing to print the template context for an error. */
static void
maybe_print_instantiation_context (buffer)
output_buffer *buffer;
{
if (!problematic_instantiation_changed () || current_instantiation () == 0)
return;
record_last_problematic_instantiation ();
print_instantiation_full_context (buffer);
}
/* Report the bare minimum context of a template instantiation. */
void
print_instantiation_context ()
{
print_instantiation_partial_context
(diagnostic_buffer, current_instantiation (), input_filename, lineno);
}

View File

@ -72,7 +72,7 @@ static tree saved_trees;
static varray_type inline_parm_levels;
static size_t inline_parm_levels_used;
tree current_tinst_level;
static tree current_tinst_level;
/* A map from local variable declarations in the body of the template
presently being instantiated to the corresponding instantiated
@ -163,7 +163,6 @@ static int coerce_template_template_parms PARAMS ((tree, tree, int,
tree, tree));
static tree determine_specialization PARAMS ((tree, tree, tree *, int));
static int template_args_equal PARAMS ((tree, tree));
static void print_template_context PARAMS ((int));
static void tsubst_default_arguments PARAMS ((tree));
static tree for_each_template_parm_r PARAMS ((tree *, int *, void *));
static tree instantiate_clone PARAMS ((tree, tree));
@ -4297,65 +4296,6 @@ int depth_reached;
static int tinst_level_tick;
static int last_template_error_tick;
/* Print out all the template instantiations that we are currently
working on. If ERR, we are being called from cp_thing, so do
the right thing for an error message. */
static void
print_template_context (err)
int err;
{
tree p = current_tinst_level;
int line = lineno;
const char *file = input_filename;
if (err && p)
{
if (current_function_decl != TINST_DECL (p)
&& current_function_decl != NULL_TREE)
/* We can get here during the processing of some synthesized
method. Then, TINST_DECL (p) will be the function that's causing
the synthesis. */
;
else
{
if (current_function_decl == TINST_DECL (p))
/* Avoid redundancy with the the "In function" line. */;
else
fprintf (stderr, "%s: In instantiation of `%s':\n",
file, decl_as_string (TINST_DECL (p),
TS_DECL_TYPE | TS_FUNC_NORETURN));
line = TINST_LINE (p);
file = TINST_FILE (p);
p = TREE_CHAIN (p);
}
}
for (; p; p = TREE_CHAIN (p))
{
fprintf (stderr, "%s:%d: instantiated from `%s'\n", file, line,
decl_as_string (TINST_DECL (p),
TS_DECL_TYPE | TS_FUNC_NORETURN));
line = TINST_LINE (p);
file = TINST_FILE (p);
}
fprintf (stderr, "%s:%d: instantiated from here\n", file, line);
}
/* Called from cp_thing to print the template context for an error. */
void
maybe_print_template_context ()
{
if (last_template_error_tick == tinst_level_tick
|| current_tinst_level == 0)
return;
last_template_error_tick = tinst_level_tick;
print_template_context (1);
}
/* We're starting to instantiate D; record the template instantiation context
for diagnostics and to restore it later. */
@ -4377,7 +4317,7 @@ push_tinst_level (d)
cp_error ("template instantiation depth exceeds maximum of %d (use -ftemplate-depth-NN to increase the maximum) instantiating `%D'",
max_tinst_depth, d);
print_template_context (0);
print_instantiation_context ();
return 0;
}
@ -10155,3 +10095,24 @@ set_mangled_name_for_template_decl (decl)
DECL_FUNCTION_MEMBER_P (decl)
+ DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl));
}
/* Return truthvalue if we're processing a template different from
the last one involved in diagnotics. */
int
problematic_instantiation_changed ()
{
return last_template_error_tick != tinst_level_tick;
}
/* Remember current template involved in diagnostics. */
void
record_last_problematic_instantiation ()
{
last_template_error_tick = tinst_level_tick;
}
tree
current_instantiation ()
{
return current_tinst_level;
}