2007-11-01 02:41:19 +08:00
|
|
|
//===--- StmtSerialization.cpp - Serialization of Statements --------------===//
|
|
|
|
//
|
|
|
|
// 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 file defines the type-specific methods for serializing statements
|
|
|
|
// and expressions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-11-07 08:17:35 +08:00
|
|
|
#include "clang/AST/Expr.h"
|
2007-11-01 02:41:19 +08:00
|
|
|
#include "llvm/Bitcode/Serialize.h"
|
|
|
|
#include "llvm/Bitcode/Deserialize.h"
|
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
|
2007-11-07 08:17:35 +08:00
|
|
|
void Stmt::Emit(llvm::Serializer& S) const {
|
|
|
|
S.EmitInt(getStmtClass());
|
|
|
|
directEmit(S);
|
|
|
|
}
|
2007-11-01 02:41:19 +08:00
|
|
|
|
2007-11-07 08:17:35 +08:00
|
|
|
Stmt* Stmt::Materialize(llvm::Deserializer& D) {
|
|
|
|
StmtClass SC = static_cast<StmtClass>(D.ReadInt());
|
2007-11-01 02:41:19 +08:00
|
|
|
|
2007-11-07 08:17:35 +08:00
|
|
|
switch (SC) {
|
|
|
|
default:
|
|
|
|
assert (false && "Not implemented.");
|
|
|
|
return NULL;
|
2007-11-07 08:37:40 +08:00
|
|
|
|
|
|
|
case BinaryOperatorClass:
|
|
|
|
return BinaryOperator::directMaterialize(D);
|
2007-11-07 08:17:35 +08:00
|
|
|
|
2007-11-07 13:25:31 +08:00
|
|
|
case BreakStmtClass:
|
|
|
|
return BreakStmt::directMaterialize(D);
|
|
|
|
|
|
|
|
case CaseStmtClass:
|
|
|
|
return CaseStmt::directMaterialize(D);
|
|
|
|
|
2007-11-07 08:17:35 +08:00
|
|
|
case CompoundStmtClass:
|
|
|
|
return CompoundStmt::directMaterialize(D);
|
|
|
|
|
|
|
|
case DeclRefExprClass:
|
|
|
|
return DeclRefExpr::directMaterialize(D);
|
|
|
|
|
2007-11-07 08:37:40 +08:00
|
|
|
case DeclStmtClass:
|
|
|
|
return DeclStmt::directMaterialize(D);
|
2007-11-07 13:25:31 +08:00
|
|
|
|
|
|
|
case DefaultStmtClass:
|
|
|
|
return DefaultStmt::directMaterialize(D);
|
2007-11-07 15:53:55 +08:00
|
|
|
|
|
|
|
case DoStmtClass:
|
|
|
|
return DoStmt::directMaterialize(D);
|
2007-11-07 16:02:55 +08:00
|
|
|
|
|
|
|
case ForStmtClass:
|
|
|
|
return ForStmt::directMaterialize(D);
|
2007-11-07 16:07:46 +08:00
|
|
|
|
|
|
|
case GotoStmtClass:
|
|
|
|
return GotoStmt::directMaterialize(D);
|
2007-11-07 13:25:31 +08:00
|
|
|
|
2007-11-07 15:19:30 +08:00
|
|
|
case IfStmtClass:
|
|
|
|
return IfStmt::directMaterialize(D);
|
|
|
|
|
2007-11-07 08:17:35 +08:00
|
|
|
case IntegerLiteralClass:
|
2007-11-07 08:40:53 +08:00
|
|
|
return IntegerLiteral::directMaterialize(D);
|
|
|
|
|
2007-11-07 08:48:04 +08:00
|
|
|
case LabelStmtClass:
|
|
|
|
return LabelStmt::directMaterialize(D);
|
|
|
|
|
2007-11-07 08:40:53 +08:00
|
|
|
case NullStmtClass:
|
|
|
|
return NullStmt::directMaterialize(D);
|
2007-11-07 08:37:40 +08:00
|
|
|
|
2007-11-07 13:25:31 +08:00
|
|
|
case ParenExprClass:
|
|
|
|
return ParenExpr::directMaterialize(D);
|
|
|
|
|
2007-11-07 08:37:40 +08:00
|
|
|
case ReturnStmtClass:
|
2007-11-07 13:25:31 +08:00
|
|
|
return ReturnStmt::directMaterialize(D);
|
|
|
|
|
|
|
|
case SwitchStmtClass:
|
|
|
|
return SwitchStmt::directMaterialize(D);
|
2007-11-07 15:50:10 +08:00
|
|
|
|
|
|
|
case WhileStmtClass:
|
|
|
|
return WhileStmt::directMaterialize(D);
|
2007-11-07 08:17:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-07 08:37:40 +08:00
|
|
|
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);
|
|
|
|
}
|
2007-11-01 02:41:19 +08:00
|
|
|
|
2007-11-07 13:25:31 +08:00
|
|
|
void BreakStmt::directEmit(llvm::Serializer& S) const {
|
|
|
|
S.Emit(BreakLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
BreakStmt* BreakStmt::directMaterialize(llvm::Deserializer& D) {
|
|
|
|
SourceLocation Loc = SourceLocation::ReadVal(D);
|
|
|
|
return new BreakStmt(Loc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CaseStmt::directEmit(llvm::Serializer& S) const {
|
|
|
|
S.Emit(CaseLoc);
|
|
|
|
S.EmitOwnedPtr(getLHS());
|
|
|
|
S.EmitOwnedPtr(getRHS());
|
|
|
|
S.EmitOwnedPtr(getSubStmt());
|
|
|
|
S.EmitPtr(getNextSwitchCase());
|
|
|
|
}
|
|
|
|
|
|
|
|
CaseStmt* CaseStmt::directMaterialize(llvm::Deserializer& D) {
|
|
|
|
SourceLocation CaseLoc = SourceLocation::ReadVal(D);
|
|
|
|
Expr* LHS = D.ReadOwnedPtr<Expr>();
|
|
|
|
Expr* RHS = D.ReadOwnedPtr<Expr>();
|
|
|
|
Stmt* SubStmt = D.ReadOwnedPtr<Stmt>();
|
|
|
|
|
|
|
|
CaseStmt* stmt = new CaseStmt(LHS,RHS,SubStmt,CaseLoc);
|
|
|
|
stmt->setNextSwitchCase(D.ReadPtr<SwitchCase>());
|
|
|
|
|
|
|
|
return stmt;
|
|
|
|
}
|
2007-11-01 02:41:19 +08:00
|
|
|
|
2007-11-07 08:17:35 +08:00
|
|
|
void CompoundStmt::directEmit(llvm::Serializer& S) const {
|
|
|
|
S.Emit(LBracLoc);
|
|
|
|
S.Emit(RBracLoc);
|
|
|
|
S.Emit(Body.size());
|
|
|
|
|
|
|
|
for (const_body_iterator I=body_begin(), E=body_end(); I!=E; ++I)
|
|
|
|
S.EmitOwnedPtr(*I);
|
|
|
|
}
|
|
|
|
|
|
|
|
CompoundStmt* CompoundStmt::directMaterialize(llvm::Deserializer& D) {
|
|
|
|
SourceLocation LB = SourceLocation::ReadVal(D);
|
|
|
|
SourceLocation RB = SourceLocation::ReadVal(D);
|
|
|
|
unsigned size = D.ReadInt();
|
|
|
|
|
|
|
|
CompoundStmt* stmt = new CompoundStmt(NULL,0,LB,RB);
|
|
|
|
|
|
|
|
stmt->Body.reserve(size);
|
2007-11-01 02:41:19 +08:00
|
|
|
|
2007-11-07 08:17:35 +08:00
|
|
|
for (unsigned i = 0; i < size; ++i)
|
|
|
|
stmt->Body.push_back(D.ReadOwnedPtr<Stmt>());
|
|
|
|
|
|
|
|
return stmt;
|
2007-11-01 02:41:19 +08:00
|
|
|
}
|
|
|
|
|
2007-11-07 08:37:40 +08:00
|
|
|
void DeclStmt::directEmit(llvm::Serializer& S) const {
|
|
|
|
// FIXME: special handling for struct decls.
|
|
|
|
S.EmitOwnedPtr(getDecl());
|
2007-11-07 08:17:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2007-11-01 02:41:19 +08:00
|
|
|
}
|
|
|
|
|
2007-11-07 08:37:40 +08:00
|
|
|
DeclStmt* DeclStmt::directMaterialize(llvm::Deserializer& D) {
|
|
|
|
ScopedDecl* decl = cast<ScopedDecl>(D.ReadOwnedPtr<Decl>());
|
|
|
|
return new DeclStmt(decl);
|
|
|
|
}
|
|
|
|
|
2007-11-07 13:25:31 +08:00
|
|
|
void DefaultStmt::directEmit(llvm::Serializer& S) const {
|
|
|
|
S.Emit(DefaultLoc);
|
|
|
|
S.EmitOwnedPtr(getSubStmt());
|
|
|
|
S.EmitPtr(getNextSwitchCase());
|
|
|
|
}
|
|
|
|
|
|
|
|
DefaultStmt* DefaultStmt::directMaterialize(llvm::Deserializer& D) {
|
|
|
|
SourceLocation Loc = SourceLocation::ReadVal(D);
|
|
|
|
Stmt* SubStmt = D.ReadOwnedPtr<Stmt>();
|
|
|
|
|
|
|
|
DefaultStmt* stmt = new DefaultStmt(Loc,SubStmt);
|
|
|
|
stmt->setNextSwitchCase(D.ReadPtr<SwitchCase>());
|
|
|
|
|
|
|
|
return stmt;
|
|
|
|
}
|
2007-11-07 08:37:40 +08:00
|
|
|
|
2007-11-07 15:53:55 +08:00
|
|
|
void DoStmt::directEmit(llvm::Serializer& S) const {
|
|
|
|
S.Emit(DoLoc);
|
|
|
|
S.EmitOwnedPtr(getCond());
|
|
|
|
S.EmitOwnedPtr(getBody());
|
|
|
|
}
|
|
|
|
|
|
|
|
DoStmt* DoStmt::directMaterialize(llvm::Deserializer& D) {
|
|
|
|
SourceLocation DoLoc = SourceLocation::ReadVal(D);
|
|
|
|
Expr* Cond = D.ReadOwnedPtr<Expr>();
|
|
|
|
Stmt* Body = D.ReadOwnedPtr<Stmt>();
|
|
|
|
return new DoStmt(Body,Cond,DoLoc);
|
|
|
|
}
|
|
|
|
|
2007-11-07 16:02:55 +08:00
|
|
|
void ForStmt::directEmit(llvm::Serializer& S) const {
|
|
|
|
S.Emit(ForLoc);
|
|
|
|
S.EmitOwnedPtr(getInit());
|
|
|
|
S.EmitOwnedPtr(getCond());
|
|
|
|
S.EmitOwnedPtr(getInc());
|
|
|
|
S.EmitOwnedPtr(getBody());
|
|
|
|
}
|
|
|
|
|
|
|
|
ForStmt* ForStmt::directMaterialize(llvm::Deserializer& D) {
|
|
|
|
SourceLocation ForLoc = SourceLocation::ReadVal(D);
|
|
|
|
Stmt* Init = D.ReadOwnedPtr<Stmt>();
|
|
|
|
Expr* Cond = D.ReadOwnedPtr<Expr>();
|
|
|
|
Expr* Inc = D.ReadOwnedPtr<Expr>();
|
|
|
|
Stmt* Body = D.ReadOwnedPtr<Stmt>();
|
|
|
|
return new ForStmt(Init,Cond,Inc,Body,ForLoc);
|
|
|
|
}
|
|
|
|
|
2007-11-07 16:07:46 +08:00
|
|
|
void GotoStmt::directEmit(llvm::Serializer& S) const {
|
|
|
|
S.Emit(GotoLoc);
|
|
|
|
S.Emit(LabelLoc);
|
|
|
|
S.EmitPtr(Label);
|
|
|
|
}
|
|
|
|
|
|
|
|
GotoStmt* GotoStmt::directMaterialize(llvm::Deserializer& D) {
|
|
|
|
SourceLocation GotoLoc = SourceLocation::ReadVal(D);
|
|
|
|
SourceLocation LabelLoc = SourceLocation::ReadVal(D);
|
|
|
|
GotoStmt* stmt = new GotoStmt(NULL,GotoLoc,LabelLoc);
|
|
|
|
D.ReadPtr(stmt->Label); // This pointer may be backpatched later.
|
|
|
|
return stmt;
|
|
|
|
}
|
|
|
|
|
2007-11-07 15:19:30 +08:00
|
|
|
void IfStmt::directEmit(llvm::Serializer& S) const {
|
|
|
|
S.Emit(IfLoc);
|
|
|
|
S.EmitOwnedPtr(getCond());
|
|
|
|
S.EmitOwnedPtr(getThen());
|
|
|
|
S.EmitOwnedPtr(getElse());
|
|
|
|
}
|
|
|
|
|
|
|
|
IfStmt* IfStmt::directMaterialize(llvm::Deserializer& D) {
|
|
|
|
SourceLocation L = SourceLocation::ReadVal(D);
|
|
|
|
Expr* Cond = D.ReadOwnedPtr<Expr>();
|
|
|
|
Stmt* Then = D.ReadOwnedPtr<Stmt>();
|
|
|
|
Stmt* Else = D.ReadOwnedPtr<Stmt>();
|
|
|
|
return new IfStmt(L,Cond,Then,Else);
|
|
|
|
}
|
|
|
|
|
2007-11-07 08:17:35 +08:00
|
|
|
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);
|
2007-11-01 02:41:19 +08:00
|
|
|
|
2007-11-07 08:17:35 +08:00
|
|
|
// 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;
|
2007-11-01 02:41:19 +08:00
|
|
|
}
|
2007-11-07 08:37:40 +08:00
|
|
|
|
2007-11-07 08:48:04 +08:00
|
|
|
void LabelStmt::directEmit(llvm::Serializer& S) const {
|
|
|
|
S.EmitPtr(Label);
|
|
|
|
S.Emit(IdentLoc);
|
|
|
|
S.EmitOwnedPtr(SubStmt);
|
|
|
|
}
|
|
|
|
|
|
|
|
LabelStmt* LabelStmt::directMaterialize(llvm::Deserializer& D) {
|
|
|
|
IdentifierInfo* Label = D.ReadPtr<IdentifierInfo>();
|
|
|
|
SourceLocation IdentLoc = SourceLocation::ReadVal(D);
|
|
|
|
Stmt* SubStmt = D.ReadOwnedPtr<Stmt>();
|
|
|
|
return new LabelStmt(IdentLoc,Label,SubStmt);
|
|
|
|
}
|
|
|
|
|
2007-11-07 08:40:53 +08:00
|
|
|
void NullStmt::directEmit(llvm::Serializer& S) const {
|
|
|
|
S.Emit(SemiLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
NullStmt* NullStmt::directMaterialize(llvm::Deserializer& D) {
|
|
|
|
SourceLocation SemiLoc = SourceLocation::ReadVal(D);
|
|
|
|
return new NullStmt(SemiLoc);
|
|
|
|
}
|
2007-11-07 08:37:40 +08:00
|
|
|
|
2007-11-07 13:25:31 +08:00
|
|
|
void ParenExpr::directEmit(llvm::Serializer& S) const {
|
|
|
|
S.Emit(L);
|
|
|
|
S.Emit(R);
|
|
|
|
S.EmitOwnedPtr(Val);
|
|
|
|
}
|
|
|
|
|
|
|
|
ParenExpr* ParenExpr::directMaterialize(llvm::Deserializer& D) {
|
|
|
|
SourceLocation L = SourceLocation::ReadVal(D);
|
|
|
|
SourceLocation R = SourceLocation::ReadVal(D);
|
|
|
|
Expr* val = D.ReadOwnedPtr<Expr>();
|
|
|
|
return new ParenExpr(L,R,val);
|
|
|
|
}
|
|
|
|
|
2007-11-07 08:37:40 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2007-11-07 13:25:31 +08:00
|
|
|
void SwitchStmt::directEmit(llvm::Serializer& S) const {
|
|
|
|
S.Emit(SwitchLoc);
|
|
|
|
S.EmitOwnedPtr(getCond());
|
|
|
|
S.EmitOwnedPtr(getBody());
|
|
|
|
S.EmitPtr(FirstCase);
|
|
|
|
}
|
|
|
|
|
|
|
|
SwitchStmt* SwitchStmt::directMaterialize(llvm::Deserializer& D) {
|
|
|
|
SourceLocation Loc = SourceLocation::ReadVal(D);
|
|
|
|
Stmt* Cond = D.ReadOwnedPtr<Stmt>();
|
|
|
|
Stmt* Body = D.ReadOwnedPtr<Stmt>();
|
|
|
|
SwitchCase* FirstCase = cast<SwitchCase>(D.ReadPtr<Stmt>());
|
|
|
|
|
|
|
|
SwitchStmt* stmt = new SwitchStmt(cast<Expr>(Cond));
|
|
|
|
stmt->setBody(Body,Loc);
|
|
|
|
stmt->FirstCase = FirstCase;
|
|
|
|
|
|
|
|
return stmt;
|
|
|
|
}
|
2007-11-07 15:50:10 +08:00
|
|
|
|
|
|
|
void WhileStmt::directEmit(llvm::Serializer& S) const {
|
|
|
|
S.Emit(WhileLoc);
|
|
|
|
S.EmitOwnedPtr(getCond());
|
|
|
|
S.EmitOwnedPtr(getBody());
|
|
|
|
}
|
|
|
|
|
|
|
|
WhileStmt* WhileStmt::directMaterialize(llvm::Deserializer& D) {
|
|
|
|
SourceLocation WhileLoc = SourceLocation::ReadVal(D);
|
|
|
|
Expr* Cond = D.ReadOwnedPtr<Expr>();
|
|
|
|
Stmt* Body = D.ReadOwnedPtr<Stmt>();
|
|
|
|
return new WhileStmt(Cond,Body,WhileLoc);
|
|
|
|
}
|