8sa1-gcc/gcc/cp/errfn.c
Mark Mitchell 8f0327178b tinfo.h (__class_type_info): Fix illegal declaration.
1999-04-02  Mark Mitchell  <mark@codesourcery.com>
	* tinfo.h (__class_type_info): Fix illegal declaration.
	* cp-tree.def (TEMPLATE_ID_EXPR): Update comment.
	* cp-tree.h (INHERITED_VALUE_BINDING_P): New macro.
	(IDENTIFIER_CLASS_VALUE): Improve documentation.
	(is_properly_derived_from): Declare.
	(invalidate_class_lookup_cache): Likewise.
	(maybe_maybe_note_name_used_in_class): Likewise.
	(note_name_declared_in_class): Likewise.
	(push_using_decl): Remove duplicate declaration.
	(id_in_current_class): Remove declaration.
	(push_class_binding): Change prototype.
	(clear_identitifer_class_values): Declare.
	* call.c (is_properly_derived_from): Make it global.
	(build_new_function_call): Be careful about updating candidates.
	(build_new_method_call): Handle COMPONENT_REFs.  Don't crash when
	asked to make illegal calls.
	* class.c: Include splay-tree.h.
	(class_stack_node): Add names_used slot.
	(check_member_decl_is_same_in_complete_scope): Remove.
	(add_method): Fix comment.  Push the declaration into class
	scope.
	(finish_struct_1): When popping the class, pop the bindings too.
	Remove check for data member/function member conflict.
	(finish_struct): Remove calls to
	check_member_decl_is_same_in_complete_scope.  Change calls to
	popclass.
	(pushclass): Clear names_used in the class stack entry.
	Use invalidate_class_lookup_cache to remove cached entries, rather
	than magic values with popclass.  Clear IDENTIFIER_CLASS_VALUE
	before entering a new class.  Remove dead code.  Don't mess with
	current_function_decl when pushing declarations.
	(invalidate_class_lookup_cache): New function, split out from ...
	(popclass): Here.  Clean up names_used on our way out.
	(instantiate_type): Adjust.
	(build_self_reference): Don't push the declaration here.
	(maybe_note_name_used_in_class): New function.
	(note_name_declared_in_class): Likewise.
	* decl.c (add_binding): Change prototype.
	(find_class_binding_level): New function.
	(innermost_nonclass_level): Likewise.
	(current_binding_level): Update documentation.
	(inner_binding_level): Remove.  Replace with current_binding_level
	throughout.
	(push_binding_level): Remove special handling of
	class_binding_level.
	(pop_binding_level): Likewise.  Use find_class_binding_level.
	(suspend_binding_level): Likewise.
	(global_bindings_p): Use innermost_nonclass_level.
	(toplevel_bindings_p): Likewise.
	(namespace_bindings_p): Likewise.
	(pseudo_global_level_p): Likewise.
	(push_binding): Clear INHERITED_VALUE_BINDING_P.
	(add_binding): Check for illegal multiple declarations.  Return a
	value indicating whether or not the new binding was legal.
	(push_local_binding): Skip over class binding levels.  Check
	return value from add_binding.
	(push_class_binding): Set INHERITED_VALUE_BINDING_P.  Call
	note_name_declared_in_class.
	(pushlevel_class): Remove "fake out the rest of the compiler"
	code.
	(poplevel_class): Reset IDENTIFIER_CLASS_VALUEs.
	(clear_identifier_class_values): New function.
	(pop_from_top_level): Use it.
	(pop_everything): Tweak.
	(maybe_process_template_type_declaration): Don't push the
	declaration for the template here.
	(pushtag): Don't push tag declarations into class scope here.
	(pushdecl): Apply DeMorgan's law for readability.
	(pushdecl_class_level): Remove special-case code for
	TYPE_BEING_DEFINED.  Handle OVERLOADs and anonymous unions.
	(push_class_level_bindng): Deal with inherited bindings.
	(lookup_name_real): Remove special-case code for
	TYPE_BEING_DEFINED, and some implicit typename magic.
	(grokdeclarator): Handle COMPONENT_REF for a template function.
	(build_enumerator): Don't call pushdecl_class_level here.
	(id_in_current_class): Remove.
	* decl2.c (grokfield): Don't call pushdecl_class_level or
	check_template_shadow.
	* errfn.c (cp_file_of): Don't declare.
	(cp_line_of): Likewise.
	* error.c (dump_decl): Handle an OVERLOAD.
	(cp_file_of): Likewise.
	(cp_line_of): Likewise.
	* init.c (build_member_call): Handle a COMPONENT_REF.
	* lex.c (do_identifier): Call maybe_note_name_used_in_class, not
	pushdecl_class_level.
	* method.c (hack_identifier): Build COMPONENT_REFs for references
	to member templates as well as member functions.  Remove dead
	code.
	* parse.y (left_curly): Remove.
	(nonnested_type): Call maybe_note_name_used_in_class, not
	pushdecl_class_level.
	* parse.c: Regenerated.
	(nested_name_specifier_1): Likewise.
	* pt.c (check_explicit_specialization): Adjust, for robustness.
	(check_template_shadow): Handle OVERLOADs.
	(build_template_decl): Set DECL_CONSTRUCTOR_P on the
	TEMPLATE_DECL, if appropriate.
	* search.c (envelope_add_decl): Remove.
	(dfs_pushdecls): Likewise.
	(dfs_compress_decls): Likewise.
	(dfs_push_decls): New function.
	(dfs_push_type_decls): Likewise.
	(setup_class_bindings): Likewise.
	(template_self_reference_p): Likewise.
	(lookup_field_r): Use it.
	(looup_member): Remove old comment.  Deal with ambiguity.
	(push_class_decls): Use dfs_push_decls and dfs_push_type_decls,
	and remove envelope processing.
	* semantics.c (begin_class_definition): Let pushclass push
	declarations for base classes.
	(finish_member_declaration): Push declarations into class scope.
	* typeck.c (build_component_ref): Just put an OVERLOAD into the
	COMPONENT_REF, not a TREE_LIST of an OVERLOAD.
	(build_x_function_call): Deal with OVERLOAD.  Handle template-ids.
	* Makefile.in (class.o): Depend on splay-tree.h.

From-SVN: r26133
1999-04-02 15:36:57 +00:00

342 lines
6.7 KiB
C

/* Provide a call-back mechanism for handling error output.
Copyright (C) 1993, 94-98, 1999 Free Software Foundation, Inc.
Contributed by Jason Merrill (jason@cygnus.com)
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "config.h"
#include "system.h"
#include "tree.h"
#include "cp-tree.h"
#include "toplev.h"
/* cp_printer is the type of a function which converts an argument into
a string for digestion by printf. The cp_printer function should deal
with all memory management; the functions in this file will not free
the char*s returned. See error.c for an example use of this code. */
typedef char* cp_printer PROTO((tree, int));
extern cp_printer * cp_printers[256];
/* Whether or not we should try to be quiet for errors and warnings; this is
used to avoid being too talkative about problems with tentative choices
when we're computing the conversion costs for a method call. */
int cp_silent = 0;
typedef void errorfn (); /* deliberately vague */
static void cp_thing PROTO ((errorfn *, int, const char *, va_list));
#define STRDUP(f) (ap = (char *) alloca (strlen (f) +1), strcpy (ap, (f)), ap)
/* This function supports only `%s', `%d', `%%', and the C++ print
codes. */
static void
cp_thing (errfn, atarg1, format, ap)
errorfn *errfn;
int atarg1;
const char *format;
va_list ap;
{
static char *buf;
static long buflen;
int nargs = 0;
long len;
long offset;
const char *f;
tree atarg = 0;
len = strlen (format) + 1;
if (len > buflen)
{
buflen = len;
buf = xrealloc (buf, buflen);
}
offset = 0;
for (f = format; *f; ++f)
{
cp_printer * function;
int alternate;
int maybe_here;
/* ignore text */
if (*f != '%')
{
buf[offset++] = *f;
continue;
}
++f;
alternate = 0;
maybe_here = 0;
/* Check for '+' and '#' (in that order). */
if (*f == '+')
{
maybe_here = 1;
++f;
}
if (*f == '#')
{
alternate = 1;
++f;
}
/* no field width or precision */
function = cp_printers[(int)*f];
if (function || *f == 's')
{
char *p;
int plen;
if (*f == 's')
{
p = va_arg (ap, char *);
nargs++;
}
else
{
tree t = va_arg (ap, tree);
nargs++;
/* This indicates that ATARG comes from a different
location than normal. */
if (maybe_here && atarg1)
atarg = t;
/* If atarg1 is set and this is the first argument, then
set ATARG appropriately. */
if (atarg1 && nargs == 1)
atarg = t;
p = (*function) (t, alternate);
}
plen = strlen (p);
len += plen;
if (len > buflen)
{
buflen = len;
buf = xrealloc (buf, len);
}
strcpy (buf + offset, p);
offset += plen;
}
else if (*f == '%')
{
/* A `%%' has occurred in the input string. Replace it with
a `%' in the formatted message buf. */
if (++len > buflen)
{
buflen = len;
buf = xrealloc (buf, len);
}
buf[offset++] = '%';
}
else
{
if (*f != 'd')
abort ();
len += HOST_BITS_PER_INT / 2;
if (len > buflen)
{
buflen = len;
buf = xrealloc (buf, len);
}
sprintf (buf + offset, "%d", va_arg (ap, int));
nargs++;
offset += strlen (buf + offset);
/* With an ANSI C library one could write
out += sprintf (...); */
}
}
buf[offset] = '\0';
/* If ATARG1 is set, but we haven't extracted any arguments, then
extract one tree argument for ATARG. */
if (nargs == 0 && atarg1)
atarg = va_arg (ap, tree);
if (atarg)
{
char *file = cp_file_of (atarg);
int line = cp_line_of (atarg);
(*errfn) (file, line, "%s", buf);
}
else
(*errfn) ("%s", buf);
}
void
cp_error VPROTO((const char *format, ...))
{
#ifndef ANSI_PROTOTYPES
char *format;
#endif
va_list ap;
VA_START (ap, format);
#ifndef ANSI_PROTOTYPES
format = va_arg (ap, char *);
#endif
if (! cp_silent)
cp_thing ((errorfn *) error, 0, format, ap);
va_end (ap);
}
void
cp_warning VPROTO((const char *format, ...))
{
#ifndef ANSI_PROTOTYPES
char *format;
#endif
va_list ap;
VA_START (ap, format);
#ifndef ANSI_PROTOTYPES
format = va_arg (ap, char *);
#endif
if (! cp_silent)
cp_thing ((errorfn *) warning, 0, format, ap);
va_end (ap);
}
void
cp_pedwarn VPROTO((const char *format, ...))
{
#ifndef ANSI_PROTOTYPES
char *format;
#endif
va_list ap;
VA_START (ap, format);
#ifndef ANSI_PROTOTYPES
format = va_arg (ap, char *);
#endif
if (! cp_silent)
cp_thing ((errorfn *) pedwarn, 0, format, ap);
va_end (ap);
}
void
cp_compiler_error VPROTO((const char *format, ...))
{
#ifndef ANSI_PROTOTYPES
char *format;
#endif
va_list ap;
VA_START (ap, format);
#ifndef ANSI_PROTOTYPES
format = va_arg (ap, char *);
#endif
if (! cp_silent)
cp_thing ((errorfn *) compiler_error, 0, format, ap);
va_end (ap);
}
void
cp_sprintf VPROTO((const char *format, ...))
{
#ifndef ANSI_PROTOTYPES
char *format;
#endif
va_list ap;
VA_START (ap, format);
#ifndef ANSI_PROTOTYPES
format = va_arg (ap, char *);
#endif
cp_thing ((errorfn *) sprintf, 0, format, ap);
va_end (ap);
}
void
cp_error_at VPROTO((const char *format, ...))
{
#ifndef ANSI_PROTOTYPES
char *format;
#endif
va_list ap;
VA_START (ap, format);
#ifndef ANSI_PROTOTYPES
format = va_arg (ap, char *);
#endif
if (! cp_silent)
cp_thing ((errorfn *) error_with_file_and_line, 1, format, ap);
va_end (ap);
}
void
cp_warning_at VPROTO((const char *format, ...))
{
#ifndef ANSI_PROTOTYPES
char *format;
#endif
va_list ap;
VA_START (ap, format);
#ifndef ANSI_PROTOTYPES
format = va_arg (ap, char *);
#endif
if (! cp_silent)
cp_thing ((errorfn *) warning_with_file_and_line, 1, format, ap);
va_end (ap);
}
void
cp_pedwarn_at VPROTO((const char *format, ...))
{
#ifndef ANSI_PROTOTYPES
char *format;
#endif
va_list ap;
VA_START (ap, format);
#ifndef ANSI_PROTOTYPES
format = va_arg (ap, char *);
#endif
if (! cp_silent)
cp_thing ((errorfn *) pedwarn_with_file_and_line, 1, format, ap);
va_end (ap);
}