Added most of the boilerplate code for Decl serialization. Still a few

key functions to implement.

llvm-svn: 43648
This commit is contained in:
Ted Kremenek 2007-11-02 18:05:11 +00:00
parent 3ae79b3d13
commit dda9a56975
2 changed files with 132 additions and 40 deletions

View File

@ -26,3 +26,120 @@ Decl* Decl::Materialize(llvm::Deserializer& D) {
assert ("FIXME: not implemented."); assert ("FIXME: not implemented.");
return NULL; return NULL;
} }
void NamedDecl::InternalEmit(llvm::Serializer& S) const {
S.EmitPtr(Identifier);
}
void NamedDecl::InternalRead(llvm::Deserializer& D) {
D.ReadPtr(Identifier);
}
void ScopedDecl::InternalEmit(llvm::Serializer& S) const {
NamedDecl::InternalEmit(S);
S.EmitPtr(Next);
S.EmitOwnedPtr<Decl>(NextDeclarator);
}
void ScopedDecl::InternalRead(llvm::Deserializer& D) {
NamedDecl::InternalRead(D);
D.ReadPtr(Next);
NextDeclarator = cast<ScopedDecl>(D.ReadOwnedPtr<Decl>());
}
void ValueDecl::InternalEmit(llvm::Serializer& S) const {
S.Emit(DeclType);
ScopedDecl::InternalEmit(S);
}
void ValueDecl::InternalRead(llvm::Deserializer& D) {
D.Read(DeclType);
ScopedDecl::InternalRead(D);
}
void VarDecl::InternalEmit(llvm::Serializer& S) const {
S.EmitInt(SClass);
S.EmitInt(objcDeclQualifier);
VarDecl::InternalEmit(S);
S.EmitOwnedPtr(Init);
}
void VarDecl::InternalRead(llvm::Deserializer& D) {
SClass = D.ReadInt();
objcDeclQualifier = static_cast<ObjcDeclQualifier>(D.ReadInt());
VarDecl::InternalRead(D);
D.ReadOwnedPtr(Init);
}
void BlockVarDecl::Emit(llvm::Serializer& S) const {
S.Emit(getLocation());
VarDecl::InternalEmit(S);
}
BlockVarDecl* BlockVarDecl::Materialize(llvm::Deserializer& D) {
SourceLocation L = SourceLocation::ReadVal(D);
BlockVarDecl* decl = new BlockVarDecl(L,NULL,QualType(),None,NULL);
decl->VarDecl::InternalRead(D);
return decl;
}
void FileVarDecl::Emit(llvm::Serializer& S) const {
S.Emit(getLocation());
VarDecl::InternalEmit(S);
}
FileVarDecl* FileVarDecl::Materialize(llvm::Deserializer& D) {
SourceLocation L = SourceLocation::ReadVal(D);
FileVarDecl* decl = new FileVarDecl(L,NULL,QualType(),None,NULL);
decl->VarDecl::InternalRead(D);
return decl;
}
void ParmVarDecl::Emit(llvm::Serializer& S) const {
S.Emit(getLocation());
VarDecl::InternalEmit(S);
}
ParmVarDecl* ParmVarDecl::Materialize(llvm::Deserializer& D) {
SourceLocation L = SourceLocation::ReadVal(D);
ParmVarDecl* decl = new ParmVarDecl(L,NULL,QualType(),None,NULL);
decl->VarDecl::InternalRead(D);
return decl;
}
void FunctionDecl::Emit(llvm::Serializer& S) const {
S.Emit(getLocation());
S.EmitInt(SClass);
S.EmitBool(IsInline);
ValueDecl::InternalEmit(S);
unsigned NumParams = getNumParams();
S.EmitInt(NumParams);
for (unsigned i = 0 ; i < NumParams; ++i)
S.EmitOwnedPtr(ParamInfo[i]);
S.EmitOwnedPtr(Body);
}
FunctionDecl* FunctionDecl::Materialize(llvm::Deserializer& D) {
SourceLocation L = SourceLocation::ReadVal(D);
StorageClass SClass = static_cast<StorageClass>(D.ReadInt());
bool IsInline = D.ReadBool();
FunctionDecl* decl = new FunctionDecl(L,NULL,QualType(),SClass,IsInline);
decl->ValueDecl::InternalRead(D);
unsigned NumParams = D.ReadInt();
decl->ParamInfo = NumParams ? new ParmVarDecl*[NumParams] : NULL;
for (unsigned i = 0 ; i < NumParams; ++i)
D.ReadOwnedPtr(decl->ParamInfo[i]);
D.ReadOwnedPtr(decl->Body);
return decl;
}

View File

@ -185,16 +185,10 @@ public:
return D->getKind() >= NamedFirst && D->getKind() <= NamedLast; return D->getKind() >= NamedFirst && D->getKind() <= NamedLast;
} }
static bool classof(const NamedDecl *D) { return true; } static bool classof(const NamedDecl *D) { return true; }
/// Emit - Serialize this NamedDecl to Bitcode. protected:
void Emit(llvm::Serializer& S) const { void InternalEmit(llvm::Serializer& S) const;
static_cast<const Decl*>(this)->Emit(S); void InternalRead(llvm::Deserializer& D);
}
/// 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 /// ScopedDecl - Represent lexically scoped names, used for all ValueDecl's
@ -229,16 +223,10 @@ public:
return D->getKind() >= ScopedFirst && D->getKind() <= ScopedLast; return D->getKind() >= ScopedFirst && D->getKind() <= ScopedLast;
} }
static bool classof(const ScopedDecl *D) { return true; } static bool classof(const ScopedDecl *D) { return true; }
/// Emit - Serialize this ScopedDecl to Bitcode. protected:
void Emit(llvm::Serializer& S) const { void InternalEmit(llvm::Serializer& S) const;
static_cast<const Decl*>(this)->Emit(S); void InternalRead(llvm::Deserializer& D);
}
/// 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 /// ValueDecl - Represent the declaration of a variable (in which case it is
@ -259,16 +247,10 @@ public:
return D->getKind() >= ValueFirst && D->getKind() <= ValueLast; return D->getKind() >= ValueFirst && D->getKind() <= ValueLast;
} }
static bool classof(const ValueDecl *D) { return true; } static bool classof(const ValueDecl *D) { return true; }
/// Emit - Serialize this ValueDecl to Bitcode. protected:
void Emit(llvm::Serializer& S) const { void InternalEmit(llvm::Serializer& S) const;
static_cast<const Decl*>(this)->Emit(S); void InternalRead(llvm::Deserializer& D);
}
/// 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 /// VarDecl - An instance of this class is created to represent a variable
@ -339,16 +321,9 @@ private:
friend class StmtIteratorBase; friend class StmtIteratorBase;
public: protected:
/// Emit - Serialize this VarDecl to Bitcode. void InternalEmit(llvm::Serializer& S) const;
void Emit(llvm::Serializer& S) const { void InternalRead(llvm::Deserializer& D);
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. /// BlockVarDecl - Represent a local variable declaration.