Ted Kremenek | 2f1f8cb | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 1 | //===--- DeclSerialization.cpp - Serialization of Decls ---------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Ted Kremenek | 2f1f8cb | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Gabor Greif | 843e934 | 2008-03-06 10:40:09 +0000 | [diff] [blame] | 10 | // This file defines methods that implement bitcode serialization for Decls. |
Ted Kremenek | 2f1f8cb | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Sam Bishop | f3c63ae | 2008-04-11 14:49:10 +0000 | [diff] [blame] | 14 | #include "clang/AST/ASTContext.h" |
Ted Kremenek | 2f1f8cb | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 15 | #include "clang/AST/Decl.h" |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclCXX.h" |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclTemplate.h" |
Ted Kremenek | 2f1f8cb | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 18 | #include "clang/AST/Expr.h" |
| 19 | #include "llvm/Bitcode/Serialize.h" |
| 20 | #include "llvm/Bitcode/Deserialize.h" |
| 21 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 22 | using llvm::Serializer; |
| 23 | using llvm::Deserializer; |
| 24 | using llvm::SerializedPtrID; |
| 25 | |
Ted Kremenek | 2f1f8cb | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 26 | using namespace clang; |
| 27 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 28 | //===----------------------------------------------------------------------===// |
| 29 | // Decl Serialization: Dispatch code to handle specialized decl types. |
| 30 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 8af8fe3 | 2007-11-05 21:38:00 +0000 | [diff] [blame] | 31 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 32 | void Decl::Emit(Serializer& S) const { |
| 33 | S.EmitInt(getKind()); |
| 34 | EmitImpl(S); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 35 | S.Emit(getLocation()); |
| 36 | S.EmitBool(InvalidDecl); |
| 37 | // FIXME: HasAttrs? |
| 38 | S.EmitBool(Implicit); |
Douglas Gregor | 3050ed4 | 2009-04-02 23:40:00 +0000 | [diff] [blame] | 39 | S.EmitInt(IdentifierNamespace); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 40 | S.EmitInt(Access); |
| 41 | S.EmitPtr(cast_or_null<Decl>(getDeclContext())); // From Decl. |
| 42 | S.EmitPtr(cast_or_null<Decl>(getLexicalDeclContext())); // From Decl. |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 43 | if (const DeclContext *DC = dyn_cast<const DeclContext>(this)) |
| 44 | DC->EmitOutRec(S); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 45 | |
| 46 | if (getDeclContext() && |
| 47 | !getDeclContext()->isFunctionOrMethod()) { |
| 48 | S.EmitBool(true); |
Chris Lattner | 244a67d | 2009-03-28 06:04:26 +0000 | [diff] [blame] | 49 | S.EmitOwnedPtr(NextDeclInContext); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 50 | } else { |
| 51 | S.EmitBool(false); |
Chris Lattner | 244a67d | 2009-03-28 06:04:26 +0000 | [diff] [blame] | 52 | S.EmitPtr(NextDeclInContext); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 53 | } |
Ted Kremenek | 2f1f8cb | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 56 | Decl* Decl::Create(Deserializer& D, ASTContext& C) { |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 57 | |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 58 | Decl *Dcl; |
Ted Kremenek | 2ebc89f | 2007-11-06 19:51:47 +0000 | [diff] [blame] | 59 | Kind k = static_cast<Kind>(D.ReadInt()); |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 60 | |
Ted Kremenek | 2ebc89f | 2007-11-06 19:51:47 +0000 | [diff] [blame] | 61 | switch (k) { |
| 62 | default: |
| 63 | assert (false && "Not implemented."); |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 64 | |
Argyrios Kyrtzidis | ef17782 | 2008-04-17 14:40:12 +0000 | [diff] [blame] | 65 | case TranslationUnit: |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 66 | Dcl = TranslationUnitDecl::CreateImpl(D, C); |
| 67 | break; |
Argyrios Kyrtzidis | ef17782 | 2008-04-17 14:40:12 +0000 | [diff] [blame] | 68 | |
Argyrios Kyrtzidis | 2d1c5d3 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 69 | case Namespace: |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 70 | Dcl = NamespaceDecl::CreateImpl(D, C); |
| 71 | break; |
Argyrios Kyrtzidis | 2d1c5d3 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 72 | |
Steve Naroff | 248a753 | 2008-04-15 22:42:06 +0000 | [diff] [blame] | 73 | case Var: |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 74 | Dcl = VarDecl::CreateImpl(D, C); |
| 75 | break; |
Ted Kremenek | 2ebc89f | 2007-11-06 19:51:47 +0000 | [diff] [blame] | 76 | |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 77 | case Enum: |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 78 | Dcl = EnumDecl::CreateImpl(D, C); |
| 79 | break; |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 80 | |
| 81 | case EnumConstant: |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 82 | Dcl = EnumConstantDecl::CreateImpl(D, C); |
| 83 | break; |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 84 | |
Ted Kremenek | f9d56c8 | 2007-11-14 17:47:01 +0000 | [diff] [blame] | 85 | case Field: |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 86 | Dcl = FieldDecl::CreateImpl(D, C); |
| 87 | break; |
Ted Kremenek | f9d56c8 | 2007-11-14 17:47:01 +0000 | [diff] [blame] | 88 | |
Ted Kremenek | 2ebc89f | 2007-11-06 19:51:47 +0000 | [diff] [blame] | 89 | case ParmVar: |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 90 | Dcl = ParmVarDecl::CreateImpl(D, C); |
| 91 | break; |
Ted Kremenek | 2ebc89f | 2007-11-06 19:51:47 +0000 | [diff] [blame] | 92 | |
Fariborz Jahanian | 73da9e4 | 2008-12-20 20:56:12 +0000 | [diff] [blame] | 93 | case OriginalParmVar: |
Douglas Gregor | 64650af | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 94 | Dcl = OriginalParmVarDecl::CreateImpl(D, C); |
Fariborz Jahanian | 73da9e4 | 2008-12-20 20:56:12 +0000 | [diff] [blame] | 95 | break; |
| 96 | |
Ted Kremenek | 2ebc89f | 2007-11-06 19:51:47 +0000 | [diff] [blame] | 97 | case Function: |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 98 | Dcl = FunctionDecl::CreateImpl(D, C); |
| 99 | break; |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 100 | |
| 101 | case OverloadedFunction: |
| 102 | Dcl = OverloadedFunctionDecl::CreateImpl(D, C); |
| 103 | break; |
| 104 | |
Argyrios Kyrtzidis | 35bc082 | 2008-10-15 00:42:39 +0000 | [diff] [blame] | 105 | case Record: |
| 106 | Dcl = RecordDecl::CreateImpl(D, C); |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 107 | break; |
Ted Kremenek | aad48b6 | 2007-11-14 08:06:37 +0000 | [diff] [blame] | 108 | |
Ted Kremenek | 2ebc89f | 2007-11-06 19:51:47 +0000 | [diff] [blame] | 109 | case Typedef: |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 110 | Dcl = TypedefDecl::CreateImpl(D, C); |
| 111 | break; |
Anders Carlsson | dfab6cb | 2008-02-08 00:33:21 +0000 | [diff] [blame] | 112 | |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 113 | case TemplateTypeParm: |
| 114 | Dcl = TemplateTypeParmDecl::CreateImpl(D, C); |
| 115 | break; |
| 116 | |
Anders Carlsson | dfab6cb | 2008-02-08 00:33:21 +0000 | [diff] [blame] | 117 | case FileScopeAsm: |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 118 | Dcl = FileScopeAsmDecl::CreateImpl(D, C); |
| 119 | break; |
Ted Kremenek | 2ebc89f | 2007-11-06 19:51:47 +0000 | [diff] [blame] | 120 | } |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 121 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 122 | Dcl->Loc = SourceLocation::ReadVal(D); // From Decl. |
| 123 | Dcl->InvalidDecl = D.ReadBool(); |
| 124 | // FIXME: HasAttrs? |
| 125 | Dcl->Implicit = D.ReadBool(); |
Douglas Gregor | 3050ed4 | 2009-04-02 23:40:00 +0000 | [diff] [blame] | 126 | Dcl->IdentifierNamespace = D.ReadInt(); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 127 | Dcl->Access = D.ReadInt(); |
| 128 | |
Chris Lattner | 10d8379 | 2009-03-27 18:46:15 +0000 | [diff] [blame] | 129 | assert(Dcl->DeclCtx.getOpaqueValue() == 0); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 130 | |
| 131 | const SerializedPtrID &SemaDCPtrID = D.ReadPtrID(); |
| 132 | const SerializedPtrID &LexicalDCPtrID = D.ReadPtrID(); |
| 133 | |
| 134 | if (SemaDCPtrID == LexicalDCPtrID) { |
| 135 | // Allow back-patching. Observe that we register the variable of the |
| 136 | // *object* for back-patching. Its actual value will get filled in later. |
Chris Lattner | 10d8379 | 2009-03-27 18:46:15 +0000 | [diff] [blame] | 137 | uintptr_t X; |
| 138 | D.ReadUIntPtr(X, SemaDCPtrID); |
Chris Lattner | ee219fd | 2009-03-29 06:06:59 +0000 | [diff] [blame] | 139 | Dcl->DeclCtx = reinterpret_cast<DeclContext*>(X); |
| 140 | } else { |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 141 | MultipleDC *MDC = new MultipleDC(); |
Chris Lattner | ee219fd | 2009-03-29 06:06:59 +0000 | [diff] [blame] | 142 | Dcl->DeclCtx = MDC; |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 143 | // Allow back-patching. Observe that we register the variable of the |
| 144 | // *object* for back-patching. Its actual value will get filled in later. |
| 145 | D.ReadPtr(MDC->SemanticDC, SemaDCPtrID); |
| 146 | D.ReadPtr(MDC->LexicalDC, LexicalDCPtrID); |
| 147 | } |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 148 | if (DeclContext *DC = dyn_cast<DeclContext>(Dcl)) |
| 149 | DC->ReadOutRec(D, C); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 150 | bool OwnsNext = D.ReadBool(); |
| 151 | if (OwnsNext) |
Chris Lattner | 244a67d | 2009-03-28 06:04:26 +0000 | [diff] [blame] | 152 | Dcl->NextDeclInContext = D.ReadOwnedPtr<Decl>(C); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 153 | else |
Chris Lattner | 244a67d | 2009-03-28 06:04:26 +0000 | [diff] [blame] | 154 | D.ReadPtr(Dcl->NextDeclInContext); |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 155 | return Dcl; |
Ted Kremenek | 2f1f8cb | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 156 | } |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 157 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 158 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 159 | // Common serialization logic for subclasses of DeclContext. |
| 160 | //===----------------------------------------------------------------------===// |
| 161 | |
| 162 | void DeclContext::EmitOutRec(Serializer& S) const { |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 163 | bool Owned = !isFunctionOrMethod(); |
| 164 | S.EmitBool(Owned); |
| 165 | if (Owned) |
| 166 | S.EmitOwnedPtr(FirstDecl); |
| 167 | else |
| 168 | S.EmitPtr(FirstDecl); |
| 169 | S.EmitPtr(LastDecl); |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | void DeclContext::ReadOutRec(Deserializer& D, ASTContext& C) { |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 173 | bool Owned = D.ReadBool(); |
| 174 | if (Owned) |
| 175 | FirstDecl = cast_or_null<Decl>(D.ReadOwnedPtr<Decl>(C)); |
| 176 | else |
| 177 | D.ReadPtr(FirstDecl); |
| 178 | D.ReadPtr(LastDecl); |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 182 | // Common serialization logic for subclasses of NamedDecl. |
| 183 | //===----------------------------------------------------------------------===// |
| 184 | |
| 185 | void NamedDecl::EmitInRec(Serializer& S) const { |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 186 | S.EmitInt(Name.getNameKind()); |
| 187 | |
| 188 | switch (Name.getNameKind()) { |
| 189 | case DeclarationName::Identifier: |
| 190 | S.EmitPtr(Name.getAsIdentifierInfo()); |
| 191 | break; |
| 192 | |
| 193 | case DeclarationName::ObjCZeroArgSelector: |
| 194 | case DeclarationName::ObjCOneArgSelector: |
| 195 | case DeclarationName::ObjCMultiArgSelector: |
| 196 | Name.getObjCSelector().Emit(S); |
| 197 | break; |
| 198 | |
| 199 | case DeclarationName::CXXConstructorName: |
| 200 | case DeclarationName::CXXDestructorName: |
| 201 | case DeclarationName::CXXConversionFunctionName: |
| 202 | Name.getCXXNameType().Emit(S); |
| 203 | break; |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 204 | |
| 205 | case DeclarationName::CXXOperatorName: |
| 206 | S.EmitInt(Name.getCXXOverloadedOperator()); |
| 207 | break; |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 208 | |
| 209 | case DeclarationName::CXXUsingDirective: |
| 210 | // No extra data to emit |
| 211 | break; |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 212 | } |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 215 | void NamedDecl::ReadInRec(Deserializer& D, ASTContext& C) { |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 216 | DeclarationName::NameKind Kind |
| 217 | = static_cast<DeclarationName::NameKind>(D.ReadInt()); |
| 218 | switch (Kind) { |
| 219 | case DeclarationName::Identifier: { |
Ted Kremenek | ddf32da | 2009-01-21 00:42:24 +0000 | [diff] [blame] | 220 | // Don't allow back-patching. The IdentifierInfo table must already |
| 221 | // be loaded. |
| 222 | Name = D.ReadPtr<IdentifierInfo>(); |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 223 | break; |
| 224 | } |
| 225 | |
| 226 | case DeclarationName::ObjCZeroArgSelector: |
| 227 | case DeclarationName::ObjCOneArgSelector: |
| 228 | case DeclarationName::ObjCMultiArgSelector: |
| 229 | Name = Selector::ReadVal(D); |
| 230 | break; |
| 231 | |
| 232 | case DeclarationName::CXXConstructorName: |
| 233 | Name = C.DeclarationNames.getCXXConstructorName(QualType::ReadVal(D)); |
| 234 | break; |
| 235 | |
| 236 | case DeclarationName::CXXDestructorName: |
| 237 | Name = C.DeclarationNames.getCXXDestructorName(QualType::ReadVal(D)); |
| 238 | break; |
| 239 | |
| 240 | case DeclarationName::CXXConversionFunctionName: |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 241 | Name |
| 242 | = C.DeclarationNames.getCXXConversionFunctionName(QualType::ReadVal(D)); |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 243 | break; |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 244 | |
| 245 | case DeclarationName::CXXOperatorName: { |
| 246 | OverloadedOperatorKind Op |
| 247 | = static_cast<OverloadedOperatorKind>(D.ReadInt()); |
| 248 | Name = C.DeclarationNames.getCXXOperatorName(Op); |
| 249 | break; |
| 250 | } |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 251 | |
| 252 | case DeclarationName::CXXUsingDirective: |
| 253 | Name = DeclarationName::getUsingDirectiveName(); |
| 254 | break; |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 255 | } |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 256 | } |
| 257 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 258 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 259 | // Common serialization logic for subclasses of ValueDecl. |
| 260 | //===----------------------------------------------------------------------===// |
| 261 | |
| 262 | void ValueDecl::EmitInRec(Serializer& S) const { |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 263 | NamedDecl::EmitInRec(S); |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 264 | S.Emit(getType()); // From ValueDecl. |
| 265 | } |
| 266 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 267 | void ValueDecl::ReadInRec(Deserializer& D, ASTContext& C) { |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 268 | NamedDecl::ReadInRec(D, C); |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 269 | DeclType = QualType::ReadVal(D); // From ValueDecl. |
| 270 | } |
| 271 | |
| 272 | //===----------------------------------------------------------------------===// |
| 273 | // Common serialization logic for subclasses of VarDecl. |
| 274 | //===----------------------------------------------------------------------===// |
| 275 | |
| 276 | void VarDecl::EmitInRec(Serializer& S) const { |
| 277 | ValueDecl::EmitInRec(S); |
| 278 | S.EmitInt(getStorageClass()); // From VarDecl. |
Douglas Gregor | 3050ed4 | 2009-04-02 23:40:00 +0000 | [diff] [blame] | 279 | S.EmitBool(ThreadSpecified); |
| 280 | S.EmitBool(HasCXXDirectInit); |
| 281 | S.EmitBool(DeclaredInCondition); |
| 282 | S.EmitPtr(PreviousDeclaration); |
| 283 | S.Emit(TypeSpecStartLoc); |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 284 | } |
| 285 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 286 | void VarDecl::ReadInRec(Deserializer& D, ASTContext& C) { |
| 287 | ValueDecl::ReadInRec(D, C); |
Fariborz Jahanian | de7b4cd | 2007-12-13 00:54:18 +0000 | [diff] [blame] | 288 | SClass = static_cast<StorageClass>(D.ReadInt()); // From VarDecl. |
Douglas Gregor | 3050ed4 | 2009-04-02 23:40:00 +0000 | [diff] [blame] | 289 | ThreadSpecified = D.ReadBool(); |
| 290 | HasCXXDirectInit = D.ReadBool(); |
| 291 | DeclaredInCondition = D.ReadBool(); |
| 292 | D.ReadPtr(PreviousDeclaration); |
| 293 | TypeSpecStartLoc = SourceLocation::ReadVal(D); |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 294 | } |
| 295 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 296 | void VarDecl::EmitOutRec(Serializer& S) const { |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 297 | // Emit this last because it will create a record of its own. |
| 298 | S.EmitOwnedPtr(getInit()); |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 299 | } |
| 300 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 301 | void VarDecl::ReadOutRec(Deserializer& D, ASTContext& C) { |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 302 | Init = D.ReadOwnedPtr<Stmt>(C); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 306 | void VarDecl::EmitImpl(Serializer& S) const { |
| 307 | VarDecl::EmitInRec(S); |
| 308 | VarDecl::EmitOutRec(S); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 309 | } |
| 310 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 311 | void VarDecl::ReadImpl(Deserializer& D, ASTContext& C) { |
| 312 | ReadInRec(D, C); |
| 313 | ReadOutRec(D, C); |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | ef17782 | 2008-04-17 14:40:12 +0000 | [diff] [blame] | 317 | // TranslationUnitDecl Serialization. |
| 318 | //===----------------------------------------------------------------------===// |
| 319 | |
| 320 | void TranslationUnitDecl::EmitImpl(llvm::Serializer& S) const |
| 321 | { |
Argyrios Kyrtzidis | ef17782 | 2008-04-17 14:40:12 +0000 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | TranslationUnitDecl* TranslationUnitDecl::CreateImpl(Deserializer& D, |
| 325 | ASTContext& C) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 326 | return new (C) TranslationUnitDecl(); |
Argyrios Kyrtzidis | ef17782 | 2008-04-17 14:40:12 +0000 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 2d1c5d3 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 330 | // NamespaceDecl Serialization. |
| 331 | //===----------------------------------------------------------------------===// |
| 332 | |
| 333 | void NamespaceDecl::EmitImpl(llvm::Serializer& S) const |
| 334 | { |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 335 | NamedDecl::EmitInRec(S); |
Argyrios Kyrtzidis | 2d1c5d3 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 336 | S.Emit(getLBracLoc()); |
| 337 | S.Emit(getRBracLoc()); |
Argyrios Kyrtzidis | 2d1c5d3 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | NamespaceDecl* NamespaceDecl::CreateImpl(Deserializer& D, ASTContext& C) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 341 | NamespaceDecl* decl = new (C) NamespaceDecl(0, SourceLocation(), 0); |
Argyrios Kyrtzidis | 2d1c5d3 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 342 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 343 | decl->NamedDecl::ReadInRec(D, C); |
Argyrios Kyrtzidis | 2d1c5d3 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 344 | decl->LBracLoc = SourceLocation::ReadVal(D); |
| 345 | decl->RBracLoc = SourceLocation::ReadVal(D); |
Argyrios Kyrtzidis | 2d1c5d3 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 346 | |
| 347 | return decl; |
| 348 | } |
| 349 | |
| 350 | //===----------------------------------------------------------------------===// |
Steve Naroff | 248a753 | 2008-04-15 22:42:06 +0000 | [diff] [blame] | 351 | // VarDecl Serialization. |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 352 | //===----------------------------------------------------------------------===// |
| 353 | |
Steve Naroff | 248a753 | 2008-04-15 22:42:06 +0000 | [diff] [blame] | 354 | VarDecl* VarDecl::CreateImpl(Deserializer& D, ASTContext& C) { |
Steve Naroff | 248a753 | 2008-04-15 22:42:06 +0000 | [diff] [blame] | 355 | VarDecl* decl = |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 356 | new (C) VarDecl(Var, 0, SourceLocation(), NULL, QualType(), None); |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 357 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 358 | decl->VarDecl::ReadImpl(D, C); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 359 | return decl; |
| 360 | } |
| 361 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 362 | //===----------------------------------------------------------------------===// |
Steve Naroff | 248a753 | 2008-04-15 22:42:06 +0000 | [diff] [blame] | 363 | // ParmVarDecl Serialization. |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 364 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 365 | |
Ted Kremenek | 137bd91 | 2007-12-13 06:28:13 +0000 | [diff] [blame] | 366 | void ParmVarDecl::EmitImpl(llvm::Serializer& S) const { |
| 367 | VarDecl::EmitImpl(S); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 368 | S.EmitInt(getObjCDeclQualifier()); // From ParmVarDecl. |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 369 | S.EmitOwnedPtr(getDefaultArg()); // From ParmVarDecl. |
Ted Kremenek | 137bd91 | 2007-12-13 06:28:13 +0000 | [diff] [blame] | 370 | } |
| 371 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 372 | ParmVarDecl* ParmVarDecl::CreateImpl(Deserializer& D, ASTContext& C) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 373 | ParmVarDecl* decl = new (C) |
Fariborz Jahanian | 4306d3c | 2008-12-20 23:29:59 +0000 | [diff] [blame] | 374 | ParmVarDecl(ParmVar, |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 375 | 0, SourceLocation(), NULL, QualType(), None, NULL); |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 376 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 377 | decl->VarDecl::ReadImpl(D, C); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 378 | decl->objcDeclQualifier = static_cast<ObjCDeclQualifier>(D.ReadInt()); |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 379 | decl->DefaultArg = D.ReadOwnedPtr<Expr>(C); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 380 | return decl; |
| 381 | } |
| 382 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 383 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 64650af | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 384 | // OriginalParmVarDecl Serialization. |
Fariborz Jahanian | 73da9e4 | 2008-12-20 20:56:12 +0000 | [diff] [blame] | 385 | //===----------------------------------------------------------------------===// |
| 386 | |
Douglas Gregor | 64650af | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 387 | void OriginalParmVarDecl::EmitImpl(llvm::Serializer& S) const { |
Fariborz Jahanian | 73da9e4 | 2008-12-20 20:56:12 +0000 | [diff] [blame] | 388 | ParmVarDecl::EmitImpl(S); |
| 389 | S.Emit(OriginalType); |
| 390 | } |
| 391 | |
Douglas Gregor | 64650af | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 392 | OriginalParmVarDecl* OriginalParmVarDecl::CreateImpl( |
Fariborz Jahanian | 73da9e4 | 2008-12-20 20:56:12 +0000 | [diff] [blame] | 393 | Deserializer& D, ASTContext& C) { |
Douglas Gregor | 64650af | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 394 | OriginalParmVarDecl* decl = new (C) |
| 395 | OriginalParmVarDecl(0, SourceLocation(), NULL, QualType(), |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 396 | QualType(), None, NULL); |
Fariborz Jahanian | 73da9e4 | 2008-12-20 20:56:12 +0000 | [diff] [blame] | 397 | |
| 398 | decl->ParmVarDecl::ReadImpl(D, C); |
| 399 | decl->OriginalType = QualType::ReadVal(D); |
| 400 | return decl; |
| 401 | } |
| 402 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 403 | // EnumDecl Serialization. |
| 404 | //===----------------------------------------------------------------------===// |
| 405 | |
| 406 | void EnumDecl::EmitImpl(Serializer& S) const { |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 407 | NamedDecl::EmitInRec(S); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 408 | S.EmitBool(isDefinition()); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 409 | S.Emit(IntegerType); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 410 | } |
| 411 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 412 | EnumDecl* EnumDecl::CreateImpl(Deserializer& D, ASTContext& C) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 413 | EnumDecl* decl = new (C) EnumDecl(0, SourceLocation(), NULL); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 414 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 415 | decl->NamedDecl::ReadInRec(D, C); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 416 | decl->setDefinition(D.ReadBool()); |
| 417 | decl->IntegerType = QualType::ReadVal(D); |
| 418 | |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 419 | return decl; |
| 420 | } |
| 421 | |
| 422 | //===----------------------------------------------------------------------===// |
| 423 | // EnumConstantDecl Serialization. |
| 424 | //===----------------------------------------------------------------------===// |
| 425 | |
| 426 | void EnumConstantDecl::EmitImpl(Serializer& S) const { |
| 427 | S.Emit(Val); |
| 428 | ValueDecl::EmitInRec(S); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 429 | S.EmitOwnedPtr(Init); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 430 | } |
| 431 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 432 | EnumConstantDecl* EnumConstantDecl::CreateImpl(Deserializer& D, ASTContext& C) { |
Ted Kremenek | 049b168 | 2007-11-14 23:38:09 +0000 | [diff] [blame] | 433 | llvm::APSInt val(1); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 434 | D.Read(val); |
| 435 | |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 436 | EnumConstantDecl* decl = new (C) |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 437 | EnumConstantDecl(0, SourceLocation(), NULL, QualType(), NULL, val); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 438 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 439 | decl->ValueDecl::ReadInRec(D, C); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 440 | decl->Init = D.ReadOwnedPtr<Stmt>(C); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 441 | return decl; |
| 442 | } |
| 443 | |
| 444 | //===----------------------------------------------------------------------===// |
Ted Kremenek | f9d56c8 | 2007-11-14 17:47:01 +0000 | [diff] [blame] | 445 | // FieldDecl Serialization. |
| 446 | //===----------------------------------------------------------------------===// |
| 447 | |
| 448 | void FieldDecl::EmitImpl(Serializer& S) const { |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 449 | S.EmitBool(Mutable); |
Ted Kremenek | f9d56c8 | 2007-11-14 17:47:01 +0000 | [diff] [blame] | 450 | S.Emit(getType()); |
Mike Stump | 080cc35 | 2009-02-10 20:06:48 +0000 | [diff] [blame] | 451 | ValueDecl::EmitInRec(S); |
Ted Kremenek | f9d56c8 | 2007-11-14 17:47:01 +0000 | [diff] [blame] | 452 | S.EmitOwnedPtr(BitWidth); |
| 453 | } |
| 454 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 455 | FieldDecl* FieldDecl::CreateImpl(Deserializer& D, ASTContext& C) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 456 | FieldDecl* decl = new (C) FieldDecl(Field, 0, SourceLocation(), NULL, |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 457 | QualType(), 0, false); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 458 | decl->Mutable = D.ReadBool(); |
Mike Stump | 080cc35 | 2009-02-10 20:06:48 +0000 | [diff] [blame] | 459 | decl->ValueDecl::ReadInRec(D, C); |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 460 | decl->BitWidth = D.ReadOwnedPtr<Expr>(C); |
Ted Kremenek | f9d56c8 | 2007-11-14 17:47:01 +0000 | [diff] [blame] | 461 | return decl; |
| 462 | } |
| 463 | |
| 464 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 465 | // FunctionDecl Serialization. |
| 466 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 467 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 468 | void FunctionDecl::EmitImpl(Serializer& S) const { |
| 469 | S.EmitInt(SClass); // From FunctionDecl. |
| 470 | S.EmitBool(IsInline); // From FunctionDecl. |
| 471 | ValueDecl::EmitInRec(S); |
Ted Kremenek | 3bbc198 | 2008-05-20 03:33:58 +0000 | [diff] [blame] | 472 | S.EmitPtr(PreviousDeclaration); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 473 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 474 | // NOTE: We do not need to serialize out the number of parameters, because |
| 475 | // that is encoded in the type (accessed via getNumParams()). |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 476 | |
Ted Kremenek | d437f23 | 2007-11-13 22:51:08 +0000 | [diff] [blame] | 477 | if (ParamInfo != NULL) { |
| 478 | S.EmitBool(true); |
Argyrios Kyrtzidis | dc5ddbf | 2008-11-07 14:22:23 +0000 | [diff] [blame] | 479 | S.EmitInt(getNumParams()); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 480 | S.BatchEmitOwnedPtrs(getNumParams(),&ParamInfo[0], Body); |
Ted Kremenek | d437f23 | 2007-11-13 22:51:08 +0000 | [diff] [blame] | 481 | } |
| 482 | else { |
| 483 | S.EmitBool(false); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 484 | S.EmitOwnedPtr(Body); |
Ted Kremenek | d437f23 | 2007-11-13 22:51:08 +0000 | [diff] [blame] | 485 | } |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 486 | } |
| 487 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 488 | FunctionDecl* FunctionDecl::CreateImpl(Deserializer& D, ASTContext& C) { |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 489 | StorageClass SClass = static_cast<StorageClass>(D.ReadInt()); |
| 490 | bool IsInline = D.ReadBool(); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 491 | |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 492 | FunctionDecl* decl = new (C) |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 493 | FunctionDecl(Function, 0, SourceLocation(), DeclarationName(), |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 494 | QualType(), SClass, IsInline); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 495 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 496 | decl->ValueDecl::ReadInRec(D, C); |
Ted Kremenek | 3bbc198 | 2008-05-20 03:33:58 +0000 | [diff] [blame] | 497 | D.ReadPtr(decl->PreviousDeclaration); |
Ted Kremenek | da25685 | 2007-11-16 18:11:10 +0000 | [diff] [blame] | 498 | |
Douglas Gregor | 6b54bd1 | 2009-01-05 17:18:30 +0000 | [diff] [blame] | 499 | int numParams = 0; |
Ted Kremenek | d437f23 | 2007-11-13 22:51:08 +0000 | [diff] [blame] | 500 | bool hasParamDecls = D.ReadBool(); |
Argyrios Kyrtzidis | dc5ddbf | 2008-11-07 14:22:23 +0000 | [diff] [blame] | 501 | if (hasParamDecls) |
| 502 | numParams = D.ReadInt(); |
Ted Kremenek | da25685 | 2007-11-16 18:11:10 +0000 | [diff] [blame] | 503 | |
| 504 | decl->ParamInfo = hasParamDecls |
Argyrios Kyrtzidis | dc5ddbf | 2008-11-07 14:22:23 +0000 | [diff] [blame] | 505 | ? new ParmVarDecl*[numParams] |
Ted Kremenek | da25685 | 2007-11-16 18:11:10 +0000 | [diff] [blame] | 506 | : NULL; |
Ted Kremenek | d437f23 | 2007-11-13 22:51:08 +0000 | [diff] [blame] | 507 | |
| 508 | if (hasParamDecls) |
Argyrios Kyrtzidis | dc5ddbf | 2008-11-07 14:22:23 +0000 | [diff] [blame] | 509 | D.BatchReadOwnedPtrs(numParams, |
Ted Kremenek | d437f23 | 2007-11-13 22:51:08 +0000 | [diff] [blame] | 510 | reinterpret_cast<Decl**>(&decl->ParamInfo[0]), |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 511 | decl->Body, C); |
Ted Kremenek | d437f23 | 2007-11-13 22:51:08 +0000 | [diff] [blame] | 512 | else |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 513 | decl->Body = D.ReadOwnedPtr<Stmt>(C); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 514 | |
| 515 | return decl; |
| 516 | } |
Ted Kremenek | f7bf411 | 2007-11-05 21:49:34 +0000 | [diff] [blame] | 517 | |
Steve Naroff | 56ee689 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 518 | void BlockDecl::EmitImpl(Serializer& S) const { |
| 519 | // FIXME: what about arguments? |
| 520 | S.Emit(getCaretLocation()); |
| 521 | S.EmitOwnedPtr(Body); |
| 522 | } |
| 523 | |
| 524 | BlockDecl* BlockDecl::CreateImpl(Deserializer& D, ASTContext& C) { |
| 525 | QualType Q = QualType::ReadVal(D); |
| 526 | SourceLocation L = SourceLocation::ReadVal(D); |
| 527 | /*CompoundStmt* BodyStmt = cast<CompoundStmt>(*/D.ReadOwnedPtr<Stmt>(C)/*)*/; |
| 528 | assert(0 && "Cannot deserialize BlockBlockExpr yet"); |
| 529 | // FIXME: need to handle parameters. |
| 530 | //return new BlockBlockExpr(L, Q, BodyStmt); |
| 531 | return 0; |
| 532 | } |
| 533 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 534 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 535 | // OverloadedFunctionDecl Serialization. |
| 536 | //===----------------------------------------------------------------------===// |
| 537 | |
| 538 | void OverloadedFunctionDecl::EmitImpl(Serializer& S) const { |
| 539 | NamedDecl::EmitInRec(S); |
| 540 | |
| 541 | S.EmitInt(getNumFunctions()); |
| 542 | for (unsigned func = 0; func < getNumFunctions(); ++func) |
| 543 | S.EmitPtr(Functions[func]); |
| 544 | } |
| 545 | |
| 546 | OverloadedFunctionDecl * |
| 547 | OverloadedFunctionDecl::CreateImpl(Deserializer& D, ASTContext& C) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 548 | OverloadedFunctionDecl* decl = new (C) |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 549 | OverloadedFunctionDecl(0, DeclarationName()); |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 550 | |
| 551 | decl->NamedDecl::ReadInRec(D, C); |
| 552 | |
| 553 | unsigned numFunctions = D.ReadInt(); |
| 554 | decl->Functions.reserve(numFunctions); |
| 555 | for (unsigned func = 0; func < numFunctions; ++func) |
| 556 | D.ReadPtr(decl->Functions[func]); |
| 557 | |
| 558 | return decl; |
| 559 | } |
| 560 | |
| 561 | //===----------------------------------------------------------------------===// |
Ted Kremenek | aad48b6 | 2007-11-14 08:06:37 +0000 | [diff] [blame] | 562 | // RecordDecl Serialization. |
| 563 | //===----------------------------------------------------------------------===// |
| 564 | |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 565 | void RecordDecl::EmitImpl(Serializer& S) const { |
Argyrios Kyrtzidis | 35bc082 | 2008-10-15 00:42:39 +0000 | [diff] [blame] | 566 | S.EmitInt(getTagKind()); |
| 567 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 568 | NamedDecl::EmitInRec(S); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 569 | S.EmitBool(isDefinition()); |
Ted Kremenek | aad48b6 | 2007-11-14 08:06:37 +0000 | [diff] [blame] | 570 | S.EmitBool(hasFlexibleArrayMember()); |
Douglas Gregor | bcbffc4 | 2009-01-07 00:43:41 +0000 | [diff] [blame] | 571 | S.EmitBool(isAnonymousStructOrUnion()); |
Ted Kremenek | aad48b6 | 2007-11-14 08:06:37 +0000 | [diff] [blame] | 572 | } |
| 573 | |
Argyrios Kyrtzidis | 35bc082 | 2008-10-15 00:42:39 +0000 | [diff] [blame] | 574 | RecordDecl* RecordDecl::CreateImpl(Deserializer& D, ASTContext& C) { |
| 575 | TagKind TK = TagKind(D.ReadInt()); |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 576 | |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 577 | RecordDecl* decl = new (C) RecordDecl(Record, TK, 0, SourceLocation(), NULL); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 578 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 579 | decl->NamedDecl::ReadInRec(D, C); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 580 | decl->setDefinition(D.ReadBool()); |
Ted Kremenek | aad48b6 | 2007-11-14 08:06:37 +0000 | [diff] [blame] | 581 | decl->setHasFlexibleArrayMember(D.ReadBool()); |
Douglas Gregor | bcbffc4 | 2009-01-07 00:43:41 +0000 | [diff] [blame] | 582 | decl->setAnonymousStructOrUnion(D.ReadBool()); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 583 | |
Ted Kremenek | aad48b6 | 2007-11-14 08:06:37 +0000 | [diff] [blame] | 584 | return decl; |
| 585 | } |
| 586 | |
| 587 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 588 | // TypedefDecl Serialization. |
| 589 | //===----------------------------------------------------------------------===// |
| 590 | |
| 591 | void TypedefDecl::EmitImpl(Serializer& S) const { |
Ted Kremenek | 2ebc89f | 2007-11-06 19:51:47 +0000 | [diff] [blame] | 592 | S.Emit(UnderlyingType); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 593 | NamedDecl::EmitInRec(S); |
Ted Kremenek | f7bf411 | 2007-11-05 21:49:34 +0000 | [diff] [blame] | 594 | } |
| 595 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 596 | TypedefDecl* TypedefDecl::CreateImpl(Deserializer& D, ASTContext& C) { |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 597 | QualType T = QualType::ReadVal(D); |
| 598 | |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 599 | TypedefDecl* decl = new (C) TypedefDecl(0, SourceLocation(), NULL, T); |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 600 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 601 | decl->NamedDecl::ReadInRec(D, C); |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 602 | |
Ted Kremenek | f7bf411 | 2007-11-05 21:49:34 +0000 | [diff] [blame] | 603 | return decl; |
| 604 | } |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 605 | |
| 606 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 607 | // TemplateTypeParmDecl Serialization. |
| 608 | //===----------------------------------------------------------------------===// |
| 609 | |
| 610 | void TemplateTypeParmDecl::EmitImpl(Serializer& S) const { |
| 611 | S.EmitBool(Typename); |
Douglas Gregor | fab9d67 | 2009-02-05 23:33:38 +0000 | [diff] [blame] | 612 | TypeDecl::EmitInRec(S); |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | TemplateTypeParmDecl * |
| 616 | TemplateTypeParmDecl::CreateImpl(Deserializer& D, ASTContext& C) { |
| 617 | bool Typename = D.ReadBool(); |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 618 | TemplateTypeParmDecl *decl |
Douglas Gregor | fab9d67 | 2009-02-05 23:33:38 +0000 | [diff] [blame] | 619 | = new (C) TemplateTypeParmDecl(0, SourceLocation(), 0, Typename, |
| 620 | QualType()); |
| 621 | decl->TypeDecl::ReadInRec(D, C); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 622 | return decl; |
| 623 | } |
| 624 | |
| 625 | //===----------------------------------------------------------------------===// |
| 626 | // NonTypeTemplateParmDecl Serialization. |
| 627 | //===----------------------------------------------------------------------===// |
| 628 | void NonTypeTemplateParmDecl::EmitImpl(Serializer& S) const { |
| 629 | S.EmitInt(Depth); |
| 630 | S.EmitInt(Position); |
| 631 | NamedDecl::Emit(S); |
| 632 | } |
| 633 | |
| 634 | NonTypeTemplateParmDecl* |
| 635 | NonTypeTemplateParmDecl::CreateImpl(Deserializer& D, ASTContext& C) { |
| 636 | unsigned Depth = D.ReadInt(); |
| 637 | unsigned Position = D.ReadInt(); |
| 638 | NonTypeTemplateParmDecl *decl |
| 639 | = new (C) NonTypeTemplateParmDecl(0, SourceLocation(), Depth, Position, |
| 640 | 0, QualType(), SourceLocation()); |
| 641 | decl->NamedDecl::ReadInRec(D, C); |
| 642 | return decl; |
| 643 | } |
| 644 | |
| 645 | //===----------------------------------------------------------------------===// |
| 646 | // TemplateTemplateParmDecl Serialization. |
| 647 | //===----------------------------------------------------------------------===// |
| 648 | void TemplateTemplateParmDecl::EmitImpl(Serializer& S) const { |
| 649 | S.EmitInt(Depth); |
| 650 | S.EmitInt(Position); |
| 651 | NamedDecl::EmitInRec(S); |
| 652 | } |
| 653 | |
| 654 | TemplateTemplateParmDecl* |
| 655 | TemplateTemplateParmDecl::CreateImpl(Deserializer& D, ASTContext& C) { |
| 656 | unsigned Depth = D.ReadInt(); |
| 657 | unsigned Position = D.ReadInt(); |
| 658 | TemplateTemplateParmDecl *decl |
| 659 | = new (C) TemplateTemplateParmDecl(0, SourceLocation(), Depth, Position, |
| 660 | 0, 0); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 661 | decl->NamedDecl::ReadInRec(D, C); |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 662 | return decl; |
| 663 | } |
| 664 | |
| 665 | //===----------------------------------------------------------------------===// |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 666 | // LinkageSpec Serialization. |
| 667 | //===----------------------------------------------------------------------===// |
| 668 | |
| 669 | void LinkageSpecDecl::EmitInRec(Serializer& S) const { |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 670 | S.EmitInt(getLanguage()); |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 671 | S.EmitBool(HadBraces); |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 672 | } |
| 673 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 674 | void LinkageSpecDecl::ReadInRec(Deserializer& D, ASTContext& C) { |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 675 | Language = static_cast<LanguageIDs>(D.ReadInt()); |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 676 | HadBraces = D.ReadBool(); |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 677 | } |
Anders Carlsson | dfab6cb | 2008-02-08 00:33:21 +0000 | [diff] [blame] | 678 | |
| 679 | //===----------------------------------------------------------------------===// |
| 680 | // FileScopeAsm Serialization. |
| 681 | //===----------------------------------------------------------------------===// |
| 682 | |
| 683 | void FileScopeAsmDecl::EmitImpl(llvm::Serializer& S) const |
| 684 | { |
Anders Carlsson | dfab6cb | 2008-02-08 00:33:21 +0000 | [diff] [blame] | 685 | S.EmitOwnedPtr(AsmString); |
| 686 | } |
| 687 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 688 | FileScopeAsmDecl* FileScopeAsmDecl::CreateImpl(Deserializer& D, ASTContext& C) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 689 | FileScopeAsmDecl* decl = new (C) FileScopeAsmDecl(0, SourceLocation(), 0); |
Anders Carlsson | dfab6cb | 2008-02-08 00:33:21 +0000 | [diff] [blame] | 690 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 691 | decl->AsmString = cast<StringLiteral>(D.ReadOwnedPtr<Expr>(C)); |
Anders Carlsson | dfab6cb | 2008-02-08 00:33:21 +0000 | [diff] [blame] | 692 | // D.ReadOwnedPtr(D.ReadOwnedPtr<StringLiteral>())<#T * * Ptr#>, <#bool AutoRegister#>)(decl->AsmString); |
| 693 | |
| 694 | return decl; |
| 695 | } |