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