[PATCH] D62293: [modules] Add PP callbacks for entering and leaving a submodule.

Vassil Vassilev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 23 02:08:28 PDT 2019


v.g.vassilev created this revision.
v.g.vassilev added reviewers: rsmith, bruno.
Herald added subscribers: jsji, dexonsmith, kbarton, nemanjai.
Herald added a project: clang.

Our usecase is that we would like to support making some modules visible (without corresponding #includes) while building a module.

Experimental implementation here: https://github.com/root-project/root/pull/3850/commits/cef39111ccff432e32db84952d0bb9b3aac8c7d5


Repository:
  rC Clang

https://reviews.llvm.org/D62293

Files:
  include/clang/Lex/PPCallbacks.h
  lib/Lex/PPLexerChange.cpp


Index: lib/Lex/PPLexerChange.cpp
===================================================================
--- lib/Lex/PPLexerChange.cpp
+++ lib/Lex/PPLexerChange.cpp
@@ -689,6 +689,8 @@
     BuildingSubmoduleStack.push_back(
         BuildingSubmoduleInfo(M, ImportLoc, ForPragma, CurSubmoduleState,
                               PendingModuleMacroNames.size()));
+    if (Callbacks)
+      Callbacks->EnteredSubmodule(M, ImportLoc, ForPragma);
     return;
   }
 
@@ -733,6 +735,9 @@
       BuildingSubmoduleInfo(M, ImportLoc, ForPragma, CurSubmoduleState,
                             PendingModuleMacroNames.size()));
 
+  if (Callbacks)
+    Callbacks->EnteredSubmodule(M, ImportLoc, ForPragma);
+
   // Switch to this submodule as the current submodule.
   CurSubmoduleState = &State;
 
@@ -773,6 +778,10 @@
     // are tracking macro visibility, don't build any, and preserve the list
     // of pending names for the surrounding submodule.
     BuildingSubmoduleStack.pop_back();
+
+    if (Callbacks)
+      Callbacks->LeftSubmodule(ForPragma);
+
     makeModuleVisible(LeavingMod, ImportLoc);
     return LeavingMod;
   }
@@ -857,6 +866,9 @@
 
   BuildingSubmoduleStack.pop_back();
 
+  if (Callbacks)
+    Callbacks->LeftSubmodule(ForPragma);
+
   // A nested #include makes the included submodule visible.
   makeModuleVisible(LeavingMod, ImportLoc);
   return LeavingMod;
Index: include/clang/Lex/PPCallbacks.h
===================================================================
--- include/clang/Lex/PPCallbacks.h
+++ include/clang/Lex/PPCallbacks.h
@@ -388,6 +388,13 @@
                                Imported, FileType);
   }
 
+  void EnteredSubmodule(Module *M, SourceLocation ImportLoc,
+                        bool ForPragma) override {
+    First->EnteredSubmodule(M, ImportLoc, ForPragma);
+    Second->EnteredSubmodule(M, ImportLoc, ForPragma);
+  }
+
+
   void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path,
                     const Module *Imported) override {
     First->moduleImport(ImportLoc, Path, Imported);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62293.200889.patch
Type: text/x-patch
Size: 2049 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190523/9c6f010d/attachment-0001.bin>


More information about the cfe-commits mailing list