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 | |
| 28 | namespace { |
| 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 | } |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 43 | |
| 44 | void VisitDecl(Decl *D); |
| 45 | void VisitTranslationUnitDecl(TranslationUnitDecl *D); |
| 46 | void VisitNamedDecl(NamedDecl *D); |
Douglas Gregor | 0cef483 | 2010-02-21 18:22:14 +0000 | [diff] [blame] | 47 | void VisitNamespaceDecl(NamespaceDecl *D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 48 | void VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| 49 | void VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 50 | void VisitTypeDecl(TypeDecl *D); |
| 51 | void VisitTypedefDecl(TypedefDecl *D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 52 | void VisitUnresolvedUsingTypename(UnresolvedUsingTypenameDecl *D); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 53 | void VisitTagDecl(TagDecl *D); |
| 54 | void VisitEnumDecl(EnumDecl *D); |
| 55 | void VisitRecordDecl(RecordDecl *D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 56 | void VisitCXXRecordDecl(CXXRecordDecl *D); |
| 57 | void VisitClassTemplateSpecializationDecl( |
| 58 | ClassTemplateSpecializationDecl *D); |
| 59 | void VisitClassTemplatePartialSpecializationDecl( |
| 60 | ClassTemplatePartialSpecializationDecl *D); |
| 61 | void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 62 | void VisitValueDecl(ValueDecl *D); |
| 63 | void VisitEnumConstantDecl(EnumConstantDecl *D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 64 | void VisitUnresolvedUsingValue(UnresolvedUsingValueDecl *D); |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 65 | void VisitDeclaratorDecl(DeclaratorDecl *D); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 66 | void VisitFunctionDecl(FunctionDecl *D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 67 | void VisitCXXMethodDecl(CXXMethodDecl *D); |
| 68 | void VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 69 | void VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 70 | void VisitCXXConversionDecl(CXXConversionDecl *D); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 71 | void VisitFieldDecl(FieldDecl *D); |
| 72 | void VisitVarDecl(VarDecl *D); |
| 73 | void VisitImplicitParamDecl(ImplicitParamDecl *D); |
| 74 | void VisitParmVarDecl(ParmVarDecl *D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 75 | void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| 76 | void VisitTemplateDecl(TemplateDecl *D); |
| 77 | void VisitClassTemplateDecl(ClassTemplateDecl *D); |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 78 | void VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 79 | void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
Argyrios Kyrtzidis | b01a552 | 2010-06-20 14:40:59 +0000 | [diff] [blame] | 80 | void VisitUsingDecl(UsingDecl *D); |
| 81 | void VisitUsingShadowDecl(UsingShadowDecl *D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 82 | void VisitLinkageSpecDecl(LinkageSpecDecl *D); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 83 | void VisitFileScopeAsmDecl(FileScopeAsmDecl *D); |
Abramo Bagnara | 6206d53 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 84 | void VisitAccessSpecDecl(AccessSpecDecl *D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 85 | void VisitFriendTemplateDecl(FriendTemplateDecl *D); |
| 86 | void VisitStaticAssertDecl(StaticAssertDecl *D); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 87 | void VisitBlockDecl(BlockDecl *D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 88 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 89 | void VisitDeclContext(DeclContext *DC, uint64_t LexicalOffset, |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 90 | uint64_t VisibleOffset); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 91 | |
| 92 | |
Sean Hunt | 9a55591 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 93 | // FIXME: Put in the same order is DeclNodes.td? |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 94 | void VisitObjCMethodDecl(ObjCMethodDecl *D); |
| 95 | void VisitObjCContainerDecl(ObjCContainerDecl *D); |
| 96 | void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
| 97 | void VisitObjCIvarDecl(ObjCIvarDecl *D); |
| 98 | void VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
| 99 | void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D); |
| 100 | void VisitObjCClassDecl(ObjCClassDecl *D); |
| 101 | void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D); |
| 102 | void VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
| 103 | void VisitObjCImplDecl(ObjCImplDecl *D); |
| 104 | void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
| 105 | void VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
| 106 | void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D); |
| 107 | void VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
| 108 | void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
John McCall | 5250f27 | 2010-06-03 19:28:45 +0000 | [diff] [blame] | 109 | |
| 110 | void WriteCXXBaseSpecifier(const CXXBaseSpecifier *Base); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 111 | }; |
| 112 | } |
| 113 | |
| 114 | void PCHDeclWriter::VisitDecl(Decl *D) { |
| 115 | Writer.AddDeclRef(cast_or_null<Decl>(D->getDeclContext()), Record); |
| 116 | Writer.AddDeclRef(cast_or_null<Decl>(D->getLexicalDeclContext()), Record); |
| 117 | Writer.AddSourceLocation(D->getLocation(), Record); |
| 118 | Record.push_back(D->isInvalidDecl()); |
| 119 | Record.push_back(D->hasAttrs()); |
| 120 | Record.push_back(D->isImplicit()); |
Douglas Gregor | c070cc6 | 2010-06-17 23:14:26 +0000 | [diff] [blame] | 121 | Record.push_back(D->isUsed(false)); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 122 | Record.push_back(D->getAccess()); |
Douglas Gregor | 7d1d49d | 2009-10-16 20:01:17 +0000 | [diff] [blame] | 123 | Record.push_back(D->getPCHLevel()); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | void PCHDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
| 127 | VisitDecl(D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 128 | Writer.AddDeclRef(D->getAnonymousNamespace(), Record); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 129 | Code = pch::DECL_TRANSLATION_UNIT; |
| 130 | } |
| 131 | |
| 132 | void PCHDeclWriter::VisitNamedDecl(NamedDecl *D) { |
| 133 | VisitDecl(D); |
| 134 | Writer.AddDeclarationName(D->getDeclName(), Record); |
| 135 | } |
| 136 | |
| 137 | void PCHDeclWriter::VisitTypeDecl(TypeDecl *D) { |
| 138 | VisitNamedDecl(D); |
Argyrios Kyrtzidis | 28d16d7 | 2010-06-19 19:29:21 +0000 | [diff] [blame] | 139 | if (isa<CXXRecordDecl>(D)) { |
| 140 | // FIXME: Hack. To read a templated CXXRecordDecl from PCH, we need an |
| 141 | // initialized CXXRecordDecl before creating an InjectedClassNameType. |
| 142 | // Delay emitting/reading CXXRecordDecl's TypeForDecl until when we handle |
| 143 | // CXXRecordDecl emitting/initialization. |
| 144 | Writer.AddTypeRef(QualType(), Record); |
| 145 | } else |
| 146 | Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | void PCHDeclWriter::VisitTypedefDecl(TypedefDecl *D) { |
| 150 | VisitTypeDecl(D); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 151 | Writer.AddTypeSourceInfo(D->getTypeSourceInfo(), Record); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 152 | Code = pch::DECL_TYPEDEF; |
| 153 | } |
| 154 | |
| 155 | void PCHDeclWriter::VisitTagDecl(TagDecl *D) { |
| 156 | VisitTypeDecl(D); |
Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 157 | Writer.AddDeclRef(D->getPreviousDeclaration(), Record); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 158 | Record.push_back((unsigned)D->getTagKind()); // FIXME: stable encoding |
| 159 | Record.push_back(D->isDefinition()); |
Douglas Gregor | b37b648 | 2010-02-12 17:40:34 +0000 | [diff] [blame] | 160 | Record.push_back(D->isEmbeddedInDeclarator()); |
Argyrios Kyrtzidis | ad93a74 | 2009-07-14 03:18:02 +0000 | [diff] [blame] | 161 | Writer.AddSourceLocation(D->getRBraceLoc(), Record); |
Douglas Gregor | 741dd9a | 2009-07-21 14:46:17 +0000 | [diff] [blame] | 162 | Writer.AddSourceLocation(D->getTagKeywordLoc(), Record); |
John McCall | b621766 | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 163 | // FIXME: maybe write optional qualifier and its range. |
| 164 | Writer.AddDeclRef(D->getTypedefForAnonDecl(), Record); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | void PCHDeclWriter::VisitEnumDecl(EnumDecl *D) { |
| 168 | VisitTagDecl(D); |
| 169 | Writer.AddTypeRef(D->getIntegerType(), Record); |
John McCall | 842aef8 | 2009-12-09 09:09:27 +0000 | [diff] [blame] | 170 | Writer.AddTypeRef(D->getPromotionType(), Record); |
John McCall | 1b5a618 | 2010-05-06 08:49:23 +0000 | [diff] [blame] | 171 | Record.push_back(D->getNumPositiveBits()); |
| 172 | Record.push_back(D->getNumNegativeBits()); |
Douglas Gregor | 8dbc3c6 | 2009-05-27 17:20:35 +0000 | [diff] [blame] | 173 | // FIXME: C++ InstantiatedFrom |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 174 | Code = pch::DECL_ENUM; |
| 175 | } |
| 176 | |
| 177 | void PCHDeclWriter::VisitRecordDecl(RecordDecl *D) { |
| 178 | VisitTagDecl(D); |
| 179 | Record.push_back(D->hasFlexibleArrayMember()); |
| 180 | Record.push_back(D->isAnonymousStructOrUnion()); |
Fariborz Jahanian | 643b7df | 2009-07-08 16:37:44 +0000 | [diff] [blame] | 181 | Record.push_back(D->hasObjectMember()); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 182 | Code = pch::DECL_RECORD; |
| 183 | } |
| 184 | |
| 185 | void PCHDeclWriter::VisitValueDecl(ValueDecl *D) { |
| 186 | VisitNamedDecl(D); |
| 187 | Writer.AddTypeRef(D->getType(), Record); |
| 188 | } |
| 189 | |
| 190 | void PCHDeclWriter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
| 191 | VisitValueDecl(D); |
| 192 | Record.push_back(D->getInitExpr()? 1 : 0); |
| 193 | if (D->getInitExpr()) |
| 194 | Writer.AddStmt(D->getInitExpr()); |
| 195 | Writer.AddAPSInt(D->getInitVal(), Record); |
| 196 | Code = pch::DECL_ENUM_CONSTANT; |
| 197 | } |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 198 | |
| 199 | void PCHDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) { |
| 200 | VisitValueDecl(D); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 201 | Writer.AddTypeSourceInfo(D->getTypeSourceInfo(), Record); |
John McCall | b621766 | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 202 | // FIXME: write optional qualifier and its range. |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 203 | } |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 204 | |
| 205 | void PCHDeclWriter::VisitFunctionDecl(FunctionDecl *D) { |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 206 | VisitDeclaratorDecl(D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 207 | |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 208 | Record.push_back(D->isThisDeclarationADefinition()); |
| 209 | if (D->isThisDeclarationADefinition()) |
Argyrios Kyrtzidis | 6fb0aee | 2009-06-30 02:35:26 +0000 | [diff] [blame] | 210 | Writer.AddStmt(D->getBody()); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 211 | |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 212 | Writer.AddDeclRef(D->getPreviousDeclaration(), Record); |
| 213 | Record.push_back(D->getStorageClass()); // FIXME: stable encoding |
Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 214 | Record.push_back(D->getStorageClassAsWritten()); |
Douglas Gregor | 0130f3c | 2009-10-27 21:01:01 +0000 | [diff] [blame] | 215 | Record.push_back(D->isInlineSpecified()); |
Anders Carlsson | 77b7f1d | 2009-05-14 22:15:41 +0000 | [diff] [blame] | 216 | Record.push_back(D->isVirtualAsWritten()); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 217 | Record.push_back(D->isPure()); |
Anders Carlsson | a75e853 | 2009-05-14 21:46:00 +0000 | [diff] [blame] | 218 | Record.push_back(D->hasInheritedPrototype()); |
| 219 | Record.push_back(D->hasWrittenPrototype()); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 220 | Record.push_back(D->isDeleted()); |
Daniel Dunbar | 7f8b57a | 2009-09-22 05:38:14 +0000 | [diff] [blame] | 221 | Record.push_back(D->isTrivial()); |
| 222 | Record.push_back(D->isCopyAssignment()); |
| 223 | Record.push_back(D->hasImplicitReturnZero()); |
Argyrios Kyrtzidis | 8cff90e | 2009-06-20 08:09:34 +0000 | [diff] [blame] | 224 | Writer.AddSourceLocation(D->getLocEnd(), Record); |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 225 | |
| 226 | Record.push_back(D->getTemplatedKind()); |
| 227 | switch (D->getTemplatedKind()) { |
| 228 | case FunctionDecl::TK_NonTemplate: |
| 229 | break; |
| 230 | case FunctionDecl::TK_FunctionTemplate: |
| 231 | Writer.AddDeclRef(D->getDescribedFunctionTemplate(), Record); |
| 232 | break; |
| 233 | case FunctionDecl::TK_MemberSpecialization: { |
| 234 | MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo(); |
| 235 | Writer.AddDeclRef(MemberInfo->getInstantiatedFrom(), Record); |
| 236 | Record.push_back(MemberInfo->getTemplateSpecializationKind()); |
| 237 | Writer.AddSourceLocation(MemberInfo->getPointOfInstantiation(), Record); |
| 238 | break; |
| 239 | } |
| 240 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
| 241 | FunctionTemplateSpecializationInfo * |
| 242 | FTSInfo = D->getTemplateSpecializationInfo(); |
| 243 | Writer.AddDeclRef(FTSInfo->getTemplate(), Record); |
| 244 | Record.push_back(FTSInfo->getTemplateSpecializationKind()); |
| 245 | |
| 246 | // Template arguments. |
| 247 | assert(FTSInfo->TemplateArguments && "No template args!"); |
| 248 | Record.push_back(FTSInfo->TemplateArguments->flat_size()); |
| 249 | for (int i=0, e = FTSInfo->TemplateArguments->flat_size(); i != e; ++i) |
| 250 | Writer.AddTemplateArgument(FTSInfo->TemplateArguments->get(i), Record); |
| 251 | |
| 252 | // Template args as written. |
| 253 | if (FTSInfo->TemplateArgumentsAsWritten) { |
| 254 | Record.push_back(FTSInfo->TemplateArgumentsAsWritten->size()); |
| 255 | for (int i=0, e = FTSInfo->TemplateArgumentsAsWritten->size(); i!=e; ++i) |
| 256 | Writer.AddTemplateArgumentLoc((*FTSInfo->TemplateArgumentsAsWritten)[i], |
| 257 | Record); |
| 258 | Writer.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->getLAngleLoc(), |
| 259 | Record); |
| 260 | Writer.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->getRAngleLoc(), |
| 261 | Record); |
| 262 | } else { |
| 263 | Record.push_back(0); |
| 264 | } |
| 265 | } |
| 266 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 267 | DependentFunctionTemplateSpecializationInfo * |
| 268 | DFTSInfo = D->getDependentSpecializationInfo(); |
| 269 | |
| 270 | // Templates. |
| 271 | Record.push_back(DFTSInfo->getNumTemplates()); |
| 272 | for (int i=0, e = DFTSInfo->getNumTemplates(); i != e; ++i) |
| 273 | Writer.AddDeclRef(DFTSInfo->getTemplate(i), Record); |
| 274 | |
| 275 | // Templates args. |
| 276 | Record.push_back(DFTSInfo->getNumTemplateArgs()); |
| 277 | for (int i=0, e = DFTSInfo->getNumTemplateArgs(); i != e; ++i) |
| 278 | Writer.AddTemplateArgumentLoc(DFTSInfo->getTemplateArg(i), Record); |
| 279 | } |
| 280 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 281 | |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 282 | Record.push_back(D->param_size()); |
| 283 | for (FunctionDecl::param_iterator P = D->param_begin(), PEnd = D->param_end(); |
| 284 | P != PEnd; ++P) |
| 285 | Writer.AddDeclRef(*P, Record); |
| 286 | Code = pch::DECL_FUNCTION; |
| 287 | } |
| 288 | |
| 289 | void PCHDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
| 290 | VisitNamedDecl(D); |
| 291 | // FIXME: convert to LazyStmtPtr? |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 292 | // Unlike C/C++, method bodies will never be in header files. |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 293 | Record.push_back(D->getBody() != 0); |
| 294 | if (D->getBody() != 0) { |
Argyrios Kyrtzidis | 6fb0aee | 2009-06-30 02:35:26 +0000 | [diff] [blame] | 295 | Writer.AddStmt(D->getBody()); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 296 | Writer.AddDeclRef(D->getSelfDecl(), Record); |
| 297 | Writer.AddDeclRef(D->getCmdDecl(), Record); |
| 298 | } |
| 299 | Record.push_back(D->isInstanceMethod()); |
| 300 | Record.push_back(D->isVariadic()); |
| 301 | Record.push_back(D->isSynthesized()); |
| 302 | // FIXME: stable encoding for @required/@optional |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 303 | Record.push_back(D->getImplementationControl()); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 304 | // FIXME: stable encoding for in/out/inout/bycopy/byref/oneway |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 305 | Record.push_back(D->getObjCDeclQualifier()); |
Fariborz Jahanian | 7732cc9 | 2010-04-08 21:29:11 +0000 | [diff] [blame] | 306 | Record.push_back(D->getNumSelectorArgs()); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 307 | Writer.AddTypeRef(D->getResultType(), Record); |
Douglas Gregor | 4bc1cb6 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 308 | Writer.AddTypeSourceInfo(D->getResultTypeSourceInfo(), Record); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 309 | Writer.AddSourceLocation(D->getLocEnd(), Record); |
| 310 | Record.push_back(D->param_size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 311 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 312 | PEnd = D->param_end(); P != PEnd; ++P) |
| 313 | Writer.AddDeclRef(*P, Record); |
| 314 | Code = pch::DECL_OBJC_METHOD; |
| 315 | } |
| 316 | |
| 317 | void PCHDeclWriter::VisitObjCContainerDecl(ObjCContainerDecl *D) { |
| 318 | VisitNamedDecl(D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 319 | Writer.AddSourceRange(D->getAtEndRange(), Record); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 320 | // Abstract class (no need to define a stable pch::DECL code). |
| 321 | } |
| 322 | |
| 323 | void PCHDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
| 324 | VisitObjCContainerDecl(D); |
| 325 | Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record); |
| 326 | Writer.AddDeclRef(D->getSuperClass(), Record); |
| 327 | Record.push_back(D->protocol_size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 328 | for (ObjCInterfaceDecl::protocol_iterator P = D->protocol_begin(), |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 329 | PEnd = D->protocol_end(); |
| 330 | P != PEnd; ++P) |
| 331 | Writer.AddDeclRef(*P, Record); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 332 | for (ObjCInterfaceDecl::protocol_loc_iterator PL = D->protocol_loc_begin(), |
| 333 | PLEnd = D->protocol_loc_end(); |
| 334 | PL != PLEnd; ++PL) |
| 335 | Writer.AddSourceLocation(*PL, Record); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 336 | Record.push_back(D->ivar_size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 337 | for (ObjCInterfaceDecl::ivar_iterator I = D->ivar_begin(), |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 338 | IEnd = D->ivar_end(); I != IEnd; ++I) |
| 339 | Writer.AddDeclRef(*I, Record); |
| 340 | Writer.AddDeclRef(D->getCategoryList(), Record); |
| 341 | Record.push_back(D->isForwardDecl()); |
| 342 | Record.push_back(D->isImplicitInterfaceDecl()); |
| 343 | Writer.AddSourceLocation(D->getClassLoc(), Record); |
| 344 | Writer.AddSourceLocation(D->getSuperClassLoc(), Record); |
| 345 | Writer.AddSourceLocation(D->getLocEnd(), Record); |
| 346 | Code = pch::DECL_OBJC_INTERFACE; |
| 347 | } |
| 348 | |
| 349 | void PCHDeclWriter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
| 350 | VisitFieldDecl(D); |
| 351 | // FIXME: stable encoding for @public/@private/@protected/@package |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 352 | Record.push_back(D->getAccessControl()); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 353 | Code = pch::DECL_OBJC_IVAR; |
| 354 | } |
| 355 | |
| 356 | void PCHDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
| 357 | VisitObjCContainerDecl(D); |
| 358 | Record.push_back(D->isForwardDecl()); |
| 359 | Writer.AddSourceLocation(D->getLocEnd(), Record); |
| 360 | Record.push_back(D->protocol_size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 361 | for (ObjCProtocolDecl::protocol_iterator |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 362 | I = D->protocol_begin(), IEnd = D->protocol_end(); I != IEnd; ++I) |
| 363 | Writer.AddDeclRef(*I, Record); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 364 | for (ObjCProtocolDecl::protocol_loc_iterator PL = D->protocol_loc_begin(), |
| 365 | PLEnd = D->protocol_loc_end(); |
| 366 | PL != PLEnd; ++PL) |
| 367 | Writer.AddSourceLocation(*PL, Record); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 368 | Code = pch::DECL_OBJC_PROTOCOL; |
| 369 | } |
| 370 | |
| 371 | void PCHDeclWriter::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) { |
| 372 | VisitFieldDecl(D); |
| 373 | Code = pch::DECL_OBJC_AT_DEFS_FIELD; |
| 374 | } |
| 375 | |
| 376 | void PCHDeclWriter::VisitObjCClassDecl(ObjCClassDecl *D) { |
| 377 | VisitDecl(D); |
| 378 | Record.push_back(D->size()); |
| 379 | for (ObjCClassDecl::iterator I = D->begin(), IEnd = D->end(); I != IEnd; ++I) |
Ted Kremenek | 321c22f | 2009-11-18 00:28:11 +0000 | [diff] [blame] | 380 | Writer.AddDeclRef(I->getInterface(), Record); |
| 381 | for (ObjCClassDecl::iterator I = D->begin(), IEnd = D->end(); I != IEnd; ++I) |
| 382 | Writer.AddSourceLocation(I->getLocation(), Record); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 383 | Code = pch::DECL_OBJC_CLASS; |
| 384 | } |
| 385 | |
| 386 | void PCHDeclWriter::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D) { |
| 387 | VisitDecl(D); |
| 388 | Record.push_back(D->protocol_size()); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 389 | for (ObjCForwardProtocolDecl::protocol_iterator |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 390 | I = D->protocol_begin(), IEnd = D->protocol_end(); I != IEnd; ++I) |
| 391 | Writer.AddDeclRef(*I, Record); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 392 | for (ObjCForwardProtocolDecl::protocol_loc_iterator |
| 393 | PL = D->protocol_loc_begin(), PLEnd = D->protocol_loc_end(); |
| 394 | PL != PLEnd; ++PL) |
| 395 | Writer.AddSourceLocation(*PL, Record); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 396 | Code = pch::DECL_OBJC_FORWARD_PROTOCOL; |
| 397 | } |
| 398 | |
| 399 | void PCHDeclWriter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
| 400 | VisitObjCContainerDecl(D); |
| 401 | Writer.AddDeclRef(D->getClassInterface(), Record); |
| 402 | Record.push_back(D->protocol_size()); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 403 | for (ObjCCategoryDecl::protocol_iterator |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 404 | I = D->protocol_begin(), IEnd = D->protocol_end(); I != IEnd; ++I) |
| 405 | Writer.AddDeclRef(*I, Record); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 406 | for (ObjCCategoryDecl::protocol_loc_iterator |
| 407 | PL = D->protocol_loc_begin(), PLEnd = D->protocol_loc_end(); |
| 408 | PL != PLEnd; ++PL) |
| 409 | Writer.AddSourceLocation(*PL, Record); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 410 | Writer.AddDeclRef(D->getNextClassCategory(), Record); |
Douglas Gregor | 3db211b | 2010-01-16 16:38:58 +0000 | [diff] [blame] | 411 | Writer.AddSourceLocation(D->getAtLoc(), Record); |
| 412 | Writer.AddSourceLocation(D->getCategoryNameLoc(), Record); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 413 | Code = pch::DECL_OBJC_CATEGORY; |
| 414 | } |
| 415 | |
| 416 | void PCHDeclWriter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D) { |
| 417 | VisitNamedDecl(D); |
| 418 | Writer.AddDeclRef(D->getClassInterface(), Record); |
| 419 | Code = pch::DECL_OBJC_COMPATIBLE_ALIAS; |
| 420 | } |
| 421 | |
| 422 | void PCHDeclWriter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
| 423 | VisitNamedDecl(D); |
Fariborz Jahanian | d050240 | 2010-01-21 17:36:00 +0000 | [diff] [blame] | 424 | Writer.AddSourceLocation(D->getAtLoc(), Record); |
John McCall | 83a230c | 2010-06-04 20:50:08 +0000 | [diff] [blame] | 425 | Writer.AddTypeSourceInfo(D->getTypeSourceInfo(), Record); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 426 | // FIXME: stable encoding |
| 427 | Record.push_back((unsigned)D->getPropertyAttributes()); |
| 428 | // FIXME: stable encoding |
| 429 | Record.push_back((unsigned)D->getPropertyImplementation()); |
| 430 | Writer.AddDeclarationName(D->getGetterName(), Record); |
| 431 | Writer.AddDeclarationName(D->getSetterName(), Record); |
| 432 | Writer.AddDeclRef(D->getGetterMethodDecl(), Record); |
| 433 | Writer.AddDeclRef(D->getSetterMethodDecl(), Record); |
| 434 | Writer.AddDeclRef(D->getPropertyIvarDecl(), Record); |
| 435 | Code = pch::DECL_OBJC_PROPERTY; |
| 436 | } |
| 437 | |
| 438 | void PCHDeclWriter::VisitObjCImplDecl(ObjCImplDecl *D) { |
Argyrios Kyrtzidis | aecae62 | 2009-07-27 19:04:32 +0000 | [diff] [blame] | 439 | VisitObjCContainerDecl(D); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 440 | Writer.AddDeclRef(D->getClassInterface(), Record); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 441 | // Abstract class (no need to define a stable pch::DECL code). |
| 442 | } |
| 443 | |
| 444 | void PCHDeclWriter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 445 | VisitObjCImplDecl(D); |
| 446 | Writer.AddIdentifierRef(D->getIdentifier(), Record); |
| 447 | Code = pch::DECL_OBJC_CATEGORY_IMPL; |
| 448 | } |
| 449 | |
| 450 | void PCHDeclWriter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| 451 | VisitObjCImplDecl(D); |
| 452 | Writer.AddDeclRef(D->getSuperClass(), Record); |
Fariborz Jahanian | e4498c6 | 2010-04-28 16:11:27 +0000 | [diff] [blame] | 453 | // FIXME add writing of IvarInitializers and NumIvarInitializers. |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 454 | Code = pch::DECL_OBJC_IMPLEMENTATION; |
| 455 | } |
| 456 | |
| 457 | void PCHDeclWriter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 458 | VisitDecl(D); |
| 459 | Writer.AddSourceLocation(D->getLocStart(), Record); |
| 460 | Writer.AddDeclRef(D->getPropertyDecl(), Record); |
| 461 | Writer.AddDeclRef(D->getPropertyIvarDecl(), Record); |
Fariborz Jahanian | 17cb326 | 2010-05-05 21:52:17 +0000 | [diff] [blame] | 462 | // FIXME. write GetterCXXConstructor and SetterCXXAssignment. |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 463 | Code = pch::DECL_OBJC_PROPERTY_IMPL; |
| 464 | } |
| 465 | |
| 466 | void PCHDeclWriter::VisitFieldDecl(FieldDecl *D) { |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 467 | VisitDeclaratorDecl(D); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 468 | Record.push_back(D->isMutable()); |
| 469 | Record.push_back(D->getBitWidth()? 1 : 0); |
| 470 | if (D->getBitWidth()) |
| 471 | Writer.AddStmt(D->getBitWidth()); |
| 472 | Code = pch::DECL_FIELD; |
| 473 | } |
| 474 | |
| 475 | void PCHDeclWriter::VisitVarDecl(VarDecl *D) { |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 476 | VisitDeclaratorDecl(D); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 477 | Record.push_back(D->getStorageClass()); // FIXME: stable encoding |
Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 478 | Record.push_back(D->getStorageClassAsWritten()); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 479 | Record.push_back(D->isThreadSpecified()); |
| 480 | Record.push_back(D->hasCXXDirectInitializer()); |
| 481 | Record.push_back(D->isDeclaredInCondition()); |
Douglas Gregor | 324b54d | 2010-05-03 18:51:14 +0000 | [diff] [blame] | 482 | Record.push_back(D->isExceptionVariable()); |
Douglas Gregor | 5077c38 | 2010-05-15 06:01:05 +0000 | [diff] [blame] | 483 | Record.push_back(D->isNRVOVariable()); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 484 | Writer.AddDeclRef(D->getPreviousDeclaration(), Record); |
Chris Lattner | 030854b | 2010-05-09 06:40:08 +0000 | [diff] [blame] | 485 | Record.push_back(D->getInit() ? 1 : 0); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 486 | if (D->getInit()) |
| 487 | Writer.AddStmt(D->getInit()); |
| 488 | Code = pch::DECL_VAR; |
| 489 | } |
| 490 | |
| 491 | void PCHDeclWriter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
| 492 | VisitVarDecl(D); |
| 493 | Code = pch::DECL_IMPLICIT_PARAM; |
| 494 | } |
| 495 | |
| 496 | void PCHDeclWriter::VisitParmVarDecl(ParmVarDecl *D) { |
| 497 | VisitVarDecl(D); |
| 498 | Record.push_back(D->getObjCDeclQualifier()); // FIXME: stable encoding |
John McCall | bf73b35 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 499 | Record.push_back(D->hasInheritedDefaultArg()); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 500 | Code = pch::DECL_PARM_VAR; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 501 | |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 502 | // If the assumptions about the DECL_PARM_VAR abbrev are true, use it. Here |
| 503 | // we dynamically check for the properties that we optimize for, but don't |
| 504 | // know are true of all PARM_VAR_DECLs. |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 505 | if (!D->getTypeSourceInfo() && |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 506 | !D->hasAttrs() && |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 507 | !D->isImplicit() && |
Douglas Gregor | c070cc6 | 2010-06-17 23:14:26 +0000 | [diff] [blame] | 508 | !D->isUsed(false) && |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 509 | D->getAccess() == AS_none && |
Douglas Gregor | 7d1d49d | 2009-10-16 20:01:17 +0000 | [diff] [blame] | 510 | D->getPCHLevel() == 0 && |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 511 | D->getStorageClass() == 0 && |
| 512 | !D->hasCXXDirectInitializer() && // Can params have this ever? |
John McCall | bf73b35 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 513 | D->getObjCDeclQualifier() == 0 && |
Chris Lattner | 030854b | 2010-05-09 06:40:08 +0000 | [diff] [blame] | 514 | !D->hasInheritedDefaultArg() && |
| 515 | D->getInit() == 0) // No default expr. |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 516 | AbbrevToUse = Writer.getParmVarDeclAbbrev(); |
| 517 | |
| 518 | // Check things we know are true of *every* PARM_VAR_DECL, which is more than |
| 519 | // just us assuming it. |
| 520 | assert(!D->isInvalidDecl() && "Shouldn't emit invalid decls"); |
| 521 | assert(!D->isThreadSpecified() && "PARM_VAR_DECL can't be __thread"); |
| 522 | assert(D->getAccess() == AS_none && "PARM_VAR_DECL can't be public/private"); |
| 523 | assert(!D->isDeclaredInCondition() && "PARM_VAR_DECL can't be in condition"); |
Douglas Gregor | 324b54d | 2010-05-03 18:51:14 +0000 | [diff] [blame] | 524 | assert(!D->isExceptionVariable() && "PARM_VAR_DECL can't be exception var"); |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 525 | assert(D->getPreviousDeclaration() == 0 && "PARM_VAR_DECL can't be redecl"); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 526 | } |
| 527 | |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 528 | void PCHDeclWriter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) { |
| 529 | VisitDecl(D); |
| 530 | Writer.AddStmt(D->getAsmString()); |
| 531 | Code = pch::DECL_FILE_SCOPE_ASM; |
| 532 | } |
| 533 | |
| 534 | void PCHDeclWriter::VisitBlockDecl(BlockDecl *D) { |
| 535 | VisitDecl(D); |
| 536 | Writer.AddStmt(D->getBody()); |
John McCall | 82dc009 | 2010-06-04 11:21:44 +0000 | [diff] [blame] | 537 | Writer.AddTypeSourceInfo(D->getSignatureAsWritten(), Record); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 538 | Record.push_back(D->param_size()); |
| 539 | for (FunctionDecl::param_iterator P = D->param_begin(), PEnd = D->param_end(); |
| 540 | P != PEnd; ++P) |
| 541 | Writer.AddDeclRef(*P, Record); |
| 542 | Code = pch::DECL_BLOCK; |
| 543 | } |
| 544 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 545 | void PCHDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 546 | VisitDecl(D); |
| 547 | // FIXME: It might be nice to serialize the brace locations for this |
| 548 | // declaration, which don't seem to be readily available in the AST. |
| 549 | Record.push_back(D->getLanguage()); |
| 550 | Record.push_back(D->hasBraces()); |
| 551 | Code = pch::DECL_LINKAGE_SPEC; |
| 552 | } |
| 553 | |
| 554 | void PCHDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) { |
| 555 | VisitNamedDecl(D); |
| 556 | Writer.AddSourceLocation(D->getLBracLoc(), Record); |
| 557 | Writer.AddSourceLocation(D->getRBracLoc(), Record); |
| 558 | Writer.AddDeclRef(D->getNextNamespace(), Record); |
| 559 | |
| 560 | // Only write one reference--original or anonymous |
| 561 | Record.push_back(D->isOriginalNamespace()); |
| 562 | if (D->isOriginalNamespace()) |
| 563 | Writer.AddDeclRef(D->getAnonymousNamespace(), Record); |
| 564 | else |
| 565 | Writer.AddDeclRef(D->getOriginalNamespace(), Record); |
| 566 | Code = pch::DECL_NAMESPACE; |
| 567 | } |
| 568 | |
| 569 | void PCHDeclWriter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
| 570 | VisitNamedDecl(D); |
| 571 | Writer.AddSourceLocation(D->getAliasLoc(), Record); |
| 572 | Writer.AddSourceRange(D->getQualifierRange(), Record); |
| 573 | Writer.AddNestedNameSpecifier(D->getQualifier(), Record); |
| 574 | Writer.AddSourceLocation(D->getTargetNameLoc(), Record); |
| 575 | Writer.AddDeclRef(D->getNamespace(), Record); |
| 576 | Code = pch::DECL_NAMESPACE_ALIAS; |
| 577 | } |
| 578 | |
Argyrios Kyrtzidis | b01a552 | 2010-06-20 14:40:59 +0000 | [diff] [blame] | 579 | void PCHDeclWriter::VisitUsingDecl(UsingDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 580 | VisitNamedDecl(D); |
| 581 | Writer.AddSourceRange(D->getNestedNameRange(), Record); |
| 582 | Writer.AddSourceLocation(D->getUsingLocation(), Record); |
| 583 | Writer.AddNestedNameSpecifier(D->getTargetNestedNameDecl(), Record); |
| 584 | Record.push_back(D->getNumShadowDecls()); |
| 585 | for (UsingDecl::shadow_iterator P = D->shadow_begin(), |
| 586 | PEnd = D->shadow_end(); P != PEnd; ++P) |
| 587 | Writer.AddDeclRef(*P, Record); |
| 588 | Record.push_back(D->isTypeName()); |
| 589 | Code = pch::DECL_USING; |
| 590 | } |
| 591 | |
Argyrios Kyrtzidis | b01a552 | 2010-06-20 14:40:59 +0000 | [diff] [blame] | 592 | void PCHDeclWriter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 593 | VisitNamedDecl(D); |
| 594 | Writer.AddDeclRef(D->getTargetDecl(), Record); |
| 595 | Writer.AddDeclRef(D->getUsingDecl(), Record); |
| 596 | Code = pch::DECL_USING_SHADOW; |
| 597 | } |
| 598 | |
| 599 | void PCHDeclWriter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
| 600 | VisitNamedDecl(D); |
| 601 | Writer.AddSourceLocation(D->getNamespaceKeyLocation(), Record); |
| 602 | Writer.AddSourceRange(D->getQualifierRange(), Record); |
| 603 | Writer.AddNestedNameSpecifier(D->getQualifier(), Record); |
| 604 | Writer.AddSourceLocation(D->getIdentLocation(), Record); |
| 605 | Writer.AddDeclRef(D->getNominatedNamespace(), Record); |
| 606 | Writer.AddDeclRef(dyn_cast<Decl>(D->getCommonAncestor()), Record); |
| 607 | Code = pch::DECL_USING_DIRECTIVE; |
| 608 | } |
| 609 | |
| 610 | void PCHDeclWriter::VisitUnresolvedUsingValue(UnresolvedUsingValueDecl *D) { |
| 611 | VisitValueDecl(D); |
| 612 | Writer.AddSourceRange(D->getTargetNestedNameRange(), Record); |
| 613 | Writer.AddSourceLocation(D->getUsingLoc(), Record); |
| 614 | Writer.AddNestedNameSpecifier(D->getTargetNestedNameSpecifier(), Record); |
| 615 | Code = pch::DECL_UNRESOLVED_USING_VALUE; |
| 616 | } |
| 617 | |
| 618 | void PCHDeclWriter::VisitUnresolvedUsingTypename( |
| 619 | UnresolvedUsingTypenameDecl *D) { |
| 620 | VisitTypeDecl(D); |
| 621 | Writer.AddSourceRange(D->getTargetNestedNameRange(), Record); |
| 622 | Writer.AddSourceLocation(D->getUsingLoc(), Record); |
| 623 | Writer.AddSourceLocation(D->getTypenameLoc(), Record); |
| 624 | Writer.AddNestedNameSpecifier(D->getTargetNestedNameSpecifier(), Record); |
| 625 | Code = pch::DECL_UNRESOLVED_USING_TYPENAME; |
| 626 | } |
| 627 | |
John McCall | 5250f27 | 2010-06-03 19:28:45 +0000 | [diff] [blame] | 628 | void PCHDeclWriter::WriteCXXBaseSpecifier(const CXXBaseSpecifier *Base) { |
| 629 | Record.push_back(Base->isVirtual()); |
| 630 | Record.push_back(Base->isBaseOfClass()); |
| 631 | Record.push_back(Base->getAccessSpecifierAsWritten()); |
| 632 | Writer.AddTypeRef(Base->getType(), Record); |
| 633 | Writer.AddSourceRange(Base->getSourceRange(), Record); |
| 634 | } |
| 635 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 636 | void PCHDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) { |
| 637 | // assert(false && "cannot write CXXRecordDecl"); |
| 638 | VisitRecordDecl(D); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 639 | |
| 640 | enum { |
| 641 | CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization |
| 642 | }; |
| 643 | if (ClassTemplateDecl *TemplD = D->getDescribedClassTemplate()) { |
| 644 | Record.push_back(CXXRecTemplate); |
| 645 | Writer.AddDeclRef(TemplD, Record); |
| 646 | } else if (MemberSpecializationInfo *MSInfo |
| 647 | = D->getMemberSpecializationInfo()) { |
| 648 | Record.push_back(CXXRecMemberSpecialization); |
| 649 | Writer.AddDeclRef(MSInfo->getInstantiatedFrom(), Record); |
| 650 | Record.push_back(MSInfo->getTemplateSpecializationKind()); |
| 651 | Writer.AddSourceLocation(MSInfo->getPointOfInstantiation(), Record); |
| 652 | } else { |
| 653 | Record.push_back(CXXRecNotTemplate); |
| 654 | } |
| 655 | |
Argyrios Kyrtzidis | 28d16d7 | 2010-06-19 19:29:21 +0000 | [diff] [blame] | 656 | // FIXME: Hack. See PCHDeclWriter::VisitTypeDecl. |
| 657 | Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record); |
| 658 | |
John McCall | 5250f27 | 2010-06-03 19:28:45 +0000 | [diff] [blame] | 659 | if (D->isDefinition()) { |
| 660 | unsigned NumBases = D->getNumBases(); |
| 661 | Record.push_back(NumBases); |
| 662 | for (CXXRecordDecl::base_class_iterator I = D->bases_begin(), |
| 663 | E = D->bases_end(); I != E; ++I) |
| 664 | WriteCXXBaseSpecifier(&*I); |
| 665 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 666 | Code = pch::DECL_CXX_RECORD; |
| 667 | } |
| 668 | |
| 669 | void PCHDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
| 670 | // assert(false && "cannot write CXXMethodDecl"); |
| 671 | VisitFunctionDecl(D); |
| 672 | Code = pch::DECL_CXX_METHOD; |
| 673 | } |
| 674 | |
| 675 | void PCHDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
| 676 | // assert(false && "cannot write CXXConstructorDecl"); |
| 677 | VisitCXXMethodDecl(D); |
| 678 | Code = pch::DECL_CXX_CONSTRUCTOR; |
| 679 | } |
| 680 | |
| 681 | void PCHDeclWriter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
| 682 | // assert(false && "cannot write CXXDestructorDecl"); |
| 683 | VisitCXXMethodDecl(D); |
| 684 | Code = pch::DECL_CXX_DESTRUCTOR; |
| 685 | } |
| 686 | |
| 687 | void PCHDeclWriter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
| 688 | // assert(false && "cannot write CXXConversionDecl"); |
| 689 | VisitCXXMethodDecl(D); |
| 690 | Code = pch::DECL_CXX_CONVERSION; |
| 691 | } |
| 692 | |
Abramo Bagnara | 6206d53 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 693 | void PCHDeclWriter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
| 694 | VisitDecl(D); |
| 695 | Writer.AddSourceLocation(D->getColonLoc(), Record); |
| 696 | Code = pch::DECL_ACCESS_SPEC; |
| 697 | } |
| 698 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 699 | void PCHDeclWriter::VisitFriendTemplateDecl(FriendTemplateDecl *D) { |
| 700 | assert(false && "cannot write FriendTemplateDecl"); |
| 701 | } |
| 702 | |
| 703 | void PCHDeclWriter::VisitTemplateDecl(TemplateDecl *D) { |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 704 | VisitNamedDecl(D); |
| 705 | |
| 706 | Writer.AddDeclRef(D->getTemplatedDecl(), Record); |
| 707 | { |
| 708 | // TemplateParams. |
| 709 | TemplateParameterList *TPL = D->getTemplateParameters(); |
| 710 | assert(TPL && "No TemplateParameters!"); |
| 711 | Writer.AddSourceLocation(TPL->getTemplateLoc(), Record); |
| 712 | Writer.AddSourceLocation(TPL->getLAngleLoc(), Record); |
| 713 | Writer.AddSourceLocation(TPL->getRAngleLoc(), Record); |
| 714 | Record.push_back(TPL->size()); |
| 715 | for (TemplateParameterList::iterator P = TPL->begin(), PEnd = TPL->end(); |
| 716 | P != PEnd; ++P) |
| 717 | Writer.AddDeclRef(*P, Record); |
| 718 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | void PCHDeclWriter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 722 | VisitTemplateDecl(D); |
| 723 | |
| 724 | Writer.AddDeclRef(D->getPreviousDeclaration(), Record); |
| 725 | if (D->getPreviousDeclaration() == 0) { |
| 726 | // This ClassTemplateDecl owns the CommonPtr; write it. |
| 727 | |
| 728 | typedef llvm::FoldingSet<ClassTemplateSpecializationDecl> CTSDSetTy; |
| 729 | CTSDSetTy &CTSDSet = D->getSpecializations(); |
| 730 | Record.push_back(CTSDSet.size()); |
| 731 | for (CTSDSetTy::iterator I=CTSDSet.begin(), E = CTSDSet.end(); I!=E; ++I) |
| 732 | Writer.AddDeclRef(&*I, Record); |
| 733 | |
| 734 | typedef llvm::FoldingSet<ClassTemplatePartialSpecializationDecl> CTPSDSetTy; |
| 735 | CTPSDSetTy &CTPSDSet = D->getPartialSpecializations(); |
| 736 | Record.push_back(CTPSDSet.size()); |
| 737 | for (CTPSDSetTy::iterator I=CTPSDSet.begin(), E = CTPSDSet.end(); I!=E; ++I) |
| 738 | Writer.AddDeclRef(&*I, Record); |
| 739 | |
| 740 | // InjectedClassNameType is computed, no need to write it. |
| 741 | |
| 742 | Writer.AddDeclRef(D->getInstantiatedFromMemberTemplate(), Record); |
| 743 | if (D->getInstantiatedFromMemberTemplate()) |
| 744 | Record.push_back(D->isMemberSpecialization()); |
| 745 | } |
| 746 | Code = pch::DECL_CLASS_TEMPLATE; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | void PCHDeclWriter::VisitClassTemplateSpecializationDecl( |
| 750 | ClassTemplateSpecializationDecl *D) { |
| 751 | assert(false && "cannot write ClassTemplateSpecializationDecl"); |
| 752 | } |
| 753 | |
| 754 | void PCHDeclWriter::VisitClassTemplatePartialSpecializationDecl( |
| 755 | ClassTemplatePartialSpecializationDecl *D) { |
| 756 | assert(false && "cannot write ClassTemplatePartialSpecializationDecl"); |
| 757 | } |
| 758 | |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 759 | void PCHDeclWriter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
| 760 | VisitTemplateDecl(D); |
| 761 | |
| 762 | Writer.AddDeclRef(D->getPreviousDeclaration(), Record); |
| 763 | if (D->getPreviousDeclaration() == 0) { |
| 764 | // This FunctionTemplateDecl owns the CommonPtr; write it. |
| 765 | |
| 766 | // FunctionTemplateSpecializationInfos are filled through the |
| 767 | // templated FunctionDecl's setFunctionTemplateSpecialization, no need to |
| 768 | // write them here. |
| 769 | |
| 770 | Writer.AddDeclRef(D->getInstantiatedFromMemberTemplate(), Record); |
| 771 | if (D->getInstantiatedFromMemberTemplate()) |
| 772 | Record.push_back(D->isMemberSpecialization()); |
| 773 | } |
| 774 | Code = pch::DECL_FUNCTION_TEMPLATE; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | void PCHDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 778 | VisitTypeDecl(D); |
| 779 | |
| 780 | Record.push_back(D->wasDeclaredWithTypename()); |
| 781 | Record.push_back(D->isParameterPack()); |
| 782 | Record.push_back(D->defaultArgumentWasInherited()); |
| 783 | Writer.AddTypeSourceInfo(D->getDefaultArgumentInfo(), Record); |
| 784 | |
| 785 | Code = pch::DECL_TEMPLATE_TYPE_PARM; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | void PCHDeclWriter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
| 789 | assert(false && "cannot write NonTypeTemplateParmDecl"); |
| 790 | } |
| 791 | |
| 792 | void PCHDeclWriter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 793 | assert(false && "cannot write TemplateTemplateParmDecl"); |
| 794 | } |
| 795 | |
| 796 | void PCHDeclWriter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 797 | assert(false && "cannot write StaticAssertDecl"); |
| 798 | } |
| 799 | |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 800 | /// \brief Emit the DeclContext part of a declaration context decl. |
| 801 | /// |
| 802 | /// \param LexicalOffset the offset at which the DECL_CONTEXT_LEXICAL |
| 803 | /// block for this declaration context is stored. May be 0 to indicate |
| 804 | /// that there are no declarations stored within this context. |
| 805 | /// |
| 806 | /// \param VisibleOffset the offset at which the DECL_CONTEXT_VISIBLE |
| 807 | /// block for this declaration context is stored. May be 0 to indicate |
| 808 | /// that there are no declarations visible from this context. Note |
| 809 | /// that this value will not be emitted for non-primary declaration |
| 810 | /// contexts. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 811 | void PCHDeclWriter::VisitDeclContext(DeclContext *DC, uint64_t LexicalOffset, |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 812 | uint64_t VisibleOffset) { |
| 813 | Record.push_back(LexicalOffset); |
| 814 | Record.push_back(VisibleOffset); |
| 815 | } |
| 816 | |
| 817 | |
| 818 | //===----------------------------------------------------------------------===// |
| 819 | // PCHWriter Implementation |
| 820 | //===----------------------------------------------------------------------===// |
| 821 | |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 822 | void PCHWriter::WriteDeclsBlockAbbrevs() { |
| 823 | using namespace llvm; |
| 824 | // Abbreviation for DECL_PARM_VAR. |
| 825 | BitCodeAbbrev *Abv = new BitCodeAbbrev(); |
| 826 | Abv->Add(BitCodeAbbrevOp(pch::DECL_PARM_VAR)); |
| 827 | |
| 828 | // Decl |
| 829 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
| 830 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext |
| 831 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location |
| 832 | Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl (!?) |
| 833 | Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs |
| 834 | Abv->Add(BitCodeAbbrevOp(0)); // isImplicit |
Douglas Gregor | e0762c9 | 2009-06-19 23:52:42 +0000 | [diff] [blame] | 835 | Abv->Add(BitCodeAbbrevOp(0)); // isUsed |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 836 | Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier |
Douglas Gregor | 7d1d49d | 2009-10-16 20:01:17 +0000 | [diff] [blame] | 837 | Abv->Add(BitCodeAbbrevOp(0)); // PCH level |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 838 | |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 839 | // NamedDecl |
| 840 | Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier |
| 841 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
| 842 | // ValueDecl |
| 843 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 844 | // DeclaratorDecl |
| 845 | Abv->Add(BitCodeAbbrevOp(pch::PREDEF_TYPE_NULL_ID)); // InfoType |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 846 | // VarDecl |
| 847 | Abv->Add(BitCodeAbbrevOp(0)); // StorageClass |
Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 848 | Abv->Add(BitCodeAbbrevOp(0)); // StorageClassAsWritten |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 849 | Abv->Add(BitCodeAbbrevOp(0)); // isThreadSpecified |
| 850 | Abv->Add(BitCodeAbbrevOp(0)); // hasCXXDirectInitializer |
| 851 | Abv->Add(BitCodeAbbrevOp(0)); // isDeclaredInCondition |
Douglas Gregor | 324b54d | 2010-05-03 18:51:14 +0000 | [diff] [blame] | 852 | Abv->Add(BitCodeAbbrevOp(0)); // isExceptionVariable |
Douglas Gregor | 5077c38 | 2010-05-15 06:01:05 +0000 | [diff] [blame] | 853 | Abv->Add(BitCodeAbbrevOp(0)); // isNRVOVariable |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 854 | Abv->Add(BitCodeAbbrevOp(0)); // PrevDecl |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 855 | Abv->Add(BitCodeAbbrevOp(0)); // HasInit |
| 856 | // ParmVarDecl |
| 857 | Abv->Add(BitCodeAbbrevOp(0)); // ObjCDeclQualifier |
John McCall | bf73b35 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 858 | Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedDefaultArg |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 859 | |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 860 | ParmVarDeclAbbrev = Stream.EmitAbbrev(Abv); |
| 861 | } |
| 862 | |
Daniel Dunbar | e24d38f | 2009-09-17 03:06:51 +0000 | [diff] [blame] | 863 | /// isRequiredDecl - Check if this is a "required" Decl, which must be seen by |
| 864 | /// consumers of the AST. |
| 865 | /// |
| 866 | /// Such decls will always be deserialized from the PCH file, so we would like |
| 867 | /// this to be as restrictive as possible. Currently the predicate is driven by |
| 868 | /// code generation requirements, if other clients have a different notion of |
| 869 | /// what is "required" then we may have to consider an alternate scheme where |
| 870 | /// clients can iterate over the top-level decls and get information on them, |
| 871 | /// without necessary deserializing them. We could explicitly require such |
| 872 | /// clients to use a separate API call to "realize" the decl. This should be |
| 873 | /// relatively painless since they would presumably only do it for top-level |
| 874 | /// decls. |
| 875 | // |
| 876 | // FIXME: This predicate is essentially IRgen's predicate to determine whether a |
| 877 | // declaration can be deferred. Merge them somehow. |
| 878 | static bool isRequiredDecl(const Decl *D, ASTContext &Context) { |
| 879 | // File scoped assembly must be seen. |
| 880 | if (isa<FileScopeAsmDecl>(D)) |
| 881 | return true; |
| 882 | |
| 883 | // Otherwise if this isn't a function or a file scoped variable it doesn't |
| 884 | // need to be seen. |
| 885 | if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { |
| 886 | if (!VD->isFileVarDecl()) |
| 887 | return false; |
| 888 | } else if (!isa<FunctionDecl>(D)) |
| 889 | return false; |
| 890 | |
| 891 | // Aliases and used decls must be seen. |
| 892 | if (D->hasAttr<AliasAttr>() || D->hasAttr<UsedAttr>()) |
| 893 | return true; |
| 894 | |
| 895 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
| 896 | // Forward declarations don't need to be seen. |
| 897 | if (!FD->isThisDeclarationADefinition()) |
| 898 | return false; |
| 899 | |
| 900 | // Constructors and destructors must be seen. |
| 901 | if (FD->hasAttr<ConstructorAttr>() || FD->hasAttr<DestructorAttr>()) |
| 902 | return true; |
| 903 | |
| 904 | // Otherwise, this is required unless it is static. |
| 905 | // |
| 906 | // FIXME: Inlines. |
| 907 | return FD->getStorageClass() != FunctionDecl::Static; |
| 908 | } else { |
| 909 | const VarDecl *VD = cast<VarDecl>(D); |
| 910 | |
| 911 | // In C++, this doesn't need to be seen if it is marked "extern". |
| 912 | if (Context.getLangOptions().CPlusPlus && !VD->getInit() && |
| 913 | (VD->getStorageClass() == VarDecl::Extern || |
| 914 | VD->isExternC())) |
| 915 | return false; |
| 916 | |
| 917 | // In C, this doesn't need to be seen unless it is a definition. |
| 918 | if (!Context.getLangOptions().CPlusPlus && !VD->getInit()) |
| 919 | return false; |
| 920 | |
| 921 | // Otherwise, this is required unless it is static. |
| 922 | return VD->getStorageClass() != VarDecl::Static; |
| 923 | } |
| 924 | } |
| 925 | |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 926 | void PCHWriter::WriteDecl(ASTContext &Context, Decl *D) { |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 927 | RecordData Record; |
| 928 | PCHDeclWriter W(*this, Context, Record); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 929 | |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 930 | // If this declaration is also a DeclContext, write blocks for the |
| 931 | // declarations that lexically stored inside its context and those |
| 932 | // declarations that are visible from its context. These blocks |
| 933 | // are written before the declaration itself so that we can put |
| 934 | // their offsets into the record for the declaration. |
| 935 | uint64_t LexicalOffset = 0; |
| 936 | uint64_t VisibleOffset = 0; |
| 937 | DeclContext *DC = dyn_cast<DeclContext>(D); |
| 938 | if (DC) { |
| 939 | LexicalOffset = WriteDeclContextLexicalBlock(Context, DC); |
| 940 | VisibleOffset = WriteDeclContextVisibleBlock(Context, DC); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 941 | } |
| 942 | |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 943 | // Determine the ID for this declaration |
| 944 | pch::DeclID &ID = DeclIDs[D]; |
| 945 | if (ID == 0) |
| 946 | ID = DeclIDs.size(); |
| 947 | |
| 948 | unsigned Index = ID - 1; |
| 949 | |
| 950 | // Record the offset for this declaration |
| 951 | if (DeclOffsets.size() == Index) |
| 952 | DeclOffsets.push_back(Stream.GetCurrentBitNo()); |
| 953 | else if (DeclOffsets.size() < Index) { |
| 954 | DeclOffsets.resize(Index+1); |
| 955 | DeclOffsets[Index] = Stream.GetCurrentBitNo(); |
| 956 | } |
| 957 | |
| 958 | // Build and emit a record for this declaration |
| 959 | Record.clear(); |
| 960 | W.Code = (pch::DeclCode)0; |
| 961 | W.AbbrevToUse = 0; |
| 962 | W.Visit(D); |
| 963 | if (DC) W.VisitDeclContext(DC, LexicalOffset, VisibleOffset); |
| 964 | |
Daniel Dunbar | 3367198 | 2009-12-03 09:13:36 +0000 | [diff] [blame] | 965 | if (!W.Code) |
Chris Lattner | 83e7a78 | 2010-04-07 22:58:06 +0000 | [diff] [blame] | 966 | llvm::report_fatal_error(llvm::StringRef("unexpected declaration kind '") + |
Daniel Dunbar | 3367198 | 2009-12-03 09:13:36 +0000 | [diff] [blame] | 967 | D->getDeclKindName() + "'"); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 968 | Stream.EmitRecord(W.Code, Record, W.AbbrevToUse); |
| 969 | |
| 970 | // If the declaration had any attributes, write them now. |
| 971 | if (D->hasAttrs()) |
| 972 | WriteAttributeRecord(D->getAttrs()); |
| 973 | |
| 974 | // Flush any expressions that were written as part of this declaration. |
| 975 | FlushStmts(); |
| 976 | |
| 977 | // Note "external" declarations so that we can add them to a record in the |
| 978 | // PCH file later. |
| 979 | // |
| 980 | // FIXME: This should be renamed, the predicate is much more complicated. |
| 981 | if (isRequiredDecl(D, Context)) |
| 982 | ExternalDefinitions.push_back(Index + 1); |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 983 | } |