Ted Kremenek | 215c2c8 | 2007-10-31 18:41:19 +0000 | [diff] [blame^] | 1 | //===--- StmtSerialization.cpp - Serialization of Statements --------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Ted Kremenek and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the type-specific methods for serializing statements |
| 11 | // and expressions. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "clang/AST/Stmt.h" |
| 16 | #include "clang/AST/StmtVisitor.h" |
| 17 | #include "llvm/Bitcode/Serialize.h" |
| 18 | #include "llvm/Bitcode/Deserialize.h" |
| 19 | |
| 20 | using llvm::Serializer; |
| 21 | using llvm::Deserializer; |
| 22 | using llvm::SerializeTrait; |
| 23 | |
| 24 | using namespace clang; |
| 25 | |
| 26 | |
| 27 | namespace { |
| 28 | class StmtSerializer : public StmtVisitor<StmtSerializer> { |
| 29 | Serializer& S; |
| 30 | public: |
| 31 | StmtSerializer(Serializer& S) : S(S) {} |
| 32 | |
| 33 | void VisitDeclStmt(DeclStmt* Stmt); |
| 34 | void VisitNullStmt(NullStmt* Stmt); |
| 35 | void VisitCompoundStmt(CompoundStmt* Stmt); |
| 36 | |
| 37 | void VisitStmt(Stmt*) { assert("Not Implemented yet"); } |
| 38 | }; |
| 39 | } // end anonymous namespace |
| 40 | |
| 41 | |
| 42 | void SerializeTrait<Stmt>::Emit(Serializer& S, const Stmt& stmt) { |
| 43 | S.EmitInt(stmt.getStmtClass()); |
| 44 | |
| 45 | StmtSerializer SS(S); |
| 46 | SS.Visit(const_cast<Stmt*>(&stmt)); |
| 47 | } |
| 48 | |
| 49 | void StmtSerializer::VisitDeclStmt(DeclStmt* Stmt) { |
| 50 | // FIXME |
| 51 | // S.EmitOwnedPtr(Stmt->getDecl()); |
| 52 | } |
| 53 | |
| 54 | void StmtSerializer::VisitNullStmt(NullStmt* Stmt) { |
| 55 | S.Emit(Stmt->getSemiLoc()); |
| 56 | } |
| 57 | |
| 58 | void StmtSerializer::VisitCompoundStmt(CompoundStmt* Stmt) { |
| 59 | S.Emit(Stmt->getLBracLoc()); |
| 60 | S.Emit(Stmt->getRBracLoc()); |
| 61 | |
| 62 | CompoundStmt::body_iterator I=Stmt->body_begin(), E=Stmt->body_end(); |
| 63 | |
| 64 | S.EmitInt(E-I); |
| 65 | |
| 66 | for ( ; I != E; ++I ) |
| 67 | S.EmitOwnedPtr(*I); |
| 68 | } |
| 69 | |
| 70 | Stmt* SerializeTrait<Stmt>::Materialize(Deserializer& D) { |
| 71 | unsigned sClass = D.ReadInt(); |
| 72 | |
| 73 | switch (sClass) { |
| 74 | default: |
| 75 | assert(false && "No matching statement class."); |
| 76 | return NULL; |
| 77 | |
| 78 | case Stmt::DeclStmtClass: |
| 79 | return NULL; // FIXME |
| 80 | // return new DeclStmt(D.ReadOwnedPtr<ScopedDecl>()); |
| 81 | |
| 82 | case Stmt::NullStmtClass: |
| 83 | return new NullStmt(D.ReadVal<SourceLocation>()); |
| 84 | |
| 85 | case Stmt::CompoundStmtClass: { |
| 86 | SourceLocation LBracLoc = D.ReadVal<SourceLocation>(); |
| 87 | SourceLocation RBracLoc = D.ReadVal<SourceLocation>(); |
| 88 | unsigned NumStmts = D.ReadInt(); |
| 89 | llvm::SmallVector<Stmt*, 16> Body; |
| 90 | |
| 91 | for (unsigned i = 0 ; i < NumStmts; ++i) |
| 92 | Body.push_back(D.ReadOwnedPtr<Stmt>()); |
| 93 | |
| 94 | return new CompoundStmt(&Body[0],NumStmts,LBracLoc,RBracLoc); |
| 95 | } |
| 96 | } |
| 97 | } |