File indexing completed on 2026-05-10 08:36:59
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_CLANG_REWRITE_CORE_TOKENREWRITER_H
0015 #define LLVM_CLANG_REWRITE_CORE_TOKENREWRITER_H
0016
0017 #include "clang/Basic/SourceLocation.h"
0018 #include "clang/Lex/Token.h"
0019 #include <cassert>
0020 #include <list>
0021 #include <map>
0022 #include <memory>
0023
0024 namespace clang {
0025
0026 class LangOptions;
0027 class ScratchBuffer;
0028 class SourceManager;
0029
0030 class TokenRewriter {
0031
0032
0033 std::list<Token> TokenList;
0034
0035
0036 using TokenRefTy = std::list<Token>::iterator;
0037
0038
0039
0040
0041
0042 std::map<SourceLocation, TokenRefTy> TokenAtLoc;
0043
0044
0045 std::unique_ptr<ScratchBuffer> ScratchBuf;
0046
0047 public:
0048
0049
0050 TokenRewriter(FileID FID, SourceManager &SM, const LangOptions &LO);
0051
0052 TokenRewriter(const TokenRewriter &) = delete;
0053 TokenRewriter &operator=(const TokenRewriter &) = delete;
0054 ~TokenRewriter();
0055
0056 using token_iterator = std::list<Token>::const_iterator;
0057
0058 token_iterator token_begin() const { return TokenList.begin(); }
0059 token_iterator token_end() const { return TokenList.end(); }
0060
0061 token_iterator AddTokenBefore(token_iterator I, const char *Val);
0062
0063 token_iterator AddTokenAfter(token_iterator I, const char *Val) {
0064 assert(I != token_end() && "Cannot insert after token_end()!");
0065 return AddTokenBefore(++I, Val);
0066 }
0067
0068 private:
0069
0070
0071 TokenRefTy RemapIterator(token_iterator I);
0072
0073
0074
0075 TokenRefTy AddToken(const Token &T, TokenRefTy Where);
0076 };
0077
0078 }
0079
0080 #endif