| //===- ASTReaderDecl.cpp - Decl Deserialization ---------------------------===// |
| // |
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| // See https://llvm.org/LICENSE.txt for license information. |
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| // |
| //===----------------------------------------------------------------------===// |
| // |
| // This file implements the ASTReader::readDeclRecord method, which is the |
| // entrypoint for loading a decl. |
| // |
| //===----------------------------------------------------------------------===// |
| |
| #include "ASTCommon.h" |
| #include "ASTReaderInternals.h" |
| #include "clang/AST/ASTConcept.h" |
| #include "clang/AST/ASTContext.h" |
| #include "clang/AST/ASTStructuralEquivalence.h" |
| #include "clang/AST/Attr.h" |
| #include "clang/AST/AttrIterator.h" |
| #include "clang/AST/Decl.h" |
| #include "clang/AST/DeclBase.h" |
| #include "clang/AST/DeclCXX.h" |
| #include "clang/AST/DeclFriend.h" |
| #include "clang/AST/DeclObjC.h" |
| #include "clang/AST/DeclOpenMP.h" |
| #include "clang/AST/DeclTemplate.h" |
| #include "clang/AST/DeclVisitor.h" |
| #include "clang/AST/DeclarationName.h" |
| #include "clang/AST/Expr.h" |
| #include "clang/AST/ExternalASTSource.h" |
| #include "clang/AST/LambdaCapture.h" |
| #include "clang/AST/NestedNameSpecifier.h" |
| #include "clang/AST/OpenMPClause.h" |
| #include "clang/AST/Redeclarable.h" |
| #include "clang/AST/Stmt.h" |
| #include "clang/AST/TemplateBase.h" |
| #include "clang/AST/Type.h" |
| #include "clang/AST/UnresolvedSet.h" |
| #include "clang/Basic/AttrKinds.h" |
| #include "clang/Basic/DiagnosticSema.h" |
| #include "clang/Basic/ExceptionSpecificationType.h" |
| #include "clang/Basic/IdentifierTable.h" |
| #include "clang/Basic/LLVM.h" |
| #include "clang/Basic/Lambda.h" |
| #include "clang/Basic/LangOptions.h" |
| #include "clang/Basic/Linkage.h" |
| #include "clang/Basic/Module.h" |
| #include "clang/Basic/PragmaKinds.h" |
| #include "clang/Basic/SourceLocation.h" |
| #include "clang/Basic/Specifiers.h" |
| #include "clang/Basic/Stack.h" |
| #include "clang/Sema/IdentifierResolver.h" |
| #include "clang/Serialization/ASTBitCodes.h" |
| #include "clang/Serialization/ASTRecordReader.h" |
| #include "clang/Serialization/ContinuousRangeMap.h" |
| #include "clang/Serialization/ModuleFile.h" |
| #include "llvm/ADT/DenseMap.h" |
| #include "llvm/ADT/FoldingSet.h" |
| #include "llvm/ADT/STLExtras.h" |
| #include "llvm/ADT/SmallPtrSet.h" |
| #include "llvm/ADT/SmallVector.h" |
| #include "llvm/ADT/iterator_range.h" |
| #include "llvm/Bitstream/BitstreamReader.h" |
| #include "llvm/Support/Casting.h" |
| #include "llvm/Support/ErrorHandling.h" |
| #include "llvm/Support/SaveAndRestore.h" |
| #include <algorithm> |
| #include <cassert> |
| #include <cstdint> |
| #include <cstring> |
| #include <string> |
| #include <utility> |
| |
| using namespace clang; |
| using namespace serialization; |
| |
| //===----------------------------------------------------------------------===// |
| // Declaration Merging |
| //===----------------------------------------------------------------------===// |
| |
| namespace { |
| /// Results from loading a RedeclarableDecl. |
| class RedeclarableResult { |
| Decl *MergeWith; |
| GlobalDeclID FirstID; |
| bool IsKeyDecl; |
| |
| public: |
| RedeclarableResult(Decl *MergeWith, GlobalDeclID FirstID, bool IsKeyDecl) |
| : MergeWith(MergeWith), FirstID(FirstID), IsKeyDecl(IsKeyDecl) {} |
| |
| /// Retrieve the first ID. |
| GlobalDeclID getFirstID() const { return FirstID; } |
| |
| /// Is this declaration a key declaration? |
| bool isKeyDecl() const { return IsKeyDecl; } |
| |
| /// Get a known declaration that this should be merged with, if |
| /// any. |
| Decl *getKnownMergeTarget() const { return MergeWith; } |
| }; |
| } // namespace |
| |
| namespace clang { |
| class ASTDeclMerger { |
| ASTReader &Reader; |
| |
| public: |
| ASTDeclMerger(ASTReader &Reader) : Reader(Reader) {} |
| |
| void mergeLambda(CXXRecordDecl *D, RedeclarableResult &Redecl, Decl &Context, |
| unsigned Number); |
| |
| /// \param KeyDeclID the decl ID of the key declaration \param D. |
| /// GlobalDeclID() if \param is not a key declaration. |
| /// See the comments of ASTReader::KeyDecls for the explanation |
| /// of key declaration. |
| template <typename T> |
| void mergeRedeclarableImpl(Redeclarable<T> *D, T *Existing, |
| GlobalDeclID KeyDeclID); |
| |
| template <typename T> |
| void mergeRedeclarable(Redeclarable<T> *D, T *Existing, |
| RedeclarableResult &Redecl) { |
| mergeRedeclarableImpl( |
| D, Existing, Redecl.isKeyDecl() ? Redecl.getFirstID() : GlobalDeclID()); |
| } |
| |
| void mergeTemplatePattern(RedeclarableTemplateDecl *D, |
| RedeclarableTemplateDecl *Existing, bool IsKeyDecl); |
| |
| void MergeDefinitionData(CXXRecordDecl *D, |
| struct CXXRecordDecl::DefinitionData &&NewDD); |
| void MergeDefinitionData(ObjCInterfaceDecl *D, |
| struct ObjCInterfaceDecl::DefinitionData &&NewDD); |
| void MergeDefinitionData(ObjCProtocolDecl *D, |
| struct ObjCProtocolDecl::DefinitionData &&NewDD); |
| }; |
| } // namespace clang |
| |
| //===----------------------------------------------------------------------===// |
| // Declaration deserialization |
| //===----------------------------------------------------------------------===// |
| |
| namespace clang { |
| class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> { |
| ASTReader &Reader; |
| ASTDeclMerger MergeImpl; |
| ASTRecordReader &Record; |
| ASTReader::RecordLocation Loc; |
| const GlobalDeclID ThisDeclID; |
| const SourceLocation ThisDeclLoc; |
| |
| using RecordData = ASTReader::RecordData; |
| |
| TypeID DeferredTypeID = 0; |
| unsigned AnonymousDeclNumber = 0; |
| GlobalDeclID NamedDeclForTagDecl = GlobalDeclID(); |
| IdentifierInfo *TypedefNameForLinkage = nullptr; |
| |
| /// A flag to carry the information for a decl from the entity is |
| /// used. We use it to delay the marking of the canonical decl as used until |
| /// the entire declaration is deserialized and merged. |
| bool IsDeclMarkedUsed = false; |
| |
| uint64_t GetCurrentCursorOffset(); |
| |
| uint64_t ReadLocalOffset() { |
| uint64_t LocalOffset = Record.readInt(); |
| assert(LocalOffset < Loc.Offset && "offset point after current record"); |
| return LocalOffset ? Loc.Offset - LocalOffset : 0; |
| } |
| |
| uint64_t ReadGlobalOffset() { |
| uint64_t Local = ReadLocalOffset(); |
| return Local ? Record.getGlobalBitOffset(Local) : 0; |
| } |
| |
| SourceLocation readSourceLocation() { return Record.readSourceLocation(); } |
| |
| SourceRange readSourceRange() { return Record.readSourceRange(); } |
| |
| TypeSourceInfo *readTypeSourceInfo() { return Record.readTypeSourceInfo(); } |
| |
| GlobalDeclID readDeclID() { return Record.readDeclID(); } |
| |
| std::string readString() { return Record.readString(); } |
| |
| void readDeclIDList(SmallVectorImpl<GlobalDeclID> &IDs) { |
| for (unsigned I = 0, Size = Record.readInt(); I != Size; ++I) |
| IDs.push_back(readDeclID()); |
| } |
| |
| Decl *readDecl() { return Record.readDecl(); } |
| |
| template <typename T> T *readDeclAs() { return Record.readDeclAs<T>(); } |
| |
| serialization::SubmoduleID readSubmoduleID() { |
| if (Record.getIdx() == Record.size()) |
| return 0; |
| |
| return Record.getGlobalSubmoduleID(Record.readInt()); |
| } |
| |
| Module *readModule() { return Record.getSubmodule(readSubmoduleID()); } |
| |
| void ReadCXXRecordDefinition(CXXRecordDecl *D, bool Update, |
| Decl *LambdaContext = nullptr, |
| unsigned IndexInLambdaContext = 0); |
| void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data, |
| const CXXRecordDecl *D, Decl *LambdaContext, |
| unsigned IndexInLambdaContext); |
| void ReadObjCDefinitionData(struct ObjCInterfaceDecl::DefinitionData &Data); |
| void ReadObjCDefinitionData(struct ObjCProtocolDecl::DefinitionData &Data); |
| |
| static DeclContext *getPrimaryDCForAnonymousDecl(DeclContext *LexicalDC); |
| |
| static NamedDecl *getAnonymousDeclForMerging(ASTReader &Reader, |
| DeclContext *DC, unsigned Index); |
| static void setAnonymousDeclForMerging(ASTReader &Reader, DeclContext *DC, |
| unsigned Index, NamedDecl *D); |
| |
| /// Commit to a primary definition of the class RD, which is known to be |
| /// a definition of the class. We might not have read the definition data |
| /// for it yet. If we haven't then allocate placeholder definition data |
| /// now too. |
| static CXXRecordDecl *getOrFakePrimaryClassDefinition(ASTReader &Reader, |
| CXXRecordDecl *RD); |
| |
| /// Class used to capture the result of searching for an existing |
| /// declaration of a specific kind and name, along with the ability |
| /// to update the place where this result was found (the declaration |
| /// chain hanging off an identifier or the DeclContext we searched in) |
| /// if requested. |
| class FindExistingResult { |
| ASTReader &Reader; |
| NamedDecl *New = nullptr; |
| NamedDecl *Existing = nullptr; |
| bool AddResult = false; |
| unsigned AnonymousDeclNumber = 0; |
| IdentifierInfo *TypedefNameForLinkage = nullptr; |
| |
| public: |
| FindExistingResult(ASTReader &Reader) : Reader(Reader) {} |
| |
| FindExistingResult(ASTReader &Reader, NamedDecl *New, NamedDecl *Existing, |
| unsigned AnonymousDeclNumber, |
| IdentifierInfo *TypedefNameForLinkage) |
| : Reader(Reader), New(New), Existing(Existing), AddResult(true), |
| AnonymousDeclNumber(AnonymousDeclNumber), |
| TypedefNameForLinkage(TypedefNameForLinkage) {} |
| |
| FindExistingResult(FindExistingResult &&Other) |
| : Reader(Other.Reader), New(Other.New), Existing(Other.Existing), |
| AddResult(Other.AddResult), |
| AnonymousDeclNumber(Other.AnonymousDeclNumber), |
| TypedefNameForLinkage(Other.TypedefNameForLinkage) { |
| Other.AddResult = false; |
| } |
| |
| FindExistingResult &operator=(FindExistingResult &&) = delete; |
| ~FindExistingResult(); |
| |
| /// Suppress the addition of this result into the known set of |
| /// names. |
| void suppress() { AddResult = false; } |
| |
| operator NamedDecl *() const { return Existing; } |
| |
| template <typename T> operator T *() const { |
| return dyn_cast_or_null<T>(Existing); |
| } |
| }; |
| |
| static DeclContext *getPrimaryContextForMerging(ASTReader &Reader, |
| DeclContext *DC); |
| FindExistingResult findExisting(NamedDecl *D); |
| |
| public: |
| ASTDeclReader(ASTReader &Reader, ASTRecordReader &Record, |
| ASTReader::RecordLocation Loc, GlobalDeclID thisDeclID, |
| SourceLocation ThisDeclLoc) |
| : Reader(Reader), MergeImpl(Reader), Record(Record), Loc(Loc), |
| ThisDeclID(thisDeclID), ThisDeclLoc(ThisDeclLoc) {} |
| |
| template <typename T> |
| static void AddLazySpecializations(T *D, SmallVectorImpl<GlobalDeclID> &IDs) { |
| if (IDs.empty()) |
| return; |
| |
| // FIXME: We should avoid this pattern of getting the ASTContext. |
| ASTContext &C = D->getASTContext(); |
| |
| auto *&LazySpecializations = D->getCommonPtr()->LazySpecializations; |
| |
| if (auto &Old = LazySpecializations) { |
| IDs.insert(IDs.end(), Old + 1, Old + 1 + Old[0].getRawValue()); |
| llvm::sort(IDs); |
| IDs.erase(std::unique(IDs.begin(), IDs.end()), IDs.end()); |
| } |
| |
| auto *Result = new (C) GlobalDeclID[1 + IDs.size()]; |
| *Result = GlobalDeclID(IDs.size()); |
| |
| std::copy(IDs.begin(), IDs.end(), Result + 1); |
| |
| LazySpecializations = Result; |
| } |
| |
| template <typename DeclT> |
| static Decl *getMostRecentDeclImpl(Redeclarable<DeclT> *D); |
| static Decl *getMostRecentDeclImpl(...); |
| static Decl *getMostRecentDecl(Decl *D); |
| |
| template <typename DeclT> |
| static void attachPreviousDeclImpl(ASTReader &Reader, Redeclarable<DeclT> *D, |
| Decl *Previous, Decl *Canon); |
| static void attachPreviousDeclImpl(ASTReader &Reader, ...); |
| static void attachPreviousDecl(ASTReader &Reader, Decl *D, Decl *Previous, |
| Decl *Canon); |
| |
| static void checkMultipleDefinitionInNamedModules(ASTReader &Reader, Decl *D, |
| Decl *Previous); |
| |
| template <typename DeclT> |
| static void attachLatestDeclImpl(Redeclarable<DeclT> *D, Decl *Latest); |
| static void attachLatestDeclImpl(...); |
| static void attachLatestDecl(Decl *D, Decl *latest); |
| |
| template <typename DeclT> |
| static void markIncompleteDeclChainImpl(Redeclarable<DeclT> *D); |
| static void markIncompleteDeclChainImpl(...); |
| |
| void ReadFunctionDefinition(FunctionDecl *FD); |
| void Visit(Decl *D); |
| |
| void UpdateDecl(Decl *D, SmallVectorImpl<GlobalDeclID> &); |
| |
| static void setNextObjCCategory(ObjCCategoryDecl *Cat, |
| ObjCCategoryDecl *Next) { |
| Cat->NextClassCategory = Next; |
| } |
| |
| void VisitDecl(Decl *D); |
| void VisitPragmaCommentDecl(PragmaCommentDecl *D); |
| void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D); |
| void VisitTranslationUnitDecl(TranslationUnitDecl *TU); |
| void VisitNamedDecl(NamedDecl *ND); |
| void VisitLabelDecl(LabelDecl *LD); |
| void VisitNamespaceDecl(NamespaceDecl *D); |
| void VisitHLSLBufferDecl(HLSLBufferDecl *D); |
| void VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| void VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
| void VisitTypeDecl(TypeDecl *TD); |
| RedeclarableResult VisitTypedefNameDecl(TypedefNameDecl *TD); |
| void VisitTypedefDecl(TypedefDecl *TD); |
| void VisitTypeAliasDecl(TypeAliasDecl *TD); |
| void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
| void VisitUnresolvedUsingIfExistsDecl(UnresolvedUsingIfExistsDecl *D); |
| RedeclarableResult VisitTagDecl(TagDecl *TD); |
| void VisitEnumDecl(EnumDecl *ED); |
| RedeclarableResult VisitRecordDeclImpl(RecordDecl *RD); |
| void VisitRecordDecl(RecordDecl *RD); |
| RedeclarableResult VisitCXXRecordDeclImpl(CXXRecordDecl *D); |
| void VisitCXXRecordDecl(CXXRecordDecl *D) { VisitCXXRecordDeclImpl(D); } |
| RedeclarableResult |
| VisitClassTemplateSpecializationDeclImpl(ClassTemplateSpecializationDecl *D); |
| |
| void |
| VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl *D) { |
| VisitClassTemplateSpecializationDeclImpl(D); |
| } |
| |
| void VisitClassTemplatePartialSpecializationDecl( |
| ClassTemplatePartialSpecializationDecl *D); |
| RedeclarableResult |
| VisitVarTemplateSpecializationDeclImpl(VarTemplateSpecializationDecl *D); |
| |
| void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D) { |
| VisitVarTemplateSpecializationDeclImpl(D); |
| } |
| |
| void VisitVarTemplatePartialSpecializationDecl( |
| VarTemplatePartialSpecializationDecl *D); |
| void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
| void VisitValueDecl(ValueDecl *VD); |
| void VisitEnumConstantDecl(EnumConstantDecl *ECD); |
| void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
| void VisitDeclaratorDecl(DeclaratorDecl *DD); |
| void VisitFunctionDecl(FunctionDecl *FD); |
| void VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *GD); |
| void VisitCXXMethodDecl(CXXMethodDecl *D); |
| void VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| void VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| void VisitCXXConversionDecl(CXXConversionDecl *D); |
| void VisitFieldDecl(FieldDecl *FD); |
| void VisitMSPropertyDecl(MSPropertyDecl *FD); |
| void VisitMSGuidDecl(MSGuidDecl *D); |
| void VisitUnnamedGlobalConstantDecl(UnnamedGlobalConstantDecl *D); |
| void VisitTemplateParamObjectDecl(TemplateParamObjectDecl *D); |
| void VisitIndirectFieldDecl(IndirectFieldDecl *FD); |
| RedeclarableResult VisitVarDeclImpl(VarDecl *D); |
| void ReadVarDeclInit(VarDecl *VD); |
| void VisitVarDecl(VarDecl *VD) { VisitVarDeclImpl(VD); } |
| void VisitImplicitParamDecl(ImplicitParamDecl *PD); |
| void VisitParmVarDecl(ParmVarDecl *PD); |
| void VisitDecompositionDecl(DecompositionDecl *DD); |
| void VisitBindingDecl(BindingDecl *BD); |
| void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| void VisitTemplateDecl(TemplateDecl *D); |
| void VisitConceptDecl(ConceptDecl *D); |
| void |
| VisitImplicitConceptSpecializationDecl(ImplicitConceptSpecializationDecl *D); |
| void VisitRequiresExprBodyDecl(RequiresExprBodyDecl *D); |
| RedeclarableResult VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D); |
| void VisitClassTemplateDecl(ClassTemplateDecl *D); |
| void VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D); |
| void VisitVarTemplateDecl(VarTemplateDecl *D); |
| void VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
| void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
| void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); |
| void VisitUsingDecl(UsingDecl *D); |
| void VisitUsingEnumDecl(UsingEnumDecl *D); |
| void VisitUsingPackDecl(UsingPackDecl *D); |
| void VisitUsingShadowDecl(UsingShadowDecl *D); |
| void VisitConstructorUsingShadowDecl(ConstructorUsingShadowDecl *D); |
| void VisitLinkageSpecDecl(LinkageSpecDecl *D); |
| void VisitExportDecl(ExportDecl *D); |
| void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD); |
| void VisitTopLevelStmtDecl(TopLevelStmtDecl *D); |
| void VisitImportDecl(ImportDecl *D); |
| void VisitAccessSpecDecl(AccessSpecDecl *D); |
| void VisitFriendDecl(FriendDecl *D); |
| void VisitFriendTemplateDecl(FriendTemplateDecl *D); |
| void VisitStaticAssertDecl(StaticAssertDecl *D); |
| void VisitBlockDecl(BlockDecl *BD); |
| void VisitCapturedDecl(CapturedDecl *CD); |
| void VisitEmptyDecl(EmptyDecl *D); |
| void VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D); |
| |
| std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC); |
| |
| template <typename T> |
| RedeclarableResult VisitRedeclarable(Redeclarable<T> *D); |
| |
| template <typename T> |
| void mergeRedeclarable(Redeclarable<T> *D, RedeclarableResult &Redecl); |
| |
| void mergeRedeclarableTemplate(RedeclarableTemplateDecl *D, |
| RedeclarableResult &Redecl); |
| |
| template <typename T> void mergeMergeable(Mergeable<T> *D); |
| |
| void mergeMergeable(LifetimeExtendedTemporaryDecl *D); |
| |
| ObjCTypeParamList *ReadObjCTypeParamList(); |
| |
| // FIXME: Reorder according to DeclNodes.td? |
| void VisitObjCMethodDecl(ObjCMethodDecl *D); |
| void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); |
| void VisitObjCContainerDecl(ObjCContainerDecl *D); |
| void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
| void VisitObjCIvarDecl(ObjCIvarDecl *D); |
| void VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
| void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D); |
| void VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
| void VisitObjCImplDecl(ObjCImplDecl *D); |
| void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
| void VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
| void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D); |
| void VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
| void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
| void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D); |
| void VisitOMPAllocateDecl(OMPAllocateDecl *D); |
| void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D); |
| void VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D); |
| void VisitOMPRequiresDecl(OMPRequiresDecl *D); |
| void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D); |
| }; |
| |
| } // namespace clang |
| |
| namespace { |
| |
| /// Iterator over the redeclarations of a declaration that have already |
| /// been merged into the same redeclaration chain. |
| template <typename DeclT> class MergedRedeclIterator { |
| DeclT *Start = nullptr; |
| DeclT *Canonical = nullptr; |
| DeclT *Current = nullptr; |
| |
| public: |
| MergedRedeclIterator() = default; |
| MergedRedeclIterator(DeclT *Start) : Start(Start), Current(Start) {} |
| |
| DeclT *operator*() { return Current; } |
| |
| MergedRedeclIterator &operator++() { |
| if (Current->isFirstDecl()) { |
| Canonical = Current; |
| Current = Current->getMostRecentDecl(); |
| } else |
| Current = Current->getPreviousDecl(); |
| |
| // If we started in the merged portion, we'll reach our start position |
| // eventually. Otherwise, we'll never reach it, but the second declaration |
| // we reached was the canonical declaration, so stop when we see that one |
| // again. |
| if (Current == Start || Current == Canonical) |
| Current = nullptr; |
| return *this; |
| } |
| |
| friend bool operator!=(const MergedRedeclIterator &A, |
| const MergedRedeclIterator &B) { |
| return A.Current != B.Current; |
| } |
| }; |
| |
| } // namespace |
| |
| template <typename DeclT> |
| static llvm::iterator_range<MergedRedeclIterator<DeclT>> |
| merged_redecls(DeclT *D) { |
| return llvm::make_range(MergedRedeclIterator<DeclT>(D), |
| MergedRedeclIterator<DeclT>()); |
| } |
| |
| uint64_t ASTDeclReader::GetCurrentCursorOffset() { |
| return Loc.F->DeclsCursor.GetCurrentBitNo() + Loc.F->GlobalBitOffset; |
| } |
| |
| void ASTDeclReader::ReadFunctionDefinition(FunctionDecl *FD) { |
| if (Record.readInt()) { |
| Reader.DefinitionSource[FD] = |
| Loc.F->Kind == ModuleKind::MK_MainFile || |
| Reader.getContext().getLangOpts().BuildingPCHWithObjectFile; |
| } |
| if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) { |
| CD->setNumCtorInitializers(Record.readInt()); |
| if (CD->getNumCtorInitializers()) |
| CD->CtorInitializers = ReadGlobalOffset(); |
| } |
| // Store the offset of the body so we can lazily load it later. |
| Reader.PendingBodies[FD] = GetCurrentCursorOffset(); |
| } |
| |
| void ASTDeclReader::Visit(Decl *D) { |
| DeclVisitor<ASTDeclReader, void>::Visit(D); |
| |
| // At this point we have deserialized and merged the decl and it is safe to |
| // update its canonical decl to signal that the entire entity is used. |
| D->getCanonicalDecl()->Used |= IsDeclMarkedUsed; |
| IsDeclMarkedUsed = false; |
| |
| if (auto *DD = dyn_cast<DeclaratorDecl>(D)) { |
| if (auto *TInfo = DD->getTypeSourceInfo()) |
| Record.readTypeLoc(TInfo->getTypeLoc()); |
| } |
| |
| if (auto *TD = dyn_cast<TypeDecl>(D)) { |
| // We have a fully initialized TypeDecl. Read its type now. |
| TD->setTypeForDecl(Reader.GetType(DeferredTypeID).getTypePtrOrNull()); |
| |
| // If this is a tag declaration with a typedef name for linkage, it's safe |
| // to load that typedef now. |
| if (NamedDeclForTagDecl.isValid()) |
| cast<TagDecl>(D)->TypedefNameDeclOrQualifier = |
| cast<TypedefNameDecl>(Reader.GetDecl(NamedDeclForTagDecl)); |
| } else if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
| // if we have a fully initialized TypeDecl, we can safely read its type now. |
| ID->TypeForDecl = Reader.GetType(DeferredTypeID).getTypePtrOrNull(); |
| } else if (auto *FD = dyn_cast<FunctionDecl>(D)) { |
| // FunctionDecl's body was written last after all other Stmts/Exprs. |
| if (Record.readInt()) |
| ReadFunctionDefinition(FD); |
| } else if (auto *VD = dyn_cast<VarDecl>(D)) { |
| ReadVarDeclInit(VD); |
| } else if (auto *FD = dyn_cast<FieldDecl>(D)) { |
| if (FD->hasInClassInitializer() && Record.readInt()) { |
| FD->setLazyInClassInitializer(LazyDeclStmtPtr(GetCurrentCursorOffset())); |
| } |
| } |
| } |
| |
| void ASTDeclReader::VisitDecl(Decl *D) { |
| BitsUnpacker DeclBits(Record.readInt()); |
| auto ModuleOwnership = |
| (Decl::ModuleOwnershipKind)DeclBits.getNextBits(/*Width=*/3); |
| D->setReferenced(DeclBits.getNextBit()); |
| D->Used = DeclBits.getNextBit(); |
| IsDeclMarkedUsed |= D->Used; |
| D->setAccess((AccessSpecifier)DeclBits.getNextBits(/*Width=*/2)); |
| D->setImplicit(DeclBits.getNextBit()); |
| bool HasStandaloneLexicalDC = DeclBits.getNextBit(); |
| bool HasAttrs = DeclBits.getNextBit(); |
| D->setTopLevelDeclInObjCContainer(DeclBits.getNextBit()); |
| D->InvalidDecl = DeclBits.getNextBit(); |
| D->FromASTFile = true; |
| |
| if (D->isTemplateParameter() || D->isTemplateParameterPack() || |
| isa<ParmVarDecl, ObjCTypeParamDecl>(D)) { |
| // We don't want to deserialize the DeclContext of a template |
| // parameter or of a parameter of a function template immediately. These |
| // entities might be used in the formulation of its DeclContext (for |
| // example, a function parameter can be used in decltype() in trailing |
| // return type of the function). Use the translation unit DeclContext as a |
| // placeholder. |
| GlobalDeclID SemaDCIDForTemplateParmDecl = readDeclID(); |
| GlobalDeclID LexicalDCIDForTemplateParmDecl = |
| HasStandaloneLexicalDC ? readDeclID() : GlobalDeclID(); |
| if (LexicalDCIDForTemplateParmDecl.isInvalid()) |
| LexicalDCIDForTemplateParmDecl = SemaDCIDForTemplateParmDecl; |
| Reader.addPendingDeclContextInfo(D, |
| SemaDCIDForTemplateParmDecl, |
| LexicalDCIDForTemplateParmDecl); |
| D->setDeclContext(Reader.getContext().getTranslationUnitDecl()); |
| } else { |
| auto *SemaDC = readDeclAs<DeclContext>(); |
| auto *LexicalDC = |
| HasStandaloneLexicalDC ? readDeclAs<DeclContext>() : nullptr; |
| if (!LexicalDC) |
| LexicalDC = SemaDC; |
| // If the context is a class, we might not have actually merged it yet, in |
| // the case where the definition comes from an update record. |
| DeclContext *MergedSemaDC; |
| if (auto *RD = dyn_cast<CXXRecordDecl>(SemaDC)) |
| MergedSemaDC = getOrFakePrimaryClassDefinition(Reader, RD); |
| else |
| MergedSemaDC = Reader.MergedDeclContexts.lookup(SemaDC); |
| // Avoid calling setLexicalDeclContext() directly because it uses |
| // Decl::getASTContext() internally which is unsafe during derialization. |
| D->setDeclContextsImpl(MergedSemaDC ? MergedSemaDC : SemaDC, LexicalDC, |
| Reader.getContext()); |
| } |
| D->setLocation(ThisDeclLoc); |
| |
| if (HasAttrs) { |
| AttrVec Attrs; |
| Record.readAttributes(Attrs); |
| // Avoid calling setAttrs() directly because it uses Decl::getASTContext() |
| // internally which is unsafe during derialization. |
| D->setAttrsImpl(Attrs, Reader.getContext()); |
| } |
| |
| // Determine whether this declaration is part of a (sub)module. If so, it |
| // may not yet be visible. |
| bool ModulePrivate = |
| (ModuleOwnership == Decl::ModuleOwnershipKind::ModulePrivate); |
| if (unsigned SubmoduleID = readSubmoduleID()) { |
| switch (ModuleOwnership) { |
| case Decl::ModuleOwnershipKind::Visible: |
| ModuleOwnership = Decl::ModuleOwnershipKind::VisibleWhenImported; |
| break; |
| case Decl::ModuleOwnershipKind::Unowned: |
| case Decl::ModuleOwnershipKind::VisibleWhenImported: |
| case Decl::ModuleOwnershipKind::ReachableWhenImported: |
| case Decl::ModuleOwnershipKind::ModulePrivate: |
| break; |
| } |
| |
| D->setModuleOwnershipKind(ModuleOwnership); |
| // Store the owning submodule ID in the declaration. |
| D->setOwningModuleID(SubmoduleID); |
| |
| if (ModulePrivate) { |
| // Module-private declarations are never visible, so there is no work to |
| // do. |
| } else if (Reader.getContext().getLangOpts().ModulesLocalVisibility) { |
| // If local visibility is being tracked, this declaration will become |
| // hidden and visible as the owning module does. |
| } else if (Module *Owner = Reader.getSubmodule(SubmoduleID)) { |
| // Mark the declaration as visible when its owning module becomes visible. |
| if (Owner->NameVisibility == Module::AllVisible) |
| D->setVisibleDespiteOwningModule(); |
| else |
| Reader.HiddenNamesMap[Owner].push_back(D); |
| } |
| } else if (ModulePrivate) { |
| D->setModuleOwnershipKind(Decl::ModuleOwnershipKind::ModulePrivate); |
| } |
| } |
| |
| void ASTDeclReader::VisitPragmaCommentDecl(PragmaCommentDecl *D) { |
| VisitDecl(D); |
| D->setLocation(readSourceLocation()); |
| D->CommentKind = (PragmaMSCommentKind)Record.readInt(); |
| std::string Arg = readString(); |
| memcpy(D->getTrailingObjects<char>(), Arg.data(), Arg.size()); |
| D->getTrailingObjects<char>()[Arg.size()] = '\0'; |
| } |
| |
| void ASTDeclReader::VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D) { |
| VisitDecl(D); |
| D->setLocation(readSourceLocation()); |
| std::string Name = readString(); |
| memcpy(D->getTrailingObjects<char>(), Name.data(), Name.size()); |
| D->getTrailingObjects<char>()[Name.size()] = '\0'; |
| |
| D->ValueStart = Name.size() + 1; |
| std::string Value = readString(); |
| memcpy(D->getTrailingObjects<char>() + D->ValueStart, Value.data(), |
| Value.size()); |
| D->getTrailingObjects<char>()[D->ValueStart + Value.size()] = '\0'; |
| } |
| |
| void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) { |
| llvm_unreachable("Translation units are not serialized"); |
| } |
| |
| void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) { |
| VisitDecl(ND); |
| ND->setDeclName(Record.readDeclarationName()); |
| AnonymousDeclNumber = Record.readInt(); |
| } |
| |
| void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) { |
| VisitNamedDecl(TD); |
| TD->setLocStart(readSourceLocation()); |
| // Delay type reading until after we have fully initialized the decl. |
| DeferredTypeID = Record.getGlobalTypeID(Record.readInt()); |
| } |
| |
| RedeclarableResult ASTDeclReader::VisitTypedefNameDecl(TypedefNameDecl *TD) { |
| RedeclarableResult Redecl = VisitRedeclarable(TD); |
| VisitTypeDecl(TD); |
| TypeSourceInfo *TInfo = readTypeSourceInfo(); |
| if (Record.readInt()) { // isModed |
| QualType modedT = Record.readType(); |
| TD->setModedTypeSourceInfo(TInfo, modedT); |
| } else |
| TD->setTypeSourceInfo(TInfo); |
| // Read and discard the declaration for which this is a typedef name for |
| // linkage, if it exists. We cannot rely on our type to pull in this decl, |
| // because it might have been merged with a type from another module and |
| // thus might not refer to our version of the declaration. |
| readDecl(); |
| return Redecl; |
| } |
| |
| void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) { |
| RedeclarableResult Redecl = VisitTypedefNameDecl(TD); |
| mergeRedeclarable(TD, Redecl); |
| } |
| |
| void ASTDeclReader::VisitTypeAliasDecl(TypeAliasDecl *TD) { |
| RedeclarableResult Redecl = VisitTypedefNameDecl(TD); |
| if (auto *Template = readDeclAs<TypeAliasTemplateDecl>()) |
| // Merged when we merge the template. |
| TD->setDescribedAliasTemplate(Template); |
| else |
| mergeRedeclarable(TD, Redecl); |
| } |
| |
| RedeclarableResult ASTDeclReader::VisitTagDecl(TagDecl *TD) { |
| RedeclarableResult Redecl = VisitRedeclarable(TD); |
| VisitTypeDecl(TD); |
| |
| TD->IdentifierNamespace = Record.readInt(); |
| |
| BitsUnpacker TagDeclBits(Record.readInt()); |
| TD->setTagKind( |
| static_cast<TagTypeKind>(TagDeclBits.getNextBits(/*Width=*/3))); |
| TD->setCompleteDefinition(TagDeclBits.getNextBit()); |
| TD->setEmbeddedInDeclarator(TagDeclBits.getNextBit()); |
| TD->setFreeStanding(TagDeclBits.getNextBit()); |
| TD->setCompleteDefinitionRequired(TagDeclBits.getNextBit()); |
| TD->setBraceRange(readSourceRange()); |
| |
| switch (TagDeclBits.getNextBits(/*Width=*/2)) { |
| case 0: |
| break; |
| case 1: { // ExtInfo |
| auto *Info = new (Reader.getContext()) TagDecl::ExtInfo(); |
| Record.readQualifierInfo(*Info); |
| TD->TypedefNameDeclOrQualifier = Info; |
| break; |
| } |
| case 2: // TypedefNameForAnonDecl |
| NamedDeclForTagDecl = readDeclID(); |
| TypedefNameForLinkage = Record.readIdentifier(); |
| break; |
| default: |
| llvm_unreachable("unexpected tag info kind"); |
| } |
| |
| if (!isa<CXXRecordDecl>(TD)) |
| mergeRedeclarable(TD, Redecl); |
| return Redecl; |
| } |
| |
| void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) { |
| VisitTagDecl(ED); |
| if (TypeSourceInfo *TI = readTypeSourceInfo()) |
| ED->setIntegerTypeSourceInfo(TI); |
| else |
| ED->setIntegerType(Record.readType()); |
| ED->setPromotionType(Record.readType()); |
| |
| BitsUnpacker EnumDeclBits(Record.readInt()); |
| ED->setNumPositiveBits(EnumDeclBits.getNextBits(/*Width=*/8)); |
| ED->setNumNegativeBits(EnumDeclBits.getNextBits(/*Width=*/8)); |
| ED->setScoped(EnumDeclBits.getNextBit()); |
| ED->setScopedUsingClassTag(EnumDeclBits.getNextBit()); |
| ED->setFixed(EnumDeclBits.getNextBit()); |
| |
| ED->setHasODRHash(true); |
| ED->ODRHash = Record.readInt(); |
| |
| // If this is a definition subject to the ODR, and we already have a |
| // definition, merge this one into it. |
| if (ED->isCompleteDefinition() && Reader.getContext().getLangOpts().Modules) { |
| EnumDecl *&OldDef = Reader.EnumDefinitions[ED->getCanonicalDecl()]; |
| if (!OldDef) { |
| // This is the first time we've seen an imported definition. Look for a |
| // local definition before deciding that we are the first definition. |
| for (auto *D : merged_redecls(ED->getCanonicalDecl())) { |
| if (!D->isFromASTFile() && D->isCompleteDefinition()) { |
| OldDef = D; |
| break; |
| } |
| } |
| } |
| if (OldDef) { |
| Reader.MergedDeclContexts.insert(std::make_pair(ED, OldDef)); |
| ED->demoteThisDefinitionToDeclaration(); |
| Reader.mergeDefinitionVisibility(OldDef, ED); |
| // We don't want to check the ODR hash value for declarations from global |
| // module fragment. |
| if (!shouldSkipCheckingODR(ED) && !shouldSkipCheckingODR(OldDef) && |
| OldDef->getODRHash() != ED->getODRHash()) |
| Reader.PendingEnumOdrMergeFailures[OldDef].push_back(ED); |
| } else { |
| OldDef = ED; |
| } |
| } |
| |
| if (auto *InstED = readDeclAs<EnumDecl>()) { |
| auto TSK = (TemplateSpecializationKind)Record.readInt(); |
| SourceLocation POI = readSourceLocation(); |
| ED->setInstantiationOfMemberEnum(Reader.getContext(), InstED, TSK); |
| ED->getMemberSpecializationInfo()->setPointOfInstantiation(POI); |
| } |
| } |
| |
| RedeclarableResult ASTDeclReader::VisitRecordDeclImpl(RecordDecl *RD) { |
| RedeclarableResult Redecl = VisitTagDecl(RD); |
| |
| BitsUnpacker RecordDeclBits(Record.readInt()); |
| RD->setHasFlexibleArrayMember(RecordDeclBits.getNextBit()); |
| RD->setAnonymousStructOrUnion(RecordDeclBits.getNextBit()); |
| RD->setHasObjectMember(RecordDeclBits.getNextBit()); |
| RD->setHasVolatileMember(RecordDeclBits.getNextBit()); |
| RD->setNonTrivialToPrimitiveDefaultInitialize(RecordDeclBits.getNextBit()); |
| RD->setNonTrivialToPrimitiveCopy(RecordDeclBits.getNextBit()); |
| RD->setNonTrivialToPrimitiveDestroy(RecordDeclBits.getNextBit()); |
| RD->setHasNonTrivialToPrimitiveDefaultInitializeCUnion( |
| RecordDeclBits.getNextBit()); |
| RD->setHasNonTrivialToPrimitiveDestructCUnion(RecordDeclBits.getNextBit()); |
| RD->setHasNonTrivialToPrimitiveCopyCUnion(RecordDeclBits.getNextBit()); |
| RD->setParamDestroyedInCallee(RecordDeclBits.getNextBit()); |
| RD->setArgPassingRestrictions( |
| (RecordArgPassingKind)RecordDeclBits.getNextBits(/*Width=*/2)); |
| return Redecl; |
| } |
| |
| void ASTDeclReader::VisitRecordDecl(RecordDecl *RD) { |
| VisitRecordDeclImpl(RD); |
| RD->setODRHash(Record.readInt()); |
| |
| // Maintain the invariant of a redeclaration chain containing only |
| // a single definition. |
| if (RD->isCompleteDefinition()) { |
| RecordDecl *Canon = static_cast<RecordDecl *>(RD->getCanonicalDecl()); |
| RecordDecl *&OldDef = Reader.RecordDefinitions[Canon]; |
| if (!OldDef) { |
| // This is the first time we've seen an imported definition. Look for a |
| // local definition before deciding that we are the first definition. |
| for (auto *D : merged_redecls(Canon)) { |
| if (!D->isFromASTFile() && D->isCompleteDefinition()) { |
| OldDef = D; |
| break; |
| } |
| } |
| } |
| if (OldDef) { |
| Reader.MergedDeclContexts.insert(std::make_pair(RD, OldDef)); |
| RD->demoteThisDefinitionToDeclaration(); |
| Reader.mergeDefinitionVisibility(OldDef, RD); |
| if (OldDef->getODRHash() != RD->getODRHash()) |
| Reader.PendingRecordOdrMergeFailures[OldDef].push_back(RD); |
| } else { |
| OldDef = RD; |
| } |
| } |
| } |
| |
| void ASTDeclReader::VisitValueDecl(ValueDecl *VD) { |
| VisitNamedDecl(VD); |
| // For function or variable declarations, defer reading the type in case the |
| // declaration has a deduced type that references an entity declared within |
| // the function definition or variable initializer. |
| if (isa<FunctionDecl, VarDecl>(VD)) |
| DeferredTypeID = Record.getGlobalTypeID(Record.readInt()); |
| else |
| VD->setType(Record.readType()); |
| } |
| |
| void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) { |
| VisitValueDecl(ECD); |
| if (Record.readInt()) |
| ECD->setInitExpr(Record.readExpr()); |
| ECD->setInitVal(Reader.getContext(), Record.readAPSInt()); |
| mergeMergeable(ECD); |
| } |
| |
| void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) { |
| VisitValueDecl(DD); |
| DD->setInnerLocStart(readSourceLocation()); |
| if (Record.readInt()) { // hasExtInfo |
| auto *Info = new (Reader.getContext()) DeclaratorDecl::ExtInfo(); |
| Record.readQualifierInfo(*Info); |
| Info->TrailingRequiresClause = Record.readExpr(); |
| DD->DeclInfo = Info; |
| } |
| QualType TSIType = Record.readType(); |
| DD->setTypeSourceInfo( |
| TSIType.isNull() ? nullptr |
| : Reader.getContext().CreateTypeSourceInfo(TSIType)); |
| } |
| |
| void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) { |
| RedeclarableResult Redecl = VisitRedeclarable(FD); |
| |
| FunctionDecl *Existing = nullptr; |
| |
| switch ((FunctionDecl::TemplatedKind)Record.readInt()) { |
| case FunctionDecl::TK_NonTemplate: |
| break; |
| case FunctionDecl::TK_DependentNonTemplate: |
| FD->setInstantiatedFromDecl(readDeclAs<FunctionDecl>()); |
| break; |
| case FunctionDecl::TK_FunctionTemplate: { |
| auto *Template = readDeclAs<FunctionTemplateDecl>(); |
| Template->init(FD); |
| FD->setDescribedFunctionTemplate(Template); |
| break; |
| } |
| case FunctionDecl::TK_MemberSpecialization: { |
| auto *InstFD = readDeclAs<FunctionDecl>(); |
| auto TSK = (TemplateSpecializationKind)Record.readInt(); |
| SourceLocation POI = readSourceLocation(); |
| FD->setInstantiationOfMemberFunction(Reader.getContext(), InstFD, TSK); |
| FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI); |
| break; |
| } |
| case FunctionDecl::TK_FunctionTemplateSpecialization: { |
| auto *Template = readDeclAs<FunctionTemplateDecl>(); |
| auto TSK = (TemplateSpecializationKind)Record.readInt(); |
| |
| // Template arguments. |
| SmallVector<TemplateArgument, 8> TemplArgs; |
| Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true); |
| |
| // Template args as written. |
| TemplateArgumentListInfo TemplArgsWritten; |
| bool HasTemplateArgumentsAsWritten = Record.readBool(); |
| if (HasTemplateArgumentsAsWritten) |
| Record.readTemplateArgumentListInfo(TemplArgsWritten); |
| |
| SourceLocation POI = readSourceLocation(); |
| |
| ASTContext &C = Reader.getContext(); |
| TemplateArgumentList *TemplArgList = |
| TemplateArgumentList::CreateCopy(C, TemplArgs); |
| |
| MemberSpecializationInfo *MSInfo = nullptr; |
| if (Record.readInt()) { |
| auto *FD = readDeclAs<FunctionDecl>(); |
| auto TSK = (TemplateSpecializationKind)Record.readInt(); |
| SourceLocation POI = readSourceLocation(); |
| |
| MSInfo = new (C) MemberSpecializationInfo(FD, TSK); |
| MSInfo->setPointOfInstantiation(POI); |
| } |
| |
| FunctionTemplateSpecializationInfo *FTInfo = |
| FunctionTemplateSpecializationInfo::Create( |
| C, FD, Template, TSK, TemplArgList, |
| HasTemplateArgumentsAsWritten ? &TemplArgsWritten : nullptr, POI, |
| MSInfo); |
| FD->TemplateOrSpecialization = FTInfo; |
| |
| if (FD->isCanonicalDecl()) { // if canonical add to template's set. |
| // The template that contains the specializations set. It's not safe to |
| // use getCanonicalDecl on Template since it may still be initializing. |
| auto *CanonTemplate = readDeclAs<FunctionTemplateDecl>(); |
| // Get the InsertPos by FindNodeOrInsertPos() instead of calling |
| // InsertNode(FTInfo) directly to avoid the getASTContext() call in |
| // FunctionTemplateSpecializationInfo's Profile(). |
| // We avoid getASTContext because a decl in the parent hierarchy may |
| // be initializing. |
| llvm::FoldingSetNodeID ID; |
| FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs, C); |
| void *InsertPos = nullptr; |
| FunctionTemplateDecl::Common *CommonPtr = CanonTemplate->getCommonPtr(); |
| FunctionTemplateSpecializationInfo *ExistingInfo = |
| CommonPtr->Specializations.FindNodeOrInsertPos(ID, InsertPos); |
| if (InsertPos) |
| CommonPtr->Specializations.InsertNode(FTInfo, InsertPos); |
| else { |
| assert(Reader.getContext().getLangOpts().Modules && |
| "already deserialized this template specialization"); |
| Existing = ExistingInfo->getFunction(); |
| } |
| } |
| break; |
| } |
| case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| // Templates. |
| UnresolvedSet<8> Candidates; |
| unsigned NumCandidates = Record.readInt(); |
| while (NumCandidates--) |
| Candidates.addDecl(readDeclAs<NamedDecl>()); |
| |
| // Templates args. |
| TemplateArgumentListInfo TemplArgsWritten; |
| bool HasTemplateArgumentsAsWritten = Record.readBool(); |
| if (HasTemplateArgumentsAsWritten) |
| Record.readTemplateArgumentListInfo(TemplArgsWritten); |
| |
| FD->setDependentTemplateSpecialization( |
| Reader.getContext(), Candidates, |
| HasTemplateArgumentsAsWritten ? &TemplArgsWritten : nullptr); |
| // These are not merged; we don't need to merge redeclarations of dependent |
| // template friends. |
| break; |
| } |
| } |
| |
| VisitDeclaratorDecl(FD); |
| |
| // Attach a type to this function. Use the real type if possible, but fall |
| // back to the type as written if it involves a deduced return type. |
| if (FD->getTypeSourceInfo() && FD->getTypeSourceInfo() |
| ->getType() |
| ->castAs<FunctionType>() |
| ->getReturnType() |
| ->getContainedAutoType()) { |
| // We'll set up the real type in Visit, once we've finished loading the |
| // function. |
| FD->setType(FD->getTypeSourceInfo()->getType()); |
| Reader.PendingDeducedFunctionTypes.push_back({FD, DeferredTypeID}); |
| } else { |
| FD->setType(Reader.GetType(DeferredTypeID)); |
| } |
| DeferredTypeID = 0; |
| |
| FD->DNLoc = Record.readDeclarationNameLoc(FD->getDeclName()); |
| FD->IdentifierNamespace = Record.readInt(); |
| |
| // FunctionDecl's body is handled last at ASTDeclReader::Visit, |
| // after everything else is read. |
| BitsUnpacker FunctionDeclBits(Record.readInt()); |
| |
| FD->setCachedLinkage((Linkage)FunctionDeclBits.getNextBits(/*Width=*/3)); |
| FD->setStorageClass((StorageClass)FunctionDeclBits.getNextBits(/*Width=*/3)); |
| FD->setInlineSpecified(FunctionDeclBits.getNextBit()); |
| FD->setImplicitlyInline(FunctionDeclBits.getNextBit()); |
| FD->setHasSkippedBody(FunctionDeclBits.getNextBit()); |
| FD->setVirtualAsWritten(FunctionDeclBits.getNextBit()); |
| // We defer calling `FunctionDecl::setPure()` here as for methods of |
| // `CXXTemplateSpecializationDecl`s, we may not have connected up the |
| // definition (which is required for `setPure`). |
| const bool Pure = FunctionDeclBits.getNextBit(); |
| FD->setHasInheritedPrototype(FunctionDeclBits.getNextBit()); |
| FD->setHasWrittenPrototype(FunctionDeclBits.getNextBit()); |
| FD->setDeletedAsWritten(FunctionDeclBits.getNextBit()); |
| FD->setTrivial(FunctionDeclBits.getNextBit()); |
| FD->setTrivialForCall(FunctionDeclBits.getNextBit()); |
| FD->setDefaulted(FunctionDeclBits.getNextBit()); |
| FD->setExplicitlyDefaulted(FunctionDeclBits.getNextBit()); |
| FD->setIneligibleOrNotSelected(FunctionDeclBits.getNextBit()); |
| FD->setConstexprKind( |
| (ConstexprSpecKind)FunctionDeclBits.getNextBits(/*Width=*/2)); |
| FD->setHasImplicitReturnZero(FunctionDeclBits.getNextBit()); |
| FD->setIsMultiVersion(FunctionDeclBits.getNextBit()); |
| FD->setLateTemplateParsed(FunctionDeclBits.getNextBit()); |
| FD->setFriendConstraintRefersToEnclosingTemplate( |
| FunctionDeclBits.getNextBit()); |
| FD->setUsesSEHTry(FunctionDeclBits.getNextBit()); |
| |
| FD->EndRangeLoc = readSourceLocation(); |
| if (FD->isExplicitlyDefaulted()) |
| FD->setDefaultLoc(readSourceLocation()); |
| |
| FD->ODRHash = Record.readInt(); |
| FD->setHasODRHash(true); |
| |
| if (FD->isDefaulted() || FD->isDeletedAsWritten()) { |
| // If 'Info' is nonzero, we need to read an DefaultedOrDeletedInfo; if, |
| // additionally, the second bit is also set, we also need to read |
| // a DeletedMessage for the DefaultedOrDeletedInfo. |
| if (auto Info = Record.readInt()) { |
| bool HasMessage = Info & 2; |
| StringLiteral *DeletedMessage = |
| HasMessage ? cast<StringLiteral>(Record.readExpr()) : nullptr; |
| |
| unsigned NumLookups = Record.readInt(); |
| SmallVector<DeclAccessPair, 8> Lookups; |
| for (unsigned I = 0; I != NumLookups; ++I) { |
| NamedDecl *ND = Record.readDeclAs<NamedDecl>(); |
| AccessSpecifier AS = (AccessSpecifier)Record.readInt(); |
| Lookups.push_back(DeclAccessPair::make(ND, AS)); |
| } |
| |
| FD->setDefaultedOrDeletedInfo( |
| FunctionDecl::DefaultedOrDeletedFunctionInfo::Create( |
| Reader.getContext(), Lookups, DeletedMessage)); |
| } |
| } |
| |
| if (Existing) |
| MergeImpl.mergeRedeclarable(FD, Existing, Redecl); |
| else if (auto Kind = FD->getTemplatedKind(); |
| Kind == FunctionDecl::TK_FunctionTemplate || |
| Kind == FunctionDecl::TK_FunctionTemplateSpecialization) { |
| // Function Templates have their FunctionTemplateDecls merged instead of |
| // their FunctionDecls. |
| auto merge = [this, &Redecl, FD](auto &&F) { |
| auto *Existing = cast_or_null<FunctionDecl>(Redecl.getKnownMergeTarget()); |
| RedeclarableResult NewRedecl(Existing ? F(Existing) : nullptr, |
| Redecl.getFirstID(), Redecl.isKeyDecl()); |
| mergeRedeclarableTemplate(F(FD), NewRedecl); |
| }; |
| if (Kind == FunctionDecl::TK_FunctionTemplate) |
| merge( |
| [](FunctionDecl *FD) { return FD->getDescribedFunctionTemplate(); }); |
| else |
| merge([](FunctionDecl *FD) { |
| return FD->getTemplateSpecializationInfo()->getTemplate(); |
| }); |
| } else |
| mergeRedeclarable(FD, Redecl); |
| |
| // Defer calling `setPure` until merging above has guaranteed we've set |
| // `DefinitionData` (as this will need to access it). |
| FD->setIsPureVirtual(Pure); |
| |
| // Read in the parameters. |
| unsigned NumParams = Record.readInt(); |
| SmallVector<ParmVarDecl *, 16> Params; |
| Params.reserve(NumParams); |
| for (unsigned I = 0; I != NumParams; ++I) |
| Params.push_back(readDeclAs<ParmVarDecl>()); |
| FD->setParams(Reader.getContext(), Params); |
| } |
| |
| void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) { |
| VisitNamedDecl(MD); |
| if (Record.readInt()) { |
| // Load the body on-demand. Most clients won't care, because method |
| // definitions rarely show up in headers. |
| Reader.PendingBodies[MD] = GetCurrentCursorOffset(); |
| } |
| MD->setSelfDecl(readDeclAs<ImplicitParamDecl>()); |
| MD->setCmdDecl(readDeclAs<ImplicitParamDecl>()); |
| MD->setInstanceMethod(Record.readInt()); |
| MD->setVariadic(Record.readInt()); |
| MD->setPropertyAccessor(Record.readInt()); |
| MD->setSynthesizedAccessorStub(Record.readInt()); |
| MD->setDefined(Record.readInt()); |
| MD->setOverriding(Record.readInt()); |
| MD->setHasSkippedBody(Record.readInt()); |
| |
| MD->setIsRedeclaration(Record.readInt()); |
| MD->setHasRedeclaration(Record.readInt()); |
| if (MD->hasRedeclaration()) |
| Reader.getContext().setObjCMethodRedeclaration(MD, |
| readDeclAs<ObjCMethodDecl>()); |
| |
| MD->setDeclImplementation( |
| static_cast<ObjCImplementationControl>(Record.readInt())); |
| MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record.readInt()); |
| MD->setRelatedResultType(Record.readInt()); |
| MD->setReturnType(Record.readType()); |
| MD->setReturnTypeSourceInfo(readTypeSourceInfo()); |
| MD->DeclEndLoc = readSourceLocation(); |
| unsigned NumParams = Record.readInt(); |
| SmallVector<ParmVarDecl *, 16> Params; |
| Params.reserve(NumParams); |
| for (unsigned I = 0; I != NumParams; ++I) |
| Params.push_back(readDeclAs<ParmVarDecl>()); |
| |
| MD->setSelLocsKind((SelectorLocationsKind)Record.readInt()); |
| unsigned NumStoredSelLocs = Record.readInt(); |
| SmallVector<SourceLocation, 16> SelLocs; |
| SelLocs.reserve(NumStoredSelLocs); |
| for (unsigned i = 0; i != NumStoredSelLocs; ++i) |
| SelLocs.push_back(readSourceLocation()); |
| |
| MD->setParamsAndSelLocs(Reader.getContext(), Params, SelLocs); |
| } |
| |
| void ASTDeclReader::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
| VisitTypedefNameDecl(D); |
| |
| D->Variance = Record.readInt(); |
| D->Index = Record.readInt(); |
| D->VarianceLoc = readSourceLocation(); |
| D->ColonLoc = readSourceLocation(); |
| } |
| |
| void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) { |
| VisitNamedDecl(CD); |
| CD->setAtStartLoc(readSourceLocation()); |
| CD->setAtEndRange(readSourceRange()); |
| } |
| |
| ObjCTypeParamList *ASTDeclReader::ReadObjCTypeParamList() { |
| unsigned numParams = Record.readInt(); |
| if (numParams == 0) |
| return nullptr; |
| |
| SmallVector<ObjCTypeParamDecl *, 4> typeParams; |
| typeParams.reserve(numParams); |
| for (unsigned i = 0; i != numParams; ++i) { |
| auto *typeParam = readDeclAs<ObjCTypeParamDecl>(); |
| if (!typeParam) |
| return nullptr; |
| |
| typeParams.push_back(typeParam); |
| } |
| |
| SourceLocation lAngleLoc = readSourceLocation(); |
| SourceLocation rAngleLoc = readSourceLocation(); |
| |
| return ObjCTypeParamList::create(Reader.getContext(), lAngleLoc, |
| typeParams, rAngleLoc); |
| } |
| |
| void ASTDeclReader::ReadObjCDefinitionData( |
| struct ObjCInterfaceDecl::DefinitionData &Data) { |
| // Read the superclass. |
| Data.SuperClassTInfo = readTypeSourceInfo(); |
| |
| Data.EndLoc = readSourceLocation(); |
| Data.HasDesignatedInitializers = Record.readInt(); |
| Data.ODRHash = Record.readInt(); |
| Data.HasODRHash = true; |
| |
| // Read the directly referenced protocols and their SourceLocations. |
| unsigned NumProtocols = Record.readInt(); |
| SmallVector<ObjCProtocolDecl *, 16> Protocols; |
| Protocols.reserve(NumProtocols); |
| for (unsigned I = 0; I != NumProtocols; ++I) |
| Protocols.push_back(readDeclAs<ObjCProtocolDecl>()); |
| SmallVector<SourceLocation, 16> ProtoLocs; |
| ProtoLocs.reserve(NumProtocols); |
| for (unsigned I = 0; I != NumProtocols; ++I) |
| ProtoLocs.push_back(readSourceLocation()); |
| Data.ReferencedProtocols.set(Protocols.data(), NumProtocols, ProtoLocs.data(), |
| Reader.getContext()); |
| |
| // Read the transitive closure of protocols referenced by this class. |
| NumProtocols = Record.readInt(); |
| Protocols.clear(); |
| Protocols.reserve(NumProtocols); |
| for (unsigned I = 0; I != NumProtocols; ++I) |
| Protocols.push_back(readDeclAs<ObjCProtocolDecl>()); |
| Data.AllReferencedProtocols.set(Protocols.data(), NumProtocols, |
| Reader.getContext()); |
| } |
| |
| void ASTDeclMerger::MergeDefinitionData( |
| ObjCInterfaceDecl *D, struct ObjCInterfaceDecl::DefinitionData &&NewDD) { |
| struct ObjCInterfaceDecl::DefinitionData &DD = D->data(); |
| if (DD.Definition == NewDD.Definition) |
| return; |
| |
| Reader.MergedDeclContexts.insert( |
| std::make_pair(NewDD.Definition, DD.Definition)); |
| Reader.mergeDefinitionVisibility(DD.Definition, NewDD.Definition); |
| |
| if (D->getODRHash() != NewDD.ODRHash) |
| Reader.PendingObjCInterfaceOdrMergeFailures[DD.Definition].push_back( |
| {NewDD.Definition, &NewDD}); |
| } |
| |
| void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) { |
| RedeclarableResult Redecl = VisitRedeclarable(ID); |
| VisitObjCContainerDecl(ID); |
| DeferredTypeID = Record.getGlobalTypeID(Record.readInt()); |
| mergeRedeclarable(ID, Redecl); |
| |
| ID->TypeParamList = ReadObjCTypeParamList(); |
| if (Record.readInt()) { |
| // Read the definition. |
| ID->allocateDefinitionData(); |
| |
| ReadObjCDefinitionData(ID->data()); |
| ObjCInterfaceDecl *Canon = ID->getCanonicalDecl(); |
| if (Canon->Data.getPointer()) { |
| // If we already have a definition, keep the definition invariant and |
| // merge the data. |
| MergeImpl.MergeDefinitionData(Canon, std::move(ID->data())); |
| ID->Data = Canon->Data; |
| } else { |
| // Set the definition data of the canonical declaration, so other |
| // redeclarations will see it. |
| ID->getCanonicalDecl()->Data = ID->Data; |
| |
| // We will rebuild this list lazily. |
| ID->setIvarList(nullptr); |
| } |
| |
| // Note that we have deserialized a definition. |
| Reader.PendingDefinitions.insert(ID); |
| |
| // Note that we've loaded this Objective-C class. |
| Reader.ObjCClassesLoaded.push_back(ID); |
| } else { |
| ID->Data = ID->getCanonicalDecl()->Data; |
| } |
| } |
| |
| void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) { |
| VisitFieldDecl(IVD); |
| IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record.readInt()); |
| // This field will be built lazily. |
| IVD->setNextIvar(nullptr); |
| bool synth = Record.readInt(); |
| IVD->setSynthesize(synth); |
| |
| // Check ivar redeclaration. |
| if (IVD->isInvalidDecl()) |
| return; |
| // Don't check ObjCInterfaceDecl as interfaces are named and mismatches can be |
| // detected in VisitObjCInterfaceDecl. Here we are looking for redeclarations |
| // in extensions. |
| if (isa<ObjCInterfaceDecl>(IVD->getDeclContext())) |
| return; |
| ObjCInterfaceDecl *CanonIntf = |
| IVD->getContainingInterface()->getCanonicalDecl(); |
| IdentifierInfo *II = IVD->getIdentifier(); |
| ObjCIvarDecl *PrevIvar = CanonIntf->lookupInstanceVariable(II); |
| if (PrevIvar && PrevIvar != IVD) { |
| auto *ParentExt = dyn_cast<ObjCCategoryDecl>(IVD->getDeclContext()); |
| auto *PrevParentExt = |
| dyn_cast<ObjCCategoryDecl>(PrevIvar->getDeclContext()); |
| if (ParentExt && PrevParentExt) { |
| // Postpone diagnostic as we should merge identical extensions from |
| // different modules. |
| Reader |
| .PendingObjCExtensionIvarRedeclarations[std::make_pair(ParentExt, |
| PrevParentExt)] |
| .push_back(std::make_pair(IVD, PrevIvar)); |
| } else if (ParentExt || PrevParentExt) { |
| // Duplicate ivars in extension + implementation are never compatible. |
| // Compatibility of implementation + implementation should be handled in |
| // VisitObjCImplementationDecl. |
| Reader.Diag(IVD->getLocation(), diag::err_duplicate_ivar_declaration) |
| << II; |
| Reader.Diag(PrevIvar->getLocation(), diag::note_previous_definition); |
| } |
| } |
| } |
| |
| void ASTDeclReader::ReadObjCDefinitionData( |
| struct ObjCProtocolDecl::DefinitionData &Data) { |
| unsigned NumProtoRefs = Record.readInt(); |
| SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; |
| ProtoRefs.reserve(NumProtoRefs); |
| for (unsigned I = 0; I != NumProtoRefs; ++I) |
| ProtoRefs.push_back(readDeclAs<ObjCProtocolDecl>()); |
| SmallVector<SourceLocation, 16> ProtoLocs; |
| ProtoLocs.reserve(NumProtoRefs); |
| for (unsigned I = 0; I != NumProtoRefs; ++I) |
| ProtoLocs.push_back(readSourceLocation()); |
| Data.ReferencedProtocols.set(ProtoRefs.data(), NumProtoRefs, |
| ProtoLocs.data(), Reader.getContext()); |
| Data.ODRHash = Record.readInt(); |
| Data.HasODRHash = true; |
| } |
| |
| void ASTDeclMerger::MergeDefinitionData( |
| ObjCProtocolDecl *D, struct ObjCProtocolDecl::DefinitionData &&NewDD) { |
| struct ObjCProtocolDecl::DefinitionData &DD = D->data(); |
| if (DD.Definition == NewDD.Definition) |
| return; |
| |
| Reader.MergedDeclContexts.insert( |
| std::make_pair(NewDD.Definition, DD.Definition)); |
| Reader.mergeDefinitionVisibility(DD.Definition, NewDD.Definition); |
| |
| if (D->getODRHash() != NewDD.ODRHash) |
| Reader.PendingObjCProtocolOdrMergeFailures[DD.Definition].push_back( |
| {NewDD.Definition, &NewDD}); |
| } |
| |
| void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) { |
| RedeclarableResult Redecl = VisitRedeclarable(PD); |
| VisitObjCContainerDecl(PD); |
| mergeRedeclarable(PD, Redecl); |
| |
| if (Record.readInt()) { |
| // Read the definition. |
| PD->allocateDefinitionData(); |
| |
| ReadObjCDefinitionData(PD->data()); |
| |
| ObjCProtocolDecl *Canon = PD->getCanonicalDecl(); |
| if (Canon->Data.getPointer()) { |
| // If we already have a definition, keep the definition invariant and |
| // merge the data. |
| MergeImpl.MergeDefinitionData(Canon, std::move(PD->data())); |
| PD->Data = Canon->Data; |
| } else { |
| // Set the definition data of the canonical declaration, so other |
| // redeclarations will see it. |
| PD->getCanonicalDecl()->Data = PD->Data; |
| } |
| // Note that we have deserialized a definition. |
| Reader.PendingDefinitions.insert(PD); |
| } else { |
| PD->Data = PD->getCanonicalDecl()->Data; |
| } |
| } |
| |
| void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) { |
| VisitFieldDecl(FD); |
| } |
| |
| void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) { |
| VisitObjCContainerDecl(CD); |
| CD->setCategoryNameLoc(readSourceLocation()); |
| CD->setIvarLBraceLoc(readSourceLocation()); |
| CD->setIvarRBraceLoc(readSourceLocation()); |
| |
| // Note that this category has been deserialized. We do this before |
| // deserializing the interface declaration, so that it will consider this |
| /// category. |
| Reader.CategoriesDeserialized.insert(CD); |
| |
| CD->ClassInterface = readDeclAs<ObjCInterfaceDecl>(); |
| CD->TypeParamList = ReadObjCTypeParamList(); |
| unsigned NumProtoRefs = Record.readInt(); |
| SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; |
| ProtoRefs.reserve(NumProtoRefs); |
| for (unsigned I = 0; I != NumProtoRefs; ++I) |
| ProtoRefs.push_back(readDeclAs<ObjCProtocolDecl>()); |
| SmallVector<SourceLocation, 16> ProtoLocs; |
| ProtoLocs.reserve(NumProtoRefs); |
| for (unsigned I = 0; I != NumProtoRefs; ++I) |
| ProtoLocs.push_back(readSourceLocation()); |
| CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(), |
| Reader.getContext()); |
| |
| // Protocols in the class extension belong to the class. |
| if (NumProtoRefs > 0 && CD->ClassInterface && CD->IsClassExtension()) |
| CD->ClassInterface->mergeClassExtensionProtocolList( |
| (ObjCProtocolDecl *const *)ProtoRefs.data(), NumProtoRefs, |
| Reader.getContext()); |
| } |
| |
| void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) { |
| VisitNamedDecl(CAD); |
| CAD->setClassInterface(readDeclAs<ObjCInterfaceDecl>()); |
| } |
| |
| void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
| VisitNamedDecl(D); |
| D->setAtLoc(readSourceLocation()); |
| D->setLParenLoc(readSourceLocation()); |
| QualType T = Record.readType(); |
| TypeSourceInfo *TSI = readTypeSourceInfo(); |
| D->setType(T, TSI); |
| D->setPropertyAttributes((ObjCPropertyAttribute::Kind)Record.readInt()); |
| D->setPropertyAttributesAsWritten( |
| (ObjCPropertyAttribute::Kind)Record.readInt()); |
| D->setPropertyImplementation( |
| (ObjCPropertyDecl::PropertyControl)Record.readInt()); |
| DeclarationName GetterName = Record.readDeclarationName(); |
| SourceLocation GetterLoc = readSourceLocation(); |
| D->setGetterName(GetterName.getObjCSelector(), GetterLoc); |
| DeclarationName SetterName = Record.readDeclarationName(); |
| SourceLocation SetterLoc = readSourceLocation(); |
| D->setSetterName(SetterName.getObjCSelector(), SetterLoc); |
| D->setGetterMethodDecl(readDeclAs<ObjCMethodDecl>()); |
| D->setSetterMethodDecl(readDeclAs<ObjCMethodDecl>()); |
| D->setPropertyIvarDecl(readDeclAs<ObjCIvarDecl>()); |
| } |
| |
| void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) { |
| VisitObjCContainerDecl(D); |
| D->setClassInterface(readDeclAs<ObjCInterfaceDecl>()); |
| } |
| |
| void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| VisitObjCImplDecl(D); |
| D->CategoryNameLoc = readSourceLocation(); |
| } |
| |
| void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| VisitObjCImplDecl(D); |
| D->setSuperClass(readDeclAs<ObjCInterfaceDecl>()); |
| D->SuperLoc = readSourceLocation(); |
| D->setIvarLBraceLoc(readSourceLocation()); |
| D->setIvarRBraceLoc(readSourceLocation()); |
| D->setHasNonZeroConstructors(Record.readInt()); |
| D->setHasDestructors(Record.readInt()); |
| D->NumIvarInitializers = Record.readInt(); |
| if (D->NumIvarInitializers) |
| D->IvarInitializers = ReadGlobalOffset(); |
| } |
| |
| void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| VisitDecl(D); |
| D->setAtLoc(readSourceLocation()); |
| D->setPropertyDecl(readDeclAs<ObjCPropertyDecl>()); |
| D->PropertyIvarDecl = readDeclAs<ObjCIvarDecl>(); |
| D->IvarLoc = readSourceLocation(); |
| D->setGetterMethodDecl(readDeclAs<ObjCMethodDecl>()); |
| D->setSetterMethodDecl(readDeclAs<ObjCMethodDecl>()); |
| D->setGetterCXXConstructor(Record.readExpr()); |
| D->setSetterCXXAssignment(Record.readExpr()); |
| } |
| |
| void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) { |
| VisitDeclaratorDecl(FD); |
| FD->Mutable = Record.readInt(); |
| |
| unsigned Bits = Record.readInt(); |
| FD->StorageKind = Bits >> 1; |
| if (FD->StorageKind == FieldDecl::ISK_CapturedVLAType) |
| FD->CapturedVLAType = |
| cast<VariableArrayType>(Record.readType().getTypePtr()); |
| else if (Bits & 1) |
| FD->setBitWidth(Record.readExpr()); |
| |
| if (!FD->getDeclName()) { |
| if (auto *Tmpl = readDeclAs<FieldDecl>()) |
| Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl); |
| } |
| mergeMergeable(FD); |
| } |
| |
| void ASTDeclReader::VisitMSPropertyDecl(MSPropertyDecl *PD) { |
| VisitDeclaratorDecl(PD); |
| PD->GetterId = Record.readIdentifier(); |
| PD->SetterId = Record.readIdentifier(); |
| } |
| |
| void ASTDeclReader::VisitMSGuidDecl(MSGuidDecl *D) { |
| VisitValueDecl(D); |
| D->PartVal.Part1 = Record.readInt(); |
| D->PartVal.Part2 = Record.readInt(); |
| D->PartVal.Part3 = Record.readInt(); |
| for (auto &C : D->PartVal.Part4And5) |
| C = Record.readInt(); |
| |
| // Add this GUID to the AST context's lookup structure, and merge if needed. |
| if (MSGuidDecl *Existing = Reader.getContext().MSGuidDecls.GetOrInsertNode(D)) |
| Reader.getContext().setPrimaryMergedDecl(D, Existing->getCanonicalDecl()); |
| } |
| |
| void ASTDeclReader::VisitUnnamedGlobalConstantDecl( |
| UnnamedGlobalConstantDecl *D) { |
| VisitValueDecl(D); |
| D->Value = Record.readAPValue(); |
| |
| // Add this to the AST context's lookup structure, and merge if needed. |
| if (UnnamedGlobalConstantDecl *Existing = |
| Reader.getContext().UnnamedGlobalConstantDecls.GetOrInsertNode(D)) |
| Reader.getContext().setPrimaryMergedDecl(D, Existing->getCanonicalDecl()); |
| } |
| |
| void ASTDeclReader::VisitTemplateParamObjectDecl(TemplateParamObjectDecl *D) { |
| VisitValueDecl(D); |
| D->Value = Record.readAPValue(); |
| |
| // Add this template parameter object to the AST context's lookup structure, |
| // and merge if needed. |
| if (TemplateParamObjectDecl *Existing = |
| Reader.getContext().TemplateParamObjectDecls.GetOrInsertNode(D)) |
| Reader.getContext().setPrimaryMergedDecl(D, Existing->getCanonicalDecl()); |
| } |
| |
| void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) { |
| VisitValueDecl(FD); |
| |
| FD->ChainingSize = Record.readInt(); |
| assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2"); |
| FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize]; |
| |
| for (unsigned I = 0; I != FD->ChainingSize; ++I) |
| FD->Chaining[I] = readDeclAs<NamedDecl>(); |
| |
| mergeMergeable(FD); |
| } |
| |
| RedeclarableResult ASTDeclReader::VisitVarDeclImpl(VarDecl *VD) { |
| RedeclarableResult Redecl = VisitRedeclarable(VD); |
| VisitDeclaratorDecl(VD); |
| |
| BitsUnpacker VarDeclBits(Record.readInt()); |
| auto VarLinkage = Linkage(VarDeclBits.getNextBits(/*Width=*/3)); |
| bool DefGeneratedInModule = VarDeclBits.getNextBit(); |
| VD->VarDeclBits.SClass = (StorageClass)VarDeclBits.getNextBits(/*Width=*/3); |
| VD->VarDeclBits.TSCSpec = VarDeclBits.getNextBits(/*Width=*/2); |
| VD->VarDeclBits.InitStyle = VarDeclBits.getNextBits(/*Width=*/2); |
| VD->VarDeclBits.ARCPseudoStrong = VarDeclBits.getNextBit(); |
| bool HasDeducedType = false; |
| if (!isa<ParmVarDecl>(VD)) { |
| VD->NonParmVarDeclBits.IsThisDeclarationADemotedDefinition = |
| VarDeclBits.getNextBit(); |
| VD->NonParmVarDeclBits.ExceptionVar = VarDeclBits.getNextBit(); |
| VD->NonParmVarDeclBits.NRVOVariable = VarDeclBits.getNextBit(); |
| VD->NonParmVarDeclBits.CXXForRangeDecl = VarDeclBits.getNextBit(); |
| |
| VD->NonParmVarDeclBits.IsInline = VarDeclBits.getNextBit(); |
| VD->NonParmVarDeclBits.IsInlineSpecified = VarDeclBits.getNextBit(); |
| VD->NonParmVarDeclBits.IsConstexpr = VarDeclBits.getNextBit(); |
| VD->NonParmVarDeclBits.IsInitCapture = VarDeclBits.getNextBit(); |
| VD->NonParmVarDeclBits.PreviousDeclInSameBlockScope = |
| VarDeclBits.getNextBit(); |
| |
| VD->NonParmVarDeclBits.EscapingByref = VarDeclBits.getNextBit(); |
| HasDeducedType = VarDeclBits.getNextBit(); |
| VD->NonParmVarDeclBits.ImplicitParamKind = |
| VarDeclBits.getNextBits(/*Width*/ 3); |
| |
| VD->NonParmVarDeclBits.ObjCForDecl = VarDeclBits.getNextBit(); |
| } |
| |
| // If this variable has a deduced type, defer reading that type until we are |
| // done deserializing this variable, because the type might refer back to the |
| // variable. |
| if (HasDeducedType) |
| Reader.PendingDeducedVarTypes.push_back({VD, DeferredTypeID}); |
| else |
| VD->setType(Reader.GetType(DeferredTypeID)); |
| DeferredTypeID = 0; |
| |
| VD->setCachedLinkage(VarLinkage); |
| |
| // Reconstruct the one piece of the IdentifierNamespace that we need. |
| if (VD->getStorageClass() == SC_Extern && VarLinkage != Linkage::None && |
| VD->getLexicalDeclContext()->isFunctionOrMethod()) |
| VD->setLocalExternDecl(); |
| |
| if (DefGeneratedInModule) { |
| Reader.DefinitionSource[VD] = |
| Loc.F->Kind == ModuleKind::MK_MainFile || |
| Reader.getContext().getLangOpts().BuildingPCHWithObjectFile; |
| } |
| |
| if (VD->hasAttr<BlocksAttr>()) { |
| Expr *CopyExpr = Record.readExpr(); |
| if (CopyExpr) |
| Reader.getContext().setBlockVarCopyInit(VD, CopyExpr, Record.readInt()); |
| } |
| |
| enum VarKind { |
| VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization |
| }; |
| switch ((VarKind)Record.readInt()) { |
| case VarNotTemplate: |
| // Only true variables (not parameters or implicit parameters) can be |
| // merged; the other kinds are not really redeclarable at all. |
| if (!isa<ParmVarDecl>(VD) && !isa<ImplicitParamDecl>(VD) && |
| !isa<VarTemplateSpecializationDecl>(VD)) |
| mergeRedeclarable(VD, Redecl); |
| break; |
| case VarTemplate: |
| // Merged when we merge the template. |
| VD->setDescribedVarTemplate(readDeclAs<VarTemplateDecl>()); |
| break; |
| case StaticDataMemberSpecialization: { // HasMemberSpecializationInfo. |
| auto *Tmpl = readDeclAs<VarDecl>(); |
| auto TSK = (TemplateSpecializationKind)Record.readInt(); |
| SourceLocation POI = readSourceLocation(); |
| Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI); |
| mergeRedeclarable(VD, Redecl); |
| break; |
| } |
| } |
| |
| return Redecl; |
| } |
| |
| void ASTDeclReader::ReadVarDeclInit(VarDecl *VD) { |
| if (uint64_t Val = Record.readInt()) { |
| EvaluatedStmt *Eval = VD->ensureEvaluatedStmt(); |
| Eval->HasConstantInitialization = (Val & 2) != 0; |
| Eval->HasConstantDestruction = (Val & 4) != 0; |
| Eval->WasEvaluated = (Val & 8) != 0; |
| if (Eval->WasEvaluated) { |
| Eval->Evaluated = Record.readAPValue(); |
| if (Eval->Evaluated.needsCleanup()) |
| Reader.getContext().addDestruction(&Eval->Evaluated); |
| } |
| |
| // Store the offset of the initializer. Don't deserialize it yet: it might |
| // not be needed, and might refer back to the variable, for example if it |
| // contains a lambda. |
| Eval->Value = GetCurrentCursorOffset(); |
| } |
| } |
| |
| void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) { |
| VisitVarDecl(PD); |
| } |
| |
| void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) { |
| VisitVarDecl(PD); |
| |
| unsigned scopeIndex = Record.readInt(); |
| BitsUnpacker ParmVarDeclBits(Record.readInt()); |
| unsigned isObjCMethodParam = ParmVarDeclBits.getNextBit(); |
| unsigned scopeDepth = ParmVarDeclBits.getNextBits(/*Width=*/7); |
| unsigned declQualifier = ParmVarDeclBits.getNextBits(/*Width=*/7); |
| if (isObjCMethodParam) { |
| assert(scopeDepth == 0); |
| PD->setObjCMethodScopeInfo(scopeIndex); |
| PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier; |
| } else { |
| PD->setScopeInfo(scopeDepth, scopeIndex); |
| } |
| PD->ParmVarDeclBits.IsKNRPromoted = ParmVarDeclBits.getNextBit(); |
| |
| PD->ParmVarDeclBits.HasInheritedDefaultArg = ParmVarDeclBits.getNextBit(); |
| if (ParmVarDeclBits.getNextBit()) // hasUninstantiatedDefaultArg. |
| PD->setUninstantiatedDefaultArg(Record.readExpr()); |
| |
| if (ParmVarDeclBits.getNextBit()) // Valid explicit object parameter |
| PD->ExplicitObjectParameterIntroducerLoc = Record.readSourceLocation(); |
| |
| // FIXME: If this is a redeclaration of a function from another module, handle |
| // inheritance of default arguments. |
| } |
| |
| void ASTDeclReader::VisitDecompositionDecl(DecompositionDecl *DD) { |
| VisitVarDecl(DD); |
| auto **BDs = DD->getTrailingObjects<BindingDecl *>(); |
| for (unsigned I = 0; I != DD->NumBindings; ++I) { |
| BDs[I] = readDeclAs<BindingDecl>(); |
| BDs[I]->setDecomposedDecl(DD); |
| } |
| } |
| |
| void ASTDeclReader::VisitBindingDecl(BindingDecl *BD) { |
| VisitValueDecl(BD); |
| BD->Binding = Record.readExpr(); |
| } |
| |
| void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) { |
| VisitDecl(AD); |
| AD->setAsmString(cast<StringLiteral>(Record.readExpr())); |
| AD->setRParenLoc(readSourceLocation()); |
| } |
| |
| void ASTDeclReader::VisitTopLevelStmtDecl(TopLevelStmtDecl *D) { |
| VisitDecl(D); |
| D->Statement = Record.readStmt(); |
| } |
| |
| void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) { |
| VisitDecl(BD); |
| BD->setBody(cast_or_null<CompoundStmt>(Record.readStmt())); |
| BD->setSignatureAsWritten(readTypeSourceInfo()); |
| unsigned NumParams = Record.readInt(); |
| SmallVector<ParmVarDecl *, 16> Params; |
| Params.reserve(NumParams); |
| for (unsigned I = 0; I != NumParams; ++I) |
| Params.push_back(readDeclAs<ParmVarDecl>()); |
| BD->setParams(Params); |
| |
| BD->setIsVariadic(Record.readInt()); |
| BD->setBlockMissingReturnType(Record.readInt()); |
| BD->setIsConversionFromLambda(Record.readInt()); |
| BD->setDoesNotEscape(Record.readInt()); |
| BD->setCanAvoidCopyToHeap(Record.readInt()); |
| |
| bool capturesCXXThis = Record.readInt(); |
| unsigned numCaptures = Record.readInt(); |
| SmallVector<BlockDecl::Capture, 16> captures; |
| captures.reserve(numCaptures); |
| for (unsigned i = 0; i != numCaptures; ++i) { |
| auto *decl = readDeclAs<VarDecl>(); |
| unsigned flags = Record.readInt(); |
| bool byRef = (flags & 1); |
| bool nested = (flags & 2); |
| Expr *copyExpr = ((flags & 4) ? Record.readExpr() : nullptr); |
| |
| captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr)); |
| } |
| BD->setCaptures(Reader.getContext(), captures, capturesCXXThis); |
| } |
| |
| void ASTDeclReader::VisitCapturedDecl(CapturedDecl *CD) { |
| VisitDecl(CD); |
| unsigned ContextParamPos = Record.readInt(); |
| CD->setNothrow(Record.readInt() != 0); |
| // Body is set by VisitCapturedStmt. |
| for (unsigned I = 0; I < CD->NumParams; ++I) { |
| if (I != ContextParamPos) |
| CD->setParam(I, readDeclAs<ImplicitParamDecl>()); |
| else |
| CD->setContextParam(I, readDeclAs<ImplicitParamDecl>()); |
| } |
| } |
| |
| void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| VisitDecl(D); |
| D->setLanguage(static_cast<LinkageSpecLanguageIDs>(Record.readInt())); |
| D->setExternLoc(readSourceLocation()); |
| D->setRBraceLoc(readSourceLocation()); |
| } |
| |
| void ASTDeclReader::VisitExportDecl(ExportDecl *D) { |
| VisitDecl(D); |
| D->RBraceLoc = readSourceLocation(); |
| } |
| |
| void ASTDeclReader::VisitLabelDecl(LabelDecl *D) { |
| VisitNamedDecl(D); |
| D->setLocStart(readSourceLocation()); |
| } |
| |
| void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) { |
| RedeclarableResult Redecl = VisitRedeclarable(D); |
| VisitNamedDecl(D); |
| |
| BitsUnpacker NamespaceDeclBits(Record.readInt()); |
| D->setInline(NamespaceDeclBits.getNextBit()); |
| D->setNested(NamespaceDeclBits.getNextBit()); |
| D->LocStart = readSourceLocation(); |
| D->RBraceLoc = readSourceLocation(); |
| |
| // Defer loading the anonymous namespace until we've finished merging |
| // this namespace; loading it might load a later declaration of the |
| // same namespace, and we have an invariant that older declarations |
| // get merged before newer ones try to merge. |
| GlobalDeclID AnonNamespace; |
| if (Redecl.getFirstID() == ThisDeclID) |
| AnonNamespace = readDeclID(); |
| |
| mergeRedeclarable(D, Redecl); |
| |
| if (AnonNamespace.isValid()) { |
| // Each module has its own anonymous namespace, which is disjoint from |
| // any other module's anonymous namespaces, so don't attach the anonymous |
| // namespace at all. |
| auto *Anon = cast<NamespaceDecl>(Reader.GetDecl(AnonNamespace)); |
| if (!Record.isModule()) |
| D->setAnonymousNamespace(Anon); |
| } |
| } |
| |
| void ASTDeclReader::VisitHLSLBufferDecl(HLSLBufferDecl *D) { |
| VisitNamedDecl(D); |
| VisitDeclContext(D); |
| D->IsCBuffer = Record.readBool(); |
| D->KwLoc = readSourceLocation(); |
| D->LBraceLoc = readSourceLocation(); |
| D->RBraceLoc = readSourceLocation(); |
| } |
| |
| void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
| RedeclarableResult Redecl = VisitRedeclarable(D); |
| VisitNamedDecl(D); |
| D->NamespaceLoc = readSourceLocation(); |
| D->IdentLoc = readSourceLocation(); |
| D->QualifierLoc = Record.readNestedNameSpecifierLoc(); |
| D->Namespace = readDeclAs<NamedDecl>(); |
| mergeRedeclarable(D, Redecl); |
| } |
| |
| void ASTDeclReader::VisitUsingDecl(UsingDecl *D) { |
| VisitNamedDecl(D); |
| D->setUsingLoc(readSourceLocation()); |
| D->QualifierLoc = Record.readNestedNameSpecifierLoc(); |
| D->DNLoc = Record.readDeclarationNameLoc(D->getDeclName()); |
| D->FirstUsingShadow.setPointer(readDeclAs<UsingShadowDecl>()); |
| D->setTypename(Record.readInt()); |
| if (auto *Pattern = readDeclAs<NamedDecl>()) |
| Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern); |
| mergeMergeable(D); |
| } |
| |
| void ASTDeclReader::VisitUsingEnumDecl(UsingEnumDecl *D) { |
| VisitNamedDecl(D); |
| D->setUsingLoc(readSourceLocation()); |
| D->setEnumLoc(readSourceLocation()); |
| D->setEnumType(Record.readTypeSourceInfo()); |
| D->FirstUsingShadow.setPointer(readDeclAs<UsingShadowDecl>()); |
| if (auto *Pattern = readDeclAs<UsingEnumDecl>()) |
| Reader.getContext().setInstantiatedFromUsingEnumDecl(D, Pattern); |
| mergeMergeable(D); |
| } |
| |
| void ASTDeclReader::VisitUsingPackDecl(UsingPackDecl *D) { |
| VisitNamedDecl(D); |
| D->InstantiatedFrom = readDeclAs<NamedDecl>(); |
| auto **Expansions = D->getTrailingObjects<NamedDecl *>(); |
| for (unsigned I = 0; I != D->NumExpansions; ++I) |
| Expansions[I] = readDeclAs<NamedDecl>(); |
| mergeMergeable(D); |
| } |
| |
| void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) { |
| RedeclarableResult Redecl = VisitRedeclarable(D); |
| VisitNamedDecl(D); |
| D->Underlying = readDeclAs<NamedDecl>(); |
| D->IdentifierNamespace = Record.readInt(); |
| D->UsingOrNextShadow = readDeclAs<NamedDecl>(); |
| auto *Pattern = readDeclAs<UsingShadowDecl>(); |
| if (Pattern) |
| Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern); |
| mergeRedeclarable(D, Redecl); |
| } |
| |
| void ASTDeclReader::VisitConstructorUsingShadowDecl( |
| ConstructorUsingShadowDecl *D) { |
| VisitUsingShadowDecl(D); |
| D->NominatedBaseClassShadowDecl = readDeclAs<ConstructorUsingShadowDecl>(); |
| D->ConstructedBaseClassShadowDecl = readDeclAs<ConstructorUsingShadowDecl>(); |
| D->IsVirtual = Record.readInt(); |
| } |
| |
| void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
| VisitNamedDecl(D); |
| D->UsingLoc = readSourceLocation(); |
| D->NamespaceLoc = readSourceLocation(); |
| D->QualifierLoc = Record.readNestedNameSpecifierLoc(); |
| D->NominatedNamespace = readDeclAs<NamedDecl>(); |
| D->CommonAncestor = readDeclAs<DeclContext>(); |
| } |
| |
| void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) { |
| VisitValueDecl(D); |
| D->setUsingLoc(readSourceLocation()); |
| D->QualifierLoc = Record.readNestedNameSpecifierLoc(); |
| D->DNLoc = Record.readDeclarationNameLoc(D->getDeclName()); |
| D->EllipsisLoc = readSourceLocation(); |
| mergeMergeable(D); |
| } |
| |
| void ASTDeclReader::VisitUnresolvedUsingTypenameDecl( |
| UnresolvedUsingTypenameDecl *D) { |
| VisitTypeDecl(D); |
| D->TypenameLocation = readSourceLocation(); |
| D->QualifierLoc = Record.readNestedNameSpecifierLoc(); |
| D->EllipsisLoc = readSourceLocation(); |
| mergeMergeable(D); |
| } |
| |
| void ASTDeclReader::VisitUnresolvedUsingIfExistsDecl( |
| UnresolvedUsingIfExistsDecl *D) { |
| VisitNamedDecl(D); |
| } |
| |
| void ASTDeclReader::ReadCXXDefinitionData( |
| struct CXXRecordDecl::DefinitionData &Data, const CXXRecordDecl *D, |
| Decl *LambdaContext, unsigned IndexInLambdaContext) { |
| |
| BitsUnpacker CXXRecordDeclBits = Record.readInt(); |
| |
| #define FIELD(Name, Width, Merge) \ |
| if (!CXXRecordDeclBits.canGetNextNBits(Width)) \ |
| CXXRecordDeclBits.updateValue(Record.readInt()); \ |
| Data.Name = CXXRecordDeclBits.getNextBits(Width); |
| |
| #include "clang/AST/CXXRecordDeclDefinitionBits.def" |
| #undef FIELD |
| |
| // Note: the caller has deserialized the IsLambda bit already. |
| Data.ODRHash = Record.readInt(); |
| Data.HasODRHash = true; |
| |
| if (Record.readInt()) { |
| Reader.DefinitionSource[D] = |
| Loc.F->Kind == ModuleKind::MK_MainFile || |
| Reader.getContext().getLangOpts().BuildingPCHWithObjectFile; |
| } |
| |
| Record.readUnresolvedSet(Data.Conversions); |
| Data.ComputedVisibleConversions = Record.readInt(); |
| if (Data.ComputedVisibleConversions) |
| Record.readUnresolvedSet(Data.VisibleConversions); |
| assert(Data.Definition && "Data.Definition should be already set!"); |
| |
| if (!Data.IsLambda) { |
| assert(!LambdaContext && !IndexInLambdaContext && |
| "given lambda context for non-lambda"); |
| |
| Data.NumBases = Record.readInt(); |
| if (Data.NumBases) |
| Data.Bases = ReadGlobalOffset(); |
| |
| Data.NumVBases = Record.readInt(); |
| if (Data.NumVBases) |
| Data.VBases = ReadGlobalOffset(); |
| |
| Data.FirstFriend = readDeclID().getRawValue(); |
| } else { |
| using Capture = LambdaCapture; |
| |
| auto &Lambda = static_cast<CXXRecordDecl::LambdaDefinitionData &>(Data); |
| |
| BitsUnpacker LambdaBits(Record.readInt()); |
| Lambda.DependencyKind = LambdaBits.getNextBits(/*Width=*/2); |
| Lambda.IsGenericLambda = LambdaBits.getNextBit(); |
| Lambda.CaptureDefault = LambdaBits.getNextBits(/*Width=*/2); |
| Lambda.NumCaptures = LambdaBits.getNextBits(/*Width=*/15); |
| Lambda.HasKnownInternalLinkage = LambdaBits.getNextBit(); |
| |
| Lambda.NumExplicitCaptures = Record.readInt(); |
| Lambda.ManglingNumber = Record.readInt(); |
| if (unsigned DeviceManglingNumber = Record.readInt()) |
| Reader.getContext().DeviceLambdaManglingNumbers[D] = DeviceManglingNumber; |
| Lambda.IndexInContext = IndexInLambdaContext; |
| Lambda.ContextDecl = LambdaContext; |
| Capture *ToCapture = nullptr; |
| if (Lambda.NumCaptures) { |
| ToCapture = (Capture *)Reader.getContext().Allocate(sizeof(Capture) * |
| Lambda.NumCaptures); |
| Lambda.AddCaptureList(Reader.getContext(), ToCapture); |
| } |
| Lambda.MethodTyInfo = readTypeSourceInfo(); |
| for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) { |
| SourceLocation Loc = readSourceLocation(); |
| BitsUnpacker CaptureBits(Record.readInt()); |
| bool IsImplicit = CaptureBits.getNextBit(); |
| auto Kind = |
| static_cast<LambdaCaptureKind>(CaptureBits.getNextBits(/*Width=*/3)); |
| switch (Kind) { |
| case LCK_StarThis: |
| case LCK_This: |
| case LCK_VLAType: |
| new (ToCapture) |
| Capture(Loc, IsImplicit, Kind, nullptr, SourceLocation()); |
| ToCapture++; |
| break; |
| case LCK_ByCopy: |
| case LCK_ByRef: |
| auto *Var = readDeclAs<ValueDecl>(); |
| SourceLocation EllipsisLoc = readSourceLocation(); |
| new (ToCapture) Capture(Loc, IsImplicit, Kind, Var, EllipsisLoc); |
| ToCapture++; |
| break; |
| } |
| } |
| } |
| } |
| |
| void ASTDeclMerger::MergeDefinitionData( |
| CXXRecordDecl *D, struct CXXRecordDecl::DefinitionData &&MergeDD) { |
| assert(D->DefinitionData && |
| "merging class definition into non-definition"); |
| auto &DD = *D->DefinitionData; |
| |
| if (DD.Definition != MergeDD.Definition) { |
| // Track that we merged the definitions. |
| Reader.MergedDeclContexts.insert(std::make_pair(MergeDD.Definition, |
| DD.Definition)); |
| Reader.PendingDefinitions.erase(MergeDD.Definition); |
| MergeDD.Definition->demoteThisDefinitionToDeclaration(); |
| Reader.mergeDefinitionVisibility(DD.Definition, MergeDD.Definition); |
| assert(!Reader.Lookups.contains(MergeDD.Definition) && |
| "already loaded pending lookups for merged definition"); |
| } |
| |
| auto PFDI = Reader.PendingFakeDefinitionData.find(&DD); |
| if (PFDI != Reader.PendingFakeDefinitionData.end() && |
| PFDI->second == ASTReader::PendingFakeDefinitionKind::Fake) { |
| // We faked up this definition data because we found a class for which we'd |
| // not yet loaded the definition. Replace it with the real thing now. |
| assert(!DD.IsLambda && !MergeDD.IsLambda && "faked up lambda definition?"); |
| PFDI->second = ASTReader::PendingFakeDefinitionKind::FakeLoaded; |
| |
| // Don't change which declaration is the definition; that is required |
| // to be invariant once we select it. |
| auto *Def = DD.Definition; |
| DD = std::move(MergeDD); |
| DD.Definition = Def; |
| return; |
| } |
| |
| bool DetectedOdrViolation = false; |
| |
| #define FIELD(Name, Width, Merge) Merge(Name) |
| #define MERGE_OR(Field) DD.Field |= MergeDD.Field; |
| #define NO_MERGE(Field) \ |
| DetectedOdrViolation |= DD.Field != MergeDD.Field; \ |
| MERGE_OR(Field) |
| #include "clang/AST/CXXRecordDeclDefinitionBits.def" |
| NO_MERGE(IsLambda) |
| #undef NO_MERGE |
| #undef MERGE_OR |
| |
| if (DD.NumBases != MergeDD.NumBases || DD.NumVBases != MergeDD.NumVBases) |
| DetectedOdrViolation = true; |
| // FIXME: Issue a diagnostic if the base classes don't match when we come |
| // to lazily load them. |
| |
| // FIXME: Issue a diagnostic if the list of conversion functions doesn't |
| // match when we come to lazily load them. |
| if (MergeDD.ComputedVisibleConversions && !DD.ComputedVisibleConversions) { |
| DD.VisibleConversions = std::move(MergeDD.VisibleConversions); |
| DD.ComputedVisibleConversions = true; |
| } |
| |
| // FIXME: Issue a diagnostic if FirstFriend doesn't match when we come to |
| // lazily load it. |
| |
| if (DD.IsLambda) { |
| auto &Lambda1 = static_cast<CXXRecordDecl::LambdaDefinitionData &>(DD); |
| auto &Lambda2 = static_cast<CXXRecordDecl::LambdaDefinitionData &>(MergeDD); |
| DetectedOdrViolation |= Lambda1.DependencyKind != Lambda2.DependencyKind; |
| DetectedOdrViolation |= Lambda1.IsGenericLambda != Lambda2.IsGenericLambda; |
| DetectedOdrViolation |= Lambda1.CaptureDefault != Lambda2.CaptureDefault; |
| DetectedOdrViolation |= Lambda1.NumCaptures != Lambda2.NumCaptures; |
| DetectedOdrViolation |= |
| Lambda1.NumExplicitCaptures != Lambda2.NumExplicitCaptures; |
| DetectedOdrViolation |= |
| Lambda1.HasKnownInternalLinkage != Lambda2.HasKnownInternalLinkage; |
| DetectedOdrViolation |= Lambda1.ManglingNumber != Lambda2.ManglingNumber; |
| |
| if (Lambda1.NumCaptures && Lambda1.NumCaptures == Lambda2.NumCaptures) { |
| for (unsigned I = 0, N = Lambda1.NumCaptures; I != N; ++I) { |
| LambdaCapture &Cap1 = Lambda1.Captures.front()[I]; |
| LambdaCapture &Cap2 = Lambda2.Captures.front()[I]; |
| DetectedOdrViolation |= Cap1.getCaptureKind() != Cap2.getCaptureKind(); |
| } |
| Lambda1.AddCaptureList(Reader.getContext(), Lambda2.Captures.front()); |
| } |
| } |
| |
| // We don't want to check ODR for decls in the global module fragment. |
| if (shouldSkipCheckingODR(MergeDD.Definition) || shouldSkipCheckingODR(D)) |
| return; |
| |
| if (D->getODRHash() != MergeDD.ODRHash) { |
| DetectedOdrViolation = true; |
| } |
| |
| if (DetectedOdrViolation) |
| Reader.PendingOdrMergeFailures[DD.Definition].push_back( |
| {MergeDD.Definition, &MergeDD}); |
| } |
| |
| void ASTDeclReader::ReadCXXRecordDefinition(CXXRecordDecl *D, bool Update, |
| Decl *LambdaContext, |
| unsigned IndexInLambdaContext) { |
| struct CXXRecordDecl::DefinitionData *DD; |
| ASTContext &C = Reader.getContext(); |
| |
| // Determine whether this is a lambda closure type, so that we can |
| // allocate the appropriate DefinitionData structure. |
| bool IsLambda = Record.readInt(); |
| assert(!(IsLambda && Update) && |
| "lambda definition should not be added by update record"); |
| if (IsLambda) |
| DD = new (C) CXXRecordDecl::LambdaDefinitionData( |
| D, nullptr, CXXRecordDecl::LDK_Unknown, false, LCD_None); |
| else |
| DD = new (C) struct CXXRecordDecl::DefinitionData(D); |
| |
| CXXRecordDecl *Canon = D->getCanonicalDecl(); |
| // Set decl definition data before reading it, so that during deserialization |
| // when we read CXXRecordDecl, it already has definition data and we don't |
| // set fake one. |
| if (!Canon->DefinitionData) |
| Canon->DefinitionData = DD; |
| D->DefinitionData = Canon->DefinitionData; |
| ReadCXXDefinitionData(*DD, D, LambdaContext, IndexInLambdaContext); |
| |
| // Mark this declaration as being a definition. |
| D->setCompleteDefinition(true); |
| |
| // We might already have a different definition for this record. This can |
| // happen either because we're reading an update record, or because we've |
| // already done some merging. Either way, just merge into it. |
| if (Canon->DefinitionData != DD) { |
| MergeImpl.MergeDefinitionData(Canon, std::move(*DD)); |
| return; |
| } |
| |
| // If this is not the first declaration or is an update record, we can have |
| // other redeclarations already. Make a note that we need to propagate the |
| // DefinitionData pointer onto them. |
| if (Update || Canon != D) |
| Reader.PendingDefinitions.insert(D); |
| } |
| |
| RedeclarableResult ASTDeclReader::VisitCXXRecordDeclImpl(CXXRecordDecl *D) { |
| RedeclarableResult Redecl = VisitRecordDeclImpl(D); |
| |
| ASTContext &C = Reader.getContext(); |
| |
| enum CXXRecKind { |
| CXXRecNotTemplate = 0, |
| CXXRecTemplate, |
| CXXRecMemberSpecialization, |
| CXXLambda |
| }; |
| |
| Decl *LambdaContext = nullptr; |
| unsigned IndexInLambdaContext = 0; |
| |
| switch ((CXXRecKind)Record.readInt()) { |
| case CXXRecNotTemplate: |
| // Merged when we merge the folding set entry in the primary template. |
| if (!isa<ClassTemplateSpecializationDecl>(D)) |
| mergeRedeclarable(D, Redecl); |
| break; |
| case CXXRecTemplate: { |
| // Merged when we merge the template. |
| auto *Template = readDeclAs<ClassTemplateDecl>(); |
| D->TemplateOrInstantiation = Template; |
| if (!Template->getTemplatedDecl()) { |
| // We've not actually loaded the ClassTemplateDecl yet, because we're |
| // currently being loaded as its pattern. Rely on it to set up our |
| // TypeForDecl (see VisitClassTemplateDecl). |
| // |
| // Beware: we do not yet know our canonical declaration, and may still |
| // get merged once the surrounding class template has got off the ground. |
| DeferredTypeID = 0; |
| } |
| break; |
| } |
| case CXXRecMemberSpecialization: { |
| auto *RD = readDeclAs<CXXRecordDecl>(); |
| auto TSK = (TemplateSpecializationKind)Record.readInt(); |
| SourceLocation POI = readSourceLocation(); |
| MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK); |
| MSI->setPointOfInstantiation(POI); |
| D->TemplateOrInstantiation = MSI; |
| mergeRedeclarable(D, Redecl); |
| break; |
| } |
| case CXXLambda: { |
| LambdaContext = readDecl(); |
| if (LambdaContext) |
| IndexInLambdaContext = Record.readInt(); |
| if (LambdaContext) |
| MergeImpl.mergeLambda(D, Redecl, *LambdaContext, IndexInLambdaContext); |
| else |
| // If we don't have a mangling context, treat this like any other |
| // declaration. |
| mergeRedeclarable(D, Redecl); |
| break; |
| } |
| } |
| |
| bool WasDefinition = Record.readInt(); |
| if (WasDefinition) |
| ReadCXXRecordDefinition(D, /*Update=*/false, LambdaContext, |
| IndexInLambdaContext); |
| else |
| // Propagate DefinitionData pointer from the canonical declaration. |
| D->DefinitionData = D->getCanonicalDecl()->DefinitionData; |
| |
| // Lazily load the key function to avoid deserializing every method so we can |
| // compute it. |
| if (WasDefinition) { |
| GlobalDeclID KeyFn = readDeclID(); |
| if (KeyFn.isValid() && D->isCompleteDefinition()) |
| // FIXME: This is wrong for the ARM ABI, where some other module may have |
| // made this function no longer be a key function. We need an update |
| // record or similar for that case. |
| C.KeyFunctions[D] = KeyFn.getRawValue(); |
| } |
| |
| return Redecl; |
| } |
| |
| void ASTDeclReader::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) { |
| D->setExplicitSpecifier(Record.readExplicitSpec()); |
| D->Ctor = readDeclAs<CXXConstructorDecl>(); |
| VisitFunctionDecl(D); |
| D->setDeductionCandidateKind( |
| static_cast<DeductionCandidate>(Record.readInt())); |
| } |
| |
| void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) { |
| VisitFunctionDecl(D); |
| |
| unsigned NumOverridenMethods = Record.readInt(); |
| if (D->isCanonicalDecl()) { |
| while (NumOverridenMethods--) { |
| // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod, |
| // MD may be initializing. |
| if (auto *MD = readDeclAs<CXXMethodDecl>()) |
| Reader.getContext().addOverriddenMethod(D, MD->getCanonicalDecl()); |
| } |
| } else { |
| // We don't care about which declarations this used to override; we get |
| // the relevant information from the canonical declaration. |
| Record.skipInts(NumOverridenMethods); |
| } |
| } |
| |
| void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
| // We need the inherited constructor information to merge the declaration, |
| // so we have to read it before we call VisitCXXMethodDecl. |
| D->setExplicitSpecifier(Record.readExplicitSpec()); |
| if (D->isInheritingConstructor()) { |
| auto *Shadow = readDeclAs<ConstructorUsingShadowDecl>(); |
| auto *Ctor = readDeclAs<CXXConstructorDecl>(); |
| *D->getTrailingObjects<InheritedConstructor>() = |
| InheritedConstructor(Shadow, Ctor); |
| } |
| |
| VisitCXXMethodDecl(D); |
| } |
| |
| void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
| VisitCXXMethodDecl(D); |
| |
| if (auto *OperatorDelete = readDeclAs<FunctionDecl>()) { |
| CXXDestructorDecl *Canon = D->getCanonicalDecl(); |
| auto *ThisArg = Record.readExpr(); |
| // FIXME: Check consistency if we have an old and new operator delete. |
| if (!Canon->OperatorDelete) { |
| Canon->OperatorDelete = OperatorDelete; |
| Canon->OperatorDeleteThisArg = ThisArg; |
| } |
| } |
| } |
| |
| void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) { |
| D->setExplicitSpecifier(Record.readExplicitSpec()); |
| VisitCXXMethodDecl(D); |
| } |
| |
| void ASTDeclReader::VisitImportDecl(ImportDecl *D) { |
| VisitDecl(D); |
| D->ImportedModule = readModule(); |
| D->setImportComplete(Record.readInt()); |
| auto *StoredLocs = D->getTrailingObjects<SourceLocation>(); |
| for (unsigned I = 0, N = Record.back(); I != N; ++I) |
| StoredLocs[I] = readSourceLocation(); |
| Record.skipInts(1); // The number of stored source locations. |
| } |
| |
| void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) { |
| VisitDecl(D); |
| D->setColonLoc(readSourceLocation()); |
| } |
| |
| void ASTDeclReader::VisitFriendDecl(FriendDecl *D) { |
| VisitDecl(D); |
| if (Record.readInt()) // hasFriendDecl |
| D->Friend = readDeclAs<NamedDecl>(); |
| else |
| D->Friend = readTypeSourceInfo(); |
| for (unsigned i = 0; i != D->NumTPLists; ++i) |
| D->getTrailingObjects<TemplateParameterList *>()[i] = |
| Record.readTemplateParameterList(); |
| D->NextFriend = readDeclID().getRawValue(); |
| D->UnsupportedFriend = (Record.readInt() != 0); |
| D->FriendLoc = readSourceLocation(); |
| D->EllipsisLoc = readSourceLocation(); |
| } |
| |
| void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) { |
| VisitDecl(D); |
| unsigned NumParams = Record.readInt(); |
| D->NumParams = NumParams; |
| D->Params = new (Reader.getContext()) TemplateParameterList *[NumParams]; |
| for (unsigned i = 0; i != NumParams; ++i) |
| D->Params[i] = Record.readTemplateParameterList(); |
| if (Record.readInt()) // HasFriendDecl |
| D->Friend = readDeclAs<NamedDecl>(); |
| else |
| D->Friend = readTypeSourceInfo(); |
| D->FriendLoc = readSourceLocation(); |
| } |
| |
| void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) { |
| VisitNamedDecl(D); |
| |
| assert(!D->TemplateParams && "TemplateParams already set!"); |
| D->TemplateParams = Record.readTemplateParameterList(); |
| D->init(readDeclAs<NamedDecl>()); |
| } |
| |
| void ASTDeclReader::VisitConceptDecl(ConceptDecl *D) { |
| VisitTemplateDecl(D); |
| D->ConstraintExpr = Record.readExpr(); |
| mergeMergeable(D); |
| } |
| |
| void ASTDeclReader::VisitImplicitConceptSpecializationDecl( |
| ImplicitConceptSpecializationDecl *D) { |
| // The size of the template list was read during creation of the Decl, so we |
| // don't have to re-read it here. |
| VisitDecl(D); |
| llvm::SmallVector<TemplateArgument, 4> Args; |
| for (unsigned I = 0; I < D->NumTemplateArgs; ++I) |
| Args.push_back(Record.readTemplateArgument(/*Canonicalize=*/true)); |
| D->setTemplateArguments(Args); |
| } |
| |
| void ASTDeclReader::VisitRequiresExprBodyDecl(RequiresExprBodyDecl *D) { |
| } |
| |
| RedeclarableResult |
| ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) { |
| RedeclarableResult Redecl = VisitRedeclarable(D); |
| |
| // Make sure we've allocated the Common pointer first. We do this before |
| // VisitTemplateDecl so that getCommonPtr() can be used during initialization. |
| RedeclarableTemplateDecl *CanonD = D->getCanonicalDecl(); |
| if (!CanonD->Common) { |
| CanonD->Common = CanonD->newCommon(Reader.getContext()); |
| Reader.PendingDefinitions.insert(CanonD); |
| } |
| D->Common = CanonD->Common; |
| |
| // If this is the first declaration of the template, fill in the information |
| // for the 'common' pointer. |
| if (ThisDeclID == Redecl.getFirstID()) { |
| if (auto *RTD = readDeclAs<RedeclarableTemplateDecl>()) { |
| assert(RTD->getKind() == D->getKind() && |
| "InstantiatedFromMemberTemplate kind mismatch"); |
| D->setInstantiatedFromMemberTemplate(RTD); |
| if (Record.readInt()) |
| D->setMemberSpecialization(); |
| } |
| } |
| |
| VisitTemplateDecl(D); |
| D->IdentifierNamespace = Record.readInt(); |
| |
| return Redecl; |
| } |
| |
| void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
| RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); |
| mergeRedeclarableTemplate(D, Redecl); |
| |
| if (ThisDeclID == Redecl.getFirstID()) { |
| // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of |
| // the specializations. |
| SmallVector<GlobalDeclID, 32> SpecIDs; |
| readDeclIDList(SpecIDs); |
| ASTDeclReader::AddLazySpecializations(D, SpecIDs); |
| } |
| |
| if (D->getTemplatedDecl()->TemplateOrInstantiation) { |
| // We were loaded before our templated declaration was. We've not set up |
| // its corresponding type yet (see VisitCXXRecordDeclImpl), so reconstruct |
| // it now. |
| Reader.getContext().getInjectedClassNameType( |
| D->getTemplatedDecl(), D->getInjectedClassNameSpecialization()); |
| } |
| } |
| |
| void ASTDeclReader::VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D) { |
| llvm_unreachable("BuiltinTemplates are not serialized"); |
| } |
| |
| /// TODO: Unify with ClassTemplateDecl version? |
| /// May require unifying ClassTemplateDecl and |
| /// VarTemplateDecl beyond TemplateDecl... |
| void ASTDeclReader::VisitVarTemplateDecl(VarTemplateDecl *D) { |
| RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); |
| mergeRedeclarableTemplate(D, Redecl); |
| |
| if (ThisDeclID == Redecl.getFirstID()) { |
| // This VarTemplateDecl owns a CommonPtr; read it to keep track of all of |
| // the specializations. |
| SmallVector<GlobalDeclID, 32> SpecIDs; |
| readDeclIDList(SpecIDs); |
| ASTDeclReader::AddLazySpecializations(D, SpecIDs); |
| } |
| } |
| |
| RedeclarableResult ASTDeclReader::VisitClassTemplateSpecializationDeclImpl( |
| ClassTemplateSpecializationDecl *D) { |
| RedeclarableResult Redecl = VisitCXXRecordDeclImpl(D); |
| |
| ASTContext &C = Reader.getContext(); |
| if (Decl *InstD = readDecl()) { |
| if (auto *CTD = dyn_cast<ClassTemplateDecl>(InstD)) { |
| D->SpecializedTemplate = CTD; |
| } else { |
| SmallVector<TemplateArgument, 8> TemplArgs; |
| Record.readTemplateArgumentList(TemplArgs); |
| TemplateArgumentList *ArgList |
| = TemplateArgumentList::CreateCopy(C, TemplArgs); |
| auto *PS = |
| new (C) ClassTemplateSpecializationDecl:: |
| SpecializedPartialSpecialization(); |
| PS->PartialSpecialization |
| = cast<ClassTemplatePartialSpecializationDecl>(InstD); |
| PS->TemplateArgs = ArgList; |
| D->SpecializedTemplate = PS; |
| } |
| } |
| |
| SmallVector<TemplateArgument, 8> TemplArgs; |
| Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true); |
| D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs); |
| D->PointOfInstantiation = readSourceLocation(); |
| D->SpecializationKind = (TemplateSpecializationKind)Record.readInt(); |
| |
| bool writtenAsCanonicalDecl = Record.readInt(); |
| if (writtenAsCanonicalDecl) { |
| auto *CanonPattern = readDeclAs<ClassTemplateDecl>(); |
| if (D->isCanonicalDecl()) { // It's kept in the folding set. |
| // Set this as, or find, the canonical declaration for this specialization |
| ClassTemplateSpecializationDecl *CanonSpec; |
| if (auto *Partial = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) { |
| CanonSpec = CanonPattern->getCommonPtr()->PartialSpecializations |
| .GetOrInsertNode(Partial); |
| } else { |
| CanonSpec = |
| CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D); |
| } |
| // If there was already a canonical specialization, merge into it. |
| if (CanonSpec != D) { |
| MergeImpl.mergeRedeclarable<TagDecl>(D, CanonSpec, Redecl); |
| |
| // This declaration might be a definition. Merge with any existing |
| // definition. |
| if (auto *DDD = D->DefinitionData) { |
| if (CanonSpec->DefinitionData) |
| MergeImpl.MergeDefinitionData(CanonSpec, std::move(*DDD)); |
| else |
| CanonSpec->DefinitionData = D->DefinitionData; |
| } |
| D->DefinitionData = CanonSpec->DefinitionData; |
| } |
| } |
| } |
| |
| // extern/template keyword locations for explicit instantiations |
| if (Record.readBool()) { |
| auto *ExplicitInfo = new (C) ExplicitInstantiationInfo; |
| ExplicitInfo->ExternKeywordLoc = readSourceLocation(); |
| ExplicitInfo->TemplateKeywordLoc = readSourceLocation(); |
| D->ExplicitInfo = ExplicitInfo; |
| } |
| |
| if (Record.readBool()) |
| D->setTemplateArgsAsWritten(Record.readASTTemplateArgumentListInfo()); |
| |
| return Redecl; |
| } |
| |
| void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl( |
| ClassTemplatePartialSpecializationDecl *D) { |
| // We need to read the template params first because redeclarable is going to |
| // need them for profiling |
| TemplateParameterList *Params = Record.readTemplateParameterList(); |
| D->TemplateParams = Params; |
| |
| RedeclarableResult Redecl = VisitClassTemplateSpecializationDeclImpl(D); |
| |
| // These are read/set from/to the first declaration. |
| if (ThisDeclID == Redecl.getFirstID()) { |
| D->InstantiatedFromMember.setPointer( |
| readDeclAs<ClassTemplatePartialSpecializationDecl>()); |
| D->InstantiatedFromMember.setInt(Record.readInt()); |
| } |
| } |
| |
| void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
| RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); |
| |
| if (ThisDeclID == Redecl.getFirstID()) { |
| // This FunctionTemplateDecl owns a CommonPtr; read it. |
| SmallVector<GlobalDeclID, 32> SpecIDs; |
| readDeclIDList(SpecIDs); |
| ASTDeclReader::AddLazySpecializations(D, SpecIDs); |
| } |
| } |
| |
| /// TODO: Unify with ClassTemplateSpecializationDecl version? |
| /// May require unifying ClassTemplate(Partial)SpecializationDecl and |
| /// VarTemplate(Partial)SpecializationDecl with a new data |
| /// structure Template(Partial)SpecializationDecl, and |
| /// using Template(Partial)SpecializationDecl as input type. |
| RedeclarableResult ASTDeclReader::VisitVarTemplateSpecializationDeclImpl( |
| VarTemplateSpecializationDecl *D) { |
| ASTContext &C = Reader.getContext(); |
| if (Decl *InstD = readDecl()) { |
| if (auto *VTD = dyn_cast<VarTemplateDecl>(InstD)) { |
| D->SpecializedTemplate = VTD; |
| } else { |
| SmallVector<TemplateArgument, 8> TemplArgs; |
| Record.readTemplateArgumentList(TemplArgs); |
| TemplateArgumentList *ArgList = TemplateArgumentList::CreateCopy( |
| C, TemplArgs); |
| auto *PS = |
| new (C) |
| VarTemplateSpecializationDecl::SpecializedPartialSpecialization(); |
| PS->PartialSpecialization = |
| cast<VarTemplatePartialSpecializationDecl>(InstD); |
| PS->TemplateArgs = ArgList; |
| D->SpecializedTemplate = PS; |
| } |
| } |
| |
| // extern/template keyword locations for explicit instantiations |
| if (Record.readBool()) { |
| auto *ExplicitInfo = new (C) ExplicitInstantiationInfo; |
| ExplicitInfo->ExternKeywordLoc = readSourceLocation(); |
| ExplicitInfo->TemplateKeywordLoc = readSourceLocation(); |
| D->ExplicitInfo = ExplicitInfo; |
| } |
| |
| if (Record.readBool()) |
| D->setTemplateArgsAsWritten(Record.readASTTemplateArgumentListInfo()); |
| |
| SmallVector<TemplateArgument, 8> TemplArgs; |
| Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true); |
| D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs); |
| D->PointOfInstantiation = readSourceLocation(); |
| D->SpecializationKind = (TemplateSpecializationKind)Record.readInt(); |
| D->IsCompleteDefinition = Record.readInt(); |
| |
| RedeclarableResult Redecl = VisitVarDeclImpl(D); |
| |
| bool writtenAsCanonicalDecl = Record.readInt(); |
| if (writtenAsCanonicalDecl) { |
| auto *CanonPattern = readDeclAs<VarTemplateDecl>(); |
| if (D->isCanonicalDecl()) { // It's kept in the folding set. |
| VarTemplateSpecializationDecl *CanonSpec; |
| if (auto *Partial = dyn_cast<VarTemplatePartialSpecializationDecl>(D)) { |