blob: e4534a26865e985e4b00c9fd34f4c6882ce162a1 [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);
49 S.EmitOwnedPtr(NextDeclInScope);
50 } else {
51 S.EmitBool(false);
52 S.EmitPtr(NextDeclInScope);
53 }
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
128 assert(Dcl->DeclCtx == 0);
129
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.
136 D.ReadUIntPtr(Dcl->DeclCtx, SemaDCPtrID);
137 }
138 else {
139 MultipleDC *MDC = new MultipleDC();
140 Dcl->DeclCtx = reinterpret_cast<uintptr_t>(MDC) | 0x1;
141 // Allow back-patching. Observe that we register the variable of the
142 // *object* for back-patching. Its actual value will get filled in later.
143 D.ReadPtr(MDC->SemanticDC, SemaDCPtrID);
144 D.ReadPtr(MDC->LexicalDC, LexicalDCPtrID);
145 }
146 D.ReadPtr(Dcl->NextDeclarator);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000147 if (DeclContext *DC = dyn_cast<DeclContext>(Dcl))
148 DC->ReadOutRec(D, C);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000149 bool OwnsNext = D.ReadBool();
150 if (OwnsNext)
151 Dcl->NextDeclInScope = D.ReadOwnedPtr<Decl>(C);
152 else
153 D.ReadPtr(Dcl->NextDeclInScope);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000154 return Dcl;
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +0000155}
Ted Kremenek04973312007-11-02 18:05:11 +0000156
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000157//===----------------------------------------------------------------------===//
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000158// Common serialization logic for subclasses of DeclContext.
159//===----------------------------------------------------------------------===//
160
161void DeclContext::EmitOutRec(Serializer& S) const {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000162 bool Owned = !isFunctionOrMethod();
163 S.EmitBool(Owned);
164 if (Owned)
165 S.EmitOwnedPtr(FirstDecl);
166 else
167 S.EmitPtr(FirstDecl);
168 S.EmitPtr(LastDecl);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000169}
170
171void DeclContext::ReadOutRec(Deserializer& D, ASTContext& C) {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000172 bool Owned = D.ReadBool();
173 if (Owned)
174 FirstDecl = cast_or_null<Decl>(D.ReadOwnedPtr<Decl>(C));
175 else
176 D.ReadPtr(FirstDecl);
177 D.ReadPtr(LastDecl);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000178}
179
180//===----------------------------------------------------------------------===//
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000181// Common serialization logic for subclasses of NamedDecl.
182//===----------------------------------------------------------------------===//
183
184void NamedDecl::EmitInRec(Serializer& S) const {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000185 S.EmitInt(Name.getNameKind());
186
187 switch (Name.getNameKind()) {
188 case DeclarationName::Identifier:
189 S.EmitPtr(Name.getAsIdentifierInfo());
190 break;
191
192 case DeclarationName::ObjCZeroArgSelector:
193 case DeclarationName::ObjCOneArgSelector:
194 case DeclarationName::ObjCMultiArgSelector:
195 Name.getObjCSelector().Emit(S);
196 break;
197
198 case DeclarationName::CXXConstructorName:
199 case DeclarationName::CXXDestructorName:
200 case DeclarationName::CXXConversionFunctionName:
201 Name.getCXXNameType().Emit(S);
202 break;
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000203
204 case DeclarationName::CXXOperatorName:
205 S.EmitInt(Name.getCXXOverloadedOperator());
206 break;
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000207
208 case DeclarationName::CXXUsingDirective:
209 // No extra data to emit
210 break;
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000211 }
Ted Kremenek04973312007-11-02 18:05:11 +0000212}
213
Sam Bishope2563ca2008-04-07 21:55:54 +0000214void NamedDecl::ReadInRec(Deserializer& D, ASTContext& C) {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000215 DeclarationName::NameKind Kind
216 = static_cast<DeclarationName::NameKind>(D.ReadInt());
217 switch (Kind) {
218 case DeclarationName::Identifier: {
Ted Kremenekddf32da2009-01-21 00:42:24 +0000219 // Don't allow back-patching. The IdentifierInfo table must already
220 // be loaded.
221 Name = D.ReadPtr<IdentifierInfo>();
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000222 break;
223 }
224
225 case DeclarationName::ObjCZeroArgSelector:
226 case DeclarationName::ObjCOneArgSelector:
227 case DeclarationName::ObjCMultiArgSelector:
228 Name = Selector::ReadVal(D);
229 break;
230
231 case DeclarationName::CXXConstructorName:
232 Name = C.DeclarationNames.getCXXConstructorName(QualType::ReadVal(D));
233 break;
234
235 case DeclarationName::CXXDestructorName:
236 Name = C.DeclarationNames.getCXXDestructorName(QualType::ReadVal(D));
237 break;
238
239 case DeclarationName::CXXConversionFunctionName:
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000240 Name
241 = C.DeclarationNames.getCXXConversionFunctionName(QualType::ReadVal(D));
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000242 break;
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000243
244 case DeclarationName::CXXOperatorName: {
245 OverloadedOperatorKind Op
246 = static_cast<OverloadedOperatorKind>(D.ReadInt());
247 Name = C.DeclarationNames.getCXXOperatorName(Op);
248 break;
249 }
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000250
251 case DeclarationName::CXXUsingDirective:
252 Name = DeclarationName::getUsingDirectiveName();
253 break;
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000254 }
Ted Kremenek04973312007-11-02 18:05:11 +0000255}
256
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000257//===----------------------------------------------------------------------===//
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000258// Common serialization logic for subclasses of ValueDecl.
259//===----------------------------------------------------------------------===//
260
261void ValueDecl::EmitInRec(Serializer& S) const {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000262 NamedDecl::EmitInRec(S);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000263 S.Emit(getType()); // From ValueDecl.
264}
265
Sam Bishope2563ca2008-04-07 21:55:54 +0000266void ValueDecl::ReadInRec(Deserializer& D, ASTContext& C) {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000267 NamedDecl::ReadInRec(D, C);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000268 DeclType = QualType::ReadVal(D); // From ValueDecl.
269}
270
271//===----------------------------------------------------------------------===//
272// Common serialization logic for subclasses of VarDecl.
273//===----------------------------------------------------------------------===//
274
275void VarDecl::EmitInRec(Serializer& S) const {
276 ValueDecl::EmitInRec(S);
277 S.EmitInt(getStorageClass()); // From VarDecl.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000278}
279
Sam Bishope2563ca2008-04-07 21:55:54 +0000280void VarDecl::ReadInRec(Deserializer& D, ASTContext& C) {
281 ValueDecl::ReadInRec(D, C);
Fariborz Jahaniande7b4cd2007-12-13 00:54:18 +0000282 SClass = static_cast<StorageClass>(D.ReadInt()); // From VarDecl.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000283}
284
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000285void VarDecl::EmitOutRec(Serializer& S) const {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000286 // Emit this last because it will create a record of its own.
287 S.EmitOwnedPtr(getInit());
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000288}
289
Sam Bishope2563ca2008-04-07 21:55:54 +0000290void VarDecl::ReadOutRec(Deserializer& D, ASTContext& C) {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000291 Init = D.ReadOwnedPtr<Stmt>(C);
Ted Kremenek04973312007-11-02 18:05:11 +0000292}
293
294
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000295void VarDecl::EmitImpl(Serializer& S) const {
296 VarDecl::EmitInRec(S);
297 VarDecl::EmitOutRec(S);
Ted Kremenek04973312007-11-02 18:05:11 +0000298}
299
Sam Bishope2563ca2008-04-07 21:55:54 +0000300void VarDecl::ReadImpl(Deserializer& D, ASTContext& C) {
301 ReadInRec(D, C);
302 ReadOutRec(D, C);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000303}
304
305//===----------------------------------------------------------------------===//
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000306// TranslationUnitDecl Serialization.
307//===----------------------------------------------------------------------===//
308
309void TranslationUnitDecl::EmitImpl(llvm::Serializer& S) const
310{
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000311}
312
313TranslationUnitDecl* TranslationUnitDecl::CreateImpl(Deserializer& D,
314 ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000315 return new (C) TranslationUnitDecl();
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000316}
317
318//===----------------------------------------------------------------------===//
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000319// NamespaceDecl Serialization.
320//===----------------------------------------------------------------------===//
321
322void NamespaceDecl::EmitImpl(llvm::Serializer& S) const
323{
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000324 NamedDecl::EmitInRec(S);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000325 S.Emit(getLBracLoc());
326 S.Emit(getRBracLoc());
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000327}
328
329NamespaceDecl* NamespaceDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000330 NamespaceDecl* decl = new (C) NamespaceDecl(0, SourceLocation(), 0);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000331
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000332 decl->NamedDecl::ReadInRec(D, C);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000333 decl->LBracLoc = SourceLocation::ReadVal(D);
334 decl->RBracLoc = SourceLocation::ReadVal(D);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000335
336 return decl;
337}
338
339//===----------------------------------------------------------------------===//
Steve Naroff248a7532008-04-15 22:42:06 +0000340// VarDecl Serialization.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000341//===----------------------------------------------------------------------===//
342
Steve Naroff248a7532008-04-15 22:42:06 +0000343VarDecl* VarDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff248a7532008-04-15 22:42:06 +0000344 VarDecl* decl =
Steve Naroff3e970492009-01-27 21:25:57 +0000345 new (C) VarDecl(Var, 0, SourceLocation(), NULL, QualType(), None);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000346
Sam Bishope2563ca2008-04-07 21:55:54 +0000347 decl->VarDecl::ReadImpl(D, C);
Ted Kremenek04973312007-11-02 18:05:11 +0000348 return decl;
349}
350
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000351//===----------------------------------------------------------------------===//
Steve Naroff248a7532008-04-15 22:42:06 +0000352// ParmVarDecl Serialization.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000353//===----------------------------------------------------------------------===//
Ted Kremenek04973312007-11-02 18:05:11 +0000354
Ted Kremenek137bd912007-12-13 06:28:13 +0000355void ParmVarDecl::EmitImpl(llvm::Serializer& S) const {
356 VarDecl::EmitImpl(S);
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000357 S.EmitInt(getObjCDeclQualifier()); // From ParmVarDecl.
Chris Lattner04421082008-04-08 04:40:51 +0000358 S.EmitOwnedPtr(getDefaultArg()); // From ParmVarDecl.
Ted Kremenek137bd912007-12-13 06:28:13 +0000359}
360
Sam Bishope2563ca2008-04-07 21:55:54 +0000361ParmVarDecl* ParmVarDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000362 ParmVarDecl* decl = new (C)
Fariborz Jahanian4306d3c2008-12-20 23:29:59 +0000363 ParmVarDecl(ParmVar,
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000364 0, SourceLocation(), NULL, QualType(), None, NULL);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000365
Sam Bishope2563ca2008-04-07 21:55:54 +0000366 decl->VarDecl::ReadImpl(D, C);
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000367 decl->objcDeclQualifier = static_cast<ObjCDeclQualifier>(D.ReadInt());
Chris Lattner04421082008-04-08 04:40:51 +0000368 decl->DefaultArg = D.ReadOwnedPtr<Expr>(C);
Ted Kremenek04973312007-11-02 18:05:11 +0000369 return decl;
370}
371
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000372//===----------------------------------------------------------------------===//
Douglas Gregor64650af2009-02-02 23:39:07 +0000373// OriginalParmVarDecl Serialization.
Fariborz Jahanian73da9e42008-12-20 20:56:12 +0000374//===----------------------------------------------------------------------===//
375
Douglas Gregor64650af2009-02-02 23:39:07 +0000376void OriginalParmVarDecl::EmitImpl(llvm::Serializer& S) const {
Fariborz Jahanian73da9e42008-12-20 20:56:12 +0000377 ParmVarDecl::EmitImpl(S);
378 S.Emit(OriginalType);
379}
380
Douglas Gregor64650af2009-02-02 23:39:07 +0000381OriginalParmVarDecl* OriginalParmVarDecl::CreateImpl(
Fariborz Jahanian73da9e42008-12-20 20:56:12 +0000382 Deserializer& D, ASTContext& C) {
Douglas Gregor64650af2009-02-02 23:39:07 +0000383 OriginalParmVarDecl* decl = new (C)
384 OriginalParmVarDecl(0, SourceLocation(), NULL, QualType(),
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000385 QualType(), None, NULL);
Fariborz Jahanian73da9e42008-12-20 20:56:12 +0000386
387 decl->ParmVarDecl::ReadImpl(D, C);
388 decl->OriginalType = QualType::ReadVal(D);
389 return decl;
390}
391//===----------------------------------------------------------------------===//
Ted Kremenek583e0082007-11-14 18:12:19 +0000392// EnumDecl Serialization.
393//===----------------------------------------------------------------------===//
394
395void EnumDecl::EmitImpl(Serializer& S) const {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000396 NamedDecl::EmitInRec(S);
Ted Kremenek583e0082007-11-14 18:12:19 +0000397 S.EmitBool(isDefinition());
Douglas Gregor44b43212008-12-11 16:49:14 +0000398 S.Emit(IntegerType);
Ted Kremenek583e0082007-11-14 18:12:19 +0000399}
400
Sam Bishope2563ca2008-04-07 21:55:54 +0000401EnumDecl* EnumDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000402 EnumDecl* decl = new (C) EnumDecl(0, SourceLocation(), NULL);
Ted Kremenek583e0082007-11-14 18:12:19 +0000403
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000404 decl->NamedDecl::ReadInRec(D, C);
Ted Kremenek583e0082007-11-14 18:12:19 +0000405 decl->setDefinition(D.ReadBool());
406 decl->IntegerType = QualType::ReadVal(D);
407
Ted Kremenek583e0082007-11-14 18:12:19 +0000408 return decl;
409}
410
411//===----------------------------------------------------------------------===//
412// EnumConstantDecl Serialization.
413//===----------------------------------------------------------------------===//
414
415void EnumConstantDecl::EmitImpl(Serializer& S) const {
416 S.Emit(Val);
417 ValueDecl::EmitInRec(S);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000418 S.EmitOwnedPtr(Init);
Ted Kremenek583e0082007-11-14 18:12:19 +0000419}
420
Sam Bishope2563ca2008-04-07 21:55:54 +0000421EnumConstantDecl* EnumConstantDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Ted Kremenek049b1682007-11-14 23:38:09 +0000422 llvm::APSInt val(1);
Ted Kremenek583e0082007-11-14 18:12:19 +0000423 D.Read(val);
424
Steve Naroff3e970492009-01-27 21:25:57 +0000425 EnumConstantDecl* decl = new (C)
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());
Mike Stump080cc352009-02-10 20:06:48 +0000440 ValueDecl::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) {
Steve Naroff3e970492009-01-27 21:25:57 +0000445 FieldDecl* decl = new (C) FieldDecl(Field, 0, SourceLocation(), NULL,
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000446 QualType(), 0, false);
Douglas Gregor44b43212008-12-11 16:49:14 +0000447 decl->Mutable = D.ReadBool();
Mike Stump080cc352009-02-10 20:06:48 +0000448 decl->ValueDecl::ReadInRec(D, C);
Sam Bishope2563ca2008-04-07 21:55:54 +0000449 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 Gregorfab9d672009-02-05 23:33:38 +0000601 TypeDecl::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
Douglas Gregorfab9d672009-02-05 23:33:38 +0000608 = new (C) TemplateTypeParmDecl(0, SourceLocation(), 0, Typename,
609 QualType());
610 decl->TypeDecl::ReadInRec(D, C);
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000611 return decl;
612}
613
614//===----------------------------------------------------------------------===//
615// NonTypeTemplateParmDecl Serialization.
616//===----------------------------------------------------------------------===//
617void NonTypeTemplateParmDecl::EmitImpl(Serializer& S) const {
618 S.EmitInt(Depth);
619 S.EmitInt(Position);
620 NamedDecl::Emit(S);
621}
622
623NonTypeTemplateParmDecl*
624NonTypeTemplateParmDecl::CreateImpl(Deserializer& D, ASTContext& C) {
625 unsigned Depth = D.ReadInt();
626 unsigned Position = D.ReadInt();
627 NonTypeTemplateParmDecl *decl
628 = new (C) NonTypeTemplateParmDecl(0, SourceLocation(), Depth, Position,
629 0, QualType(), SourceLocation());
630 decl->NamedDecl::ReadInRec(D, C);
631 return decl;
632}
633
634//===----------------------------------------------------------------------===//
635// TemplateTemplateParmDecl Serialization.
636//===----------------------------------------------------------------------===//
637void TemplateTemplateParmDecl::EmitImpl(Serializer& S) const {
638 S.EmitInt(Depth);
639 S.EmitInt(Position);
640 NamedDecl::EmitInRec(S);
641}
642
643TemplateTemplateParmDecl*
644TemplateTemplateParmDecl::CreateImpl(Deserializer& D, ASTContext& C) {
645 unsigned Depth = D.ReadInt();
646 unsigned Position = D.ReadInt();
647 TemplateTemplateParmDecl *decl
648 = new (C) TemplateTemplateParmDecl(0, SourceLocation(), Depth, Position,
649 0, 0);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000650 decl->NamedDecl::ReadInRec(D, C);
Douglas Gregor72c3f312008-12-05 18:15:24 +0000651 return decl;
652}
653
654//===----------------------------------------------------------------------===//
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000655// LinkageSpec Serialization.
656//===----------------------------------------------------------------------===//
657
658void LinkageSpecDecl::EmitInRec(Serializer& S) const {
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000659 S.EmitInt(getLanguage());
Douglas Gregorf44515a2008-12-16 22:23:02 +0000660 S.EmitBool(HadBraces);
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000661}
662
Sam Bishope2563ca2008-04-07 21:55:54 +0000663void LinkageSpecDecl::ReadInRec(Deserializer& D, ASTContext& C) {
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000664 Language = static_cast<LanguageIDs>(D.ReadInt());
Douglas Gregorf44515a2008-12-16 22:23:02 +0000665 HadBraces = D.ReadBool();
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000666}
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000667
668//===----------------------------------------------------------------------===//
669// FileScopeAsm Serialization.
670//===----------------------------------------------------------------------===//
671
672void FileScopeAsmDecl::EmitImpl(llvm::Serializer& S) const
673{
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000674 S.EmitOwnedPtr(AsmString);
675}
676
Sam Bishope2563ca2008-04-07 21:55:54 +0000677FileScopeAsmDecl* FileScopeAsmDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000678 FileScopeAsmDecl* decl = new (C) FileScopeAsmDecl(0, SourceLocation(), 0);
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000679
Sam Bishope2563ca2008-04-07 21:55:54 +0000680 decl->AsmString = cast<StringLiteral>(D.ReadOwnedPtr<Expr>(C));
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000681// D.ReadOwnedPtr(D.ReadOwnedPtr<StringLiteral>())<#T * * Ptr#>, <#bool AutoRegister#>)(decl->AsmString);
682
683 return decl;
684}