eduucaldas created this revision. eduucaldas added a reviewer: gribozavr2. Herald added a project: clang. Herald added a subscriber: cfe-commits. eduucaldas requested review of this revision.
Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D87523 Files: clang/include/clang/Tooling/Syntax/Tree.h clang/lib/Tooling/Syntax/Synthesis.cpp Index: clang/lib/Tooling/Syntax/Synthesis.cpp =================================================================== --- clang/lib/Tooling/Syntax/Synthesis.cpp +++ clang/lib/Tooling/Syntax/Synthesis.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// #include "clang/Tooling/Syntax/BuildTree.h" +#include "clang/Tooling/Syntax/Tree.h" using namespace clang; @@ -19,13 +20,19 @@ 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)); + } }; clang::syntax::Leaf *syntax::createPunctuation(clang::syntax::Arena &A, clang::tok::TokenKind K) { - auto Tokens = A.lexBuffer(llvm::MemoryBuffer::getMemBuffer( - clang::tok::getPunctuatorSpelling(K))) - .second; + auto Tokens = + FactoryImpl::lexBuffer(A, llvm::MemoryBuffer::getMemBuffer( + clang::tok::getPunctuatorSpelling(K))) + .second; assert(Tokens.size() == 1); assert(Tokens.front().kind() == K); auto *L = new (A.getAllocator()) clang::syntax::Leaf(Tokens.begin()); Index: clang/include/clang/Tooling/Syntax/Tree.h =================================================================== --- clang/include/clang/Tooling/Syntax/Tree.h +++ clang/include/clang/Tooling/Syntax/Tree.h @@ -47,11 +47,13 @@ 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;
Index: clang/lib/Tooling/Syntax/Synthesis.cpp =================================================================== --- clang/lib/Tooling/Syntax/Synthesis.cpp +++ clang/lib/Tooling/Syntax/Synthesis.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// #include "clang/Tooling/Syntax/BuildTree.h" +#include "clang/Tooling/Syntax/Tree.h" using namespace clang; @@ -19,13 +20,19 @@ 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)); + } }; clang::syntax::Leaf *syntax::createPunctuation(clang::syntax::Arena &A, clang::tok::TokenKind K) { - auto Tokens = A.lexBuffer(llvm::MemoryBuffer::getMemBuffer( - clang::tok::getPunctuatorSpelling(K))) - .second; + auto Tokens = + FactoryImpl::lexBuffer(A, llvm::MemoryBuffer::getMemBuffer( + clang::tok::getPunctuatorSpelling(K))) + .second; assert(Tokens.size() == 1); assert(Tokens.front().kind() == K); auto *L = new (A.getAllocator()) clang::syntax::Leaf(Tokens.begin()); Index: clang/include/clang/Tooling/Syntax/Tree.h =================================================================== --- clang/include/clang/Tooling/Syntax/Tree.h +++ clang/include/clang/Tooling/Syntax/Tree.h @@ -47,11 +47,13 @@ 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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits