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