No functional change intended.

Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk?

-- >8 --

A lot of places use (*modules)[0] to refer to the module state for the
current TU.  This is a bit awkward to type and not particularly clear
what it represents; make a helper function to clarify it.

gcc/cp/ChangeLog:

        * module.cc (this_module): New function.
        (import_entity_module): Use it.
        (trees_out::decl_node): Likewise.
        (get_module): Likewise.
        (module_state::check_not_purview): Likewise.
        (module_state::read_imports): Likewise.
        (module_state::read_using_directives): Likewise.
        (module_state::read_initial): Likewise.
        (get_import_bitmap): Likewise.
        (module_may_redeclare): Likewise.
        (direct_import): Likewise.
        (declare_module): Likewise.
        (name_pending_imports): Likewise.
        (preprocess_module): Likewise.
        (finish_module_processing): Likewise.
        (late_finish_module): Likewise.

Signed-off-by: Nathaniel Shead <nathanielosh...@gmail.com>
---
 gcc/cp/module.cc | 46 +++++++++++++++++++++++++++-------------------
 1 file changed, 27 insertions(+), 19 deletions(-)

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 5ab340afe36..50fc1af0354 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -4097,6 +4097,13 @@ static unsigned lazy_hard_limit; /* Hard limit on open 
modules.  */
    current TU; imports start at 1.  */
 static GTY(()) vec<module_state *, va_gc> *modules;
 
+/* Get the module state for the current TU's module.  */
+
+static module_state *
+this_module() {
+  return (*modules)[0];
+}
+
 /* Hash of module state, findable by {name, parent}. */
 static GTY(()) hash_table<module_state_hash> *modules_hash;
 
@@ -4247,7 +4254,7 @@ import_entity_module (unsigned index)
 {
   if (index > ~(~0u >> 1))
     /* This is an index for an exported entity.  */
-    return (*modules)[0];
+    return this_module ();
 
   /* Do not include the current TU (not an off-by-one error).  */
   unsigned pos = 1;
@@ -9394,7 +9401,7 @@ trees_out::decl_node (tree decl, walk_kind ref)
   if (streaming_p () && dump (dumper::TREE))
     {
       char const *kind = "import";
-      module_state *from = (*modules)[0];
+      module_state *from = this_module ();
       if (dep->is_import ())
        /* Rediscover the unremapped index.  */
        from = import_entity_module (import_entity_index (decl));
@@ -15890,7 +15897,7 @@ get_module (tree name, module_state *parent, bool 
partition)
   if (partition)
     {
       if (!parent)
-       parent = get_primary ((*modules)[0]);
+       parent = get_primary (this_module ());
 
       if (!parent->is_partition () && !parent->flatname)
        parent->set_flatname ();
@@ -15994,7 +16001,7 @@ recursive_lazy (unsigned snum = ~0u)
 bool
 module_state::check_not_purview (location_t from)
 {
-  module_state *imp = (*modules)[0];
+  module_state *imp = this_module ();
   if (imp && !imp->name)
     imp = imp->parent;
   if (imp == this)
@@ -16295,7 +16302,7 @@ module_state::read_imports (bytes_in &sec, cpp_reader 
*reader, line_maps *lmaps)
         module as this TU.  */
       if (imp && imp->is_partition () &&
          (!named_module_p ()
-          || (get_primary ((*modules)[0]) != get_primary (imp))))
+          || (get_primary (this_module ()) != get_primary (imp))))
        imp = NULL;
 
       if (!imp)
@@ -17327,7 +17334,7 @@ module_state::write_using_directives (elf_out *to, 
depset::hash &table,
 bool
 module_state::read_using_directives (unsigned num)
 {
-  if (!bitmap_bit_p ((*modules)[0]->imports, mod))
+  if (!bitmap_bit_p (this_module ()->imports, mod))
     {
       dump () && dump ("Ignoring using-directives because module %M "
                       "is not visible in this TU", this);
@@ -20550,7 +20557,7 @@ module_state::read_initial (cpp_reader *reader)
 
   /* Determine the module's number.  */
   gcc_checking_assert (mod == MODULE_UNKNOWN);
-  gcc_checking_assert (this != (*modules)[0]);
+  gcc_checking_assert (this != this_module ());
 
   {
     /* Allocate space in the entities array now -- that array must be
@@ -20901,7 +20908,7 @@ module_name (unsigned ix, bool header_ok)
 bitmap
 get_import_bitmap ()
 {
-  return (*modules)[0]->imports;
+  return this_module ()->imports;
 }
 
 /* Return the visible imports and path of instantiation for an
@@ -21141,7 +21148,7 @@ module_may_redeclare (tree olddecl, tree newdecl)
     // FIXME: Should we be checking this in more places on the scope chain?
     return true;
 
-  module_state *old_mod = (*modules)[0];
+  module_state *old_mod = this_module ();
   module_state *new_mod = old_mod;
 
   tree old_origin = get_originating_module_decl (decl);
@@ -21781,7 +21788,7 @@ direct_import (module_state *import, cpp_reader *reader)
     if (!import->do_import (reader, true))
       gcc_unreachable ();
 
-  (*modules)[0]->set_import (import, import->exported_p);
+  this_module ()->set_import (import, import->exported_p);
 
   if (import->loadedness < ML_LANGUAGE)
     {
@@ -21837,7 +21844,7 @@ declare_module (module_state *module, location_t 
from_loc, bool exporting_p,
 {
   gcc_assert (global_namespace == current_scope ());
 
-  module_state *current = (*modules)[0];
+  module_state *current = this_module ();
   if (module_purview_p () || module->loadedness > ML_CONFIG)
     {
       auto_diagnostic_group d;
@@ -21853,7 +21860,7 @@ declare_module (module_state *module, location_t 
from_loc, bool exporting_p,
       return;
     }
 
-  gcc_checking_assert (module->module_p);
+  gcc_checking_assert (module->is_module ());
   gcc_checking_assert (module->is_direct () && module->has_location ());
 
   /* Yer a module, 'arry.  */
@@ -22225,8 +22232,9 @@ name_pending_imports (cpp_reader *reader)
       gcc_checking_assert (module->is_direct ());
       if (!module->filename && !module->visited_p)
        {
-         bool export_p = (module->module_p
-                          && (module->is_partition () || module->exported_p));
+         bool export_p = (module->is_module ()
+                          && (module->is_partition ()
+                              || module->is_exported ()));
 
          Cody::Flags flags = Cody::Flags::None;
          if (flag_preprocess_only
@@ -22357,8 +22365,8 @@ preprocess_module (module_state *module, location_t 
from_loc,
          for (unsigned ix = 0; ix != pending_imports->length (); ix++)
            {
              auto *import = (*pending_imports)[ix];
-             if (!(import->module_p
-                   && (import->is_partition () || import->exported_p))
+             if (!(import->is_module ()
+                   && (import->is_partition () || import->is_exported ()))
                  && import->loadedness == ML_NONE
                  && (import->is_header () || !flag_preprocess_only))
                {
@@ -22757,7 +22765,7 @@ finish_module_processing (cpp_reader *reader)
   if (header_module_p ())
     module_kind &= ~MK_EXPORTING;
 
-  if (!modules || !(*modules)[0]->name)
+  if (!modules || !this_module ()->name)
     {
       if (flag_module_only)
        warning (0, "%<-fmodule-only%> used for non-interface");
@@ -22776,7 +22784,7 @@ finish_module_processing (cpp_reader *reader)
       /* We write to a tmpname, and then atomically rename.  */
       char *cmi_name = NULL;
       char *tmp_name = NULL;
-      module_state *state = (*modules)[0];
+      module_state *state = this_module ();
 
       unsigned n = dump.push (state);
       state->announce ("creating");
@@ -22860,7 +22868,7 @@ late_finish_module (cpp_reader *reader,  
module_processing_cookie *cookie,
 {
   timevar_start (TV_MODULE_EXPORT);
 
-  module_state *state = (*modules)[0];
+  module_state *state = this_module ();
   unsigned n = dump.push (state);
   state->announce ("finishing");
 
-- 
2.51.0

Reply via email to