| 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/DeclTemplate.h" |
| 17 | #include "clang/AST/DeclVisitor.h" |
| 18 | #include "clang/AST/Expr.h" |
| 19 | #include "clang/AST/OpenMPClause.h" |
| 20 | #include "clang/AST/PrettyDeclStackTrace.h" |
| 21 | #include "clang/Basic/SourceManager.h" |
| 22 | #include "clang/Serialization/ASTReader.h" |
| 23 | #include "clang/Serialization/ASTRecordWriter.h" |
| 24 | #include "llvm/Bitstream/BitstreamWriter.h" |
| 25 | #include "llvm/Support/ErrorHandling.h" |
| 26 | using namespace clang; |
| 27 | using namespace serialization; |
| 28 | |
| 29 | //===----------------------------------------------------------------------===// |
| 30 | // Utility functions |
| 31 | //===----------------------------------------------------------------------===// |
| 32 | |
| 33 | namespace { |
| 34 | |
| 35 | // Helper function that returns true if the decl passed in the argument is |
| 36 | // a defintion in dependent contxt. |
| 37 | template <typename DT> bool isDefinitionInDependentContext(DT *D) { |
| 38 | return D->isDependentContext() && D->isThisDeclarationADefinition(); |
| 39 | } |
| 40 | |
| 41 | } // namespace |
| 42 | |
| 43 | //===----------------------------------------------------------------------===// |
| 44 | // Declaration serialization |
| 45 | //===----------------------------------------------------------------------===// |
| 46 | |
| 47 | namespace clang { |
| 48 | class ASTDeclWriter : public DeclVisitor<ASTDeclWriter, void> { |
| 49 | ASTWriter &Writer; |
| 50 | ASTRecordWriter Record; |
| 51 | |
| 52 | serialization::DeclCode Code; |
| 53 | unsigned AbbrevToUse; |
| 54 | |
| 55 | bool GeneratingReducedBMI = false; |
| 56 | |
| 57 | public: |
| 58 | ASTDeclWriter(ASTWriter &Writer, ASTContext &Context, |
| 59 | ASTWriter::RecordDataImpl &Record, bool GeneratingReducedBMI) |
| 60 | : Writer(Writer), Record(Context, Writer, Record), |
| 61 | Code((serialization::DeclCode)0), AbbrevToUse(0), |
| 62 | GeneratingReducedBMI(GeneratingReducedBMI) {} |
| 63 | |
| 64 | uint64_t Emit(Decl *D) { |
| 65 | if (!Code) |
| 66 | llvm::report_fatal_error(reason: StringRef("unexpected declaration kind '" ) + |
| 67 | D->getDeclKindName() + "'" ); |
| 68 | return Record.Emit(Code, Abbrev: AbbrevToUse); |
| 69 | } |
| 70 | |
| 71 | void Visit(Decl *D); |
| 72 | |
| 73 | void VisitDecl(Decl *D); |
| 74 | void VisitPragmaCommentDecl(PragmaCommentDecl *D); |
| 75 | void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D); |
| 76 | void VisitTranslationUnitDecl(TranslationUnitDecl *D); |
| 77 | void VisitNamedDecl(NamedDecl *D); |
| 78 | void VisitLabelDecl(LabelDecl *LD); |
| 79 | void VisitNamespaceDecl(NamespaceDecl *D); |
| 80 | void VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| 81 | void VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
| 82 | void VisitTypeDecl(TypeDecl *D); |
| 83 | void VisitTypedefNameDecl(TypedefNameDecl *D); |
| 84 | void VisitTypedefDecl(TypedefDecl *D); |
| 85 | void VisitTypeAliasDecl(TypeAliasDecl *D); |
| 86 | void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
| 87 | void VisitUnresolvedUsingIfExistsDecl(UnresolvedUsingIfExistsDecl *D); |
| 88 | void VisitTagDecl(TagDecl *D); |
| 89 | void VisitEnumDecl(EnumDecl *D); |
| 90 | void VisitRecordDecl(RecordDecl *D); |
| 91 | void VisitCXXRecordDecl(CXXRecordDecl *D); |
| 92 | void VisitClassTemplateSpecializationDecl( |
| 93 | ClassTemplateSpecializationDecl *D); |
| 94 | void VisitClassTemplatePartialSpecializationDecl( |
| 95 | ClassTemplatePartialSpecializationDecl *D); |
| 96 | void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); |
| 97 | void VisitVarTemplatePartialSpecializationDecl( |
| 98 | VarTemplatePartialSpecializationDecl *D); |
| 99 | void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
| 100 | void VisitValueDecl(ValueDecl *D); |
| 101 | void VisitEnumConstantDecl(EnumConstantDecl *D); |
| 102 | void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
| 103 | void VisitDeclaratorDecl(DeclaratorDecl *D); |
| 104 | void VisitFunctionDecl(FunctionDecl *D); |
| 105 | void VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D); |
| 106 | void VisitCXXMethodDecl(CXXMethodDecl *D); |
| 107 | void VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 108 | void VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 109 | void VisitCXXConversionDecl(CXXConversionDecl *D); |
| 110 | void VisitFieldDecl(FieldDecl *D); |
| 111 | void VisitMSPropertyDecl(MSPropertyDecl *D); |
| 112 | void VisitMSGuidDecl(MSGuidDecl *D); |
| 113 | void VisitUnnamedGlobalConstantDecl(UnnamedGlobalConstantDecl *D); |
| 114 | void VisitTemplateParamObjectDecl(TemplateParamObjectDecl *D); |
| 115 | void VisitIndirectFieldDecl(IndirectFieldDecl *D); |
| 116 | void VisitVarDecl(VarDecl *D); |
| 117 | void VisitImplicitParamDecl(ImplicitParamDecl *D); |
| 118 | void VisitParmVarDecl(ParmVarDecl *D); |
| 119 | void VisitDecompositionDecl(DecompositionDecl *D); |
| 120 | void VisitBindingDecl(BindingDecl *D); |
| 121 | void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| 122 | void VisitTemplateDecl(TemplateDecl *D); |
| 123 | void VisitConceptDecl(ConceptDecl *D); |
| 124 | void VisitImplicitConceptSpecializationDecl( |
| 125 | ImplicitConceptSpecializationDecl *D); |
| 126 | void VisitRequiresExprBodyDecl(RequiresExprBodyDecl *D); |
| 127 | void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D); |
| 128 | void VisitClassTemplateDecl(ClassTemplateDecl *D); |
| 129 | void VisitVarTemplateDecl(VarTemplateDecl *D); |
| 130 | void VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
| 131 | void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
| 132 | void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); |
| 133 | void VisitUsingDecl(UsingDecl *D); |
| 134 | void VisitUsingEnumDecl(UsingEnumDecl *D); |
| 135 | void VisitUsingPackDecl(UsingPackDecl *D); |
| 136 | void VisitUsingShadowDecl(UsingShadowDecl *D); |
| 137 | void VisitConstructorUsingShadowDecl(ConstructorUsingShadowDecl *D); |
| 138 | void VisitLinkageSpecDecl(LinkageSpecDecl *D); |
| 139 | void VisitExportDecl(ExportDecl *D); |
| 140 | void VisitFileScopeAsmDecl(FileScopeAsmDecl *D); |
| 141 | void VisitTopLevelStmtDecl(TopLevelStmtDecl *D); |
| 142 | void VisitImportDecl(ImportDecl *D); |
| 143 | void VisitAccessSpecDecl(AccessSpecDecl *D); |
| 144 | void VisitFriendDecl(FriendDecl *D); |
| 145 | void VisitFriendTemplateDecl(FriendTemplateDecl *D); |
| 146 | void VisitStaticAssertDecl(StaticAssertDecl *D); |
| 147 | void VisitBlockDecl(BlockDecl *D); |
| 148 | void VisitOutlinedFunctionDecl(OutlinedFunctionDecl *D); |
| 149 | void VisitCapturedDecl(CapturedDecl *D); |
| 150 | void VisitEmptyDecl(EmptyDecl *D); |
| 151 | void VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D); |
| 152 | void VisitDeclContext(DeclContext *DC); |
| 153 | template <typename T> void VisitRedeclarable(Redeclarable<T> *D); |
| 154 | void VisitHLSLBufferDecl(HLSLBufferDecl *D); |
| 155 | |
| 156 | // FIXME: Put in the same order is DeclNodes.td? |
| 157 | void VisitObjCMethodDecl(ObjCMethodDecl *D); |
| 158 | void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); |
| 159 | void VisitObjCContainerDecl(ObjCContainerDecl *D); |
| 160 | void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
| 161 | void VisitObjCIvarDecl(ObjCIvarDecl *D); |
| 162 | void VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
| 163 | void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D); |
| 164 | void VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
| 165 | void VisitObjCImplDecl(ObjCImplDecl *D); |
| 166 | void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
| 167 | void VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
| 168 | void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D); |
| 169 | void VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
| 170 | void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
| 171 | void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D); |
| 172 | void VisitOMPAllocateDecl(OMPAllocateDecl *D); |
| 173 | void VisitOMPRequiresDecl(OMPRequiresDecl *D); |
| 174 | void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D); |
| 175 | void VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D); |
| 176 | void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D); |
| 177 | |
| 178 | void VisitOpenACCDeclareDecl(OpenACCDeclareDecl *D); |
| 179 | void VisitOpenACCRoutineDecl(OpenACCRoutineDecl *D); |
| 180 | |
| 181 | /// Add an Objective-C type parameter list to the given record. |
| 182 | void AddObjCTypeParamList(ObjCTypeParamList *typeParams) { |
| 183 | // Empty type parameter list. |
| 184 | if (!typeParams) { |
| 185 | Record.push_back(N: 0); |
| 186 | return; |
| 187 | } |
| 188 | |
| 189 | Record.push_back(N: typeParams->size()); |
| 190 | for (auto *typeParam : *typeParams) { |
| 191 | Record.AddDeclRef(D: typeParam); |
| 192 | } |
| 193 | Record.AddSourceLocation(Loc: typeParams->getLAngleLoc()); |
| 194 | Record.AddSourceLocation(Loc: typeParams->getRAngleLoc()); |
| 195 | } |
| 196 | |
| 197 | /// Add to the record the first declaration from each module file that |
| 198 | /// provides a declaration of D. The intent is to provide a sufficient |
| 199 | /// set such that reloading this set will load all current redeclarations. |
| 200 | void AddFirstDeclFromEachModule(const Decl *D, bool IncludeLocal) { |
| 201 | auto Firsts = Writer.CollectFirstDeclFromEachModule(D, IncludeLocal); |
| 202 | for (const auto &[_, First] : Firsts) |
| 203 | Record.AddDeclRef(D: First); |
| 204 | } |
| 205 | |
| 206 | template <typename T> bool shouldSkipWritingSpecializations(T *Spec) { |
| 207 | // Now we will only avoid writing specializations if we're generating |
| 208 | // reduced BMI. |
| 209 | if (!GeneratingReducedBMI) |
| 210 | return false; |
| 211 | |
| 212 | assert((isa<FunctionDecl, ClassTemplateSpecializationDecl, |
| 213 | VarTemplateSpecializationDecl>(Spec))); |
| 214 | |
| 215 | ArrayRef<TemplateArgument> Args; |
| 216 | if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(Spec)) |
| 217 | Args = CTSD->getTemplateArgs().asArray(); |
| 218 | else if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(Spec)) |
| 219 | Args = VTSD->getTemplateArgs().asArray(); |
| 220 | else |
| 221 | Args = cast<FunctionDecl>(Spec) |
| 222 | ->getTemplateSpecializationArgs() |
| 223 | ->asArray(); |
| 224 | |
| 225 | // If there is any template argument is TULocal, we can avoid writing the |
| 226 | // specialization since the consumers of reduced BMI won't get the |
| 227 | // specialization anyway. |
| 228 | for (const TemplateArgument &TA : Args) { |
| 229 | switch (TA.getKind()) { |
| 230 | case TemplateArgument::Type: { |
| 231 | Linkage L = TA.getAsType()->getLinkage(); |
| 232 | if (!isExternallyVisible(L)) |
| 233 | return true; |
| 234 | break; |
| 235 | } |
| 236 | case TemplateArgument::Declaration: |
| 237 | if (!TA.getAsDecl()->isExternallyVisible()) |
| 238 | return true; |
| 239 | break; |
| 240 | default: |
| 241 | break; |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | return false; |
| 246 | } |
| 247 | |
| 248 | /// Add to the record the first template specialization from each module |
| 249 | /// file that provides a declaration of D. We store the DeclId and an |
| 250 | /// ODRHash of the template arguments of D which should provide enough |
| 251 | /// information to load D only if the template instantiator needs it. |
| 252 | void AddFirstSpecializationDeclFromEachModule( |
| 253 | const Decl *D, llvm::SmallVectorImpl<const Decl *> &SpecsInMap, |
| 254 | llvm::SmallVectorImpl<const Decl *> &PartialSpecsInMap) { |
| 255 | assert((isa<ClassTemplateSpecializationDecl>(D) || |
| 256 | isa<VarTemplateSpecializationDecl>(D) || isa<FunctionDecl>(D)) && |
| 257 | "Must not be called with other decls" ); |
| 258 | auto Firsts = |
| 259 | Writer.CollectFirstDeclFromEachModule(D, /*IncludeLocal=*/true); |
| 260 | for (const auto &[_, First] : Firsts) { |
| 261 | if (shouldSkipWritingSpecializations(Spec: First)) |
| 262 | continue; |
| 263 | |
| 264 | if (isa<ClassTemplatePartialSpecializationDecl, |
| 265 | VarTemplatePartialSpecializationDecl>(Val: First)) |
| 266 | PartialSpecsInMap.push_back(Elt: First); |
| 267 | else |
| 268 | SpecsInMap.push_back(Elt: First); |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | /// Get the specialization decl from an entry in the specialization list. |
| 273 | template <typename EntryType> |
| 274 | typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType * |
| 275 | getSpecializationDecl(EntryType &T) { |
| 276 | return RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::getDecl(&T); |
| 277 | } |
| 278 | |
| 279 | /// Get the list of partial specializations from a template's common ptr. |
| 280 | template<typename T> |
| 281 | decltype(T::PartialSpecializations) &getPartialSpecializations(T *Common) { |
| 282 | return Common->PartialSpecializations; |
| 283 | } |
| 284 | MutableArrayRef<FunctionTemplateSpecializationInfo> |
| 285 | getPartialSpecializations(FunctionTemplateDecl::Common *) { |
| 286 | return {}; |
| 287 | } |
| 288 | |
| 289 | template<typename DeclTy> |
| 290 | void AddTemplateSpecializations(DeclTy *D) { |
| 291 | auto *Common = D->getCommonPtr(); |
| 292 | |
| 293 | // If we have any lazy specializations, and the external AST source is |
| 294 | // our chained AST reader, we can just write out the DeclIDs. Otherwise, |
| 295 | // we need to resolve them to actual declarations. |
| 296 | if (Writer.Chain != Record.getASTContext().getExternalSource() && |
| 297 | Writer.Chain && Writer.Chain->haveUnloadedSpecializations(D)) { |
| 298 | D->LoadLazySpecializations(); |
| 299 | assert(!Writer.Chain->haveUnloadedSpecializations(D)); |
| 300 | } |
| 301 | |
| 302 | // AddFirstSpecializationDeclFromEachModule might trigger deserialization, |
| 303 | // invalidating *Specializations iterators. |
| 304 | llvm::SmallVector<const Decl *, 16> AllSpecs; |
| 305 | for (auto &Entry : Common->Specializations) |
| 306 | AllSpecs.push_back(Elt: getSpecializationDecl(Entry)); |
| 307 | for (auto &Entry : getPartialSpecializations(Common)) |
| 308 | AllSpecs.push_back(Elt: getSpecializationDecl(Entry)); |
| 309 | |
| 310 | llvm::SmallVector<const Decl *, 16> Specs; |
| 311 | llvm::SmallVector<const Decl *, 16> PartialSpecs; |
| 312 | for (auto *D : AllSpecs) { |
| 313 | assert(D->isCanonicalDecl() && "non-canonical decl in set" ); |
| 314 | AddFirstSpecializationDeclFromEachModule(D, SpecsInMap&: Specs, PartialSpecsInMap&: PartialSpecs); |
| 315 | } |
| 316 | |
| 317 | Record.AddOffset(BitOffset: Writer.WriteSpecializationInfoLookupTable( |
| 318 | D, Specializations&: Specs, /*IsPartial=*/false)); |
| 319 | |
| 320 | // Function Template Decl doesn't have partial decls. |
| 321 | if (isa<FunctionTemplateDecl>(D)) { |
| 322 | assert(PartialSpecs.empty()); |
| 323 | return; |
| 324 | } |
| 325 | |
| 326 | Record.AddOffset(BitOffset: Writer.WriteSpecializationInfoLookupTable( |
| 327 | D, Specializations&: PartialSpecs, /*IsPartial=*/true)); |
| 328 | } |
| 329 | |
| 330 | /// Ensure that this template specialization is associated with the specified |
| 331 | /// template on reload. |
| 332 | void RegisterTemplateSpecialization(const Decl *Template, |
| 333 | const Decl *Specialization) { |
| 334 | Template = Template->getCanonicalDecl(); |
| 335 | |
| 336 | // If the canonical template is local, we'll write out this specialization |
| 337 | // when we emit it. |
| 338 | // FIXME: We can do the same thing if there is any local declaration of |
| 339 | // the template, to avoid emitting an update record. |
| 340 | if (!Template->isFromASTFile()) |
| 341 | return; |
| 342 | |
| 343 | // We only need to associate the first local declaration of the |
| 344 | // specialization. The other declarations will get pulled in by it. |
| 345 | if (Writer.getFirstLocalDecl(D: Specialization) != Specialization) |
| 346 | return; |
| 347 | |
| 348 | if (isa<ClassTemplatePartialSpecializationDecl, |
| 349 | VarTemplatePartialSpecializationDecl>(Val: Specialization)) |
| 350 | Writer.PartialSpecializationsUpdates[cast<NamedDecl>(Val: Template)] |
| 351 | .push_back(Elt: cast<NamedDecl>(Val: Specialization)); |
| 352 | else |
| 353 | Writer.SpecializationsUpdates[cast<NamedDecl>(Val: Template)].push_back( |
| 354 | Elt: cast<NamedDecl>(Val: Specialization)); |
| 355 | } |
| 356 | }; |
| 357 | } |
| 358 | |
| 359 | // When building a C++20 module interface unit or a partition unit, a |
| 360 | // strong definition in the module interface is provided by the |
| 361 | // compilation of that unit, not by its users. (Inline variables are still |
| 362 | // emitted in module users.) |
| 363 | static bool shouldVarGenerateHereOnly(const VarDecl *VD) { |
| 364 | if (VD->getStorageDuration() != SD_Static) |
| 365 | return false; |
| 366 | |
| 367 | if (VD->getDescribedVarTemplate()) |
| 368 | return false; |
| 369 | |
| 370 | Module *M = VD->getOwningModule(); |
| 371 | if (!M) |
| 372 | return false; |
| 373 | |
| 374 | M = M->getTopLevelModule(); |
| 375 | ASTContext &Ctx = VD->getASTContext(); |
| 376 | if (!M->isInterfaceOrPartition() && |
| 377 | (!VD->hasAttr<DLLExportAttr>() || |
| 378 | !Ctx.getLangOpts().BuildingPCHWithObjectFile)) |
| 379 | return false; |
| 380 | |
| 381 | return Ctx.GetGVALinkageForVariable(VD) >= GVA_StrongExternal; |
| 382 | } |
| 383 | |
| 384 | static bool shouldFunctionGenerateHereOnly(const FunctionDecl *FD) { |
| 385 | if (FD->isDependentContext()) |
| 386 | return false; |
| 387 | |
| 388 | ASTContext &Ctx = FD->getASTContext(); |
| 389 | auto Linkage = Ctx.GetGVALinkageForFunction(FD); |
| 390 | if (Ctx.getLangOpts().ModulesCodegen || |
| 391 | (FD->hasAttr<DLLExportAttr>() && |
| 392 | Ctx.getLangOpts().BuildingPCHWithObjectFile)) |
| 393 | // Under -fmodules-codegen, codegen is performed for all non-internal, |
| 394 | // non-always_inline functions, unless they are available elsewhere. |
| 395 | if (!FD->hasAttr<AlwaysInlineAttr>() && Linkage != GVA_Internal && |
| 396 | Linkage != GVA_AvailableExternally) |
| 397 | return true; |
| 398 | |
| 399 | Module *M = FD->getOwningModule(); |
| 400 | if (!M) |
| 401 | return false; |
| 402 | |
| 403 | M = M->getTopLevelModule(); |
| 404 | if (M->isInterfaceOrPartition()) |
| 405 | if (Linkage >= GVA_StrongExternal) |
| 406 | return true; |
| 407 | |
| 408 | return false; |
| 409 | } |
| 410 | |
| 411 | bool clang::CanElideDeclDef(const Decl *D) { |
| 412 | if (auto *FD = dyn_cast<FunctionDecl>(Val: D)) { |
| 413 | if (FD->isInlined() || FD->isConstexpr() || FD->isConsteval()) |
| 414 | return false; |
| 415 | |
| 416 | // If the function should be generated somewhere else, we shouldn't elide |
| 417 | // it. |
| 418 | if (!shouldFunctionGenerateHereOnly(FD)) |
| 419 | return false; |
| 420 | } |
| 421 | |
| 422 | if (auto *VD = dyn_cast<VarDecl>(Val: D)) { |
| 423 | if (VD->getDeclContext()->isDependentContext()) |
| 424 | return false; |
| 425 | |
| 426 | // Constant initialized variable may not affect the ABI, but they |
| 427 | // may be used in constant evaluation in the frontend, so we have |
| 428 | // to remain them. |
| 429 | if (VD->hasConstantInitialization() || VD->isConstexpr()) |
| 430 | return false; |
| 431 | |
| 432 | // If the variable should be generated somewhere else, we shouldn't elide |
| 433 | // it. |
| 434 | if (!shouldVarGenerateHereOnly(VD)) |
| 435 | return false; |
| 436 | } |
| 437 | |
| 438 | return true; |
| 439 | } |
| 440 | |
| 441 | void ASTDeclWriter::Visit(Decl *D) { |
| 442 | DeclVisitor<ASTDeclWriter>::Visit(D); |
| 443 | |
| 444 | // Source locations require array (variable-length) abbreviations. The |
| 445 | // abbreviation infrastructure requires that arrays are encoded last, so |
| 446 | // we handle it here in the case of those classes derived from DeclaratorDecl |
| 447 | if (auto *DD = dyn_cast<DeclaratorDecl>(Val: D)) { |
| 448 | if (auto *TInfo = DD->getTypeSourceInfo()) |
| 449 | Record.AddTypeLoc(TL: TInfo->getTypeLoc()); |
| 450 | } |
| 451 | |
| 452 | // Handle FunctionDecl's body here and write it after all other Stmts/Exprs |
| 453 | // have been written. We want it last because we will not read it back when |
| 454 | // retrieving it from the AST, we'll just lazily set the offset. |
| 455 | if (auto *FD = dyn_cast<FunctionDecl>(Val: D)) { |
| 456 | if (!GeneratingReducedBMI || !CanElideDeclDef(D: FD)) { |
| 457 | Record.push_back(N: FD->doesThisDeclarationHaveABody()); |
| 458 | if (FD->doesThisDeclarationHaveABody()) |
| 459 | Record.AddFunctionDefinition(FD); |
| 460 | } else |
| 461 | Record.push_back(N: 0); |
| 462 | } |
| 463 | |
| 464 | // Similar to FunctionDecls, handle VarDecl's initializer here and write it |
| 465 | // after all other Stmts/Exprs. We will not read the initializer until after |
| 466 | // we have finished recursive deserialization, because it can recursively |
| 467 | // refer back to the variable. |
| 468 | if (auto *VD = dyn_cast<VarDecl>(Val: D)) { |
| 469 | if (!GeneratingReducedBMI || !CanElideDeclDef(D: VD)) |
| 470 | Record.AddVarDeclInit(VD); |
| 471 | else |
| 472 | Record.push_back(N: 0); |
| 473 | } |
| 474 | |
| 475 | // And similarly for FieldDecls. We already serialized whether there is a |
| 476 | // default member initializer. |
| 477 | if (auto *FD = dyn_cast<FieldDecl>(Val: D)) { |
| 478 | if (FD->hasInClassInitializer()) { |
| 479 | if (Expr *Init = FD->getInClassInitializer()) { |
| 480 | Record.push_back(N: 1); |
| 481 | Record.AddStmt(S: Init); |
| 482 | } else { |
| 483 | Record.push_back(N: 0); |
| 484 | // Initializer has not been instantiated yet. |
| 485 | } |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | // If this declaration is also a DeclContext, write blocks for the |
| 490 | // declarations that lexically stored inside its context and those |
| 491 | // declarations that are visible from its context. |
| 492 | if (auto *DC = dyn_cast<DeclContext>(Val: D)) |
| 493 | VisitDeclContext(DC); |
| 494 | } |
| 495 | |
| 496 | void ASTDeclWriter::VisitDecl(Decl *D) { |
| 497 | BitsPacker DeclBits; |
| 498 | |
| 499 | // The order matters here. It will be better to put the bit with higher |
| 500 | // probability to be 0 in the end of the bits. |
| 501 | // |
| 502 | // Since we're using VBR6 format to store it. |
| 503 | // It will be pretty effient if all the higher bits are 0. |
| 504 | // For example, if we need to pack 8 bits into a value and the stored value |
| 505 | // is 0xf0, the actual stored value will be 0b000111'110000, which takes 12 |
| 506 | // bits actually. However, if we changed the order to be 0x0f, then we can |
| 507 | // store it as 0b001111, which takes 6 bits only now. |
| 508 | DeclBits.addBits(Value: (uint64_t)D->getModuleOwnershipKind(), /*BitWidth=*/BitsWidth: 3); |
| 509 | DeclBits.addBit(Value: D->isThisDeclarationReferenced()); |
| 510 | // If we're writing a BMI for a named module unit, we can treat all decls as in |
| 511 | // the BMI as used. Otherwise, the consumer need to mark it as used again, this |
| 512 | // simply waste time. |
| 513 | DeclBits.addBit(Value: Writer.isWritingStdCXXNamedModules() ? true : D->isUsed(CheckUsedAttr: false)); |
| 514 | DeclBits.addBits(Value: D->getAccess(), /*BitWidth=*/BitsWidth: 2); |
| 515 | DeclBits.addBit(Value: D->isImplicit()); |
| 516 | DeclBits.addBit(Value: D->getDeclContext() != D->getLexicalDeclContext()); |
| 517 | DeclBits.addBit(Value: D->hasAttrs()); |
| 518 | DeclBits.addBit(Value: D->isTopLevelDeclInObjCContainer()); |
| 519 | DeclBits.addBit(Value: D->isInvalidDecl()); |
| 520 | Record.push_back(N: DeclBits); |
| 521 | |
| 522 | Record.AddDeclRef(D: cast_or_null<Decl>(Val: D->getDeclContext())); |
| 523 | if (D->getDeclContext() != D->getLexicalDeclContext()) |
| 524 | Record.AddDeclRef(D: cast_or_null<Decl>(Val: D->getLexicalDeclContext())); |
| 525 | |
| 526 | if (D->hasAttrs()) |
| 527 | Record.AddAttributes(Attrs: D->getAttrs()); |
| 528 | |
| 529 | Record.push_back(N: Writer.getSubmoduleID(Mod: D->getOwningModule())); |
| 530 | |
| 531 | // If this declaration injected a name into a context different from its |
| 532 | // lexical context, and that context is an imported namespace, we need to |
| 533 | // update its visible declarations to include this name. |
| 534 | // |
| 535 | // This happens when we instantiate a class with a friend declaration or a |
| 536 | // function with a local extern declaration, for instance. |
| 537 | // |
| 538 | // FIXME: Can we handle this in AddedVisibleDecl instead? |
| 539 | if (D->isOutOfLine()) { |
| 540 | auto *DC = D->getDeclContext(); |
| 541 | while (auto *NS = dyn_cast<NamespaceDecl>(Val: DC->getRedeclContext())) { |
| 542 | if (!NS->isFromASTFile()) |
| 543 | break; |
| 544 | Writer.UpdatedDeclContexts.insert(X: NS->getPrimaryContext()); |
| 545 | if (!NS->isInlineNamespace()) |
| 546 | break; |
| 547 | DC = NS->getParent(); |
| 548 | } |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | void ASTDeclWriter::(PragmaCommentDecl *D) { |
| 553 | StringRef Arg = D->getArg(); |
| 554 | Record.push_back(N: Arg.size()); |
| 555 | VisitDecl(D); |
| 556 | Record.AddSourceLocation(Loc: D->getBeginLoc()); |
| 557 | Record.push_back(N: D->getCommentKind()); |
| 558 | Record.AddString(Str: Arg); |
| 559 | Code = serialization::DECL_PRAGMA_COMMENT; |
| 560 | } |
| 561 | |
| 562 | void ASTDeclWriter::VisitPragmaDetectMismatchDecl( |
| 563 | PragmaDetectMismatchDecl *D) { |
| 564 | StringRef Name = D->getName(); |
| 565 | StringRef Value = D->getValue(); |
| 566 | Record.push_back(N: Name.size() + 1 + Value.size()); |
| 567 | VisitDecl(D); |
| 568 | Record.AddSourceLocation(Loc: D->getBeginLoc()); |
| 569 | Record.AddString(Str: Name); |
| 570 | Record.AddString(Str: Value); |
| 571 | Code = serialization::DECL_PRAGMA_DETECT_MISMATCH; |
| 572 | } |
| 573 | |
| 574 | void ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
| 575 | llvm_unreachable("Translation units aren't directly serialized" ); |
| 576 | } |
| 577 | |
| 578 | void ASTDeclWriter::VisitNamedDecl(NamedDecl *D) { |
| 579 | VisitDecl(D); |
| 580 | Record.AddDeclarationName(Name: D->getDeclName()); |
| 581 | Record.push_back(N: needsAnonymousDeclarationNumber(D) |
| 582 | ? Writer.getAnonymousDeclarationNumber(D) |
| 583 | : 0); |
| 584 | } |
| 585 | |
| 586 | void ASTDeclWriter::VisitTypeDecl(TypeDecl *D) { |
| 587 | VisitNamedDecl(D); |
| 588 | Record.AddSourceLocation(Loc: D->getBeginLoc()); |
| 589 | if (!isa<TagDecl, TypedefDecl, TypeAliasDecl>(Val: D)) |
| 590 | Record.AddTypeRef(T: QualType(D->getTypeForDecl(), 0)); |
| 591 | } |
| 592 | |
| 593 | void ASTDeclWriter::VisitTypedefNameDecl(TypedefNameDecl *D) { |
| 594 | VisitRedeclarable(D); |
| 595 | VisitTypeDecl(D); |
| 596 | Record.AddTypeSourceInfo(TInfo: D->getTypeSourceInfo()); |
| 597 | Record.push_back(N: D->isModed()); |
| 598 | if (D->isModed()) |
| 599 | Record.AddTypeRef(T: D->getUnderlyingType()); |
| 600 | Record.AddDeclRef(D: D->getAnonDeclWithTypedefName(AnyRedecl: false)); |
| 601 | } |
| 602 | |
| 603 | void ASTDeclWriter::VisitTypedefDecl(TypedefDecl *D) { |
| 604 | VisitTypedefNameDecl(D); |
| 605 | if (D->getDeclContext() == D->getLexicalDeclContext() && |
| 606 | !D->hasAttrs() && |
| 607 | !D->isImplicit() && |
| 608 | D->getFirstDecl() == D->getMostRecentDecl() && |
| 609 | !D->isInvalidDecl() && |
| 610 | !D->isTopLevelDeclInObjCContainer() && |
| 611 | !D->isModulePrivate() && |
| 612 | !needsAnonymousDeclarationNumber(D) && |
| 613 | D->getDeclName().getNameKind() == DeclarationName::Identifier) |
| 614 | AbbrevToUse = Writer.getDeclTypedefAbbrev(); |
| 615 | |
| 616 | Code = serialization::DECL_TYPEDEF; |
| 617 | } |
| 618 | |
| 619 | void ASTDeclWriter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
| 620 | VisitTypedefNameDecl(D); |
| 621 | Record.AddDeclRef(D: D->getDescribedAliasTemplate()); |
| 622 | Code = serialization::DECL_TYPEALIAS; |
| 623 | } |
| 624 | |
| 625 | void ASTDeclWriter::VisitTagDecl(TagDecl *D) { |
| 626 | static_assert(DeclContext::NumTagDeclBits == 23, |
| 627 | "You need to update the serializer after you change the " |
| 628 | "TagDeclBits" ); |
| 629 | |
| 630 | VisitRedeclarable(D); |
| 631 | VisitTypeDecl(D); |
| 632 | Record.push_back(N: D->getIdentifierNamespace()); |
| 633 | |
| 634 | BitsPacker TagDeclBits; |
| 635 | TagDeclBits.addBits(Value: llvm::to_underlying(E: D->getTagKind()), /*BitWidth=*/BitsWidth: 3); |
| 636 | TagDeclBits.addBit(Value: !isa<CXXRecordDecl>(Val: D) ? D->isCompleteDefinition() : 0); |
| 637 | TagDeclBits.addBit(Value: D->isEmbeddedInDeclarator()); |
| 638 | TagDeclBits.addBit(Value: D->isFreeStanding()); |
| 639 | TagDeclBits.addBit(Value: D->isCompleteDefinitionRequired()); |
| 640 | TagDeclBits.addBits( |
| 641 | Value: D->hasExtInfo() ? 1 : (D->getTypedefNameForAnonDecl() ? 2 : 0), |
| 642 | /*BitWidth=*/BitsWidth: 2); |
| 643 | Record.push_back(N: TagDeclBits); |
| 644 | |
| 645 | Record.AddSourceRange(Range: D->getBraceRange()); |
| 646 | |
| 647 | if (D->hasExtInfo()) { |
| 648 | Record.AddQualifierInfo(Info: *D->getExtInfo()); |
| 649 | } else if (auto *TD = D->getTypedefNameForAnonDecl()) { |
| 650 | Record.AddDeclRef(D: TD); |
| 651 | Record.AddIdentifierRef(II: TD->getDeclName().getAsIdentifierInfo()); |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) { |
| 656 | static_assert(DeclContext::NumEnumDeclBits == 43, |
| 657 | "You need to update the serializer after you change the " |
| 658 | "EnumDeclBits" ); |
| 659 | |
| 660 | VisitTagDecl(D); |
| 661 | Record.AddTypeSourceInfo(TInfo: D->getIntegerTypeSourceInfo()); |
| 662 | if (!D->getIntegerTypeSourceInfo()) |
| 663 | Record.AddTypeRef(T: D->getIntegerType()); |
| 664 | Record.AddTypeRef(T: D->getPromotionType()); |
| 665 | |
| 666 | BitsPacker EnumDeclBits; |
| 667 | EnumDeclBits.addBits(Value: D->getNumPositiveBits(), /*BitWidth=*/BitsWidth: 8); |
| 668 | EnumDeclBits.addBits(Value: D->getNumNegativeBits(), /*BitWidth=*/BitsWidth: 8); |
| 669 | EnumDeclBits.addBit(Value: D->isScoped()); |
| 670 | EnumDeclBits.addBit(Value: D->isScopedUsingClassTag()); |
| 671 | EnumDeclBits.addBit(Value: D->isFixed()); |
| 672 | Record.push_back(N: EnumDeclBits); |
| 673 | |
| 674 | Record.push_back(N: D->getODRHash()); |
| 675 | |
| 676 | if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) { |
| 677 | Record.AddDeclRef(D: MemberInfo->getInstantiatedFrom()); |
| 678 | Record.push_back(N: MemberInfo->getTemplateSpecializationKind()); |
| 679 | Record.AddSourceLocation(Loc: MemberInfo->getPointOfInstantiation()); |
| 680 | } else { |
| 681 | Record.AddDeclRef(D: nullptr); |
| 682 | } |
| 683 | |
| 684 | if (D->getDeclContext() == D->getLexicalDeclContext() && !D->hasAttrs() && |
| 685 | !D->isInvalidDecl() && !D->isImplicit() && !D->hasExtInfo() && |
| 686 | !D->getTypedefNameForAnonDecl() && |
| 687 | D->getFirstDecl() == D->getMostRecentDecl() && |
| 688 | !D->isTopLevelDeclInObjCContainer() && |
| 689 | !CXXRecordDecl::classofKind(K: D->getKind()) && |
| 690 | !D->getIntegerTypeSourceInfo() && !D->getMemberSpecializationInfo() && |
| 691 | !needsAnonymousDeclarationNumber(D) && |
| 692 | D->getDeclName().getNameKind() == DeclarationName::Identifier) |
| 693 | AbbrevToUse = Writer.getDeclEnumAbbrev(); |
| 694 | |
| 695 | Code = serialization::DECL_ENUM; |
| 696 | } |
| 697 | |
| 698 | void ASTDeclWriter::VisitRecordDecl(RecordDecl *D) { |
| 699 | static_assert(DeclContext::NumRecordDeclBits == 64, |
| 700 | "You need to update the serializer after you change the " |
| 701 | "RecordDeclBits" ); |
| 702 | |
| 703 | VisitTagDecl(D); |
| 704 | |
| 705 | BitsPacker RecordDeclBits; |
| 706 | RecordDeclBits.addBit(Value: D->hasFlexibleArrayMember()); |
| 707 | RecordDeclBits.addBit(Value: D->isAnonymousStructOrUnion()); |
| 708 | RecordDeclBits.addBit(Value: D->hasObjectMember()); |
| 709 | RecordDeclBits.addBit(Value: D->hasVolatileMember()); |
| 710 | RecordDeclBits.addBit(Value: D->isNonTrivialToPrimitiveDefaultInitialize()); |
| 711 | RecordDeclBits.addBit(Value: D->isNonTrivialToPrimitiveCopy()); |
| 712 | RecordDeclBits.addBit(Value: D->isNonTrivialToPrimitiveDestroy()); |
| 713 | RecordDeclBits.addBit(Value: D->hasNonTrivialToPrimitiveDefaultInitializeCUnion()); |
| 714 | RecordDeclBits.addBit(Value: D->hasNonTrivialToPrimitiveDestructCUnion()); |
| 715 | RecordDeclBits.addBit(Value: D->hasNonTrivialToPrimitiveCopyCUnion()); |
| 716 | RecordDeclBits.addBit(Value: D->hasUninitializedExplicitInitFields()); |
| 717 | RecordDeclBits.addBit(Value: D->isParamDestroyedInCallee()); |
| 718 | RecordDeclBits.addBits(Value: llvm::to_underlying(E: D->getArgPassingRestrictions()), BitsWidth: 2); |
| 719 | Record.push_back(N: RecordDeclBits); |
| 720 | |
| 721 | // Only compute this for C/Objective-C, in C++ this is computed as part |
| 722 | // of CXXRecordDecl. |
| 723 | if (!isa<CXXRecordDecl>(Val: D)) |
| 724 | Record.push_back(N: D->getODRHash()); |
| 725 | |
| 726 | if (D->getDeclContext() == D->getLexicalDeclContext() && !D->hasAttrs() && |
| 727 | !D->isImplicit() && !D->isInvalidDecl() && !D->hasExtInfo() && |
| 728 | !D->getTypedefNameForAnonDecl() && |
| 729 | D->getFirstDecl() == D->getMostRecentDecl() && |
| 730 | !D->isTopLevelDeclInObjCContainer() && |
| 731 | !CXXRecordDecl::classofKind(K: D->getKind()) && |
| 732 | !needsAnonymousDeclarationNumber(D) && |
| 733 | D->getDeclName().getNameKind() == DeclarationName::Identifier) |
| 734 | AbbrevToUse = Writer.getDeclRecordAbbrev(); |
| 735 | |
| 736 | Code = serialization::DECL_RECORD; |
| 737 | } |
| 738 | |
| 739 | void ASTDeclWriter::VisitValueDecl(ValueDecl *D) { |
| 740 | VisitNamedDecl(D); |
| 741 | Record.AddTypeRef(T: D->getType()); |
| 742 | } |
| 743 | |
| 744 | void ASTDeclWriter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
| 745 | VisitValueDecl(D); |
| 746 | Record.push_back(N: D->getInitExpr()? 1 : 0); |
| 747 | if (D->getInitExpr()) |
| 748 | Record.AddStmt(S: D->getInitExpr()); |
| 749 | Record.AddAPSInt(Value: D->getInitVal()); |
| 750 | |
| 751 | Code = serialization::DECL_ENUM_CONSTANT; |
| 752 | } |
| 753 | |
| 754 | void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) { |
| 755 | VisitValueDecl(D); |
| 756 | Record.AddSourceLocation(Loc: D->getInnerLocStart()); |
| 757 | Record.push_back(N: D->hasExtInfo()); |
| 758 | if (D->hasExtInfo()) { |
| 759 | DeclaratorDecl::ExtInfo *Info = D->getExtInfo(); |
| 760 | Record.AddQualifierInfo(Info: *Info); |
| 761 | Record.AddStmt( |
| 762 | S: const_cast<Expr *>(Info->TrailingRequiresClause.ConstraintExpr)); |
| 763 | Record.writeUnsignedOrNone(Value: Info->TrailingRequiresClause.ArgPackSubstIndex); |
| 764 | } |
| 765 | // The location information is deferred until the end of the record. |
| 766 | Record.AddTypeRef(T: D->getTypeSourceInfo() ? D->getTypeSourceInfo()->getType() |
| 767 | : QualType()); |
| 768 | } |
| 769 | |
| 770 | void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) { |
| 771 | static_assert(DeclContext::NumFunctionDeclBits == 45, |
| 772 | "You need to update the serializer after you change the " |
| 773 | "FunctionDeclBits" ); |
| 774 | |
| 775 | VisitRedeclarable(D); |
| 776 | |
| 777 | Record.push_back(N: D->getTemplatedKind()); |
| 778 | switch (D->getTemplatedKind()) { |
| 779 | case FunctionDecl::TK_NonTemplate: |
| 780 | break; |
| 781 | case FunctionDecl::TK_DependentNonTemplate: |
| 782 | Record.AddDeclRef(D: D->getInstantiatedFromDecl()); |
| 783 | break; |
| 784 | case FunctionDecl::TK_FunctionTemplate: |
| 785 | Record.AddDeclRef(D: D->getDescribedFunctionTemplate()); |
| 786 | break; |
| 787 | case FunctionDecl::TK_MemberSpecialization: { |
| 788 | MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo(); |
| 789 | Record.AddDeclRef(D: MemberInfo->getInstantiatedFrom()); |
| 790 | Record.push_back(N: MemberInfo->getTemplateSpecializationKind()); |
| 791 | Record.AddSourceLocation(Loc: MemberInfo->getPointOfInstantiation()); |
| 792 | break; |
| 793 | } |
| 794 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
| 795 | FunctionTemplateSpecializationInfo * |
| 796 | FTSInfo = D->getTemplateSpecializationInfo(); |
| 797 | |
| 798 | RegisterTemplateSpecialization(Template: FTSInfo->getTemplate(), Specialization: D); |
| 799 | |
| 800 | Record.AddDeclRef(D: FTSInfo->getTemplate()); |
| 801 | Record.push_back(N: FTSInfo->getTemplateSpecializationKind()); |
| 802 | |
| 803 | // Template arguments. |
| 804 | Record.AddTemplateArgumentList(TemplateArgs: FTSInfo->TemplateArguments); |
| 805 | |
| 806 | // Template args as written. |
| 807 | Record.push_back(N: FTSInfo->TemplateArgumentsAsWritten != nullptr); |
| 808 | if (FTSInfo->TemplateArgumentsAsWritten) |
| 809 | Record.AddASTTemplateArgumentListInfo( |
| 810 | ASTTemplArgList: FTSInfo->TemplateArgumentsAsWritten); |
| 811 | |
| 812 | Record.AddSourceLocation(Loc: FTSInfo->getPointOfInstantiation()); |
| 813 | |
| 814 | if (MemberSpecializationInfo *MemberInfo = |
| 815 | FTSInfo->getMemberSpecializationInfo()) { |
| 816 | Record.push_back(N: 1); |
| 817 | Record.AddDeclRef(D: MemberInfo->getInstantiatedFrom()); |
| 818 | Record.push_back(N: MemberInfo->getTemplateSpecializationKind()); |
| 819 | Record.AddSourceLocation(Loc: MemberInfo->getPointOfInstantiation()); |
| 820 | } else { |
| 821 | Record.push_back(N: 0); |
| 822 | } |
| 823 | |
| 824 | if (D->isCanonicalDecl()) { |
| 825 | // Write the template that contains the specializations set. We will |
| 826 | // add a FunctionTemplateSpecializationInfo to it when reading. |
| 827 | Record.AddDeclRef(D: FTSInfo->getTemplate()->getCanonicalDecl()); |
| 828 | } |
| 829 | break; |
| 830 | } |
| 831 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 832 | DependentFunctionTemplateSpecializationInfo * |
| 833 | DFTSInfo = D->getDependentSpecializationInfo(); |
| 834 | |
| 835 | // Candidates. |
| 836 | Record.push_back(N: DFTSInfo->getCandidates().size()); |
| 837 | for (FunctionTemplateDecl *FTD : DFTSInfo->getCandidates()) |
| 838 | Record.AddDeclRef(D: FTD); |
| 839 | |
| 840 | // Templates args. |
| 841 | Record.push_back(N: DFTSInfo->TemplateArgumentsAsWritten != nullptr); |
| 842 | if (DFTSInfo->TemplateArgumentsAsWritten) |
| 843 | Record.AddASTTemplateArgumentListInfo( |
| 844 | ASTTemplArgList: DFTSInfo->TemplateArgumentsAsWritten); |
| 845 | break; |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | VisitDeclaratorDecl(D); |
| 850 | Record.AddDeclarationNameLoc(DNLoc: D->DNLoc, Name: D->getDeclName()); |
| 851 | Record.push_back(N: D->getIdentifierNamespace()); |
| 852 | |
| 853 | // The order matters here. It will be better to put the bit with higher |
| 854 | // probability to be 0 in the end of the bits. See the comments in VisitDecl |
| 855 | // for details. |
| 856 | BitsPacker FunctionDeclBits; |
| 857 | // FIXME: stable encoding |
| 858 | FunctionDeclBits.addBits(Value: llvm::to_underlying(E: D->getLinkageInternal()), BitsWidth: 3); |
| 859 | FunctionDeclBits.addBits(Value: (uint32_t)D->getStorageClass(), /*BitWidth=*/BitsWidth: 3); |
| 860 | FunctionDeclBits.addBit(Value: D->isInlineSpecified()); |
| 861 | FunctionDeclBits.addBit(Value: D->isInlined()); |
| 862 | FunctionDeclBits.addBit(Value: D->hasSkippedBody()); |
| 863 | FunctionDeclBits.addBit(Value: D->isVirtualAsWritten()); |
| 864 | FunctionDeclBits.addBit(Value: D->isPureVirtual()); |
| 865 | FunctionDeclBits.addBit(Value: D->hasInheritedPrototype()); |
| 866 | FunctionDeclBits.addBit(Value: D->hasWrittenPrototype()); |
| 867 | FunctionDeclBits.addBit(Value: D->isDeletedBit()); |
| 868 | FunctionDeclBits.addBit(Value: D->isTrivial()); |
| 869 | FunctionDeclBits.addBit(Value: D->isTrivialForCall()); |
| 870 | FunctionDeclBits.addBit(Value: D->isDefaulted()); |
| 871 | FunctionDeclBits.addBit(Value: D->isExplicitlyDefaulted()); |
| 872 | FunctionDeclBits.addBit(Value: D->isIneligibleOrNotSelected()); |
| 873 | FunctionDeclBits.addBits(Value: (uint64_t)(D->getConstexprKind()), /*BitWidth=*/BitsWidth: 2); |
| 874 | FunctionDeclBits.addBit(Value: D->hasImplicitReturnZero()); |
| 875 | FunctionDeclBits.addBit(Value: D->isMultiVersion()); |
| 876 | FunctionDeclBits.addBit(Value: D->isLateTemplateParsed()); |
| 877 | FunctionDeclBits.addBit(Value: D->isInstantiatedFromMemberTemplate()); |
| 878 | FunctionDeclBits.addBit(Value: D->FriendConstraintRefersToEnclosingTemplate()); |
| 879 | FunctionDeclBits.addBit(Value: D->usesSEHTry()); |
| 880 | FunctionDeclBits.addBit(Value: D->isDestroyingOperatorDelete()); |
| 881 | FunctionDeclBits.addBit(Value: D->isTypeAwareOperatorNewOrDelete()); |
| 882 | Record.push_back(N: FunctionDeclBits); |
| 883 | |
| 884 | Record.AddSourceLocation(Loc: D->getEndLoc()); |
| 885 | if (D->isExplicitlyDefaulted()) |
| 886 | Record.AddSourceLocation(Loc: D->getDefaultLoc()); |
| 887 | |
| 888 | Record.push_back(N: D->getODRHash()); |
| 889 | |
| 890 | if (D->isDefaulted() || D->isDeletedAsWritten()) { |
| 891 | if (auto *FDI = D->getDefaultedOrDeletedInfo()) { |
| 892 | // Store both that there is an DefaultedOrDeletedInfo and whether it |
| 893 | // contains a DeletedMessage. |
| 894 | StringLiteral *DeletedMessage = FDI->getDeletedMessage(); |
| 895 | Record.push_back(N: 1 | (DeletedMessage ? 2 : 0)); |
| 896 | if (DeletedMessage) |
| 897 | Record.AddStmt(S: DeletedMessage); |
| 898 | |
| 899 | Record.push_back(N: FDI->getUnqualifiedLookups().size()); |
| 900 | for (DeclAccessPair P : FDI->getUnqualifiedLookups()) { |
| 901 | Record.AddDeclRef(D: P.getDecl()); |
| 902 | Record.push_back(N: P.getAccess()); |
| 903 | } |
| 904 | } else { |
| 905 | Record.push_back(N: 0); |
| 906 | } |
| 907 | } |
| 908 | |
| 909 | if (D->getFriendObjectKind()) { |
| 910 | // For a friend function defined inline within a class template, we have to |
| 911 | // force the definition to be the one inside the definition of the template |
| 912 | // class. Remember this relation to deserialize them together. |
| 913 | if (auto *RD = dyn_cast<CXXRecordDecl>(Val: D->getLexicalParent()); |
| 914 | RD && isDefinitionInDependentContext(D: RD)) { |
| 915 | Writer.RelatedDeclsMap[Writer.GetDeclRef(D: RD)].push_back( |
| 916 | Elt: Writer.GetDeclRef(D)); |
| 917 | } |
| 918 | } |
| 919 | |
| 920 | Record.push_back(N: D->param_size()); |
| 921 | for (auto *P : D->parameters()) |
| 922 | Record.AddDeclRef(D: P); |
| 923 | Code = serialization::DECL_FUNCTION; |
| 924 | } |
| 925 | |
| 926 | static void addExplicitSpecifier(ExplicitSpecifier ES, |
| 927 | ASTRecordWriter &Record) { |
| 928 | uint64_t Kind = static_cast<uint64_t>(ES.getKind()); |
| 929 | Kind = Kind << 1 | static_cast<bool>(ES.getExpr()); |
| 930 | Record.push_back(N: Kind); |
| 931 | if (ES.getExpr()) { |
| 932 | Record.AddStmt(S: ES.getExpr()); |
| 933 | } |
| 934 | } |
| 935 | |
| 936 | void ASTDeclWriter::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) { |
| 937 | addExplicitSpecifier(ES: D->getExplicitSpecifier(), Record); |
| 938 | Record.AddDeclRef(D: D->Ctor); |
| 939 | VisitFunctionDecl(D); |
| 940 | Record.push_back(N: static_cast<unsigned char>(D->getDeductionCandidateKind())); |
| 941 | Record.AddDeclRef(D: D->getSourceDeductionGuide()); |
| 942 | Record.push_back( |
| 943 | N: static_cast<unsigned char>(D->getSourceDeductionGuideKind())); |
| 944 | Code = serialization::DECL_CXX_DEDUCTION_GUIDE; |
| 945 | } |
| 946 | |
| 947 | void ASTDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
| 948 | static_assert(DeclContext::NumObjCMethodDeclBits == 37, |
| 949 | "You need to update the serializer after you change the " |
| 950 | "ObjCMethodDeclBits" ); |
| 951 | |
| 952 | VisitNamedDecl(D); |
| 953 | // FIXME: convert to LazyStmtPtr? |
| 954 | // Unlike C/C++, method bodies will never be in header files. |
| 955 | bool HasBodyStuff = D->getBody() != nullptr; |
| 956 | Record.push_back(N: HasBodyStuff); |
| 957 | if (HasBodyStuff) { |
| 958 | Record.AddStmt(S: D->getBody()); |
| 959 | } |
| 960 | Record.AddDeclRef(D: D->getSelfDecl()); |
| 961 | Record.AddDeclRef(D: D->getCmdDecl()); |
| 962 | Record.push_back(N: D->isInstanceMethod()); |
| 963 | Record.push_back(N: D->isVariadic()); |
| 964 | Record.push_back(N: D->isPropertyAccessor()); |
| 965 | Record.push_back(N: D->isSynthesizedAccessorStub()); |
| 966 | Record.push_back(N: D->isDefined()); |
| 967 | Record.push_back(N: D->isOverriding()); |
| 968 | Record.push_back(N: D->hasSkippedBody()); |
| 969 | |
| 970 | Record.push_back(N: D->isRedeclaration()); |
| 971 | Record.push_back(N: D->hasRedeclaration()); |
| 972 | if (D->hasRedeclaration()) { |
| 973 | assert(Record.getASTContext().getObjCMethodRedeclaration(D)); |
| 974 | Record.AddDeclRef(D: Record.getASTContext().getObjCMethodRedeclaration(MD: D)); |
| 975 | } |
| 976 | |
| 977 | // FIXME: stable encoding for @required/@optional |
| 978 | Record.push_back(N: llvm::to_underlying(E: D->getImplementationControl())); |
| 979 | // FIXME: stable encoding for in/out/inout/bycopy/byref/oneway/nullability |
| 980 | Record.push_back(N: D->getObjCDeclQualifier()); |
| 981 | Record.push_back(N: D->hasRelatedResultType()); |
| 982 | Record.AddTypeRef(T: D->getReturnType()); |
| 983 | Record.AddTypeSourceInfo(TInfo: D->getReturnTypeSourceInfo()); |
| 984 | Record.AddSourceLocation(Loc: D->getEndLoc()); |
| 985 | Record.push_back(N: D->param_size()); |
| 986 | for (const auto *P : D->parameters()) |
| 987 | Record.AddDeclRef(D: P); |
| 988 | |
| 989 | Record.push_back(N: D->getSelLocsKind()); |
| 990 | unsigned NumStoredSelLocs = D->getNumStoredSelLocs(); |
| 991 | SourceLocation *SelLocs = D->getStoredSelLocs(); |
| 992 | Record.push_back(N: NumStoredSelLocs); |
| 993 | for (unsigned i = 0; i != NumStoredSelLocs; ++i) |
| 994 | Record.AddSourceLocation(Loc: SelLocs[i]); |
| 995 | |
| 996 | Code = serialization::DECL_OBJC_METHOD; |
| 997 | } |
| 998 | |
| 999 | void ASTDeclWriter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
| 1000 | VisitTypedefNameDecl(D); |
| 1001 | Record.push_back(N: D->Variance); |
| 1002 | Record.push_back(N: D->Index); |
| 1003 | Record.AddSourceLocation(Loc: D->VarianceLoc); |
| 1004 | Record.AddSourceLocation(Loc: D->ColonLoc); |
| 1005 | |
| 1006 | Code = serialization::DECL_OBJC_TYPE_PARAM; |
| 1007 | } |
| 1008 | |
| 1009 | void ASTDeclWriter::VisitObjCContainerDecl(ObjCContainerDecl *D) { |
| 1010 | static_assert(DeclContext::NumObjCContainerDeclBits == 64, |
| 1011 | "You need to update the serializer after you change the " |
| 1012 | "ObjCContainerDeclBits" ); |
| 1013 | |
| 1014 | VisitNamedDecl(D); |
| 1015 | Record.AddSourceLocation(Loc: D->getAtStartLoc()); |
| 1016 | Record.AddSourceRange(Range: D->getAtEndRange()); |
| 1017 | // Abstract class (no need to define a stable serialization::DECL code). |
| 1018 | } |
| 1019 | |
| 1020 | void ASTDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
| 1021 | VisitRedeclarable(D); |
| 1022 | VisitObjCContainerDecl(D); |
| 1023 | Record.AddTypeRef(T: QualType(D->getTypeForDecl(), 0)); |
| 1024 | AddObjCTypeParamList(typeParams: D->TypeParamList); |
| 1025 | |
| 1026 | Record.push_back(N: D->isThisDeclarationADefinition()); |
| 1027 | if (D->isThisDeclarationADefinition()) { |
| 1028 | // Write the DefinitionData |
| 1029 | ObjCInterfaceDecl::DefinitionData &Data = D->data(); |
| 1030 | |
| 1031 | Record.AddTypeSourceInfo(TInfo: D->getSuperClassTInfo()); |
| 1032 | Record.AddSourceLocation(Loc: D->getEndOfDefinitionLoc()); |
| 1033 | Record.push_back(N: Data.HasDesignatedInitializers); |
| 1034 | Record.push_back(N: D->getODRHash()); |
| 1035 | |
| 1036 | // Write out the protocols that are directly referenced by the @interface. |
| 1037 | Record.push_back(N: Data.ReferencedProtocols.size()); |
| 1038 | for (const auto *P : D->protocols()) |
| 1039 | Record.AddDeclRef(D: P); |
| 1040 | for (const auto &PL : D->protocol_locs()) |
| 1041 | Record.AddSourceLocation(Loc: PL); |
| 1042 | |
| 1043 | // Write out the protocols that are transitively referenced. |
| 1044 | Record.push_back(N: Data.AllReferencedProtocols.size()); |
| 1045 | for (ObjCList<ObjCProtocolDecl>::iterator |
| 1046 | P = Data.AllReferencedProtocols.begin(), |
| 1047 | PEnd = Data.AllReferencedProtocols.end(); |
| 1048 | P != PEnd; ++P) |
| 1049 | Record.AddDeclRef(D: *P); |
| 1050 | |
| 1051 | |
| 1052 | if (ObjCCategoryDecl *Cat = D->getCategoryListRaw()) { |
| 1053 | // Ensure that we write out the set of categories for this class. |
| 1054 | Writer.ObjCClassesWithCategories.insert(X: D); |
| 1055 | |
| 1056 | // Make sure that the categories get serialized. |
| 1057 | for (; Cat; Cat = Cat->getNextClassCategoryRaw()) |
| 1058 | (void)Writer.GetDeclRef(D: Cat); |
| 1059 | } |
| 1060 | } |
| 1061 | |
| 1062 | Code = serialization::DECL_OBJC_INTERFACE; |
| 1063 | } |
| 1064 | |
| 1065 | void ASTDeclWriter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
| 1066 | VisitFieldDecl(D); |
| 1067 | // FIXME: stable encoding for @public/@private/@protected/@package |
| 1068 | Record.push_back(N: D->getAccessControl()); |
| 1069 | Record.push_back(N: D->getSynthesize()); |
| 1070 | |
| 1071 | if (D->getDeclContext() == D->getLexicalDeclContext() && |
| 1072 | !D->hasAttrs() && |
| 1073 | !D->isImplicit() && |
| 1074 | !D->isUsed(CheckUsedAttr: false) && |
| 1075 | !D->isInvalidDecl() && |
| 1076 | !D->isReferenced() && |
| 1077 | !D->isModulePrivate() && |
| 1078 | !D->getBitWidth() && |
| 1079 | !D->hasExtInfo() && |
| 1080 | D->getDeclName()) |
| 1081 | AbbrevToUse = Writer.getDeclObjCIvarAbbrev(); |
| 1082 | |
| 1083 | Code = serialization::DECL_OBJC_IVAR; |
| 1084 | } |
| 1085 | |
| 1086 | void ASTDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
| 1087 | VisitRedeclarable(D); |
| 1088 | VisitObjCContainerDecl(D); |
| 1089 | |
| 1090 | Record.push_back(N: D->isThisDeclarationADefinition()); |
| 1091 | if (D->isThisDeclarationADefinition()) { |
| 1092 | Record.push_back(N: D->protocol_size()); |
| 1093 | for (const auto *I : D->protocols()) |
| 1094 | Record.AddDeclRef(D: I); |
| 1095 | for (const auto &PL : D->protocol_locs()) |
| 1096 | Record.AddSourceLocation(Loc: PL); |
| 1097 | Record.push_back(N: D->getODRHash()); |
| 1098 | } |
| 1099 | |
| 1100 | Code = serialization::DECL_OBJC_PROTOCOL; |
| 1101 | } |
| 1102 | |
| 1103 | void ASTDeclWriter::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) { |
| 1104 | VisitFieldDecl(D); |
| 1105 | Code = serialization::DECL_OBJC_AT_DEFS_FIELD; |
| 1106 | } |
| 1107 | |
| 1108 | void ASTDeclWriter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
| 1109 | VisitObjCContainerDecl(D); |
| 1110 | Record.AddSourceLocation(Loc: D->getCategoryNameLoc()); |
| 1111 | Record.AddSourceLocation(Loc: D->getIvarLBraceLoc()); |
| 1112 | Record.AddSourceLocation(Loc: D->getIvarRBraceLoc()); |
| 1113 | Record.AddDeclRef(D: D->getClassInterface()); |
| 1114 | AddObjCTypeParamList(typeParams: D->TypeParamList); |
| 1115 | Record.push_back(N: D->protocol_size()); |
| 1116 | for (const auto *I : D->protocols()) |
| 1117 | Record.AddDeclRef(D: I); |
| 1118 | for (const auto &PL : D->protocol_locs()) |
| 1119 | Record.AddSourceLocation(Loc: PL); |
| 1120 | Code = serialization::DECL_OBJC_CATEGORY; |
| 1121 | } |
| 1122 | |
| 1123 | void ASTDeclWriter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D) { |
| 1124 | VisitNamedDecl(D); |
| 1125 | Record.AddDeclRef(D: D->getClassInterface()); |
| 1126 | Code = serialization::DECL_OBJC_COMPATIBLE_ALIAS; |
| 1127 | } |
| 1128 | |
| 1129 | void ASTDeclWriter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
| 1130 | VisitNamedDecl(D); |
| 1131 | Record.AddSourceLocation(Loc: D->getAtLoc()); |
| 1132 | Record.AddSourceLocation(Loc: D->getLParenLoc()); |
| 1133 | Record.AddTypeRef(T: D->getType()); |
| 1134 | Record.AddTypeSourceInfo(TInfo: D->getTypeSourceInfo()); |
| 1135 | // FIXME: stable encoding |
| 1136 | Record.push_back(N: (unsigned)D->getPropertyAttributes()); |
| 1137 | Record.push_back(N: (unsigned)D->getPropertyAttributesAsWritten()); |
| 1138 | // FIXME: stable encoding |
| 1139 | Record.push_back(N: (unsigned)D->getPropertyImplementation()); |
| 1140 | Record.AddDeclarationName(Name: D->getGetterName()); |
| 1141 | Record.AddSourceLocation(Loc: D->getGetterNameLoc()); |
| 1142 | Record.AddDeclarationName(Name: D->getSetterName()); |
| 1143 | Record.AddSourceLocation(Loc: D->getSetterNameLoc()); |
| 1144 | Record.AddDeclRef(D: D->getGetterMethodDecl()); |
| 1145 | Record.AddDeclRef(D: D->getSetterMethodDecl()); |
| 1146 | Record.AddDeclRef(D: D->getPropertyIvarDecl()); |
| 1147 | Code = serialization::DECL_OBJC_PROPERTY; |
| 1148 | } |
| 1149 | |
| 1150 | void ASTDeclWriter::VisitObjCImplDecl(ObjCImplDecl *D) { |
| 1151 | VisitObjCContainerDecl(D); |
| 1152 | Record.AddDeclRef(D: D->getClassInterface()); |
| 1153 | // Abstract class (no need to define a stable serialization::DECL code). |
| 1154 | } |
| 1155 | |
| 1156 | void ASTDeclWriter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 1157 | VisitObjCImplDecl(D); |
| 1158 | Record.AddSourceLocation(Loc: D->getCategoryNameLoc()); |
| 1159 | Code = serialization::DECL_OBJC_CATEGORY_IMPL; |
| 1160 | } |
| 1161 | |
| 1162 | void ASTDeclWriter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| 1163 | VisitObjCImplDecl(D); |
| 1164 | Record.AddDeclRef(D: D->getSuperClass()); |
| 1165 | Record.AddSourceLocation(Loc: D->getSuperClassLoc()); |
| 1166 | Record.AddSourceLocation(Loc: D->getIvarLBraceLoc()); |
| 1167 | Record.AddSourceLocation(Loc: D->getIvarRBraceLoc()); |
| 1168 | Record.push_back(N: D->hasNonZeroConstructors()); |
| 1169 | Record.push_back(N: D->hasDestructors()); |
| 1170 | Record.push_back(N: D->NumIvarInitializers); |
| 1171 | if (D->NumIvarInitializers) |
| 1172 | Record.AddCXXCtorInitializers( |
| 1173 | CtorInits: llvm::ArrayRef(D->init_begin(), D->init_end())); |
| 1174 | Code = serialization::DECL_OBJC_IMPLEMENTATION; |
| 1175 | } |
| 1176 | |
| 1177 | void ASTDeclWriter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 1178 | VisitDecl(D); |
| 1179 | Record.AddSourceLocation(Loc: D->getBeginLoc()); |
| 1180 | Record.AddDeclRef(D: D->getPropertyDecl()); |
| 1181 | Record.AddDeclRef(D: D->getPropertyIvarDecl()); |
| 1182 | Record.AddSourceLocation(Loc: D->getPropertyIvarDeclLoc()); |
| 1183 | Record.AddDeclRef(D: D->getGetterMethodDecl()); |
| 1184 | Record.AddDeclRef(D: D->getSetterMethodDecl()); |
| 1185 | Record.AddStmt(S: D->getGetterCXXConstructor()); |
| 1186 | Record.AddStmt(S: D->getSetterCXXAssignment()); |
| 1187 | Code = serialization::DECL_OBJC_PROPERTY_IMPL; |
| 1188 | } |
| 1189 | |
| 1190 | void ASTDeclWriter::VisitFieldDecl(FieldDecl *D) { |
| 1191 | VisitDeclaratorDecl(D); |
| 1192 | Record.push_back(N: D->isMutable()); |
| 1193 | |
| 1194 | Record.push_back(N: (D->StorageKind << 1) | D->BitField); |
| 1195 | if (D->StorageKind == FieldDecl::ISK_CapturedVLAType) |
| 1196 | Record.AddTypeRef(T: QualType(D->getCapturedVLAType(), 0)); |
| 1197 | else if (D->BitField) |
| 1198 | Record.AddStmt(S: D->getBitWidth()); |
| 1199 | |
| 1200 | if (!D->getDeclName() || D->isPlaceholderVar(LangOpts: Writer.getLangOpts())) |
| 1201 | Record.AddDeclRef( |
| 1202 | D: Record.getASTContext().getInstantiatedFromUnnamedFieldDecl(Field: D)); |
| 1203 | |
| 1204 | if (D->getDeclContext() == D->getLexicalDeclContext() && |
| 1205 | !D->hasAttrs() && |
| 1206 | !D->isImplicit() && |
| 1207 | !D->isUsed(CheckUsedAttr: false) && |
| 1208 | !D->isInvalidDecl() && |
| 1209 | !D->isReferenced() && |
| 1210 | !D->isTopLevelDeclInObjCContainer() && |
| 1211 | !D->isModulePrivate() && |
| 1212 | !D->getBitWidth() && |
| 1213 | !D->hasInClassInitializer() && |
| 1214 | !D->hasCapturedVLAType() && |
| 1215 | !D->hasExtInfo() && |
| 1216 | !ObjCIvarDecl::classofKind(K: D->getKind()) && |
| 1217 | !ObjCAtDefsFieldDecl::classofKind(K: D->getKind()) && |
| 1218 | D->getDeclName()) |
| 1219 | AbbrevToUse = Writer.getDeclFieldAbbrev(); |
| 1220 | |
| 1221 | Code = serialization::DECL_FIELD; |
| 1222 | } |
| 1223 | |
| 1224 | void ASTDeclWriter::VisitMSPropertyDecl(MSPropertyDecl *D) { |
| 1225 | VisitDeclaratorDecl(D); |
| 1226 | Record.AddIdentifierRef(II: D->getGetterId()); |
| 1227 | Record.AddIdentifierRef(II: D->getSetterId()); |
| 1228 | Code = serialization::DECL_MS_PROPERTY; |
| 1229 | } |
| 1230 | |
| 1231 | void ASTDeclWriter::VisitMSGuidDecl(MSGuidDecl *D) { |
| 1232 | VisitValueDecl(D); |
| 1233 | MSGuidDecl::Parts Parts = D->getParts(); |
| 1234 | Record.push_back(N: Parts.Part1); |
| 1235 | Record.push_back(N: Parts.Part2); |
| 1236 | Record.push_back(N: Parts.Part3); |
| 1237 | Record.append(begin: std::begin(arr&: Parts.Part4And5), end: std::end(arr&: Parts.Part4And5)); |
| 1238 | Code = serialization::DECL_MS_GUID; |
| 1239 | } |
| 1240 | |
| 1241 | void ASTDeclWriter::VisitUnnamedGlobalConstantDecl( |
| 1242 | UnnamedGlobalConstantDecl *D) { |
| 1243 | VisitValueDecl(D); |
| 1244 | Record.AddAPValue(Value: D->getValue()); |
| 1245 | Code = serialization::DECL_UNNAMED_GLOBAL_CONSTANT; |
| 1246 | } |
| 1247 | |
| 1248 | void ASTDeclWriter::VisitTemplateParamObjectDecl(TemplateParamObjectDecl *D) { |
| 1249 | VisitValueDecl(D); |
| 1250 | Record.AddAPValue(Value: D->getValue()); |
| 1251 | Code = serialization::DECL_TEMPLATE_PARAM_OBJECT; |
| 1252 | } |
| 1253 | |
| 1254 | void ASTDeclWriter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
| 1255 | VisitValueDecl(D); |
| 1256 | Record.push_back(N: D->getChainingSize()); |
| 1257 | |
| 1258 | for (const auto *P : D->chain()) |
| 1259 | Record.AddDeclRef(D: P); |
| 1260 | Code = serialization::DECL_INDIRECTFIELD; |
| 1261 | } |
| 1262 | |
| 1263 | void ASTDeclWriter::VisitVarDecl(VarDecl *D) { |
| 1264 | VisitRedeclarable(D); |
| 1265 | VisitDeclaratorDecl(D); |
| 1266 | |
| 1267 | // The order matters here. It will be better to put the bit with higher |
| 1268 | // probability to be 0 in the end of the bits. See the comments in VisitDecl |
| 1269 | // for details. |
| 1270 | BitsPacker VarDeclBits; |
| 1271 | VarDeclBits.addBits(Value: llvm::to_underlying(E: D->getLinkageInternal()), |
| 1272 | /*BitWidth=*/BitsWidth: 3); |
| 1273 | |
| 1274 | bool ModulesCodegen = shouldVarGenerateHereOnly(VD: D); |
| 1275 | VarDeclBits.addBit(Value: ModulesCodegen); |
| 1276 | |
| 1277 | VarDeclBits.addBits(Value: D->getStorageClass(), /*BitWidth=*/BitsWidth: 3); |
| 1278 | VarDeclBits.addBits(Value: D->getTSCSpec(), /*BitWidth=*/BitsWidth: 2); |
| 1279 | VarDeclBits.addBits(Value: D->getInitStyle(), /*BitWidth=*/BitsWidth: 2); |
| 1280 | VarDeclBits.addBit(Value: D->isARCPseudoStrong()); |
| 1281 | |
| 1282 | bool HasDeducedType = false; |
| 1283 | if (!isa<ParmVarDecl>(Val: D)) { |
| 1284 | VarDeclBits.addBit(Value: D->isThisDeclarationADemotedDefinition()); |
| 1285 | VarDeclBits.addBit(Value: D->isExceptionVariable()); |
| 1286 | VarDeclBits.addBit(Value: D->isNRVOVariable()); |
| 1287 | VarDeclBits.addBit(Value: D->isCXXForRangeDecl()); |
| 1288 | |
| 1289 | VarDeclBits.addBit(Value: D->isInline()); |
| 1290 | VarDeclBits.addBit(Value: D->isInlineSpecified()); |
| 1291 | VarDeclBits.addBit(Value: D->isConstexpr()); |
| 1292 | VarDeclBits.addBit(Value: D->isInitCapture()); |
| 1293 | VarDeclBits.addBit(Value: D->isPreviousDeclInSameBlockScope()); |
| 1294 | |
| 1295 | VarDeclBits.addBit(Value: D->isEscapingByref()); |
| 1296 | HasDeducedType = D->getType()->getContainedDeducedType(); |
| 1297 | VarDeclBits.addBit(Value: HasDeducedType); |
| 1298 | |
| 1299 | if (const auto *IPD = dyn_cast<ImplicitParamDecl>(Val: D)) |
| 1300 | VarDeclBits.addBits(Value: llvm::to_underlying(E: IPD->getParameterKind()), |
| 1301 | /*Width=*/BitsWidth: 3); |
| 1302 | else |
| 1303 | VarDeclBits.addBits(Value: 0, /*Width=*/BitsWidth: 3); |
| 1304 | |
| 1305 | VarDeclBits.addBit(Value: D->isObjCForDecl()); |
| 1306 | VarDeclBits.addBit(Value: D->isCXXForRangeImplicitVar()); |
| 1307 | } |
| 1308 | |
| 1309 | Record.push_back(N: VarDeclBits); |
| 1310 | |
| 1311 | if (ModulesCodegen) |
| 1312 | Writer.AddDeclRef(D, Record&: Writer.ModularCodegenDecls); |
| 1313 | |
| 1314 | if (D->hasAttr<BlocksAttr>()) { |
| 1315 | BlockVarCopyInit Init = Record.getASTContext().getBlockVarCopyInit(VD: D); |
| 1316 | Record.AddStmt(S: Init.getCopyExpr()); |
| 1317 | if (Init.getCopyExpr()) |
| 1318 | Record.push_back(N: Init.canThrow()); |
| 1319 | } |
| 1320 | |
| 1321 | enum { |
| 1322 | VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization |
| 1323 | }; |
| 1324 | if (VarTemplateDecl *TemplD = D->getDescribedVarTemplate()) { |
| 1325 | Record.push_back(N: VarTemplate); |
| 1326 | Record.AddDeclRef(D: TemplD); |
| 1327 | } else if (MemberSpecializationInfo *SpecInfo |
| 1328 | = D->getMemberSpecializationInfo()) { |
| 1329 | Record.push_back(N: StaticDataMemberSpecialization); |
| 1330 | Record.AddDeclRef(D: SpecInfo->getInstantiatedFrom()); |
| 1331 | Record.push_back(N: SpecInfo->getTemplateSpecializationKind()); |
| 1332 | Record.AddSourceLocation(Loc: SpecInfo->getPointOfInstantiation()); |
| 1333 | } else { |
| 1334 | Record.push_back(N: VarNotTemplate); |
| 1335 | } |
| 1336 | |
| 1337 | if (D->getDeclContext() == D->getLexicalDeclContext() && !D->hasAttrs() && |
| 1338 | !D->isTopLevelDeclInObjCContainer() && |
| 1339 | !needsAnonymousDeclarationNumber(D) && |
| 1340 | D->getDeclName().getNameKind() == DeclarationName::Identifier && |
| 1341 | !D->hasExtInfo() && D->getFirstDecl() == D->getMostRecentDecl() && |
| 1342 | D->getKind() == Decl::Var && !D->isInline() && !D->isConstexpr() && |
| 1343 | !D->isInitCapture() && !D->isPreviousDeclInSameBlockScope() && |
| 1344 | !D->hasInitWithSideEffects() && !D->isEscapingByref() && |
| 1345 | !HasDeducedType && D->getStorageDuration() != SD_Static && |
| 1346 | !D->getDescribedVarTemplate() && !D->getMemberSpecializationInfo() && |
| 1347 | !D->isObjCForDecl() && !isa<ImplicitParamDecl>(Val: D) && |
| 1348 | !D->isEscapingByref()) |
| 1349 | AbbrevToUse = Writer.getDeclVarAbbrev(); |
| 1350 | |
| 1351 | Code = serialization::DECL_VAR; |
| 1352 | } |
| 1353 | |
| 1354 | void ASTDeclWriter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
| 1355 | VisitVarDecl(D); |
| 1356 | Code = serialization::DECL_IMPLICIT_PARAM; |
| 1357 | } |
| 1358 | |
| 1359 | void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl *D) { |
| 1360 | VisitVarDecl(D); |
| 1361 | |
| 1362 | // See the implementation of `ParmVarDecl::getParameterIndex()`, which may |
| 1363 | // exceed the size of the normal bitfield. So it may be better to not pack |
| 1364 | // these bits. |
| 1365 | Record.push_back(N: D->getFunctionScopeIndex()); |
| 1366 | |
| 1367 | BitsPacker ParmVarDeclBits; |
| 1368 | ParmVarDeclBits.addBit(Value: D->isObjCMethodParameter()); |
| 1369 | ParmVarDeclBits.addBits(Value: D->getFunctionScopeDepth(), /*BitsWidth=*/7); |
| 1370 | // FIXME: stable encoding |
| 1371 | ParmVarDeclBits.addBits(Value: D->getObjCDeclQualifier(), /*BitsWidth=*/7); |
| 1372 | ParmVarDeclBits.addBit(Value: D->isKNRPromoted()); |
| 1373 | ParmVarDeclBits.addBit(Value: D->hasInheritedDefaultArg()); |
| 1374 | ParmVarDeclBits.addBit(Value: D->hasUninstantiatedDefaultArg()); |
| 1375 | ParmVarDeclBits.addBit(Value: D->getExplicitObjectParamThisLoc().isValid()); |
| 1376 | Record.push_back(N: ParmVarDeclBits); |
| 1377 | |
| 1378 | if (D->hasUninstantiatedDefaultArg()) |
| 1379 | Record.AddStmt(S: D->getUninstantiatedDefaultArg()); |
| 1380 | if (D->getExplicitObjectParamThisLoc().isValid()) |
| 1381 | Record.AddSourceLocation(Loc: D->getExplicitObjectParamThisLoc()); |
| 1382 | Code = serialization::DECL_PARM_VAR; |
| 1383 | |
| 1384 | // If the assumptions about the DECL_PARM_VAR abbrev are true, use it. Here |
| 1385 | // we dynamically check for the properties that we optimize for, but don't |
| 1386 | // know are true of all PARM_VAR_DECLs. |
| 1387 | if (D->getDeclContext() == D->getLexicalDeclContext() && !D->hasAttrs() && |
| 1388 | !D->hasExtInfo() && D->getStorageClass() == 0 && !D->isInvalidDecl() && |
| 1389 | !D->isTopLevelDeclInObjCContainer() && |
| 1390 | D->getInitStyle() == VarDecl::CInit && // Can params have anything else? |
| 1391 | D->getInit() == nullptr) // No default expr. |
| 1392 | AbbrevToUse = Writer.getDeclParmVarAbbrev(); |
| 1393 | |
| 1394 | // Check things we know are true of *every* PARM_VAR_DECL, which is more than |
| 1395 | // just us assuming it. |
| 1396 | assert(!D->getTSCSpec() && "PARM_VAR_DECL can't use TLS" ); |
| 1397 | assert(!D->isThisDeclarationADemotedDefinition() |
| 1398 | && "PARM_VAR_DECL can't be demoted definition." ); |
| 1399 | assert(D->getAccess() == AS_none && "PARM_VAR_DECL can't be public/private" ); |
| 1400 | assert(!D->isExceptionVariable() && "PARM_VAR_DECL can't be exception var" ); |
| 1401 | assert(D->getPreviousDecl() == nullptr && "PARM_VAR_DECL can't be redecl" ); |
| 1402 | assert(!D->isStaticDataMember() && |
| 1403 | "PARM_VAR_DECL can't be static data member" ); |
| 1404 | } |
| 1405 | |
| 1406 | void ASTDeclWriter::VisitDecompositionDecl(DecompositionDecl *D) { |
| 1407 | // Record the number of bindings first to simplify deserialization. |
| 1408 | Record.push_back(N: D->bindings().size()); |
| 1409 | |
| 1410 | VisitVarDecl(D); |
| 1411 | for (auto *B : D->bindings()) |
| 1412 | Record.AddDeclRef(D: B); |
| 1413 | Code = serialization::DECL_DECOMPOSITION; |
| 1414 | } |
| 1415 | |
| 1416 | void ASTDeclWriter::VisitBindingDecl(BindingDecl *D) { |
| 1417 | VisitValueDecl(D); |
| 1418 | Record.AddStmt(S: D->getBinding()); |
| 1419 | Code = serialization::DECL_BINDING; |
| 1420 | } |
| 1421 | |
| 1422 | void ASTDeclWriter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) { |
| 1423 | VisitDecl(D); |
| 1424 | Record.AddStmt(S: D->getAsmStringExpr()); |
| 1425 | Record.AddSourceLocation(Loc: D->getRParenLoc()); |
| 1426 | Code = serialization::DECL_FILE_SCOPE_ASM; |
| 1427 | } |
| 1428 | |
| 1429 | void ASTDeclWriter::VisitTopLevelStmtDecl(TopLevelStmtDecl *D) { |
| 1430 | VisitDecl(D); |
| 1431 | Record.AddStmt(S: D->getStmt()); |
| 1432 | Code = serialization::DECL_TOP_LEVEL_STMT_DECL; |
| 1433 | } |
| 1434 | |
| 1435 | void ASTDeclWriter::VisitEmptyDecl(EmptyDecl *D) { |
| 1436 | VisitDecl(D); |
| 1437 | Code = serialization::DECL_EMPTY; |
| 1438 | } |
| 1439 | |
| 1440 | void ASTDeclWriter::VisitLifetimeExtendedTemporaryDecl( |
| 1441 | LifetimeExtendedTemporaryDecl *D) { |
| 1442 | VisitDecl(D); |
| 1443 | Record.AddDeclRef(D: D->getExtendingDecl()); |
| 1444 | Record.AddStmt(S: D->getTemporaryExpr()); |
| 1445 | Record.push_back(N: static_cast<bool>(D->getValue())); |
| 1446 | if (D->getValue()) |
| 1447 | Record.AddAPValue(Value: *D->getValue()); |
| 1448 | Record.push_back(N: D->getManglingNumber()); |
| 1449 | Code = serialization::DECL_LIFETIME_EXTENDED_TEMPORARY; |
| 1450 | } |
| 1451 | void ASTDeclWriter::VisitBlockDecl(BlockDecl *D) { |
| 1452 | VisitDecl(D); |
| 1453 | Record.AddStmt(S: D->getBody()); |
| 1454 | Record.AddTypeSourceInfo(TInfo: D->getSignatureAsWritten()); |
| 1455 | Record.push_back(N: D->param_size()); |
| 1456 | for (ParmVarDecl *P : D->parameters()) |
| 1457 | Record.AddDeclRef(D: P); |
| 1458 | Record.push_back(N: D->isVariadic()); |
| 1459 | Record.push_back(N: D->blockMissingReturnType()); |
| 1460 | Record.push_back(N: D->isConversionFromLambda()); |
| 1461 | Record.push_back(N: D->doesNotEscape()); |
| 1462 | Record.push_back(N: D->canAvoidCopyToHeap()); |
| 1463 | Record.push_back(N: D->capturesCXXThis()); |
| 1464 | Record.push_back(N: D->getNumCaptures()); |
| 1465 | for (const auto &capture : D->captures()) { |
| 1466 | Record.AddDeclRef(D: capture.getVariable()); |
| 1467 | |
| 1468 | unsigned flags = 0; |
| 1469 | if (capture.isByRef()) flags |= 1; |
| 1470 | if (capture.isNested()) flags |= 2; |
| 1471 | if (capture.hasCopyExpr()) flags |= 4; |
| 1472 | Record.push_back(N: flags); |
| 1473 | |
| 1474 | if (capture.hasCopyExpr()) Record.AddStmt(S: capture.getCopyExpr()); |
| 1475 | } |
| 1476 | |
| 1477 | Code = serialization::DECL_BLOCK; |
| 1478 | } |
| 1479 | |
| 1480 | void ASTDeclWriter::VisitOutlinedFunctionDecl(OutlinedFunctionDecl *D) { |
| 1481 | Record.push_back(N: D->getNumParams()); |
| 1482 | VisitDecl(D); |
| 1483 | for (unsigned I = 0; I < D->getNumParams(); ++I) |
| 1484 | Record.AddDeclRef(D: D->getParam(i: I)); |
| 1485 | Record.push_back(N: D->isNothrow() ? 1 : 0); |
| 1486 | Record.AddStmt(S: D->getBody()); |
| 1487 | Code = serialization::DECL_OUTLINEDFUNCTION; |
| 1488 | } |
| 1489 | |
| 1490 | void ASTDeclWriter::VisitCapturedDecl(CapturedDecl *CD) { |
| 1491 | Record.push_back(N: CD->getNumParams()); |
| 1492 | VisitDecl(D: CD); |
| 1493 | Record.push_back(N: CD->getContextParamPosition()); |
| 1494 | Record.push_back(N: CD->isNothrow() ? 1 : 0); |
| 1495 | // Body is stored by VisitCapturedStmt. |
| 1496 | for (unsigned I = 0; I < CD->getNumParams(); ++I) |
| 1497 | Record.AddDeclRef(D: CD->getParam(i: I)); |
| 1498 | Code = serialization::DECL_CAPTURED; |
| 1499 | } |
| 1500 | |
| 1501 | void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 1502 | static_assert(DeclContext::NumLinkageSpecDeclBits == 17, |
| 1503 | "You need to update the serializer after you change the" |
| 1504 | "LinkageSpecDeclBits" ); |
| 1505 | |
| 1506 | VisitDecl(D); |
| 1507 | Record.push_back(N: llvm::to_underlying(E: D->getLanguage())); |
| 1508 | Record.AddSourceLocation(Loc: D->getExternLoc()); |
| 1509 | Record.AddSourceLocation(Loc: D->getRBraceLoc()); |
| 1510 | Code = serialization::DECL_LINKAGE_SPEC; |
| 1511 | } |
| 1512 | |
| 1513 | void ASTDeclWriter::VisitExportDecl(ExportDecl *D) { |
| 1514 | VisitDecl(D); |
| 1515 | Record.AddSourceLocation(Loc: D->getRBraceLoc()); |
| 1516 | Code = serialization::DECL_EXPORT; |
| 1517 | } |
| 1518 | |
| 1519 | void ASTDeclWriter::VisitLabelDecl(LabelDecl *D) { |
| 1520 | VisitNamedDecl(D); |
| 1521 | Record.AddSourceLocation(Loc: D->getBeginLoc()); |
| 1522 | Code = serialization::DECL_LABEL; |
| 1523 | } |
| 1524 | |
| 1525 | |
| 1526 | void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) { |
| 1527 | VisitRedeclarable(D); |
| 1528 | VisitNamedDecl(D); |
| 1529 | |
| 1530 | BitsPacker NamespaceDeclBits; |
| 1531 | NamespaceDeclBits.addBit(Value: D->isInline()); |
| 1532 | NamespaceDeclBits.addBit(Value: D->isNested()); |
| 1533 | Record.push_back(N: NamespaceDeclBits); |
| 1534 | |
| 1535 | Record.AddSourceLocation(Loc: D->getBeginLoc()); |
| 1536 | Record.AddSourceLocation(Loc: D->getRBraceLoc()); |
| 1537 | |
| 1538 | if (D->isFirstDecl()) |
| 1539 | Record.AddDeclRef(D: D->getAnonymousNamespace()); |
| 1540 | Code = serialization::DECL_NAMESPACE; |
| 1541 | |
| 1542 | if (Writer.hasChain() && D->isAnonymousNamespace() && |
| 1543 | D == D->getMostRecentDecl()) { |
| 1544 | // This is a most recent reopening of the anonymous namespace. If its parent |
| 1545 | // is in a previous PCH (or is the TU), mark that parent for update, because |
| 1546 | // the original namespace always points to the latest re-opening of its |
| 1547 | // anonymous namespace. |
| 1548 | Decl *Parent = cast<Decl>( |
| 1549 | Val: D->getParent()->getRedeclContext()->getPrimaryContext()); |
| 1550 | if (Parent->isFromASTFile() || isa<TranslationUnitDecl>(Val: Parent)) { |
| 1551 | Writer.DeclUpdates[Parent].push_back( |
| 1552 | Elt: ASTWriter::DeclUpdate(DeclUpdateKind::CXXAddedAnonymousNamespace, D)); |
| 1553 | } |
| 1554 | } |
| 1555 | } |
| 1556 | |
| 1557 | void ASTDeclWriter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
| 1558 | VisitRedeclarable(D); |
| 1559 | VisitNamedDecl(D); |
| 1560 | Record.AddSourceLocation(Loc: D->getNamespaceLoc()); |
| 1561 | Record.AddSourceLocation(Loc: D->getTargetNameLoc()); |
| 1562 | Record.AddNestedNameSpecifierLoc(NNS: D->getQualifierLoc()); |
| 1563 | Record.AddDeclRef(D: D->getNamespace()); |
| 1564 | Code = serialization::DECL_NAMESPACE_ALIAS; |
| 1565 | } |
| 1566 | |
| 1567 | void ASTDeclWriter::VisitUsingDecl(UsingDecl *D) { |
| 1568 | VisitNamedDecl(D); |
| 1569 | Record.AddSourceLocation(Loc: D->getUsingLoc()); |
| 1570 | Record.AddNestedNameSpecifierLoc(NNS: D->getQualifierLoc()); |
| 1571 | Record.AddDeclarationNameLoc(DNLoc: D->DNLoc, Name: D->getDeclName()); |
| 1572 | Record.AddDeclRef(D: D->FirstUsingShadow.getPointer()); |
| 1573 | Record.push_back(N: D->hasTypename()); |
| 1574 | Record.AddDeclRef(D: Record.getASTContext().getInstantiatedFromUsingDecl(Inst: D)); |
| 1575 | Code = serialization::DECL_USING; |
| 1576 | } |
| 1577 | |
| 1578 | void ASTDeclWriter::VisitUsingEnumDecl(UsingEnumDecl *D) { |
| 1579 | VisitNamedDecl(D); |
| 1580 | Record.AddSourceLocation(Loc: D->getUsingLoc()); |
| 1581 | Record.AddSourceLocation(Loc: D->getEnumLoc()); |
| 1582 | Record.AddTypeSourceInfo(TInfo: D->getEnumType()); |
| 1583 | Record.AddDeclRef(D: D->FirstUsingShadow.getPointer()); |
| 1584 | Record.AddDeclRef(D: Record.getASTContext().getInstantiatedFromUsingEnumDecl(Inst: D)); |
| 1585 | Code = serialization::DECL_USING_ENUM; |
| 1586 | } |
| 1587 | |
| 1588 | void ASTDeclWriter::VisitUsingPackDecl(UsingPackDecl *D) { |
| 1589 | Record.push_back(N: D->NumExpansions); |
| 1590 | VisitNamedDecl(D); |
| 1591 | Record.AddDeclRef(D: D->getInstantiatedFromUsingDecl()); |
| 1592 | for (auto *E : D->expansions()) |
| 1593 | Record.AddDeclRef(D: E); |
| 1594 | Code = serialization::DECL_USING_PACK; |
| 1595 | } |
| 1596 | |
| 1597 | void ASTDeclWriter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
| 1598 | VisitRedeclarable(D); |
| 1599 | VisitNamedDecl(D); |
| 1600 | Record.AddDeclRef(D: D->getTargetDecl()); |
| 1601 | Record.push_back(N: D->getIdentifierNamespace()); |
| 1602 | Record.AddDeclRef(D: D->UsingOrNextShadow); |
| 1603 | Record.AddDeclRef( |
| 1604 | D: Record.getASTContext().getInstantiatedFromUsingShadowDecl(Inst: D)); |
| 1605 | |
| 1606 | if (D->getDeclContext() == D->getLexicalDeclContext() && |
| 1607 | D->getFirstDecl() == D->getMostRecentDecl() && !D->hasAttrs() && |
| 1608 | !needsAnonymousDeclarationNumber(D) && |
| 1609 | D->getDeclName().getNameKind() == DeclarationName::Identifier) |
| 1610 | AbbrevToUse = Writer.getDeclUsingShadowAbbrev(); |
| 1611 | |
| 1612 | Code = serialization::DECL_USING_SHADOW; |
| 1613 | } |
| 1614 | |
| 1615 | void ASTDeclWriter::VisitConstructorUsingShadowDecl( |
| 1616 | ConstructorUsingShadowDecl *D) { |
| 1617 | VisitUsingShadowDecl(D); |
| 1618 | Record.AddDeclRef(D: D->NominatedBaseClassShadowDecl); |
| 1619 | Record.AddDeclRef(D: D->ConstructedBaseClassShadowDecl); |
| 1620 | Record.push_back(N: D->IsVirtual); |
| 1621 | Code = serialization::DECL_CONSTRUCTOR_USING_SHADOW; |
| 1622 | } |
| 1623 | |
| 1624 | void ASTDeclWriter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
| 1625 | VisitNamedDecl(D); |
| 1626 | Record.AddSourceLocation(Loc: D->getUsingLoc()); |
| 1627 | Record.AddSourceLocation(Loc: D->getNamespaceKeyLocation()); |
| 1628 | Record.AddNestedNameSpecifierLoc(NNS: D->getQualifierLoc()); |
| 1629 | Record.AddDeclRef(D: D->getNominatedNamespace()); |
| 1630 | Record.AddDeclRef(D: dyn_cast<Decl>(Val: D->getCommonAncestor())); |
| 1631 | Code = serialization::DECL_USING_DIRECTIVE; |
| 1632 | } |
| 1633 | |
| 1634 | void ASTDeclWriter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) { |
| 1635 | VisitValueDecl(D); |
| 1636 | Record.AddSourceLocation(Loc: D->getUsingLoc()); |
| 1637 | Record.AddNestedNameSpecifierLoc(NNS: D->getQualifierLoc()); |
| 1638 | Record.AddDeclarationNameLoc(DNLoc: D->DNLoc, Name: D->getDeclName()); |
| 1639 | Record.AddSourceLocation(Loc: D->getEllipsisLoc()); |
| 1640 | Code = serialization::DECL_UNRESOLVED_USING_VALUE; |
| 1641 | } |
| 1642 | |
| 1643 | void ASTDeclWriter::VisitUnresolvedUsingTypenameDecl( |
| 1644 | UnresolvedUsingTypenameDecl *D) { |
| 1645 | VisitTypeDecl(D); |
| 1646 | Record.AddSourceLocation(Loc: D->getTypenameLoc()); |
| 1647 | Record.AddNestedNameSpecifierLoc(NNS: D->getQualifierLoc()); |
| 1648 | Record.AddSourceLocation(Loc: D->getEllipsisLoc()); |
| 1649 | Code = serialization::DECL_UNRESOLVED_USING_TYPENAME; |
| 1650 | } |
| 1651 | |
| 1652 | void ASTDeclWriter::VisitUnresolvedUsingIfExistsDecl( |
| 1653 | UnresolvedUsingIfExistsDecl *D) { |
| 1654 | VisitNamedDecl(D); |
| 1655 | Code = serialization::DECL_UNRESOLVED_USING_IF_EXISTS; |
| 1656 | } |
| 1657 | |
| 1658 | void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) { |
| 1659 | VisitRecordDecl(D); |
| 1660 | |
| 1661 | enum { |
| 1662 | CXXRecNotTemplate = 0, |
| 1663 | CXXRecTemplate, |
| 1664 | CXXRecMemberSpecialization, |
| 1665 | CXXLambda |
| 1666 | }; |
| 1667 | if (ClassTemplateDecl *TemplD = D->getDescribedClassTemplate()) { |
| 1668 | Record.push_back(N: CXXRecTemplate); |
| 1669 | Record.AddDeclRef(D: TemplD); |
| 1670 | } else if (MemberSpecializationInfo *MSInfo |
| 1671 | = D->getMemberSpecializationInfo()) { |
| 1672 | Record.push_back(N: CXXRecMemberSpecialization); |
| 1673 | Record.AddDeclRef(D: MSInfo->getInstantiatedFrom()); |
| 1674 | Record.push_back(N: MSInfo->getTemplateSpecializationKind()); |
| 1675 | Record.AddSourceLocation(Loc: MSInfo->getPointOfInstantiation()); |
| 1676 | } else if (D->isLambda()) { |
| 1677 | // For a lambda, we need some information early for merging. |
| 1678 | Record.push_back(N: CXXLambda); |
| 1679 | if (auto *Context = D->getLambdaContextDecl()) { |
| 1680 | Record.AddDeclRef(D: Context); |
| 1681 | Record.push_back(N: D->getLambdaIndexInContext()); |
| 1682 | } else { |
| 1683 | Record.push_back(N: 0); |
| 1684 | } |
| 1685 | // For lambdas inside template functions, remember the mapping to |
| 1686 | // deserialize them together. |
| 1687 | if (auto *FD = llvm::dyn_cast_or_null<FunctionDecl>(Val: D->getDeclContext()); |
| 1688 | FD && isDefinitionInDependentContext(D: FD)) { |
| 1689 | Writer.RelatedDeclsMap[Writer.GetDeclRef(D: FD)].push_back( |
| 1690 | Elt: Writer.GetDeclRef(D: D->getLambdaCallOperator())); |
| 1691 | } |
| 1692 | } else { |
| 1693 | Record.push_back(N: CXXRecNotTemplate); |
| 1694 | } |
| 1695 | |
| 1696 | Record.push_back(N: D->isThisDeclarationADefinition()); |
| 1697 | if (D->isThisDeclarationADefinition()) |
| 1698 | Record.AddCXXDefinitionData(D); |
| 1699 | |
| 1700 | if (D->isCompleteDefinition() && D->isInNamedModule()) |
| 1701 | Writer.AddDeclRef(D, Record&: Writer.ModularCodegenDecls); |
| 1702 | |
| 1703 | // Store (what we currently believe to be) the key function to avoid |
| 1704 | // deserializing every method so we can compute it. |
| 1705 | // |
| 1706 | // FIXME: Avoid adding the key function if the class is defined in |
| 1707 | // module purview since in that case the key function is meaningless. |
| 1708 | if (D->isCompleteDefinition()) |
| 1709 | Record.AddDeclRef(D: Record.getASTContext().getCurrentKeyFunction(RD: D)); |
| 1710 | |
| 1711 | Code = serialization::DECL_CXX_RECORD; |
| 1712 | } |
| 1713 | |
| 1714 | void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
| 1715 | VisitFunctionDecl(D); |
| 1716 | if (D->isCanonicalDecl()) { |
| 1717 | Record.push_back(N: D->size_overridden_methods()); |
| 1718 | for (const CXXMethodDecl *MD : D->overridden_methods()) |
| 1719 | Record.AddDeclRef(D: MD); |
| 1720 | } else { |
| 1721 | // We only need to record overridden methods once for the canonical decl. |
| 1722 | Record.push_back(N: 0); |
| 1723 | } |
| 1724 | |
| 1725 | if (D->getDeclContext() == D->getLexicalDeclContext() && |
| 1726 | D->getFirstDecl() == D->getMostRecentDecl() && !D->isInvalidDecl() && |
| 1727 | !D->hasAttrs() && !D->isTopLevelDeclInObjCContainer() && |
| 1728 | D->getDeclName().getNameKind() == DeclarationName::Identifier && |
| 1729 | !D->hasExtInfo() && !D->isExplicitlyDefaulted()) { |
| 1730 | if (D->getTemplatedKind() == FunctionDecl::TK_NonTemplate || |
| 1731 | D->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate || |
| 1732 | D->getTemplatedKind() == FunctionDecl::TK_MemberSpecialization || |
| 1733 | D->getTemplatedKind() == FunctionDecl::TK_DependentNonTemplate) |
| 1734 | AbbrevToUse = Writer.getDeclCXXMethodAbbrev(Kind: D->getTemplatedKind()); |
| 1735 | else if (D->getTemplatedKind() == |
| 1736 | FunctionDecl::TK_FunctionTemplateSpecialization) { |
| 1737 | FunctionTemplateSpecializationInfo *FTSInfo = |
| 1738 | D->getTemplateSpecializationInfo(); |
| 1739 | |
| 1740 | if (FTSInfo->TemplateArguments->size() == 1) { |
| 1741 | const TemplateArgument &TA = FTSInfo->TemplateArguments->get(Idx: 0); |
| 1742 | if (TA.getKind() == TemplateArgument::Type && |
| 1743 | !FTSInfo->TemplateArgumentsAsWritten && |
| 1744 | !FTSInfo->getMemberSpecializationInfo()) |
| 1745 | AbbrevToUse = Writer.getDeclCXXMethodAbbrev(Kind: D->getTemplatedKind()); |
| 1746 | } |
| 1747 | } else if (D->getTemplatedKind() == |
| 1748 | FunctionDecl::TK_DependentFunctionTemplateSpecialization) { |
| 1749 | DependentFunctionTemplateSpecializationInfo *DFTSInfo = |
| 1750 | D->getDependentSpecializationInfo(); |
| 1751 | if (!DFTSInfo->TemplateArgumentsAsWritten) |
| 1752 | AbbrevToUse = Writer.getDeclCXXMethodAbbrev(Kind: D->getTemplatedKind()); |
| 1753 | } |
| 1754 | } |
| 1755 | |
| 1756 | Code = serialization::DECL_CXX_METHOD; |
| 1757 | } |
| 1758 | |
| 1759 | void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
| 1760 | static_assert(DeclContext::NumCXXConstructorDeclBits == 64, |
| 1761 | "You need to update the serializer after you change the " |
| 1762 | "CXXConstructorDeclBits" ); |
| 1763 | |
| 1764 | Record.push_back(N: D->getTrailingAllocKind()); |
| 1765 | addExplicitSpecifier(ES: D->getExplicitSpecifierInternal(), Record); |
| 1766 | if (auto Inherited = D->getInheritedConstructor()) { |
| 1767 | Record.AddDeclRef(D: Inherited.getShadowDecl()); |
| 1768 | Record.AddDeclRef(D: Inherited.getConstructor()); |
| 1769 | } |
| 1770 | |
| 1771 | VisitCXXMethodDecl(D); |
| 1772 | Code = serialization::DECL_CXX_CONSTRUCTOR; |
| 1773 | } |
| 1774 | |
| 1775 | void ASTDeclWriter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
| 1776 | VisitCXXMethodDecl(D); |
| 1777 | |
| 1778 | Record.AddDeclRef(D: D->getOperatorDelete()); |
| 1779 | if (D->getOperatorDelete()) |
| 1780 | Record.AddStmt(S: D->getOperatorDeleteThisArg()); |
| 1781 | Record.AddDeclRef(D: D->getOperatorGlobalDelete()); |
| 1782 | Record.AddDeclRef(D: D->getArrayOperatorDelete()); |
| 1783 | Record.AddDeclRef(D: D->getGlobalArrayOperatorDelete()); |
| 1784 | |
| 1785 | Code = serialization::DECL_CXX_DESTRUCTOR; |
| 1786 | } |
| 1787 | |
| 1788 | void ASTDeclWriter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
| 1789 | addExplicitSpecifier(ES: D->getExplicitSpecifier(), Record); |
| 1790 | VisitCXXMethodDecl(D); |
| 1791 | Code = serialization::DECL_CXX_CONVERSION; |
| 1792 | } |
| 1793 | |
| 1794 | void ASTDeclWriter::VisitImportDecl(ImportDecl *D) { |
| 1795 | VisitDecl(D); |
| 1796 | Record.push_back(N: Writer.getSubmoduleID(Mod: D->getImportedModule())); |
| 1797 | ArrayRef<SourceLocation> IdentifierLocs = D->getIdentifierLocs(); |
| 1798 | Record.push_back(N: !IdentifierLocs.empty()); |
| 1799 | if (IdentifierLocs.empty()) { |
| 1800 | Record.AddSourceLocation(Loc: D->getEndLoc()); |
| 1801 | Record.push_back(N: 1); |
| 1802 | } else { |
| 1803 | for (unsigned I = 0, N = IdentifierLocs.size(); I != N; ++I) |
| 1804 | Record.AddSourceLocation(Loc: IdentifierLocs[I]); |
| 1805 | Record.push_back(N: IdentifierLocs.size()); |
| 1806 | } |
| 1807 | // Note: the number of source locations must always be the last element in |
| 1808 | // the record. |
| 1809 | Code = serialization::DECL_IMPORT; |
| 1810 | } |
| 1811 | |
| 1812 | void ASTDeclWriter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
| 1813 | VisitDecl(D); |
| 1814 | Record.AddSourceLocation(Loc: D->getColonLoc()); |
| 1815 | Code = serialization::DECL_ACCESS_SPEC; |
| 1816 | } |
| 1817 | |
| 1818 | void ASTDeclWriter::VisitFriendDecl(FriendDecl *D) { |
| 1819 | // Record the number of friend type template parameter lists here |
| 1820 | // so as to simplify memory allocation during deserialization. |
| 1821 | Record.push_back(N: D->NumTPLists); |
| 1822 | VisitDecl(D); |
| 1823 | bool hasFriendDecl = isa<NamedDecl *>(Val: D->Friend); |
| 1824 | Record.push_back(N: hasFriendDecl); |
| 1825 | if (hasFriendDecl) |
| 1826 | Record.AddDeclRef(D: D->getFriendDecl()); |
| 1827 | else |
| 1828 | Record.AddTypeSourceInfo(TInfo: D->getFriendType()); |
| 1829 | for (unsigned i = 0; i < D->NumTPLists; ++i) |
| 1830 | Record.AddTemplateParameterList(TemplateParams: D->getFriendTypeTemplateParameterList(N: i)); |
| 1831 | Record.AddDeclRef(D: D->getNextFriend()); |
| 1832 | Record.push_back(N: D->UnsupportedFriend); |
| 1833 | Record.AddSourceLocation(Loc: D->FriendLoc); |
| 1834 | Record.AddSourceLocation(Loc: D->EllipsisLoc); |
| 1835 | Code = serialization::DECL_FRIEND; |
| 1836 | } |
| 1837 | |
| 1838 | void ASTDeclWriter::VisitFriendTemplateDecl(FriendTemplateDecl *D) { |
| 1839 | VisitDecl(D); |
| 1840 | Record.push_back(N: D->getNumTemplateParameters()); |
| 1841 | for (unsigned i = 0, e = D->getNumTemplateParameters(); i != e; ++i) |
| 1842 | Record.AddTemplateParameterList(TemplateParams: D->getTemplateParameterList(i)); |
| 1843 | Record.push_back(N: D->getFriendDecl() != nullptr); |
| 1844 | if (D->getFriendDecl()) |
| 1845 | Record.AddDeclRef(D: D->getFriendDecl()); |
| 1846 | else |
| 1847 | Record.AddTypeSourceInfo(TInfo: D->getFriendType()); |
| 1848 | Record.AddSourceLocation(Loc: D->getFriendLoc()); |
| 1849 | Code = serialization::DECL_FRIEND_TEMPLATE; |
| 1850 | } |
| 1851 | |
| 1852 | void ASTDeclWriter::VisitTemplateDecl(TemplateDecl *D) { |
| 1853 | VisitNamedDecl(D); |
| 1854 | |
| 1855 | Record.AddTemplateParameterList(TemplateParams: D->getTemplateParameters()); |
| 1856 | Record.AddDeclRef(D: D->getTemplatedDecl()); |
| 1857 | } |
| 1858 | |
| 1859 | void ASTDeclWriter::VisitConceptDecl(ConceptDecl *D) { |
| 1860 | VisitTemplateDecl(D); |
| 1861 | Record.AddStmt(S: D->getConstraintExpr()); |
| 1862 | Code = serialization::DECL_CONCEPT; |
| 1863 | } |
| 1864 | |
| 1865 | void ASTDeclWriter::VisitImplicitConceptSpecializationDecl( |
| 1866 | ImplicitConceptSpecializationDecl *D) { |
| 1867 | Record.push_back(N: D->getTemplateArguments().size()); |
| 1868 | VisitDecl(D); |
| 1869 | for (const TemplateArgument &Arg : D->getTemplateArguments()) |
| 1870 | Record.AddTemplateArgument(Arg); |
| 1871 | Code = serialization::DECL_IMPLICIT_CONCEPT_SPECIALIZATION; |
| 1872 | } |
| 1873 | |
| 1874 | void ASTDeclWriter::VisitRequiresExprBodyDecl(RequiresExprBodyDecl *D) { |
| 1875 | Code = serialization::DECL_REQUIRES_EXPR_BODY; |
| 1876 | } |
| 1877 | |
| 1878 | void ASTDeclWriter::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) { |
| 1879 | VisitRedeclarable(D); |
| 1880 | |
| 1881 | // Emit data to initialize CommonOrPrev before VisitTemplateDecl so that |
| 1882 | // getCommonPtr() can be used while this is still initializing. |
| 1883 | if (D->isFirstDecl()) { |
| 1884 | // This declaration owns the 'common' pointer, so serialize that data now. |
| 1885 | Record.AddDeclRef(D: D->getInstantiatedFromMemberTemplate()); |
| 1886 | if (D->getInstantiatedFromMemberTemplate()) |
| 1887 | Record.push_back(N: D->isMemberSpecialization()); |
| 1888 | } |
| 1889 | |
| 1890 | VisitTemplateDecl(D); |
| 1891 | Record.push_back(N: D->getIdentifierNamespace()); |
| 1892 | } |
| 1893 | |
| 1894 | void ASTDeclWriter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
| 1895 | VisitRedeclarableTemplateDecl(D); |
| 1896 | |
| 1897 | if (D->isFirstDecl()) |
| 1898 | AddTemplateSpecializations(D); |
| 1899 | |
| 1900 | // Force emitting the corresponding deduction guide in reduced BMI mode. |
| 1901 | // Otherwise, the deduction guide may be optimized out incorrectly. |
| 1902 | if (Writer.isGeneratingReducedBMI()) { |
| 1903 | auto Name = |
| 1904 | Record.getASTContext().DeclarationNames.getCXXDeductionGuideName(TD: D); |
| 1905 | for (auto *DG : D->getDeclContext()->noload_lookup(Name)) |
| 1906 | Writer.GetDeclRef(D: DG->getCanonicalDecl()); |
| 1907 | } |
| 1908 | |
| 1909 | Code = serialization::DECL_CLASS_TEMPLATE; |
| 1910 | } |
| 1911 | |
| 1912 | void ASTDeclWriter::VisitClassTemplateSpecializationDecl( |
| 1913 | ClassTemplateSpecializationDecl *D) { |
| 1914 | RegisterTemplateSpecialization(Template: D->getSpecializedTemplate(), Specialization: D); |
| 1915 | |
| 1916 | VisitCXXRecordDecl(D); |
| 1917 | |
| 1918 | llvm::PointerUnion<ClassTemplateDecl *, |
| 1919 | ClassTemplatePartialSpecializationDecl *> InstFrom |
| 1920 | = D->getSpecializedTemplateOrPartial(); |
| 1921 | if (Decl *InstFromD = InstFrom.dyn_cast<ClassTemplateDecl *>()) { |
| 1922 | Record.AddDeclRef(D: InstFromD); |
| 1923 | } else { |
| 1924 | Record.AddDeclRef(D: cast<ClassTemplatePartialSpecializationDecl *>(Val&: InstFrom)); |
| 1925 | Record.AddTemplateArgumentList(TemplateArgs: &D->getTemplateInstantiationArgs()); |
| 1926 | } |
| 1927 | |
| 1928 | Record.AddTemplateArgumentList(TemplateArgs: &D->getTemplateArgs()); |
| 1929 | Record.AddSourceLocation(Loc: D->getPointOfInstantiation()); |
| 1930 | Record.push_back(N: D->getSpecializationKind()); |
| 1931 | Record.push_back(N: D->hasStrictPackMatch()); |
| 1932 | Record.push_back(N: D->isCanonicalDecl()); |
| 1933 | |
| 1934 | if (D->isCanonicalDecl()) { |
| 1935 | // When reading, we'll add it to the folding set of the following template. |
| 1936 | Record.AddDeclRef(D: D->getSpecializedTemplate()->getCanonicalDecl()); |
| 1937 | } |
| 1938 | |
| 1939 | bool ExplicitInstantiation = |
| 1940 | D->getTemplateSpecializationKind() == |
| 1941 | TSK_ExplicitInstantiationDeclaration || |
| 1942 | D->getTemplateSpecializationKind() == TSK_ExplicitInstantiationDefinition; |
| 1943 | Record.push_back(N: ExplicitInstantiation); |
| 1944 | if (ExplicitInstantiation) { |
| 1945 | Record.AddSourceLocation(Loc: D->getExternKeywordLoc()); |
| 1946 | Record.AddSourceLocation(Loc: D->getTemplateKeywordLoc()); |
| 1947 | } |
| 1948 | |
| 1949 | const ASTTemplateArgumentListInfo *ArgsWritten = |
| 1950 | D->getTemplateArgsAsWritten(); |
| 1951 | Record.push_back(N: !!ArgsWritten); |
| 1952 | if (ArgsWritten) |
| 1953 | Record.AddASTTemplateArgumentListInfo(ASTTemplArgList: ArgsWritten); |
| 1954 | |
| 1955 | // Mention the implicitly generated C++ deduction guide to make sure the |
| 1956 | // deduction guide will be rewritten as expected. |
| 1957 | // |
| 1958 | // FIXME: Would it be more efficient to add a callback register function |
| 1959 | // in sema to register the deduction guide? |
| 1960 | if (Writer.isWritingStdCXXNamedModules()) { |
| 1961 | auto Name = |
| 1962 | Record.getASTContext().DeclarationNames.getCXXDeductionGuideName( |
| 1963 | TD: D->getSpecializedTemplate()); |
| 1964 | for (auto *DG : D->getDeclContext()->noload_lookup(Name)) |
| 1965 | Writer.GetDeclRef(D: DG->getCanonicalDecl()); |
| 1966 | } |
| 1967 | |
| 1968 | Code = serialization::DECL_CLASS_TEMPLATE_SPECIALIZATION; |
| 1969 | } |
| 1970 | |
| 1971 | void ASTDeclWriter::VisitClassTemplatePartialSpecializationDecl( |
| 1972 | ClassTemplatePartialSpecializationDecl *D) { |
| 1973 | Record.AddTemplateParameterList(TemplateParams: D->getTemplateParameters()); |
| 1974 | |
| 1975 | VisitClassTemplateSpecializationDecl(D); |
| 1976 | |
| 1977 | // These are read/set from/to the first declaration. |
| 1978 | if (D->getPreviousDecl() == nullptr) { |
| 1979 | Record.AddDeclRef(D: D->getInstantiatedFromMember()); |
| 1980 | Record.push_back(N: D->isMemberSpecialization()); |
| 1981 | } |
| 1982 | |
| 1983 | Code = serialization::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION; |
| 1984 | } |
| 1985 | |
| 1986 | void ASTDeclWriter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
| 1987 | VisitRedeclarableTemplateDecl(D); |
| 1988 | |
| 1989 | if (D->isFirstDecl()) |
| 1990 | AddTemplateSpecializations(D); |
| 1991 | Code = serialization::DECL_VAR_TEMPLATE; |
| 1992 | } |
| 1993 | |
| 1994 | void ASTDeclWriter::VisitVarTemplateSpecializationDecl( |
| 1995 | VarTemplateSpecializationDecl *D) { |
| 1996 | RegisterTemplateSpecialization(Template: D->getSpecializedTemplate(), Specialization: D); |
| 1997 | |
| 1998 | llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *> |
| 1999 | InstFrom = D->getSpecializedTemplateOrPartial(); |
| 2000 | if (Decl *InstFromD = InstFrom.dyn_cast<VarTemplateDecl *>()) { |
| 2001 | Record.AddDeclRef(D: InstFromD); |
| 2002 | } else { |
| 2003 | Record.AddDeclRef(D: cast<VarTemplatePartialSpecializationDecl *>(Val&: InstFrom)); |
| 2004 | Record.AddTemplateArgumentList(TemplateArgs: &D->getTemplateInstantiationArgs()); |
| 2005 | } |
| 2006 | |
| 2007 | bool ExplicitInstantiation = |
| 2008 | D->getTemplateSpecializationKind() == |
| 2009 | TSK_ExplicitInstantiationDeclaration || |
| 2010 | D->getTemplateSpecializationKind() == TSK_ExplicitInstantiationDefinition; |
| 2011 | Record.push_back(N: ExplicitInstantiation); |
| 2012 | if (ExplicitInstantiation) { |
| 2013 | Record.AddSourceLocation(Loc: D->getExternKeywordLoc()); |
| 2014 | Record.AddSourceLocation(Loc: D->getTemplateKeywordLoc()); |
| 2015 | } |
| 2016 | |
| 2017 | const ASTTemplateArgumentListInfo *ArgsWritten = |
| 2018 | D->getTemplateArgsAsWritten(); |
| 2019 | Record.push_back(N: !!ArgsWritten); |
| 2020 | if (ArgsWritten) |
| 2021 | Record.AddASTTemplateArgumentListInfo(ASTTemplArgList: ArgsWritten); |
| 2022 | |
| 2023 | Record.AddTemplateArgumentList(TemplateArgs: &D->getTemplateArgs()); |
| 2024 | Record.AddSourceLocation(Loc: D->getPointOfInstantiation()); |
| 2025 | Record.push_back(N: D->getSpecializationKind()); |
| 2026 | Record.push_back(N: D->IsCompleteDefinition); |
| 2027 | |
| 2028 | VisitVarDecl(D); |
| 2029 | |
| 2030 | Record.push_back(N: D->isCanonicalDecl()); |
| 2031 | |
| 2032 | if (D->isCanonicalDecl()) { |
| 2033 | // When reading, we'll add it to the folding set of the following template. |
| 2034 | Record.AddDeclRef(D: D->getSpecializedTemplate()->getCanonicalDecl()); |
| 2035 | } |
| 2036 | |
| 2037 | Code = serialization::DECL_VAR_TEMPLATE_SPECIALIZATION; |
| 2038 | } |
| 2039 | |
| 2040 | void ASTDeclWriter::VisitVarTemplatePartialSpecializationDecl( |
| 2041 | VarTemplatePartialSpecializationDecl *D) { |
| 2042 | Record.AddTemplateParameterList(TemplateParams: D->getTemplateParameters()); |
| 2043 | |
| 2044 | VisitVarTemplateSpecializationDecl(D); |
| 2045 | |
| 2046 | // These are read/set from/to the first declaration. |
| 2047 | if (D->getPreviousDecl() == nullptr) { |
| 2048 | Record.AddDeclRef(D: D->getInstantiatedFromMember()); |
| 2049 | Record.push_back(N: D->isMemberSpecialization()); |
| 2050 | } |
| 2051 | |
| 2052 | Code = serialization::DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION; |
| 2053 | } |
| 2054 | |
| 2055 | void ASTDeclWriter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
| 2056 | VisitRedeclarableTemplateDecl(D); |
| 2057 | |
| 2058 | if (D->isFirstDecl()) |
| 2059 | AddTemplateSpecializations(D); |
| 2060 | Code = serialization::DECL_FUNCTION_TEMPLATE; |
| 2061 | } |
| 2062 | |
| 2063 | void ASTDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
| 2064 | Record.push_back(N: D->hasTypeConstraint()); |
| 2065 | VisitTypeDecl(D); |
| 2066 | |
| 2067 | Record.push_back(N: D->wasDeclaredWithTypename()); |
| 2068 | |
| 2069 | const TypeConstraint *TC = D->getTypeConstraint(); |
| 2070 | if (D->hasTypeConstraint()) |
| 2071 | Record.push_back(/*TypeConstraintInitialized=*/N: TC != nullptr); |
| 2072 | if (TC) { |
| 2073 | auto *CR = TC->getConceptReference(); |
| 2074 | Record.push_back(N: CR != nullptr); |
| 2075 | if (CR) |
| 2076 | Record.AddConceptReference(CR); |
| 2077 | Record.AddStmt(S: TC->getImmediatelyDeclaredConstraint()); |
| 2078 | Record.writeUnsignedOrNone(Value: TC->getArgPackSubstIndex()); |
| 2079 | Record.writeUnsignedOrNone(Value: D->getNumExpansionParameters()); |
| 2080 | } |
| 2081 | |
| 2082 | bool OwnsDefaultArg = D->hasDefaultArgument() && |
| 2083 | !D->defaultArgumentWasInherited(); |
| 2084 | Record.push_back(N: OwnsDefaultArg); |
| 2085 | if (OwnsDefaultArg) |
| 2086 | Record.AddTemplateArgumentLoc(Arg: D->getDefaultArgument()); |
| 2087 | |
| 2088 | if (!D->hasTypeConstraint() && !OwnsDefaultArg && |
| 2089 | D->getDeclContext() == D->getLexicalDeclContext() && |
| 2090 | !D->isInvalidDecl() && !D->hasAttrs() && |
| 2091 | !D->isTopLevelDeclInObjCContainer() && !D->isImplicit() && |
| 2092 | D->getDeclName().getNameKind() == DeclarationName::Identifier) |
| 2093 | AbbrevToUse = Writer.getDeclTemplateTypeParmAbbrev(); |
| 2094 | |
| 2095 | Code = serialization::DECL_TEMPLATE_TYPE_PARM; |
| 2096 | } |
| 2097 | |
| 2098 | void ASTDeclWriter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
| 2099 | // For an expanded parameter pack, record the number of expansion types here |
| 2100 | // so that it's easier for deserialization to allocate the right amount of |
| 2101 | // memory. |
| 2102 | Record.push_back(N: D->hasPlaceholderTypeConstraint()); |
| 2103 | if (D->isExpandedParameterPack()) |
| 2104 | Record.push_back(N: D->getNumExpansionTypes()); |
| 2105 | |
| 2106 | VisitDeclaratorDecl(D); |
| 2107 | // TemplateParmPosition. |
| 2108 | Record.push_back(N: D->getDepth()); |
| 2109 | Record.push_back(N: D->getPosition()); |
| 2110 | |
| 2111 | if (D->hasPlaceholderTypeConstraint()) |
| 2112 | Record.AddStmt(S: D->getPlaceholderTypeConstraint()); |
| 2113 | |
| 2114 | if (D->isExpandedParameterPack()) { |
| 2115 | for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) { |
| 2116 | Record.AddTypeRef(T: D->getExpansionType(I)); |
| 2117 | Record.AddTypeSourceInfo(TInfo: D->getExpansionTypeSourceInfo(I)); |
| 2118 | } |
| 2119 | |
| 2120 | Code = serialization::DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK; |
| 2121 | } else { |
| 2122 | // Rest of NonTypeTemplateParmDecl. |
| 2123 | Record.push_back(N: D->isParameterPack()); |
| 2124 | bool OwnsDefaultArg = D->hasDefaultArgument() && |
| 2125 | !D->defaultArgumentWasInherited(); |
| 2126 | Record.push_back(N: OwnsDefaultArg); |
| 2127 | if (OwnsDefaultArg) |
| 2128 | Record.AddTemplateArgumentLoc(Arg: D->getDefaultArgument()); |
| 2129 | Code = serialization::DECL_NON_TYPE_TEMPLATE_PARM; |
| 2130 | } |
| 2131 | } |
| 2132 | |
| 2133 | void ASTDeclWriter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 2134 | // For an expanded parameter pack, record the number of expansion types here |
| 2135 | // so that it's easier for deserialization to allocate the right amount of |
| 2136 | // memory. |
| 2137 | if (D->isExpandedParameterPack()) |
| 2138 | Record.push_back(N: D->getNumExpansionTemplateParameters()); |
| 2139 | |
| 2140 | VisitTemplateDecl(D); |
| 2141 | Record.push_back(N: D->templateParameterKind()); |
| 2142 | Record.push_back(N: D->wasDeclaredWithTypename()); |
| 2143 | // TemplateParmPosition. |
| 2144 | Record.push_back(N: D->getDepth()); |
| 2145 | Record.push_back(N: D->getPosition()); |
| 2146 | |
| 2147 | if (D->isExpandedParameterPack()) { |
| 2148 | for (unsigned I = 0, N = D->getNumExpansionTemplateParameters(); |
| 2149 | I != N; ++I) |
| 2150 | Record.AddTemplateParameterList(TemplateParams: D->getExpansionTemplateParameters(I)); |
| 2151 | Code = serialization::DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK; |
| 2152 | } else { |
| 2153 | // Rest of TemplateTemplateParmDecl. |
| 2154 | Record.push_back(N: D->isParameterPack()); |
| 2155 | bool OwnsDefaultArg = D->hasDefaultArgument() && |
| 2156 | !D->defaultArgumentWasInherited(); |
| 2157 | Record.push_back(N: OwnsDefaultArg); |
| 2158 | if (OwnsDefaultArg) |
| 2159 | Record.AddTemplateArgumentLoc(Arg: D->getDefaultArgument()); |
| 2160 | Code = serialization::DECL_TEMPLATE_TEMPLATE_PARM; |
| 2161 | } |
| 2162 | } |
| 2163 | |
| 2164 | void ASTDeclWriter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
| 2165 | VisitRedeclarableTemplateDecl(D); |
| 2166 | Code = serialization::DECL_TYPE_ALIAS_TEMPLATE; |
| 2167 | } |
| 2168 | |
| 2169 | void ASTDeclWriter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 2170 | VisitDecl(D); |
| 2171 | Record.AddStmt(S: D->getAssertExpr()); |
| 2172 | Record.push_back(N: D->isFailed()); |
| 2173 | Record.AddStmt(S: D->getMessage()); |
| 2174 | Record.AddSourceLocation(Loc: D->getRParenLoc()); |
| 2175 | Code = serialization::DECL_STATIC_ASSERT; |
| 2176 | } |
| 2177 | |
| 2178 | /// Emit the DeclContext part of a declaration context decl. |
| 2179 | void ASTDeclWriter::VisitDeclContext(DeclContext *DC) { |
| 2180 | static_assert(DeclContext::NumDeclContextBits == 13, |
| 2181 | "You need to update the serializer after you change the " |
| 2182 | "DeclContextBits" ); |
| 2183 | LookupBlockOffsets Offsets; |
| 2184 | |
| 2185 | if (Writer.isGeneratingReducedBMI() && isa<NamespaceDecl>(Val: DC) && |
| 2186 | cast<NamespaceDecl>(Val: DC)->isFromExplicitGlobalModule()) { |
| 2187 | // In reduced BMI, delay writing lexical and visible block for namespace |
| 2188 | // in the global module fragment. See the comments of DelayedNamespace for |
| 2189 | // details. |
| 2190 | Writer.DelayedNamespace.push_back(Elt: cast<NamespaceDecl>(Val: DC)); |
| 2191 | } else { |
| 2192 | Offsets.LexicalOffset = |
| 2193 | Writer.WriteDeclContextLexicalBlock(Context&: Record.getASTContext(), DC); |
| 2194 | Writer.WriteDeclContextVisibleBlock(Context&: Record.getASTContext(), DC, Offsets); |
| 2195 | } |
| 2196 | |
| 2197 | Record.AddLookupOffsets(Offsets); |
| 2198 | } |
| 2199 | |
| 2200 | const Decl *ASTWriter::getFirstLocalDecl(const Decl *D) { |
| 2201 | assert(IsLocalDecl(D) && "expected a local declaration" ); |
| 2202 | |
| 2203 | const Decl *Canon = D->getCanonicalDecl(); |
| 2204 | if (IsLocalDecl(D: Canon)) |
| 2205 | return Canon; |
| 2206 | |
| 2207 | const Decl *&CacheEntry = FirstLocalDeclCache[Canon]; |
| 2208 | if (CacheEntry) |
| 2209 | return CacheEntry; |
| 2210 | |
| 2211 | for (const Decl *Redecl = D; Redecl; Redecl = Redecl->getPreviousDecl()) |
| 2212 | if (IsLocalDecl(D: Redecl)) |
| 2213 | D = Redecl; |
| 2214 | return CacheEntry = D; |
| 2215 | } |
| 2216 | |
| 2217 | template <typename T> |
| 2218 | void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) { |
| 2219 | T *First = D->getFirstDecl(); |
| 2220 | T *MostRecent = First->getMostRecentDecl(); |
| 2221 | T *DAsT = static_cast<T *>(D); |
| 2222 | if (MostRecent != First) { |
| 2223 | assert(isRedeclarableDeclKind(DAsT->getKind()) && |
| 2224 | "Not considered redeclarable?" ); |
| 2225 | |
| 2226 | Record.AddDeclRef(D: First); |
| 2227 | |
| 2228 | // Write out a list of local redeclarations of this declaration if it's the |
| 2229 | // first local declaration in the chain. |
| 2230 | const Decl *FirstLocal = Writer.getFirstLocalDecl(D: DAsT); |
| 2231 | if (DAsT == FirstLocal) { |
| 2232 | // Emit a list of all imported first declarations so that we can be sure |
| 2233 | // that all redeclarations visible to this module are before D in the |
| 2234 | // redecl chain. |
| 2235 | unsigned I = Record.size(); |
| 2236 | Record.push_back(N: 0); |
| 2237 | if (Writer.Chain) |
| 2238 | AddFirstDeclFromEachModule(D: DAsT, /*IncludeLocal*/false); |
| 2239 | // This is the number of imported first declarations + 1. |
| 2240 | Record[I] = Record.size() - I; |
| 2241 | |
| 2242 | // Collect the set of local redeclarations of this declaration, from |
| 2243 | // newest to oldest. |
| 2244 | ASTWriter::RecordData LocalRedecls; |
| 2245 | ASTRecordWriter LocalRedeclWriter(Record, LocalRedecls); |
| 2246 | for (const Decl *Prev = FirstLocal->getMostRecentDecl(); |
| 2247 | Prev != FirstLocal; Prev = Prev->getPreviousDecl()) |
| 2248 | if (!Prev->isFromASTFile()) |
| 2249 | LocalRedeclWriter.AddDeclRef(D: Prev); |
| 2250 | |
| 2251 | // If we have any redecls, write them now as a separate record preceding |
| 2252 | // the declaration itself. |
| 2253 | if (LocalRedecls.empty()) |
| 2254 | Record.push_back(N: 0); |
| 2255 | else |
| 2256 | Record.AddOffset(BitOffset: LocalRedeclWriter.Emit(Code: LOCAL_REDECLARATIONS)); |
| 2257 | } else { |
| 2258 | Record.push_back(N: 0); |
| 2259 | Record.AddDeclRef(D: FirstLocal); |
| 2260 | } |
| 2261 | |
| 2262 | // Make sure that we serialize both the previous and the most-recent |
| 2263 | // declarations, which (transitively) ensures that all declarations in the |
| 2264 | // chain get serialized. |
| 2265 | // |
| 2266 | // FIXME: This is not correct; when we reach an imported declaration we |
| 2267 | // won't emit its previous declaration. |
| 2268 | (void)Writer.GetDeclRef(D: D->getPreviousDecl()); |
| 2269 | (void)Writer.GetDeclRef(D: MostRecent); |
| 2270 | } else { |
| 2271 | // We use the sentinel value 0 to indicate an only declaration. |
| 2272 | Record.push_back(N: 0); |
| 2273 | } |
| 2274 | } |
| 2275 | |
| 2276 | void ASTDeclWriter::VisitHLSLBufferDecl(HLSLBufferDecl *D) { |
| 2277 | VisitNamedDecl(D); |
| 2278 | VisitDeclContext(DC: D); |
| 2279 | Record.push_back(N: D->isCBuffer()); |
| 2280 | Record.AddSourceLocation(Loc: D->getLocStart()); |
| 2281 | Record.AddSourceLocation(Loc: D->getLBraceLoc()); |
| 2282 | Record.AddSourceLocation(Loc: D->getRBraceLoc()); |
| 2283 | |
| 2284 | Code = serialization::DECL_HLSL_BUFFER; |
| 2285 | } |
| 2286 | |
| 2287 | void ASTDeclWriter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) { |
| 2288 | Record.writeOMPChildren(Data: D->Data); |
| 2289 | VisitDecl(D); |
| 2290 | Code = serialization::DECL_OMP_THREADPRIVATE; |
| 2291 | } |
| 2292 | |
| 2293 | void ASTDeclWriter::VisitOMPAllocateDecl(OMPAllocateDecl *D) { |
| 2294 | Record.writeOMPChildren(Data: D->Data); |
| 2295 | VisitDecl(D); |
| 2296 | Code = serialization::DECL_OMP_ALLOCATE; |
| 2297 | } |
| 2298 | |
| 2299 | void ASTDeclWriter::VisitOMPRequiresDecl(OMPRequiresDecl *D) { |
| 2300 | Record.writeOMPChildren(Data: D->Data); |
| 2301 | VisitDecl(D); |
| 2302 | Code = serialization::DECL_OMP_REQUIRES; |
| 2303 | } |
| 2304 | |
| 2305 | void ASTDeclWriter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) { |
| 2306 | static_assert(DeclContext::NumOMPDeclareReductionDeclBits == 15, |
| 2307 | "You need to update the serializer after you change the " |
| 2308 | "NumOMPDeclareReductionDeclBits" ); |
| 2309 | |
| 2310 | VisitValueDecl(D); |
| 2311 | Record.AddSourceLocation(Loc: D->getBeginLoc()); |
| 2312 | Record.AddStmt(S: D->getCombinerIn()); |
| 2313 | Record.AddStmt(S: D->getCombinerOut()); |
| 2314 | Record.AddStmt(S: D->getCombiner()); |
| 2315 | Record.AddStmt(S: D->getInitOrig()); |
| 2316 | Record.AddStmt(S: D->getInitPriv()); |
| 2317 | Record.AddStmt(S: D->getInitializer()); |
| 2318 | Record.push_back(N: llvm::to_underlying(E: D->getInitializerKind())); |
| 2319 | Record.AddDeclRef(D: D->getPrevDeclInScope()); |
| 2320 | Code = serialization::DECL_OMP_DECLARE_REDUCTION; |
| 2321 | } |
| 2322 | |
| 2323 | void ASTDeclWriter::VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D) { |
| 2324 | Record.writeOMPChildren(Data: D->Data); |
| 2325 | VisitValueDecl(D); |
| 2326 | Record.AddDeclarationName(Name: D->getVarName()); |
| 2327 | Record.AddDeclRef(D: D->getPrevDeclInScope()); |
| 2328 | Code = serialization::DECL_OMP_DECLARE_MAPPER; |
| 2329 | } |
| 2330 | |
| 2331 | void ASTDeclWriter::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) { |
| 2332 | VisitVarDecl(D); |
| 2333 | Code = serialization::DECL_OMP_CAPTUREDEXPR; |
| 2334 | } |
| 2335 | |
| 2336 | void ASTDeclWriter::VisitOpenACCDeclareDecl(OpenACCDeclareDecl *D) { |
| 2337 | Record.writeUInt32(Value: D->clauses().size()); |
| 2338 | VisitDecl(D); |
| 2339 | Record.writeEnum(value: D->DirKind); |
| 2340 | Record.AddSourceLocation(Loc: D->DirectiveLoc); |
| 2341 | Record.AddSourceLocation(Loc: D->EndLoc); |
| 2342 | Record.writeOpenACCClauseList(Clauses: D->clauses()); |
| 2343 | Code = serialization::DECL_OPENACC_DECLARE; |
| 2344 | } |
| 2345 | void ASTDeclWriter::VisitOpenACCRoutineDecl(OpenACCRoutineDecl *D) { |
| 2346 | Record.writeUInt32(Value: D->clauses().size()); |
| 2347 | VisitDecl(D); |
| 2348 | Record.writeEnum(value: D->DirKind); |
| 2349 | Record.AddSourceLocation(Loc: D->DirectiveLoc); |
| 2350 | Record.AddSourceLocation(Loc: D->EndLoc); |
| 2351 | Record.AddSourceRange(Range: D->ParensLoc); |
| 2352 | Record.AddStmt(S: D->FuncRef); |
| 2353 | Record.writeOpenACCClauseList(Clauses: D->clauses()); |
| 2354 | Code = serialization::DECL_OPENACC_ROUTINE; |
| 2355 | } |
| 2356 | |
| 2357 | //===----------------------------------------------------------------------===// |
| 2358 | // ASTWriter Implementation |
| 2359 | //===----------------------------------------------------------------------===// |
| 2360 | |
| 2361 | namespace { |
| 2362 | template <FunctionDecl::TemplatedKind Kind> |
| 2363 | std::shared_ptr<llvm::BitCodeAbbrev> |
| 2364 | getFunctionDeclAbbrev(serialization::DeclCode Code) { |
| 2365 | using namespace llvm; |
| 2366 | |
| 2367 | auto Abv = std::make_shared<BitCodeAbbrev>(); |
| 2368 | Abv->Add(OpInfo: BitCodeAbbrevOp(Code)); |
| 2369 | // RedeclarableDecl |
| 2370 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // CanonicalDecl |
| 2371 | Abv->Add(OpInfo: BitCodeAbbrevOp(Kind)); |
| 2372 | if constexpr (Kind == FunctionDecl::TK_NonTemplate) { |
| 2373 | |
| 2374 | } else if constexpr (Kind == FunctionDecl::TK_FunctionTemplate) { |
| 2375 | // DescribedFunctionTemplate |
| 2376 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); |
| 2377 | } else if constexpr (Kind == FunctionDecl::TK_DependentNonTemplate) { |
| 2378 | // Instantiated From Decl |
| 2379 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); |
| 2380 | } else if constexpr (Kind == FunctionDecl::TK_MemberSpecialization) { |
| 2381 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InstantiatedFrom |
| 2382 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
| 2383 | 3)); // TemplateSpecializationKind |
| 2384 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Specialized Location |
| 2385 | } else if constexpr (Kind == |
| 2386 | FunctionDecl::TK_FunctionTemplateSpecialization) { |
| 2387 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Template |
| 2388 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
| 2389 | 3)); // TemplateSpecializationKind |
| 2390 | Abv->Add(OpInfo: BitCodeAbbrevOp(1)); // Template Argument Size |
| 2391 | Abv->Add(OpInfo: BitCodeAbbrevOp(TemplateArgument::Type)); // Template Argument Kind |
| 2392 | Abv->Add( |
| 2393 | OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Template Argument Type |
| 2394 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Is Defaulted |
| 2395 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // TemplateArgumentsAsWritten |
| 2396 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation |
| 2397 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); |
| 2398 | Abv->Add( |
| 2399 | OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Canonical Decl of template |
| 2400 | } else if constexpr (Kind == FunctionDecl:: |
| 2401 | TK_DependentFunctionTemplateSpecialization) { |
| 2402 | // Candidates of specialization |
| 2403 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
| 2404 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // TemplateArgumentsAsWritten |
| 2405 | } else { |
| 2406 | llvm_unreachable("Unknown templated kind?" ); |
| 2407 | } |
| 2408 | // Decl |
| 2409 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
| 2410 | 8)); // Packed DeclBits: ModuleOwnershipKind, |
| 2411 | // isUsed, isReferenced, AccessSpecifier, |
| 2412 | // isImplicit |
| 2413 | // |
| 2414 | // The following bits should be 0: |
| 2415 | // HasStandaloneLexicalDC, HasAttrs, |
| 2416 | // TopLevelDeclInObjCContainer, |
| 2417 | // isInvalidDecl |
| 2418 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
| 2419 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
| 2420 | // NamedDecl |
| 2421 | Abv->Add(OpInfo: BitCodeAbbrevOp(DeclarationName::Identifier)); // NameKind |
| 2422 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Identifier |
| 2423 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // AnonDeclNumber |
| 2424 | // ValueDecl |
| 2425 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 2426 | // DeclaratorDecl |
| 2427 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerLocStart |
| 2428 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // HasExtInfo |
| 2429 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType |
| 2430 | // FunctionDecl |
| 2431 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 11)); // IDNS |
| 2432 | Abv->Add(OpInfo: BitCodeAbbrevOp( |
| 2433 | BitCodeAbbrevOp::Fixed, |
| 2434 | 28)); // Packed Function Bits: StorageClass, Inline, InlineSpecified, |
| 2435 | // VirtualAsWritten, Pure, HasInheritedProto, HasWrittenProto, |
| 2436 | // Deleted, Trivial, TrivialForCall, Defaulted, ExplicitlyDefaulted, |
| 2437 | // IsIneligibleOrNotSelected, ImplicitReturnZero, Constexpr, |
| 2438 | // UsesSEHTry, SkippedBody, MultiVersion, LateParsed, |
| 2439 | // FriendConstraintRefersToEnclosingTemplate, Linkage, |
| 2440 | // ShouldSkipCheckingODR |
| 2441 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LocEnd |
| 2442 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // ODRHash |
| 2443 | // This Array slurps the rest of the record. Fortunately we want to encode |
| 2444 | // (nearly) all the remaining (variable number of) fields in the same way. |
| 2445 | // |
| 2446 | // This is: |
| 2447 | // NumParams and Params[] from FunctionDecl, and |
| 2448 | // NumOverriddenMethods, OverriddenMethods[] from CXXMethodDecl. |
| 2449 | // |
| 2450 | // Add an AbbrevOp for 'size then elements' and use it here. |
| 2451 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
| 2452 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); |
| 2453 | return Abv; |
| 2454 | } |
| 2455 | |
| 2456 | template <FunctionDecl::TemplatedKind Kind> |
| 2457 | std::shared_ptr<llvm::BitCodeAbbrev> getCXXMethodAbbrev() { |
| 2458 | return getFunctionDeclAbbrev<Kind>(serialization::DECL_CXX_METHOD); |
| 2459 | } |
| 2460 | } // namespace |
| 2461 | |
| 2462 | void ASTWriter::WriteDeclAbbrevs() { |
| 2463 | using namespace llvm; |
| 2464 | |
| 2465 | std::shared_ptr<BitCodeAbbrev> Abv; |
| 2466 | |
| 2467 | // Abbreviation for DECL_FIELD |
| 2468 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2469 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_FIELD)); |
| 2470 | // Decl |
| 2471 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
| 2472 | 7)); // Packed DeclBits: ModuleOwnershipKind, |
| 2473 | // isUsed, isReferenced, AccessSpecifier, |
| 2474 | // |
| 2475 | // The following bits should be 0: |
| 2476 | // isImplicit, HasStandaloneLexicalDC, HasAttrs, |
| 2477 | // TopLevelDeclInObjCContainer, |
| 2478 | // isInvalidDecl |
| 2479 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
| 2480 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
| 2481 | // NamedDecl |
| 2482 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // NameKind = Identifier |
| 2483 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
| 2484 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // AnonDeclNumber |
| 2485 | // ValueDecl |
| 2486 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 2487 | // DeclaratorDecl |
| 2488 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc |
| 2489 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // hasExtInfo |
| 2490 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType |
| 2491 | // FieldDecl |
| 2492 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable |
| 2493 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // StorageKind |
| 2494 | // Type Source Info |
| 2495 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
| 2496 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc |
| 2497 | DeclFieldAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2498 | |
| 2499 | // Abbreviation for DECL_OBJC_IVAR |
| 2500 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2501 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_OBJC_IVAR)); |
| 2502 | // Decl |
| 2503 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
| 2504 | 12)); // Packed DeclBits: HasStandaloneLexicalDC, |
| 2505 | // isInvalidDecl, HasAttrs, isImplicit, isUsed, |
| 2506 | // isReferenced, TopLevelDeclInObjCContainer, |
| 2507 | // AccessSpecifier, ModuleOwnershipKind |
| 2508 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
| 2509 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
| 2510 | // NamedDecl |
| 2511 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // NameKind = Identifier |
| 2512 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
| 2513 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // AnonDeclNumber |
| 2514 | // ValueDecl |
| 2515 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 2516 | // DeclaratorDecl |
| 2517 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc |
| 2518 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // hasExtInfo |
| 2519 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType |
| 2520 | // FieldDecl |
| 2521 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable |
| 2522 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // InitStyle |
| 2523 | // ObjC Ivar |
| 2524 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getAccessControl |
| 2525 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getSynthesize |
| 2526 | // Type Source Info |
| 2527 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
| 2528 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc |
| 2529 | DeclObjCIvarAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2530 | |
| 2531 | // Abbreviation for DECL_ENUM |
| 2532 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2533 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_ENUM)); |
| 2534 | // Redeclarable |
| 2535 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // No redeclaration |
| 2536 | // Decl |
| 2537 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
| 2538 | 7)); // Packed DeclBits: ModuleOwnershipKind, |
| 2539 | // isUsed, isReferenced, AccessSpecifier, |
| 2540 | // |
| 2541 | // The following bits should be 0: |
| 2542 | // isImplicit, HasStandaloneLexicalDC, HasAttrs, |
| 2543 | // TopLevelDeclInObjCContainer, |
| 2544 | // isInvalidDecl |
| 2545 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
| 2546 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
| 2547 | // NamedDecl |
| 2548 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // NameKind = Identifier |
| 2549 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
| 2550 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // AnonDeclNumber |
| 2551 | // TypeDecl |
| 2552 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
| 2553 | // TagDecl |
| 2554 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace |
| 2555 | Abv->Add(OpInfo: BitCodeAbbrevOp( |
| 2556 | BitCodeAbbrevOp::Fixed, |
| 2557 | 9)); // Packed Tag Decl Bits: getTagKind, isCompleteDefinition, |
| 2558 | // EmbeddedInDeclarator, IsFreeStanding, |
| 2559 | // isCompleteDefinitionRequired, ExtInfoKind |
| 2560 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation |
| 2561 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation |
| 2562 | // EnumDecl |
| 2563 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // AddTypeRef |
| 2564 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IntegerType |
| 2565 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getPromotionType |
| 2566 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 20)); // Enum Decl Bits |
| 2567 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));// ODRHash |
| 2568 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InstantiatedMembEnum |
| 2569 | // DC |
| 2570 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset |
| 2571 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset |
| 2572 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ModuleLocalOffset |
| 2573 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TULocalOffset |
| 2574 | DeclEnumAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2575 | |
| 2576 | // Abbreviation for DECL_RECORD |
| 2577 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2578 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_RECORD)); |
| 2579 | // Redeclarable |
| 2580 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // No redeclaration |
| 2581 | // Decl |
| 2582 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
| 2583 | 7)); // Packed DeclBits: ModuleOwnershipKind, |
| 2584 | // isUsed, isReferenced, AccessSpecifier, |
| 2585 | // |
| 2586 | // The following bits should be 0: |
| 2587 | // isImplicit, HasStandaloneLexicalDC, HasAttrs, |
| 2588 | // TopLevelDeclInObjCContainer, |
| 2589 | // isInvalidDecl |
| 2590 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
| 2591 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
| 2592 | // NamedDecl |
| 2593 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // NameKind = Identifier |
| 2594 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
| 2595 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // AnonDeclNumber |
| 2596 | // TypeDecl |
| 2597 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
| 2598 | // TagDecl |
| 2599 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace |
| 2600 | Abv->Add(OpInfo: BitCodeAbbrevOp( |
| 2601 | BitCodeAbbrevOp::Fixed, |
| 2602 | 9)); // Packed Tag Decl Bits: getTagKind, isCompleteDefinition, |
| 2603 | // EmbeddedInDeclarator, IsFreeStanding, |
| 2604 | // isCompleteDefinitionRequired, ExtInfoKind |
| 2605 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation |
| 2606 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation |
| 2607 | // RecordDecl |
| 2608 | Abv->Add(OpInfo: BitCodeAbbrevOp( |
| 2609 | BitCodeAbbrevOp::Fixed, |
| 2610 | 14)); // Packed Record Decl Bits: FlexibleArrayMember, |
| 2611 | // AnonymousStructUnion, hasObjectMember, hasVolatileMember, |
| 2612 | // isNonTrivialToPrimitiveDefaultInitialize, |
| 2613 | // isNonTrivialToPrimitiveCopy, isNonTrivialToPrimitiveDestroy, |
| 2614 | // hasNonTrivialToPrimitiveDefaultInitializeCUnion, |
| 2615 | // hasNonTrivialToPrimitiveDestructCUnion, |
| 2616 | // hasNonTrivialToPrimitiveCopyCUnion, |
| 2617 | // hasUninitializedExplicitInitFields, isParamDestroyedInCallee, |
| 2618 | // getArgPassingRestrictions |
| 2619 | // ODRHash |
| 2620 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 26)); |
| 2621 | |
| 2622 | // DC |
| 2623 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset |
| 2624 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset |
| 2625 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ModuleLocalOffset |
| 2626 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TULocalOffset |
| 2627 | DeclRecordAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2628 | |
| 2629 | // Abbreviation for DECL_PARM_VAR |
| 2630 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2631 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_PARM_VAR)); |
| 2632 | // Redeclarable |
| 2633 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // No redeclaration |
| 2634 | // Decl |
| 2635 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
| 2636 | 8)); // Packed DeclBits: ModuleOwnershipKind, isUsed, |
| 2637 | // isReferenced, AccessSpecifier, |
| 2638 | // HasStandaloneLexicalDC, HasAttrs, isImplicit, |
| 2639 | // TopLevelDeclInObjCContainer, |
| 2640 | // isInvalidDecl, |
| 2641 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
| 2642 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
| 2643 | // NamedDecl |
| 2644 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // NameKind = Identifier |
| 2645 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
| 2646 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // AnonDeclNumber |
| 2647 | // ValueDecl |
| 2648 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 2649 | // DeclaratorDecl |
| 2650 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc |
| 2651 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // hasExtInfo |
| 2652 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType |
| 2653 | // VarDecl |
| 2654 | Abv->Add( |
| 2655 | OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
| 2656 | 12)); // Packed Var Decl bits: SClass, TSCSpec, InitStyle, |
| 2657 | // isARCPseudoStrong, Linkage, ModulesCodegen |
| 2658 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // VarKind (local enum) |
| 2659 | // ParmVarDecl |
| 2660 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ScopeIndex |
| 2661 | Abv->Add(OpInfo: BitCodeAbbrevOp( |
| 2662 | BitCodeAbbrevOp::Fixed, |
| 2663 | 19)); // Packed Parm Var Decl bits: IsObjCMethodParameter, ScopeDepth, |
| 2664 | // ObjCDeclQualifier, KNRPromoted, |
| 2665 | // HasInheritedDefaultArg, HasUninstantiatedDefaultArg |
| 2666 | // Type Source Info |
| 2667 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
| 2668 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc |
| 2669 | DeclParmVarAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2670 | |
| 2671 | // Abbreviation for DECL_TYPEDEF |
| 2672 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2673 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_TYPEDEF)); |
| 2674 | // Redeclarable |
| 2675 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // No redeclaration |
| 2676 | // Decl |
| 2677 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
| 2678 | 7)); // Packed DeclBits: ModuleOwnershipKind, |
| 2679 | // isReferenced, isUsed, AccessSpecifier. Other |
| 2680 | // higher bits should be 0: isImplicit, |
| 2681 | // HasStandaloneLexicalDC, HasAttrs, |
| 2682 | // TopLevelDeclInObjCContainer, isInvalidDecl |
| 2683 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
| 2684 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
| 2685 | // NamedDecl |
| 2686 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // NameKind = Identifier |
| 2687 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
| 2688 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // AnonDeclNumber |
| 2689 | // TypeDecl |
| 2690 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
| 2691 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref |
| 2692 | // TypedefDecl |
| 2693 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
| 2694 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc |
| 2695 | DeclTypedefAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2696 | |
| 2697 | // Abbreviation for DECL_VAR |
| 2698 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2699 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_VAR)); |
| 2700 | // Redeclarable |
| 2701 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // No redeclaration |
| 2702 | // Decl |
| 2703 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
| 2704 | 12)); // Packed DeclBits: HasStandaloneLexicalDC, |
| 2705 | // isInvalidDecl, HasAttrs, isImplicit, isUsed, |
| 2706 | // isReferenced, TopLevelDeclInObjCContainer, |
| 2707 | // AccessSpecifier, ModuleOwnershipKind |
| 2708 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
| 2709 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
| 2710 | // NamedDecl |
| 2711 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // NameKind = Identifier |
| 2712 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
| 2713 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // AnonDeclNumber |
| 2714 | // ValueDecl |
| 2715 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 2716 | // DeclaratorDecl |
| 2717 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc |
| 2718 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // hasExtInfo |
| 2719 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType |
| 2720 | // VarDecl |
| 2721 | Abv->Add(OpInfo: BitCodeAbbrevOp( |
| 2722 | BitCodeAbbrevOp::Fixed, |
| 2723 | 22)); // Packed Var Decl bits: Linkage, ModulesCodegen, |
| 2724 | // SClass, TSCSpec, InitStyle, |
| 2725 | // isARCPseudoStrong, IsThisDeclarationADemotedDefinition, |
| 2726 | // isExceptionVariable, isNRVOVariable, isCXXForRangeDecl, |
| 2727 | // isInline, isInlineSpecified, isConstexpr, |
| 2728 | // isInitCapture, isPrevDeclInSameScope, hasInitWithSideEffects, |
| 2729 | // EscapingByref, HasDeducedType, ImplicitParamKind, isObjCForDecl |
| 2730 | // IsCXXForRangeImplicitVar |
| 2731 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // VarKind (local enum) |
| 2732 | // Type Source Info |
| 2733 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
| 2734 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc |
| 2735 | DeclVarAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2736 | |
| 2737 | // Abbreviation for DECL_CXX_METHOD |
| 2738 | DeclCXXMethodAbbrev = |
| 2739 | Stream.EmitAbbrev(Abbv: getCXXMethodAbbrev<FunctionDecl::TK_NonTemplate>()); |
| 2740 | DeclTemplateCXXMethodAbbrev = Stream.EmitAbbrev( |
| 2741 | Abbv: getCXXMethodAbbrev<FunctionDecl::TK_FunctionTemplate>()); |
| 2742 | DeclDependentNonTemplateCXXMethodAbbrev = Stream.EmitAbbrev( |
| 2743 | Abbv: getCXXMethodAbbrev<FunctionDecl::TK_DependentNonTemplate>()); |
| 2744 | DeclMemberSpecializedCXXMethodAbbrev = Stream.EmitAbbrev( |
| 2745 | Abbv: getCXXMethodAbbrev<FunctionDecl::TK_MemberSpecialization>()); |
| 2746 | DeclTemplateSpecializedCXXMethodAbbrev = Stream.EmitAbbrev( |
| 2747 | Abbv: getCXXMethodAbbrev<FunctionDecl::TK_FunctionTemplateSpecialization>()); |
| 2748 | DeclDependentSpecializationCXXMethodAbbrev = Stream.EmitAbbrev( |
| 2749 | Abbv: getCXXMethodAbbrev< |
| 2750 | FunctionDecl::TK_DependentFunctionTemplateSpecialization>()); |
| 2751 | |
| 2752 | // Abbreviation for DECL_TEMPLATE_TYPE_PARM |
| 2753 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2754 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_TEMPLATE_TYPE_PARM)); |
| 2755 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // hasTypeConstraint |
| 2756 | // Decl |
| 2757 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
| 2758 | 7)); // Packed DeclBits: ModuleOwnershipKind, |
| 2759 | // isReferenced, isUsed, AccessSpecifier. Other |
| 2760 | // higher bits should be 0: isImplicit, |
| 2761 | // HasStandaloneLexicalDC, HasAttrs, |
| 2762 | // TopLevelDeclInObjCContainer, isInvalidDecl |
| 2763 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
| 2764 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
| 2765 | // NamedDecl |
| 2766 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // NameKind = Identifier |
| 2767 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
| 2768 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); |
| 2769 | // TypeDecl |
| 2770 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
| 2771 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref |
| 2772 | // TemplateTypeParmDecl |
| 2773 | Abv->Add( |
| 2774 | OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // wasDeclaredWithTypename |
| 2775 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // OwnsDefaultArg |
| 2776 | DeclTemplateTypeParmAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2777 | |
| 2778 | // Abbreviation for DECL_USING_SHADOW |
| 2779 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2780 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_USING_SHADOW)); |
| 2781 | // Redeclarable |
| 2782 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // No redeclaration |
| 2783 | // Decl |
| 2784 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
| 2785 | 12)); // Packed DeclBits: HasStandaloneLexicalDC, |
| 2786 | // isInvalidDecl, HasAttrs, isImplicit, isUsed, |
| 2787 | // isReferenced, TopLevelDeclInObjCContainer, |
| 2788 | // AccessSpecifier, ModuleOwnershipKind |
| 2789 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
| 2790 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
| 2791 | // NamedDecl |
| 2792 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // NameKind = Identifier |
| 2793 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
| 2794 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); |
| 2795 | // UsingShadowDecl |
| 2796 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TargetDecl |
| 2797 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 11)); // IDNS |
| 2798 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // UsingOrNextShadow |
| 2799 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, |
| 2800 | 6)); // InstantiatedFromUsingShadowDecl |
| 2801 | DeclUsingShadowAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2802 | |
| 2803 | // Abbreviation for EXPR_DECL_REF |
| 2804 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2805 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::EXPR_DECL_REF)); |
| 2806 | // Stmt |
| 2807 | // Expr |
| 2808 | // PackingBits: DependenceKind, ValueKind. ObjectKind should be 0. |
| 2809 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7)); |
| 2810 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 2811 | // DeclRefExpr |
| 2812 | // Packing Bits: , HadMultipleCandidates, RefersToEnclosingVariableOrCapture, |
| 2813 | // IsImmediateEscalating, NonOdrUseReason. |
| 2814 | // GetDeclFound, HasQualifier and ExplicitTemplateArgs should be 0. |
| 2815 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5)); |
| 2816 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclRef |
| 2817 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location |
| 2818 | DeclRefExprAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2819 | |
| 2820 | // Abbreviation for EXPR_INTEGER_LITERAL |
| 2821 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2822 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::EXPR_INTEGER_LITERAL)); |
| 2823 | //Stmt |
| 2824 | // Expr |
| 2825 | // DependenceKind, ValueKind, ObjectKind |
| 2826 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); |
| 2827 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 2828 | // Integer Literal |
| 2829 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location |
| 2830 | Abv->Add(OpInfo: BitCodeAbbrevOp(32)); // Bit Width |
| 2831 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Value |
| 2832 | IntegerLiteralAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2833 | |
| 2834 | // Abbreviation for EXPR_CHARACTER_LITERAL |
| 2835 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2836 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::EXPR_CHARACTER_LITERAL)); |
| 2837 | //Stmt |
| 2838 | // Expr |
| 2839 | // DependenceKind, ValueKind, ObjectKind |
| 2840 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); |
| 2841 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 2842 | // Character Literal |
| 2843 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getValue |
| 2844 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location |
| 2845 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // getKind |
| 2846 | CharacterLiteralAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2847 | |
| 2848 | // Abbreviation for EXPR_IMPLICIT_CAST |
| 2849 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2850 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::EXPR_IMPLICIT_CAST)); |
| 2851 | // Stmt |
| 2852 | // Expr |
| 2853 | // Packing Bits: DependenceKind, ValueKind, ObjectKind, |
| 2854 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); |
| 2855 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 2856 | // CastExpr |
| 2857 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // PathSize |
| 2858 | // Packing Bits: CastKind, StoredFPFeatures, isPartOfExplicitCast |
| 2859 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 9)); |
| 2860 | // ImplicitCastExpr |
| 2861 | ExprImplicitCastAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2862 | |
| 2863 | // Abbreviation for EXPR_BINARY_OPERATOR |
| 2864 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2865 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::EXPR_BINARY_OPERATOR)); |
| 2866 | // Stmt |
| 2867 | // Expr |
| 2868 | // Packing Bits: DependenceKind. ValueKind and ObjectKind should |
| 2869 | // be 0 in this case. |
| 2870 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5)); |
| 2871 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 2872 | // BinaryOperator |
| 2873 | Abv->Add( |
| 2874 | OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // OpCode and HasFPFeatures |
| 2875 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
| 2876 | BinaryOperatorAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2877 | |
| 2878 | // Abbreviation for EXPR_COMPOUND_ASSIGN_OPERATOR |
| 2879 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2880 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::EXPR_COMPOUND_ASSIGN_OPERATOR)); |
| 2881 | // Stmt |
| 2882 | // Expr |
| 2883 | // Packing Bits: DependenceKind. ValueKind and ObjectKind should |
| 2884 | // be 0 in this case. |
| 2885 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5)); |
| 2886 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 2887 | // BinaryOperator |
| 2888 | // Packing Bits: OpCode. The HasFPFeatures bit should be 0 |
| 2889 | Abv->Add( |
| 2890 | OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // OpCode and HasFPFeatures |
| 2891 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
| 2892 | // CompoundAssignOperator |
| 2893 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LHSType |
| 2894 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Result Type |
| 2895 | CompoundAssignOperatorAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2896 | |
| 2897 | // Abbreviation for EXPR_CALL |
| 2898 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2899 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::EXPR_CALL)); |
| 2900 | // Stmt |
| 2901 | // Expr |
| 2902 | // Packing Bits: DependenceKind, ValueKind, ObjectKind, |
| 2903 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); |
| 2904 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 2905 | // CallExpr |
| 2906 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // NumArgs |
| 2907 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // ADLCallKind |
| 2908 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
| 2909 | CallExprAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2910 | |
| 2911 | // Abbreviation for EXPR_CXX_OPERATOR_CALL |
| 2912 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2913 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::EXPR_CXX_OPERATOR_CALL)); |
| 2914 | // Stmt |
| 2915 | // Expr |
| 2916 | // Packing Bits: DependenceKind, ValueKind, ObjectKind, |
| 2917 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); |
| 2918 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 2919 | // CallExpr |
| 2920 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // NumArgs |
| 2921 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // ADLCallKind |
| 2922 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
| 2923 | // CXXOperatorCallExpr |
| 2924 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Operator Kind |
| 2925 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
| 2926 | CXXOperatorCallExprAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2927 | |
| 2928 | // Abbreviation for EXPR_CXX_MEMBER_CALL |
| 2929 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2930 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::EXPR_CXX_MEMBER_CALL)); |
| 2931 | // Stmt |
| 2932 | // Expr |
| 2933 | // Packing Bits: DependenceKind, ValueKind, ObjectKind, |
| 2934 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); |
| 2935 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 2936 | // CallExpr |
| 2937 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // NumArgs |
| 2938 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // ADLCallKind |
| 2939 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
| 2940 | // CXXMemberCallExpr |
| 2941 | CXXMemberCallExprAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2942 | |
| 2943 | // Abbreviation for STMT_COMPOUND |
| 2944 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2945 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::STMT_COMPOUND)); |
| 2946 | // Stmt |
| 2947 | // CompoundStmt |
| 2948 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Num Stmts |
| 2949 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // hasStoredFPFeatures |
| 2950 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
| 2951 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
| 2952 | CompoundStmtAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2953 | |
| 2954 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2955 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_CONTEXT_LEXICAL)); |
| 2956 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2957 | DeclContextLexicalAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2958 | |
| 2959 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2960 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_CONTEXT_VISIBLE)); |
| 2961 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2962 | DeclContextVisibleLookupAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2963 | |
| 2964 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2965 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_CONTEXT_MODULE_LOCAL_VISIBLE)); |
| 2966 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2967 | DeclModuleLocalVisibleLookupAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2968 | |
| 2969 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2970 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_CONTEXT_TU_LOCAL_VISIBLE)); |
| 2971 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2972 | DeclTULocalLookupAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2973 | |
| 2974 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2975 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_SPECIALIZATIONS)); |
| 2976 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2977 | DeclSpecializationsAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2978 | |
| 2979 | Abv = std::make_shared<BitCodeAbbrev>(); |
| 2980 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_PARTIAL_SPECIALIZATIONS)); |
| 2981 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2982 | DeclPartialSpecializationsAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
| 2983 | } |
| 2984 | |
| 2985 | /// isRequiredDecl - Check if this is a "required" Decl, which must be seen by |
| 2986 | /// consumers of the AST. |
| 2987 | /// |
| 2988 | /// Such decls will always be deserialized from the AST file, so we would like |
| 2989 | /// this to be as restrictive as possible. Currently the predicate is driven by |
| 2990 | /// code generation requirements, if other clients have a different notion of |
| 2991 | /// what is "required" then we may have to consider an alternate scheme where |
| 2992 | /// clients can iterate over the top-level decls and get information on them, |
| 2993 | /// without necessary deserializing them. We could explicitly require such |
| 2994 | /// clients to use a separate API call to "realize" the decl. This should be |
| 2995 | /// relatively painless since they would presumably only do it for top-level |
| 2996 | /// decls. |
| 2997 | static bool isRequiredDecl(const Decl *D, ASTContext &Context, |
| 2998 | Module *WritingModule) { |
| 2999 | // Named modules have different semantics than header modules. Every named |
| 3000 | // module units owns a translation unit. So the importer of named modules |
| 3001 | // doesn't need to deserilize everything ahead of time. |
| 3002 | if (WritingModule && WritingModule->isNamedModule()) { |
| 3003 | // The PragmaCommentDecl and PragmaDetectMismatchDecl are MSVC's extension. |
| 3004 | // And the behavior of MSVC for such cases will leak this to the module |
| 3005 | // users. Given pragma is not a standard thing, the compiler has the space |
| 3006 | // to do their own decision. Let's follow MSVC here. |
| 3007 | if (isa<PragmaCommentDecl, PragmaDetectMismatchDecl>(Val: D)) |
| 3008 | return true; |
| 3009 | return false; |
| 3010 | } |
| 3011 | |
| 3012 | // An ObjCMethodDecl is never considered as "required" because its |
| 3013 | // implementation container always is. |
| 3014 | |
| 3015 | // File scoped assembly or obj-c or OMP declare target implementation must be |
| 3016 | // seen. |
| 3017 | if (isa<FileScopeAsmDecl, TopLevelStmtDecl, ObjCImplDecl>(Val: D)) |
| 3018 | return true; |
| 3019 | |
| 3020 | if (WritingModule && isPartOfPerModuleInitializer(D)) { |
| 3021 | // These declarations are part of the module initializer, and are emitted |
| 3022 | // if and when the module is imported, rather than being emitted eagerly. |
| 3023 | return false; |
| 3024 | } |
| 3025 | |
| 3026 | return Context.DeclMustBeEmitted(D); |
| 3027 | } |
| 3028 | |
| 3029 | void ASTWriter::WriteDecl(ASTContext &Context, Decl *D) { |
| 3030 | PrettyDeclStackTraceEntry CrashInfo(Context, D, SourceLocation(), |
| 3031 | "serializing" ); |
| 3032 | |
| 3033 | // Determine the ID for this declaration. |
| 3034 | LocalDeclID ID; |
| 3035 | assert(!D->isFromASTFile() && "should not be emitting imported decl" ); |
| 3036 | LocalDeclID &IDR = DeclIDs[D]; |
| 3037 | if (IDR.isInvalid()) |
| 3038 | IDR = NextDeclID++; |
| 3039 | |
| 3040 | ID = IDR; |
| 3041 | |
| 3042 | assert(ID >= FirstDeclID && "invalid decl ID" ); |
| 3043 | |
| 3044 | RecordData Record; |
| 3045 | ASTDeclWriter W(*this, Context, Record, GeneratingReducedBMI); |
| 3046 | |
| 3047 | // Build a record for this declaration |
| 3048 | W.Visit(D); |
| 3049 | |
| 3050 | // Emit this declaration to the bitstream. |
| 3051 | uint64_t Offset = W.Emit(D); |
| 3052 | |
| 3053 | // Record the offset for this declaration |
| 3054 | SourceLocation Loc = D->getLocation(); |
| 3055 | SourceLocationEncoding::RawLocEncoding RawLoc = |
| 3056 | getRawSourceLocationEncoding(Loc: getAdjustedLocation(Loc)); |
| 3057 | |
| 3058 | unsigned Index = ID.getRawValue() - FirstDeclID.getRawValue(); |
| 3059 | if (DeclOffsets.size() == Index) |
| 3060 | DeclOffsets.emplace_back(args&: RawLoc, args&: Offset, args&: DeclTypesBlockStartOffset); |
| 3061 | else if (DeclOffsets.size() < Index) { |
| 3062 | // FIXME: Can/should this happen? |
| 3063 | DeclOffsets.resize(new_size: Index+1); |
| 3064 | DeclOffsets[Index].setRawLoc(RawLoc); |
| 3065 | DeclOffsets[Index].setBitOffset(Offset, DeclTypesBlockStartOffset); |
| 3066 | } else { |
| 3067 | llvm_unreachable("declarations should be emitted in ID order" ); |
| 3068 | } |
| 3069 | |
| 3070 | SourceManager &SM = Context.getSourceManager(); |
| 3071 | if (Loc.isValid() && SM.isLocalSourceLocation(Loc)) |
| 3072 | associateDeclWithFile(D, ID); |
| 3073 | |
| 3074 | // Note declarations that should be deserialized eagerly so that we can add |
| 3075 | // them to a record in the AST file later. |
| 3076 | if (isRequiredDecl(D, Context, WritingModule)) |
| 3077 | AddDeclRef(D, Record&: EagerlyDeserializedDecls); |
| 3078 | } |
| 3079 | |
| 3080 | void ASTRecordWriter::AddFunctionDefinition(const FunctionDecl *FD) { |
| 3081 | // Switch case IDs are per function body. |
| 3082 | Writer->ClearSwitchCaseIDs(); |
| 3083 | |
| 3084 | assert(FD->doesThisDeclarationHaveABody()); |
| 3085 | bool ModulesCodegen = shouldFunctionGenerateHereOnly(FD); |
| 3086 | Record->push_back(Elt: ModulesCodegen); |
| 3087 | if (ModulesCodegen) |
| 3088 | Writer->AddDeclRef(D: FD, Record&: Writer->ModularCodegenDecls); |
| 3089 | if (auto *CD = dyn_cast<CXXConstructorDecl>(Val: FD)) { |
| 3090 | Record->push_back(Elt: CD->getNumCtorInitializers()); |
| 3091 | if (CD->getNumCtorInitializers()) |
| 3092 | AddCXXCtorInitializers(CtorInits: llvm::ArrayRef(CD->init_begin(), CD->init_end())); |
| 3093 | } |
| 3094 | AddStmt(S: FD->getBody()); |
| 3095 | } |
| 3096 | |