From 583e008bbfbb937524d567ad6450b8f0e8485bca Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 14 Nov 2007 18:12:19 +0000 Subject: [PATCH] Implemented serialization of EnumDecl and EnumConstantDecl. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44127 91177308-0d34-0410-b5e6-96231b3b80d8 --- AST/DeclSerialization.cpp | 70 +++++++++++++++++++++++++++++++++++++-- include/clang/AST/Decl.h | 22 ++++++++++-- 2 files changed, 88 insertions(+), 4 deletions(-) diff --git a/AST/DeclSerialization.cpp b/AST/DeclSerialization.cpp index 3e2ce0fcc8..51c93fbd12 100644 --- a/AST/DeclSerialization.cpp +++ b/AST/DeclSerialization.cpp @@ -43,6 +43,12 @@ Decl* Decl::Create(Deserializer& D) { case BlockVar: return BlockVarDecl::CreateImpl(D); + case Enum: + return EnumDecl::CreateImpl(D); + + case EnumConstant: + return EnumConstantDecl::CreateImpl(D); + case Field: return FieldDecl::CreateImpl(D); @@ -219,6 +225,64 @@ ParmVarDecl* ParmVarDecl::CreateImpl(Deserializer& D) { return decl; } +//===----------------------------------------------------------------------===// +// EnumDecl Serialization. +//===----------------------------------------------------------------------===// + +void EnumDecl::EmitImpl(Serializer& S) const { + ScopedDecl::EmitInRec(S); + S.EmitBool(isDefinition()); + S.Emit(IntegerType); + S.BatchEmitOwnedPtrs(ElementList,getNextDeclarator()); +} + +EnumDecl* EnumDecl::CreateImpl(Deserializer& D) { + EnumDecl* decl = new EnumDecl(SourceLocation(),NULL,NULL); + + decl->ScopedDecl::ReadInRec(D); + decl->setDefinition(D.ReadBool()); + decl->IntegerType = QualType::ReadVal(D); + + Decl* next_declarator; + Decl* Elist; + + D.BatchReadOwnedPtrs(Elist,next_declarator); + + decl->ElementList = cast_or_null(Elist); + decl->setNextDeclarator(cast_or_null(next_declarator)); + + return decl; +} + +//===----------------------------------------------------------------------===// +// EnumConstantDecl Serialization. +//===----------------------------------------------------------------------===// + +void EnumConstantDecl::EmitImpl(Serializer& S) const { + S.Emit(Val); + ValueDecl::EmitInRec(S); + S.BatchEmitOwnedPtrs(getNextDeclarator(),Init); +} + +EnumConstantDecl* EnumConstantDecl::CreateImpl(Deserializer& D) { + llvm::APSInt val(0); + D.Read(val); + + EnumConstantDecl* decl = + new EnumConstantDecl(SourceLocation(),NULL,QualType(),NULL, + val,NULL); + + decl->ValueDecl::ReadInRec(D); + + Decl* next_declarator; + + D.BatchReadOwnedPtrs(next_declarator,decl->Init); + + decl->setNextDeclarator(cast(next_declarator)); + + return decl; +} + //===----------------------------------------------------------------------===// // FieldDecl Serialization. //===----------------------------------------------------------------------===// @@ -295,8 +359,9 @@ FunctionDecl* FunctionDecl::CreateImpl(Deserializer& D) { // RecordDecl Serialization. //===----------------------------------------------------------------------===// -void RecordDecl::EmitImpl(llvm::Serializer& S) const { +void RecordDecl::EmitImpl(Serializer& S) const { ScopedDecl::EmitInRec(S); + S.EmitBool(isDefinition()); S.EmitBool(hasFlexibleArrayMember()); S.EmitSInt(getNumMembers()); if (getNumMembers() > 0) { @@ -310,8 +375,9 @@ void RecordDecl::EmitImpl(llvm::Serializer& S) const { RecordDecl* RecordDecl::CreateImpl(Decl::Kind DK, Deserializer& D) { RecordDecl* decl = new RecordDecl(DK,SourceLocation(),NULL,NULL); - + decl->ScopedDecl::ReadInRec(D); + decl->setDefinition(D.ReadBool()); decl->setHasFlexibleArrayMember(D.ReadBool()); decl->NumMembers = D.ReadSInt(); diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 5930d96711..fa1b3a7ad9 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -540,6 +540,15 @@ public: static bool classof(const EnumConstantDecl *D) { return true; } friend class StmtIteratorBase; + +protected: + /// EmitImpl - Serialize this EnumConstantDecl. Called by Decl::Emit. + virtual void EmitImpl(llvm::Serializer& S) const; + + /// CreateImpl - Deserialize a EnumConstantDecl. Called by Decl::Create. + static EnumConstantDecl* CreateImpl(llvm::Deserializer& D); + + friend Decl* Decl::Create(llvm::Deserializer& D); }; @@ -663,6 +672,15 @@ public: static bool classof(const Decl *D) { return D->getKind() == Enum; } static bool classof(const EnumDecl *D) { return true; } + +protected: + /// EmitImpl - Serialize this EnumDecl. Called by Decl::Emit. + virtual void EmitImpl(llvm::Serializer& S) const; + + /// CreateImpl - Deserialize a EnumDecl. Called by Decl::Create. + static EnumDecl* CreateImpl(llvm::Deserializer& D); + + friend Decl* Decl::Create(llvm::Deserializer& D); }; @@ -712,10 +730,10 @@ public: static bool classof(const RecordDecl *D) { return true; } protected: - /// EmitImpl - Serialize this TypedefDecl. Called by Decl::Emit. + /// EmitImpl - Serialize this RecordDecl. Called by Decl::Emit. virtual void EmitImpl(llvm::Serializer& S) const; - /// CreateImpl - Deserialize a TypedefDecl. Called by Decl::Create. + /// CreateImpl - Deserialize a RecordDecl. Called by Decl::Create. static RecordDecl* CreateImpl(Kind DK, llvm::Deserializer& D); friend Decl* Decl::Create(llvm::Deserializer& D); -- 2.40.0