Sebastian Redl | 4ee2ad0 | 2010-08-18 23:56:31 +0000 | [diff] [blame] | 1 | //===--- ASTWriterDecl.cpp - Declaration Serialization --------------------===// |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements serialization for Declarations. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Sebastian Redl | 7faa2ec | 2010-08-18 23:56:37 +0000 | [diff] [blame] | 14 | #include "clang/Serialization/ASTWriter.h" |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 15 | #include "clang/AST/DeclVisitor.h" |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclCXX.h" |
| 17 | #include "clang/AST/DeclTemplate.h" |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 18 | #include "clang/AST/Expr.h" |
Argyrios Kyrtzidis | 0ad6dc3 | 2010-10-20 16:22:56 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclContextInternals.h" |
Daniel Dunbar | 3367198 | 2009-12-03 09:13:36 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/Twine.h" |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 21 | #include "llvm/Bitcode/BitstreamWriter.h" |
Daniel Dunbar | 3367198 | 2009-12-03 09:13:36 +0000 | [diff] [blame] | 22 | #include "llvm/Support/ErrorHandling.h" |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 23 | using namespace clang; |
| 24 | |
| 25 | //===----------------------------------------------------------------------===// |
| 26 | // Declaration serialization |
| 27 | //===----------------------------------------------------------------------===// |
| 28 | |
Argyrios Kyrtzidis | 6764334 | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 29 | namespace clang { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 30 | class ASTDeclWriter : public DeclVisitor<ASTDeclWriter, void> { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 31 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 32 | ASTWriter &Writer; |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 33 | ASTContext &Context; |
Argyrios Kyrtzidis | c01dc6f | 2010-10-24 17:26:27 +0000 | [diff] [blame] | 34 | typedef ASTWriter::RecordData RecordData; |
| 35 | RecordData &Record; |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 36 | |
| 37 | public: |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 38 | serialization::DeclCode Code; |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 39 | unsigned AbbrevToUse; |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 40 | |
Argyrios Kyrtzidis | c01dc6f | 2010-10-24 17:26:27 +0000 | [diff] [blame] | 41 | ASTDeclWriter(ASTWriter &Writer, ASTContext &Context, RecordData &Record) |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 42 | : Writer(Writer), Context(Context), Record(Record) { |
| 43 | } |
Argyrios Kyrtzidis | c01dc6f | 2010-10-24 17:26:27 +0000 | [diff] [blame] | 44 | |
Argyrios Kyrtzidis | 9146832 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 45 | void Visit(Decl *D); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 46 | |
| 47 | void VisitDecl(Decl *D); |
| 48 | void VisitTranslationUnitDecl(TranslationUnitDecl *D); |
| 49 | void VisitNamedDecl(NamedDecl *D); |
Douglas Gregor | 0cef483 | 2010-02-21 18:22:14 +0000 | [diff] [blame] | 50 | void VisitNamespaceDecl(NamespaceDecl *D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 51 | void VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| 52 | void VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 53 | void VisitTypeDecl(TypeDecl *D); |
| 54 | void VisitTypedefDecl(TypedefDecl *D); |
Argyrios Kyrtzidis | 8f4eae9 | 2010-06-30 08:49:30 +0000 | [diff] [blame] | 55 | void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 56 | void VisitTagDecl(TagDecl *D); |
| 57 | void VisitEnumDecl(EnumDecl *D); |
| 58 | void VisitRecordDecl(RecordDecl *D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 59 | void VisitCXXRecordDecl(CXXRecordDecl *D); |
| 60 | void VisitClassTemplateSpecializationDecl( |
| 61 | ClassTemplateSpecializationDecl *D); |
| 62 | void VisitClassTemplatePartialSpecializationDecl( |
| 63 | ClassTemplatePartialSpecializationDecl *D); |
| 64 | void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 65 | void VisitValueDecl(ValueDecl *D); |
| 66 | void VisitEnumConstantDecl(EnumConstantDecl *D); |
Argyrios Kyrtzidis | 8f4eae9 | 2010-06-30 08:49:30 +0000 | [diff] [blame] | 67 | void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 68 | void VisitDeclaratorDecl(DeclaratorDecl *D); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 69 | void VisitFunctionDecl(FunctionDecl *D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 70 | void VisitCXXMethodDecl(CXXMethodDecl *D); |
| 71 | void VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 72 | void VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 73 | void VisitCXXConversionDecl(CXXConversionDecl *D); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 74 | void VisitFieldDecl(FieldDecl *D); |
Francois Pichet | 87c2e12 | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 75 | void VisitIndirectFieldDecl(IndirectFieldDecl *D); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 76 | void VisitVarDecl(VarDecl *D); |
| 77 | void VisitImplicitParamDecl(ImplicitParamDecl *D); |
| 78 | void VisitParmVarDecl(ParmVarDecl *D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 79 | void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| 80 | void VisitTemplateDecl(TemplateDecl *D); |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 81 | void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 82 | void VisitClassTemplateDecl(ClassTemplateDecl *D); |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 83 | void VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 84 | void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
Argyrios Kyrtzidis | b01a552 | 2010-06-20 14:40:59 +0000 | [diff] [blame] | 85 | void VisitUsingDecl(UsingDecl *D); |
| 86 | void VisitUsingShadowDecl(UsingShadowDecl *D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 87 | void VisitLinkageSpecDecl(LinkageSpecDecl *D); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 88 | void VisitFileScopeAsmDecl(FileScopeAsmDecl *D); |
Abramo Bagnara | 6206d53 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 89 | void VisitAccessSpecDecl(AccessSpecDecl *D); |
Argyrios Kyrtzidis | 6764334 | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 90 | void VisitFriendDecl(FriendDecl *D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 91 | void VisitFriendTemplateDecl(FriendTemplateDecl *D); |
| 92 | void VisitStaticAssertDecl(StaticAssertDecl *D); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 93 | void VisitBlockDecl(BlockDecl *D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 94 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 95 | void VisitDeclContext(DeclContext *DC, uint64_t LexicalOffset, |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 96 | uint64_t VisibleOffset); |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 97 | template <typename T> void VisitRedeclarable(Redeclarable<T> *D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 98 | |
| 99 | |
Sean Hunt | 9a55591 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 100 | // FIXME: Put in the same order is DeclNodes.td? |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 101 | void VisitObjCMethodDecl(ObjCMethodDecl *D); |
| 102 | void VisitObjCContainerDecl(ObjCContainerDecl *D); |
| 103 | void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
| 104 | void VisitObjCIvarDecl(ObjCIvarDecl *D); |
| 105 | void VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
| 106 | void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D); |
| 107 | void VisitObjCClassDecl(ObjCClassDecl *D); |
| 108 | void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D); |
| 109 | void VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
| 110 | void VisitObjCImplDecl(ObjCImplDecl *D); |
| 111 | void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
| 112 | void VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
| 113 | void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D); |
| 114 | void VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
| 115 | void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
| 116 | }; |
| 117 | } |
| 118 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 119 | void ASTDeclWriter::Visit(Decl *D) { |
| 120 | DeclVisitor<ASTDeclWriter>::Visit(D); |
Argyrios Kyrtzidis | 9146832 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 121 | |
| 122 | // Handle FunctionDecl's body here and write it after all other Stmts/Exprs |
| 123 | // have been written. We want it last because we will not read it back when |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 124 | // retrieving it from the AST, we'll just lazily set the offset. |
Argyrios Kyrtzidis | 9146832 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 125 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
| 126 | Record.push_back(FD->isThisDeclarationADefinition()); |
| 127 | if (FD->isThisDeclarationADefinition()) |
| 128 | Writer.AddStmt(FD->getBody()); |
| 129 | } |
| 130 | } |
| 131 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 132 | void ASTDeclWriter::VisitDecl(Decl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 133 | Writer.AddDeclRef(cast_or_null<Decl>(D->getDeclContext()), Record); |
| 134 | Writer.AddDeclRef(cast_or_null<Decl>(D->getLexicalDeclContext()), Record); |
| 135 | Writer.AddSourceLocation(D->getLocation(), Record); |
| 136 | Record.push_back(D->isInvalidDecl()); |
| 137 | Record.push_back(D->hasAttrs()); |
Argyrios Kyrtzidis | 4eb9fc0 | 2010-10-18 19:20:11 +0000 | [diff] [blame] | 138 | if (D->hasAttrs()) |
| 139 | Writer.WriteAttributes(D->getAttrs(), Record); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 140 | Record.push_back(D->isImplicit()); |
Douglas Gregor | c070cc6 | 2010-06-17 23:14:26 +0000 | [diff] [blame] | 141 | Record.push_back(D->isUsed(false)); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 142 | Record.push_back(D->getAccess()); |
Douglas Gregor | 7d1d49d | 2009-10-16 20:01:17 +0000 | [diff] [blame] | 143 | Record.push_back(D->getPCHLevel()); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 146 | void ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 147 | VisitDecl(D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 148 | Writer.AddDeclRef(D->getAnonymousNamespace(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 149 | Code = serialization::DECL_TRANSLATION_UNIT; |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 152 | void ASTDeclWriter::VisitNamedDecl(NamedDecl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 153 | VisitDecl(D); |
| 154 | Writer.AddDeclarationName(D->getDeclName(), Record); |
| 155 | } |
| 156 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 157 | void ASTDeclWriter::VisitTypeDecl(TypeDecl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 158 | VisitNamedDecl(D); |
Argyrios Kyrtzidis | d8a0c6f | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 159 | Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 162 | void ASTDeclWriter::VisitTypedefDecl(TypedefDecl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 163 | VisitTypeDecl(D); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 164 | Writer.AddTypeSourceInfo(D->getTypeSourceInfo(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 165 | Code = serialization::DECL_TYPEDEF; |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 166 | } |
| 167 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 168 | void ASTDeclWriter::VisitTagDecl(TagDecl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 169 | VisitTypeDecl(D); |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 170 | VisitRedeclarable(D); |
Argyrios Kyrtzidis | 6b54151 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 171 | Record.push_back(D->getIdentifierNamespace()); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 172 | Record.push_back((unsigned)D->getTagKind()); // FIXME: stable encoding |
| 173 | Record.push_back(D->isDefinition()); |
Douglas Gregor | b37b648 | 2010-02-12 17:40:34 +0000 | [diff] [blame] | 174 | Record.push_back(D->isEmbeddedInDeclarator()); |
Argyrios Kyrtzidis | ad93a74 | 2009-07-14 03:18:02 +0000 | [diff] [blame] | 175 | Writer.AddSourceLocation(D->getRBraceLoc(), Record); |
Douglas Gregor | 741dd9a | 2009-07-21 14:46:17 +0000 | [diff] [blame] | 176 | Writer.AddSourceLocation(D->getTagKeywordLoc(), Record); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 177 | Record.push_back(D->hasExtInfo()); |
| 178 | if (D->hasExtInfo()) |
| 179 | Writer.AddQualifierInfo(*D->getExtInfo(), Record); |
| 180 | else |
| 181 | Writer.AddDeclRef(D->getTypedefForAnonDecl(), Record); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 182 | } |
| 183 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 184 | void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 185 | VisitTagDecl(D); |
Douglas Gregor | 1274ccd | 2010-10-08 23:50:27 +0000 | [diff] [blame] | 186 | Writer.AddTypeSourceInfo(D->getIntegerTypeSourceInfo(), Record); |
| 187 | if (!D->getIntegerTypeSourceInfo()) |
| 188 | Writer.AddTypeRef(D->getIntegerType(), Record); |
John McCall | 842aef8 | 2009-12-09 09:09:27 +0000 | [diff] [blame] | 189 | Writer.AddTypeRef(D->getPromotionType(), Record); |
John McCall | 1b5a618 | 2010-05-06 08:49:23 +0000 | [diff] [blame] | 190 | Record.push_back(D->getNumPositiveBits()); |
| 191 | Record.push_back(D->getNumNegativeBits()); |
Douglas Gregor | 1274ccd | 2010-10-08 23:50:27 +0000 | [diff] [blame] | 192 | Record.push_back(D->isScoped()); |
Abramo Bagnara | a88cefd | 2010-12-03 18:54:17 +0000 | [diff] [blame] | 193 | Record.push_back(D->isScopedUsingClassTag()); |
Douglas Gregor | 1274ccd | 2010-10-08 23:50:27 +0000 | [diff] [blame] | 194 | Record.push_back(D->isFixed()); |
Argyrios Kyrtzidis | 7422827 | 2010-07-06 15:36:48 +0000 | [diff] [blame] | 195 | Writer.AddDeclRef(D->getInstantiatedFromMemberEnum(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 196 | Code = serialization::DECL_ENUM; |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 197 | } |
| 198 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 199 | void ASTDeclWriter::VisitRecordDecl(RecordDecl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 200 | VisitTagDecl(D); |
| 201 | Record.push_back(D->hasFlexibleArrayMember()); |
| 202 | Record.push_back(D->isAnonymousStructOrUnion()); |
Fariborz Jahanian | 643b7df | 2009-07-08 16:37:44 +0000 | [diff] [blame] | 203 | Record.push_back(D->hasObjectMember()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 204 | Code = serialization::DECL_RECORD; |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 205 | } |
| 206 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 207 | void ASTDeclWriter::VisitValueDecl(ValueDecl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 208 | VisitNamedDecl(D); |
| 209 | Writer.AddTypeRef(D->getType(), Record); |
| 210 | } |
| 211 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 212 | void ASTDeclWriter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 213 | VisitValueDecl(D); |
| 214 | Record.push_back(D->getInitExpr()? 1 : 0); |
| 215 | if (D->getInitExpr()) |
| 216 | Writer.AddStmt(D->getInitExpr()); |
| 217 | Writer.AddAPSInt(D->getInitVal(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 218 | Code = serialization::DECL_ENUM_CONSTANT; |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 219 | } |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 220 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 221 | void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) { |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 222 | VisitValueDecl(D); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 223 | Record.push_back(D->hasExtInfo()); |
| 224 | if (D->hasExtInfo()) |
| 225 | Writer.AddQualifierInfo(*D->getExtInfo(), Record); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 226 | Writer.AddTypeSourceInfo(D->getTypeSourceInfo(), Record); |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 227 | } |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 228 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 229 | void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) { |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 230 | VisitDeclaratorDecl(D); |
Argyrios Kyrtzidis | 6b54151 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 231 | VisitRedeclarable(D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 232 | |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 233 | Writer.AddDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record); |
Argyrios Kyrtzidis | c8f9af2 | 2010-07-05 10:38:01 +0000 | [diff] [blame] | 234 | Record.push_back(D->getIdentifierNamespace()); |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 235 | Record.push_back(D->getTemplatedKind()); |
| 236 | switch (D->getTemplatedKind()) { |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 237 | default: assert(false && "Unhandled TemplatedKind!"); |
| 238 | break; |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 239 | case FunctionDecl::TK_NonTemplate: |
| 240 | break; |
| 241 | case FunctionDecl::TK_FunctionTemplate: |
| 242 | Writer.AddDeclRef(D->getDescribedFunctionTemplate(), Record); |
| 243 | break; |
| 244 | case FunctionDecl::TK_MemberSpecialization: { |
| 245 | MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo(); |
| 246 | Writer.AddDeclRef(MemberInfo->getInstantiatedFrom(), Record); |
| 247 | Record.push_back(MemberInfo->getTemplateSpecializationKind()); |
| 248 | Writer.AddSourceLocation(MemberInfo->getPointOfInstantiation(), Record); |
| 249 | break; |
| 250 | } |
| 251 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
| 252 | FunctionTemplateSpecializationInfo * |
| 253 | FTSInfo = D->getTemplateSpecializationInfo(); |
Argyrios Kyrtzidis | a626a3d | 2010-09-09 11:28:23 +0000 | [diff] [blame] | 254 | Writer.AddDeclRef(FTSInfo->getTemplate(), Record); |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 255 | Record.push_back(FTSInfo->getTemplateSpecializationKind()); |
| 256 | |
| 257 | // Template arguments. |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 258 | Writer.AddTemplateArgumentList(FTSInfo->TemplateArguments, Record); |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 259 | |
| 260 | // Template args as written. |
Argyrios Kyrtzidis | 5efb06f | 2010-07-02 11:55:40 +0000 | [diff] [blame] | 261 | Record.push_back(FTSInfo->TemplateArgumentsAsWritten != 0); |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 262 | if (FTSInfo->TemplateArgumentsAsWritten) { |
| 263 | Record.push_back(FTSInfo->TemplateArgumentsAsWritten->size()); |
| 264 | for (int i=0, e = FTSInfo->TemplateArgumentsAsWritten->size(); i!=e; ++i) |
| 265 | Writer.AddTemplateArgumentLoc((*FTSInfo->TemplateArgumentsAsWritten)[i], |
| 266 | Record); |
| 267 | Writer.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->getLAngleLoc(), |
| 268 | Record); |
| 269 | Writer.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->getRAngleLoc(), |
| 270 | Record); |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 271 | } |
Argyrios Kyrtzidis | 7b081c8 | 2010-07-05 10:37:55 +0000 | [diff] [blame] | 272 | |
| 273 | Writer.AddSourceLocation(FTSInfo->getPointOfInstantiation(), Record); |
Argyrios Kyrtzidis | 99a8ca0 | 2010-09-13 11:45:48 +0000 | [diff] [blame] | 274 | |
| 275 | if (D->isCanonicalDecl()) { |
| 276 | // Write the template that contains the specializations set. We will |
| 277 | // add a FunctionTemplateSpecializationInfo to it when reading. |
| 278 | Writer.AddDeclRef(FTSInfo->getTemplate()->getCanonicalDecl(), Record); |
| 279 | } |
Argyrios Kyrtzidis | a56b049 | 2010-06-25 16:24:51 +0000 | [diff] [blame] | 280 | break; |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 281 | } |
| 282 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 283 | DependentFunctionTemplateSpecializationInfo * |
| 284 | DFTSInfo = D->getDependentSpecializationInfo(); |
| 285 | |
| 286 | // Templates. |
| 287 | Record.push_back(DFTSInfo->getNumTemplates()); |
| 288 | for (int i=0, e = DFTSInfo->getNumTemplates(); i != e; ++i) |
| 289 | Writer.AddDeclRef(DFTSInfo->getTemplate(i), Record); |
| 290 | |
| 291 | // Templates args. |
| 292 | Record.push_back(DFTSInfo->getNumTemplateArgs()); |
| 293 | for (int i=0, e = DFTSInfo->getNumTemplateArgs(); i != e; ++i) |
| 294 | Writer.AddTemplateArgumentLoc(DFTSInfo->getTemplateArg(i), Record); |
Argyrios Kyrtzidis | 7b081c8 | 2010-07-05 10:37:55 +0000 | [diff] [blame] | 295 | Writer.AddSourceLocation(DFTSInfo->getLAngleLoc(), Record); |
| 296 | Writer.AddSourceLocation(DFTSInfo->getRAngleLoc(), Record); |
Argyrios Kyrtzidis | a56b049 | 2010-06-25 16:24:51 +0000 | [diff] [blame] | 297 | break; |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 298 | } |
| 299 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 300 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 301 | // FunctionDecl's body is handled last at ASTWriterDecl::Visit, |
Argyrios Kyrtzidis | 9146832 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 302 | // after everything else is written. |
Argyrios Kyrtzidis | 5efb06f | 2010-07-02 11:55:40 +0000 | [diff] [blame] | 303 | |
Argyrios Kyrtzidis | 5efb06f | 2010-07-02 11:55:40 +0000 | [diff] [blame] | 304 | Record.push_back(D->getStorageClass()); // FIXME: stable encoding |
| 305 | Record.push_back(D->getStorageClassAsWritten()); |
Douglas Gregor | 8f15094 | 2010-12-09 16:59:22 +0000 | [diff] [blame] | 306 | Record.push_back(D->IsInline); |
Argyrios Kyrtzidis | 5efb06f | 2010-07-02 11:55:40 +0000 | [diff] [blame] | 307 | Record.push_back(D->isInlineSpecified()); |
| 308 | Record.push_back(D->isVirtualAsWritten()); |
| 309 | Record.push_back(D->isPure()); |
| 310 | Record.push_back(D->hasInheritedPrototype()); |
| 311 | Record.push_back(D->hasWrittenPrototype()); |
| 312 | Record.push_back(D->isDeleted()); |
| 313 | Record.push_back(D->isTrivial()); |
Argyrios Kyrtzidis | 5efb06f | 2010-07-02 11:55:40 +0000 | [diff] [blame] | 314 | Record.push_back(D->hasImplicitReturnZero()); |
| 315 | Writer.AddSourceLocation(D->getLocEnd(), Record); |
| 316 | |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 317 | Record.push_back(D->param_size()); |
| 318 | for (FunctionDecl::param_iterator P = D->param_begin(), PEnd = D->param_end(); |
| 319 | P != PEnd; ++P) |
| 320 | Writer.AddDeclRef(*P, Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 321 | Code = serialization::DECL_FUNCTION; |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 322 | } |
| 323 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 324 | void ASTDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 325 | VisitNamedDecl(D); |
| 326 | // FIXME: convert to LazyStmtPtr? |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 327 | // Unlike C/C++, method bodies will never be in header files. |
Argyrios Kyrtzidis | 2f92230 | 2010-08-09 10:54:37 +0000 | [diff] [blame] | 328 | bool HasBodyStuff = D->getBody() != 0 || |
| 329 | D->getSelfDecl() != 0 || D->getCmdDecl() != 0; |
| 330 | Record.push_back(HasBodyStuff); |
| 331 | if (HasBodyStuff) { |
Argyrios Kyrtzidis | 6fb0aee | 2009-06-30 02:35:26 +0000 | [diff] [blame] | 332 | Writer.AddStmt(D->getBody()); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 333 | Writer.AddDeclRef(D->getSelfDecl(), Record); |
| 334 | Writer.AddDeclRef(D->getCmdDecl(), Record); |
| 335 | } |
| 336 | Record.push_back(D->isInstanceMethod()); |
| 337 | Record.push_back(D->isVariadic()); |
| 338 | Record.push_back(D->isSynthesized()); |
Fariborz Jahanian | 3fe1041 | 2010-07-22 18:24:20 +0000 | [diff] [blame] | 339 | Record.push_back(D->isDefined()); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 340 | // FIXME: stable encoding for @required/@optional |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 341 | Record.push_back(D->getImplementationControl()); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 342 | // FIXME: stable encoding for in/out/inout/bycopy/byref/oneway |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 343 | Record.push_back(D->getObjCDeclQualifier()); |
Fariborz Jahanian | 7732cc9 | 2010-04-08 21:29:11 +0000 | [diff] [blame] | 344 | Record.push_back(D->getNumSelectorArgs()); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 345 | Writer.AddTypeRef(D->getResultType(), Record); |
Douglas Gregor | 4bc1cb6 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 346 | Writer.AddTypeSourceInfo(D->getResultTypeSourceInfo(), Record); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 347 | Writer.AddSourceLocation(D->getLocEnd(), Record); |
| 348 | Record.push_back(D->param_size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 349 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 350 | PEnd = D->param_end(); P != PEnd; ++P) |
| 351 | Writer.AddDeclRef(*P, Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 352 | Code = serialization::DECL_OBJC_METHOD; |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 353 | } |
| 354 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 355 | void ASTDeclWriter::VisitObjCContainerDecl(ObjCContainerDecl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 356 | VisitNamedDecl(D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 357 | Writer.AddSourceRange(D->getAtEndRange(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 358 | // Abstract class (no need to define a stable serialization::DECL code). |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 359 | } |
| 360 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 361 | void ASTDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 362 | VisitObjCContainerDecl(D); |
| 363 | Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record); |
| 364 | Writer.AddDeclRef(D->getSuperClass(), Record); |
Ted Kremenek | 53b9441 | 2010-09-01 01:21:15 +0000 | [diff] [blame] | 365 | |
| 366 | // Write out the protocols that are directly referenced by the @interface. |
| 367 | Record.push_back(D->ReferencedProtocols.size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 368 | for (ObjCInterfaceDecl::protocol_iterator P = D->protocol_begin(), |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 369 | PEnd = D->protocol_end(); |
| 370 | P != PEnd; ++P) |
| 371 | Writer.AddDeclRef(*P, Record); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 372 | for (ObjCInterfaceDecl::protocol_loc_iterator PL = D->protocol_loc_begin(), |
| 373 | PLEnd = D->protocol_loc_end(); |
| 374 | PL != PLEnd; ++PL) |
| 375 | Writer.AddSourceLocation(*PL, Record); |
Ted Kremenek | 53b9441 | 2010-09-01 01:21:15 +0000 | [diff] [blame] | 376 | |
| 377 | // Write out the protocols that are transitively referenced. |
| 378 | Record.push_back(D->AllReferencedProtocols.size()); |
| 379 | for (ObjCList<ObjCProtocolDecl>::iterator |
| 380 | P = D->AllReferencedProtocols.begin(), |
| 381 | PEnd = D->AllReferencedProtocols.end(); |
| 382 | P != PEnd; ++P) |
| 383 | Writer.AddDeclRef(*P, Record); |
| 384 | |
| 385 | // Write out the ivars. |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 386 | Record.push_back(D->ivar_size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 387 | for (ObjCInterfaceDecl::ivar_iterator I = D->ivar_begin(), |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 388 | IEnd = D->ivar_end(); I != IEnd; ++I) |
| 389 | Writer.AddDeclRef(*I, Record); |
| 390 | Writer.AddDeclRef(D->getCategoryList(), Record); |
Douglas Gregor | deacbdc | 2010-08-11 12:19:30 +0000 | [diff] [blame] | 391 | Record.push_back(D->isForwardDecl()); |
| 392 | Record.push_back(D->isImplicitInterfaceDecl()); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 393 | Writer.AddSourceLocation(D->getClassLoc(), Record); |
| 394 | Writer.AddSourceLocation(D->getSuperClassLoc(), Record); |
| 395 | Writer.AddSourceLocation(D->getLocEnd(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 396 | Code = serialization::DECL_OBJC_INTERFACE; |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 397 | } |
| 398 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 399 | void ASTDeclWriter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 400 | VisitFieldDecl(D); |
| 401 | // FIXME: stable encoding for @public/@private/@protected/@package |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 402 | Record.push_back(D->getAccessControl()); |
Fariborz Jahanian | ac0021b | 2010-07-17 18:35:47 +0000 | [diff] [blame] | 403 | Record.push_back(D->getSynthesize()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 404 | Code = serialization::DECL_OBJC_IVAR; |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 405 | } |
| 406 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 407 | void ASTDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 408 | VisitObjCContainerDecl(D); |
| 409 | Record.push_back(D->isForwardDecl()); |
| 410 | Writer.AddSourceLocation(D->getLocEnd(), Record); |
| 411 | Record.push_back(D->protocol_size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 412 | for (ObjCProtocolDecl::protocol_iterator |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 413 | I = D->protocol_begin(), IEnd = D->protocol_end(); I != IEnd; ++I) |
| 414 | Writer.AddDeclRef(*I, Record); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 415 | for (ObjCProtocolDecl::protocol_loc_iterator PL = D->protocol_loc_begin(), |
| 416 | PLEnd = D->protocol_loc_end(); |
| 417 | PL != PLEnd; ++PL) |
| 418 | Writer.AddSourceLocation(*PL, Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 419 | Code = serialization::DECL_OBJC_PROTOCOL; |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 420 | } |
| 421 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 422 | void ASTDeclWriter::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 423 | VisitFieldDecl(D); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 424 | Code = serialization::DECL_OBJC_AT_DEFS_FIELD; |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 425 | } |
| 426 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 427 | void ASTDeclWriter::VisitObjCClassDecl(ObjCClassDecl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 428 | VisitDecl(D); |
| 429 | Record.push_back(D->size()); |
| 430 | for (ObjCClassDecl::iterator I = D->begin(), IEnd = D->end(); I != IEnd; ++I) |
Ted Kremenek | 321c22f | 2009-11-18 00:28:11 +0000 | [diff] [blame] | 431 | Writer.AddDeclRef(I->getInterface(), Record); |
| 432 | for (ObjCClassDecl::iterator I = D->begin(), IEnd = D->end(); I != IEnd; ++I) |
| 433 | Writer.AddSourceLocation(I->getLocation(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 434 | Code = serialization::DECL_OBJC_CLASS; |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 435 | } |
| 436 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 437 | void ASTDeclWriter::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 438 | VisitDecl(D); |
| 439 | Record.push_back(D->protocol_size()); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 440 | for (ObjCForwardProtocolDecl::protocol_iterator |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 441 | I = D->protocol_begin(), IEnd = D->protocol_end(); I != IEnd; ++I) |
| 442 | Writer.AddDeclRef(*I, Record); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 443 | for (ObjCForwardProtocolDecl::protocol_loc_iterator |
| 444 | PL = D->protocol_loc_begin(), PLEnd = D->protocol_loc_end(); |
| 445 | PL != PLEnd; ++PL) |
| 446 | Writer.AddSourceLocation(*PL, Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 447 | Code = serialization::DECL_OBJC_FORWARD_PROTOCOL; |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 448 | } |
| 449 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 450 | void ASTDeclWriter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 451 | VisitObjCContainerDecl(D); |
| 452 | Writer.AddDeclRef(D->getClassInterface(), Record); |
| 453 | Record.push_back(D->protocol_size()); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 454 | for (ObjCCategoryDecl::protocol_iterator |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 455 | I = D->protocol_begin(), IEnd = D->protocol_end(); I != IEnd; ++I) |
| 456 | Writer.AddDeclRef(*I, Record); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 457 | for (ObjCCategoryDecl::protocol_loc_iterator |
| 458 | PL = D->protocol_loc_begin(), PLEnd = D->protocol_loc_end(); |
| 459 | PL != PLEnd; ++PL) |
| 460 | Writer.AddSourceLocation(*PL, Record); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 461 | Writer.AddDeclRef(D->getNextClassCategory(), Record); |
Fariborz Jahanian | 000835d | 2010-08-23 18:51:39 +0000 | [diff] [blame] | 462 | Record.push_back(D->hasSynthBitfield()); |
Douglas Gregor | 3db211b | 2010-01-16 16:38:58 +0000 | [diff] [blame] | 463 | Writer.AddSourceLocation(D->getAtLoc(), Record); |
| 464 | Writer.AddSourceLocation(D->getCategoryNameLoc(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 465 | Code = serialization::DECL_OBJC_CATEGORY; |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 466 | } |
| 467 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 468 | void ASTDeclWriter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 469 | VisitNamedDecl(D); |
| 470 | Writer.AddDeclRef(D->getClassInterface(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 471 | Code = serialization::DECL_OBJC_COMPATIBLE_ALIAS; |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 472 | } |
| 473 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 474 | void ASTDeclWriter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 475 | VisitNamedDecl(D); |
Fariborz Jahanian | d050240 | 2010-01-21 17:36:00 +0000 | [diff] [blame] | 476 | Writer.AddSourceLocation(D->getAtLoc(), Record); |
John McCall | 83a230c | 2010-06-04 20:50:08 +0000 | [diff] [blame] | 477 | Writer.AddTypeSourceInfo(D->getTypeSourceInfo(), Record); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 478 | // FIXME: stable encoding |
| 479 | Record.push_back((unsigned)D->getPropertyAttributes()); |
Fariborz Jahanian | 80aa1cd | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 480 | Record.push_back((unsigned)D->getPropertyAttributesAsWritten()); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 481 | // FIXME: stable encoding |
| 482 | Record.push_back((unsigned)D->getPropertyImplementation()); |
| 483 | Writer.AddDeclarationName(D->getGetterName(), Record); |
| 484 | Writer.AddDeclarationName(D->getSetterName(), Record); |
| 485 | Writer.AddDeclRef(D->getGetterMethodDecl(), Record); |
| 486 | Writer.AddDeclRef(D->getSetterMethodDecl(), Record); |
| 487 | Writer.AddDeclRef(D->getPropertyIvarDecl(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 488 | Code = serialization::DECL_OBJC_PROPERTY; |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 489 | } |
| 490 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 491 | void ASTDeclWriter::VisitObjCImplDecl(ObjCImplDecl *D) { |
Argyrios Kyrtzidis | aecae62 | 2009-07-27 19:04:32 +0000 | [diff] [blame] | 492 | VisitObjCContainerDecl(D); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 493 | Writer.AddDeclRef(D->getClassInterface(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 494 | // Abstract class (no need to define a stable serialization::DECL code). |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 495 | } |
| 496 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 497 | void ASTDeclWriter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 498 | VisitObjCImplDecl(D); |
| 499 | Writer.AddIdentifierRef(D->getIdentifier(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 500 | Code = serialization::DECL_OBJC_CATEGORY_IMPL; |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 501 | } |
| 502 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 503 | void ASTDeclWriter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 504 | VisitObjCImplDecl(D); |
| 505 | Writer.AddDeclRef(D->getSuperClass(), Record); |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 506 | Writer.AddCXXCtorInitializers(D->IvarInitializers, D->NumIvarInitializers, |
| 507 | Record); |
Fariborz Jahanian | 000835d | 2010-08-23 18:51:39 +0000 | [diff] [blame] | 508 | Record.push_back(D->hasSynthBitfield()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 509 | Code = serialization::DECL_OBJC_IMPLEMENTATION; |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 510 | } |
| 511 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 512 | void ASTDeclWriter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 513 | VisitDecl(D); |
| 514 | Writer.AddSourceLocation(D->getLocStart(), Record); |
| 515 | Writer.AddDeclRef(D->getPropertyDecl(), Record); |
| 516 | Writer.AddDeclRef(D->getPropertyIvarDecl(), Record); |
Douglas Gregor | a4ffd85 | 2010-11-17 01:03:52 +0000 | [diff] [blame] | 517 | Writer.AddSourceLocation(D->getPropertyIvarDeclLoc(), Record); |
Argyrios Kyrtzidis | 2f92230 | 2010-08-09 10:54:37 +0000 | [diff] [blame] | 518 | Writer.AddStmt(D->getGetterCXXConstructor()); |
| 519 | Writer.AddStmt(D->getSetterCXXAssignment()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 520 | Code = serialization::DECL_OBJC_PROPERTY_IMPL; |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 521 | } |
| 522 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 523 | void ASTDeclWriter::VisitFieldDecl(FieldDecl *D) { |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 524 | VisitDeclaratorDecl(D); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 525 | Record.push_back(D->isMutable()); |
| 526 | Record.push_back(D->getBitWidth()? 1 : 0); |
| 527 | if (D->getBitWidth()) |
| 528 | Writer.AddStmt(D->getBitWidth()); |
Argyrios Kyrtzidis | c91e9f4 | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 529 | if (!D->getDeclName()) |
| 530 | Writer.AddDeclRef(Context.getInstantiatedFromUnnamedFieldDecl(D), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 531 | Code = serialization::DECL_FIELD; |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 532 | } |
| 533 | |
Francois Pichet | 87c2e12 | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 534 | void ASTDeclWriter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
| 535 | VisitValueDecl(D); |
| 536 | Record.push_back(D->getChainingSize()); |
| 537 | |
| 538 | for (IndirectFieldDecl::chain_iterator |
| 539 | P = D->chain_begin(), |
| 540 | PEnd = D->chain_end(); P != PEnd; ++P) |
| 541 | Writer.AddDeclRef(*P, Record); |
| 542 | Code = serialization::DECL_INDIRECTFIELD; |
| 543 | } |
| 544 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 545 | void ASTDeclWriter::VisitVarDecl(VarDecl *D) { |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 546 | VisitDeclaratorDecl(D); |
Argyrios Kyrtzidis | 6b54151 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 547 | VisitRedeclarable(D); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 548 | Record.push_back(D->getStorageClass()); // FIXME: stable encoding |
Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 549 | Record.push_back(D->getStorageClassAsWritten()); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 550 | Record.push_back(D->isThreadSpecified()); |
| 551 | Record.push_back(D->hasCXXDirectInitializer()); |
Douglas Gregor | 324b54d | 2010-05-03 18:51:14 +0000 | [diff] [blame] | 552 | Record.push_back(D->isExceptionVariable()); |
Douglas Gregor | 5077c38 | 2010-05-15 06:01:05 +0000 | [diff] [blame] | 553 | Record.push_back(D->isNRVOVariable()); |
Chris Lattner | 030854b | 2010-05-09 06:40:08 +0000 | [diff] [blame] | 554 | Record.push_back(D->getInit() ? 1 : 0); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 555 | if (D->getInit()) |
| 556 | Writer.AddStmt(D->getInit()); |
Argyrios Kyrtzidis | 9421adc | 2010-07-04 21:44:00 +0000 | [diff] [blame] | 557 | |
| 558 | MemberSpecializationInfo *SpecInfo |
| 559 | = D->isStaticDataMember() ? D->getMemberSpecializationInfo() : 0; |
| 560 | Record.push_back(SpecInfo != 0); |
| 561 | if (SpecInfo) { |
| 562 | Writer.AddDeclRef(SpecInfo->getInstantiatedFrom(), Record); |
| 563 | Record.push_back(SpecInfo->getTemplateSpecializationKind()); |
| 564 | Writer.AddSourceLocation(SpecInfo->getPointOfInstantiation(), Record); |
| 565 | } |
| 566 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 567 | Code = serialization::DECL_VAR; |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 568 | } |
| 569 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 570 | void ASTDeclWriter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 571 | VisitVarDecl(D); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 572 | Code = serialization::DECL_IMPLICIT_PARAM; |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 573 | } |
| 574 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 575 | void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 576 | VisitVarDecl(D); |
| 577 | Record.push_back(D->getObjCDeclQualifier()); // FIXME: stable encoding |
John McCall | bf73b35 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 578 | Record.push_back(D->hasInheritedDefaultArg()); |
Argyrios Kyrtzidis | 691d77f | 2010-07-04 21:44:07 +0000 | [diff] [blame] | 579 | Record.push_back(D->hasUninstantiatedDefaultArg()); |
| 580 | if (D->hasUninstantiatedDefaultArg()) |
| 581 | Writer.AddStmt(D->getUninstantiatedDefaultArg()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 582 | Code = serialization::DECL_PARM_VAR; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 583 | |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 584 | // If the assumptions about the DECL_PARM_VAR abbrev are true, use it. Here |
| 585 | // we dynamically check for the properties that we optimize for, but don't |
| 586 | // know are true of all PARM_VAR_DECLs. |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 587 | if (!D->getTypeSourceInfo() && |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 588 | !D->hasAttrs() && |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 589 | !D->isImplicit() && |
Douglas Gregor | c070cc6 | 2010-06-17 23:14:26 +0000 | [diff] [blame] | 590 | !D->isUsed(false) && |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 591 | D->getAccess() == AS_none && |
Douglas Gregor | 7d1d49d | 2009-10-16 20:01:17 +0000 | [diff] [blame] | 592 | D->getPCHLevel() == 0 && |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 593 | D->getStorageClass() == 0 && |
| 594 | !D->hasCXXDirectInitializer() && // Can params have this ever? |
John McCall | bf73b35 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 595 | D->getObjCDeclQualifier() == 0 && |
Chris Lattner | 030854b | 2010-05-09 06:40:08 +0000 | [diff] [blame] | 596 | !D->hasInheritedDefaultArg() && |
Argyrios Kyrtzidis | 691d77f | 2010-07-04 21:44:07 +0000 | [diff] [blame] | 597 | D->getInit() == 0 && |
| 598 | !D->hasUninstantiatedDefaultArg()) // No default expr. |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 599 | AbbrevToUse = Writer.getParmVarDeclAbbrev(); |
| 600 | |
| 601 | // Check things we know are true of *every* PARM_VAR_DECL, which is more than |
| 602 | // just us assuming it. |
| 603 | assert(!D->isInvalidDecl() && "Shouldn't emit invalid decls"); |
| 604 | assert(!D->isThreadSpecified() && "PARM_VAR_DECL can't be __thread"); |
| 605 | assert(D->getAccess() == AS_none && "PARM_VAR_DECL can't be public/private"); |
Douglas Gregor | 324b54d | 2010-05-03 18:51:14 +0000 | [diff] [blame] | 606 | assert(!D->isExceptionVariable() && "PARM_VAR_DECL can't be exception var"); |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 607 | assert(D->getPreviousDeclaration() == 0 && "PARM_VAR_DECL can't be redecl"); |
Argyrios Kyrtzidis | 9421adc | 2010-07-04 21:44:00 +0000 | [diff] [blame] | 608 | assert(!D->isStaticDataMember() && |
| 609 | "PARM_VAR_DECL can't be static data member"); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 610 | } |
| 611 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 612 | void ASTDeclWriter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 613 | VisitDecl(D); |
| 614 | Writer.AddStmt(D->getAsmString()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 615 | Code = serialization::DECL_FILE_SCOPE_ASM; |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 616 | } |
| 617 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 618 | void ASTDeclWriter::VisitBlockDecl(BlockDecl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 619 | VisitDecl(D); |
| 620 | Writer.AddStmt(D->getBody()); |
John McCall | 82dc009 | 2010-06-04 11:21:44 +0000 | [diff] [blame] | 621 | Writer.AddTypeSourceInfo(D->getSignatureAsWritten(), Record); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 622 | Record.push_back(D->param_size()); |
| 623 | for (FunctionDecl::param_iterator P = D->param_begin(), PEnd = D->param_end(); |
| 624 | P != PEnd; ++P) |
| 625 | Writer.AddDeclRef(*P, Record); |
John McCall | 469a1eb | 2011-02-02 13:00:07 +0000 | [diff] [blame] | 626 | Record.push_back(D->capturesCXXThis()); |
John McCall | 6b5a61b | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 627 | Record.push_back(D->getNumCaptures()); |
John McCall | 469a1eb | 2011-02-02 13:00:07 +0000 | [diff] [blame] | 628 | for (BlockDecl::capture_iterator |
John McCall | 6b5a61b | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 629 | i = D->capture_begin(), e = D->capture_end(); i != e; ++i) { |
| 630 | const BlockDecl::Capture &capture = *i; |
| 631 | Writer.AddDeclRef(capture.getVariable(), Record); |
| 632 | |
| 633 | unsigned flags = 0; |
| 634 | if (capture.isByRef()) flags |= 1; |
| 635 | if (capture.isNested()) flags |= 2; |
| 636 | if (capture.hasCopyExpr()) flags |= 4; |
| 637 | Record.push_back(flags); |
| 638 | |
| 639 | if (capture.hasCopyExpr()) Writer.AddStmt(capture.getCopyExpr()); |
| 640 | } |
John McCall | 469a1eb | 2011-02-02 13:00:07 +0000 | [diff] [blame] | 641 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 642 | Code = serialization::DECL_BLOCK; |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 643 | } |
| 644 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 645 | void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 646 | VisitDecl(D); |
| 647 | // FIXME: It might be nice to serialize the brace locations for this |
| 648 | // declaration, which don't seem to be readily available in the AST. |
| 649 | Record.push_back(D->getLanguage()); |
| 650 | Record.push_back(D->hasBraces()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 651 | Code = serialization::DECL_LINKAGE_SPEC; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 652 | } |
| 653 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 654 | void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 655 | VisitNamedDecl(D); |
Douglas Gregor | 0a0c3e7 | 2010-10-05 20:41:58 +0000 | [diff] [blame] | 656 | Record.push_back(D->isInline()); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 657 | Writer.AddSourceLocation(D->getLBracLoc(), Record); |
| 658 | Writer.AddSourceLocation(D->getRBracLoc(), Record); |
| 659 | Writer.AddDeclRef(D->getNextNamespace(), Record); |
| 660 | |
| 661 | // Only write one reference--original or anonymous |
| 662 | Record.push_back(D->isOriginalNamespace()); |
| 663 | if (D->isOriginalNamespace()) |
| 664 | Writer.AddDeclRef(D->getAnonymousNamespace(), Record); |
| 665 | else |
| 666 | Writer.AddDeclRef(D->getOriginalNamespace(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 667 | Code = serialization::DECL_NAMESPACE; |
Sebastian Redl | a7be506 | 2010-08-05 21:22:19 +0000 | [diff] [blame] | 668 | |
| 669 | if (Writer.hasChain() && !D->isOriginalNamespace() && |
| 670 | D->getOriginalNamespace()->getPCHLevel() > 0) { |
Argyrios Kyrtzidis | 0ad6dc3 | 2010-10-20 16:22:56 +0000 | [diff] [blame] | 671 | NamespaceDecl *NS = D->getOriginalNamespace(); |
Argyrios Kyrtzidis | 100050b | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 672 | Writer.AddUpdatedDeclContext(NS); |
Argyrios Kyrtzidis | 0ad6dc3 | 2010-10-20 16:22:56 +0000 | [diff] [blame] | 673 | |
| 674 | // Make sure all visible decls are written. They will be recorded later. |
| 675 | NS->lookup(DeclarationName()); |
| 676 | StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(NS->getLookupPtr()); |
| 677 | if (Map) { |
| 678 | for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end(); |
| 679 | D != DEnd; ++D) { |
Argyrios Kyrtzidis | 0ad6dc3 | 2010-10-20 16:22:56 +0000 | [diff] [blame] | 680 | DeclContext::lookup_result Result = D->second.getLookupResult(); |
| 681 | while (Result.first != Result.second) { |
| 682 | Writer.GetDeclRef(*Result.first); |
| 683 | ++Result.first; |
| 684 | } |
| 685 | } |
| 686 | } |
Sebastian Redl | a7be506 | 2010-08-05 21:22:19 +0000 | [diff] [blame] | 687 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 688 | } |
| 689 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 690 | void ASTDeclWriter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 691 | VisitNamedDecl(D); |
Douglas Gregor | 8ea5b9d | 2010-09-01 00:08:19 +0000 | [diff] [blame] | 692 | Writer.AddSourceLocation(D->getNamespaceLoc(), Record); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 693 | Writer.AddSourceRange(D->getQualifierRange(), Record); |
| 694 | Writer.AddNestedNameSpecifier(D->getQualifier(), Record); |
| 695 | Writer.AddSourceLocation(D->getTargetNameLoc(), Record); |
| 696 | Writer.AddDeclRef(D->getNamespace(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 697 | Code = serialization::DECL_NAMESPACE_ALIAS; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 698 | } |
| 699 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 700 | void ASTDeclWriter::VisitUsingDecl(UsingDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 701 | VisitNamedDecl(D); |
| 702 | Writer.AddSourceRange(D->getNestedNameRange(), Record); |
| 703 | Writer.AddSourceLocation(D->getUsingLocation(), Record); |
| 704 | Writer.AddNestedNameSpecifier(D->getTargetNestedNameDecl(), Record); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 705 | Writer.AddDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record); |
Argyrios Kyrtzidis | 826faa2 | 2010-11-10 05:40:41 +0000 | [diff] [blame] | 706 | Writer.AddDeclRef(D->FirstUsingShadow, Record); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 707 | Record.push_back(D->isTypeName()); |
Argyrios Kyrtzidis | c91e9f4 | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 708 | Writer.AddDeclRef(Context.getInstantiatedFromUsingDecl(D), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 709 | Code = serialization::DECL_USING; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 710 | } |
| 711 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 712 | void ASTDeclWriter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 713 | VisitNamedDecl(D); |
| 714 | Writer.AddDeclRef(D->getTargetDecl(), Record); |
Argyrios Kyrtzidis | 826faa2 | 2010-11-10 05:40:41 +0000 | [diff] [blame] | 715 | Writer.AddDeclRef(D->UsingOrNextShadow, Record); |
Argyrios Kyrtzidis | c91e9f4 | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 716 | Writer.AddDeclRef(Context.getInstantiatedFromUsingShadowDecl(D), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 717 | Code = serialization::DECL_USING_SHADOW; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 718 | } |
| 719 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 720 | void ASTDeclWriter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 721 | VisitNamedDecl(D); |
Douglas Gregor | 0a35bce | 2010-09-01 03:07:18 +0000 | [diff] [blame] | 722 | Writer.AddSourceLocation(D->getUsingLoc(), Record); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 723 | Writer.AddSourceLocation(D->getNamespaceKeyLocation(), Record); |
| 724 | Writer.AddSourceRange(D->getQualifierRange(), Record); |
| 725 | Writer.AddNestedNameSpecifier(D->getQualifier(), Record); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 726 | Writer.AddDeclRef(D->getNominatedNamespace(), Record); |
| 727 | Writer.AddDeclRef(dyn_cast<Decl>(D->getCommonAncestor()), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 728 | Code = serialization::DECL_USING_DIRECTIVE; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 729 | } |
| 730 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 731 | void ASTDeclWriter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 732 | VisitValueDecl(D); |
| 733 | Writer.AddSourceRange(D->getTargetNestedNameRange(), Record); |
| 734 | Writer.AddSourceLocation(D->getUsingLoc(), Record); |
| 735 | Writer.AddNestedNameSpecifier(D->getTargetNestedNameSpecifier(), Record); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 736 | Writer.AddDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 737 | Code = serialization::DECL_UNRESOLVED_USING_VALUE; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 738 | } |
| 739 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 740 | void ASTDeclWriter::VisitUnresolvedUsingTypenameDecl( |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 741 | UnresolvedUsingTypenameDecl *D) { |
| 742 | VisitTypeDecl(D); |
| 743 | Writer.AddSourceRange(D->getTargetNestedNameRange(), Record); |
| 744 | Writer.AddSourceLocation(D->getUsingLoc(), Record); |
| 745 | Writer.AddSourceLocation(D->getTypenameLoc(), Record); |
| 746 | Writer.AddNestedNameSpecifier(D->getTargetNestedNameSpecifier(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 747 | Code = serialization::DECL_UNRESOLVED_USING_TYPENAME; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 748 | } |
| 749 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 750 | void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 751 | VisitRecordDecl(D); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 752 | |
Argyrios Kyrtzidis | 134db1f | 2010-10-24 17:26:31 +0000 | [diff] [blame] | 753 | CXXRecordDecl *DefinitionDecl = 0; |
| 754 | if (D->DefinitionData) |
| 755 | DefinitionDecl = D->DefinitionData->Definition; |
| 756 | Writer.AddDeclRef(DefinitionDecl, Record); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 757 | if (D == DefinitionDecl) |
| 758 | Writer.AddCXXDefinitionData(D, Record); |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 759 | |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 760 | enum { |
| 761 | CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization |
| 762 | }; |
| 763 | if (ClassTemplateDecl *TemplD = D->getDescribedClassTemplate()) { |
| 764 | Record.push_back(CXXRecTemplate); |
| 765 | Writer.AddDeclRef(TemplD, Record); |
| 766 | } else if (MemberSpecializationInfo *MSInfo |
| 767 | = D->getMemberSpecializationInfo()) { |
| 768 | Record.push_back(CXXRecMemberSpecialization); |
| 769 | Writer.AddDeclRef(MSInfo->getInstantiatedFrom(), Record); |
| 770 | Record.push_back(MSInfo->getTemplateSpecializationKind()); |
| 771 | Writer.AddSourceLocation(MSInfo->getPointOfInstantiation(), Record); |
| 772 | } else { |
| 773 | Record.push_back(CXXRecNotTemplate); |
| 774 | } |
| 775 | |
Argyrios Kyrtzidis | 36d2fd4 | 2010-10-14 20:14:38 +0000 | [diff] [blame] | 776 | // Store the key function to avoid deserializing every method so we can |
| 777 | // compute it. |
| 778 | if (D->IsDefinition) |
| 779 | Writer.AddDeclRef(Context.getKeyFunction(D), Record); |
| 780 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 781 | Code = serialization::DECL_CXX_RECORD; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 782 | } |
| 783 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 784 | void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 785 | VisitFunctionDecl(D); |
Argyrios Kyrtzidis | c91e9f4 | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 786 | Record.push_back(D->size_overridden_methods()); |
| 787 | for (CXXMethodDecl::method_iterator |
| 788 | I = D->begin_overridden_methods(), E = D->end_overridden_methods(); |
| 789 | I != E; ++I) |
| 790 | Writer.AddDeclRef(*I, Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 791 | Code = serialization::DECL_CXX_METHOD; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 792 | } |
| 793 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 794 | void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 795 | VisitCXXMethodDecl(D); |
Argyrios Kyrtzidis | 9146832 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 796 | |
| 797 | Record.push_back(D->IsExplicitSpecified); |
| 798 | Record.push_back(D->ImplicitlyDefined); |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 799 | Writer.AddCXXCtorInitializers(D->CtorInitializers, D->NumCtorInitializers, |
| 800 | Record); |
Argyrios Kyrtzidis | 9146832 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 801 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 802 | Code = serialization::DECL_CXX_CONSTRUCTOR; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 803 | } |
| 804 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 805 | void ASTDeclWriter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 806 | VisitCXXMethodDecl(D); |
Argyrios Kyrtzidis | 9146832 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 807 | |
| 808 | Record.push_back(D->ImplicitlyDefined); |
| 809 | Writer.AddDeclRef(D->OperatorDelete, Record); |
| 810 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 811 | Code = serialization::DECL_CXX_DESTRUCTOR; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 812 | } |
| 813 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 814 | void ASTDeclWriter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 815 | VisitCXXMethodDecl(D); |
Argyrios Kyrtzidis | 9146832 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 816 | Record.push_back(D->IsExplicitSpecified); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 817 | Code = serialization::DECL_CXX_CONVERSION; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 818 | } |
| 819 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 820 | void ASTDeclWriter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
Abramo Bagnara | 6206d53 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 821 | VisitDecl(D); |
| 822 | Writer.AddSourceLocation(D->getColonLoc(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 823 | Code = serialization::DECL_ACCESS_SPEC; |
Abramo Bagnara | 6206d53 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 824 | } |
| 825 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 826 | void ASTDeclWriter::VisitFriendDecl(FriendDecl *D) { |
Argyrios Kyrtzidis | c8f9af2 | 2010-07-05 10:38:01 +0000 | [diff] [blame] | 827 | VisitDecl(D); |
Argyrios Kyrtzidis | 6764334 | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 828 | Record.push_back(D->Friend.is<TypeSourceInfo*>()); |
| 829 | if (D->Friend.is<TypeSourceInfo*>()) |
| 830 | Writer.AddTypeSourceInfo(D->Friend.get<TypeSourceInfo*>(), Record); |
| 831 | else |
| 832 | Writer.AddDeclRef(D->Friend.get<NamedDecl*>(), Record); |
Douglas Gregor | 69aecc6 | 2010-10-27 20:23:41 +0000 | [diff] [blame] | 833 | Writer.AddDeclRef(D->getNextFriend(), Record); |
John McCall | 6102ca1 | 2010-10-16 06:59:13 +0000 | [diff] [blame] | 834 | Record.push_back(D->UnsupportedFriend); |
Argyrios Kyrtzidis | 6764334 | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 835 | Writer.AddSourceLocation(D->FriendLoc, Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 836 | Code = serialization::DECL_FRIEND; |
Argyrios Kyrtzidis | 6764334 | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 837 | } |
| 838 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 839 | void ASTDeclWriter::VisitFriendTemplateDecl(FriendTemplateDecl *D) { |
Argyrios Kyrtzidis | 554e6aa | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 840 | VisitDecl(D); |
| 841 | Record.push_back(D->getNumTemplateParameters()); |
| 842 | for (unsigned i = 0, e = D->getNumTemplateParameters(); i != e; ++i) |
| 843 | Writer.AddTemplateParameterList(D->getTemplateParameterList(i), Record); |
| 844 | Record.push_back(D->getFriendDecl() != 0); |
| 845 | if (D->getFriendDecl()) |
| 846 | Writer.AddDeclRef(D->getFriendDecl(), Record); |
| 847 | else |
| 848 | Writer.AddTypeSourceInfo(D->getFriendType(), Record); |
| 849 | Writer.AddSourceLocation(D->getFriendLoc(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 850 | Code = serialization::DECL_FRIEND_TEMPLATE; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 851 | } |
| 852 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 853 | void ASTDeclWriter::VisitTemplateDecl(TemplateDecl *D) { |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 854 | VisitNamedDecl(D); |
| 855 | |
| 856 | Writer.AddDeclRef(D->getTemplatedDecl(), Record); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 857 | Writer.AddTemplateParameterList(D->getTemplateParameters(), Record); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 858 | } |
| 859 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 860 | void ASTDeclWriter::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) { |
Argyrios Kyrtzidis | 6b54151 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 861 | // Emit data to initialize CommonOrPrev before VisitTemplateDecl so that |
| 862 | // getCommonPtr() can be used while this is still initializing. |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 863 | |
| 864 | Writer.AddDeclRef(D->getPreviousDeclaration(), Record); |
| 865 | if (D->getPreviousDeclaration() == 0) { |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 866 | // This TemplateDecl owns the CommonPtr; write it. |
Argyrios Kyrtzidis | ecf966e | 2010-07-09 21:11:43 +0000 | [diff] [blame] | 867 | assert(D->isCanonicalDecl()); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 868 | |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 869 | Writer.AddDeclRef(D->getInstantiatedFromMemberTemplate(), Record); |
| 870 | if (D->getInstantiatedFromMemberTemplate()) |
| 871 | Record.push_back(D->isMemberSpecialization()); |
Peter Collingbourne | 8a798a7 | 2010-07-29 16:12:01 +0000 | [diff] [blame] | 872 | |
| 873 | Writer.AddDeclRef(D->getCommonPtr()->Latest, Record); |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 874 | } else { |
| 875 | RedeclarableTemplateDecl *First = D->getFirstDeclaration(); |
| 876 | assert(First != D); |
| 877 | // If this is a most recent redeclaration that is pointed to by a first decl |
| 878 | // in a chained PCH, keep track of the association with the map so we can |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 879 | // update the first decl during AST reading. |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 880 | if (First->getMostRecentDeclaration() == D && |
| 881 | First->getPCHLevel() > D->getPCHLevel()) { |
| 882 | assert(Writer.FirstLatestDecls.find(First)==Writer.FirstLatestDecls.end() |
| 883 | && "The latest is already set"); |
| 884 | Writer.FirstLatestDecls[First] = D; |
| 885 | } |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 886 | } |
Argyrios Kyrtzidis | 6b54151 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 887 | |
| 888 | VisitTemplateDecl(D); |
| 889 | Record.push_back(D->getIdentifierNamespace()); |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 890 | } |
| 891 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 892 | void ASTDeclWriter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 893 | VisitRedeclarableTemplateDecl(D); |
| 894 | |
| 895 | if (D->getPreviousDeclaration() == 0) { |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 896 | typedef llvm::FoldingSet<ClassTemplateSpecializationDecl> CTSDSetTy; |
| 897 | CTSDSetTy &CTSDSet = D->getSpecializations(); |
| 898 | Record.push_back(CTSDSet.size()); |
Argyrios Kyrtzidis | 7d53048 | 2010-07-02 11:55:37 +0000 | [diff] [blame] | 899 | for (CTSDSetTy::iterator I=CTSDSet.begin(), E = CTSDSet.end(); I!=E; ++I) { |
Argyrios Kyrtzidis | bc5ab7c | 2010-07-20 13:59:40 +0000 | [diff] [blame] | 900 | assert(I->isCanonicalDecl() && "Expected only canonical decls in set"); |
Argyrios Kyrtzidis | ecf966e | 2010-07-09 21:11:43 +0000 | [diff] [blame] | 901 | Writer.AddDeclRef(&*I, Record); |
Argyrios Kyrtzidis | 7d53048 | 2010-07-02 11:55:37 +0000 | [diff] [blame] | 902 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 903 | |
| 904 | typedef llvm::FoldingSet<ClassTemplatePartialSpecializationDecl> CTPSDSetTy; |
| 905 | CTPSDSetTy &CTPSDSet = D->getPartialSpecializations(); |
| 906 | Record.push_back(CTPSDSet.size()); |
Argyrios Kyrtzidis | 7d53048 | 2010-07-02 11:55:37 +0000 | [diff] [blame] | 907 | for (CTPSDSetTy::iterator I=CTPSDSet.begin(), E=CTPSDSet.end(); I!=E; ++I) { |
Argyrios Kyrtzidis | bc5ab7c | 2010-07-20 13:59:40 +0000 | [diff] [blame] | 908 | assert(I->isCanonicalDecl() && "Expected only canonical decls in set"); |
Argyrios Kyrtzidis | ecf966e | 2010-07-09 21:11:43 +0000 | [diff] [blame] | 909 | Writer.AddDeclRef(&*I, Record); |
Argyrios Kyrtzidis | 7d53048 | 2010-07-02 11:55:37 +0000 | [diff] [blame] | 910 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 911 | |
| 912 | // InjectedClassNameType is computed, no need to write it. |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 913 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 914 | Code = serialization::DECL_CLASS_TEMPLATE; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 915 | } |
| 916 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 917 | void ASTDeclWriter::VisitClassTemplateSpecializationDecl( |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 918 | ClassTemplateSpecializationDecl *D) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 919 | VisitCXXRecordDecl(D); |
| 920 | |
| 921 | llvm::PointerUnion<ClassTemplateDecl *, |
| 922 | ClassTemplatePartialSpecializationDecl *> InstFrom |
| 923 | = D->getSpecializedTemplateOrPartial(); |
Sebastian Redl | 4153a06 | 2010-08-24 22:50:24 +0000 | [diff] [blame] | 924 | Decl *InstFromD; |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 925 | if (InstFrom.is<ClassTemplateDecl *>()) { |
Sebastian Redl | 4153a06 | 2010-08-24 22:50:24 +0000 | [diff] [blame] | 926 | InstFromD = InstFrom.get<ClassTemplateDecl *>(); |
| 927 | Writer.AddDeclRef(InstFromD, Record); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 928 | } else { |
Sebastian Redl | 4153a06 | 2010-08-24 22:50:24 +0000 | [diff] [blame] | 929 | InstFromD = InstFrom.get<ClassTemplatePartialSpecializationDecl *>(); |
| 930 | Writer.AddDeclRef(InstFromD, Record); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 931 | Writer.AddTemplateArgumentList(&D->getTemplateInstantiationArgs(), Record); |
Sebastian Redl | 4153a06 | 2010-08-24 22:50:24 +0000 | [diff] [blame] | 932 | InstFromD = cast<ClassTemplatePartialSpecializationDecl>(InstFromD)-> |
| 933 | getSpecializedTemplate(); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | // Explicit info. |
| 937 | Writer.AddTypeSourceInfo(D->getTypeAsWritten(), Record); |
| 938 | if (D->getTypeAsWritten()) { |
| 939 | Writer.AddSourceLocation(D->getExternLoc(), Record); |
| 940 | Writer.AddSourceLocation(D->getTemplateKeywordLoc(), Record); |
| 941 | } |
| 942 | |
| 943 | Writer.AddTemplateArgumentList(&D->getTemplateArgs(), Record); |
| 944 | Writer.AddSourceLocation(D->getPointOfInstantiation(), Record); |
| 945 | Record.push_back(D->getSpecializationKind()); |
| 946 | |
Argyrios Kyrtzidis | bc5ab7c | 2010-07-20 13:59:40 +0000 | [diff] [blame] | 947 | if (D->isCanonicalDecl()) { |
| 948 | // When reading, we'll add it to the folding set of the following template. |
Argyrios Kyrtzidis | ecf966e | 2010-07-09 21:11:43 +0000 | [diff] [blame] | 949 | Writer.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl(), Record); |
| 950 | } |
| 951 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 952 | Code = serialization::DECL_CLASS_TEMPLATE_SPECIALIZATION; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 953 | } |
| 954 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 955 | void ASTDeclWriter::VisitClassTemplatePartialSpecializationDecl( |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 956 | ClassTemplatePartialSpecializationDecl *D) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 957 | VisitClassTemplateSpecializationDecl(D); |
| 958 | |
| 959 | Writer.AddTemplateParameterList(D->getTemplateParameters(), Record); |
| 960 | |
| 961 | Record.push_back(D->getNumTemplateArgsAsWritten()); |
| 962 | for (int i = 0, e = D->getNumTemplateArgsAsWritten(); i != e; ++i) |
| 963 | Writer.AddTemplateArgumentLoc(D->getTemplateArgsAsWritten()[i], Record); |
| 964 | |
| 965 | Record.push_back(D->getSequenceNumber()); |
| 966 | |
| 967 | // These are read/set from/to the first declaration. |
| 968 | if (D->getPreviousDeclaration() == 0) { |
| 969 | Writer.AddDeclRef(D->getInstantiatedFromMember(), Record); |
| 970 | Record.push_back(D->isMemberSpecialization()); |
| 971 | } |
| 972 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 973 | Code = serialization::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 974 | } |
| 975 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 976 | void ASTDeclWriter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 977 | VisitRedeclarableTemplateDecl(D); |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 978 | |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 979 | if (D->getPreviousDeclaration() == 0) { |
| 980 | // This FunctionTemplateDecl owns the CommonPtr; write it. |
| 981 | |
Argyrios Kyrtzidis | 057d9af | 2010-07-06 15:37:09 +0000 | [diff] [blame] | 982 | // Write the function specialization declarations. |
| 983 | Record.push_back(D->getSpecializations().size()); |
| 984 | for (llvm::FoldingSet<FunctionTemplateSpecializationInfo>::iterator |
| 985 | I = D->getSpecializations().begin(), |
Argyrios Kyrtzidis | 2c853e4 | 2010-07-20 13:59:58 +0000 | [diff] [blame] | 986 | E = D->getSpecializations().end() ; I != E; ++I) { |
| 987 | assert(I->Function->isCanonicalDecl() && |
| 988 | "Expected only canonical decls in set"); |
Argyrios Kyrtzidis | 057d9af | 2010-07-06 15:37:09 +0000 | [diff] [blame] | 989 | Writer.AddDeclRef(I->Function, Record); |
Argyrios Kyrtzidis | 2c853e4 | 2010-07-20 13:59:58 +0000 | [diff] [blame] | 990 | } |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 991 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 992 | Code = serialization::DECL_FUNCTION_TEMPLATE; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 993 | } |
| 994 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 995 | void ASTDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 996 | VisitTypeDecl(D); |
| 997 | |
| 998 | Record.push_back(D->wasDeclaredWithTypename()); |
| 999 | Record.push_back(D->isParameterPack()); |
| 1000 | Record.push_back(D->defaultArgumentWasInherited()); |
| 1001 | Writer.AddTypeSourceInfo(D->getDefaultArgumentInfo(), Record); |
| 1002 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1003 | Code = serialization::DECL_TEMPLATE_TYPE_PARM; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1004 | } |
| 1005 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1006 | void ASTDeclWriter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
Douglas Gregor | 6952f1e | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 1007 | // For an expanded parameter pack, record the number of expansion types here |
| 1008 | // so that it's easier for |
| 1009 | if (D->isExpandedParameterPack()) |
| 1010 | Record.push_back(D->getNumExpansionTypes()); |
| 1011 | |
Argyrios Kyrtzidis | b24e199 | 2010-06-25 16:25:09 +0000 | [diff] [blame] | 1012 | VisitVarDecl(D); |
| 1013 | // TemplateParmPosition. |
| 1014 | Record.push_back(D->getDepth()); |
| 1015 | Record.push_back(D->getPosition()); |
Douglas Gregor | 6952f1e | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 1016 | |
| 1017 | if (D->isExpandedParameterPack()) { |
| 1018 | for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) { |
| 1019 | Writer.AddTypeRef(D->getExpansionType(I), Record); |
| 1020 | Writer.AddTypeSourceInfo(D->getExpansionTypeSourceInfo(I), Record); |
| 1021 | } |
| 1022 | |
| 1023 | Code = serialization::DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK; |
| 1024 | } else { |
| 1025 | // Rest of NonTypeTemplateParmDecl. |
| 1026 | Record.push_back(D->isParameterPack()); |
| 1027 | Record.push_back(D->getDefaultArgument() != 0); |
| 1028 | if (D->getDefaultArgument()) { |
| 1029 | Writer.AddStmt(D->getDefaultArgument()); |
| 1030 | Record.push_back(D->defaultArgumentWasInherited()); |
| 1031 | } |
| 1032 | Code = serialization::DECL_NON_TYPE_TEMPLATE_PARM; |
Argyrios Kyrtzidis | b24e199 | 2010-06-25 16:25:09 +0000 | [diff] [blame] | 1033 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1034 | } |
| 1035 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1036 | void ASTDeclWriter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
Argyrios Kyrtzidis | bfcc92c | 2010-07-08 17:12:57 +0000 | [diff] [blame] | 1037 | VisitTemplateDecl(D); |
| 1038 | // TemplateParmPosition. |
| 1039 | Record.push_back(D->getDepth()); |
| 1040 | Record.push_back(D->getPosition()); |
| 1041 | // Rest of TemplateTemplateParmDecl. |
| 1042 | Writer.AddTemplateArgumentLoc(D->getDefaultArgument(), Record); |
| 1043 | Record.push_back(D->defaultArgumentWasInherited()); |
Douglas Gregor | 61c4d28 | 2011-01-05 15:48:55 +0000 | [diff] [blame] | 1044 | Record.push_back(D->isParameterPack()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1045 | Code = serialization::DECL_TEMPLATE_TEMPLATE_PARM; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1046 | } |
| 1047 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1048 | void ASTDeclWriter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
Argyrios Kyrtzidis | 0d39689 | 2010-07-22 17:28:12 +0000 | [diff] [blame] | 1049 | VisitDecl(D); |
| 1050 | Writer.AddStmt(D->getAssertExpr()); |
| 1051 | Writer.AddStmt(D->getMessage()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1052 | Code = serialization::DECL_STATIC_ASSERT; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 1055 | /// \brief Emit the DeclContext part of a declaration context decl. |
| 1056 | /// |
| 1057 | /// \param LexicalOffset the offset at which the DECL_CONTEXT_LEXICAL |
| 1058 | /// block for this declaration context is stored. May be 0 to indicate |
| 1059 | /// that there are no declarations stored within this context. |
| 1060 | /// |
| 1061 | /// \param VisibleOffset the offset at which the DECL_CONTEXT_VISIBLE |
| 1062 | /// block for this declaration context is stored. May be 0 to indicate |
| 1063 | /// that there are no declarations visible from this context. Note |
| 1064 | /// that this value will not be emitted for non-primary declaration |
| 1065 | /// contexts. |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1066 | void ASTDeclWriter::VisitDeclContext(DeclContext *DC, uint64_t LexicalOffset, |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 1067 | uint64_t VisibleOffset) { |
| 1068 | Record.push_back(LexicalOffset); |
| 1069 | Record.push_back(VisibleOffset); |
| 1070 | } |
| 1071 | |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1072 | template <typename T> |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1073 | void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1074 | enum { NoRedeclaration = 0, PointsToPrevious, PointsToLatest }; |
| 1075 | if (D->RedeclLink.getNext() == D) { |
| 1076 | Record.push_back(NoRedeclaration); |
| 1077 | } else { |
| 1078 | Record.push_back(D->RedeclLink.NextIsPrevious() ? PointsToPrevious |
| 1079 | : PointsToLatest); |
| 1080 | Writer.AddDeclRef(D->RedeclLink.getPointer(), Record); |
| 1081 | } |
| 1082 | |
| 1083 | T *First = D->getFirstDeclaration(); |
| 1084 | T *ThisDecl = static_cast<T*>(D); |
| 1085 | // If this is a most recent redeclaration that is pointed to by a first decl |
| 1086 | // in a chained PCH, keep track of the association with the map so we can |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1087 | // update the first decl during AST reading. |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1088 | if (ThisDecl != First && First->getMostRecentDeclaration() == ThisDecl && |
| 1089 | First->getPCHLevel() > ThisDecl->getPCHLevel()) { |
| 1090 | assert(Writer.FirstLatestDecls.find(First) == Writer.FirstLatestDecls.end() |
| 1091 | && "The latest is already set"); |
| 1092 | Writer.FirstLatestDecls[First] = ThisDecl; |
| 1093 | } |
| 1094 | } |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 1095 | |
| 1096 | //===----------------------------------------------------------------------===// |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1097 | // ASTWriter Implementation |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 1098 | //===----------------------------------------------------------------------===// |
| 1099 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1100 | void ASTWriter::WriteDeclsBlockAbbrevs() { |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 1101 | using namespace llvm; |
| 1102 | // Abbreviation for DECL_PARM_VAR. |
| 1103 | BitCodeAbbrev *Abv = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1104 | Abv->Add(BitCodeAbbrevOp(serialization::DECL_PARM_VAR)); |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 1105 | |
| 1106 | // Decl |
| 1107 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
| 1108 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext |
| 1109 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location |
| 1110 | Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl (!?) |
| 1111 | Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs |
| 1112 | Abv->Add(BitCodeAbbrevOp(0)); // isImplicit |
Douglas Gregor | e0762c9 | 2009-06-19 23:52:42 +0000 | [diff] [blame] | 1113 | Abv->Add(BitCodeAbbrevOp(0)); // isUsed |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 1114 | Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier |
Douglas Gregor | 7d1d49d | 2009-10-16 20:01:17 +0000 | [diff] [blame] | 1115 | Abv->Add(BitCodeAbbrevOp(0)); // PCH level |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1116 | |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 1117 | // NamedDecl |
| 1118 | Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier |
| 1119 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
| 1120 | // ValueDecl |
| 1121 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 1122 | // DeclaratorDecl |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 1123 | Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1124 | Abv->Add(BitCodeAbbrevOp(serialization::PREDEF_TYPE_NULL_ID)); // InfoType |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 1125 | // VarDecl |
Andrew Trick | 220a9c8 | 2010-10-19 21:54:32 +0000 | [diff] [blame] | 1126 | Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 1127 | Abv->Add(BitCodeAbbrevOp(0)); // StorageClass |
Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 1128 | Abv->Add(BitCodeAbbrevOp(0)); // StorageClassAsWritten |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 1129 | Abv->Add(BitCodeAbbrevOp(0)); // isThreadSpecified |
| 1130 | Abv->Add(BitCodeAbbrevOp(0)); // hasCXXDirectInitializer |
Douglas Gregor | 324b54d | 2010-05-03 18:51:14 +0000 | [diff] [blame] | 1131 | Abv->Add(BitCodeAbbrevOp(0)); // isExceptionVariable |
Douglas Gregor | 5077c38 | 2010-05-15 06:01:05 +0000 | [diff] [blame] | 1132 | Abv->Add(BitCodeAbbrevOp(0)); // isNRVOVariable |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 1133 | Abv->Add(BitCodeAbbrevOp(0)); // HasInit |
Argyrios Kyrtzidis | 9421adc | 2010-07-04 21:44:00 +0000 | [diff] [blame] | 1134 | Abv->Add(BitCodeAbbrevOp(0)); // HasMemberSpecializationInfo |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 1135 | // ParmVarDecl |
| 1136 | Abv->Add(BitCodeAbbrevOp(0)); // ObjCDeclQualifier |
John McCall | bf73b35 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 1137 | Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedDefaultArg |
Argyrios Kyrtzidis | 691d77f | 2010-07-04 21:44:07 +0000 | [diff] [blame] | 1138 | Abv->Add(BitCodeAbbrevOp(0)); // HasUninstantiatedDefaultArg |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1139 | |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 1140 | ParmVarDeclAbbrev = Stream.EmitAbbrev(Abv); |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 1141 | |
| 1142 | Abv = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1143 | Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_LEXICAL)); |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 1144 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1145 | DeclContextLexicalAbbrev = Stream.EmitAbbrev(Abv); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 1146 | |
| 1147 | Abv = new BitCodeAbbrev(); |
| 1148 | Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_VISIBLE)); |
| 1149 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1150 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1151 | DeclContextVisibleLookupAbbrev = Stream.EmitAbbrev(Abv); |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 1152 | } |
| 1153 | |
Daniel Dunbar | e24d38f | 2009-09-17 03:06:51 +0000 | [diff] [blame] | 1154 | /// isRequiredDecl - Check if this is a "required" Decl, which must be seen by |
| 1155 | /// consumers of the AST. |
| 1156 | /// |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1157 | /// Such decls will always be deserialized from the AST file, so we would like |
Daniel Dunbar | e24d38f | 2009-09-17 03:06:51 +0000 | [diff] [blame] | 1158 | /// this to be as restrictive as possible. Currently the predicate is driven by |
| 1159 | /// code generation requirements, if other clients have a different notion of |
| 1160 | /// what is "required" then we may have to consider an alternate scheme where |
| 1161 | /// clients can iterate over the top-level decls and get information on them, |
| 1162 | /// without necessary deserializing them. We could explicitly require such |
| 1163 | /// clients to use a separate API call to "realize" the decl. This should be |
| 1164 | /// relatively painless since they would presumably only do it for top-level |
| 1165 | /// decls. |
Daniel Dunbar | e24d38f | 2009-09-17 03:06:51 +0000 | [diff] [blame] | 1166 | static bool isRequiredDecl(const Decl *D, ASTContext &Context) { |
Argyrios Kyrtzidis | 9d50c06 | 2010-08-09 10:54:20 +0000 | [diff] [blame] | 1167 | // File scoped assembly or obj-c implementation must be seen. |
| 1168 | if (isa<FileScopeAsmDecl>(D) || isa<ObjCImplementationDecl>(D)) |
Daniel Dunbar | e24d38f | 2009-09-17 03:06:51 +0000 | [diff] [blame] | 1169 | return true; |
| 1170 | |
Argyrios Kyrtzidis | 4ac7c0b | 2010-07-29 20:08:05 +0000 | [diff] [blame] | 1171 | return Context.DeclMustBeEmitted(D); |
Daniel Dunbar | e24d38f | 2009-09-17 03:06:51 +0000 | [diff] [blame] | 1172 | } |
| 1173 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1174 | void ASTWriter::WriteDecl(ASTContext &Context, Decl *D) { |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 1175 | // Switch case IDs are per Decl. |
| 1176 | ClearSwitchCaseIDs(); |
| 1177 | |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 1178 | RecordData Record; |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1179 | ASTDeclWriter W(*this, Context, Record); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 1180 | |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 1181 | // If this declaration is also a DeclContext, write blocks for the |
| 1182 | // declarations that lexically stored inside its context and those |
| 1183 | // declarations that are visible from its context. These blocks |
| 1184 | // are written before the declaration itself so that we can put |
| 1185 | // their offsets into the record for the declaration. |
| 1186 | uint64_t LexicalOffset = 0; |
| 1187 | uint64_t VisibleOffset = 0; |
| 1188 | DeclContext *DC = dyn_cast<DeclContext>(D); |
| 1189 | if (DC) { |
| 1190 | LexicalOffset = WriteDeclContextLexicalBlock(Context, DC); |
| 1191 | VisibleOffset = WriteDeclContextVisibleBlock(Context, DC); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 1192 | } |
| 1193 | |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 1194 | // Determine the ID for this declaration |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1195 | serialization::DeclID &IDR = DeclIDs[D]; |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 1196 | if (IDR == 0) |
| 1197 | IDR = NextDeclID++; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1198 | serialization::DeclID ID = IDR; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 1199 | |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 1200 | if (ID < FirstDeclID) { |
| 1201 | // We're replacing a decl in a previous file. |
| 1202 | ReplacedDecls.push_back(std::make_pair(ID, Stream.GetCurrentBitNo())); |
| 1203 | } else { |
| 1204 | unsigned Index = ID - FirstDeclID; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 1205 | |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 1206 | // Record the offset for this declaration |
| 1207 | if (DeclOffsets.size() == Index) |
| 1208 | DeclOffsets.push_back(Stream.GetCurrentBitNo()); |
| 1209 | else if (DeclOffsets.size() < Index) { |
| 1210 | DeclOffsets.resize(Index+1); |
| 1211 | DeclOffsets[Index] = Stream.GetCurrentBitNo(); |
| 1212 | } |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 1213 | } |
| 1214 | |
| 1215 | // Build and emit a record for this declaration |
| 1216 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1217 | W.Code = (serialization::DeclCode)0; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 1218 | W.AbbrevToUse = 0; |
| 1219 | W.Visit(D); |
| 1220 | if (DC) W.VisitDeclContext(DC, LexicalOffset, VisibleOffset); |
| 1221 | |
Daniel Dunbar | 3367198 | 2009-12-03 09:13:36 +0000 | [diff] [blame] | 1222 | if (!W.Code) |
Chris Lattner | 83e7a78 | 2010-04-07 22:58:06 +0000 | [diff] [blame] | 1223 | llvm::report_fatal_error(llvm::StringRef("unexpected declaration kind '") + |
Daniel Dunbar | 3367198 | 2009-12-03 09:13:36 +0000 | [diff] [blame] | 1224 | D->getDeclKindName() + "'"); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 1225 | Stream.EmitRecord(W.Code, Record, W.AbbrevToUse); |
| 1226 | |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 1227 | // Flush any expressions that were written as part of this declaration. |
| 1228 | FlushStmts(); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 1229 | |
| 1230 | // Flush C++ base specifiers, if there are any. |
| 1231 | FlushCXXBaseSpecifiers(); |
| 1232 | |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 1233 | // Note "external" declarations so that we can add them to a record in the |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1234 | // AST file later. |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 1235 | // |
| 1236 | // FIXME: This should be renamed, the predicate is much more complicated. |
| 1237 | if (isRequiredDecl(D, Context)) |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 1238 | ExternalDefinitions.push_back(ID); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 1239 | } |