summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam McCall <sam.mccall@gmail.com>2019-05-28 21:52:34 +0000
committerSam McCall <sam.mccall@gmail.com>2019-05-28 21:52:34 +0000
commit81748bae47fdaf280877dfa8d7d309b88b848de9 (patch)
tree2efd5ac45da00951062811f02cec9f7e8cb8f90e
parente88173abc01b454f91cec54b50e58e67a5aed263 (diff)
downloadbcm5719-llvm-81748bae47fdaf280877dfa8d7d309b88b848de9.tar.gz
bcm5719-llvm-81748bae47fdaf280877dfa8d7d309b88b848de9.zip
[clangd] Add SourceManager accessor to ParsedAST. NFC
llvm-svn: 361883
-rw-r--r--clang-tools-extra/clangd/ClangdUnit.h7
-rw-r--r--clang-tools-extra/clangd/XRefs.cpp21
-rw-r--r--clang-tools-extra/clangd/refactor/Rename.cpp7
-rw-r--r--clang-tools-extra/clangd/refactor/Tweak.cpp2
-rw-r--r--clang-tools-extra/clangd/refactor/tweaks/RawStringLiteral.cpp5
-rw-r--r--clang-tools-extra/clangd/refactor/tweaks/SwapIfBranches.cpp2
-rw-r--r--clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp2
-rw-r--r--clang-tools-extra/clangd/unittests/SelectionTests.cpp2
-rw-r--r--clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp5
9 files changed, 27 insertions, 26 deletions
diff --git a/clang-tools-extra/clangd/ClangdUnit.h b/clang-tools-extra/clangd/ClangdUnit.h
index 042bb0d6a03..16246eb2784 100644
--- a/clang-tools-extra/clangd/ClangdUnit.h
+++ b/clang-tools-extra/clangd/ClangdUnit.h
@@ -95,6 +95,13 @@ public:
std::shared_ptr<Preprocessor> getPreprocessorPtr();
const Preprocessor &getPreprocessor() const;
+ SourceManager &getSourceManager() {
+ return getASTContext().getSourceManager();
+ }
+ const SourceManager &getSourceManager() const {
+ return getASTContext().getSourceManager();
+ }
+
/// This function returns top-level decls present in the main file of the AST.
/// The result does not include the decls that come from the preamble.
/// (These should be const, but RecursiveASTVisitor requires Decl*).
diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp
index e5e137df21f..4b9b95362c7 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -286,7 +286,7 @@ llvm::Optional<Location> makeLocation(ASTContext &AST, SourceLocation TokLoc,
std::vector<LocatedSymbol> locateSymbolAt(ParsedAST &AST, Position Pos,
const SymbolIndex *Index) {
- const auto &SM = AST.getASTContext().getSourceManager();
+ const auto &SM = AST.getSourceManager();
auto MainFilePath =
getCanonicalPath(SM.getFileEntryForID(SM.getMainFileID()), SM);
if (!MainFilePath) {
@@ -461,7 +461,7 @@ findRefs(const std::vector<const Decl *> &Decls, ParsedAST &AST) {
std::vector<DocumentHighlight> findDocumentHighlights(ParsedAST &AST,
Position Pos) {
- const SourceManager &SM = AST.getASTContext().getSourceManager();
+ const SourceManager &SM = AST.getSourceManager();
auto Symbols = getSymbolAtPosition(
AST, getBeginningOfIdentifier(AST, Pos, SM.getMainFileID()));
auto References = findRefs(Symbols.Decls, AST);
@@ -719,7 +719,7 @@ static HoverInfo getHoverContents(QualType T, const Decl *D,
/// Generate a \p Hover object given the macro \p MacroDecl.
static HoverInfo getHoverContents(MacroDecl Decl, ParsedAST &AST) {
HoverInfo HI;
- SourceManager &SM = AST.getASTContext().getSourceManager();
+ SourceManager &SM = AST.getSourceManager();
HI.Name = Decl.Name;
HI.Kind = indexSymbolKindToSymbolKind(
index::getSymbolInfoForMacro(*Decl.Info).Kind);
@@ -864,9 +864,8 @@ bool hasDeducedType(ParsedAST &AST, SourceLocation SourceLocationBeg) {
llvm::Optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
format::FormatStyle Style) {
llvm::Optional<HoverInfo> HI;
- const SourceManager &SourceMgr = AST.getASTContext().getSourceManager();
- SourceLocation SourceLocationBeg =
- getBeginningOfIdentifier(AST, Pos, SourceMgr.getMainFileID());
+ SourceLocation SourceLocationBeg = getBeginningOfIdentifier(
+ AST, Pos, AST.getSourceManager().getMainFileID());
// Identified symbols at a specific position.
auto Symbols = getSymbolAtPosition(AST, SourceLocationBeg);
@@ -900,7 +899,7 @@ std::vector<Location> findReferences(ParsedAST &AST, Position Pos,
if (!Limit)
Limit = std::numeric_limits<uint32_t>::max();
std::vector<Location> Results;
- const SourceManager &SM = AST.getASTContext().getSourceManager();
+ const SourceManager &SM = AST.getSourceManager();
auto MainFilePath =
getCanonicalPath(SM.getFileEntryForID(SM.getMainFileID()), SM);
if (!MainFilePath) {
@@ -949,7 +948,7 @@ std::vector<Location> findReferences(ParsedAST &AST, Position Pos,
}
std::vector<SymbolDetails> getSymbolInfo(ParsedAST &AST, Position Pos) {
- const SourceManager &SM = AST.getASTContext().getSourceManager();
+ const SourceManager &SM = AST.getSourceManager();
auto Loc = getBeginningOfIdentifier(AST, Pos, SM.getMainFileID());
auto Symbols = getSymbolAtPosition(AST, Loc);
@@ -1084,10 +1083,8 @@ getTypeAncestors(const CXXRecordDecl &CXXRD, ASTContext &ASTCtx,
}
const CXXRecordDecl *findRecordTypeAt(ParsedAST &AST, Position Pos) {
- ASTContext &ASTCtx = AST.getASTContext();
- const SourceManager &SourceMgr = ASTCtx.getSourceManager();
- SourceLocation SourceLocationBeg =
- getBeginningOfIdentifier(AST, Pos, SourceMgr.getMainFileID());
+ SourceLocation SourceLocationBeg = getBeginningOfIdentifier(
+ AST, Pos, AST.getSourceManager().getMainFileID());
IdentifiedSymbol Symbols = getSymbolAtPosition(AST, SourceLocationBeg);
if (Symbols.Decls.empty())
return nullptr;
diff --git a/clang-tools-extra/clangd/refactor/Rename.cpp b/clang-tools-extra/clangd/refactor/Rename.cpp
index 98d6fd488bb..46fd19d29f2 100644
--- a/clang-tools-extra/clangd/refactor/Rename.cpp
+++ b/clang-tools-extra/clangd/refactor/Rename.cpp
@@ -45,10 +45,9 @@ renameWithinFile(ParsedAST &AST, llvm::StringRef File, Position Pos,
llvm::StringRef NewName) {
RefactoringResultCollector ResultCollector;
ASTContext &ASTCtx = AST.getASTContext();
- const SourceManager &SourceMgr = ASTCtx.getSourceManager();
- SourceLocation SourceLocationBeg =
- clangd::getBeginningOfIdentifier(AST, Pos, SourceMgr.getMainFileID());
- tooling::RefactoringRuleContext Context(ASTCtx.getSourceManager());
+ SourceLocation SourceLocationBeg = clangd::getBeginningOfIdentifier(
+ AST, Pos, AST.getSourceManager().getMainFileID());
+ tooling::RefactoringRuleContext Context(AST.getSourceManager());
Context.setASTContext(ASTCtx);
auto Rename = clang::tooling::RenameOccurrences::initiate(
Context, SourceRange(SourceLocationBeg), NewName);
diff --git a/clang-tools-extra/clangd/refactor/Tweak.cpp b/clang-tools-extra/clangd/refactor/Tweak.cpp
index 34634e64b6f..6a19751e375 100644
--- a/clang-tools-extra/clangd/refactor/Tweak.cpp
+++ b/clang-tools-extra/clangd/refactor/Tweak.cpp
@@ -41,7 +41,7 @@ void validateRegistry() {
Tweak::Selection::Selection(ParsedAST &AST, unsigned RangeBegin,
unsigned RangeEnd)
: AST(AST), ASTSelection(AST.getASTContext(), RangeBegin, RangeEnd) {
- auto &SM = AST.getASTContext().getSourceManager();
+ auto &SM = AST.getSourceManager();
Code = SM.getBufferData(SM.getMainFileID());
Cursor = SM.getComposedLoc(SM.getMainFileID(), RangeBegin);
}
diff --git a/clang-tools-extra/clangd/refactor/tweaks/RawStringLiteral.cpp b/clang-tools-extra/clangd/refactor/tweaks/RawStringLiteral.cpp
index e3eaba50192..7feadd1eb78 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/RawStringLiteral.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/RawStringLiteral.cpp
@@ -82,15 +82,14 @@ bool RawStringLiteral::prepare(const Selection &Inputs) {
return false;
Str = dyn_cast_or_null<StringLiteral>(N->ASTNode.get<Stmt>());
return Str &&
- isNormalString(*Str, Inputs.Cursor,
- Inputs.AST.getASTContext().getSourceManager()) &&
+ isNormalString(*Str, Inputs.Cursor, Inputs.AST.getSourceManager()) &&
needsRaw(Str->getBytes()) && canBeRaw(Str->getBytes());
}
Expected<tooling::Replacements>
RawStringLiteral::apply(const Selection &Inputs) {
return tooling::Replacements(
- tooling::Replacement(Inputs.AST.getASTContext().getSourceManager(), Str,
+ tooling::Replacement(Inputs.AST.getSourceManager(), Str,
("R\"(" + Str->getBytes() + ")\"").str(),
Inputs.AST.getASTContext().getLangOpts()));
}
diff --git a/clang-tools-extra/clangd/refactor/tweaks/SwapIfBranches.cpp b/clang-tools-extra/clangd/refactor/tweaks/SwapIfBranches.cpp
index 9b0b72d94ca..12838d2a06a 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/SwapIfBranches.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/SwapIfBranches.cpp
@@ -62,7 +62,7 @@ bool SwapIfBranches::prepare(const Selection &Inputs) {
Expected<tooling::Replacements> SwapIfBranches::apply(const Selection &Inputs) {
auto &Ctx = Inputs.AST.getASTContext();
- auto &SrcMgr = Ctx.getSourceManager();
+ auto &SrcMgr = Inputs.AST.getSourceManager();
auto ThenRng = toHalfOpenFileRange(SrcMgr, Ctx.getLangOpts(),
If->getThen()->getSourceRange());
diff --git a/clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp b/clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
index 2c239ce76ac..100e92c3c65 100644
--- a/clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
@@ -49,7 +49,7 @@ Bar* bar;
std::string WithPreamble = Preamble + Text;
Annotations TestCase(WithPreamble);
auto AST = TestTU::withCode(TestCase.code()).build();
- const auto &SourceMgr = AST.getASTContext().getSourceManager();
+ const auto &SourceMgr = AST.getSourceManager();
SourceLocation Actual = getBeginningOfIdentifier(
AST, TestCase.points().back(), SourceMgr.getMainFileID());
Position ActualPos = offsetToPosition(
diff --git a/clang-tools-extra/clangd/unittests/SelectionTests.cpp b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
index ac9facca839..deae9f40b33 100644
--- a/clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -37,7 +37,7 @@ SelectionTree makeSelectionTree(const StringRef MarkedCode, ParsedAST &AST) {
Range nodeRange(const SelectionTree::Node *N, ParsedAST &AST) {
if (!N)
return Range{};
- SourceManager &SM = AST.getASTContext().getSourceManager();
+ SourceManager &SM = AST.getSourceManager();
StringRef Buffer = SM.getBufferData(SM.getMainFileID());
SourceRange SR = N->ASTNode.getSourceRange();
SR.setBegin(SM.getFileLoc(SR.getBegin()));
diff --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
index d372b1d6722..e422f5ca82b 100644
--- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -123,11 +123,10 @@ public:
assert(AST.hasValue());
const NamedDecl &ND =
Qualified ? findDecl(*AST, Name) : findUnqualifiedDecl(*AST, Name);
- ASTContext& Ctx = AST->getASTContext();
- const SourceManager& SM = Ctx.getSourceManager();
+ const SourceManager& SM = AST->getSourceManager();
bool MainFile = SM.isWrittenInMainFile(SM.getExpansionLoc(ND.getBeginLoc()));
return SymbolCollector::shouldCollectSymbol(
- ND, Ctx, SymbolCollector::Options(), MainFile);
+ ND, AST->getASTContext(), SymbolCollector::Options(), MainFile);
}
protected:
OpenPOWER on IntegriCloud