blob: b37e7b4cfe5bf22afcb2a64fe81bb0f13102a0a8 [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);
Douglas Gregor4afa39d2009-01-20 01:17:11 +000034 S.Emit(getLocation());
35 S.EmitBool(InvalidDecl);
36 // FIXME: HasAttrs?
37 S.EmitBool(Implicit);
38 S.EmitInt(Access);
39 S.EmitPtr(cast_or_null<Decl>(getDeclContext())); // From Decl.
40 S.EmitPtr(cast_or_null<Decl>(getLexicalDeclContext())); // From Decl.
41 S.EmitPtr(NextDeclarator);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000042 if (const DeclContext *DC = dyn_cast<const DeclContext>(this))
43 DC->EmitOutRec(S);
Douglas Gregor4afa39d2009-01-20 01:17:11 +000044
45 if (getDeclContext() &&
46 !getDeclContext()->isFunctionOrMethod()) {
47 S.EmitBool(true);
48 S.EmitOwnedPtr(NextDeclInScope);
49 } else {
50 S.EmitBool(false);
51 S.EmitPtr(NextDeclInScope);
52 }
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +000053}
54
Sam Bishope2563ca2008-04-07 21:55:54 +000055Decl* Decl::Create(Deserializer& D, ASTContext& C) {
Ted Kremenek928fd7f2007-11-13 00:15:39 +000056
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000057 Decl *Dcl;
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000058 Kind k = static_cast<Kind>(D.ReadInt());
Sam Bishope2563ca2008-04-07 21:55:54 +000059
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000060 switch (k) {
61 default:
62 assert (false && "Not implemented.");
Chris Lattner0ed844b2008-04-04 06:12:32 +000063
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +000064 case TranslationUnit:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000065 Dcl = TranslationUnitDecl::CreateImpl(D, C);
66 break;
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +000067
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +000068 case Namespace:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000069 Dcl = NamespaceDecl::CreateImpl(D, C);
70 break;
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +000071
Steve Naroff248a7532008-04-15 22:42:06 +000072 case Var:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000073 Dcl = VarDecl::CreateImpl(D, C);
74 break;
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000075
Ted Kremenek583e0082007-11-14 18:12:19 +000076 case Enum:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000077 Dcl = EnumDecl::CreateImpl(D, C);
78 break;
Ted Kremenek583e0082007-11-14 18:12:19 +000079
80 case EnumConstant:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000081 Dcl = EnumConstantDecl::CreateImpl(D, C);
82 break;
Ted Kremenek583e0082007-11-14 18:12:19 +000083
Ted Kremenekf9d56c82007-11-14 17:47:01 +000084 case Field:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000085 Dcl = FieldDecl::CreateImpl(D, C);
86 break;
Ted Kremenekf9d56c82007-11-14 17:47:01 +000087
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000088 case ParmVar:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000089 Dcl = ParmVarDecl::CreateImpl(D, C);
90 break;
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000091
Fariborz Jahanian73da9e42008-12-20 20:56:12 +000092 case OriginalParmVar:
93 Dcl = ParmVarWithOriginalTypeDecl::CreateImpl(D, C);
94 break;
95
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000096 case Function:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000097 Dcl = FunctionDecl::CreateImpl(D, C);
98 break;
Douglas Gregor8e9bebd2008-10-21 16:13:35 +000099
100 case OverloadedFunction:
101 Dcl = OverloadedFunctionDecl::CreateImpl(D, C);
102 break;
103
Argyrios Kyrtzidis35bc0822008-10-15 00:42:39 +0000104 case Record:
105 Dcl = RecordDecl::CreateImpl(D, C);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000106 break;
Ted Kremenekaad48b62007-11-14 08:06:37 +0000107
Ted Kremenek2ebc89f2007-11-06 19:51:47 +0000108 case Typedef:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000109 Dcl = TypedefDecl::CreateImpl(D, C);
110 break;
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000111
Douglas Gregor72c3f312008-12-05 18:15:24 +0000112 case TemplateTypeParm:
113 Dcl = TemplateTypeParmDecl::CreateImpl(D, C);
114 break;
115
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000116 case FileScopeAsm:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000117 Dcl = FileScopeAsmDecl::CreateImpl(D, C);
118 break;
Ted Kremenek2ebc89f2007-11-06 19:51:47 +0000119 }
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000120
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000121 Dcl->Loc = SourceLocation::ReadVal(D); // From Decl.
122 Dcl->InvalidDecl = D.ReadBool();
123 // FIXME: HasAttrs?
124 Dcl->Implicit = D.ReadBool();
125 Dcl->Access = D.ReadInt();
126
127 assert(Dcl->DeclCtx == 0);
128
129 const SerializedPtrID &SemaDCPtrID = D.ReadPtrID();
130 const SerializedPtrID &LexicalDCPtrID = D.ReadPtrID();
131
132 if (SemaDCPtrID == LexicalDCPtrID) {
133 // Allow back-patching. Observe that we register the variable of the
134 // *object* for back-patching. Its actual value will get filled in later.
135 D.ReadUIntPtr(Dcl->DeclCtx, SemaDCPtrID);
136 }
137 else {
138 MultipleDC *MDC = new MultipleDC();
139 Dcl->DeclCtx = reinterpret_cast<uintptr_t>(MDC) | 0x1;
140 // Allow back-patching. Observe that we register the variable of the
141 // *object* for back-patching. Its actual value will get filled in later.
142 D.ReadPtr(MDC->SemanticDC, SemaDCPtrID);
143 D.ReadPtr(MDC->LexicalDC, LexicalDCPtrID);
144 }
145 D.ReadPtr(Dcl->NextDeclarator);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000146 if (DeclContext *DC = dyn_cast<DeclContext>(Dcl))
147 DC->ReadOutRec(D, C);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000148 bool OwnsNext = D.ReadBool();
149 if (OwnsNext)
150 Dcl->NextDeclInScope = D.ReadOwnedPtr<Decl>(C);
151 else
152 D.ReadPtr(Dcl->NextDeclInScope);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000153 return Dcl;
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +0000154}
Ted Kremenek04973312007-11-02 18:05:11 +0000155
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000156//===----------------------------------------------------------------------===//
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000157// Common serialization logic for subclasses of DeclContext.
158//===----------------------------------------------------------------------===//
159
160void DeclContext::EmitOutRec(Serializer& S) const {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000161 bool Owned = !isFunctionOrMethod();
162 S.EmitBool(Owned);
163 if (Owned)
164 S.EmitOwnedPtr(FirstDecl);
165 else
166 S.EmitPtr(FirstDecl);
167 S.EmitPtr(LastDecl);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000168}
169
170void DeclContext::ReadOutRec(Deserializer& D, ASTContext& C) {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000171 bool Owned = D.ReadBool();
172 if (Owned)
173 FirstDecl = cast_or_null<Decl>(D.ReadOwnedPtr<Decl>(C));
174 else
175 D.ReadPtr(FirstDecl);
176 D.ReadPtr(LastDecl);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000177}
178
179//===----------------------------------------------------------------------===//
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000180// Common serialization logic for subclasses of NamedDecl.
181//===----------------------------------------------------------------------===//
182
183void NamedDecl::EmitInRec(Serializer& S) const {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000184 S.EmitInt(Name.getNameKind());
185
186 switch (Name.getNameKind()) {
187 case DeclarationName::Identifier:
188 S.EmitPtr(Name.getAsIdentifierInfo());
189 break;
190
191 case DeclarationName::ObjCZeroArgSelector:
192 case DeclarationName::ObjCOneArgSelector:
193 case DeclarationName::ObjCMultiArgSelector:
194 Name.getObjCSelector().Emit(S);
195 break;
196
197 case DeclarationName::CXXConstructorName:
198 case DeclarationName::CXXDestructorName:
199 case DeclarationName::CXXConversionFunctionName:
200 Name.getCXXNameType().Emit(S);
201 break;
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000202
203 case DeclarationName::CXXOperatorName:
204 S.EmitInt(Name.getCXXOverloadedOperator());
205 break;
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000206 }
Ted Kremenek04973312007-11-02 18:05:11 +0000207}
208
Sam Bishope2563ca2008-04-07 21:55:54 +0000209void NamedDecl::ReadInRec(Deserializer& D, ASTContext& C) {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000210 DeclarationName::NameKind Kind
211 = static_cast<DeclarationName::NameKind>(D.ReadInt());
212 switch (Kind) {
213 case DeclarationName::Identifier: {
214 IdentifierInfo *Identifier;
215 D.ReadPtr(Identifier);
216 Name = Identifier;
217 break;
218 }
219
220 case DeclarationName::ObjCZeroArgSelector:
221 case DeclarationName::ObjCOneArgSelector:
222 case DeclarationName::ObjCMultiArgSelector:
223 Name = Selector::ReadVal(D);
224 break;
225
226 case DeclarationName::CXXConstructorName:
227 Name = C.DeclarationNames.getCXXConstructorName(QualType::ReadVal(D));
228 break;
229
230 case DeclarationName::CXXDestructorName:
231 Name = C.DeclarationNames.getCXXDestructorName(QualType::ReadVal(D));
232 break;
233
234 case DeclarationName::CXXConversionFunctionName:
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000235 Name
236 = C.DeclarationNames.getCXXConversionFunctionName(QualType::ReadVal(D));
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000237 break;
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000238
239 case DeclarationName::CXXOperatorName: {
240 OverloadedOperatorKind Op
241 = static_cast<OverloadedOperatorKind>(D.ReadInt());
242 Name = C.DeclarationNames.getCXXOperatorName(Op);
243 break;
244 }
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000245 }
Ted Kremenek04973312007-11-02 18:05:11 +0000246}
247
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000248//===----------------------------------------------------------------------===//
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000249// Common serialization logic for subclasses of ValueDecl.
250//===----------------------------------------------------------------------===//
251
252void ValueDecl::EmitInRec(Serializer& S) const {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000253 NamedDecl::EmitInRec(S);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000254 S.Emit(getType()); // From ValueDecl.
255}
256
Sam Bishope2563ca2008-04-07 21:55:54 +0000257void ValueDecl::ReadInRec(Deserializer& D, ASTContext& C) {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000258 NamedDecl::ReadInRec(D, C);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000259 DeclType = QualType::ReadVal(D); // From ValueDecl.
260}
261
262//===----------------------------------------------------------------------===//
263// Common serialization logic for subclasses of VarDecl.
264//===----------------------------------------------------------------------===//
265
266void VarDecl::EmitInRec(Serializer& S) const {
267 ValueDecl::EmitInRec(S);
268 S.EmitInt(getStorageClass()); // From VarDecl.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000269}
270
Sam Bishope2563ca2008-04-07 21:55:54 +0000271void VarDecl::ReadInRec(Deserializer& D, ASTContext& C) {
272 ValueDecl::ReadInRec(D, C);
Fariborz Jahaniande7b4cd2007-12-13 00:54:18 +0000273 SClass = static_cast<StorageClass>(D.ReadInt()); // From VarDecl.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000274}
275
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000276void VarDecl::EmitOutRec(Serializer& S) const {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000277 // Emit this last because it will create a record of its own.
278 S.EmitOwnedPtr(getInit());
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000279}
280
Sam Bishope2563ca2008-04-07 21:55:54 +0000281void VarDecl::ReadOutRec(Deserializer& D, ASTContext& C) {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000282 Init = D.ReadOwnedPtr<Stmt>(C);
Ted Kremenek04973312007-11-02 18:05:11 +0000283}
284
285
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000286void VarDecl::EmitImpl(Serializer& S) const {
287 VarDecl::EmitInRec(S);
288 VarDecl::EmitOutRec(S);
Ted Kremenek04973312007-11-02 18:05:11 +0000289}
290
Sam Bishope2563ca2008-04-07 21:55:54 +0000291void VarDecl::ReadImpl(Deserializer& D, ASTContext& C) {
292 ReadInRec(D, C);
293 ReadOutRec(D, C);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000294}
295
296//===----------------------------------------------------------------------===//
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000297// TranslationUnitDecl Serialization.
298//===----------------------------------------------------------------------===//
299
300void TranslationUnitDecl::EmitImpl(llvm::Serializer& S) const
301{
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000302}
303
304TranslationUnitDecl* TranslationUnitDecl::CreateImpl(Deserializer& D,
305 ASTContext& C) {
306 void *Mem = C.getAllocator().Allocate<TranslationUnitDecl>();
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000307 TranslationUnitDecl* decl = new (Mem) TranslationUnitDecl();
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000308
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000309 return decl;
310}
311
312//===----------------------------------------------------------------------===//
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000313// NamespaceDecl Serialization.
314//===----------------------------------------------------------------------===//
315
316void NamespaceDecl::EmitImpl(llvm::Serializer& S) const
317{
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000318 NamedDecl::EmitInRec(S);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000319 S.Emit(getLBracLoc());
320 S.Emit(getRBracLoc());
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000321}
322
323NamespaceDecl* NamespaceDecl::CreateImpl(Deserializer& D, ASTContext& C) {
324 void *Mem = C.getAllocator().Allocate<NamespaceDecl>();
325 NamespaceDecl* decl = new (Mem) NamespaceDecl(0, SourceLocation(), 0);
326
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000327 decl->NamedDecl::ReadInRec(D, C);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000328 decl->LBracLoc = SourceLocation::ReadVal(D);
329 decl->RBracLoc = SourceLocation::ReadVal(D);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000330
331 return decl;
332}
333
334//===----------------------------------------------------------------------===//
Steve Naroff248a7532008-04-15 22:42:06 +0000335// VarDecl Serialization.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000336//===----------------------------------------------------------------------===//
337
Steve Naroff248a7532008-04-15 22:42:06 +0000338VarDecl* VarDecl::CreateImpl(Deserializer& D, ASTContext& C) {
339 void *Mem = C.getAllocator().Allocate<VarDecl>();
340 VarDecl* decl =
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000341 new (Mem) VarDecl(Var, 0, SourceLocation(), NULL, QualType(), None);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000342
Sam Bishope2563ca2008-04-07 21:55:54 +0000343 decl->VarDecl::ReadImpl(D, C);
Ted Kremenek04973312007-11-02 18:05:11 +0000344 return decl;
345}
346
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000347//===----------------------------------------------------------------------===//
Steve Naroff248a7532008-04-15 22:42:06 +0000348// ParmVarDecl Serialization.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000349//===----------------------------------------------------------------------===//
Ted Kremenek04973312007-11-02 18:05:11 +0000350
Ted Kremenek137bd912007-12-13 06:28:13 +0000351void ParmVarDecl::EmitImpl(llvm::Serializer& S) const {
352 VarDecl::EmitImpl(S);
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000353 S.EmitInt(getObjCDeclQualifier()); // From ParmVarDecl.
Chris Lattner04421082008-04-08 04:40:51 +0000354 S.EmitOwnedPtr(getDefaultArg()); // From ParmVarDecl.
Ted Kremenek137bd912007-12-13 06:28:13 +0000355}
356
Sam Bishope2563ca2008-04-07 21:55:54 +0000357ParmVarDecl* ParmVarDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Sam Bishopf3c63ae2008-04-11 14:49:10 +0000358 void *Mem = C.getAllocator().Allocate<ParmVarDecl>();
359 ParmVarDecl* decl = new (Mem)
Fariborz Jahanian4306d3c2008-12-20 23:29:59 +0000360 ParmVarDecl(ParmVar,
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000361 0, SourceLocation(), NULL, QualType(), None, NULL);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000362
Sam Bishope2563ca2008-04-07 21:55:54 +0000363 decl->VarDecl::ReadImpl(D, C);
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000364 decl->objcDeclQualifier = static_cast<ObjCDeclQualifier>(D.ReadInt());
Chris Lattner04421082008-04-08 04:40:51 +0000365 decl->DefaultArg = D.ReadOwnedPtr<Expr>(C);
Ted Kremenek04973312007-11-02 18:05:11 +0000366 return decl;
367}
368
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000369//===----------------------------------------------------------------------===//
Fariborz Jahanian73da9e42008-12-20 20:56:12 +0000370// ParmVarWithOriginalTypeDecl Serialization.
371//===----------------------------------------------------------------------===//
372
373void ParmVarWithOriginalTypeDecl::EmitImpl(llvm::Serializer& S) const {
374 ParmVarDecl::EmitImpl(S);
375 S.Emit(OriginalType);
376}
377
378ParmVarWithOriginalTypeDecl* ParmVarWithOriginalTypeDecl::CreateImpl(
379 Deserializer& D, ASTContext& C) {
380 void *Mem = C.getAllocator().Allocate<ParmVarWithOriginalTypeDecl>();
381 ParmVarWithOriginalTypeDecl* decl = new (Mem)
382 ParmVarWithOriginalTypeDecl(0, SourceLocation(), NULL, QualType(),
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000383 QualType(), None, NULL);
Fariborz Jahanian73da9e42008-12-20 20:56:12 +0000384
385 decl->ParmVarDecl::ReadImpl(D, C);
386 decl->OriginalType = QualType::ReadVal(D);
387 return decl;
388}
389//===----------------------------------------------------------------------===//
Ted Kremenek583e0082007-11-14 18:12:19 +0000390// EnumDecl Serialization.
391//===----------------------------------------------------------------------===//
392
393void EnumDecl::EmitImpl(Serializer& S) const {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000394 NamedDecl::EmitInRec(S);
Ted Kremenek583e0082007-11-14 18:12:19 +0000395 S.EmitBool(isDefinition());
Douglas Gregor44b43212008-12-11 16:49:14 +0000396 S.Emit(IntegerType);
Ted Kremenek583e0082007-11-14 18:12:19 +0000397}
398
Sam Bishope2563ca2008-04-07 21:55:54 +0000399EnumDecl* EnumDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Sam Bishopf3c63ae2008-04-11 14:49:10 +0000400 void *Mem = C.getAllocator().Allocate<EnumDecl>();
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000401 EnumDecl* decl = new (Mem) EnumDecl(0, SourceLocation(), NULL);
Ted Kremenek583e0082007-11-14 18:12:19 +0000402
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000403 decl->NamedDecl::ReadInRec(D, C);
Ted Kremenek583e0082007-11-14 18:12:19 +0000404 decl->setDefinition(D.ReadBool());
405 decl->IntegerType = QualType::ReadVal(D);
406
Ted Kremenek583e0082007-11-14 18:12:19 +0000407 return decl;
408}
409
410//===----------------------------------------------------------------------===//
411// EnumConstantDecl Serialization.
412//===----------------------------------------------------------------------===//
413
414void EnumConstantDecl::EmitImpl(Serializer& S) const {
415 S.Emit(Val);
416 ValueDecl::EmitInRec(S);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000417 S.EmitOwnedPtr(Init);
Ted Kremenek583e0082007-11-14 18:12:19 +0000418}
419
Sam Bishope2563ca2008-04-07 21:55:54 +0000420EnumConstantDecl* EnumConstantDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Ted Kremenek049b1682007-11-14 23:38:09 +0000421 llvm::APSInt val(1);
Ted Kremenek583e0082007-11-14 18:12:19 +0000422 D.Read(val);
423
Sam Bishopf3c63ae2008-04-11 14:49:10 +0000424 void *Mem = C.getAllocator().Allocate<EnumConstantDecl>();
425 EnumConstantDecl* decl = new (Mem)
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000426 EnumConstantDecl(0, SourceLocation(), NULL, QualType(), NULL, val);
Ted Kremenek583e0082007-11-14 18:12:19 +0000427
Sam Bishope2563ca2008-04-07 21:55:54 +0000428 decl->ValueDecl::ReadInRec(D, C);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000429 decl->Init = D.ReadOwnedPtr<Stmt>(C);
Ted Kremenek583e0082007-11-14 18:12:19 +0000430 return decl;
431}
432
433//===----------------------------------------------------------------------===//
Ted Kremenekf9d56c82007-11-14 17:47:01 +0000434// FieldDecl Serialization.
435//===----------------------------------------------------------------------===//
436
437void FieldDecl::EmitImpl(Serializer& S) const {
Douglas Gregor44b43212008-12-11 16:49:14 +0000438 S.EmitBool(Mutable);
Ted Kremenekf9d56c82007-11-14 17:47:01 +0000439 S.Emit(getType());
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000440 NamedDecl::EmitInRec(S);
Ted Kremenekf9d56c82007-11-14 17:47:01 +0000441 S.EmitOwnedPtr(BitWidth);
442}
443
Sam Bishope2563ca2008-04-07 21:55:54 +0000444FieldDecl* FieldDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Sam Bishopf3c63ae2008-04-11 14:49:10 +0000445 void *Mem = C.getAllocator().Allocate<FieldDecl>();
Douglas Gregor44b43212008-12-11 16:49:14 +0000446 FieldDecl* decl = new (Mem) FieldDecl(Field, 0, SourceLocation(), NULL,
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000447 QualType(), 0, false);
Douglas Gregor44b43212008-12-11 16:49:14 +0000448 decl->Mutable = D.ReadBool();
Ted Kremenek21d50e12007-11-14 22:51:02 +0000449 decl->DeclType.ReadBackpatch(D);
Sam Bishope2563ca2008-04-07 21:55:54 +0000450 decl->ReadInRec(D, C);
451 decl->BitWidth = D.ReadOwnedPtr<Expr>(C);
Ted Kremenekf9d56c82007-11-14 17:47:01 +0000452 return decl;
453}
454
455//===----------------------------------------------------------------------===//
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000456// FunctionDecl Serialization.
457//===----------------------------------------------------------------------===//
Ted Kremenek04973312007-11-02 18:05:11 +0000458
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000459void FunctionDecl::EmitImpl(Serializer& S) const {
460 S.EmitInt(SClass); // From FunctionDecl.
461 S.EmitBool(IsInline); // From FunctionDecl.
462 ValueDecl::EmitInRec(S);
Ted Kremenek3bbc1982008-05-20 03:33:58 +0000463 S.EmitPtr(PreviousDeclaration);
Ted Kremenek04973312007-11-02 18:05:11 +0000464
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000465 // NOTE: We do not need to serialize out the number of parameters, because
466 // that is encoded in the type (accessed via getNumParams()).
Ted Kremenek04973312007-11-02 18:05:11 +0000467
Ted Kremenekd437f232007-11-13 22:51:08 +0000468 if (ParamInfo != NULL) {
469 S.EmitBool(true);
Argyrios Kyrtzidisdc5ddbf2008-11-07 14:22:23 +0000470 S.EmitInt(getNumParams());
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000471 S.BatchEmitOwnedPtrs(getNumParams(),&ParamInfo[0], Body);
Ted Kremenekd437f232007-11-13 22:51:08 +0000472 }
473 else {
474 S.EmitBool(false);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000475 S.EmitOwnedPtr(Body);
Ted Kremenekd437f232007-11-13 22:51:08 +0000476 }
Ted Kremenek04973312007-11-02 18:05:11 +0000477}
478
Sam Bishope2563ca2008-04-07 21:55:54 +0000479FunctionDecl* FunctionDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Ted Kremenek04973312007-11-02 18:05:11 +0000480 StorageClass SClass = static_cast<StorageClass>(D.ReadInt());
481 bool IsInline = D.ReadBool();
Ted Kremenek04973312007-11-02 18:05:11 +0000482
Sam Bishopf3c63ae2008-04-11 14:49:10 +0000483 void *Mem = C.getAllocator().Allocate<FunctionDecl>();
484 FunctionDecl* decl = new (Mem)
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000485 FunctionDecl(Function, 0, SourceLocation(), DeclarationName(),
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000486 QualType(), SClass, IsInline);
Ted Kremenek04973312007-11-02 18:05:11 +0000487
Sam Bishope2563ca2008-04-07 21:55:54 +0000488 decl->ValueDecl::ReadInRec(D, C);
Ted Kremenek3bbc1982008-05-20 03:33:58 +0000489 D.ReadPtr(decl->PreviousDeclaration);
Ted Kremenekda256852007-11-16 18:11:10 +0000490
Douglas Gregor6b54bd12009-01-05 17:18:30 +0000491 int numParams = 0;
Ted Kremenekd437f232007-11-13 22:51:08 +0000492 bool hasParamDecls = D.ReadBool();
Argyrios Kyrtzidisdc5ddbf2008-11-07 14:22:23 +0000493 if (hasParamDecls)
494 numParams = D.ReadInt();
Ted Kremenekda256852007-11-16 18:11:10 +0000495
496 decl->ParamInfo = hasParamDecls
Argyrios Kyrtzidisdc5ddbf2008-11-07 14:22:23 +0000497 ? new ParmVarDecl*[numParams]
Ted Kremenekda256852007-11-16 18:11:10 +0000498 : NULL;
Ted Kremenekd437f232007-11-13 22:51:08 +0000499
500 if (hasParamDecls)
Argyrios Kyrtzidisdc5ddbf2008-11-07 14:22:23 +0000501 D.BatchReadOwnedPtrs(numParams,
Ted Kremenekd437f232007-11-13 22:51:08 +0000502 reinterpret_cast<Decl**>(&decl->ParamInfo[0]),
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000503 decl->Body, C);
Ted Kremenekd437f232007-11-13 22:51:08 +0000504 else
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000505 decl->Body = D.ReadOwnedPtr<Stmt>(C);
Ted Kremenek04973312007-11-02 18:05:11 +0000506
507 return decl;
508}
Ted Kremenekf7bf4112007-11-05 21:49:34 +0000509
Steve Naroff56ee6892008-10-08 17:01:13 +0000510void BlockDecl::EmitImpl(Serializer& S) const {
511 // FIXME: what about arguments?
512 S.Emit(getCaretLocation());
513 S.EmitOwnedPtr(Body);
514}
515
516BlockDecl* BlockDecl::CreateImpl(Deserializer& D, ASTContext& C) {
517 QualType Q = QualType::ReadVal(D);
518 SourceLocation L = SourceLocation::ReadVal(D);
519 /*CompoundStmt* BodyStmt = cast<CompoundStmt>(*/D.ReadOwnedPtr<Stmt>(C)/*)*/;
520 assert(0 && "Cannot deserialize BlockBlockExpr yet");
521 // FIXME: need to handle parameters.
522 //return new BlockBlockExpr(L, Q, BodyStmt);
523 return 0;
524}
525
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000526//===----------------------------------------------------------------------===//
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000527// OverloadedFunctionDecl Serialization.
528//===----------------------------------------------------------------------===//
529
530void OverloadedFunctionDecl::EmitImpl(Serializer& S) const {
531 NamedDecl::EmitInRec(S);
532
533 S.EmitInt(getNumFunctions());
534 for (unsigned func = 0; func < getNumFunctions(); ++func)
535 S.EmitPtr(Functions[func]);
536}
537
538OverloadedFunctionDecl *
539OverloadedFunctionDecl::CreateImpl(Deserializer& D, ASTContext& C) {
540 void *Mem = C.getAllocator().Allocate<OverloadedFunctionDecl>();
541 OverloadedFunctionDecl* decl = new (Mem)
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000542 OverloadedFunctionDecl(0, DeclarationName());
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000543
544 decl->NamedDecl::ReadInRec(D, C);
545
546 unsigned numFunctions = D.ReadInt();
547 decl->Functions.reserve(numFunctions);
548 for (unsigned func = 0; func < numFunctions; ++func)
549 D.ReadPtr(decl->Functions[func]);
550
551 return decl;
552}
553
554//===----------------------------------------------------------------------===//
Ted Kremenekaad48b62007-11-14 08:06:37 +0000555// RecordDecl Serialization.
556//===----------------------------------------------------------------------===//
557
Ted Kremenek583e0082007-11-14 18:12:19 +0000558void RecordDecl::EmitImpl(Serializer& S) const {
Argyrios Kyrtzidis35bc0822008-10-15 00:42:39 +0000559 S.EmitInt(getTagKind());
560
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000561 NamedDecl::EmitInRec(S);
Ted Kremenek583e0082007-11-14 18:12:19 +0000562 S.EmitBool(isDefinition());
Ted Kremenekaad48b62007-11-14 08:06:37 +0000563 S.EmitBool(hasFlexibleArrayMember());
Douglas Gregorbcbffc42009-01-07 00:43:41 +0000564 S.EmitBool(isAnonymousStructOrUnion());
Ted Kremenekaad48b62007-11-14 08:06:37 +0000565}
566
Argyrios Kyrtzidis35bc0822008-10-15 00:42:39 +0000567RecordDecl* RecordDecl::CreateImpl(Deserializer& D, ASTContext& C) {
568 TagKind TK = TagKind(D.ReadInt());
Sam Bishope2563ca2008-04-07 21:55:54 +0000569
Sam Bishopf3c63ae2008-04-11 14:49:10 +0000570 void *Mem = C.getAllocator().Allocate<RecordDecl>();
Argyrios Kyrtzidis35bc0822008-10-15 00:42:39 +0000571 RecordDecl* decl = new (Mem) RecordDecl(Record, TK, 0, SourceLocation(), NULL);
Ted Kremenek583e0082007-11-14 18:12:19 +0000572
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000573 decl->NamedDecl::ReadInRec(D, C);
Ted Kremenek583e0082007-11-14 18:12:19 +0000574 decl->setDefinition(D.ReadBool());
Ted Kremenekaad48b62007-11-14 08:06:37 +0000575 decl->setHasFlexibleArrayMember(D.ReadBool());
Douglas Gregorbcbffc42009-01-07 00:43:41 +0000576 decl->setAnonymousStructOrUnion(D.ReadBool());
Douglas Gregor44b43212008-12-11 16:49:14 +0000577
Ted Kremenekaad48b62007-11-14 08:06:37 +0000578 return decl;
579}
580
581//===----------------------------------------------------------------------===//
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000582// TypedefDecl Serialization.
583//===----------------------------------------------------------------------===//
584
585void TypedefDecl::EmitImpl(Serializer& S) const {
Ted Kremenek2ebc89f2007-11-06 19:51:47 +0000586 S.Emit(UnderlyingType);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000587 NamedDecl::EmitInRec(S);
Ted Kremenekf7bf4112007-11-05 21:49:34 +0000588}
589
Sam Bishope2563ca2008-04-07 21:55:54 +0000590TypedefDecl* TypedefDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000591 QualType T = QualType::ReadVal(D);
592
Sam Bishopf3c63ae2008-04-11 14:49:10 +0000593 void *Mem = C.getAllocator().Allocate<TypedefDecl>();
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000594 TypedefDecl* decl = new (Mem) TypedefDecl(0, SourceLocation(), NULL, T);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000595
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000596 decl->NamedDecl::ReadInRec(D, C);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000597
Ted Kremenekf7bf4112007-11-05 21:49:34 +0000598 return decl;
599}
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000600
601//===----------------------------------------------------------------------===//
Douglas Gregor72c3f312008-12-05 18:15:24 +0000602// TemplateTypeParmDecl Serialization.
603//===----------------------------------------------------------------------===//
604
605void TemplateTypeParmDecl::EmitImpl(Serializer& S) const {
606 S.EmitBool(Typename);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000607 NamedDecl::EmitInRec(S);
Douglas Gregor72c3f312008-12-05 18:15:24 +0000608}
609
610TemplateTypeParmDecl *
611TemplateTypeParmDecl::CreateImpl(Deserializer& D, ASTContext& C) {
612 bool Typename = D.ReadBool();
613 void *Mem = C.getAllocator().Allocate<TemplateTypeParmDecl>();
614 TemplateTypeParmDecl *decl
615 = new (Mem) TemplateTypeParmDecl(0, SourceLocation(), NULL, Typename);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000616 decl->NamedDecl::ReadInRec(D, C);
Douglas Gregor72c3f312008-12-05 18:15:24 +0000617 return decl;
618}
619
620//===----------------------------------------------------------------------===//
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000621// LinkageSpec Serialization.
622//===----------------------------------------------------------------------===//
623
624void LinkageSpecDecl::EmitInRec(Serializer& S) const {
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000625 S.EmitInt(getLanguage());
Douglas Gregorf44515a2008-12-16 22:23:02 +0000626 S.EmitBool(HadBraces);
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000627}
628
Sam Bishope2563ca2008-04-07 21:55:54 +0000629void LinkageSpecDecl::ReadInRec(Deserializer& D, ASTContext& C) {
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000630 Language = static_cast<LanguageIDs>(D.ReadInt());
Douglas Gregorf44515a2008-12-16 22:23:02 +0000631 HadBraces = D.ReadBool();
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000632}
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000633
634//===----------------------------------------------------------------------===//
635// FileScopeAsm Serialization.
636//===----------------------------------------------------------------------===//
637
638void FileScopeAsmDecl::EmitImpl(llvm::Serializer& S) const
639{
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000640 S.EmitOwnedPtr(AsmString);
641}
642
Sam Bishope2563ca2008-04-07 21:55:54 +0000643FileScopeAsmDecl* FileScopeAsmDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Sam Bishopf3c63ae2008-04-11 14:49:10 +0000644 void *Mem = C.getAllocator().Allocate<FileScopeAsmDecl>();
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000645 FileScopeAsmDecl* decl = new (Mem) FileScopeAsmDecl(0, SourceLocation(), 0);
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000646
Sam Bishope2563ca2008-04-07 21:55:54 +0000647 decl->AsmString = cast<StringLiteral>(D.ReadOwnedPtr<Expr>(C));
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000648// D.ReadOwnedPtr(D.ReadOwnedPtr<StringLiteral>())<#T * * Ptr#>, <#bool AutoRegister#>)(decl->AsmString);
649
650 return decl;
651}