aboutsummaryrefslogtreecommitdiff
path: root/include/clang/Basic
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-02-03 05:58:22 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-02-03 05:58:22 +0000
commitcbf46a0b2bb2b47d6e13437e0d52cc583c5ce539 (patch)
tree5340c9ce936d820fd757cef447feeaca57b78c00 /include/clang/Basic
parent8deabc133c121f6c5561d0b2171a41cb2c29b2ce (diff)
Change the fixed array of FixitHints to a SmallVector to lift off
the limit on the number of fixits. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149676 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic')
-rw-r--r--include/clang/Basic/Diagnostic.h28
-rw-r--r--include/clang/Basic/PartialDiagnostic.h24
2 files changed, 16 insertions, 36 deletions
diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h
index 3aa1d55c10..8cb1e19940 100644
--- a/include/clang/Basic/Diagnostic.h
+++ b/include/clang/Basic/Diagnostic.h
@@ -614,9 +614,6 @@ private:
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 @@ private:
/// 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 @@ public:
/// 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 @@ public:
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 @@ public:
/// \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 @@ public:
}
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 @@ public:
}
unsigned getNumFixItHints() const {
- return DiagObj->NumFixItHints;
+ return DiagObj->FixItHints.size();
}
const FixItHint &getFixItHint(unsigned Idx) const {
@@ -1005,8 +997,8 @@ public:
}
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
diff --git a/include/clang/Basic/PartialDiagnostic.h b/include/clang/Basic/PartialDiagnostic.h
index 6049123148..f6092e6858 100644
--- a/include/clang/Basic/PartialDiagnostic.h
+++ b/include/clang/Basic/PartialDiagnostic.h
@@ -30,12 +30,11 @@ public:
// 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 @@ public:
/// 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 @@ public:
/// 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 @@ public:
Storage *Result = FreeList[--NumFreeListEntries];
Result->NumDiagArgs = 0;
Result->NumDiagRanges = 0;
- Result->NumFixItHints = 0;
+ Result->FixItHints.clear();
return Result;
}
@@ -172,12 +165,7 @@ private:
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 @@ public:
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]);
}