Author: sammccall Date: Tue May 28 14:52:34 2019 New Revision: 361883 URL: http://llvm.org/viewvc/llvm-project?rev=361883&view=rev Log: [clangd] Add SourceManager accessor to ParsedAST. NFC
Modified: clang-tools-extra/trunk/clangd/ClangdUnit.h clang-tools-extra/trunk/clangd/XRefs.cpp clang-tools-extra/trunk/clangd/refactor/Rename.cpp clang-tools-extra/trunk/clangd/refactor/Tweak.cpp clang-tools-extra/trunk/clangd/refactor/tweaks/RawStringLiteral.cpp clang-tools-extra/trunk/clangd/refactor/tweaks/SwapIfBranches.cpp clang-tools-extra/trunk/clangd/unittests/ClangdUnitTests.cpp clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp clang-tools-extra/trunk/clangd/unittests/SymbolCollectorTests.cpp Modified: clang-tools-extra/trunk/clangd/ClangdUnit.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.h?rev=361883&r1=361882&r2=361883&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/ClangdUnit.h (original) +++ clang-tools-extra/trunk/clangd/ClangdUnit.h Tue May 28 14:52:34 2019 @@ -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*). Modified: clang-tools-extra/trunk/clangd/XRefs.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=361883&r1=361882&r2=361883&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/XRefs.cpp (original) +++ clang-tools-extra/trunk/clangd/XRefs.cpp Tue May 28 14:52:34 2019 @@ -286,7 +286,7 @@ llvm::Optional<Location> makeLocation(AS 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 *> 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(QualTy /// 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, Sour 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(Par 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(Par } 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 &CX } 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; Modified: clang-tools-extra/trunk/clangd/refactor/Rename.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/refactor/Rename.cpp?rev=361883&r1=361882&r2=361883&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/refactor/Rename.cpp (original) +++ clang-tools-extra/trunk/clangd/refactor/Rename.cpp Tue May 28 14:52:34 2019 @@ -45,10 +45,9 @@ renameWithinFile(ParsedAST &AST, llvm::S 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); Modified: clang-tools-extra/trunk/clangd/refactor/Tweak.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/refactor/Tweak.cpp?rev=361883&r1=361882&r2=361883&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/refactor/Tweak.cpp (original) +++ clang-tools-extra/trunk/clangd/refactor/Tweak.cpp Tue May 28 14:52:34 2019 @@ -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); } Modified: clang-tools-extra/trunk/clangd/refactor/tweaks/RawStringLiteral.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/refactor/tweaks/RawStringLiteral.cpp?rev=361883&r1=361882&r2=361883&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/refactor/tweaks/RawStringLiteral.cpp (original) +++ clang-tools-extra/trunk/clangd/refactor/tweaks/RawStringLiteral.cpp Tue May 28 14:52:34 2019 @@ -82,15 +82,14 @@ bool RawStringLiteral::prepare(const Sel 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())); } Modified: clang-tools-extra/trunk/clangd/refactor/tweaks/SwapIfBranches.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/refactor/tweaks/SwapIfBranches.cpp?rev=361883&r1=361882&r2=361883&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/refactor/tweaks/SwapIfBranches.cpp (original) +++ clang-tools-extra/trunk/clangd/refactor/tweaks/SwapIfBranches.cpp Tue May 28 14:52:34 2019 @@ -62,7 +62,7 @@ bool SwapIfBranches::prepare(const Selec 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()); Modified: clang-tools-extra/trunk/clangd/unittests/ClangdUnitTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/ClangdUnitTests.cpp?rev=361883&r1=361882&r2=361883&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/unittests/ClangdUnitTests.cpp (original) +++ clang-tools-extra/trunk/clangd/unittests/ClangdUnitTests.cpp Tue May 28 14:52:34 2019 @@ -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( Modified: clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp?rev=361883&r1=361882&r2=361883&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp (original) +++ clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp Tue May 28 14:52:34 2019 @@ -37,7 +37,7 @@ SelectionTree makeSelectionTree(const St 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())); Modified: clang-tools-extra/trunk/clangd/unittests/SymbolCollectorTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/SymbolCollectorTests.cpp?rev=361883&r1=361882&r2=361883&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/unittests/SymbolCollectorTests.cpp (original) +++ clang-tools-extra/trunk/clangd/unittests/SymbolCollectorTests.cpp Tue May 28 14:52:34 2019 @@ -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: _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits