From: Ted Kremenek Date: Wed, 31 Oct 2007 18:41:19 +0000 (+0000) Subject: Preliminary support for serializing statements. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e522d85ffcf500681eeca93671b82f565d993300;p=clang Preliminary support for serializing statements. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43566 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/AST/StmtSerialization.cpp b/AST/StmtSerialization.cpp new file mode 100644 index 0000000000..b26042e6f4 --- /dev/null +++ b/AST/StmtSerialization.cpp @@ -0,0 +1,97 @@ +//===--- 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. +// +//===----------------------------------------------------------------------===// + +#include "clang/AST/Stmt.h" +#include "clang/AST/StmtVisitor.h" +#include "llvm/Bitcode/Serialize.h" +#include "llvm/Bitcode/Deserialize.h" + +using llvm::Serializer; +using llvm::Deserializer; +using llvm::SerializeTrait; + +using namespace clang; + + +namespace { +class StmtSerializer : public StmtVisitor { + 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"); } +}; +} // end anonymous namespace + + +void SerializeTrait::Emit(Serializer& S, const Stmt& stmt) { + S.EmitInt(stmt.getStmtClass()); + + StmtSerializer SS(S); + SS.Visit(const_cast(&stmt)); +} + +void StmtSerializer::VisitDeclStmt(DeclStmt* Stmt) { + // FIXME + // S.EmitOwnedPtr(Stmt->getDecl()); +} + +void StmtSerializer::VisitNullStmt(NullStmt* Stmt) { + S.Emit(Stmt->getSemiLoc()); +} + +void StmtSerializer::VisitCompoundStmt(CompoundStmt* Stmt) { + S.Emit(Stmt->getLBracLoc()); + S.Emit(Stmt->getRBracLoc()); + + CompoundStmt::body_iterator I=Stmt->body_begin(), E=Stmt->body_end(); + + S.EmitInt(E-I); + + for ( ; I != E; ++I ) + S.EmitOwnedPtr(*I); +} + +Stmt* SerializeTrait::Materialize(Deserializer& D) { + unsigned sClass = D.ReadInt(); + + switch (sClass) { + default: + assert(false && "No matching statement class."); + return NULL; + + case Stmt::DeclStmtClass: + return NULL; // FIXME +// return new DeclStmt(D.ReadOwnedPtr()); + + case Stmt::NullStmtClass: + return new NullStmt(D.ReadVal()); + + case Stmt::CompoundStmtClass: { + SourceLocation LBracLoc = D.ReadVal(); + SourceLocation RBracLoc = D.ReadVal(); + unsigned NumStmts = D.ReadInt(); + llvm::SmallVector Body; + + for (unsigned i = 0 ; i < NumStmts; ++i) + Body.push_back(D.ReadOwnedPtr()); + + return new CompoundStmt(&Body[0],NumStmts,LBracLoc,RBracLoc); + } + } +}