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