llvm.org GIT mirror llvm / c6acc58
Added some sectioning comments to Serialize.h. Added additional serialization functors for use with std::foreach. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45162 91177308-0d34-0410-b5e6-96231b3b80d8 Ted Kremenek 12 years ago
1 changed file(s) with 74 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
3232 public:
3333 explicit Serializer(BitstreamWriter& stream);
3434 ~Serializer();
35
36 template
35
36 //==------------------------------------------------==//
37 // Template-based dispatch to emit arbitrary types.
38 //==------------------------------------------------==//
39
40 template
3741 inline void Emit(const T& X) { SerializeTrait::Emit(*this,X); }
3842
39 template
40 struct Emitter {
41 Serializer &S;
42
43 Emitter(Serializer& s) : S(s) {}
44 void operator()(const T& x) const { S.Emit(x); }
45 };
46
47 template
48 Emitter MakeEmitter() { return Emitter(*this); }
43 //==------------------------------------------------==//
44 // Methods to emit primitive types.
45 //==------------------------------------------------==//
4946
5047 void EmitInt(uint64_t X);
5148 void EmitSInt(int64_t X);
5249
53 void EmitBool(bool X) { EmitInt(X); }
50 inline void EmitBool(bool X) { EmitInt(X); }
5451 void EmitCStr(const char* beg, const char* end);
5552 void EmitCStr(const char* cstr);
5653
5754 void EmitPtr(const void* ptr) { EmitInt(getPtrId(ptr)); }
5855
5956 template
60 void EmitRef(const T& ref) { EmitPtr(&ref); }
61
62 template
63 void EmitOwnedPtr(T* ptr) {
57 inline void EmitRef(const T& ref) { EmitPtr(&ref); }
58
59 template
60 inline void EmitOwnedPtr(T* ptr) {
6461 EmitPtr(ptr);
6562 if (ptr) SerializeTrait::Emit(*this,*ptr);
6663 }
6764
65
66 //==------------------------------------------------==//
67 // Batch emission of pointers.
68 //==------------------------------------------------==//
69
6870 template
6971 void BatchEmitOwnedPtrs(T1* p1, T2* p2) {
7072 EmitPtr(p1);
134136 if (p2) SerializeTrait::Emit(*this,*p2);
135137 if (p3) SerializeTrait::Emit(*this,*p3);
136138 }
139
140 //==------------------------------------------------==//
141 // Emitter Functors
142 //==------------------------------------------------==//
143
144 template
145 struct Emitter0 {
146 Serializer& S;
147 Emitter0(Serializer& s) : S(s) {}
148 void operator()(const T& x) const {
149 SerializeTrait::Emit(S,x);
150 }
151 };
152
153 template
154 struct Emitter1 {
155 Serializer& S;
156 Arg1 A1;
157
158 Emitter1(Serializer& s, Arg1 a1) : S(s), A1(a1) {}
159 void operator()(const T& x) const {
160 SerializeTrait::Emit(S,x,A1);
161 }
162 };
163
164 template
165 struct Emitter2 {
166 Serializer& S;
167 Arg1 A1;
168 Arg2 A2;
169
170 Emitter2(Serializer& s, Arg1 a1, Arg2 a2) : S(s), A1(a1), A2(a2) {}
171 void operator()(const T& x) const {
172 SerializeTrait::Emit(S,x,A1,A2);
173 }
174 };
175
176 template
177 Emitter0 MakeEmitter() {
178 return Emitter0(*this);
179 }
180
181 template
182 Emitter1 MakeEmitter(Arg1 a1) {
183 return Emitter1(*this,a1);
184 }
185
186 template
187 Emitter2 MakeEmitter(Arg1 a1, Arg2 a2) {
188 return Emitter2(*this,a1,a2);
189 }
190
191 //==------------------------------------------------==//
192 // Misc. query and block/record manipulation methods.
193 //==------------------------------------------------==//
137194
138195 bool isRegistered(const void* p) const;
139196