#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 Decl::Emit(llvm::Serializer& S) const {
+ assert ("FIXME: not implemented.");
}
-
-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;
- }
+Decl* Decl::Materialize(llvm::Deserializer& D) {
+ assert ("FIXME: not implemented.");
+ return NULL;
}
#include "clang/Basic/SourceLocation.h"
#include "clang/AST/Type.h"
#include "llvm/ADT/APSInt.h"
-#include "llvm/Bitcode/Serialization.h"
+#include "llvm/Bitcode/SerializationFwd.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;
class Stmt;
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; }
+
+ /// Emit - Serialize this Decl to Bitcode.
+ void Emit(llvm::Serializer& S) const;
+
+ /// Materialize - Deserialize a Decl from Bitcode.
+ static Decl* Materialize(llvm::Deserializer& D);
};
/// NamedDecl - This represents a decl with an identifier for a name. Many
return D->getKind() >= NamedFirst && D->getKind() <= NamedLast;
}
static bool classof(const NamedDecl *D) { return true; }
+
+ /// Emit - Serialize this NamedDecl to Bitcode.
+ void Emit(llvm::Serializer& S) const {
+ static_cast<const Decl*>(this)->Emit(S);
+ }
+
+ /// Materialize - Deserialize a ScopedDecl from Bitcode.
+ static inline NamedDecl* Materialize(llvm::Deserializer& D) {
+ return cast<NamedDecl>(Decl::Materialize(D));
+ }
};
/// ScopedDecl - Represent lexically scoped names, used for all ValueDecl's
return D->getKind() >= ScopedFirst && D->getKind() <= ScopedLast;
}
static bool classof(const ScopedDecl *D) { return true; }
+
+ /// Emit - Serialize this ScopedDecl to Bitcode.
+ void Emit(llvm::Serializer& S) const {
+ static_cast<const Decl*>(this)->Emit(S);
+ }
+
+ /// Materialize - Deserialize a ScopedDecl from Bitcode.
+ static inline ScopedDecl* Materialize(llvm::Deserializer& D) {
+ return cast<ScopedDecl>(Decl::Materialize(D));
+ }
};
/// ValueDecl - Represent the declaration of a variable (in which case it is
return D->getKind() >= ValueFirst && D->getKind() <= ValueLast;
}
static bool classof(const ValueDecl *D) { return true; }
+
+ /// Emit - Serialize this ValueDecl to Bitcode.
+ void Emit(llvm::Serializer& S) const {
+ static_cast<const Decl*>(this)->Emit(S);
+ }
+
+ /// Materialize - Deserialize a ValueDecl from Bitcode.
+ static inline ValueDecl* Materialize(llvm::Deserializer& D) {
+ return cast<ValueDecl>(Decl::Materialize(D));
+ }
};
/// VarDecl - An instance of this class is created to represent a variable
ObjcDeclQualifier objcDeclQualifier : 6;
friend class StmtIteratorBase;
+
+public:
+ /// Emit - Serialize this VarDecl to Bitcode.
+ void Emit(llvm::Serializer& S) const {
+ static_cast<const Decl*>(this)->Emit(S);
+ }
+
+ /// Materialize - Deserialize a VarDecl from Bitcode.
+ static inline VarDecl* Materialize(llvm::Deserializer& D) {
+ return cast<VarDecl>(Decl::Materialize(D));
+ }
};
/// BlockVarDecl - Represent a local variable declaration.
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return D->getKind() == BlockVar; }
- static bool classof(const BlockVarDecl *D) { return true; }
+ static bool classof(const BlockVarDecl *D) { return true; }
+
+ /// Emit - Serialize this BlockVarDecl to Bitcode.
+ void Emit(llvm::Serializer& S) const;
+
+ /// Materialize - Deserialize a BlockVarDecl from Bitcode.
+ static BlockVarDecl* Materialize(llvm::Deserializer& D);
};
/// FileVarDecl - Represent a file scoped variable declaration. This
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return D->getKind() == FileVar; }
static bool classof(const FileVarDecl *D) { return true; }
+
+ /// Emit - Serialize this FileVarDecl to Bitcode.
+ void Emit(llvm::Serializer& S) const;
+
+ /// Materialize - Deserialize a FileVarDecl from Bitcode.
+ static FileVarDecl* Materialize(llvm::Deserializer& D);
};
/// ParmVarDecl - Represent a parameter to a function.
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return D->getKind() == ParmVar; }
static bool classof(const ParmVarDecl *D) { return true; }
+
+ /// Emit - Serialize this ParmVarDecl to Bitcode.
+ void Emit(llvm::Serializer& S) const;
+
+ /// Materialize - Deserialize a ParmVarDecl from Bitcode.
+ static ParmVarDecl* Materialize(llvm::Deserializer& D);
};
/// FunctionDecl - An instance of this class is created to represent a function
StorageClass SClass : 2;
bool IsInline : 1;
+
+public:
+ /// Emit - Serialize this FunctionDecl to Bitcode.
+ void Emit(llvm::Serializer& S) const;
+
+ /// Materialize - Deserialize a FunctionDecl from Bitcode.
+ static FunctionDecl* Materialize(llvm::Deserializer& D);
};
return D->getKind() >= FieldFirst && D->getKind() <= FieldLast;
}
static bool classof(const FieldDecl *D) { return true; }
+
+public:
+ /// Emit - Serialize this FieldDecl to Bitcode.
+ void Emit(llvm::Serializer& S) const;
+
+ /// Materialize - Deserialize a FieldDecl from Bitcode.
+ static FieldDecl* Materialize(llvm::Deserializer& D);
};
/// EnumConstantDecl - An instance of this object exists for each enum constant
static bool classof(const EnumConstantDecl *D) { return true; }
friend class StmtIteratorBase;
+
+ /// Emit - Serialize this EnumConstantDecl to Bitcode.
+ void Emit(llvm::Serializer& S) const;
+
+ /// Materialize - Deserialize a EnumConstantDecl from Bitcode.
+ static EnumConstantDecl* Materialize(llvm::Deserializer& D);
};
return D->getKind() >= TypeFirst && D->getKind() <= TypeLast;
}
static bool classof(const TypeDecl *D) { return true; }
+
+ /// Emit - Serialize this TypeDecl to Bitcode.
+ void Emit(llvm::Serializer& S) const;
+
+ /// Materialize - Deserialize a TypeDecl from Bitcode.
+ static TypeDecl* Materialize(llvm::Deserializer& D);
};
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return D->getKind() == Typedef; }
static bool classof(const TypedefDecl *D) { return true; }
+
+ /// Emit - Serialize this TypedefDecl to Bitcode.
+ void Emit(llvm::Serializer& S) const;
+
+ /// Materialize - Deserialize a TypedefDecl from Bitcode.
+ static TypedefDecl* Materialize(llvm::Deserializer& D);
};
static bool classof(const TagDecl *D) { return true; }
protected:
void setDefinition(bool V) { IsDefinition = V; }
+
+public:
+ /// Emit - Serialize this TagDecl to Bitcode.
+ void Emit(llvm::Serializer& S) const;
+
+ /// Materialize - Deserialize a TagDecl from Bitcode.
+ static TagDecl* Materialize(llvm::Deserializer& D);
};
/// EnumDecl - Represents an enum. As an extension, we allow forward-declared
static bool classof(const Decl *D) { return D->getKind() == Enum; }
static bool classof(const EnumDecl *D) { return true; }
+
+public:
+ /// Emit - Serialize this EnumDecl to Bitcode.
+ void Emit(llvm::Serializer& S) const;
+
+ /// Materialize - Deserialize a EnumDecl from Bitcode.
+ static EnumDecl* Materialize(llvm::Deserializer& D);
};
return D->getKind() >= RecordFirst && D->getKind() <= RecordLast;
}
static bool classof(const RecordDecl *D) { return true; }
+
+public:
+ /// Emit - Serialize this RecordDecl to Bitcode.
+ void Emit(llvm::Serializer& S) const;
+
+ /// Materialize - Deserialize a RecordDecl from Bitcode.
+ static RecordDecl* Materialize(llvm::Deserializer& D);
};
} // end namespace clang
X.ID = Encoding;
return X;
}
+
+ /// Emit - Emit this SourceLocation object to Bitcode.
+ void Emit(llvm::Serializer& S) const;
+
+ /// ReadVal - Read a SourceLocation object from Bitcode.
+ static SourceLocation ReadVal(llvm::Deserializer& D);
};
inline bool operator==(const SourceLocation &LHS, const SourceLocation &RHS) {
void setEnd(SourceLocation e) { E = e; }
bool isValid() const { return B.isValid() && E.isValid(); }
-};
-
-} // end namespace clang
-
-//===----------------------------------------------------------------------===//
-// Serialization of SourceLocations and SourceRanges.
-//===----------------------------------------------------------------------===//
-
-namespace llvm {
-template<> struct SerializeTrait<clang::SourceLocation> {
- static void Emit(Serializer& S, clang::SourceLocation L);
- static clang::SourceLocation ReadVal(Deserializer& D);
-};
+ /// Emit - Emit this SourceRange object to Bitcode.
+ void Emit(llvm::Serializer& S) const;
-template<> struct SerializeTrait<clang::SourceRange> {
- static inline void Emit(Serializer& S, clang::SourceRange R) {
- SerializeTrait<clang::SourceLocation>::Emit(S,R.getBegin());
- SerializeTrait<clang::SourceLocation>::Emit(S,R.getEnd());
- }
-
- static inline clang::SourceRange ReadVal(Deserializer& D) {
- using clang::SourceLocation;
- SourceLocation L = SerializeTrait<SourceLocation>::ReadVal(D);
- SourceLocation R = SerializeTrait<SourceLocation>::ReadVal(D);
- return clang::SourceRange(L,R);
- }
+ /// ReadVal - Read a SourceRange object from Bitcode.
+ static SourceRange ReadVal(llvm::Deserializer& D);
};
-} // end namespace llvm
+} // end namespace clang
#endif