summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2010-07-25 21:40:48 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2010-07-25 21:40:48 +0000
commitf5c4b49278f8e619f6ff9682b5fd07fc9fbee72c (patch)
tree7001c0524a5f7062606fbd0291719452592abdb3 /clang
parent8ae3ecad2bbf6449111e863625c25b190c15cf6a (diff)
downloadbcm5719-llvm-f5c4b49278f8e619f6ff9682b5fd07fc9fbee72c.tar.gz
bcm5719-llvm-f5c4b49278f8e619f6ff9682b5fd07fc9fbee72c.zip
Wrap bit mangling logic for DiagMappings in its own class so it doesn't leak
into other code. Make it an array instead of a constant-length vector. llvm-svn: 109384
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/Basic/Diagnostic.h26
-rw-r--r--clang/lib/Basic/Diagnostic.cpp7
2 files changed, 21 insertions, 12 deletions
diff --git a/clang/include/clang/Basic/Diagnostic.h b/clang/include/clang/Basic/Diagnostic.h
index b09fd814b97..c67de985a02 100644
--- a/clang/include/clang/Basic/Diagnostic.h
+++ b/clang/include/clang/Basic/Diagnostic.h
@@ -213,8 +213,24 @@ private:
/// when the mapping was established as a user mapping. If the high bit is
/// clear, then the low bits are set to the default value, and should be
/// mapped with -pedantic, -Werror, etc.
+ class DiagMappings {
+ unsigned char Values[diag::DIAG_UPPER_LIMIT/2];
+
+ public:
+ DiagMappings() {
+ memset(Values, 0, diag::DIAG_UPPER_LIMIT/2);
+ }
+
+ void setMapping(diag::kind Diag, unsigned Map) {
+ size_t Shift = (Diag & 1)*4;
+ Values[Diag/2] = (Values[Diag/2] & ~(15 << Shift)) | (Map << Shift);
+ }
+
+ diag::Mapping getMapping(diag::kind Diag) const {
+ return (diag::Mapping)((Values[Diag/2] >> (Diag & 1)*4) & 15);
+ }
+ };
- typedef std::vector<unsigned char> DiagMappings;
mutable std::vector<DiagMappings> DiagMappingsStack;
/// ErrorOccurred / FatalErrorOccurred - This is set to true when an error or
@@ -539,17 +555,13 @@ private:
/// specified builtin diagnostic. This returns the high bit encoding, or zero
/// if the field is completely uninitialized.
diag::Mapping getDiagnosticMappingInfo(diag::kind Diag) const {
- const DiagMappings &currentMappings = DiagMappingsStack.back();
- return (diag::Mapping)((currentMappings[Diag/2] >> (Diag & 1)*4) & 15);
+ return DiagMappingsStack.back().getMapping(Diag);
}
void setDiagnosticMappingInternal(unsigned DiagId, unsigned Map,
bool isUser) const {
if (isUser) Map |= 8; // Set the high bit for user mappings.
- unsigned char &Slot = DiagMappingsStack.back()[DiagId/2];
- unsigned Shift = (DiagId & 1)*4;
- Slot &= ~(15 << Shift);
- Slot |= Map << Shift;
+ DiagMappingsStack.back().setMapping((diag::kind)DiagId, Map);
}
/// getDiagnosticLevel - This is an internal implementation helper used when
diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index 68548da0cb1..f956f1aec85 100644
--- a/clang/lib/Basic/Diagnostic.cpp
+++ b/clang/lib/Basic/Diagnostic.cpp
@@ -334,11 +334,8 @@ void Diagnostic::Reset() {
DelayedDiagID = 0;
// Set all mappings to 'unset'.
- while (!DiagMappingsStack.empty())
- DiagMappingsStack.pop_back();
-
- DiagMappings BlankDiags(diag::DIAG_UPPER_LIMIT/2, 0);
- DiagMappingsStack.push_back(BlankDiags);
+ DiagMappingsStack.clear();
+ DiagMappingsStack.push_back(DiagMappings());
}
/// getDescription - Given a diagnostic ID, return a description of the
OpenPOWER on IntegriCloud