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