From 239751f9c8992d19423a9a6ee16f1599e8f2391f Mon Sep 17 00:00:00 2001 From: crowl Date: Tue, 19 Apr 2011 01:54:03 +0000 Subject: [PATCH] First stab at getting namespaces working with PPH. This change will put top-level namespaces into the global namespace. It does not, however, appear to their members in any place useful. Some tuning of tracing output. Index: gcc/cp/ChangeLog.pph 2011-04-18 Lawrence Crowl * pph.c (pth_save_identifiers): Fix FIXME comment. (pph_add_names_to_namespace): Add contained namespaces to scope as well as regular symbols. * pph-streamer.c (enum pph_trace_type): Add a trace for refs. (pph_stream_trace): Add the ref printing. Reduce bulk of trace messages. Filter off uninteresting traces, primarily traces of null pointers. (pph_stream_trace_tree): Convert ref_p to trace value. * pph-streamer.h: Adjust flag_pph_tracer comparisons for better traces. (pph_stream_trace_tree): Add ref_p parameter. Propogate such parameters at all call sites. (pph_output_tree_lst): New. Like pph_output_tree, but for list and chain contexts. (pph_stream_write_tree): The callback is auxillary. (pph_output_chain_filtered): Call pph_output_tree_lst. Index: libcpp/ChangeLog.pph 2011-04-18 Lawrence Crowl * init.c: Fix spelling in comment. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/pph@172690 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog.pph | 18 ++++++++++++++++++ gcc/cp/pph-streamer-out.c | 4 ++-- gcc/cp/pph-streamer.c | 29 ++++++++++++++++++++++++----- gcc/cp/pph-streamer.h | 24 +++++++++++++++++------- gcc/cp/pph.c | 17 ++++++++++++++++- libcpp/ChangeLog.pph | 4 ++++ libcpp/init.c | 2 +- 7 files changed, 82 insertions(+), 16 deletions(-) diff --git a/gcc/cp/ChangeLog.pph b/gcc/cp/ChangeLog.pph index 357c4ce0b41..4110e86fee7 100644 --- a/gcc/cp/ChangeLog.pph +++ b/gcc/cp/ChangeLog.pph @@ -1,3 +1,21 @@ +2011-04-18 Lawrence Crowl + + * pph.c (pth_save_identifiers): Fix FIXME comment. + (pph_add_names_to_namespace): Add contained namespaces to scope as + well as regular symbols. + * pph-streamer.c (enum pph_trace_type): Add a trace for refs. + (pph_stream_trace): Add the ref printing. Reduce bulk of trace + messages. Filter off uninteresting traces, primarily traces of null + pointers. + (pph_stream_trace_tree): Convert ref_p to trace value. + * pph-streamer.h: Adjust flag_pph_tracer comparisons for better traces. + (pph_stream_trace_tree): Add ref_p parameter. Propogate such + parameters at all call sites. + (pph_output_tree_lst): New. Like pph_output_tree, but for list and + chain contexts. + (pph_stream_write_tree): The callback is auxillary. + (pph_output_chain_filtered): Call pph_output_tree_lst. + 2011-04-14 Diego Novillo * pph.c (pph_read_file_contents): Re-instate call to diff --git a/gcc/cp/pph-streamer-out.c b/gcc/cp/pph-streamer-out.c index babf751ec5b..38c7bbe6573 100644 --- a/gcc/cp/pph-streamer-out.c +++ b/gcc/cp/pph-streamer-out.c @@ -791,7 +791,7 @@ pph_stream_write_tree (struct output_block *ob, tree expr, bool ref_p) } if (TREE_CODE (expr) == TYPE_DECL) - pph_output_tree (stream, DECL_ORIGINAL_TYPE (expr), ref_p); + pph_output_tree_aux (stream, DECL_ORIGINAL_TYPE (expr), ref_p); } else if (TREE_CODE (expr) == STATEMENT_LIST) { @@ -855,7 +855,7 @@ pph_output_chain_filtered (pph_stream *stream, tree first, bool ref_p, saved_chain = TREE_CHAIN (t); TREE_CHAIN (t) = NULL_TREE; - pph_output_tree (stream, t, ref_p); + pph_output_tree_lst (stream, t, ref_p); TREE_CHAIN (t) = saved_chain; } diff --git a/gcc/cp/pph-streamer.c b/gcc/cp/pph-streamer.c index 91e01a4c64a..d6ef167a107 100644 --- a/gcc/cp/pph-streamer.c +++ b/gcc/cp/pph-streamer.c @@ -118,6 +118,7 @@ pph_stream_close (pph_stream *stream) enum pph_trace_type { PPH_TRACE_TREE, + PPH_TRACE_REF, PPH_TRACE_UINT, PPH_TRACE_BYTES, PPH_TRACE_STRING, @@ -134,11 +135,15 @@ static void pph_stream_trace (pph_stream *stream, const void *data, unsigned int nbytes, enum pph_trace_type type) { - const char *op = (stream->write_p) ? "write" : "read"; - const char *type_s[] = { "tree", "uint", "bytes", "string", "chain", + const char *op = (stream->write_p) ? "<<" : ">>"; + const char *type_s[] = { "tree", "ref", "uint", "bytes", "string", "chain", "bitpack" }; - fprintf (pph_logfile, "*** %s: op=%s, type=%s, size=%u, value=", + if ((type == PPH_TRACE_TREE || type == PPH_TRACE_CHAIN) + && !data && flag_pph_tracer <= 3) + return; + + fprintf (pph_logfile, "*** %s: %s%s/%u, value=", stream->name, op, type_s[type], (unsigned) nbytes); switch (type) @@ -157,6 +162,20 @@ pph_stream_trace (pph_stream *stream, const void *data, unsigned int nbytes, } break; + case PPH_TRACE_REF: + { + const_tree t = (const_tree) data; + if (t) + { + print_generic_expr (pph_logfile, CONST_CAST (union tree_node *, t), + 0); + fprintf (pph_logfile, ", code=%s", tree_code_name[TREE_CODE (t)]); + } + else + fprintf (pph_logfile, "NULL_TREE"); + } + break; + case PPH_TRACE_UINT: { unsigned int val = *((const unsigned int *) data); @@ -212,10 +231,10 @@ pph_stream_trace (pph_stream *stream, const void *data, unsigned int nbytes, /* Show tracing information for T on STREAM. */ void -pph_stream_trace_tree (pph_stream *stream, tree t) +pph_stream_trace_tree (pph_stream *stream, tree t, bool ref_p) { pph_stream_trace (stream, t, t ? tree_code_size (TREE_CODE (t)) : 0, - PPH_TRACE_TREE); + ref_p ? PPH_TRACE_REF : PPH_TRACE_TREE); } diff --git a/gcc/cp/pph-streamer.h b/gcc/cp/pph-streamer.h index 0bc2b4edf17..e0040b2af94 100644 --- a/gcc/cp/pph-streamer.h +++ b/gcc/cp/pph-streamer.h @@ -93,7 +93,7 @@ enum chain_filter { NONE, NO_BUILTINS }; /* In pph-streamer.c. */ pph_stream *pph_stream_open (const char *, const char *); void pph_stream_close (pph_stream *); -void pph_stream_trace_tree (pph_stream *, tree); +void pph_stream_trace_tree (pph_stream *, tree, bool ref_p); void pph_stream_trace_uint (pph_stream *, unsigned int); void pph_stream_trace_bytes (pph_stream *, const void *, size_t); void pph_stream_trace_string (pph_stream *, const char *); @@ -134,17 +134,27 @@ static inline void pph_output_tree (pph_stream *stream, tree t, bool ref_p) { if (flag_pph_tracer >= 1) - pph_stream_trace_tree (stream, t); + pph_stream_trace_tree (stream, t, ref_p); lto_output_tree (stream->ob, t, ref_p); } /* Output AST T to STREAM. If REF_P is true, output all the leaves of T - as references. this function is an internal auxillary routine. */ + as references. This function is an list auxillary routine. */ +static inline void +pph_output_tree_lst (pph_stream *stream, tree t, bool ref_p) +{ + if (flag_pph_tracer >= 2) + pph_stream_trace_tree (stream, t, ref_p); + lto_output_tree (stream->ob, t, ref_p); +} + +/* Output AST T to STREAM. If REF_P is true, output all the leaves of T + as references. This function is an internal auxillary routine. */ static inline void pph_output_tree_aux (pph_stream *stream, tree t, bool ref_p) { if (flag_pph_tracer >= 3) - pph_stream_trace_tree (stream, t); + pph_stream_trace_tree (stream, t, ref_p); lto_output_tree (stream->ob, t, ref_p); } @@ -153,7 +163,7 @@ static inline void pph_output_tree_or_ref (pph_stream *stream, tree t, bool ref_p) { if (flag_pph_tracer >= 2) - pph_stream_trace_tree (stream, t); + pph_stream_trace_tree (stream, t, ref_p); lto_output_tree_or_ref (stream->ob, t, ref_p); } @@ -220,7 +230,7 @@ pph_output_string_with_length (pph_stream *stream, const char *str, static inline void pph_output_chain (pph_stream *stream, tree first, bool ref_p) { - if (flag_pph_tracer >= 3) + if (flag_pph_tracer >= 2) pph_stream_trace_chain (stream, first); lto_output_chain (stream->ob, first, ref_p); } @@ -285,7 +295,7 @@ pph_input_tree (pph_stream *stream) { tree t = lto_input_tree (stream->ib, stream->data_in); if (flag_pph_tracer >= 4) - pph_stream_trace_tree (stream, t); + pph_stream_trace_tree (stream, t, false); /* FIXME pph: always false? */ return t; } diff --git a/gcc/cp/pph.c b/gcc/cp/pph.c index 6584e722dfc..6a93ad9910d 100644 --- a/gcc/cp/pph.c +++ b/gcc/cp/pph.c @@ -792,7 +792,7 @@ pth_save_identifiers (cpp_idents_used *identifiers, pph_stream *stream) if (!(entry->used_by_directive || entry->expanded_to_text)) continue; - /* FIX pph: We are wasting space; ident_len, used_by_directive + /* FIXME pph: We are wasting space; ident_len, used_by_directive and expanded_to_text together could fit into a single uint. */ pph_output_uint (stream, entry->used_by_directive); @@ -1956,6 +1956,21 @@ pph_add_names_to_namespace (tree ns, tree new_ns) chain = DECL_CHAIN (t); pushdecl_with_scope (t, level, /*is_friend=*/false); } + + for (t = new_level->namespaces; t; t = chain) + { + /* Pushing a decl into a scope clobbers its DECL_CHAIN. + Preserve it. */ + /* FIXME pph: we should first check to see if it isn't already there. */ + chain = DECL_CHAIN (t); + pushdecl_with_scope (t, level, /*is_friend=*/false); + /* FIXME pph: The change above enables the namespace, + but its symbols are still missing. + The recursive call below causes multiple errors. + pph_add_names_to_namespace (t, t); + */ + } + } diff --git a/libcpp/ChangeLog.pph b/libcpp/ChangeLog.pph index f1573007a0b..70b1c121a72 100644 --- a/libcpp/ChangeLog.pph +++ b/libcpp/ChangeLog.pph @@ -1,3 +1,7 @@ +2011-04-18 Lawrence Crowl + + * init.c: Fix spelling in comment. + 2011-04-14 Lawrence Crowl * include/cpplib.h (cpp_hashnode): Use a macro for the number of bits diff --git a/libcpp/init.c b/libcpp/init.c index 3a526c618f4..8b5e11dc402 100644 --- a/libcpp/init.c +++ b/libcpp/init.c @@ -395,7 +395,7 @@ static const struct builtin_operator operator_array[] = }; #undef B -/* Verify that the indicies of the named operators fit within the +/* Verify that the indices of the named operators fit within the number of bits available. */ #define B(n, t) unsigned char t ## _too_large_for_bitfield[ \ -- 2.11.4.GIT