llvm-project/clang/lib/Tooling/Syntax/TokenBufferTokenManager.cpp
Haojian Wu 263dcf452f [syntax] Introduce a TokenManager interface.
TokenManager defines Token interfaces for the clang syntax-tree. This is the level
of abstraction that the syntax-tree should use to operate on Tokens.

It decouples the syntax-tree from a particular token implementation (TokenBuffer
previously).  This enables us to use a different underlying token implementation
for the syntax Leaf node -- in clang pseudoparser, we want to produce a
syntax-tree with its own pseudo::Token rather than syntax::Token.

Differential Revision: https://reviews.llvm.org/D128411
2022-07-15 10:30:37 +02:00

26 lines
914 B
C++

//===- TokenBufferTokenManager.cpp ----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "clang/Tooling/Syntax/TokenBufferTokenManager.h"
namespace clang {
namespace syntax {
constexpr llvm::StringLiteral syntax::TokenBufferTokenManager::Kind;
std::pair<FileID, ArrayRef<syntax::Token>>
syntax::TokenBufferTokenManager::lexBuffer(
std::unique_ptr<llvm::MemoryBuffer> Input) {
auto FID = SM.createFileID(std::move(Input));
auto It = ExtraTokens.try_emplace(FID, tokenize(FID, SM, LangOpts));
assert(It.second && "duplicate FileID");
return {FID, It.first->second};
}
} // namespace syntax
} // namespace clang