Author: Eduardo Caldas Date: 2020-09-11T18:32:38Z New Revision: 515238d5b1133f87f85445b9f35783ca2d3a2e7b
URL: https://github.com/llvm/llvm-project/commit/515238d5b1133f87f85445b9f35783ca2d3a2e7b DIFF: https://github.com/llvm/llvm-project/commit/515238d5b1133f87f85445b9f35783ca2d3a2e7b.diff LOG: [SyntaxTree] Reduce visibility of `Arena::lexBuffer`. Differential Revision: https://reviews.llvm.org/D87523 Added: Modified: clang/include/clang/Tooling/Syntax/Tree.h clang/lib/Tooling/Syntax/Synthesis.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Tooling/Syntax/Tree.h b/clang/include/clang/Tooling/Syntax/Tree.h index aab904ab65d32..b49a09344c0fb 100644 --- a/clang/include/clang/Tooling/Syntax/Tree.h +++ b/clang/include/clang/Tooling/Syntax/Tree.h @@ -47,11 +47,13 @@ class Arena { const TokenBuffer &getTokenBuffer() const; llvm::BumpPtrAllocator &getAllocator() { return Allocator; } +private: /// Add \p Buffer to the underlying source manager, tokenize it and store the - /// resulting tokens. Useful when there is a need to materialize tokens that - /// were not written in user code. + /// resulting tokens. Used exclusively in `FactoryImpl` to materialize tokens + /// that were not written in user code. std::pair<FileID, ArrayRef<Token>> lexBuffer(std::unique_ptr<llvm::MemoryBuffer> Buffer); + friend class FactoryImpl; private: SourceManager &SourceMgr; diff --git a/clang/lib/Tooling/Syntax/Synthesis.cpp b/clang/lib/Tooling/Syntax/Synthesis.cpp index 8d51325706fa0..772429ff4c466 100644 --- a/clang/lib/Tooling/Syntax/Synthesis.cpp +++ b/clang/lib/Tooling/Syntax/Synthesis.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "clang/Basic/TokenKinds.h" #include "clang/Tooling/Syntax/BuildTree.h" +#include "clang/Tooling/Syntax/Tree.h" using namespace clang; @@ -20,11 +21,18 @@ class clang::syntax::FactoryImpl { syntax::NodeRole R) { T->prependChildLowLevel(Child, R); } + + static std::pair<FileID, ArrayRef<Token>> + lexBuffer(syntax::Arena &A, std::unique_ptr<llvm::MemoryBuffer> Buffer) { + return A.lexBuffer(std::move(Buffer)); + } }; syntax::Leaf *clang::syntax::createLeaf(syntax::Arena &A, tok::TokenKind K, StringRef Spelling) { - auto Tokens = A.lexBuffer(llvm::MemoryBuffer::getMemBuffer(Spelling)).second; + auto Tokens = + FactoryImpl::lexBuffer(A, llvm::MemoryBuffer::getMemBuffer(Spelling)) + .second; assert(Tokens.size() == 1); assert(Tokens.front().kind() == K && "spelling is not lexed into the expected kind of token"); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits