Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions clang-tools-extra/clangd/CollectMacros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ namespace clang {
namespace clangd {

Range MacroOccurrence::toRange(const SourceManager &SM) const {
auto MainFile = SM.getMainFileID();
return halfOpenToRange(
SM, syntax::FileRange(MainFile, StartOffset, EndOffset).toCharRange(SM));
SM, syntax::FileRange(FID, StartOffset, EndOffset).toCharRange(SM));
}

void CollectMainFileMacros::add(const Token &MacroNameTok, const MacroInfo *MI,
Expand All @@ -34,12 +33,13 @@ void CollectMainFileMacros::add(const Token &MacroNameTok, const MacroInfo *MI,

auto Name = MacroNameTok.getIdentifierInfo()->getName();
Out.Names.insert(Name);
size_t Start = SM.getFileOffset(Loc);
auto [FID, Start] = SM.getDecomposedLoc(Loc);
size_t End = SM.getFileOffset(MacroNameTok.getEndLoc());
if (auto SID = getSymbolID(Name, MI, SM))
Out.MacroRefs[SID].push_back({Start, End, IsDefinition, InIfCondition});
Out.MacroRefs[SID].push_back(
{FID, Start, End, IsDefinition, InIfCondition});
else
Out.UnknownMacros.push_back({Start, End, IsDefinition, InIfCondition});
Out.UnknownMacros.push_back({FID, Start, End, IsDefinition, InIfCondition});
}

void CollectMainFileMacros::FileChanged(SourceLocation Loc, FileChangeReason,
Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/clangd/CollectMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace clangd {

struct MacroOccurrence {
// Half-open range (end offset is exclusive) inside the main file.
FileID FID;
size_t StartOffset;
size_t EndOffset;

Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/IncludeCleaner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ collectMacroReferences(ParsedAST &AST) {
std::vector<include_cleaner::SymbolReference> Macros;
for (const auto &[_, Refs] : AST.getMacros().MacroRefs) {
for (const auto &Ref : Refs) {
auto Loc = SM.getComposedLoc(SM.getMainFileID(), Ref.StartOffset);
auto Loc = SM.getComposedLoc(Ref.FID, Ref.StartOffset);
const auto *Tok = AST.getTokens().spelledTokenContaining(Loc);
if (!Tok)
continue;
Expand Down