This patch extracts the code that searches for a file id from translateFile to findFileIDsForFile to allow the users to map from one file entry to multiple FileIDs.
Will be used as a basis for a clang-rename fix in https://reviews.llvm.org/D50801.
Details
Diff Detail
- Repository
- rC Clang
Event Timeline
include/clang/Basic/SourceManager.h | ||
---|---|---|
1551 | nit: put this closer to the closely related translateFile? | |
1557 | Callback pattern seems uncommon in LLVM/Clang. I'd suggest making this return a set of FileIDs and put the callback-based function as a helper (shared by this and translateFile)in the implementation. |
Address review comments.
include/clang/Basic/SourceManager.h | ||
---|---|---|
1557 | I created a helper, but unfortunately it needs to be a member of SourceManager as FileID::get is private. |
Address review comments
lib/Basic/SourceManager.cpp | ||
---|---|---|
1705 | I don't really need this for my use case. |
lib/Basic/SourceManager.cpp | ||
---|---|---|
1705 | But it's not clear from the interface AFAICT. We should either handle this case (maybe controlled with a flag), or make it clear in the API (with a different name or documentation). |
lib/Basic/SourceManager.cpp | ||
---|---|---|
1705 | Hmm, I think that would be better. I pulled that code into the findFileIDsForFile helper function, so we can call it in two modes now. It's probably good to do that check just in case in the new API too, so it does that check as well. |
lib/Basic/SourceManager.cpp | ||
---|---|---|
1626 | Should we check FileID::get(I) is valid? | |
1628 | The conditions here are pretty hard to follow and reason about. Could we maybe split them (some documentation would also help)? | |
1628 | In the original version, file system updates are checked last (after modules). Any reason to move it before modules? Also, it seems that this code path could also be run when FileIDabove is invalid? So I wonder whether else if is correct here. |
Remove dead code for filesystem update fileID matching.
lib/Basic/SourceManager.cpp | ||
---|---|---|
1626 | That's not really necessary. The FileID we get should be valid as a local SLoc entry should have a corresponding FileID. The SLoc 0 is not a File loc entry so we can never get FileID::get(0) here. | |
1628 | I just realized that the original file system code has never been executed and was just dead code! If we take a look at this logic: for (unsigned I = 0, N = local_sloc_entry_size(); I != N; ++I) { FileID IFileID; IFileID.ID = I; const SLocEntry &SLoc = getSLocEntry(IFileID, &Invalid); if (Invalid) return false; You'll notice that the loop starts iterating at 0. Get SLocEntry is called with FileID 0, which sets the Invalid flag to true. Then we simply return, so the loop never reached the code below. Looks like it's a regression that happened years ago. I removed this code for now, but I'll reinstate it correctly in a follow-up patch. |
nit: put this closer to the closely related translateFile?