summaryrefslogtreecommitdiffstats
path: root/clang/lib/Rewrite/TokenRewriter.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2012-09-01 05:09:24 +0000
committerTed Kremenek <kremenek@apple.com>2012-09-01 05:09:24 +0000
commitcdf814900d7ca310144b38ba66b2c949530647b7 (patch)
tree8e9d997ec1a7fde94517529ab7f707e8d3c0e43b /clang/lib/Rewrite/TokenRewriter.cpp
parentec385012ae7bc3ca9ba886ec35430f22a21cb41f (diff)
downloadbcm5719-llvm-cdf814900d7ca310144b38ba66b2c949530647b7.tar.gz
bcm5719-llvm-cdf814900d7ca310144b38ba66b2c949530647b7.zip
Split library clangRewrite into clangRewriteCore and clangRewriteFrontend.
This is similar to how we divide up the StaticAnalyzer libraries to separate core functionality to what is clearly associated with Frontend actions. llvm-svn: 163050
Diffstat (limited to 'clang/lib/Rewrite/TokenRewriter.cpp')
-rw-r--r--clang/lib/Rewrite/TokenRewriter.cpp99
1 files changed, 0 insertions, 99 deletions
diff --git a/clang/lib/Rewrite/TokenRewriter.cpp b/clang/lib/Rewrite/TokenRewriter.cpp
deleted file mode 100644
index 03ce63ea117..00000000000
--- a/clang/lib/Rewrite/TokenRewriter.cpp
+++ /dev/null
@@ -1,99 +0,0 @@
-//===--- TokenRewriter.cpp - Token-based code rewriting interface ---------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file implements the TokenRewriter class, which is used for code
-// transformations.
-//
-//===----------------------------------------------------------------------===//
-
-#include "clang/Rewrite/TokenRewriter.h"
-#include "clang/Lex/Lexer.h"
-#include "clang/Lex/ScratchBuffer.h"
-#include "clang/Basic/SourceManager.h"
-using namespace clang;
-
-TokenRewriter::TokenRewriter(FileID FID, SourceManager &SM,
- const LangOptions &LangOpts) {
- ScratchBuf.reset(new ScratchBuffer(SM));
-
- // Create a lexer to lex all the tokens of the main file in raw mode.
- const llvm::MemoryBuffer *FromFile = SM.getBuffer(FID);
- Lexer RawLex(FID, FromFile, SM, LangOpts);
-
- // Return all comments and whitespace as tokens.
- RawLex.SetKeepWhitespaceMode(true);
-
- // Lex the file, populating our datastructures.
- Token RawTok;
- RawLex.LexFromRawLexer(RawTok);
- while (RawTok.isNot(tok::eof)) {
-#if 0
- if (Tok.is(tok::raw_identifier)) {
- // Look up the identifier info for the token. This should use
- // IdentifierTable directly instead of PP.
- PP.LookUpIdentifierInfo(Tok);
- }
-#endif
-
- AddToken(RawTok, TokenList.end());
- RawLex.LexFromRawLexer(RawTok);
- }
-}
-
-TokenRewriter::~TokenRewriter() {
-}
-
-
-/// RemapIterator - Convert from token_iterator (a const iterator) to
-/// TokenRefTy (a non-const iterator).
-TokenRewriter::TokenRefTy TokenRewriter::RemapIterator(token_iterator I) {
- if (I == token_end()) return TokenList.end();
-
- // FIXME: This is horrible, we should use our own list or something to avoid
- // this.
- std::map<SourceLocation, TokenRefTy>::iterator MapIt =
- TokenAtLoc.find(I->getLocation());
- assert(MapIt != TokenAtLoc.end() && "iterator not in rewriter?");
- return MapIt->second;
-}
-
-
-/// AddToken - Add the specified token into the Rewriter before the other
-/// position.
-TokenRewriter::TokenRefTy
-TokenRewriter::AddToken(const Token &T, TokenRefTy Where) {
- Where = TokenList.insert(Where, T);
-
- bool InsertSuccess = TokenAtLoc.insert(std::make_pair(T.getLocation(),
- Where)).second;
- assert(InsertSuccess && "Token location already in rewriter!");
- (void)InsertSuccess;
- return Where;
-}
-
-
-TokenRewriter::token_iterator
-TokenRewriter::AddTokenBefore(token_iterator I, const char *Val) {
- unsigned Len = strlen(Val);
-
- // Plop the string into the scratch buffer, then create a token for this
- // string.
- Token Tok;
- Tok.startToken();
- const char *Spelling;
- Tok.setLocation(ScratchBuf->getToken(Val, Len, Spelling));
- Tok.setLength(Len);
-
- // TODO: Form a whole lexer around this and relex the token! For now, just
- // set kind to tok::unknown.
- Tok.setKind(tok::unknown);
-
- return AddToken(Tok, RemapIterator(I));
-}
-
OpenPOWER on IntegriCloud