Added skeleton for Decl serialization.

llvm-svn: 43361
This commit is contained in:
Ted Kremenek 2007-10-25 21:37:16 +00:00
parent 51f2182338
commit 1f1e756483
2 changed files with 83 additions and 1 deletions

View File

@ -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<Stmt>(decl.getInitExpr());
// S.Emit(decl.getInitVal()); FIXME
S.EmitOwnedPtr<Decl>(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>(decl.getNextDeclarator());
}
void SerializeTrait<Decl>::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<EnumConstantDecl>(decl));
return;
case Decl::Function:
EmitFunctionDecl(S,cast<FunctionDecl>(decl));
return;
}
}

View File

@ -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<clang::Decl> {
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 <typename DeclType>
static inline DeclType* DeserializeDecl(llvm::Deserializer& D) {
Decl* decl = llvm::SerializeTrait<Decl>::Materialize(D);
return cast<DeclType>(decl);
}
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *) { return true; }
@ -575,4 +594,5 @@ public:
};
} // end namespace clang
#endif