[clang][lex] NFC: Use FileEntryRef in PreprocessorLexer::getFileEntry()
authorJan Svoboda <jan_svoboda@apple.com>
Fri, 15 Apr 2022 12:48:34 +0000 (14:48 +0200)
committerJan Svoboda <jan_svoboda@apple.com>
Fri, 15 Apr 2022 13:16:17 +0000 (15:16 +0200)
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

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

index b43197a..356b8c4 100644 (file)
@@ -165,7 +165,7 @@ public:
 
   /// 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).
index 5f6f4a1..23c80d3 100644 (file)
@@ -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());
 }
index 9d29594..c1492ff 100644 (file)
@@ -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);