When we parse a pragma, keep track of how that pragma was originally
spelled (#pragma, _Pragma, __pragma). In -E mode, use that information to add appropriate newlines when translating _Pragma and __pragma into #pragma, like GCC does. Fixes <rdar://problem/8412013>. llvm-svn: 113553
This commit is contained in:
@@ -120,6 +120,8 @@ public:
|
||||
void SetEmittedTokensOnThisLine() { EmittedTokensOnThisLine = true; }
|
||||
bool hasEmittedTokensOnThisLine() const { return EmittedTokensOnThisLine; }
|
||||
|
||||
bool StartNewLineIfNeeded();
|
||||
|
||||
virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason,
|
||||
SrcMgr::CharacteristicKind FileType);
|
||||
virtual void Ident(SourceLocation Loc, const std::string &str);
|
||||
@@ -138,7 +140,7 @@ public:
|
||||
return ConcatInfo.AvoidConcat(PrevPrevTok, PrevTok, Tok);
|
||||
}
|
||||
void WriteLineInfo(unsigned LineNo, const char *Extra=0, unsigned ExtraLen=0);
|
||||
|
||||
bool LineMarkersAreDisabled() const { return DisableLineMarkers; }
|
||||
void HandleNewlinesInToken(const char *TokStr, unsigned Len);
|
||||
|
||||
/// MacroDefined - This hook is called whenever a macro definition is seen.
|
||||
@@ -213,6 +215,17 @@ bool PrintPPOutputPPCallbacks::MoveToLine(unsigned LineNo) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintPPOutputPPCallbacks::StartNewLineIfNeeded() {
|
||||
if (EmittedTokensOnThisLine || EmittedMacroOnThisLine) {
|
||||
OS << '\n';
|
||||
EmittedTokensOnThisLine = false;
|
||||
EmittedMacroOnThisLine = false;
|
||||
++CurLine;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// FileChanged - Whenever the preprocessor enters or exits a #include file
|
||||
/// it invokes this handler. Update our conception of the current source
|
||||
@@ -438,12 +451,15 @@ struct UnknownPragmaHandler : public PragmaHandler {
|
||||
|
||||
UnknownPragmaHandler(const char *prefix, PrintPPOutputPPCallbacks *callbacks)
|
||||
: Prefix(prefix), Callbacks(callbacks) {}
|
||||
virtual void HandlePragma(Preprocessor &PP, Token &PragmaTok) {
|
||||
virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
|
||||
Token &PragmaTok) {
|
||||
// Figure out what line we went to and insert the appropriate number of
|
||||
// newline characters.
|
||||
if (Introducer == PIK__Pragma || Introducer == PIK___pragma)
|
||||
Callbacks->StartNewLineIfNeeded();
|
||||
Callbacks->MoveToLine(PragmaTok.getLocation());
|
||||
Callbacks->OS.write(Prefix, strlen(Prefix));
|
||||
|
||||
Callbacks->SetEmittedTokensOnThisLine();
|
||||
// Read and print all of the pragma tokens.
|
||||
while (PragmaTok.isNot(tok::eom)) {
|
||||
if (PragmaTok.hasLeadingSpace())
|
||||
@@ -452,7 +468,7 @@ struct UnknownPragmaHandler : public PragmaHandler {
|
||||
Callbacks->OS.write(&TokSpell[0], TokSpell.size());
|
||||
PP.LexUnexpandedToken(PragmaTok);
|
||||
}
|
||||
Callbacks->OS << '\n';
|
||||
Callbacks->StartNewLineIfNeeded();
|
||||
}
|
||||
};
|
||||
} // end anonymous namespace
|
||||
|
||||
Reference in New Issue
Block a user