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