[cfe-commits] r109384 - in /cfe/trunk: include/clang/Basic/Diagnostic.h lib/Basic/Diagnostic.cpp
Benjamin Kramer
benny.kra at googlemail.com
Sun Jul 25 14:40:48 PDT 2010
Author: d0k
Date: Sun Jul 25 16:40:48 2010
New Revision: 109384
URL: http://llvm.org/viewvc/llvm-project?rev=109384&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/Basic/Diagnostic.h
cfe/trunk/lib/Basic/Diagnostic.cpp
Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=109384&r1=109383&r2=109384&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Sun Jul 25 16:40:48 2010
@@ -213,8 +213,24 @@
/// 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 @@
/// 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 ¤tMappings = 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
Modified: cfe/trunk/lib/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Diagnostic.cpp?rev=109384&r1=109383&r2=109384&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Basic/Diagnostic.cpp Sun Jul 25 16:40:48 2010
@@ -334,11 +334,8 @@
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
More information about the cfe-commits
mailing list