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 | // |
| 10 | // This files defines methods that implement bitcode serialization for Decls. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/AST/Decl.h" |
| 15 | #include "clang/AST/Expr.h" |
| 16 | #include "llvm/Bitcode/Serialize.h" |
| 17 | #include "llvm/Bitcode/Deserialize.h" |
| 18 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 19 | using llvm::Serializer; |
| 20 | using llvm::Deserializer; |
| 21 | using llvm::SerializedPtrID; |
| 22 | |
Ted Kremenek | 2f1f8cb | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 23 | using namespace clang; |
| 24 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 25 | //===----------------------------------------------------------------------===// |
| 26 | // Decl Serialization: Dispatch code to handle specialized decl types. |
| 27 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 8af8fe3 | 2007-11-05 21:38:00 +0000 | [diff] [blame] | 28 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 29 | void Decl::Emit(Serializer& S) const { |
| 30 | S.EmitInt(getKind()); |
| 31 | EmitImpl(S); |
Ted Kremenek | 2f1f8cb | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 32 | } |
| 33 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 34 | Decl* Decl::Create(Deserializer& D) { |
| 35 | |
Ted Kremenek | 2ebc89f | 2007-11-06 19:51:47 +0000 | [diff] [blame] | 36 | Kind k = static_cast<Kind>(D.ReadInt()); |
| 37 | |
| 38 | switch (k) { |
| 39 | default: |
| 40 | assert (false && "Not implemented."); |
| 41 | break; |
| 42 | |
| 43 | case BlockVar: |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 44 | return BlockVarDecl::CreateImpl(D); |
Ted Kremenek | 2ebc89f | 2007-11-06 19:51:47 +0000 | [diff] [blame] | 45 | |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 46 | case Enum: |
| 47 | return EnumDecl::CreateImpl(D); |
| 48 | |
| 49 | case EnumConstant: |
| 50 | return EnumConstantDecl::CreateImpl(D); |
| 51 | |
Ted Kremenek | f9d56c8 | 2007-11-14 17:47:01 +0000 | [diff] [blame] | 52 | case Field: |
| 53 | return FieldDecl::CreateImpl(D); |
| 54 | |
Ted Kremenek | 2ebc89f | 2007-11-06 19:51:47 +0000 | [diff] [blame] | 55 | case FileVar: |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 56 | return FileVarDecl::CreateImpl(D); |
Ted Kremenek | 2ebc89f | 2007-11-06 19:51:47 +0000 | [diff] [blame] | 57 | |
| 58 | case ParmVar: |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 59 | return ParmVarDecl::CreateImpl(D); |
Ted Kremenek | 2ebc89f | 2007-11-06 19:51:47 +0000 | [diff] [blame] | 60 | |
| 61 | case Function: |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 62 | return FunctionDecl::CreateImpl(D); |
Ted Kremenek | 5f670ed | 2007-11-14 21:15:42 +0000 | [diff] [blame] | 63 | |
| 64 | case Union: |
Ted Kremenek | aad48b6 | 2007-11-14 08:06:37 +0000 | [diff] [blame] | 65 | case Struct: |
| 66 | return RecordDecl::CreateImpl(k,D); |
| 67 | |
Ted Kremenek | 2ebc89f | 2007-11-06 19:51:47 +0000 | [diff] [blame] | 68 | case Typedef: |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 69 | return TypedefDecl::CreateImpl(D); |
Ted Kremenek | 2ebc89f | 2007-11-06 19:51:47 +0000 | [diff] [blame] | 70 | } |
Ted Kremenek | 2f1f8cb | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 71 | } |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 72 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 73 | //===----------------------------------------------------------------------===// |
| 74 | // Common serialization logic for subclasses of Decl. |
| 75 | //===----------------------------------------------------------------------===// |
| 76 | |
| 77 | void Decl::EmitInRec(Serializer& S) const { |
| 78 | S.Emit(getLocation()); // From Decl. |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 81 | void Decl::ReadInRec(Deserializer& D) { |
| 82 | Loc = SourceLocation::ReadVal(D); // From Decl. |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 85 | //===----------------------------------------------------------------------===// |
| 86 | // Common serialization logic for subclasses of NamedDecl. |
| 87 | //===----------------------------------------------------------------------===// |
| 88 | |
| 89 | void NamedDecl::EmitInRec(Serializer& S) const { |
| 90 | Decl::EmitInRec(S); |
| 91 | S.EmitPtr(getIdentifier()); // From NamedDecl. |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 94 | void NamedDecl::ReadInRec(Deserializer& D) { |
| 95 | Decl::ReadInRec(D); |
| 96 | D.ReadPtr(Identifier); // From NamedDecl. |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 99 | //===----------------------------------------------------------------------===// |
| 100 | // Common serialization logic for subclasses of ScopedDecl. |
| 101 | //===----------------------------------------------------------------------===// |
| 102 | |
| 103 | void ScopedDecl::EmitInRec(Serializer& S) const { |
| 104 | NamedDecl::EmitInRec(S); |
| 105 | S.EmitPtr(getNext()); // From ScopedDecl. |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 108 | void ScopedDecl::ReadInRec(Deserializer& D) { |
| 109 | NamedDecl::ReadInRec(D); |
| 110 | D.ReadPtr(Next); // From ScopedDecl. |
| 111 | } |
| 112 | |
| 113 | //===------------------------------------------------------------===// |
| 114 | // NOTE: Not all subclasses of ScopedDecl will use the "OutRec" // |
| 115 | // methods. This is because owned pointers are usually "batched" // |
| 116 | // together for efficiency. // |
| 117 | //===------------------------------------------------------------===// |
| 118 | |
| 119 | void ScopedDecl::EmitOutRec(Serializer& S) const { |
| 120 | S.EmitOwnedPtr(getNextDeclarator()); // From ScopedDecl. |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 123 | void ScopedDecl::ReadOutRec(Deserializer& D) { |
| 124 | NextDeclarator = |
| 125 | cast_or_null<ScopedDecl>(D.ReadOwnedPtr<Decl>()); // From ScopedDecl. |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 126 | } |
| 127 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 128 | //===----------------------------------------------------------------------===// |
| 129 | // Common serialization logic for subclasses of ValueDecl. |
| 130 | //===----------------------------------------------------------------------===// |
| 131 | |
| 132 | void ValueDecl::EmitInRec(Serializer& S) const { |
| 133 | ScopedDecl::EmitInRec(S); |
| 134 | S.Emit(getType()); // From ValueDecl. |
| 135 | } |
| 136 | |
| 137 | void ValueDecl::ReadInRec(Deserializer& D) { |
| 138 | ScopedDecl::ReadInRec(D); |
| 139 | DeclType = QualType::ReadVal(D); // From ValueDecl. |
| 140 | } |
| 141 | |
| 142 | //===----------------------------------------------------------------------===// |
| 143 | // Common serialization logic for subclasses of VarDecl. |
| 144 | //===----------------------------------------------------------------------===// |
| 145 | |
| 146 | void VarDecl::EmitInRec(Serializer& S) const { |
| 147 | ValueDecl::EmitInRec(S); |
| 148 | S.EmitInt(getStorageClass()); // From VarDecl. |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | void VarDecl::ReadInRec(Deserializer& D) { |
| 152 | ValueDecl::ReadInRec(D); |
Fariborz Jahanian | de7b4cd | 2007-12-13 00:54:18 +0000 | [diff] [blame] | 153 | SClass = static_cast<StorageClass>(D.ReadInt()); // From VarDecl. |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | //===------------------------------------------------------------===// |
| 157 | // NOTE: VarDecl has its own "OutRec" methods that doesn't use // |
| 158 | // the one define in ScopedDecl. This is to batch emit the // |
| 159 | // owned pointers, which results in a smaller output. |
| 160 | //===------------------------------------------------------------===// |
| 161 | |
| 162 | void VarDecl::EmitOutRec(Serializer& S) const { |
| 163 | // Emit these last because they will create records of their own. |
| 164 | S.BatchEmitOwnedPtrs(getInit(), // From VarDecl. |
| 165 | getNextDeclarator()); // From ScopedDecl. |
| 166 | } |
| 167 | |
| 168 | void VarDecl::ReadOutRec(Deserializer& D) { |
| 169 | Decl* next_declarator; |
| 170 | |
| 171 | D.BatchReadOwnedPtrs(Init, // From VarDecl. |
| 172 | next_declarator); // From ScopedDecl. |
| 173 | |
| 174 | setNextDeclarator(cast_or_null<ScopedDecl>(next_declarator)); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 178 | void VarDecl::EmitImpl(Serializer& S) const { |
| 179 | VarDecl::EmitInRec(S); |
| 180 | VarDecl::EmitOutRec(S); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 181 | } |
| 182 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 183 | void VarDecl::ReadImpl(Deserializer& D) { |
| 184 | ReadInRec(D); |
| 185 | ReadOutRec(D); |
| 186 | } |
| 187 | |
| 188 | //===----------------------------------------------------------------------===// |
| 189 | // BlockVarDecl Serialization. |
| 190 | //===----------------------------------------------------------------------===// |
| 191 | |
| 192 | BlockVarDecl* BlockVarDecl::CreateImpl(Deserializer& D) { |
| 193 | BlockVarDecl* decl = |
| 194 | new BlockVarDecl(SourceLocation(),NULL,QualType(),None,NULL); |
| 195 | |
| 196 | decl->VarDecl::ReadImpl(D); |
| 197 | |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 198 | return decl; |
| 199 | } |
| 200 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 201 | //===----------------------------------------------------------------------===// |
| 202 | // FileVarDecl Serialization. |
| 203 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 204 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 205 | FileVarDecl* FileVarDecl::CreateImpl(Deserializer& D) { |
| 206 | FileVarDecl* decl = |
| 207 | new FileVarDecl(SourceLocation(),NULL,QualType(),None,NULL); |
| 208 | |
| 209 | decl->VarDecl::ReadImpl(D); |
| 210 | |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 211 | return decl; |
| 212 | } |
| 213 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 214 | //===----------------------------------------------------------------------===// |
| 215 | // ParmDecl Serialization. |
| 216 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 217 | |
Ted Kremenek | 137bd91 | 2007-12-13 06:28:13 +0000 | [diff] [blame] | 218 | void ParmVarDecl::EmitImpl(llvm::Serializer& S) const { |
| 219 | VarDecl::EmitImpl(S); |
| 220 | S.EmitInt(getObjcDeclQualifier()); // From ParmVarDecl. |
| 221 | } |
| 222 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 223 | ParmVarDecl* ParmVarDecl::CreateImpl(Deserializer& D) { |
| 224 | ParmVarDecl* decl = |
| 225 | new ParmVarDecl(SourceLocation(),NULL,QualType(),None,NULL); |
| 226 | |
| 227 | decl->VarDecl::ReadImpl(D); |
Ted Kremenek | 137bd91 | 2007-12-13 06:28:13 +0000 | [diff] [blame] | 228 | decl->objcDeclQualifier = static_cast<ObjcDeclQualifier>(D.ReadInt()); |
| 229 | |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 230 | return decl; |
| 231 | } |
| 232 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 233 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 234 | // EnumDecl Serialization. |
| 235 | //===----------------------------------------------------------------------===// |
| 236 | |
| 237 | void EnumDecl::EmitImpl(Serializer& S) const { |
| 238 | ScopedDecl::EmitInRec(S); |
| 239 | S.EmitBool(isDefinition()); |
| 240 | S.Emit(IntegerType); |
| 241 | S.BatchEmitOwnedPtrs(ElementList,getNextDeclarator()); |
| 242 | } |
| 243 | |
| 244 | EnumDecl* EnumDecl::CreateImpl(Deserializer& D) { |
| 245 | EnumDecl* decl = new EnumDecl(SourceLocation(),NULL,NULL); |
| 246 | |
| 247 | decl->ScopedDecl::ReadInRec(D); |
| 248 | decl->setDefinition(D.ReadBool()); |
| 249 | decl->IntegerType = QualType::ReadVal(D); |
| 250 | |
| 251 | Decl* next_declarator; |
| 252 | Decl* Elist; |
| 253 | |
| 254 | D.BatchReadOwnedPtrs(Elist,next_declarator); |
| 255 | |
| 256 | decl->ElementList = cast_or_null<EnumConstantDecl>(Elist); |
| 257 | decl->setNextDeclarator(cast_or_null<ScopedDecl>(next_declarator)); |
| 258 | |
| 259 | return decl; |
| 260 | } |
| 261 | |
| 262 | //===----------------------------------------------------------------------===// |
| 263 | // EnumConstantDecl Serialization. |
| 264 | //===----------------------------------------------------------------------===// |
| 265 | |
| 266 | void EnumConstantDecl::EmitImpl(Serializer& S) const { |
| 267 | S.Emit(Val); |
| 268 | ValueDecl::EmitInRec(S); |
| 269 | S.BatchEmitOwnedPtrs(getNextDeclarator(),Init); |
| 270 | } |
| 271 | |
| 272 | EnumConstantDecl* EnumConstantDecl::CreateImpl(Deserializer& D) { |
Ted Kremenek | 049b168 | 2007-11-14 23:38:09 +0000 | [diff] [blame] | 273 | llvm::APSInt val(1); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 274 | D.Read(val); |
| 275 | |
| 276 | EnumConstantDecl* decl = |
| 277 | new EnumConstantDecl(SourceLocation(),NULL,QualType(),NULL, |
| 278 | val,NULL); |
| 279 | |
| 280 | decl->ValueDecl::ReadInRec(D); |
| 281 | |
| 282 | Decl* next_declarator; |
| 283 | |
| 284 | D.BatchReadOwnedPtrs(next_declarator,decl->Init); |
| 285 | |
Ted Kremenek | 049b168 | 2007-11-14 23:38:09 +0000 | [diff] [blame] | 286 | decl->setNextDeclarator(cast_or_null<ScopedDecl>(next_declarator)); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 287 | |
| 288 | return decl; |
| 289 | } |
| 290 | |
| 291 | //===----------------------------------------------------------------------===// |
Ted Kremenek | f9d56c8 | 2007-11-14 17:47:01 +0000 | [diff] [blame] | 292 | // FieldDecl Serialization. |
| 293 | //===----------------------------------------------------------------------===// |
| 294 | |
| 295 | void FieldDecl::EmitImpl(Serializer& S) const { |
| 296 | S.Emit(getType()); |
| 297 | NamedDecl::EmitInRec(S); |
| 298 | S.EmitOwnedPtr(BitWidth); |
| 299 | } |
| 300 | |
| 301 | FieldDecl* FieldDecl::CreateImpl(Deserializer& D) { |
Ted Kremenek | 21d50e1 | 2007-11-14 22:51:02 +0000 | [diff] [blame] | 302 | FieldDecl* decl = new FieldDecl(SourceLocation(),NULL,QualType()); |
| 303 | decl->DeclType.ReadBackpatch(D); |
Ted Kremenek | f9d56c8 | 2007-11-14 17:47:01 +0000 | [diff] [blame] | 304 | decl->ReadInRec(D); |
| 305 | decl->BitWidth = D.ReadOwnedPtr<Expr>(); |
| 306 | return decl; |
| 307 | } |
| 308 | |
| 309 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 310 | // FunctionDecl Serialization. |
| 311 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 312 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 313 | void FunctionDecl::EmitImpl(Serializer& S) const { |
| 314 | S.EmitInt(SClass); // From FunctionDecl. |
| 315 | S.EmitBool(IsInline); // From FunctionDecl. |
| 316 | ValueDecl::EmitInRec(S); |
| 317 | S.EmitPtr(DeclChain); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 318 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 319 | // NOTE: We do not need to serialize out the number of parameters, because |
| 320 | // that is encoded in the type (accessed via getNumParams()). |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 321 | |
Ted Kremenek | d437f23 | 2007-11-13 22:51:08 +0000 | [diff] [blame] | 322 | if (ParamInfo != NULL) { |
| 323 | S.EmitBool(true); |
| 324 | S.BatchEmitOwnedPtrs(getNumParams(),&ParamInfo[0], Body, |
| 325 | getNextDeclarator()); |
| 326 | } |
| 327 | else { |
| 328 | S.EmitBool(false); |
| 329 | S.BatchEmitOwnedPtrs(Body,getNextDeclarator()); |
| 330 | } |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 331 | } |
| 332 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 333 | FunctionDecl* FunctionDecl::CreateImpl(Deserializer& D) { |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 334 | StorageClass SClass = static_cast<StorageClass>(D.ReadInt()); |
| 335 | bool IsInline = D.ReadBool(); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 336 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 337 | FunctionDecl* decl = |
| 338 | new FunctionDecl(SourceLocation(),NULL,QualType(),SClass,IsInline); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 339 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 340 | decl->ValueDecl::ReadInRec(D); |
| 341 | D.ReadPtr(decl->DeclChain); |
Ted Kremenek | da25685 | 2007-11-16 18:11:10 +0000 | [diff] [blame] | 342 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 343 | Decl* next_declarator; |
| 344 | |
Ted Kremenek | d437f23 | 2007-11-13 22:51:08 +0000 | [diff] [blame] | 345 | bool hasParamDecls = D.ReadBool(); |
Ted Kremenek | da25685 | 2007-11-16 18:11:10 +0000 | [diff] [blame] | 346 | |
| 347 | decl->ParamInfo = hasParamDecls |
| 348 | ? new ParmVarDecl*[decl->getNumParams()] |
| 349 | : NULL; |
Ted Kremenek | d437f23 | 2007-11-13 22:51:08 +0000 | [diff] [blame] | 350 | |
| 351 | if (hasParamDecls) |
| 352 | D.BatchReadOwnedPtrs(decl->getNumParams(), |
| 353 | reinterpret_cast<Decl**>(&decl->ParamInfo[0]), |
| 354 | decl->Body, next_declarator); |
| 355 | else |
| 356 | D.BatchReadOwnedPtrs(decl->Body, next_declarator); |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 357 | |
| 358 | decl->setNextDeclarator(cast_or_null<ScopedDecl>(next_declarator)); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 359 | |
| 360 | return decl; |
| 361 | } |
Ted Kremenek | f7bf411 | 2007-11-05 21:49:34 +0000 | [diff] [blame] | 362 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 363 | //===----------------------------------------------------------------------===// |
Ted Kremenek | aad48b6 | 2007-11-14 08:06:37 +0000 | [diff] [blame] | 364 | // RecordDecl Serialization. |
| 365 | //===----------------------------------------------------------------------===// |
| 366 | |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 367 | void RecordDecl::EmitImpl(Serializer& S) const { |
Ted Kremenek | aad48b6 | 2007-11-14 08:06:37 +0000 | [diff] [blame] | 368 | ScopedDecl::EmitInRec(S); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 369 | S.EmitBool(isDefinition()); |
Ted Kremenek | aad48b6 | 2007-11-14 08:06:37 +0000 | [diff] [blame] | 370 | S.EmitBool(hasFlexibleArrayMember()); |
| 371 | S.EmitSInt(getNumMembers()); |
| 372 | if (getNumMembers() > 0) { |
| 373 | assert (Members); |
| 374 | S.BatchEmitOwnedPtrs((unsigned) getNumMembers(), |
| 375 | (Decl**) &Members[0],getNextDeclarator()); |
| 376 | } |
| 377 | else |
| 378 | ScopedDecl::EmitOutRec(S); |
| 379 | } |
| 380 | |
| 381 | RecordDecl* RecordDecl::CreateImpl(Decl::Kind DK, Deserializer& D) { |
| 382 | RecordDecl* decl = new RecordDecl(DK,SourceLocation(),NULL,NULL); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 383 | |
Ted Kremenek | aad48b6 | 2007-11-14 08:06:37 +0000 | [diff] [blame] | 384 | decl->ScopedDecl::ReadInRec(D); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 385 | decl->setDefinition(D.ReadBool()); |
Ted Kremenek | aad48b6 | 2007-11-14 08:06:37 +0000 | [diff] [blame] | 386 | decl->setHasFlexibleArrayMember(D.ReadBool()); |
| 387 | decl->NumMembers = D.ReadSInt(); |
| 388 | |
| 389 | if (decl->getNumMembers() > 0) { |
| 390 | Decl* next_declarator; |
| 391 | decl->Members = new FieldDecl*[(unsigned) decl->getNumMembers()]; |
| 392 | |
| 393 | D.BatchReadOwnedPtrs((unsigned) decl->getNumMembers(), |
| 394 | (Decl**) &decl->Members[0], |
| 395 | next_declarator); |
| 396 | |
| 397 | decl->setNextDeclarator(cast_or_null<ScopedDecl>(next_declarator)); |
| 398 | } |
| 399 | else |
| 400 | decl->ScopedDecl::ReadOutRec(D); |
| 401 | |
| 402 | return decl; |
| 403 | } |
| 404 | |
| 405 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 406 | // TypedefDecl Serialization. |
| 407 | //===----------------------------------------------------------------------===// |
| 408 | |
| 409 | void TypedefDecl::EmitImpl(Serializer& S) const { |
Ted Kremenek | 2ebc89f | 2007-11-06 19:51:47 +0000 | [diff] [blame] | 410 | S.Emit(UnderlyingType); |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 411 | ScopedDecl::EmitInRec(S); |
| 412 | ScopedDecl::EmitOutRec(S); |
Ted Kremenek | f7bf411 | 2007-11-05 21:49:34 +0000 | [diff] [blame] | 413 | } |
| 414 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 415 | TypedefDecl* TypedefDecl::CreateImpl(Deserializer& D) { |
| 416 | QualType T = QualType::ReadVal(D); |
| 417 | |
| 418 | TypedefDecl* decl = new TypedefDecl(SourceLocation(),NULL,T,NULL); |
| 419 | |
| 420 | decl->ScopedDecl::ReadInRec(D); |
| 421 | decl->ScopedDecl::ReadOutRec(D); |
| 422 | |
Ted Kremenek | f7bf411 | 2007-11-05 21:49:34 +0000 | [diff] [blame] | 423 | return decl; |
| 424 | } |