[cfe-commits] r149676 - in /cfe/trunk: include/clang/Basic/Diagnostic.h include/clang/Basic/PartialDiagnostic.h lib/Basic/Diagnostic.cpp lib/Basic/DiagnosticIDs.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Thu Feb 2 21:58:22 PST 2012
Author: akirtzidis
Date: Thu Feb 2 23:58:22 2012
New Revision: 149676
URL: http://llvm.org/viewvc/llvm-project?rev=149676&view=rev
Log:
Change the fixed array of FixitHints to a SmallVector to lift off
the limit on the number of fixits.
Modified:
cfe/trunk/include/clang/Basic/Diagnostic.h
cfe/trunk/include/clang/Basic/PartialDiagnostic.h
cfe/trunk/lib/Basic/Diagnostic.cpp
cfe/trunk/lib/Basic/DiagnosticIDs.cpp
Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=149676&r1=149675&r2=149676&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Thu Feb 2 23:58:22 2012
@@ -614,9 +614,6 @@
signed char NumDiagArgs;
/// NumRanges - This is the number of ranges in the DiagRanges array.
unsigned char NumDiagRanges;
- /// \brief The number of code modifications hints in the
- /// FixItHints array.
- unsigned char NumFixItHints;
/// DiagArgumentsKind - This is an array of ArgumentKind::ArgumentKind enum
/// values, with one for each argument. This specifies whether the argument
@@ -638,11 +635,9 @@
/// only support 10 ranges, could easily be extended if needed.
CharSourceRange DiagRanges[10];
- enum { MaxFixItHints = 6 };
-
/// FixItHints - If valid, provides a hint with some code
/// to insert, remove, or modify at a particular position.
- FixItHint FixItHints[MaxFixItHints];
+ SmallVector<FixItHint, 6> FixItHints;
DiagnosticMappingInfo makeMappingInfo(diag::Mapping Map, SourceLocation L) {
bool isPragma = L.isValid();
@@ -720,12 +715,14 @@
/// for example.
class DiagnosticBuilder {
mutable DiagnosticsEngine *DiagObj;
- mutable unsigned NumArgs, NumRanges, NumFixItHints;
+ mutable unsigned NumArgs, NumRanges;
void operator=(const DiagnosticBuilder&); // DO NOT IMPLEMENT
friend class DiagnosticsEngine;
explicit DiagnosticBuilder(DiagnosticsEngine *diagObj)
- : DiagObj(diagObj), NumArgs(0), NumRanges(0), NumFixItHints(0) {}
+ : DiagObj(diagObj), NumArgs(0), NumRanges(0) {
+ DiagObj->FixItHints.clear();
+ }
friend class PartialDiagnostic;
@@ -740,7 +737,6 @@
D.DiagObj = 0;
NumArgs = D.NumArgs;
NumRanges = D.NumRanges;
- NumFixItHints = D.NumFixItHints;
}
/// \brief Simple enumeration value used to give a name to the
@@ -750,7 +746,7 @@
/// \brief Create an empty DiagnosticBuilder object that represents
/// no actual diagnostic.
explicit DiagnosticBuilder(SuppressKind)
- : DiagObj(0), NumArgs(0), NumRanges(0), NumFixItHints(0) { }
+ : DiagObj(0), NumArgs(0), NumRanges(0) { }
/// \brief Force the diagnostic builder to emit the diagnostic now.
///
@@ -816,12 +812,8 @@
}
void AddFixItHint(const FixItHint &Hint) const {
- assert(NumFixItHints < DiagnosticsEngine::MaxFixItHints &&
- "Too many fix-it hints!");
- if (NumFixItHints >= DiagnosticsEngine::MaxFixItHints)
- return; // Don't crash in release builds
if (DiagObj)
- DiagObj->FixItHints[NumFixItHints++] = Hint;
+ DiagObj->FixItHints.push_back(Hint);
}
};
@@ -997,7 +989,7 @@
}
unsigned getNumFixItHints() const {
- return DiagObj->NumFixItHints;
+ return DiagObj->FixItHints.size();
}
const FixItHint &getFixItHint(unsigned Idx) const {
@@ -1005,8 +997,8 @@
}
const FixItHint *getFixItHints() const {
- return DiagObj->NumFixItHints?
- &DiagObj->FixItHints[0] : 0;
+ return getNumFixItHints()?
+ DiagObj->FixItHints.data() : 0;
}
/// FormatDiagnostic - Format this diagnostic into a string, substituting the
Modified: cfe/trunk/include/clang/Basic/PartialDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/PartialDiagnostic.h?rev=149676&r1=149675&r2=149676&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/PartialDiagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/PartialDiagnostic.h Thu Feb 2 23:58:22 2012
@@ -30,12 +30,11 @@
// DiagnosticsEngine are private but DiagnosticsEngine declares
// PartialDiagnostic a friend. These enum values are redeclared
// here so that the nested Storage class below can access them.
- MaxArguments = DiagnosticsEngine::MaxArguments,
- MaxFixItHints = DiagnosticsEngine::MaxFixItHints
+ MaxArguments = DiagnosticsEngine::MaxArguments
};
struct Storage {
- Storage() : NumDiagArgs(0), NumDiagRanges(0), NumFixItHints(0) { }
+ Storage() : NumDiagArgs(0), NumDiagRanges(0) { }
enum {
/// MaxArguments - The maximum number of arguments we can hold. We
@@ -51,10 +50,6 @@
/// NumDiagRanges - This is the number of ranges in the DiagRanges array.
unsigned char NumDiagRanges;
- /// \brief The number of code modifications hints in the
- /// FixItHints array.
- unsigned char NumFixItHints;
-
/// DiagArgumentsKind - This is an array of ArgumentKind::ArgumentKind enum
/// values, with one for each argument. This specifies whether the argument
/// is in DiagArgumentsStr or in DiagArguments.
@@ -74,11 +69,9 @@
/// only support 10 ranges, could easily be extended if needed.
CharSourceRange DiagRanges[10];
- enum { MaxFixItHints = PartialDiagnostic::MaxFixItHints };
-
/// FixItHints - If valid, provides a hint with some code
/// to insert, remove, or modify at a particular position.
- FixItHint FixItHints[MaxFixItHints];
+ SmallVector<FixItHint, 6> FixItHints;
};
/// \brief An allocator for Storage objects, which uses a small cache to
@@ -101,7 +94,7 @@
Storage *Result = FreeList[--NumFreeListEntries];
Result->NumDiagArgs = 0;
Result->NumDiagRanges = 0;
- Result->NumFixItHints = 0;
+ Result->FixItHints.clear();
return Result;
}
@@ -172,12 +165,7 @@
if (!DiagStorage)
DiagStorage = getStorage();
- assert(DiagStorage->NumFixItHints < Storage::MaxFixItHints &&
- "Too many code modification hints!");
- if (DiagStorage->NumFixItHints >= Storage::MaxFixItHints)
- return; // Don't crash in release builds
- DiagStorage->FixItHints[DiagStorage->NumFixItHints++]
- = Hint;
+ DiagStorage->FixItHints.push_back(Hint);
}
public:
@@ -281,7 +269,7 @@
DB.AddSourceRange(DiagStorage->DiagRanges[i]);
// Add all fix-its.
- for (unsigned i = 0, e = DiagStorage->NumFixItHints; i != e; ++i)
+ for (unsigned i = 0, e = DiagStorage->FixItHints.size(); i != e; ++i)
DB.AddFixItHint(DiagStorage->FixItHints[i]);
}
Modified: cfe/trunk/lib/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Diagnostic.cpp?rev=149676&r1=149675&r2=149676&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Basic/Diagnostic.cpp Thu Feb 2 23:58:22 2012
@@ -330,14 +330,11 @@
RE = storedDiag.range_end(); RI != RE; ++RI)
DiagRanges[i++] = *RI;
- NumFixItHints = storedDiag.fixit_size();
- assert(NumFixItHints < DiagnosticsEngine::MaxFixItHints &&
- "Too many fix-it hints!");
- i = 0;
+ FixItHints.clear();
for (StoredDiagnostic::fixit_iterator
FI = storedDiag.fixit_begin(),
FE = storedDiag.fixit_end(); FI != FE; ++FI)
- FixItHints[i++] = *FI;
+ FixItHints.push_back(*FI);
assert(Client && "DiagnosticConsumer not set!");
Level DiagLevel = storedDiag.getLevel();
@@ -354,7 +351,6 @@
void DiagnosticBuilder::FlushCounts() {
DiagObj->NumDiagArgs = NumArgs;
DiagObj->NumDiagRanges = NumRanges;
- DiagObj->NumFixItHints = NumFixItHints;
}
bool DiagnosticBuilder::Emit() {
Modified: cfe/trunk/lib/Basic/DiagnosticIDs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/DiagnosticIDs.cpp?rev=149676&r1=149675&r2=149676&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/DiagnosticIDs.cpp (original)
+++ cfe/trunk/lib/Basic/DiagnosticIDs.cpp Thu Feb 2 23:58:22 2012
@@ -799,12 +799,12 @@
// If we have any Fix-Its, make sure that all of the Fix-Its point into
// source locations that aren't macro expansions. If any point into macro
// expansions, remove all of the Fix-Its.
- for (unsigned I = 0, N = Diag.NumFixItHints; I != N; ++I) {
+ for (unsigned I = 0, N = Diag.FixItHints.size(); I != N; ++I) {
const FixItHint &FixIt = Diag.FixItHints[I];
if (FixIt.RemoveRange.isInvalid() ||
FixIt.RemoveRange.getBegin().isMacroID() ||
FixIt.RemoveRange.getEnd().isMacroID()) {
- Diag.NumFixItHints = 0;
+ Diag.FixItHints.clear();
break;
}
}
More information about the cfe-commits
mailing list