diff options
author | Alp Toker <alp@nuanti.com> | 2014-01-26 05:07:32 +0000 |
---|---|---|
committer | Alp Toker <alp@nuanti.com> | 2014-01-26 05:07:32 +0000 |
commit | 35fe9a0c1e52c387dfadabafa4b2d26761595786 (patch) | |
tree | c6a81dbdcae82885c6c80ece724b8ac2f4840787 /lib/ARCMigrate/TransformActions.cpp | |
parent | 9a85eb6cbc966636b60b207cf693ab4220594a91 (diff) |
ARCMigrate: Introduce proper diagnostics for TransformActions
This starts to switch ARCMT to use proper diagnostic messages. The old use was
based on incorrect example code from the documentation.
The logic of the previous report() functions has been retained to support any
external consumers that might be intercepting diagnostic messages through the
old interface.
Note that the change in test/Misc/warning-flags.c isn't a new warning without a
flag, rather one that was previously invisible to the test. Adding a flag might
be a good idea though.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@200124 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ARCMigrate/TransformActions.cpp')
-rw-r--r-- | lib/ARCMigrate/TransformActions.cpp | 71 |
1 files changed, 23 insertions, 48 deletions
diff --git a/lib/ARCMigrate/TransformActions.cpp b/lib/ARCMigrate/TransformActions.cpp index 2fd0619df9..e6268a1792 100644 --- a/lib/ARCMigrate/TransformActions.cpp +++ b/lib/ARCMigrate/TransformActions.cpp @@ -673,60 +673,35 @@ void TransformActions::applyRewrites(RewriteReceiver &receiver) { static_cast<TransformActionsImpl*>(Impl)->applyRewrites(receiver); } -void TransformActions::reportError(StringRef error, SourceLocation loc, - SourceRange range) { - assert(!static_cast<TransformActionsImpl*>(Impl)->isInTransaction() && +DiagnosticBuilder TransformActions::report(SourceLocation loc, unsigned diagId, + SourceRange range) { + assert(!static_cast<TransformActionsImpl *>(Impl)->isInTransaction() && "Errors should be emitted out of a transaction"); - SourceManager &SM = static_cast<TransformActionsImpl*>(Impl)-> - getASTContext().getSourceManager(); - if (SM.isInSystemHeader(SM.getExpansionLoc(loc))) - return; - - // FIXME: Use a custom category name to distinguish rewriter errors. - std::string rewriteErr = "[rewriter] "; - rewriteErr += error; - unsigned diagID - = Diags.getDiagnosticIDs()->getCustomDiagID(DiagnosticIDs::Error, - rewriteErr); - Diags.Report(loc, diagID) << range; - ReportedErrors = true; + SourceManager &SM = static_cast<TransformActionsImpl *>(Impl) + ->getASTContext() + .getSourceManager(); + DiagnosticsEngine::Level L = Diags.getDiagnosticLevel(diagId, loc); + // TODO: Move this check to the caller to ensure consistent note attachments. + if (L == DiagnosticsEngine::Ignored || + SM.isInSystemHeader(SM.getExpansionLoc(loc))) + return DiagnosticBuilder::getEmpty(); + if (L >= DiagnosticsEngine::Error) + ReportedErrors = true; + return Diags.Report(loc, diagId) << range; } -void TransformActions::reportWarning(StringRef warning, SourceLocation loc, +void TransformActions::reportError(StringRef message, SourceLocation loc, SourceRange range) { - assert(!static_cast<TransformActionsImpl*>(Impl)->isInTransaction() && - "Warning should be emitted out of a transaction"); - - SourceManager &SM = static_cast<TransformActionsImpl*>(Impl)-> - getASTContext().getSourceManager(); - if (SM.isInSystemHeader(SM.getExpansionLoc(loc))) - return; - - // FIXME: Use a custom category name to distinguish rewriter errors. - std::string rewriterWarn = "[rewriter] "; - rewriterWarn += warning; - unsigned diagID - = Diags.getDiagnosticIDs()->getCustomDiagID(DiagnosticIDs::Warning, - rewriterWarn); - Diags.Report(loc, diagID) << range; + report(loc, diag::err_mt_message, range) << message; } -void TransformActions::reportNote(StringRef note, SourceLocation loc, - SourceRange range) { - assert(!static_cast<TransformActionsImpl*>(Impl)->isInTransaction() && - "Errors should be emitted out of a transaction"); - - SourceManager &SM = static_cast<TransformActionsImpl*>(Impl)-> - getASTContext().getSourceManager(); - if (SM.isInSystemHeader(SM.getExpansionLoc(loc))) - return; +void TransformActions::reportWarning(StringRef message, SourceLocation loc, + SourceRange range) { + report(loc, diag::warn_mt_message, range) << message; +} - // FIXME: Use a custom category name to distinguish rewriter errors. - std::string rewriteNote = "[rewriter] "; - rewriteNote += note; - unsigned diagID - = Diags.getDiagnosticIDs()->getCustomDiagID(DiagnosticIDs::Note, - rewriteNote); - Diags.Report(loc, diagID) << range; +void TransformActions::reportNote(StringRef message, SourceLocation loc, + SourceRange range) { + report(loc, diag::note_mt_message, range) << message; } |