[PATCH] D89834: FileManager: Improve the FileEntryRef API and add MaybeFileEntryRef

Duncan P. N. Exon Smith via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 20 16:19:27 PDT 2020


dexonsmith created this revision.
dexonsmith added reviewers: JDevlieghere, arphaman, teemperor.
Herald added subscribers: llvm-commits, ributzka, mgorny.
Herald added a project: LLVM.
dexonsmith requested review of this revision.

Make a few changes to the `FileEntryRef` API in preparation for
propagating it enough to remove `FileEntry::getName()`.

- Change `operator==` to compare the underlying `FileEntry*`, ignoring any difference to the spelling of the name. There were 0 users of the existing function because it's not useful. This avoids adding noisy code where `getFileEntry()` is used pervasively to compare equality. In case comparing the named reference becomes important, add (and test) the API now called `isSameRef`.
- Add `MaybeFileEntryRef`, which is a pointer-sized version of `Optional<FileEntryRef>` that is designed to replace fields that are currently `FileEntry*`. To avoid code duplication, the guts of `FileEntryRef` were moved to a common base class, `FileEntryRefBase`. Besides interoperation with `Optional`, this calls exposes `getName()` (`Optional` version) and `getFileEntry()` (pointer version).
- Add implicit conversions to `FileEntry*` to allow functions currently returning `const FileEntry*` to be updated to `FileEntryRef` or `MaybeFileEntryRef` without requiring all callers to be updated in the same step. This helps avoid both (a) massive patches where many fields and locals are updated simultaneously and (b) noisy incremental patches where the first patch adds `getFileEntry()` at call sites and the second patch removes it.
- Add various `operator==` for easy interoperation.
- Remove the `const` from the return of `FileEntryRef::getName`.
- As a drive-by cleanup, delete the unused `FileEntry::isOpenForTests`.

Note that there are still `FileEntry` APIs that aren't wrapped and I
plan to deal with these separately / incrementally, as they are needed.


https://reviews.llvm.org/D89834

Files:
  clang/include/clang/Basic/FileEntry.h
  clang/include/clang/Basic/FileManager.h
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/FileEntry.cpp
  llvm/include/llvm/Support/FileSystem.h
  llvm/include/llvm/Support/FileSystem/UniqueID.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89834.299502.patch
Type: text/x-patch
Size: 15580 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201020/37d7205b/attachment-0001.bin>


More information about the cfe-commits mailing list