summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2007-10-25 21:37:16 +0000
committerTed Kremenek <kremenek@apple.com>2007-10-25 21:37:16 +0000
commit1f1e7564834577ae031120d8988c26cb5fdd0ced (patch)
tree23e857075fb9c1e00946acaead2cd7a4ac3a0bca
parent51f2182338e55e076d360b9eff6e1ac0d7411d32 (diff)
downloadbcm5719-llvm-1f1e7564834577ae031120d8988c26cb5fdd0ced.tar.gz
bcm5719-llvm-1f1e7564834577ae031120d8988c26cb5fdd0ced.zip
Added skeleton for Decl serialization.
llvm-svn: 43361
-rw-r--r--clang/AST/DeclSerialization.cpp62
-rw-r--r--clang/include/clang/AST/Decl.h22
2 files changed, 83 insertions, 1 deletions
diff --git a/clang/AST/DeclSerialization.cpp b/clang/AST/DeclSerialization.cpp
new file mode 100644
index 00000000000..9b2278a4beb
--- /dev/null
+++ b/clang/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<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;
+ }
+}
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index d06481fbdd3..5788dc40f55 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/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<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
OpenPOWER on IntegriCloud