Go to the documentation of this file.
18 #include "llvm/Support/Path.h"
19 #include "llvm/Support/raw_ostream.h"
23 using namespace clang;
48 unsigned &CurTok,
bool ReturnComment) {
49 assert(CurTok < RawTokens.size() &&
"Overran eof!");
52 if (!ReturnComment && RawTokens[CurTok].is(tok::comment))
55 return RawTokens[CurTok++];
62 std::vector<Token> &RawTokens) {
67 llvm::MemoryBufferRef FromFile =
SM.getBufferOrFake(
SM.getMainFileID());
80 if (RawTok.
is(tok::raw_identifier))
83 RawTokens.push_back(RawTok);
96 std::vector<Token> RawTokens;
98 unsigned CurRawTok = 0;
117 if (!
SM.isWrittenInMainFile(PPLoc)) {
129 if (RawTokens[CurRawTok].is(tok::identifier)) {
130 const IdentifierInfo *II = RawTokens[CurRawTok].getIdentifierInfo();
131 if (II->
getName() ==
"warning") {
134 }
else if (II->
getName() ==
"pragma" &&
135 RawTokens[CurRawTok+1].is(tok::identifier) &&
136 (RawTokens[CurRawTok+1].getIdentifierInfo()->getName() ==
153 unsigned PPOffs =
SM.getFileOffset(PPLoc);
157 if (PPOffs == RawOffs &&
isSameToken(RawTok, PPTok)) {
165 if (RawOffs <= PPOffs) {
178 if (RawTok.
is(tok::comment)) {
185 (PPOffs != RawOffs || !
isSameToken(RawTok, PPTok)));
194 unsigned InsertPos = PPOffs;
196 while (PPOffs < RawOffs) {
200 PPOffs =
SM.getFileOffset(PPLoc);
209 Rewrite.getRewriteBufferFor(
SM.getMainFileID())) {
211 *OS <<
std::string(RewriteBuf->begin(), RewriteBuf->end());
213 fprintf(stderr,
"No changes\n");
void InsertTextAfter(unsigned OrigOffset, StringRef Str)
InsertTextAfter - Insert some text at the specified point, where the offset in the buffer is specifie...
bool hasLeadingSpace() const
Return true if this token has whitespace before it.
void SetCommentRetentionState(bool Mode)
SetCommentRetentionMode - Change the comment retention mode of the lexer to the specified mode.
void Lex(Token &Result)
Lex the next token for this preprocessor.
Encodes a location in the source.
IdentifierInfo * getIdentifierInfo() const
@ Rewrite
We are substituting template parameters for (typically) other template parameters in order to rewrite...
bool isAtStartOfLine() const
isAtStartOfLine - Return true if this token is at the start of a line.
bool LexFromRawLexer(Token &Result)
LexFromRawLexer - Lex a token from a designated raw lexer (one with no associated preprocessor object...
Token - This structure provides full information about a lexed token.
static void LexRawTokensFromMainFile(Preprocessor &PP, std::vector< Token > &RawTokens)
LexRawTokensFromMainFile - Lets all the raw tokens from the main file into the specified vector.
This class handles loading and caching of source files into memory.
const LangOptions & getLangOpts() const
void InsertTextBefore(unsigned OrigOffset, StringRef Str)
InsertTextBefore - Insert some text before the specified point, where the offset in the buffer is spe...
Lexer - This provides a simple interface that turns a text buffer into a stream of tokens.
static bool isSameToken(Token &RawTok, Token &PPTok)
isSameToken - Return true if the two specified tokens start have the same content.
static const Token & GetNextRawTok(const std::vector< Token > &RawTokens, unsigned &CurTok, bool ReturnComment)
GetNextRawTok - Return the next raw token in the stream, skipping over comments if ReturnComment is f...
tok::TokenKind getKind() const
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {....
void EnterMainSourceFile()
Enter the specified FileID as the main source file, which implicitly adds the builtin defines etc.
bool isNot(tok::TokenKind K) const
unsigned getLength() const
SourceManager & getSourceManager() const
StringRef getSpelling(SourceLocation loc, SmallVectorImpl< char > &buffer, bool *invalid=nullptr) const
Return the 'spelling' of the token at the given location; does not go up to the spelling location or ...
void RewriteMacrosInInput(Preprocessor &PP, raw_ostream *OS)
RewriteMacrosInInput - Implement -rewrite-macros mode.
One of these records is kept for each identifier that is lexed.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
StringRef getName() const
Return the actual identifier string.
RewriteBuffer - As code is rewritten, SourceBuffer's from the original input with modifications get a...
IdentifierInfo * LookUpIdentifierInfo(Token &Identifier) const
Given a tok::raw_identifier token, look up the identifier information for the token and install it in...
Rewriter - This is the main interface to the rewrite buffers.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.