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