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