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