summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang-tools-extra/clangd/SourceCode.cpp6
-rw-r--r--clang-tools-extra/clangd/SourceCode.h3
-rw-r--r--clang-tools-extra/clangd/XRefs.cpp32
-rw-r--r--clang-tools-extra/clangd/refactor/Rename.cpp5
4 files changed, 26 insertions, 20 deletions
diff --git a/clang-tools-extra/clangd/SourceCode.cpp b/clang-tools-extra/clangd/SourceCode.cpp
index 42910163bd9..812e42a7a2a 100644
--- a/clang-tools-extra/clangd/SourceCode.cpp
+++ b/clang-tools-extra/clangd/SourceCode.cpp
@@ -250,7 +250,7 @@ SourceLocation getBeginningOfIdentifier(const Position &Pos,
// location is correct for both!
SourceLocation InputLoc = SM.getComposedLoc(FID, *Offset);
if (*Offset == 0) // Case 1 or 3.
- return SM.getMacroArgExpandedLocation(InputLoc);
+ return InputLoc;
SourceLocation Before = SM.getComposedLoc(FID, *Offset - 1);
Before = Lexer::GetBeginningOfToken(Before, SM, LangOpts);
@@ -258,8 +258,8 @@ SourceLocation getBeginningOfIdentifier(const Position &Pos,
if (Before.isValid() &&
!Lexer::getRawToken(Before, Tok, SM, LangOpts, false) &&
Tok.is(tok::raw_identifier))
- return SM.getMacroArgExpandedLocation(Before); // Case 2.
- return SM.getMacroArgExpandedLocation(InputLoc); // Case 1 or 3.
+ return Before; // Case 2.
+ return InputLoc; // Case 1 or 3.
}
bool isValidFileRange(const SourceManager &Mgr, SourceRange R) {
diff --git a/clang-tools-extra/clangd/SourceCode.h b/clang-tools-extra/clangd/SourceCode.h
index 5f27ee2be21..81b4672b184 100644
--- a/clang-tools-extra/clangd/SourceCode.h
+++ b/clang-tools-extra/clangd/SourceCode.h
@@ -77,7 +77,8 @@ llvm::Expected<SourceLocation> sourceLocationInMainFile(const SourceManager &SM,
/// Get the beginning SourceLocation at a specified \p Pos in the main file.
/// May be invalid if Pos is, or if there's no identifier.
-/// FIXME: this returns the macro-expansion location, but it shouldn't.
+/// The returned position is in the main file, callers may prefer to
+/// obtain the macro expansion location.
SourceLocation getBeginningOfIdentifier(const Position &Pos,
const SourceManager &SM,
const LangOptions &LangOpts);
diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp
index b21987e6a5a..bc2c222a28c 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -255,8 +255,9 @@ std::vector<LocatedSymbol> locateSymbolAt(ParsedAST &AST, Position Pos,
}
}
- SourceLocation SourceLocationBeg = getBeginningOfIdentifier(
- Pos, AST.getSourceManager(), AST.getASTContext().getLangOpts());
+ SourceLocation SourceLocationBeg =
+ SM.getMacroArgExpandedLocation(getBeginningOfIdentifier(
+ Pos, AST.getSourceManager(), AST.getASTContext().getLangOpts()));
// Macros are simple: there's no declaration/definition distinction.
// As a consequence, there's no need to look them up in the index either.
@@ -409,10 +410,11 @@ std::vector<DocumentHighlight> findDocumentHighlights(ParsedAST &AST,
Position Pos) {
const SourceManager &SM = AST.getSourceManager();
// FIXME: show references to macro within file?
- auto References = findRefs(
- getDeclAtPosition(AST, getBeginningOfIdentifier(
- Pos, SM, AST.getASTContext().getLangOpts())),
- AST);
+ auto References =
+ findRefs(getDeclAtPosition(
+ AST, SM.getMacroArgExpandedLocation(getBeginningOfIdentifier(
+ Pos, SM, AST.getASTContext().getLangOpts()))),
+ AST);
// FIXME: we may get multiple DocumentHighlights with the same location and
// different kinds, deduplicate them.
@@ -875,9 +877,10 @@ bool hasDeducedType(ParsedAST &AST, SourceLocation SourceLocationBeg) {
llvm::Optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
format::FormatStyle Style,
const SymbolIndex *Index) {
+ const SourceManager &SM = AST.getSourceManager();
llvm::Optional<HoverInfo> HI;
- SourceLocation SourceLocationBeg = getBeginningOfIdentifier(
- Pos, AST.getSourceManager(), AST.getASTContext().getLangOpts());
+ SourceLocation SourceLocationBeg = SM.getMacroArgExpandedLocation(
+ getBeginningOfIdentifier(Pos, SM, AST.getASTContext().getLangOpts()));
if (auto M = locateMacroAt(SourceLocationBeg, AST.getPreprocessor())) {
HI = getHoverContents(*M, AST);
@@ -919,8 +922,8 @@ std::vector<Location> findReferences(ParsedAST &AST, Position Pos,
elog("Failed to get a path for the main file, so no references");
return Results;
}
- auto Loc =
- getBeginningOfIdentifier(Pos, SM, AST.getASTContext().getLangOpts());
+ auto Loc = SM.getMacroArgExpandedLocation(
+ getBeginningOfIdentifier(Pos, SM, AST.getASTContext().getLangOpts()));
// TODO: should we handle macros, too?
auto Decls = getDeclAtPosition(AST, Loc);
@@ -976,8 +979,8 @@ std::vector<Location> findReferences(ParsedAST &AST, Position Pos,
std::vector<SymbolDetails> getSymbolInfo(ParsedAST &AST, Position Pos) {
const SourceManager &SM = AST.getSourceManager();
- auto Loc =
- getBeginningOfIdentifier(Pos, SM, AST.getASTContext().getLangOpts());
+ auto Loc = SM.getMacroArgExpandedLocation(
+ getBeginningOfIdentifier(Pos, SM, AST.getASTContext().getLangOpts()));
std::vector<SymbolDetails> Results;
@@ -1147,8 +1150,9 @@ static void fillSuperTypes(const CXXRecordDecl &CXXRD, ASTContext &ASTCtx,
}
const CXXRecordDecl *findRecordTypeAt(ParsedAST &AST, Position Pos) {
- SourceLocation SourceLocationBeg = getBeginningOfIdentifier(
- Pos, AST.getSourceManager(), AST.getASTContext().getLangOpts());
+ const SourceManager &SM = AST.getSourceManager();
+ SourceLocation SourceLocationBeg = SM.getMacroArgExpandedLocation(
+ getBeginningOfIdentifier(Pos, SM, AST.getASTContext().getLangOpts()));
auto Decls = getDeclAtPosition(AST, SourceLocationBeg);
if (Decls.empty())
return nullptr;
diff --git a/clang-tools-extra/clangd/refactor/Rename.cpp b/clang-tools-extra/clangd/refactor/Rename.cpp
index 306c804bb59..770064fc613 100644
--- a/clang-tools-extra/clangd/refactor/Rename.cpp
+++ b/clang-tools-extra/clangd/refactor/Rename.cpp
@@ -153,8 +153,9 @@ findOccurrencesWithinFile(ParsedAST &AST, const NamedDecl *RenameDecl) {
llvm::Expected<tooling::Replacements>
renameWithinFile(ParsedAST &AST, llvm::StringRef File, Position Pos,
llvm::StringRef NewName, const SymbolIndex *Index) {
- SourceLocation SourceLocationBeg = getBeginningOfIdentifier(
- Pos, AST.getSourceManager(), AST.getASTContext().getLangOpts());
+ const SourceManager &SM = AST.getSourceManager();
+ SourceLocation SourceLocationBeg = SM.getMacroArgExpandedLocation(
+ getBeginningOfIdentifier(Pos, SM, AST.getASTContext().getLangOpts()));
// FIXME: renaming macros is not supported yet, the macro-handling code should
// be moved to rename tooling library.
if (locateMacroAt(SourceLocationBeg, AST.getPreprocessor()))
OpenPOWER on IntegriCloud