switch DeclBase::DeclCtx to the new happy and type-safe
llvm::PointerUnion class.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67988 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h
index e98a378..aaec16e 100644
--- a/include/clang/AST/DeclBase.h
+++ b/include/clang/AST/DeclBase.h
@@ -19,6 +19,7 @@
// FIXME: Layering violation
#include "clang/Parse/AccessSpecifier.h"
#include "llvm/Support/PrettyStackTrace.h"
+#include "llvm/ADT/PointerUnion.h"
namespace clang {
class DeclContext;
@@ -113,6 +114,12 @@
friend class DeclContext;
+ struct MultipleDC {
+ DeclContext *SemanticDC;
+ DeclContext *LexicalDC;
+ };
+
+
/// DeclCtx - Holds either a DeclContext* or a MultipleDC*.
/// For declarations that don't contain C++ scope specifiers, it contains
/// the DeclContext where the Decl was declared.
@@ -126,23 +133,15 @@
/// }
/// void A::f(); // SemanticDC == namespace 'A'
/// // LexicalDC == global namespace
- llvm::PointerIntPair<DeclContext*, 1, bool> DeclCtx;
+ llvm::PointerUnion<DeclContext*, MultipleDC*> DeclCtx;
- struct MultipleDC {
- DeclContext *SemanticDC;
- DeclContext *LexicalDC;
- };
-
- inline bool isInSemaDC() const { return DeclCtx.getInt() == 0; }
- inline bool isOutOfSemaDC() const { return DeclCtx.getInt() != 0; }
+ inline bool isInSemaDC() const { return DeclCtx.is<DeclContext*>(); }
+ inline bool isOutOfSemaDC() const { return DeclCtx.is<MultipleDC*>(); }
inline MultipleDC *getMultipleDC() const {
- assert(isOutOfSemaDC() && "Invalid accessor");
- return reinterpret_cast<MultipleDC*>(DeclCtx.getPointer());
+ return DeclCtx.get<MultipleDC*>();
}
-
inline DeclContext *getSemanticDC() const {
- assert(isInSemaDC() && "Invalid accessor");
- return static_cast<DeclContext*>(DeclCtx.getPointer());
+ return DeclCtx.get<DeclContext*>();
}
/// Loc - The location that this decl.
@@ -178,7 +177,7 @@
Decl(Kind DK, DeclContext *DC, SourceLocation L)
: NextDeclarator(0), NextDeclInContext(0),
- DeclCtx(DC, 0),
+ DeclCtx(DC),
Loc(L), DeclKind(DK), InvalidDecl(0),
HasAttrs(false), Implicit(false),
IdentifierNamespace(getIdentifierNamespaceForKind(DK)), Access(AS_none) {
diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp
index 9ab269d..d45ad41 100644
--- a/lib/AST/DeclBase.cpp
+++ b/lib/AST/DeclBase.cpp
@@ -129,8 +129,7 @@
if (isOutOfSemaDC())
delete getMultipleDC();
- DeclCtx.setPointer(DC);
- DeclCtx.setInt(false);
+ DeclCtx = DC;
}
void Decl::setLexicalDeclContext(DeclContext *DC) {
@@ -141,8 +140,7 @@
MultipleDC *MDC = new MultipleDC();
MDC->SemanticDC = getDeclContext();
MDC->LexicalDC = DC;
- DeclCtx.setPointer(reinterpret_cast<DeclContext*>(MDC));
- DeclCtx.setInt(true);
+ DeclCtx = MDC;
} else {
getMultipleDC()->LexicalDC = DC;
}
diff --git a/lib/AST/DeclSerialization.cpp b/lib/AST/DeclSerialization.cpp
index 9658745..8e3ef08 100644
--- a/lib/AST/DeclSerialization.cpp
+++ b/lib/AST/DeclSerialization.cpp
@@ -135,12 +135,10 @@
// *object* for back-patching. Its actual value will get filled in later.
uintptr_t X;
D.ReadUIntPtr(X, SemaDCPtrID);
- Dcl->DeclCtx.setFromOpaqueValue(reinterpret_cast<void*>(X));
- }
- else {
+ Dcl->DeclCtx = reinterpret_cast<DeclContext*>(X);
+ } else {
MultipleDC *MDC = new MultipleDC();
- Dcl->DeclCtx.setPointer(reinterpret_cast<DeclContext*>(MDC));
- Dcl->DeclCtx.setInt(true);
+ Dcl->DeclCtx = MDC;
// Allow back-patching. Observe that we register the variable of the
// *object* for back-patching. Its actual value will get filled in later.
D.ReadPtr(MDC->SemanticDC, SemaDCPtrID);