#include "optinfo-emit-json.h"
#include "stringpool.h" /* for get_identifier. */
#include "spellcheck.h"
+#include "make-unique.h"
/* If non-NULL, return one past-the-end of the matching SUBPART of
the WHOLE string. */
/* Make an item for the given dump call, equivalent to print_gimple_stmt. */
-static optinfo_item *
+static std::unique_ptr<optinfo_item>
make_item_for_dump_gimple_stmt (gimple *stmt, int spc, dump_flags_t dump_flags)
{
pretty_printer pp;
pp_gimple_stmt_1 (&pp, stmt, spc, dump_flags);
pp_newline (&pp);
- optinfo_item *item
- = new optinfo_item (OPTINFO_ITEM_KIND_GIMPLE, gimple_location (stmt),
- xstrdup (pp_formatted_text (&pp)));
+ std::unique_ptr<optinfo_item> item
+ = make_unique<optinfo_item> (OPTINFO_ITEM_KIND_GIMPLE,
+ gimple_location (stmt),
+ xstrdup (pp_formatted_text (&pp)));
return item;
}
dump_flags_t extra_dump_flags,
gimple *gs, int spc)
{
- optinfo_item *item
+ auto item
= make_item_for_dump_gimple_stmt (gs, spc, dump_flags | extra_dump_flags);
- emit_item (item, metadata.get_dump_flags ());
+ emit_item (*item.get (), metadata.get_dump_flags ());
if (optinfo_enabled_p ())
{
optinfo &info = ensure_pending_optinfo (metadata);
- info.add_item (item);
+ info.add_item (std::move (item));
}
- else
- delete item;
}
/* Similar to dump_gimple_stmt, except additionally print source location. */
/* Make an item for the given dump call, equivalent to print_gimple_expr. */
-static optinfo_item *
+static std::unique_ptr<optinfo_item>
make_item_for_dump_gimple_expr (gimple *stmt, int spc, dump_flags_t dump_flags)
{
dump_flags |= TDF_RHS_ONLY;
pp_needs_newline (&pp) = true;
pp_gimple_stmt_1 (&pp, stmt, spc, dump_flags);
- optinfo_item *item
- = new optinfo_item (OPTINFO_ITEM_KIND_GIMPLE, gimple_location (stmt),
- xstrdup (pp_formatted_text (&pp)));
+ std::unique_ptr<optinfo_item> item
+ = make_unique<optinfo_item> (OPTINFO_ITEM_KIND_GIMPLE,
+ gimple_location (stmt),
+ xstrdup (pp_formatted_text (&pp)));
return item;
}
dump_flags_t extra_dump_flags,
gimple *gs, int spc)
{
- optinfo_item *item
+ std::unique_ptr<optinfo_item> item
= make_item_for_dump_gimple_expr (gs, spc, dump_flags | extra_dump_flags);
- emit_item (item, metadata.get_dump_flags ());
+ emit_item (*item.get (), metadata.get_dump_flags ());
if (optinfo_enabled_p ())
{
optinfo &info = ensure_pending_optinfo (metadata);
- info.add_item (item);
+ info.add_item (std::move (item));
}
- else
- delete item;
}
/* Similar to dump_gimple_expr, except additionally print source location. */
/* Make an item for the given dump call, equivalent to print_generic_expr. */
-static optinfo_item *
+static std::unique_ptr<optinfo_item>
make_item_for_dump_generic_expr (tree node, dump_flags_t dump_flags)
{
pretty_printer pp;
if (EXPR_HAS_LOCATION (node))
loc = EXPR_LOCATION (node);
- optinfo_item *item
- = new optinfo_item (OPTINFO_ITEM_KIND_TREE, loc,
- xstrdup (pp_formatted_text (&pp)));
+ std::unique_ptr<optinfo_item> item
+ = make_unique<optinfo_item> (OPTINFO_ITEM_KIND_TREE, loc,
+ xstrdup (pp_formatted_text (&pp)));
return item;
}
dump_flags_t extra_dump_flags,
tree t)
{
- optinfo_item *item
+ std::unique_ptr<optinfo_item> item
= make_item_for_dump_generic_expr (t, dump_flags | extra_dump_flags);
- emit_item (item, metadata.get_dump_flags ());
+ emit_item (*item.get (), metadata.get_dump_flags ());
if (optinfo_enabled_p ())
{
optinfo &info = ensure_pending_optinfo (metadata);
- info.add_item (item);
+ info.add_item (std::move (item));
}
- else
- delete item;
}
/* Make an item for the given dump call. */
-static optinfo_item *
+static std::unique_ptr<optinfo_item>
make_item_for_dump_symtab_node (symtab_node *node)
{
location_t loc = DECL_SOURCE_LOCATION (node->decl);
- optinfo_item *item
- = new optinfo_item (OPTINFO_ITEM_KIND_SYMTAB_NODE, loc,
- xstrdup (node->dump_name ()));
+ std::unique_ptr<optinfo_item> item
+ = make_unique<optinfo_item> (OPTINFO_ITEM_KIND_SYMTAB_NODE, loc,
+ xstrdup (node->dump_name ()));
return item;
}
{
emit_any_pending_textual_chunks (dest);
/* This chunk has a stashed item: use it. */
- emit_item (m_stashed_items[stashed_item_idx++].item, dest);
+ std::unique_ptr <optinfo_item> item
+ (m_stashed_items[stashed_item_idx++].item);
+ emit_item (std::move (item), dest);
}
else
/* This chunk is purely textual. Print it (to
return;
char *formatted_text = xstrdup (pp_formatted_text (this));
- optinfo_item *item
- = new optinfo_item (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION,
- formatted_text);
- emit_item (item, dest);
+ std::unique_ptr<optinfo_item> item
+ = make_unique<optinfo_item> (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION,
+ formatted_text);
+ emit_item (std::move (item), dest);
/* Clear the pending text by unwinding formatted_text back to the start
of the buffer (without deallocating). */
to DEST; otherwise delete ITEM. */
void
-dump_pretty_printer::emit_item (optinfo_item *item, optinfo *dest)
+dump_pretty_printer::emit_item (std::unique_ptr<optinfo_item> item,
+ optinfo *dest)
{
- m_context->emit_item (item, m_dump_kind);
+ m_context->emit_item (*item.get (), m_dump_kind);
if (dest)
- dest->add_item (item);
- else
- delete item;
+ dest->add_item (std::move (item));
}
/* Record that ITEM (generated in phase 2 of formatting) is to be used for
the chunk at BUFFER_PTR in phase 3 (by emit_items). */
void
-dump_pretty_printer::stash_item (const char **buffer_ptr, optinfo_item *item)
+dump_pretty_printer::stash_item (const char **buffer_ptr,
+ std::unique_ptr<optinfo_item> item)
{
gcc_assert (buffer_ptr);
- gcc_assert (item);
+ gcc_assert (item.get ());
- m_stashed_items.safe_push (stashed_item (buffer_ptr, item));
+ m_stashed_items.safe_push (stashed_item (buffer_ptr, item.release ()));
}
/* pp_format_decoder callback for dump_pretty_printer, and thus for
cgraph_node *node = va_arg (*text->m_args_ptr, cgraph_node *);
/* Make an item for the node, and stash it. */
- optinfo_item *item = make_item_for_dump_symtab_node (node);
- stash_item (buffer_ptr, item);
+ auto item = make_item_for_dump_symtab_node (node);
+ stash_item (buffer_ptr, std::move (item));
return true;
}
gimple *stmt = va_arg (*text->m_args_ptr, gimple *);
/* Make an item for the stmt, and stash it. */
- optinfo_item *item = make_item_for_dump_gimple_expr (stmt, 0, TDF_SLIM);
- stash_item (buffer_ptr, item);
+ auto item = make_item_for_dump_gimple_expr (stmt, 0, TDF_SLIM);
+ stash_item (buffer_ptr, std::move (item));
return true;
}
gimple *stmt = va_arg (*text->m_args_ptr, gimple *);
/* Make an item for the stmt, and stash it. */
- optinfo_item *item = make_item_for_dump_gimple_stmt (stmt, 0, TDF_SLIM);
- stash_item (buffer_ptr, item);
+ auto item = make_item_for_dump_gimple_stmt (stmt, 0, TDF_SLIM);
+ stash_item (buffer_ptr, std::move (item));
return true;
}
tree t = va_arg (*text->m_args_ptr, tree);
/* Make an item for the tree, and stash it. */
- optinfo_item *item = make_item_for_dump_generic_expr (t, TDF_SLIM);
- stash_item (buffer_ptr, item);
+ auto item = make_item_for_dump_generic_expr (t, TDF_SLIM);
+ stash_item (buffer_ptr, std::move (item));
return true;
}
/* Output a formatted message using FORMAT on appropriate dump streams. */
void
-dump_context::dump_printf_va (const dump_metadata_t &metadata, const char *format,
+dump_context::dump_printf_va (const dump_metadata_t &metadata,
+ const char *format,
va_list *ap)
{
dump_pretty_printer pp (this, metadata.get_dump_flags ());
/* Make an item for the given dump call, equivalent to print_dec. */
template<unsigned int N, typename C>
-static optinfo_item *
+static std::unique_ptr<optinfo_item>
make_item_for_dump_dec (const poly_int<N, C> &value)
{
STATIC_ASSERT (poly_coeff_traits<C>::signedness >= 0);
}
}
- optinfo_item *item
- = new optinfo_item (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION,
- xstrdup (pp_formatted_text (&pp)));
+ auto item
+ = make_unique<optinfo_item> (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION,
+ xstrdup (pp_formatted_text (&pp)));
return item;
}
template<unsigned int N, typename C>
void
-dump_context::dump_dec (const dump_metadata_t &metadata, const poly_int<N, C> &value)
+dump_context::dump_dec (const dump_metadata_t &metadata,
+ const poly_int<N, C> &value)
{
- optinfo_item *item = make_item_for_dump_dec (value);
- emit_item (item, metadata.get_dump_flags ());
+ auto item = make_item_for_dump_dec (value);
+ emit_item (*item.get (), metadata.get_dump_flags ());
if (optinfo_enabled_p ())
{
optinfo &info = ensure_pending_optinfo (metadata);
- info.add_item (item);
+ info.add_item (std::move (item));
}
- else
- delete item;
}
/* Output the name of NODE on appropriate dump streams. */
void
-dump_context::dump_symtab_node (const dump_metadata_t &metadata, symtab_node *node)
+dump_context::dump_symtab_node (const dump_metadata_t &metadata,
+ symtab_node *node)
{
- optinfo_item *item = make_item_for_dump_symtab_node (node);
- emit_item (item, metadata.get_dump_flags ());
+ auto item = make_item_for_dump_symtab_node (node);
+ emit_item (*item.get (), metadata.get_dump_flags ());
if (optinfo_enabled_p ())
{
optinfo &info = ensure_pending_optinfo (metadata);
- info.add_item (item);
+ info.add_item (std::move (item));
}
- else
- delete item;
}
/* Get the current dump scope-nesting depth.
pretty_printer pp;
pp_printf (&pp, "%s %s %s", "===", name, "===");
pp_newline (&pp);
- optinfo_item *item
- = new optinfo_item (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION,
- xstrdup (pp_formatted_text (&pp)));
- emit_item (item, MSG_NOTE);
+ std::unique_ptr<optinfo_item> item
+ = make_unique<optinfo_item> (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION,
+ xstrdup (pp_formatted_text (&pp)));
+ emit_item (*item.get (), MSG_NOTE);
if (optinfo_enabled_p ())
{
= begin_next_optinfo (dump_metadata_t (MSG_NOTE, impl_location),
user_location);
info.m_kind = OPTINFO_KIND_SCOPE;
- info.add_item (item);
+ info.add_item (std::move (item));
end_any_optinfo ();
}
- else
- delete item;
}
/* Pop a nested dump scope. */
consolidation into optinfo instances). */
void
-dump_context::emit_item (optinfo_item *item, dump_flags_t dump_kind)
+dump_context::emit_item (const optinfo_item &item, dump_flags_t dump_kind)
{
if (dump_file && apply_dump_filter_p (dump_kind, pflags))
- fprintf (dump_file, "%s", item->get_text ());
+ fprintf (dump_file, "%s", item.get_text ());
if (alt_dump_file && apply_dump_filter_p (dump_kind, alt_flags))
- fprintf (alt_dump_file, "%s", item->get_text ());
+ fprintf (alt_dump_file, "%s", item.get_text ());
/* Support for temp_dump_context in selftests. */
if (m_test_pp && apply_dump_filter_p (dump_kind, m_test_pp_flags))
- pp_string (m_test_pp, item->get_text ());
+ pp_string (m_test_pp, item.get_text ());
}
/* The current singleton dump_context, and its default. */