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