blob: 965874502d0c80eadec7750ee1850c6b195f7dec [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);
138 Dcl->DeclCtx.setFromOpaqueValue(reinterpret_cast<void*>(X));
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000139 }
140 else {
141 MultipleDC *MDC = new MultipleDC();
Chris Lattner0eda3b32009-03-29 04:32:54 +0000142 Dcl->DeclCtx.setPointer(reinterpret_cast<DeclContext*>(MDC));
Chris Lattner10d83792009-03-27 18:46:15 +0000143 Dcl->DeclCtx.setInt(true);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000144 // Allow back-patching. Observe that we register the variable of the
145 // *object* for back-patching. Its actual value will get filled in later.
146 D.ReadPtr(MDC->SemanticDC, SemaDCPtrID);
147 D.ReadPtr(MDC->LexicalDC, LexicalDCPtrID);
148 }
149 D.ReadPtr(Dcl->NextDeclarator);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000150 if (DeclContext *DC = dyn_cast<DeclContext>(Dcl))
151 DC->ReadOutRec(D, C);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000152 bool OwnsNext = D.ReadBool();
153 if (OwnsNext)
Chris Lattner244a67d2009-03-28 06:04:26 +0000154 Dcl->NextDeclInContext = D.ReadOwnedPtr<Decl>(C);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000155 else
Chris Lattner244a67d2009-03-28 06:04:26 +0000156 D.ReadPtr(Dcl->NextDeclInContext);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000157 return Dcl;
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +0000158}
Ted Kremenek04973312007-11-02 18:05:11 +0000159
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000160//===----------------------------------------------------------------------===//
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000161// Common serialization logic for subclasses of DeclContext.
162//===----------------------------------------------------------------------===//
163
164void DeclContext::EmitOutRec(Serializer& S) const {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000165 bool Owned = !isFunctionOrMethod();
166 S.EmitBool(Owned);
167 if (Owned)
168 S.EmitOwnedPtr(FirstDecl);
169 else
170 S.EmitPtr(FirstDecl);
171 S.EmitPtr(LastDecl);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000172}
173
174void DeclContext::ReadOutRec(Deserializer& D, ASTContext& C) {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000175 bool Owned = D.ReadBool();
176 if (Owned)
177 FirstDecl = cast_or_null<Decl>(D.ReadOwnedPtr<Decl>(C));
178 else
179 D.ReadPtr(FirstDecl);
180 D.ReadPtr(LastDecl);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000181}
182
183//===----------------------------------------------------------------------===//
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000184// Common serialization logic for subclasses of NamedDecl.
185//===----------------------------------------------------------------------===//
186
187void NamedDecl::EmitInRec(Serializer& S) const {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000188 S.EmitInt(Name.getNameKind());
189
190 switch (Name.getNameKind()) {
191 case DeclarationName::Identifier:
192 S.EmitPtr(Name.getAsIdentifierInfo());
193 break;
194
195 case DeclarationName::ObjCZeroArgSelector:
196 case DeclarationName::ObjCOneArgSelector:
197 case DeclarationName::ObjCMultiArgSelector:
198 Name.getObjCSelector().Emit(S);
199 break;
200
201 case DeclarationName::CXXConstructorName:
202 case DeclarationName::CXXDestructorName:
203 case DeclarationName::CXXConversionFunctionName:
204 Name.getCXXNameType().Emit(S);
205 break;
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000206
207 case DeclarationName::CXXOperatorName:
208 S.EmitInt(Name.getCXXOverloadedOperator());
209 break;
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000210
211 case DeclarationName::CXXUsingDirective:
212 // No extra data to emit
213 break;
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000214 }
Ted Kremenek04973312007-11-02 18:05:11 +0000215}
216
Sam Bishope2563ca2008-04-07 21:55:54 +0000217void NamedDecl::ReadInRec(Deserializer& D, ASTContext& C) {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000218 DeclarationName::NameKind Kind
219 = static_cast<DeclarationName::NameKind>(D.ReadInt());
220 switch (Kind) {
221 case DeclarationName::Identifier: {
Ted Kremenekddf32da2009-01-21 00:42:24 +0000222 // Don't allow back-patching. The IdentifierInfo table must already
223 // be loaded.
224 Name = D.ReadPtr<IdentifierInfo>();
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000225 break;
226 }
227
228 case DeclarationName::ObjCZeroArgSelector:
229 case DeclarationName::ObjCOneArgSelector:
230 case DeclarationName::ObjCMultiArgSelector:
231 Name = Selector::ReadVal(D);
232 break;
233
234 case DeclarationName::CXXConstructorName:
235 Name = C.DeclarationNames.getCXXConstructorName(QualType::ReadVal(D));
236 break;
237
238 case DeclarationName::CXXDestructorName:
239 Name = C.DeclarationNames.getCXXDestructorName(QualType::ReadVal(D));
240 break;
241
242 case DeclarationName::CXXConversionFunctionName:
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000243 Name
244 = C.DeclarationNames.getCXXConversionFunctionName(QualType::ReadVal(D));
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000245 break;
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000246
247 case DeclarationName::CXXOperatorName: {
248 OverloadedOperatorKind Op
249 = static_cast<OverloadedOperatorKind>(D.ReadInt());
250 Name = C.DeclarationNames.getCXXOperatorName(Op);
251 break;
252 }
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000253
254 case DeclarationName::CXXUsingDirective:
255 Name = DeclarationName::getUsingDirectiveName();
256 break;
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000257 }
Ted Kremenek04973312007-11-02 18:05:11 +0000258}
259
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000260//===----------------------------------------------------------------------===//
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000261// Common serialization logic for subclasses of ValueDecl.
262//===----------------------------------------------------------------------===//
263
264void ValueDecl::EmitInRec(Serializer& S) const {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000265 NamedDecl::EmitInRec(S);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000266 S.Emit(getType()); // From ValueDecl.
267}
268
Sam Bishope2563ca2008-04-07 21:55:54 +0000269void ValueDecl::ReadInRec(Deserializer& D, ASTContext& C) {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000270 NamedDecl::ReadInRec(D, C);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000271 DeclType = QualType::ReadVal(D); // From ValueDecl.
272}
273
274//===----------------------------------------------------------------------===//
275// Common serialization logic for subclasses of VarDecl.
276//===----------------------------------------------------------------------===//
277
278void VarDecl::EmitInRec(Serializer& S) const {
279 ValueDecl::EmitInRec(S);
280 S.EmitInt(getStorageClass()); // From VarDecl.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000281}
282
Sam Bishope2563ca2008-04-07 21:55:54 +0000283void VarDecl::ReadInRec(Deserializer& D, ASTContext& C) {
284 ValueDecl::ReadInRec(D, C);
Fariborz Jahaniande7b4cd2007-12-13 00:54:18 +0000285 SClass = static_cast<StorageClass>(D.ReadInt()); // From VarDecl.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000286}
287
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000288void VarDecl::EmitOutRec(Serializer& S) const {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000289 // Emit this last because it will create a record of its own.
290 S.EmitOwnedPtr(getInit());
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000291}
292
Sam Bishope2563ca2008-04-07 21:55:54 +0000293void VarDecl::ReadOutRec(Deserializer& D, ASTContext& C) {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000294 Init = D.ReadOwnedPtr<Stmt>(C);
Ted Kremenek04973312007-11-02 18:05:11 +0000295}
296
297
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000298void VarDecl::EmitImpl(Serializer& S) const {
299 VarDecl::EmitInRec(S);
300 VarDecl::EmitOutRec(S);
Ted Kremenek04973312007-11-02 18:05:11 +0000301}
302
Sam Bishope2563ca2008-04-07 21:55:54 +0000303void VarDecl::ReadImpl(Deserializer& D, ASTContext& C) {
304 ReadInRec(D, C);
305 ReadOutRec(D, C);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000306}
307
308//===----------------------------------------------------------------------===//
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000309// TranslationUnitDecl Serialization.
310//===----------------------------------------------------------------------===//
311
312void TranslationUnitDecl::EmitImpl(llvm::Serializer& S) const
313{
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000314}
315
316TranslationUnitDecl* TranslationUnitDecl::CreateImpl(Deserializer& D,
317 ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000318 return new (C) TranslationUnitDecl();
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000319}
320
321//===----------------------------------------------------------------------===//
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000322// NamespaceDecl Serialization.
323//===----------------------------------------------------------------------===//
324
325void NamespaceDecl::EmitImpl(llvm::Serializer& S) const
326{
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000327 NamedDecl::EmitInRec(S);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000328 S.Emit(getLBracLoc());
329 S.Emit(getRBracLoc());
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000330}
331
332NamespaceDecl* NamespaceDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000333 NamespaceDecl* decl = new (C) NamespaceDecl(0, SourceLocation(), 0);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000334
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000335 decl->NamedDecl::ReadInRec(D, C);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000336 decl->LBracLoc = SourceLocation::ReadVal(D);
337 decl->RBracLoc = SourceLocation::ReadVal(D);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000338
339 return decl;
340}
341
342//===----------------------------------------------------------------------===//
Steve Naroff248a7532008-04-15 22:42:06 +0000343// VarDecl Serialization.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000344//===----------------------------------------------------------------------===//
345
Steve Naroff248a7532008-04-15 22:42:06 +0000346VarDecl* VarDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff248a7532008-04-15 22:42:06 +0000347 VarDecl* decl =
Steve Naroff3e970492009-01-27 21:25:57 +0000348 new (C) VarDecl(Var, 0, SourceLocation(), NULL, QualType(), None);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000349
Sam Bishope2563ca2008-04-07 21:55:54 +0000350 decl->VarDecl::ReadImpl(D, C);
Ted Kremenek04973312007-11-02 18:05:11 +0000351 return decl;
352}
353
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000354//===----------------------------------------------------------------------===//
Steve Naroff248a7532008-04-15 22:42:06 +0000355// ParmVarDecl Serialization.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000356//===----------------------------------------------------------------------===//
Ted Kremenek04973312007-11-02 18:05:11 +0000357
Ted Kremenek137bd912007-12-13 06:28:13 +0000358void ParmVarDecl::EmitImpl(llvm::Serializer& S) const {
359 VarDecl::EmitImpl(S);
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000360 S.EmitInt(getObjCDeclQualifier()); // From ParmVarDecl.
Chris Lattner04421082008-04-08 04:40:51 +0000361 S.EmitOwnedPtr(getDefaultArg()); // From ParmVarDecl.
Ted Kremenek137bd912007-12-13 06:28:13 +0000362}
363
Sam Bishope2563ca2008-04-07 21:55:54 +0000364ParmVarDecl* ParmVarDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000365 ParmVarDecl* decl = new (C)
Fariborz Jahanian4306d3c2008-12-20 23:29:59 +0000366 ParmVarDecl(ParmVar,
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000367 0, SourceLocation(), NULL, QualType(), None, NULL);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000368
Sam Bishope2563ca2008-04-07 21:55:54 +0000369 decl->VarDecl::ReadImpl(D, C);
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000370 decl->objcDeclQualifier = static_cast<ObjCDeclQualifier>(D.ReadInt());
Chris Lattner04421082008-04-08 04:40:51 +0000371 decl->DefaultArg = D.ReadOwnedPtr<Expr>(C);
Ted Kremenek04973312007-11-02 18:05:11 +0000372 return decl;
373}
374
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000375//===----------------------------------------------------------------------===//
Douglas Gregor64650af2009-02-02 23:39:07 +0000376// OriginalParmVarDecl Serialization.
Fariborz Jahanian73da9e42008-12-20 20:56:12 +0000377//===----------------------------------------------------------------------===//
378
Douglas Gregor64650af2009-02-02 23:39:07 +0000379void OriginalParmVarDecl::EmitImpl(llvm::Serializer& S) const {
Fariborz Jahanian73da9e42008-12-20 20:56:12 +0000380 ParmVarDecl::EmitImpl(S);
381 S.Emit(OriginalType);
382}
383
Douglas Gregor64650af2009-02-02 23:39:07 +0000384OriginalParmVarDecl* OriginalParmVarDecl::CreateImpl(
Fariborz Jahanian73da9e42008-12-20 20:56:12 +0000385 Deserializer& D, ASTContext& C) {
Douglas Gregor64650af2009-02-02 23:39:07 +0000386 OriginalParmVarDecl* decl = new (C)
387 OriginalParmVarDecl(0, SourceLocation(), NULL, QualType(),
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000388 QualType(), None, NULL);
Fariborz Jahanian73da9e42008-12-20 20:56:12 +0000389
390 decl->ParmVarDecl::ReadImpl(D, C);
391 decl->OriginalType = QualType::ReadVal(D);
392 return decl;
393}
394//===----------------------------------------------------------------------===//
Ted Kremenek583e0082007-11-14 18:12:19 +0000395// EnumDecl Serialization.
396//===----------------------------------------------------------------------===//
397
398void EnumDecl::EmitImpl(Serializer& S) const {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000399 NamedDecl::EmitInRec(S);
Ted Kremenek583e0082007-11-14 18:12:19 +0000400 S.EmitBool(isDefinition());
Douglas Gregor44b43212008-12-11 16:49:14 +0000401 S.Emit(IntegerType);
Ted Kremenek583e0082007-11-14 18:12:19 +0000402}
403
Sam Bishope2563ca2008-04-07 21:55:54 +0000404EnumDecl* EnumDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000405 EnumDecl* decl = new (C) EnumDecl(0, SourceLocation(), NULL);
Ted Kremenek583e0082007-11-14 18:12:19 +0000406
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000407 decl->NamedDecl::ReadInRec(D, C);
Ted Kremenek583e0082007-11-14 18:12:19 +0000408 decl->setDefinition(D.ReadBool());
409 decl->IntegerType = QualType::ReadVal(D);
410
Ted Kremenek583e0082007-11-14 18:12:19 +0000411 return decl;
412}
413
414//===----------------------------------------------------------------------===//
415// EnumConstantDecl Serialization.
416//===----------------------------------------------------------------------===//
417
418void EnumConstantDecl::EmitImpl(Serializer& S) const {
419 S.Emit(Val);
420 ValueDecl::EmitInRec(S);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000421 S.EmitOwnedPtr(Init);
Ted Kremenek583e0082007-11-14 18:12:19 +0000422}
423
Sam Bishope2563ca2008-04-07 21:55:54 +0000424EnumConstantDecl* EnumConstantDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Ted Kremenek049b1682007-11-14 23:38:09 +0000425 llvm::APSInt val(1);
Ted Kremenek583e0082007-11-14 18:12:19 +0000426 D.Read(val);
427
Steve Naroff3e970492009-01-27 21:25:57 +0000428 EnumConstantDecl* decl = new (C)
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000429 EnumConstantDecl(0, SourceLocation(), NULL, QualType(), NULL, val);
Ted Kremenek583e0082007-11-14 18:12:19 +0000430
Sam Bishope2563ca2008-04-07 21:55:54 +0000431 decl->ValueDecl::ReadInRec(D, C);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000432 decl->Init = D.ReadOwnedPtr<Stmt>(C);
Ted Kremenek583e0082007-11-14 18:12:19 +0000433 return decl;
434}
435
436//===----------------------------------------------------------------------===//
Ted Kremenekf9d56c82007-11-14 17:47:01 +0000437// FieldDecl Serialization.
438//===----------------------------------------------------------------------===//
439
440void FieldDecl::EmitImpl(Serializer& S) const {
Douglas Gregor44b43212008-12-11 16:49:14 +0000441 S.EmitBool(Mutable);
Ted Kremenekf9d56c82007-11-14 17:47:01 +0000442 S.Emit(getType());
Mike Stump080cc352009-02-10 20:06:48 +0000443 ValueDecl::EmitInRec(S);
Ted Kremenekf9d56c82007-11-14 17:47:01 +0000444 S.EmitOwnedPtr(BitWidth);
445}
446
Sam Bishope2563ca2008-04-07 21:55:54 +0000447FieldDecl* FieldDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000448 FieldDecl* decl = new (C) FieldDecl(Field, 0, SourceLocation(), NULL,
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000449 QualType(), 0, false);
Douglas Gregor44b43212008-12-11 16:49:14 +0000450 decl->Mutable = D.ReadBool();
Mike Stump080cc352009-02-10 20:06:48 +0000451 decl->ValueDecl::ReadInRec(D, C);
Sam Bishope2563ca2008-04-07 21:55:54 +0000452 decl->BitWidth = D.ReadOwnedPtr<Expr>(C);
Ted Kremenekf9d56c82007-11-14 17:47:01 +0000453 return decl;
454}
455
456//===----------------------------------------------------------------------===//
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000457// FunctionDecl Serialization.
458//===----------------------------------------------------------------------===//
Ted Kremenek04973312007-11-02 18:05:11 +0000459
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000460void FunctionDecl::EmitImpl(Serializer& S) const {
461 S.EmitInt(SClass); // From FunctionDecl.
462 S.EmitBool(IsInline); // From FunctionDecl.
463 ValueDecl::EmitInRec(S);
Ted Kremenek3bbc1982008-05-20 03:33:58 +0000464 S.EmitPtr(PreviousDeclaration);
Ted Kremenek04973312007-11-02 18:05:11 +0000465
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000466 // NOTE: We do not need to serialize out the number of parameters, because
467 // that is encoded in the type (accessed via getNumParams()).
Ted Kremenek04973312007-11-02 18:05:11 +0000468
Ted Kremenekd437f232007-11-13 22:51:08 +0000469 if (ParamInfo != NULL) {
470 S.EmitBool(true);
Argyrios Kyrtzidisdc5ddbf2008-11-07 14:22:23 +0000471 S.EmitInt(getNumParams());
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000472 S.BatchEmitOwnedPtrs(getNumParams(),&ParamInfo[0], Body);
Ted Kremenekd437f232007-11-13 22:51:08 +0000473 }
474 else {
475 S.EmitBool(false);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000476 S.EmitOwnedPtr(Body);
Ted Kremenekd437f232007-11-13 22:51:08 +0000477 }
Ted Kremenek04973312007-11-02 18:05:11 +0000478}
479
Sam Bishope2563ca2008-04-07 21:55:54 +0000480FunctionDecl* FunctionDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Ted Kremenek04973312007-11-02 18:05:11 +0000481 StorageClass SClass = static_cast<StorageClass>(D.ReadInt());
482 bool IsInline = D.ReadBool();
Ted Kremenek04973312007-11-02 18:05:11 +0000483
Steve Naroff3e970492009-01-27 21:25:57 +0000484 FunctionDecl* decl = new (C)
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000485 FunctionDecl(Function, 0, SourceLocation(), DeclarationName(),
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000486 QualType(), SClass, IsInline);
Ted Kremenek04973312007-11-02 18:05:11 +0000487
Sam Bishope2563ca2008-04-07 21:55:54 +0000488 decl->ValueDecl::ReadInRec(D, C);
Ted Kremenek3bbc1982008-05-20 03:33:58 +0000489 D.ReadPtr(decl->PreviousDeclaration);
Ted Kremenekda256852007-11-16 18:11:10 +0000490
Douglas Gregor6b54bd12009-01-05 17:18:30 +0000491 int numParams = 0;
Ted Kremenekd437f232007-11-13 22:51:08 +0000492 bool hasParamDecls = D.ReadBool();
Argyrios Kyrtzidisdc5ddbf2008-11-07 14:22:23 +0000493 if (hasParamDecls)
494 numParams = D.ReadInt();
Ted Kremenekda256852007-11-16 18:11:10 +0000495
496 decl->ParamInfo = hasParamDecls
Argyrios Kyrtzidisdc5ddbf2008-11-07 14:22:23 +0000497 ? new ParmVarDecl*[numParams]
Ted Kremenekda256852007-11-16 18:11:10 +0000498 : NULL;
Ted Kremenekd437f232007-11-13 22:51:08 +0000499
500 if (hasParamDecls)
Argyrios Kyrtzidisdc5ddbf2008-11-07 14:22:23 +0000501 D.BatchReadOwnedPtrs(numParams,
Ted Kremenekd437f232007-11-13 22:51:08 +0000502 reinterpret_cast<Decl**>(&decl->ParamInfo[0]),
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000503 decl->Body, C);
Ted Kremenekd437f232007-11-13 22:51:08 +0000504 else
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000505 decl->Body = D.ReadOwnedPtr<Stmt>(C);
Ted Kremenek04973312007-11-02 18:05:11 +0000506
507 return decl;
508}
Ted Kremenekf7bf4112007-11-05 21:49:34 +0000509
Steve Naroff56ee6892008-10-08 17:01:13 +0000510void BlockDecl::EmitImpl(Serializer& S) const {
511 // FIXME: what about arguments?
512 S.Emit(getCaretLocation());
513 S.EmitOwnedPtr(Body);
514}
515
516BlockDecl* BlockDecl::CreateImpl(Deserializer& D, ASTContext& C) {
517 QualType Q = QualType::ReadVal(D);
518 SourceLocation L = SourceLocation::ReadVal(D);
519 /*CompoundStmt* BodyStmt = cast<CompoundStmt>(*/D.ReadOwnedPtr<Stmt>(C)/*)*/;
520 assert(0 && "Cannot deserialize BlockBlockExpr yet");
521 // FIXME: need to handle parameters.
522 //return new BlockBlockExpr(L, Q, BodyStmt);
523 return 0;
524}
525
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000526//===----------------------------------------------------------------------===//
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000527// OverloadedFunctionDecl Serialization.
528//===----------------------------------------------------------------------===//
529
530void OverloadedFunctionDecl::EmitImpl(Serializer& S) const {
531 NamedDecl::EmitInRec(S);
532
533 S.EmitInt(getNumFunctions());
534 for (unsigned func = 0; func < getNumFunctions(); ++func)
535 S.EmitPtr(Functions[func]);
536}
537
538OverloadedFunctionDecl *
539OverloadedFunctionDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000540 OverloadedFunctionDecl* decl = new (C)
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000541 OverloadedFunctionDecl(0, DeclarationName());
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000542
543 decl->NamedDecl::ReadInRec(D, C);
544
545 unsigned numFunctions = D.ReadInt();
546 decl->Functions.reserve(numFunctions);
547 for (unsigned func = 0; func < numFunctions; ++func)
548 D.ReadPtr(decl->Functions[func]);
549
550 return decl;
551}
552
553//===----------------------------------------------------------------------===//
Ted Kremenekaad48b62007-11-14 08:06:37 +0000554// RecordDecl Serialization.
555//===----------------------------------------------------------------------===//
556
Ted Kremenek583e0082007-11-14 18:12:19 +0000557void RecordDecl::EmitImpl(Serializer& S) const {
Argyrios Kyrtzidis35bc0822008-10-15 00:42:39 +0000558 S.EmitInt(getTagKind());
559
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000560 NamedDecl::EmitInRec(S);
Ted Kremenek583e0082007-11-14 18:12:19 +0000561 S.EmitBool(isDefinition());
Ted Kremenekaad48b62007-11-14 08:06:37 +0000562 S.EmitBool(hasFlexibleArrayMember());
Douglas Gregorbcbffc42009-01-07 00:43:41 +0000563 S.EmitBool(isAnonymousStructOrUnion());
Ted Kremenekaad48b62007-11-14 08:06:37 +0000564}
565
Argyrios Kyrtzidis35bc0822008-10-15 00:42:39 +0000566RecordDecl* RecordDecl::CreateImpl(Deserializer& D, ASTContext& C) {
567 TagKind TK = TagKind(D.ReadInt());
Sam Bishope2563ca2008-04-07 21:55:54 +0000568
Steve Naroff3e970492009-01-27 21:25:57 +0000569 RecordDecl* decl = new (C) RecordDecl(Record, TK, 0, SourceLocation(), NULL);
Ted Kremenek583e0082007-11-14 18:12:19 +0000570
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000571 decl->NamedDecl::ReadInRec(D, C);
Ted Kremenek583e0082007-11-14 18:12:19 +0000572 decl->setDefinition(D.ReadBool());
Ted Kremenekaad48b62007-11-14 08:06:37 +0000573 decl->setHasFlexibleArrayMember(D.ReadBool());
Douglas Gregorbcbffc42009-01-07 00:43:41 +0000574 decl->setAnonymousStructOrUnion(D.ReadBool());
Douglas Gregor44b43212008-12-11 16:49:14 +0000575
Ted Kremenekaad48b62007-11-14 08:06:37 +0000576 return decl;
577}
578
579//===----------------------------------------------------------------------===//
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000580// TypedefDecl Serialization.
581//===----------------------------------------------------------------------===//
582
583void TypedefDecl::EmitImpl(Serializer& S) const {
Ted Kremenek2ebc89f2007-11-06 19:51:47 +0000584 S.Emit(UnderlyingType);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000585 NamedDecl::EmitInRec(S);
Ted Kremenekf7bf4112007-11-05 21:49:34 +0000586}
587
Sam Bishope2563ca2008-04-07 21:55:54 +0000588TypedefDecl* TypedefDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000589 QualType T = QualType::ReadVal(D);
590
Steve Naroff3e970492009-01-27 21:25:57 +0000591 TypedefDecl* decl = new (C) TypedefDecl(0, SourceLocation(), NULL, T);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000592
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000593 decl->NamedDecl::ReadInRec(D, C);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000594
Ted Kremenekf7bf4112007-11-05 21:49:34 +0000595 return decl;
596}
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000597
598//===----------------------------------------------------------------------===//
Douglas Gregor72c3f312008-12-05 18:15:24 +0000599// TemplateTypeParmDecl Serialization.
600//===----------------------------------------------------------------------===//
601
602void TemplateTypeParmDecl::EmitImpl(Serializer& S) const {
603 S.EmitBool(Typename);
Douglas Gregorfab9d672009-02-05 23:33:38 +0000604 TypeDecl::EmitInRec(S);
Douglas Gregor72c3f312008-12-05 18:15:24 +0000605}
606
607TemplateTypeParmDecl *
608TemplateTypeParmDecl::CreateImpl(Deserializer& D, ASTContext& C) {
609 bool Typename = D.ReadBool();
Douglas Gregor72c3f312008-12-05 18:15:24 +0000610 TemplateTypeParmDecl *decl
Douglas Gregorfab9d672009-02-05 23:33:38 +0000611 = new (C) TemplateTypeParmDecl(0, SourceLocation(), 0, Typename,
612 QualType());
613 decl->TypeDecl::ReadInRec(D, C);
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000614 return decl;
615}
616
617//===----------------------------------------------------------------------===//
618// NonTypeTemplateParmDecl Serialization.
619//===----------------------------------------------------------------------===//
620void NonTypeTemplateParmDecl::EmitImpl(Serializer& S) const {
621 S.EmitInt(Depth);
622 S.EmitInt(Position);
623 NamedDecl::Emit(S);
624}
625
626NonTypeTemplateParmDecl*
627NonTypeTemplateParmDecl::CreateImpl(Deserializer& D, ASTContext& C) {
628 unsigned Depth = D.ReadInt();
629 unsigned Position = D.ReadInt();
630 NonTypeTemplateParmDecl *decl
631 = new (C) NonTypeTemplateParmDecl(0, SourceLocation(), Depth, Position,
632 0, QualType(), SourceLocation());
633 decl->NamedDecl::ReadInRec(D, C);
634 return decl;
635}
636
637//===----------------------------------------------------------------------===//
638// TemplateTemplateParmDecl Serialization.
639//===----------------------------------------------------------------------===//
640void TemplateTemplateParmDecl::EmitImpl(Serializer& S) const {
641 S.EmitInt(Depth);
642 S.EmitInt(Position);
643 NamedDecl::EmitInRec(S);
644}
645
646TemplateTemplateParmDecl*
647TemplateTemplateParmDecl::CreateImpl(Deserializer& D, ASTContext& C) {
648 unsigned Depth = D.ReadInt();
649 unsigned Position = D.ReadInt();
650 TemplateTemplateParmDecl *decl
651 = new (C) TemplateTemplateParmDecl(0, SourceLocation(), Depth, Position,
652 0, 0);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000653 decl->NamedDecl::ReadInRec(D, C);
Douglas Gregor72c3f312008-12-05 18:15:24 +0000654 return decl;
655}
656
657//===----------------------------------------------------------------------===//
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000658// LinkageSpec Serialization.
659//===----------------------------------------------------------------------===//
660
661void LinkageSpecDecl::EmitInRec(Serializer& S) const {
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000662 S.EmitInt(getLanguage());
Douglas Gregorf44515a2008-12-16 22:23:02 +0000663 S.EmitBool(HadBraces);
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000664}
665
Sam Bishope2563ca2008-04-07 21:55:54 +0000666void LinkageSpecDecl::ReadInRec(Deserializer& D, ASTContext& C) {
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000667 Language = static_cast<LanguageIDs>(D.ReadInt());
Douglas Gregorf44515a2008-12-16 22:23:02 +0000668 HadBraces = D.ReadBool();
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000669}
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000670
671//===----------------------------------------------------------------------===//
672// FileScopeAsm Serialization.
673//===----------------------------------------------------------------------===//
674
675void FileScopeAsmDecl::EmitImpl(llvm::Serializer& S) const
676{
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000677 S.EmitOwnedPtr(AsmString);
678}
679
Sam Bishope2563ca2008-04-07 21:55:54 +0000680FileScopeAsmDecl* FileScopeAsmDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000681 FileScopeAsmDecl* decl = new (C) FileScopeAsmDecl(0, SourceLocation(), 0);
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000682
Sam Bishope2563ca2008-04-07 21:55:54 +0000683 decl->AsmString = cast<StringLiteral>(D.ReadOwnedPtr<Expr>(C));
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000684// D.ReadOwnedPtr(D.ReadOwnedPtr<StringLiteral>())<#T * * Ptr#>, <#bool AutoRegister#>)(decl->AsmString);
685
686 return decl;
687}