[clang] 0b09b5d - [clang][lex] NFC: Use FileEntryRef in PreprocessorLexer::getFileEntry()

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 15 06:16:31 PDT 2022


Author: Jan Svoboda
Date: 2022-04-15T15:16:17+02:00
New Revision: 0b09b5d44837ea71c6bf017607b33f283c4417c6

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

LOG: [clang][lex] NFC: Use FileEntryRef in PreprocessorLexer::getFileEntry()

This patch changes the return type of `PreprocessorLexer::getFileEntry()` so that its clients may stop using the deprecated APIs of `FileEntry`.

Reviewed By: bnbarham

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

Added: 
    

Modified: 
    clang/include/clang/Lex/PreprocessorLexer.h
    clang/lib/Lex/PreprocessorLexer.cpp
    clang/lib/Sema/SemaCodeComplete.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Lex/PreprocessorLexer.h b/clang/include/clang/Lex/PreprocessorLexer.h
index b43197a6031cb..356b8c4098fd8 100644
--- a/clang/include/clang/Lex/PreprocessorLexer.h
+++ b/clang/include/clang/Lex/PreprocessorLexer.h
@@ -165,7 +165,7 @@ class PreprocessorLexer {
 
   /// getFileEntry - Return the FileEntry corresponding to this FileID.  Like
   /// getFileID(), this only works for lexers with attached preprocessors.
-  const FileEntry *getFileEntry() const;
+  OptionalFileEntryRefDegradesToFileEntryPtr getFileEntry() const;
 
   /// Iterator that traverses the current stack of preprocessor
   /// conditional directives (\#if/\#ifdef/\#ifndef).

diff  --git a/clang/lib/Lex/PreprocessorLexer.cpp b/clang/lib/Lex/PreprocessorLexer.cpp
index 5f6f4a13419be..23c80d375214c 100644
--- a/clang/lib/Lex/PreprocessorLexer.cpp
+++ b/clang/lib/Lex/PreprocessorLexer.cpp
@@ -47,6 +47,7 @@ void PreprocessorLexer::LexIncludeFilename(Token &FilenameTok) {
 
 /// getFileEntry - Return the FileEntry corresponding to this FileID.  Like
 /// getFileID(), this only works for lexers with attached preprocessors.
-const FileEntry *PreprocessorLexer::getFileEntry() const {
-  return PP->getSourceManager().getFileEntryForID(getFileID());
+OptionalFileEntryRefDegradesToFileEntryPtr
+PreprocessorLexer::getFileEntry() const {
+  return PP->getSourceManager().getFileEntryRefForID(getFileID());
 }

diff  --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index 9d295941234f7..c1492ff8aa33c 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -9972,7 +9972,7 @@ void Sema::CodeCompleteIncludedFile(llvm::StringRef Dir, bool Angled) {
   using llvm::make_range;
   if (!Angled) {
     // The current directory is on the include path for "quoted" includes.
-    auto *CurFile = PP.getCurrentFileLexer()->getFileEntry();
+    const FileEntry *CurFile = PP.getCurrentFileLexer()->getFileEntry();
     if (CurFile && CurFile->getDir())
       AddFilesFromIncludeDir(CurFile->getDir()->getName(), false,
                              DirectoryLookup::LT_NormalDir);


        


More information about the cfe-commits mailing list