]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++/modules: Clean up include translation [PR110980]
authorNathaniel Shead <nathanieloshead@gmail.com>
Thu, 22 Aug 2024 11:04:11 +0000 (21:04 +1000)
committerNathaniel Shead <nathanieloshead@gmail.com>
Tue, 27 Aug 2024 01:03:14 +0000 (11:03 +1000)
Currently the handling of include translation is confusing to read,
using a tri-state integer without much clarity on what different states
mean.  This patch cleans this up to use explicit enumerators indicating
the different possible states instead, and fixes a bug where the option
'-flang-info-include-translate' ended being accidentally unusable.

PR c++/110980

gcc/cp/ChangeLog:

* module.cc (maybe_translate_include): Clean up.

gcc/testsuite/ChangeLog:

* g++.dg/modules/inc-xlate-2_a.H: New test.
* g++.dg/modules/inc-xlate-2_b.H: New test.
* g++.dg/modules/inc-xlate-3.h: New test.
* g++.dg/modules/inc-xlate-3_a.H: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
gcc/cp/module.cc
gcc/testsuite/g++.dg/modules/inc-xlate-2_a.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/inc-xlate-2_b.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/inc-xlate-3.h [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/inc-xlate-3_a.H [new file with mode: 0644]

index 07477d33955c7eb154fb1a1b5405f301c32ac397..4cd7e1c284b872a081a6a4b81b738edaa30cec0e 100644 (file)
@@ -20118,15 +20118,19 @@ maybe_translate_include (cpp_reader *reader, line_maps *lmaps, location_t loc,
   size_t len = strlen (path);
   path = canonicalize_header_name (NULL, loc, true, path, len);
   auto packet = mapper->IncludeTranslate (path, Cody::Flags::None, len);
-  int xlate = false;
+
+  enum class xlate_kind {
+    unknown, text, import,
+  } translate = xlate_kind::unknown;
+
   if (packet.GetCode () == Cody::Client::PC_BOOL)
-    xlate = -int (packet.GetInteger ());
+    translate = packet.GetInteger () ? xlate_kind::text : xlate_kind::unknown;
   else if (packet.GetCode () == Cody::Client::PC_PATHNAME)
     {
       /* Record the CMI name for when we do the import.  */
       module_state *import = get_module (build_string (len, path));
       import->set_filename (packet);
-      xlate = +1;
+      translate = xlate_kind::import;
     }
   else
     {
@@ -20136,9 +20140,9 @@ maybe_translate_include (cpp_reader *reader, line_maps *lmaps, location_t loc,
     }
 
   bool note = false;
-  if (note_include_translate_yes && xlate > 1)
+  if (note_include_translate_yes && translate == xlate_kind::import)
     note = true;
-  else if (note_include_translate_no && xlate == 0)
+  else if (note_include_translate_no && translate == xlate_kind::unknown)
     note = true;
   else if (note_includes)
     /* We do not expect the note_includes vector to be large, so O(N)
@@ -20148,15 +20152,16 @@ maybe_translate_include (cpp_reader *reader, line_maps *lmaps, location_t loc,
        note = true;
 
   if (note)
-    inform (loc, xlate
+    inform (loc, translate == xlate_kind::import
            ? G_("include %qs translated to import")
-           : G_("include %qs processed textually") , path);
+           : G_("include %qs processed textually"), path);
 
-  dump () && dump (xlate ? "Translating include to import"
+  dump () && dump (translate == xlate_kind::import
+                  ? "Translating include to import"
                   : "Keeping include as include");
   dump.pop (0);
 
-  if (!(xlate > 0))
+  if (translate != xlate_kind::import)
     return nullptr;
   
   /* Create the translation text.  */
diff --git a/gcc/testsuite/g++.dg/modules/inc-xlate-2_a.H b/gcc/testsuite/g++.dg/modules/inc-xlate-2_a.H
new file mode 100644 (file)
index 0000000..d6a4866
--- /dev/null
@@ -0,0 +1,3 @@
+// PR c++/110980
+// { dg-additional-options "-fmodule-header" }
+// { dg-module-cmi {} }
diff --git a/gcc/testsuite/g++.dg/modules/inc-xlate-2_b.H b/gcc/testsuite/g++.dg/modules/inc-xlate-2_b.H
new file mode 100644 (file)
index 0000000..f04dd43
--- /dev/null
@@ -0,0 +1,5 @@
+// PR c++/110980
+// { dg-additional-options "-fmodule-header -flang-info-include-translate" }
+// { dg-module-cmi {} }
+
+#include "inc-xlate-2_a.H"  // { dg-message "translated to import" }
diff --git a/gcc/testsuite/g++.dg/modules/inc-xlate-3.h b/gcc/testsuite/g++.dg/modules/inc-xlate-3.h
new file mode 100644 (file)
index 0000000..c0584ba
--- /dev/null
@@ -0,0 +1,2 @@
+// PR c++/110980
+// Just an empty file to be an include target.
diff --git a/gcc/testsuite/g++.dg/modules/inc-xlate-3_a.H b/gcc/testsuite/g++.dg/modules/inc-xlate-3_a.H
new file mode 100644 (file)
index 0000000..4777208
--- /dev/null
@@ -0,0 +1,5 @@
+// PR c++/110980
+// { dg-additional-options "-fmodule-header -flang-info-include-translate-not" }
+// { dg-module-cmi {} }
+
+#include "inc-xlate-3.h"  // { dg-message "processed textually" }