[PATCH] D62293: [modules] Add PP callbacks for entering and leaving a submodule.
v.g.vassilev closed this revision. v.g.vassilev added a comment. Herald added subscribers: wuzish, MaskRay. r365153. Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D62293/new/ https://reviews.llvm.org/D62293 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D62293: [modules] Add PP callbacks for entering and leaving a submodule.
v.g.vassilev updated this revision to Diff 206887. v.g.vassilev marked an inline comment as done. v.g.vassilev added a comment. Add comments, add missing callbacks. Thanks Richard! Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D62293/new/ 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 @@ -647,6 +647,8 @@ BuildingSubmoduleStack.push_back( BuildingSubmoduleInfo(M, ImportLoc, ForPragma, CurSubmoduleState, PendingModuleMacroNames.size())); +if (Callbacks) + Callbacks->EnteredSubmodule(M, ImportLoc, ForPragma); return; } @@ -691,6 +693,9 @@ BuildingSubmoduleInfo(M, ImportLoc, ForPragma, CurSubmoduleState, PendingModuleMacroNames.size())); + if (Callbacks) +Callbacks->EnteredSubmodule(M, ImportLoc, ForPragma); + // Switch to this submodule as the current submodule. CurSubmoduleState = @@ -731,6 +736,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(LeavingMod, ImportLoc, ForPragma); + makeModuleVisible(LeavingMod, ImportLoc); return LeavingMod; } @@ -815,6 +824,9 @@ BuildingSubmoduleStack.pop_back(); + if (Callbacks) +Callbacks->LeftSubmodule(LeavingMod, ImportLoc, 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 @@ -132,6 +132,28 @@ 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 /// syntax. /// @@ -395,6 +417,18 @@ 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, const Module *Imported) override { First->moduleImport(ImportLoc, Path, Imported); Index: lib/Lex/PPLexerChange.cpp === --- lib/Lex/PPLexerChange.cpp +++ lib/Lex/PPLexerChange.cpp @@ -647,6 +647,8 @@ BuildingSubmoduleStack.push_back( BuildingSubmoduleInfo(M, ImportLoc, ForPragma, CurSubmoduleState, PendingModuleMacroNames.size())); +if (Callbacks) + Callbacks->EnteredSubmodule(M, ImportLoc, ForPragma); return; } @@ -691,6 +693,9 @@ BuildingSubmoduleInfo(M, ImportLoc, ForPragma, CurSubmoduleState, PendingModuleMacroNames.size())); + if (Callbacks) +Callbacks->EnteredSubmodule(M, ImportLoc, ForPragma); + // Switch to this submodule as the current submodule. CurSubmoduleState = @@ -731,6 +736,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(LeavingMod, ImportLoc, ForPragma); + makeModuleVisible(LeavingMod, ImportLoc); return LeavingMod; } @@ -815,6 +824,9 @@ BuildingSubmoduleStack.pop_back(); + if (Callbacks) +Callbacks->LeftSubmodule(LeavingMod, ImportLoc, ForPragma); + // A nested #include makes the included submodule visible.
[PATCH] D62293: [modules] Add PP callbacks for entering and leaving a submodule.
rsmith added a comment. `PPCallbacks` seems to be missing the addition of `EnteredSubmodule` and `LeftSubmodule`; `PPChainedCallbacks` seems to be missing the addition of `LeftSubmodule`. Generally this seems reasonable. Comment at: lib/Lex/PPLexerChange.cpp:783 +if (Callbacks) + Callbacks->LeftSubmodule(ForPragma); + Would it be useful to pass in the module (and maybe the import location) here? Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D62293/new/ https://reviews.llvm.org/D62293 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D62293: [modules] Add PP callbacks for entering and leaving a submodule.
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 = @@ -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); 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 = @@ -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); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits