[clangd] Add SourceManager accessor to ParsedAST. NFC
llvm-svn: 361883
This commit is contained in:
parent
e88173abc0
commit
81748bae47
|
@ -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*).
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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()));
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue