[cfe-commits] r111362 - in /cfe/trunk: include/clang/Basic/Diagnostic.h lib/Basic/Diagnostic.cpp lib/Frontend/TextDiagnosticPrinter.cpp lib/Rewrite/FixItRewriter.cpp tools/libclang/CIndexDiagnostic.cpp
Douglas Gregor
dgregor at apple.com
Wed Aug 18 07:24:02 PDT 2010
Author: dgregor
Date: Wed Aug 18 09:24:02 2010
New Revision: 111362
URL: http://llvm.org/viewvc/llvm-project?rev=111362&view=rev
Log:
Simplify FixItHint by eliminated the unnecessary InsertionLoc
location. Patch by Eelis van der Weegen!
Modified:
cfe/trunk/include/clang/Basic/Diagnostic.h
cfe/trunk/lib/Basic/Diagnostic.cpp
cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
cfe/trunk/lib/Rewrite/FixItRewriter.cpp
cfe/trunk/tools/libclang/CIndexDiagnostic.cpp
Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=111362&r1=111361&r2=111362&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Wed Aug 18 09:24:02 2010
@@ -95,23 +95,20 @@
/// compilation.
class FixItHint {
public:
- /// \brief Code that should be removed to correct the error.
+ /// \brief Code that should be replaced to correct the error. Empty for an
+ /// insertion hint.
CharSourceRange RemoveRange;
- /// \brief The location at which we should insert code to correct
- /// the error.
- SourceLocation InsertionLoc;
-
/// \brief The actual code to insert at the insertion location, as a
/// string.
std::string CodeToInsert;
/// \brief Empty code modification hint, indicating that no code
/// modification is known.
- FixItHint() : RemoveRange(), InsertionLoc() { }
+ FixItHint() : RemoveRange() { }
bool isNull() const {
- return !RemoveRange.isValid() && !InsertionLoc.isValid();
+ return !RemoveRange.isValid();
}
/// \brief Create a code modification hint that inserts the given
@@ -119,7 +116,8 @@
static FixItHint CreateInsertion(SourceLocation InsertionLoc,
llvm::StringRef Code) {
FixItHint Hint;
- Hint.InsertionLoc = InsertionLoc;
+ Hint.RemoveRange =
+ CharSourceRange(SourceRange(InsertionLoc, InsertionLoc), false);
Hint.CodeToInsert = Code;
return Hint;
}
@@ -141,7 +139,6 @@
llvm::StringRef Code) {
FixItHint Hint;
Hint.RemoveRange = RemoveRange;
- Hint.InsertionLoc = RemoveRange.getBegin();
Hint.CodeToInsert = Code;
return Hint;
}
Modified: cfe/trunk/lib/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Diagnostic.cpp?rev=111362&r1=111361&r2=111362&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Basic/Diagnostic.cpp Wed Aug 18 09:24:02 2010
@@ -1152,11 +1152,6 @@
break;
}
- if (F->InsertionLoc.isValid() && F->InsertionLoc.isMacroID()) {
- NumFixIts = 0;
- break;
- }
-
++NumFixIts;
}
@@ -1166,7 +1161,6 @@
WriteSourceLocation(OS, SM, F->RemoveRange.getBegin());
WriteSourceLocation(OS, SM, F->RemoveRange.getEnd());
WriteUnsigned(OS, F->RemoveRange.isTokenRange());
- WriteSourceLocation(OS, SM, F->InsertionLoc);
WriteString(OS, F->CodeToInsert);
}
}
@@ -1294,12 +1288,11 @@
if (ReadUnsigned(Memory, MemoryEnd, NumFixIts))
return Diag;
for (unsigned I = 0; I != NumFixIts; ++I) {
- SourceLocation RemoveBegin, RemoveEnd, InsertionLoc;
+ SourceLocation RemoveBegin, RemoveEnd;
unsigned InsertLen = 0, RemoveIsTokenRange;
if (ReadSourceLocation(FM, SM, Memory, MemoryEnd, RemoveBegin) ||
ReadSourceLocation(FM, SM, Memory, MemoryEnd, RemoveEnd) ||
ReadUnsigned(Memory, MemoryEnd, RemoveIsTokenRange) ||
- ReadSourceLocation(FM, SM, Memory, MemoryEnd, InsertionLoc) ||
ReadUnsigned(Memory, MemoryEnd, InsertLen) ||
Memory + InsertLen > MemoryEnd) {
Diag.FixIts.clear();
@@ -1309,7 +1302,6 @@
FixItHint Hint;
Hint.RemoveRange = CharSourceRange(SourceRange(RemoveBegin, RemoveEnd),
RemoveIsTokenRange);
- Hint.InsertionLoc = InsertionLoc;
Hint.CodeToInsert.assign(Memory, Memory + InsertLen);
Memory += InsertLen;
Diag.FixIts.push_back(Hint);
Modified: cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp?rev=111362&r1=111361&r2=111362&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp Wed Aug 18 09:24:02 2010
@@ -447,11 +447,11 @@
if (NumHints && DiagOpts->ShowFixits) {
for (const FixItHint *Hint = Hints, *LastHint = Hints + NumHints;
Hint != LastHint; ++Hint) {
- if (Hint->InsertionLoc.isValid()) {
+ if (!Hint->CodeToInsert.empty()) {
// We have an insertion hint. Determine whether the inserted
// code is on the same line as the caret.
std::pair<FileID, unsigned> HintLocInfo
- = SM.getDecomposedInstantiationLoc(Hint->InsertionLoc);
+ = SM.getDecomposedInstantiationLoc(Hint->RemoveRange.getBegin());
if (SM.getLineNumber(HintLocInfo.first, HintLocInfo.second) ==
SM.getLineNumber(FID, FileOffset)) {
// Insert the new code into the line just below the code
Modified: cfe/trunk/lib/Rewrite/FixItRewriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/FixItRewriter.cpp?rev=111362&r1=111361&r2=111362&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/FixItRewriter.cpp (original)
+++ cfe/trunk/lib/Rewrite/FixItRewriter.cpp Wed Aug 18 09:24:02 2010
@@ -96,12 +96,6 @@
CanRewrite = false;
break;
}
-
- if (Hint.InsertionLoc.isValid() &&
- !Rewrite.isRewritable(Hint.InsertionLoc)) {
- CanRewrite = false;
- break;
- }
}
if (!CanRewrite) {
@@ -120,12 +114,6 @@
for (unsigned Idx = 0, Last = Info.getNumFixItHints();
Idx < Last; ++Idx) {
const FixItHint &Hint = Info.getFixItHint(Idx);
- if (!Hint.RemoveRange.isValid()) {
- // We're adding code.
- if (Rewrite.InsertTextBefore(Hint.InsertionLoc, Hint.CodeToInsert))
- Failed = true;
- continue;
- }
if (Hint.CodeToInsert.empty()) {
// We're removing code.
Modified: cfe/trunk/tools/libclang/CIndexDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexDiagnostic.cpp?rev=111362&r1=111361&r2=111362&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexDiagnostic.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexDiagnostic.cpp Wed Aug 18 09:24:02 2010
@@ -204,26 +204,13 @@
const FixItHint &Hint = StoredDiag->Diag.fixit_begin()[FixIt];
if (ReplacementRange) {
- if (Hint.RemoveRange.isInvalid()) {
- // Create an empty range that refers to a single source
- // location (which is the insertion point).
- CXSourceRange Range = {
- { (void *)&StoredDiag->Diag.getLocation().getManager(),
- (void *)&StoredDiag->LangOpts },
- Hint.InsertionLoc.getRawEncoding(),
- Hint.InsertionLoc.getRawEncoding()
- };
-
- *ReplacementRange = Range;
- } else {
- // Create a range that covers the entire replacement (or
- // removal) range, adjusting the end of the range to point to
- // the end of the token.
- *ReplacementRange
- = translateSourceRange(StoredDiag->Diag.getLocation().getManager(),
- StoredDiag->LangOpts,
- Hint.RemoveRange);
- }
+ // Create a range that covers the entire replacement (or
+ // removal) range, adjusting the end of the range to point to
+ // the end of the token.
+ *ReplacementRange
+ = translateSourceRange(StoredDiag->Diag.getLocation().getManager(),
+ StoredDiag->LangOpts,
+ Hint.RemoveRange);
}
return createCXString(Hint.CodeToInsert);
More information about the cfe-commits
mailing list