blob: 0a298139bd9c0dc8c12dad3439e2ce175a26ecf8 [file] [log] [blame]
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +00001//===--- DeclSerialization.cpp - Serialization of Decls ---------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +00007//
8//===----------------------------------------------------------------------===//
9//
Gabor Greif843e9342008-03-06 10:40:09 +000010// This file defines methods that implement bitcode serialization for Decls.
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +000011//
12//===----------------------------------------------------------------------===//
13
Sam Bishopf3c63ae2008-04-11 14:49:10 +000014#include "clang/AST/ASTContext.h"
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +000015#include "clang/AST/Decl.h"
Douglas Gregor8e9bebd2008-10-21 16:13:35 +000016#include "clang/AST/DeclCXX.h"
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +000017#include "clang/AST/Expr.h"
18#include "llvm/Bitcode/Serialize.h"
19#include "llvm/Bitcode/Deserialize.h"
20
Ted Kremenek928fd7f2007-11-13 00:15:39 +000021using llvm::Serializer;
22using llvm::Deserializer;
23using llvm::SerializedPtrID;
24
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +000025using namespace clang;
26
Ted Kremenek928fd7f2007-11-13 00:15:39 +000027//===----------------------------------------------------------------------===//
28// Decl Serialization: Dispatch code to handle specialized decl types.
29//===----------------------------------------------------------------------===//
Ted Kremenek8af8fe32007-11-05 21:38:00 +000030
Ted Kremenek928fd7f2007-11-13 00:15:39 +000031void Decl::Emit(Serializer& S) const {
32 S.EmitInt(getKind());
33 EmitImpl(S);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000034 if (const DeclContext *DC = dyn_cast<const DeclContext>(this))
35 DC->EmitOutRec(S);
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +000036}
37
Sam Bishope2563ca2008-04-07 21:55:54 +000038Decl* Decl::Create(Deserializer& D, ASTContext& C) {
Ted Kremenek928fd7f2007-11-13 00:15:39 +000039
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000040 Decl *Dcl;
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000041 Kind k = static_cast<Kind>(D.ReadInt());
Sam Bishope2563ca2008-04-07 21:55:54 +000042
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000043 switch (k) {
44 default:
45 assert (false && "Not implemented.");
Chris Lattner0ed844b2008-04-04 06:12:32 +000046
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +000047 case TranslationUnit:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000048 Dcl = TranslationUnitDecl::CreateImpl(D, C);
49 break;
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +000050
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +000051 case Namespace:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000052 Dcl = NamespaceDecl::CreateImpl(D, C);
53 break;
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +000054
Steve Naroff248a7532008-04-15 22:42:06 +000055 case Var:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000056 Dcl = VarDecl::CreateImpl(D, C);
57 break;
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000058
Ted Kremenek583e0082007-11-14 18:12:19 +000059 case Enum:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000060 Dcl = EnumDecl::CreateImpl(D, C);
61 break;
Ted Kremenek583e0082007-11-14 18:12:19 +000062
63 case EnumConstant:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000064 Dcl = EnumConstantDecl::CreateImpl(D, C);
65 break;
Ted Kremenek583e0082007-11-14 18:12:19 +000066
Ted Kremenekf9d56c82007-11-14 17:47:01 +000067 case Field:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000068 Dcl = FieldDecl::CreateImpl(D, C);
69 break;
Ted Kremenekf9d56c82007-11-14 17:47:01 +000070
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000071 case ParmVar:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000072 Dcl = ParmVarDecl::CreateImpl(D, C);
73 break;
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000074
Fariborz Jahanian73da9e42008-12-20 20:56:12 +000075 case OriginalParmVar:
76 Dcl = ParmVarWithOriginalTypeDecl::CreateImpl(D, C);
77 break;
78
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000079 case Function:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000080 Dcl = FunctionDecl::CreateImpl(D, C);
81 break;
Douglas Gregor8e9bebd2008-10-21 16:13:35 +000082
83 case OverloadedFunction:
84 Dcl = OverloadedFunctionDecl::CreateImpl(D, C);
85 break;
86
Argyrios Kyrtzidis35bc0822008-10-15 00:42:39 +000087 case Record:
88 Dcl = RecordDecl::CreateImpl(D, C);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000089 break;
Ted Kremenekaad48b62007-11-14 08:06:37 +000090
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000091 case Typedef:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000092 Dcl = TypedefDecl::CreateImpl(D, C);
93 break;
Anders Carlssondfab6cb2008-02-08 00:33:21 +000094
Douglas Gregor72c3f312008-12-05 18:15:24 +000095 case TemplateTypeParm:
96 Dcl = TemplateTypeParmDecl::CreateImpl(D, C);
97 break;
98
Anders Carlssondfab6cb2008-02-08 00:33:21 +000099 case FileScopeAsm:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000100 Dcl = FileScopeAsmDecl::CreateImpl(D, C);
101 break;
Ted Kremenek2ebc89f2007-11-06 19:51:47 +0000102 }
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000103
104 if (DeclContext *DC = dyn_cast<DeclContext>(Dcl))
105 DC->ReadOutRec(D, C);
106
107 return Dcl;
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +0000108}
Ted Kremenek04973312007-11-02 18:05:11 +0000109
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000110//===----------------------------------------------------------------------===//
111// Common serialization logic for subclasses of Decl.
112//===----------------------------------------------------------------------===//
113
114void Decl::EmitInRec(Serializer& S) const {
115 S.Emit(getLocation()); // From Decl.
Ted Kremenek04973312007-11-02 18:05:11 +0000116}
117
Sam Bishope2563ca2008-04-07 21:55:54 +0000118void Decl::ReadInRec(Deserializer& D, ASTContext& C) {
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000119 Loc = SourceLocation::ReadVal(D); // From Decl.
Ted Kremenek04973312007-11-02 18:05:11 +0000120}
121
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000122//===----------------------------------------------------------------------===//
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000123// Common serialization logic for subclasses of DeclContext.
124//===----------------------------------------------------------------------===//
125
126void DeclContext::EmitOutRec(Serializer& S) const {
Douglas Gregor44b43212008-12-11 16:49:14 +0000127 S.EmitInt(Decls.size());
128 for (decl_iterator D = decls_begin(); D != decls_end(); ++D) {
129 bool Owned = ((*D)->getLexicalDeclContext() == this &&
130 DeclKind != Decl::TranslationUnit &&
131 !isFunctionOrMethod());
132 S.EmitBool(Owned);
133 if (Owned)
134 S.EmitOwnedPtr(*D);
135 else
136 S.EmitPtr(*D);
137 }
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000138}
139
140void DeclContext::ReadOutRec(Deserializer& D, ASTContext& C) {
Douglas Gregor44b43212008-12-11 16:49:14 +0000141 unsigned NumDecls = D.ReadInt();
142 Decls.resize(NumDecls);
143 for (unsigned Idx = 0; Idx < NumDecls; ++Idx) {
144 bool Owned = D.ReadBool();
145 if (Owned)
146 Decls[Idx] = cast_or_null<ScopedDecl>(D.ReadOwnedPtr<Decl>(C));
147 else
148 D.ReadPtr<ScopedDecl>(Decls[Idx]);
149 }
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000150}
151
152//===----------------------------------------------------------------------===//
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000153// Common serialization logic for subclasses of NamedDecl.
154//===----------------------------------------------------------------------===//
155
156void NamedDecl::EmitInRec(Serializer& S) const {
157 Decl::EmitInRec(S);
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000158 S.EmitInt(Name.getNameKind());
159
160 switch (Name.getNameKind()) {
161 case DeclarationName::Identifier:
162 S.EmitPtr(Name.getAsIdentifierInfo());
163 break;
164
165 case DeclarationName::ObjCZeroArgSelector:
166 case DeclarationName::ObjCOneArgSelector:
167 case DeclarationName::ObjCMultiArgSelector:
168 Name.getObjCSelector().Emit(S);
169 break;
170
171 case DeclarationName::CXXConstructorName:
172 case DeclarationName::CXXDestructorName:
173 case DeclarationName::CXXConversionFunctionName:
174 Name.getCXXNameType().Emit(S);
175 break;
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000176
177 case DeclarationName::CXXOperatorName:
178 S.EmitInt(Name.getCXXOverloadedOperator());
179 break;
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000180 }
Ted Kremenek04973312007-11-02 18:05:11 +0000181}
182
Sam Bishope2563ca2008-04-07 21:55:54 +0000183void NamedDecl::ReadInRec(Deserializer& D, ASTContext& C) {
184 Decl::ReadInRec(D, C);
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000185
186 DeclarationName::NameKind Kind
187 = static_cast<DeclarationName::NameKind>(D.ReadInt());
188 switch (Kind) {
189 case DeclarationName::Identifier: {
190 IdentifierInfo *Identifier;
191 D.ReadPtr(Identifier);
192 Name = Identifier;
193 break;
194 }
195
196 case DeclarationName::ObjCZeroArgSelector:
197 case DeclarationName::ObjCOneArgSelector:
198 case DeclarationName::ObjCMultiArgSelector:
199 Name = Selector::ReadVal(D);
200 break;
201
202 case DeclarationName::CXXConstructorName:
203 Name = C.DeclarationNames.getCXXConstructorName(QualType::ReadVal(D));
204 break;
205
206 case DeclarationName::CXXDestructorName:
207 Name = C.DeclarationNames.getCXXDestructorName(QualType::ReadVal(D));
208 break;
209
210 case DeclarationName::CXXConversionFunctionName:
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000211 Name
212 = C.DeclarationNames.getCXXConversionFunctionName(QualType::ReadVal(D));
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000213 break;
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000214
215 case DeclarationName::CXXOperatorName: {
216 OverloadedOperatorKind Op
217 = static_cast<OverloadedOperatorKind>(D.ReadInt());
218 Name = C.DeclarationNames.getCXXOperatorName(Op);
219 break;
220 }
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000221 }
Ted Kremenek04973312007-11-02 18:05:11 +0000222}
223
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000224//===----------------------------------------------------------------------===//
225// Common serialization logic for subclasses of ScopedDecl.
226//===----------------------------------------------------------------------===//
227
228void ScopedDecl::EmitInRec(Serializer& S) const {
229 NamedDecl::EmitInRec(S);
Chris Lattnerb048c982008-04-06 04:47:34 +0000230 S.EmitPtr(cast_or_null<Decl>(getDeclContext())); // From ScopedDecl.
Argyrios Kyrtzidis52393042008-11-09 23:41:00 +0000231 S.EmitPtr(cast_or_null<Decl>(getLexicalDeclContext())); // From ScopedDecl.
Ted Kremenek04973312007-11-02 18:05:11 +0000232}
233
Sam Bishope2563ca2008-04-07 21:55:54 +0000234void ScopedDecl::ReadInRec(Deserializer& D, ASTContext& C) {
235 NamedDecl::ReadInRec(D, C);
Argyrios Kyrtzidis52393042008-11-09 23:41:00 +0000236
237 assert(DeclCtx == 0);
238
239 const SerializedPtrID &SemaDCPtrID = D.ReadPtrID();
240 const SerializedPtrID &LexicalDCPtrID = D.ReadPtrID();
241
242 if (SemaDCPtrID == LexicalDCPtrID) {
243 // Allow back-patching. Observe that we register the variable of the
244 // *object* for back-patching. Its actual value will get filled in later.
245 D.ReadUIntPtr(DeclCtx, SemaDCPtrID);
246 }
247 else {
248 MultipleDC *MDC = new MultipleDC();
249 DeclCtx = reinterpret_cast<uintptr_t>(MDC) | 0x1;
250 // Allow back-patching. Observe that we register the variable of the
251 // *object* for back-patching. Its actual value will get filled in later.
Argyrios Kyrtzidisb0b847e2008-11-14 23:32:45 +0000252 D.ReadPtr(MDC->SemanticDC, SemaDCPtrID);
253 D.ReadPtr(MDC->LexicalDC, LexicalDCPtrID);
Argyrios Kyrtzidis52393042008-11-09 23:41:00 +0000254 }
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000255}
256
257 //===------------------------------------------------------------===//
258 // NOTE: Not all subclasses of ScopedDecl will use the "OutRec" //
259 // methods. This is because owned pointers are usually "batched" //
260 // together for efficiency. //
261 //===------------------------------------------------------------===//
262
263void ScopedDecl::EmitOutRec(Serializer& S) const {
264 S.EmitOwnedPtr(getNextDeclarator()); // From ScopedDecl.
Ted Kremenek04973312007-11-02 18:05:11 +0000265}
266
Sam Bishope2563ca2008-04-07 21:55:54 +0000267void ScopedDecl::ReadOutRec(Deserializer& D, ASTContext& C) {
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000268 NextDeclarator =
Sam Bishope2563ca2008-04-07 21:55:54 +0000269 cast_or_null<ScopedDecl>(D.ReadOwnedPtr<Decl>(C)); // From ScopedDecl.
Ted Kremenek04973312007-11-02 18:05:11 +0000270}
271
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000272//===----------------------------------------------------------------------===//
273// Common serialization logic for subclasses of ValueDecl.
274//===----------------------------------------------------------------------===//
275
276void ValueDecl::EmitInRec(Serializer& S) const {
277 ScopedDecl::EmitInRec(S);
278 S.Emit(getType()); // From ValueDecl.
279}
280
Sam Bishope2563ca2008-04-07 21:55:54 +0000281void ValueDecl::ReadInRec(Deserializer& D, ASTContext& C) {
282 ScopedDecl::ReadInRec(D, C);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000283 DeclType = QualType::ReadVal(D); // From ValueDecl.
284}
285
286//===----------------------------------------------------------------------===//
287// Common serialization logic for subclasses of VarDecl.
288//===----------------------------------------------------------------------===//
289
290void VarDecl::EmitInRec(Serializer& S) const {
291 ValueDecl::EmitInRec(S);
292 S.EmitInt(getStorageClass()); // From VarDecl.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000293}
294
Sam Bishope2563ca2008-04-07 21:55:54 +0000295void VarDecl::ReadInRec(Deserializer& D, ASTContext& C) {
296 ValueDecl::ReadInRec(D, C);
Fariborz Jahaniande7b4cd2007-12-13 00:54:18 +0000297 SClass = static_cast<StorageClass>(D.ReadInt()); // From VarDecl.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000298}
299
300 //===------------------------------------------------------------===//
301 // NOTE: VarDecl has its own "OutRec" methods that doesn't use //
302 // the one define in ScopedDecl. This is to batch emit the //
303 // owned pointers, which results in a smaller output.
304 //===------------------------------------------------------------===//
305
306void VarDecl::EmitOutRec(Serializer& S) const {
307 // Emit these last because they will create records of their own.
308 S.BatchEmitOwnedPtrs(getInit(), // From VarDecl.
309 getNextDeclarator()); // From ScopedDecl.
310}
311
Sam Bishope2563ca2008-04-07 21:55:54 +0000312void VarDecl::ReadOutRec(Deserializer& D, ASTContext& C) {
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000313 Decl* next_declarator;
314
Sam Bishope2563ca2008-04-07 21:55:54 +0000315 D.BatchReadOwnedPtrs(Init, // From VarDecl.
316 next_declarator, // From ScopedDecl.
317 C);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000318
319 setNextDeclarator(cast_or_null<ScopedDecl>(next_declarator));
Ted Kremenek04973312007-11-02 18:05:11 +0000320}
321
322
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000323void VarDecl::EmitImpl(Serializer& S) const {
324 VarDecl::EmitInRec(S);
325 VarDecl::EmitOutRec(S);
Ted Kremenek04973312007-11-02 18:05:11 +0000326}
327
Sam Bishope2563ca2008-04-07 21:55:54 +0000328void VarDecl::ReadImpl(Deserializer& D, ASTContext& C) {
329 ReadInRec(D, C);
330 ReadOutRec(D, C);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000331}
332
333//===----------------------------------------------------------------------===//
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000334// TranslationUnitDecl Serialization.
335//===----------------------------------------------------------------------===//
336
337void TranslationUnitDecl::EmitImpl(llvm::Serializer& S) const
338{
339 Decl::EmitInRec(S);
340}
341
342TranslationUnitDecl* TranslationUnitDecl::CreateImpl(Deserializer& D,
343 ASTContext& C) {
344 void *Mem = C.getAllocator().Allocate<TranslationUnitDecl>();
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000345 TranslationUnitDecl* decl = new (Mem) TranslationUnitDecl();
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000346
347 decl->Decl::ReadInRec(D, C);
348
349 return decl;
350}
351
352//===----------------------------------------------------------------------===//
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000353// NamespaceDecl Serialization.
354//===----------------------------------------------------------------------===//
355
356void NamespaceDecl::EmitImpl(llvm::Serializer& S) const
357{
358 ScopedDecl::EmitInRec(S);
359 S.Emit(getLBracLoc());
360 S.Emit(getRBracLoc());
361 ScopedDecl::EmitOutRec(S);
362}
363
364NamespaceDecl* NamespaceDecl::CreateImpl(Deserializer& D, ASTContext& C) {
365 void *Mem = C.getAllocator().Allocate<NamespaceDecl>();
366 NamespaceDecl* decl = new (Mem) NamespaceDecl(0, SourceLocation(), 0);
367
368 decl->ScopedDecl::ReadInRec(D, C);
369 decl->LBracLoc = SourceLocation::ReadVal(D);
370 decl->RBracLoc = SourceLocation::ReadVal(D);
371 decl->ScopedDecl::ReadOutRec(D, C);
372
373 return decl;
374}
375
376//===----------------------------------------------------------------------===//
Steve Naroff248a7532008-04-15 22:42:06 +0000377// VarDecl Serialization.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000378//===----------------------------------------------------------------------===//
379
Steve Naroff248a7532008-04-15 22:42:06 +0000380VarDecl* VarDecl::CreateImpl(Deserializer& D, ASTContext& C) {
381 void *Mem = C.getAllocator().Allocate<VarDecl>();
382 VarDecl* decl =
383 new (Mem) VarDecl(Var, 0, SourceLocation(), NULL, QualType(), None, NULL);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000384
Sam Bishope2563ca2008-04-07 21:55:54 +0000385 decl->VarDecl::ReadImpl(D, C);
Ted Kremenek04973312007-11-02 18:05:11 +0000386 return decl;
387}
388
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000389//===----------------------------------------------------------------------===//
Steve Naroff248a7532008-04-15 22:42:06 +0000390// ParmVarDecl Serialization.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000391//===----------------------------------------------------------------------===//
Ted Kremenek04973312007-11-02 18:05:11 +0000392
Ted Kremenek137bd912007-12-13 06:28:13 +0000393void ParmVarDecl::EmitImpl(llvm::Serializer& S) const {
394 VarDecl::EmitImpl(S);
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000395 S.EmitInt(getObjCDeclQualifier()); // From ParmVarDecl.
Chris Lattner04421082008-04-08 04:40:51 +0000396 S.EmitOwnedPtr(getDefaultArg()); // From ParmVarDecl.
Ted Kremenek137bd912007-12-13 06:28:13 +0000397}
398
Sam Bishope2563ca2008-04-07 21:55:54 +0000399ParmVarDecl* ParmVarDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Sam Bishopf3c63ae2008-04-11 14:49:10 +0000400 void *Mem = C.getAllocator().Allocate<ParmVarDecl>();
401 ParmVarDecl* decl = new (Mem)
Fariborz Jahanian4306d3c2008-12-20 23:29:59 +0000402 ParmVarDecl(ParmVar,
403 0, SourceLocation(), NULL, QualType(), None, NULL, NULL);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000404
Sam Bishope2563ca2008-04-07 21:55:54 +0000405 decl->VarDecl::ReadImpl(D, C);
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000406 decl->objcDeclQualifier = static_cast<ObjCDeclQualifier>(D.ReadInt());
Chris Lattner04421082008-04-08 04:40:51 +0000407 decl->DefaultArg = D.ReadOwnedPtr<Expr>(C);
Ted Kremenek04973312007-11-02 18:05:11 +0000408 return decl;
409}
410
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000411//===----------------------------------------------------------------------===//
Fariborz Jahanian73da9e42008-12-20 20:56:12 +0000412// ParmVarWithOriginalTypeDecl Serialization.
413//===----------------------------------------------------------------------===//
414
415void ParmVarWithOriginalTypeDecl::EmitImpl(llvm::Serializer& S) const {
416 ParmVarDecl::EmitImpl(S);
417 S.Emit(OriginalType);
418}
419
420ParmVarWithOriginalTypeDecl* ParmVarWithOriginalTypeDecl::CreateImpl(
421 Deserializer& D, ASTContext& C) {
422 void *Mem = C.getAllocator().Allocate<ParmVarWithOriginalTypeDecl>();
423 ParmVarWithOriginalTypeDecl* decl = new (Mem)
424 ParmVarWithOriginalTypeDecl(0, SourceLocation(), NULL, QualType(),
425 QualType(), None, NULL, NULL);
426
427 decl->ParmVarDecl::ReadImpl(D, C);
428 decl->OriginalType = QualType::ReadVal(D);
429 return decl;
430}
431//===----------------------------------------------------------------------===//
Ted Kremenek583e0082007-11-14 18:12:19 +0000432// EnumDecl Serialization.
433//===----------------------------------------------------------------------===//
434
435void EnumDecl::EmitImpl(Serializer& S) const {
436 ScopedDecl::EmitInRec(S);
437 S.EmitBool(isDefinition());
Douglas Gregor44b43212008-12-11 16:49:14 +0000438 S.Emit(IntegerType);
439 S.EmitOwnedPtr(getNextDeclarator());
Ted Kremenek583e0082007-11-14 18:12:19 +0000440}
441
Sam Bishope2563ca2008-04-07 21:55:54 +0000442EnumDecl* EnumDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Sam Bishopf3c63ae2008-04-11 14:49:10 +0000443 void *Mem = C.getAllocator().Allocate<EnumDecl>();
444 EnumDecl* decl = new (Mem) EnumDecl(0, SourceLocation(), NULL, NULL);
Ted Kremenek583e0082007-11-14 18:12:19 +0000445
Sam Bishope2563ca2008-04-07 21:55:54 +0000446 decl->ScopedDecl::ReadInRec(D, C);
Ted Kremenek583e0082007-11-14 18:12:19 +0000447 decl->setDefinition(D.ReadBool());
448 decl->IntegerType = QualType::ReadVal(D);
449
Douglas Gregor44b43212008-12-11 16:49:14 +0000450 Decl* next_declarator = D.ReadOwnedPtr<Decl>(C);
Ted Kremenek583e0082007-11-14 18:12:19 +0000451 decl->setNextDeclarator(cast_or_null<ScopedDecl>(next_declarator));
452
453 return decl;
454}
455
456//===----------------------------------------------------------------------===//
457// EnumConstantDecl Serialization.
458//===----------------------------------------------------------------------===//
459
460void EnumConstantDecl::EmitImpl(Serializer& S) const {
461 S.Emit(Val);
462 ValueDecl::EmitInRec(S);
463 S.BatchEmitOwnedPtrs(getNextDeclarator(),Init);
464}
465
Sam Bishope2563ca2008-04-07 21:55:54 +0000466EnumConstantDecl* EnumConstantDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Ted Kremenek049b1682007-11-14 23:38:09 +0000467 llvm::APSInt val(1);
Ted Kremenek583e0082007-11-14 18:12:19 +0000468 D.Read(val);
469
Sam Bishopf3c63ae2008-04-11 14:49:10 +0000470 void *Mem = C.getAllocator().Allocate<EnumConstantDecl>();
471 EnumConstantDecl* decl = new (Mem)
472 EnumConstantDecl(0, SourceLocation(), NULL, QualType(), NULL, val, NULL);
Ted Kremenek583e0082007-11-14 18:12:19 +0000473
Sam Bishope2563ca2008-04-07 21:55:54 +0000474 decl->ValueDecl::ReadInRec(D, C);
Ted Kremenek583e0082007-11-14 18:12:19 +0000475
476 Decl* next_declarator;
477
Sam Bishope2563ca2008-04-07 21:55:54 +0000478 D.BatchReadOwnedPtrs(next_declarator, decl->Init, C);
Ted Kremenek583e0082007-11-14 18:12:19 +0000479
Ted Kremenek049b1682007-11-14 23:38:09 +0000480 decl->setNextDeclarator(cast_or_null<ScopedDecl>(next_declarator));
Ted Kremenek583e0082007-11-14 18:12:19 +0000481
482 return decl;
483}
484
485//===----------------------------------------------------------------------===//
Ted Kremenekf9d56c82007-11-14 17:47:01 +0000486// FieldDecl Serialization.
487//===----------------------------------------------------------------------===//
488
489void FieldDecl::EmitImpl(Serializer& S) const {
Douglas Gregor44b43212008-12-11 16:49:14 +0000490 S.EmitBool(Mutable);
Ted Kremenekf9d56c82007-11-14 17:47:01 +0000491 S.Emit(getType());
Douglas Gregor44b43212008-12-11 16:49:14 +0000492 ScopedDecl::EmitInRec(S);
Ted Kremenekf9d56c82007-11-14 17:47:01 +0000493 S.EmitOwnedPtr(BitWidth);
494}
495
Sam Bishope2563ca2008-04-07 21:55:54 +0000496FieldDecl* FieldDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Sam Bishopf3c63ae2008-04-11 14:49:10 +0000497 void *Mem = C.getAllocator().Allocate<FieldDecl>();
Douglas Gregor44b43212008-12-11 16:49:14 +0000498 FieldDecl* decl = new (Mem) FieldDecl(Field, 0, SourceLocation(), NULL,
499 QualType(), 0, false, 0);
500 decl->Mutable = D.ReadBool();
Ted Kremenek21d50e12007-11-14 22:51:02 +0000501 decl->DeclType.ReadBackpatch(D);
Sam Bishope2563ca2008-04-07 21:55:54 +0000502 decl->ReadInRec(D, C);
503 decl->BitWidth = D.ReadOwnedPtr<Expr>(C);
Ted Kremenekf9d56c82007-11-14 17:47:01 +0000504 return decl;
505}
506
507//===----------------------------------------------------------------------===//
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000508// FunctionDecl Serialization.
509//===----------------------------------------------------------------------===//
Ted Kremenek04973312007-11-02 18:05:11 +0000510
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000511void FunctionDecl::EmitImpl(Serializer& S) const {
512 S.EmitInt(SClass); // From FunctionDecl.
513 S.EmitBool(IsInline); // From FunctionDecl.
514 ValueDecl::EmitInRec(S);
Ted Kremenek3bbc1982008-05-20 03:33:58 +0000515 S.EmitPtr(PreviousDeclaration);
Ted Kremenek04973312007-11-02 18:05:11 +0000516
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000517 // NOTE: We do not need to serialize out the number of parameters, because
518 // that is encoded in the type (accessed via getNumParams()).
Ted Kremenek04973312007-11-02 18:05:11 +0000519
Ted Kremenekd437f232007-11-13 22:51:08 +0000520 if (ParamInfo != NULL) {
521 S.EmitBool(true);
Argyrios Kyrtzidisdc5ddbf2008-11-07 14:22:23 +0000522 S.EmitInt(getNumParams());
Ted Kremenekd437f232007-11-13 22:51:08 +0000523 S.BatchEmitOwnedPtrs(getNumParams(),&ParamInfo[0], Body,
524 getNextDeclarator());
525 }
526 else {
527 S.EmitBool(false);
528 S.BatchEmitOwnedPtrs(Body,getNextDeclarator());
529 }
Ted Kremenek04973312007-11-02 18:05:11 +0000530}
531
Sam Bishope2563ca2008-04-07 21:55:54 +0000532FunctionDecl* FunctionDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Ted Kremenek04973312007-11-02 18:05:11 +0000533 StorageClass SClass = static_cast<StorageClass>(D.ReadInt());
534 bool IsInline = D.ReadBool();
Ted Kremenek04973312007-11-02 18:05:11 +0000535
Sam Bishopf3c63ae2008-04-11 14:49:10 +0000536 void *Mem = C.getAllocator().Allocate<FunctionDecl>();
537 FunctionDecl* decl = new (Mem)
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000538 FunctionDecl(Function, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +0000539 QualType(), SClass, IsInline, 0);
Ted Kremenek04973312007-11-02 18:05:11 +0000540
Sam Bishope2563ca2008-04-07 21:55:54 +0000541 decl->ValueDecl::ReadInRec(D, C);
Ted Kremenek3bbc1982008-05-20 03:33:58 +0000542 D.ReadPtr(decl->PreviousDeclaration);
Ted Kremenekda256852007-11-16 18:11:10 +0000543
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000544 Decl* next_declarator;
545
Douglas Gregor6b54bd12009-01-05 17:18:30 +0000546 int numParams = 0;
Ted Kremenekd437f232007-11-13 22:51:08 +0000547 bool hasParamDecls = D.ReadBool();
Argyrios Kyrtzidisdc5ddbf2008-11-07 14:22:23 +0000548 if (hasParamDecls)
549 numParams = D.ReadInt();
Ted Kremenekda256852007-11-16 18:11:10 +0000550
551 decl->ParamInfo = hasParamDecls
Argyrios Kyrtzidisdc5ddbf2008-11-07 14:22:23 +0000552 ? new ParmVarDecl*[numParams]
Ted Kremenekda256852007-11-16 18:11:10 +0000553 : NULL;
Ted Kremenekd437f232007-11-13 22:51:08 +0000554
555 if (hasParamDecls)
Argyrios Kyrtzidisdc5ddbf2008-11-07 14:22:23 +0000556 D.BatchReadOwnedPtrs(numParams,
Ted Kremenekd437f232007-11-13 22:51:08 +0000557 reinterpret_cast<Decl**>(&decl->ParamInfo[0]),
Sam Bishope2563ca2008-04-07 21:55:54 +0000558 decl->Body, next_declarator, C);
Ted Kremenekd437f232007-11-13 22:51:08 +0000559 else
Sam Bishope2563ca2008-04-07 21:55:54 +0000560 D.BatchReadOwnedPtrs(decl->Body, next_declarator, C);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000561
562 decl->setNextDeclarator(cast_or_null<ScopedDecl>(next_declarator));
Ted Kremenek04973312007-11-02 18:05:11 +0000563
564 return decl;
565}
Ted Kremenekf7bf4112007-11-05 21:49:34 +0000566
Steve Naroff56ee6892008-10-08 17:01:13 +0000567void BlockDecl::EmitImpl(Serializer& S) const {
568 // FIXME: what about arguments?
569 S.Emit(getCaretLocation());
570 S.EmitOwnedPtr(Body);
571}
572
573BlockDecl* BlockDecl::CreateImpl(Deserializer& D, ASTContext& C) {
574 QualType Q = QualType::ReadVal(D);
575 SourceLocation L = SourceLocation::ReadVal(D);
576 /*CompoundStmt* BodyStmt = cast<CompoundStmt>(*/D.ReadOwnedPtr<Stmt>(C)/*)*/;
577 assert(0 && "Cannot deserialize BlockBlockExpr yet");
578 // FIXME: need to handle parameters.
579 //return new BlockBlockExpr(L, Q, BodyStmt);
580 return 0;
581}
582
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000583//===----------------------------------------------------------------------===//
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000584// OverloadedFunctionDecl Serialization.
585//===----------------------------------------------------------------------===//
586
587void OverloadedFunctionDecl::EmitImpl(Serializer& S) const {
588 NamedDecl::EmitInRec(S);
589
590 S.EmitInt(getNumFunctions());
591 for (unsigned func = 0; func < getNumFunctions(); ++func)
592 S.EmitPtr(Functions[func]);
593}
594
595OverloadedFunctionDecl *
596OverloadedFunctionDecl::CreateImpl(Deserializer& D, ASTContext& C) {
597 void *Mem = C.getAllocator().Allocate<OverloadedFunctionDecl>();
598 OverloadedFunctionDecl* decl = new (Mem)
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000599 OverloadedFunctionDecl(0, DeclarationName());
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000600
601 decl->NamedDecl::ReadInRec(D, C);
602
603 unsigned numFunctions = D.ReadInt();
604 decl->Functions.reserve(numFunctions);
605 for (unsigned func = 0; func < numFunctions; ++func)
606 D.ReadPtr(decl->Functions[func]);
607
608 return decl;
609}
610
611//===----------------------------------------------------------------------===//
Ted Kremenekaad48b62007-11-14 08:06:37 +0000612// RecordDecl Serialization.
613//===----------------------------------------------------------------------===//
614
Ted Kremenek583e0082007-11-14 18:12:19 +0000615void RecordDecl::EmitImpl(Serializer& S) const {
Argyrios Kyrtzidis35bc0822008-10-15 00:42:39 +0000616 S.EmitInt(getTagKind());
617
Ted Kremenekaad48b62007-11-14 08:06:37 +0000618 ScopedDecl::EmitInRec(S);
Ted Kremenek583e0082007-11-14 18:12:19 +0000619 S.EmitBool(isDefinition());
Ted Kremenekaad48b62007-11-14 08:06:37 +0000620 S.EmitBool(hasFlexibleArrayMember());
Douglas Gregor44b43212008-12-11 16:49:14 +0000621 ScopedDecl::EmitOutRec(S);
Ted Kremenekaad48b62007-11-14 08:06:37 +0000622}
623
Argyrios Kyrtzidis35bc0822008-10-15 00:42:39 +0000624RecordDecl* RecordDecl::CreateImpl(Deserializer& D, ASTContext& C) {
625 TagKind TK = TagKind(D.ReadInt());
Sam Bishope2563ca2008-04-07 21:55:54 +0000626
Sam Bishopf3c63ae2008-04-11 14:49:10 +0000627 void *Mem = C.getAllocator().Allocate<RecordDecl>();
Argyrios Kyrtzidis35bc0822008-10-15 00:42:39 +0000628 RecordDecl* decl = new (Mem) RecordDecl(Record, TK, 0, SourceLocation(), NULL);
Ted Kremenek583e0082007-11-14 18:12:19 +0000629
Sam Bishope2563ca2008-04-07 21:55:54 +0000630 decl->ScopedDecl::ReadInRec(D, C);
Ted Kremenek583e0082007-11-14 18:12:19 +0000631 decl->setDefinition(D.ReadBool());
Ted Kremenekaad48b62007-11-14 08:06:37 +0000632 decl->setHasFlexibleArrayMember(D.ReadBool());
Douglas Gregor44b43212008-12-11 16:49:14 +0000633 decl->ScopedDecl::ReadOutRec(D, C);
634
Ted Kremenekaad48b62007-11-14 08:06:37 +0000635 return decl;
636}
637
638//===----------------------------------------------------------------------===//
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000639// TypedefDecl Serialization.
640//===----------------------------------------------------------------------===//
641
642void TypedefDecl::EmitImpl(Serializer& S) const {
Ted Kremenek2ebc89f2007-11-06 19:51:47 +0000643 S.Emit(UnderlyingType);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000644 ScopedDecl::EmitInRec(S);
645 ScopedDecl::EmitOutRec(S);
Ted Kremenekf7bf4112007-11-05 21:49:34 +0000646}
647
Sam Bishope2563ca2008-04-07 21:55:54 +0000648TypedefDecl* TypedefDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000649 QualType T = QualType::ReadVal(D);
650
Sam Bishopf3c63ae2008-04-11 14:49:10 +0000651 void *Mem = C.getAllocator().Allocate<TypedefDecl>();
652 TypedefDecl* decl = new (Mem) TypedefDecl(0, SourceLocation(), NULL, T, NULL);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000653
Sam Bishope2563ca2008-04-07 21:55:54 +0000654 decl->ScopedDecl::ReadInRec(D, C);
655 decl->ScopedDecl::ReadOutRec(D, C);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000656
Ted Kremenekf7bf4112007-11-05 21:49:34 +0000657 return decl;
658}
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000659
660//===----------------------------------------------------------------------===//
Douglas Gregor72c3f312008-12-05 18:15:24 +0000661// TemplateTypeParmDecl Serialization.
662//===----------------------------------------------------------------------===//
663
664void TemplateTypeParmDecl::EmitImpl(Serializer& S) const {
665 S.EmitBool(Typename);
666 ScopedDecl::EmitInRec(S);
667 ScopedDecl::EmitOutRec(S);
668}
669
670TemplateTypeParmDecl *
671TemplateTypeParmDecl::CreateImpl(Deserializer& D, ASTContext& C) {
672 bool Typename = D.ReadBool();
673 void *Mem = C.getAllocator().Allocate<TemplateTypeParmDecl>();
674 TemplateTypeParmDecl *decl
675 = new (Mem) TemplateTypeParmDecl(0, SourceLocation(), NULL, Typename);
676 decl->ScopedDecl::ReadInRec(D, C);
677 decl->ScopedDecl::ReadOutRec(D, C);
678 return decl;
679}
680
681//===----------------------------------------------------------------------===//
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000682// LinkageSpec Serialization.
683//===----------------------------------------------------------------------===//
684
685void LinkageSpecDecl::EmitInRec(Serializer& S) const {
686 Decl::EmitInRec(S);
687 S.EmitInt(getLanguage());
Douglas Gregorf44515a2008-12-16 22:23:02 +0000688 S.EmitBool(HadBraces);
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000689}
690
Sam Bishope2563ca2008-04-07 21:55:54 +0000691void LinkageSpecDecl::ReadInRec(Deserializer& D, ASTContext& C) {
692 Decl::ReadInRec(D, C);
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000693 Language = static_cast<LanguageIDs>(D.ReadInt());
Douglas Gregorf44515a2008-12-16 22:23:02 +0000694 HadBraces = D.ReadBool();
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000695}
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000696
697//===----------------------------------------------------------------------===//
698// FileScopeAsm Serialization.
699//===----------------------------------------------------------------------===//
700
701void FileScopeAsmDecl::EmitImpl(llvm::Serializer& S) const
702{
703 Decl::EmitInRec(S);
704 S.EmitOwnedPtr(AsmString);
705}
706
Sam Bishope2563ca2008-04-07 21:55:54 +0000707FileScopeAsmDecl* FileScopeAsmDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Sam Bishopf3c63ae2008-04-11 14:49:10 +0000708 void *Mem = C.getAllocator().Allocate<FileScopeAsmDecl>();
709 FileScopeAsmDecl* decl = new (Mem) FileScopeAsmDecl(SourceLocation(), 0);
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000710
Sam Bishope2563ca2008-04-07 21:55:54 +0000711 decl->Decl::ReadInRec(D, C);
712 decl->AsmString = cast<StringLiteral>(D.ReadOwnedPtr<Expr>(C));
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000713// D.ReadOwnedPtr(D.ReadOwnedPtr<StringLiteral>())<#T * * Ptr#>, <#bool AutoRegister#>)(decl->AsmString);
714
715 return decl;
716}