[clang] e19f352 - [clang][lex] NFCI: Use DirectoryEntryRef in Preprocessor::MainFileDir

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Tue May 30 13:54:20 PDT 2023


Author: Jan Svoboda
Date: 2023-05-30T13:54:06-07:00
New Revision: e19f352beee72d8fc30d9a5366eadd2372719fa3

URL: https://github.com/llvm/llvm-project/commit/e19f352beee72d8fc30d9a5366eadd2372719fa3
DIFF: https://github.com/llvm/llvm-project/commit/e19f352beee72d8fc30d9a5366eadd2372719fa3.diff

LOG: [clang][lex] NFCI: Use DirectoryEntryRef in Preprocessor::MainFileDir

This patch changes the type of `Preprocessor::MainFileDir` from `const DirectoryEntry *` to `Optional<DirectoryEntryRef>` in order to remove some calls to the deprecated `DirectoryEntry::getName()`.

Depends on D127658.

Reviewed By: bnbarham

Differential Revision: https://reviews.llvm.org/D127660

Added: 
    

Modified: 
    clang/include/clang/Lex/Preprocessor.h
    clang/lib/Frontend/FrontendAction.cpp
    clang/lib/Lex/PPDirectives.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h
index 8bdaf25e9b87..8fbc002059a8 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -625,7 +625,7 @@ class Preprocessor {
   /// The directory that the main file should be considered to occupy,
   /// if it does not correspond to a real file (as happens when building a
   /// module).
-  const DirectoryEntry *MainFileDir = nullptr;
+  OptionalDirectoryEntryRef MainFileDir;
 
   /// The number of bytes that we will initially skip when entering the
   /// main file, along with a flag that indicates whether skipping this number
@@ -2012,9 +2012,7 @@ class Preprocessor {
 
   /// Set the directory in which the main file should be considered
   /// to have been found, if it is not a real file.
-  void setMainFileDir(const DirectoryEntry *Dir) {
-    MainFileDir = Dir;
-  }
+  void setMainFileDir(DirectoryEntryRef Dir) { MainFileDir = Dir; }
 
   /// Instruct the preprocessor to skip part of the main source file.
   ///

diff  --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp
index 77d03c406222..a8dcdb44b08d 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -511,7 +511,7 @@ static Module *prepareToBuildModule(CompilerInstance &CI,
 
   // Inform the preprocessor that includes from within the input buffer should
   // be resolved relative to the build directory of the module map file.
-  CI.getPreprocessor().setMainFileDir(M->Directory);
+  CI.getPreprocessor().setMainFileDir(*M->Directory);
 
   // If the module was inferred from a 
diff erent module map (via an expanded
   // umbrella module definition), track that fact.

diff  --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 2066c61748ef..1a5398e3adea 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -956,7 +956,7 @@ OptionalFileEntryRef Preprocessor::LookupFile(
     // map file.
     if (!FileEnt) {
       if (FID == SourceMgr.getMainFileID() && MainFileDir) {
-        Includers.push_back(std::make_pair(nullptr, MainFileDir));
+        Includers.push_back(std::make_pair(nullptr, *MainFileDir));
         BuildSystemModule = getCurrentModule()->IsSystem;
       } else if ((FileEnt =
                     SourceMgr.getFileEntryForID(SourceMgr.getMainFileID())))


        


More information about the cfe-commits mailing list