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