From a59e05070b25861a8974817c87d7aa782c9a52f8 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 25 Jul 2008 16:37:06 +0000 Subject: [PATCH] comment out #pragma mark and #warning directives. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54020 91177308-0d34-0410-b5e6-96231b3b80d8 --- Driver/RewriteMacros.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/Driver/RewriteMacros.cpp b/Driver/RewriteMacros.cpp index 6f5e6baa16..c2989438fd 100644 --- a/Driver/RewriteMacros.cpp +++ b/Driver/RewriteMacros.cpp @@ -121,9 +121,28 @@ void clang::RewriteMacrosInInput(Preprocessor &PP,const std::string &InFileName, } // If the raw file hits a preprocessor directive, they will be extra tokens - // in the input file, but we don't want to treat them as such... just ignore - // them. + // in the raw file that don't exist in the preprocsesed file. However, we + // choose to preserve them in the output file and otherwise handle them + // specially. if (RawTok.is(tok::hash) && RawTok.isAtStartOfLine()) { + // If this is a #warning directive or #pragma mark (GNU extensions), + // comment the line out. + if (RawTokens[CurRawTok].is(tok::identifier)) { + const IdentifierInfo *II = RawTokens[CurRawTok].getIdentifierInfo(); + if (!strcmp(II->getName(), "warning")) { + // Comment out #warning. + RB.InsertTextAfter(SM.getFullFilePos(RawTok.getLocation()), "//", 2); + } else if (!strcmp(II->getName(), "pragma") && + RawTokens[CurRawTok+1].is(tok::identifier) && + !strcmp(RawTokens[CurRawTok+1].getIdentifierInfo()->getName(), + "mark")){ + // Comment out #pragma mark. + RB.InsertTextAfter(SM.getFullFilePos(RawTok.getLocation()), "//", 2); + } + } + + // Otherwise, if this is a #include or some other directive, just leave it + // in the file by skipping over the line. RawTok = GetNextRawTok(RawTokens, CurRawTok, false); while (!RawTok.isAtStartOfLine() && RawTok.isNot(tok::eof)) RawTok = GetNextRawTok(RawTokens, CurRawTok, false); -- 2.40.0