diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-10-06 23:49:24 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-10-06 23:49:24 +0000 |
commit | c7b07c19daa861880ad4bbf257d0fb2c7961355f (patch) | |
tree | 2f3e66dfea40ecacec44fcfa1a6d1d2eea1d15e8 | |
parent | 4021a84eb1634a1e18bb3c258274477e8fdcd861 (diff) |
Added prototype serialization code for DeclGroup.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57222 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/AST/DeclGroup.h | 37 | ||||
-rw-r--r-- | lib/AST/DeclGroup.cpp | 62 |
2 files changed, 94 insertions, 5 deletions
diff --git a/include/clang/AST/DeclGroup.h b/include/clang/AST/DeclGroup.h index 4818fc219a..0dac050ad2 100644 --- a/include/clang/AST/DeclGroup.h +++ b/include/clang/AST/DeclGroup.h @@ -15,6 +15,7 @@ #define LLVM_CLANG_AST_DECLGROUP_H #include "llvm/Support/DataTypes.h" +#include "llvm/Bitcode/SerializationFwd.h" #include <cassert> namespace clang { @@ -29,6 +30,7 @@ class DeclGroup { unsigned NumDecls; private: + DeclGroup() : NumDecls(0) {} DeclGroup(unsigned numdecls, Decl** decls); public: @@ -40,8 +42,18 @@ public: assert (i < NumDecls && "Out-of-bounds access."); return *((Decl**) (this+1)); } -}; + const Decl*& operator[](unsigned i) const { + assert (i < NumDecls && "Out-of-bounds access."); + return *((const Decl**) (this+1)); + } + + /// Emit - Serialize a DeclGroup to Bitcode. + void Emit(llvm::Serializer& S) const; + + /// Read - Deserialize a DeclGroup from Bitcode. + static DeclGroup* Create(llvm::Deserializer& D, ASTContext& C); +}; class DeclGroupRef { protected: @@ -57,7 +69,7 @@ public: explicit DeclGroupRef(Decl* d) : D(d) {} explicit DeclGroupRef(DeclGroup* dg) - : D((Decl*) (reinterpret_cast<uintptr_t>(D) | DeclGroupKind)) {} + : D((Decl*) (reinterpret_cast<uintptr_t>(dg) | DeclGroupKind)) {} typedef Decl** iterator; @@ -71,22 +83,37 @@ public: if (getKind() == DeclKind) return D ? &D + 1 : 0; DeclGroup& G = *((DeclGroup*) (reinterpret_cast<uintptr_t>(D) & ~Mask)); return &G[0] + G.size(); - } + } + + /// Emit - Serialize a DeclGroupRef to Bitcode. + void Emit(llvm::Serializer& S) const; + + /// Read - Deserialize a DeclGroupRef from Bitcode. + static DeclGroupRef ReadVal(llvm::Deserializer& D); }; class DeclGroupOwningRef : public DeclGroupRef { public: + explicit DeclGroupOwningRef(Decl* d) : DeclGroupRef(d) {} + explicit DeclGroupOwningRef(DeclGroup* dg) : DeclGroupRef(dg) {} + ~DeclGroupOwningRef(); void Destroy(ASTContext& C); - explicit DeclGroupOwningRef(DeclGroupOwningRef& R) + DeclGroupOwningRef(DeclGroupOwningRef& R) : DeclGroupRef(R) { R.D = 0; } - + DeclGroupOwningRef& operator=(DeclGroupOwningRef& R) { D = R.D; R.D = 0; return *this; } + + /// Emit - Serialize a DeclGroupOwningRef to Bitcode. + void Emit(llvm::Serializer& S) const; + + /// Read - Deserialize a DeclGroupOwningRef from Bitcode. + static DeclGroupOwningRef ReadVal(llvm::Deserializer& D, ASTContext& C); }; } // end clang namespace diff --git a/lib/AST/DeclGroup.cpp b/lib/AST/DeclGroup.cpp index 34b37dada5..bd79fafc8f 100644 --- a/lib/AST/DeclGroup.cpp +++ b/lib/AST/DeclGroup.cpp @@ -15,6 +15,8 @@ #include "clang/AST/Decl.h" #include "clang/AST/ASTContext.h" #include "llvm/Support/Allocator.h" +#include "llvm/Bitcode/Serialize.h" +#include "llvm/Bitcode/Deserialize.h" using namespace clang; @@ -26,6 +28,24 @@ DeclGroup* DeclGroup::Create(ASTContext& C, unsigned numdecls, Decl** decls) { return static_cast<DeclGroup*>(mem); } +/// Emit - Serialize a DeclGroup to Bitcode. +void DeclGroup::Emit(llvm::Serializer& S) const { + S.EmitInt(NumDecls); + S.BatchEmitOwnedPtrs(NumDecls, &(*this)[0]); +} + +/// Read - Deserialize a DeclGroup from Bitcode. +DeclGroup* DeclGroup::Create(llvm::Deserializer& D, ASTContext& C) { + unsigned NumDecls = (unsigned) D.ReadInt(); + unsigned size = sizeof(DeclGroup) + sizeof(Decl*) * NumDecls; + unsigned alignment = llvm::AlignOf<DeclGroup>::Alignment; + DeclGroup* DG = (DeclGroup*) C.getAllocator().Allocate(size, alignment); + new (DG) DeclGroup(); + DG->NumDecls = NumDecls; + D.BatchReadOwnedPtrs(NumDecls, &(*DG)[0], C); + return DG; +} + DeclGroup::DeclGroup(unsigned numdecls, Decl** decls) { assert (numdecls > 0); assert (decls); @@ -58,3 +78,45 @@ void DeclGroupOwningRef::Destroy(ASTContext& C) { D = 0; } + +void DeclGroupRef::Emit(llvm::Serializer& S) const { + if (getKind() == DeclKind) { + S.EmitBool(false); + S.EmitPtr(D); + } + else { + S.EmitBool(true); + S.EmitPtr(reinterpret_cast<DeclGroup*>(reinterpret_cast<uintptr_t>(D) + & ~Mask)); + } +} + +DeclGroupRef DeclGroupRef::ReadVal(llvm::Deserializer& D) { + if (D.ReadBool()) + return DeclGroupRef(D.ReadPtr<Decl>()); + + return DeclGroupRef(D.ReadPtr<DeclGroup>()); +} + +void DeclGroupOwningRef::Emit(llvm::Serializer& S) const { + if (getKind() == DeclKind) { + S.EmitBool(false); + S.EmitOwnedPtr(D); + } + else { + S.EmitBool(true); + S.EmitOwnedPtr(reinterpret_cast<DeclGroup*>(reinterpret_cast<uintptr_t>(D) + & ~Mask)); + } +} + +DeclGroupOwningRef DeclGroupOwningRef::ReadVal(llvm::Deserializer& D, + ASTContext& C) { + if (D.ReadBool()) { + DeclGroupOwningRef DG(D.ReadOwnedPtr<Decl>(C)); + return DG; + } + + DeclGroupOwningRef DG(D.ReadOwnedPtr<DeclGroup>(C)); + return DG; +} |