[cfe-commits] r43361 - in /cfe/trunk: AST/DeclSerialization.cpp include/clang/AST/Decl.h
Ted Kremenek
kremenek at apple.com
Thu Oct 25 14:37:17 PDT 2007
Author: kremenek
Date: Thu Oct 25 16:37:16 2007
New Revision: 43361
URL: http://llvm.org/viewvc/llvm-project?rev=43361&view=rev
Log:
Added skeleton for Decl serialization.
Added:
cfe/trunk/AST/DeclSerialization.cpp
Modified:
cfe/trunk/include/clang/AST/Decl.h
Added: cfe/trunk/AST/DeclSerialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/DeclSerialization.cpp?rev=43361&view=auto
==============================================================================
--- cfe/trunk/AST/DeclSerialization.cpp (added)
+++ cfe/trunk/AST/DeclSerialization.cpp Thu Oct 25 16:37:16 2007
@@ -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;
+ }
+}
Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=43361&r1=43360&r2=43361&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Thu Oct 25 16:37:16 2007
@@ -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 @@
/// 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 @@
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 @@
};
} // end namespace clang
+
#endif
More information about the cfe-commits
mailing list