소스 검색

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@365153 91177308-0d34-0410-b5e6-96231b3b80d8
Vassil Vassilev 6 년 전
부모
커밋
794aa0aa0d
2개의 변경된 파일46개의 추가작업 그리고 0개의 파일을 삭제
  1. 34 0
      include/clang/Lex/PPCallbacks.h
  2. 12 0
      lib/Lex/PPLexerChange.cpp

+ 34 - 0
include/clang/Lex/PPCallbacks.h

@@ -132,6 +132,28 @@ public:
                                   SrcMgr::CharacteristicKind FileType) {
                                   SrcMgr::CharacteristicKind FileType) {
   }
   }
 
 
+  /// Callback invoked whenever a submodule was entered.
+  ///
+  /// \param M The submodule we have entered.
+  ///
+  /// \param ImportLoc The location of import directive token.
+  ///
+  /// \param ForPragma If entering from pragma directive.
+  ///
+  virtual void EnteredSubmodule(Module *M, SourceLocation ImportLoc,
+                                bool ForPragma) { }
+
+  /// Callback invoked whenever a submodule was left.
+  ///
+  /// \param M The submodule we have left.
+  ///
+  /// \param ImportLoc The location of import directive token.
+  ///
+  /// \param ForPragma If entering from pragma directive.
+  ///
+  virtual void LeftSubmodule(Module *M, SourceLocation ImportLoc,
+                             bool ForPragma) { }
+
   /// Callback invoked whenever there was an explicit module-import
   /// Callback invoked whenever there was an explicit module-import
   /// syntax.
   /// syntax.
   ///
   ///
@@ -395,6 +417,18 @@ public:
                                Imported, FileType);
                                Imported, FileType);
   }
   }
 
 
+  void EnteredSubmodule(Module *M, SourceLocation ImportLoc,
+                        bool ForPragma) override {
+    First->EnteredSubmodule(M, ImportLoc, ForPragma);
+    Second->EnteredSubmodule(M, ImportLoc, ForPragma);
+  }
+
+  void LeftSubmodule(Module *M, SourceLocation ImportLoc,
+                     bool ForPragma) override {
+    First->LeftSubmodule(M, ImportLoc, ForPragma);
+    Second->LeftSubmodule(M, ImportLoc, ForPragma);
+  }
+
   void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path,
   void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path,
                     const Module *Imported) override {
                     const Module *Imported) override {
     First->moduleImport(ImportLoc, Path, Imported);
     First->moduleImport(ImportLoc, Path, Imported);

+ 12 - 0
lib/Lex/PPLexerChange.cpp

@@ -647,6 +647,8 @@ void Preprocessor::EnterSubmodule(Module *M, SourceLocation ImportLoc,
     BuildingSubmoduleStack.push_back(
     BuildingSubmoduleStack.push_back(
         BuildingSubmoduleInfo(M, ImportLoc, ForPragma, CurSubmoduleState,
         BuildingSubmoduleInfo(M, ImportLoc, ForPragma, CurSubmoduleState,
                               PendingModuleMacroNames.size()));
                               PendingModuleMacroNames.size()));
+    if (Callbacks)
+      Callbacks->EnteredSubmodule(M, ImportLoc, ForPragma);
     return;
     return;
   }
   }
 
 
@@ -691,6 +693,9 @@ void Preprocessor::EnterSubmodule(Module *M, SourceLocation ImportLoc,
       BuildingSubmoduleInfo(M, ImportLoc, ForPragma, CurSubmoduleState,
       BuildingSubmoduleInfo(M, ImportLoc, ForPragma, CurSubmoduleState,
                             PendingModuleMacroNames.size()));
                             PendingModuleMacroNames.size()));
 
 
+  if (Callbacks)
+    Callbacks->EnteredSubmodule(M, ImportLoc, ForPragma);
+
   // Switch to this submodule as the current submodule.
   // Switch to this submodule as the current submodule.
   CurSubmoduleState = &State;
   CurSubmoduleState = &State;
 
 
@@ -731,6 +736,10 @@ Module *Preprocessor::LeaveSubmodule(bool ForPragma) {
     // are tracking macro visibility, don't build any, and preserve the list
     // are tracking macro visibility, don't build any, and preserve the list
     // of pending names for the surrounding submodule.
     // of pending names for the surrounding submodule.
     BuildingSubmoduleStack.pop_back();
     BuildingSubmoduleStack.pop_back();
+
+    if (Callbacks)
+      Callbacks->LeftSubmodule(LeavingMod, ImportLoc, ForPragma);
+
     makeModuleVisible(LeavingMod, ImportLoc);
     makeModuleVisible(LeavingMod, ImportLoc);
     return LeavingMod;
     return LeavingMod;
   }
   }
@@ -815,6 +824,9 @@ Module *Preprocessor::LeaveSubmodule(bool ForPragma) {
 
 
   BuildingSubmoduleStack.pop_back();
   BuildingSubmoduleStack.pop_back();
 
 
+  if (Callbacks)
+    Callbacks->LeftSubmodule(LeavingMod, ImportLoc, ForPragma);
+
   // A nested #include makes the included submodule visible.
   // A nested #include makes the included submodule visible.
   makeModuleVisible(LeavingMod, ImportLoc);
   makeModuleVisible(LeavingMod, ImportLoc);
   return LeavingMod;
   return LeavingMod;