From: Ted Kremenek Date: Thu, 25 Oct 2007 21:37:16 +0000 (+0000) Subject: Added skeleton for Decl serialization. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2f1f8cb1b8f487086053579802407d64ca2b587f;p=clang Added skeleton for Decl serialization. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43361 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/AST/DeclSerialization.cpp b/AST/DeclSerialization.cpp new file mode 100644 index 0000000000..9b2278a4be --- /dev/null +++ b/AST/DeclSerialization.cpp @@ -0,0 +1,62 @@ +//===--- DeclSerialization.cpp - Serialization of Decls ---------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Ted Kremenek and is distributed under +// the University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This files defines methods that implement bitcode serialization for Decls. +// +//===----------------------------------------------------------------------===// + +#include "clang/AST/Decl.h" +#include "clang/AST/Expr.h" +#include "llvm/Bitcode/Serialize.h" +#include "llvm/Bitcode/Deserialize.h" + +using llvm::SerializeTrait; +using llvm::Deserializer; +using llvm::Serializer; +using namespace clang; + + +static void EmitEnumConstantDecl(Serializer& S, EnumConstantDecl& decl) { + S.Emit(decl.getLocation()); + S.EmitPtr(decl.getIdentifier()); +// S.Emit(decl.getType()); FIXME + S.EmitOwnedPtr(decl.getInitExpr()); + // S.Emit(decl.getInitVal()); FIXME + S.EmitOwnedPtr(decl.getNextDeclarator()); +} + +static void EmitFunctionDecl(Serializer& S, FunctionDecl& decl) { + S.Emit(decl.getLocation()); + S.EmitPtr(decl.getIdentifier()); +// S.Emit(decl.getType()); FIXME +// S.Emit(decl.getStorageClass()); FIXME + S.EmitBool(decl.isInline()); + S.EmitOwnedPtr(decl.getNextDeclarator()); +} + + +void SerializeTrait::Emit(Serializer& S, Decl& decl) { + assert (!decl.isInvalidDecl() && "Can only serialize valid decls."); + + S.EmitInt((unsigned) decl.getKind()); + + switch (decl.getKind()) { + default: + assert (false && "Serialization not implemented for decl type."); + return; + + case Decl::EnumConstant: + EmitEnumConstantDecl(S,cast(decl)); + return; + + case Decl::Function: + EmitFunctionDecl(S,cast(decl)); + return; + } +} diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index d06481fbdd..5788dc40f5 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -17,6 +17,18 @@ #include "clang/Basic/SourceLocation.h" #include "clang/AST/Type.h" #include "llvm/ADT/APSInt.h" +#include "llvm/Bitcode/Serialization.h" + +namespace clang { +class Decl; +} + +namespace llvm { +template <> struct SerializeTrait { + static void Emit(Serializer& S, clang::Decl& D); + static clang::Decl* Materialize(Deserializer& D); +}; +} // end namespace llvm namespace clang { class Expr; @@ -113,7 +125,7 @@ public: /// setInvalidDecl - Indicates the Decl had a semantic error. This /// allows for graceful error recovery. void setInvalidDecl() { InvalidDecl = 1; } - int isInvalidDecl() const { return InvalidDecl; } + bool isInvalidDecl() const { return (bool) InvalidDecl; } IdentifierNamespace getIdentifierNamespace() const { switch (DeclKind) { @@ -138,6 +150,13 @@ public: static void addDeclKind(const Kind k); static bool CollectingStats(bool enable=false); static void PrintStats(); + + // Deserialization of Decls. + template + static inline DeclType* DeserializeDecl(llvm::Deserializer& D) { + Decl* decl = llvm::SerializeTrait::Materialize(D); + return cast(decl); + } // Implement isa/cast/dyncast/etc. static bool classof(const Decl *) { return true; } @@ -575,4 +594,5 @@ public: }; } // end namespace clang + #endif