blob: 662de369a7f3b7bb1ac31633a9ac1fea936e9f9b [file] [log] [blame]
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +00001//===--- DeclSerialization.cpp - Serialization of Decls ---------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +00007//
8//===----------------------------------------------------------------------===//
9//
Gabor Greif843e9342008-03-06 10:40:09 +000010// This file defines methods that implement bitcode serialization for Decls.
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +000011//
12//===----------------------------------------------------------------------===//
13
Sam Bishopf3c63ae2008-04-11 14:49:10 +000014#include "clang/AST/ASTContext.h"
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +000015#include "clang/AST/Decl.h"
Douglas Gregor8e9bebd2008-10-21 16:13:35 +000016#include "clang/AST/DeclCXX.h"
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +000017#include "clang/AST/Expr.h"
18#include "llvm/Bitcode/Serialize.h"
19#include "llvm/Bitcode/Deserialize.h"
20
Ted Kremenek928fd7f2007-11-13 00:15:39 +000021using llvm::Serializer;
22using llvm::Deserializer;
23using llvm::SerializedPtrID;
24
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +000025using namespace clang;
26
Ted Kremenek928fd7f2007-11-13 00:15:39 +000027//===----------------------------------------------------------------------===//
28// Decl Serialization: Dispatch code to handle specialized decl types.
29//===----------------------------------------------------------------------===//
Ted Kremenek8af8fe32007-11-05 21:38:00 +000030
Ted Kremenek928fd7f2007-11-13 00:15:39 +000031void Decl::Emit(Serializer& S) const {
32 S.EmitInt(getKind());
33 EmitImpl(S);
Douglas Gregor4afa39d2009-01-20 01:17:11 +000034 S.Emit(getLocation());
35 S.EmitBool(InvalidDecl);
36 // FIXME: HasAttrs?
37 S.EmitBool(Implicit);
38 S.EmitInt(Access);
39 S.EmitPtr(cast_or_null<Decl>(getDeclContext())); // From Decl.
40 S.EmitPtr(cast_or_null<Decl>(getLexicalDeclContext())); // From Decl.
41 S.EmitPtr(NextDeclarator);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000042 if (const DeclContext *DC = dyn_cast<const DeclContext>(this))
43 DC->EmitOutRec(S);
Douglas Gregor4afa39d2009-01-20 01:17:11 +000044
45 if (getDeclContext() &&
46 !getDeclContext()->isFunctionOrMethod()) {
47 S.EmitBool(true);
48 S.EmitOwnedPtr(NextDeclInScope);
49 } else {
50 S.EmitBool(false);
51 S.EmitPtr(NextDeclInScope);
52 }
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +000053}
54
Sam Bishope2563ca2008-04-07 21:55:54 +000055Decl* Decl::Create(Deserializer& D, ASTContext& C) {
Ted Kremenek928fd7f2007-11-13 00:15:39 +000056
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000057 Decl *Dcl;
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000058 Kind k = static_cast<Kind>(D.ReadInt());
Sam Bishope2563ca2008-04-07 21:55:54 +000059
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000060 switch (k) {
61 default:
62 assert (false && "Not implemented.");
Chris Lattner0ed844b2008-04-04 06:12:32 +000063
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +000064 case TranslationUnit:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000065 Dcl = TranslationUnitDecl::CreateImpl(D, C);
66 break;
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +000067
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +000068 case Namespace:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000069 Dcl = NamespaceDecl::CreateImpl(D, C);
70 break;
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +000071
Steve Naroff248a7532008-04-15 22:42:06 +000072 case Var:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000073 Dcl = VarDecl::CreateImpl(D, C);
74 break;
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000075
Ted Kremenek583e0082007-11-14 18:12:19 +000076 case Enum:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000077 Dcl = EnumDecl::CreateImpl(D, C);
78 break;
Ted Kremenek583e0082007-11-14 18:12:19 +000079
80 case EnumConstant:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000081 Dcl = EnumConstantDecl::CreateImpl(D, C);
82 break;
Ted Kremenek583e0082007-11-14 18:12:19 +000083
Ted Kremenekf9d56c82007-11-14 17:47:01 +000084 case Field:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000085 Dcl = FieldDecl::CreateImpl(D, C);
86 break;
Ted Kremenekf9d56c82007-11-14 17:47:01 +000087
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000088 case ParmVar:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000089 Dcl = ParmVarDecl::CreateImpl(D, C);
90 break;
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000091
Fariborz Jahanian73da9e42008-12-20 20:56:12 +000092 case OriginalParmVar:
93 Dcl = ParmVarWithOriginalTypeDecl::CreateImpl(D, C);
94 break;
95
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000096 case Function:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000097 Dcl = FunctionDecl::CreateImpl(D, C);
98 break;
Douglas Gregor8e9bebd2008-10-21 16:13:35 +000099
100 case OverloadedFunction:
101 Dcl = OverloadedFunctionDecl::CreateImpl(D, C);
102 break;
103
Argyrios Kyrtzidis35bc0822008-10-15 00:42:39 +0000104 case Record:
105 Dcl = RecordDecl::CreateImpl(D, C);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000106 break;
Ted Kremenekaad48b62007-11-14 08:06:37 +0000107
Ted Kremenek2ebc89f2007-11-06 19:51:47 +0000108 case Typedef:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000109 Dcl = TypedefDecl::CreateImpl(D, C);
110 break;
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000111
Douglas Gregor72c3f312008-12-05 18:15:24 +0000112 case TemplateTypeParm:
113 Dcl = TemplateTypeParmDecl::CreateImpl(D, C);
114 break;
115
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000116 case FileScopeAsm:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000117 Dcl = FileScopeAsmDecl::CreateImpl(D, C);
118 break;
Ted Kremenek2ebc89f2007-11-06 19:51:47 +0000119 }
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000120
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000121 Dcl->Loc = SourceLocation::ReadVal(D); // From Decl.
122 Dcl->InvalidDecl = D.ReadBool();
123 // FIXME: HasAttrs?
124 Dcl->Implicit = D.ReadBool();
125 Dcl->Access = D.ReadInt();
126
127 assert(Dcl->DeclCtx == 0);
128
129 const SerializedPtrID &SemaDCPtrID = D.ReadPtrID();
130 const SerializedPtrID &LexicalDCPtrID = D.ReadPtrID();
131
132 if (SemaDCPtrID == LexicalDCPtrID) {
133 // Allow back-patching. Observe that we register the variable of the
134 // *object* for back-patching. Its actual value will get filled in later.
135 D.ReadUIntPtr(Dcl->DeclCtx, SemaDCPtrID);
136 }
137 else {
138 MultipleDC *MDC = new MultipleDC();
139 Dcl->DeclCtx = reinterpret_cast<uintptr_t>(MDC) | 0x1;
140 // Allow back-patching. Observe that we register the variable of the
141 // *object* for back-patching. Its actual value will get filled in later.
142 D.ReadPtr(MDC->SemanticDC, SemaDCPtrID);
143 D.ReadPtr(MDC->LexicalDC, LexicalDCPtrID);
144 }
145 D.ReadPtr(Dcl->NextDeclarator);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000146 if (DeclContext *DC = dyn_cast<DeclContext>(Dcl))
147 DC->ReadOutRec(D, C);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000148 bool OwnsNext = D.ReadBool();
149 if (OwnsNext)
150 Dcl->NextDeclInScope = D.ReadOwnedPtr<Decl>(C);
151 else
152 D.ReadPtr(Dcl->NextDeclInScope);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000153 return Dcl;
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +0000154}
Ted Kremenek04973312007-11-02 18:05:11 +0000155
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000156//===----------------------------------------------------------------------===//
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000157// Common serialization logic for subclasses of DeclContext.
158//===----------------------------------------------------------------------===//
159
160void DeclContext::EmitOutRec(Serializer& S) const {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000161 bool Owned = !isFunctionOrMethod();
162 S.EmitBool(Owned);
163 if (Owned)
164 S.EmitOwnedPtr(FirstDecl);
165 else
166 S.EmitPtr(FirstDecl);
167 S.EmitPtr(LastDecl);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000168}
169
170void DeclContext::ReadOutRec(Deserializer& D, ASTContext& C) {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000171 bool Owned = D.ReadBool();
172 if (Owned)
173 FirstDecl = cast_or_null<Decl>(D.ReadOwnedPtr<Decl>(C));
174 else
175 D.ReadPtr(FirstDecl);
176 D.ReadPtr(LastDecl);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000177}
178
179//===----------------------------------------------------------------------===//
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000180// Common serialization logic for subclasses of NamedDecl.
181//===----------------------------------------------------------------------===//
182
183void NamedDecl::EmitInRec(Serializer& S) const {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000184 S.EmitInt(Name.getNameKind());
185
186 switch (Name.getNameKind()) {
187 case DeclarationName::Identifier:
188 S.EmitPtr(Name.getAsIdentifierInfo());
189 break;
190
191 case DeclarationName::ObjCZeroArgSelector:
192 case DeclarationName::ObjCOneArgSelector:
193 case DeclarationName::ObjCMultiArgSelector:
194 Name.getObjCSelector().Emit(S);
195 break;
196
197 case DeclarationName::CXXConstructorName:
198 case DeclarationName::CXXDestructorName:
199 case DeclarationName::CXXConversionFunctionName:
200 Name.getCXXNameType().Emit(S);
201 break;
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000202
203 case DeclarationName::CXXOperatorName:
204 S.EmitInt(Name.getCXXOverloadedOperator());
205 break;
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000206 }
Ted Kremenek04973312007-11-02 18:05:11 +0000207}
208
Sam Bishope2563ca2008-04-07 21:55:54 +0000209void NamedDecl::ReadInRec(Deserializer& D, ASTContext& C) {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000210 DeclarationName::NameKind Kind
211 = static_cast<DeclarationName::NameKind>(D.ReadInt());
212 switch (Kind) {
213 case DeclarationName::Identifier: {
Ted Kremenekddf32da2009-01-21 00:42:24 +0000214 // Don't allow back-patching. The IdentifierInfo table must already
215 // be loaded.
216 Name = D.ReadPtr<IdentifierInfo>();
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000217 break;
218 }
219
220 case DeclarationName::ObjCZeroArgSelector:
221 case DeclarationName::ObjCOneArgSelector:
222 case DeclarationName::ObjCMultiArgSelector:
223 Name = Selector::ReadVal(D);
224 break;
225
226 case DeclarationName::CXXConstructorName:
227 Name = C.DeclarationNames.getCXXConstructorName(QualType::ReadVal(D));
228 break;
229
230 case DeclarationName::CXXDestructorName:
231 Name = C.DeclarationNames.getCXXDestructorName(QualType::ReadVal(D));
232 break;
233
234 case DeclarationName::CXXConversionFunctionName:
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000235 Name
236 = C.DeclarationNames.getCXXConversionFunctionName(QualType::ReadVal(D));
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000237 break;
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000238
239 case DeclarationName::CXXOperatorName: {
240 OverloadedOperatorKind Op
241 = static_cast<OverloadedOperatorKind>(D.ReadInt());
242 Name = C.DeclarationNames.getCXXOperatorName(Op);
243 break;
244 }
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000245 }
Ted Kremenek04973312007-11-02 18:05:11 +0000246}
247
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000248//===----------------------------------------------------------------------===//
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000249// Common serialization logic for subclasses of ValueDecl.
250//===----------------------------------------------------------------------===//
251
252void ValueDecl::EmitInRec(Serializer& S) const {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000253 NamedDecl::EmitInRec(S);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000254 S.Emit(getType()); // From ValueDecl.
255}
256
Sam Bishope2563ca2008-04-07 21:55:54 +0000257void ValueDecl::ReadInRec(Deserializer& D, ASTContext& C) {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000258 NamedDecl::ReadInRec(D, C);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000259 DeclType = QualType::ReadVal(D); // From ValueDecl.
260}
261
262//===----------------------------------------------------------------------===//
263// Common serialization logic for subclasses of VarDecl.
264//===----------------------------------------------------------------------===//
265
266void VarDecl::EmitInRec(Serializer& S) const {
267 ValueDecl::EmitInRec(S);
268 S.EmitInt(getStorageClass()); // From VarDecl.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000269}
270
Sam Bishope2563ca2008-04-07 21:55:54 +0000271void VarDecl::ReadInRec(Deserializer& D, ASTContext& C) {
272 ValueDecl::ReadInRec(D, C);
Fariborz Jahaniande7b4cd2007-12-13 00:54:18 +0000273 SClass = static_cast<StorageClass>(D.ReadInt()); // From VarDecl.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000274}
275
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000276void VarDecl::EmitOutRec(Serializer& S) const {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000277 // Emit this last because it will create a record of its own.
278 S.EmitOwnedPtr(getInit());
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000279}
280
Sam Bishope2563ca2008-04-07 21:55:54 +0000281void VarDecl::ReadOutRec(Deserializer& D, ASTContext& C) {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000282 Init = D.ReadOwnedPtr<Stmt>(C);
Ted Kremenek04973312007-11-02 18:05:11 +0000283}
284
285
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000286void VarDecl::EmitImpl(Serializer& S) const {
287 VarDecl::EmitInRec(S);
288 VarDecl::EmitOutRec(S);
Ted Kremenek04973312007-11-02 18:05:11 +0000289}
290
Sam Bishope2563ca2008-04-07 21:55:54 +0000291void VarDecl::ReadImpl(Deserializer& D, ASTContext& C) {
292 ReadInRec(D, C);
293 ReadOutRec(D, C);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000294}
295
296//===----------------------------------------------------------------------===//
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000297// TranslationUnitDecl Serialization.
298//===----------------------------------------------------------------------===//
299
300void TranslationUnitDecl::EmitImpl(llvm::Serializer& S) const
301{
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000302}
303
304TranslationUnitDecl* TranslationUnitDecl::CreateImpl(Deserializer& D,
305 ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000306 return new (C) TranslationUnitDecl();
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000307}
308
309//===----------------------------------------------------------------------===//
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000310// NamespaceDecl Serialization.
311//===----------------------------------------------------------------------===//
312
313void NamespaceDecl::EmitImpl(llvm::Serializer& S) const
314{
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000315 NamedDecl::EmitInRec(S);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000316 S.Emit(getLBracLoc());
317 S.Emit(getRBracLoc());
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000318}
319
320NamespaceDecl* NamespaceDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000321 NamespaceDecl* decl = new (C) NamespaceDecl(0, SourceLocation(), 0);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000322
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000323 decl->NamedDecl::ReadInRec(D, C);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000324 decl->LBracLoc = SourceLocation::ReadVal(D);
325 decl->RBracLoc = SourceLocation::ReadVal(D);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000326
327 return decl;
328}
329
330//===----------------------------------------------------------------------===//
Steve Naroff248a7532008-04-15 22:42:06 +0000331// VarDecl Serialization.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000332//===----------------------------------------------------------------------===//
333
Steve Naroff248a7532008-04-15 22:42:06 +0000334VarDecl* VarDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff248a7532008-04-15 22:42:06 +0000335 VarDecl* decl =
Steve Naroff3e970492009-01-27 21:25:57 +0000336 new (C) VarDecl(Var, 0, SourceLocation(), NULL, QualType(), None);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000337
Sam Bishope2563ca2008-04-07 21:55:54 +0000338 decl->VarDecl::ReadImpl(D, C);
Ted Kremenek04973312007-11-02 18:05:11 +0000339 return decl;
340}
341
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000342//===----------------------------------------------------------------------===//
Steve Naroff248a7532008-04-15 22:42:06 +0000343// ParmVarDecl Serialization.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000344//===----------------------------------------------------------------------===//
Ted Kremenek04973312007-11-02 18:05:11 +0000345
Ted Kremenek137bd912007-12-13 06:28:13 +0000346void ParmVarDecl::EmitImpl(llvm::Serializer& S) const {
347 VarDecl::EmitImpl(S);
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000348 S.EmitInt(getObjCDeclQualifier()); // From ParmVarDecl.
Chris Lattner04421082008-04-08 04:40:51 +0000349 S.EmitOwnedPtr(getDefaultArg()); // From ParmVarDecl.
Ted Kremenek137bd912007-12-13 06:28:13 +0000350}
351
Sam Bishope2563ca2008-04-07 21:55:54 +0000352ParmVarDecl* ParmVarDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000353 ParmVarDecl* decl = new (C)
Fariborz Jahanian4306d3c2008-12-20 23:29:59 +0000354 ParmVarDecl(ParmVar,
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000355 0, SourceLocation(), NULL, QualType(), None, NULL);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000356
Sam Bishope2563ca2008-04-07 21:55:54 +0000357 decl->VarDecl::ReadImpl(D, C);
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000358 decl->objcDeclQualifier = static_cast<ObjCDeclQualifier>(D.ReadInt());
Chris Lattner04421082008-04-08 04:40:51 +0000359 decl->DefaultArg = D.ReadOwnedPtr<Expr>(C);
Ted Kremenek04973312007-11-02 18:05:11 +0000360 return decl;
361}
362
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000363//===----------------------------------------------------------------------===//
Fariborz Jahanian73da9e42008-12-20 20:56:12 +0000364// ParmVarWithOriginalTypeDecl Serialization.
365//===----------------------------------------------------------------------===//
366
367void ParmVarWithOriginalTypeDecl::EmitImpl(llvm::Serializer& S) const {
368 ParmVarDecl::EmitImpl(S);
369 S.Emit(OriginalType);
370}
371
372ParmVarWithOriginalTypeDecl* ParmVarWithOriginalTypeDecl::CreateImpl(
373 Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000374 ParmVarWithOriginalTypeDecl* decl = new (C)
Fariborz Jahanian73da9e42008-12-20 20:56:12 +0000375 ParmVarWithOriginalTypeDecl(0, SourceLocation(), NULL, QualType(),
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000376 QualType(), None, NULL);
Fariborz Jahanian73da9e42008-12-20 20:56:12 +0000377
378 decl->ParmVarDecl::ReadImpl(D, C);
379 decl->OriginalType = QualType::ReadVal(D);
380 return decl;
381}
382//===----------------------------------------------------------------------===//
Ted Kremenek583e0082007-11-14 18:12:19 +0000383// EnumDecl Serialization.
384//===----------------------------------------------------------------------===//
385
386void EnumDecl::EmitImpl(Serializer& S) const {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000387 NamedDecl::EmitInRec(S);
Ted Kremenek583e0082007-11-14 18:12:19 +0000388 S.EmitBool(isDefinition());
Douglas Gregor44b43212008-12-11 16:49:14 +0000389 S.Emit(IntegerType);
Ted Kremenek583e0082007-11-14 18:12:19 +0000390}
391
Sam Bishope2563ca2008-04-07 21:55:54 +0000392EnumDecl* EnumDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000393 EnumDecl* decl = new (C) EnumDecl(0, SourceLocation(), NULL);
Ted Kremenek583e0082007-11-14 18:12:19 +0000394
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000395 decl->NamedDecl::ReadInRec(D, C);
Ted Kremenek583e0082007-11-14 18:12:19 +0000396 decl->setDefinition(D.ReadBool());
397 decl->IntegerType = QualType::ReadVal(D);
398
Ted Kremenek583e0082007-11-14 18:12:19 +0000399 return decl;
400}
401
402//===----------------------------------------------------------------------===//
403// EnumConstantDecl Serialization.
404//===----------------------------------------------------------------------===//
405
406void EnumConstantDecl::EmitImpl(Serializer& S) const {
407 S.Emit(Val);
408 ValueDecl::EmitInRec(S);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000409 S.EmitOwnedPtr(Init);
Ted Kremenek583e0082007-11-14 18:12:19 +0000410}
411
Sam Bishope2563ca2008-04-07 21:55:54 +0000412EnumConstantDecl* EnumConstantDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Ted Kremenek049b1682007-11-14 23:38:09 +0000413 llvm::APSInt val(1);
Ted Kremenek583e0082007-11-14 18:12:19 +0000414 D.Read(val);
415
Steve Naroff3e970492009-01-27 21:25:57 +0000416 EnumConstantDecl* decl = new (C)
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000417 EnumConstantDecl(0, SourceLocation(), NULL, QualType(), NULL, val);
Ted Kremenek583e0082007-11-14 18:12:19 +0000418
Sam Bishope2563ca2008-04-07 21:55:54 +0000419 decl->ValueDecl::ReadInRec(D, C);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000420 decl->Init = D.ReadOwnedPtr<Stmt>(C);
Ted Kremenek583e0082007-11-14 18:12:19 +0000421 return decl;
422}
423
424//===----------------------------------------------------------------------===//
Ted Kremenekf9d56c82007-11-14 17:47:01 +0000425// FieldDecl Serialization.
426//===----------------------------------------------------------------------===//
427
428void FieldDecl::EmitImpl(Serializer& S) const {
Douglas Gregor44b43212008-12-11 16:49:14 +0000429 S.EmitBool(Mutable);
Ted Kremenekf9d56c82007-11-14 17:47:01 +0000430 S.Emit(getType());
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000431 NamedDecl::EmitInRec(S);
Ted Kremenekf9d56c82007-11-14 17:47:01 +0000432 S.EmitOwnedPtr(BitWidth);
433}
434
Sam Bishope2563ca2008-04-07 21:55:54 +0000435FieldDecl* FieldDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000436 FieldDecl* decl = new (C) FieldDecl(Field, 0, SourceLocation(), NULL,
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000437 QualType(), 0, false);
Douglas Gregor44b43212008-12-11 16:49:14 +0000438 decl->Mutable = D.ReadBool();
Ted Kremenek21d50e12007-11-14 22:51:02 +0000439 decl->DeclType.ReadBackpatch(D);
Sam Bishope2563ca2008-04-07 21:55:54 +0000440 decl->ReadInRec(D, C);
441 decl->BitWidth = D.ReadOwnedPtr<Expr>(C);
Ted Kremenekf9d56c82007-11-14 17:47:01 +0000442 return decl;
443}
444
445//===----------------------------------------------------------------------===//
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000446// FunctionDecl Serialization.
447//===----------------------------------------------------------------------===//
Ted Kremenek04973312007-11-02 18:05:11 +0000448
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000449void FunctionDecl::EmitImpl(Serializer& S) const {
450 S.EmitInt(SClass); // From FunctionDecl.
451 S.EmitBool(IsInline); // From FunctionDecl.
452 ValueDecl::EmitInRec(S);
Ted Kremenek3bbc1982008-05-20 03:33:58 +0000453 S.EmitPtr(PreviousDeclaration);
Ted Kremenek04973312007-11-02 18:05:11 +0000454
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000455 // NOTE: We do not need to serialize out the number of parameters, because
456 // that is encoded in the type (accessed via getNumParams()).
Ted Kremenek04973312007-11-02 18:05:11 +0000457
Ted Kremenekd437f232007-11-13 22:51:08 +0000458 if (ParamInfo != NULL) {
459 S.EmitBool(true);
Argyrios Kyrtzidisdc5ddbf2008-11-07 14:22:23 +0000460 S.EmitInt(getNumParams());
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000461 S.BatchEmitOwnedPtrs(getNumParams(),&ParamInfo[0], Body);
Ted Kremenekd437f232007-11-13 22:51:08 +0000462 }
463 else {
464 S.EmitBool(false);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000465 S.EmitOwnedPtr(Body);
Ted Kremenekd437f232007-11-13 22:51:08 +0000466 }
Ted Kremenek04973312007-11-02 18:05:11 +0000467}
468
Sam Bishope2563ca2008-04-07 21:55:54 +0000469FunctionDecl* FunctionDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Ted Kremenek04973312007-11-02 18:05:11 +0000470 StorageClass SClass = static_cast<StorageClass>(D.ReadInt());
471 bool IsInline = D.ReadBool();
Ted Kremenek04973312007-11-02 18:05:11 +0000472
Steve Naroff3e970492009-01-27 21:25:57 +0000473 FunctionDecl* decl = new (C)
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000474 FunctionDecl(Function, 0, SourceLocation(), DeclarationName(),
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000475 QualType(), SClass, IsInline);
Ted Kremenek04973312007-11-02 18:05:11 +0000476
Sam Bishope2563ca2008-04-07 21:55:54 +0000477 decl->ValueDecl::ReadInRec(D, C);
Ted Kremenek3bbc1982008-05-20 03:33:58 +0000478 D.ReadPtr(decl->PreviousDeclaration);
Ted Kremenekda256852007-11-16 18:11:10 +0000479
Douglas Gregor6b54bd12009-01-05 17:18:30 +0000480 int numParams = 0;
Ted Kremenekd437f232007-11-13 22:51:08 +0000481 bool hasParamDecls = D.ReadBool();
Argyrios Kyrtzidisdc5ddbf2008-11-07 14:22:23 +0000482 if (hasParamDecls)
483 numParams = D.ReadInt();
Ted Kremenekda256852007-11-16 18:11:10 +0000484
485 decl->ParamInfo = hasParamDecls
Argyrios Kyrtzidisdc5ddbf2008-11-07 14:22:23 +0000486 ? new ParmVarDecl*[numParams]
Ted Kremenekda256852007-11-16 18:11:10 +0000487 : NULL;
Ted Kremenekd437f232007-11-13 22:51:08 +0000488
489 if (hasParamDecls)
Argyrios Kyrtzidisdc5ddbf2008-11-07 14:22:23 +0000490 D.BatchReadOwnedPtrs(numParams,
Ted Kremenekd437f232007-11-13 22:51:08 +0000491 reinterpret_cast<Decl**>(&decl->ParamInfo[0]),
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000492 decl->Body, C);
Ted Kremenekd437f232007-11-13 22:51:08 +0000493 else
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000494 decl->Body = D.ReadOwnedPtr<Stmt>(C);
Ted Kremenek04973312007-11-02 18:05:11 +0000495
496 return decl;
497}
Ted Kremenekf7bf4112007-11-05 21:49:34 +0000498
Steve Naroff56ee6892008-10-08 17:01:13 +0000499void BlockDecl::EmitImpl(Serializer& S) const {
500 // FIXME: what about arguments?
501 S.Emit(getCaretLocation());
502 S.EmitOwnedPtr(Body);
503}
504
505BlockDecl* BlockDecl::CreateImpl(Deserializer& D, ASTContext& C) {
506 QualType Q = QualType::ReadVal(D);
507 SourceLocation L = SourceLocation::ReadVal(D);
508 /*CompoundStmt* BodyStmt = cast<CompoundStmt>(*/D.ReadOwnedPtr<Stmt>(C)/*)*/;
509 assert(0 && "Cannot deserialize BlockBlockExpr yet");
510 // FIXME: need to handle parameters.
511 //return new BlockBlockExpr(L, Q, BodyStmt);
512 return 0;
513}
514
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000515//===----------------------------------------------------------------------===//
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000516// OverloadedFunctionDecl Serialization.
517//===----------------------------------------------------------------------===//
518
519void OverloadedFunctionDecl::EmitImpl(Serializer& S) const {
520 NamedDecl::EmitInRec(S);
521
522 S.EmitInt(getNumFunctions());
523 for (unsigned func = 0; func < getNumFunctions(); ++func)
524 S.EmitPtr(Functions[func]);
525}
526
527OverloadedFunctionDecl *
528OverloadedFunctionDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000529 OverloadedFunctionDecl* decl = new (C)
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000530 OverloadedFunctionDecl(0, DeclarationName());
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000531
532 decl->NamedDecl::ReadInRec(D, C);
533
534 unsigned numFunctions = D.ReadInt();
535 decl->Functions.reserve(numFunctions);
536 for (unsigned func = 0; func < numFunctions; ++func)
537 D.ReadPtr(decl->Functions[func]);
538
539 return decl;
540}
541
542//===----------------------------------------------------------------------===//
Ted Kremenekaad48b62007-11-14 08:06:37 +0000543// RecordDecl Serialization.
544//===----------------------------------------------------------------------===//
545
Ted Kremenek583e0082007-11-14 18:12:19 +0000546void RecordDecl::EmitImpl(Serializer& S) const {
Argyrios Kyrtzidis35bc0822008-10-15 00:42:39 +0000547 S.EmitInt(getTagKind());
548
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000549 NamedDecl::EmitInRec(S);
Ted Kremenek583e0082007-11-14 18:12:19 +0000550 S.EmitBool(isDefinition());
Ted Kremenekaad48b62007-11-14 08:06:37 +0000551 S.EmitBool(hasFlexibleArrayMember());
Douglas Gregorbcbffc42009-01-07 00:43:41 +0000552 S.EmitBool(isAnonymousStructOrUnion());
Ted Kremenekaad48b62007-11-14 08:06:37 +0000553}
554
Argyrios Kyrtzidis35bc0822008-10-15 00:42:39 +0000555RecordDecl* RecordDecl::CreateImpl(Deserializer& D, ASTContext& C) {
556 TagKind TK = TagKind(D.ReadInt());
Sam Bishope2563ca2008-04-07 21:55:54 +0000557
Steve Naroff3e970492009-01-27 21:25:57 +0000558 RecordDecl* decl = new (C) RecordDecl(Record, TK, 0, SourceLocation(), NULL);
Ted Kremenek583e0082007-11-14 18:12:19 +0000559
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000560 decl->NamedDecl::ReadInRec(D, C);
Ted Kremenek583e0082007-11-14 18:12:19 +0000561 decl->setDefinition(D.ReadBool());
Ted Kremenekaad48b62007-11-14 08:06:37 +0000562 decl->setHasFlexibleArrayMember(D.ReadBool());
Douglas Gregorbcbffc42009-01-07 00:43:41 +0000563 decl->setAnonymousStructOrUnion(D.ReadBool());
Douglas Gregor44b43212008-12-11 16:49:14 +0000564
Ted Kremenekaad48b62007-11-14 08:06:37 +0000565 return decl;
566}
567
568//===----------------------------------------------------------------------===//
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000569// TypedefDecl Serialization.
570//===----------------------------------------------------------------------===//
571
572void TypedefDecl::EmitImpl(Serializer& S) const {
Ted Kremenek2ebc89f2007-11-06 19:51:47 +0000573 S.Emit(UnderlyingType);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000574 NamedDecl::EmitInRec(S);
Ted Kremenekf7bf4112007-11-05 21:49:34 +0000575}
576
Sam Bishope2563ca2008-04-07 21:55:54 +0000577TypedefDecl* TypedefDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000578 QualType T = QualType::ReadVal(D);
579
Steve Naroff3e970492009-01-27 21:25:57 +0000580 TypedefDecl* decl = new (C) TypedefDecl(0, SourceLocation(), NULL, T);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000581
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000582 decl->NamedDecl::ReadInRec(D, C);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000583
Ted Kremenekf7bf4112007-11-05 21:49:34 +0000584 return decl;
585}
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000586
587//===----------------------------------------------------------------------===//
Douglas Gregor72c3f312008-12-05 18:15:24 +0000588// TemplateTypeParmDecl Serialization.
589//===----------------------------------------------------------------------===//
590
591void TemplateTypeParmDecl::EmitImpl(Serializer& S) const {
592 S.EmitBool(Typename);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000593 NamedDecl::EmitInRec(S);
Douglas Gregor72c3f312008-12-05 18:15:24 +0000594}
595
596TemplateTypeParmDecl *
597TemplateTypeParmDecl::CreateImpl(Deserializer& D, ASTContext& C) {
598 bool Typename = D.ReadBool();
Douglas Gregor72c3f312008-12-05 18:15:24 +0000599 TemplateTypeParmDecl *decl
Steve Naroff3e970492009-01-27 21:25:57 +0000600 = new (C) TemplateTypeParmDecl(0, SourceLocation(), NULL, Typename);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000601 decl->NamedDecl::ReadInRec(D, C);
Douglas Gregor72c3f312008-12-05 18:15:24 +0000602 return decl;
603}
604
605//===----------------------------------------------------------------------===//
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000606// LinkageSpec Serialization.
607//===----------------------------------------------------------------------===//
608
609void LinkageSpecDecl::EmitInRec(Serializer& S) const {
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000610 S.EmitInt(getLanguage());
Douglas Gregorf44515a2008-12-16 22:23:02 +0000611 S.EmitBool(HadBraces);
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000612}
613
Sam Bishope2563ca2008-04-07 21:55:54 +0000614void LinkageSpecDecl::ReadInRec(Deserializer& D, ASTContext& C) {
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000615 Language = static_cast<LanguageIDs>(D.ReadInt());
Douglas Gregorf44515a2008-12-16 22:23:02 +0000616 HadBraces = D.ReadBool();
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000617}
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000618
619//===----------------------------------------------------------------------===//
620// FileScopeAsm Serialization.
621//===----------------------------------------------------------------------===//
622
623void FileScopeAsmDecl::EmitImpl(llvm::Serializer& S) const
624{
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000625 S.EmitOwnedPtr(AsmString);
626}
627
Sam Bishope2563ca2008-04-07 21:55:54 +0000628FileScopeAsmDecl* FileScopeAsmDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000629 FileScopeAsmDecl* decl = new (C) FileScopeAsmDecl(0, SourceLocation(), 0);
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000630
Sam Bishope2563ca2008-04-07 21:55:54 +0000631 decl->AsmString = cast<StringLiteral>(D.ReadOwnedPtr<Expr>(C));
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000632// D.ReadOwnedPtr(D.ReadOwnedPtr<StringLiteral>())<#T * * Ptr#>, <#bool AutoRegister#>)(decl->AsmString);
633
634 return decl;
635}