c++: Module-specific error and tree dumping

With modules, we need the ability to name 'foos' in different modules.
The idiom for that is a trailing '@modulename' suffix.  This adds that
to the error printing routines.  I also augment the tree dumping
machinery to show module-specific metadata.

	gcc/cp/
	* error.c (dump_module_suffix): New.
	(dump_aggr_type, dump_simple_decl, dump_function_name): Call it.
	* ptree.c (cxx_print_decl): Print module information.
	* module.cc (module_name, get_importing_module): Stubs.
This commit is contained in:
Nathan Sidwell 2020-12-09 12:18:06 -08:00
parent 79c1b9fb44
commit 8c60696b69
3 changed files with 86 additions and 0 deletions

View File

@ -179,6 +179,38 @@ cxx_initialize_diagnostics (diagnostic_context *context)
pp->m_format_postprocessor = new cxx_format_postprocessor ();
}
/* Dump an '@module' name suffix for DECL, if any. */
static void
dump_module_suffix (cxx_pretty_printer *pp, tree decl)
{
if (!modules_p ())
return;
if (!DECL_CONTEXT (decl))
return;
if (TREE_CODE (decl) != CONST_DECL
|| !UNSCOPED_ENUM_P (DECL_CONTEXT (decl)))
{
if (!DECL_NAMESPACE_SCOPE_P (decl))
return;
if (TREE_CODE (decl) == NAMESPACE_DECL
&& !DECL_NAMESPACE_ALIAS (decl)
&& (TREE_PUBLIC (decl) || !TREE_PUBLIC (CP_DECL_CONTEXT (decl))))
return;
}
if (unsigned m = get_originating_module (decl))
if (const char *n = module_name (m, false))
{
pp_character (pp, '@');
pp->padding = pp_none;
pp_string (pp, n);
}
}
/* Dump a scope, if deemed necessary. */
static void
@ -771,6 +803,8 @@ dump_aggr_type (cxx_pretty_printer *pp, tree t, int flags)
else
pp_cxx_tree_identifier (pp, DECL_NAME (decl));
dump_module_suffix (pp, decl);
if (tmplate)
dump_template_parms (pp, TYPE_TEMPLATE_INFO (t),
!CLASSTYPE_USE_TEMPLATE (t),
@ -1077,6 +1111,9 @@ dump_simple_decl (cxx_pretty_printer *pp, tree t, tree type, int flags)
pp_string (pp, M_("<structured bindings>"));
else
pp_string (pp, M_("<anonymous>"));
dump_module_suffix (pp, t);
if (flags & TFF_DECL_SPECIFIERS)
dump_type_suffix (pp, type, flags);
}
@ -1894,6 +1931,8 @@ dump_function_name (cxx_pretty_printer *pp, tree t, int flags)
else
dump_decl (pp, name, flags);
dump_module_suffix (pp, t);
if (DECL_TEMPLATE_INFO (t)
&& !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t)
&& (TREE_CODE (DECL_TI_TEMPLATE (t)) != TEMPLATE_DECL

View File

@ -74,6 +74,11 @@ get_module (tree, module_state *, bool)
return nullptr;
}
const char *
module_name (unsigned, bool)
{
return nullptr;
}
void
mangle_module (int, bool)
@ -102,6 +107,12 @@ get_originating_module (tree, bool)
return 0;
}
unsigned
get_importing_module (tree, bool)
{
return 0;
}
bool
module_may_redeclare (tree)
{

View File

@ -59,6 +59,42 @@ cxx_print_decl (FILE *file, tree node, int indent)
bool need_indent = true;
if (TREE_CODE (node) == FUNCTION_DECL
|| TREE_CODE (node) == VAR_DECL
|| TREE_CODE (node) == TYPE_DECL
|| TREE_CODE (node) == TEMPLATE_DECL
|| TREE_CODE (node) == CONCEPT_DECL
|| TREE_CODE (node) == NAMESPACE_DECL)
{
unsigned m = 0;
if (DECL_LANG_SPECIFIC (node) && DECL_MODULE_IMPORT_P (node))
m = get_importing_module (node, true);
if (const char *name = m == ~0u ? "" : module_name (m, true))
{
if (need_indent)
indent_to (file, indent + 3);
fprintf (file, " module %d:%s", m, name);
need_indent = false;
}
if (DECL_LANG_SPECIFIC (node) && DECL_MODULE_PURVIEW_P (node))
{
if (need_indent)
indent_to (file, indent + 3);
fprintf (file, " purview");
need_indent = false;
}
}
if (DECL_MODULE_EXPORT_P (node))
{
if (need_indent)
indent_to (file, indent + 3);
fprintf (file, " exported");
need_indent = false;
}
if (DECL_EXTERNAL (node) && DECL_NOT_REALLY_EXTERN (node))
{
if (need_indent)