From 7c175fb196a2bc3dbc86ea3865c713e1875f3f6d Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 13 Mar 2009 21:44:46 +0000 Subject: fix PR3798 by ignoring all diagnostics generated while repreprocessing a file in rewrite macros. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66961 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Rewrite/HTMLRewrite.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'lib/Rewrite/HTMLRewrite.cpp') diff --git a/lib/Rewrite/HTMLRewrite.cpp b/lib/Rewrite/HTMLRewrite.cpp index 380f7da743..9bb5d7cfd3 100644 --- a/lib/Rewrite/HTMLRewrite.cpp +++ b/lib/Rewrite/HTMLRewrite.cpp @@ -424,6 +424,17 @@ void html::SyntaxHighlight(Rewriter &R, FileID FID, Preprocessor &PP) { } } +namespace { +/// IgnoringDiagClient - This is a diagnostic client that just ignores all +/// diags. +class IgnoringDiagClient : public DiagnosticClient { + void HandleDiagnostic(Diagnostic::Level DiagLevel, + const DiagnosticInfo &Info) { + // Just ignore it. + } +}; +} + /// HighlightMacros - This uses the macro table state from the end of the /// file, to re-expand macros and insert (into the HTML) information about the /// macro expansions. This won't be perfectly perfect, but it will be @@ -466,6 +477,14 @@ void html::HighlightMacros(Rewriter &R, FileID FID, Preprocessor& PP) { if (Tok.is(tok::eof)) break; } + // Temporarily change the diagnostics object so that we ignore any generated + // diagnostics from this pass. + IgnoringDiagClient TmpDC; + Diagnostic TmpDiags(&TmpDC); + + Diagnostic *OldDiags = &PP.getDiagnostics(); + PP.setDiagnostics(TmpDiags); + // Inform the preprocessor that we don't want comments. PP.SetCommentRetentionState(false, false); @@ -542,6 +561,9 @@ void html::HighlightMacros(Rewriter &R, FileID FID, Preprocessor& PP) { HighlightRange(R, LLoc.first, LLoc.second, "", Expansion.c_str()); } + + // Restore diagnostics object back to its own thing. + PP.setDiagnostics(*OldDiags); } void html::HighlightMacros(Rewriter &R, FileID FID, -- cgit v1.2.3-18-g5258