diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-04-02 19:05:20 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-04-02 19:05:20 +0000 |
commit | 26df2f09587ad6978ac8e357ca46b2731d591cc4 (patch) | |
tree | 1196ee4c5e3ebc1f03d3b89676484f23f6a0bf9c /lib/Frontend/FixItRewriter.cpp | |
parent | d09a456e466597fe1667ea5e757bfe53be2cba7d (diff) |
Add a new command-line option "-fixit-at=file:line:column" that only
applies fix-its to error messages that occur at that specific location
in the program.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68342 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/FixItRewriter.cpp')
-rw-r--r-- | lib/Frontend/FixItRewriter.cpp | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/lib/Frontend/FixItRewriter.cpp b/lib/Frontend/FixItRewriter.cpp index 8883b91ab9..6fde5dae75 100644 --- a/lib/Frontend/FixItRewriter.cpp +++ b/lib/Frontend/FixItRewriter.cpp @@ -81,8 +81,43 @@ bool FixItRewriter::IncludeInDiagnosticCounts() const { void FixItRewriter::HandleDiagnostic(Diagnostic::Level DiagLevel, const DiagnosticInfo &Info) { - if (Client) - Client->HandleDiagnostic(DiagLevel, Info); + Client->HandleDiagnostic(DiagLevel, Info); + + // Skip over any diagnostics that are ignored. + if (DiagLevel == Diagnostic::Ignored) + return; + + if (!FixItLocations.empty()) { + // The user has specified the locations where we should perform + // the various fix-it modifications. + + // If this diagnostic does not have any code modifications, + // completely ignore it, even if it's an error: fix-it locations + // are meant to perform specific fix-ups even in the presence of + // other errors. + if (Info.getNumCodeModificationHints() == 0) + return; + + // See if the location of the error is one that matches what the + // user requested. + bool AcceptableLocation = false; + const FileEntry *File + = Rewrite.getSourceMgr().getFileEntryForID( + Info.getLocation().getFileID()); + unsigned Line = Info.getLocation().getSpellingLineNumber(); + unsigned Column = Info.getLocation().getSpellingColumnNumber(); + for (llvm::SmallVector<RequestedSourceLocation, 4>::iterator + Loc = FixItLocations.begin(), LocEnd = FixItLocations.end(); + Loc != LocEnd; ++Loc) { + if (Loc->File == File && Loc->Line == Line && Loc->Column == Column) { + AcceptableLocation = true; + break; + } + } + + if (!AcceptableLocation) + return; + } // Make sure that we can perform all of the modifications we // in this diagnostic. |