[clang] [Clang] Implement P3034R1 Module Declarations Shouldn’t be Macros (PR #90574)

via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 18 01:52:27 PDT 2024


================
@@ -3071,6 +3073,45 @@ struct EmbedAnnotationData {
 /// Registry of pragma handlers added by plugins
 using PragmaHandlerRegistry = llvm::Registry<PragmaHandler>;
 
+/// Module/Partition name token sequance.
+///
+///     module-name:
+///           module-name-qualifier[opt] identifier
+///
+///     module-name-qualifier
+///           module-name-qualifier[opt] identifier .
+class ModuleNameInfo {
+  friend class Preprocessor;
+  ArrayRef<Token> ModuleName;
+  ArrayRef<Token> PartitionName;
+
+  ModuleNameInfo(ArrayRef<Token> Module, ArrayRef<Token> Partition)
+      : ModuleName(Module), PartitionName(Partition) {}
+
+public:
+  ArrayRef<Token> getTokens() const {
+    if (ModuleName.empty())
+      return PartitionName;
+    if (PartitionName.empty())
+      return ModuleName;
+    return ArrayRef(ModuleName.begin(), PartitionName.end());
----------------
cor3ntin wrote:

This is subtle.
It relies on the two source array being contiguous in memory
https://github.com/llvm/llvm-project/pull/90574/files#diff-e33e22703774cdd6fbed70f2c691485f818c168f0a2bb1d394b87a1c540b2df6R1285

We at least need a comment + `assert(Module.end() == Partition.begin());`

https://github.com/llvm/llvm-project/pull/90574


More information about the cfe-commits mailing list