19 #include "llvm/Support/Path.h"
20 #include "llvm/Support/raw_ostream.h"
24 using namespace clang;
49 unsigned &CurTok,
bool ReturnComment) {
50 assert(CurTok < RawTokens.size() &&
"Overran eof!");
53 if (!ReturnComment && RawTokens[CurTok].is(tok::comment))
56 return RawTokens[CurTok++];
63 std::vector<Token> &RawTokens) {
76 RawLex.LexFromRawLexer(RawTok);
81 if (RawTok.
is(tok::raw_identifier))
84 RawTokens.push_back(RawTok);
97 std::vector<Token> RawTokens;
99 unsigned CurRawTok = 0;
130 if (RawTokens[CurRawTok].is(tok::identifier)) {
131 const IdentifierInfo *II = RawTokens[CurRawTok].getIdentifierInfo();
132 if (II->
getName() ==
"warning") {
135 }
else if (II->
getName() ==
"pragma" &&
136 RawTokens[CurRawTok+1].is(tok::identifier) &&
137 (RawTokens[CurRawTok+1].getIdentifierInfo()->getName() ==
158 if (PPOffs == RawOffs &&
isSameToken(RawTok, PPTok)) {
166 if (RawOffs <= PPOffs) {
179 if (RawTok.
is(tok::comment)) {
186 (PPOffs != RawOffs || !
isSameToken(RawTok, PPTok)));
195 unsigned InsertPos = PPOffs;
196 std::string Expansion;
197 while (PPOffs < RawOffs) {
212 *OS << std::string(RewriteBuf->begin(), RewriteBuf->end());
214 fprintf(stderr,
"No changes\n");
bool isAtStartOfLine() const
SourceManager & getSourceManager() const
Defines the SourceManager interface.
const RewriteBuffer * getRewriteBufferFor(FileID FID) const
llvm::MemoryBuffer * getBuffer(FileID FID, SourceLocation Loc, bool *Invalid=nullptr) const
Return the buffer for the specified FileID.
bool hasLeadingSpace() const
Return true if this token has whitespace before it.
RewriteBuffer & getEditBuffer(FileID FID)
StringRef getSpelling(SourceLocation loc, SmallVectorImpl< char > &buffer, bool *invalid=nullptr) const
static bool isSameToken(Token &RawTok, Token &PPTok)
const LangOptions & getLangOpts() const
void RewriteMacrosInInput(Preprocessor &PP, raw_ostream *OS)
RewriteMacrosInInput - Implement -rewrite-macros mode.
tok::TokenKind getKind() const
StringRef getName() const
Return the actual identifier string.
void EnterMainSourceFile()
Enter the specified FileID as the main source file, which implicitly adds the builtin defines etc...
Defines the clang::Preprocessor interface.
void InsertTextAfter(unsigned OrigOffset, StringRef Str)
bool isWrittenInMainFile(SourceLocation Loc) const
Returns true if the spelling location for the given location is in the main file buffer.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
bool isNot(tok::TokenKind K) const
static void LexRawTokensFromMainFile(Preprocessor &PP, std::vector< Token > &RawTokens)
void setSourceMgr(SourceManager &SM, const LangOptions &LO)
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
void Lex(Token &Result)
Lex the next token for this preprocessor.
FileID getMainFileID() const
Returns the FileID of the main source file.
bool is(tok::TokenKind K) const
void InsertTextBefore(unsigned OrigOffset, StringRef Str)
static const Token & GetNextRawTok(const std::vector< Token > &RawTokens, unsigned &CurTok, bool ReturnComment)
void SetCommentRetentionState(bool Mode)
IdentifierInfo * LookUpIdentifierInfo(Token &Identifier) const
unsigned getLength() const
unsigned getFileOffset(SourceLocation SpellingLoc) const
Returns the offset from the start of the file that the specified SourceLocation represents.
SourceLocation getExpansionLoc(SourceLocation Loc) const
Given a SourceLocation object Loc, return the expansion location referenced by the ID...
This class handles loading and caching of source files into memory.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
IdentifierInfo * getIdentifierInfo() const