1 //===--- ASTWriterDecl.cpp - Declaration Serialization --------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file implements serialization for Declarations. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "ASTCommon.h" 14 #include "clang/AST/Attr.h" 15 #include "clang/AST/DeclCXX.h" 16 #include "clang/AST/DeclContextInternals.h" 17 #include "clang/AST/DeclTemplate.h" 18 #include "clang/AST/DeclVisitor.h" 19 #include "clang/AST/Expr.h" 20 #include "clang/AST/OpenMPClause.h" 21 #include "clang/AST/PrettyDeclStackTrace.h" 22 #include "clang/Basic/SourceManager.h" 23 #include "clang/Serialization/ASTReader.h" 24 #include "clang/Serialization/ASTRecordWriter.h" 25 #include "llvm/Bitstream/BitstreamWriter.h" 26 #include "llvm/Support/ErrorHandling.h" 27 using namespace clang; 28 using namespace serialization; 29 30 //===----------------------------------------------------------------------===// 31 // Declaration serialization 32 //===----------------------------------------------------------------------===// 33 34 namespace clang { 35 class ASTDeclWriter : public DeclVisitor<ASTDeclWriter, void> { 36 ASTWriter &Writer; 37 ASTContext &Context; 38 ASTRecordWriter Record; 39 40 serialization::DeclCode Code; 41 unsigned AbbrevToUse; 42 43 public: 44 ASTDeclWriter(ASTWriter &Writer, ASTContext &Context, 45 ASTWriter::RecordDataImpl &Record) 46 : Writer(Writer), Context(Context), Record(Writer, Record), 47 Code((serialization::DeclCode)0), AbbrevToUse(0) {} 48 49 uint64_t Emit(Decl *D) { 50 if (!Code) 51 llvm::report_fatal_error(StringRef("unexpected declaration kind '") + 52 D->getDeclKindName() + "'"); 53 return Record.Emit(Code, AbbrevToUse); 54 } 55 56 void Visit(Decl *D); 57 58 void VisitDecl(Decl *D); 59 void VisitPragmaCommentDecl(PragmaCommentDecl *D); 60 void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D); 61 void VisitTranslationUnitDecl(TranslationUnitDecl *D); 62 void VisitNamedDecl(NamedDecl *D); 63 void VisitLabelDecl(LabelDecl *LD); 64 void VisitNamespaceDecl(NamespaceDecl *D); 65 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D); 66 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D); 67 void VisitTypeDecl(TypeDecl *D); 68 void VisitTypedefNameDecl(TypedefNameDecl *D); 69 void VisitTypedefDecl(TypedefDecl *D); 70 void VisitTypeAliasDecl(TypeAliasDecl *D); 71 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); 72 void VisitTagDecl(TagDecl *D); 73 void VisitEnumDecl(EnumDecl *D); 74 void VisitRecordDecl(RecordDecl *D); 75 void VisitCXXRecordDecl(CXXRecordDecl *D); 76 void VisitClassTemplateSpecializationDecl( 77 ClassTemplateSpecializationDecl *D); 78 void VisitClassTemplatePartialSpecializationDecl( 79 ClassTemplatePartialSpecializationDecl *D); 80 void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); 81 void VisitVarTemplatePartialSpecializationDecl( 82 VarTemplatePartialSpecializationDecl *D); 83 void VisitClassScopeFunctionSpecializationDecl( 84 ClassScopeFunctionSpecializationDecl *D); 85 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); 86 void VisitValueDecl(ValueDecl *D); 87 void VisitEnumConstantDecl(EnumConstantDecl *D); 88 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); 89 void VisitDeclaratorDecl(DeclaratorDecl *D); 90 void VisitFunctionDecl(FunctionDecl *D); 91 void VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D); 92 void VisitCXXMethodDecl(CXXMethodDecl *D); 93 void VisitCXXConstructorDecl(CXXConstructorDecl *D); 94 void VisitCXXDestructorDecl(CXXDestructorDecl *D); 95 void VisitCXXConversionDecl(CXXConversionDecl *D); 96 void VisitFieldDecl(FieldDecl *D); 97 void VisitMSPropertyDecl(MSPropertyDecl *D); 98 void VisitMSGuidDecl(MSGuidDecl *D); 99 void VisitTemplateParamObjectDecl(TemplateParamObjectDecl *D); 100 void VisitIndirectFieldDecl(IndirectFieldDecl *D); 101 void VisitVarDecl(VarDecl *D); 102 void VisitImplicitParamDecl(ImplicitParamDecl *D); 103 void VisitParmVarDecl(ParmVarDecl *D); 104 void VisitDecompositionDecl(DecompositionDecl *D); 105 void VisitBindingDecl(BindingDecl *D); 106 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); 107 void VisitTemplateDecl(TemplateDecl *D); 108 void VisitConceptDecl(ConceptDecl *D); 109 void VisitRequiresExprBodyDecl(RequiresExprBodyDecl *D); 110 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D); 111 void VisitClassTemplateDecl(ClassTemplateDecl *D); 112 void VisitVarTemplateDecl(VarTemplateDecl *D); 113 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D); 114 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); 115 void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); 116 void VisitUsingDecl(UsingDecl *D); 117 void VisitUsingPackDecl(UsingPackDecl *D); 118 void VisitUsingShadowDecl(UsingShadowDecl *D); 119 void VisitConstructorUsingShadowDecl(ConstructorUsingShadowDecl *D); 120 void VisitLinkageSpecDecl(LinkageSpecDecl *D); 121 void VisitExportDecl(ExportDecl *D); 122 void VisitFileScopeAsmDecl(FileScopeAsmDecl *D); 123 void VisitImportDecl(ImportDecl *D); 124 void VisitAccessSpecDecl(AccessSpecDecl *D); 125 void VisitFriendDecl(FriendDecl *D); 126 void VisitFriendTemplateDecl(FriendTemplateDecl *D); 127 void VisitStaticAssertDecl(StaticAssertDecl *D); 128 void VisitBlockDecl(BlockDecl *D); 129 void VisitCapturedDecl(CapturedDecl *D); 130 void VisitEmptyDecl(EmptyDecl *D); 131 void VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D); 132 133 void VisitDeclContext(DeclContext *DC); 134 template <typename T> void VisitRedeclarable(Redeclarable<T> *D); 135 136 137 // FIXME: Put in the same order is DeclNodes.td? 138 void VisitObjCMethodDecl(ObjCMethodDecl *D); 139 void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); 140 void VisitObjCContainerDecl(ObjCContainerDecl *D); 141 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); 142 void VisitObjCIvarDecl(ObjCIvarDecl *D); 143 void VisitObjCProtocolDecl(ObjCProtocolDecl *D); 144 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D); 145 void VisitObjCCategoryDecl(ObjCCategoryDecl *D); 146 void VisitObjCImplDecl(ObjCImplDecl *D); 147 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); 148 void VisitObjCImplementationDecl(ObjCImplementationDecl *D); 149 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D); 150 void VisitObjCPropertyDecl(ObjCPropertyDecl *D); 151 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); 152 void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D); 153 void VisitOMPAllocateDecl(OMPAllocateDecl *D); 154 void VisitOMPRequiresDecl(OMPRequiresDecl *D); 155 void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D); 156 void VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D); 157 void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D); 158 159 /// Add an Objective-C type parameter list to the given record. 160 void AddObjCTypeParamList(ObjCTypeParamList *typeParams) { 161 // Empty type parameter list. 162 if (!typeParams) { 163 Record.push_back(0); 164 return; 165 } 166 167 Record.push_back(typeParams->size()); 168 for (auto typeParam : *typeParams) { 169 Record.AddDeclRef(typeParam); 170 } 171 Record.AddSourceLocation(typeParams->getLAngleLoc()); 172 Record.AddSourceLocation(typeParams->getRAngleLoc()); 173 } 174 175 /// Add to the record the first declaration from each module file that 176 /// provides a declaration of D. The intent is to provide a sufficient 177 /// set such that reloading this set will load all current redeclarations. 178 void AddFirstDeclFromEachModule(const Decl *D, bool IncludeLocal) { 179 llvm::MapVector<ModuleFile*, const Decl*> Firsts; 180 // FIXME: We can skip entries that we know are implied by others. 181 for (const Decl *R = D->getMostRecentDecl(); R; R = R->getPreviousDecl()) { 182 if (R->isFromASTFile()) 183 Firsts[Writer.Chain->getOwningModuleFile(R)] = R; 184 else if (IncludeLocal) 185 Firsts[nullptr] = R; 186 } 187 for (const auto &F : Firsts) 188 Record.AddDeclRef(F.second); 189 } 190 191 /// Get the specialization decl from an entry in the specialization list. 192 template <typename EntryType> 193 typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType * 194 getSpecializationDecl(EntryType &T) { 195 return RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::getDecl(&T); 196 } 197 198 /// Get the list of partial specializations from a template's common ptr. 199 template<typename T> 200 decltype(T::PartialSpecializations) &getPartialSpecializations(T *Common) { 201 return Common->PartialSpecializations; 202 } 203 ArrayRef<Decl> getPartialSpecializations(FunctionTemplateDecl::Common *) { 204 return None; 205 } 206 207 template<typename DeclTy> 208 void AddTemplateSpecializations(DeclTy *D) { 209 auto *Common = D->getCommonPtr(); 210 211 // If we have any lazy specializations, and the external AST source is 212 // our chained AST reader, we can just write out the DeclIDs. Otherwise, 213 // we need to resolve them to actual declarations. 214 if (Writer.Chain != Writer.Context->getExternalSource() && 215 Common->LazySpecializations) { 216 D->LoadLazySpecializations(); 217 assert(!Common->LazySpecializations); 218 } 219 220 ArrayRef<DeclID> LazySpecializations; 221 if (auto *LS = Common->LazySpecializations) 222 LazySpecializations = llvm::makeArrayRef(LS + 1, LS[0]); 223 224 // Add a slot to the record for the number of specializations. 225 unsigned I = Record.size(); 226 Record.push_back(0); 227 228 // AddFirstDeclFromEachModule might trigger deserialization, invalidating 229 // *Specializations iterators. 230 llvm::SmallVector<const Decl*, 16> Specs; 231 for (auto &Entry : Common->Specializations) 232 Specs.push_back(getSpecializationDecl(Entry)); 233 for (auto &Entry : getPartialSpecializations(Common)) 234 Specs.push_back(getSpecializationDecl(Entry)); 235 236 for (auto *D : Specs) { 237 assert(D->isCanonicalDecl() && "non-canonical decl in set"); 238 AddFirstDeclFromEachModule(D, /*IncludeLocal*/true); 239 } 240 Record.append(LazySpecializations.begin(), LazySpecializations.end()); 241 242 // Update the size entry we added earlier. 243 Record[I] = Record.size() - I - 1; 244 } 245 246 /// Ensure that this template specialization is associated with the specified 247 /// template on reload. 248 void RegisterTemplateSpecialization(const Decl *Template, 249 const Decl *Specialization) { 250 Template = Template->getCanonicalDecl(); 251 252 // If the canonical template is local, we'll write out this specialization 253 // when we emit it. 254 // FIXME: We can do the same thing if there is any local declaration of 255 // the template, to avoid emitting an update record. 256 if (!Template->isFromASTFile()) 257 return; 258 259 // We only need to associate the first local declaration of the 260 // specialization. The other declarations will get pulled in by it. 261 if (Writer.getFirstLocalDecl(Specialization) != Specialization) 262 return; 263 264 Writer.DeclUpdates[Template].push_back(ASTWriter::DeclUpdate( 265 UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION, Specialization)); 266 } 267 }; 268 } 269 270 void ASTDeclWriter::Visit(Decl *D) { 271 DeclVisitor<ASTDeclWriter>::Visit(D); 272 273 // Source locations require array (variable-length) abbreviations. The 274 // abbreviation infrastructure requires that arrays are encoded last, so 275 // we handle it here in the case of those classes derived from DeclaratorDecl 276 if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) { 277 if (auto *TInfo = DD->getTypeSourceInfo()) 278 Record.AddTypeLoc(TInfo->getTypeLoc()); 279 } 280 281 // Handle FunctionDecl's body here and write it after all other Stmts/Exprs 282 // have been written. We want it last because we will not read it back when 283 // retrieving it from the AST, we'll just lazily set the offset. 284 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 285 Record.push_back(FD->doesThisDeclarationHaveABody()); 286 if (FD->doesThisDeclarationHaveABody()) 287 Record.AddFunctionDefinition(FD); 288 } 289 290 // If this declaration is also a DeclContext, write blocks for the 291 // declarations that lexically stored inside its context and those 292 // declarations that are visible from its context. 293 if (DeclContext *DC = dyn_cast<DeclContext>(D)) 294 VisitDeclContext(DC); 295 } 296 297 void ASTDeclWriter::VisitDecl(Decl *D) { 298 Record.AddDeclRef(cast_or_null<Decl>(D->getDeclContext())); 299 if (D->getDeclContext() != D->getLexicalDeclContext()) 300 Record.AddDeclRef(cast_or_null<Decl>(D->getLexicalDeclContext())); 301 else 302 Record.push_back(0); 303 Record.push_back(D->isInvalidDecl()); 304 Record.push_back(D->hasAttrs()); 305 if (D->hasAttrs()) 306 Record.AddAttributes(D->getAttrs()); 307 Record.push_back(D->isImplicit()); 308 Record.push_back(D->isUsed(false)); 309 Record.push_back(D->isReferenced()); 310 Record.push_back(D->isTopLevelDeclInObjCContainer()); 311 Record.push_back(D->getAccess()); 312 Record.push_back(D->isModulePrivate()); 313 Record.push_back(Writer.getSubmoduleID(D->getOwningModule())); 314 315 // If this declaration injected a name into a context different from its 316 // lexical context, and that context is an imported namespace, we need to 317 // update its visible declarations to include this name. 318 // 319 // This happens when we instantiate a class with a friend declaration or a 320 // function with a local extern declaration, for instance. 321 // 322 // FIXME: Can we handle this in AddedVisibleDecl instead? 323 if (D->isOutOfLine()) { 324 auto *DC = D->getDeclContext(); 325 while (auto *NS = dyn_cast<NamespaceDecl>(DC->getRedeclContext())) { 326 if (!NS->isFromASTFile()) 327 break; 328 Writer.UpdatedDeclContexts.insert(NS->getPrimaryContext()); 329 if (!NS->isInlineNamespace()) 330 break; 331 DC = NS->getParent(); 332 } 333 } 334 } 335 336 void ASTDeclWriter::VisitPragmaCommentDecl(PragmaCommentDecl *D) { 337 StringRef Arg = D->getArg(); 338 Record.push_back(Arg.size()); 339 VisitDecl(D); 340 Record.AddSourceLocation(D->getBeginLoc()); 341 Record.push_back(D->getCommentKind()); 342 Record.AddString(Arg); 343 Code = serialization::DECL_PRAGMA_COMMENT; 344 } 345 346 void ASTDeclWriter::VisitPragmaDetectMismatchDecl( 347 PragmaDetectMismatchDecl *D) { 348 StringRef Name = D->getName(); 349 StringRef Value = D->getValue(); 350 Record.push_back(Name.size() + 1 + Value.size()); 351 VisitDecl(D); 352 Record.AddSourceLocation(D->getBeginLoc()); 353 Record.AddString(Name); 354 Record.AddString(Value); 355 Code = serialization::DECL_PRAGMA_DETECT_MISMATCH; 356 } 357 358 void ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { 359 llvm_unreachable("Translation units aren't directly serialized"); 360 } 361 362 void ASTDeclWriter::VisitNamedDecl(NamedDecl *D) { 363 VisitDecl(D); 364 Record.AddDeclarationName(D->getDeclName()); 365 Record.push_back(needsAnonymousDeclarationNumber(D) 366 ? Writer.getAnonymousDeclarationNumber(D) 367 : 0); 368 } 369 370 void ASTDeclWriter::VisitTypeDecl(TypeDecl *D) { 371 VisitNamedDecl(D); 372 Record.AddSourceLocation(D->getBeginLoc()); 373 Record.AddTypeRef(QualType(D->getTypeForDecl(), 0)); 374 } 375 376 void ASTDeclWriter::VisitTypedefNameDecl(TypedefNameDecl *D) { 377 VisitRedeclarable(D); 378 VisitTypeDecl(D); 379 Record.AddTypeSourceInfo(D->getTypeSourceInfo()); 380 Record.push_back(D->isModed()); 381 if (D->isModed()) 382 Record.AddTypeRef(D->getUnderlyingType()); 383 Record.AddDeclRef(D->getAnonDeclWithTypedefName(false)); 384 } 385 386 void ASTDeclWriter::VisitTypedefDecl(TypedefDecl *D) { 387 VisitTypedefNameDecl(D); 388 if (D->getDeclContext() == D->getLexicalDeclContext() && 389 !D->hasAttrs() && 390 !D->isImplicit() && 391 D->getFirstDecl() == D->getMostRecentDecl() && 392 !D->isInvalidDecl() && 393 !D->isTopLevelDeclInObjCContainer() && 394 !D->isModulePrivate() && 395 !needsAnonymousDeclarationNumber(D) && 396 D->getDeclName().getNameKind() == DeclarationName::Identifier) 397 AbbrevToUse = Writer.getDeclTypedefAbbrev(); 398 399 Code = serialization::DECL_TYPEDEF; 400 } 401 402 void ASTDeclWriter::VisitTypeAliasDecl(TypeAliasDecl *D) { 403 VisitTypedefNameDecl(D); 404 Record.AddDeclRef(D->getDescribedAliasTemplate()); 405 Code = serialization::DECL_TYPEALIAS; 406 } 407 408 void ASTDeclWriter::VisitTagDecl(TagDecl *D) { 409 VisitRedeclarable(D); 410 VisitTypeDecl(D); 411 Record.push_back(D->getIdentifierNamespace()); 412 Record.push_back((unsigned)D->getTagKind()); // FIXME: stable encoding 413 if (!isa<CXXRecordDecl>(D)) 414 Record.push_back(D->isCompleteDefinition()); 415 Record.push_back(D->isEmbeddedInDeclarator()); 416 Record.push_back(D->isFreeStanding()); 417 Record.push_back(D->isCompleteDefinitionRequired()); 418 Record.AddSourceRange(D->getBraceRange()); 419 420 if (D->hasExtInfo()) { 421 Record.push_back(1); 422 Record.AddQualifierInfo(*D->getExtInfo()); 423 } else if (auto *TD = D->getTypedefNameForAnonDecl()) { 424 Record.push_back(2); 425 Record.AddDeclRef(TD); 426 Record.AddIdentifierRef(TD->getDeclName().getAsIdentifierInfo()); 427 } else { 428 Record.push_back(0); 429 } 430 } 431 432 void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) { 433 VisitTagDecl(D); 434 Record.AddTypeSourceInfo(D->getIntegerTypeSourceInfo()); 435 if (!D->getIntegerTypeSourceInfo()) 436 Record.AddTypeRef(D->getIntegerType()); 437 Record.AddTypeRef(D->getPromotionType()); 438 Record.push_back(D->getNumPositiveBits()); 439 Record.push_back(D->getNumNegativeBits()); 440 Record.push_back(D->isScoped()); 441 Record.push_back(D->isScopedUsingClassTag()); 442 Record.push_back(D->isFixed()); 443 Record.push_back(D->getODRHash()); 444 445 if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) { 446 Record.AddDeclRef(MemberInfo->getInstantiatedFrom()); 447 Record.push_back(MemberInfo->getTemplateSpecializationKind()); 448 Record.AddSourceLocation(MemberInfo->getPointOfInstantiation()); 449 } else { 450 Record.AddDeclRef(nullptr); 451 } 452 453 if (D->getDeclContext() == D->getLexicalDeclContext() && 454 !D->hasAttrs() && 455 !D->isImplicit() && 456 !D->isUsed(false) && 457 !D->hasExtInfo() && 458 !D->getTypedefNameForAnonDecl() && 459 D->getFirstDecl() == D->getMostRecentDecl() && 460 !D->isInvalidDecl() && 461 !D->isReferenced() && 462 !D->isTopLevelDeclInObjCContainer() && 463 D->getAccess() == AS_none && 464 !D->isModulePrivate() && 465 !CXXRecordDecl::classofKind(D->getKind()) && 466 !D->getIntegerTypeSourceInfo() && 467 !D->getMemberSpecializationInfo() && 468 !needsAnonymousDeclarationNumber(D) && 469 D->getDeclName().getNameKind() == DeclarationName::Identifier) 470 AbbrevToUse = Writer.getDeclEnumAbbrev(); 471 472 Code = serialization::DECL_ENUM; 473 } 474 475 void ASTDeclWriter::VisitRecordDecl(RecordDecl *D) { 476 VisitTagDecl(D); 477 Record.push_back(D->hasFlexibleArrayMember()); 478 Record.push_back(D->isAnonymousStructOrUnion()); 479 Record.push_back(D->hasObjectMember()); 480 Record.push_back(D->hasVolatileMember()); 481 Record.push_back(D->isNonTrivialToPrimitiveDefaultInitialize()); 482 Record.push_back(D->isNonTrivialToPrimitiveCopy()); 483 Record.push_back(D->isNonTrivialToPrimitiveDestroy()); 484 Record.push_back(D->hasNonTrivialToPrimitiveDefaultInitializeCUnion()); 485 Record.push_back(D->hasNonTrivialToPrimitiveDestructCUnion()); 486 Record.push_back(D->hasNonTrivialToPrimitiveCopyCUnion()); 487 Record.push_back(D->isParamDestroyedInCallee()); 488 Record.push_back(D->getArgPassingRestrictions()); 489 490 if (D->getDeclContext() == D->getLexicalDeclContext() && 491 !D->hasAttrs() && 492 !D->isImplicit() && 493 !D->isUsed(false) && 494 !D->hasExtInfo() && 495 !D->getTypedefNameForAnonDecl() && 496 D->getFirstDecl() == D->getMostRecentDecl() && 497 !D->isInvalidDecl() && 498 !D->isReferenced() && 499 !D->isTopLevelDeclInObjCContainer() && 500 D->getAccess() == AS_none && 501 !D->isModulePrivate() && 502 !CXXRecordDecl::classofKind(D->getKind()) && 503 !needsAnonymousDeclarationNumber(D) && 504 D->getDeclName().getNameKind() == DeclarationName::Identifier) 505 AbbrevToUse = Writer.getDeclRecordAbbrev(); 506 507 Code = serialization::DECL_RECORD; 508 } 509 510 void ASTDeclWriter::VisitValueDecl(ValueDecl *D) { 511 VisitNamedDecl(D); 512 Record.AddTypeRef(D->getType()); 513 } 514 515 void ASTDeclWriter::VisitEnumConstantDecl(EnumConstantDecl *D) { 516 VisitValueDecl(D); 517 Record.push_back(D->getInitExpr()? 1 : 0); 518 if (D->getInitExpr()) 519 Record.AddStmt(D->getInitExpr()); 520 Record.AddAPSInt(D->getInitVal()); 521 522 Code = serialization::DECL_ENUM_CONSTANT; 523 } 524 525 void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) { 526 VisitValueDecl(D); 527 Record.AddSourceLocation(D->getInnerLocStart()); 528 Record.push_back(D->hasExtInfo()); 529 if (D->hasExtInfo()) { 530 DeclaratorDecl::ExtInfo *Info = D->getExtInfo(); 531 Record.AddQualifierInfo(*Info); 532 Record.AddStmt(Info->TrailingRequiresClause); 533 } 534 // The location information is deferred until the end of the record. 535 Record.AddTypeRef(D->getTypeSourceInfo() ? D->getTypeSourceInfo()->getType() 536 : QualType()); 537 } 538 539 void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) { 540 VisitRedeclarable(D); 541 VisitDeclaratorDecl(D); 542 Record.AddDeclarationNameLoc(D->DNLoc, D->getDeclName()); 543 Record.push_back(D->getIdentifierNamespace()); 544 545 // FunctionDecl's body is handled last at ASTWriterDecl::Visit, 546 // after everything else is written. 547 Record.push_back(static_cast<int>(D->getStorageClass())); // FIXME: stable encoding 548 Record.push_back(D->isInlineSpecified()); 549 Record.push_back(D->isInlined()); 550 Record.push_back(D->isVirtualAsWritten()); 551 Record.push_back(D->isPure()); 552 Record.push_back(D->hasInheritedPrototype()); 553 Record.push_back(D->hasWrittenPrototype()); 554 Record.push_back(D->isDeletedBit()); 555 Record.push_back(D->isTrivial()); 556 Record.push_back(D->isTrivialForCall()); 557 Record.push_back(D->isDefaulted()); 558 Record.push_back(D->isExplicitlyDefaulted()); 559 Record.push_back(D->hasImplicitReturnZero()); 560 Record.push_back(static_cast<uint64_t>(D->getConstexprKind())); 561 Record.push_back(D->usesSEHTry()); 562 Record.push_back(D->hasSkippedBody()); 563 Record.push_back(D->isMultiVersion()); 564 Record.push_back(D->isLateTemplateParsed()); 565 Record.push_back(D->getLinkageInternal()); 566 Record.AddSourceLocation(D->getEndLoc()); 567 568 Record.push_back(D->getODRHash()); 569 570 if (D->isDefaulted()) { 571 if (auto *FDI = D->getDefaultedFunctionInfo()) { 572 Record.push_back(FDI->getUnqualifiedLookups().size()); 573 for (DeclAccessPair P : FDI->getUnqualifiedLookups()) { 574 Record.AddDeclRef(P.getDecl()); 575 Record.push_back(P.getAccess()); 576 } 577 } else { 578 Record.push_back(0); 579 } 580 } 581 582 Record.push_back(D->getTemplatedKind()); 583 switch (D->getTemplatedKind()) { 584 case FunctionDecl::TK_NonTemplate: 585 break; 586 case FunctionDecl::TK_FunctionTemplate: 587 Record.AddDeclRef(D->getDescribedFunctionTemplate()); 588 break; 589 case FunctionDecl::TK_MemberSpecialization: { 590 MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo(); 591 Record.AddDeclRef(MemberInfo->getInstantiatedFrom()); 592 Record.push_back(MemberInfo->getTemplateSpecializationKind()); 593 Record.AddSourceLocation(MemberInfo->getPointOfInstantiation()); 594 break; 595 } 596 case FunctionDecl::TK_FunctionTemplateSpecialization: { 597 FunctionTemplateSpecializationInfo * 598 FTSInfo = D->getTemplateSpecializationInfo(); 599 600 RegisterTemplateSpecialization(FTSInfo->getTemplate(), D); 601 602 Record.AddDeclRef(FTSInfo->getTemplate()); 603 Record.push_back(FTSInfo->getTemplateSpecializationKind()); 604 605 // Template arguments. 606 Record.AddTemplateArgumentList(FTSInfo->TemplateArguments); 607 608 // Template args as written. 609 Record.push_back(FTSInfo->TemplateArgumentsAsWritten != nullptr); 610 if (FTSInfo->TemplateArgumentsAsWritten) { 611 Record.push_back(FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs); 612 for (int i=0, e = FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs; 613 i!=e; ++i) 614 Record.AddTemplateArgumentLoc( 615 (*FTSInfo->TemplateArgumentsAsWritten)[i]); 616 Record.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->LAngleLoc); 617 Record.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->RAngleLoc); 618 } 619 620 Record.AddSourceLocation(FTSInfo->getPointOfInstantiation()); 621 622 if (MemberSpecializationInfo *MemberInfo = 623 FTSInfo->getMemberSpecializationInfo()) { 624 Record.push_back(1); 625 Record.AddDeclRef(MemberInfo->getInstantiatedFrom()); 626 Record.push_back(MemberInfo->getTemplateSpecializationKind()); 627 Record.AddSourceLocation(MemberInfo->getPointOfInstantiation()); 628 } else { 629 Record.push_back(0); 630 } 631 632 if (D->isCanonicalDecl()) { 633 // Write the template that contains the specializations set. We will 634 // add a FunctionTemplateSpecializationInfo to it when reading. 635 Record.AddDeclRef(FTSInfo->getTemplate()->getCanonicalDecl()); 636 } 637 break; 638 } 639 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { 640 DependentFunctionTemplateSpecializationInfo * 641 DFTSInfo = D->getDependentSpecializationInfo(); 642 643 // Templates. 644 Record.push_back(DFTSInfo->getNumTemplates()); 645 for (int i=0, e = DFTSInfo->getNumTemplates(); i != e; ++i) 646 Record.AddDeclRef(DFTSInfo->getTemplate(i)); 647 648 // Templates args. 649 Record.push_back(DFTSInfo->getNumTemplateArgs()); 650 for (int i=0, e = DFTSInfo->getNumTemplateArgs(); i != e; ++i) 651 Record.AddTemplateArgumentLoc(DFTSInfo->getTemplateArg(i)); 652 Record.AddSourceLocation(DFTSInfo->getLAngleLoc()); 653 Record.AddSourceLocation(DFTSInfo->getRAngleLoc()); 654 break; 655 } 656 } 657 658 Record.push_back(D->param_size()); 659 for (auto P : D->parameters()) 660 Record.AddDeclRef(P); 661 Code = serialization::DECL_FUNCTION; 662 } 663 664 static void addExplicitSpecifier(ExplicitSpecifier ES, 665 ASTRecordWriter &Record) { 666 uint64_t Kind = static_cast<uint64_t>(ES.getKind()); 667 Kind = Kind << 1 | static_cast<bool>(ES.getExpr()); 668 Record.push_back(Kind); 669 if (ES.getExpr()) { 670 Record.AddStmt(ES.getExpr()); 671 } 672 } 673 674 void ASTDeclWriter::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) { 675 addExplicitSpecifier(D->getExplicitSpecifier(), Record); 676 VisitFunctionDecl(D); 677 Record.push_back(D->isCopyDeductionCandidate()); 678 Code = serialization::DECL_CXX_DEDUCTION_GUIDE; 679 } 680 681 void ASTDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) { 682 VisitNamedDecl(D); 683 // FIXME: convert to LazyStmtPtr? 684 // Unlike C/C++, method bodies will never be in header files. 685 bool HasBodyStuff = D->getBody() != nullptr; 686 Record.push_back(HasBodyStuff); 687 if (HasBodyStuff) { 688 Record.AddStmt(D->getBody()); 689 } 690 Record.AddDeclRef(D->getSelfDecl()); 691 Record.AddDeclRef(D->getCmdDecl()); 692 Record.push_back(D->isInstanceMethod()); 693 Record.push_back(D->isVariadic()); 694 Record.push_back(D->isPropertyAccessor()); 695 Record.push_back(D->isSynthesizedAccessorStub()); 696 Record.push_back(D->isDefined()); 697 Record.push_back(D->isOverriding()); 698 Record.push_back(D->hasSkippedBody()); 699 700 Record.push_back(D->isRedeclaration()); 701 Record.push_back(D->hasRedeclaration()); 702 if (D->hasRedeclaration()) { 703 assert(Context.getObjCMethodRedeclaration(D)); 704 Record.AddDeclRef(Context.getObjCMethodRedeclaration(D)); 705 } 706 707 // FIXME: stable encoding for @required/@optional 708 Record.push_back(D->getImplementationControl()); 709 // FIXME: stable encoding for in/out/inout/bycopy/byref/oneway/nullability 710 Record.push_back(D->getObjCDeclQualifier()); 711 Record.push_back(D->hasRelatedResultType()); 712 Record.AddTypeRef(D->getReturnType()); 713 Record.AddTypeSourceInfo(D->getReturnTypeSourceInfo()); 714 Record.AddSourceLocation(D->getEndLoc()); 715 Record.push_back(D->param_size()); 716 for (const auto *P : D->parameters()) 717 Record.AddDeclRef(P); 718 719 Record.push_back(D->getSelLocsKind()); 720 unsigned NumStoredSelLocs = D->getNumStoredSelLocs(); 721 SourceLocation *SelLocs = D->getStoredSelLocs(); 722 Record.push_back(NumStoredSelLocs); 723 for (unsigned i = 0; i != NumStoredSelLocs; ++i) 724 Record.AddSourceLocation(SelLocs[i]); 725 726 Code = serialization::DECL_OBJC_METHOD; 727 } 728 729 void ASTDeclWriter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { 730 VisitTypedefNameDecl(D); 731 Record.push_back(D->Variance); 732 Record.push_back(D->Index); 733 Record.AddSourceLocation(D->VarianceLoc); 734 Record.AddSourceLocation(D->ColonLoc); 735 736 Code = serialization::DECL_OBJC_TYPE_PARAM; 737 } 738 739 void ASTDeclWriter::VisitObjCContainerDecl(ObjCContainerDecl *D) { 740 VisitNamedDecl(D); 741 Record.AddSourceLocation(D->getAtStartLoc()); 742 Record.AddSourceRange(D->getAtEndRange()); 743 // Abstract class (no need to define a stable serialization::DECL code). 744 } 745 746 void ASTDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { 747 VisitRedeclarable(D); 748 VisitObjCContainerDecl(D); 749 Record.AddTypeRef(QualType(D->getTypeForDecl(), 0)); 750 AddObjCTypeParamList(D->TypeParamList); 751 752 Record.push_back(D->isThisDeclarationADefinition()); 753 if (D->isThisDeclarationADefinition()) { 754 // Write the DefinitionData 755 ObjCInterfaceDecl::DefinitionData &Data = D->data(); 756 757 Record.AddTypeSourceInfo(D->getSuperClassTInfo()); 758 Record.AddSourceLocation(D->getEndOfDefinitionLoc()); 759 Record.push_back(Data.HasDesignatedInitializers); 760 761 // Write out the protocols that are directly referenced by the @interface. 762 Record.push_back(Data.ReferencedProtocols.size()); 763 for (const auto *P : D->protocols()) 764 Record.AddDeclRef(P); 765 for (const auto &PL : D->protocol_locs()) 766 Record.AddSourceLocation(PL); 767 768 // Write out the protocols that are transitively referenced. 769 Record.push_back(Data.AllReferencedProtocols.size()); 770 for (ObjCList<ObjCProtocolDecl>::iterator 771 P = Data.AllReferencedProtocols.begin(), 772 PEnd = Data.AllReferencedProtocols.end(); 773 P != PEnd; ++P) 774 Record.AddDeclRef(*P); 775 776 777 if (ObjCCategoryDecl *Cat = D->getCategoryListRaw()) { 778 // Ensure that we write out the set of categories for this class. 779 Writer.ObjCClassesWithCategories.insert(D); 780 781 // Make sure that the categories get serialized. 782 for (; Cat; Cat = Cat->getNextClassCategoryRaw()) 783 (void)Writer.GetDeclRef(Cat); 784 } 785 } 786 787 Code = serialization::DECL_OBJC_INTERFACE; 788 } 789 790 void ASTDeclWriter::VisitObjCIvarDecl(ObjCIvarDecl *D) { 791 VisitFieldDecl(D); 792 // FIXME: stable encoding for @public/@private/@protected/@package 793 Record.push_back(D->getAccessControl()); 794 Record.push_back(D->getSynthesize()); 795 796 if (D->getDeclContext() == D->getLexicalDeclContext() && 797 !D->hasAttrs() && 798 !D->isImplicit() && 799 !D->isUsed(false) && 800 !D->isInvalidDecl() && 801 !D->isReferenced() && 802 !D->isModulePrivate() && 803 !D->getBitWidth() && 804 !D->hasExtInfo() && 805 D->getDeclName()) 806 AbbrevToUse = Writer.getDeclObjCIvarAbbrev(); 807 808 Code = serialization::DECL_OBJC_IVAR; 809 } 810 811 void ASTDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { 812 VisitRedeclarable(D); 813 VisitObjCContainerDecl(D); 814 815 Record.push_back(D->isThisDeclarationADefinition()); 816 if (D->isThisDeclarationADefinition()) { 817 Record.push_back(D->protocol_size()); 818 for (const auto *I : D->protocols()) 819 Record.AddDeclRef(I); 820 for (const auto &PL : D->protocol_locs()) 821 Record.AddSourceLocation(PL); 822 } 823 824 Code = serialization::DECL_OBJC_PROTOCOL; 825 } 826 827 void ASTDeclWriter::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) { 828 VisitFieldDecl(D); 829 Code = serialization::DECL_OBJC_AT_DEFS_FIELD; 830 } 831 832 void ASTDeclWriter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { 833 VisitObjCContainerDecl(D); 834 Record.AddSourceLocation(D->getCategoryNameLoc()); 835 Record.AddSourceLocation(D->getIvarLBraceLoc()); 836 Record.AddSourceLocation(D->getIvarRBraceLoc()); 837 Record.AddDeclRef(D->getClassInterface()); 838 AddObjCTypeParamList(D->TypeParamList); 839 Record.push_back(D->protocol_size()); 840 for (const auto *I : D->protocols()) 841 Record.AddDeclRef(I); 842 for (const auto &PL : D->protocol_locs()) 843 Record.AddSourceLocation(PL); 844 Code = serialization::DECL_OBJC_CATEGORY; 845 } 846 847 void ASTDeclWriter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D) { 848 VisitNamedDecl(D); 849 Record.AddDeclRef(D->getClassInterface()); 850 Code = serialization::DECL_OBJC_COMPATIBLE_ALIAS; 851 } 852 853 void ASTDeclWriter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { 854 VisitNamedDecl(D); 855 Record.AddSourceLocation(D->getAtLoc()); 856 Record.AddSourceLocation(D->getLParenLoc()); 857 Record.AddTypeRef(D->getType()); 858 Record.AddTypeSourceInfo(D->getTypeSourceInfo()); 859 // FIXME: stable encoding 860 Record.push_back((unsigned)D->getPropertyAttributes()); 861 Record.push_back((unsigned)D->getPropertyAttributesAsWritten()); 862 // FIXME: stable encoding 863 Record.push_back((unsigned)D->getPropertyImplementation()); 864 Record.AddDeclarationName(D->getGetterName()); 865 Record.AddSourceLocation(D->getGetterNameLoc()); 866 Record.AddDeclarationName(D->getSetterName()); 867 Record.AddSourceLocation(D->getSetterNameLoc()); 868 Record.AddDeclRef(D->getGetterMethodDecl()); 869 Record.AddDeclRef(D->getSetterMethodDecl()); 870 Record.AddDeclRef(D->getPropertyIvarDecl()); 871 Code = serialization::DECL_OBJC_PROPERTY; 872 } 873 874 void ASTDeclWriter::VisitObjCImplDecl(ObjCImplDecl *D) { 875 VisitObjCContainerDecl(D); 876 Record.AddDeclRef(D->getClassInterface()); 877 // Abstract class (no need to define a stable serialization::DECL code). 878 } 879 880 void ASTDeclWriter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { 881 VisitObjCImplDecl(D); 882 Record.AddSourceLocation(D->getCategoryNameLoc()); 883 Code = serialization::DECL_OBJC_CATEGORY_IMPL; 884 } 885 886 void ASTDeclWriter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { 887 VisitObjCImplDecl(D); 888 Record.AddDeclRef(D->getSuperClass()); 889 Record.AddSourceLocation(D->getSuperClassLoc()); 890 Record.AddSourceLocation(D->getIvarLBraceLoc()); 891 Record.AddSourceLocation(D->getIvarRBraceLoc()); 892 Record.push_back(D->hasNonZeroConstructors()); 893 Record.push_back(D->hasDestructors()); 894 Record.push_back(D->NumIvarInitializers); 895 if (D->NumIvarInitializers) 896 Record.AddCXXCtorInitializers( 897 llvm::makeArrayRef(D->init_begin(), D->init_end())); 898 Code = serialization::DECL_OBJC_IMPLEMENTATION; 899 } 900 901 void ASTDeclWriter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { 902 VisitDecl(D); 903 Record.AddSourceLocation(D->getBeginLoc()); 904 Record.AddDeclRef(D->getPropertyDecl()); 905 Record.AddDeclRef(D->getPropertyIvarDecl()); 906 Record.AddSourceLocation(D->getPropertyIvarDeclLoc()); 907 Record.AddDeclRef(D->getGetterMethodDecl()); 908 Record.AddDeclRef(D->getSetterMethodDecl()); 909 Record.AddStmt(D->getGetterCXXConstructor()); 910 Record.AddStmt(D->getSetterCXXAssignment()); 911 Code = serialization::DECL_OBJC_PROPERTY_IMPL; 912 } 913 914 void ASTDeclWriter::VisitFieldDecl(FieldDecl *D) { 915 VisitDeclaratorDecl(D); 916 Record.push_back(D->isMutable()); 917 918 FieldDecl::InitStorageKind ISK = D->InitStorage.getInt(); 919 Record.push_back(ISK); 920 if (ISK == FieldDecl::ISK_CapturedVLAType) 921 Record.AddTypeRef(QualType(D->getCapturedVLAType(), 0)); 922 else if (ISK) 923 Record.AddStmt(D->getInClassInitializer()); 924 925 Record.AddStmt(D->getBitWidth()); 926 927 if (!D->getDeclName()) 928 Record.AddDeclRef(Context.getInstantiatedFromUnnamedFieldDecl(D)); 929 930 if (D->getDeclContext() == D->getLexicalDeclContext() && 931 !D->hasAttrs() && 932 !D->isImplicit() && 933 !D->isUsed(false) && 934 !D->isInvalidDecl() && 935 !D->isReferenced() && 936 !D->isTopLevelDeclInObjCContainer() && 937 !D->isModulePrivate() && 938 !D->getBitWidth() && 939 !D->hasInClassInitializer() && 940 !D->hasCapturedVLAType() && 941 !D->hasExtInfo() && 942 !ObjCIvarDecl::classofKind(D->getKind()) && 943 !ObjCAtDefsFieldDecl::classofKind(D->getKind()) && 944 D->getDeclName()) 945 AbbrevToUse = Writer.getDeclFieldAbbrev(); 946 947 Code = serialization::DECL_FIELD; 948 } 949 950 void ASTDeclWriter::VisitMSPropertyDecl(MSPropertyDecl *D) { 951 VisitDeclaratorDecl(D); 952 Record.AddIdentifierRef(D->getGetterId()); 953 Record.AddIdentifierRef(D->getSetterId()); 954 Code = serialization::DECL_MS_PROPERTY; 955 } 956 957 void ASTDeclWriter::VisitMSGuidDecl(MSGuidDecl *D) { 958 VisitValueDecl(D); 959 MSGuidDecl::Parts Parts = D->getParts(); 960 Record.push_back(Parts.Part1); 961 Record.push_back(Parts.Part2); 962 Record.push_back(Parts.Part3); 963 for (auto C : Parts.Part4And5) 964 Record.push_back(C); 965 Code = serialization::DECL_MS_GUID; 966 } 967 968 void ASTDeclWriter::VisitTemplateParamObjectDecl(TemplateParamObjectDecl *D) { 969 VisitValueDecl(D); 970 Record.AddAPValue(D->getValue()); 971 Code = serialization::DECL_TEMPLATE_PARAM_OBJECT; 972 } 973 974 void ASTDeclWriter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { 975 VisitValueDecl(D); 976 Record.push_back(D->getChainingSize()); 977 978 for (const auto *P : D->chain()) 979 Record.AddDeclRef(P); 980 Code = serialization::DECL_INDIRECTFIELD; 981 } 982 983 void ASTDeclWriter::VisitVarDecl(VarDecl *D) { 984 VisitRedeclarable(D); 985 VisitDeclaratorDecl(D); 986 Record.push_back(D->getStorageClass()); 987 Record.push_back(D->getTSCSpec()); 988 Record.push_back(D->getInitStyle()); 989 Record.push_back(D->isARCPseudoStrong()); 990 if (!isa<ParmVarDecl>(D)) { 991 Record.push_back(D->isThisDeclarationADemotedDefinition()); 992 Record.push_back(D->isExceptionVariable()); 993 Record.push_back(D->isNRVOVariable()); 994 Record.push_back(D->isCXXForRangeDecl()); 995 Record.push_back(D->isObjCForDecl()); 996 Record.push_back(D->isInline()); 997 Record.push_back(D->isInlineSpecified()); 998 Record.push_back(D->isConstexpr()); 999 Record.push_back(D->isInitCapture()); 1000 Record.push_back(D->isPreviousDeclInSameBlockScope()); 1001 if (const auto *IPD = dyn_cast<ImplicitParamDecl>(D)) 1002 Record.push_back(static_cast<unsigned>(IPD->getParameterKind())); 1003 else 1004 Record.push_back(0); 1005 Record.push_back(D->isEscapingByref()); 1006 } 1007 Record.push_back(D->getLinkageInternal()); 1008 1009 Record.AddVarDeclInit(D); 1010 1011 if (D->hasAttr<BlocksAttr>() && D->getType()->getAsCXXRecordDecl()) { 1012 BlockVarCopyInit Init = Writer.Context->getBlockVarCopyInit(D); 1013 Record.AddStmt(Init.getCopyExpr()); 1014 if (Init.getCopyExpr()) 1015 Record.push_back(Init.canThrow()); 1016 } 1017 1018 if (D->getStorageDuration() == SD_Static) { 1019 bool ModulesCodegen = false; 1020 if (Writer.WritingModule && 1021 !D->getDescribedVarTemplate() && !D->getMemberSpecializationInfo() && 1022 !isa<VarTemplateSpecializationDecl>(D)) { 1023 // When building a C++ Modules TS module interface unit, a strong 1024 // definition in the module interface is provided by the compilation of 1025 // that module interface unit, not by its users. (Inline variables are 1026 // still emitted in module users.) 1027 ModulesCodegen = 1028 (Writer.WritingModule->Kind == Module::ModuleInterfaceUnit || 1029 (D->hasAttr<DLLExportAttr>() && 1030 Writer.Context->getLangOpts().BuildingPCHWithObjectFile)) && 1031 Writer.Context->GetGVALinkageForVariable(D) == GVA_StrongExternal; 1032 } 1033 Record.push_back(ModulesCodegen); 1034 if (ModulesCodegen) 1035 Writer.ModularCodegenDecls.push_back(Writer.GetDeclRef(D)); 1036 } 1037 1038 enum { 1039 VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization 1040 }; 1041 if (VarTemplateDecl *TemplD = D->getDescribedVarTemplate()) { 1042 Record.push_back(VarTemplate); 1043 Record.AddDeclRef(TemplD); 1044 } else if (MemberSpecializationInfo *SpecInfo 1045 = D->getMemberSpecializationInfo()) { 1046 Record.push_back(StaticDataMemberSpecialization); 1047 Record.AddDeclRef(SpecInfo->getInstantiatedFrom()); 1048 Record.push_back(SpecInfo->getTemplateSpecializationKind()); 1049 Record.AddSourceLocation(SpecInfo->getPointOfInstantiation()); 1050 } else { 1051 Record.push_back(VarNotTemplate); 1052 } 1053 1054 if (D->getDeclContext() == D->getLexicalDeclContext() && 1055 !D->hasAttrs() && 1056 !D->isImplicit() && 1057 !D->isUsed(false) && 1058 !D->isInvalidDecl() && 1059 !D->isReferenced() && 1060 !D->isTopLevelDeclInObjCContainer() && 1061 D->getAccess() == AS_none && 1062 !D->isModulePrivate() && 1063 !needsAnonymousDeclarationNumber(D) && 1064 D->getDeclName().getNameKind() == DeclarationName::Identifier && 1065 !D->hasExtInfo() && 1066 D->getFirstDecl() == D->getMostRecentDecl() && 1067 D->getKind() == Decl::Var && 1068 !D->isInline() && 1069 !D->isConstexpr() && 1070 !D->isInitCapture() && 1071 !D->isPreviousDeclInSameBlockScope() && 1072 !(D->hasAttr<BlocksAttr>() && D->getType()->getAsCXXRecordDecl()) && 1073 !D->isEscapingByref() && 1074 D->getStorageDuration() != SD_Static && 1075 !D->getMemberSpecializationInfo()) 1076 AbbrevToUse = Writer.getDeclVarAbbrev(); 1077 1078 Code = serialization::DECL_VAR; 1079 } 1080 1081 void ASTDeclWriter::VisitImplicitParamDecl(ImplicitParamDecl *D) { 1082 VisitVarDecl(D); 1083 Code = serialization::DECL_IMPLICIT_PARAM; 1084 } 1085 1086 void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl *D) { 1087 VisitVarDecl(D); 1088 Record.push_back(D->isObjCMethodParameter()); 1089 Record.push_back(D->getFunctionScopeDepth()); 1090 Record.push_back(D->getFunctionScopeIndex()); 1091 Record.push_back(D->getObjCDeclQualifier()); // FIXME: stable encoding 1092 Record.push_back(D->isKNRPromoted()); 1093 Record.push_back(D->hasInheritedDefaultArg()); 1094 Record.push_back(D->hasUninstantiatedDefaultArg()); 1095 if (D->hasUninstantiatedDefaultArg()) 1096 Record.AddStmt(D->getUninstantiatedDefaultArg()); 1097 Code = serialization::DECL_PARM_VAR; 1098 1099 // If the assumptions about the DECL_PARM_VAR abbrev are true, use it. Here 1100 // we dynamically check for the properties that we optimize for, but don't 1101 // know are true of all PARM_VAR_DECLs. 1102 if (D->getDeclContext() == D->getLexicalDeclContext() && 1103 !D->hasAttrs() && 1104 !D->hasExtInfo() && 1105 !D->isImplicit() && 1106 !D->isUsed(false) && 1107 !D->isInvalidDecl() && 1108 !D->isReferenced() && 1109 D->getAccess() == AS_none && 1110 !D->isModulePrivate() && 1111 D->getStorageClass() == 0 && 1112 D->getInitStyle() == VarDecl::CInit && // Can params have anything else? 1113 D->getFunctionScopeDepth() == 0 && 1114 D->getObjCDeclQualifier() == 0 && 1115 !D->isKNRPromoted() && 1116 !D->hasInheritedDefaultArg() && 1117 D->getInit() == nullptr && 1118 !D->hasUninstantiatedDefaultArg()) // No default expr. 1119 AbbrevToUse = Writer.getDeclParmVarAbbrev(); 1120 1121 // Check things we know are true of *every* PARM_VAR_DECL, which is more than 1122 // just us assuming it. 1123 assert(!D->getTSCSpec() && "PARM_VAR_DECL can't use TLS"); 1124 assert(!D->isThisDeclarationADemotedDefinition() 1125 && "PARM_VAR_DECL can't be demoted definition."); 1126 assert(D->getAccess() == AS_none && "PARM_VAR_DECL can't be public/private"); 1127 assert(!D->isExceptionVariable() && "PARM_VAR_DECL can't be exception var"); 1128 assert(D->getPreviousDecl() == nullptr && "PARM_VAR_DECL can't be redecl"); 1129 assert(!D->isStaticDataMember() && 1130 "PARM_VAR_DECL can't be static data member"); 1131 } 1132 1133 void ASTDeclWriter::VisitDecompositionDecl(DecompositionDecl *D) { 1134 // Record the number of bindings first to simplify deserialization. 1135 Record.push_back(D->bindings().size()); 1136 1137 VisitVarDecl(D); 1138 for (auto *B : D->bindings()) 1139 Record.AddDeclRef(B); 1140 Code = serialization::DECL_DECOMPOSITION; 1141 } 1142 1143 void ASTDeclWriter::VisitBindingDecl(BindingDecl *D) { 1144 VisitValueDecl(D); 1145 Record.AddStmt(D->getBinding()); 1146 Code = serialization::DECL_BINDING; 1147 } 1148 1149 void ASTDeclWriter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) { 1150 VisitDecl(D); 1151 Record.AddStmt(D->getAsmString()); 1152 Record.AddSourceLocation(D->getRParenLoc()); 1153 Code = serialization::DECL_FILE_SCOPE_ASM; 1154 } 1155 1156 void ASTDeclWriter::VisitEmptyDecl(EmptyDecl *D) { 1157 VisitDecl(D); 1158 Code = serialization::DECL_EMPTY; 1159 } 1160 1161 void ASTDeclWriter::VisitLifetimeExtendedTemporaryDecl( 1162 LifetimeExtendedTemporaryDecl *D) { 1163 VisitDecl(D); 1164 Record.AddDeclRef(D->getExtendingDecl()); 1165 Record.AddStmt(D->getTemporaryExpr()); 1166 Record.push_back(static_cast<bool>(D->getValue())); 1167 if (D->getValue()) 1168 Record.AddAPValue(*D->getValue()); 1169 Record.push_back(D->getManglingNumber()); 1170 Code = serialization::DECL_LIFETIME_EXTENDED_TEMPORARY; 1171 } 1172 void ASTDeclWriter::VisitBlockDecl(BlockDecl *D) { 1173 VisitDecl(D); 1174 Record.AddStmt(D->getBody()); 1175 Record.AddTypeSourceInfo(D->getSignatureAsWritten()); 1176 Record.push_back(D->param_size()); 1177 for (ParmVarDecl *P : D->parameters()) 1178 Record.AddDeclRef(P); 1179 Record.push_back(D->isVariadic()); 1180 Record.push_back(D->blockMissingReturnType()); 1181 Record.push_back(D->isConversionFromLambda()); 1182 Record.push_back(D->doesNotEscape()); 1183 Record.push_back(D->canAvoidCopyToHeap()); 1184 Record.push_back(D->capturesCXXThis()); 1185 Record.push_back(D->getNumCaptures()); 1186 for (const auto &capture : D->captures()) { 1187 Record.AddDeclRef(capture.getVariable()); 1188 1189 unsigned flags = 0; 1190 if (capture.isByRef()) flags |= 1; 1191 if (capture.isNested()) flags |= 2; 1192 if (capture.hasCopyExpr()) flags |= 4; 1193 Record.push_back(flags); 1194 1195 if (capture.hasCopyExpr()) Record.AddStmt(capture.getCopyExpr()); 1196 } 1197 1198 Code = serialization::DECL_BLOCK; 1199 } 1200 1201 void ASTDeclWriter::VisitCapturedDecl(CapturedDecl *CD) { 1202 Record.push_back(CD->getNumParams()); 1203 VisitDecl(CD); 1204 Record.push_back(CD->getContextParamPosition()); 1205 Record.push_back(CD->isNothrow() ? 1 : 0); 1206 // Body is stored by VisitCapturedStmt. 1207 for (unsigned I = 0; I < CD->getNumParams(); ++I) 1208 Record.AddDeclRef(CD->getParam(I)); 1209 Code = serialization::DECL_CAPTURED; 1210 } 1211 1212 void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { 1213 VisitDecl(D); 1214 Record.push_back(D->getLanguage()); 1215 Record.AddSourceLocation(D->getExternLoc()); 1216 Record.AddSourceLocation(D->getRBraceLoc()); 1217 Code = serialization::DECL_LINKAGE_SPEC; 1218 } 1219 1220 void ASTDeclWriter::VisitExportDecl(ExportDecl *D) { 1221 VisitDecl(D); 1222 Record.AddSourceLocation(D->getRBraceLoc()); 1223 Code = serialization::DECL_EXPORT; 1224 } 1225 1226 void ASTDeclWriter::VisitLabelDecl(LabelDecl *D) { 1227 VisitNamedDecl(D); 1228 Record.AddSourceLocation(D->getBeginLoc()); 1229 Code = serialization::DECL_LABEL; 1230 } 1231 1232 1233 void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) { 1234 VisitRedeclarable(D); 1235 VisitNamedDecl(D); 1236 Record.push_back(D->isInline()); 1237 Record.AddSourceLocation(D->getBeginLoc()); 1238 Record.AddSourceLocation(D->getRBraceLoc()); 1239 1240 if (D->isOriginalNamespace()) 1241 Record.AddDeclRef(D->getAnonymousNamespace()); 1242 Code = serialization::DECL_NAMESPACE; 1243 1244 if (Writer.hasChain() && D->isAnonymousNamespace() && 1245 D == D->getMostRecentDecl()) { 1246 // This is a most recent reopening of the anonymous namespace. If its parent 1247 // is in a previous PCH (or is the TU), mark that parent for update, because 1248 // the original namespace always points to the latest re-opening of its 1249 // anonymous namespace. 1250 Decl *Parent = cast<Decl>( 1251 D->getParent()->getRedeclContext()->getPrimaryContext()); 1252 if (Parent->isFromASTFile() || isa<TranslationUnitDecl>(Parent)) { 1253 Writer.DeclUpdates[Parent].push_back( 1254 ASTWriter::DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, D)); 1255 } 1256 } 1257 } 1258 1259 void ASTDeclWriter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { 1260 VisitRedeclarable(D); 1261 VisitNamedDecl(D); 1262 Record.AddSourceLocation(D->getNamespaceLoc()); 1263 Record.AddSourceLocation(D->getTargetNameLoc()); 1264 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc()); 1265 Record.AddDeclRef(D->getNamespace()); 1266 Code = serialization::DECL_NAMESPACE_ALIAS; 1267 } 1268 1269 void ASTDeclWriter::VisitUsingDecl(UsingDecl *D) { 1270 VisitNamedDecl(D); 1271 Record.AddSourceLocation(D->getUsingLoc()); 1272 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc()); 1273 Record.AddDeclarationNameLoc(D->DNLoc, D->getDeclName()); 1274 Record.AddDeclRef(D->FirstUsingShadow.getPointer()); 1275 Record.push_back(D->hasTypename()); 1276 Record.AddDeclRef(Context.getInstantiatedFromUsingDecl(D)); 1277 Code = serialization::DECL_USING; 1278 } 1279 1280 void ASTDeclWriter::VisitUsingPackDecl(UsingPackDecl *D) { 1281 Record.push_back(D->NumExpansions); 1282 VisitNamedDecl(D); 1283 Record.AddDeclRef(D->getInstantiatedFromUsingDecl()); 1284 for (auto *E : D->expansions()) 1285 Record.AddDeclRef(E); 1286 Code = serialization::DECL_USING_PACK; 1287 } 1288 1289 void ASTDeclWriter::VisitUsingShadowDecl(UsingShadowDecl *D) { 1290 VisitRedeclarable(D); 1291 VisitNamedDecl(D); 1292 Record.AddDeclRef(D->getTargetDecl()); 1293 Record.push_back(D->getIdentifierNamespace()); 1294 Record.AddDeclRef(D->UsingOrNextShadow); 1295 Record.AddDeclRef(Context.getInstantiatedFromUsingShadowDecl(D)); 1296 Code = serialization::DECL_USING_SHADOW; 1297 } 1298 1299 void ASTDeclWriter::VisitConstructorUsingShadowDecl( 1300 ConstructorUsingShadowDecl *D) { 1301 VisitUsingShadowDecl(D); 1302 Record.AddDeclRef(D->NominatedBaseClassShadowDecl); 1303 Record.AddDeclRef(D->ConstructedBaseClassShadowDecl); 1304 Record.push_back(D->IsVirtual); 1305 Code = serialization::DECL_CONSTRUCTOR_USING_SHADOW; 1306 } 1307 1308 void ASTDeclWriter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { 1309 VisitNamedDecl(D); 1310 Record.AddSourceLocation(D->getUsingLoc()); 1311 Record.AddSourceLocation(D->getNamespaceKeyLocation()); 1312 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc()); 1313 Record.AddDeclRef(D->getNominatedNamespace()); 1314 Record.AddDeclRef(dyn_cast<Decl>(D->getCommonAncestor())); 1315 Code = serialization::DECL_USING_DIRECTIVE; 1316 } 1317 1318 void ASTDeclWriter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) { 1319 VisitValueDecl(D); 1320 Record.AddSourceLocation(D->getUsingLoc()); 1321 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc()); 1322 Record.AddDeclarationNameLoc(D->DNLoc, D->getDeclName()); 1323 Record.AddSourceLocation(D->getEllipsisLoc()); 1324 Code = serialization::DECL_UNRESOLVED_USING_VALUE; 1325 } 1326 1327 void ASTDeclWriter::VisitUnresolvedUsingTypenameDecl( 1328 UnresolvedUsingTypenameDecl *D) { 1329 VisitTypeDecl(D); 1330 Record.AddSourceLocation(D->getTypenameLoc()); 1331 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc()); 1332 Record.AddSourceLocation(D->getEllipsisLoc()); 1333 Code = serialization::DECL_UNRESOLVED_USING_TYPENAME; 1334 } 1335 1336 void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) { 1337 VisitRecordDecl(D); 1338 1339 enum { 1340 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization 1341 }; 1342 if (ClassTemplateDecl *TemplD = D->getDescribedClassTemplate()) { 1343 Record.push_back(CXXRecTemplate); 1344 Record.AddDeclRef(TemplD); 1345 } else if (MemberSpecializationInfo *MSInfo 1346 = D->getMemberSpecializationInfo()) { 1347 Record.push_back(CXXRecMemberSpecialization); 1348 Record.AddDeclRef(MSInfo->getInstantiatedFrom()); 1349 Record.push_back(MSInfo->getTemplateSpecializationKind()); 1350 Record.AddSourceLocation(MSInfo->getPointOfInstantiation()); 1351 } else { 1352 Record.push_back(CXXRecNotTemplate); 1353 } 1354 1355 Record.push_back(D->isThisDeclarationADefinition()); 1356 if (D->isThisDeclarationADefinition()) 1357 Record.AddCXXDefinitionData(D); 1358 1359 // Store (what we currently believe to be) the key function to avoid 1360 // deserializing every method so we can compute it. 1361 if (D->isCompleteDefinition()) 1362 Record.AddDeclRef(Context.getCurrentKeyFunction(D)); 1363 1364 Code = serialization::DECL_CXX_RECORD; 1365 } 1366 1367 void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) { 1368 VisitFunctionDecl(D); 1369 if (D->isCanonicalDecl()) { 1370 Record.push_back(D->size_overridden_methods()); 1371 for (const CXXMethodDecl *MD : D->overridden_methods()) 1372 Record.AddDeclRef(MD); 1373 } else { 1374 // We only need to record overridden methods once for the canonical decl. 1375 Record.push_back(0); 1376 } 1377 1378 if (D->getDeclContext() == D->getLexicalDeclContext() && 1379 D->getFirstDecl() == D->getMostRecentDecl() && 1380 !D->isInvalidDecl() && 1381 !D->hasAttrs() && 1382 !D->isTopLevelDeclInObjCContainer() && 1383 D->getDeclName().getNameKind() == DeclarationName::Identifier && 1384 !D->hasExtInfo() && 1385 !D->hasInheritedPrototype() && 1386 D->hasWrittenPrototype()) 1387 AbbrevToUse = Writer.getDeclCXXMethodAbbrev(); 1388 1389 Code = serialization::DECL_CXX_METHOD; 1390 } 1391 1392 void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { 1393 Record.push_back(D->getTraillingAllocKind()); 1394 addExplicitSpecifier(D->getExplicitSpecifier(), Record); 1395 if (auto Inherited = D->getInheritedConstructor()) { 1396 Record.AddDeclRef(Inherited.getShadowDecl()); 1397 Record.AddDeclRef(Inherited.getConstructor()); 1398 } 1399 1400 VisitCXXMethodDecl(D); 1401 Code = serialization::DECL_CXX_CONSTRUCTOR; 1402 } 1403 1404 void ASTDeclWriter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { 1405 VisitCXXMethodDecl(D); 1406 1407 Record.AddDeclRef(D->getOperatorDelete()); 1408 if (D->getOperatorDelete()) 1409 Record.AddStmt(D->getOperatorDeleteThisArg()); 1410 1411 Code = serialization::DECL_CXX_DESTRUCTOR; 1412 } 1413 1414 void ASTDeclWriter::VisitCXXConversionDecl(CXXConversionDecl *D) { 1415 addExplicitSpecifier(D->getExplicitSpecifier(), Record); 1416 VisitCXXMethodDecl(D); 1417 Code = serialization::DECL_CXX_CONVERSION; 1418 } 1419 1420 void ASTDeclWriter::VisitImportDecl(ImportDecl *D) { 1421 VisitDecl(D); 1422 Record.push_back(Writer.getSubmoduleID(D->getImportedModule())); 1423 ArrayRef<SourceLocation> IdentifierLocs = D->getIdentifierLocs(); 1424 Record.push_back(!IdentifierLocs.empty()); 1425 if (IdentifierLocs.empty()) { 1426 Record.AddSourceLocation(D->getEndLoc()); 1427 Record.push_back(1); 1428 } else { 1429 for (unsigned I = 0, N = IdentifierLocs.size(); I != N; ++I) 1430 Record.AddSourceLocation(IdentifierLocs[I]); 1431 Record.push_back(IdentifierLocs.size()); 1432 } 1433 // Note: the number of source locations must always be the last element in 1434 // the record. 1435 Code = serialization::DECL_IMPORT; 1436 } 1437 1438 void ASTDeclWriter::VisitAccessSpecDecl(AccessSpecDecl *D) { 1439 VisitDecl(D); 1440 Record.AddSourceLocation(D->getColonLoc()); 1441 Code = serialization::DECL_ACCESS_SPEC; 1442 } 1443 1444 void ASTDeclWriter::VisitFriendDecl(FriendDecl *D) { 1445 // Record the number of friend type template parameter lists here 1446 // so as to simplify memory allocation during deserialization. 1447 Record.push_back(D->NumTPLists); 1448 VisitDecl(D); 1449 bool hasFriendDecl = D->Friend.is<NamedDecl*>(); 1450 Record.push_back(hasFriendDecl); 1451 if (hasFriendDecl) 1452 Record.AddDeclRef(D->getFriendDecl()); 1453 else 1454 Record.AddTypeSourceInfo(D->getFriendType()); 1455 for (unsigned i = 0; i < D->NumTPLists; ++i) 1456 Record.AddTemplateParameterList(D->getFriendTypeTemplateParameterList(i)); 1457 Record.AddDeclRef(D->getNextFriend()); 1458 Record.push_back(D->UnsupportedFriend); 1459 Record.AddSourceLocation(D->FriendLoc); 1460 Code = serialization::DECL_FRIEND; 1461 } 1462 1463 void ASTDeclWriter::VisitFriendTemplateDecl(FriendTemplateDecl *D) { 1464 VisitDecl(D); 1465 Record.push_back(D->getNumTemplateParameters()); 1466 for (unsigned i = 0, e = D->getNumTemplateParameters(); i != e; ++i) 1467 Record.AddTemplateParameterList(D->getTemplateParameterList(i)); 1468 Record.push_back(D->getFriendDecl() != nullptr); 1469 if (D->getFriendDecl()) 1470 Record.AddDeclRef(D->getFriendDecl()); 1471 else 1472 Record.AddTypeSourceInfo(D->getFriendType()); 1473 Record.AddSourceLocation(D->getFriendLoc()); 1474 Code = serialization::DECL_FRIEND_TEMPLATE; 1475 } 1476 1477 void ASTDeclWriter::VisitTemplateDecl(TemplateDecl *D) { 1478 VisitNamedDecl(D); 1479 1480 Record.AddDeclRef(D->getTemplatedDecl()); 1481 Record.AddTemplateParameterList(D->getTemplateParameters()); 1482 } 1483 1484 void ASTDeclWriter::VisitConceptDecl(ConceptDecl *D) { 1485 VisitTemplateDecl(D); 1486 Record.AddStmt(D->getConstraintExpr()); 1487 Code = serialization::DECL_CONCEPT; 1488 } 1489 1490 void ASTDeclWriter::VisitRequiresExprBodyDecl(RequiresExprBodyDecl *D) { 1491 Code = serialization::DECL_REQUIRES_EXPR_BODY; 1492 } 1493 1494 void ASTDeclWriter::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) { 1495 VisitRedeclarable(D); 1496 1497 // Emit data to initialize CommonOrPrev before VisitTemplateDecl so that 1498 // getCommonPtr() can be used while this is still initializing. 1499 if (D->isFirstDecl()) { 1500 // This declaration owns the 'common' pointer, so serialize that data now. 1501 Record.AddDeclRef(D->getInstantiatedFromMemberTemplate()); 1502 if (D->getInstantiatedFromMemberTemplate()) 1503 Record.push_back(D->isMemberSpecialization()); 1504 } 1505 1506 VisitTemplateDecl(D); 1507 Record.push_back(D->getIdentifierNamespace()); 1508 } 1509 1510 void ASTDeclWriter::VisitClassTemplateDecl(ClassTemplateDecl *D) { 1511 VisitRedeclarableTemplateDecl(D); 1512 1513 if (D->isFirstDecl()) 1514 AddTemplateSpecializations(D); 1515 Code = serialization::DECL_CLASS_TEMPLATE; 1516 } 1517 1518 void ASTDeclWriter::VisitClassTemplateSpecializationDecl( 1519 ClassTemplateSpecializationDecl *D) { 1520 RegisterTemplateSpecialization(D->getSpecializedTemplate(), D); 1521 1522 VisitCXXRecordDecl(D); 1523 1524 llvm::PointerUnion<ClassTemplateDecl *, 1525 ClassTemplatePartialSpecializationDecl *> InstFrom 1526 = D->getSpecializedTemplateOrPartial(); 1527 if (Decl *InstFromD = InstFrom.dyn_cast<ClassTemplateDecl *>()) { 1528 Record.AddDeclRef(InstFromD); 1529 } else { 1530 Record.AddDeclRef(InstFrom.get<ClassTemplatePartialSpecializationDecl *>()); 1531 Record.AddTemplateArgumentList(&D->getTemplateInstantiationArgs()); 1532 } 1533 1534 Record.AddTemplateArgumentList(&D->getTemplateArgs()); 1535 Record.AddSourceLocation(D->getPointOfInstantiation()); 1536 Record.push_back(D->getSpecializationKind()); 1537 Record.push_back(D->isCanonicalDecl()); 1538 1539 if (D->isCanonicalDecl()) { 1540 // When reading, we'll add it to the folding set of the following template. 1541 Record.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl()); 1542 } 1543 1544 // Explicit info. 1545 Record.AddTypeSourceInfo(D->getTypeAsWritten()); 1546 if (D->getTypeAsWritten()) { 1547 Record.AddSourceLocation(D->getExternLoc()); 1548 Record.AddSourceLocation(D->getTemplateKeywordLoc()); 1549 } 1550 1551 Code = serialization::DECL_CLASS_TEMPLATE_SPECIALIZATION; 1552 } 1553 1554 void ASTDeclWriter::VisitClassTemplatePartialSpecializationDecl( 1555 ClassTemplatePartialSpecializationDecl *D) { 1556 Record.AddTemplateParameterList(D->getTemplateParameters()); 1557 Record.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten()); 1558 1559 VisitClassTemplateSpecializationDecl(D); 1560 1561 // These are read/set from/to the first declaration. 1562 if (D->getPreviousDecl() == nullptr) { 1563 Record.AddDeclRef(D->getInstantiatedFromMember()); 1564 Record.push_back(D->isMemberSpecialization()); 1565 } 1566 1567 Code = serialization::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION; 1568 } 1569 1570 void ASTDeclWriter::VisitVarTemplateDecl(VarTemplateDecl *D) { 1571 VisitRedeclarableTemplateDecl(D); 1572 1573 if (D->isFirstDecl()) 1574 AddTemplateSpecializations(D); 1575 Code = serialization::DECL_VAR_TEMPLATE; 1576 } 1577 1578 void ASTDeclWriter::VisitVarTemplateSpecializationDecl( 1579 VarTemplateSpecializationDecl *D) { 1580 RegisterTemplateSpecialization(D->getSpecializedTemplate(), D); 1581 1582 VisitVarDecl(D); 1583 1584 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *> 1585 InstFrom = D->getSpecializedTemplateOrPartial(); 1586 if (Decl *InstFromD = InstFrom.dyn_cast<VarTemplateDecl *>()) { 1587 Record.AddDeclRef(InstFromD); 1588 } else { 1589 Record.AddDeclRef(InstFrom.get<VarTemplatePartialSpecializationDecl *>()); 1590 Record.AddTemplateArgumentList(&D->getTemplateInstantiationArgs()); 1591 } 1592 1593 // Explicit info. 1594 Record.AddTypeSourceInfo(D->getTypeAsWritten()); 1595 if (D->getTypeAsWritten()) { 1596 Record.AddSourceLocation(D->getExternLoc()); 1597 Record.AddSourceLocation(D->getTemplateKeywordLoc()); 1598 } 1599 1600 Record.AddTemplateArgumentList(&D->getTemplateArgs()); 1601 Record.AddSourceLocation(D->getPointOfInstantiation()); 1602 Record.push_back(D->getSpecializationKind()); 1603 Record.push_back(D->IsCompleteDefinition); 1604 Record.push_back(D->isCanonicalDecl()); 1605 1606 if (D->isCanonicalDecl()) { 1607 // When reading, we'll add it to the folding set of the following template. 1608 Record.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl()); 1609 } 1610 1611 Code = serialization::DECL_VAR_TEMPLATE_SPECIALIZATION; 1612 } 1613 1614 void ASTDeclWriter::VisitVarTemplatePartialSpecializationDecl( 1615 VarTemplatePartialSpecializationDecl *D) { 1616 Record.AddTemplateParameterList(D->getTemplateParameters()); 1617 Record.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten()); 1618 1619 VisitVarTemplateSpecializationDecl(D); 1620 1621 // These are read/set from/to the first declaration. 1622 if (D->getPreviousDecl() == nullptr) { 1623 Record.AddDeclRef(D->getInstantiatedFromMember()); 1624 Record.push_back(D->isMemberSpecialization()); 1625 } 1626 1627 Code = serialization::DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION; 1628 } 1629 1630 void ASTDeclWriter::VisitClassScopeFunctionSpecializationDecl( 1631 ClassScopeFunctionSpecializationDecl *D) { 1632 VisitDecl(D); 1633 Record.AddDeclRef(D->getSpecialization()); 1634 Record.push_back(D->hasExplicitTemplateArgs()); 1635 if (D->hasExplicitTemplateArgs()) 1636 Record.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten()); 1637 Code = serialization::DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION; 1638 } 1639 1640 1641 void ASTDeclWriter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { 1642 VisitRedeclarableTemplateDecl(D); 1643 1644 if (D->isFirstDecl()) 1645 AddTemplateSpecializations(D); 1646 Code = serialization::DECL_FUNCTION_TEMPLATE; 1647 } 1648 1649 void ASTDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { 1650 Record.push_back(D->hasTypeConstraint()); 1651 VisitTypeDecl(D); 1652 1653 Record.push_back(D->wasDeclaredWithTypename()); 1654 1655 const TypeConstraint *TC = D->getTypeConstraint(); 1656 Record.push_back(TC != nullptr); 1657 if (TC) { 1658 Record.AddNestedNameSpecifierLoc(TC->getNestedNameSpecifierLoc()); 1659 Record.AddDeclarationNameInfo(TC->getConceptNameInfo()); 1660 Record.AddDeclRef(TC->getNamedConcept()); 1661 Record.push_back(TC->getTemplateArgsAsWritten() != nullptr); 1662 if (TC->getTemplateArgsAsWritten()) 1663 Record.AddASTTemplateArgumentListInfo(TC->getTemplateArgsAsWritten()); 1664 Record.AddStmt(TC->getImmediatelyDeclaredConstraint()); 1665 Record.push_back(D->isExpandedParameterPack()); 1666 if (D->isExpandedParameterPack()) 1667 Record.push_back(D->getNumExpansionParameters()); 1668 } 1669 1670 bool OwnsDefaultArg = D->hasDefaultArgument() && 1671 !D->defaultArgumentWasInherited(); 1672 Record.push_back(OwnsDefaultArg); 1673 if (OwnsDefaultArg) 1674 Record.AddTypeSourceInfo(D->getDefaultArgumentInfo()); 1675 1676 Code = serialization::DECL_TEMPLATE_TYPE_PARM; 1677 } 1678 1679 void ASTDeclWriter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { 1680 // For an expanded parameter pack, record the number of expansion types here 1681 // so that it's easier for deserialization to allocate the right amount of 1682 // memory. 1683 Expr *TypeConstraint = D->getPlaceholderTypeConstraint(); 1684 Record.push_back(!!TypeConstraint); 1685 if (D->isExpandedParameterPack()) 1686 Record.push_back(D->getNumExpansionTypes()); 1687 1688 VisitDeclaratorDecl(D); 1689 // TemplateParmPosition. 1690 Record.push_back(D->getDepth()); 1691 Record.push_back(D->getPosition()); 1692 if (TypeConstraint) 1693 Record.AddStmt(TypeConstraint); 1694 1695 if (D->isExpandedParameterPack()) { 1696 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) { 1697 Record.AddTypeRef(D->getExpansionType(I)); 1698 Record.AddTypeSourceInfo(D->getExpansionTypeSourceInfo(I)); 1699 } 1700 1701 Code = serialization::DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK; 1702 } else { 1703 // Rest of NonTypeTemplateParmDecl. 1704 Record.push_back(D->isParameterPack()); 1705 bool OwnsDefaultArg = D->hasDefaultArgument() && 1706 !D->defaultArgumentWasInherited(); 1707 Record.push_back(OwnsDefaultArg); 1708 if (OwnsDefaultArg) 1709 Record.AddStmt(D->getDefaultArgument()); 1710 Code = serialization::DECL_NON_TYPE_TEMPLATE_PARM; 1711 } 1712 } 1713 1714 void ASTDeclWriter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { 1715 // For an expanded parameter pack, record the number of expansion types here 1716 // so that it's easier for deserialization to allocate the right amount of 1717 // memory. 1718 if (D->isExpandedParameterPack()) 1719 Record.push_back(D->getNumExpansionTemplateParameters()); 1720 1721 VisitTemplateDecl(D); 1722 // TemplateParmPosition. 1723 Record.push_back(D->getDepth()); 1724 Record.push_back(D->getPosition()); 1725 1726 if (D->isExpandedParameterPack()) { 1727 for (unsigned I = 0, N = D->getNumExpansionTemplateParameters(); 1728 I != N; ++I) 1729 Record.AddTemplateParameterList(D->getExpansionTemplateParameters(I)); 1730 Code = serialization::DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK; 1731 } else { 1732 // Rest of TemplateTemplateParmDecl. 1733 Record.push_back(D->isParameterPack()); 1734 bool OwnsDefaultArg = D->hasDefaultArgument() && 1735 !D->defaultArgumentWasInherited(); 1736 Record.push_back(OwnsDefaultArg); 1737 if (OwnsDefaultArg) 1738 Record.AddTemplateArgumentLoc(D->getDefaultArgument()); 1739 Code = serialization::DECL_TEMPLATE_TEMPLATE_PARM; 1740 } 1741 } 1742 1743 void ASTDeclWriter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { 1744 VisitRedeclarableTemplateDecl(D); 1745 Code = serialization::DECL_TYPE_ALIAS_TEMPLATE; 1746 } 1747 1748 void ASTDeclWriter::VisitStaticAssertDecl(StaticAssertDecl *D) { 1749 VisitDecl(D); 1750 Record.AddStmt(D->getAssertExpr()); 1751 Record.push_back(D->isFailed()); 1752 Record.AddStmt(D->getMessage()); 1753 Record.AddSourceLocation(D->getRParenLoc()); 1754 Code = serialization::DECL_STATIC_ASSERT; 1755 } 1756 1757 /// Emit the DeclContext part of a declaration context decl. 1758 void ASTDeclWriter::VisitDeclContext(DeclContext *DC) { 1759 Record.AddOffset(Writer.WriteDeclContextLexicalBlock(Context, DC)); 1760 Record.AddOffset(Writer.WriteDeclContextVisibleBlock(Context, DC)); 1761 } 1762 1763 const Decl *ASTWriter::getFirstLocalDecl(const Decl *D) { 1764 assert(IsLocalDecl(D) && "expected a local declaration"); 1765 1766 const Decl *Canon = D->getCanonicalDecl(); 1767 if (IsLocalDecl(Canon)) 1768 return Canon; 1769 1770 const Decl *&CacheEntry = FirstLocalDeclCache[Canon]; 1771 if (CacheEntry) 1772 return CacheEntry; 1773 1774 for (const Decl *Redecl = D; Redecl; Redecl = Redecl->getPreviousDecl()) 1775 if (IsLocalDecl(Redecl)) 1776 D = Redecl; 1777 return CacheEntry = D; 1778 } 1779 1780 template <typename T> 1781 void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) { 1782 T *First = D->getFirstDecl(); 1783 T *MostRecent = First->getMostRecentDecl(); 1784 T *DAsT = static_cast<T *>(D); 1785 if (MostRecent != First) { 1786 assert(isRedeclarableDeclKind(DAsT->getKind()) && 1787 "Not considered redeclarable?"); 1788 1789 Record.AddDeclRef(First); 1790 1791 // Write out a list of local redeclarations of this declaration if it's the 1792 // first local declaration in the chain. 1793 const Decl *FirstLocal = Writer.getFirstLocalDecl(DAsT); 1794 if (DAsT == FirstLocal) { 1795 // Emit a list of all imported first declarations so that we can be sure 1796 // that all redeclarations visible to this module are before D in the 1797 // redecl chain. 1798 unsigned I = Record.size(); 1799 Record.push_back(0); 1800 if (Writer.Chain) 1801 AddFirstDeclFromEachModule(DAsT, /*IncludeLocal*/false); 1802 // This is the number of imported first declarations + 1. 1803 Record[I] = Record.size() - I; 1804 1805 // Collect the set of local redeclarations of this declaration, from 1806 // newest to oldest. 1807 ASTWriter::RecordData LocalRedecls; 1808 ASTRecordWriter LocalRedeclWriter(Record, LocalRedecls); 1809 for (const Decl *Prev = FirstLocal->getMostRecentDecl(); 1810 Prev != FirstLocal; Prev = Prev->getPreviousDecl()) 1811 if (!Prev->isFromASTFile()) 1812 LocalRedeclWriter.AddDeclRef(Prev); 1813 1814 // If we have any redecls, write them now as a separate record preceding 1815 // the declaration itself. 1816 if (LocalRedecls.empty()) 1817 Record.push_back(0); 1818 else 1819 Record.AddOffset(LocalRedeclWriter.Emit(LOCAL_REDECLARATIONS)); 1820 } else { 1821 Record.push_back(0); 1822 Record.AddDeclRef(FirstLocal); 1823 } 1824 1825 // Make sure that we serialize both the previous and the most-recent 1826 // declarations, which (transitively) ensures that all declarations in the 1827 // chain get serialized. 1828 // 1829 // FIXME: This is not correct; when we reach an imported declaration we 1830 // won't emit its previous declaration. 1831 (void)Writer.GetDeclRef(D->getPreviousDecl()); 1832 (void)Writer.GetDeclRef(MostRecent); 1833 } else { 1834 // We use the sentinel value 0 to indicate an only declaration. 1835 Record.push_back(0); 1836 } 1837 } 1838 1839 void ASTDeclWriter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) { 1840 Record.writeOMPChildren(D->Data); 1841 VisitDecl(D); 1842 Code = serialization::DECL_OMP_THREADPRIVATE; 1843 } 1844 1845 void ASTDeclWriter::VisitOMPAllocateDecl(OMPAllocateDecl *D) { 1846 Record.writeOMPChildren(D->Data); 1847 VisitDecl(D); 1848 Code = serialization::DECL_OMP_ALLOCATE; 1849 } 1850 1851 void ASTDeclWriter::VisitOMPRequiresDecl(OMPRequiresDecl *D) { 1852 Record.writeOMPChildren(D->Data); 1853 VisitDecl(D); 1854 Code = serialization::DECL_OMP_REQUIRES; 1855 } 1856 1857 void ASTDeclWriter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) { 1858 VisitValueDecl(D); 1859 Record.AddSourceLocation(D->getBeginLoc()); 1860 Record.AddStmt(D->getCombinerIn()); 1861 Record.AddStmt(D->getCombinerOut()); 1862 Record.AddStmt(D->getCombiner()); 1863 Record.AddStmt(D->getInitOrig()); 1864 Record.AddStmt(D->getInitPriv()); 1865 Record.AddStmt(D->getInitializer()); 1866 Record.push_back(D->getInitializerKind()); 1867 Record.AddDeclRef(D->getPrevDeclInScope()); 1868 Code = serialization::DECL_OMP_DECLARE_REDUCTION; 1869 } 1870 1871 void ASTDeclWriter::VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D) { 1872 Record.writeOMPChildren(D->Data); 1873 VisitValueDecl(D); 1874 Record.AddDeclarationName(D->getVarName()); 1875 Record.AddDeclRef(D->getPrevDeclInScope()); 1876 Code = serialization::DECL_OMP_DECLARE_MAPPER; 1877 } 1878 1879 void ASTDeclWriter::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) { 1880 VisitVarDecl(D); 1881 Code = serialization::DECL_OMP_CAPTUREDEXPR; 1882 } 1883 1884 //===----------------------------------------------------------------------===// 1885 // ASTWriter Implementation 1886 //===----------------------------------------------------------------------===// 1887 1888 void ASTWriter::WriteDeclAbbrevs() { 1889 using namespace llvm; 1890 1891 std::shared_ptr<BitCodeAbbrev> Abv; 1892 1893 // Abbreviation for DECL_FIELD 1894 Abv = std::make_shared<BitCodeAbbrev>(); 1895 Abv->Add(BitCodeAbbrevOp(serialization::DECL_FIELD)); 1896 // Decl 1897 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext 1898 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext 1899 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl 1900 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs 1901 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit 1902 Abv->Add(BitCodeAbbrevOp(0)); // isUsed 1903 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced 1904 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer 1905 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier 1906 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate 1907 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID 1908 // NamedDecl 1909 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier 1910 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name 1911 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber 1912 // ValueDecl 1913 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type 1914 // DeclaratorDecl 1915 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc 1916 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo 1917 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType 1918 // FieldDecl 1919 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable 1920 Abv->Add(BitCodeAbbrevOp(0)); // InitStyle 1921 // Type Source Info 1922 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); 1923 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc 1924 DeclFieldAbbrev = Stream.EmitAbbrev(std::move(Abv)); 1925 1926 // Abbreviation for DECL_OBJC_IVAR 1927 Abv = std::make_shared<BitCodeAbbrev>(); 1928 Abv->Add(BitCodeAbbrevOp(serialization::DECL_OBJC_IVAR)); 1929 // Decl 1930 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext 1931 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext 1932 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl 1933 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs 1934 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit 1935 Abv->Add(BitCodeAbbrevOp(0)); // isUsed 1936 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced 1937 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer 1938 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier 1939 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate 1940 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID 1941 // NamedDecl 1942 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier 1943 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name 1944 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber 1945 // ValueDecl 1946 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type 1947 // DeclaratorDecl 1948 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc 1949 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo 1950 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType 1951 // FieldDecl 1952 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable 1953 Abv->Add(BitCodeAbbrevOp(0)); // InitStyle 1954 // ObjC Ivar 1955 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getAccessControl 1956 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getSynthesize 1957 // Type Source Info 1958 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); 1959 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc 1960 DeclObjCIvarAbbrev = Stream.EmitAbbrev(std::move(Abv)); 1961 1962 // Abbreviation for DECL_ENUM 1963 Abv = std::make_shared<BitCodeAbbrev>(); 1964 Abv->Add(BitCodeAbbrevOp(serialization::DECL_ENUM)); 1965 // Redeclarable 1966 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration 1967 // Decl 1968 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext 1969 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext 1970 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl 1971 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs 1972 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit 1973 Abv->Add(BitCodeAbbrevOp(0)); // isUsed 1974 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced 1975 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer 1976 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier 1977 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate 1978 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID 1979 // NamedDecl 1980 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier 1981 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name 1982 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber 1983 // TypeDecl 1984 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location 1985 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref 1986 // TagDecl 1987 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace 1988 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getTagKind 1989 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition 1990 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator 1991 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding 1992 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired 1993 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation 1994 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation 1995 Abv->Add(BitCodeAbbrevOp(0)); // ExtInfoKind 1996 // EnumDecl 1997 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // AddTypeRef 1998 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IntegerType 1999 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getPromotionType 2000 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getNumPositiveBits 2001 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getNumNegativeBits 2002 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScoped 2003 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScopedUsingClassTag 2004 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isFixed 2005 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));// ODRHash 2006 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InstantiatedMembEnum 2007 // DC 2008 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset 2009 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset 2010 DeclEnumAbbrev = Stream.EmitAbbrev(std::move(Abv)); 2011 2012 // Abbreviation for DECL_RECORD 2013 Abv = std::make_shared<BitCodeAbbrev>(); 2014 Abv->Add(BitCodeAbbrevOp(serialization::DECL_RECORD)); 2015 // Redeclarable 2016 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration 2017 // Decl 2018 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext 2019 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext 2020 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl 2021 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs 2022 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit 2023 Abv->Add(BitCodeAbbrevOp(0)); // isUsed 2024 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced 2025 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer 2026 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier 2027 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate 2028 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID 2029 // NamedDecl 2030 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier 2031 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name 2032 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber 2033 // TypeDecl 2034 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location 2035 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref 2036 // TagDecl 2037 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace 2038 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getTagKind 2039 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition 2040 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator 2041 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding 2042 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired 2043 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation 2044 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation 2045 Abv->Add(BitCodeAbbrevOp(0)); // ExtInfoKind 2046 // RecordDecl 2047 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // FlexibleArrayMember 2048 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // AnonymousStructUnion 2049 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasObjectMember 2050 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasVolatileMember 2051 2052 // isNonTrivialToPrimitiveDefaultInitialize 2053 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); 2054 // isNonTrivialToPrimitiveCopy 2055 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); 2056 // isNonTrivialToPrimitiveDestroy 2057 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); 2058 // hasNonTrivialToPrimitiveDefaultInitializeCUnion 2059 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); 2060 // hasNonTrivialToPrimitiveDestructCUnion 2061 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); 2062 // hasNonTrivialToPrimitiveCopyCUnion 2063 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); 2064 // isParamDestroyedInCallee 2065 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); 2066 // getArgPassingRestrictions 2067 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); 2068 2069 // DC 2070 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset 2071 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset 2072 DeclRecordAbbrev = Stream.EmitAbbrev(std::move(Abv)); 2073 2074 // Abbreviation for DECL_PARM_VAR 2075 Abv = std::make_shared<BitCodeAbbrev>(); 2076 Abv->Add(BitCodeAbbrevOp(serialization::DECL_PARM_VAR)); 2077 // Redeclarable 2078 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration 2079 // Decl 2080 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext 2081 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext 2082 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl 2083 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs 2084 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit 2085 Abv->Add(BitCodeAbbrevOp(0)); // isUsed 2086 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced 2087 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer 2088 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier 2089 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate 2090 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID 2091 // NamedDecl 2092 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier 2093 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name 2094 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber 2095 // ValueDecl 2096 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type 2097 // DeclaratorDecl 2098 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc 2099 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo 2100 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType 2101 // VarDecl 2102 Abv->Add(BitCodeAbbrevOp(0)); // SClass 2103 Abv->Add(BitCodeAbbrevOp(0)); // TSCSpec 2104 Abv->Add(BitCodeAbbrevOp(0)); // InitStyle 2105 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isARCPseudoStrong 2106 Abv->Add(BitCodeAbbrevOp(0)); // Linkage 2107 Abv->Add(BitCodeAbbrevOp(0)); // HasInit 2108 Abv->Add(BitCodeAbbrevOp(0)); // HasMemberSpecializationInfo 2109 // ParmVarDecl 2110 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsObjCMethodParameter 2111 Abv->Add(BitCodeAbbrevOp(0)); // ScopeDepth 2112 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ScopeIndex 2113 Abv->Add(BitCodeAbbrevOp(0)); // ObjCDeclQualifier 2114 Abv->Add(BitCodeAbbrevOp(0)); // KNRPromoted 2115 Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedDefaultArg 2116 Abv->Add(BitCodeAbbrevOp(0)); // HasUninstantiatedDefaultArg 2117 // Type Source Info 2118 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); 2119 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc 2120 DeclParmVarAbbrev = Stream.EmitAbbrev(std::move(Abv)); 2121 2122 // Abbreviation for DECL_TYPEDEF 2123 Abv = std::make_shared<BitCodeAbbrev>(); 2124 Abv->Add(BitCodeAbbrevOp(serialization::DECL_TYPEDEF)); 2125 // Redeclarable 2126 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration 2127 // Decl 2128 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext 2129 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext 2130 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl 2131 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs 2132 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit 2133 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isUsed 2134 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isReferenced 2135 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer 2136 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // C++ AccessSpecifier 2137 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate 2138 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID 2139 // NamedDecl 2140 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier 2141 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name 2142 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber 2143 // TypeDecl 2144 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location 2145 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref 2146 // TypedefDecl 2147 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); 2148 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc 2149 DeclTypedefAbbrev = Stream.EmitAbbrev(std::move(Abv)); 2150 2151 // Abbreviation for DECL_VAR 2152 Abv = std::make_shared<BitCodeAbbrev>(); 2153 Abv->Add(BitCodeAbbrevOp(serialization::DECL_VAR)); 2154 // Redeclarable 2155 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration 2156 // Decl 2157 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext 2158 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext 2159 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl 2160 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs 2161 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit 2162 Abv->Add(BitCodeAbbrevOp(0)); // isUsed 2163 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced 2164 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer 2165 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier 2166 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate 2167 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID 2168 // NamedDecl 2169 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier 2170 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name 2171 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber 2172 // ValueDecl 2173 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type 2174 // DeclaratorDecl 2175 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc 2176 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo 2177 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType 2178 // VarDecl 2179 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // SClass 2180 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // TSCSpec 2181 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // InitStyle 2182 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isARCPseudoStrong 2183 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsThisDeclarationADemotedDefinition 2184 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isExceptionVariable 2185 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isNRVOVariable 2186 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCXXForRangeDecl 2187 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isObjCForDecl 2188 Abv->Add(BitCodeAbbrevOp(0)); // isInline 2189 Abv->Add(BitCodeAbbrevOp(0)); // isInlineSpecified 2190 Abv->Add(BitCodeAbbrevOp(0)); // isConstexpr 2191 Abv->Add(BitCodeAbbrevOp(0)); // isInitCapture 2192 Abv->Add(BitCodeAbbrevOp(0)); // isPrevDeclInSameScope 2193 Abv->Add(BitCodeAbbrevOp(0)); // ImplicitParamKind 2194 Abv->Add(BitCodeAbbrevOp(0)); // EscapingByref 2195 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage 2196 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // HasConstant* 2197 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // VarKind (local enum) 2198 // Type Source Info 2199 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); 2200 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc 2201 DeclVarAbbrev = Stream.EmitAbbrev(std::move(Abv)); 2202 2203 // Abbreviation for DECL_CXX_METHOD 2204 Abv = std::make_shared<BitCodeAbbrev>(); 2205 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CXX_METHOD)); 2206 // RedeclarableDecl 2207 Abv->Add(BitCodeAbbrevOp(0)); // CanonicalDecl 2208 // Decl 2209 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext 2210 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext 2211 Abv->Add(BitCodeAbbrevOp(0)); // Invalid 2212 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs 2213 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Implicit 2214 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Used 2215 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Referenced 2216 Abv->Add(BitCodeAbbrevOp(0)); // InObjCContainer 2217 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Access 2218 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ModulePrivate 2219 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID 2220 // NamedDecl 2221 Abv->Add(BitCodeAbbrevOp(DeclarationName::Identifier)); // NameKind 2222 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Identifier 2223 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber 2224 // ValueDecl 2225 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type 2226 // DeclaratorDecl 2227 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerLocStart 2228 Abv->Add(BitCodeAbbrevOp(0)); // HasExtInfo 2229 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType 2230 // FunctionDecl 2231 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 11)); // IDNS 2232 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // StorageClass 2233 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Inline 2234 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InlineSpecified 2235 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // VirtualAsWritten 2236 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Pure 2237 Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedProto 2238 Abv->Add(BitCodeAbbrevOp(1)); // HasWrittenProto 2239 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Deleted 2240 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Trivial 2241 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // TrivialForCall 2242 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Defaulted 2243 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ExplicitlyDefaulted 2244 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ImplicitReturnZero 2245 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Constexpr 2246 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // UsesSEHTry 2247 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // SkippedBody 2248 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // MultiVersion 2249 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // LateParsed 2250 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage 2251 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LocEnd 2252 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // ODRHash 2253 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // TemplateKind 2254 // This Array slurps the rest of the record. Fortunately we want to encode 2255 // (nearly) all the remaining (variable number of) fields in the same way. 2256 // 2257 // This is the function template information if any, then 2258 // NumParams and Params[] from FunctionDecl, and 2259 // NumOverriddenMethods, OverriddenMethods[] from CXXMethodDecl. 2260 // 2261 // Add an AbbrevOp for 'size then elements' and use it here. 2262 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); 2263 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); 2264 DeclCXXMethodAbbrev = Stream.EmitAbbrev(std::move(Abv)); 2265 2266 // Abbreviation for EXPR_DECL_REF 2267 Abv = std::make_shared<BitCodeAbbrev>(); 2268 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_DECL_REF)); 2269 //Stmt 2270 // Expr 2271 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type 2272 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent 2273 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent 2274 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent 2275 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack 2276 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ContainsErrors 2277 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind 2278 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind 2279 //DeclRefExpr 2280 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HasQualifier 2281 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //GetDeclFound 2282 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ExplicitTemplateArgs 2283 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HadMultipleCandidates 2284 Abv->Add(BitCodeAbbrevOp(0)); // RefersToEnclosingVariableOrCapture 2285 Abv->Add(BitCodeAbbrevOp(0)); // NonOdrUseReason 2286 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclRef 2287 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location 2288 DeclRefExprAbbrev = Stream.EmitAbbrev(std::move(Abv)); 2289 2290 // Abbreviation for EXPR_INTEGER_LITERAL 2291 Abv = std::make_shared<BitCodeAbbrev>(); 2292 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_INTEGER_LITERAL)); 2293 //Stmt 2294 // Expr 2295 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type 2296 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent 2297 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent 2298 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent 2299 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack 2300 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ContainsErrors 2301 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind 2302 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind 2303 //Integer Literal 2304 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location 2305 Abv->Add(BitCodeAbbrevOp(32)); // Bit Width 2306 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Value 2307 IntegerLiteralAbbrev = Stream.EmitAbbrev(std::move(Abv)); 2308 2309 // Abbreviation for EXPR_CHARACTER_LITERAL 2310 Abv = std::make_shared<BitCodeAbbrev>(); 2311 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_CHARACTER_LITERAL)); 2312 //Stmt 2313 // Expr 2314 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type 2315 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent 2316 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent 2317 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent 2318 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack 2319 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ContainsErrors 2320 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind 2321 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind 2322 //Character Literal 2323 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getValue 2324 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location 2325 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // getKind 2326 CharacterLiteralAbbrev = Stream.EmitAbbrev(std::move(Abv)); 2327 2328 // Abbreviation for EXPR_IMPLICIT_CAST 2329 Abv = std::make_shared<BitCodeAbbrev>(); 2330 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_IMPLICIT_CAST)); 2331 // Stmt 2332 // Expr 2333 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type 2334 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent 2335 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent 2336 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent 2337 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack 2338 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ContainsErrors 2339 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind 2340 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind 2341 // CastExpr 2342 Abv->Add(BitCodeAbbrevOp(0)); // PathSize 2343 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // HasFPFeatures 2344 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 6)); // CastKind 2345 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // PartOfExplicitCast 2346 // ImplicitCastExpr 2347 ExprImplicitCastAbbrev = Stream.EmitAbbrev(std::move(Abv)); 2348 2349 Abv = std::make_shared<BitCodeAbbrev>(); 2350 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_LEXICAL)); 2351 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 2352 DeclContextLexicalAbbrev = Stream.EmitAbbrev(std::move(Abv)); 2353 2354 Abv = std::make_shared<BitCodeAbbrev>(); 2355 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_VISIBLE)); 2356 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 2357 DeclContextVisibleLookupAbbrev = Stream.EmitAbbrev(std::move(Abv)); 2358 } 2359 2360 /// isRequiredDecl - Check if this is a "required" Decl, which must be seen by 2361 /// consumers of the AST. 2362 /// 2363 /// Such decls will always be deserialized from the AST file, so we would like 2364 /// this to be as restrictive as possible. Currently the predicate is driven by 2365 /// code generation requirements, if other clients have a different notion of 2366 /// what is "required" then we may have to consider an alternate scheme where 2367 /// clients can iterate over the top-level decls and get information on them, 2368 /// without necessary deserializing them. We could explicitly require such 2369 /// clients to use a separate API call to "realize" the decl. This should be 2370 /// relatively painless since they would presumably only do it for top-level 2371 /// decls. 2372 static bool isRequiredDecl(const Decl *D, ASTContext &Context, 2373 bool WritingModule) { 2374 // An ObjCMethodDecl is never considered as "required" because its 2375 // implementation container always is. 2376 2377 // File scoped assembly or obj-c or OMP declare target implementation must be 2378 // seen. 2379 if (isa<FileScopeAsmDecl>(D) || isa<ObjCImplDecl>(D)) 2380 return true; 2381 2382 if (WritingModule && isPartOfPerModuleInitializer(D)) { 2383 // These declarations are part of the module initializer, and are emitted 2384 // if and when the module is imported, rather than being emitted eagerly. 2385 return false; 2386 } 2387 2388 return Context.DeclMustBeEmitted(D); 2389 } 2390 2391 void ASTWriter::WriteDecl(ASTContext &Context, Decl *D) { 2392 PrettyDeclStackTraceEntry CrashInfo(Context, D, SourceLocation(), 2393 "serializing"); 2394 2395 // Determine the ID for this declaration. 2396 serialization::DeclID ID; 2397 assert(!D->isFromASTFile() && "should not be emitting imported decl"); 2398 serialization::DeclID &IDR = DeclIDs[D]; 2399 if (IDR == 0) 2400 IDR = NextDeclID++; 2401 2402 ID = IDR; 2403 2404 assert(ID >= FirstDeclID && "invalid decl ID"); 2405 2406 RecordData Record; 2407 ASTDeclWriter W(*this, Context, Record); 2408 2409 // Build a record for this declaration 2410 W.Visit(D); 2411 2412 // Emit this declaration to the bitstream. 2413 uint64_t Offset = W.Emit(D); 2414 2415 // Record the offset for this declaration 2416 SourceLocation Loc = D->getLocation(); 2417 unsigned Index = ID - FirstDeclID; 2418 if (DeclOffsets.size() == Index) 2419 DeclOffsets.emplace_back(Loc, Offset, DeclTypesBlockStartOffset); 2420 else if (DeclOffsets.size() < Index) { 2421 // FIXME: Can/should this happen? 2422 DeclOffsets.resize(Index+1); 2423 DeclOffsets[Index].setLocation(Loc); 2424 DeclOffsets[Index].setBitOffset(Offset, DeclTypesBlockStartOffset); 2425 } else { 2426 llvm_unreachable("declarations should be emitted in ID order"); 2427 } 2428 2429 SourceManager &SM = Context.getSourceManager(); 2430 if (Loc.isValid() && SM.isLocalSourceLocation(Loc)) 2431 associateDeclWithFile(D, ID); 2432 2433 // Note declarations that should be deserialized eagerly so that we can add 2434 // them to a record in the AST file later. 2435 if (isRequiredDecl(D, Context, WritingModule)) 2436 EagerlyDeserializedDecls.push_back(ID); 2437 } 2438 2439 void ASTRecordWriter::AddFunctionDefinition(const FunctionDecl *FD) { 2440 // Switch case IDs are per function body. 2441 Writer->ClearSwitchCaseIDs(); 2442 2443 assert(FD->doesThisDeclarationHaveABody()); 2444 bool ModulesCodegen = false; 2445 if (!FD->isDependentContext()) { 2446 Optional<GVALinkage> Linkage; 2447 if (Writer->WritingModule && 2448 Writer->WritingModule->Kind == Module::ModuleInterfaceUnit) { 2449 // When building a C++ Modules TS module interface unit, a strong 2450 // definition in the module interface is provided by the compilation of 2451 // that module interface unit, not by its users. (Inline functions are 2452 // still emitted in module users.) 2453 Linkage = Writer->Context->GetGVALinkageForFunction(FD); 2454 ModulesCodegen = *Linkage == GVA_StrongExternal; 2455 } 2456 if (Writer->Context->getLangOpts().ModulesCodegen || 2457 (FD->hasAttr<DLLExportAttr>() && 2458 Writer->Context->getLangOpts().BuildingPCHWithObjectFile)) { 2459 2460 // Under -fmodules-codegen, codegen is performed for all non-internal, 2461 // non-always_inline functions, unless they are available elsewhere. 2462 if (!FD->hasAttr<AlwaysInlineAttr>()) { 2463 if (!Linkage) 2464 Linkage = Writer->Context->GetGVALinkageForFunction(FD); 2465 ModulesCodegen = 2466 *Linkage != GVA_Internal && *Linkage != GVA_AvailableExternally; 2467 } 2468 } 2469 } 2470 Record->push_back(ModulesCodegen); 2471 if (ModulesCodegen) 2472 Writer->ModularCodegenDecls.push_back(Writer->GetDeclRef(FD)); 2473 if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) { 2474 Record->push_back(CD->getNumCtorInitializers()); 2475 if (CD->getNumCtorInitializers()) 2476 AddCXXCtorInitializers( 2477 llvm::makeArrayRef(CD->init_begin(), CD->init_end())); 2478 } 2479 AddStmt(FD->getBody()); 2480 } 2481