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