diff options
author | Chris Lattner <sabre@nondot.org> | 2009-03-29 06:06:59 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-03-29 06:06:59 +0000 |
commit | ee219fd5f2776d8dd39d857f87304297b5ed743a (patch) | |
tree | 6a1f0d98a223dac5a4fac1e5069811f147647daf | |
parent | 4656978783e444bbd4a70ead1946e341587779ca (diff) |
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
-rw-r--r-- | include/clang/AST/DeclBase.h | 27 | ||||
-rw-r--r-- | lib/AST/DeclBase.cpp | 6 | ||||
-rw-r--r-- | lib/AST/DeclSerialization.cpp | 8 |
3 files changed, 18 insertions, 23 deletions
diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h index e98a378502..aaec16ee44 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 @@ private: 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 @@ private: /// } /// 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 @@ protected: 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 9ab269d305..d45ad4177c 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -129,8 +129,7 @@ void Decl::setDeclContext(DeclContext *DC) { if (isOutOfSemaDC()) delete getMultipleDC(); - DeclCtx.setPointer(DC); - DeclCtx.setInt(false); + DeclCtx = DC; } void Decl::setLexicalDeclContext(DeclContext *DC) { @@ -141,8 +140,7 @@ void Decl::setLexicalDeclContext(DeclContext *DC) { 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 965874502d..8e3ef08d2c 100644 --- a/lib/AST/DeclSerialization.cpp +++ b/lib/AST/DeclSerialization.cpp @@ -135,12 +135,10 @@ Decl* Decl::Create(Deserializer& D, ASTContext& C) { // *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); |