diff options
Diffstat (limited to 'lib/Frontend/PrintPreprocessedOutput.cpp')
-rw-r--r-- | lib/Frontend/PrintPreprocessedOutput.cpp | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/lib/Frontend/PrintPreprocessedOutput.cpp b/lib/Frontend/PrintPreprocessedOutput.cpp index a58c935620a2..77b80e612fbf 100644 --- a/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/lib/Frontend/PrintPreprocessedOutput.cpp @@ -326,8 +326,20 @@ void PrintPPOutputPPCallbacks::InclusionDirective(SourceLocation HashLoc, if (Imported) { startNewLineIfNeeded(); MoveToLine(HashLoc); - OS << "@import " << Imported->getFullModuleName() << ";" - << " /* clang -E: implicit import for \"" << File->getName() << "\" */"; + if (PP.getLangOpts().ObjC2) { + OS << "@import " << Imported->getFullModuleName() << ";" + << " /* clang -E: implicit import for \"" << File->getName() + << "\" */"; + } else { + // FIXME: Preseve whether this was a + // #include/#include_next/#include_macros/#import. + OS << "#include " + << (IsAngled ? '<' : '"') + << FileName + << (IsAngled ? '>' : '"') + << " /* clang -E: implicit import for module " + << Imported->getFullModuleName() << " */"; + } // Since we want a newline after the @import, but not a #<line>, start a new // line immediately. EmittedTokensOnThisLine = true; @@ -369,18 +381,16 @@ void PrintPPOutputPPCallbacks::MacroUndefined(const Token &MacroNameTok, setEmittedDirectiveOnThisLine(); } -static void outputPrintable(llvm::raw_ostream& OS, - const std::string &Str) { - for (unsigned i = 0, e = Str.size(); i != e; ++i) { - unsigned char Char = Str[i]; - if (isPrintable(Char) && Char != '\\' && Char != '"') - OS << (char)Char; - else // Output anything hard as an octal escape. - OS << '\\' - << (char)('0'+ ((Char >> 6) & 7)) - << (char)('0'+ ((Char >> 3) & 7)) - << (char)('0'+ ((Char >> 0) & 7)); - } +static void outputPrintable(raw_ostream &OS, StringRef Str) { + for (unsigned char Char : Str) { + if (isPrintable(Char) && Char != '\\' && Char != '"') + OS << (char)Char; + else // Output anything hard as an octal escape. + OS << '\\' + << (char)('0' + ((Char >> 6) & 7)) + << (char)('0' + ((Char >> 3) & 7)) + << (char)('0' + ((Char >> 0) & 7)); + } } void PrintPPOutputPPCallbacks::PragmaMessage(SourceLocation Loc, @@ -547,8 +557,10 @@ void PrintPPOutputPPCallbacks::HandleNewlinesInToken(const char *TokStr, // If we have \n\r or \r\n, skip both and count as one line. if (Len != 1 && (TokStr[1] == '\n' || TokStr[1] == '\r') && - TokStr[0] != TokStr[1]) - ++TokStr, --Len; + TokStr[0] != TokStr[1]) { + ++TokStr; + --Len; + } } if (NumNewlines == 0) return; @@ -577,6 +589,15 @@ struct UnknownPragmaHandler : public PragmaHandler { Callbacks->MoveToLine(PragmaTok.getLocation()); Callbacks->OS.write(Prefix, strlen(Prefix)); + if (ShouldExpandTokens) { + // The first token does not have expanded macros. Expand them, if + // required. + auto Toks = llvm::make_unique<Token[]>(1); + Toks[0] = PragmaTok; + PP.EnterTokenStream(std::move(Toks), /*NumToks=*/1, + /*DisableMacroExpansion=*/false); + PP.Lex(PragmaTok); + } Token PrevToken; Token PrevPrevToken; PrevToken.startToken(); |