diff options
| author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-07-26 15:32:04 +0000 |
|---|---|---|
| committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-07-26 15:32:04 +0000 |
| commit | 17ff2e577f72550c317e30fb73539448824868a6 (patch) | |
| tree | 4cdeab256ea1979a1e07a6712883f520889e815a /clang/lib/Rewrite/Frontend/InclusionRewriter.cpp | |
| parent | 05e53fc0c1c76d3bbe9daaf221867f13a7a8cc25 (diff) | |
| download | bcm5719-llvm-17ff2e577f72550c317e30fb73539448824868a6.tar.gz bcm5719-llvm-17ff2e577f72550c317e30fb73539448824868a6.zip | |
[frontend] '-frewrite-includes' should not ignore headers included from command-line.
rdar://14556182
llvm-svn: 187207
Diffstat (limited to 'clang/lib/Rewrite/Frontend/InclusionRewriter.cpp')
| -rw-r--r-- | clang/lib/Rewrite/Frontend/InclusionRewriter.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/clang/lib/Rewrite/Frontend/InclusionRewriter.cpp b/clang/lib/Rewrite/Frontend/InclusionRewriter.cpp index 93ad9b88d60..a2297f9179d 100644 --- a/clang/lib/Rewrite/Frontend/InclusionRewriter.cpp +++ b/clang/lib/Rewrite/Frontend/InclusionRewriter.cpp @@ -40,6 +40,7 @@ class InclusionRewriter : public PPCallbacks { Preprocessor &PP; ///< Used to find inclusion directives. SourceManager &SM; ///< Used to read and manage source files. raw_ostream &OS; ///< The destination stream for rewritten contents. + const llvm::MemoryBuffer *PredefinesBuffer; ///< The preprocessor predefines. bool ShowLineMarkers; ///< Show #line markers. bool UseLineDirective; ///< Use of line directives or line markers. typedef std::map<unsigned, FileChange> FileChangeMap; @@ -50,6 +51,9 @@ class InclusionRewriter : public PPCallbacks { public: InclusionRewriter(Preprocessor &PP, raw_ostream &OS, bool ShowLineMarkers); bool Process(FileID FileId, SrcMgr::CharacteristicKind FileType); + void setPredefinesBuffer(const llvm::MemoryBuffer *Buf) { + PredefinesBuffer = Buf; + } private: virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason, SrcMgr::CharacteristicKind FileType, @@ -89,7 +93,7 @@ private: /// Initializes an InclusionRewriter with a \p PP source and \p OS destination. InclusionRewriter::InclusionRewriter(Preprocessor &PP, raw_ostream &OS, bool ShowLineMarkers) - : PP(PP), SM(PP.getSourceManager()), OS(OS), + : PP(PP), SM(PP.getSourceManager()), OS(OS), PredefinesBuffer(0), ShowLineMarkers(ShowLineMarkers), LastInsertedFileChange(FileChanges.end()) { // If we're in microsoft mode, use normal #line instead of line markers. @@ -214,6 +218,11 @@ void InclusionRewriter::OutputContentUpTo(const MemoryBuffer &FromFile, bool EnsureNewline) { if (WriteTo <= WriteFrom) return; + if (&FromFile == PredefinesBuffer) { + // Ignore the #defines of the predefines buffer. + WriteFrom = WriteTo; + return; + } OS.write(FromFile.getBufferStart() + WriteFrom, WriteTo - WriteFrom); // count lines manually, it's faster than getPresumedLoc() Line += std::count(FromFile.getBufferStart() + WriteFrom, @@ -525,6 +534,8 @@ void clang::RewriteIncludesInInput(Preprocessor &PP, raw_ostream *OS, do { PP.Lex(Tok); } while (Tok.isNot(tok::eof)); + Rewrite->setPredefinesBuffer(SM.getBuffer(PP.getPredefinesFileID())); + Rewrite->Process(PP.getPredefinesFileID(), SrcMgr::C_User); Rewrite->Process(SM.getMainFileID(), SrcMgr::C_User); OS->flush(); } |

