Revert "[clangd] Handle PresumedLocations in IncludeCollector"
This reverts commit 4f7917c269d65cd3c85eddee19385861c4b8390c as it is
breaking windows build bots.
diff --git a/clang-tools-extra/clangd/Headers.cpp b/clang-tools-extra/clangd/Headers.cpp
index ffd6bd1..50c3759 100644
--- a/clang-tools-extra/clangd/Headers.cpp
+++ b/clang-tools-extra/clangd/Headers.cpp
@@ -10,8 +10,6 @@
#include "Compiler.h"
#include "SourceCode.h"
#include "support/Logger.h"
-#include "clang/Basic/SourceLocation.h"
-#include "clang/Basic/SourceManager.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/CompilerInvocation.h"
#include "clang/Frontend/FrontendActions.h"
@@ -23,11 +21,6 @@
namespace clangd {
namespace {
-bool isMainFile(llvm::StringRef FileName, const SourceManager &SM) {
- auto FE = SM.getFileManager().getFile(FileName);
- return FE && *FE == SM.getFileEntryForID(SM.getMainFileID());
-}
-
class RecordHeaders : public PPCallbacks {
public:
RecordHeaders(const SourceManager &SM, IncludeStructure *Out)
@@ -37,27 +30,11 @@
// in the main file are collected.
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
llvm::StringRef FileName, bool IsAngled,
- CharSourceRange /*FilenameRange*/,
- const FileEntry *File, llvm::StringRef /*SearchPath*/,
+ CharSourceRange FilenameRange, const FileEntry *File,
+ llvm::StringRef /*SearchPath*/,
llvm::StringRef /*RelativePath*/,
const Module * /*Imported*/,
SrcMgr::CharacteristicKind FileKind) override {
- auto MainFID = SM.getMainFileID();
- // If an include is part of the preamble patch, translate #line directives.
- if (InBuiltinFile) {
- auto Presumed = SM.getPresumedLoc(HashLoc);
- // Presumed locations will have an invalid file id when #line directive
- // changes the filename.
- if (Presumed.getFileID().isInvalid() &&
- isMainFile(Presumed.getFilename(), SM)) {
- // Now we'll hit the case below.
- HashLoc = SM.translateLineCol(MainFID, Presumed.getLine(),
- Presumed.getColumn());
- }
- }
-
- // Record main-file inclusions (including those mapped from the preamble
- // patch).
if (isInsideMainFile(HashLoc, SM)) {
Out->MainFileIncludes.emplace_back();
auto &Inc = Out->MainFileIncludes.back();
@@ -70,48 +47,21 @@
Inc.FileKind = FileKind;
Inc.Directive = IncludeTok.getIdentifierInfo()->getPPKeywordID();
}
-
- // Record include graph (not just for main-file includes)
if (File) {
auto *IncludingFileEntry = SM.getFileEntryForID(SM.getFileID(HashLoc));
if (!IncludingFileEntry) {
assert(SM.getBufferName(HashLoc).startswith("<") &&
"Expected #include location to be a file or <built-in>");
// Treat as if included from the main file.
- IncludingFileEntry = SM.getFileEntryForID(MainFID);
+ IncludingFileEntry = SM.getFileEntryForID(SM.getMainFileID());
}
Out->recordInclude(IncludingFileEntry->getName(), File->getName(),
File->tryGetRealPathName());
}
}
- void FileChanged(SourceLocation Loc, FileChangeReason Reason,
- SrcMgr::CharacteristicKind FileType,
- FileID PrevFID) override {
- switch (Reason) {
- case PPCallbacks::EnterFile:
- if (BuiltinFile.isInvalid() && SM.isWrittenInBuiltinFile(Loc)) {
- BuiltinFile = SM.getFileID(Loc);
- InBuiltinFile = true;
- }
- break;
- case PPCallbacks::ExitFile:
- if (PrevFID == BuiltinFile)
- InBuiltinFile = false;
- break;
- case PPCallbacks::RenameFile:
- case PPCallbacks::SystemHeaderPragma:
- break;
- }
- }
-
private:
const SourceManager &SM;
- // Set after entering the <built-in> file.
- FileID BuiltinFile;
- // Indicates whether <built-in> file is part of include stack.
- bool InBuiltinFile = false;
-
IncludeStructure *Out;
};