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