blob: b26042e6f4c9169e9bfa25e338f252f7d5905b86 [file] [log] [blame]
Ted Kremenek215c2c82007-10-31 18:41:19 +00001//===--- 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
20using llvm::Serializer;
21using llvm::Deserializer;
22using llvm::SerializeTrait;
23
24using namespace clang;
25
26
27namespace {
28class StmtSerializer : public StmtVisitor<StmtSerializer> {
29 Serializer& S;
30public:
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
42void 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
49void StmtSerializer::VisitDeclStmt(DeclStmt* Stmt) {
50 // FIXME
51 // S.EmitOwnedPtr(Stmt->getDecl());
52}
53
54void StmtSerializer::VisitNullStmt(NullStmt* Stmt) {
55 S.Emit(Stmt->getSemiLoc());
56}
57
58void 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
70Stmt* 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}