blob: a10b229fcd67268760acdc910c4574e2921e0187 [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:
Douglas Gregor64650af2009-02-02 23:39:07 +000093 Dcl = OriginalParmVarDecl::CreateImpl(D, C);
Fariborz Jahanian73da9e42008-12-20 20:56:12 +000094 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 Gregor2a3009a2009-02-03 19:21:40 +0000206
207 case DeclarationName::CXXUsingDirective:
208 // No extra data to emit
209 break;
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000210 }
Ted Kremenek04973312007-11-02 18:05:11 +0000211}
212
Sam Bishope2563ca2008-04-07 21:55:54 +0000213void NamedDecl::ReadInRec(Deserializer& D, ASTContext& C) {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000214 DeclarationName::NameKind Kind
215 = static_cast<DeclarationName::NameKind>(D.ReadInt());
216 switch (Kind) {
217 case DeclarationName::Identifier: {
Ted Kremenekddf32da2009-01-21 00:42:24 +0000218 // Don't allow back-patching. The IdentifierInfo table must already
219 // be loaded.
220 Name = D.ReadPtr<IdentifierInfo>();
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000221 break;
222 }
223
224 case DeclarationName::ObjCZeroArgSelector:
225 case DeclarationName::ObjCOneArgSelector:
226 case DeclarationName::ObjCMultiArgSelector:
227 Name = Selector::ReadVal(D);
228 break;
229
230 case DeclarationName::CXXConstructorName:
231 Name = C.DeclarationNames.getCXXConstructorName(QualType::ReadVal(D));
232 break;
233
234 case DeclarationName::CXXDestructorName:
235 Name = C.DeclarationNames.getCXXDestructorName(QualType::ReadVal(D));
236 break;
237
238 case DeclarationName::CXXConversionFunctionName:
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000239 Name
240 = C.DeclarationNames.getCXXConversionFunctionName(QualType::ReadVal(D));
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000241 break;
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000242
243 case DeclarationName::CXXOperatorName: {
244 OverloadedOperatorKind Op
245 = static_cast<OverloadedOperatorKind>(D.ReadInt());
246 Name = C.DeclarationNames.getCXXOperatorName(Op);
247 break;
248 }
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000249
250 case DeclarationName::CXXUsingDirective:
251 Name = DeclarationName::getUsingDirectiveName();
252 break;
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000253 }
Ted Kremenek04973312007-11-02 18:05:11 +0000254}
255
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000256//===----------------------------------------------------------------------===//
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000257// Common serialization logic for subclasses of ValueDecl.
258//===----------------------------------------------------------------------===//
259
260void ValueDecl::EmitInRec(Serializer& S) const {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000261 NamedDecl::EmitInRec(S);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000262 S.Emit(getType()); // From ValueDecl.
263}
264
Sam Bishope2563ca2008-04-07 21:55:54 +0000265void ValueDecl::ReadInRec(Deserializer& D, ASTContext& C) {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000266 NamedDecl::ReadInRec(D, C);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000267 DeclType = QualType::ReadVal(D); // From ValueDecl.
268}
269
270//===----------------------------------------------------------------------===//
271// Common serialization logic for subclasses of VarDecl.
272//===----------------------------------------------------------------------===//
273
274void VarDecl::EmitInRec(Serializer& S) const {
275 ValueDecl::EmitInRec(S);
276 S.EmitInt(getStorageClass()); // From VarDecl.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000277}
278
Sam Bishope2563ca2008-04-07 21:55:54 +0000279void VarDecl::ReadInRec(Deserializer& D, ASTContext& C) {
280 ValueDecl::ReadInRec(D, C);
Fariborz Jahaniande7b4cd2007-12-13 00:54:18 +0000281 SClass = static_cast<StorageClass>(D.ReadInt()); // From VarDecl.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000282}
283
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000284void VarDecl::EmitOutRec(Serializer& S) const {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000285 // Emit this last because it will create a record of its own.
286 S.EmitOwnedPtr(getInit());
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000287}
288
Sam Bishope2563ca2008-04-07 21:55:54 +0000289void VarDecl::ReadOutRec(Deserializer& D, ASTContext& C) {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000290 Init = D.ReadOwnedPtr<Stmt>(C);
Ted Kremenek04973312007-11-02 18:05:11 +0000291}
292
293
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000294void VarDecl::EmitImpl(Serializer& S) const {
295 VarDecl::EmitInRec(S);
296 VarDecl::EmitOutRec(S);
Ted Kremenek04973312007-11-02 18:05:11 +0000297}
298
Sam Bishope2563ca2008-04-07 21:55:54 +0000299void VarDecl::ReadImpl(Deserializer& D, ASTContext& C) {
300 ReadInRec(D, C);
301 ReadOutRec(D, C);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000302}
303
304//===----------------------------------------------------------------------===//
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000305// TranslationUnitDecl Serialization.
306//===----------------------------------------------------------------------===//
307
308void TranslationUnitDecl::EmitImpl(llvm::Serializer& S) const
309{
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000310}
311
312TranslationUnitDecl* TranslationUnitDecl::CreateImpl(Deserializer& D,
313 ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000314 return new (C) TranslationUnitDecl();
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000315}
316
317//===----------------------------------------------------------------------===//
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000318// NamespaceDecl Serialization.
319//===----------------------------------------------------------------------===//
320
321void NamespaceDecl::EmitImpl(llvm::Serializer& S) const
322{
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000323 NamedDecl::EmitInRec(S);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000324 S.Emit(getLBracLoc());
325 S.Emit(getRBracLoc());
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000326}
327
328NamespaceDecl* NamespaceDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000329 NamespaceDecl* decl = new (C) NamespaceDecl(0, SourceLocation(), 0);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000330
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000331 decl->NamedDecl::ReadInRec(D, C);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000332 decl->LBracLoc = SourceLocation::ReadVal(D);
333 decl->RBracLoc = SourceLocation::ReadVal(D);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000334
335 return decl;
336}
337
338//===----------------------------------------------------------------------===//
Steve Naroff248a7532008-04-15 22:42:06 +0000339// VarDecl Serialization.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000340//===----------------------------------------------------------------------===//
341
Steve Naroff248a7532008-04-15 22:42:06 +0000342VarDecl* VarDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff248a7532008-04-15 22:42:06 +0000343 VarDecl* decl =
Steve Naroff3e970492009-01-27 21:25:57 +0000344 new (C) VarDecl(Var, 0, SourceLocation(), NULL, QualType(), None);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000345
Sam Bishope2563ca2008-04-07 21:55:54 +0000346 decl->VarDecl::ReadImpl(D, C);
Ted Kremenek04973312007-11-02 18:05:11 +0000347 return decl;
348}
349
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000350//===----------------------------------------------------------------------===//
Steve Naroff248a7532008-04-15 22:42:06 +0000351// ParmVarDecl Serialization.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000352//===----------------------------------------------------------------------===//
Ted Kremenek04973312007-11-02 18:05:11 +0000353
Ted Kremenek137bd912007-12-13 06:28:13 +0000354void ParmVarDecl::EmitImpl(llvm::Serializer& S) const {
355 VarDecl::EmitImpl(S);
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000356 S.EmitInt(getObjCDeclQualifier()); // From ParmVarDecl.
Chris Lattner04421082008-04-08 04:40:51 +0000357 S.EmitOwnedPtr(getDefaultArg()); // From ParmVarDecl.
Ted Kremenek137bd912007-12-13 06:28:13 +0000358}
359
Sam Bishope2563ca2008-04-07 21:55:54 +0000360ParmVarDecl* ParmVarDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000361 ParmVarDecl* decl = new (C)
Fariborz Jahanian4306d3c2008-12-20 23:29:59 +0000362 ParmVarDecl(ParmVar,
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000363 0, SourceLocation(), NULL, QualType(), None, NULL);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000364
Sam Bishope2563ca2008-04-07 21:55:54 +0000365 decl->VarDecl::ReadImpl(D, C);
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000366 decl->objcDeclQualifier = static_cast<ObjCDeclQualifier>(D.ReadInt());
Chris Lattner04421082008-04-08 04:40:51 +0000367 decl->DefaultArg = D.ReadOwnedPtr<Expr>(C);
Ted Kremenek04973312007-11-02 18:05:11 +0000368 return decl;
369}
370
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000371//===----------------------------------------------------------------------===//
Douglas Gregor64650af2009-02-02 23:39:07 +0000372// OriginalParmVarDecl Serialization.
Fariborz Jahanian73da9e42008-12-20 20:56:12 +0000373//===----------------------------------------------------------------------===//
374
Douglas Gregor64650af2009-02-02 23:39:07 +0000375void OriginalParmVarDecl::EmitImpl(llvm::Serializer& S) const {
Fariborz Jahanian73da9e42008-12-20 20:56:12 +0000376 ParmVarDecl::EmitImpl(S);
377 S.Emit(OriginalType);
378}
379
Douglas Gregor64650af2009-02-02 23:39:07 +0000380OriginalParmVarDecl* OriginalParmVarDecl::CreateImpl(
Fariborz Jahanian73da9e42008-12-20 20:56:12 +0000381 Deserializer& D, ASTContext& C) {
Douglas Gregor64650af2009-02-02 23:39:07 +0000382 OriginalParmVarDecl* decl = new (C)
383 OriginalParmVarDecl(0, SourceLocation(), NULL, QualType(),
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000384 QualType(), None, NULL);
Fariborz Jahanian73da9e42008-12-20 20:56:12 +0000385
386 decl->ParmVarDecl::ReadImpl(D, C);
387 decl->OriginalType = QualType::ReadVal(D);
388 return decl;
389}
390//===----------------------------------------------------------------------===//
Ted Kremenek583e0082007-11-14 18:12:19 +0000391// EnumDecl Serialization.
392//===----------------------------------------------------------------------===//
393
394void EnumDecl::EmitImpl(Serializer& S) const {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000395 NamedDecl::EmitInRec(S);
Ted Kremenek583e0082007-11-14 18:12:19 +0000396 S.EmitBool(isDefinition());
Douglas Gregor44b43212008-12-11 16:49:14 +0000397 S.Emit(IntegerType);
Ted Kremenek583e0082007-11-14 18:12:19 +0000398}
399
Sam Bishope2563ca2008-04-07 21:55:54 +0000400EnumDecl* EnumDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000401 EnumDecl* decl = new (C) 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
Steve Naroff3e970492009-01-27 21:25:57 +0000424 EnumConstantDecl* decl = new (C)
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000425 EnumConstantDecl(0, SourceLocation(), NULL, QualType(), NULL, val);
Ted Kremenek583e0082007-11-14 18:12:19 +0000426
Sam Bishope2563ca2008-04-07 21:55:54 +0000427 decl->ValueDecl::ReadInRec(D, C);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000428 decl->Init = D.ReadOwnedPtr<Stmt>(C);
Ted Kremenek583e0082007-11-14 18:12:19 +0000429 return decl;
430}
431
432//===----------------------------------------------------------------------===//
Ted Kremenekf9d56c82007-11-14 17:47:01 +0000433// FieldDecl Serialization.
434//===----------------------------------------------------------------------===//
435
436void FieldDecl::EmitImpl(Serializer& S) const {
Douglas Gregor44b43212008-12-11 16:49:14 +0000437 S.EmitBool(Mutable);
Ted Kremenekf9d56c82007-11-14 17:47:01 +0000438 S.Emit(getType());
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000439 NamedDecl::EmitInRec(S);
Ted Kremenekf9d56c82007-11-14 17:47:01 +0000440 S.EmitOwnedPtr(BitWidth);
441}
442
Sam Bishope2563ca2008-04-07 21:55:54 +0000443FieldDecl* FieldDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000444 FieldDecl* decl = new (C) FieldDecl(Field, 0, SourceLocation(), NULL,
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000445 QualType(), 0, false);
Douglas Gregor44b43212008-12-11 16:49:14 +0000446 decl->Mutable = D.ReadBool();
Ted Kremenek21d50e12007-11-14 22:51:02 +0000447 decl->DeclType.ReadBackpatch(D);
Sam Bishope2563ca2008-04-07 21:55:54 +0000448 decl->ReadInRec(D, C);
449 decl->BitWidth = D.ReadOwnedPtr<Expr>(C);
Ted Kremenekf9d56c82007-11-14 17:47:01 +0000450 return decl;
451}
452
453//===----------------------------------------------------------------------===//
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000454// FunctionDecl Serialization.
455//===----------------------------------------------------------------------===//
Ted Kremenek04973312007-11-02 18:05:11 +0000456
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000457void FunctionDecl::EmitImpl(Serializer& S) const {
458 S.EmitInt(SClass); // From FunctionDecl.
459 S.EmitBool(IsInline); // From FunctionDecl.
460 ValueDecl::EmitInRec(S);
Ted Kremenek3bbc1982008-05-20 03:33:58 +0000461 S.EmitPtr(PreviousDeclaration);
Ted Kremenek04973312007-11-02 18:05:11 +0000462
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000463 // NOTE: We do not need to serialize out the number of parameters, because
464 // that is encoded in the type (accessed via getNumParams()).
Ted Kremenek04973312007-11-02 18:05:11 +0000465
Ted Kremenekd437f232007-11-13 22:51:08 +0000466 if (ParamInfo != NULL) {
467 S.EmitBool(true);
Argyrios Kyrtzidisdc5ddbf2008-11-07 14:22:23 +0000468 S.EmitInt(getNumParams());
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000469 S.BatchEmitOwnedPtrs(getNumParams(),&ParamInfo[0], Body);
Ted Kremenekd437f232007-11-13 22:51:08 +0000470 }
471 else {
472 S.EmitBool(false);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000473 S.EmitOwnedPtr(Body);
Ted Kremenekd437f232007-11-13 22:51:08 +0000474 }
Ted Kremenek04973312007-11-02 18:05:11 +0000475}
476
Sam Bishope2563ca2008-04-07 21:55:54 +0000477FunctionDecl* FunctionDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Ted Kremenek04973312007-11-02 18:05:11 +0000478 StorageClass SClass = static_cast<StorageClass>(D.ReadInt());
479 bool IsInline = D.ReadBool();
Ted Kremenek04973312007-11-02 18:05:11 +0000480
Steve Naroff3e970492009-01-27 21:25:57 +0000481 FunctionDecl* decl = new (C)
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000482 FunctionDecl(Function, 0, SourceLocation(), DeclarationName(),
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000483 QualType(), SClass, IsInline);
Ted Kremenek04973312007-11-02 18:05:11 +0000484
Sam Bishope2563ca2008-04-07 21:55:54 +0000485 decl->ValueDecl::ReadInRec(D, C);
Ted Kremenek3bbc1982008-05-20 03:33:58 +0000486 D.ReadPtr(decl->PreviousDeclaration);
Ted Kremenekda256852007-11-16 18:11:10 +0000487
Douglas Gregor6b54bd12009-01-05 17:18:30 +0000488 int numParams = 0;
Ted Kremenekd437f232007-11-13 22:51:08 +0000489 bool hasParamDecls = D.ReadBool();
Argyrios Kyrtzidisdc5ddbf2008-11-07 14:22:23 +0000490 if (hasParamDecls)
491 numParams = D.ReadInt();
Ted Kremenekda256852007-11-16 18:11:10 +0000492
493 decl->ParamInfo = hasParamDecls
Argyrios Kyrtzidisdc5ddbf2008-11-07 14:22:23 +0000494 ? new ParmVarDecl*[numParams]
Ted Kremenekda256852007-11-16 18:11:10 +0000495 : NULL;
Ted Kremenekd437f232007-11-13 22:51:08 +0000496
497 if (hasParamDecls)
Argyrios Kyrtzidisdc5ddbf2008-11-07 14:22:23 +0000498 D.BatchReadOwnedPtrs(numParams,
Ted Kremenekd437f232007-11-13 22:51:08 +0000499 reinterpret_cast<Decl**>(&decl->ParamInfo[0]),
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000500 decl->Body, C);
Ted Kremenekd437f232007-11-13 22:51:08 +0000501 else
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000502 decl->Body = D.ReadOwnedPtr<Stmt>(C);
Ted Kremenek04973312007-11-02 18:05:11 +0000503
504 return decl;
505}
Ted Kremenekf7bf4112007-11-05 21:49:34 +0000506
Steve Naroff56ee6892008-10-08 17:01:13 +0000507void BlockDecl::EmitImpl(Serializer& S) const {
508 // FIXME: what about arguments?
509 S.Emit(getCaretLocation());
510 S.EmitOwnedPtr(Body);
511}
512
513BlockDecl* BlockDecl::CreateImpl(Deserializer& D, ASTContext& C) {
514 QualType Q = QualType::ReadVal(D);
515 SourceLocation L = SourceLocation::ReadVal(D);
516 /*CompoundStmt* BodyStmt = cast<CompoundStmt>(*/D.ReadOwnedPtr<Stmt>(C)/*)*/;
517 assert(0 && "Cannot deserialize BlockBlockExpr yet");
518 // FIXME: need to handle parameters.
519 //return new BlockBlockExpr(L, Q, BodyStmt);
520 return 0;
521}
522
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000523//===----------------------------------------------------------------------===//
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000524// OverloadedFunctionDecl Serialization.
525//===----------------------------------------------------------------------===//
526
527void OverloadedFunctionDecl::EmitImpl(Serializer& S) const {
528 NamedDecl::EmitInRec(S);
529
530 S.EmitInt(getNumFunctions());
531 for (unsigned func = 0; func < getNumFunctions(); ++func)
532 S.EmitPtr(Functions[func]);
533}
534
535OverloadedFunctionDecl *
536OverloadedFunctionDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000537 OverloadedFunctionDecl* decl = new (C)
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000538 OverloadedFunctionDecl(0, DeclarationName());
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000539
540 decl->NamedDecl::ReadInRec(D, C);
541
542 unsigned numFunctions = D.ReadInt();
543 decl->Functions.reserve(numFunctions);
544 for (unsigned func = 0; func < numFunctions; ++func)
545 D.ReadPtr(decl->Functions[func]);
546
547 return decl;
548}
549
550//===----------------------------------------------------------------------===//
Ted Kremenekaad48b62007-11-14 08:06:37 +0000551// RecordDecl Serialization.
552//===----------------------------------------------------------------------===//
553
Ted Kremenek583e0082007-11-14 18:12:19 +0000554void RecordDecl::EmitImpl(Serializer& S) const {
Argyrios Kyrtzidis35bc0822008-10-15 00:42:39 +0000555 S.EmitInt(getTagKind());
556
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000557 NamedDecl::EmitInRec(S);
Ted Kremenek583e0082007-11-14 18:12:19 +0000558 S.EmitBool(isDefinition());
Ted Kremenekaad48b62007-11-14 08:06:37 +0000559 S.EmitBool(hasFlexibleArrayMember());
Douglas Gregorbcbffc42009-01-07 00:43:41 +0000560 S.EmitBool(isAnonymousStructOrUnion());
Ted Kremenekaad48b62007-11-14 08:06:37 +0000561}
562
Argyrios Kyrtzidis35bc0822008-10-15 00:42:39 +0000563RecordDecl* RecordDecl::CreateImpl(Deserializer& D, ASTContext& C) {
564 TagKind TK = TagKind(D.ReadInt());
Sam Bishope2563ca2008-04-07 21:55:54 +0000565
Steve Naroff3e970492009-01-27 21:25:57 +0000566 RecordDecl* decl = new (C) RecordDecl(Record, TK, 0, SourceLocation(), NULL);
Ted Kremenek583e0082007-11-14 18:12:19 +0000567
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000568 decl->NamedDecl::ReadInRec(D, C);
Ted Kremenek583e0082007-11-14 18:12:19 +0000569 decl->setDefinition(D.ReadBool());
Ted Kremenekaad48b62007-11-14 08:06:37 +0000570 decl->setHasFlexibleArrayMember(D.ReadBool());
Douglas Gregorbcbffc42009-01-07 00:43:41 +0000571 decl->setAnonymousStructOrUnion(D.ReadBool());
Douglas Gregor44b43212008-12-11 16:49:14 +0000572
Ted Kremenekaad48b62007-11-14 08:06:37 +0000573 return decl;
574}
575
576//===----------------------------------------------------------------------===//
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000577// TypedefDecl Serialization.
578//===----------------------------------------------------------------------===//
579
580void TypedefDecl::EmitImpl(Serializer& S) const {
Ted Kremenek2ebc89f2007-11-06 19:51:47 +0000581 S.Emit(UnderlyingType);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000582 NamedDecl::EmitInRec(S);
Ted Kremenekf7bf4112007-11-05 21:49:34 +0000583}
584
Sam Bishope2563ca2008-04-07 21:55:54 +0000585TypedefDecl* TypedefDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000586 QualType T = QualType::ReadVal(D);
587
Steve Naroff3e970492009-01-27 21:25:57 +0000588 TypedefDecl* decl = new (C) TypedefDecl(0, SourceLocation(), NULL, T);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000589
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000590 decl->NamedDecl::ReadInRec(D, C);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000591
Ted Kremenekf7bf4112007-11-05 21:49:34 +0000592 return decl;
593}
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000594
595//===----------------------------------------------------------------------===//
Douglas Gregor72c3f312008-12-05 18:15:24 +0000596// TemplateTypeParmDecl Serialization.
597//===----------------------------------------------------------------------===//
598
599void TemplateTypeParmDecl::EmitImpl(Serializer& S) const {
600 S.EmitBool(Typename);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000601 NamedDecl::EmitInRec(S);
Douglas Gregor72c3f312008-12-05 18:15:24 +0000602}
603
604TemplateTypeParmDecl *
605TemplateTypeParmDecl::CreateImpl(Deserializer& D, ASTContext& C) {
606 bool Typename = D.ReadBool();
Douglas Gregor72c3f312008-12-05 18:15:24 +0000607 TemplateTypeParmDecl *decl
Steve Naroff3e970492009-01-27 21:25:57 +0000608 = new (C) TemplateTypeParmDecl(0, SourceLocation(), NULL, Typename);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000609 decl->NamedDecl::ReadInRec(D, C);
Douglas Gregor72c3f312008-12-05 18:15:24 +0000610 return decl;
611}
612
613//===----------------------------------------------------------------------===//
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000614// LinkageSpec Serialization.
615//===----------------------------------------------------------------------===//
616
617void LinkageSpecDecl::EmitInRec(Serializer& S) const {
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000618 S.EmitInt(getLanguage());
Douglas Gregorf44515a2008-12-16 22:23:02 +0000619 S.EmitBool(HadBraces);
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000620}
621
Sam Bishope2563ca2008-04-07 21:55:54 +0000622void LinkageSpecDecl::ReadInRec(Deserializer& D, ASTContext& C) {
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000623 Language = static_cast<LanguageIDs>(D.ReadInt());
Douglas Gregorf44515a2008-12-16 22:23:02 +0000624 HadBraces = D.ReadBool();
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000625}
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000626
627//===----------------------------------------------------------------------===//
628// FileScopeAsm Serialization.
629//===----------------------------------------------------------------------===//
630
631void FileScopeAsmDecl::EmitImpl(llvm::Serializer& S) const
632{
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000633 S.EmitOwnedPtr(AsmString);
634}
635
Sam Bishope2563ca2008-04-07 21:55:54 +0000636FileScopeAsmDecl* FileScopeAsmDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000637 FileScopeAsmDecl* decl = new (C) FileScopeAsmDecl(0, SourceLocation(), 0);
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000638
Sam Bishope2563ca2008-04-07 21:55:54 +0000639 decl->AsmString = cast<StringLiteral>(D.ReadOwnedPtr<Expr>(C));
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000640// D.ReadOwnedPtr(D.ReadOwnedPtr<StringLiteral>())<#T * * Ptr#>, <#bool AutoRegister#>)(decl->AsmString);
641
642 return decl;
643}