forked from OSchip/llvm-project
Overhauled serialization of statements. We no longer use specialized SerializeTrait<> classes,
but methods in Stmt (like other objects we are serializing). Full serialization of all statements is not yet complete. llvm-svn: 43793
This commit is contained in:
parent
abcfe90802
commit
148aa5edbc
|
@ -12,86 +12,128 @@
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "clang/AST/Stmt.h"
|
#include "clang/AST/Expr.h"
|
||||||
#include "clang/AST/StmtVisitor.h"
|
|
||||||
#include "llvm/Bitcode/Serialize.h"
|
#include "llvm/Bitcode/Serialize.h"
|
||||||
#include "llvm/Bitcode/Deserialize.h"
|
#include "llvm/Bitcode/Deserialize.h"
|
||||||
|
|
||||||
using llvm::Serializer;
|
|
||||||
using llvm::Deserializer;
|
|
||||||
using llvm::SerializeTrait;
|
|
||||||
|
|
||||||
using namespace clang;
|
using namespace clang;
|
||||||
|
|
||||||
|
void Stmt::Emit(llvm::Serializer& S) const {
|
||||||
|
S.EmitInt(getStmtClass());
|
||||||
|
directEmit(S);
|
||||||
|
}
|
||||||
|
|
||||||
namespace {
|
Stmt* Stmt::Materialize(llvm::Deserializer& D) {
|
||||||
class StmtSerializer : public StmtVisitor<StmtSerializer> {
|
StmtClass SC = static_cast<StmtClass>(D.ReadInt());
|
||||||
Serializer& S;
|
|
||||||
public:
|
|
||||||
StmtSerializer(Serializer& S) : S(S) {}
|
|
||||||
|
|
||||||
void VisitDeclStmt(DeclStmt* Stmt);
|
|
||||||
void VisitNullStmt(NullStmt* Stmt);
|
|
||||||
void VisitCompoundStmt(CompoundStmt* Stmt);
|
|
||||||
|
|
||||||
void VisitStmt(Stmt*) { assert("Not Implemented yet"); }
|
switch (SC) {
|
||||||
};
|
default:
|
||||||
} // end anonymous namespace
|
assert (false && "Not implemented.");
|
||||||
|
return NULL;
|
||||||
|
|
||||||
void SerializeTrait<Stmt>::Emit(Serializer& S, const Stmt& stmt) {
|
case CompoundStmtClass:
|
||||||
S.EmitInt(stmt.getStmtClass());
|
return CompoundStmt::directMaterialize(D);
|
||||||
|
|
||||||
StmtSerializer SS(S);
|
case ReturnStmtClass:
|
||||||
SS.Visit(const_cast<Stmt*>(&stmt));
|
return ReturnStmt::directMaterialize(D);
|
||||||
|
|
||||||
|
case BinaryOperatorClass:
|
||||||
|
return BinaryOperator::directMaterialize(D);
|
||||||
|
|
||||||
|
case DeclRefExprClass:
|
||||||
|
return DeclRefExpr::directMaterialize(D);
|
||||||
|
|
||||||
|
case IntegerLiteralClass:
|
||||||
|
return IntegerLiteral::directMaterialize(D);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StmtSerializer::VisitDeclStmt(DeclStmt* Stmt) {
|
|
||||||
// FIXME
|
|
||||||
// S.EmitOwnedPtr(Stmt->getDecl());
|
|
||||||
}
|
|
||||||
|
|
||||||
void StmtSerializer::VisitNullStmt(NullStmt* Stmt) {
|
|
||||||
S.Emit(Stmt->getSemiLoc());
|
|
||||||
}
|
|
||||||
|
|
||||||
void StmtSerializer::VisitCompoundStmt(CompoundStmt* Stmt) {
|
void CompoundStmt::directEmit(llvm::Serializer& S) const {
|
||||||
S.Emit(Stmt->getLBracLoc());
|
S.Emit(LBracLoc);
|
||||||
S.Emit(Stmt->getRBracLoc());
|
S.Emit(RBracLoc);
|
||||||
|
S.Emit(Body.size());
|
||||||
CompoundStmt::body_iterator I=Stmt->body_begin(), E=Stmt->body_end();
|
|
||||||
|
|
||||||
S.EmitInt(E-I);
|
|
||||||
|
|
||||||
for ( ; I != E; ++I )
|
for (const_body_iterator I=body_begin(), E=body_end(); I!=E; ++I)
|
||||||
S.EmitOwnedPtr(*I);
|
S.EmitOwnedPtr(*I);
|
||||||
}
|
}
|
||||||
|
|
||||||
Stmt* SerializeTrait<Stmt>::Materialize(Deserializer& D) {
|
CompoundStmt* CompoundStmt::directMaterialize(llvm::Deserializer& D) {
|
||||||
unsigned sClass = D.ReadInt();
|
SourceLocation LB = SourceLocation::ReadVal(D);
|
||||||
|
SourceLocation RB = SourceLocation::ReadVal(D);
|
||||||
|
unsigned size = D.ReadInt();
|
||||||
|
|
||||||
switch (sClass) {
|
CompoundStmt* stmt = new CompoundStmt(NULL,0,LB,RB);
|
||||||
default:
|
|
||||||
assert(false && "No matching statement class.");
|
stmt->Body.reserve(size);
|
||||||
return NULL;
|
|
||||||
|
for (unsigned i = 0; i < size; ++i)
|
||||||
case Stmt::DeclStmtClass:
|
stmt->Body.push_back(D.ReadOwnedPtr<Stmt>());
|
||||||
return NULL; // FIXME
|
|
||||||
// return new DeclStmt(D.ReadOwnedPtr<ScopedDecl>());
|
return stmt;
|
||||||
|
|
||||||
case Stmt::NullStmtClass:
|
|
||||||
return new NullStmt(SourceLocation::ReadVal(D));
|
|
||||||
|
|
||||||
case Stmt::CompoundStmtClass: {
|
|
||||||
SourceLocation LBracLoc = SourceLocation::ReadVal(D);
|
|
||||||
SourceLocation RBracLoc = SourceLocation::ReadVal(D);
|
|
||||||
unsigned NumStmts = D.ReadInt();
|
|
||||||
llvm::SmallVector<Stmt*, 16> Body;
|
|
||||||
|
|
||||||
for (unsigned i = 0 ; i < NumStmts; ++i)
|
|
||||||
Body.push_back(D.ReadOwnedPtr<Stmt>());
|
|
||||||
|
|
||||||
return new CompoundStmt(&Body[0],NumStmts,LBracLoc,RBracLoc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ReturnStmt::directEmit(llvm::Serializer& S) const {
|
||||||
|
S.Emit(RetLoc);
|
||||||
|
S.EmitOwnedPtr(RetExpr);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnStmt* ReturnStmt::directMaterialize(llvm::Deserializer& D) {
|
||||||
|
SourceLocation RetLoc = SourceLocation::ReadVal(D);
|
||||||
|
Expr* RetExpr = D.ReadOwnedPtr<Expr>();
|
||||||
|
return new ReturnStmt(RetLoc,RetExpr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void BinaryOperator::directEmit(llvm::Serializer& S) const {
|
||||||
|
S.EmitInt(Opc);
|
||||||
|
S.Emit(OpLoc);;
|
||||||
|
S.Emit(getType());
|
||||||
|
S.EmitOwnedPtr(getLHS());
|
||||||
|
S.EmitOwnedPtr(getRHS());
|
||||||
|
}
|
||||||
|
|
||||||
|
BinaryOperator* BinaryOperator::directMaterialize(llvm::Deserializer& D) {
|
||||||
|
Opcode Opc = static_cast<Opcode>(D.ReadInt());
|
||||||
|
SourceLocation OpLoc = SourceLocation::ReadVal(D);
|
||||||
|
QualType Result = QualType::ReadVal(D);
|
||||||
|
Expr* LHS = D.ReadOwnedPtr<Expr>();
|
||||||
|
Expr* RHS = D.ReadOwnedPtr<Expr>();
|
||||||
|
return new BinaryOperator(LHS,RHS,Opc,Result,OpLoc);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeclRefExpr::directEmit(llvm::Serializer& S) const {
|
||||||
|
S.Emit(Loc);
|
||||||
|
S.Emit(getType());
|
||||||
|
S.EmitPtr(getDecl());
|
||||||
|
}
|
||||||
|
|
||||||
|
DeclRefExpr* DeclRefExpr::directMaterialize(llvm::Deserializer& D) {
|
||||||
|
SourceLocation Loc = SourceLocation::ReadVal(D);
|
||||||
|
QualType T = QualType::ReadVal(D);
|
||||||
|
DeclRefExpr* dr = new DeclRefExpr(NULL,T,Loc);
|
||||||
|
D.ReadPtr(dr->D,false);
|
||||||
|
return dr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntegerLiteral::directEmit(llvm::Serializer& S) const {
|
||||||
|
S.Emit(Loc);
|
||||||
|
S.Emit(getType());
|
||||||
|
S.Emit(getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
IntegerLiteral* IntegerLiteral::directMaterialize(llvm::Deserializer& D) {
|
||||||
|
SourceLocation Loc = SourceLocation::ReadVal(D);
|
||||||
|
QualType T = QualType::ReadVal(D);
|
||||||
|
|
||||||
|
// Create a dummy APInt because it is more efficient to deserialize
|
||||||
|
// it in place with the deserialized IntegerLiteral. (fewer copies)
|
||||||
|
llvm::APInt temp;
|
||||||
|
IntegerLiteral* expr = new IntegerLiteral(temp,T,Loc);
|
||||||
|
D.Read(expr->Value);
|
||||||
|
|
||||||
|
return expr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,12 +111,8 @@ public:
|
||||||
}
|
}
|
||||||
static bool classof(const Expr *) { return true; }
|
static bool classof(const Expr *) { return true; }
|
||||||
|
|
||||||
void Emit(llvm::Serializer& S) const {
|
|
||||||
llvm::SerializeTrait<Stmt>::Emit(S,*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline Expr* Materialize(llvm::Deserializer& D) {
|
static inline Expr* Materialize(llvm::Deserializer& D) {
|
||||||
return cast<Expr>(llvm::SerializeTrait<Stmt>::Materialize(D));
|
return cast<Expr>(Stmt::Materialize(D));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -146,6 +142,9 @@ public:
|
||||||
// Iterators
|
// Iterators
|
||||||
virtual child_iterator child_begin();
|
virtual child_iterator child_begin();
|
||||||
virtual child_iterator child_end();
|
virtual child_iterator child_end();
|
||||||
|
|
||||||
|
virtual void directEmit(llvm::Serializer& S) const;
|
||||||
|
static DeclRefExpr* directMaterialize(llvm::Deserializer& D);
|
||||||
};
|
};
|
||||||
|
|
||||||
/// PreDefinedExpr - [C99 6.4.2.2] - A pre-defined identifier such as __func__.
|
/// PreDefinedExpr - [C99 6.4.2.2] - A pre-defined identifier such as __func__.
|
||||||
|
@ -199,6 +198,9 @@ public:
|
||||||
// Iterators
|
// Iterators
|
||||||
virtual child_iterator child_begin();
|
virtual child_iterator child_begin();
|
||||||
virtual child_iterator child_end();
|
virtual child_iterator child_end();
|
||||||
|
|
||||||
|
virtual void directEmit(llvm::Serializer& S) const;
|
||||||
|
static IntegerLiteral* directMaterialize(llvm::Deserializer& D);
|
||||||
};
|
};
|
||||||
|
|
||||||
class CharacterLiteral : public Expr {
|
class CharacterLiteral : public Expr {
|
||||||
|
@ -799,6 +801,9 @@ public:
|
||||||
// Iterators
|
// Iterators
|
||||||
virtual child_iterator child_begin();
|
virtual child_iterator child_begin();
|
||||||
virtual child_iterator child_end();
|
virtual child_iterator child_end();
|
||||||
|
|
||||||
|
virtual void directEmit(llvm::Serializer& S) const;
|
||||||
|
static BinaryOperator* directMaterialize(llvm::Deserializer& D);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
|
BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
|
||||||
|
|
|
@ -110,6 +110,14 @@ public:
|
||||||
const_child_iterator child_end() const {
|
const_child_iterator child_end() const {
|
||||||
return const_child_iterator(const_cast<Stmt*>(this)->child_end());
|
return const_child_iterator(const_cast<Stmt*>(this)->child_end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Emit(llvm::Serializer& S) const;
|
||||||
|
static Stmt* Materialize(llvm::Deserializer& D);
|
||||||
|
|
||||||
|
virtual void directEmit(llvm::Serializer& S) const {
|
||||||
|
// This method will eventually be a pure-virtual function.
|
||||||
|
assert (false && "Not implemented.");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// DeclStmt - Adaptor class for mixing declarations with statements and
|
/// DeclStmt - Adaptor class for mixing declarations with statements and
|
||||||
|
@ -207,6 +215,9 @@ public:
|
||||||
// Iterators
|
// Iterators
|
||||||
virtual child_iterator child_begin();
|
virtual child_iterator child_begin();
|
||||||
virtual child_iterator child_end();
|
virtual child_iterator child_end();
|
||||||
|
|
||||||
|
virtual void directEmit(llvm::Serializer& S) const;
|
||||||
|
static CompoundStmt* directMaterialize(llvm::Deserializer& D);
|
||||||
};
|
};
|
||||||
|
|
||||||
// SwitchCase is the base class for CaseStmt and DefaultStmt,
|
// SwitchCase is the base class for CaseStmt and DefaultStmt,
|
||||||
|
@ -636,6 +647,9 @@ public:
|
||||||
// Iterators
|
// Iterators
|
||||||
virtual child_iterator child_begin();
|
virtual child_iterator child_begin();
|
||||||
virtual child_iterator child_end();
|
virtual child_iterator child_end();
|
||||||
|
|
||||||
|
virtual void directEmit(llvm::Serializer& S) const;
|
||||||
|
static ReturnStmt* directMaterialize(llvm::Deserializer& D);
|
||||||
};
|
};
|
||||||
|
|
||||||
/// AsmStmt - This represents a GNU inline-assembly statement extension.
|
/// AsmStmt - This represents a GNU inline-assembly statement extension.
|
||||||
|
@ -779,17 +793,4 @@ public:
|
||||||
|
|
||||||
} // end namespace clang
|
} // end namespace clang
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
// For Stmt serialization.
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
namespace llvm {
|
|
||||||
|
|
||||||
template<> struct SerializeTrait<clang::Stmt> {
|
|
||||||
static void Emit(Serializer& S, const clang::Stmt& stmt);
|
|
||||||
static clang::Stmt* Materialize(Deserializer& D);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // end namespace llvm
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue