diff options
author | rdivacky <rdivacky@FreeBSD.org> | 2010-05-04 16:12:48 +0000 |
---|---|---|
committer | rdivacky <rdivacky@FreeBSD.org> | 2010-05-04 16:12:48 +0000 |
commit | 8aaf5818a64e9f7687798852af5945b053c68a54 (patch) | |
tree | d6a70c3518b8dea8be7062438d7e8676820ed17f /lib/Frontend/PrintPreprocessedOutput.cpp | |
parent | 71438373cd57f0d5d8c93bb5cf690844a0fbc9d0 (diff) | |
download | FreeBSD-src-8aaf5818a64e9f7687798852af5945b053c68a54.zip FreeBSD-src-8aaf5818a64e9f7687798852af5945b053c68a54.tar.gz |
Update clang to r103004.
Diffstat (limited to 'lib/Frontend/PrintPreprocessedOutput.cpp')
-rw-r--r-- | lib/Frontend/PrintPreprocessedOutput.cpp | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/lib/Frontend/PrintPreprocessedOutput.cpp b/lib/Frontend/PrintPreprocessedOutput.cpp index 02afd24..b6c18b7 100644 --- a/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/lib/Frontend/PrintPreprocessedOutput.cpp @@ -78,6 +78,7 @@ static void PrintMacroDefinition(const IdentifierInfo &II, const MacroInfo &MI, namespace { class PrintPPOutputPPCallbacks : public PPCallbacks { Preprocessor &PP; + SourceManager &SM; TokenConcatenation ConcatInfo; public: llvm::raw_ostream &OS; @@ -94,7 +95,8 @@ private: public: PrintPPOutputPPCallbacks(Preprocessor &pp, llvm::raw_ostream &os, bool lineMarkers, bool defines) - : PP(pp), ConcatInfo(PP), OS(os), DisableLineMarkers(lineMarkers), + : PP(pp), SM(PP.getSourceManager()), + ConcatInfo(PP), OS(os), DisableLineMarkers(lineMarkers), DumpDefines(defines) { CurLine = 0; CurFilename += "<uninit>"; @@ -118,9 +120,14 @@ public: bool HandleFirstTokOnLine(Token &Tok); - bool MoveToLine(SourceLocation Loc); - bool AvoidConcat(const Token &PrevTok, const Token &Tok) { - return ConcatInfo.AvoidConcat(PrevTok, Tok); + bool MoveToLine(SourceLocation Loc) { + return MoveToLine(SM.getPresumedLoc(Loc).getLine()); + } + bool MoveToLine(unsigned LineNo); + + bool AvoidConcat(const Token &PrevPrevTok, const Token &PrevTok, + const Token &Tok) { + return ConcatInfo.AvoidConcat(PrevPrevTok, PrevTok, Tok); } void WriteLineInfo(unsigned LineNo, const char *Extra=0, unsigned ExtraLen=0); @@ -166,9 +173,7 @@ void PrintPPOutputPPCallbacks::WriteLineInfo(unsigned LineNo, /// object. We can do this by emitting some number of \n's, or be emitting a /// #line directive. This returns false if already at the specified line, true /// if some newlines were emitted. -bool PrintPPOutputPPCallbacks::MoveToLine(SourceLocation Loc) { - unsigned LineNo = PP.getSourceManager().getInstantiationLineNumber(Loc); - +bool PrintPPOutputPPCallbacks::MoveToLine(unsigned LineNo) { if (DisableLineMarkers) { if (LineNo == CurLine) return false; @@ -211,27 +216,29 @@ void PrintPPOutputPPCallbacks::FileChanged(SourceLocation Loc, SrcMgr::CharacteristicKind NewFileType) { // Unless we are exiting a #include, make sure to skip ahead to the line the // #include directive was at. - SourceManager &SourceMgr = PP.getSourceManager(); + SourceManager &SourceMgr = SM; + + PresumedLoc UserLoc = SourceMgr.getPresumedLoc(Loc); + unsigned NewLine = UserLoc.getLine(); + if (Reason == PPCallbacks::EnterFile) { SourceLocation IncludeLoc = SourceMgr.getPresumedLoc(Loc).getIncludeLoc(); if (IncludeLoc.isValid()) MoveToLine(IncludeLoc); } else if (Reason == PPCallbacks::SystemHeaderPragma) { - MoveToLine(Loc); + MoveToLine(NewLine); // TODO GCC emits the # directive for this directive on the line AFTER the // directive and emits a bunch of spaces that aren't needed. Emulate this // strange behavior. } - - Loc = SourceMgr.getInstantiationLoc(Loc); - // FIXME: Should use presumed line #! - CurLine = SourceMgr.getInstantiationLineNumber(Loc); + + CurLine = NewLine; if (DisableLineMarkers) return; CurFilename.clear(); - CurFilename += SourceMgr.getPresumedLoc(Loc).getFilename(); + CurFilename += UserLoc.getFilename(); Lexer::Stringify(CurFilename); FileType = NewFileType; @@ -318,8 +325,7 @@ bool PrintPPOutputPPCallbacks::HandleFirstTokOnLine(Token &Tok) { // Print out space characters so that the first token on a line is // indented for easy reading. - const SourceManager &SourceMgr = PP.getSourceManager(); - unsigned ColNo = SourceMgr.getInstantiationColumnNumber(Tok.getLocation()); + unsigned ColNo = SM.getInstantiationColumnNumber(Tok.getLocation()); // This hack prevents stuff like: // #define HASH # @@ -391,6 +397,7 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok, PrintPPOutputPPCallbacks *Callbacks, llvm::raw_ostream &OS) { char Buffer[256]; + Token PrevPrevTok; Token PrevTok; while (1) { @@ -402,7 +409,7 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok, // useful to look at and no concatenation could happen anyway. (Callbacks->hasEmittedTokensOnThisLine() && // Don't print "-" next to "-", it would form "--". - Callbacks->AvoidConcat(PrevTok, Tok))) { + Callbacks->AvoidConcat(PrevPrevTok, PrevTok, Tok))) { OS << ' '; } @@ -433,6 +440,7 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok, if (Tok.is(tok::eof)) break; + PrevPrevTok = PrevTok; PrevTok = Tok; PP.Lex(Tok); } @@ -448,8 +456,7 @@ static int MacroIDCompare(const void* a, const void* b) { static void DoPrintMacros(Preprocessor &PP, llvm::raw_ostream *OS) { // -dM mode just scans and ignores all tokens in the files, then dumps out // the macro table at the end. - if (PP.EnterMainSourceFile()) - return; + PP.EnterMainSourceFile(); Token Tok; do PP.Lex(Tok); @@ -484,8 +491,6 @@ void clang::DoPrintPreprocessedInput(Preprocessor &PP, llvm::raw_ostream *OS, // to -C or -CC. PP.SetCommentRetentionState(Opts.ShowComments, Opts.ShowMacroComments); - OS->SetBufferSize(64*1024); - PrintPPOutputPPCallbacks *Callbacks = new PrintPPOutputPPCallbacks(PP, *OS, !Opts.ShowLineMarkers, Opts.ShowMacros); @@ -496,8 +501,7 @@ void clang::DoPrintPreprocessedInput(Preprocessor &PP, llvm::raw_ostream *OS, PP.addPPCallbacks(Callbacks); // After we have configured the preprocessor, enter the main file. - if (PP.EnterMainSourceFile()) - return; + PP.EnterMainSourceFile(); // Consume all of the tokens that come from the predefines buffer. Those // should not be emitted into the output and are guaranteed to be at the |