blob: acaced2468635fcd1eb1d1c0ee7eb6beedcfc8c2 [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.
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);
Chris Lattner244a67d2009-03-28 06:04:26 +000048 S.EmitOwnedPtr(NextDeclInContext);
Douglas Gregor4afa39d2009-01-20 01:17:11 +000049 } else {
50 S.EmitBool(false);
Chris Lattner244a67d2009-03-28 06:04:26 +000051 S.EmitPtr(NextDeclInContext);
Douglas Gregor4afa39d2009-01-20 01:17:11 +000052 }
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +000053}
54
Sam Bishope2563ca2008-04-07 21:55:54 +000055Decl* Decl::Create(Deserializer& D, ASTContext& C) {
Ted Kremenek928fd7f2007-11-13 00:15:39 +000056
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000057 Decl *Dcl;
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000058 Kind k = static_cast<Kind>(D.ReadInt());
Sam Bishope2563ca2008-04-07 21:55:54 +000059
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000060 switch (k) {
61 default:
62 assert (false && "Not implemented.");
Chris Lattner0ed844b2008-04-04 06:12:32 +000063
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +000064 case TranslationUnit:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000065 Dcl = TranslationUnitDecl::CreateImpl(D, C);
66 break;
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +000067
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +000068 case Namespace:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000069 Dcl = NamespaceDecl::CreateImpl(D, C);
70 break;
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +000071
Steve Naroff248a7532008-04-15 22:42:06 +000072 case Var:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000073 Dcl = VarDecl::CreateImpl(D, C);
74 break;
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000075
Ted Kremenek583e0082007-11-14 18:12:19 +000076 case Enum:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000077 Dcl = EnumDecl::CreateImpl(D, C);
78 break;
Ted Kremenek583e0082007-11-14 18:12:19 +000079
80 case EnumConstant:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000081 Dcl = EnumConstantDecl::CreateImpl(D, C);
82 break;
Ted Kremenek583e0082007-11-14 18:12:19 +000083
Ted Kremenekf9d56c82007-11-14 17:47:01 +000084 case Field:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000085 Dcl = FieldDecl::CreateImpl(D, C);
86 break;
Ted Kremenekf9d56c82007-11-14 17:47:01 +000087
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000088 case ParmVar:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000089 Dcl = ParmVarDecl::CreateImpl(D, C);
90 break;
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000091
Fariborz Jahanian73da9e42008-12-20 20:56:12 +000092 case OriginalParmVar:
Douglas Gregor64650af2009-02-02 23:39:07 +000093 Dcl = OriginalParmVarDecl::CreateImpl(D, C);
Fariborz Jahanian73da9e42008-12-20 20:56:12 +000094 break;
95
Ted Kremenek2ebc89f2007-11-06 19:51:47 +000096 case Function:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +000097 Dcl = FunctionDecl::CreateImpl(D, C);
98 break;
Douglas Gregor8e9bebd2008-10-21 16:13:35 +000099
100 case OverloadedFunction:
101 Dcl = OverloadedFunctionDecl::CreateImpl(D, C);
102 break;
103
Argyrios Kyrtzidis35bc0822008-10-15 00:42:39 +0000104 case Record:
105 Dcl = RecordDecl::CreateImpl(D, C);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000106 break;
Ted Kremenekaad48b62007-11-14 08:06:37 +0000107
Ted Kremenek2ebc89f2007-11-06 19:51:47 +0000108 case Typedef:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000109 Dcl = TypedefDecl::CreateImpl(D, C);
110 break;
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000111
Douglas Gregor72c3f312008-12-05 18:15:24 +0000112 case TemplateTypeParm:
113 Dcl = TemplateTypeParmDecl::CreateImpl(D, C);
114 break;
115
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000116 case FileScopeAsm:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000117 Dcl = FileScopeAsmDecl::CreateImpl(D, C);
118 break;
Ted Kremenek2ebc89f2007-11-06 19:51:47 +0000119 }
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000120
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000121 Dcl->Loc = SourceLocation::ReadVal(D); // From Decl.
122 Dcl->InvalidDecl = D.ReadBool();
123 // FIXME: HasAttrs?
124 Dcl->Implicit = D.ReadBool();
125 Dcl->Access = D.ReadInt();
126
Chris Lattner10d83792009-03-27 18:46:15 +0000127 assert(Dcl->DeclCtx.getOpaqueValue() == 0);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000128
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.
Chris Lattner10d83792009-03-27 18:46:15 +0000135 uintptr_t X;
136 D.ReadUIntPtr(X, SemaDCPtrID);
Chris Lattneree219fd2009-03-29 06:06:59 +0000137 Dcl->DeclCtx = reinterpret_cast<DeclContext*>(X);
138 } else {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000139 MultipleDC *MDC = new MultipleDC();
Chris Lattneree219fd2009-03-29 06:06:59 +0000140 Dcl->DeclCtx = MDC;
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000141 // 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 }
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)
Chris Lattner244a67d2009-03-28 06:04:26 +0000150 Dcl->NextDeclInContext = D.ReadOwnedPtr<Decl>(C);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000151 else
Chris Lattner244a67d2009-03-28 06:04:26 +0000152 D.ReadPtr(Dcl->NextDeclInContext);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000153 return Dcl;
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +0000154}
Ted Kremenek04973312007-11-02 18:05:11 +0000155
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000156//===----------------------------------------------------------------------===//
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000157// Common serialization logic for subclasses of DeclContext.
158//===----------------------------------------------------------------------===//
159
160void DeclContext::EmitOutRec(Serializer& S) const {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000161 bool Owned = !isFunctionOrMethod();
162 S.EmitBool(Owned);
163 if (Owned)
164 S.EmitOwnedPtr(FirstDecl);
165 else
166 S.EmitPtr(FirstDecl);
167 S.EmitPtr(LastDecl);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000168}
169
170void DeclContext::ReadOutRec(Deserializer& D, ASTContext& C) {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000171 bool Owned = D.ReadBool();
172 if (Owned)
173 FirstDecl = cast_or_null<Decl>(D.ReadOwnedPtr<Decl>(C));
174 else
175 D.ReadPtr(FirstDecl);
176 D.ReadPtr(LastDecl);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000177}
178
179//===----------------------------------------------------------------------===//
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000180// Common serialization logic for subclasses of NamedDecl.
181//===----------------------------------------------------------------------===//
182
183void NamedDecl::EmitInRec(Serializer& S) const {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000184 S.EmitInt(Name.getNameKind());
185
186 switch (Name.getNameKind()) {
187 case DeclarationName::Identifier:
188 S.EmitPtr(Name.getAsIdentifierInfo());
189 break;
190
191 case DeclarationName::ObjCZeroArgSelector:
192 case DeclarationName::ObjCOneArgSelector:
193 case DeclarationName::ObjCMultiArgSelector:
194 Name.getObjCSelector().Emit(S);
195 break;
196
197 case DeclarationName::CXXConstructorName:
198 case DeclarationName::CXXDestructorName:
199 case DeclarationName::CXXConversionFunctionName:
200 Name.getCXXNameType().Emit(S);
201 break;
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000202
203 case DeclarationName::CXXOperatorName:
204 S.EmitInt(Name.getCXXOverloadedOperator());
205 break;
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000206
207 case DeclarationName::CXXUsingDirective:
208 // No extra data to emit
209 break;
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000210 }
Ted Kremenek04973312007-11-02 18:05:11 +0000211}
212
Sam Bishope2563ca2008-04-07 21:55:54 +0000213void NamedDecl::ReadInRec(Deserializer& D, ASTContext& C) {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000214 DeclarationName::NameKind Kind
215 = static_cast<DeclarationName::NameKind>(D.ReadInt());
216 switch (Kind) {
217 case DeclarationName::Identifier: {
Ted Kremenekddf32da2009-01-21 00:42:24 +0000218 // Don't allow back-patching. The IdentifierInfo table must already
219 // be loaded.
220 Name = D.ReadPtr<IdentifierInfo>();
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000221 break;
222 }
223
224 case DeclarationName::ObjCZeroArgSelector:
225 case DeclarationName::ObjCOneArgSelector:
226 case DeclarationName::ObjCMultiArgSelector:
227 Name = Selector::ReadVal(D);
228 break;
229
230 case DeclarationName::CXXConstructorName:
231 Name = C.DeclarationNames.getCXXConstructorName(QualType::ReadVal(D));
232 break;
233
234 case DeclarationName::CXXDestructorName:
235 Name = C.DeclarationNames.getCXXDestructorName(QualType::ReadVal(D));
236 break;
237
238 case DeclarationName::CXXConversionFunctionName:
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000239 Name
240 = C.DeclarationNames.getCXXConversionFunctionName(QualType::ReadVal(D));
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000241 break;
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000242
243 case DeclarationName::CXXOperatorName: {
244 OverloadedOperatorKind Op
245 = static_cast<OverloadedOperatorKind>(D.ReadInt());
246 Name = C.DeclarationNames.getCXXOperatorName(Op);
247 break;
248 }
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000249
250 case DeclarationName::CXXUsingDirective:
251 Name = DeclarationName::getUsingDirectiveName();
252 break;
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000253 }
Ted Kremenek04973312007-11-02 18:05:11 +0000254}
255
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000256//===----------------------------------------------------------------------===//
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000257// Common serialization logic for subclasses of ValueDecl.
258//===----------------------------------------------------------------------===//
259
260void ValueDecl::EmitInRec(Serializer& S) const {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000261 NamedDecl::EmitInRec(S);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000262 S.Emit(getType()); // From ValueDecl.
263}
264
Sam Bishope2563ca2008-04-07 21:55:54 +0000265void ValueDecl::ReadInRec(Deserializer& D, ASTContext& C) {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000266 NamedDecl::ReadInRec(D, C);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000267 DeclType = QualType::ReadVal(D); // From ValueDecl.
268}
269
270//===----------------------------------------------------------------------===//
271// Common serialization logic for subclasses of VarDecl.
272//===----------------------------------------------------------------------===//
273
274void VarDecl::EmitInRec(Serializer& S) const {
275 ValueDecl::EmitInRec(S);
276 S.EmitInt(getStorageClass()); // From VarDecl.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000277}
278
Sam Bishope2563ca2008-04-07 21:55:54 +0000279void VarDecl::ReadInRec(Deserializer& D, ASTContext& C) {
280 ValueDecl::ReadInRec(D, C);
Fariborz Jahaniande7b4cd2007-12-13 00:54:18 +0000281 SClass = static_cast<StorageClass>(D.ReadInt()); // From VarDecl.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000282}
283
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000284void VarDecl::EmitOutRec(Serializer& S) const {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000285 // Emit this last because it will create a record of its own.
286 S.EmitOwnedPtr(getInit());
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000287}
288
Sam Bishope2563ca2008-04-07 21:55:54 +0000289void VarDecl::ReadOutRec(Deserializer& D, ASTContext& C) {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000290 Init = D.ReadOwnedPtr<Stmt>(C);
Ted Kremenek04973312007-11-02 18:05:11 +0000291}
292
293
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000294void VarDecl::EmitImpl(Serializer& S) const {
295 VarDecl::EmitInRec(S);
296 VarDecl::EmitOutRec(S);
Ted Kremenek04973312007-11-02 18:05:11 +0000297}
298
Sam Bishope2563ca2008-04-07 21:55:54 +0000299void VarDecl::ReadImpl(Deserializer& D, ASTContext& C) {
300 ReadInRec(D, C);
301 ReadOutRec(D, C);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000302}
303
304//===----------------------------------------------------------------------===//
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000305// TranslationUnitDecl Serialization.
306//===----------------------------------------------------------------------===//
307
308void TranslationUnitDecl::EmitImpl(llvm::Serializer& S) const
309{
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000310}
311
312TranslationUnitDecl* TranslationUnitDecl::CreateImpl(Deserializer& D,
313 ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000314 return new (C) TranslationUnitDecl();
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000315}
316
317//===----------------------------------------------------------------------===//
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000318// NamespaceDecl Serialization.
319//===----------------------------------------------------------------------===//
320
321void NamespaceDecl::EmitImpl(llvm::Serializer& S) const
322{
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000323 NamedDecl::EmitInRec(S);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000324 S.Emit(getLBracLoc());
325 S.Emit(getRBracLoc());
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000326}
327
328NamespaceDecl* NamespaceDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000329 NamespaceDecl* decl = new (C) NamespaceDecl(0, SourceLocation(), 0);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000330
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000331 decl->NamedDecl::ReadInRec(D, C);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000332 decl->LBracLoc = SourceLocation::ReadVal(D);
333 decl->RBracLoc = SourceLocation::ReadVal(D);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000334
335 return decl;
336}
337
338//===----------------------------------------------------------------------===//
Steve Naroff248a7532008-04-15 22:42:06 +0000339// VarDecl Serialization.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000340//===----------------------------------------------------------------------===//
341
Steve Naroff248a7532008-04-15 22:42:06 +0000342VarDecl* VarDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff248a7532008-04-15 22:42:06 +0000343 VarDecl* decl =
Steve Naroff3e970492009-01-27 21:25:57 +0000344 new (C) VarDecl(Var, 0, SourceLocation(), NULL, QualType(), None);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000345
Sam Bishope2563ca2008-04-07 21:55:54 +0000346 decl->VarDecl::ReadImpl(D, C);
Ted Kremenek04973312007-11-02 18:05:11 +0000347 return decl;
348}
349
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000350//===----------------------------------------------------------------------===//
Steve Naroff248a7532008-04-15 22:42:06 +0000351// ParmVarDecl Serialization.
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000352//===----------------------------------------------------------------------===//
Ted Kremenek04973312007-11-02 18:05:11 +0000353
Ted Kremenek137bd912007-12-13 06:28:13 +0000354void ParmVarDecl::EmitImpl(llvm::Serializer& S) const {
355 VarDecl::EmitImpl(S);
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000356 S.EmitInt(getObjCDeclQualifier()); // From ParmVarDecl.
Chris Lattner04421082008-04-08 04:40:51 +0000357 S.EmitOwnedPtr(getDefaultArg()); // From ParmVarDecl.
Ted Kremenek137bd912007-12-13 06:28:13 +0000358}
359
Sam Bishope2563ca2008-04-07 21:55:54 +0000360ParmVarDecl* ParmVarDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000361 ParmVarDecl* decl = new (C)
Fariborz Jahanian4306d3c2008-12-20 23:29:59 +0000362 ParmVarDecl(ParmVar,
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000363 0, SourceLocation(), NULL, QualType(), None, NULL);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000364
Sam Bishope2563ca2008-04-07 21:55:54 +0000365 decl->VarDecl::ReadImpl(D, C);
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000366 decl->objcDeclQualifier = static_cast<ObjCDeclQualifier>(D.ReadInt());
Chris Lattner04421082008-04-08 04:40:51 +0000367 decl->DefaultArg = D.ReadOwnedPtr<Expr>(C);
Ted Kremenek04973312007-11-02 18:05:11 +0000368 return decl;
369}
370
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000371//===----------------------------------------------------------------------===//
Douglas Gregor64650af2009-02-02 23:39:07 +0000372// OriginalParmVarDecl Serialization.
Fariborz Jahanian73da9e42008-12-20 20:56:12 +0000373//===----------------------------------------------------------------------===//
374
Douglas Gregor64650af2009-02-02 23:39:07 +0000375void OriginalParmVarDecl::EmitImpl(llvm::Serializer& S) const {
Fariborz Jahanian73da9e42008-12-20 20:56:12 +0000376 ParmVarDecl::EmitImpl(S);
377 S.Emit(OriginalType);
378}
379
Douglas Gregor64650af2009-02-02 23:39:07 +0000380OriginalParmVarDecl* OriginalParmVarDecl::CreateImpl(
Fariborz Jahanian73da9e42008-12-20 20:56:12 +0000381 Deserializer& D, ASTContext& C) {
Douglas Gregor64650af2009-02-02 23:39:07 +0000382 OriginalParmVarDecl* decl = new (C)
383 OriginalParmVarDecl(0, SourceLocation(), NULL, QualType(),
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000384 QualType(), None, NULL);
Fariborz Jahanian73da9e42008-12-20 20:56:12 +0000385
386 decl->ParmVarDecl::ReadImpl(D, C);
387 decl->OriginalType = QualType::ReadVal(D);
388 return decl;
389}
390//===----------------------------------------------------------------------===//
Ted Kremenek583e0082007-11-14 18:12:19 +0000391// EnumDecl Serialization.
392//===----------------------------------------------------------------------===//
393
394void EnumDecl::EmitImpl(Serializer& S) const {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000395 NamedDecl::EmitInRec(S);
Ted Kremenek583e0082007-11-14 18:12:19 +0000396 S.EmitBool(isDefinition());
Douglas Gregor44b43212008-12-11 16:49:14 +0000397 S.Emit(IntegerType);
Ted Kremenek583e0082007-11-14 18:12:19 +0000398}
399
Sam Bishope2563ca2008-04-07 21:55:54 +0000400EnumDecl* EnumDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000401 EnumDecl* decl = new (C) EnumDecl(0, SourceLocation(), NULL);
Ted Kremenek583e0082007-11-14 18:12:19 +0000402
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000403 decl->NamedDecl::ReadInRec(D, C);
Ted Kremenek583e0082007-11-14 18:12:19 +0000404 decl->setDefinition(D.ReadBool());
405 decl->IntegerType = QualType::ReadVal(D);
406
Ted Kremenek583e0082007-11-14 18:12:19 +0000407 return decl;
408}
409
410//===----------------------------------------------------------------------===//
411// EnumConstantDecl Serialization.
412//===----------------------------------------------------------------------===//
413
414void EnumConstantDecl::EmitImpl(Serializer& S) const {
415 S.Emit(Val);
416 ValueDecl::EmitInRec(S);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000417 S.EmitOwnedPtr(Init);
Ted Kremenek583e0082007-11-14 18:12:19 +0000418}
419
Sam Bishope2563ca2008-04-07 21:55:54 +0000420EnumConstantDecl* EnumConstantDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Ted Kremenek049b1682007-11-14 23:38:09 +0000421 llvm::APSInt val(1);
Ted Kremenek583e0082007-11-14 18:12:19 +0000422 D.Read(val);
423
Steve Naroff3e970492009-01-27 21:25:57 +0000424 EnumConstantDecl* decl = new (C)
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000425 EnumConstantDecl(0, SourceLocation(), NULL, QualType(), NULL, val);
Ted Kremenek583e0082007-11-14 18:12:19 +0000426
Sam Bishope2563ca2008-04-07 21:55:54 +0000427 decl->ValueDecl::ReadInRec(D, C);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000428 decl->Init = D.ReadOwnedPtr<Stmt>(C);
Ted Kremenek583e0082007-11-14 18:12:19 +0000429 return decl;
430}
431
432//===----------------------------------------------------------------------===//
Ted Kremenekf9d56c82007-11-14 17:47:01 +0000433// FieldDecl Serialization.
434//===----------------------------------------------------------------------===//
435
436void FieldDecl::EmitImpl(Serializer& S) const {
Douglas Gregor44b43212008-12-11 16:49:14 +0000437 S.EmitBool(Mutable);
Ted Kremenekf9d56c82007-11-14 17:47:01 +0000438 S.Emit(getType());
Mike Stump080cc352009-02-10 20:06:48 +0000439 ValueDecl::EmitInRec(S);
Ted Kremenekf9d56c82007-11-14 17:47:01 +0000440 S.EmitOwnedPtr(BitWidth);
441}
442
Sam Bishope2563ca2008-04-07 21:55:54 +0000443FieldDecl* FieldDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000444 FieldDecl* decl = new (C) FieldDecl(Field, 0, SourceLocation(), NULL,
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000445 QualType(), 0, false);
Douglas Gregor44b43212008-12-11 16:49:14 +0000446 decl->Mutable = D.ReadBool();
Mike Stump080cc352009-02-10 20:06:48 +0000447 decl->ValueDecl::ReadInRec(D, C);
Sam Bishope2563ca2008-04-07 21:55:54 +0000448 decl->BitWidth = D.ReadOwnedPtr<Expr>(C);
Ted Kremenekf9d56c82007-11-14 17:47:01 +0000449 return decl;
450}
451
452//===----------------------------------------------------------------------===//
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000453// FunctionDecl Serialization.
454//===----------------------------------------------------------------------===//
Ted Kremenek04973312007-11-02 18:05:11 +0000455
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000456void FunctionDecl::EmitImpl(Serializer& S) const {
457 S.EmitInt(SClass); // From FunctionDecl.
458 S.EmitBool(IsInline); // From FunctionDecl.
459 ValueDecl::EmitInRec(S);
Ted Kremenek3bbc1982008-05-20 03:33:58 +0000460 S.EmitPtr(PreviousDeclaration);
Ted Kremenek04973312007-11-02 18:05:11 +0000461
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000462 // NOTE: We do not need to serialize out the number of parameters, because
463 // that is encoded in the type (accessed via getNumParams()).
Ted Kremenek04973312007-11-02 18:05:11 +0000464
Ted Kremenekd437f232007-11-13 22:51:08 +0000465 if (ParamInfo != NULL) {
466 S.EmitBool(true);
Argyrios Kyrtzidisdc5ddbf2008-11-07 14:22:23 +0000467 S.EmitInt(getNumParams());
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000468 S.BatchEmitOwnedPtrs(getNumParams(),&ParamInfo[0], Body);
Ted Kremenekd437f232007-11-13 22:51:08 +0000469 }
470 else {
471 S.EmitBool(false);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000472 S.EmitOwnedPtr(Body);
Ted Kremenekd437f232007-11-13 22:51:08 +0000473 }
Ted Kremenek04973312007-11-02 18:05:11 +0000474}
475
Sam Bishope2563ca2008-04-07 21:55:54 +0000476FunctionDecl* FunctionDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Ted Kremenek04973312007-11-02 18:05:11 +0000477 StorageClass SClass = static_cast<StorageClass>(D.ReadInt());
478 bool IsInline = D.ReadBool();
Ted Kremenek04973312007-11-02 18:05:11 +0000479
Steve Naroff3e970492009-01-27 21:25:57 +0000480 FunctionDecl* decl = new (C)
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000481 FunctionDecl(Function, 0, SourceLocation(), DeclarationName(),
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000482 QualType(), SClass, IsInline);
Ted Kremenek04973312007-11-02 18:05:11 +0000483
Sam Bishope2563ca2008-04-07 21:55:54 +0000484 decl->ValueDecl::ReadInRec(D, C);
Ted Kremenek3bbc1982008-05-20 03:33:58 +0000485 D.ReadPtr(decl->PreviousDeclaration);
Ted Kremenekda256852007-11-16 18:11:10 +0000486
Douglas Gregor6b54bd12009-01-05 17:18:30 +0000487 int numParams = 0;
Ted Kremenekd437f232007-11-13 22:51:08 +0000488 bool hasParamDecls = D.ReadBool();
Argyrios Kyrtzidisdc5ddbf2008-11-07 14:22:23 +0000489 if (hasParamDecls)
490 numParams = D.ReadInt();
Ted Kremenekda256852007-11-16 18:11:10 +0000491
492 decl->ParamInfo = hasParamDecls
Argyrios Kyrtzidisdc5ddbf2008-11-07 14:22:23 +0000493 ? new ParmVarDecl*[numParams]
Ted Kremenekda256852007-11-16 18:11:10 +0000494 : NULL;
Ted Kremenekd437f232007-11-13 22:51:08 +0000495
496 if (hasParamDecls)
Argyrios Kyrtzidisdc5ddbf2008-11-07 14:22:23 +0000497 D.BatchReadOwnedPtrs(numParams,
Ted Kremenekd437f232007-11-13 22:51:08 +0000498 reinterpret_cast<Decl**>(&decl->ParamInfo[0]),
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000499 decl->Body, C);
Ted Kremenekd437f232007-11-13 22:51:08 +0000500 else
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000501 decl->Body = D.ReadOwnedPtr<Stmt>(C);
Ted Kremenek04973312007-11-02 18:05:11 +0000502
503 return decl;
504}
Ted Kremenekf7bf4112007-11-05 21:49:34 +0000505
Steve Naroff56ee6892008-10-08 17:01:13 +0000506void BlockDecl::EmitImpl(Serializer& S) const {
507 // FIXME: what about arguments?
508 S.Emit(getCaretLocation());
509 S.EmitOwnedPtr(Body);
510}
511
512BlockDecl* BlockDecl::CreateImpl(Deserializer& D, ASTContext& C) {
513 QualType Q = QualType::ReadVal(D);
514 SourceLocation L = SourceLocation::ReadVal(D);
515 /*CompoundStmt* BodyStmt = cast<CompoundStmt>(*/D.ReadOwnedPtr<Stmt>(C)/*)*/;
516 assert(0 && "Cannot deserialize BlockBlockExpr yet");
517 // FIXME: need to handle parameters.
518 //return new BlockBlockExpr(L, Q, BodyStmt);
519 return 0;
520}
521
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000522//===----------------------------------------------------------------------===//
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000523// OverloadedFunctionDecl Serialization.
524//===----------------------------------------------------------------------===//
525
526void OverloadedFunctionDecl::EmitImpl(Serializer& S) const {
527 NamedDecl::EmitInRec(S);
528
529 S.EmitInt(getNumFunctions());
530 for (unsigned func = 0; func < getNumFunctions(); ++func)
531 S.EmitPtr(Functions[func]);
532}
533
534OverloadedFunctionDecl *
535OverloadedFunctionDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000536 OverloadedFunctionDecl* decl = new (C)
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000537 OverloadedFunctionDecl(0, DeclarationName());
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000538
539 decl->NamedDecl::ReadInRec(D, C);
540
541 unsigned numFunctions = D.ReadInt();
542 decl->Functions.reserve(numFunctions);
543 for (unsigned func = 0; func < numFunctions; ++func)
544 D.ReadPtr(decl->Functions[func]);
545
546 return decl;
547}
548
549//===----------------------------------------------------------------------===//
Ted Kremenekaad48b62007-11-14 08:06:37 +0000550// RecordDecl Serialization.
551//===----------------------------------------------------------------------===//
552
Ted Kremenek583e0082007-11-14 18:12:19 +0000553void RecordDecl::EmitImpl(Serializer& S) const {
Argyrios Kyrtzidis35bc0822008-10-15 00:42:39 +0000554 S.EmitInt(getTagKind());
555
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000556 NamedDecl::EmitInRec(S);
Ted Kremenek583e0082007-11-14 18:12:19 +0000557 S.EmitBool(isDefinition());
Ted Kremenekaad48b62007-11-14 08:06:37 +0000558 S.EmitBool(hasFlexibleArrayMember());
Douglas Gregorbcbffc42009-01-07 00:43:41 +0000559 S.EmitBool(isAnonymousStructOrUnion());
Ted Kremenekaad48b62007-11-14 08:06:37 +0000560}
561
Argyrios Kyrtzidis35bc0822008-10-15 00:42:39 +0000562RecordDecl* RecordDecl::CreateImpl(Deserializer& D, ASTContext& C) {
563 TagKind TK = TagKind(D.ReadInt());
Sam Bishope2563ca2008-04-07 21:55:54 +0000564
Steve Naroff3e970492009-01-27 21:25:57 +0000565 RecordDecl* decl = new (C) RecordDecl(Record, TK, 0, SourceLocation(), NULL);
Ted Kremenek583e0082007-11-14 18:12:19 +0000566
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000567 decl->NamedDecl::ReadInRec(D, C);
Ted Kremenek583e0082007-11-14 18:12:19 +0000568 decl->setDefinition(D.ReadBool());
Ted Kremenekaad48b62007-11-14 08:06:37 +0000569 decl->setHasFlexibleArrayMember(D.ReadBool());
Douglas Gregorbcbffc42009-01-07 00:43:41 +0000570 decl->setAnonymousStructOrUnion(D.ReadBool());
Douglas Gregor44b43212008-12-11 16:49:14 +0000571
Ted Kremenekaad48b62007-11-14 08:06:37 +0000572 return decl;
573}
574
575//===----------------------------------------------------------------------===//
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000576// TypedefDecl Serialization.
577//===----------------------------------------------------------------------===//
578
579void TypedefDecl::EmitImpl(Serializer& S) const {
Ted Kremenek2ebc89f2007-11-06 19:51:47 +0000580 S.Emit(UnderlyingType);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000581 NamedDecl::EmitInRec(S);
Ted Kremenekf7bf4112007-11-05 21:49:34 +0000582}
583
Sam Bishope2563ca2008-04-07 21:55:54 +0000584TypedefDecl* TypedefDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000585 QualType T = QualType::ReadVal(D);
586
Steve Naroff3e970492009-01-27 21:25:57 +0000587 TypedefDecl* decl = new (C) TypedefDecl(0, SourceLocation(), NULL, T);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000588
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000589 decl->NamedDecl::ReadInRec(D, C);
Ted Kremenek928fd7f2007-11-13 00:15:39 +0000590
Ted Kremenekf7bf4112007-11-05 21:49:34 +0000591 return decl;
592}
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000593
594//===----------------------------------------------------------------------===//
Douglas Gregor72c3f312008-12-05 18:15:24 +0000595// TemplateTypeParmDecl Serialization.
596//===----------------------------------------------------------------------===//
597
598void TemplateTypeParmDecl::EmitImpl(Serializer& S) const {
599 S.EmitBool(Typename);
Douglas Gregorfab9d672009-02-05 23:33:38 +0000600 TypeDecl::EmitInRec(S);
Douglas Gregor72c3f312008-12-05 18:15:24 +0000601}
602
603TemplateTypeParmDecl *
604TemplateTypeParmDecl::CreateImpl(Deserializer& D, ASTContext& C) {
605 bool Typename = D.ReadBool();
Douglas Gregor72c3f312008-12-05 18:15:24 +0000606 TemplateTypeParmDecl *decl
Douglas Gregorfab9d672009-02-05 23:33:38 +0000607 = new (C) TemplateTypeParmDecl(0, SourceLocation(), 0, Typename,
608 QualType());
609 decl->TypeDecl::ReadInRec(D, C);
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000610 return decl;
611}
612
613//===----------------------------------------------------------------------===//
614// NonTypeTemplateParmDecl Serialization.
615//===----------------------------------------------------------------------===//
616void NonTypeTemplateParmDecl::EmitImpl(Serializer& S) const {
617 S.EmitInt(Depth);
618 S.EmitInt(Position);
619 NamedDecl::Emit(S);
620}
621
622NonTypeTemplateParmDecl*
623NonTypeTemplateParmDecl::CreateImpl(Deserializer& D, ASTContext& C) {
624 unsigned Depth = D.ReadInt();
625 unsigned Position = D.ReadInt();
626 NonTypeTemplateParmDecl *decl
627 = new (C) NonTypeTemplateParmDecl(0, SourceLocation(), Depth, Position,
628 0, QualType(), SourceLocation());
629 decl->NamedDecl::ReadInRec(D, C);
630 return decl;
631}
632
633//===----------------------------------------------------------------------===//
634// TemplateTemplateParmDecl Serialization.
635//===----------------------------------------------------------------------===//
636void TemplateTemplateParmDecl::EmitImpl(Serializer& S) const {
637 S.EmitInt(Depth);
638 S.EmitInt(Position);
639 NamedDecl::EmitInRec(S);
640}
641
642TemplateTemplateParmDecl*
643TemplateTemplateParmDecl::CreateImpl(Deserializer& D, ASTContext& C) {
644 unsigned Depth = D.ReadInt();
645 unsigned Position = D.ReadInt();
646 TemplateTemplateParmDecl *decl
647 = new (C) TemplateTemplateParmDecl(0, SourceLocation(), Depth, Position,
648 0, 0);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000649 decl->NamedDecl::ReadInRec(D, C);
Douglas Gregor72c3f312008-12-05 18:15:24 +0000650 return decl;
651}
652
653//===----------------------------------------------------------------------===//
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000654// LinkageSpec Serialization.
655//===----------------------------------------------------------------------===//
656
657void LinkageSpecDecl::EmitInRec(Serializer& S) const {
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000658 S.EmitInt(getLanguage());
Douglas Gregorf44515a2008-12-16 22:23:02 +0000659 S.EmitBool(HadBraces);
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000660}
661
Sam Bishope2563ca2008-04-07 21:55:54 +0000662void LinkageSpecDecl::ReadInRec(Deserializer& D, ASTContext& C) {
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000663 Language = static_cast<LanguageIDs>(D.ReadInt());
Douglas Gregorf44515a2008-12-16 22:23:02 +0000664 HadBraces = D.ReadBool();
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000665}
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000666
667//===----------------------------------------------------------------------===//
668// FileScopeAsm Serialization.
669//===----------------------------------------------------------------------===//
670
671void FileScopeAsmDecl::EmitImpl(llvm::Serializer& S) const
672{
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000673 S.EmitOwnedPtr(AsmString);
674}
675
Sam Bishope2563ca2008-04-07 21:55:54 +0000676FileScopeAsmDecl* FileScopeAsmDecl::CreateImpl(Deserializer& D, ASTContext& C) {
Steve Naroff3e970492009-01-27 21:25:57 +0000677 FileScopeAsmDecl* decl = new (C) FileScopeAsmDecl(0, SourceLocation(), 0);
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000678
Sam Bishope2563ca2008-04-07 21:55:54 +0000679 decl->AsmString = cast<StringLiteral>(D.ReadOwnedPtr<Expr>(C));
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000680// D.ReadOwnedPtr(D.ReadOwnedPtr<StringLiteral>())<#T * * Ptr#>, <#bool AutoRegister#>)(decl->AsmString);
681
682 return decl;
683}