blob: 8e3ef08d2c8b8f8778286c4aa303cbbcceef410d [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"
Douglas Gregoraaba5e32009-02-04 19:02:06 +000017#include "clang/AST/DeclTemplate.h"
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +000018#include "clang/AST/Expr.h"
19#include "llvm/Bitcode/Serialize.h"
20#include "llvm/Bitcode/Deserialize.h"
21
Ted Kremenek928fd7f2007-11-13 00:15:39 +000022using llvm::Serializer;
23using llvm::Deserializer;
24using llvm::SerializedPtrID;
25
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +000026using namespace clang;
27
Ted Kremenek928fd7f2007-11-13 00:15:39 +000028//===----------------------------------------------------------------------===//
29// Decl Serialization: Dispatch code to handle specialized decl types.
30//===----------------------------------------------------------------------===//
Ted Kremenek8af8fe32007-11-05 21:38:00 +000031
Ted Kremenek928fd7f2007-11-13 00:15:39 +000032void Decl::Emit(Serializer& S) const {
33 S.EmitInt(getKind());
34 EmitImpl(S);
Douglas Gregor4afa39d2009-01-20 01:17:11 +000035 S.Emit(getLocation());
36 S.EmitBool(InvalidDecl);
37 // FIXME: HasAttrs?
38 S.EmitBool(Implicit);
39 S.EmitInt(Access);
40 S.EmitPtr(cast_or_null<Decl>(getDeclContext())); // From Decl.
41 S.EmitPtr(cast_or_null<Decl>(getLexicalDeclContext())); // From Decl.
42 S.EmitPtr(NextDeclarator);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000043 if (const DeclContext *DC = dyn_cast<const DeclContext>(this))
44 DC->EmitOutRec(S);
Douglas Gregor4afa39d2009-01-20 01:17:11 +000045
46 if (getDeclContext() &&
47 !getDeclContext()->isFunctionOrMethod()) {
48 S.EmitBool(true);
Chris Lattner244a67d2009-03-28 06:04:26 +000049 S.EmitOwnedPtr(NextDeclInContext);
Douglas Gregor4afa39d2009-01-20 01:17:11 +000050 } else {
51 S.EmitBool(false);
Chris Lattner244a67d2009-03-28 06:04:26 +000052 S.EmitPtr(NextDeclInContext);
Douglas Gregor4afa39d2009-01-20 01:17:11 +000053 }
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +000054}
55
Sam Bishope2563ca2008-04-07 21:55:54 +000056Decl* Decl::Create(Deserializer& D, ASTContext& C) {
Ted Kremenek928fd7f2007-11-13 00:15:39 +000057
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000058 Decl *Dcl;
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000059 Kind k = static_cast<Kind>(D.ReadInt());
Sam Bishope2563ca2008-04-07 21:55:54 +000060
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000061 switch (k) {
62 default:
63 assert (false && "Not implemented.");
Chris Lattner0ed844b2008-04-04 06:12:32 +000064
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +000065 case TranslationUnit:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000066 Dcl = TranslationUnitDecl::CreateImpl(D, C);
67 break;
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +000068
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +000069 case Namespace:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000070 Dcl = NamespaceDecl::CreateImpl(D, C);
71 break;
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +000072
Steve Naroff248a7532008-04-15 22:42:06 +000073 case Var:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000074 Dcl = VarDecl::CreateImpl(D, C);
75 break;
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000076
Ted Kremenek583e0082007-11-14 18:12:19 +000077 case Enum:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000078 Dcl = EnumDecl::CreateImpl(D, C);
79 break;
Ted Kremenek583e0082007-11-14 18:12:19 +000080
81 case EnumConstant:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000082 Dcl = EnumConstantDecl::CreateImpl(D, C);
83 break;
Ted Kremenek583e0082007-11-14 18:12:19 +000084
Ted Kremenekf9d56c82007-11-14 17:47:01 +000085 case Field:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000086 Dcl = FieldDecl::CreateImpl(D, C);
87 break;
Ted Kremenekf9d56c82007-11-14 17:47:01 +000088
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000089 case ParmVar:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000090 Dcl = ParmVarDecl::CreateImpl(D, C);
91 break;
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000092
Fariborz Jahanian73da9e42008-12-20 20:56:12 +000093 case OriginalParmVar:
Douglas Gregor64650af2009-02-02 23:39:07 +000094 Dcl = OriginalParmVarDecl::CreateImpl(D, C);
Fariborz Jahanian73da9e42008-12-20 20:56:12 +000095 break;
96
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000097 case Function:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000098 Dcl = FunctionDecl::CreateImpl(D, C);
99 break;
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000100
101 case OverloadedFunction:
102 Dcl = OverloadedFunctionDecl::CreateImpl(D, C);
103 break;
104
Argyrios Kyrtzidis35bc0822008-10-15 00:42:39 +0000105 case Record:
106 Dcl = RecordDecl::CreateImpl(D, C);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000107 break;
Ted Kremenekaad48b62007-11-14 08:06:37 +0000108
Ted Kremenek2ebc89f2007-11-06 19:51:47 +0000109 case Typedef:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000110 Dcl = TypedefDecl::CreateImpl(D, C);
111 break;
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000112
Douglas Gregor72c3f312008-12-05 18:15:24 +0000113 case TemplateTypeParm:
114 Dcl = TemplateTypeParmDecl::CreateImpl(D, C);
115 break;
116
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000117 case FileScopeAsm:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000118 Dcl = FileScopeAsmDecl::CreateImpl(D, C);
119 break;
Ted Kremenek2ebc89f2007-11-06 19:51:47 +0000120 }
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000121
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000122 Dcl->Loc = SourceLocation::ReadVal(D); // From Decl.
123 Dcl->InvalidDecl = D.ReadBool();
124 // FIXME: HasAttrs?
125 Dcl->Implicit = D.ReadBool();
126 Dcl->Access = D.ReadInt();
127
Chris Lattner10d83792009-03-27 18:46:15 +0000128 assert(Dcl->DeclCtx.getOpaqueValue() == 0);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000129
130 const SerializedPtrID &SemaDCPtrID = D.ReadPtrID();
131 const SerializedPtrID &LexicalDCPtrID = D.ReadPtrID();
132
133 if (SemaDCPtrID == LexicalDCPtrID) {
134 // Allow back-patching. Observe that we register the variable of the
135 // *object* for back-patching. Its actual value will get filled in later.
Chris Lattner10d83792009-03-27 18:46:15 +0000136 uintptr_t X;
137 D.ReadUIntPtr(X, SemaDCPtrID);
Chris Lattneree219fd2009-03-29 06:06:59 +0000138 Dcl->DeclCtx = reinterpret_cast<DeclContext*>(X);
139 } else {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000140 MultipleDC *MDC = new MultipleDC();
Chris Lattneree219fd2009-03-29 06:06:59 +0000141 Dcl->DeclCtx = MDC;
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000142 // Allow back-patching. Observe that we register the variable of the
143 // *object* for back-patching. Its actual value will get filled in later.
144 D.ReadPtr(MDC->SemanticDC, SemaDCPtrID);
145 D.ReadPtr(MDC->LexicalDC, LexicalDCPtrID);
146 }
147 D.ReadPtr(Dcl->NextDeclarator);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000148 if (DeclContext *DC = dyn_cast<DeclContext>(Dcl))
149 DC->ReadOutRec(D, C);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000150 bool OwnsNext = D.ReadBool();
151 if (OwnsNext)
Chris Lattner244a67d2009-03-28 06:04:26 +0000152 Dcl->NextDeclInContext = D.ReadOwnedPtr<Decl>(C);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000153 else
Chris Lattner244a67d2009-03-28 06:04:26 +0000154 D.ReadPtr(Dcl->NextDeclInContext);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000155 return Dcl;
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +0000156}
Ted Kremenek04973312007-11-02 18:05:11 +0000157
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000158//===----------------------------------------------------------------------===//
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000159// Common serialization logic for subclasses of DeclContext.
160//===----------------------------------------------------------------------===//
161
162void DeclContext::EmitOutRec(Serializer& S) const {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000163 bool Owned = !isFunctionOrMethod();
164 S.EmitBool(Owned);
165 if (Owned)
166 S.EmitOwnedPtr(FirstDecl);
167 else
168 S.EmitPtr(FirstDecl);
169 S.EmitPtr(LastDecl);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000170}
171
172void DeclContext::ReadOutRec(Deserializer& D, ASTContext& C) {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000173 bool Owned = D.ReadBool();
174 if (Owned)
175 FirstDecl = cast_or_null<Decl>(D.ReadOwnedPtr<Decl>(C));
176 else
177 D.ReadPtr(FirstDecl);
178 D.ReadPtr(LastDecl);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000179}
180
181//===----------------------------------------------------------------------===//
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000182// Common serialization logic for subclasses of NamedDecl.
183//===----------------------------------------------------------------------===//
184
185void NamedDecl::EmitInRec(Serializer& S) const {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000186 S.EmitInt(Name.getNameKind());
187
188 switch (Name.getNameKind()) {
189 case DeclarationName::Identifier:
190 S.EmitPtr(Name.getAsIdentifierInfo());
191 break;
192
193 case DeclarationName::ObjCZeroArgSelector:
194 case DeclarationName::ObjCOneArgSelector:
195 case DeclarationName::ObjCMultiArgSelector:
196 Name.getObjCSelector().Emit(S);
197 break;
198
199 case DeclarationName::CXXConstructorName:
200 case DeclarationName::CXXDestructorName:
201 case DeclarationName::CXXConversionFunctionName:
202 Name.getCXXNameType().Emit(S);
203 break;
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000204
205 case DeclarationName::CXXOperatorName:
206 S.EmitInt(Name.getCXXOverloadedOperator());
207 break;
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000208
209 case DeclarationName::CXXUsingDirective:
210 // No extra data to emit
211 break;
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000212 }
Ted Kremenek04973312007-11-02 18:05:11 +0000213}
214
Sam Bishope2563ca2008-04-07 21:55:54 +0000215void NamedDecl::ReadInRec(Deserializer& D, ASTContext& C) {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000216 DeclarationName::NameKind Kind
217 = static_cast<DeclarationName::NameKind>(D.ReadInt());
218 switch (Kind) {
219 case DeclarationName::Identifier: {
Ted Kremenekddf32da2009-01-21 00:42:24 +0000220 // Don't allow back-patching. The IdentifierInfo table must already
221 // be loaded.
222 Name = D.ReadPtr<IdentifierInfo>();
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000223 break;
224 }
225
226 case DeclarationName::ObjCZeroArgSelector:
227 case DeclarationName::ObjCOneArgSelector:
228 case DeclarationName::ObjCMultiArgSelector:
229 Name = Selector::ReadVal(D);
230 break;
231
232 case DeclarationName::CXXConstructorName:
233 Name = C.DeclarationNames.getCXXConstructorName(QualType::ReadVal(D));
234 break;
235
236 case DeclarationName::CXXDestructorName:
237 Name = C.DeclarationNames.getCXXDestructorName(QualType::ReadVal(D));
238 break;
239
240 case DeclarationName::CXXConversionFunctionName:
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000241 Name
242 = C.DeclarationNames.getCXXConversionFunctionName(QualType::ReadVal(D));
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000243 break;
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000244
245 case DeclarationName::CXXOperatorName: {
246 OverloadedOperatorKind Op
247 = static_cast<OverloadedOperatorKind>(D.ReadInt());
248 Name = C.DeclarationNames.getCXXOperatorName(Op);
249 break;
250 }
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000251
252 case DeclarationName::CXXUsingDirective:
253 Name = DeclarationName::getUsingDirectiveName();
254 break;
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000255 }
Ted Kremenek04973312007-11-02 18:05:11 +0000256}
257
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000258//===----------------------------------------------------------------------===//
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000259// Common serialization logic for subclasses of ValueDecl.
260//===----------------------------------------------------------------------===//
261
262void ValueDecl::EmitInRec(Serializer& S) const {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000263 NamedDecl::EmitInRec(S);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000264 S.Emit(getType()); // From ValueDecl.
265}
266
Sam Bishope2563ca2008-04-07 21:55:54 +0000267void ValueDecl::ReadInRec(Deserializer& D, ASTContext& C) {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000268 NamedDecl::ReadInRec(D, C);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000269 DeclType = QualType::ReadVal(D); // From ValueDecl.
270}
271
272//===----------------------------------------------------------------------===//
273// Common serialization logic for subclasses of VarDecl.
274//===----------------------------------------------------------------------===//
275
276void VarDecl::EmitInRec(Serializer& S) const {
277 ValueDecl::EmitInRec(S);
278 S.EmitInt(getStorageClass()); // From VarDecl.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000279}
280
Sam Bishope2563ca2008-04-07 21:55:54 +0000281void VarDecl::ReadInRec(Deserializer& D, ASTContext& C) {
282 ValueDecl::ReadInRec(D, C);
Fariborz Jahaniande7b4cd2007-12-13 00:54:18 +0000283 SClass = static_cast<StorageClass>(D.ReadInt()); // From VarDecl.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000284}
285
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000286void VarDecl::EmitOutRec(Serializer& S) const {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000287 // Emit this last because it will create a record of its own.
288 S.EmitOwnedPtr(getInit());
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000289}
290
Sam Bishope2563ca2008-04-07 21:55:54 +0000291void VarDecl::ReadOutRec(Deserializer& D, ASTContext& C) {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000292 Init = D.ReadOwnedPtr<Stmt>(C);
Ted Kremenek04973312007-11-02 18:05:11 +0000293}
294
295
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000296void VarDecl::EmitImpl(Serializer& S) const {
297 VarDecl::EmitInRec(S);
298 VarDecl::EmitOutRec(S);
Ted Kremenek04973312007-11-02 18:05:11 +0000299}
300
Sam Bishope2563ca2008-04-07 21:55:54 +0000301void VarDecl::ReadImpl(Deserializer& D, ASTContext& C) {
302 ReadInRec(D, C);
303 ReadOutRec(D, C);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000304}
305
306//===----------------------------------------------------------------------===//
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000307// TranslationUnitDecl Serialization.
308//===----------------------------------------------------------------------===//
309
310void TranslationUnitDecl::EmitImpl(llvm::Serializer& S) const
311{
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000312}
313
314TranslationUnitDecl* TranslationUnitDecl::CreateImpl(Deserializer& D,
315 ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000316 return new (C) TranslationUnitDecl();
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000317}
318
319//===----------------------------------------------------------------------===//
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000320// NamespaceDecl Serialization.
321//===----------------------------------------------------------------------===//
322
323void NamespaceDecl::EmitImpl(llvm::Serializer& S) const
324{
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000325 NamedDecl::EmitInRec(S);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000326 S.Emit(getLBracLoc());
327 S.Emit(getRBracLoc());
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000328}
329
330NamespaceDecl* NamespaceDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000331 NamespaceDecl* decl = new (C) NamespaceDecl(0, SourceLocation(), 0);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000332
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000333 decl->NamedDecl::ReadInRec(D, C);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000334 decl->LBracLoc = SourceLocation::ReadVal(D);
335 decl->RBracLoc = SourceLocation::ReadVal(D);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000336
337 return decl;
338}
339
340//===----------------------------------------------------------------------===//
Steve Naroff248a7532008-04-15 22:42:06 +0000341// VarDecl Serialization.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000342//===----------------------------------------------------------------------===//
343
Steve Naroff248a7532008-04-15 22:42:06 +0000344VarDecl* VarDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff248a7532008-04-15 22:42:06 +0000345 VarDecl* decl =
Steve Naroff3e970492009-01-27 21:25:57 +0000346 new (C) VarDecl(Var, 0, SourceLocation(), NULL, QualType(), None);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000347
Sam Bishope2563ca2008-04-07 21:55:54 +0000348 decl->VarDecl::ReadImpl(D, C);
Ted Kremenek04973312007-11-02 18:05:11 +0000349 return decl;
350}
351
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000352//===----------------------------------------------------------------------===//
Steve Naroff248a7532008-04-15 22:42:06 +0000353// ParmVarDecl Serialization.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000354//===----------------------------------------------------------------------===//
Ted Kremenek04973312007-11-02 18:05:11 +0000355
Ted Kremenek137bd912007-12-13 06:28:13 +0000356void ParmVarDecl::EmitImpl(llvm::Serializer& S) const {
357 VarDecl::EmitImpl(S);
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000358 S.EmitInt(getObjCDeclQualifier()); // From ParmVarDecl.
Chris Lattner04421082008-04-08 04:40:51 +0000359 S.EmitOwnedPtr(getDefaultArg()); // From ParmVarDecl.
Ted Kremenek137bd912007-12-13 06:28:13 +0000360}
361
Sam Bishope2563ca2008-04-07 21:55:54 +0000362ParmVarDecl* ParmVarDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000363 ParmVarDecl* decl = new (C)
Fariborz Jahanian4306d3c2008-12-20 23:29:59 +0000364 ParmVarDecl(ParmVar,
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000365 0, SourceLocation(), NULL, QualType(), None, NULL);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000366
Sam Bishope2563ca2008-04-07 21:55:54 +0000367 decl->VarDecl::ReadImpl(D, C);
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000368 decl->objcDeclQualifier = static_cast<ObjCDeclQualifier>(D.ReadInt());
Chris Lattner04421082008-04-08 04:40:51 +0000369 decl->DefaultArg = D.ReadOwnedPtr<Expr>(C);
Ted Kremenek04973312007-11-02 18:05:11 +0000370 return decl;
371}
372
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000373//===----------------------------------------------------------------------===//
Douglas Gregor64650af2009-02-02 23:39:07 +0000374// OriginalParmVarDecl Serialization.
Fariborz Jahanian73da9e42008-12-20 20:56:12 +0000375//===----------------------------------------------------------------------===//
376
Douglas Gregor64650af2009-02-02 23:39:07 +0000377void OriginalParmVarDecl::EmitImpl(llvm::Serializer& S) const {
Fariborz Jahanian73da9e42008-12-20 20:56:12 +0000378 ParmVarDecl::EmitImpl(S);
379 S.Emit(OriginalType);
380}
381
Douglas Gregor64650af2009-02-02 23:39:07 +0000382OriginalParmVarDecl* OriginalParmVarDecl::CreateImpl(
Fariborz Jahanian73da9e42008-12-20 20:56:12 +0000383 Deserializer& D, ASTContext& C) {
Douglas Gregor64650af2009-02-02 23:39:07 +0000384 OriginalParmVarDecl* decl = new (C)
385 OriginalParmVarDecl(0, SourceLocation(), NULL, QualType(),
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000386 QualType(), None, NULL);
Fariborz Jahanian73da9e42008-12-20 20:56:12 +0000387
388 decl->ParmVarDecl::ReadImpl(D, C);
389 decl->OriginalType = QualType::ReadVal(D);
390 return decl;
391}
392//===----------------------------------------------------------------------===//
Ted Kremenek583e0082007-11-14 18:12:19 +0000393// EnumDecl Serialization.
394//===----------------------------------------------------------------------===//
395
396void EnumDecl::EmitImpl(Serializer& S) const {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000397 NamedDecl::EmitInRec(S);
Ted Kremenek583e0082007-11-14 18:12:19 +0000398 S.EmitBool(isDefinition());
Douglas Gregor44b43212008-12-11 16:49:14 +0000399 S.Emit(IntegerType);
Ted Kremenek583e0082007-11-14 18:12:19 +0000400}
401
Sam Bishope2563ca2008-04-07 21:55:54 +0000402EnumDecl* EnumDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000403 EnumDecl* decl = new (C) EnumDecl(0, SourceLocation(), NULL);
Ted Kremenek583e0082007-11-14 18:12:19 +0000404
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000405 decl->NamedDecl::ReadInRec(D, C);
Ted Kremenek583e0082007-11-14 18:12:19 +0000406 decl->setDefinition(D.ReadBool());
407 decl->IntegerType = QualType::ReadVal(D);
408
Ted Kremenek583e0082007-11-14 18:12:19 +0000409 return decl;
410}
411
412//===----------------------------------------------------------------------===//
413// EnumConstantDecl Serialization.
414//===----------------------------------------------------------------------===//
415
416void EnumConstantDecl::EmitImpl(Serializer& S) const {
417 S.Emit(Val);
418 ValueDecl::EmitInRec(S);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000419 S.EmitOwnedPtr(Init);
Ted Kremenek583e0082007-11-14 18:12:19 +0000420}
421
Sam Bishope2563ca2008-04-07 21:55:54 +0000422EnumConstantDecl* EnumConstantDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Ted Kremenek049b1682007-11-14 23:38:09 +0000423 llvm::APSInt val(1);
Ted Kremenek583e0082007-11-14 18:12:19 +0000424 D.Read(val);
425
Steve Naroff3e970492009-01-27 21:25:57 +0000426 EnumConstantDecl* decl = new (C)
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000427 EnumConstantDecl(0, SourceLocation(), NULL, QualType(), NULL, val);
Ted Kremenek583e0082007-11-14 18:12:19 +0000428
Sam Bishope2563ca2008-04-07 21:55:54 +0000429 decl->ValueDecl::ReadInRec(D, C);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000430 decl->Init = D.ReadOwnedPtr<Stmt>(C);
Ted Kremenek583e0082007-11-14 18:12:19 +0000431 return decl;
432}
433
434//===----------------------------------------------------------------------===//
Ted Kremenekf9d56c82007-11-14 17:47:01 +0000435// FieldDecl Serialization.
436//===----------------------------------------------------------------------===//
437
438void FieldDecl::EmitImpl(Serializer& S) const {
Douglas Gregor44b43212008-12-11 16:49:14 +0000439 S.EmitBool(Mutable);
Ted Kremenekf9d56c82007-11-14 17:47:01 +0000440 S.Emit(getType());
Mike Stump080cc352009-02-10 20:06:48 +0000441 ValueDecl::EmitInRec(S);
Ted Kremenekf9d56c82007-11-14 17:47:01 +0000442 S.EmitOwnedPtr(BitWidth);
443}
444
Sam Bishope2563ca2008-04-07 21:55:54 +0000445FieldDecl* FieldDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000446 FieldDecl* decl = new (C) 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();
Mike Stump080cc352009-02-10 20:06:48 +0000449 decl->ValueDecl::ReadInRec(D, C);
Sam Bishope2563ca2008-04-07 21:55:54 +0000450 decl->BitWidth = D.ReadOwnedPtr<Expr>(C);
Ted Kremenekf9d56c82007-11-14 17:47:01 +0000451 return decl;
452}
453
454//===----------------------------------------------------------------------===//
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000455// FunctionDecl Serialization.
456//===----------------------------------------------------------------------===//
Ted Kremenek04973312007-11-02 18:05:11 +0000457
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000458void FunctionDecl::EmitImpl(Serializer& S) const {
459 S.EmitInt(SClass); // From FunctionDecl.
460 S.EmitBool(IsInline); // From FunctionDecl.
461 ValueDecl::EmitInRec(S);
Ted Kremenek3bbc1982008-05-20 03:33:58 +0000462 S.EmitPtr(PreviousDeclaration);
Ted Kremenek04973312007-11-02 18:05:11 +0000463
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000464 // NOTE: We do not need to serialize out the number of parameters, because
465 // that is encoded in the type (accessed via getNumParams()).
Ted Kremenek04973312007-11-02 18:05:11 +0000466
Ted Kremenekd437f232007-11-13 22:51:08 +0000467 if (ParamInfo != NULL) {
468 S.EmitBool(true);
Argyrios Kyrtzidisdc5ddbf2008-11-07 14:22:23 +0000469 S.EmitInt(getNumParams());
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000470 S.BatchEmitOwnedPtrs(getNumParams(),&ParamInfo[0], Body);
Ted Kremenekd437f232007-11-13 22:51:08 +0000471 }
472 else {
473 S.EmitBool(false);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000474 S.EmitOwnedPtr(Body);
Ted Kremenekd437f232007-11-13 22:51:08 +0000475 }
Ted Kremenek04973312007-11-02 18:05:11 +0000476}
477
Sam Bishope2563ca2008-04-07 21:55:54 +0000478FunctionDecl* FunctionDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Ted Kremenek04973312007-11-02 18:05:11 +0000479 StorageClass SClass = static_cast<StorageClass>(D.ReadInt());
480 bool IsInline = D.ReadBool();
Ted Kremenek04973312007-11-02 18:05:11 +0000481
Steve Naroff3e970492009-01-27 21:25:57 +0000482 FunctionDecl* decl = new (C)
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000483 FunctionDecl(Function, 0, SourceLocation(), DeclarationName(),
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000484 QualType(), SClass, IsInline);
Ted Kremenek04973312007-11-02 18:05:11 +0000485
Sam Bishope2563ca2008-04-07 21:55:54 +0000486 decl->ValueDecl::ReadInRec(D, C);
Ted Kremenek3bbc1982008-05-20 03:33:58 +0000487 D.ReadPtr(decl->PreviousDeclaration);
Ted Kremenekda256852007-11-16 18:11:10 +0000488
Douglas Gregor6b54bd12009-01-05 17:18:30 +0000489 int numParams = 0;
Ted Kremenekd437f232007-11-13 22:51:08 +0000490 bool hasParamDecls = D.ReadBool();
Argyrios Kyrtzidisdc5ddbf2008-11-07 14:22:23 +0000491 if (hasParamDecls)
492 numParams = D.ReadInt();
Ted Kremenekda256852007-11-16 18:11:10 +0000493
494 decl->ParamInfo = hasParamDecls
Argyrios Kyrtzidisdc5ddbf2008-11-07 14:22:23 +0000495 ? new ParmVarDecl*[numParams]
Ted Kremenekda256852007-11-16 18:11:10 +0000496 : NULL;
Ted Kremenekd437f232007-11-13 22:51:08 +0000497
498 if (hasParamDecls)
Argyrios Kyrtzidisdc5ddbf2008-11-07 14:22:23 +0000499 D.BatchReadOwnedPtrs(numParams,
Ted Kremenekd437f232007-11-13 22:51:08 +0000500 reinterpret_cast<Decl**>(&decl->ParamInfo[0]),
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000501 decl->Body, C);
Ted Kremenekd437f232007-11-13 22:51:08 +0000502 else
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000503 decl->Body = D.ReadOwnedPtr<Stmt>(C);
Ted Kremenek04973312007-11-02 18:05:11 +0000504
505 return decl;
506}
Ted Kremenekf7bf4112007-11-05 21:49:34 +0000507
Steve Naroff56ee6892008-10-08 17:01:13 +0000508void BlockDecl::EmitImpl(Serializer& S) const {
509 // FIXME: what about arguments?
510 S.Emit(getCaretLocation());
511 S.EmitOwnedPtr(Body);
512}
513
514BlockDecl* BlockDecl::CreateImpl(Deserializer& D, ASTContext& C) {
515 QualType Q = QualType::ReadVal(D);
516 SourceLocation L = SourceLocation::ReadVal(D);
517 /*CompoundStmt* BodyStmt = cast<CompoundStmt>(*/D.ReadOwnedPtr<Stmt>(C)/*)*/;
518 assert(0 && "Cannot deserialize BlockBlockExpr yet");
519 // FIXME: need to handle parameters.
520 //return new BlockBlockExpr(L, Q, BodyStmt);
521 return 0;
522}
523
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000524//===----------------------------------------------------------------------===//
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000525// OverloadedFunctionDecl Serialization.
526//===----------------------------------------------------------------------===//
527
528void OverloadedFunctionDecl::EmitImpl(Serializer& S) const {
529 NamedDecl::EmitInRec(S);
530
531 S.EmitInt(getNumFunctions());
532 for (unsigned func = 0; func < getNumFunctions(); ++func)
533 S.EmitPtr(Functions[func]);
534}
535
536OverloadedFunctionDecl *
537OverloadedFunctionDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000538 OverloadedFunctionDecl* decl = new (C)
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000539 OverloadedFunctionDecl(0, DeclarationName());
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000540
541 decl->NamedDecl::ReadInRec(D, C);
542
543 unsigned numFunctions = D.ReadInt();
544 decl->Functions.reserve(numFunctions);
545 for (unsigned func = 0; func < numFunctions; ++func)
546 D.ReadPtr(decl->Functions[func]);
547
548 return decl;
549}
550
551//===----------------------------------------------------------------------===//
Ted Kremenekaad48b62007-11-14 08:06:37 +0000552// RecordDecl Serialization.
553//===----------------------------------------------------------------------===//
554
Ted Kremenek583e0082007-11-14 18:12:19 +0000555void RecordDecl::EmitImpl(Serializer& S) const {
Argyrios Kyrtzidis35bc0822008-10-15 00:42:39 +0000556 S.EmitInt(getTagKind());
557
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000558 NamedDecl::EmitInRec(S);
Ted Kremenek583e0082007-11-14 18:12:19 +0000559 S.EmitBool(isDefinition());
Ted Kremenekaad48b62007-11-14 08:06:37 +0000560 S.EmitBool(hasFlexibleArrayMember());
Douglas Gregorbcbffc42009-01-07 00:43:41 +0000561 S.EmitBool(isAnonymousStructOrUnion());
Ted Kremenekaad48b62007-11-14 08:06:37 +0000562}
563
Argyrios Kyrtzidis35bc0822008-10-15 00:42:39 +0000564RecordDecl* RecordDecl::CreateImpl(Deserializer& D, ASTContext& C) {
565 TagKind TK = TagKind(D.ReadInt());
Sam Bishope2563ca2008-04-07 21:55:54 +0000566
Steve Naroff3e970492009-01-27 21:25:57 +0000567 RecordDecl* decl = new (C) RecordDecl(Record, TK, 0, SourceLocation(), NULL);
Ted Kremenek583e0082007-11-14 18:12:19 +0000568
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000569 decl->NamedDecl::ReadInRec(D, C);
Ted Kremenek583e0082007-11-14 18:12:19 +0000570 decl->setDefinition(D.ReadBool());
Ted Kremenekaad48b62007-11-14 08:06:37 +0000571 decl->setHasFlexibleArrayMember(D.ReadBool());
Douglas Gregorbcbffc42009-01-07 00:43:41 +0000572 decl->setAnonymousStructOrUnion(D.ReadBool());
Douglas Gregor44b43212008-12-11 16:49:14 +0000573
Ted Kremenekaad48b62007-11-14 08:06:37 +0000574 return decl;
575}
576
577//===----------------------------------------------------------------------===//
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000578// TypedefDecl Serialization.
579//===----------------------------------------------------------------------===//
580
581void TypedefDecl::EmitImpl(Serializer& S) const {
Ted Kremenek2ebc89f2007-11-06 19:51:47 +0000582 S.Emit(UnderlyingType);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000583 NamedDecl::EmitInRec(S);
Ted Kremenekf7bf4112007-11-05 21:49:34 +0000584}
585
Sam Bishope2563ca2008-04-07 21:55:54 +0000586TypedefDecl* TypedefDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000587 QualType T = QualType::ReadVal(D);
588
Steve Naroff3e970492009-01-27 21:25:57 +0000589 TypedefDecl* decl = new (C) TypedefDecl(0, SourceLocation(), NULL, T);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000590
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000591 decl->NamedDecl::ReadInRec(D, C);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000592
Ted Kremenekf7bf4112007-11-05 21:49:34 +0000593 return decl;
594}
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000595
596//===----------------------------------------------------------------------===//
Douglas Gregor72c3f312008-12-05 18:15:24 +0000597// TemplateTypeParmDecl Serialization.
598//===----------------------------------------------------------------------===//
599
600void TemplateTypeParmDecl::EmitImpl(Serializer& S) const {
601 S.EmitBool(Typename);
Douglas Gregorfab9d672009-02-05 23:33:38 +0000602 TypeDecl::EmitInRec(S);
Douglas Gregor72c3f312008-12-05 18:15:24 +0000603}
604
605TemplateTypeParmDecl *
606TemplateTypeParmDecl::CreateImpl(Deserializer& D, ASTContext& C) {
607 bool Typename = D.ReadBool();
Douglas Gregor72c3f312008-12-05 18:15:24 +0000608 TemplateTypeParmDecl *decl
Douglas Gregorfab9d672009-02-05 23:33:38 +0000609 = new (C) TemplateTypeParmDecl(0, SourceLocation(), 0, Typename,
610 QualType());
611 decl->TypeDecl::ReadInRec(D, C);
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000612 return decl;
613}
614
615//===----------------------------------------------------------------------===//
616// NonTypeTemplateParmDecl Serialization.
617//===----------------------------------------------------------------------===//
618void NonTypeTemplateParmDecl::EmitImpl(Serializer& S) const {
619 S.EmitInt(Depth);
620 S.EmitInt(Position);
621 NamedDecl::Emit(S);
622}
623
624NonTypeTemplateParmDecl*
625NonTypeTemplateParmDecl::CreateImpl(Deserializer& D, ASTContext& C) {
626 unsigned Depth = D.ReadInt();
627 unsigned Position = D.ReadInt();
628 NonTypeTemplateParmDecl *decl
629 = new (C) NonTypeTemplateParmDecl(0, SourceLocation(), Depth, Position,
630 0, QualType(), SourceLocation());
631 decl->NamedDecl::ReadInRec(D, C);
632 return decl;
633}
634
635//===----------------------------------------------------------------------===//
636// TemplateTemplateParmDecl Serialization.
637//===----------------------------------------------------------------------===//
638void TemplateTemplateParmDecl::EmitImpl(Serializer& S) const {
639 S.EmitInt(Depth);
640 S.EmitInt(Position);
641 NamedDecl::EmitInRec(S);
642}
643
644TemplateTemplateParmDecl*
645TemplateTemplateParmDecl::CreateImpl(Deserializer& D, ASTContext& C) {
646 unsigned Depth = D.ReadInt();
647 unsigned Position = D.ReadInt();
648 TemplateTemplateParmDecl *decl
649 = new (C) TemplateTemplateParmDecl(0, SourceLocation(), Depth, Position,
650 0, 0);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000651 decl->NamedDecl::ReadInRec(D, C);
Douglas Gregor72c3f312008-12-05 18:15:24 +0000652 return decl;
653}
654
655//===----------------------------------------------------------------------===//
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000656// LinkageSpec Serialization.
657//===----------------------------------------------------------------------===//
658
659void LinkageSpecDecl::EmitInRec(Serializer& S) const {
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000660 S.EmitInt(getLanguage());
Douglas Gregorf44515a2008-12-16 22:23:02 +0000661 S.EmitBool(HadBraces);
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000662}
663
Sam Bishope2563ca2008-04-07 21:55:54 +0000664void LinkageSpecDecl::ReadInRec(Deserializer& D, ASTContext& C) {
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000665 Language = static_cast<LanguageIDs>(D.ReadInt());
Douglas Gregorf44515a2008-12-16 22:23:02 +0000666 HadBraces = D.ReadBool();
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000667}
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000668
669//===----------------------------------------------------------------------===//
670// FileScopeAsm Serialization.
671//===----------------------------------------------------------------------===//
672
673void FileScopeAsmDecl::EmitImpl(llvm::Serializer& S) const
674{
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000675 S.EmitOwnedPtr(AsmString);
676}
677
Sam Bishope2563ca2008-04-07 21:55:54 +0000678FileScopeAsmDecl* FileScopeAsmDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000679 FileScopeAsmDecl* decl = new (C) FileScopeAsmDecl(0, SourceLocation(), 0);
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000680
Sam Bishope2563ca2008-04-07 21:55:54 +0000681 decl->AsmString = cast<StringLiteral>(D.ReadOwnedPtr<Expr>(C));
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000682// D.ReadOwnedPtr(D.ReadOwnedPtr<StringLiteral>())<#T * * Ptr#>, <#bool AutoRegister#>)(decl->AsmString);
683
684 return decl;
685}