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