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