Ted Kremenek | 2f1f8cb | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 1 | //===--- DeclSerialization.cpp - Serialization of Decls ---------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Ted Kremenek | 2f1f8cb | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Gabor Greif | 843e934 | 2008-03-06 10:40:09 +0000 | [diff] [blame] | 10 | // This file defines methods that implement bitcode serialization for Decls. |
Ted Kremenek | 2f1f8cb | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Sam Bishop | f3c63ae | 2008-04-11 14:49:10 +0000 | [diff] [blame] | 14 | #include "clang/AST/ASTContext.h" |
Ted Kremenek | 2f1f8cb | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 15 | #include "clang/AST/Decl.h" |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclCXX.h" |
Ted Kremenek | 2f1f8cb | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 17 | #include "clang/AST/Expr.h" |
| 18 | #include "llvm/Bitcode/Serialize.h" |
| 19 | #include "llvm/Bitcode/Deserialize.h" |
| 20 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 21 | using llvm::Serializer; |
| 22 | using llvm::Deserializer; |
| 23 | using llvm::SerializedPtrID; |
| 24 | |
Ted Kremenek | 2f1f8cb | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 25 | using namespace clang; |
| 26 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 27 | //===----------------------------------------------------------------------===// |
| 28 | // Decl Serialization: Dispatch code to handle specialized decl types. |
| 29 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 8af8fe3 | 2007-11-05 21:38:00 +0000 | [diff] [blame] | 30 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 31 | void Decl::Emit(Serializer& S) const { |
| 32 | S.EmitInt(getKind()); |
| 33 | EmitImpl(S); |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 34 | if (const DeclContext *DC = dyn_cast<const DeclContext>(this)) |
| 35 | DC->EmitOutRec(S); |
Ted Kremenek | 2f1f8cb | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 38 | Decl* Decl::Create(Deserializer& D, ASTContext& C) { |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 39 | |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 40 | Decl *Dcl; |
Ted Kremenek | 2ebc89f | 2007-11-06 19:51:47 +0000 | [diff] [blame] | 41 | Kind k = static_cast<Kind>(D.ReadInt()); |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 42 | |
Ted Kremenek | 2ebc89f | 2007-11-06 19:51:47 +0000 | [diff] [blame] | 43 | switch (k) { |
| 44 | default: |
| 45 | assert (false && "Not implemented."); |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 46 | |
Argyrios Kyrtzidis | ef17782 | 2008-04-17 14:40:12 +0000 | [diff] [blame] | 47 | case TranslationUnit: |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 48 | Dcl = TranslationUnitDecl::CreateImpl(D, C); |
| 49 | break; |
Argyrios Kyrtzidis | ef17782 | 2008-04-17 14:40:12 +0000 | [diff] [blame] | 50 | |
Argyrios Kyrtzidis | 2d1c5d3 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 51 | case Namespace: |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 52 | Dcl = NamespaceDecl::CreateImpl(D, C); |
| 53 | break; |
Argyrios Kyrtzidis | 2d1c5d3 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 54 | |
Steve Naroff | 248a753 | 2008-04-15 22:42:06 +0000 | [diff] [blame] | 55 | case Var: |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 56 | Dcl = VarDecl::CreateImpl(D, C); |
| 57 | break; |
Ted Kremenek | 2ebc89f | 2007-11-06 19:51:47 +0000 | [diff] [blame] | 58 | |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 59 | case Enum: |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 60 | Dcl = EnumDecl::CreateImpl(D, C); |
| 61 | break; |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 62 | |
| 63 | case EnumConstant: |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 64 | Dcl = EnumConstantDecl::CreateImpl(D, C); |
| 65 | break; |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 66 | |
Ted Kremenek | f9d56c8 | 2007-11-14 17:47:01 +0000 | [diff] [blame] | 67 | case Field: |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 68 | Dcl = FieldDecl::CreateImpl(D, C); |
| 69 | break; |
Ted Kremenek | f9d56c8 | 2007-11-14 17:47:01 +0000 | [diff] [blame] | 70 | |
Ted Kremenek | 2ebc89f | 2007-11-06 19:51:47 +0000 | [diff] [blame] | 71 | case ParmVar: |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 72 | Dcl = ParmVarDecl::CreateImpl(D, C); |
| 73 | break; |
Ted Kremenek | 2ebc89f | 2007-11-06 19:51:47 +0000 | [diff] [blame] | 74 | |
| 75 | case Function: |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 76 | Dcl = FunctionDecl::CreateImpl(D, C); |
| 77 | break; |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 78 | |
| 79 | case OverloadedFunction: |
| 80 | Dcl = OverloadedFunctionDecl::CreateImpl(D, C); |
| 81 | break; |
| 82 | |
Argyrios Kyrtzidis | 35bc082 | 2008-10-15 00:42:39 +0000 | [diff] [blame] | 83 | case Record: |
| 84 | Dcl = RecordDecl::CreateImpl(D, C); |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 85 | break; |
Ted Kremenek | aad48b6 | 2007-11-14 08:06:37 +0000 | [diff] [blame] | 86 | |
Ted Kremenek | 2ebc89f | 2007-11-06 19:51:47 +0000 | [diff] [blame] | 87 | case Typedef: |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 88 | Dcl = TypedefDecl::CreateImpl(D, C); |
| 89 | break; |
Anders Carlsson | dfab6cb | 2008-02-08 00:33:21 +0000 | [diff] [blame] | 90 | |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 91 | case TemplateTypeParm: |
| 92 | Dcl = TemplateTypeParmDecl::CreateImpl(D, C); |
| 93 | break; |
| 94 | |
Anders Carlsson | dfab6cb | 2008-02-08 00:33:21 +0000 | [diff] [blame] | 95 | case FileScopeAsm: |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 96 | Dcl = FileScopeAsmDecl::CreateImpl(D, C); |
| 97 | break; |
Ted Kremenek | 2ebc89f | 2007-11-06 19:51:47 +0000 | [diff] [blame] | 98 | } |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 99 | |
| 100 | if (DeclContext *DC = dyn_cast<DeclContext>(Dcl)) |
| 101 | DC->ReadOutRec(D, C); |
| 102 | |
| 103 | return Dcl; |
Ted Kremenek | 2f1f8cb | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 104 | } |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 105 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 106 | //===----------------------------------------------------------------------===// |
| 107 | // Common serialization logic for subclasses of Decl. |
| 108 | //===----------------------------------------------------------------------===// |
| 109 | |
| 110 | void Decl::EmitInRec(Serializer& S) const { |
| 111 | S.Emit(getLocation()); // From Decl. |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 112 | } |
| 113 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 114 | void Decl::ReadInRec(Deserializer& D, ASTContext& C) { |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 115 | Loc = SourceLocation::ReadVal(D); // From Decl. |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 118 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 119 | // Common serialization logic for subclasses of DeclContext. |
| 120 | //===----------------------------------------------------------------------===// |
| 121 | |
| 122 | void DeclContext::EmitOutRec(Serializer& S) const { |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 123 | S.EmitInt(Decls.size()); |
| 124 | for (decl_iterator D = decls_begin(); D != decls_end(); ++D) { |
| 125 | bool Owned = ((*D)->getLexicalDeclContext() == this && |
| 126 | DeclKind != Decl::TranslationUnit && |
| 127 | !isFunctionOrMethod()); |
| 128 | S.EmitBool(Owned); |
| 129 | if (Owned) |
| 130 | S.EmitOwnedPtr(*D); |
| 131 | else |
| 132 | S.EmitPtr(*D); |
| 133 | } |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | void DeclContext::ReadOutRec(Deserializer& D, ASTContext& C) { |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 137 | unsigned NumDecls = D.ReadInt(); |
| 138 | Decls.resize(NumDecls); |
| 139 | for (unsigned Idx = 0; Idx < NumDecls; ++Idx) { |
| 140 | bool Owned = D.ReadBool(); |
| 141 | if (Owned) |
| 142 | Decls[Idx] = cast_or_null<ScopedDecl>(D.ReadOwnedPtr<Decl>(C)); |
| 143 | else |
| 144 | D.ReadPtr<ScopedDecl>(Decls[Idx]); |
| 145 | } |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 149 | // Common serialization logic for subclasses of NamedDecl. |
| 150 | //===----------------------------------------------------------------------===// |
| 151 | |
| 152 | void NamedDecl::EmitInRec(Serializer& S) const { |
| 153 | Decl::EmitInRec(S); |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 154 | S.EmitInt(Name.getNameKind()); |
| 155 | |
| 156 | switch (Name.getNameKind()) { |
| 157 | case DeclarationName::Identifier: |
| 158 | S.EmitPtr(Name.getAsIdentifierInfo()); |
| 159 | break; |
| 160 | |
| 161 | case DeclarationName::ObjCZeroArgSelector: |
| 162 | case DeclarationName::ObjCOneArgSelector: |
| 163 | case DeclarationName::ObjCMultiArgSelector: |
| 164 | Name.getObjCSelector().Emit(S); |
| 165 | break; |
| 166 | |
| 167 | case DeclarationName::CXXConstructorName: |
| 168 | case DeclarationName::CXXDestructorName: |
| 169 | case DeclarationName::CXXConversionFunctionName: |
| 170 | Name.getCXXNameType().Emit(S); |
| 171 | break; |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 172 | |
| 173 | case DeclarationName::CXXOperatorName: |
| 174 | S.EmitInt(Name.getCXXOverloadedOperator()); |
| 175 | break; |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 176 | } |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 179 | void NamedDecl::ReadInRec(Deserializer& D, ASTContext& C) { |
| 180 | Decl::ReadInRec(D, C); |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 181 | |
| 182 | DeclarationName::NameKind Kind |
| 183 | = static_cast<DeclarationName::NameKind>(D.ReadInt()); |
| 184 | switch (Kind) { |
| 185 | case DeclarationName::Identifier: { |
| 186 | IdentifierInfo *Identifier; |
| 187 | D.ReadPtr(Identifier); |
| 188 | Name = Identifier; |
| 189 | break; |
| 190 | } |
| 191 | |
| 192 | case DeclarationName::ObjCZeroArgSelector: |
| 193 | case DeclarationName::ObjCOneArgSelector: |
| 194 | case DeclarationName::ObjCMultiArgSelector: |
| 195 | Name = Selector::ReadVal(D); |
| 196 | break; |
| 197 | |
| 198 | case DeclarationName::CXXConstructorName: |
| 199 | Name = C.DeclarationNames.getCXXConstructorName(QualType::ReadVal(D)); |
| 200 | break; |
| 201 | |
| 202 | case DeclarationName::CXXDestructorName: |
| 203 | Name = C.DeclarationNames.getCXXDestructorName(QualType::ReadVal(D)); |
| 204 | break; |
| 205 | |
| 206 | case DeclarationName::CXXConversionFunctionName: |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 207 | Name |
| 208 | = C.DeclarationNames.getCXXConversionFunctionName(QualType::ReadVal(D)); |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 209 | break; |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 210 | |
| 211 | case DeclarationName::CXXOperatorName: { |
| 212 | OverloadedOperatorKind Op |
| 213 | = static_cast<OverloadedOperatorKind>(D.ReadInt()); |
| 214 | Name = C.DeclarationNames.getCXXOperatorName(Op); |
| 215 | break; |
| 216 | } |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 217 | } |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 218 | } |
| 219 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 220 | //===----------------------------------------------------------------------===// |
| 221 | // Common serialization logic for subclasses of ScopedDecl. |
| 222 | //===----------------------------------------------------------------------===// |
| 223 | |
| 224 | void ScopedDecl::EmitInRec(Serializer& S) const { |
| 225 | NamedDecl::EmitInRec(S); |
Chris Lattner | b048c98 | 2008-04-06 04:47:34 +0000 | [diff] [blame] | 226 | S.EmitPtr(cast_or_null<Decl>(getDeclContext())); // From ScopedDecl. |
Argyrios Kyrtzidis | 5239304 | 2008-11-09 23:41:00 +0000 | [diff] [blame] | 227 | S.EmitPtr(cast_or_null<Decl>(getLexicalDeclContext())); // From ScopedDecl. |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 230 | void ScopedDecl::ReadInRec(Deserializer& D, ASTContext& C) { |
| 231 | NamedDecl::ReadInRec(D, C); |
Argyrios Kyrtzidis | 5239304 | 2008-11-09 23:41:00 +0000 | [diff] [blame] | 232 | |
| 233 | assert(DeclCtx == 0); |
| 234 | |
| 235 | const SerializedPtrID &SemaDCPtrID = D.ReadPtrID(); |
| 236 | const SerializedPtrID &LexicalDCPtrID = D.ReadPtrID(); |
| 237 | |
| 238 | if (SemaDCPtrID == LexicalDCPtrID) { |
| 239 | // Allow back-patching. Observe that we register the variable of the |
| 240 | // *object* for back-patching. Its actual value will get filled in later. |
| 241 | D.ReadUIntPtr(DeclCtx, SemaDCPtrID); |
| 242 | } |
| 243 | else { |
| 244 | MultipleDC *MDC = new MultipleDC(); |
| 245 | DeclCtx = reinterpret_cast<uintptr_t>(MDC) | 0x1; |
| 246 | // Allow back-patching. Observe that we register the variable of the |
| 247 | // *object* for back-patching. Its actual value will get filled in later. |
Argyrios Kyrtzidis | b0b847e | 2008-11-14 23:32:45 +0000 | [diff] [blame] | 248 | D.ReadPtr(MDC->SemanticDC, SemaDCPtrID); |
| 249 | D.ReadPtr(MDC->LexicalDC, LexicalDCPtrID); |
Argyrios Kyrtzidis | 5239304 | 2008-11-09 23:41:00 +0000 | [diff] [blame] | 250 | } |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | //===------------------------------------------------------------===// |
| 254 | // NOTE: Not all subclasses of ScopedDecl will use the "OutRec" // |
| 255 | // methods. This is because owned pointers are usually "batched" // |
| 256 | // together for efficiency. // |
| 257 | //===------------------------------------------------------------===// |
| 258 | |
| 259 | void ScopedDecl::EmitOutRec(Serializer& S) const { |
| 260 | S.EmitOwnedPtr(getNextDeclarator()); // From ScopedDecl. |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 261 | } |
| 262 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 263 | void ScopedDecl::ReadOutRec(Deserializer& D, ASTContext& C) { |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 264 | NextDeclarator = |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 265 | cast_or_null<ScopedDecl>(D.ReadOwnedPtr<Decl>(C)); // From ScopedDecl. |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 266 | } |
| 267 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 268 | //===----------------------------------------------------------------------===// |
| 269 | // Common serialization logic for subclasses of ValueDecl. |
| 270 | //===----------------------------------------------------------------------===// |
| 271 | |
| 272 | void ValueDecl::EmitInRec(Serializer& S) const { |
| 273 | ScopedDecl::EmitInRec(S); |
| 274 | S.Emit(getType()); // From ValueDecl. |
| 275 | } |
| 276 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 277 | void ValueDecl::ReadInRec(Deserializer& D, ASTContext& C) { |
| 278 | ScopedDecl::ReadInRec(D, C); |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 279 | DeclType = QualType::ReadVal(D); // From ValueDecl. |
| 280 | } |
| 281 | |
| 282 | //===----------------------------------------------------------------------===// |
| 283 | // Common serialization logic for subclasses of VarDecl. |
| 284 | //===----------------------------------------------------------------------===// |
| 285 | |
| 286 | void VarDecl::EmitInRec(Serializer& S) const { |
| 287 | ValueDecl::EmitInRec(S); |
| 288 | S.EmitInt(getStorageClass()); // From VarDecl. |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 289 | } |
| 290 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 291 | void VarDecl::ReadInRec(Deserializer& D, ASTContext& C) { |
| 292 | ValueDecl::ReadInRec(D, C); |
Fariborz Jahanian | de7b4cd | 2007-12-13 00:54:18 +0000 | [diff] [blame] | 293 | SClass = static_cast<StorageClass>(D.ReadInt()); // From VarDecl. |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | //===------------------------------------------------------------===// |
| 297 | // NOTE: VarDecl has its own "OutRec" methods that doesn't use // |
| 298 | // the one define in ScopedDecl. This is to batch emit the // |
| 299 | // owned pointers, which results in a smaller output. |
| 300 | //===------------------------------------------------------------===// |
| 301 | |
| 302 | void VarDecl::EmitOutRec(Serializer& S) const { |
| 303 | // Emit these last because they will create records of their own. |
| 304 | S.BatchEmitOwnedPtrs(getInit(), // From VarDecl. |
| 305 | getNextDeclarator()); // From ScopedDecl. |
| 306 | } |
| 307 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 308 | void VarDecl::ReadOutRec(Deserializer& D, ASTContext& C) { |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 309 | Decl* next_declarator; |
| 310 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 311 | D.BatchReadOwnedPtrs(Init, // From VarDecl. |
| 312 | next_declarator, // From ScopedDecl. |
| 313 | C); |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 314 | |
| 315 | setNextDeclarator(cast_or_null<ScopedDecl>(next_declarator)); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 319 | void VarDecl::EmitImpl(Serializer& S) const { |
| 320 | VarDecl::EmitInRec(S); |
| 321 | VarDecl::EmitOutRec(S); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 322 | } |
| 323 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 324 | void VarDecl::ReadImpl(Deserializer& D, ASTContext& C) { |
| 325 | ReadInRec(D, C); |
| 326 | ReadOutRec(D, C); |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | ef17782 | 2008-04-17 14:40:12 +0000 | [diff] [blame] | 330 | // TranslationUnitDecl Serialization. |
| 331 | //===----------------------------------------------------------------------===// |
| 332 | |
| 333 | void TranslationUnitDecl::EmitImpl(llvm::Serializer& S) const |
| 334 | { |
| 335 | Decl::EmitInRec(S); |
| 336 | } |
| 337 | |
| 338 | TranslationUnitDecl* TranslationUnitDecl::CreateImpl(Deserializer& D, |
| 339 | ASTContext& C) { |
| 340 | void *Mem = C.getAllocator().Allocate<TranslationUnitDecl>(); |
Argyrios Kyrtzidis | 2d1c5d3 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 341 | TranslationUnitDecl* decl = new (Mem) TranslationUnitDecl(); |
Argyrios Kyrtzidis | ef17782 | 2008-04-17 14:40:12 +0000 | [diff] [blame] | 342 | |
| 343 | decl->Decl::ReadInRec(D, C); |
| 344 | |
| 345 | return decl; |
| 346 | } |
| 347 | |
| 348 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 2d1c5d3 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 349 | // NamespaceDecl Serialization. |
| 350 | //===----------------------------------------------------------------------===// |
| 351 | |
| 352 | void NamespaceDecl::EmitImpl(llvm::Serializer& S) const |
| 353 | { |
| 354 | ScopedDecl::EmitInRec(S); |
| 355 | S.Emit(getLBracLoc()); |
| 356 | S.Emit(getRBracLoc()); |
| 357 | ScopedDecl::EmitOutRec(S); |
| 358 | } |
| 359 | |
| 360 | NamespaceDecl* NamespaceDecl::CreateImpl(Deserializer& D, ASTContext& C) { |
| 361 | void *Mem = C.getAllocator().Allocate<NamespaceDecl>(); |
| 362 | NamespaceDecl* decl = new (Mem) NamespaceDecl(0, SourceLocation(), 0); |
| 363 | |
| 364 | decl->ScopedDecl::ReadInRec(D, C); |
| 365 | decl->LBracLoc = SourceLocation::ReadVal(D); |
| 366 | decl->RBracLoc = SourceLocation::ReadVal(D); |
| 367 | decl->ScopedDecl::ReadOutRec(D, C); |
| 368 | |
| 369 | return decl; |
| 370 | } |
| 371 | |
| 372 | //===----------------------------------------------------------------------===// |
Steve Naroff | 248a753 | 2008-04-15 22:42:06 +0000 | [diff] [blame] | 373 | // VarDecl Serialization. |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 374 | //===----------------------------------------------------------------------===// |
| 375 | |
Steve Naroff | 248a753 | 2008-04-15 22:42:06 +0000 | [diff] [blame] | 376 | VarDecl* VarDecl::CreateImpl(Deserializer& D, ASTContext& C) { |
| 377 | void *Mem = C.getAllocator().Allocate<VarDecl>(); |
| 378 | VarDecl* decl = |
| 379 | new (Mem) VarDecl(Var, 0, SourceLocation(), NULL, QualType(), None, NULL); |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 380 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 381 | decl->VarDecl::ReadImpl(D, C); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 382 | return decl; |
| 383 | } |
| 384 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 385 | //===----------------------------------------------------------------------===// |
Steve Naroff | 248a753 | 2008-04-15 22:42:06 +0000 | [diff] [blame] | 386 | // ParmVarDecl Serialization. |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 387 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 388 | |
Ted Kremenek | 137bd91 | 2007-12-13 06:28:13 +0000 | [diff] [blame] | 389 | void ParmVarDecl::EmitImpl(llvm::Serializer& S) const { |
| 390 | VarDecl::EmitImpl(S); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 391 | S.EmitInt(getObjCDeclQualifier()); // From ParmVarDecl. |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 392 | S.EmitOwnedPtr(getDefaultArg()); // From ParmVarDecl. |
Ted Kremenek | 137bd91 | 2007-12-13 06:28:13 +0000 | [diff] [blame] | 393 | } |
| 394 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 395 | ParmVarDecl* ParmVarDecl::CreateImpl(Deserializer& D, ASTContext& C) { |
Sam Bishop | f3c63ae | 2008-04-11 14:49:10 +0000 | [diff] [blame] | 396 | void *Mem = C.getAllocator().Allocate<ParmVarDecl>(); |
| 397 | ParmVarDecl* decl = new (Mem) |
| 398 | ParmVarDecl(0, SourceLocation(), NULL, QualType(), None, NULL, NULL); |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 399 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 400 | decl->VarDecl::ReadImpl(D, C); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 401 | decl->objcDeclQualifier = static_cast<ObjCDeclQualifier>(D.ReadInt()); |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 402 | decl->DefaultArg = D.ReadOwnedPtr<Expr>(C); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 403 | return decl; |
| 404 | } |
| 405 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 406 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 407 | // EnumDecl Serialization. |
| 408 | //===----------------------------------------------------------------------===// |
| 409 | |
| 410 | void EnumDecl::EmitImpl(Serializer& S) const { |
| 411 | ScopedDecl::EmitInRec(S); |
| 412 | S.EmitBool(isDefinition()); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 413 | S.Emit(IntegerType); |
| 414 | S.EmitOwnedPtr(getNextDeclarator()); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 417 | EnumDecl* EnumDecl::CreateImpl(Deserializer& D, ASTContext& C) { |
Sam Bishop | f3c63ae | 2008-04-11 14:49:10 +0000 | [diff] [blame] | 418 | void *Mem = C.getAllocator().Allocate<EnumDecl>(); |
| 419 | EnumDecl* decl = new (Mem) EnumDecl(0, SourceLocation(), NULL, NULL); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 420 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 421 | decl->ScopedDecl::ReadInRec(D, C); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 422 | decl->setDefinition(D.ReadBool()); |
| 423 | decl->IntegerType = QualType::ReadVal(D); |
| 424 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 425 | Decl* next_declarator = D.ReadOwnedPtr<Decl>(C); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 426 | decl->setNextDeclarator(cast_or_null<ScopedDecl>(next_declarator)); |
| 427 | |
| 428 | return decl; |
| 429 | } |
| 430 | |
| 431 | //===----------------------------------------------------------------------===// |
| 432 | // EnumConstantDecl Serialization. |
| 433 | //===----------------------------------------------------------------------===// |
| 434 | |
| 435 | void EnumConstantDecl::EmitImpl(Serializer& S) const { |
| 436 | S.Emit(Val); |
| 437 | ValueDecl::EmitInRec(S); |
| 438 | S.BatchEmitOwnedPtrs(getNextDeclarator(),Init); |
| 439 | } |
| 440 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 441 | EnumConstantDecl* EnumConstantDecl::CreateImpl(Deserializer& D, ASTContext& C) { |
Ted Kremenek | 049b168 | 2007-11-14 23:38:09 +0000 | [diff] [blame] | 442 | llvm::APSInt val(1); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 443 | D.Read(val); |
| 444 | |
Sam Bishop | f3c63ae | 2008-04-11 14:49:10 +0000 | [diff] [blame] | 445 | void *Mem = C.getAllocator().Allocate<EnumConstantDecl>(); |
| 446 | EnumConstantDecl* decl = new (Mem) |
| 447 | EnumConstantDecl(0, SourceLocation(), NULL, QualType(), NULL, val, NULL); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 448 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 449 | decl->ValueDecl::ReadInRec(D, C); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 450 | |
| 451 | Decl* next_declarator; |
| 452 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 453 | D.BatchReadOwnedPtrs(next_declarator, decl->Init, C); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 454 | |
Ted Kremenek | 049b168 | 2007-11-14 23:38:09 +0000 | [diff] [blame] | 455 | decl->setNextDeclarator(cast_or_null<ScopedDecl>(next_declarator)); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 456 | |
| 457 | return decl; |
| 458 | } |
| 459 | |
| 460 | //===----------------------------------------------------------------------===// |
Ted Kremenek | f9d56c8 | 2007-11-14 17:47:01 +0000 | [diff] [blame] | 461 | // FieldDecl Serialization. |
| 462 | //===----------------------------------------------------------------------===// |
| 463 | |
| 464 | void FieldDecl::EmitImpl(Serializer& S) const { |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 465 | S.EmitBool(Mutable); |
Ted Kremenek | f9d56c8 | 2007-11-14 17:47:01 +0000 | [diff] [blame] | 466 | S.Emit(getType()); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 467 | ScopedDecl::EmitInRec(S); |
Ted Kremenek | f9d56c8 | 2007-11-14 17:47:01 +0000 | [diff] [blame] | 468 | S.EmitOwnedPtr(BitWidth); |
| 469 | } |
| 470 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 471 | FieldDecl* FieldDecl::CreateImpl(Deserializer& D, ASTContext& C) { |
Sam Bishop | f3c63ae | 2008-04-11 14:49:10 +0000 | [diff] [blame] | 472 | void *Mem = C.getAllocator().Allocate<FieldDecl>(); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 473 | FieldDecl* decl = new (Mem) FieldDecl(Field, 0, SourceLocation(), NULL, |
| 474 | QualType(), 0, false, 0); |
| 475 | decl->Mutable = D.ReadBool(); |
Ted Kremenek | 21d50e1 | 2007-11-14 22:51:02 +0000 | [diff] [blame] | 476 | decl->DeclType.ReadBackpatch(D); |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 477 | decl->ReadInRec(D, C); |
| 478 | decl->BitWidth = D.ReadOwnedPtr<Expr>(C); |
Ted Kremenek | f9d56c8 | 2007-11-14 17:47:01 +0000 | [diff] [blame] | 479 | return decl; |
| 480 | } |
| 481 | |
| 482 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 483 | // FunctionDecl Serialization. |
| 484 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 485 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 486 | void FunctionDecl::EmitImpl(Serializer& S) const { |
| 487 | S.EmitInt(SClass); // From FunctionDecl. |
| 488 | S.EmitBool(IsInline); // From FunctionDecl. |
| 489 | ValueDecl::EmitInRec(S); |
Ted Kremenek | 3bbc198 | 2008-05-20 03:33:58 +0000 | [diff] [blame] | 490 | S.EmitPtr(PreviousDeclaration); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 491 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 492 | // NOTE: We do not need to serialize out the number of parameters, because |
| 493 | // that is encoded in the type (accessed via getNumParams()). |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 494 | |
Ted Kremenek | d437f23 | 2007-11-13 22:51:08 +0000 | [diff] [blame] | 495 | if (ParamInfo != NULL) { |
| 496 | S.EmitBool(true); |
Argyrios Kyrtzidis | dc5ddbf | 2008-11-07 14:22:23 +0000 | [diff] [blame] | 497 | S.EmitInt(getNumParams()); |
Ted Kremenek | d437f23 | 2007-11-13 22:51:08 +0000 | [diff] [blame] | 498 | S.BatchEmitOwnedPtrs(getNumParams(),&ParamInfo[0], Body, |
| 499 | getNextDeclarator()); |
| 500 | } |
| 501 | else { |
| 502 | S.EmitBool(false); |
| 503 | S.BatchEmitOwnedPtrs(Body,getNextDeclarator()); |
| 504 | } |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 505 | } |
| 506 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 507 | FunctionDecl* FunctionDecl::CreateImpl(Deserializer& D, ASTContext& C) { |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 508 | StorageClass SClass = static_cast<StorageClass>(D.ReadInt()); |
| 509 | bool IsInline = D.ReadBool(); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 510 | |
Sam Bishop | f3c63ae | 2008-04-11 14:49:10 +0000 | [diff] [blame] | 511 | void *Mem = C.getAllocator().Allocate<FunctionDecl>(); |
| 512 | FunctionDecl* decl = new (Mem) |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 513 | FunctionDecl(Function, 0, SourceLocation(), DeclarationName(), |
Argyrios Kyrtzidis | d3bb44f | 2008-06-09 21:05:31 +0000 | [diff] [blame] | 514 | QualType(), SClass, IsInline, 0); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 515 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 516 | decl->ValueDecl::ReadInRec(D, C); |
Ted Kremenek | 3bbc198 | 2008-05-20 03:33:58 +0000 | [diff] [blame] | 517 | D.ReadPtr(decl->PreviousDeclaration); |
Ted Kremenek | da25685 | 2007-11-16 18:11:10 +0000 | [diff] [blame] | 518 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 519 | Decl* next_declarator; |
| 520 | |
Argyrios Kyrtzidis | dc5ddbf | 2008-11-07 14:22:23 +0000 | [diff] [blame] | 521 | int numParams; |
Ted Kremenek | d437f23 | 2007-11-13 22:51:08 +0000 | [diff] [blame] | 522 | bool hasParamDecls = D.ReadBool(); |
Argyrios Kyrtzidis | dc5ddbf | 2008-11-07 14:22:23 +0000 | [diff] [blame] | 523 | if (hasParamDecls) |
| 524 | numParams = D.ReadInt(); |
Ted Kremenek | da25685 | 2007-11-16 18:11:10 +0000 | [diff] [blame] | 525 | |
| 526 | decl->ParamInfo = hasParamDecls |
Argyrios Kyrtzidis | dc5ddbf | 2008-11-07 14:22:23 +0000 | [diff] [blame] | 527 | ? new ParmVarDecl*[numParams] |
Ted Kremenek | da25685 | 2007-11-16 18:11:10 +0000 | [diff] [blame] | 528 | : NULL; |
Ted Kremenek | d437f23 | 2007-11-13 22:51:08 +0000 | [diff] [blame] | 529 | |
| 530 | if (hasParamDecls) |
Argyrios Kyrtzidis | dc5ddbf | 2008-11-07 14:22:23 +0000 | [diff] [blame] | 531 | D.BatchReadOwnedPtrs(numParams, |
Ted Kremenek | d437f23 | 2007-11-13 22:51:08 +0000 | [diff] [blame] | 532 | reinterpret_cast<Decl**>(&decl->ParamInfo[0]), |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 533 | decl->Body, next_declarator, C); |
Ted Kremenek | d437f23 | 2007-11-13 22:51:08 +0000 | [diff] [blame] | 534 | else |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 535 | D.BatchReadOwnedPtrs(decl->Body, next_declarator, C); |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 536 | |
| 537 | decl->setNextDeclarator(cast_or_null<ScopedDecl>(next_declarator)); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 538 | |
| 539 | return decl; |
| 540 | } |
Ted Kremenek | f7bf411 | 2007-11-05 21:49:34 +0000 | [diff] [blame] | 541 | |
Steve Naroff | 56ee689 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 542 | void BlockDecl::EmitImpl(Serializer& S) const { |
| 543 | // FIXME: what about arguments? |
| 544 | S.Emit(getCaretLocation()); |
| 545 | S.EmitOwnedPtr(Body); |
| 546 | } |
| 547 | |
| 548 | BlockDecl* BlockDecl::CreateImpl(Deserializer& D, ASTContext& C) { |
| 549 | QualType Q = QualType::ReadVal(D); |
| 550 | SourceLocation L = SourceLocation::ReadVal(D); |
| 551 | /*CompoundStmt* BodyStmt = cast<CompoundStmt>(*/D.ReadOwnedPtr<Stmt>(C)/*)*/; |
| 552 | assert(0 && "Cannot deserialize BlockBlockExpr yet"); |
| 553 | // FIXME: need to handle parameters. |
| 554 | //return new BlockBlockExpr(L, Q, BodyStmt); |
| 555 | return 0; |
| 556 | } |
| 557 | |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 558 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 559 | // OverloadedFunctionDecl Serialization. |
| 560 | //===----------------------------------------------------------------------===// |
| 561 | |
| 562 | void OverloadedFunctionDecl::EmitImpl(Serializer& S) const { |
| 563 | NamedDecl::EmitInRec(S); |
| 564 | |
| 565 | S.EmitInt(getNumFunctions()); |
| 566 | for (unsigned func = 0; func < getNumFunctions(); ++func) |
| 567 | S.EmitPtr(Functions[func]); |
| 568 | } |
| 569 | |
| 570 | OverloadedFunctionDecl * |
| 571 | OverloadedFunctionDecl::CreateImpl(Deserializer& D, ASTContext& C) { |
| 572 | void *Mem = C.getAllocator().Allocate<OverloadedFunctionDecl>(); |
| 573 | OverloadedFunctionDecl* decl = new (Mem) |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 574 | OverloadedFunctionDecl(0, DeclarationName()); |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 575 | |
| 576 | decl->NamedDecl::ReadInRec(D, C); |
| 577 | |
| 578 | unsigned numFunctions = D.ReadInt(); |
| 579 | decl->Functions.reserve(numFunctions); |
| 580 | for (unsigned func = 0; func < numFunctions; ++func) |
| 581 | D.ReadPtr(decl->Functions[func]); |
| 582 | |
| 583 | return decl; |
| 584 | } |
| 585 | |
| 586 | //===----------------------------------------------------------------------===// |
Ted Kremenek | aad48b6 | 2007-11-14 08:06:37 +0000 | [diff] [blame] | 587 | // RecordDecl Serialization. |
| 588 | //===----------------------------------------------------------------------===// |
| 589 | |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 590 | void RecordDecl::EmitImpl(Serializer& S) const { |
Argyrios Kyrtzidis | 35bc082 | 2008-10-15 00:42:39 +0000 | [diff] [blame] | 591 | S.EmitInt(getTagKind()); |
| 592 | |
Ted Kremenek | aad48b6 | 2007-11-14 08:06:37 +0000 | [diff] [blame] | 593 | ScopedDecl::EmitInRec(S); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 594 | S.EmitBool(isDefinition()); |
Ted Kremenek | aad48b6 | 2007-11-14 08:06:37 +0000 | [diff] [blame] | 595 | S.EmitBool(hasFlexibleArrayMember()); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 596 | ScopedDecl::EmitOutRec(S); |
Ted Kremenek | aad48b6 | 2007-11-14 08:06:37 +0000 | [diff] [blame] | 597 | } |
| 598 | |
Argyrios Kyrtzidis | 35bc082 | 2008-10-15 00:42:39 +0000 | [diff] [blame] | 599 | RecordDecl* RecordDecl::CreateImpl(Deserializer& D, ASTContext& C) { |
| 600 | TagKind TK = TagKind(D.ReadInt()); |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 601 | |
Sam Bishop | f3c63ae | 2008-04-11 14:49:10 +0000 | [diff] [blame] | 602 | void *Mem = C.getAllocator().Allocate<RecordDecl>(); |
Argyrios Kyrtzidis | 35bc082 | 2008-10-15 00:42:39 +0000 | [diff] [blame] | 603 | RecordDecl* decl = new (Mem) RecordDecl(Record, TK, 0, SourceLocation(), NULL); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 604 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 605 | decl->ScopedDecl::ReadInRec(D, C); |
Ted Kremenek | 583e008 | 2007-11-14 18:12:19 +0000 | [diff] [blame] | 606 | decl->setDefinition(D.ReadBool()); |
Ted Kremenek | aad48b6 | 2007-11-14 08:06:37 +0000 | [diff] [blame] | 607 | decl->setHasFlexibleArrayMember(D.ReadBool()); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 608 | decl->ScopedDecl::ReadOutRec(D, C); |
| 609 | |
Ted Kremenek | aad48b6 | 2007-11-14 08:06:37 +0000 | [diff] [blame] | 610 | return decl; |
| 611 | } |
| 612 | |
| 613 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 614 | // TypedefDecl Serialization. |
| 615 | //===----------------------------------------------------------------------===// |
| 616 | |
| 617 | void TypedefDecl::EmitImpl(Serializer& S) const { |
Ted Kremenek | 2ebc89f | 2007-11-06 19:51:47 +0000 | [diff] [blame] | 618 | S.Emit(UnderlyingType); |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 619 | ScopedDecl::EmitInRec(S); |
| 620 | ScopedDecl::EmitOutRec(S); |
Ted Kremenek | f7bf411 | 2007-11-05 21:49:34 +0000 | [diff] [blame] | 621 | } |
| 622 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 623 | TypedefDecl* TypedefDecl::CreateImpl(Deserializer& D, ASTContext& C) { |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 624 | QualType T = QualType::ReadVal(D); |
| 625 | |
Sam Bishop | f3c63ae | 2008-04-11 14:49:10 +0000 | [diff] [blame] | 626 | void *Mem = C.getAllocator().Allocate<TypedefDecl>(); |
| 627 | TypedefDecl* decl = new (Mem) TypedefDecl(0, SourceLocation(), NULL, T, NULL); |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 628 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 629 | decl->ScopedDecl::ReadInRec(D, C); |
| 630 | decl->ScopedDecl::ReadOutRec(D, C); |
Ted Kremenek | 928fd7f | 2007-11-13 00:15:39 +0000 | [diff] [blame] | 631 | |
Ted Kremenek | f7bf411 | 2007-11-05 21:49:34 +0000 | [diff] [blame] | 632 | return decl; |
| 633 | } |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 634 | |
| 635 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 636 | // TemplateTypeParmDecl Serialization. |
| 637 | //===----------------------------------------------------------------------===// |
| 638 | |
| 639 | void TemplateTypeParmDecl::EmitImpl(Serializer& S) const { |
| 640 | S.EmitBool(Typename); |
| 641 | ScopedDecl::EmitInRec(S); |
| 642 | ScopedDecl::EmitOutRec(S); |
| 643 | } |
| 644 | |
| 645 | TemplateTypeParmDecl * |
| 646 | TemplateTypeParmDecl::CreateImpl(Deserializer& D, ASTContext& C) { |
| 647 | bool Typename = D.ReadBool(); |
| 648 | void *Mem = C.getAllocator().Allocate<TemplateTypeParmDecl>(); |
| 649 | TemplateTypeParmDecl *decl |
| 650 | = new (Mem) TemplateTypeParmDecl(0, SourceLocation(), NULL, Typename); |
| 651 | decl->ScopedDecl::ReadInRec(D, C); |
| 652 | decl->ScopedDecl::ReadOutRec(D, C); |
| 653 | return decl; |
| 654 | } |
| 655 | |
| 656 | //===----------------------------------------------------------------------===// |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 657 | // LinkageSpec Serialization. |
| 658 | //===----------------------------------------------------------------------===// |
| 659 | |
| 660 | void LinkageSpecDecl::EmitInRec(Serializer& S) const { |
| 661 | Decl::EmitInRec(S); |
| 662 | S.EmitInt(getLanguage()); |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 663 | S.EmitBool(HadBraces); |
| 664 | if (HadBraces) { |
| 665 | S.EmitInt(NumDecls); |
| 666 | for (decl_const_iterator D = decls_begin(), DEnd = decls_end(); |
| 667 | D != DEnd; ++D) |
| 668 | S.EmitPtr(*D); |
| 669 | } else { |
| 670 | S.EmitPtr((Decl*)Decls); |
| 671 | } |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 672 | } |
| 673 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 674 | void LinkageSpecDecl::ReadInRec(Deserializer& D, ASTContext& C) { |
| 675 | Decl::ReadInRec(D, C); |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 676 | Language = static_cast<LanguageIDs>(D.ReadInt()); |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 677 | HadBraces = D.ReadBool(); |
| 678 | if (HadBraces) { |
| 679 | NumDecls = D.ReadInt(); |
| 680 | Decl **NewDecls = new Decl*[NumDecls]; |
| 681 | Decls = NewDecls; |
| 682 | for (unsigned I = 0; I < NumDecls; ++I) |
| 683 | D.ReadPtr(NewDecls[I]); |
| 684 | } else { |
| 685 | D.ReadPtr(this->Decls); |
| 686 | } |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 687 | } |
Anders Carlsson | dfab6cb | 2008-02-08 00:33:21 +0000 | [diff] [blame] | 688 | |
| 689 | //===----------------------------------------------------------------------===// |
| 690 | // FileScopeAsm Serialization. |
| 691 | //===----------------------------------------------------------------------===// |
| 692 | |
| 693 | void FileScopeAsmDecl::EmitImpl(llvm::Serializer& S) const |
| 694 | { |
| 695 | Decl::EmitInRec(S); |
| 696 | S.EmitOwnedPtr(AsmString); |
| 697 | } |
| 698 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 699 | FileScopeAsmDecl* FileScopeAsmDecl::CreateImpl(Deserializer& D, ASTContext& C) { |
Sam Bishop | f3c63ae | 2008-04-11 14:49:10 +0000 | [diff] [blame] | 700 | void *Mem = C.getAllocator().Allocate<FileScopeAsmDecl>(); |
| 701 | FileScopeAsmDecl* decl = new (Mem) FileScopeAsmDecl(SourceLocation(), 0); |
Anders Carlsson | dfab6cb | 2008-02-08 00:33:21 +0000 | [diff] [blame] | 702 | |
Sam Bishop | e2563ca | 2008-04-07 21:55:54 +0000 | [diff] [blame] | 703 | decl->Decl::ReadInRec(D, C); |
| 704 | decl->AsmString = cast<StringLiteral>(D.ReadOwnedPtr<Expr>(C)); |
Anders Carlsson | dfab6cb | 2008-02-08 00:33:21 +0000 | [diff] [blame] | 705 | // D.ReadOwnedPtr(D.ReadOwnedPtr<StringLiteral>())<#T * * Ptr#>, <#bool AutoRegister#>)(decl->AsmString); |
| 706 | |
| 707 | return decl; |
| 708 | } |