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 | // |
| 5 | // This file was developed by Ted Kremenek and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 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. |
| 149 | S.EmitInt(getObjcDeclQualifier()); // From VarDecl. |
| 150 | } |
| 151 | |
| 152 | void VarDecl::ReadInRec(Deserializer& D) { |
| 153 | ValueDecl::ReadInRec(D); |
| 154 | SClass = static_cast<StorageClass>(D.ReadInt()); // From VarDecl. |
| 155 | objcDeclQualifier = static_cast<ObjcDeclQualifier>(D.ReadInt()); // VarDecl. |
| 156 | } |
| 157 | |
| 158 | //===------------------------------------------------------------===// |
| 159 | // NOTE: VarDecl has its own "OutRec" methods that doesn't use // |
| 160 | // the one define in ScopedDecl. This is to batch emit the // |
| 161 | // owned pointers, which results in a smaller output. |
| 162 | //===------------------------------------------------------------===// |
| 163 | |
| 164 | void VarDecl::EmitOutRec(Serializer& S) const { |
| 165 | // Emit these last because they will create records of their own. |
| 166 | S.BatchEmitOwnedPtrs(getInit(), // From VarDecl. |
| 167 | getNextDeclarator()); // From ScopedDecl. |
| 168 | } |
| 169 | |
| 170 | void VarDecl::ReadOutRec(Deserializer& D) { |
| 171 | Decl* next_declarator; |
| 172 | |
| 173 | D.BatchReadOwnedPtrs(Init, // From VarDecl. |
| 174 | next_declarator); // From ScopedDecl. |
| 175 | |
| 176 | setNextDeclarator(cast_or_null<ScopedDecl>(next_declarator)); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 180 | void VarDecl::EmitImpl(Serializer& S) const { |
| 181 | VarDecl::EmitInRec(S); |
| 182 | VarDecl::EmitOutRec(S); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 185 | void VarDecl::ReadImpl(Deserializer& D) { |
| 186 | ReadInRec(D); |
| 187 | ReadOutRec(D); |
| 188 | } |
| 189 | |
| 190 | //===----------------------------------------------------------------------===// |
| 191 | // BlockVarDecl Serialization. |
| 192 | //===----------------------------------------------------------------------===// |
| 193 | |
| 194 | BlockVarDecl* BlockVarDecl::CreateImpl(Deserializer& D) { |
| 195 | BlockVarDecl* decl = |
| 196 | new BlockVarDecl(SourceLocation(),NULL,QualType(),None,NULL); |
| 197 | |
| 198 | decl->VarDecl::ReadImpl(D); |
| 199 | |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 200 | return decl; |
| 201 | } |
| 202 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 203 | //===----------------------------------------------------------------------===// |
| 204 | // FileVarDecl Serialization. |
| 205 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 206 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 207 | FileVarDecl* FileVarDecl::CreateImpl(Deserializer& D) { |
| 208 | FileVarDecl* decl = |
| 209 | new FileVarDecl(SourceLocation(),NULL,QualType(),None,NULL); |
| 210 | |
| 211 | decl->VarDecl::ReadImpl(D); |
| 212 | |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 213 | return decl; |
| 214 | } |
| 215 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 216 | //===----------------------------------------------------------------------===// |
| 217 | // ParmDecl Serialization. |
| 218 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 219 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 220 | ParmVarDecl* ParmVarDecl::CreateImpl(Deserializer& D) { |
| 221 | ParmVarDecl* decl = |
| 222 | new ParmVarDecl(SourceLocation(),NULL,QualType(),None,NULL); |
| 223 | |
| 224 | decl->VarDecl::ReadImpl(D); |
| 225 | |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 226 | return decl; |
| 227 | } |
| 228 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 229 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 230 | // EnumDecl Serialization. |
| 231 | //===----------------------------------------------------------------------===// |
| 232 | |
| 233 | void EnumDecl::EmitImpl(Serializer& S) const { |
| 234 | ScopedDecl::EmitInRec(S); |
| 235 | S.EmitBool(isDefinition()); |
| 236 | S.Emit(IntegerType); |
| 237 | S.BatchEmitOwnedPtrs(ElementList,getNextDeclarator()); |
| 238 | } |
| 239 | |
| 240 | EnumDecl* EnumDecl::CreateImpl(Deserializer& D) { |
| 241 | EnumDecl* decl = new EnumDecl(SourceLocation(),NULL,NULL); |
| 242 | |
| 243 | decl->ScopedDecl::ReadInRec(D); |
| 244 | decl->setDefinition(D.ReadBool()); |
| 245 | decl->IntegerType = QualType::ReadVal(D); |
| 246 | |
| 247 | Decl* next_declarator; |
| 248 | Decl* Elist; |
| 249 | |
| 250 | D.BatchReadOwnedPtrs(Elist,next_declarator); |
| 251 | |
| 252 | decl->ElementList = cast_or_null<EnumConstantDecl>(Elist); |
| 253 | decl->setNextDeclarator(cast_or_null<ScopedDecl>(next_declarator)); |
| 254 | |
| 255 | return decl; |
| 256 | } |
| 257 | |
| 258 | //===----------------------------------------------------------------------===// |
| 259 | // EnumConstantDecl Serialization. |
| 260 | //===----------------------------------------------------------------------===// |
| 261 | |
| 262 | void EnumConstantDecl::EmitImpl(Serializer& S) const { |
| 263 | S.Emit(Val); |
| 264 | ValueDecl::EmitInRec(S); |
| 265 | S.BatchEmitOwnedPtrs(getNextDeclarator(),Init); |
| 266 | } |
| 267 | |
| 268 | EnumConstantDecl* EnumConstantDecl::CreateImpl(Deserializer& D) { |
| 269 | llvm::APSInt val(0); |
| 270 | D.Read(val); |
| 271 | |
| 272 | EnumConstantDecl* decl = |
| 273 | new EnumConstantDecl(SourceLocation(),NULL,QualType(),NULL, |
| 274 | val,NULL); |
| 275 | |
| 276 | decl->ValueDecl::ReadInRec(D); |
| 277 | |
| 278 | Decl* next_declarator; |
| 279 | |
| 280 | D.BatchReadOwnedPtrs(next_declarator,decl->Init); |
| 281 | |
| 282 | decl->setNextDeclarator(cast<ScopedDecl>(next_declarator)); |
| 283 | |
| 284 | return decl; |
| 285 | } |
| 286 | |
| 287 | //===----------------------------------------------------------------------===// |
Ted Kremenek | f9d56c8 | 2007-11-14 17:47:01 +0000 | [diff] [blame] | 288 | // FieldDecl Serialization. |
| 289 | //===----------------------------------------------------------------------===// |
| 290 | |
| 291 | void FieldDecl::EmitImpl(Serializer& S) const { |
| 292 | S.Emit(getType()); |
| 293 | NamedDecl::EmitInRec(S); |
| 294 | S.EmitOwnedPtr(BitWidth); |
| 295 | } |
| 296 | |
| 297 | FieldDecl* FieldDecl::CreateImpl(Deserializer& D) { |
| 298 | QualType DeclType = QualType::ReadVal(D); |
| 299 | FieldDecl* decl = new FieldDecl(SourceLocation(),NULL,DeclType); |
| 300 | decl->ReadInRec(D); |
| 301 | decl->BitWidth = D.ReadOwnedPtr<Expr>(); |
| 302 | return decl; |
| 303 | } |
| 304 | |
| 305 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 306 | // FunctionDecl Serialization. |
| 307 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 308 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 309 | void FunctionDecl::EmitImpl(Serializer& S) const { |
| 310 | S.EmitInt(SClass); // From FunctionDecl. |
| 311 | S.EmitBool(IsInline); // From FunctionDecl. |
| 312 | ValueDecl::EmitInRec(S); |
| 313 | S.EmitPtr(DeclChain); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 314 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 315 | // NOTE: We do not need to serialize out the number of parameters, because |
| 316 | // that is encoded in the type (accessed via getNumParams()). |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 317 | |
Ted Kremenek | d437f23 | 2007-11-13 22:51:08 +0000 | [diff] [blame] | 318 | if (ParamInfo != NULL) { |
| 319 | S.EmitBool(true); |
| 320 | S.BatchEmitOwnedPtrs(getNumParams(),&ParamInfo[0], Body, |
| 321 | getNextDeclarator()); |
| 322 | } |
| 323 | else { |
| 324 | S.EmitBool(false); |
| 325 | S.BatchEmitOwnedPtrs(Body,getNextDeclarator()); |
| 326 | } |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 327 | } |
| 328 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 329 | FunctionDecl* FunctionDecl::CreateImpl(Deserializer& D) { |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 330 | StorageClass SClass = static_cast<StorageClass>(D.ReadInt()); |
| 331 | bool IsInline = D.ReadBool(); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 332 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 333 | FunctionDecl* decl = |
| 334 | new FunctionDecl(SourceLocation(),NULL,QualType(),SClass,IsInline); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 335 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 336 | decl->ValueDecl::ReadInRec(D); |
| 337 | D.ReadPtr(decl->DeclChain); |
| 338 | |
| 339 | decl->ParamInfo = decl->getNumParams() |
| 340 | ? new ParmVarDecl*[decl->getNumParams()] |
| 341 | : NULL; |
| 342 | |
| 343 | Decl* next_declarator; |
| 344 | |
Ted Kremenek | d437f23 | 2007-11-13 22:51:08 +0000 | [diff] [blame] | 345 | bool hasParamDecls = D.ReadBool(); |
| 346 | |
| 347 | if (hasParamDecls) |
| 348 | D.BatchReadOwnedPtrs(decl->getNumParams(), |
| 349 | reinterpret_cast<Decl**>(&decl->ParamInfo[0]), |
| 350 | decl->Body, next_declarator); |
| 351 | else |
| 352 | D.BatchReadOwnedPtrs(decl->Body, next_declarator); |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 353 | |
| 354 | decl->setNextDeclarator(cast_or_null<ScopedDecl>(next_declarator)); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 355 | |
| 356 | return decl; |
| 357 | } |
Ted Kremenek | f7bf411 | 2007-11-05 21:49:34 +0000 | [diff] [blame] | 358 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 359 | //===----------------------------------------------------------------------===// |
Ted Kremenek | aad48b6 | 2007-11-14 08:06:37 +0000 | [diff] [blame] | 360 | // RecordDecl Serialization. |
| 361 | //===----------------------------------------------------------------------===// |
| 362 | |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 363 | void RecordDecl::EmitImpl(Serializer& S) const { |
Ted Kremenek | aad48b6 | 2007-11-14 08:06:37 +0000 | [diff] [blame] | 364 | ScopedDecl::EmitInRec(S); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 365 | S.EmitBool(isDefinition()); |
Ted Kremenek | aad48b6 | 2007-11-14 08:06:37 +0000 | [diff] [blame] | 366 | S.EmitBool(hasFlexibleArrayMember()); |
| 367 | S.EmitSInt(getNumMembers()); |
| 368 | if (getNumMembers() > 0) { |
| 369 | assert (Members); |
| 370 | S.BatchEmitOwnedPtrs((unsigned) getNumMembers(), |
| 371 | (Decl**) &Members[0],getNextDeclarator()); |
| 372 | } |
| 373 | else |
| 374 | ScopedDecl::EmitOutRec(S); |
| 375 | } |
| 376 | |
| 377 | RecordDecl* RecordDecl::CreateImpl(Decl::Kind DK, Deserializer& D) { |
| 378 | RecordDecl* decl = new RecordDecl(DK,SourceLocation(),NULL,NULL); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 379 | |
Ted Kremenek | aad48b6 | 2007-11-14 08:06:37 +0000 | [diff] [blame] | 380 | decl->ScopedDecl::ReadInRec(D); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 381 | decl->setDefinition(D.ReadBool()); |
Ted Kremenek | aad48b6 | 2007-11-14 08:06:37 +0000 | [diff] [blame] | 382 | decl->setHasFlexibleArrayMember(D.ReadBool()); |
| 383 | decl->NumMembers = D.ReadSInt(); |
| 384 | |
| 385 | if (decl->getNumMembers() > 0) { |
| 386 | Decl* next_declarator; |
| 387 | decl->Members = new FieldDecl*[(unsigned) decl->getNumMembers()]; |
| 388 | |
| 389 | D.BatchReadOwnedPtrs((unsigned) decl->getNumMembers(), |
| 390 | (Decl**) &decl->Members[0], |
| 391 | next_declarator); |
| 392 | |
| 393 | decl->setNextDeclarator(cast_or_null<ScopedDecl>(next_declarator)); |
| 394 | } |
| 395 | else |
| 396 | decl->ScopedDecl::ReadOutRec(D); |
| 397 | |
| 398 | return decl; |
| 399 | } |
| 400 | |
| 401 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 402 | // TypedefDecl Serialization. |
| 403 | //===----------------------------------------------------------------------===// |
| 404 | |
| 405 | void TypedefDecl::EmitImpl(Serializer& S) const { |
Ted Kremenek | 2ebc89f | 2007-11-06 19:51:47 +0000 | [diff] [blame] | 406 | S.Emit(UnderlyingType); |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 407 | ScopedDecl::EmitInRec(S); |
| 408 | ScopedDecl::EmitOutRec(S); |
Ted Kremenek | f7bf411 | 2007-11-05 21:49:34 +0000 | [diff] [blame] | 409 | } |
| 410 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 411 | TypedefDecl* TypedefDecl::CreateImpl(Deserializer& D) { |
| 412 | QualType T = QualType::ReadVal(D); |
| 413 | |
| 414 | TypedefDecl* decl = new TypedefDecl(SourceLocation(),NULL,T,NULL); |
| 415 | |
| 416 | decl->ScopedDecl::ReadInRec(D); |
| 417 | decl->ScopedDecl::ReadOutRec(D); |
| 418 | |
Ted Kremenek | f7bf411 | 2007-11-05 21:49:34 +0000 | [diff] [blame] | 419 | return decl; |
| 420 | } |