aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorManuel López-Ibáñez <manu@gcc.gnu.org>2014-10-26 21:21:58 +0000
committerManuel López-Ibáñez <manu@gcc.gnu.org>2014-10-26 21:21:58 +0000
commitd723bb7c757e0d7d94df7b059f52ad50a2175c50 (patch)
tree37cbb1525929f4ecbfc1d14e764c60d380839efd /gcc/cp
parent23487675cd29d1702f44c9bc60885c1602a401f1 (diff)
downloadgcc-d723bb7c757e0d7d94df7b059f52ad50a2175c50.zip
gcc-d723bb7c757e0d7d94df7b059f52ad50a2175c50.tar.gz
gcc-d723bb7c757e0d7d94df7b059f52ad50a2175c50.tar.bz2
In cp/error.c...
In cp/error.c, I separate the initialization of the diagnostic context from the initialization of the scratch pretty-printer (cxx_pp). This was suggested by Gabriel in the last review of the patch and now I realize it was a good idea. Now cxx_initialize_diagnostics is the equivalent version of c_initialize_diagnostics. To avoid having to make extern a bunch of functions, I moved it from cp-objcp-common.c to error.c. I moved the setting of diagnostic_format_decoder (global_dc) = c_tree_printer, from c_objc_common_init to c_initialize_diagnostics, and right after c_common_diagnostics_set_defaults. This mimics what is done in cxx_initialize_diagnostics. Moreover, in both c_initialize_diagnostics and cxx_initialize_diagnostics, the FE-specific pretty-printer is initialized first and then other settings are applied. This does not make a difference right now, but if in the future one wishes to touch something in the pretty-printer, it will not get overriden immediately. In fact, the code I removed in c_common_initialize_diagnostics, which sets line_cutoff to 80, is useless because the pretty-printer created here is actually never used, but overriden by the FE-specific pretty-printers. This also means that doc/invoke.texi was wrong. Finally, it is useless to set the maximum line length to 0 in the constructor of cxx_pretty_printer. It is the default anyway. gcc/c/ChangeLog: 2014-10-26 Manuel López-Ibáñez <manu@gcc.gnu.org> PR c++/53061 * c-objc-common.c (c_objc_common_init): Do not do diagnostics initialization here... (c_initialize_diagnostics): ... but here. Set defaults after building pretty-printer. gcc/ChangeLog: 2014-10-26 Manuel López-Ibáñez <manu@gcc.gnu.org> PR c++/53061 * doc/invoke.texi (fmessage-length): Update text to match reality. gcc/cp/ChangeLog: 2014-10-26 Manuel López-Ibáñez <manu@gcc.gnu.org> PR c++/53061 * cp-objcp-common.c: Do not include new. (cxx_initialize_diagnostics): Move from here to ... * error.c (cxx_initialize_diagnostics): : ... here. Move diagnostics initialization here from init_error. (cxx_pp): Use a real pointer not a macro. (init_error): Just initialize cxx_pp. * cxx-pretty-print.c (cxx_pretty_printer::cxx_pretty_printer): Do not set maximum line length. gcc/c-family/ChangeLog: 2014-10-26 Manuel López-Ibáñez <manu@gcc.gnu.org> PR c++/53061 * c-opts.c (c_common_diagnostics_set_defaults): Renamed from c_common_initialize_diagnostics. * c-common.h: Likewise. From-SVN: r216720
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog12
-rw-r--r--gcc/cp/cp-objcp-common.c18
-rw-r--r--gcc/cp/cxx-pretty-print.c2
-rw-r--r--gcc/cp/error.c40
4 files changed, 45 insertions, 27 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index f741bfb..e105edc 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,15 @@
+2014-10-26 Manuel López-Ibáñez <manu@gcc.gnu.org>
+
+ PR c++/53061
+ * cp-objcp-common.c: Do not include new.
+ (cxx_initialize_diagnostics): Move from here to ...
+ * error.c (cxx_initialize_diagnostics): : ... here. Move
+ diagnostics initialization here from init_error.
+ (cxx_pp): Use a real pointer not a macro.
+ (init_error): Just initialize cxx_pp.
+ * cxx-pretty-print.c (cxx_pretty_printer::cxx_pretty_printer): Do
+ not set maximum line length.
+
2014-10-23 Jonathan Wakely <jwakely@redhat.com>
PR c++/63619
diff --git a/gcc/cp/cp-objcp-common.c b/gcc/cp/cp-objcp-common.c
index 0d144ef..12df4c2 100644
--- a/gcc/cp/cp-objcp-common.c
+++ b/gcc/cp/cp-objcp-common.c
@@ -32,8 +32,6 @@ along with GCC; see the file COPYING3. If not see
#include "cxx-pretty-print.h"
#include "cp-objcp-common.h"
-#include <new> // For placement new.
-
/* Special routine to get the alias set for C++. */
alias_set_type
@@ -132,22 +130,6 @@ cp_var_mod_type_p (tree type, tree fn)
return false;
}
-/* Construct a C++-aware pretty-printer for CONTEXT. It is assumed
- that CONTEXT->printer is an already constructed basic pretty_printer. */
-void
-cxx_initialize_diagnostics (diagnostic_context *context)
-{
- c_common_initialize_diagnostics (context);
-
- pretty_printer *base = context->printer;
- cxx_pretty_printer *pp = XNEW (cxx_pretty_printer);
- context->printer = new (pp) cxx_pretty_printer ();
-
- /* It is safe to free this object because it was previously XNEW()'d. */
- base->~pretty_printer ();
- XDELETE (base);
-}
-
/* This compares two types for equivalence ("compatible" in C-based languages).
This routine should only return 1 if it is sure. It should not be used
in contexts where erroneously returning 0 causes problems. */
diff --git a/gcc/cp/cxx-pretty-print.c b/gcc/cp/cxx-pretty-print.c
index 67e84c0..02ce346 100644
--- a/gcc/cp/cxx-pretty-print.c
+++ b/gcc/cp/cxx-pretty-print.c
@@ -2433,8 +2433,6 @@ cxx_pretty_printer::cxx_pretty_printer ()
: c_pretty_printer (),
enclosing_scope (global_namespace)
{
- pp_set_line_maximum_length (this, 0);
-
type_specifier_seq = (pp_fun) pp_cxx_type_specifier_seq;
parameter_list = (pp_fun) pp_cxx_parameter_declaration_clause;
}
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index 57f3c31..755bb00 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -39,11 +39,13 @@ along with GCC; see the file COPYING3. If not see
#define pp_separate_with_comma(PP) pp_cxx_separate_with (PP, ',')
#define pp_separate_with_semicolon(PP) pp_cxx_separate_with (PP, ';')
-/* The global buffer where we dump everything. It is there only for
- transitional purpose. It is expected, in the near future, to be
- completely removed. */
+/* cxx_pp is a C++ front-end-specific pretty printer: this is where we
+ dump C++ ASTs as strings. It is mostly used only by the various
+ tree -> string functions that are occasionally called from the
+ debugger or by the front-end for things like
+ __PRETTY_FUNCTION__. */
static cxx_pretty_printer scratch_pretty_printer;
-#define cxx_pp (&scratch_pretty_printer)
+static cxx_pretty_printer * cxx_pp = &scratch_pretty_printer;
/* Translate if being used for diagnostics, but not for dump files or
__PRETTY_FUNCTION. */
@@ -104,13 +106,37 @@ static void cp_print_error_function (diagnostic_context *, diagnostic_info *);
static bool cp_printer (pretty_printer *, text_info *, const char *,
int, bool, bool, bool);
+/* CONTEXT->printer is a basic pretty printer that was constructed
+ presumably by diagnostic_initialize(), called early in the
+ compiler's initialization process (in general_init) Before the FE
+ is initialized. This (C++) FE-specific diagnostic initializer is
+ thus replacing the basic pretty printer with one that has C++-aware
+ capacities. */
+
void
-init_error (void)
+cxx_initialize_diagnostics (diagnostic_context *context)
{
- diagnostic_starter (global_dc) = cp_diagnostic_starter;
+ pretty_printer *base = context->printer;
+ cxx_pretty_printer *pp = XNEW (cxx_pretty_printer);
+ context->printer = new (pp) cxx_pretty_printer ();
+
+ /* It is safe to free this object because it was previously XNEW()'d. */
+ base->~pretty_printer ();
+ XDELETE (base);
+
+ c_common_diagnostics_set_defaults (context);
+ diagnostic_starter (context) = cp_diagnostic_starter;
/* diagnostic_finalizer is already c_diagnostic_finalizer. */
- diagnostic_format_decoder (global_dc) = cp_printer;
+ diagnostic_format_decoder (context) = cp_printer;
+}
+/* Initialize the global cxx_pp that is used as the memory store for
+ the string representation of C++ AST. See the description of
+ cxx_pp above. */
+
+void
+init_error (void)
+{
new (cxx_pp) cxx_pretty_printer ();
}