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