From 881dff36831f30d6b4792e398bc5a28775ac2757 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Fri, 13 Sep 2013 22:00:30 +0000 Subject: Lex and ignore Microsoft's #pragma warning(...) Summary: This fixes PR17145 and avoids unknown pragma warnings. This change does not attempt to map MSVC warning numbers to clang warning flags. Perhaps in the future we will implement a mapping for some common subset of Microsoft warnings, but for now we don't. Reviewers: rsmith CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1652 llvm-svn: 190726 --- clang/lib/Frontend/PrintPreprocessedOutput.cpp | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'clang/lib/Frontend/PrintPreprocessedOutput.cpp') diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp index e0ec08fb90a..3e45fc79f40 100644 --- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp @@ -152,6 +152,10 @@ public: StringRef Namespace); virtual void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace, diag::Mapping Map, StringRef Str); + virtual void PragmaWarning(SourceLocation Loc, StringRef WarningSpec, + ArrayRef Ids); + virtual void PragmaWarningPush(SourceLocation Loc, int Level); + virtual void PragmaWarningPop(SourceLocation Loc); bool HandleFirstTokOnLine(Token &Tok); @@ -507,6 +511,36 @@ PragmaDiagnostic(SourceLocation Loc, StringRef Namespace, setEmittedDirectiveOnThisLine(); } +void PrintPPOutputPPCallbacks::PragmaWarning(SourceLocation Loc, + StringRef WarningSpec, + ArrayRef Ids) { + startNewLineIfNeeded(); + MoveToLine(Loc); + OS << "#pragma warning(" << WarningSpec << ':'; + for (ArrayRef::iterator I = Ids.begin(), E = Ids.end(); I != E; ++I) + OS << ' ' << *I; + OS << ')'; + setEmittedDirectiveOnThisLine(); +} + +void PrintPPOutputPPCallbacks::PragmaWarningPush(SourceLocation Loc, + int Level) { + startNewLineIfNeeded(); + MoveToLine(Loc); + OS << "#pragma warning(push"; + if (Level) + OS << ", " << Level; + OS << ')'; + setEmittedDirectiveOnThisLine(); +} + +void PrintPPOutputPPCallbacks::PragmaWarningPop(SourceLocation Loc) { + startNewLineIfNeeded(); + MoveToLine(Loc); + OS << "#pragma warning(pop)"; + setEmittedDirectiveOnThisLine(); +} + /// HandleFirstTokOnLine - When emitting a preprocessed file in -E mode, this /// is called for the first token on each new line. If this really is the start /// of a new logical line, handle it and return true, otherwise return false. -- cgit v1.2.3