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