File: | tools/clang/lib/Serialization/ASTReaderDecl.cpp |
Warning: | line 1827, column 31 Access to field 'PartialSpecialization' results in a dereference of a null pointer (loaded from variable 'PS') |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | //===--- ASTReaderDecl.cpp - Decl Deserialization ---------------*- C++ -*-===// | |||
2 | // | |||
3 | // The LLVM Compiler Infrastructure | |||
4 | // | |||
5 | // This file is distributed under the University of Illinois Open Source | |||
6 | // License. See LICENSE.TXT for details. | |||
7 | // | |||
8 | //===----------------------------------------------------------------------===// | |||
9 | // | |||
10 | // This file implements the ASTReader::ReadDeclRecord method, which is the | |||
11 | // entrypoint for loading a decl. | |||
12 | // | |||
13 | //===----------------------------------------------------------------------===// | |||
14 | ||||
15 | #include "ASTCommon.h" | |||
16 | #include "ASTReaderInternals.h" | |||
17 | #include "clang/AST/ASTContext.h" | |||
18 | #include "clang/AST/DeclCXX.h" | |||
19 | #include "clang/AST/DeclGroup.h" | |||
20 | #include "clang/AST/DeclTemplate.h" | |||
21 | #include "clang/AST/DeclVisitor.h" | |||
22 | #include "clang/AST/Expr.h" | |||
23 | #include "clang/Sema/IdentifierResolver.h" | |||
24 | #include "clang/Sema/SemaDiagnostic.h" | |||
25 | #include "clang/Serialization/ASTReader.h" | |||
26 | #include "llvm/Support/SaveAndRestore.h" | |||
27 | ||||
28 | using namespace clang; | |||
29 | using namespace clang::serialization; | |||
30 | ||||
31 | //===----------------------------------------------------------------------===// | |||
32 | // Declaration deserialization | |||
33 | //===----------------------------------------------------------------------===// | |||
34 | ||||
35 | namespace clang { | |||
36 | class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> { | |||
37 | ASTReader &Reader; | |||
38 | ASTRecordReader &Record; | |||
39 | ASTReader::RecordLocation Loc; | |||
40 | const DeclID ThisDeclID; | |||
41 | const SourceLocation ThisDeclLoc; | |||
42 | typedef ASTReader::RecordData RecordData; | |||
43 | TypeID TypeIDForTypeDecl; | |||
44 | unsigned AnonymousDeclNumber; | |||
45 | GlobalDeclID NamedDeclForTagDecl; | |||
46 | IdentifierInfo *TypedefNameForLinkage; | |||
47 | ||||
48 | bool HasPendingBody; | |||
49 | ||||
50 | ///\brief A flag to carry the information for a decl from the entity is | |||
51 | /// used. We use it to delay the marking of the canonical decl as used until | |||
52 | /// the entire declaration is deserialized and merged. | |||
53 | bool IsDeclMarkedUsed; | |||
54 | ||||
55 | uint64_t GetCurrentCursorOffset(); | |||
56 | ||||
57 | uint64_t ReadLocalOffset() { | |||
58 | uint64_t LocalOffset = Record.readInt(); | |||
59 | assert(LocalOffset < Loc.Offset && "offset point after current record")(static_cast <bool> (LocalOffset < Loc.Offset && "offset point after current record") ? void (0) : __assert_fail ("LocalOffset < Loc.Offset && \"offset point after current record\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 59, __extension__ __PRETTY_FUNCTION__)); | |||
60 | return LocalOffset ? Loc.Offset - LocalOffset : 0; | |||
61 | } | |||
62 | ||||
63 | uint64_t ReadGlobalOffset() { | |||
64 | uint64_t Local = ReadLocalOffset(); | |||
65 | return Local ? Record.getGlobalBitOffset(Local) : 0; | |||
66 | } | |||
67 | ||||
68 | SourceLocation ReadSourceLocation() { | |||
69 | return Record.readSourceLocation(); | |||
70 | } | |||
71 | ||||
72 | SourceRange ReadSourceRange() { | |||
73 | return Record.readSourceRange(); | |||
74 | } | |||
75 | ||||
76 | TypeSourceInfo *GetTypeSourceInfo() { | |||
77 | return Record.getTypeSourceInfo(); | |||
78 | } | |||
79 | ||||
80 | serialization::DeclID ReadDeclID() { | |||
81 | return Record.readDeclID(); | |||
82 | } | |||
83 | ||||
84 | std::string ReadString() { | |||
85 | return Record.readString(); | |||
86 | } | |||
87 | ||||
88 | void ReadDeclIDList(SmallVectorImpl<DeclID> &IDs) { | |||
89 | for (unsigned I = 0, Size = Record.readInt(); I != Size; ++I) | |||
90 | IDs.push_back(ReadDeclID()); | |||
91 | } | |||
92 | ||||
93 | Decl *ReadDecl() { | |||
94 | return Record.readDecl(); | |||
95 | } | |||
96 | ||||
97 | template<typename T> | |||
98 | T *ReadDeclAs() { | |||
99 | return Record.readDeclAs<T>(); | |||
100 | } | |||
101 | ||||
102 | void ReadQualifierInfo(QualifierInfo &Info) { | |||
103 | Record.readQualifierInfo(Info); | |||
104 | } | |||
105 | ||||
106 | void ReadDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name) { | |||
107 | Record.readDeclarationNameLoc(DNLoc, Name); | |||
108 | } | |||
109 | ||||
110 | serialization::SubmoduleID readSubmoduleID() { | |||
111 | if (Record.getIdx() == Record.size()) | |||
112 | return 0; | |||
113 | ||||
114 | return Record.getGlobalSubmoduleID(Record.readInt()); | |||
115 | } | |||
116 | ||||
117 | Module *readModule() { | |||
118 | return Record.getSubmodule(readSubmoduleID()); | |||
119 | } | |||
120 | ||||
121 | void ReadCXXRecordDefinition(CXXRecordDecl *D, bool Update); | |||
122 | void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data, | |||
123 | const CXXRecordDecl *D); | |||
124 | void MergeDefinitionData(CXXRecordDecl *D, | |||
125 | struct CXXRecordDecl::DefinitionData &&NewDD); | |||
126 | void ReadObjCDefinitionData(struct ObjCInterfaceDecl::DefinitionData &Data); | |||
127 | void MergeDefinitionData(ObjCInterfaceDecl *D, | |||
128 | struct ObjCInterfaceDecl::DefinitionData &&NewDD); | |||
129 | void ReadObjCDefinitionData(struct ObjCProtocolDecl::DefinitionData &Data); | |||
130 | void MergeDefinitionData(ObjCProtocolDecl *D, | |||
131 | struct ObjCProtocolDecl::DefinitionData &&NewDD); | |||
132 | ||||
133 | static NamedDecl *getAnonymousDeclForMerging(ASTReader &Reader, | |||
134 | DeclContext *DC, | |||
135 | unsigned Index); | |||
136 | static void setAnonymousDeclForMerging(ASTReader &Reader, DeclContext *DC, | |||
137 | unsigned Index, NamedDecl *D); | |||
138 | ||||
139 | /// Results from loading a RedeclarableDecl. | |||
140 | class RedeclarableResult { | |||
141 | Decl *MergeWith; | |||
142 | GlobalDeclID FirstID; | |||
143 | bool IsKeyDecl; | |||
144 | ||||
145 | public: | |||
146 | RedeclarableResult(Decl *MergeWith, GlobalDeclID FirstID, bool IsKeyDecl) | |||
147 | : MergeWith(MergeWith), FirstID(FirstID), IsKeyDecl(IsKeyDecl) {} | |||
148 | ||||
149 | /// \brief Retrieve the first ID. | |||
150 | GlobalDeclID getFirstID() const { return FirstID; } | |||
151 | ||||
152 | /// \brief Is this declaration a key declaration? | |||
153 | bool isKeyDecl() const { return IsKeyDecl; } | |||
154 | ||||
155 | /// \brief Get a known declaration that this should be merged with, if | |||
156 | /// any. | |||
157 | Decl *getKnownMergeTarget() const { return MergeWith; } | |||
158 | }; | |||
159 | ||||
160 | /// \brief Class used to capture the result of searching for an existing | |||
161 | /// declaration of a specific kind and name, along with the ability | |||
162 | /// to update the place where this result was found (the declaration | |||
163 | /// chain hanging off an identifier or the DeclContext we searched in) | |||
164 | /// if requested. | |||
165 | class FindExistingResult { | |||
166 | ASTReader &Reader; | |||
167 | NamedDecl *New; | |||
168 | NamedDecl *Existing; | |||
169 | bool AddResult; | |||
170 | ||||
171 | unsigned AnonymousDeclNumber; | |||
172 | IdentifierInfo *TypedefNameForLinkage; | |||
173 | ||||
174 | void operator=(FindExistingResult &&) = delete; | |||
175 | ||||
176 | public: | |||
177 | FindExistingResult(ASTReader &Reader) | |||
178 | : Reader(Reader), New(nullptr), Existing(nullptr), AddResult(false), | |||
179 | AnonymousDeclNumber(0), TypedefNameForLinkage(nullptr) {} | |||
180 | ||||
181 | FindExistingResult(ASTReader &Reader, NamedDecl *New, NamedDecl *Existing, | |||
182 | unsigned AnonymousDeclNumber, | |||
183 | IdentifierInfo *TypedefNameForLinkage) | |||
184 | : Reader(Reader), New(New), Existing(Existing), AddResult(true), | |||
185 | AnonymousDeclNumber(AnonymousDeclNumber), | |||
186 | TypedefNameForLinkage(TypedefNameForLinkage) {} | |||
187 | ||||
188 | FindExistingResult(FindExistingResult &&Other) | |||
189 | : Reader(Other.Reader), New(Other.New), Existing(Other.Existing), | |||
190 | AddResult(Other.AddResult), | |||
191 | AnonymousDeclNumber(Other.AnonymousDeclNumber), | |||
192 | TypedefNameForLinkage(Other.TypedefNameForLinkage) { | |||
193 | Other.AddResult = false; | |||
194 | } | |||
195 | ||||
196 | ~FindExistingResult(); | |||
197 | ||||
198 | /// \brief Suppress the addition of this result into the known set of | |||
199 | /// names. | |||
200 | void suppress() { AddResult = false; } | |||
201 | ||||
202 | operator NamedDecl*() const { return Existing; } | |||
203 | ||||
204 | template<typename T> | |||
205 | operator T*() const { return dyn_cast_or_null<T>(Existing); } | |||
206 | }; | |||
207 | ||||
208 | static DeclContext *getPrimaryContextForMerging(ASTReader &Reader, | |||
209 | DeclContext *DC); | |||
210 | FindExistingResult findExisting(NamedDecl *D); | |||
211 | ||||
212 | public: | |||
213 | ASTDeclReader(ASTReader &Reader, ASTRecordReader &Record, | |||
214 | ASTReader::RecordLocation Loc, | |||
215 | DeclID thisDeclID, SourceLocation ThisDeclLoc) | |||
216 | : Reader(Reader), Record(Record), Loc(Loc), | |||
217 | ThisDeclID(thisDeclID), ThisDeclLoc(ThisDeclLoc), | |||
218 | TypeIDForTypeDecl(0), NamedDeclForTagDecl(0), | |||
219 | TypedefNameForLinkage(nullptr), HasPendingBody(false), | |||
220 | IsDeclMarkedUsed(false) {} | |||
221 | ||||
222 | template <typename T> static | |||
223 | void AddLazySpecializations(T *D, | |||
224 | SmallVectorImpl<serialization::DeclID>& IDs) { | |||
225 | if (IDs.empty()) | |||
226 | return; | |||
227 | ||||
228 | // FIXME: We should avoid this pattern of getting the ASTContext. | |||
229 | ASTContext &C = D->getASTContext(); | |||
230 | ||||
231 | auto *&LazySpecializations = D->getCommonPtr()->LazySpecializations; | |||
232 | ||||
233 | if (auto &Old = LazySpecializations) { | |||
234 | IDs.insert(IDs.end(), Old + 1, Old + 1 + Old[0]); | |||
235 | std::sort(IDs.begin(), IDs.end()); | |||
236 | IDs.erase(std::unique(IDs.begin(), IDs.end()), IDs.end()); | |||
237 | } | |||
238 | ||||
239 | auto *Result = new (C) serialization::DeclID[1 + IDs.size()]; | |||
240 | *Result = IDs.size(); | |||
241 | std::copy(IDs.begin(), IDs.end(), Result + 1); | |||
242 | ||||
243 | LazySpecializations = Result; | |||
244 | } | |||
245 | ||||
246 | template <typename DeclT> | |||
247 | static Decl *getMostRecentDeclImpl(Redeclarable<DeclT> *D); | |||
248 | static Decl *getMostRecentDeclImpl(...); | |||
249 | static Decl *getMostRecentDecl(Decl *D); | |||
250 | ||||
251 | template <typename DeclT> | |||
252 | static void attachPreviousDeclImpl(ASTReader &Reader, | |||
253 | Redeclarable<DeclT> *D, Decl *Previous, | |||
254 | Decl *Canon); | |||
255 | static void attachPreviousDeclImpl(ASTReader &Reader, ...); | |||
256 | static void attachPreviousDecl(ASTReader &Reader, Decl *D, Decl *Previous, | |||
257 | Decl *Canon); | |||
258 | ||||
259 | template <typename DeclT> | |||
260 | static void attachLatestDeclImpl(Redeclarable<DeclT> *D, Decl *Latest); | |||
261 | static void attachLatestDeclImpl(...); | |||
262 | static void attachLatestDecl(Decl *D, Decl *latest); | |||
263 | ||||
264 | template <typename DeclT> | |||
265 | static void markIncompleteDeclChainImpl(Redeclarable<DeclT> *D); | |||
266 | static void markIncompleteDeclChainImpl(...); | |||
267 | ||||
268 | /// \brief Determine whether this declaration has a pending body. | |||
269 | bool hasPendingBody() const { return HasPendingBody; } | |||
270 | ||||
271 | void ReadFunctionDefinition(FunctionDecl *FD); | |||
272 | void Visit(Decl *D); | |||
273 | ||||
274 | void UpdateDecl(Decl *D, llvm::SmallVectorImpl<serialization::DeclID>&); | |||
275 | ||||
276 | static void setNextObjCCategory(ObjCCategoryDecl *Cat, | |||
277 | ObjCCategoryDecl *Next) { | |||
278 | Cat->NextClassCategory = Next; | |||
279 | } | |||
280 | ||||
281 | void VisitDecl(Decl *D); | |||
282 | void VisitPragmaCommentDecl(PragmaCommentDecl *D); | |||
283 | void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D); | |||
284 | void VisitTranslationUnitDecl(TranslationUnitDecl *TU); | |||
285 | void VisitNamedDecl(NamedDecl *ND); | |||
286 | void VisitLabelDecl(LabelDecl *LD); | |||
287 | void VisitNamespaceDecl(NamespaceDecl *D); | |||
288 | void VisitUsingDirectiveDecl(UsingDirectiveDecl *D); | |||
289 | void VisitNamespaceAliasDecl(NamespaceAliasDecl *D); | |||
290 | void VisitTypeDecl(TypeDecl *TD); | |||
291 | RedeclarableResult VisitTypedefNameDecl(TypedefNameDecl *TD); | |||
292 | void VisitTypedefDecl(TypedefDecl *TD); | |||
293 | void VisitTypeAliasDecl(TypeAliasDecl *TD); | |||
294 | void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); | |||
295 | RedeclarableResult VisitTagDecl(TagDecl *TD); | |||
296 | void VisitEnumDecl(EnumDecl *ED); | |||
297 | RedeclarableResult VisitRecordDeclImpl(RecordDecl *RD); | |||
298 | void VisitRecordDecl(RecordDecl *RD) { VisitRecordDeclImpl(RD); } | |||
299 | RedeclarableResult VisitCXXRecordDeclImpl(CXXRecordDecl *D); | |||
300 | void VisitCXXRecordDecl(CXXRecordDecl *D) { VisitCXXRecordDeclImpl(D); } | |||
301 | RedeclarableResult VisitClassTemplateSpecializationDeclImpl( | |||
302 | ClassTemplateSpecializationDecl *D); | |||
303 | void VisitClassTemplateSpecializationDecl( | |||
304 | ClassTemplateSpecializationDecl *D) { | |||
305 | VisitClassTemplateSpecializationDeclImpl(D); | |||
306 | } | |||
307 | void VisitClassTemplatePartialSpecializationDecl( | |||
308 | ClassTemplatePartialSpecializationDecl *D); | |||
309 | void VisitClassScopeFunctionSpecializationDecl( | |||
310 | ClassScopeFunctionSpecializationDecl *D); | |||
311 | RedeclarableResult | |||
312 | VisitVarTemplateSpecializationDeclImpl(VarTemplateSpecializationDecl *D); | |||
313 | void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D) { | |||
314 | VisitVarTemplateSpecializationDeclImpl(D); | |||
315 | } | |||
316 | void VisitVarTemplatePartialSpecializationDecl( | |||
317 | VarTemplatePartialSpecializationDecl *D); | |||
318 | void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); | |||
319 | void VisitValueDecl(ValueDecl *VD); | |||
320 | void VisitEnumConstantDecl(EnumConstantDecl *ECD); | |||
321 | void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); | |||
322 | void VisitDeclaratorDecl(DeclaratorDecl *DD); | |||
323 | void VisitFunctionDecl(FunctionDecl *FD); | |||
324 | void VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *GD); | |||
325 | void VisitCXXMethodDecl(CXXMethodDecl *D); | |||
326 | void VisitCXXConstructorDecl(CXXConstructorDecl *D); | |||
327 | void VisitCXXDestructorDecl(CXXDestructorDecl *D); | |||
328 | void VisitCXXConversionDecl(CXXConversionDecl *D); | |||
329 | void VisitFieldDecl(FieldDecl *FD); | |||
330 | void VisitMSPropertyDecl(MSPropertyDecl *FD); | |||
331 | void VisitIndirectFieldDecl(IndirectFieldDecl *FD); | |||
332 | RedeclarableResult VisitVarDeclImpl(VarDecl *D); | |||
333 | void VisitVarDecl(VarDecl *VD) { VisitVarDeclImpl(VD); } | |||
334 | void VisitImplicitParamDecl(ImplicitParamDecl *PD); | |||
335 | void VisitParmVarDecl(ParmVarDecl *PD); | |||
336 | void VisitDecompositionDecl(DecompositionDecl *DD); | |||
337 | void VisitBindingDecl(BindingDecl *BD); | |||
338 | void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); | |||
339 | DeclID VisitTemplateDecl(TemplateDecl *D); | |||
340 | RedeclarableResult VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D); | |||
341 | void VisitClassTemplateDecl(ClassTemplateDecl *D); | |||
342 | void VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D); | |||
343 | void VisitVarTemplateDecl(VarTemplateDecl *D); | |||
344 | void VisitFunctionTemplateDecl(FunctionTemplateDecl *D); | |||
345 | void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); | |||
346 | void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); | |||
347 | void VisitUsingDecl(UsingDecl *D); | |||
348 | void VisitUsingPackDecl(UsingPackDecl *D); | |||
349 | void VisitUsingShadowDecl(UsingShadowDecl *D); | |||
350 | void VisitConstructorUsingShadowDecl(ConstructorUsingShadowDecl *D); | |||
351 | void VisitLinkageSpecDecl(LinkageSpecDecl *D); | |||
352 | void VisitExportDecl(ExportDecl *D); | |||
353 | void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD); | |||
354 | void VisitImportDecl(ImportDecl *D); | |||
355 | void VisitAccessSpecDecl(AccessSpecDecl *D); | |||
356 | void VisitFriendDecl(FriendDecl *D); | |||
357 | void VisitFriendTemplateDecl(FriendTemplateDecl *D); | |||
358 | void VisitStaticAssertDecl(StaticAssertDecl *D); | |||
359 | void VisitBlockDecl(BlockDecl *BD); | |||
360 | void VisitCapturedDecl(CapturedDecl *CD); | |||
361 | void VisitEmptyDecl(EmptyDecl *D); | |||
362 | ||||
363 | std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC); | |||
364 | ||||
365 | template<typename T> | |||
366 | RedeclarableResult VisitRedeclarable(Redeclarable<T> *D); | |||
367 | ||||
368 | template<typename T> | |||
369 | void mergeRedeclarable(Redeclarable<T> *D, RedeclarableResult &Redecl, | |||
370 | DeclID TemplatePatternID = 0); | |||
371 | ||||
372 | template<typename T> | |||
373 | void mergeRedeclarable(Redeclarable<T> *D, T *Existing, | |||
374 | RedeclarableResult &Redecl, | |||
375 | DeclID TemplatePatternID = 0); | |||
376 | ||||
377 | template<typename T> | |||
378 | void mergeMergeable(Mergeable<T> *D); | |||
379 | ||||
380 | void mergeTemplatePattern(RedeclarableTemplateDecl *D, | |||
381 | RedeclarableTemplateDecl *Existing, | |||
382 | DeclID DsID, bool IsKeyDecl); | |||
383 | ||||
384 | ObjCTypeParamList *ReadObjCTypeParamList(); | |||
385 | ||||
386 | // FIXME: Reorder according to DeclNodes.td? | |||
387 | void VisitObjCMethodDecl(ObjCMethodDecl *D); | |||
388 | void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); | |||
389 | void VisitObjCContainerDecl(ObjCContainerDecl *D); | |||
390 | void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); | |||
391 | void VisitObjCIvarDecl(ObjCIvarDecl *D); | |||
392 | void VisitObjCProtocolDecl(ObjCProtocolDecl *D); | |||
393 | void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D); | |||
394 | void VisitObjCCategoryDecl(ObjCCategoryDecl *D); | |||
395 | void VisitObjCImplDecl(ObjCImplDecl *D); | |||
396 | void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); | |||
397 | void VisitObjCImplementationDecl(ObjCImplementationDecl *D); | |||
398 | void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D); | |||
399 | void VisitObjCPropertyDecl(ObjCPropertyDecl *D); | |||
400 | void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); | |||
401 | void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D); | |||
402 | void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D); | |||
403 | void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D); | |||
404 | }; | |||
405 | } // end namespace clang | |||
406 | ||||
407 | namespace { | |||
408 | /// Iterator over the redeclarations of a declaration that have already | |||
409 | /// been merged into the same redeclaration chain. | |||
410 | template<typename DeclT> | |||
411 | class MergedRedeclIterator { | |||
412 | DeclT *Start, *Canonical, *Current; | |||
413 | public: | |||
414 | MergedRedeclIterator() : Current(nullptr) {} | |||
415 | MergedRedeclIterator(DeclT *Start) | |||
416 | : Start(Start), Canonical(nullptr), Current(Start) {} | |||
417 | ||||
418 | DeclT *operator*() { return Current; } | |||
419 | ||||
420 | MergedRedeclIterator &operator++() { | |||
421 | if (Current->isFirstDecl()) { | |||
422 | Canonical = Current; | |||
423 | Current = Current->getMostRecentDecl(); | |||
424 | } else | |||
425 | Current = Current->getPreviousDecl(); | |||
426 | ||||
427 | // If we started in the merged portion, we'll reach our start position | |||
428 | // eventually. Otherwise, we'll never reach it, but the second declaration | |||
429 | // we reached was the canonical declaration, so stop when we see that one | |||
430 | // again. | |||
431 | if (Current == Start || Current == Canonical) | |||
432 | Current = nullptr; | |||
433 | return *this; | |||
434 | } | |||
435 | ||||
436 | friend bool operator!=(const MergedRedeclIterator &A, | |||
437 | const MergedRedeclIterator &B) { | |||
438 | return A.Current != B.Current; | |||
439 | } | |||
440 | }; | |||
441 | } // end anonymous namespace | |||
442 | ||||
443 | template <typename DeclT> | |||
444 | static llvm::iterator_range<MergedRedeclIterator<DeclT>> | |||
445 | merged_redecls(DeclT *D) { | |||
446 | return llvm::make_range(MergedRedeclIterator<DeclT>(D), | |||
447 | MergedRedeclIterator<DeclT>()); | |||
448 | } | |||
449 | ||||
450 | uint64_t ASTDeclReader::GetCurrentCursorOffset() { | |||
451 | return Loc.F->DeclsCursor.GetCurrentBitNo() + Loc.F->GlobalBitOffset; | |||
452 | } | |||
453 | ||||
454 | void ASTDeclReader::ReadFunctionDefinition(FunctionDecl *FD) { | |||
455 | if (Record.readInt()) | |||
456 | Reader.DefinitionSource[FD] = Loc.F->Kind == ModuleKind::MK_MainFile; | |||
457 | if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) { | |||
458 | CD->NumCtorInitializers = Record.readInt(); | |||
459 | if (CD->NumCtorInitializers) | |||
460 | CD->CtorInitializers = ReadGlobalOffset(); | |||
461 | } | |||
462 | // Store the offset of the body so we can lazily load it later. | |||
463 | Reader.PendingBodies[FD] = GetCurrentCursorOffset(); | |||
464 | HasPendingBody = true; | |||
465 | } | |||
466 | ||||
467 | void ASTDeclReader::Visit(Decl *D) { | |||
468 | DeclVisitor<ASTDeclReader, void>::Visit(D); | |||
469 | ||||
470 | // At this point we have deserialized and merged the decl and it is safe to | |||
471 | // update its canonical decl to signal that the entire entity is used. | |||
472 | D->getCanonicalDecl()->Used |= IsDeclMarkedUsed; | |||
473 | IsDeclMarkedUsed = false; | |||
474 | ||||
475 | if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) { | |||
476 | if (DD->DeclInfo) { | |||
477 | DeclaratorDecl::ExtInfo *Info = | |||
478 | DD->DeclInfo.get<DeclaratorDecl::ExtInfo *>(); | |||
479 | Info->TInfo = GetTypeSourceInfo(); | |||
480 | } | |||
481 | else { | |||
482 | DD->DeclInfo = GetTypeSourceInfo(); | |||
483 | } | |||
484 | } | |||
485 | ||||
486 | if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) { | |||
487 | // We have a fully initialized TypeDecl. Read its type now. | |||
488 | TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull()); | |||
489 | ||||
490 | // If this is a tag declaration with a typedef name for linkage, it's safe | |||
491 | // to load that typedef now. | |||
492 | if (NamedDeclForTagDecl) | |||
493 | cast<TagDecl>(D)->TypedefNameDeclOrQualifier = | |||
494 | cast<TypedefNameDecl>(Reader.GetDecl(NamedDeclForTagDecl)); | |||
495 | } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) { | |||
496 | // if we have a fully initialized TypeDecl, we can safely read its type now. | |||
497 | ID->TypeForDecl = Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull(); | |||
498 | } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { | |||
499 | // FunctionDecl's body was written last after all other Stmts/Exprs. | |||
500 | // We only read it if FD doesn't already have a body (e.g., from another | |||
501 | // module). | |||
502 | // FIXME: Can we diagnose ODR violations somehow? | |||
503 | if (Record.readInt()) | |||
504 | ReadFunctionDefinition(FD); | |||
505 | } | |||
506 | } | |||
507 | ||||
508 | void ASTDeclReader::VisitDecl(Decl *D) { | |||
509 | if (D->isTemplateParameter() || D->isTemplateParameterPack() || | |||
510 | isa<ParmVarDecl>(D)) { | |||
511 | // We don't want to deserialize the DeclContext of a template | |||
512 | // parameter or of a parameter of a function template immediately. These | |||
513 | // entities might be used in the formulation of its DeclContext (for | |||
514 | // example, a function parameter can be used in decltype() in trailing | |||
515 | // return type of the function). Use the translation unit DeclContext as a | |||
516 | // placeholder. | |||
517 | GlobalDeclID SemaDCIDForTemplateParmDecl = ReadDeclID(); | |||
518 | GlobalDeclID LexicalDCIDForTemplateParmDecl = ReadDeclID(); | |||
519 | if (!LexicalDCIDForTemplateParmDecl) | |||
520 | LexicalDCIDForTemplateParmDecl = SemaDCIDForTemplateParmDecl; | |||
521 | Reader.addPendingDeclContextInfo(D, | |||
522 | SemaDCIDForTemplateParmDecl, | |||
523 | LexicalDCIDForTemplateParmDecl); | |||
524 | D->setDeclContext(Reader.getContext().getTranslationUnitDecl()); | |||
525 | } else { | |||
526 | DeclContext *SemaDC = ReadDeclAs<DeclContext>(); | |||
527 | DeclContext *LexicalDC = ReadDeclAs<DeclContext>(); | |||
528 | if (!LexicalDC) | |||
529 | LexicalDC = SemaDC; | |||
530 | DeclContext *MergedSemaDC = Reader.MergedDeclContexts.lookup(SemaDC); | |||
531 | // Avoid calling setLexicalDeclContext() directly because it uses | |||
532 | // Decl::getASTContext() internally which is unsafe during derialization. | |||
533 | D->setDeclContextsImpl(MergedSemaDC ? MergedSemaDC : SemaDC, LexicalDC, | |||
534 | Reader.getContext()); | |||
535 | } | |||
536 | D->setLocation(ThisDeclLoc); | |||
537 | D->setInvalidDecl(Record.readInt()); | |||
538 | if (Record.readInt()) { // hasAttrs | |||
539 | AttrVec Attrs; | |||
540 | Record.readAttributes(Attrs); | |||
541 | // Avoid calling setAttrs() directly because it uses Decl::getASTContext() | |||
542 | // internally which is unsafe during derialization. | |||
543 | D->setAttrsImpl(Attrs, Reader.getContext()); | |||
544 | } | |||
545 | D->setImplicit(Record.readInt()); | |||
546 | D->Used = Record.readInt(); | |||
547 | IsDeclMarkedUsed |= D->Used; | |||
548 | D->setReferenced(Record.readInt()); | |||
549 | D->setTopLevelDeclInObjCContainer(Record.readInt()); | |||
550 | D->setAccess((AccessSpecifier)Record.readInt()); | |||
551 | D->FromASTFile = true; | |||
552 | bool ModulePrivate = Record.readInt(); | |||
553 | ||||
554 | // Determine whether this declaration is part of a (sub)module. If so, it | |||
555 | // may not yet be visible. | |||
556 | if (unsigned SubmoduleID = readSubmoduleID()) { | |||
557 | // Store the owning submodule ID in the declaration. | |||
558 | D->setModuleOwnershipKind( | |||
559 | ModulePrivate ? Decl::ModuleOwnershipKind::ModulePrivate | |||
560 | : Decl::ModuleOwnershipKind::VisibleWhenImported); | |||
561 | D->setOwningModuleID(SubmoduleID); | |||
562 | ||||
563 | if (ModulePrivate) { | |||
564 | // Module-private declarations are never visible, so there is no work to | |||
565 | // do. | |||
566 | } else if (Reader.getContext().getLangOpts().ModulesLocalVisibility) { | |||
567 | // If local visibility is being tracked, this declaration will become | |||
568 | // hidden and visible as the owning module does. | |||
569 | } else if (Module *Owner = Reader.getSubmodule(SubmoduleID)) { | |||
570 | // Mark the declaration as visible when its owning module becomes visible. | |||
571 | if (Owner->NameVisibility == Module::AllVisible) | |||
572 | D->setVisibleDespiteOwningModule(); | |||
573 | else | |||
574 | Reader.HiddenNamesMap[Owner].push_back(D); | |||
575 | } | |||
576 | } else if (ModulePrivate) { | |||
577 | D->setModuleOwnershipKind(Decl::ModuleOwnershipKind::ModulePrivate); | |||
578 | } | |||
579 | } | |||
580 | ||||
581 | void ASTDeclReader::VisitPragmaCommentDecl(PragmaCommentDecl *D) { | |||
582 | VisitDecl(D); | |||
583 | D->setLocation(ReadSourceLocation()); | |||
584 | D->CommentKind = (PragmaMSCommentKind)Record.readInt(); | |||
585 | std::string Arg = ReadString(); | |||
586 | memcpy(D->getTrailingObjects<char>(), Arg.data(), Arg.size()); | |||
587 | D->getTrailingObjects<char>()[Arg.size()] = '\0'; | |||
588 | } | |||
589 | ||||
590 | void ASTDeclReader::VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D) { | |||
591 | VisitDecl(D); | |||
592 | D->setLocation(ReadSourceLocation()); | |||
593 | std::string Name = ReadString(); | |||
594 | memcpy(D->getTrailingObjects<char>(), Name.data(), Name.size()); | |||
595 | D->getTrailingObjects<char>()[Name.size()] = '\0'; | |||
596 | ||||
597 | D->ValueStart = Name.size() + 1; | |||
598 | std::string Value = ReadString(); | |||
599 | memcpy(D->getTrailingObjects<char>() + D->ValueStart, Value.data(), | |||
600 | Value.size()); | |||
601 | D->getTrailingObjects<char>()[D->ValueStart + Value.size()] = '\0'; | |||
602 | } | |||
603 | ||||
604 | void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) { | |||
605 | llvm_unreachable("Translation units are not serialized")::llvm::llvm_unreachable_internal("Translation units are not serialized" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 605); | |||
606 | } | |||
607 | ||||
608 | void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) { | |||
609 | VisitDecl(ND); | |||
610 | ND->setDeclName(Record.readDeclarationName()); | |||
611 | AnonymousDeclNumber = Record.readInt(); | |||
612 | } | |||
613 | ||||
614 | void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) { | |||
615 | VisitNamedDecl(TD); | |||
616 | TD->setLocStart(ReadSourceLocation()); | |||
617 | // Delay type reading until after we have fully initialized the decl. | |||
618 | TypeIDForTypeDecl = Record.getGlobalTypeID(Record.readInt()); | |||
619 | } | |||
620 | ||||
621 | ASTDeclReader::RedeclarableResult | |||
622 | ASTDeclReader::VisitTypedefNameDecl(TypedefNameDecl *TD) { | |||
623 | RedeclarableResult Redecl = VisitRedeclarable(TD); | |||
624 | VisitTypeDecl(TD); | |||
625 | TypeSourceInfo *TInfo = GetTypeSourceInfo(); | |||
626 | if (Record.readInt()) { // isModed | |||
627 | QualType modedT = Record.readType(); | |||
628 | TD->setModedTypeSourceInfo(TInfo, modedT); | |||
629 | } else | |||
630 | TD->setTypeSourceInfo(TInfo); | |||
631 | // Read and discard the declaration for which this is a typedef name for | |||
632 | // linkage, if it exists. We cannot rely on our type to pull in this decl, | |||
633 | // because it might have been merged with a type from another module and | |||
634 | // thus might not refer to our version of the declaration. | |||
635 | ReadDecl(); | |||
636 | return Redecl; | |||
637 | } | |||
638 | ||||
639 | void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) { | |||
640 | RedeclarableResult Redecl = VisitTypedefNameDecl(TD); | |||
641 | mergeRedeclarable(TD, Redecl); | |||
642 | } | |||
643 | ||||
644 | void ASTDeclReader::VisitTypeAliasDecl(TypeAliasDecl *TD) { | |||
645 | RedeclarableResult Redecl = VisitTypedefNameDecl(TD); | |||
646 | if (auto *Template = ReadDeclAs<TypeAliasTemplateDecl>()) | |||
647 | // Merged when we merge the template. | |||
648 | TD->setDescribedAliasTemplate(Template); | |||
649 | else | |||
650 | mergeRedeclarable(TD, Redecl); | |||
651 | } | |||
652 | ||||
653 | ASTDeclReader::RedeclarableResult ASTDeclReader::VisitTagDecl(TagDecl *TD) { | |||
654 | RedeclarableResult Redecl = VisitRedeclarable(TD); | |||
655 | VisitTypeDecl(TD); | |||
656 | ||||
657 | TD->IdentifierNamespace = Record.readInt(); | |||
658 | TD->setTagKind((TagDecl::TagKind)Record.readInt()); | |||
659 | if (!isa<CXXRecordDecl>(TD)) | |||
660 | TD->setCompleteDefinition(Record.readInt()); | |||
661 | TD->setEmbeddedInDeclarator(Record.readInt()); | |||
662 | TD->setFreeStanding(Record.readInt()); | |||
663 | TD->setCompleteDefinitionRequired(Record.readInt()); | |||
664 | TD->setBraceRange(ReadSourceRange()); | |||
665 | ||||
666 | switch (Record.readInt()) { | |||
667 | case 0: | |||
668 | break; | |||
669 | case 1: { // ExtInfo | |||
670 | TagDecl::ExtInfo *Info = new (Reader.getContext()) TagDecl::ExtInfo(); | |||
671 | ReadQualifierInfo(*Info); | |||
672 | TD->TypedefNameDeclOrQualifier = Info; | |||
673 | break; | |||
674 | } | |||
675 | case 2: // TypedefNameForAnonDecl | |||
676 | NamedDeclForTagDecl = ReadDeclID(); | |||
677 | TypedefNameForLinkage = Record.getIdentifierInfo(); | |||
678 | break; | |||
679 | default: | |||
680 | llvm_unreachable("unexpected tag info kind")::llvm::llvm_unreachable_internal("unexpected tag info kind", "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 680); | |||
681 | } | |||
682 | ||||
683 | if (!isa<CXXRecordDecl>(TD)) | |||
684 | mergeRedeclarable(TD, Redecl); | |||
685 | return Redecl; | |||
686 | } | |||
687 | ||||
688 | void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) { | |||
689 | VisitTagDecl(ED); | |||
690 | if (TypeSourceInfo *TI = GetTypeSourceInfo()) | |||
691 | ED->setIntegerTypeSourceInfo(TI); | |||
692 | else | |||
693 | ED->setIntegerType(Record.readType()); | |||
694 | ED->setPromotionType(Record.readType()); | |||
695 | ED->setNumPositiveBits(Record.readInt()); | |||
696 | ED->setNumNegativeBits(Record.readInt()); | |||
697 | ED->IsScoped = Record.readInt(); | |||
698 | ED->IsScopedUsingClassTag = Record.readInt(); | |||
699 | ED->IsFixed = Record.readInt(); | |||
700 | ||||
701 | // If this is a definition subject to the ODR, and we already have a | |||
702 | // definition, merge this one into it. | |||
703 | if (ED->IsCompleteDefinition && | |||
704 | Reader.getContext().getLangOpts().Modules && | |||
705 | Reader.getContext().getLangOpts().CPlusPlus) { | |||
706 | EnumDecl *&OldDef = Reader.EnumDefinitions[ED->getCanonicalDecl()]; | |||
707 | if (!OldDef) { | |||
708 | // This is the first time we've seen an imported definition. Look for a | |||
709 | // local definition before deciding that we are the first definition. | |||
710 | for (auto *D : merged_redecls(ED->getCanonicalDecl())) { | |||
711 | if (!D->isFromASTFile() && D->isCompleteDefinition()) { | |||
712 | OldDef = D; | |||
713 | break; | |||
714 | } | |||
715 | } | |||
716 | } | |||
717 | if (OldDef) { | |||
718 | Reader.MergedDeclContexts.insert(std::make_pair(ED, OldDef)); | |||
719 | ED->IsCompleteDefinition = false; | |||
720 | Reader.mergeDefinitionVisibility(OldDef, ED); | |||
721 | } else { | |||
722 | OldDef = ED; | |||
723 | } | |||
724 | } | |||
725 | ||||
726 | if (EnumDecl *InstED = ReadDeclAs<EnumDecl>()) { | |||
727 | TemplateSpecializationKind TSK = | |||
728 | (TemplateSpecializationKind)Record.readInt(); | |||
729 | SourceLocation POI = ReadSourceLocation(); | |||
730 | ED->setInstantiationOfMemberEnum(Reader.getContext(), InstED, TSK); | |||
731 | ED->getMemberSpecializationInfo()->setPointOfInstantiation(POI); | |||
732 | } | |||
733 | } | |||
734 | ||||
735 | ASTDeclReader::RedeclarableResult | |||
736 | ASTDeclReader::VisitRecordDeclImpl(RecordDecl *RD) { | |||
737 | RedeclarableResult Redecl = VisitTagDecl(RD); | |||
738 | RD->setHasFlexibleArrayMember(Record.readInt()); | |||
739 | RD->setAnonymousStructOrUnion(Record.readInt()); | |||
740 | RD->setHasObjectMember(Record.readInt()); | |||
741 | RD->setHasVolatileMember(Record.readInt()); | |||
742 | return Redecl; | |||
743 | } | |||
744 | ||||
745 | void ASTDeclReader::VisitValueDecl(ValueDecl *VD) { | |||
746 | VisitNamedDecl(VD); | |||
747 | VD->setType(Record.readType()); | |||
748 | } | |||
749 | ||||
750 | void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) { | |||
751 | VisitValueDecl(ECD); | |||
752 | if (Record.readInt()) | |||
753 | ECD->setInitExpr(Record.readExpr()); | |||
754 | ECD->setInitVal(Record.readAPSInt()); | |||
755 | mergeMergeable(ECD); | |||
756 | } | |||
757 | ||||
758 | void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) { | |||
759 | VisitValueDecl(DD); | |||
760 | DD->setInnerLocStart(ReadSourceLocation()); | |||
761 | if (Record.readInt()) { // hasExtInfo | |||
762 | DeclaratorDecl::ExtInfo *Info | |||
763 | = new (Reader.getContext()) DeclaratorDecl::ExtInfo(); | |||
764 | ReadQualifierInfo(*Info); | |||
765 | DD->DeclInfo = Info; | |||
766 | } | |||
767 | } | |||
768 | ||||
769 | void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) { | |||
770 | RedeclarableResult Redecl = VisitRedeclarable(FD); | |||
771 | VisitDeclaratorDecl(FD); | |||
772 | ||||
773 | ReadDeclarationNameLoc(FD->DNLoc, FD->getDeclName()); | |||
774 | FD->IdentifierNamespace = Record.readInt(); | |||
775 | ||||
776 | // FunctionDecl's body is handled last at ASTDeclReader::Visit, | |||
777 | // after everything else is read. | |||
778 | ||||
779 | FD->SClass = (StorageClass)Record.readInt(); | |||
780 | FD->IsInline = Record.readInt(); | |||
781 | FD->IsInlineSpecified = Record.readInt(); | |||
782 | FD->IsExplicitSpecified = Record.readInt(); | |||
783 | FD->IsVirtualAsWritten = Record.readInt(); | |||
784 | FD->IsPure = Record.readInt(); | |||
785 | FD->HasInheritedPrototype = Record.readInt(); | |||
786 | FD->HasWrittenPrototype = Record.readInt(); | |||
787 | FD->IsDeleted = Record.readInt(); | |||
788 | FD->IsTrivial = Record.readInt(); | |||
789 | FD->IsTrivialForCall = Record.readInt(); | |||
790 | FD->IsDefaulted = Record.readInt(); | |||
791 | FD->IsExplicitlyDefaulted = Record.readInt(); | |||
792 | FD->HasImplicitReturnZero = Record.readInt(); | |||
793 | FD->IsConstexpr = Record.readInt(); | |||
794 | FD->UsesSEHTry = Record.readInt(); | |||
795 | FD->HasSkippedBody = Record.readInt(); | |||
796 | FD->IsMultiVersion = Record.readInt(); | |||
797 | FD->IsLateTemplateParsed = Record.readInt(); | |||
798 | FD->setCachedLinkage(Linkage(Record.readInt())); | |||
799 | FD->EndRangeLoc = ReadSourceLocation(); | |||
800 | ||||
801 | FD->ODRHash = Record.readInt(); | |||
802 | FD->HasODRHash = true; | |||
803 | ||||
804 | switch ((FunctionDecl::TemplatedKind)Record.readInt()) { | |||
805 | case FunctionDecl::TK_NonTemplate: | |||
806 | mergeRedeclarable(FD, Redecl); | |||
807 | break; | |||
808 | case FunctionDecl::TK_FunctionTemplate: | |||
809 | // Merged when we merge the template. | |||
810 | FD->setDescribedFunctionTemplate(ReadDeclAs<FunctionTemplateDecl>()); | |||
811 | break; | |||
812 | case FunctionDecl::TK_MemberSpecialization: { | |||
813 | FunctionDecl *InstFD = ReadDeclAs<FunctionDecl>(); | |||
814 | TemplateSpecializationKind TSK = | |||
815 | (TemplateSpecializationKind)Record.readInt(); | |||
816 | SourceLocation POI = ReadSourceLocation(); | |||
817 | FD->setInstantiationOfMemberFunction(Reader.getContext(), InstFD, TSK); | |||
818 | FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI); | |||
819 | mergeRedeclarable(FD, Redecl); | |||
820 | break; | |||
821 | } | |||
822 | case FunctionDecl::TK_FunctionTemplateSpecialization: { | |||
823 | FunctionTemplateDecl *Template = ReadDeclAs<FunctionTemplateDecl>(); | |||
824 | TemplateSpecializationKind TSK = | |||
825 | (TemplateSpecializationKind)Record.readInt(); | |||
826 | ||||
827 | // Template arguments. | |||
828 | SmallVector<TemplateArgument, 8> TemplArgs; | |||
829 | Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true); | |||
830 | ||||
831 | // Template args as written. | |||
832 | SmallVector<TemplateArgumentLoc, 8> TemplArgLocs; | |||
833 | SourceLocation LAngleLoc, RAngleLoc; | |||
834 | bool HasTemplateArgumentsAsWritten = Record.readInt(); | |||
835 | if (HasTemplateArgumentsAsWritten) { | |||
836 | unsigned NumTemplateArgLocs = Record.readInt(); | |||
837 | TemplArgLocs.reserve(NumTemplateArgLocs); | |||
838 | for (unsigned i=0; i != NumTemplateArgLocs; ++i) | |||
839 | TemplArgLocs.push_back(Record.readTemplateArgumentLoc()); | |||
840 | ||||
841 | LAngleLoc = ReadSourceLocation(); | |||
842 | RAngleLoc = ReadSourceLocation(); | |||
843 | } | |||
844 | ||||
845 | SourceLocation POI = ReadSourceLocation(); | |||
846 | ||||
847 | ASTContext &C = Reader.getContext(); | |||
848 | TemplateArgumentList *TemplArgList | |||
849 | = TemplateArgumentList::CreateCopy(C, TemplArgs); | |||
850 | TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc); | |||
851 | for (unsigned i=0, e = TemplArgLocs.size(); i != e; ++i) | |||
852 | TemplArgsInfo.addArgument(TemplArgLocs[i]); | |||
853 | FunctionTemplateSpecializationInfo *FTInfo | |||
854 | = FunctionTemplateSpecializationInfo::Create(C, FD, Template, TSK, | |||
855 | TemplArgList, | |||
856 | HasTemplateArgumentsAsWritten ? &TemplArgsInfo | |||
857 | : nullptr, | |||
858 | POI); | |||
859 | FD->TemplateOrSpecialization = FTInfo; | |||
860 | ||||
861 | if (FD->isCanonicalDecl()) { // if canonical add to template's set. | |||
862 | // The template that contains the specializations set. It's not safe to | |||
863 | // use getCanonicalDecl on Template since it may still be initializing. | |||
864 | FunctionTemplateDecl *CanonTemplate = ReadDeclAs<FunctionTemplateDecl>(); | |||
865 | // Get the InsertPos by FindNodeOrInsertPos() instead of calling | |||
866 | // InsertNode(FTInfo) directly to avoid the getASTContext() call in | |||
867 | // FunctionTemplateSpecializationInfo's Profile(). | |||
868 | // We avoid getASTContext because a decl in the parent hierarchy may | |||
869 | // be initializing. | |||
870 | llvm::FoldingSetNodeID ID; | |||
871 | FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs, C); | |||
872 | void *InsertPos = nullptr; | |||
873 | FunctionTemplateDecl::Common *CommonPtr = CanonTemplate->getCommonPtr(); | |||
874 | FunctionTemplateSpecializationInfo *ExistingInfo = | |||
875 | CommonPtr->Specializations.FindNodeOrInsertPos(ID, InsertPos); | |||
876 | if (InsertPos) | |||
877 | CommonPtr->Specializations.InsertNode(FTInfo, InsertPos); | |||
878 | else { | |||
879 | assert(Reader.getContext().getLangOpts().Modules &&(static_cast <bool> (Reader.getContext().getLangOpts(). Modules && "already deserialized this template specialization" ) ? void (0) : __assert_fail ("Reader.getContext().getLangOpts().Modules && \"already deserialized this template specialization\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 880, __extension__ __PRETTY_FUNCTION__)) | |||
880 | "already deserialized this template specialization")(static_cast <bool> (Reader.getContext().getLangOpts(). Modules && "already deserialized this template specialization" ) ? void (0) : __assert_fail ("Reader.getContext().getLangOpts().Modules && \"already deserialized this template specialization\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 880, __extension__ __PRETTY_FUNCTION__)); | |||
881 | mergeRedeclarable(FD, ExistingInfo->Function, Redecl); | |||
882 | } | |||
883 | } | |||
884 | break; | |||
885 | } | |||
886 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { | |||
887 | // Templates. | |||
888 | UnresolvedSet<8> TemplDecls; | |||
889 | unsigned NumTemplates = Record.readInt(); | |||
890 | while (NumTemplates--) | |||
891 | TemplDecls.addDecl(ReadDeclAs<NamedDecl>()); | |||
892 | ||||
893 | // Templates args. | |||
894 | TemplateArgumentListInfo TemplArgs; | |||
895 | unsigned NumArgs = Record.readInt(); | |||
896 | while (NumArgs--) | |||
897 | TemplArgs.addArgument(Record.readTemplateArgumentLoc()); | |||
898 | TemplArgs.setLAngleLoc(ReadSourceLocation()); | |||
899 | TemplArgs.setRAngleLoc(ReadSourceLocation()); | |||
900 | ||||
901 | FD->setDependentTemplateSpecialization(Reader.getContext(), | |||
902 | TemplDecls, TemplArgs); | |||
903 | // These are not merged; we don't need to merge redeclarations of dependent | |||
904 | // template friends. | |||
905 | break; | |||
906 | } | |||
907 | } | |||
908 | ||||
909 | // Read in the parameters. | |||
910 | unsigned NumParams = Record.readInt(); | |||
911 | SmallVector<ParmVarDecl *, 16> Params; | |||
912 | Params.reserve(NumParams); | |||
913 | for (unsigned I = 0; I != NumParams; ++I) | |||
914 | Params.push_back(ReadDeclAs<ParmVarDecl>()); | |||
915 | FD->setParams(Reader.getContext(), Params); | |||
916 | } | |||
917 | ||||
918 | void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) { | |||
919 | VisitNamedDecl(MD); | |||
920 | if (Record.readInt()) { | |||
921 | // Load the body on-demand. Most clients won't care, because method | |||
922 | // definitions rarely show up in headers. | |||
923 | Reader.PendingBodies[MD] = GetCurrentCursorOffset(); | |||
924 | HasPendingBody = true; | |||
925 | MD->setSelfDecl(ReadDeclAs<ImplicitParamDecl>()); | |||
926 | MD->setCmdDecl(ReadDeclAs<ImplicitParamDecl>()); | |||
927 | } | |||
928 | MD->setInstanceMethod(Record.readInt()); | |||
929 | MD->setVariadic(Record.readInt()); | |||
930 | MD->setPropertyAccessor(Record.readInt()); | |||
931 | MD->setDefined(Record.readInt()); | |||
932 | MD->IsOverriding = Record.readInt(); | |||
933 | MD->HasSkippedBody = Record.readInt(); | |||
934 | ||||
935 | MD->IsRedeclaration = Record.readInt(); | |||
936 | MD->HasRedeclaration = Record.readInt(); | |||
937 | if (MD->HasRedeclaration) | |||
938 | Reader.getContext().setObjCMethodRedeclaration(MD, | |||
939 | ReadDeclAs<ObjCMethodDecl>()); | |||
940 | ||||
941 | MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record.readInt()); | |||
942 | MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record.readInt()); | |||
943 | MD->SetRelatedResultType(Record.readInt()); | |||
944 | MD->setReturnType(Record.readType()); | |||
945 | MD->setReturnTypeSourceInfo(GetTypeSourceInfo()); | |||
946 | MD->DeclEndLoc = ReadSourceLocation(); | |||
947 | unsigned NumParams = Record.readInt(); | |||
948 | SmallVector<ParmVarDecl *, 16> Params; | |||
949 | Params.reserve(NumParams); | |||
950 | for (unsigned I = 0; I != NumParams; ++I) | |||
951 | Params.push_back(ReadDeclAs<ParmVarDecl>()); | |||
952 | ||||
953 | MD->SelLocsKind = Record.readInt(); | |||
954 | unsigned NumStoredSelLocs = Record.readInt(); | |||
955 | SmallVector<SourceLocation, 16> SelLocs; | |||
956 | SelLocs.reserve(NumStoredSelLocs); | |||
957 | for (unsigned i = 0; i != NumStoredSelLocs; ++i) | |||
958 | SelLocs.push_back(ReadSourceLocation()); | |||
959 | ||||
960 | MD->setParamsAndSelLocs(Reader.getContext(), Params, SelLocs); | |||
961 | } | |||
962 | ||||
963 | void ASTDeclReader::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { | |||
964 | VisitTypedefNameDecl(D); | |||
965 | ||||
966 | D->Variance = Record.readInt(); | |||
967 | D->Index = Record.readInt(); | |||
968 | D->VarianceLoc = ReadSourceLocation(); | |||
969 | D->ColonLoc = ReadSourceLocation(); | |||
970 | } | |||
971 | ||||
972 | void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) { | |||
973 | VisitNamedDecl(CD); | |||
974 | CD->setAtStartLoc(ReadSourceLocation()); | |||
975 | CD->setAtEndRange(ReadSourceRange()); | |||
976 | } | |||
977 | ||||
978 | ObjCTypeParamList *ASTDeclReader::ReadObjCTypeParamList() { | |||
979 | unsigned numParams = Record.readInt(); | |||
980 | if (numParams == 0) | |||
981 | return nullptr; | |||
982 | ||||
983 | SmallVector<ObjCTypeParamDecl *, 4> typeParams; | |||
984 | typeParams.reserve(numParams); | |||
985 | for (unsigned i = 0; i != numParams; ++i) { | |||
986 | auto typeParam = ReadDeclAs<ObjCTypeParamDecl>(); | |||
987 | if (!typeParam) | |||
988 | return nullptr; | |||
989 | ||||
990 | typeParams.push_back(typeParam); | |||
991 | } | |||
992 | ||||
993 | SourceLocation lAngleLoc = ReadSourceLocation(); | |||
994 | SourceLocation rAngleLoc = ReadSourceLocation(); | |||
995 | ||||
996 | return ObjCTypeParamList::create(Reader.getContext(), lAngleLoc, | |||
997 | typeParams, rAngleLoc); | |||
998 | } | |||
999 | ||||
1000 | void ASTDeclReader::ReadObjCDefinitionData( | |||
1001 | struct ObjCInterfaceDecl::DefinitionData &Data) { | |||
1002 | // Read the superclass. | |||
1003 | Data.SuperClassTInfo = GetTypeSourceInfo(); | |||
1004 | ||||
1005 | Data.EndLoc = ReadSourceLocation(); | |||
1006 | Data.HasDesignatedInitializers = Record.readInt(); | |||
1007 | ||||
1008 | // Read the directly referenced protocols and their SourceLocations. | |||
1009 | unsigned NumProtocols = Record.readInt(); | |||
1010 | SmallVector<ObjCProtocolDecl *, 16> Protocols; | |||
1011 | Protocols.reserve(NumProtocols); | |||
1012 | for (unsigned I = 0; I != NumProtocols; ++I) | |||
1013 | Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>()); | |||
1014 | SmallVector<SourceLocation, 16> ProtoLocs; | |||
1015 | ProtoLocs.reserve(NumProtocols); | |||
1016 | for (unsigned I = 0; I != NumProtocols; ++I) | |||
1017 | ProtoLocs.push_back(ReadSourceLocation()); | |||
1018 | Data.ReferencedProtocols.set(Protocols.data(), NumProtocols, ProtoLocs.data(), | |||
1019 | Reader.getContext()); | |||
1020 | ||||
1021 | // Read the transitive closure of protocols referenced by this class. | |||
1022 | NumProtocols = Record.readInt(); | |||
1023 | Protocols.clear(); | |||
1024 | Protocols.reserve(NumProtocols); | |||
1025 | for (unsigned I = 0; I != NumProtocols; ++I) | |||
1026 | Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>()); | |||
1027 | Data.AllReferencedProtocols.set(Protocols.data(), NumProtocols, | |||
1028 | Reader.getContext()); | |||
1029 | } | |||
1030 | ||||
1031 | void ASTDeclReader::MergeDefinitionData(ObjCInterfaceDecl *D, | |||
1032 | struct ObjCInterfaceDecl::DefinitionData &&NewDD) { | |||
1033 | // FIXME: odr checking? | |||
1034 | } | |||
1035 | ||||
1036 | void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) { | |||
1037 | RedeclarableResult Redecl = VisitRedeclarable(ID); | |||
1038 | VisitObjCContainerDecl(ID); | |||
1039 | TypeIDForTypeDecl = Record.getGlobalTypeID(Record.readInt()); | |||
1040 | mergeRedeclarable(ID, Redecl); | |||
1041 | ||||
1042 | ID->TypeParamList = ReadObjCTypeParamList(); | |||
1043 | if (Record.readInt()) { | |||
1044 | // Read the definition. | |||
1045 | ID->allocateDefinitionData(); | |||
1046 | ||||
1047 | ReadObjCDefinitionData(ID->data()); | |||
1048 | ObjCInterfaceDecl *Canon = ID->getCanonicalDecl(); | |||
1049 | if (Canon->Data.getPointer()) { | |||
1050 | // If we already have a definition, keep the definition invariant and | |||
1051 | // merge the data. | |||
1052 | MergeDefinitionData(Canon, std::move(ID->data())); | |||
1053 | ID->Data = Canon->Data; | |||
1054 | } else { | |||
1055 | // Set the definition data of the canonical declaration, so other | |||
1056 | // redeclarations will see it. | |||
1057 | ID->getCanonicalDecl()->Data = ID->Data; | |||
1058 | ||||
1059 | // We will rebuild this list lazily. | |||
1060 | ID->setIvarList(nullptr); | |||
1061 | } | |||
1062 | ||||
1063 | // Note that we have deserialized a definition. | |||
1064 | Reader.PendingDefinitions.insert(ID); | |||
1065 | ||||
1066 | // Note that we've loaded this Objective-C class. | |||
1067 | Reader.ObjCClassesLoaded.push_back(ID); | |||
1068 | } else { | |||
1069 | ID->Data = ID->getCanonicalDecl()->Data; | |||
1070 | } | |||
1071 | } | |||
1072 | ||||
1073 | void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) { | |||
1074 | VisitFieldDecl(IVD); | |||
1075 | IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record.readInt()); | |||
1076 | // This field will be built lazily. | |||
1077 | IVD->setNextIvar(nullptr); | |||
1078 | bool synth = Record.readInt(); | |||
1079 | IVD->setSynthesize(synth); | |||
1080 | } | |||
1081 | ||||
1082 | void ASTDeclReader::ReadObjCDefinitionData( | |||
1083 | struct ObjCProtocolDecl::DefinitionData &Data) { | |||
1084 | ||||
1085 | unsigned NumProtoRefs = Record.readInt(); | |||
1086 | SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; | |||
1087 | ProtoRefs.reserve(NumProtoRefs); | |||
1088 | for (unsigned I = 0; I != NumProtoRefs; ++I) | |||
1089 | ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>()); | |||
1090 | SmallVector<SourceLocation, 16> ProtoLocs; | |||
1091 | ProtoLocs.reserve(NumProtoRefs); | |||
1092 | for (unsigned I = 0; I != NumProtoRefs; ++I) | |||
1093 | ProtoLocs.push_back(ReadSourceLocation()); | |||
1094 | Data.ReferencedProtocols.set(ProtoRefs.data(), NumProtoRefs, | |||
1095 | ProtoLocs.data(), Reader.getContext()); | |||
1096 | } | |||
1097 | ||||
1098 | void ASTDeclReader::MergeDefinitionData(ObjCProtocolDecl *D, | |||
1099 | struct ObjCProtocolDecl::DefinitionData &&NewDD) { | |||
1100 | // FIXME: odr checking? | |||
1101 | } | |||
1102 | ||||
1103 | void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) { | |||
1104 | RedeclarableResult Redecl = VisitRedeclarable(PD); | |||
1105 | VisitObjCContainerDecl(PD); | |||
1106 | mergeRedeclarable(PD, Redecl); | |||
1107 | ||||
1108 | if (Record.readInt()) { | |||
1109 | // Read the definition. | |||
1110 | PD->allocateDefinitionData(); | |||
1111 | ||||
1112 | ReadObjCDefinitionData(PD->data()); | |||
1113 | ||||
1114 | ObjCProtocolDecl *Canon = PD->getCanonicalDecl(); | |||
1115 | if (Canon->Data.getPointer()) { | |||
1116 | // If we already have a definition, keep the definition invariant and | |||
1117 | // merge the data. | |||
1118 | MergeDefinitionData(Canon, std::move(PD->data())); | |||
1119 | PD->Data = Canon->Data; | |||
1120 | } else { | |||
1121 | // Set the definition data of the canonical declaration, so other | |||
1122 | // redeclarations will see it. | |||
1123 | PD->getCanonicalDecl()->Data = PD->Data; | |||
1124 | } | |||
1125 | // Note that we have deserialized a definition. | |||
1126 | Reader.PendingDefinitions.insert(PD); | |||
1127 | } else { | |||
1128 | PD->Data = PD->getCanonicalDecl()->Data; | |||
1129 | } | |||
1130 | } | |||
1131 | ||||
1132 | void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) { | |||
1133 | VisitFieldDecl(FD); | |||
1134 | } | |||
1135 | ||||
1136 | void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) { | |||
1137 | VisitObjCContainerDecl(CD); | |||
1138 | CD->setCategoryNameLoc(ReadSourceLocation()); | |||
1139 | CD->setIvarLBraceLoc(ReadSourceLocation()); | |||
1140 | CD->setIvarRBraceLoc(ReadSourceLocation()); | |||
1141 | ||||
1142 | // Note that this category has been deserialized. We do this before | |||
1143 | // deserializing the interface declaration, so that it will consider this | |||
1144 | /// category. | |||
1145 | Reader.CategoriesDeserialized.insert(CD); | |||
1146 | ||||
1147 | CD->ClassInterface = ReadDeclAs<ObjCInterfaceDecl>(); | |||
1148 | CD->TypeParamList = ReadObjCTypeParamList(); | |||
1149 | unsigned NumProtoRefs = Record.readInt(); | |||
1150 | SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; | |||
1151 | ProtoRefs.reserve(NumProtoRefs); | |||
1152 | for (unsigned I = 0; I != NumProtoRefs; ++I) | |||
1153 | ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>()); | |||
1154 | SmallVector<SourceLocation, 16> ProtoLocs; | |||
1155 | ProtoLocs.reserve(NumProtoRefs); | |||
1156 | for (unsigned I = 0; I != NumProtoRefs; ++I) | |||
1157 | ProtoLocs.push_back(ReadSourceLocation()); | |||
1158 | CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(), | |||
1159 | Reader.getContext()); | |||
1160 | } | |||
1161 | ||||
1162 | void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) { | |||
1163 | VisitNamedDecl(CAD); | |||
1164 | CAD->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>()); | |||
1165 | } | |||
1166 | ||||
1167 | void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { | |||
1168 | VisitNamedDecl(D); | |||
1169 | D->setAtLoc(ReadSourceLocation()); | |||
1170 | D->setLParenLoc(ReadSourceLocation()); | |||
1171 | QualType T = Record.readType(); | |||
1172 | TypeSourceInfo *TSI = GetTypeSourceInfo(); | |||
1173 | D->setType(T, TSI); | |||
1174 | D->setPropertyAttributes( | |||
1175 | (ObjCPropertyDecl::PropertyAttributeKind)Record.readInt()); | |||
1176 | D->setPropertyAttributesAsWritten( | |||
1177 | (ObjCPropertyDecl::PropertyAttributeKind)Record.readInt()); | |||
1178 | D->setPropertyImplementation( | |||
1179 | (ObjCPropertyDecl::PropertyControl)Record.readInt()); | |||
1180 | DeclarationName GetterName = Record.readDeclarationName(); | |||
1181 | SourceLocation GetterLoc = ReadSourceLocation(); | |||
1182 | D->setGetterName(GetterName.getObjCSelector(), GetterLoc); | |||
1183 | DeclarationName SetterName = Record.readDeclarationName(); | |||
1184 | SourceLocation SetterLoc = ReadSourceLocation(); | |||
1185 | D->setSetterName(SetterName.getObjCSelector(), SetterLoc); | |||
1186 | D->setGetterMethodDecl(ReadDeclAs<ObjCMethodDecl>()); | |||
1187 | D->setSetterMethodDecl(ReadDeclAs<ObjCMethodDecl>()); | |||
1188 | D->setPropertyIvarDecl(ReadDeclAs<ObjCIvarDecl>()); | |||
1189 | } | |||
1190 | ||||
1191 | void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) { | |||
1192 | VisitObjCContainerDecl(D); | |||
1193 | D->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>()); | |||
1194 | } | |||
1195 | ||||
1196 | void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { | |||
1197 | VisitObjCImplDecl(D); | |||
1198 | D->CategoryNameLoc = ReadSourceLocation(); | |||
1199 | } | |||
1200 | ||||
1201 | void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { | |||
1202 | VisitObjCImplDecl(D); | |||
1203 | D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>()); | |||
1204 | D->SuperLoc = ReadSourceLocation(); | |||
1205 | D->setIvarLBraceLoc(ReadSourceLocation()); | |||
1206 | D->setIvarRBraceLoc(ReadSourceLocation()); | |||
1207 | D->setHasNonZeroConstructors(Record.readInt()); | |||
1208 | D->setHasDestructors(Record.readInt()); | |||
1209 | D->NumIvarInitializers = Record.readInt(); | |||
1210 | if (D->NumIvarInitializers) | |||
1211 | D->IvarInitializers = ReadGlobalOffset(); | |||
1212 | } | |||
1213 | ||||
1214 | void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { | |||
1215 | VisitDecl(D); | |||
1216 | D->setAtLoc(ReadSourceLocation()); | |||
1217 | D->setPropertyDecl(ReadDeclAs<ObjCPropertyDecl>()); | |||
1218 | D->PropertyIvarDecl = ReadDeclAs<ObjCIvarDecl>(); | |||
1219 | D->IvarLoc = ReadSourceLocation(); | |||
1220 | D->setGetterCXXConstructor(Record.readExpr()); | |||
1221 | D->setSetterCXXAssignment(Record.readExpr()); | |||
1222 | } | |||
1223 | ||||
1224 | void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) { | |||
1225 | VisitDeclaratorDecl(FD); | |||
1226 | FD->Mutable = Record.readInt(); | |||
1227 | ||||
1228 | if (auto ISK = static_cast<FieldDecl::InitStorageKind>(Record.readInt())) { | |||
1229 | FD->InitStorage.setInt(ISK); | |||
1230 | FD->InitStorage.setPointer(ISK == FieldDecl::ISK_CapturedVLAType | |||
1231 | ? Record.readType().getAsOpaquePtr() | |||
1232 | : Record.readExpr()); | |||
1233 | } | |||
1234 | ||||
1235 | if (auto *BW = Record.readExpr()) | |||
1236 | FD->setBitWidth(BW); | |||
1237 | ||||
1238 | if (!FD->getDeclName()) { | |||
1239 | if (FieldDecl *Tmpl = ReadDeclAs<FieldDecl>()) | |||
1240 | Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl); | |||
1241 | } | |||
1242 | mergeMergeable(FD); | |||
1243 | } | |||
1244 | ||||
1245 | void ASTDeclReader::VisitMSPropertyDecl(MSPropertyDecl *PD) { | |||
1246 | VisitDeclaratorDecl(PD); | |||
1247 | PD->GetterId = Record.getIdentifierInfo(); | |||
1248 | PD->SetterId = Record.getIdentifierInfo(); | |||
1249 | } | |||
1250 | ||||
1251 | void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) { | |||
1252 | VisitValueDecl(FD); | |||
1253 | ||||
1254 | FD->ChainingSize = Record.readInt(); | |||
1255 | assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2")(static_cast <bool> (FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2") ? void (0) : __assert_fail ("FD->ChainingSize >= 2 && \"Anonymous chaining must be >= 2\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 1255, __extension__ __PRETTY_FUNCTION__)); | |||
1256 | FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize]; | |||
1257 | ||||
1258 | for (unsigned I = 0; I != FD->ChainingSize; ++I) | |||
1259 | FD->Chaining[I] = ReadDeclAs<NamedDecl>(); | |||
1260 | ||||
1261 | mergeMergeable(FD); | |||
1262 | } | |||
1263 | ||||
1264 | ASTDeclReader::RedeclarableResult ASTDeclReader::VisitVarDeclImpl(VarDecl *VD) { | |||
1265 | RedeclarableResult Redecl = VisitRedeclarable(VD); | |||
1266 | VisitDeclaratorDecl(VD); | |||
1267 | ||||
1268 | VD->VarDeclBits.SClass = (StorageClass)Record.readInt(); | |||
1269 | VD->VarDeclBits.TSCSpec = Record.readInt(); | |||
1270 | VD->VarDeclBits.InitStyle = Record.readInt(); | |||
1271 | if (!isa<ParmVarDecl>(VD)) { | |||
1272 | VD->NonParmVarDeclBits.IsThisDeclarationADemotedDefinition = | |||
1273 | Record.readInt(); | |||
1274 | VD->NonParmVarDeclBits.ExceptionVar = Record.readInt(); | |||
1275 | VD->NonParmVarDeclBits.NRVOVariable = Record.readInt(); | |||
1276 | VD->NonParmVarDeclBits.CXXForRangeDecl = Record.readInt(); | |||
1277 | VD->NonParmVarDeclBits.ARCPseudoStrong = Record.readInt(); | |||
1278 | VD->NonParmVarDeclBits.IsInline = Record.readInt(); | |||
1279 | VD->NonParmVarDeclBits.IsInlineSpecified = Record.readInt(); | |||
1280 | VD->NonParmVarDeclBits.IsConstexpr = Record.readInt(); | |||
1281 | VD->NonParmVarDeclBits.IsInitCapture = Record.readInt(); | |||
1282 | VD->NonParmVarDeclBits.PreviousDeclInSameBlockScope = Record.readInt(); | |||
1283 | VD->NonParmVarDeclBits.ImplicitParamKind = Record.readInt(); | |||
1284 | } | |||
1285 | Linkage VarLinkage = Linkage(Record.readInt()); | |||
1286 | VD->setCachedLinkage(VarLinkage); | |||
1287 | ||||
1288 | // Reconstruct the one piece of the IdentifierNamespace that we need. | |||
1289 | if (VD->getStorageClass() == SC_Extern && VarLinkage != NoLinkage && | |||
1290 | VD->getLexicalDeclContext()->isFunctionOrMethod()) | |||
1291 | VD->setLocalExternDecl(); | |||
1292 | ||||
1293 | if (uint64_t Val = Record.readInt()) { | |||
1294 | VD->setInit(Record.readExpr()); | |||
1295 | if (Val > 1) { // IsInitKnownICE = 1, IsInitNotICE = 2, IsInitICE = 3 | |||
1296 | EvaluatedStmt *Eval = VD->ensureEvaluatedStmt(); | |||
1297 | Eval->CheckedICE = true; | |||
1298 | Eval->IsICE = Val == 3; | |||
1299 | } | |||
1300 | } | |||
1301 | ||||
1302 | if (VD->getStorageDuration() == SD_Static && Record.readInt()) | |||
1303 | Reader.DefinitionSource[VD] = Loc.F->Kind == ModuleKind::MK_MainFile; | |||
1304 | ||||
1305 | enum VarKind { | |||
1306 | VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization | |||
1307 | }; | |||
1308 | switch ((VarKind)Record.readInt()) { | |||
1309 | case VarNotTemplate: | |||
1310 | // Only true variables (not parameters or implicit parameters) can be | |||
1311 | // merged; the other kinds are not really redeclarable at all. | |||
1312 | if (!isa<ParmVarDecl>(VD) && !isa<ImplicitParamDecl>(VD) && | |||
1313 | !isa<VarTemplateSpecializationDecl>(VD)) | |||
1314 | mergeRedeclarable(VD, Redecl); | |||
1315 | break; | |||
1316 | case VarTemplate: | |||
1317 | // Merged when we merge the template. | |||
1318 | VD->setDescribedVarTemplate(ReadDeclAs<VarTemplateDecl>()); | |||
1319 | break; | |||
1320 | case StaticDataMemberSpecialization: { // HasMemberSpecializationInfo. | |||
1321 | VarDecl *Tmpl = ReadDeclAs<VarDecl>(); | |||
1322 | TemplateSpecializationKind TSK = | |||
1323 | (TemplateSpecializationKind)Record.readInt(); | |||
1324 | SourceLocation POI = ReadSourceLocation(); | |||
1325 | Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI); | |||
1326 | mergeRedeclarable(VD, Redecl); | |||
1327 | break; | |||
1328 | } | |||
1329 | } | |||
1330 | ||||
1331 | return Redecl; | |||
1332 | } | |||
1333 | ||||
1334 | void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) { | |||
1335 | VisitVarDecl(PD); | |||
1336 | } | |||
1337 | ||||
1338 | void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) { | |||
1339 | VisitVarDecl(PD); | |||
1340 | unsigned isObjCMethodParam = Record.readInt(); | |||
1341 | unsigned scopeDepth = Record.readInt(); | |||
1342 | unsigned scopeIndex = Record.readInt(); | |||
1343 | unsigned declQualifier = Record.readInt(); | |||
1344 | if (isObjCMethodParam) { | |||
1345 | assert(scopeDepth == 0)(static_cast <bool> (scopeDepth == 0) ? void (0) : __assert_fail ("scopeDepth == 0", "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 1345, __extension__ __PRETTY_FUNCTION__)); | |||
1346 | PD->setObjCMethodScopeInfo(scopeIndex); | |||
1347 | PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier; | |||
1348 | } else { | |||
1349 | PD->setScopeInfo(scopeDepth, scopeIndex); | |||
1350 | } | |||
1351 | PD->ParmVarDeclBits.IsKNRPromoted = Record.readInt(); | |||
1352 | PD->ParmVarDeclBits.HasInheritedDefaultArg = Record.readInt(); | |||
1353 | if (Record.readInt()) // hasUninstantiatedDefaultArg. | |||
1354 | PD->setUninstantiatedDefaultArg(Record.readExpr()); | |||
1355 | ||||
1356 | // FIXME: If this is a redeclaration of a function from another module, handle | |||
1357 | // inheritance of default arguments. | |||
1358 | } | |||
1359 | ||||
1360 | void ASTDeclReader::VisitDecompositionDecl(DecompositionDecl *DD) { | |||
1361 | VisitVarDecl(DD); | |||
1362 | BindingDecl **BDs = DD->getTrailingObjects<BindingDecl*>(); | |||
1363 | for (unsigned I = 0; I != DD->NumBindings; ++I) | |||
1364 | BDs[I] = ReadDeclAs<BindingDecl>(); | |||
1365 | } | |||
1366 | ||||
1367 | void ASTDeclReader::VisitBindingDecl(BindingDecl *BD) { | |||
1368 | VisitValueDecl(BD); | |||
1369 | BD->Binding = Record.readExpr(); | |||
1370 | } | |||
1371 | ||||
1372 | void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) { | |||
1373 | VisitDecl(AD); | |||
1374 | AD->setAsmString(cast<StringLiteral>(Record.readExpr())); | |||
1375 | AD->setRParenLoc(ReadSourceLocation()); | |||
1376 | } | |||
1377 | ||||
1378 | void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) { | |||
1379 | VisitDecl(BD); | |||
1380 | BD->setBody(cast_or_null<CompoundStmt>(Record.readStmt())); | |||
1381 | BD->setSignatureAsWritten(GetTypeSourceInfo()); | |||
1382 | unsigned NumParams = Record.readInt(); | |||
1383 | SmallVector<ParmVarDecl *, 16> Params; | |||
1384 | Params.reserve(NumParams); | |||
1385 | for (unsigned I = 0; I != NumParams; ++I) | |||
1386 | Params.push_back(ReadDeclAs<ParmVarDecl>()); | |||
1387 | BD->setParams(Params); | |||
1388 | ||||
1389 | BD->setIsVariadic(Record.readInt()); | |||
1390 | BD->setBlockMissingReturnType(Record.readInt()); | |||
1391 | BD->setIsConversionFromLambda(Record.readInt()); | |||
1392 | ||||
1393 | bool capturesCXXThis = Record.readInt(); | |||
1394 | unsigned numCaptures = Record.readInt(); | |||
1395 | SmallVector<BlockDecl::Capture, 16> captures; | |||
1396 | captures.reserve(numCaptures); | |||
1397 | for (unsigned i = 0; i != numCaptures; ++i) { | |||
1398 | VarDecl *decl = ReadDeclAs<VarDecl>(); | |||
1399 | unsigned flags = Record.readInt(); | |||
1400 | bool byRef = (flags & 1); | |||
1401 | bool nested = (flags & 2); | |||
1402 | Expr *copyExpr = ((flags & 4) ? Record.readExpr() : nullptr); | |||
1403 | ||||
1404 | captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr)); | |||
1405 | } | |||
1406 | BD->setCaptures(Reader.getContext(), captures, capturesCXXThis); | |||
1407 | } | |||
1408 | ||||
1409 | void ASTDeclReader::VisitCapturedDecl(CapturedDecl *CD) { | |||
1410 | VisitDecl(CD); | |||
1411 | unsigned ContextParamPos = Record.readInt(); | |||
1412 | CD->setNothrow(Record.readInt() != 0); | |||
1413 | // Body is set by VisitCapturedStmt. | |||
1414 | for (unsigned I = 0; I < CD->NumParams; ++I) { | |||
1415 | if (I != ContextParamPos) | |||
1416 | CD->setParam(I, ReadDeclAs<ImplicitParamDecl>()); | |||
1417 | else | |||
1418 | CD->setContextParam(I, ReadDeclAs<ImplicitParamDecl>()); | |||
1419 | } | |||
1420 | } | |||
1421 | ||||
1422 | void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) { | |||
1423 | VisitDecl(D); | |||
1424 | D->setLanguage((LinkageSpecDecl::LanguageIDs)Record.readInt()); | |||
1425 | D->setExternLoc(ReadSourceLocation()); | |||
1426 | D->setRBraceLoc(ReadSourceLocation()); | |||
1427 | } | |||
1428 | ||||
1429 | void ASTDeclReader::VisitExportDecl(ExportDecl *D) { | |||
1430 | VisitDecl(D); | |||
1431 | D->RBraceLoc = ReadSourceLocation(); | |||
1432 | } | |||
1433 | ||||
1434 | void ASTDeclReader::VisitLabelDecl(LabelDecl *D) { | |||
1435 | VisitNamedDecl(D); | |||
1436 | D->setLocStart(ReadSourceLocation()); | |||
1437 | } | |||
1438 | ||||
1439 | void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) { | |||
1440 | RedeclarableResult Redecl = VisitRedeclarable(D); | |||
1441 | VisitNamedDecl(D); | |||
1442 | D->setInline(Record.readInt()); | |||
1443 | D->LocStart = ReadSourceLocation(); | |||
1444 | D->RBraceLoc = ReadSourceLocation(); | |||
1445 | ||||
1446 | // Defer loading the anonymous namespace until we've finished merging | |||
1447 | // this namespace; loading it might load a later declaration of the | |||
1448 | // same namespace, and we have an invariant that older declarations | |||
1449 | // get merged before newer ones try to merge. | |||
1450 | GlobalDeclID AnonNamespace = 0; | |||
1451 | if (Redecl.getFirstID() == ThisDeclID) { | |||
1452 | AnonNamespace = ReadDeclID(); | |||
1453 | } else { | |||
1454 | // Link this namespace back to the first declaration, which has already | |||
1455 | // been deserialized. | |||
1456 | D->AnonOrFirstNamespaceAndInline.setPointer(D->getFirstDecl()); | |||
1457 | } | |||
1458 | ||||
1459 | mergeRedeclarable(D, Redecl); | |||
1460 | ||||
1461 | if (AnonNamespace) { | |||
1462 | // Each module has its own anonymous namespace, which is disjoint from | |||
1463 | // any other module's anonymous namespaces, so don't attach the anonymous | |||
1464 | // namespace at all. | |||
1465 | NamespaceDecl *Anon = cast<NamespaceDecl>(Reader.GetDecl(AnonNamespace)); | |||
1466 | if (!Record.isModule()) | |||
1467 | D->setAnonymousNamespace(Anon); | |||
1468 | } | |||
1469 | } | |||
1470 | ||||
1471 | void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { | |||
1472 | RedeclarableResult Redecl = VisitRedeclarable(D); | |||
1473 | VisitNamedDecl(D); | |||
1474 | D->NamespaceLoc = ReadSourceLocation(); | |||
1475 | D->IdentLoc = ReadSourceLocation(); | |||
1476 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); | |||
1477 | D->Namespace = ReadDeclAs<NamedDecl>(); | |||
1478 | mergeRedeclarable(D, Redecl); | |||
1479 | } | |||
1480 | ||||
1481 | void ASTDeclReader::VisitUsingDecl(UsingDecl *D) { | |||
1482 | VisitNamedDecl(D); | |||
1483 | D->setUsingLoc(ReadSourceLocation()); | |||
1484 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); | |||
1485 | ReadDeclarationNameLoc(D->DNLoc, D->getDeclName()); | |||
1486 | D->FirstUsingShadow.setPointer(ReadDeclAs<UsingShadowDecl>()); | |||
1487 | D->setTypename(Record.readInt()); | |||
1488 | if (NamedDecl *Pattern = ReadDeclAs<NamedDecl>()) | |||
1489 | Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern); | |||
1490 | mergeMergeable(D); | |||
1491 | } | |||
1492 | ||||
1493 | void ASTDeclReader::VisitUsingPackDecl(UsingPackDecl *D) { | |||
1494 | VisitNamedDecl(D); | |||
1495 | D->InstantiatedFrom = ReadDeclAs<NamedDecl>(); | |||
1496 | NamedDecl **Expansions = D->getTrailingObjects<NamedDecl*>(); | |||
1497 | for (unsigned I = 0; I != D->NumExpansions; ++I) | |||
1498 | Expansions[I] = ReadDeclAs<NamedDecl>(); | |||
1499 | mergeMergeable(D); | |||
1500 | } | |||
1501 | ||||
1502 | void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) { | |||
1503 | RedeclarableResult Redecl = VisitRedeclarable(D); | |||
1504 | VisitNamedDecl(D); | |||
1505 | D->Underlying = ReadDeclAs<NamedDecl>(); | |||
1506 | D->IdentifierNamespace = Record.readInt(); | |||
1507 | D->UsingOrNextShadow = ReadDeclAs<NamedDecl>(); | |||
1508 | UsingShadowDecl *Pattern = ReadDeclAs<UsingShadowDecl>(); | |||
1509 | if (Pattern) | |||
1510 | Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern); | |||
1511 | mergeRedeclarable(D, Redecl); | |||
1512 | } | |||
1513 | ||||
1514 | void ASTDeclReader::VisitConstructorUsingShadowDecl( | |||
1515 | ConstructorUsingShadowDecl *D) { | |||
1516 | VisitUsingShadowDecl(D); | |||
1517 | D->NominatedBaseClassShadowDecl = ReadDeclAs<ConstructorUsingShadowDecl>(); | |||
1518 | D->ConstructedBaseClassShadowDecl = ReadDeclAs<ConstructorUsingShadowDecl>(); | |||
1519 | D->IsVirtual = Record.readInt(); | |||
1520 | } | |||
1521 | ||||
1522 | void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { | |||
1523 | VisitNamedDecl(D); | |||
1524 | D->UsingLoc = ReadSourceLocation(); | |||
1525 | D->NamespaceLoc = ReadSourceLocation(); | |||
1526 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); | |||
1527 | D->NominatedNamespace = ReadDeclAs<NamedDecl>(); | |||
1528 | D->CommonAncestor = ReadDeclAs<DeclContext>(); | |||
1529 | } | |||
1530 | ||||
1531 | void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) { | |||
1532 | VisitValueDecl(D); | |||
1533 | D->setUsingLoc(ReadSourceLocation()); | |||
1534 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); | |||
1535 | ReadDeclarationNameLoc(D->DNLoc, D->getDeclName()); | |||
1536 | D->EllipsisLoc = ReadSourceLocation(); | |||
1537 | mergeMergeable(D); | |||
1538 | } | |||
1539 | ||||
1540 | void ASTDeclReader::VisitUnresolvedUsingTypenameDecl( | |||
1541 | UnresolvedUsingTypenameDecl *D) { | |||
1542 | VisitTypeDecl(D); | |||
1543 | D->TypenameLocation = ReadSourceLocation(); | |||
1544 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); | |||
1545 | D->EllipsisLoc = ReadSourceLocation(); | |||
1546 | mergeMergeable(D); | |||
1547 | } | |||
1548 | ||||
1549 | void ASTDeclReader::ReadCXXDefinitionData( | |||
1550 | struct CXXRecordDecl::DefinitionData &Data, const CXXRecordDecl *D) { | |||
1551 | // Note: the caller has deserialized the IsLambda bit already. | |||
1552 | Data.UserDeclaredConstructor = Record.readInt(); | |||
1553 | Data.UserDeclaredSpecialMembers = Record.readInt(); | |||
1554 | Data.Aggregate = Record.readInt(); | |||
1555 | Data.PlainOldData = Record.readInt(); | |||
1556 | Data.Empty = Record.readInt(); | |||
1557 | Data.Polymorphic = Record.readInt(); | |||
1558 | Data.Abstract = Record.readInt(); | |||
1559 | Data.IsStandardLayout = Record.readInt(); | |||
1560 | Data.HasNoNonEmptyBases = Record.readInt(); | |||
1561 | Data.HasPrivateFields = Record.readInt(); | |||
1562 | Data.HasProtectedFields = Record.readInt(); | |||
1563 | Data.HasPublicFields = Record.readInt(); | |||
1564 | Data.HasMutableFields = Record.readInt(); | |||
1565 | Data.HasVariantMembers = Record.readInt(); | |||
1566 | Data.HasOnlyCMembers = Record.readInt(); | |||
1567 | Data.HasInClassInitializer = Record.readInt(); | |||
1568 | Data.HasUninitializedReferenceMember = Record.readInt(); | |||
1569 | Data.HasUninitializedFields = Record.readInt(); | |||
1570 | Data.HasInheritedConstructor = Record.readInt(); | |||
1571 | Data.HasInheritedAssignment = Record.readInt(); | |||
1572 | Data.NeedOverloadResolutionForCopyConstructor = Record.readInt(); | |||
1573 | Data.NeedOverloadResolutionForMoveConstructor = Record.readInt(); | |||
1574 | Data.NeedOverloadResolutionForMoveAssignment = Record.readInt(); | |||
1575 | Data.NeedOverloadResolutionForDestructor = Record.readInt(); | |||
1576 | Data.DefaultedCopyConstructorIsDeleted = Record.readInt(); | |||
1577 | Data.DefaultedMoveConstructorIsDeleted = Record.readInt(); | |||
1578 | Data.DefaultedMoveAssignmentIsDeleted = Record.readInt(); | |||
1579 | Data.DefaultedDestructorIsDeleted = Record.readInt(); | |||
1580 | Data.HasTrivialSpecialMembers = Record.readInt(); | |||
1581 | Data.HasTrivialSpecialMembersForCall = Record.readInt(); | |||
1582 | Data.DeclaredNonTrivialSpecialMembers = Record.readInt(); | |||
1583 | Data.DeclaredNonTrivialSpecialMembersForCall = Record.readInt(); | |||
1584 | Data.HasIrrelevantDestructor = Record.readInt(); | |||
1585 | Data.HasConstexprNonCopyMoveConstructor = Record.readInt(); | |||
1586 | Data.HasDefaultedDefaultConstructor = Record.readInt(); | |||
1587 | Data.CanPassInRegisters = Record.readInt(); | |||
1588 | Data.DefaultedDefaultConstructorIsConstexpr = Record.readInt(); | |||
1589 | Data.HasConstexprDefaultConstructor = Record.readInt(); | |||
1590 | Data.HasNonLiteralTypeFieldsOrBases = Record.readInt(); | |||
1591 | Data.ComputedVisibleConversions = Record.readInt(); | |||
1592 | Data.UserProvidedDefaultConstructor = Record.readInt(); | |||
1593 | Data.DeclaredSpecialMembers = Record.readInt(); | |||
1594 | Data.ImplicitCopyConstructorCanHaveConstParamForVBase = Record.readInt(); | |||
1595 | Data.ImplicitCopyConstructorCanHaveConstParamForNonVBase = Record.readInt(); | |||
1596 | Data.ImplicitCopyAssignmentHasConstParam = Record.readInt(); | |||
1597 | Data.HasDeclaredCopyConstructorWithConstParam = Record.readInt(); | |||
1598 | Data.HasDeclaredCopyAssignmentWithConstParam = Record.readInt(); | |||
1599 | Data.ODRHash = Record.readInt(); | |||
1600 | Data.HasODRHash = true; | |||
1601 | ||||
1602 | if (Record.readInt()) | |||
1603 | Reader.DefinitionSource[D] = Loc.F->Kind == ModuleKind::MK_MainFile; | |||
1604 | ||||
1605 | Data.NumBases = Record.readInt(); | |||
1606 | if (Data.NumBases) | |||
1607 | Data.Bases = ReadGlobalOffset(); | |||
1608 | Data.NumVBases = Record.readInt(); | |||
1609 | if (Data.NumVBases) | |||
1610 | Data.VBases = ReadGlobalOffset(); | |||
1611 | ||||
1612 | Record.readUnresolvedSet(Data.Conversions); | |||
1613 | Record.readUnresolvedSet(Data.VisibleConversions); | |||
1614 | assert(Data.Definition && "Data.Definition should be already set!")(static_cast <bool> (Data.Definition && "Data.Definition should be already set!" ) ? void (0) : __assert_fail ("Data.Definition && \"Data.Definition should be already set!\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 1614, __extension__ __PRETTY_FUNCTION__)); | |||
1615 | Data.FirstFriend = ReadDeclID(); | |||
1616 | ||||
1617 | if (Data.IsLambda) { | |||
1618 | typedef LambdaCapture Capture; | |||
1619 | CXXRecordDecl::LambdaDefinitionData &Lambda | |||
1620 | = static_cast<CXXRecordDecl::LambdaDefinitionData &>(Data); | |||
1621 | Lambda.Dependent = Record.readInt(); | |||
1622 | Lambda.IsGenericLambda = Record.readInt(); | |||
1623 | Lambda.CaptureDefault = Record.readInt(); | |||
1624 | Lambda.NumCaptures = Record.readInt(); | |||
1625 | Lambda.NumExplicitCaptures = Record.readInt(); | |||
1626 | Lambda.ManglingNumber = Record.readInt(); | |||
1627 | Lambda.ContextDecl = ReadDeclID(); | |||
1628 | Lambda.Captures = (Capture *)Reader.getContext().Allocate( | |||
1629 | sizeof(Capture) * Lambda.NumCaptures); | |||
1630 | Capture *ToCapture = Lambda.Captures; | |||
1631 | Lambda.MethodTyInfo = GetTypeSourceInfo(); | |||
1632 | for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) { | |||
1633 | SourceLocation Loc = ReadSourceLocation(); | |||
1634 | bool IsImplicit = Record.readInt(); | |||
1635 | LambdaCaptureKind Kind = static_cast<LambdaCaptureKind>(Record.readInt()); | |||
1636 | switch (Kind) { | |||
1637 | case LCK_StarThis: | |||
1638 | case LCK_This: | |||
1639 | case LCK_VLAType: | |||
1640 | *ToCapture++ = Capture(Loc, IsImplicit, Kind, nullptr,SourceLocation()); | |||
1641 | break; | |||
1642 | case LCK_ByCopy: | |||
1643 | case LCK_ByRef: | |||
1644 | VarDecl *Var = ReadDeclAs<VarDecl>(); | |||
1645 | SourceLocation EllipsisLoc = ReadSourceLocation(); | |||
1646 | *ToCapture++ = Capture(Loc, IsImplicit, Kind, Var, EllipsisLoc); | |||
1647 | break; | |||
1648 | } | |||
1649 | } | |||
1650 | } | |||
1651 | } | |||
1652 | ||||
1653 | void ASTDeclReader::MergeDefinitionData( | |||
1654 | CXXRecordDecl *D, struct CXXRecordDecl::DefinitionData &&MergeDD) { | |||
1655 | assert(D->DefinitionData &&(static_cast <bool> (D->DefinitionData && "merging class definition into non-definition" ) ? void (0) : __assert_fail ("D->DefinitionData && \"merging class definition into non-definition\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 1656, __extension__ __PRETTY_FUNCTION__)) | |||
1656 | "merging class definition into non-definition")(static_cast <bool> (D->DefinitionData && "merging class definition into non-definition" ) ? void (0) : __assert_fail ("D->DefinitionData && \"merging class definition into non-definition\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 1656, __extension__ __PRETTY_FUNCTION__)); | |||
1657 | auto &DD = *D->DefinitionData; | |||
1658 | ||||
1659 | if (DD.Definition != MergeDD.Definition) { | |||
1660 | // Track that we merged the definitions. | |||
1661 | Reader.MergedDeclContexts.insert(std::make_pair(MergeDD.Definition, | |||
1662 | DD.Definition)); | |||
1663 | Reader.PendingDefinitions.erase(MergeDD.Definition); | |||
1664 | MergeDD.Definition->IsCompleteDefinition = false; | |||
1665 | Reader.mergeDefinitionVisibility(DD.Definition, MergeDD.Definition); | |||
1666 | assert(Reader.Lookups.find(MergeDD.Definition) == Reader.Lookups.end() &&(static_cast <bool> (Reader.Lookups.find(MergeDD.Definition ) == Reader.Lookups.end() && "already loaded pending lookups for merged definition" ) ? void (0) : __assert_fail ("Reader.Lookups.find(MergeDD.Definition) == Reader.Lookups.end() && \"already loaded pending lookups for merged definition\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 1667, __extension__ __PRETTY_FUNCTION__)) | |||
1667 | "already loaded pending lookups for merged definition")(static_cast <bool> (Reader.Lookups.find(MergeDD.Definition ) == Reader.Lookups.end() && "already loaded pending lookups for merged definition" ) ? void (0) : __assert_fail ("Reader.Lookups.find(MergeDD.Definition) == Reader.Lookups.end() && \"already loaded pending lookups for merged definition\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 1667, __extension__ __PRETTY_FUNCTION__)); | |||
1668 | } | |||
1669 | ||||
1670 | auto PFDI = Reader.PendingFakeDefinitionData.find(&DD); | |||
1671 | if (PFDI != Reader.PendingFakeDefinitionData.end() && | |||
1672 | PFDI->second == ASTReader::PendingFakeDefinitionKind::Fake) { | |||
1673 | // We faked up this definition data because we found a class for which we'd | |||
1674 | // not yet loaded the definition. Replace it with the real thing now. | |||
1675 | assert(!DD.IsLambda && !MergeDD.IsLambda && "faked up lambda definition?")(static_cast <bool> (!DD.IsLambda && !MergeDD.IsLambda && "faked up lambda definition?") ? void (0) : __assert_fail ("!DD.IsLambda && !MergeDD.IsLambda && \"faked up lambda definition?\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 1675, __extension__ __PRETTY_FUNCTION__)); | |||
1676 | PFDI->second = ASTReader::PendingFakeDefinitionKind::FakeLoaded; | |||
1677 | ||||
1678 | // Don't change which declaration is the definition; that is required | |||
1679 | // to be invariant once we select it. | |||
1680 | auto *Def = DD.Definition; | |||
1681 | DD = std::move(MergeDD); | |||
1682 | DD.Definition = Def; | |||
1683 | return; | |||
1684 | } | |||
1685 | ||||
1686 | // FIXME: Move this out into a .def file? | |||
1687 | bool DetectedOdrViolation = false; | |||
1688 | #define OR_FIELD(Field) DD.Field |= MergeDD.Field; | |||
1689 | #define MATCH_FIELD(Field) \ | |||
1690 | DetectedOdrViolation |= DD.Field != MergeDD.Field; \ | |||
1691 | OR_FIELD(Field) | |||
1692 | MATCH_FIELD(UserDeclaredConstructor) | |||
1693 | MATCH_FIELD(UserDeclaredSpecialMembers) | |||
1694 | MATCH_FIELD(Aggregate) | |||
1695 | MATCH_FIELD(PlainOldData) | |||
1696 | MATCH_FIELD(Empty) | |||
1697 | MATCH_FIELD(Polymorphic) | |||
1698 | MATCH_FIELD(Abstract) | |||
1699 | MATCH_FIELD(IsStandardLayout) | |||
1700 | MATCH_FIELD(HasNoNonEmptyBases) | |||
1701 | MATCH_FIELD(HasPrivateFields) | |||
1702 | MATCH_FIELD(HasProtectedFields) | |||
1703 | MATCH_FIELD(HasPublicFields) | |||
1704 | MATCH_FIELD(HasMutableFields) | |||
1705 | MATCH_FIELD(HasVariantMembers) | |||
1706 | MATCH_FIELD(HasOnlyCMembers) | |||
1707 | MATCH_FIELD(HasInClassInitializer) | |||
1708 | MATCH_FIELD(HasUninitializedReferenceMember) | |||
1709 | MATCH_FIELD(HasUninitializedFields) | |||
1710 | MATCH_FIELD(HasInheritedConstructor) | |||
1711 | MATCH_FIELD(HasInheritedAssignment) | |||
1712 | MATCH_FIELD(NeedOverloadResolutionForCopyConstructor) | |||
1713 | MATCH_FIELD(NeedOverloadResolutionForMoveConstructor) | |||
1714 | MATCH_FIELD(NeedOverloadResolutionForMoveAssignment) | |||
1715 | MATCH_FIELD(NeedOverloadResolutionForDestructor) | |||
1716 | MATCH_FIELD(DefaultedCopyConstructorIsDeleted) | |||
1717 | MATCH_FIELD(DefaultedMoveConstructorIsDeleted) | |||
1718 | MATCH_FIELD(DefaultedMoveAssignmentIsDeleted) | |||
1719 | MATCH_FIELD(DefaultedDestructorIsDeleted) | |||
1720 | OR_FIELD(HasTrivialSpecialMembers) | |||
1721 | OR_FIELD(HasTrivialSpecialMembersForCall) | |||
1722 | OR_FIELD(DeclaredNonTrivialSpecialMembers) | |||
1723 | OR_FIELD(DeclaredNonTrivialSpecialMembersForCall) | |||
1724 | MATCH_FIELD(HasIrrelevantDestructor) | |||
1725 | OR_FIELD(HasConstexprNonCopyMoveConstructor) | |||
1726 | OR_FIELD(HasDefaultedDefaultConstructor) | |||
1727 | MATCH_FIELD(CanPassInRegisters) | |||
1728 | MATCH_FIELD(DefaultedDefaultConstructorIsConstexpr) | |||
1729 | OR_FIELD(HasConstexprDefaultConstructor) | |||
1730 | MATCH_FIELD(HasNonLiteralTypeFieldsOrBases) | |||
1731 | // ComputedVisibleConversions is handled below. | |||
1732 | MATCH_FIELD(UserProvidedDefaultConstructor) | |||
1733 | OR_FIELD(DeclaredSpecialMembers) | |||
1734 | MATCH_FIELD(ImplicitCopyConstructorCanHaveConstParamForVBase) | |||
1735 | MATCH_FIELD(ImplicitCopyConstructorCanHaveConstParamForNonVBase) | |||
1736 | MATCH_FIELD(ImplicitCopyAssignmentHasConstParam) | |||
1737 | OR_FIELD(HasDeclaredCopyConstructorWithConstParam) | |||
1738 | OR_FIELD(HasDeclaredCopyAssignmentWithConstParam) | |||
1739 | MATCH_FIELD(IsLambda) | |||
1740 | #undef OR_FIELD | |||
1741 | #undef MATCH_FIELD | |||
1742 | ||||
1743 | if (DD.NumBases != MergeDD.NumBases || DD.NumVBases != MergeDD.NumVBases) | |||
1744 | DetectedOdrViolation = true; | |||
1745 | // FIXME: Issue a diagnostic if the base classes don't match when we come | |||
1746 | // to lazily load them. | |||
1747 | ||||
1748 | // FIXME: Issue a diagnostic if the list of conversion functions doesn't | |||
1749 | // match when we come to lazily load them. | |||
1750 | if (MergeDD.ComputedVisibleConversions && !DD.ComputedVisibleConversions) { | |||
1751 | DD.VisibleConversions = std::move(MergeDD.VisibleConversions); | |||
1752 | DD.ComputedVisibleConversions = true; | |||
1753 | } | |||
1754 | ||||
1755 | // FIXME: Issue a diagnostic if FirstFriend doesn't match when we come to | |||
1756 | // lazily load it. | |||
1757 | ||||
1758 | if (DD.IsLambda) { | |||
1759 | // FIXME: ODR-checking for merging lambdas (this happens, for instance, | |||
1760 | // when they occur within the body of a function template specialization). | |||
1761 | } | |||
1762 | ||||
1763 | if (D->getODRHash() != MergeDD.ODRHash) { | |||
1764 | DetectedOdrViolation = true; | |||
1765 | } | |||
1766 | ||||
1767 | if (DetectedOdrViolation) | |||
1768 | Reader.PendingOdrMergeFailures[DD.Definition].push_back( | |||
1769 | {MergeDD.Definition, &MergeDD}); | |||
1770 | } | |||
1771 | ||||
1772 | void ASTDeclReader::ReadCXXRecordDefinition(CXXRecordDecl *D, bool Update) { | |||
1773 | struct CXXRecordDecl::DefinitionData *DD; | |||
1774 | ASTContext &C = Reader.getContext(); | |||
1775 | ||||
1776 | // Determine whether this is a lambda closure type, so that we can | |||
1777 | // allocate the appropriate DefinitionData structure. | |||
1778 | bool IsLambda = Record.readInt(); | |||
1779 | if (IsLambda) | |||
1780 | DD = new (C) CXXRecordDecl::LambdaDefinitionData(D, nullptr, false, false, | |||
1781 | LCD_None); | |||
1782 | else | |||
1783 | DD = new (C) struct CXXRecordDecl::DefinitionData(D); | |||
1784 | ||||
1785 | ReadCXXDefinitionData(*DD, D); | |||
1786 | ||||
1787 | // We might already have a definition for this record. This can happen either | |||
1788 | // because we're reading an update record, or because we've already done some | |||
1789 | // merging. Either way, just merge into it. | |||
1790 | CXXRecordDecl *Canon = D->getCanonicalDecl(); | |||
1791 | if (Canon->DefinitionData) { | |||
1792 | MergeDefinitionData(Canon, std::move(*DD)); | |||
1793 | D->DefinitionData = Canon->DefinitionData; | |||
1794 | return; | |||
1795 | } | |||
1796 | ||||
1797 | // Mark this declaration as being a definition. | |||
1798 | D->IsCompleteDefinition = true; | |||
1799 | D->DefinitionData = DD; | |||
1800 | ||||
1801 | // If this is not the first declaration or is an update record, we can have | |||
1802 | // other redeclarations already. Make a note that we need to propagate the | |||
1803 | // DefinitionData pointer onto them. | |||
1804 | if (Update || Canon != D) { | |||
1805 | Canon->DefinitionData = D->DefinitionData; | |||
1806 | Reader.PendingDefinitions.insert(D); | |||
1807 | } | |||
1808 | } | |||
1809 | ||||
1810 | ASTDeclReader::RedeclarableResult | |||
1811 | ASTDeclReader::VisitCXXRecordDeclImpl(CXXRecordDecl *D) { | |||
1812 | RedeclarableResult Redecl = VisitRecordDeclImpl(D); | |||
1813 | ||||
1814 | ASTContext &C = Reader.getContext(); | |||
1815 | ||||
1816 | enum CXXRecKind { | |||
1817 | CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization | |||
1818 | }; | |||
1819 | switch ((CXXRecKind)Record.readInt()) { | |||
1820 | case CXXRecNotTemplate: | |||
1821 | // Merged when we merge the folding set entry in the primary template. | |||
1822 | if (!isa<ClassTemplateSpecializationDecl>(D)) | |||
1823 | mergeRedeclarable(D, Redecl); | |||
1824 | break; | |||
1825 | case CXXRecTemplate: { | |||
1826 | // Merged when we merge the template. | |||
1827 | ClassTemplateDecl *Template = ReadDeclAs<ClassTemplateDecl>(); | |||
1828 | D->TemplateOrInstantiation = Template; | |||
1829 | if (!Template->getTemplatedDecl()) { | |||
1830 | // We've not actually loaded the ClassTemplateDecl yet, because we're | |||
1831 | // currently being loaded as its pattern. Rely on it to set up our | |||
1832 | // TypeForDecl (see VisitClassTemplateDecl). | |||
1833 | // | |||
1834 | // Beware: we do not yet know our canonical declaration, and may still | |||
1835 | // get merged once the surrounding class template has got off the ground. | |||
1836 | TypeIDForTypeDecl = 0; | |||
1837 | } | |||
1838 | break; | |||
1839 | } | |||
1840 | case CXXRecMemberSpecialization: { | |||
1841 | CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(); | |||
1842 | TemplateSpecializationKind TSK = | |||
1843 | (TemplateSpecializationKind)Record.readInt(); | |||
1844 | SourceLocation POI = ReadSourceLocation(); | |||
1845 | MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK); | |||
1846 | MSI->setPointOfInstantiation(POI); | |||
1847 | D->TemplateOrInstantiation = MSI; | |||
1848 | mergeRedeclarable(D, Redecl); | |||
1849 | break; | |||
1850 | } | |||
1851 | } | |||
1852 | ||||
1853 | bool WasDefinition = Record.readInt(); | |||
1854 | if (WasDefinition) | |||
1855 | ReadCXXRecordDefinition(D, /*Update*/false); | |||
1856 | else | |||
1857 | // Propagate DefinitionData pointer from the canonical declaration. | |||
1858 | D->DefinitionData = D->getCanonicalDecl()->DefinitionData; | |||
1859 | ||||
1860 | // Lazily load the key function to avoid deserializing every method so we can | |||
1861 | // compute it. | |||
1862 | if (WasDefinition) { | |||
1863 | DeclID KeyFn = ReadDeclID(); | |||
1864 | if (KeyFn && D->IsCompleteDefinition) | |||
1865 | // FIXME: This is wrong for the ARM ABI, where some other module may have | |||
1866 | // made this function no longer be a key function. We need an update | |||
1867 | // record or similar for that case. | |||
1868 | C.KeyFunctions[D] = KeyFn; | |||
1869 | } | |||
1870 | ||||
1871 | return Redecl; | |||
1872 | } | |||
1873 | ||||
1874 | void ASTDeclReader::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) { | |||
1875 | VisitFunctionDecl(D); | |||
1876 | D->IsCopyDeductionCandidate = Record.readInt(); | |||
1877 | } | |||
1878 | ||||
1879 | void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) { | |||
1880 | VisitFunctionDecl(D); | |||
1881 | ||||
1882 | unsigned NumOverridenMethods = Record.readInt(); | |||
1883 | if (D->isCanonicalDecl()) { | |||
1884 | while (NumOverridenMethods--) { | |||
1885 | // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod, | |||
1886 | // MD may be initializing. | |||
1887 | if (CXXMethodDecl *MD = ReadDeclAs<CXXMethodDecl>()) | |||
1888 | Reader.getContext().addOverriddenMethod(D, MD->getCanonicalDecl()); | |||
1889 | } | |||
1890 | } else { | |||
1891 | // We don't care about which declarations this used to override; we get | |||
1892 | // the relevant information from the canonical declaration. | |||
1893 | Record.skipInts(NumOverridenMethods); | |||
1894 | } | |||
1895 | } | |||
1896 | ||||
1897 | void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) { | |||
1898 | // We need the inherited constructor information to merge the declaration, | |||
1899 | // so we have to read it before we call VisitCXXMethodDecl. | |||
1900 | if (D->isInheritingConstructor()) { | |||
1901 | auto *Shadow = ReadDeclAs<ConstructorUsingShadowDecl>(); | |||
1902 | auto *Ctor = ReadDeclAs<CXXConstructorDecl>(); | |||
1903 | *D->getTrailingObjects<InheritedConstructor>() = | |||
1904 | InheritedConstructor(Shadow, Ctor); | |||
1905 | } | |||
1906 | ||||
1907 | VisitCXXMethodDecl(D); | |||
1908 | } | |||
1909 | ||||
1910 | void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) { | |||
1911 | VisitCXXMethodDecl(D); | |||
1912 | ||||
1913 | if (auto *OperatorDelete = ReadDeclAs<FunctionDecl>()) { | |||
1914 | CXXDestructorDecl *Canon = D->getCanonicalDecl(); | |||
1915 | auto *ThisArg = Record.readExpr(); | |||
1916 | // FIXME: Check consistency if we have an old and new operator delete. | |||
1917 | if (!Canon->OperatorDelete) { | |||
1918 | Canon->OperatorDelete = OperatorDelete; | |||
1919 | Canon->OperatorDeleteThisArg = ThisArg; | |||
1920 | } | |||
1921 | } | |||
1922 | } | |||
1923 | ||||
1924 | void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) { | |||
1925 | VisitCXXMethodDecl(D); | |||
1926 | } | |||
1927 | ||||
1928 | void ASTDeclReader::VisitImportDecl(ImportDecl *D) { | |||
1929 | VisitDecl(D); | |||
1930 | D->ImportedAndComplete.setPointer(readModule()); | |||
1931 | D->ImportedAndComplete.setInt(Record.readInt()); | |||
1932 | SourceLocation *StoredLocs = D->getTrailingObjects<SourceLocation>(); | |||
1933 | for (unsigned I = 0, N = Record.back(); I != N; ++I) | |||
1934 | StoredLocs[I] = ReadSourceLocation(); | |||
1935 | Record.skipInts(1); // The number of stored source locations. | |||
1936 | } | |||
1937 | ||||
1938 | void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) { | |||
1939 | VisitDecl(D); | |||
1940 | D->setColonLoc(ReadSourceLocation()); | |||
1941 | } | |||
1942 | ||||
1943 | void ASTDeclReader::VisitFriendDecl(FriendDecl *D) { | |||
1944 | VisitDecl(D); | |||
1945 | if (Record.readInt()) // hasFriendDecl | |||
1946 | D->Friend = ReadDeclAs<NamedDecl>(); | |||
1947 | else | |||
1948 | D->Friend = GetTypeSourceInfo(); | |||
1949 | for (unsigned i = 0; i != D->NumTPLists; ++i) | |||
1950 | D->getTrailingObjects<TemplateParameterList *>()[i] = | |||
1951 | Record.readTemplateParameterList(); | |||
1952 | D->NextFriend = ReadDeclID(); | |||
1953 | D->UnsupportedFriend = (Record.readInt() != 0); | |||
1954 | D->FriendLoc = ReadSourceLocation(); | |||
1955 | } | |||
1956 | ||||
1957 | void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) { | |||
1958 | VisitDecl(D); | |||
1959 | unsigned NumParams = Record.readInt(); | |||
1960 | D->NumParams = NumParams; | |||
1961 | D->Params = new TemplateParameterList*[NumParams]; | |||
1962 | for (unsigned i = 0; i != NumParams; ++i) | |||
1963 | D->Params[i] = Record.readTemplateParameterList(); | |||
1964 | if (Record.readInt()) // HasFriendDecl | |||
1965 | D->Friend = ReadDeclAs<NamedDecl>(); | |||
1966 | else | |||
1967 | D->Friend = GetTypeSourceInfo(); | |||
1968 | D->FriendLoc = ReadSourceLocation(); | |||
1969 | } | |||
1970 | ||||
1971 | DeclID ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) { | |||
1972 | VisitNamedDecl(D); | |||
1973 | ||||
1974 | DeclID PatternID = ReadDeclID(); | |||
1975 | NamedDecl *TemplatedDecl = cast_or_null<NamedDecl>(Reader.GetDecl(PatternID)); | |||
1976 | TemplateParameterList *TemplateParams = Record.readTemplateParameterList(); | |||
1977 | // FIXME handle associated constraints | |||
1978 | D->init(TemplatedDecl, TemplateParams); | |||
1979 | ||||
1980 | return PatternID; | |||
1981 | } | |||
1982 | ||||
1983 | ASTDeclReader::RedeclarableResult | |||
1984 | ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) { | |||
1985 | RedeclarableResult Redecl = VisitRedeclarable(D); | |||
1986 | ||||
1987 | // Make sure we've allocated the Common pointer first. We do this before | |||
1988 | // VisitTemplateDecl so that getCommonPtr() can be used during initialization. | |||
1989 | RedeclarableTemplateDecl *CanonD = D->getCanonicalDecl(); | |||
1990 | if (!CanonD->Common) { | |||
1991 | CanonD->Common = CanonD->newCommon(Reader.getContext()); | |||
1992 | Reader.PendingDefinitions.insert(CanonD); | |||
1993 | } | |||
1994 | D->Common = CanonD->Common; | |||
1995 | ||||
1996 | // If this is the first declaration of the template, fill in the information | |||
1997 | // for the 'common' pointer. | |||
1998 | if (ThisDeclID == Redecl.getFirstID()) { | |||
1999 | if (RedeclarableTemplateDecl *RTD | |||
2000 | = ReadDeclAs<RedeclarableTemplateDecl>()) { | |||
2001 | assert(RTD->getKind() == D->getKind() &&(static_cast <bool> (RTD->getKind() == D->getKind () && "InstantiatedFromMemberTemplate kind mismatch") ? void (0) : __assert_fail ("RTD->getKind() == D->getKind() && \"InstantiatedFromMemberTemplate kind mismatch\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 2002, __extension__ __PRETTY_FUNCTION__)) | |||
2002 | "InstantiatedFromMemberTemplate kind mismatch")(static_cast <bool> (RTD->getKind() == D->getKind () && "InstantiatedFromMemberTemplate kind mismatch") ? void (0) : __assert_fail ("RTD->getKind() == D->getKind() && \"InstantiatedFromMemberTemplate kind mismatch\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 2002, __extension__ __PRETTY_FUNCTION__)); | |||
2003 | D->setInstantiatedFromMemberTemplate(RTD); | |||
2004 | if (Record.readInt()) | |||
2005 | D->setMemberSpecialization(); | |||
2006 | } | |||
2007 | } | |||
2008 | ||||
2009 | DeclID PatternID = VisitTemplateDecl(D); | |||
2010 | D->IdentifierNamespace = Record.readInt(); | |||
2011 | ||||
2012 | mergeRedeclarable(D, Redecl, PatternID); | |||
2013 | ||||
2014 | // If we merged the template with a prior declaration chain, merge the common | |||
2015 | // pointer. | |||
2016 | // FIXME: Actually merge here, don't just overwrite. | |||
2017 | D->Common = D->getCanonicalDecl()->Common; | |||
2018 | ||||
2019 | return Redecl; | |||
2020 | } | |||
2021 | ||||
2022 | void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) { | |||
2023 | RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); | |||
2024 | ||||
2025 | if (ThisDeclID == Redecl.getFirstID()) { | |||
2026 | // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of | |||
2027 | // the specializations. | |||
2028 | SmallVector<serialization::DeclID, 32> SpecIDs; | |||
2029 | ReadDeclIDList(SpecIDs); | |||
2030 | ASTDeclReader::AddLazySpecializations(D, SpecIDs); | |||
2031 | } | |||
2032 | ||||
2033 | if (D->getTemplatedDecl()->TemplateOrInstantiation) { | |||
2034 | // We were loaded before our templated declaration was. We've not set up | |||
2035 | // its corresponding type yet (see VisitCXXRecordDeclImpl), so reconstruct | |||
2036 | // it now. | |||
2037 | Reader.getContext().getInjectedClassNameType( | |||
2038 | D->getTemplatedDecl(), D->getInjectedClassNameSpecialization()); | |||
2039 | } | |||
2040 | } | |||
2041 | ||||
2042 | void ASTDeclReader::VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D) { | |||
2043 | llvm_unreachable("BuiltinTemplates are not serialized")::llvm::llvm_unreachable_internal("BuiltinTemplates are not serialized" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 2043); | |||
2044 | } | |||
2045 | ||||
2046 | /// TODO: Unify with ClassTemplateDecl version? | |||
2047 | /// May require unifying ClassTemplateDecl and | |||
2048 | /// VarTemplateDecl beyond TemplateDecl... | |||
2049 | void ASTDeclReader::VisitVarTemplateDecl(VarTemplateDecl *D) { | |||
2050 | RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); | |||
2051 | ||||
2052 | if (ThisDeclID == Redecl.getFirstID()) { | |||
2053 | // This VarTemplateDecl owns a CommonPtr; read it to keep track of all of | |||
2054 | // the specializations. | |||
2055 | SmallVector<serialization::DeclID, 32> SpecIDs; | |||
2056 | ReadDeclIDList(SpecIDs); | |||
2057 | ASTDeclReader::AddLazySpecializations(D, SpecIDs); | |||
2058 | } | |||
2059 | } | |||
2060 | ||||
2061 | ASTDeclReader::RedeclarableResult | |||
2062 | ASTDeclReader::VisitClassTemplateSpecializationDeclImpl( | |||
2063 | ClassTemplateSpecializationDecl *D) { | |||
2064 | RedeclarableResult Redecl = VisitCXXRecordDeclImpl(D); | |||
2065 | ||||
2066 | ASTContext &C = Reader.getContext(); | |||
2067 | if (Decl *InstD = ReadDecl()) { | |||
2068 | if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) { | |||
2069 | D->SpecializedTemplate = CTD; | |||
2070 | } else { | |||
2071 | SmallVector<TemplateArgument, 8> TemplArgs; | |||
2072 | Record.readTemplateArgumentList(TemplArgs); | |||
2073 | TemplateArgumentList *ArgList | |||
2074 | = TemplateArgumentList::CreateCopy(C, TemplArgs); | |||
2075 | ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS | |||
2076 | = new (C) ClassTemplateSpecializationDecl:: | |||
2077 | SpecializedPartialSpecialization(); | |||
2078 | PS->PartialSpecialization | |||
2079 | = cast<ClassTemplatePartialSpecializationDecl>(InstD); | |||
2080 | PS->TemplateArgs = ArgList; | |||
2081 | D->SpecializedTemplate = PS; | |||
2082 | } | |||
2083 | } | |||
2084 | ||||
2085 | SmallVector<TemplateArgument, 8> TemplArgs; | |||
2086 | Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true); | |||
2087 | D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs); | |||
2088 | D->PointOfInstantiation = ReadSourceLocation(); | |||
2089 | D->SpecializationKind = (TemplateSpecializationKind)Record.readInt(); | |||
2090 | ||||
2091 | bool writtenAsCanonicalDecl = Record.readInt(); | |||
2092 | if (writtenAsCanonicalDecl) { | |||
2093 | ClassTemplateDecl *CanonPattern = ReadDeclAs<ClassTemplateDecl>(); | |||
2094 | if (D->isCanonicalDecl()) { // It's kept in the folding set. | |||
2095 | // Set this as, or find, the canonical declaration for this specialization | |||
2096 | ClassTemplateSpecializationDecl *CanonSpec; | |||
2097 | if (ClassTemplatePartialSpecializationDecl *Partial = | |||
2098 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) { | |||
2099 | CanonSpec = CanonPattern->getCommonPtr()->PartialSpecializations | |||
2100 | .GetOrInsertNode(Partial); | |||
2101 | } else { | |||
2102 | CanonSpec = | |||
2103 | CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D); | |||
2104 | } | |||
2105 | // If there was already a canonical specialization, merge into it. | |||
2106 | if (CanonSpec != D) { | |||
2107 | mergeRedeclarable<TagDecl>(D, CanonSpec, Redecl); | |||
2108 | ||||
2109 | // This declaration might be a definition. Merge with any existing | |||
2110 | // definition. | |||
2111 | if (auto *DDD = D->DefinitionData) { | |||
2112 | if (CanonSpec->DefinitionData) | |||
2113 | MergeDefinitionData(CanonSpec, std::move(*DDD)); | |||
2114 | else | |||
2115 | CanonSpec->DefinitionData = D->DefinitionData; | |||
2116 | } | |||
2117 | D->DefinitionData = CanonSpec->DefinitionData; | |||
2118 | } | |||
2119 | } | |||
2120 | } | |||
2121 | ||||
2122 | // Explicit info. | |||
2123 | if (TypeSourceInfo *TyInfo = GetTypeSourceInfo()) { | |||
2124 | ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo | |||
2125 | = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo; | |||
2126 | ExplicitInfo->TypeAsWritten = TyInfo; | |||
2127 | ExplicitInfo->ExternLoc = ReadSourceLocation(); | |||
2128 | ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(); | |||
2129 | D->ExplicitInfo = ExplicitInfo; | |||
2130 | } | |||
2131 | ||||
2132 | return Redecl; | |||
2133 | } | |||
2134 | ||||
2135 | void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl( | |||
2136 | ClassTemplatePartialSpecializationDecl *D) { | |||
2137 | RedeclarableResult Redecl = VisitClassTemplateSpecializationDeclImpl(D); | |||
2138 | ||||
2139 | D->TemplateParams = Record.readTemplateParameterList(); | |||
2140 | D->ArgsAsWritten = Record.readASTTemplateArgumentListInfo(); | |||
2141 | ||||
2142 | // These are read/set from/to the first declaration. | |||
2143 | if (ThisDeclID == Redecl.getFirstID()) { | |||
2144 | D->InstantiatedFromMember.setPointer( | |||
2145 | ReadDeclAs<ClassTemplatePartialSpecializationDecl>()); | |||
2146 | D->InstantiatedFromMember.setInt(Record.readInt()); | |||
2147 | } | |||
2148 | } | |||
2149 | ||||
2150 | void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl( | |||
2151 | ClassScopeFunctionSpecializationDecl *D) { | |||
2152 | VisitDecl(D); | |||
2153 | D->Specialization = ReadDeclAs<CXXMethodDecl>(); | |||
2154 | } | |||
2155 | ||||
2156 | void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { | |||
2157 | RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); | |||
2158 | ||||
2159 | if (ThisDeclID == Redecl.getFirstID()) { | |||
2160 | // This FunctionTemplateDecl owns a CommonPtr; read it. | |||
2161 | SmallVector<serialization::DeclID, 32> SpecIDs; | |||
2162 | ReadDeclIDList(SpecIDs); | |||
2163 | ASTDeclReader::AddLazySpecializations(D, SpecIDs); | |||
2164 | } | |||
2165 | } | |||
2166 | ||||
2167 | /// TODO: Unify with ClassTemplateSpecializationDecl version? | |||
2168 | /// May require unifying ClassTemplate(Partial)SpecializationDecl and | |||
2169 | /// VarTemplate(Partial)SpecializationDecl with a new data | |||
2170 | /// structure Template(Partial)SpecializationDecl, and | |||
2171 | /// using Template(Partial)SpecializationDecl as input type. | |||
2172 | ASTDeclReader::RedeclarableResult | |||
2173 | ASTDeclReader::VisitVarTemplateSpecializationDeclImpl( | |||
2174 | VarTemplateSpecializationDecl *D) { | |||
2175 | RedeclarableResult Redecl = VisitVarDeclImpl(D); | |||
2176 | ||||
2177 | ASTContext &C = Reader.getContext(); | |||
2178 | if (Decl *InstD = ReadDecl()) { | |||
2179 | if (VarTemplateDecl *VTD = dyn_cast<VarTemplateDecl>(InstD)) { | |||
2180 | D->SpecializedTemplate = VTD; | |||
2181 | } else { | |||
2182 | SmallVector<TemplateArgument, 8> TemplArgs; | |||
2183 | Record.readTemplateArgumentList(TemplArgs); | |||
2184 | TemplateArgumentList *ArgList = TemplateArgumentList::CreateCopy( | |||
2185 | C, TemplArgs); | |||
2186 | VarTemplateSpecializationDecl::SpecializedPartialSpecialization *PS = | |||
2187 | new (C) | |||
2188 | VarTemplateSpecializationDecl::SpecializedPartialSpecialization(); | |||
2189 | PS->PartialSpecialization = | |||
2190 | cast<VarTemplatePartialSpecializationDecl>(InstD); | |||
2191 | PS->TemplateArgs = ArgList; | |||
2192 | D->SpecializedTemplate = PS; | |||
2193 | } | |||
2194 | } | |||
2195 | ||||
2196 | // Explicit info. | |||
2197 | if (TypeSourceInfo *TyInfo = GetTypeSourceInfo()) { | |||
2198 | VarTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo = | |||
2199 | new (C) VarTemplateSpecializationDecl::ExplicitSpecializationInfo; | |||
2200 | ExplicitInfo->TypeAsWritten = TyInfo; | |||
2201 | ExplicitInfo->ExternLoc = ReadSourceLocation(); | |||
2202 | ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(); | |||
2203 | D->ExplicitInfo = ExplicitInfo; | |||
2204 | } | |||
2205 | ||||
2206 | SmallVector<TemplateArgument, 8> TemplArgs; | |||
2207 | Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true); | |||
2208 | D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs); | |||
2209 | D->PointOfInstantiation = ReadSourceLocation(); | |||
2210 | D->SpecializationKind = (TemplateSpecializationKind)Record.readInt(); | |||
2211 | D->IsCompleteDefinition = Record.readInt(); | |||
2212 | ||||
2213 | bool writtenAsCanonicalDecl = Record.readInt(); | |||
2214 | if (writtenAsCanonicalDecl) { | |||
2215 | VarTemplateDecl *CanonPattern = ReadDeclAs<VarTemplateDecl>(); | |||
2216 | if (D->isCanonicalDecl()) { // It's kept in the folding set. | |||
2217 | // FIXME: If it's already present, merge it. | |||
2218 | if (VarTemplatePartialSpecializationDecl *Partial = | |||
2219 | dyn_cast<VarTemplatePartialSpecializationDecl>(D)) { | |||
2220 | CanonPattern->getCommonPtr()->PartialSpecializations | |||
2221 | .GetOrInsertNode(Partial); | |||
2222 | } else { | |||
2223 | CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D); | |||
2224 | } | |||
2225 | } | |||
2226 | } | |||
2227 | ||||
2228 | return Redecl; | |||
2229 | } | |||
2230 | ||||
2231 | /// TODO: Unify with ClassTemplatePartialSpecializationDecl version? | |||
2232 | /// May require unifying ClassTemplate(Partial)SpecializationDecl and | |||
2233 | /// VarTemplate(Partial)SpecializationDecl with a new data | |||
2234 | /// structure Template(Partial)SpecializationDecl, and | |||
2235 | /// using Template(Partial)SpecializationDecl as input type. | |||
2236 | void ASTDeclReader::VisitVarTemplatePartialSpecializationDecl( | |||
2237 | VarTemplatePartialSpecializationDecl *D) { | |||
2238 | RedeclarableResult Redecl = VisitVarTemplateSpecializationDeclImpl(D); | |||
2239 | ||||
2240 | D->TemplateParams = Record.readTemplateParameterList(); | |||
2241 | D->ArgsAsWritten = Record.readASTTemplateArgumentListInfo(); | |||
2242 | ||||
2243 | // These are read/set from/to the first declaration. | |||
2244 | if (ThisDeclID == Redecl.getFirstID()) { | |||
2245 | D->InstantiatedFromMember.setPointer( | |||
2246 | ReadDeclAs<VarTemplatePartialSpecializationDecl>()); | |||
2247 | D->InstantiatedFromMember.setInt(Record.readInt()); | |||
2248 | } | |||
2249 | } | |||
2250 | ||||
2251 | void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { | |||
2252 | VisitTypeDecl(D); | |||
2253 | ||||
2254 | D->setDeclaredWithTypename(Record.readInt()); | |||
2255 | ||||
2256 | if (Record.readInt()) | |||
2257 | D->setDefaultArgument(GetTypeSourceInfo()); | |||
2258 | } | |||
2259 | ||||
2260 | void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { | |||
2261 | VisitDeclaratorDecl(D); | |||
2262 | // TemplateParmPosition. | |||
2263 | D->setDepth(Record.readInt()); | |||
2264 | D->setPosition(Record.readInt()); | |||
2265 | if (D->isExpandedParameterPack()) { | |||
2266 | auto TypesAndInfos = | |||
2267 | D->getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>(); | |||
2268 | for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) { | |||
2269 | new (&TypesAndInfos[I].first) QualType(Record.readType()); | |||
2270 | TypesAndInfos[I].second = GetTypeSourceInfo(); | |||
2271 | } | |||
2272 | } else { | |||
2273 | // Rest of NonTypeTemplateParmDecl. | |||
2274 | D->ParameterPack = Record.readInt(); | |||
2275 | if (Record.readInt()) | |||
2276 | D->setDefaultArgument(Record.readExpr()); | |||
2277 | } | |||
2278 | } | |||
2279 | ||||
2280 | void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { | |||
2281 | VisitTemplateDecl(D); | |||
2282 | // TemplateParmPosition. | |||
2283 | D->setDepth(Record.readInt()); | |||
2284 | D->setPosition(Record.readInt()); | |||
2285 | if (D->isExpandedParameterPack()) { | |||
2286 | TemplateParameterList **Data = | |||
2287 | D->getTrailingObjects<TemplateParameterList *>(); | |||
2288 | for (unsigned I = 0, N = D->getNumExpansionTemplateParameters(); | |||
2289 | I != N; ++I) | |||
2290 | Data[I] = Record.readTemplateParameterList(); | |||
2291 | } else { | |||
2292 | // Rest of TemplateTemplateParmDecl. | |||
2293 | D->ParameterPack = Record.readInt(); | |||
2294 | if (Record.readInt()) | |||
2295 | D->setDefaultArgument(Reader.getContext(), | |||
2296 | Record.readTemplateArgumentLoc()); | |||
2297 | } | |||
2298 | } | |||
2299 | ||||
2300 | void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { | |||
2301 | VisitRedeclarableTemplateDecl(D); | |||
2302 | } | |||
2303 | ||||
2304 | void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) { | |||
2305 | VisitDecl(D); | |||
2306 | D->AssertExprAndFailed.setPointer(Record.readExpr()); | |||
2307 | D->AssertExprAndFailed.setInt(Record.readInt()); | |||
2308 | D->Message = cast_or_null<StringLiteral>(Record.readExpr()); | |||
2309 | D->RParenLoc = ReadSourceLocation(); | |||
2310 | } | |||
2311 | ||||
2312 | void ASTDeclReader::VisitEmptyDecl(EmptyDecl *D) { | |||
2313 | VisitDecl(D); | |||
2314 | } | |||
2315 | ||||
2316 | std::pair<uint64_t, uint64_t> | |||
2317 | ASTDeclReader::VisitDeclContext(DeclContext *DC) { | |||
2318 | uint64_t LexicalOffset = ReadLocalOffset(); | |||
2319 | uint64_t VisibleOffset = ReadLocalOffset(); | |||
2320 | return std::make_pair(LexicalOffset, VisibleOffset); | |||
2321 | } | |||
2322 | ||||
2323 | template <typename T> | |||
2324 | ASTDeclReader::RedeclarableResult | |||
2325 | ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) { | |||
2326 | DeclID FirstDeclID = ReadDeclID(); | |||
2327 | Decl *MergeWith = nullptr; | |||
2328 | ||||
2329 | bool IsKeyDecl = ThisDeclID == FirstDeclID; | |||
2330 | bool IsFirstLocalDecl = false; | |||
2331 | ||||
2332 | uint64_t RedeclOffset = 0; | |||
2333 | ||||
2334 | // 0 indicates that this declaration was the only declaration of its entity, | |||
2335 | // and is used for space optimization. | |||
2336 | if (FirstDeclID == 0) { | |||
2337 | FirstDeclID = ThisDeclID; | |||
2338 | IsKeyDecl = true; | |||
2339 | IsFirstLocalDecl = true; | |||
2340 | } else if (unsigned N = Record.readInt()) { | |||
2341 | // This declaration was the first local declaration, but may have imported | |||
2342 | // other declarations. | |||
2343 | IsKeyDecl = N == 1; | |||
2344 | IsFirstLocalDecl = true; | |||
2345 | ||||
2346 | // We have some declarations that must be before us in our redeclaration | |||
2347 | // chain. Read them now, and remember that we ought to merge with one of | |||
2348 | // them. | |||
2349 | // FIXME: Provide a known merge target to the second and subsequent such | |||
2350 | // declaration. | |||
2351 | for (unsigned I = 0; I != N - 1; ++I) | |||
2352 | MergeWith = ReadDecl(); | |||
2353 | ||||
2354 | RedeclOffset = ReadLocalOffset(); | |||
2355 | } else { | |||
2356 | // This declaration was not the first local declaration. Read the first | |||
2357 | // local declaration now, to trigger the import of other redeclarations. | |||
2358 | (void)ReadDecl(); | |||
2359 | } | |||
2360 | ||||
2361 | T *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID)); | |||
2362 | if (FirstDecl != D) { | |||
2363 | // We delay loading of the redeclaration chain to avoid deeply nested calls. | |||
2364 | // We temporarily set the first (canonical) declaration as the previous one | |||
2365 | // which is the one that matters and mark the real previous DeclID to be | |||
2366 | // loaded & attached later on. | |||
2367 | D->RedeclLink = Redeclarable<T>::PreviousDeclLink(FirstDecl); | |||
2368 | D->First = FirstDecl->getCanonicalDecl(); | |||
2369 | } | |||
2370 | ||||
2371 | T *DAsT = static_cast<T*>(D); | |||
2372 | ||||
2373 | // Note that we need to load local redeclarations of this decl and build a | |||
2374 | // decl chain for them. This must happen *after* we perform the preloading | |||
2375 | // above; this ensures that the redeclaration chain is built in the correct | |||
2376 | // order. | |||
2377 | if (IsFirstLocalDecl) | |||
2378 | Reader.PendingDeclChains.push_back(std::make_pair(DAsT, RedeclOffset)); | |||
2379 | ||||
2380 | return RedeclarableResult(MergeWith, FirstDeclID, IsKeyDecl); | |||
2381 | } | |||
2382 | ||||
2383 | /// \brief Attempts to merge the given declaration (D) with another declaration | |||
2384 | /// of the same entity. | |||
2385 | template<typename T> | |||
2386 | void ASTDeclReader::mergeRedeclarable(Redeclarable<T> *DBase, | |||
2387 | RedeclarableResult &Redecl, | |||
2388 | DeclID TemplatePatternID) { | |||
2389 | // If modules are not available, there is no reason to perform this merge. | |||
2390 | if (!Reader.getContext().getLangOpts().Modules) | |||
2391 | return; | |||
2392 | ||||
2393 | // If we're not the canonical declaration, we don't need to merge. | |||
2394 | if (!DBase->isFirstDecl()) | |||
2395 | return; | |||
2396 | ||||
2397 | T *D = static_cast<T*>(DBase); | |||
2398 | ||||
2399 | if (auto *Existing = Redecl.getKnownMergeTarget()) | |||
2400 | // We already know of an existing declaration we should merge with. | |||
2401 | mergeRedeclarable(D, cast<T>(Existing), Redecl, TemplatePatternID); | |||
2402 | else if (FindExistingResult ExistingRes = findExisting(D)) | |||
2403 | if (T *Existing = ExistingRes) | |||
2404 | mergeRedeclarable(D, Existing, Redecl, TemplatePatternID); | |||
2405 | } | |||
2406 | ||||
2407 | /// \brief "Cast" to type T, asserting if we don't have an implicit conversion. | |||
2408 | /// We use this to put code in a template that will only be valid for certain | |||
2409 | /// instantiations. | |||
2410 | template<typename T> static T assert_cast(T t) { return t; } | |||
2411 | template<typename T> static T assert_cast(...) { | |||
2412 | llvm_unreachable("bad assert_cast")::llvm::llvm_unreachable_internal("bad assert_cast", "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 2412); | |||
2413 | } | |||
2414 | ||||
2415 | /// \brief Merge together the pattern declarations from two template | |||
2416 | /// declarations. | |||
2417 | void ASTDeclReader::mergeTemplatePattern(RedeclarableTemplateDecl *D, | |||
2418 | RedeclarableTemplateDecl *Existing, | |||
2419 | DeclID DsID, bool IsKeyDecl) { | |||
2420 | auto *DPattern = D->getTemplatedDecl(); | |||
2421 | auto *ExistingPattern = Existing->getTemplatedDecl(); | |||
2422 | RedeclarableResult Result(/*MergeWith*/ ExistingPattern, | |||
2423 | DPattern->getCanonicalDecl()->getGlobalID(), | |||
2424 | IsKeyDecl); | |||
2425 | ||||
2426 | if (auto *DClass = dyn_cast<CXXRecordDecl>(DPattern)) { | |||
2427 | // Merge with any existing definition. | |||
2428 | // FIXME: This is duplicated in several places. Refactor. | |||
2429 | auto *ExistingClass = | |||
2430 | cast<CXXRecordDecl>(ExistingPattern)->getCanonicalDecl(); | |||
2431 | if (auto *DDD = DClass->DefinitionData) { | |||
2432 | if (ExistingClass->DefinitionData) { | |||
2433 | MergeDefinitionData(ExistingClass, std::move(*DDD)); | |||
2434 | } else { | |||
2435 | ExistingClass->DefinitionData = DClass->DefinitionData; | |||
2436 | // We may have skipped this before because we thought that DClass | |||
2437 | // was the canonical declaration. | |||
2438 | Reader.PendingDefinitions.insert(DClass); | |||
2439 | } | |||
2440 | } | |||
2441 | DClass->DefinitionData = ExistingClass->DefinitionData; | |||
2442 | ||||
2443 | return mergeRedeclarable(DClass, cast<TagDecl>(ExistingPattern), | |||
2444 | Result); | |||
2445 | } | |||
2446 | if (auto *DFunction = dyn_cast<FunctionDecl>(DPattern)) | |||
2447 | return mergeRedeclarable(DFunction, cast<FunctionDecl>(ExistingPattern), | |||
2448 | Result); | |||
2449 | if (auto *DVar = dyn_cast<VarDecl>(DPattern)) | |||
2450 | return mergeRedeclarable(DVar, cast<VarDecl>(ExistingPattern), Result); | |||
2451 | if (auto *DAlias = dyn_cast<TypeAliasDecl>(DPattern)) | |||
2452 | return mergeRedeclarable(DAlias, cast<TypedefNameDecl>(ExistingPattern), | |||
2453 | Result); | |||
2454 | llvm_unreachable("merged an unknown kind of redeclarable template")::llvm::llvm_unreachable_internal("merged an unknown kind of redeclarable template" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 2454); | |||
2455 | } | |||
2456 | ||||
2457 | /// \brief Attempts to merge the given declaration (D) with another declaration | |||
2458 | /// of the same entity. | |||
2459 | template<typename T> | |||
2460 | void ASTDeclReader::mergeRedeclarable(Redeclarable<T> *DBase, T *Existing, | |||
2461 | RedeclarableResult &Redecl, | |||
2462 | DeclID TemplatePatternID) { | |||
2463 | T *D = static_cast<T*>(DBase); | |||
2464 | T *ExistingCanon = Existing->getCanonicalDecl(); | |||
2465 | T *DCanon = D->getCanonicalDecl(); | |||
2466 | if (ExistingCanon != DCanon) { | |||
2467 | assert(DCanon->getGlobalID() == Redecl.getFirstID() &&(static_cast <bool> (DCanon->getGlobalID() == Redecl .getFirstID() && "already merged this declaration") ? void (0) : __assert_fail ("DCanon->getGlobalID() == Redecl.getFirstID() && \"already merged this declaration\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 2468, __extension__ __PRETTY_FUNCTION__)) | |||
2468 | "already merged this declaration")(static_cast <bool> (DCanon->getGlobalID() == Redecl .getFirstID() && "already merged this declaration") ? void (0) : __assert_fail ("DCanon->getGlobalID() == Redecl.getFirstID() && \"already merged this declaration\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 2468, __extension__ __PRETTY_FUNCTION__)); | |||
2469 | ||||
2470 | // Have our redeclaration link point back at the canonical declaration | |||
2471 | // of the existing declaration, so that this declaration has the | |||
2472 | // appropriate canonical declaration. | |||
2473 | D->RedeclLink = Redeclarable<T>::PreviousDeclLink(ExistingCanon); | |||
2474 | D->First = ExistingCanon; | |||
2475 | ExistingCanon->Used |= D->Used; | |||
2476 | D->Used = false; | |||
2477 | ||||
2478 | // When we merge a namespace, update its pointer to the first namespace. | |||
2479 | // We cannot have loaded any redeclarations of this declaration yet, so | |||
2480 | // there's nothing else that needs to be updated. | |||
2481 | if (auto *Namespace = dyn_cast<NamespaceDecl>(D)) | |||
2482 | Namespace->AnonOrFirstNamespaceAndInline.setPointer( | |||
2483 | assert_cast<NamespaceDecl*>(ExistingCanon)); | |||
2484 | ||||
2485 | // When we merge a template, merge its pattern. | |||
2486 | if (auto *DTemplate = dyn_cast<RedeclarableTemplateDecl>(D)) | |||
2487 | mergeTemplatePattern( | |||
2488 | DTemplate, assert_cast<RedeclarableTemplateDecl*>(ExistingCanon), | |||
2489 | TemplatePatternID, Redecl.isKeyDecl()); | |||
2490 | ||||
2491 | // If this declaration is a key declaration, make a note of that. | |||
2492 | if (Redecl.isKeyDecl()) | |||
2493 | Reader.KeyDecls[ExistingCanon].push_back(Redecl.getFirstID()); | |||
2494 | } | |||
2495 | } | |||
2496 | ||||
2497 | /// \brief Attempts to merge the given declaration (D) with another declaration | |||
2498 | /// of the same entity, for the case where the entity is not actually | |||
2499 | /// redeclarable. This happens, for instance, when merging the fields of | |||
2500 | /// identical class definitions from two different modules. | |||
2501 | template<typename T> | |||
2502 | void ASTDeclReader::mergeMergeable(Mergeable<T> *D) { | |||
2503 | // If modules are not available, there is no reason to perform this merge. | |||
2504 | if (!Reader.getContext().getLangOpts().Modules) | |||
2505 | return; | |||
2506 | ||||
2507 | // ODR-based merging is only performed in C++. In C, identically-named things | |||
2508 | // in different translation units are not redeclarations (but may still have | |||
2509 | // compatible types). | |||
2510 | if (!Reader.getContext().getLangOpts().CPlusPlus) | |||
2511 | return; | |||
2512 | ||||
2513 | if (FindExistingResult ExistingRes = findExisting(static_cast<T*>(D))) | |||
2514 | if (T *Existing = ExistingRes) | |||
2515 | Reader.getContext().setPrimaryMergedDecl(static_cast<T *>(D), | |||
2516 | Existing->getCanonicalDecl()); | |||
2517 | } | |||
2518 | ||||
2519 | void ASTDeclReader::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) { | |||
2520 | VisitDecl(D); | |||
2521 | unsigned NumVars = D->varlist_size(); | |||
2522 | SmallVector<Expr *, 16> Vars; | |||
2523 | Vars.reserve(NumVars); | |||
2524 | for (unsigned i = 0; i != NumVars; ++i) { | |||
2525 | Vars.push_back(Record.readExpr()); | |||
2526 | } | |||
2527 | D->setVars(Vars); | |||
2528 | } | |||
2529 | ||||
2530 | void ASTDeclReader::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) { | |||
2531 | VisitValueDecl(D); | |||
2532 | D->setLocation(ReadSourceLocation()); | |||
2533 | D->setCombiner(Record.readExpr()); | |||
2534 | D->setInitializer( | |||
2535 | Record.readExpr(), | |||
2536 | static_cast<OMPDeclareReductionDecl::InitKind>(Record.readInt())); | |||
2537 | D->PrevDeclInScope = ReadDeclID(); | |||
2538 | } | |||
2539 | ||||
2540 | void ASTDeclReader::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) { | |||
2541 | VisitVarDecl(D); | |||
2542 | } | |||
2543 | ||||
2544 | //===----------------------------------------------------------------------===// | |||
2545 | // Attribute Reading | |||
2546 | //===----------------------------------------------------------------------===// | |||
2547 | ||||
2548 | /// \brief Reads attributes from the current stream position. | |||
2549 | void ASTReader::ReadAttributes(ASTRecordReader &Record, AttrVec &Attrs) { | |||
2550 | for (unsigned i = 0, e = Record.readInt(); i != e; ++i) { | |||
2551 | Attr *New = nullptr; | |||
2552 | attr::Kind Kind = (attr::Kind)Record.readInt(); | |||
2553 | SourceRange Range = Record.readSourceRange(); | |||
2554 | ASTContext &Context = getContext(); | |||
2555 | ||||
2556 | #include "clang/Serialization/AttrPCHRead.inc" | |||
2557 | ||||
2558 | assert(New && "Unable to decode attribute?")(static_cast <bool> (New && "Unable to decode attribute?" ) ? void (0) : __assert_fail ("New && \"Unable to decode attribute?\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 2558, __extension__ __PRETTY_FUNCTION__)); | |||
2559 | Attrs.push_back(New); | |||
2560 | } | |||
2561 | } | |||
2562 | ||||
2563 | //===----------------------------------------------------------------------===// | |||
2564 | // ASTReader Implementation | |||
2565 | //===----------------------------------------------------------------------===// | |||
2566 | ||||
2567 | /// \brief Note that we have loaded the declaration with the given | |||
2568 | /// Index. | |||
2569 | /// | |||
2570 | /// This routine notes that this declaration has already been loaded, | |||
2571 | /// so that future GetDecl calls will return this declaration rather | |||
2572 | /// than trying to load a new declaration. | |||
2573 | inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) { | |||
2574 | assert(!DeclsLoaded[Index] && "Decl loaded twice?")(static_cast <bool> (!DeclsLoaded[Index] && "Decl loaded twice?" ) ? void (0) : __assert_fail ("!DeclsLoaded[Index] && \"Decl loaded twice?\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 2574, __extension__ __PRETTY_FUNCTION__)); | |||
2575 | DeclsLoaded[Index] = D; | |||
2576 | } | |||
2577 | ||||
2578 | ||||
2579 | /// \brief Determine whether the consumer will be interested in seeing | |||
2580 | /// this declaration (via HandleTopLevelDecl). | |||
2581 | /// | |||
2582 | /// This routine should return true for anything that might affect | |||
2583 | /// code generation, e.g., inline function definitions, Objective-C | |||
2584 | /// declarations with metadata, etc. | |||
2585 | static bool isConsumerInterestedIn(ASTContext &Ctx, Decl *D, bool HasBody) { | |||
2586 | // An ObjCMethodDecl is never considered as "interesting" because its | |||
2587 | // implementation container always is. | |||
2588 | ||||
2589 | // An ImportDecl or VarDecl imported from a module map module will get | |||
2590 | // emitted when we import the relevant module. | |||
2591 | if (isa<ImportDecl>(D) || isa<VarDecl>(D)) { | |||
2592 | auto *M = D->getImportedOwningModule(); | |||
2593 | if (M && M->Kind == Module::ModuleMapModule && | |||
2594 | Ctx.DeclMustBeEmitted(D)) | |||
2595 | return false; | |||
2596 | } | |||
2597 | ||||
2598 | if (isa<FileScopeAsmDecl>(D) || | |||
2599 | isa<ObjCProtocolDecl>(D) || | |||
2600 | isa<ObjCImplDecl>(D) || | |||
2601 | isa<ImportDecl>(D) || | |||
2602 | isa<PragmaCommentDecl>(D) || | |||
2603 | isa<PragmaDetectMismatchDecl>(D)) | |||
2604 | return true; | |||
2605 | if (isa<OMPThreadPrivateDecl>(D) || isa<OMPDeclareReductionDecl>(D)) | |||
2606 | return !D->getDeclContext()->isFunctionOrMethod(); | |||
2607 | if (VarDecl *Var = dyn_cast<VarDecl>(D)) | |||
2608 | return Var->isFileVarDecl() && | |||
2609 | Var->isThisDeclarationADefinition() == VarDecl::Definition; | |||
2610 | if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D)) | |||
2611 | return Func->doesThisDeclarationHaveABody() || HasBody; | |||
2612 | ||||
2613 | if (auto *ES = D->getASTContext().getExternalSource()) | |||
2614 | if (ES->hasExternalDefinitions(D) == ExternalASTSource::EK_Never) | |||
2615 | return true; | |||
2616 | ||||
2617 | return false; | |||
2618 | } | |||
2619 | ||||
2620 | /// \brief Get the correct cursor and offset for loading a declaration. | |||
2621 | ASTReader::RecordLocation | |||
2622 | ASTReader::DeclCursorForID(DeclID ID, SourceLocation &Loc) { | |||
2623 | GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID); | |||
2624 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map")(static_cast <bool> (I != GlobalDeclMap.end() && "Corrupted global declaration map") ? void (0) : __assert_fail ("I != GlobalDeclMap.end() && \"Corrupted global declaration map\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 2624, __extension__ __PRETTY_FUNCTION__)); | |||
2625 | ModuleFile *M = I->second; | |||
2626 | const DeclOffset &DOffs = | |||
2627 | M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS]; | |||
2628 | Loc = TranslateSourceLocation(*M, DOffs.getLocation()); | |||
2629 | return RecordLocation(M, DOffs.BitOffset); | |||
2630 | } | |||
2631 | ||||
2632 | ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) { | |||
2633 | ContinuousRangeMap<uint64_t, ModuleFile*, 4>::iterator I | |||
2634 | = GlobalBitOffsetsMap.find(GlobalOffset); | |||
2635 | ||||
2636 | assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map")(static_cast <bool> (I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map") ? void (0) : __assert_fail ("I != GlobalBitOffsetsMap.end() && \"Corrupted global bit offsets map\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 2636, __extension__ __PRETTY_FUNCTION__)); | |||
2637 | return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset); | |||
2638 | } | |||
2639 | ||||
2640 | uint64_t ASTReader::getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset) { | |||
2641 | return LocalOffset + M.GlobalBitOffset; | |||
2642 | } | |||
2643 | ||||
2644 | static bool isSameTemplateParameterList(const TemplateParameterList *X, | |||
2645 | const TemplateParameterList *Y); | |||
2646 | ||||
2647 | /// \brief Determine whether two template parameters are similar enough | |||
2648 | /// that they may be used in declarations of the same template. | |||
2649 | static bool isSameTemplateParameter(const NamedDecl *X, | |||
2650 | const NamedDecl *Y) { | |||
2651 | if (X->getKind() != Y->getKind()) | |||
2652 | return false; | |||
2653 | ||||
2654 | if (const TemplateTypeParmDecl *TX = dyn_cast<TemplateTypeParmDecl>(X)) { | |||
2655 | const TemplateTypeParmDecl *TY = cast<TemplateTypeParmDecl>(Y); | |||
2656 | return TX->isParameterPack() == TY->isParameterPack(); | |||
2657 | } | |||
2658 | ||||
2659 | if (const NonTypeTemplateParmDecl *TX = dyn_cast<NonTypeTemplateParmDecl>(X)) { | |||
2660 | const NonTypeTemplateParmDecl *TY = cast<NonTypeTemplateParmDecl>(Y); | |||
2661 | return TX->isParameterPack() == TY->isParameterPack() && | |||
2662 | TX->getASTContext().hasSameType(TX->getType(), TY->getType()); | |||
2663 | } | |||
2664 | ||||
2665 | const TemplateTemplateParmDecl *TX = cast<TemplateTemplateParmDecl>(X); | |||
2666 | const TemplateTemplateParmDecl *TY = cast<TemplateTemplateParmDecl>(Y); | |||
2667 | return TX->isParameterPack() == TY->isParameterPack() && | |||
2668 | isSameTemplateParameterList(TX->getTemplateParameters(), | |||
2669 | TY->getTemplateParameters()); | |||
2670 | } | |||
2671 | ||||
2672 | static NamespaceDecl *getNamespace(const NestedNameSpecifier *X) { | |||
2673 | if (auto *NS = X->getAsNamespace()) | |||
2674 | return NS; | |||
2675 | if (auto *NAS = X->getAsNamespaceAlias()) | |||
2676 | return NAS->getNamespace(); | |||
2677 | return nullptr; | |||
2678 | } | |||
2679 | ||||
2680 | static bool isSameQualifier(const NestedNameSpecifier *X, | |||
2681 | const NestedNameSpecifier *Y) { | |||
2682 | if (auto *NSX = getNamespace(X)) { | |||
2683 | auto *NSY = getNamespace(Y); | |||
2684 | if (!NSY || NSX->getCanonicalDecl() != NSY->getCanonicalDecl()) | |||
2685 | return false; | |||
2686 | } else if (X->getKind() != Y->getKind()) | |||
2687 | return false; | |||
2688 | ||||
2689 | // FIXME: For namespaces and types, we're permitted to check that the entity | |||
2690 | // is named via the same tokens. We should probably do so. | |||
2691 | switch (X->getKind()) { | |||
2692 | case NestedNameSpecifier::Identifier: | |||
2693 | if (X->getAsIdentifier() != Y->getAsIdentifier()) | |||
2694 | return false; | |||
2695 | break; | |||
2696 | case NestedNameSpecifier::Namespace: | |||
2697 | case NestedNameSpecifier::NamespaceAlias: | |||
2698 | // We've already checked that we named the same namespace. | |||
2699 | break; | |||
2700 | case NestedNameSpecifier::TypeSpec: | |||
2701 | case NestedNameSpecifier::TypeSpecWithTemplate: | |||
2702 | if (X->getAsType()->getCanonicalTypeInternal() != | |||
2703 | Y->getAsType()->getCanonicalTypeInternal()) | |||
2704 | return false; | |||
2705 | break; | |||
2706 | case NestedNameSpecifier::Global: | |||
2707 | case NestedNameSpecifier::Super: | |||
2708 | return true; | |||
2709 | } | |||
2710 | ||||
2711 | // Recurse into earlier portion of NNS, if any. | |||
2712 | auto *PX = X->getPrefix(); | |||
2713 | auto *PY = Y->getPrefix(); | |||
2714 | if (PX && PY) | |||
2715 | return isSameQualifier(PX, PY); | |||
2716 | return !PX && !PY; | |||
2717 | } | |||
2718 | ||||
2719 | /// \brief Determine whether two template parameter lists are similar enough | |||
2720 | /// that they may be used in declarations of the same template. | |||
2721 | static bool isSameTemplateParameterList(const TemplateParameterList *X, | |||
2722 | const TemplateParameterList *Y) { | |||
2723 | if (X->size() != Y->size()) | |||
2724 | return false; | |||
2725 | ||||
2726 | for (unsigned I = 0, N = X->size(); I != N; ++I) | |||
2727 | if (!isSameTemplateParameter(X->getParam(I), Y->getParam(I))) | |||
2728 | return false; | |||
2729 | ||||
2730 | return true; | |||
2731 | } | |||
2732 | ||||
2733 | /// Determine whether the attributes we can overload on are identical for A and | |||
2734 | /// B. Will ignore any overloadable attrs represented in the type of A and B. | |||
2735 | static bool hasSameOverloadableAttrs(const FunctionDecl *A, | |||
2736 | const FunctionDecl *B) { | |||
2737 | // Note that pass_object_size attributes are represented in the function's | |||
2738 | // ExtParameterInfo, so we don't need to check them here. | |||
2739 | ||||
2740 | SmallVector<const EnableIfAttr *, 4> AEnableIfs; | |||
2741 | // Since this is an equality check, we can ignore that enable_if attrs show up | |||
2742 | // in reverse order. | |||
2743 | for (const auto *EIA : A->specific_attrs<EnableIfAttr>()) | |||
2744 | AEnableIfs.push_back(EIA); | |||
2745 | ||||
2746 | SmallVector<const EnableIfAttr *, 4> BEnableIfs; | |||
2747 | for (const auto *EIA : B->specific_attrs<EnableIfAttr>()) | |||
2748 | BEnableIfs.push_back(EIA); | |||
2749 | ||||
2750 | // Two very common cases: either we have 0 enable_if attrs, or we have an | |||
2751 | // unequal number of enable_if attrs. | |||
2752 | if (AEnableIfs.empty() && BEnableIfs.empty()) | |||
2753 | return true; | |||
2754 | ||||
2755 | if (AEnableIfs.size() != BEnableIfs.size()) | |||
2756 | return false; | |||
2757 | ||||
2758 | llvm::FoldingSetNodeID Cand1ID, Cand2ID; | |||
2759 | for (unsigned I = 0, E = AEnableIfs.size(); I != E; ++I) { | |||
2760 | Cand1ID.clear(); | |||
2761 | Cand2ID.clear(); | |||
2762 | ||||
2763 | AEnableIfs[I]->getCond()->Profile(Cand1ID, A->getASTContext(), true); | |||
2764 | BEnableIfs[I]->getCond()->Profile(Cand2ID, B->getASTContext(), true); | |||
2765 | if (Cand1ID != Cand2ID) | |||
2766 | return false; | |||
2767 | } | |||
2768 | ||||
2769 | return true; | |||
2770 | } | |||
2771 | ||||
2772 | /// \brief Determine whether the two declarations refer to the same entity. | |||
2773 | static bool isSameEntity(NamedDecl *X, NamedDecl *Y) { | |||
2774 | assert(X->getDeclName() == Y->getDeclName() && "Declaration name mismatch!")(static_cast <bool> (X->getDeclName() == Y->getDeclName () && "Declaration name mismatch!") ? void (0) : __assert_fail ("X->getDeclName() == Y->getDeclName() && \"Declaration name mismatch!\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 2774, __extension__ __PRETTY_FUNCTION__)); | |||
2775 | ||||
2776 | if (X == Y) | |||
2777 | return true; | |||
2778 | ||||
2779 | // Must be in the same context. | |||
2780 | if (!X->getDeclContext()->getRedeclContext()->Equals( | |||
2781 | Y->getDeclContext()->getRedeclContext())) | |||
2782 | return false; | |||
2783 | ||||
2784 | // Two typedefs refer to the same entity if they have the same underlying | |||
2785 | // type. | |||
2786 | if (TypedefNameDecl *TypedefX = dyn_cast<TypedefNameDecl>(X)) | |||
2787 | if (TypedefNameDecl *TypedefY = dyn_cast<TypedefNameDecl>(Y)) | |||
2788 | return X->getASTContext().hasSameType(TypedefX->getUnderlyingType(), | |||
2789 | TypedefY->getUnderlyingType()); | |||
2790 | ||||
2791 | // Must have the same kind. | |||
2792 | if (X->getKind() != Y->getKind()) | |||
2793 | return false; | |||
2794 | ||||
2795 | // Objective-C classes and protocols with the same name always match. | |||
2796 | if (isa<ObjCInterfaceDecl>(X) || isa<ObjCProtocolDecl>(X)) | |||
2797 | return true; | |||
2798 | ||||
2799 | if (isa<ClassTemplateSpecializationDecl>(X)) { | |||
2800 | // No need to handle these here: we merge them when adding them to the | |||
2801 | // template. | |||
2802 | return false; | |||
2803 | } | |||
2804 | ||||
2805 | // Compatible tags match. | |||
2806 | if (TagDecl *TagX = dyn_cast<TagDecl>(X)) { | |||
2807 | TagDecl *TagY = cast<TagDecl>(Y); | |||
2808 | return (TagX->getTagKind() == TagY->getTagKind()) || | |||
2809 | ((TagX->getTagKind() == TTK_Struct || TagX->getTagKind() == TTK_Class || | |||
2810 | TagX->getTagKind() == TTK_Interface) && | |||
2811 | (TagY->getTagKind() == TTK_Struct || TagY->getTagKind() == TTK_Class || | |||
2812 | TagY->getTagKind() == TTK_Interface)); | |||
2813 | } | |||
2814 | ||||
2815 | // Functions with the same type and linkage match. | |||
2816 | // FIXME: This needs to cope with merging of prototyped/non-prototyped | |||
2817 | // functions, etc. | |||
2818 | if (FunctionDecl *FuncX = dyn_cast<FunctionDecl>(X)) { | |||
2819 | FunctionDecl *FuncY = cast<FunctionDecl>(Y); | |||
2820 | if (CXXConstructorDecl *CtorX = dyn_cast<CXXConstructorDecl>(X)) { | |||
2821 | CXXConstructorDecl *CtorY = cast<CXXConstructorDecl>(Y); | |||
2822 | if (CtorX->getInheritedConstructor() && | |||
2823 | !isSameEntity(CtorX->getInheritedConstructor().getConstructor(), | |||
2824 | CtorY->getInheritedConstructor().getConstructor())) | |||
2825 | return false; | |||
2826 | } | |||
2827 | ||||
2828 | if (FuncX->isMultiVersion() != FuncY->isMultiVersion()) | |||
2829 | return false; | |||
2830 | ||||
2831 | // Multiversioned functions with different feature strings are represented | |||
2832 | // as separate declarations. | |||
2833 | if (FuncX->isMultiVersion()) { | |||
2834 | const auto *TAX = FuncX->getAttr<TargetAttr>(); | |||
2835 | const auto *TAY = FuncY->getAttr<TargetAttr>(); | |||
2836 | assert(TAX && TAY && "Multiversion Function without target attribute")(static_cast <bool> (TAX && TAY && "Multiversion Function without target attribute" ) ? void (0) : __assert_fail ("TAX && TAY && \"Multiversion Function without target attribute\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 2836, __extension__ __PRETTY_FUNCTION__)); | |||
2837 | ||||
2838 | if (TAX->getFeaturesStr() != TAY->getFeaturesStr()) | |||
2839 | return false; | |||
2840 | } | |||
2841 | ||||
2842 | ASTContext &C = FuncX->getASTContext(); | |||
2843 | if (!C.hasSameType(FuncX->getType(), FuncY->getType())) { | |||
2844 | // We can get functions with different types on the redecl chain in C++17 | |||
2845 | // if they have differing exception specifications and at least one of | |||
2846 | // the excpetion specs is unresolved. | |||
2847 | // FIXME: Do we need to check for C++14 deduced return types here too? | |||
2848 | auto *XFPT = FuncX->getType()->getAs<FunctionProtoType>(); | |||
2849 | auto *YFPT = FuncY->getType()->getAs<FunctionProtoType>(); | |||
2850 | if (C.getLangOpts().CPlusPlus17 && XFPT && YFPT && | |||
2851 | (isUnresolvedExceptionSpec(XFPT->getExceptionSpecType()) || | |||
2852 | isUnresolvedExceptionSpec(YFPT->getExceptionSpecType())) && | |||
2853 | C.hasSameFunctionTypeIgnoringExceptionSpec(FuncX->getType(), | |||
2854 | FuncY->getType())) | |||
2855 | return true; | |||
2856 | return false; | |||
2857 | } | |||
2858 | return FuncX->getLinkageInternal() == FuncY->getLinkageInternal() && | |||
2859 | hasSameOverloadableAttrs(FuncX, FuncY); | |||
2860 | } | |||
2861 | ||||
2862 | // Variables with the same type and linkage match. | |||
2863 | if (VarDecl *VarX = dyn_cast<VarDecl>(X)) { | |||
2864 | VarDecl *VarY = cast<VarDecl>(Y); | |||
2865 | if (VarX->getLinkageInternal() == VarY->getLinkageInternal()) { | |||
2866 | ASTContext &C = VarX->getASTContext(); | |||
2867 | if (C.hasSameType(VarX->getType(), VarY->getType())) | |||
2868 | return true; | |||
2869 | ||||
2870 | // We can get decls with different types on the redecl chain. Eg. | |||
2871 | // template <typename T> struct S { static T Var[]; }; // #1 | |||
2872 | // template <typename T> T S<T>::Var[sizeof(T)]; // #2 | |||
2873 | // Only? happens when completing an incomplete array type. In this case | |||
2874 | // when comparing #1 and #2 we should go through their element type. | |||
2875 | const ArrayType *VarXTy = C.getAsArrayType(VarX->getType()); | |||
2876 | const ArrayType *VarYTy = C.getAsArrayType(VarY->getType()); | |||
2877 | if (!VarXTy || !VarYTy) | |||
2878 | return false; | |||
2879 | if (VarXTy->isIncompleteArrayType() || VarYTy->isIncompleteArrayType()) | |||
2880 | return C.hasSameType(VarXTy->getElementType(), VarYTy->getElementType()); | |||
2881 | } | |||
2882 | return false; | |||
2883 | } | |||
2884 | ||||
2885 | // Namespaces with the same name and inlinedness match. | |||
2886 | if (NamespaceDecl *NamespaceX = dyn_cast<NamespaceDecl>(X)) { | |||
2887 | NamespaceDecl *NamespaceY = cast<NamespaceDecl>(Y); | |||
2888 | return NamespaceX->isInline() == NamespaceY->isInline(); | |||
2889 | } | |||
2890 | ||||
2891 | // Identical template names and kinds match if their template parameter lists | |||
2892 | // and patterns match. | |||
2893 | if (TemplateDecl *TemplateX = dyn_cast<TemplateDecl>(X)) { | |||
2894 | TemplateDecl *TemplateY = cast<TemplateDecl>(Y); | |||
2895 | return isSameEntity(TemplateX->getTemplatedDecl(), | |||
2896 | TemplateY->getTemplatedDecl()) && | |||
2897 | isSameTemplateParameterList(TemplateX->getTemplateParameters(), | |||
2898 | TemplateY->getTemplateParameters()); | |||
2899 | } | |||
2900 | ||||
2901 | // Fields with the same name and the same type match. | |||
2902 | if (FieldDecl *FDX = dyn_cast<FieldDecl>(X)) { | |||
2903 | FieldDecl *FDY = cast<FieldDecl>(Y); | |||
2904 | // FIXME: Also check the bitwidth is odr-equivalent, if any. | |||
2905 | return X->getASTContext().hasSameType(FDX->getType(), FDY->getType()); | |||
2906 | } | |||
2907 | ||||
2908 | // Indirect fields with the same target field match. | |||
2909 | if (auto *IFDX = dyn_cast<IndirectFieldDecl>(X)) { | |||
2910 | auto *IFDY = cast<IndirectFieldDecl>(Y); | |||
2911 | return IFDX->getAnonField()->getCanonicalDecl() == | |||
2912 | IFDY->getAnonField()->getCanonicalDecl(); | |||
2913 | } | |||
2914 | ||||
2915 | // Enumerators with the same name match. | |||
2916 | if (isa<EnumConstantDecl>(X)) | |||
2917 | // FIXME: Also check the value is odr-equivalent. | |||
2918 | return true; | |||
2919 | ||||
2920 | // Using shadow declarations with the same target match. | |||
2921 | if (UsingShadowDecl *USX = dyn_cast<UsingShadowDecl>(X)) { | |||
2922 | UsingShadowDecl *USY = cast<UsingShadowDecl>(Y); | |||
2923 | return USX->getTargetDecl() == USY->getTargetDecl(); | |||
2924 | } | |||
2925 | ||||
2926 | // Using declarations with the same qualifier match. (We already know that | |||
2927 | // the name matches.) | |||
2928 | if (auto *UX = dyn_cast<UsingDecl>(X)) { | |||
2929 | auto *UY = cast<UsingDecl>(Y); | |||
2930 | return isSameQualifier(UX->getQualifier(), UY->getQualifier()) && | |||
2931 | UX->hasTypename() == UY->hasTypename() && | |||
2932 | UX->isAccessDeclaration() == UY->isAccessDeclaration(); | |||
2933 | } | |||
2934 | if (auto *UX = dyn_cast<UnresolvedUsingValueDecl>(X)) { | |||
2935 | auto *UY = cast<UnresolvedUsingValueDecl>(Y); | |||
2936 | return isSameQualifier(UX->getQualifier(), UY->getQualifier()) && | |||
2937 | UX->isAccessDeclaration() == UY->isAccessDeclaration(); | |||
2938 | } | |||
2939 | if (auto *UX = dyn_cast<UnresolvedUsingTypenameDecl>(X)) | |||
2940 | return isSameQualifier( | |||
2941 | UX->getQualifier(), | |||
2942 | cast<UnresolvedUsingTypenameDecl>(Y)->getQualifier()); | |||
2943 | ||||
2944 | // Namespace alias definitions with the same target match. | |||
2945 | if (auto *NAX = dyn_cast<NamespaceAliasDecl>(X)) { | |||
2946 | auto *NAY = cast<NamespaceAliasDecl>(Y); | |||
2947 | return NAX->getNamespace()->Equals(NAY->getNamespace()); | |||
2948 | } | |||
2949 | ||||
2950 | return false; | |||
2951 | } | |||
2952 | ||||
2953 | /// Find the context in which we should search for previous declarations when | |||
2954 | /// looking for declarations to merge. | |||
2955 | DeclContext *ASTDeclReader::getPrimaryContextForMerging(ASTReader &Reader, | |||
2956 | DeclContext *DC) { | |||
2957 | if (NamespaceDecl *ND = dyn_cast<NamespaceDecl>(DC)) | |||
2958 | return ND->getOriginalNamespace(); | |||
2959 | ||||
2960 | if (CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(DC)) { | |||
2961 | // Try to dig out the definition. | |||
2962 | auto *DD = RD->DefinitionData; | |||
2963 | if (!DD) | |||
2964 | DD = RD->getCanonicalDecl()->DefinitionData; | |||
2965 | ||||
2966 | // If there's no definition yet, then DC's definition is added by an update | |||
2967 | // record, but we've not yet loaded that update record. In this case, we | |||
2968 | // commit to DC being the canonical definition now, and will fix this when | |||
2969 | // we load the update record. | |||
2970 | if (!DD) { | |||
2971 | DD = new (Reader.getContext()) struct CXXRecordDecl::DefinitionData(RD); | |||
2972 | RD->IsCompleteDefinition = true; | |||
2973 | RD->DefinitionData = DD; | |||
2974 | RD->getCanonicalDecl()->DefinitionData = DD; | |||
2975 | ||||
2976 | // Track that we did this horrible thing so that we can fix it later. | |||
2977 | Reader.PendingFakeDefinitionData.insert( | |||
2978 | std::make_pair(DD, ASTReader::PendingFakeDefinitionKind::Fake)); | |||
2979 | } | |||
2980 | ||||
2981 | return DD->Definition; | |||
2982 | } | |||
2983 | ||||
2984 | if (EnumDecl *ED = dyn_cast<EnumDecl>(DC)) | |||
2985 | return ED->getASTContext().getLangOpts().CPlusPlus? ED->getDefinition() | |||
2986 | : nullptr; | |||
2987 | ||||
2988 | // We can see the TU here only if we have no Sema object. In that case, | |||
2989 | // there's no TU scope to look in, so using the DC alone is sufficient. | |||
2990 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) | |||
2991 | return TU; | |||
2992 | ||||
2993 | return nullptr; | |||
2994 | } | |||
2995 | ||||
2996 | ASTDeclReader::FindExistingResult::~FindExistingResult() { | |||
2997 | // Record that we had a typedef name for linkage whether or not we merge | |||
2998 | // with that declaration. | |||
2999 | if (TypedefNameForLinkage) { | |||
3000 | DeclContext *DC = New->getDeclContext()->getRedeclContext(); | |||
3001 | Reader.ImportedTypedefNamesForLinkage.insert( | |||
3002 | std::make_pair(std::make_pair(DC, TypedefNameForLinkage), New)); | |||
3003 | return; | |||
3004 | } | |||
3005 | ||||
3006 | if (!AddResult || Existing) | |||
3007 | return; | |||
3008 | ||||
3009 | DeclarationName Name = New->getDeclName(); | |||
3010 | DeclContext *DC = New->getDeclContext()->getRedeclContext(); | |||
3011 | if (needsAnonymousDeclarationNumber(New)) { | |||
3012 | setAnonymousDeclForMerging(Reader, New->getLexicalDeclContext(), | |||
3013 | AnonymousDeclNumber, New); | |||
3014 | } else if (DC->isTranslationUnit() && | |||
3015 | !Reader.getContext().getLangOpts().CPlusPlus) { | |||
3016 | if (Reader.getIdResolver().tryAddTopLevelDecl(New, Name)) | |||
3017 | Reader.PendingFakeLookupResults[Name.getAsIdentifierInfo()] | |||
3018 | .push_back(New); | |||
3019 | } else if (DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) { | |||
3020 | // Add the declaration to its redeclaration context so later merging | |||
3021 | // lookups will find it. | |||
3022 | MergeDC->makeDeclVisibleInContextImpl(New, /*Internal*/true); | |||
3023 | } | |||
3024 | } | |||
3025 | ||||
3026 | /// Find the declaration that should be merged into, given the declaration found | |||
3027 | /// by name lookup. If we're merging an anonymous declaration within a typedef, | |||
3028 | /// we need a matching typedef, and we merge with the type inside it. | |||
3029 | static NamedDecl *getDeclForMerging(NamedDecl *Found, | |||
3030 | bool IsTypedefNameForLinkage) { | |||
3031 | if (!IsTypedefNameForLinkage) | |||
3032 | return Found; | |||
3033 | ||||
3034 | // If we found a typedef declaration that gives a name to some other | |||
3035 | // declaration, then we want that inner declaration. Declarations from | |||
3036 | // AST files are handled via ImportedTypedefNamesForLinkage. | |||
3037 | if (Found->isFromASTFile()) | |||
3038 | return nullptr; | |||
3039 | ||||
3040 | if (auto *TND = dyn_cast<TypedefNameDecl>(Found)) | |||
3041 | return TND->getAnonDeclWithTypedefName(/*AnyRedecl*/true); | |||
3042 | ||||
3043 | return nullptr; | |||
3044 | } | |||
3045 | ||||
3046 | NamedDecl *ASTDeclReader::getAnonymousDeclForMerging(ASTReader &Reader, | |||
3047 | DeclContext *DC, | |||
3048 | unsigned Index) { | |||
3049 | // If the lexical context has been merged, look into the now-canonical | |||
3050 | // definition. | |||
3051 | if (auto *Merged = Reader.MergedDeclContexts.lookup(DC)) | |||
3052 | DC = Merged; | |||
3053 | ||||
3054 | // If we've seen this before, return the canonical declaration. | |||
3055 | auto &Previous = Reader.AnonymousDeclarationsForMerging[DC]; | |||
3056 | if (Index < Previous.size() && Previous[Index]) | |||
3057 | return Previous[Index]; | |||
3058 | ||||
3059 | // If this is the first time, but we have parsed a declaration of the context, | |||
3060 | // build the anonymous declaration list from the parsed declaration. | |||
3061 | if (!cast<Decl>(DC)->isFromASTFile()) { | |||
3062 | numberAnonymousDeclsWithin(DC, [&](NamedDecl *ND, unsigned Number) { | |||
3063 | if (Previous.size() == Number) | |||
3064 | Previous.push_back(cast<NamedDecl>(ND->getCanonicalDecl())); | |||
3065 | else | |||
3066 | Previous[Number] = cast<NamedDecl>(ND->getCanonicalDecl()); | |||
3067 | }); | |||
3068 | } | |||
3069 | ||||
3070 | return Index < Previous.size() ? Previous[Index] : nullptr; | |||
3071 | } | |||
3072 | ||||
3073 | void ASTDeclReader::setAnonymousDeclForMerging(ASTReader &Reader, | |||
3074 | DeclContext *DC, unsigned Index, | |||
3075 | NamedDecl *D) { | |||
3076 | if (auto *Merged = Reader.MergedDeclContexts.lookup(DC)) | |||
3077 | DC = Merged; | |||
3078 | ||||
3079 | auto &Previous = Reader.AnonymousDeclarationsForMerging[DC]; | |||
3080 | if (Index >= Previous.size()) | |||
3081 | Previous.resize(Index + 1); | |||
3082 | if (!Previous[Index]) | |||
3083 | Previous[Index] = D; | |||
3084 | } | |||
3085 | ||||
3086 | ASTDeclReader::FindExistingResult ASTDeclReader::findExisting(NamedDecl *D) { | |||
3087 | DeclarationName Name = TypedefNameForLinkage ? TypedefNameForLinkage | |||
3088 | : D->getDeclName(); | |||
3089 | ||||
3090 | if (!Name && !needsAnonymousDeclarationNumber(D)) { | |||
3091 | // Don't bother trying to find unnamed declarations that are in | |||
3092 | // unmergeable contexts. | |||
3093 | FindExistingResult Result(Reader, D, /*Existing=*/nullptr, | |||
3094 | AnonymousDeclNumber, TypedefNameForLinkage); | |||
3095 | Result.suppress(); | |||
3096 | return Result; | |||
3097 | } | |||
3098 | ||||
3099 | DeclContext *DC = D->getDeclContext()->getRedeclContext(); | |||
3100 | if (TypedefNameForLinkage) { | |||
3101 | auto It = Reader.ImportedTypedefNamesForLinkage.find( | |||
3102 | std::make_pair(DC, TypedefNameForLinkage)); | |||
3103 | if (It != Reader.ImportedTypedefNamesForLinkage.end()) | |||
3104 | if (isSameEntity(It->second, D)) | |||
3105 | return FindExistingResult(Reader, D, It->second, AnonymousDeclNumber, | |||
3106 | TypedefNameForLinkage); | |||
3107 | // Go on to check in other places in case an existing typedef name | |||
3108 | // was not imported. | |||
3109 | } | |||
3110 | ||||
3111 | if (needsAnonymousDeclarationNumber(D)) { | |||
3112 | // This is an anonymous declaration that we may need to merge. Look it up | |||
3113 | // in its context by number. | |||
3114 | if (auto *Existing = getAnonymousDeclForMerging( | |||
3115 | Reader, D->getLexicalDeclContext(), AnonymousDeclNumber)) | |||
3116 | if (isSameEntity(Existing, D)) | |||
3117 | return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber, | |||
3118 | TypedefNameForLinkage); | |||
3119 | } else if (DC->isTranslationUnit() && | |||
3120 | !Reader.getContext().getLangOpts().CPlusPlus) { | |||
3121 | IdentifierResolver &IdResolver = Reader.getIdResolver(); | |||
3122 | ||||
3123 | // Temporarily consider the identifier to be up-to-date. We don't want to | |||
3124 | // cause additional lookups here. | |||
3125 | class UpToDateIdentifierRAII { | |||
3126 | IdentifierInfo *II; | |||
3127 | bool WasOutToDate; | |||
3128 | ||||
3129 | public: | |||
3130 | explicit UpToDateIdentifierRAII(IdentifierInfo *II) | |||
3131 | : II(II), WasOutToDate(false) | |||
3132 | { | |||
3133 | if (II) { | |||
3134 | WasOutToDate = II->isOutOfDate(); | |||
3135 | if (WasOutToDate) | |||
3136 | II->setOutOfDate(false); | |||
3137 | } | |||
3138 | } | |||
3139 | ||||
3140 | ~UpToDateIdentifierRAII() { | |||
3141 | if (WasOutToDate) | |||
3142 | II->setOutOfDate(true); | |||
3143 | } | |||
3144 | } UpToDate(Name.getAsIdentifierInfo()); | |||
3145 | ||||
3146 | for (IdentifierResolver::iterator I = IdResolver.begin(Name), | |||
3147 | IEnd = IdResolver.end(); | |||
3148 | I != IEnd; ++I) { | |||
3149 | if (NamedDecl *Existing = getDeclForMerging(*I, TypedefNameForLinkage)) | |||
3150 | if (isSameEntity(Existing, D)) | |||
3151 | return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber, | |||
3152 | TypedefNameForLinkage); | |||
3153 | } | |||
3154 | } else if (DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) { | |||
3155 | DeclContext::lookup_result R = MergeDC->noload_lookup(Name); | |||
3156 | for (DeclContext::lookup_iterator I = R.begin(), E = R.end(); I != E; ++I) { | |||
3157 | if (NamedDecl *Existing = getDeclForMerging(*I, TypedefNameForLinkage)) | |||
3158 | if (isSameEntity(Existing, D)) | |||
3159 | return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber, | |||
3160 | TypedefNameForLinkage); | |||
3161 | } | |||
3162 | } else { | |||
3163 | // Not in a mergeable context. | |||
3164 | return FindExistingResult(Reader); | |||
3165 | } | |||
3166 | ||||
3167 | // If this declaration is from a merged context, make a note that we need to | |||
3168 | // check that the canonical definition of that context contains the decl. | |||
3169 | // | |||
3170 | // FIXME: We should do something similar if we merge two definitions of the | |||
3171 | // same template specialization into the same CXXRecordDecl. | |||
3172 | auto MergedDCIt = Reader.MergedDeclContexts.find(D->getLexicalDeclContext()); | |||
3173 | if (MergedDCIt != Reader.MergedDeclContexts.end() && | |||
3174 | MergedDCIt->second == D->getDeclContext()) | |||
3175 | Reader.PendingOdrMergeChecks.push_back(D); | |||
3176 | ||||
3177 | return FindExistingResult(Reader, D, /*Existing=*/nullptr, | |||
3178 | AnonymousDeclNumber, TypedefNameForLinkage); | |||
3179 | } | |||
3180 | ||||
3181 | template<typename DeclT> | |||
3182 | Decl *ASTDeclReader::getMostRecentDeclImpl(Redeclarable<DeclT> *D) { | |||
3183 | return D->RedeclLink.getLatestNotUpdated(); | |||
3184 | } | |||
3185 | Decl *ASTDeclReader::getMostRecentDeclImpl(...) { | |||
3186 | llvm_unreachable("getMostRecentDecl on non-redeclarable declaration")::llvm::llvm_unreachable_internal("getMostRecentDecl on non-redeclarable declaration" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 3186); | |||
3187 | } | |||
3188 | ||||
3189 | Decl *ASTDeclReader::getMostRecentDecl(Decl *D) { | |||
3190 | assert(D)(static_cast <bool> (D) ? void (0) : __assert_fail ("D" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 3190, __extension__ __PRETTY_FUNCTION__)); | |||
3191 | ||||
3192 | switch (D->getKind()) { | |||
3193 | #define ABSTRACT_DECL(TYPE) | |||
3194 | #define DECL(TYPE, BASE) \ | |||
3195 | case Decl::TYPE: \ | |||
3196 | return getMostRecentDeclImpl(cast<TYPE##Decl>(D)); | |||
3197 | #include "clang/AST/DeclNodes.inc" | |||
3198 | } | |||
3199 | llvm_unreachable("unknown decl kind")::llvm::llvm_unreachable_internal("unknown decl kind", "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 3199); | |||
3200 | } | |||
3201 | ||||
3202 | Decl *ASTReader::getMostRecentExistingDecl(Decl *D) { | |||
3203 | return ASTDeclReader::getMostRecentDecl(D->getCanonicalDecl()); | |||
3204 | } | |||
3205 | ||||
3206 | template<typename DeclT> | |||
3207 | void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, | |||
3208 | Redeclarable<DeclT> *D, | |||
3209 | Decl *Previous, Decl *Canon) { | |||
3210 | D->RedeclLink.setPrevious(cast<DeclT>(Previous)); | |||
3211 | D->First = cast<DeclT>(Previous)->First; | |||
3212 | } | |||
3213 | ||||
3214 | namespace clang { | |||
3215 | template<> | |||
3216 | void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, | |||
3217 | Redeclarable<VarDecl> *D, | |||
3218 | Decl *Previous, Decl *Canon) { | |||
3219 | VarDecl *VD = static_cast<VarDecl*>(D); | |||
3220 | VarDecl *PrevVD = cast<VarDecl>(Previous); | |||
3221 | D->RedeclLink.setPrevious(PrevVD); | |||
3222 | D->First = PrevVD->First; | |||
3223 | ||||
3224 | // We should keep at most one definition on the chain. | |||
3225 | // FIXME: Cache the definition once we've found it. Building a chain with | |||
3226 | // N definitions currently takes O(N^2) time here. | |||
3227 | if (VD->isThisDeclarationADefinition() == VarDecl::Definition) { | |||
3228 | for (VarDecl *CurD = PrevVD; CurD; CurD = CurD->getPreviousDecl()) { | |||
3229 | if (CurD->isThisDeclarationADefinition() == VarDecl::Definition) { | |||
3230 | Reader.mergeDefinitionVisibility(CurD, VD); | |||
3231 | VD->demoteThisDefinitionToDeclaration(); | |||
3232 | break; | |||
3233 | } | |||
3234 | } | |||
3235 | } | |||
3236 | } | |||
3237 | ||||
3238 | template<> | |||
3239 | void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, | |||
3240 | Redeclarable<FunctionDecl> *D, | |||
3241 | Decl *Previous, Decl *Canon) { | |||
3242 | FunctionDecl *FD = static_cast<FunctionDecl*>(D); | |||
3243 | FunctionDecl *PrevFD = cast<FunctionDecl>(Previous); | |||
3244 | ||||
3245 | FD->RedeclLink.setPrevious(PrevFD); | |||
3246 | FD->First = PrevFD->First; | |||
3247 | ||||
3248 | // If the previous declaration is an inline function declaration, then this | |||
3249 | // declaration is too. | |||
3250 | if (PrevFD->IsInline != FD->IsInline) { | |||
3251 | // FIXME: [dcl.fct.spec]p4: | |||
3252 | // If a function with external linkage is declared inline in one | |||
3253 | // translation unit, it shall be declared inline in all translation | |||
3254 | // units in which it appears. | |||
3255 | // | |||
3256 | // Be careful of this case: | |||
3257 | // | |||
3258 | // module A: | |||
3259 | // template<typename T> struct X { void f(); }; | |||
3260 | // template<typename T> inline void X<T>::f() {} | |||
3261 | // | |||
3262 | // module B instantiates the declaration of X<int>::f | |||
3263 | // module C instantiates the definition of X<int>::f | |||
3264 | // | |||
3265 | // If module B and C are merged, we do not have a violation of this rule. | |||
3266 | FD->IsInline = true; | |||
3267 | } | |||
3268 | ||||
3269 | // If we need to propagate an exception specification along the redecl | |||
3270 | // chain, make a note of that so that we can do so later. | |||
3271 | auto *FPT = FD->getType()->getAs<FunctionProtoType>(); | |||
3272 | auto *PrevFPT = PrevFD->getType()->getAs<FunctionProtoType>(); | |||
3273 | if (FPT && PrevFPT) { | |||
3274 | bool IsUnresolved = isUnresolvedExceptionSpec(FPT->getExceptionSpecType()); | |||
3275 | bool WasUnresolved = | |||
3276 | isUnresolvedExceptionSpec(PrevFPT->getExceptionSpecType()); | |||
3277 | if (IsUnresolved != WasUnresolved) | |||
3278 | Reader.PendingExceptionSpecUpdates.insert( | |||
3279 | std::make_pair(Canon, IsUnresolved ? PrevFD : FD)); | |||
3280 | } | |||
3281 | } | |||
3282 | } // end namespace clang | |||
3283 | ||||
3284 | void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, ...) { | |||
3285 | llvm_unreachable("attachPreviousDecl on non-redeclarable declaration")::llvm::llvm_unreachable_internal("attachPreviousDecl on non-redeclarable declaration" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 3285); | |||
3286 | } | |||
3287 | ||||
3288 | /// Inherit the default template argument from \p From to \p To. Returns | |||
3289 | /// \c false if there is no default template for \p From. | |||
3290 | template <typename ParmDecl> | |||
3291 | static bool inheritDefaultTemplateArgument(ASTContext &Context, ParmDecl *From, | |||
3292 | Decl *ToD) { | |||
3293 | auto *To = cast<ParmDecl>(ToD); | |||
3294 | if (!From->hasDefaultArgument()) | |||
3295 | return false; | |||
3296 | To->setInheritedDefaultArgument(Context, From); | |||
3297 | return true; | |||
3298 | } | |||
3299 | ||||
3300 | static void inheritDefaultTemplateArguments(ASTContext &Context, | |||
3301 | TemplateDecl *From, | |||
3302 | TemplateDecl *To) { | |||
3303 | auto *FromTP = From->getTemplateParameters(); | |||
3304 | auto *ToTP = To->getTemplateParameters(); | |||
3305 | assert(FromTP->size() == ToTP->size() && "merged mismatched templates?")(static_cast <bool> (FromTP->size() == ToTP->size () && "merged mismatched templates?") ? void (0) : __assert_fail ("FromTP->size() == ToTP->size() && \"merged mismatched templates?\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 3305, __extension__ __PRETTY_FUNCTION__)); | |||
3306 | ||||
3307 | for (unsigned I = 0, N = FromTP->size(); I != N; ++I) { | |||
3308 | NamedDecl *FromParam = FromTP->getParam(N - I - 1); | |||
3309 | if (FromParam->isParameterPack()) | |||
3310 | continue; | |||
3311 | NamedDecl *ToParam = ToTP->getParam(N - I - 1); | |||
3312 | ||||
3313 | if (auto *FTTP = dyn_cast<TemplateTypeParmDecl>(FromParam)) { | |||
3314 | if (!inheritDefaultTemplateArgument(Context, FTTP, ToParam)) | |||
3315 | break; | |||
3316 | } else if (auto *FNTTP = dyn_cast<NonTypeTemplateParmDecl>(FromParam)) { | |||
3317 | if (!inheritDefaultTemplateArgument(Context, FNTTP, ToParam)) | |||
3318 | break; | |||
3319 | } else { | |||
3320 | if (!inheritDefaultTemplateArgument( | |||
3321 | Context, cast<TemplateTemplateParmDecl>(FromParam), ToParam)) | |||
3322 | break; | |||
3323 | } | |||
3324 | } | |||
3325 | } | |||
3326 | ||||
3327 | void ASTDeclReader::attachPreviousDecl(ASTReader &Reader, Decl *D, | |||
3328 | Decl *Previous, Decl *Canon) { | |||
3329 | assert(D && Previous)(static_cast <bool> (D && Previous) ? void (0) : __assert_fail ("D && Previous", "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 3329, __extension__ __PRETTY_FUNCTION__)); | |||
3330 | ||||
3331 | switch (D->getKind()) { | |||
3332 | #define ABSTRACT_DECL(TYPE) | |||
3333 | #define DECL(TYPE, BASE) \ | |||
3334 | case Decl::TYPE: \ | |||
3335 | attachPreviousDeclImpl(Reader, cast<TYPE##Decl>(D), Previous, Canon); \ | |||
3336 | break; | |||
3337 | #include "clang/AST/DeclNodes.inc" | |||
3338 | } | |||
3339 | ||||
3340 | // If the declaration was visible in one module, a redeclaration of it in | |||
3341 | // another module remains visible even if it wouldn't be visible by itself. | |||
3342 | // | |||
3343 | // FIXME: In this case, the declaration should only be visible if a module | |||
3344 | // that makes it visible has been imported. | |||
3345 | D->IdentifierNamespace |= | |||
3346 | Previous->IdentifierNamespace & | |||
3347 | (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type); | |||
3348 | ||||
3349 | // If the declaration declares a template, it may inherit default arguments | |||
3350 | // from the previous declaration. | |||
3351 | if (TemplateDecl *TD = dyn_cast<TemplateDecl>(D)) | |||
3352 | inheritDefaultTemplateArguments(Reader.getContext(), | |||
3353 | cast<TemplateDecl>(Previous), TD); | |||
3354 | } | |||
3355 | ||||
3356 | template<typename DeclT> | |||
3357 | void ASTDeclReader::attachLatestDeclImpl(Redeclarable<DeclT> *D, Decl *Latest) { | |||
3358 | D->RedeclLink.setLatest(cast<DeclT>(Latest)); | |||
3359 | } | |||
3360 | void ASTDeclReader::attachLatestDeclImpl(...) { | |||
3361 | llvm_unreachable("attachLatestDecl on non-redeclarable declaration")::llvm::llvm_unreachable_internal("attachLatestDecl on non-redeclarable declaration" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 3361); | |||
3362 | } | |||
3363 | ||||
3364 | void ASTDeclReader::attachLatestDecl(Decl *D, Decl *Latest) { | |||
3365 | assert(D && Latest)(static_cast <bool> (D && Latest) ? void (0) : __assert_fail ("D && Latest", "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 3365, __extension__ __PRETTY_FUNCTION__)); | |||
3366 | ||||
3367 | switch (D->getKind()) { | |||
3368 | #define ABSTRACT_DECL(TYPE) | |||
3369 | #define DECL(TYPE, BASE) \ | |||
3370 | case Decl::TYPE: \ | |||
3371 | attachLatestDeclImpl(cast<TYPE##Decl>(D), Latest); \ | |||
3372 | break; | |||
3373 | #include "clang/AST/DeclNodes.inc" | |||
3374 | } | |||
3375 | } | |||
3376 | ||||
3377 | template<typename DeclT> | |||
3378 | void ASTDeclReader::markIncompleteDeclChainImpl(Redeclarable<DeclT> *D) { | |||
3379 | D->RedeclLink.markIncomplete(); | |||
3380 | } | |||
3381 | void ASTDeclReader::markIncompleteDeclChainImpl(...) { | |||
3382 | llvm_unreachable("markIncompleteDeclChain on non-redeclarable declaration")::llvm::llvm_unreachable_internal("markIncompleteDeclChain on non-redeclarable declaration" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 3382); | |||
3383 | } | |||
3384 | ||||
3385 | void ASTReader::markIncompleteDeclChain(Decl *D) { | |||
3386 | switch (D->getKind()) { | |||
3387 | #define ABSTRACT_DECL(TYPE) | |||
3388 | #define DECL(TYPE, BASE) \ | |||
3389 | case Decl::TYPE: \ | |||
3390 | ASTDeclReader::markIncompleteDeclChainImpl(cast<TYPE##Decl>(D)); \ | |||
3391 | break; | |||
3392 | #include "clang/AST/DeclNodes.inc" | |||
3393 | } | |||
3394 | } | |||
3395 | ||||
3396 | /// \brief Read the declaration at the given offset from the AST file. | |||
3397 | Decl *ASTReader::ReadDeclRecord(DeclID ID) { | |||
3398 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; | |||
3399 | SourceLocation DeclLoc; | |||
3400 | RecordLocation Loc = DeclCursorForID(ID, DeclLoc); | |||
3401 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; | |||
3402 | // Keep track of where we are in the stream, then jump back there | |||
3403 | // after reading this declaration. | |||
3404 | SavedStreamPosition SavedPosition(DeclsCursor); | |||
3405 | ||||
3406 | ReadingKindTracker ReadingKind(Read_Decl, *this); | |||
3407 | ||||
3408 | // Note that we are loading a declaration record. | |||
3409 | Deserializing ADecl(this); | |||
3410 | ||||
3411 | DeclsCursor.JumpToBit(Loc.Offset); | |||
3412 | ASTRecordReader Record(*this, *Loc.F); | |||
3413 | ASTDeclReader Reader(*this, Record, Loc, ID, DeclLoc); | |||
3414 | unsigned Code = DeclsCursor.ReadCode(); | |||
3415 | ||||
3416 | ASTContext &Context = getContext(); | |||
3417 | Decl *D = nullptr; | |||
3418 | switch ((DeclCode)Record.readRecord(DeclsCursor, Code)) { | |||
3419 | case DECL_CONTEXT_LEXICAL: | |||
3420 | case DECL_CONTEXT_VISIBLE: | |||
3421 | llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord")::llvm::llvm_unreachable_internal("Record cannot be de-serialized with ReadDeclRecord" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 3421); | |||
3422 | case DECL_TYPEDEF: | |||
3423 | D = TypedefDecl::CreateDeserialized(Context, ID); | |||
3424 | break; | |||
3425 | case DECL_TYPEALIAS: | |||
3426 | D = TypeAliasDecl::CreateDeserialized(Context, ID); | |||
3427 | break; | |||
3428 | case DECL_ENUM: | |||
3429 | D = EnumDecl::CreateDeserialized(Context, ID); | |||
3430 | break; | |||
3431 | case DECL_RECORD: | |||
3432 | D = RecordDecl::CreateDeserialized(Context, ID); | |||
3433 | break; | |||
3434 | case DECL_ENUM_CONSTANT: | |||
3435 | D = EnumConstantDecl::CreateDeserialized(Context, ID); | |||
3436 | break; | |||
3437 | case DECL_FUNCTION: | |||
3438 | D = FunctionDecl::CreateDeserialized(Context, ID); | |||
3439 | break; | |||
3440 | case DECL_LINKAGE_SPEC: | |||
3441 | D = LinkageSpecDecl::CreateDeserialized(Context, ID); | |||
3442 | break; | |||
3443 | case DECL_EXPORT: | |||
3444 | D = ExportDecl::CreateDeserialized(Context, ID); | |||
3445 | break; | |||
3446 | case DECL_LABEL: | |||
3447 | D = LabelDecl::CreateDeserialized(Context, ID); | |||
3448 | break; | |||
3449 | case DECL_NAMESPACE: | |||
3450 | D = NamespaceDecl::CreateDeserialized(Context, ID); | |||
3451 | break; | |||
3452 | case DECL_NAMESPACE_ALIAS: | |||
3453 | D = NamespaceAliasDecl::CreateDeserialized(Context, ID); | |||
3454 | break; | |||
3455 | case DECL_USING: | |||
3456 | D = UsingDecl::CreateDeserialized(Context, ID); | |||
3457 | break; | |||
3458 | case DECL_USING_PACK: | |||
3459 | D = UsingPackDecl::CreateDeserialized(Context, ID, Record.readInt()); | |||
3460 | break; | |||
3461 | case DECL_USING_SHADOW: | |||
3462 | D = UsingShadowDecl::CreateDeserialized(Context, ID); | |||
3463 | break; | |||
3464 | case DECL_CONSTRUCTOR_USING_SHADOW: | |||
3465 | D = ConstructorUsingShadowDecl::CreateDeserialized(Context, ID); | |||
3466 | break; | |||
3467 | case DECL_USING_DIRECTIVE: | |||
3468 | D = UsingDirectiveDecl::CreateDeserialized(Context, ID); | |||
3469 | break; | |||
3470 | case DECL_UNRESOLVED_USING_VALUE: | |||
3471 | D = UnresolvedUsingValueDecl::CreateDeserialized(Context, ID); | |||
3472 | break; | |||
3473 | case DECL_UNRESOLVED_USING_TYPENAME: | |||
3474 | D = UnresolvedUsingTypenameDecl::CreateDeserialized(Context, ID); | |||
3475 | break; | |||
3476 | case DECL_CXX_RECORD: | |||
3477 | D = CXXRecordDecl::CreateDeserialized(Context, ID); | |||
3478 | break; | |||
3479 | case DECL_CXX_DEDUCTION_GUIDE: | |||
3480 | D = CXXDeductionGuideDecl::CreateDeserialized(Context, ID); | |||
3481 | break; | |||
3482 | case DECL_CXX_METHOD: | |||
3483 | D = CXXMethodDecl::CreateDeserialized(Context, ID); | |||
3484 | break; | |||
3485 | case DECL_CXX_CONSTRUCTOR: | |||
3486 | D = CXXConstructorDecl::CreateDeserialized(Context, ID, false); | |||
3487 | break; | |||
3488 | case DECL_CXX_INHERITED_CONSTRUCTOR: | |||
3489 | D = CXXConstructorDecl::CreateDeserialized(Context, ID, true); | |||
3490 | break; | |||
3491 | case DECL_CXX_DESTRUCTOR: | |||
3492 | D = CXXDestructorDecl::CreateDeserialized(Context, ID); | |||
3493 | break; | |||
3494 | case DECL_CXX_CONVERSION: | |||
3495 | D = CXXConversionDecl::CreateDeserialized(Context, ID); | |||
3496 | break; | |||
3497 | case DECL_ACCESS_SPEC: | |||
3498 | D = AccessSpecDecl::CreateDeserialized(Context, ID); | |||
3499 | break; | |||
3500 | case DECL_FRIEND: | |||
3501 | D = FriendDecl::CreateDeserialized(Context, ID, Record.readInt()); | |||
3502 | break; | |||
3503 | case DECL_FRIEND_TEMPLATE: | |||
3504 | D = FriendTemplateDecl::CreateDeserialized(Context, ID); | |||
3505 | break; | |||
3506 | case DECL_CLASS_TEMPLATE: | |||
3507 | D = ClassTemplateDecl::CreateDeserialized(Context, ID); | |||
3508 | break; | |||
3509 | case DECL_CLASS_TEMPLATE_SPECIALIZATION: | |||
3510 | D = ClassTemplateSpecializationDecl::CreateDeserialized(Context, ID); | |||
3511 | break; | |||
3512 | case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION: | |||
3513 | D = ClassTemplatePartialSpecializationDecl::CreateDeserialized(Context, ID); | |||
3514 | break; | |||
3515 | case DECL_VAR_TEMPLATE: | |||
3516 | D = VarTemplateDecl::CreateDeserialized(Context, ID); | |||
3517 | break; | |||
3518 | case DECL_VAR_TEMPLATE_SPECIALIZATION: | |||
3519 | D = VarTemplateSpecializationDecl::CreateDeserialized(Context, ID); | |||
3520 | break; | |||
3521 | case DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION: | |||
3522 | D = VarTemplatePartialSpecializationDecl::CreateDeserialized(Context, ID); | |||
3523 | break; | |||
3524 | case DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION: | |||
3525 | D = ClassScopeFunctionSpecializationDecl::CreateDeserialized(Context, ID); | |||
3526 | break; | |||
3527 | case DECL_FUNCTION_TEMPLATE: | |||
3528 | D = FunctionTemplateDecl::CreateDeserialized(Context, ID); | |||
3529 | break; | |||
3530 | case DECL_TEMPLATE_TYPE_PARM: | |||
3531 | D = TemplateTypeParmDecl::CreateDeserialized(Context, ID); | |||
3532 | break; | |||
3533 | case DECL_NON_TYPE_TEMPLATE_PARM: | |||
3534 | D = NonTypeTemplateParmDecl::CreateDeserialized(Context, ID); | |||
3535 | break; | |||
3536 | case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK: | |||
3537 | D = NonTypeTemplateParmDecl::CreateDeserialized(Context, ID, | |||
3538 | Record.readInt()); | |||
3539 | break; | |||
3540 | case DECL_TEMPLATE_TEMPLATE_PARM: | |||
3541 | D = TemplateTemplateParmDecl::CreateDeserialized(Context, ID); | |||
3542 | break; | |||
3543 | case DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK: | |||
3544 | D = TemplateTemplateParmDecl::CreateDeserialized(Context, ID, | |||
3545 | Record.readInt()); | |||
3546 | break; | |||
3547 | case DECL_TYPE_ALIAS_TEMPLATE: | |||
3548 | D = TypeAliasTemplateDecl::CreateDeserialized(Context, ID); | |||
3549 | break; | |||
3550 | case DECL_STATIC_ASSERT: | |||
3551 | D = StaticAssertDecl::CreateDeserialized(Context, ID); | |||
3552 | break; | |||
3553 | case DECL_OBJC_METHOD: | |||
3554 | D = ObjCMethodDecl::CreateDeserialized(Context, ID); | |||
3555 | break; | |||
3556 | case DECL_OBJC_INTERFACE: | |||
3557 | D = ObjCInterfaceDecl::CreateDeserialized(Context, ID); | |||
3558 | break; | |||
3559 | case DECL_OBJC_IVAR: | |||
3560 | D = ObjCIvarDecl::CreateDeserialized(Context, ID); | |||
3561 | break; | |||
3562 | case DECL_OBJC_PROTOCOL: | |||
3563 | D = ObjCProtocolDecl::CreateDeserialized(Context, ID); | |||
3564 | break; | |||
3565 | case DECL_OBJC_AT_DEFS_FIELD: | |||
3566 | D = ObjCAtDefsFieldDecl::CreateDeserialized(Context, ID); | |||
3567 | break; | |||
3568 | case DECL_OBJC_CATEGORY: | |||
3569 | D = ObjCCategoryDecl::CreateDeserialized(Context, ID); | |||
3570 | break; | |||
3571 | case DECL_OBJC_CATEGORY_IMPL: | |||
3572 | D = ObjCCategoryImplDecl::CreateDeserialized(Context, ID); | |||
3573 | break; | |||
3574 | case DECL_OBJC_IMPLEMENTATION: | |||
3575 | D = ObjCImplementationDecl::CreateDeserialized(Context, ID); | |||
3576 | break; | |||
3577 | case DECL_OBJC_COMPATIBLE_ALIAS: | |||
3578 | D = ObjCCompatibleAliasDecl::CreateDeserialized(Context, ID); | |||
3579 | break; | |||
3580 | case DECL_OBJC_PROPERTY: | |||
3581 | D = ObjCPropertyDecl::CreateDeserialized(Context, ID); | |||
3582 | break; | |||
3583 | case DECL_OBJC_PROPERTY_IMPL: | |||
3584 | D = ObjCPropertyImplDecl::CreateDeserialized(Context, ID); | |||
3585 | break; | |||
3586 | case DECL_FIELD: | |||
3587 | D = FieldDecl::CreateDeserialized(Context, ID); | |||
3588 | break; | |||
3589 | case DECL_INDIRECTFIELD: | |||
3590 | D = IndirectFieldDecl::CreateDeserialized(Context, ID); | |||
3591 | break; | |||
3592 | case DECL_VAR: | |||
3593 | D = VarDecl::CreateDeserialized(Context, ID); | |||
3594 | break; | |||
3595 | case DECL_IMPLICIT_PARAM: | |||
3596 | D = ImplicitParamDecl::CreateDeserialized(Context, ID); | |||
3597 | break; | |||
3598 | case DECL_PARM_VAR: | |||
3599 | D = ParmVarDecl::CreateDeserialized(Context, ID); | |||
3600 | break; | |||
3601 | case DECL_DECOMPOSITION: | |||
3602 | D = DecompositionDecl::CreateDeserialized(Context, ID, Record.readInt()); | |||
3603 | break; | |||
3604 | case DECL_BINDING: | |||
3605 | D = BindingDecl::CreateDeserialized(Context, ID); | |||
3606 | break; | |||
3607 | case DECL_FILE_SCOPE_ASM: | |||
3608 | D = FileScopeAsmDecl::CreateDeserialized(Context, ID); | |||
3609 | break; | |||
3610 | case DECL_BLOCK: | |||
3611 | D = BlockDecl::CreateDeserialized(Context, ID); | |||
3612 | break; | |||
3613 | case DECL_MS_PROPERTY: | |||
3614 | D = MSPropertyDecl::CreateDeserialized(Context, ID); | |||
3615 | break; | |||
3616 | case DECL_CAPTURED: | |||
3617 | D = CapturedDecl::CreateDeserialized(Context, ID, Record.readInt()); | |||
3618 | break; | |||
3619 | case DECL_CXX_BASE_SPECIFIERS: | |||
3620 | Error("attempt to read a C++ base-specifier record as a declaration"); | |||
3621 | return nullptr; | |||
3622 | case DECL_CXX_CTOR_INITIALIZERS: | |||
3623 | Error("attempt to read a C++ ctor initializer record as a declaration"); | |||
3624 | return nullptr; | |||
3625 | case DECL_IMPORT: | |||
3626 | // Note: last entry of the ImportDecl record is the number of stored source | |||
3627 | // locations. | |||
3628 | D = ImportDecl::CreateDeserialized(Context, ID, Record.back()); | |||
3629 | break; | |||
3630 | case DECL_OMP_THREADPRIVATE: | |||
3631 | D = OMPThreadPrivateDecl::CreateDeserialized(Context, ID, Record.readInt()); | |||
3632 | break; | |||
3633 | case DECL_OMP_DECLARE_REDUCTION: | |||
3634 | D = OMPDeclareReductionDecl::CreateDeserialized(Context, ID); | |||
3635 | break; | |||
3636 | case DECL_OMP_CAPTUREDEXPR: | |||
3637 | D = OMPCapturedExprDecl::CreateDeserialized(Context, ID); | |||
3638 | break; | |||
3639 | case DECL_PRAGMA_COMMENT: | |||
3640 | D = PragmaCommentDecl::CreateDeserialized(Context, ID, Record.readInt()); | |||
3641 | break; | |||
3642 | case DECL_PRAGMA_DETECT_MISMATCH: | |||
3643 | D = PragmaDetectMismatchDecl::CreateDeserialized(Context, ID, | |||
3644 | Record.readInt()); | |||
3645 | break; | |||
3646 | case DECL_EMPTY: | |||
3647 | D = EmptyDecl::CreateDeserialized(Context, ID); | |||
3648 | break; | |||
3649 | case DECL_OBJC_TYPE_PARAM: | |||
3650 | D = ObjCTypeParamDecl::CreateDeserialized(Context, ID); | |||
3651 | break; | |||
3652 | } | |||
3653 | ||||
3654 | assert(D && "Unknown declaration reading AST file")(static_cast <bool> (D && "Unknown declaration reading AST file" ) ? void (0) : __assert_fail ("D && \"Unknown declaration reading AST file\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 3654, __extension__ __PRETTY_FUNCTION__)); | |||
3655 | LoadedDecl(Index, D); | |||
3656 | // Set the DeclContext before doing any deserialization, to make sure internal | |||
3657 | // calls to Decl::getASTContext() by Decl's methods will find the | |||
3658 | // TranslationUnitDecl without crashing. | |||
3659 | D->setDeclContext(Context.getTranslationUnitDecl()); | |||
3660 | Reader.Visit(D); | |||
3661 | ||||
3662 | // If this declaration is also a declaration context, get the | |||
3663 | // offsets for its tables of lexical and visible declarations. | |||
3664 | if (DeclContext *DC = dyn_cast<DeclContext>(D)) { | |||
3665 | std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC); | |||
3666 | if (Offsets.first && | |||
3667 | ReadLexicalDeclContextStorage(*Loc.F, DeclsCursor, Offsets.first, DC)) | |||
3668 | return nullptr; | |||
3669 | if (Offsets.second && | |||
3670 | ReadVisibleDeclContextStorage(*Loc.F, DeclsCursor, Offsets.second, ID)) | |||
3671 | return nullptr; | |||
3672 | } | |||
3673 | assert(Record.getIdx() == Record.size())(static_cast <bool> (Record.getIdx() == Record.size()) ? void (0) : __assert_fail ("Record.getIdx() == Record.size()" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 3673, __extension__ __PRETTY_FUNCTION__)); | |||
3674 | ||||
3675 | // Load any relevant update records. | |||
3676 | PendingUpdateRecords.push_back( | |||
3677 | PendingUpdateRecord(ID, D, /*JustLoaded=*/true)); | |||
3678 | ||||
3679 | // Load the categories after recursive loading is finished. | |||
3680 | if (ObjCInterfaceDecl *Class = dyn_cast<ObjCInterfaceDecl>(D)) | |||
3681 | // If we already have a definition when deserializing the ObjCInterfaceDecl, | |||
3682 | // we put the Decl in PendingDefinitions so we can pull the categories here. | |||
3683 | if (Class->isThisDeclarationADefinition() || | |||
3684 | PendingDefinitions.count(Class)) | |||
3685 | loadObjCCategories(ID, Class); | |||
3686 | ||||
3687 | // If we have deserialized a declaration that has a definition the | |||
3688 | // AST consumer might need to know about, queue it. | |||
3689 | // We don't pass it to the consumer immediately because we may be in recursive | |||
3690 | // loading, and some declarations may still be initializing. | |||
3691 | PotentiallyInterestingDecls.push_back( | |||
3692 | InterestingDecl(D, Reader.hasPendingBody())); | |||
3693 | ||||
3694 | return D; | |||
3695 | } | |||
3696 | ||||
3697 | void ASTReader::PassInterestingDeclsToConsumer() { | |||
3698 | assert(Consumer)(static_cast <bool> (Consumer) ? void (0) : __assert_fail ("Consumer", "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 3698, __extension__ __PRETTY_FUNCTION__)); | |||
3699 | ||||
3700 | if (PassingDeclsToConsumer) | |||
3701 | return; | |||
3702 | ||||
3703 | // Guard variable to avoid recursively redoing the process of passing | |||
3704 | // decls to consumer. | |||
3705 | SaveAndRestore<bool> GuardPassingDeclsToConsumer(PassingDeclsToConsumer, | |||
3706 | true); | |||
3707 | ||||
3708 | // Ensure that we've loaded all potentially-interesting declarations | |||
3709 | // that need to be eagerly loaded. | |||
3710 | for (auto ID : EagerlyDeserializedDecls) | |||
3711 | GetDecl(ID); | |||
3712 | EagerlyDeserializedDecls.clear(); | |||
3713 | ||||
3714 | while (!PotentiallyInterestingDecls.empty()) { | |||
3715 | InterestingDecl D = PotentiallyInterestingDecls.front(); | |||
3716 | PotentiallyInterestingDecls.pop_front(); | |||
3717 | if (isConsumerInterestedIn(getContext(), D.getDecl(), D.hasPendingBody())) | |||
3718 | PassInterestingDeclToConsumer(D.getDecl()); | |||
3719 | } | |||
3720 | } | |||
3721 | ||||
3722 | void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &Record) { | |||
3723 | // The declaration may have been modified by files later in the chain. | |||
3724 | // If this is the case, read the record containing the updates from each file | |||
3725 | // and pass it to ASTDeclReader to make the modifications. | |||
3726 | serialization::GlobalDeclID ID = Record.ID; | |||
3727 | Decl *D = Record.D; | |||
3728 | ProcessingUpdatesRAIIObj ProcessingUpdates(*this); | |||
3729 | DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID); | |||
3730 | ||||
3731 | llvm::SmallVector<serialization::DeclID, 8> PendingLazySpecializationIDs; | |||
3732 | ||||
3733 | if (UpdI != DeclUpdateOffsets.end()) { | |||
| ||||
3734 | auto UpdateOffsets = std::move(UpdI->second); | |||
3735 | DeclUpdateOffsets.erase(UpdI); | |||
3736 | ||||
3737 | // Check if this decl was interesting to the consumer. If we just loaded | |||
3738 | // the declaration, then we know it was interesting and we skip the call | |||
3739 | // to isConsumerInterestedIn because it is unsafe to call in the | |||
3740 | // current ASTReader state. | |||
3741 | bool WasInteresting = | |||
3742 | Record.JustLoaded || isConsumerInterestedIn(getContext(), D, false); | |||
3743 | for (auto &FileAndOffset : UpdateOffsets) { | |||
3744 | ModuleFile *F = FileAndOffset.first; | |||
3745 | uint64_t Offset = FileAndOffset.second; | |||
3746 | llvm::BitstreamCursor &Cursor = F->DeclsCursor; | |||
3747 | SavedStreamPosition SavedPosition(Cursor); | |||
3748 | Cursor.JumpToBit(Offset); | |||
3749 | unsigned Code = Cursor.ReadCode(); | |||
3750 | ASTRecordReader Record(*this, *F); | |||
3751 | unsigned RecCode = Record.readRecord(Cursor, Code); | |||
3752 | (void)RecCode; | |||
3753 | assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!")(static_cast <bool> (RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!") ? void (0) : __assert_fail ( "RecCode == DECL_UPDATES && \"Expected DECL_UPDATES record!\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 3753, __extension__ __PRETTY_FUNCTION__)); | |||
3754 | ||||
3755 | ASTDeclReader Reader(*this, Record, RecordLocation(F, Offset), ID, | |||
3756 | SourceLocation()); | |||
3757 | Reader.UpdateDecl(D, PendingLazySpecializationIDs); | |||
3758 | ||||
3759 | // We might have made this declaration interesting. If so, remember that | |||
3760 | // we need to hand it off to the consumer. | |||
3761 | if (!WasInteresting && | |||
3762 | isConsumerInterestedIn(getContext(), D, Reader.hasPendingBody())) { | |||
3763 | PotentiallyInterestingDecls.push_back( | |||
3764 | InterestingDecl(D, Reader.hasPendingBody())); | |||
3765 | WasInteresting = true; | |||
3766 | } | |||
3767 | } | |||
3768 | } | |||
3769 | // Add the lazy specializations to the template. | |||
3770 | assert((PendingLazySpecializationIDs.empty() || isa<ClassTemplateDecl>(D) ||(static_cast <bool> ((PendingLazySpecializationIDs.empty () || isa<ClassTemplateDecl>(D) || isa<FunctionTemplateDecl >(D) || isa<VarTemplateDecl>(D)) && "Must not have pending specializations" ) ? void (0) : __assert_fail ("(PendingLazySpecializationIDs.empty() || isa<ClassTemplateDecl>(D) || isa<FunctionTemplateDecl>(D) || isa<VarTemplateDecl>(D)) && \"Must not have pending specializations\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 3772, __extension__ __PRETTY_FUNCTION__)) | |||
3771 | isa<FunctionTemplateDecl>(D) || isa<VarTemplateDecl>(D)) &&(static_cast <bool> ((PendingLazySpecializationIDs.empty () || isa<ClassTemplateDecl>(D) || isa<FunctionTemplateDecl >(D) || isa<VarTemplateDecl>(D)) && "Must not have pending specializations" ) ? void (0) : __assert_fail ("(PendingLazySpecializationIDs.empty() || isa<ClassTemplateDecl>(D) || isa<FunctionTemplateDecl>(D) || isa<VarTemplateDecl>(D)) && \"Must not have pending specializations\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 3772, __extension__ __PRETTY_FUNCTION__)) | |||
3772 | "Must not have pending specializations")(static_cast <bool> ((PendingLazySpecializationIDs.empty () || isa<ClassTemplateDecl>(D) || isa<FunctionTemplateDecl >(D) || isa<VarTemplateDecl>(D)) && "Must not have pending specializations" ) ? void (0) : __assert_fail ("(PendingLazySpecializationIDs.empty() || isa<ClassTemplateDecl>(D) || isa<FunctionTemplateDecl>(D) || isa<VarTemplateDecl>(D)) && \"Must not have pending specializations\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 3772, __extension__ __PRETTY_FUNCTION__)); | |||
3773 | if (auto *CTD = dyn_cast<ClassTemplateDecl>(D)) | |||
3774 | ASTDeclReader::AddLazySpecializations(CTD, PendingLazySpecializationIDs); | |||
3775 | else if (auto *FTD = dyn_cast<FunctionTemplateDecl>(D)) | |||
3776 | ASTDeclReader::AddLazySpecializations(FTD, PendingLazySpecializationIDs); | |||
3777 | else if (auto *VTD = dyn_cast<VarTemplateDecl>(D)) | |||
3778 | ASTDeclReader::AddLazySpecializations(VTD, PendingLazySpecializationIDs); | |||
3779 | PendingLazySpecializationIDs.clear(); | |||
3780 | ||||
3781 | // Load the pending visible updates for this decl context, if it has any. | |||
3782 | auto I = PendingVisibleUpdates.find(ID); | |||
3783 | if (I != PendingVisibleUpdates.end()) { | |||
3784 | auto VisibleUpdates = std::move(I->second); | |||
3785 | PendingVisibleUpdates.erase(I); | |||
3786 | ||||
3787 | auto *DC = cast<DeclContext>(D)->getPrimaryContext(); | |||
3788 | for (const PendingVisibleUpdate &Update : VisibleUpdates) | |||
3789 | Lookups[DC].Table.add( | |||
3790 | Update.Mod, Update.Data, | |||
3791 | reader::ASTDeclContextNameLookupTrait(*this, *Update.Mod)); | |||
3792 | DC->setHasExternalVisibleStorage(true); | |||
3793 | } | |||
3794 | } | |||
3795 | ||||
3796 | void ASTReader::loadPendingDeclChain(Decl *FirstLocal, uint64_t LocalOffset) { | |||
3797 | // Attach FirstLocal to the end of the decl chain. | |||
3798 | Decl *CanonDecl = FirstLocal->getCanonicalDecl(); | |||
3799 | if (FirstLocal != CanonDecl) { | |||
3800 | Decl *PrevMostRecent = ASTDeclReader::getMostRecentDecl(CanonDecl); | |||
3801 | ASTDeclReader::attachPreviousDecl( | |||
3802 | *this, FirstLocal, PrevMostRecent ? PrevMostRecent : CanonDecl, | |||
3803 | CanonDecl); | |||
3804 | } | |||
3805 | ||||
3806 | if (!LocalOffset) { | |||
3807 | ASTDeclReader::attachLatestDecl(CanonDecl, FirstLocal); | |||
3808 | return; | |||
3809 | } | |||
3810 | ||||
3811 | // Load the list of other redeclarations from this module file. | |||
3812 | ModuleFile *M = getOwningModuleFile(FirstLocal); | |||
3813 | assert(M && "imported decl from no module file")(static_cast <bool> (M && "imported decl from no module file" ) ? void (0) : __assert_fail ("M && \"imported decl from no module file\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 3813, __extension__ __PRETTY_FUNCTION__)); | |||
3814 | ||||
3815 | llvm::BitstreamCursor &Cursor = M->DeclsCursor; | |||
3816 | SavedStreamPosition SavedPosition(Cursor); | |||
3817 | Cursor.JumpToBit(LocalOffset); | |||
3818 | ||||
3819 | RecordData Record; | |||
3820 | unsigned Code = Cursor.ReadCode(); | |||
3821 | unsigned RecCode = Cursor.readRecord(Code, Record); | |||
3822 | (void)RecCode; | |||
3823 | assert(RecCode == LOCAL_REDECLARATIONS && "expected LOCAL_REDECLARATIONS record!")(static_cast <bool> (RecCode == LOCAL_REDECLARATIONS && "expected LOCAL_REDECLARATIONS record!") ? void (0) : __assert_fail ("RecCode == LOCAL_REDECLARATIONS && \"expected LOCAL_REDECLARATIONS record!\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 3823, __extension__ __PRETTY_FUNCTION__)); | |||
3824 | ||||
3825 | // FIXME: We have several different dispatches on decl kind here; maybe | |||
3826 | // we should instead generate one loop per kind and dispatch up-front? | |||
3827 | Decl *MostRecent = FirstLocal; | |||
3828 | for (unsigned I = 0, N = Record.size(); I != N; ++I) { | |||
3829 | auto *D = GetLocalDecl(*M, Record[N - I - 1]); | |||
3830 | ASTDeclReader::attachPreviousDecl(*this, D, MostRecent, CanonDecl); | |||
3831 | MostRecent = D; | |||
3832 | } | |||
3833 | ASTDeclReader::attachLatestDecl(CanonDecl, MostRecent); | |||
3834 | } | |||
3835 | ||||
3836 | namespace { | |||
3837 | /// \brief Given an ObjC interface, goes through the modules and links to the | |||
3838 | /// interface all the categories for it. | |||
3839 | class ObjCCategoriesVisitor { | |||
3840 | ASTReader &Reader; | |||
3841 | ObjCInterfaceDecl *Interface; | |||
3842 | llvm::SmallPtrSetImpl<ObjCCategoryDecl *> &Deserialized; | |||
3843 | ObjCCategoryDecl *Tail; | |||
3844 | llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap; | |||
3845 | serialization::GlobalDeclID InterfaceID; | |||
3846 | unsigned PreviousGeneration; | |||
3847 | ||||
3848 | void add(ObjCCategoryDecl *Cat) { | |||
3849 | // Only process each category once. | |||
3850 | if (!Deserialized.erase(Cat)) | |||
3851 | return; | |||
3852 | ||||
3853 | // Check for duplicate categories. | |||
3854 | if (Cat->getDeclName()) { | |||
3855 | ObjCCategoryDecl *&Existing = NameCategoryMap[Cat->getDeclName()]; | |||
3856 | if (Existing && | |||
3857 | Reader.getOwningModuleFile(Existing) | |||
3858 | != Reader.getOwningModuleFile(Cat)) { | |||
3859 | // FIXME: We should not warn for duplicates in diamond: | |||
3860 | // | |||
3861 | // MT // | |||
3862 | // / \ // | |||
3863 | // ML MR // | |||
3864 | // \ / // | |||
3865 | // MB // | |||
3866 | // | |||
3867 | // If there are duplicates in ML/MR, there will be warning when | |||
3868 | // creating MB *and* when importing MB. We should not warn when | |||
3869 | // importing. | |||
3870 | Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def) | |||
3871 | << Interface->getDeclName() << Cat->getDeclName(); | |||
3872 | Reader.Diag(Existing->getLocation(), diag::note_previous_definition); | |||
3873 | } else if (!Existing) { | |||
3874 | // Record this category. | |||
3875 | Existing = Cat; | |||
3876 | } | |||
3877 | } | |||
3878 | ||||
3879 | // Add this category to the end of the chain. | |||
3880 | if (Tail) | |||
3881 | ASTDeclReader::setNextObjCCategory(Tail, Cat); | |||
3882 | else | |||
3883 | Interface->setCategoryListRaw(Cat); | |||
3884 | Tail = Cat; | |||
3885 | } | |||
3886 | ||||
3887 | public: | |||
3888 | ObjCCategoriesVisitor(ASTReader &Reader, | |||
3889 | ObjCInterfaceDecl *Interface, | |||
3890 | llvm::SmallPtrSetImpl<ObjCCategoryDecl *> &Deserialized, | |||
3891 | serialization::GlobalDeclID InterfaceID, | |||
3892 | unsigned PreviousGeneration) | |||
3893 | : Reader(Reader), Interface(Interface), Deserialized(Deserialized), | |||
3894 | Tail(nullptr), InterfaceID(InterfaceID), | |||
3895 | PreviousGeneration(PreviousGeneration) | |||
3896 | { | |||
3897 | // Populate the name -> category map with the set of known categories. | |||
3898 | for (auto *Cat : Interface->known_categories()) { | |||
3899 | if (Cat->getDeclName()) | |||
3900 | NameCategoryMap[Cat->getDeclName()] = Cat; | |||
3901 | ||||
3902 | // Keep track of the tail of the category list. | |||
3903 | Tail = Cat; | |||
3904 | } | |||
3905 | } | |||
3906 | ||||
3907 | bool operator()(ModuleFile &M) { | |||
3908 | // If we've loaded all of the category information we care about from | |||
3909 | // this module file, we're done. | |||
3910 | if (M.Generation <= PreviousGeneration) | |||
3911 | return true; | |||
3912 | ||||
3913 | // Map global ID of the definition down to the local ID used in this | |||
3914 | // module file. If there is no such mapping, we'll find nothing here | |||
3915 | // (or in any module it imports). | |||
3916 | DeclID LocalID = Reader.mapGlobalIDToModuleFileGlobalID(M, InterfaceID); | |||
3917 | if (!LocalID) | |||
3918 | return true; | |||
3919 | ||||
3920 | // Perform a binary search to find the local redeclarations for this | |||
3921 | // declaration (if any). | |||
3922 | const ObjCCategoriesInfo Compare = { LocalID, 0 }; | |||
3923 | const ObjCCategoriesInfo *Result | |||
3924 | = std::lower_bound(M.ObjCCategoriesMap, | |||
3925 | M.ObjCCategoriesMap + M.LocalNumObjCCategoriesInMap, | |||
3926 | Compare); | |||
3927 | if (Result == M.ObjCCategoriesMap + M.LocalNumObjCCategoriesInMap || | |||
3928 | Result->DefinitionID != LocalID) { | |||
3929 | // We didn't find anything. If the class definition is in this module | |||
3930 | // file, then the module files it depends on cannot have any categories, | |||
3931 | // so suppress further lookup. | |||
3932 | return Reader.isDeclIDFromModule(InterfaceID, M); | |||
3933 | } | |||
3934 | ||||
3935 | // We found something. Dig out all of the categories. | |||
3936 | unsigned Offset = Result->Offset; | |||
3937 | unsigned N = M.ObjCCategories[Offset]; | |||
3938 | M.ObjCCategories[Offset++] = 0; // Don't try to deserialize again | |||
3939 | for (unsigned I = 0; I != N; ++I) | |||
3940 | add(cast_or_null<ObjCCategoryDecl>( | |||
3941 | Reader.GetLocalDecl(M, M.ObjCCategories[Offset++]))); | |||
3942 | return true; | |||
3943 | } | |||
3944 | }; | |||
3945 | } // end anonymous namespace | |||
3946 | ||||
3947 | void ASTReader::loadObjCCategories(serialization::GlobalDeclID ID, | |||
3948 | ObjCInterfaceDecl *D, | |||
3949 | unsigned PreviousGeneration) { | |||
3950 | ObjCCategoriesVisitor Visitor(*this, D, CategoriesDeserialized, ID, | |||
3951 | PreviousGeneration); | |||
3952 | ModuleMgr.visit(Visitor); | |||
3953 | } | |||
3954 | ||||
3955 | template<typename DeclT, typename Fn> | |||
3956 | static void forAllLaterRedecls(DeclT *D, Fn F) { | |||
3957 | F(D); | |||
3958 | ||||
3959 | // Check whether we've already merged D into its redeclaration chain. | |||
3960 | // MostRecent may or may not be nullptr if D has not been merged. If | |||
3961 | // not, walk the merged redecl chain and see if it's there. | |||
3962 | auto *MostRecent = D->getMostRecentDecl(); | |||
3963 | bool Found = false; | |||
3964 | for (auto *Redecl = MostRecent; Redecl && !Found; | |||
3965 | Redecl = Redecl->getPreviousDecl()) | |||
3966 | Found = (Redecl == D); | |||
3967 | ||||
3968 | // If this declaration is merged, apply the functor to all later decls. | |||
3969 | if (Found) { | |||
3970 | for (auto *Redecl = MostRecent; Redecl != D; | |||
3971 | Redecl = Redecl->getPreviousDecl()) | |||
3972 | F(Redecl); | |||
3973 | } | |||
3974 | } | |||
3975 | ||||
3976 | void ASTDeclReader::UpdateDecl(Decl *D, | |||
3977 | llvm::SmallVectorImpl<serialization::DeclID> &PendingLazySpecializationIDs) { | |||
3978 | while (Record.getIdx() < Record.size()) { | |||
3979 | switch ((DeclUpdateKind)Record.readInt()) { | |||
3980 | case UPD_CXX_ADDED_IMPLICIT_MEMBER: { | |||
3981 | auto *RD = cast<CXXRecordDecl>(D); | |||
3982 | // FIXME: If we also have an update record for instantiating the | |||
3983 | // definition of D, we need that to happen before we get here. | |||
3984 | Decl *MD = Record.readDecl(); | |||
3985 | assert(MD && "couldn't read decl from update record")(static_cast <bool> (MD && "couldn't read decl from update record" ) ? void (0) : __assert_fail ("MD && \"couldn't read decl from update record\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 3985, __extension__ __PRETTY_FUNCTION__)); | |||
3986 | // FIXME: We should call addHiddenDecl instead, to add the member | |||
3987 | // to its DeclContext. | |||
3988 | RD->addedMember(MD); | |||
3989 | break; | |||
3990 | } | |||
3991 | ||||
3992 | case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION: | |||
3993 | // It will be added to the template's lazy specialization set. | |||
3994 | PendingLazySpecializationIDs.push_back(ReadDeclID()); | |||
3995 | break; | |||
3996 | ||||
3997 | case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: { | |||
3998 | NamespaceDecl *Anon = ReadDeclAs<NamespaceDecl>(); | |||
3999 | ||||
4000 | // Each module has its own anonymous namespace, which is disjoint from | |||
4001 | // any other module's anonymous namespaces, so don't attach the anonymous | |||
4002 | // namespace at all. | |||
4003 | if (!Record.isModule()) { | |||
4004 | if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(D)) | |||
4005 | TU->setAnonymousNamespace(Anon); | |||
4006 | else | |||
4007 | cast<NamespaceDecl>(D)->setAnonymousNamespace(Anon); | |||
4008 | } | |||
4009 | break; | |||
4010 | } | |||
4011 | ||||
4012 | case UPD_CXX_ADDED_VAR_DEFINITION: { | |||
4013 | VarDecl *VD = cast<VarDecl>(D); | |||
4014 | VD->NonParmVarDeclBits.IsInline = Record.readInt(); | |||
4015 | VD->NonParmVarDeclBits.IsInlineSpecified = Record.readInt(); | |||
4016 | uint64_t Val = Record.readInt(); | |||
4017 | if (Val && !VD->getInit()) { | |||
4018 | VD->setInit(Record.readExpr()); | |||
4019 | if (Val > 1) { // IsInitKnownICE = 1, IsInitNotICE = 2, IsInitICE = 3 | |||
4020 | EvaluatedStmt *Eval = VD->ensureEvaluatedStmt(); | |||
4021 | Eval->CheckedICE = true; | |||
4022 | Eval->IsICE = Val == 3; | |||
4023 | } | |||
4024 | } | |||
4025 | break; | |||
4026 | } | |||
4027 | ||||
4028 | case UPD_CXX_POINT_OF_INSTANTIATION: { | |||
4029 | SourceLocation POI = Record.readSourceLocation(); | |||
4030 | if (VarTemplateSpecializationDecl *VTSD = | |||
4031 | dyn_cast<VarTemplateSpecializationDecl>(D)) { | |||
4032 | VTSD->setPointOfInstantiation(POI); | |||
4033 | } else if (auto *VD = dyn_cast<VarDecl>(D)) { | |||
4034 | VD->getMemberSpecializationInfo()->setPointOfInstantiation(POI); | |||
4035 | } else { | |||
4036 | auto *FD = cast<FunctionDecl>(D); | |||
4037 | if (auto *FTSInfo = FD->TemplateOrSpecialization | |||
4038 | .dyn_cast<FunctionTemplateSpecializationInfo *>()) | |||
4039 | FTSInfo->setPointOfInstantiation(POI); | |||
4040 | else | |||
4041 | FD->TemplateOrSpecialization.get<MemberSpecializationInfo *>() | |||
4042 | ->setPointOfInstantiation(POI); | |||
4043 | } | |||
4044 | break; | |||
4045 | } | |||
4046 | ||||
4047 | case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT: { | |||
4048 | auto Param = cast<ParmVarDecl>(D); | |||
4049 | ||||
4050 | // We have to read the default argument regardless of whether we use it | |||
4051 | // so that hypothetical further update records aren't messed up. | |||
4052 | // TODO: Add a function to skip over the next expr record. | |||
4053 | auto DefaultArg = Record.readExpr(); | |||
4054 | ||||
4055 | // Only apply the update if the parameter still has an uninstantiated | |||
4056 | // default argument. | |||
4057 | if (Param->hasUninstantiatedDefaultArg()) | |||
4058 | Param->setDefaultArg(DefaultArg); | |||
4059 | break; | |||
4060 | } | |||
4061 | ||||
4062 | case UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER: { | |||
4063 | auto FD = cast<FieldDecl>(D); | |||
4064 | auto DefaultInit = Record.readExpr(); | |||
4065 | ||||
4066 | // Only apply the update if the field still has an uninstantiated | |||
4067 | // default member initializer. | |||
4068 | if (FD->hasInClassInitializer() && !FD->getInClassInitializer()) { | |||
4069 | if (DefaultInit) | |||
4070 | FD->setInClassInitializer(DefaultInit); | |||
4071 | else | |||
4072 | // Instantiation failed. We can get here if we serialized an AST for | |||
4073 | // an invalid program. | |||
4074 | FD->removeInClassInitializer(); | |||
4075 | } | |||
4076 | break; | |||
4077 | } | |||
4078 | ||||
4079 | case UPD_CXX_ADDED_FUNCTION_DEFINITION: { | |||
4080 | FunctionDecl *FD = cast<FunctionDecl>(D); | |||
4081 | if (Reader.PendingBodies[FD]) { | |||
4082 | // FIXME: Maybe check for ODR violations. | |||
4083 | // It's safe to stop now because this update record is always last. | |||
4084 | return; | |||
4085 | } | |||
4086 | ||||
4087 | if (Record.readInt()) { | |||
4088 | // Maintain AST consistency: any later redeclarations of this function | |||
4089 | // are inline if this one is. (We might have merged another declaration | |||
4090 | // into this one.) | |||
4091 | forAllLaterRedecls(FD, [](FunctionDecl *FD) { | |||
4092 | FD->setImplicitlyInline(); | |||
4093 | }); | |||
4094 | } | |||
4095 | FD->setInnerLocStart(ReadSourceLocation()); | |||
4096 | ReadFunctionDefinition(FD); | |||
4097 | assert(Record.getIdx() == Record.size() && "lazy body must be last")(static_cast <bool> (Record.getIdx() == Record.size() && "lazy body must be last") ? void (0) : __assert_fail ("Record.getIdx() == Record.size() && \"lazy body must be last\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 4097, __extension__ __PRETTY_FUNCTION__)); | |||
4098 | break; | |||
4099 | } | |||
4100 | ||||
4101 | case UPD_CXX_INSTANTIATED_CLASS_DEFINITION: { | |||
4102 | auto *RD = cast<CXXRecordDecl>(D); | |||
4103 | auto *OldDD = RD->getCanonicalDecl()->DefinitionData; | |||
4104 | bool HadRealDefinition = | |||
4105 | OldDD && (OldDD->Definition != RD || | |||
4106 | !Reader.PendingFakeDefinitionData.count(OldDD)); | |||
4107 | ReadCXXRecordDefinition(RD, /*Update*/true); | |||
4108 | ||||
4109 | // Visible update is handled separately. | |||
4110 | uint64_t LexicalOffset = ReadLocalOffset(); | |||
4111 | if (!HadRealDefinition && LexicalOffset) { | |||
4112 | Record.readLexicalDeclContextStorage(LexicalOffset, RD); | |||
4113 | Reader.PendingFakeDefinitionData.erase(OldDD); | |||
4114 | } | |||
4115 | ||||
4116 | auto TSK = (TemplateSpecializationKind)Record.readInt(); | |||
4117 | SourceLocation POI = ReadSourceLocation(); | |||
4118 | if (MemberSpecializationInfo *MSInfo = | |||
4119 | RD->getMemberSpecializationInfo()) { | |||
4120 | MSInfo->setTemplateSpecializationKind(TSK); | |||
4121 | MSInfo->setPointOfInstantiation(POI); | |||
4122 | } else { | |||
4123 | ClassTemplateSpecializationDecl *Spec = | |||
4124 | cast<ClassTemplateSpecializationDecl>(RD); | |||
4125 | Spec->setTemplateSpecializationKind(TSK); | |||
4126 | Spec->setPointOfInstantiation(POI); | |||
4127 | ||||
4128 | if (Record.readInt()) { | |||
4129 | auto PartialSpec = | |||
4130 | ReadDeclAs<ClassTemplatePartialSpecializationDecl>(); | |||
4131 | SmallVector<TemplateArgument, 8> TemplArgs; | |||
4132 | Record.readTemplateArgumentList(TemplArgs); | |||
4133 | auto *TemplArgList = TemplateArgumentList::CreateCopy( | |||
4134 | Reader.getContext(), TemplArgs); | |||
4135 | ||||
4136 | // FIXME: If we already have a partial specialization set, | |||
4137 | // check that it matches. | |||
4138 | if (!Spec->getSpecializedTemplateOrPartial() | |||
4139 | .is<ClassTemplatePartialSpecializationDecl *>()) | |||
4140 | Spec->setInstantiationOf(PartialSpec, TemplArgList); | |||
4141 | } | |||
4142 | } | |||
4143 | ||||
4144 | RD->setTagKind((TagTypeKind)Record.readInt()); | |||
4145 | RD->setLocation(ReadSourceLocation()); | |||
4146 | RD->setLocStart(ReadSourceLocation()); | |||
4147 | RD->setBraceRange(ReadSourceRange()); | |||
4148 | ||||
4149 | if (Record.readInt()) { | |||
4150 | AttrVec Attrs; | |||
4151 | Record.readAttributes(Attrs); | |||
4152 | // If the declaration already has attributes, we assume that some other | |||
4153 | // AST file already loaded them. | |||
4154 | if (!D->hasAttrs()) | |||
4155 | D->setAttrsImpl(Attrs, Reader.getContext()); | |||
4156 | } | |||
4157 | break; | |||
4158 | } | |||
4159 | ||||
4160 | case UPD_CXX_RESOLVED_DTOR_DELETE: { | |||
4161 | // Set the 'operator delete' directly to avoid emitting another update | |||
4162 | // record. | |||
4163 | auto *Del = ReadDeclAs<FunctionDecl>(); | |||
4164 | auto *First = cast<CXXDestructorDecl>(D->getCanonicalDecl()); | |||
4165 | auto *ThisArg = Record.readExpr(); | |||
4166 | // FIXME: Check consistency if we have an old and new operator delete. | |||
4167 | if (!First->OperatorDelete) { | |||
4168 | First->OperatorDelete = Del; | |||
4169 | First->OperatorDeleteThisArg = ThisArg; | |||
4170 | } | |||
4171 | break; | |||
4172 | } | |||
4173 | ||||
4174 | case UPD_CXX_RESOLVED_EXCEPTION_SPEC: { | |||
4175 | FunctionProtoType::ExceptionSpecInfo ESI; | |||
4176 | SmallVector<QualType, 8> ExceptionStorage; | |||
4177 | Record.readExceptionSpec(ExceptionStorage, ESI); | |||
4178 | ||||
4179 | // Update this declaration's exception specification, if needed. | |||
4180 | auto *FD = cast<FunctionDecl>(D); | |||
4181 | auto *FPT = FD->getType()->castAs<FunctionProtoType>(); | |||
4182 | // FIXME: If the exception specification is already present, check that it | |||
4183 | // matches. | |||
4184 | if (isUnresolvedExceptionSpec(FPT->getExceptionSpecType())) { | |||
4185 | FD->setType(Reader.getContext().getFunctionType( | |||
4186 | FPT->getReturnType(), FPT->getParamTypes(), | |||
4187 | FPT->getExtProtoInfo().withExceptionSpec(ESI))); | |||
4188 | ||||
4189 | // When we get to the end of deserializing, see if there are other decls | |||
4190 | // that we need to propagate this exception specification onto. | |||
4191 | Reader.PendingExceptionSpecUpdates.insert( | |||
4192 | std::make_pair(FD->getCanonicalDecl(), FD)); | |||
4193 | } | |||
4194 | break; | |||
4195 | } | |||
4196 | ||||
4197 | case UPD_CXX_DEDUCED_RETURN_TYPE: { | |||
4198 | // FIXME: Also do this when merging redecls. | |||
4199 | QualType DeducedResultType = Record.readType(); | |||
4200 | for (auto *Redecl : merged_redecls(D)) { | |||
4201 | // FIXME: If the return type is already deduced, check that it matches. | |||
4202 | FunctionDecl *FD = cast<FunctionDecl>(Redecl); | |||
4203 | Reader.getContext().adjustDeducedFunctionResultType(FD, | |||
4204 | DeducedResultType); | |||
4205 | } | |||
4206 | break; | |||
4207 | } | |||
4208 | ||||
4209 | case UPD_DECL_MARKED_USED: { | |||
4210 | // Maintain AST consistency: any later redeclarations are used too. | |||
4211 | D->markUsed(Reader.getContext()); | |||
4212 | break; | |||
4213 | } | |||
4214 | ||||
4215 | case UPD_MANGLING_NUMBER: | |||
4216 | Reader.getContext().setManglingNumber(cast<NamedDecl>(D), | |||
4217 | Record.readInt()); | |||
4218 | break; | |||
4219 | ||||
4220 | case UPD_STATIC_LOCAL_NUMBER: | |||
4221 | Reader.getContext().setStaticLocalNumber(cast<VarDecl>(D), | |||
4222 | Record.readInt()); | |||
4223 | break; | |||
4224 | ||||
4225 | case UPD_DECL_MARKED_OPENMP_THREADPRIVATE: | |||
4226 | D->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit(Reader.getContext(), | |||
4227 | ReadSourceRange())); | |||
4228 | break; | |||
4229 | ||||
4230 | case UPD_DECL_EXPORTED: { | |||
4231 | unsigned SubmoduleID = readSubmoduleID(); | |||
4232 | auto *Exported = cast<NamedDecl>(D); | |||
4233 | if (auto *TD = dyn_cast<TagDecl>(Exported)) | |||
4234 | Exported = TD->getDefinition(); | |||
4235 | Module *Owner = SubmoduleID ? Reader.getSubmodule(SubmoduleID) : nullptr; | |||
4236 | if (Reader.getContext().getLangOpts().ModulesLocalVisibility) { | |||
4237 | Reader.getContext().mergeDefinitionIntoModule(cast<NamedDecl>(Exported), | |||
4238 | Owner); | |||
4239 | Reader.PendingMergedDefinitionsToDeduplicate.insert( | |||
4240 | cast<NamedDecl>(Exported)); | |||
4241 | } else if (Owner && Owner->NameVisibility != Module::AllVisible) { | |||
4242 | // If Owner is made visible at some later point, make this declaration | |||
4243 | // visible too. | |||
4244 | Reader.HiddenNamesMap[Owner].push_back(Exported); | |||
4245 | } else { | |||
4246 | // The declaration is now visible. | |||
4247 | Exported->setVisibleDespiteOwningModule(); | |||
4248 | } | |||
4249 | break; | |||
4250 | } | |||
4251 | ||||
4252 | case UPD_DECL_MARKED_OPENMP_DECLARETARGET: | |||
4253 | case UPD_ADDED_ATTR_TO_RECORD: | |||
4254 | AttrVec Attrs; | |||
4255 | Record.readAttributes(Attrs); | |||
4256 | assert(Attrs.size() == 1)(static_cast <bool> (Attrs.size() == 1) ? void (0) : __assert_fail ("Attrs.size() == 1", "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/Serialization/ASTReaderDecl.cpp" , 4256, __extension__ __PRETTY_FUNCTION__)); | |||
4257 | D->addAttr(Attrs[0]); | |||
4258 | break; | |||
4259 | } | |||
4260 | } | |||
4261 | } |
1 | //===- DeclTemplate.h - Classes for representing C++ templates --*- C++ -*-===// | |||
2 | // | |||
3 | // The LLVM Compiler Infrastructure | |||
4 | // | |||
5 | // This file is distributed under the University of Illinois Open Source | |||
6 | // License. See LICENSE.TXT for details. | |||
7 | // | |||
8 | //===----------------------------------------------------------------------===// | |||
9 | // | |||
10 | /// \file | |||
11 | /// \brief Defines the C++ template declaration subclasses. | |||
12 | // | |||
13 | //===----------------------------------------------------------------------===// | |||
14 | ||||
15 | #ifndef LLVM_CLANG_AST_DECLTEMPLATE_H | |||
16 | #define LLVM_CLANG_AST_DECLTEMPLATE_H | |||
17 | ||||
18 | #include "clang/AST/Decl.h" | |||
19 | #include "clang/AST/DeclBase.h" | |||
20 | #include "clang/AST/DeclCXX.h" | |||
21 | #include "clang/AST/DeclarationName.h" | |||
22 | #include "clang/AST/Redeclarable.h" | |||
23 | #include "clang/AST/TemplateBase.h" | |||
24 | #include "clang/AST/Type.h" | |||
25 | #include "clang/Basic/LLVM.h" | |||
26 | #include "clang/Basic/SourceLocation.h" | |||
27 | #include "clang/Basic/Specifiers.h" | |||
28 | #include "llvm/ADT/ArrayRef.h" | |||
29 | #include "llvm/ADT/FoldingSet.h" | |||
30 | #include "llvm/ADT/PointerIntPair.h" | |||
31 | #include "llvm/ADT/PointerUnion.h" | |||
32 | #include "llvm/ADT/iterator.h" | |||
33 | #include "llvm/ADT/iterator_range.h" | |||
34 | #include "llvm/Support/Casting.h" | |||
35 | #include "llvm/Support/Compiler.h" | |||
36 | #include "llvm/Support/TrailingObjects.h" | |||
37 | #include <cassert> | |||
38 | #include <cstddef> | |||
39 | #include <cstdint> | |||
40 | #include <iterator> | |||
41 | #include <utility> | |||
42 | ||||
43 | namespace clang { | |||
44 | ||||
45 | enum BuiltinTemplateKind : int; | |||
46 | class ClassTemplateDecl; | |||
47 | class ClassTemplatePartialSpecializationDecl; | |||
48 | class Expr; | |||
49 | class FunctionTemplateDecl; | |||
50 | class IdentifierInfo; | |||
51 | class NonTypeTemplateParmDecl; | |||
52 | class TemplateDecl; | |||
53 | class TemplateTemplateParmDecl; | |||
54 | class TemplateTypeParmDecl; | |||
55 | class UnresolvedSetImpl; | |||
56 | class VarTemplateDecl; | |||
57 | class VarTemplatePartialSpecializationDecl; | |||
58 | ||||
59 | /// \brief Stores a template parameter of any kind. | |||
60 | using TemplateParameter = | |||
61 | llvm::PointerUnion3<TemplateTypeParmDecl *, NonTypeTemplateParmDecl *, | |||
62 | TemplateTemplateParmDecl *>; | |||
63 | ||||
64 | NamedDecl *getAsNamedDecl(TemplateParameter P); | |||
65 | ||||
66 | /// \brief Stores a list of template parameters for a TemplateDecl and its | |||
67 | /// derived classes. | |||
68 | class TemplateParameterList final | |||
69 | : private llvm::TrailingObjects<TemplateParameterList, NamedDecl *, | |||
70 | Expr *> { | |||
71 | /// The location of the 'template' keyword. | |||
72 | SourceLocation TemplateLoc; | |||
73 | ||||
74 | /// The locations of the '<' and '>' angle brackets. | |||
75 | SourceLocation LAngleLoc, RAngleLoc; | |||
76 | ||||
77 | /// The number of template parameters in this template | |||
78 | /// parameter list. | |||
79 | unsigned NumParams : 30; | |||
80 | ||||
81 | /// Whether this template parameter list contains an unexpanded parameter | |||
82 | /// pack. | |||
83 | unsigned ContainsUnexpandedParameterPack : 1; | |||
84 | ||||
85 | /// Whether this template parameter list has an associated requires-clause | |||
86 | unsigned HasRequiresClause : 1; | |||
87 | ||||
88 | protected: | |||
89 | TemplateParameterList(SourceLocation TemplateLoc, SourceLocation LAngleLoc, | |||
90 | ArrayRef<NamedDecl *> Params, SourceLocation RAngleLoc, | |||
91 | Expr *RequiresClause); | |||
92 | ||||
93 | size_t numTrailingObjects(OverloadToken<NamedDecl *>) const { | |||
94 | return NumParams; | |||
95 | } | |||
96 | ||||
97 | size_t numTrailingObjects(OverloadToken<Expr *>) const { | |||
98 | return HasRequiresClause; | |||
99 | } | |||
100 | ||||
101 | public: | |||
102 | template <size_t N, bool HasRequiresClause> | |||
103 | friend class FixedSizeTemplateParameterListStorage; | |||
104 | friend TrailingObjects; | |||
105 | ||||
106 | static TemplateParameterList *Create(const ASTContext &C, | |||
107 | SourceLocation TemplateLoc, | |||
108 | SourceLocation LAngleLoc, | |||
109 | ArrayRef<NamedDecl *> Params, | |||
110 | SourceLocation RAngleLoc, | |||
111 | Expr *RequiresClause); | |||
112 | ||||
113 | /// \brief Iterates through the template parameters in this list. | |||
114 | using iterator = NamedDecl **; | |||
115 | ||||
116 | /// \brief Iterates through the template parameters in this list. | |||
117 | using const_iterator = NamedDecl * const *; | |||
118 | ||||
119 | iterator begin() { return getTrailingObjects<NamedDecl *>(); } | |||
120 | const_iterator begin() const { return getTrailingObjects<NamedDecl *>(); } | |||
121 | iterator end() { return begin() + NumParams; } | |||
122 | const_iterator end() const { return begin() + NumParams; } | |||
123 | ||||
124 | unsigned size() const { return NumParams; } | |||
125 | ||||
126 | ArrayRef<NamedDecl*> asArray() { | |||
127 | return llvm::makeArrayRef(begin(), end()); | |||
128 | } | |||
129 | ArrayRef<const NamedDecl*> asArray() const { | |||
130 | return llvm::makeArrayRef(begin(), size()); | |||
131 | } | |||
132 | ||||
133 | NamedDecl* getParam(unsigned Idx) { | |||
134 | assert(Idx < size() && "Template parameter index out-of-range")(static_cast <bool> (Idx < size() && "Template parameter index out-of-range" ) ? void (0) : __assert_fail ("Idx < size() && \"Template parameter index out-of-range\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 134, __extension__ __PRETTY_FUNCTION__)); | |||
135 | return begin()[Idx]; | |||
136 | } | |||
137 | const NamedDecl* getParam(unsigned Idx) const { | |||
138 | assert(Idx < size() && "Template parameter index out-of-range")(static_cast <bool> (Idx < size() && "Template parameter index out-of-range" ) ? void (0) : __assert_fail ("Idx < size() && \"Template parameter index out-of-range\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 138, __extension__ __PRETTY_FUNCTION__)); | |||
139 | return begin()[Idx]; | |||
140 | } | |||
141 | ||||
142 | /// \brief Returns the minimum number of arguments needed to form a | |||
143 | /// template specialization. | |||
144 | /// | |||
145 | /// This may be fewer than the number of template parameters, if some of | |||
146 | /// the parameters have default arguments or if there is a parameter pack. | |||
147 | unsigned getMinRequiredArguments() const; | |||
148 | ||||
149 | /// \brief Get the depth of this template parameter list in the set of | |||
150 | /// template parameter lists. | |||
151 | /// | |||
152 | /// The first template parameter list in a declaration will have depth 0, | |||
153 | /// the second template parameter list will have depth 1, etc. | |||
154 | unsigned getDepth() const; | |||
155 | ||||
156 | /// \brief Determine whether this template parameter list contains an | |||
157 | /// unexpanded parameter pack. | |||
158 | bool containsUnexpandedParameterPack() const { | |||
159 | return ContainsUnexpandedParameterPack; | |||
160 | } | |||
161 | ||||
162 | /// \brief The constraint-expression of the associated requires-clause. | |||
163 | Expr *getRequiresClause() { | |||
164 | return HasRequiresClause ? *getTrailingObjects<Expr *>() : nullptr; | |||
165 | } | |||
166 | ||||
167 | /// \brief The constraint-expression of the associated requires-clause. | |||
168 | const Expr *getRequiresClause() const { | |||
169 | return HasRequiresClause ? *getTrailingObjects<Expr *>() : nullptr; | |||
170 | } | |||
171 | ||||
172 | SourceLocation getTemplateLoc() const { return TemplateLoc; } | |||
173 | SourceLocation getLAngleLoc() const { return LAngleLoc; } | |||
174 | SourceLocation getRAngleLoc() const { return RAngleLoc; } | |||
175 | ||||
176 | SourceRange getSourceRange() const LLVM_READONLY__attribute__((__pure__)) { | |||
177 | return SourceRange(TemplateLoc, RAngleLoc); | |||
178 | } | |||
179 | ||||
180 | public: | |||
181 | // FIXME: workaround for MSVC 2013; remove when no longer needed | |||
182 | using FixedSizeStorageOwner = TrailingObjects::FixedSizeStorageOwner; | |||
183 | }; | |||
184 | ||||
185 | /// \brief Stores a list of template parameters and the associated | |||
186 | /// requires-clause (if any) for a TemplateDecl and its derived classes. | |||
187 | /// Suitable for creating on the stack. | |||
188 | template <size_t N, bool HasRequiresClause> | |||
189 | class FixedSizeTemplateParameterListStorage | |||
190 | : public TemplateParameterList::FixedSizeStorageOwner { | |||
191 | typename TemplateParameterList::FixedSizeStorage< | |||
192 | NamedDecl *, Expr *>::with_counts< | |||
193 | N, HasRequiresClause ? 1u : 0u | |||
194 | >::type storage; | |||
195 | ||||
196 | public: | |||
197 | FixedSizeTemplateParameterListStorage(SourceLocation TemplateLoc, | |||
198 | SourceLocation LAngleLoc, | |||
199 | ArrayRef<NamedDecl *> Params, | |||
200 | SourceLocation RAngleLoc, | |||
201 | Expr *RequiresClause) | |||
202 | : FixedSizeStorageOwner( | |||
203 | (assert(N == Params.size())(static_cast <bool> (N == Params.size()) ? void (0) : __assert_fail ("N == Params.size()", "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 203, __extension__ __PRETTY_FUNCTION__)), | |||
204 | assert(HasRequiresClause == static_cast<bool>(RequiresClause))(static_cast <bool> (HasRequiresClause == static_cast< bool>(RequiresClause)) ? void (0) : __assert_fail ("HasRequiresClause == static_cast<bool>(RequiresClause)" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 204, __extension__ __PRETTY_FUNCTION__)), | |||
205 | new (static_cast<void *>(&storage)) TemplateParameterList( | |||
206 | TemplateLoc, LAngleLoc, Params, RAngleLoc, RequiresClause))) {} | |||
207 | }; | |||
208 | ||||
209 | /// \brief A template argument list. | |||
210 | class TemplateArgumentList final | |||
211 | : private llvm::TrailingObjects<TemplateArgumentList, TemplateArgument> { | |||
212 | /// \brief The template argument list. | |||
213 | const TemplateArgument *Arguments; | |||
214 | ||||
215 | /// \brief The number of template arguments in this template | |||
216 | /// argument list. | |||
217 | unsigned NumArguments; | |||
218 | ||||
219 | // Constructs an instance with an internal Argument list, containing | |||
220 | // a copy of the Args array. (Called by CreateCopy) | |||
221 | TemplateArgumentList(ArrayRef<TemplateArgument> Args); | |||
222 | ||||
223 | public: | |||
224 | friend TrailingObjects; | |||
225 | ||||
226 | TemplateArgumentList(const TemplateArgumentList &) = delete; | |||
227 | TemplateArgumentList &operator=(const TemplateArgumentList &) = delete; | |||
228 | ||||
229 | /// \brief Type used to indicate that the template argument list itself is a | |||
230 | /// stack object. It does not own its template arguments. | |||
231 | enum OnStackType { OnStack }; | |||
232 | ||||
233 | /// \brief Create a new template argument list that copies the given set of | |||
234 | /// template arguments. | |||
235 | static TemplateArgumentList *CreateCopy(ASTContext &Context, | |||
236 | ArrayRef<TemplateArgument> Args); | |||
237 | ||||
238 | /// \brief Construct a new, temporary template argument list on the stack. | |||
239 | /// | |||
240 | /// The template argument list does not own the template arguments | |||
241 | /// provided. | |||
242 | explicit TemplateArgumentList(OnStackType, ArrayRef<TemplateArgument> Args) | |||
243 | : Arguments(Args.data()), NumArguments(Args.size()) {} | |||
244 | ||||
245 | /// \brief Produces a shallow copy of the given template argument list. | |||
246 | /// | |||
247 | /// This operation assumes that the input argument list outlives it. | |||
248 | /// This takes the list as a pointer to avoid looking like a copy | |||
249 | /// constructor, since this really really isn't safe to use that | |||
250 | /// way. | |||
251 | explicit TemplateArgumentList(const TemplateArgumentList *Other) | |||
252 | : Arguments(Other->data()), NumArguments(Other->size()) {} | |||
253 | ||||
254 | /// \brief Retrieve the template argument at a given index. | |||
255 | const TemplateArgument &get(unsigned Idx) const { | |||
256 | assert(Idx < NumArguments && "Invalid template argument index")(static_cast <bool> (Idx < NumArguments && "Invalid template argument index" ) ? void (0) : __assert_fail ("Idx < NumArguments && \"Invalid template argument index\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 256, __extension__ __PRETTY_FUNCTION__)); | |||
257 | return data()[Idx]; | |||
258 | } | |||
259 | ||||
260 | /// \brief Retrieve the template argument at a given index. | |||
261 | const TemplateArgument &operator[](unsigned Idx) const { return get(Idx); } | |||
262 | ||||
263 | /// \brief Produce this as an array ref. | |||
264 | ArrayRef<TemplateArgument> asArray() const { | |||
265 | return llvm::makeArrayRef(data(), size()); | |||
266 | } | |||
267 | ||||
268 | /// \brief Retrieve the number of template arguments in this | |||
269 | /// template argument list. | |||
270 | unsigned size() const { return NumArguments; } | |||
271 | ||||
272 | /// \brief Retrieve a pointer to the template argument list. | |||
273 | const TemplateArgument *data() const { return Arguments; } | |||
274 | }; | |||
275 | ||||
276 | void *allocateDefaultArgStorageChain(const ASTContext &C); | |||
277 | ||||
278 | /// Storage for a default argument. This is conceptually either empty, or an | |||
279 | /// argument value, or a pointer to a previous declaration that had a default | |||
280 | /// argument. | |||
281 | /// | |||
282 | /// However, this is complicated by modules: while we require all the default | |||
283 | /// arguments for a template to be equivalent, there may be more than one, and | |||
284 | /// we need to track all the originating parameters to determine if the default | |||
285 | /// argument is visible. | |||
286 | template<typename ParmDecl, typename ArgType> | |||
287 | class DefaultArgStorage { | |||
288 | /// Storage for both the value *and* another parameter from which we inherit | |||
289 | /// the default argument. This is used when multiple default arguments for a | |||
290 | /// parameter are merged together from different modules. | |||
291 | struct Chain { | |||
292 | ParmDecl *PrevDeclWithDefaultArg; | |||
293 | ArgType Value; | |||
294 | }; | |||
295 | static_assert(sizeof(Chain) == sizeof(void *) * 2, | |||
296 | "non-pointer argument type?"); | |||
297 | ||||
298 | llvm::PointerUnion3<ArgType, ParmDecl*, Chain*> ValueOrInherited; | |||
299 | ||||
300 | static ParmDecl *getParmOwningDefaultArg(ParmDecl *Parm) { | |||
301 | const DefaultArgStorage &Storage = Parm->getDefaultArgStorage(); | |||
302 | if (auto *Prev = Storage.ValueOrInherited.template dyn_cast<ParmDecl*>()) | |||
303 | Parm = Prev; | |||
304 | assert(!Parm->getDefaultArgStorage()(static_cast <bool> (!Parm->getDefaultArgStorage() . ValueOrInherited.template is<ParmDecl *>() && "should only be one level of indirection" ) ? void (0) : __assert_fail ("!Parm->getDefaultArgStorage() .ValueOrInherited.template is<ParmDecl *>() && \"should only be one level of indirection\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 306, __extension__ __PRETTY_FUNCTION__)) | |||
305 | .ValueOrInherited.template is<ParmDecl *>() &&(static_cast <bool> (!Parm->getDefaultArgStorage() . ValueOrInherited.template is<ParmDecl *>() && "should only be one level of indirection" ) ? void (0) : __assert_fail ("!Parm->getDefaultArgStorage() .ValueOrInherited.template is<ParmDecl *>() && \"should only be one level of indirection\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 306, __extension__ __PRETTY_FUNCTION__)) | |||
306 | "should only be one level of indirection")(static_cast <bool> (!Parm->getDefaultArgStorage() . ValueOrInherited.template is<ParmDecl *>() && "should only be one level of indirection" ) ? void (0) : __assert_fail ("!Parm->getDefaultArgStorage() .ValueOrInherited.template is<ParmDecl *>() && \"should only be one level of indirection\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 306, __extension__ __PRETTY_FUNCTION__)); | |||
307 | return Parm; | |||
308 | } | |||
309 | ||||
310 | public: | |||
311 | DefaultArgStorage() : ValueOrInherited(ArgType()) {} | |||
312 | ||||
313 | /// Determine whether there is a default argument for this parameter. | |||
314 | bool isSet() const { return !ValueOrInherited.isNull(); } | |||
315 | ||||
316 | /// Determine whether the default argument for this parameter was inherited | |||
317 | /// from a previous declaration of the same entity. | |||
318 | bool isInherited() const { return ValueOrInherited.template is<ParmDecl*>(); } | |||
319 | ||||
320 | /// Get the default argument's value. This does not consider whether the | |||
321 | /// default argument is visible. | |||
322 | ArgType get() const { | |||
323 | const DefaultArgStorage *Storage = this; | |||
324 | if (auto *Prev = ValueOrInherited.template dyn_cast<ParmDecl*>()) | |||
325 | Storage = &Prev->getDefaultArgStorage(); | |||
326 | if (auto *C = Storage->ValueOrInherited.template dyn_cast<Chain*>()) | |||
327 | return C->Value; | |||
328 | return Storage->ValueOrInherited.template get<ArgType>(); | |||
329 | } | |||
330 | ||||
331 | /// Get the parameter from which we inherit the default argument, if any. | |||
332 | /// This is the parameter on which the default argument was actually written. | |||
333 | const ParmDecl *getInheritedFrom() const { | |||
334 | if (auto *D = ValueOrInherited.template dyn_cast<ParmDecl*>()) | |||
335 | return D; | |||
336 | if (auto *C = ValueOrInherited.template dyn_cast<Chain*>()) | |||
337 | return C->PrevDeclWithDefaultArg; | |||
338 | return nullptr; | |||
339 | } | |||
340 | ||||
341 | /// Set the default argument. | |||
342 | void set(ArgType Arg) { | |||
343 | assert(!isSet() && "default argument already set")(static_cast <bool> (!isSet() && "default argument already set" ) ? void (0) : __assert_fail ("!isSet() && \"default argument already set\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 343, __extension__ __PRETTY_FUNCTION__)); | |||
344 | ValueOrInherited = Arg; | |||
345 | } | |||
346 | ||||
347 | /// Set that the default argument was inherited from another parameter. | |||
348 | void setInherited(const ASTContext &C, ParmDecl *InheritedFrom) { | |||
349 | assert(!isInherited() && "default argument already inherited")(static_cast <bool> (!isInherited() && "default argument already inherited" ) ? void (0) : __assert_fail ("!isInherited() && \"default argument already inherited\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 349, __extension__ __PRETTY_FUNCTION__)); | |||
350 | InheritedFrom = getParmOwningDefaultArg(InheritedFrom); | |||
351 | if (!isSet()) | |||
352 | ValueOrInherited = InheritedFrom; | |||
353 | else | |||
354 | ValueOrInherited = new (allocateDefaultArgStorageChain(C)) | |||
355 | Chain{InheritedFrom, ValueOrInherited.template get<ArgType>()}; | |||
356 | } | |||
357 | ||||
358 | /// Remove the default argument, even if it was inherited. | |||
359 | void clear() { | |||
360 | ValueOrInherited = ArgType(); | |||
361 | } | |||
362 | }; | |||
363 | ||||
364 | //===----------------------------------------------------------------------===// | |||
365 | // Kinds of Templates | |||
366 | //===----------------------------------------------------------------------===// | |||
367 | ||||
368 | /// \brief Stores the template parameter list and associated constraints for | |||
369 | /// \c TemplateDecl objects that track associated constraints. | |||
370 | class ConstrainedTemplateDeclInfo { | |||
371 | friend TemplateDecl; | |||
372 | ||||
373 | public: | |||
374 | ConstrainedTemplateDeclInfo() = default; | |||
375 | ||||
376 | TemplateParameterList *getTemplateParameters() const { | |||
377 | return TemplateParams; | |||
378 | } | |||
379 | ||||
380 | Expr *getAssociatedConstraints() const { return AssociatedConstraints; } | |||
381 | ||||
382 | protected: | |||
383 | void setTemplateParameters(TemplateParameterList *TParams) { | |||
384 | TemplateParams = TParams; | |||
385 | } | |||
386 | ||||
387 | void setAssociatedConstraints(Expr *AC) { AssociatedConstraints = AC; } | |||
388 | ||||
389 | TemplateParameterList *TemplateParams = nullptr; | |||
390 | Expr *AssociatedConstraints = nullptr; | |||
391 | }; | |||
392 | ||||
393 | ||||
394 | /// \brief The base class of all kinds of template declarations (e.g., | |||
395 | /// class, function, etc.). | |||
396 | /// | |||
397 | /// The TemplateDecl class stores the list of template parameters and a | |||
398 | /// reference to the templated scoped declaration: the underlying AST node. | |||
399 | class TemplateDecl : public NamedDecl { | |||
400 | void anchor() override; | |||
401 | ||||
402 | protected: | |||
403 | // Construct a template decl with the given name and parameters. | |||
404 | // Used when there is no templated element (e.g., for tt-params). | |||
405 | TemplateDecl(ConstrainedTemplateDeclInfo *CTDI, Kind DK, DeclContext *DC, | |||
406 | SourceLocation L, DeclarationName Name, | |||
407 | TemplateParameterList *Params) | |||
408 | : NamedDecl(DK, DC, L, Name), TemplatedDecl(nullptr), | |||
409 | TemplateParams(CTDI) { | |||
410 | this->setTemplateParameters(Params); | |||
411 | } | |||
412 | ||||
413 | TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name, | |||
414 | TemplateParameterList *Params) | |||
415 | : TemplateDecl(nullptr, DK, DC, L, Name, Params) {} | |||
416 | ||||
417 | // Construct a template decl with name, parameters, and templated element. | |||
418 | TemplateDecl(ConstrainedTemplateDeclInfo *CTDI, Kind DK, DeclContext *DC, | |||
419 | SourceLocation L, DeclarationName Name, | |||
420 | TemplateParameterList *Params, NamedDecl *Decl) | |||
421 | : NamedDecl(DK, DC, L, Name), TemplatedDecl(Decl), | |||
422 | TemplateParams(CTDI) { | |||
423 | this->setTemplateParameters(Params); | |||
424 | } | |||
425 | ||||
426 | TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name, | |||
427 | TemplateParameterList *Params, NamedDecl *Decl) | |||
428 | : TemplateDecl(nullptr, DK, DC, L, Name, Params, Decl) {} | |||
429 | ||||
430 | public: | |||
431 | /// Get the list of template parameters | |||
432 | TemplateParameterList *getTemplateParameters() const { | |||
433 | const auto *const CTDI = | |||
434 | TemplateParams.dyn_cast<ConstrainedTemplateDeclInfo *>(); | |||
435 | return CTDI ? CTDI->getTemplateParameters() | |||
436 | : TemplateParams.get<TemplateParameterList *>(); | |||
437 | } | |||
438 | ||||
439 | /// Get the constraint-expression from the associated requires-clause (if any) | |||
440 | const Expr *getRequiresClause() const { | |||
441 | const TemplateParameterList *const TP = getTemplateParameters(); | |||
442 | return TP ? TP->getRequiresClause() : nullptr; | |||
443 | } | |||
444 | ||||
445 | Expr *getAssociatedConstraints() const { | |||
446 | const TemplateDecl *const C = cast<TemplateDecl>(getCanonicalDecl()); | |||
447 | const auto *const CTDI = | |||
448 | C->TemplateParams.dyn_cast<ConstrainedTemplateDeclInfo *>(); | |||
449 | return CTDI ? CTDI->getAssociatedConstraints() : nullptr; | |||
450 | } | |||
451 | ||||
452 | /// Get the underlying, templated declaration. | |||
453 | NamedDecl *getTemplatedDecl() const { return TemplatedDecl; } | |||
454 | ||||
455 | // Implement isa/cast/dyncast/etc. | |||
456 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } | |||
457 | ||||
458 | static bool classofKind(Kind K) { | |||
459 | return K >= firstTemplate && K <= lastTemplate; | |||
460 | } | |||
461 | ||||
462 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)) { | |||
463 | return SourceRange(getTemplateParameters()->getTemplateLoc(), | |||
464 | TemplatedDecl->getSourceRange().getEnd()); | |||
465 | } | |||
466 | ||||
467 | protected: | |||
468 | NamedDecl *TemplatedDecl; | |||
469 | /// \brief The template parameter list and optional requires-clause | |||
470 | /// associated with this declaration; alternatively, a | |||
471 | /// \c ConstrainedTemplateDeclInfo if the associated constraints of the | |||
472 | /// template are being tracked by this particular declaration. | |||
473 | llvm::PointerUnion<TemplateParameterList *, | |||
474 | ConstrainedTemplateDeclInfo *> | |||
475 | TemplateParams; | |||
476 | ||||
477 | void setTemplateParameters(TemplateParameterList *TParams) { | |||
478 | if (auto *const CTDI = | |||
479 | TemplateParams.dyn_cast<ConstrainedTemplateDeclInfo *>()) { | |||
480 | CTDI->setTemplateParameters(TParams); | |||
481 | } else { | |||
482 | TemplateParams = TParams; | |||
483 | } | |||
484 | } | |||
485 | ||||
486 | void setAssociatedConstraints(Expr *AC) { | |||
487 | assert(isCanonicalDecl() &&(static_cast <bool> (isCanonicalDecl() && "Attaching associated constraints to non-canonical Decl" ) ? void (0) : __assert_fail ("isCanonicalDecl() && \"Attaching associated constraints to non-canonical Decl\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 488, __extension__ __PRETTY_FUNCTION__)) | |||
488 | "Attaching associated constraints to non-canonical Decl")(static_cast <bool> (isCanonicalDecl() && "Attaching associated constraints to non-canonical Decl" ) ? void (0) : __assert_fail ("isCanonicalDecl() && \"Attaching associated constraints to non-canonical Decl\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 488, __extension__ __PRETTY_FUNCTION__)); | |||
489 | TemplateParams.get<ConstrainedTemplateDeclInfo *>() | |||
490 | ->setAssociatedConstraints(AC); | |||
491 | } | |||
492 | ||||
493 | public: | |||
494 | /// \brief Initialize the underlying templated declaration and | |||
495 | /// template parameters. | |||
496 | void init(NamedDecl *templatedDecl, TemplateParameterList* templateParams) { | |||
497 | assert(!TemplatedDecl && "TemplatedDecl already set!")(static_cast <bool> (!TemplatedDecl && "TemplatedDecl already set!" ) ? void (0) : __assert_fail ("!TemplatedDecl && \"TemplatedDecl already set!\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 497, __extension__ __PRETTY_FUNCTION__)); | |||
498 | assert(!TemplateParams && "TemplateParams already set!")(static_cast <bool> (!TemplateParams && "TemplateParams already set!" ) ? void (0) : __assert_fail ("!TemplateParams && \"TemplateParams already set!\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 498, __extension__ __PRETTY_FUNCTION__)); | |||
499 | TemplatedDecl = templatedDecl; | |||
500 | TemplateParams = templateParams; | |||
501 | } | |||
502 | }; | |||
503 | ||||
504 | /// \brief Provides information about a function template specialization, | |||
505 | /// which is a FunctionDecl that has been explicitly specialization or | |||
506 | /// instantiated from a function template. | |||
507 | class FunctionTemplateSpecializationInfo : public llvm::FoldingSetNode { | |||
508 | FunctionTemplateSpecializationInfo(FunctionDecl *FD, | |||
509 | FunctionTemplateDecl *Template, | |||
510 | TemplateSpecializationKind TSK, | |||
511 | const TemplateArgumentList *TemplateArgs, | |||
512 | const ASTTemplateArgumentListInfo *TemplateArgsAsWritten, | |||
513 | SourceLocation POI) | |||
514 | : Function(FD), Template(Template, TSK - 1), | |||
515 | TemplateArguments(TemplateArgs), | |||
516 | TemplateArgumentsAsWritten(TemplateArgsAsWritten), | |||
517 | PointOfInstantiation(POI) {} | |||
518 | ||||
519 | public: | |||
520 | static FunctionTemplateSpecializationInfo * | |||
521 | Create(ASTContext &C, FunctionDecl *FD, FunctionTemplateDecl *Template, | |||
522 | TemplateSpecializationKind TSK, | |||
523 | const TemplateArgumentList *TemplateArgs, | |||
524 | const TemplateArgumentListInfo *TemplateArgsAsWritten, | |||
525 | SourceLocation POI); | |||
526 | ||||
527 | /// \brief The function template specialization that this structure | |||
528 | /// describes. | |||
529 | FunctionDecl *Function; | |||
530 | ||||
531 | /// \brief The function template from which this function template | |||
532 | /// specialization was generated. | |||
533 | /// | |||
534 | /// The two bits contain the top 4 values of TemplateSpecializationKind. | |||
535 | llvm::PointerIntPair<FunctionTemplateDecl *, 2> Template; | |||
536 | ||||
537 | /// \brief The template arguments used to produce the function template | |||
538 | /// specialization from the function template. | |||
539 | const TemplateArgumentList *TemplateArguments; | |||
540 | ||||
541 | /// \brief The template arguments as written in the sources, if provided. | |||
542 | const ASTTemplateArgumentListInfo *TemplateArgumentsAsWritten; | |||
543 | ||||
544 | /// \brief The point at which this function template specialization was | |||
545 | /// first instantiated. | |||
546 | SourceLocation PointOfInstantiation; | |||
547 | ||||
548 | /// \brief Retrieve the template from which this function was specialized. | |||
549 | FunctionTemplateDecl *getTemplate() const { return Template.getPointer(); } | |||
550 | ||||
551 | /// \brief Determine what kind of template specialization this is. | |||
552 | TemplateSpecializationKind getTemplateSpecializationKind() const { | |||
553 | return (TemplateSpecializationKind)(Template.getInt() + 1); | |||
554 | } | |||
555 | ||||
556 | bool isExplicitSpecialization() const { | |||
557 | return getTemplateSpecializationKind() == TSK_ExplicitSpecialization; | |||
558 | } | |||
559 | ||||
560 | /// \brief True if this declaration is an explicit specialization, | |||
561 | /// explicit instantiation declaration, or explicit instantiation | |||
562 | /// definition. | |||
563 | bool isExplicitInstantiationOrSpecialization() const { | |||
564 | return isTemplateExplicitInstantiationOrSpecialization( | |||
565 | getTemplateSpecializationKind()); | |||
566 | } | |||
567 | ||||
568 | /// \brief Set the template specialization kind. | |||
569 | void setTemplateSpecializationKind(TemplateSpecializationKind TSK) { | |||
570 | assert(TSK != TSK_Undeclared &&(static_cast <bool> (TSK != TSK_Undeclared && "Cannot encode TSK_Undeclared for a function template specialization" ) ? void (0) : __assert_fail ("TSK != TSK_Undeclared && \"Cannot encode TSK_Undeclared for a function template specialization\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 571, __extension__ __PRETTY_FUNCTION__)) | |||
571 | "Cannot encode TSK_Undeclared for a function template specialization")(static_cast <bool> (TSK != TSK_Undeclared && "Cannot encode TSK_Undeclared for a function template specialization" ) ? void (0) : __assert_fail ("TSK != TSK_Undeclared && \"Cannot encode TSK_Undeclared for a function template specialization\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 571, __extension__ __PRETTY_FUNCTION__)); | |||
572 | Template.setInt(TSK - 1); | |||
573 | } | |||
574 | ||||
575 | /// \brief Retrieve the first point of instantiation of this function | |||
576 | /// template specialization. | |||
577 | /// | |||
578 | /// The point of instantiation may be an invalid source location if this | |||
579 | /// function has yet to be instantiated. | |||
580 | SourceLocation getPointOfInstantiation() const { | |||
581 | return PointOfInstantiation; | |||
582 | } | |||
583 | ||||
584 | /// \brief Set the (first) point of instantiation of this function template | |||
585 | /// specialization. | |||
586 | void setPointOfInstantiation(SourceLocation POI) { | |||
587 | PointOfInstantiation = POI; | |||
588 | } | |||
589 | ||||
590 | void Profile(llvm::FoldingSetNodeID &ID) { | |||
591 | Profile(ID, TemplateArguments->asArray(), | |||
592 | Function->getASTContext()); | |||
593 | } | |||
594 | ||||
595 | static void | |||
596 | Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs, | |||
597 | ASTContext &Context) { | |||
598 | ID.AddInteger(TemplateArgs.size()); | |||
599 | for (const TemplateArgument &TemplateArg : TemplateArgs) | |||
600 | TemplateArg.Profile(ID, Context); | |||
601 | } | |||
602 | }; | |||
603 | ||||
604 | /// \brief Provides information a specialization of a member of a class | |||
605 | /// template, which may be a member function, static data member, | |||
606 | /// member class or member enumeration. | |||
607 | class MemberSpecializationInfo { | |||
608 | // The member declaration from which this member was instantiated, and the | |||
609 | // manner in which the instantiation occurred (in the lower two bits). | |||
610 | llvm::PointerIntPair<NamedDecl *, 2> MemberAndTSK; | |||
611 | ||||
612 | // The point at which this member was first instantiated. | |||
613 | SourceLocation PointOfInstantiation; | |||
614 | ||||
615 | public: | |||
616 | explicit | |||
617 | MemberSpecializationInfo(NamedDecl *IF, TemplateSpecializationKind TSK, | |||
618 | SourceLocation POI = SourceLocation()) | |||
619 | : MemberAndTSK(IF, TSK - 1), PointOfInstantiation(POI) { | |||
620 | assert(TSK != TSK_Undeclared &&(static_cast <bool> (TSK != TSK_Undeclared && "Cannot encode undeclared template specializations for members" ) ? void (0) : __assert_fail ("TSK != TSK_Undeclared && \"Cannot encode undeclared template specializations for members\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 621, __extension__ __PRETTY_FUNCTION__)) | |||
621 | "Cannot encode undeclared template specializations for members")(static_cast <bool> (TSK != TSK_Undeclared && "Cannot encode undeclared template specializations for members" ) ? void (0) : __assert_fail ("TSK != TSK_Undeclared && \"Cannot encode undeclared template specializations for members\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 621, __extension__ __PRETTY_FUNCTION__)); | |||
622 | } | |||
623 | ||||
624 | /// \brief Retrieve the member declaration from which this member was | |||
625 | /// instantiated. | |||
626 | NamedDecl *getInstantiatedFrom() const { return MemberAndTSK.getPointer(); } | |||
627 | ||||
628 | /// \brief Determine what kind of template specialization this is. | |||
629 | TemplateSpecializationKind getTemplateSpecializationKind() const { | |||
630 | return (TemplateSpecializationKind)(MemberAndTSK.getInt() + 1); | |||
631 | } | |||
632 | ||||
633 | bool isExplicitSpecialization() const { | |||
634 | return getTemplateSpecializationKind() == TSK_ExplicitSpecialization; | |||
635 | } | |||
636 | ||||
637 | /// \brief Set the template specialization kind. | |||
638 | void setTemplateSpecializationKind(TemplateSpecializationKind TSK) { | |||
639 | assert(TSK != TSK_Undeclared &&(static_cast <bool> (TSK != TSK_Undeclared && "Cannot encode undeclared template specializations for members" ) ? void (0) : __assert_fail ("TSK != TSK_Undeclared && \"Cannot encode undeclared template specializations for members\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 640, __extension__ __PRETTY_FUNCTION__)) | |||
640 | "Cannot encode undeclared template specializations for members")(static_cast <bool> (TSK != TSK_Undeclared && "Cannot encode undeclared template specializations for members" ) ? void (0) : __assert_fail ("TSK != TSK_Undeclared && \"Cannot encode undeclared template specializations for members\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 640, __extension__ __PRETTY_FUNCTION__)); | |||
641 | MemberAndTSK.setInt(TSK - 1); | |||
642 | } | |||
643 | ||||
644 | /// \brief Retrieve the first point of instantiation of this member. | |||
645 | /// If the point of instantiation is an invalid location, then this member | |||
646 | /// has not yet been instantiated. | |||
647 | SourceLocation getPointOfInstantiation() const { | |||
648 | return PointOfInstantiation; | |||
649 | } | |||
650 | ||||
651 | /// \brief Set the first point of instantiation. | |||
652 | void setPointOfInstantiation(SourceLocation POI) { | |||
653 | PointOfInstantiation = POI; | |||
654 | } | |||
655 | }; | |||
656 | ||||
657 | /// \brief Provides information about a dependent function-template | |||
658 | /// specialization declaration. | |||
659 | /// | |||
660 | /// Since explicit function template specialization and instantiation | |||
661 | /// declarations can only appear in namespace scope, and you can only | |||
662 | /// specialize a member of a fully-specialized class, the only way to | |||
663 | /// get one of these is in a friend declaration like the following: | |||
664 | /// | |||
665 | /// \code | |||
666 | /// template \<class T> void foo(T); | |||
667 | /// template \<class T> class A { | |||
668 | /// friend void foo<>(T); | |||
669 | /// }; | |||
670 | /// \endcode | |||
671 | class DependentFunctionTemplateSpecializationInfo final | |||
672 | : private llvm::TrailingObjects<DependentFunctionTemplateSpecializationInfo, | |||
673 | TemplateArgumentLoc, | |||
674 | FunctionTemplateDecl *> { | |||
675 | /// The number of potential template candidates. | |||
676 | unsigned NumTemplates; | |||
677 | ||||
678 | /// The number of template arguments. | |||
679 | unsigned NumArgs; | |||
680 | ||||
681 | /// The locations of the left and right angle brackets. | |||
682 | SourceRange AngleLocs; | |||
683 | ||||
684 | size_t numTrailingObjects(OverloadToken<TemplateArgumentLoc>) const { | |||
685 | return NumArgs; | |||
686 | } | |||
687 | size_t numTrailingObjects(OverloadToken<FunctionTemplateDecl *>) const { | |||
688 | return NumTemplates; | |||
689 | } | |||
690 | ||||
691 | DependentFunctionTemplateSpecializationInfo( | |||
692 | const UnresolvedSetImpl &Templates, | |||
693 | const TemplateArgumentListInfo &TemplateArgs); | |||
694 | ||||
695 | public: | |||
696 | friend TrailingObjects; | |||
697 | ||||
698 | static DependentFunctionTemplateSpecializationInfo * | |||
699 | Create(ASTContext &Context, const UnresolvedSetImpl &Templates, | |||
700 | const TemplateArgumentListInfo &TemplateArgs); | |||
701 | ||||
702 | /// \brief Returns the number of function templates that this might | |||
703 | /// be a specialization of. | |||
704 | unsigned getNumTemplates() const { return NumTemplates; } | |||
705 | ||||
706 | /// \brief Returns the i'th template candidate. | |||
707 | FunctionTemplateDecl *getTemplate(unsigned I) const { | |||
708 | assert(I < getNumTemplates() && "template index out of range")(static_cast <bool> (I < getNumTemplates() && "template index out of range") ? void (0) : __assert_fail ("I < getNumTemplates() && \"template index out of range\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 708, __extension__ __PRETTY_FUNCTION__)); | |||
709 | return getTrailingObjects<FunctionTemplateDecl *>()[I]; | |||
710 | } | |||
711 | ||||
712 | /// \brief Returns the explicit template arguments that were given. | |||
713 | const TemplateArgumentLoc *getTemplateArgs() const { | |||
714 | return getTrailingObjects<TemplateArgumentLoc>(); | |||
715 | } | |||
716 | ||||
717 | /// \brief Returns the number of explicit template arguments that were given. | |||
718 | unsigned getNumTemplateArgs() const { return NumArgs; } | |||
719 | ||||
720 | /// \brief Returns the nth template argument. | |||
721 | const TemplateArgumentLoc &getTemplateArg(unsigned I) const { | |||
722 | assert(I < getNumTemplateArgs() && "template arg index out of range")(static_cast <bool> (I < getNumTemplateArgs() && "template arg index out of range") ? void (0) : __assert_fail ("I < getNumTemplateArgs() && \"template arg index out of range\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 722, __extension__ __PRETTY_FUNCTION__)); | |||
723 | return getTemplateArgs()[I]; | |||
724 | } | |||
725 | ||||
726 | SourceLocation getLAngleLoc() const { | |||
727 | return AngleLocs.getBegin(); | |||
728 | } | |||
729 | ||||
730 | SourceLocation getRAngleLoc() const { | |||
731 | return AngleLocs.getEnd(); | |||
732 | } | |||
733 | }; | |||
734 | ||||
735 | /// Declaration of a redeclarable template. | |||
736 | class RedeclarableTemplateDecl : public TemplateDecl, | |||
737 | public Redeclarable<RedeclarableTemplateDecl> | |||
738 | { | |||
739 | using redeclarable_base = Redeclarable<RedeclarableTemplateDecl>; | |||
740 | ||||
741 | RedeclarableTemplateDecl *getNextRedeclarationImpl() override { | |||
742 | return getNextRedeclaration(); | |||
743 | } | |||
744 | ||||
745 | RedeclarableTemplateDecl *getPreviousDeclImpl() override { | |||
746 | return getPreviousDecl(); | |||
747 | } | |||
748 | ||||
749 | RedeclarableTemplateDecl *getMostRecentDeclImpl() override { | |||
750 | return getMostRecentDecl(); | |||
751 | } | |||
752 | ||||
753 | protected: | |||
754 | template <typename EntryType> struct SpecEntryTraits { | |||
755 | using DeclType = EntryType; | |||
756 | ||||
757 | static DeclType *getDecl(EntryType *D) { | |||
758 | return D; | |||
759 | } | |||
760 | ||||
761 | static ArrayRef<TemplateArgument> getTemplateArgs(EntryType *D) { | |||
762 | return D->getTemplateArgs().asArray(); | |||
763 | } | |||
764 | }; | |||
765 | ||||
766 | template <typename EntryType, typename SETraits = SpecEntryTraits<EntryType>, | |||
767 | typename DeclType = typename SETraits::DeclType> | |||
768 | struct SpecIterator | |||
769 | : llvm::iterator_adaptor_base< | |||
770 | SpecIterator<EntryType, SETraits, DeclType>, | |||
771 | typename llvm::FoldingSetVector<EntryType>::iterator, | |||
772 | typename std::iterator_traits<typename llvm::FoldingSetVector< | |||
773 | EntryType>::iterator>::iterator_category, | |||
774 | DeclType *, ptrdiff_t, DeclType *, DeclType *> { | |||
775 | SpecIterator() = default; | |||
776 | explicit SpecIterator( | |||
777 | typename llvm::FoldingSetVector<EntryType>::iterator SetIter) | |||
778 | : SpecIterator::iterator_adaptor_base(std::move(SetIter)) {} | |||
779 | ||||
780 | DeclType *operator*() const { | |||
781 | return SETraits::getDecl(&*this->I)->getMostRecentDecl(); | |||
782 | } | |||
783 | ||||
784 | DeclType *operator->() const { return **this; } | |||
785 | }; | |||
786 | ||||
787 | template <typename EntryType> | |||
788 | static SpecIterator<EntryType> | |||
789 | makeSpecIterator(llvm::FoldingSetVector<EntryType> &Specs, bool isEnd) { | |||
790 | return SpecIterator<EntryType>(isEnd ? Specs.end() : Specs.begin()); | |||
791 | } | |||
792 | ||||
793 | void loadLazySpecializationsImpl() const; | |||
794 | ||||
795 | template <class EntryType> typename SpecEntryTraits<EntryType>::DeclType* | |||
796 | findSpecializationImpl(llvm::FoldingSetVector<EntryType> &Specs, | |||
797 | ArrayRef<TemplateArgument> Args, void *&InsertPos); | |||
798 | ||||
799 | template <class Derived, class EntryType> | |||
800 | void addSpecializationImpl(llvm::FoldingSetVector<EntryType> &Specs, | |||
801 | EntryType *Entry, void *InsertPos); | |||
802 | ||||
803 | struct CommonBase { | |||
804 | CommonBase() : InstantiatedFromMember(nullptr, false) {} | |||
805 | ||||
806 | /// \brief The template from which this was most | |||
807 | /// directly instantiated (or null). | |||
808 | /// | |||
809 | /// The boolean value indicates whether this template | |||
810 | /// was explicitly specialized. | |||
811 | llvm::PointerIntPair<RedeclarableTemplateDecl*, 1, bool> | |||
812 | InstantiatedFromMember; | |||
813 | ||||
814 | /// \brief If non-null, points to an array of specializations (including | |||
815 | /// partial specializations) known only by their external declaration IDs. | |||
816 | /// | |||
817 | /// The first value in the array is the number of specializations/partial | |||
818 | /// specializations that follow. | |||
819 | uint32_t *LazySpecializations = nullptr; | |||
820 | }; | |||
821 | ||||
822 | /// \brief Pointer to the common data shared by all declarations of this | |||
823 | /// template. | |||
824 | mutable CommonBase *Common = nullptr; | |||
825 | ||||
826 | /// \brief Retrieves the "common" pointer shared by all (re-)declarations of | |||
827 | /// the same template. Calling this routine may implicitly allocate memory | |||
828 | /// for the common pointer. | |||
829 | CommonBase *getCommonPtr() const; | |||
830 | ||||
831 | virtual CommonBase *newCommon(ASTContext &C) const = 0; | |||
832 | ||||
833 | // Construct a template decl with name, parameters, and templated element. | |||
834 | RedeclarableTemplateDecl(ConstrainedTemplateDeclInfo *CTDI, Kind DK, | |||
835 | ASTContext &C, DeclContext *DC, SourceLocation L, | |||
836 | DeclarationName Name, TemplateParameterList *Params, | |||
837 | NamedDecl *Decl) | |||
838 | : TemplateDecl(CTDI, DK, DC, L, Name, Params, Decl), redeclarable_base(C) | |||
839 | {} | |||
840 | ||||
841 | RedeclarableTemplateDecl(Kind DK, ASTContext &C, DeclContext *DC, | |||
842 | SourceLocation L, DeclarationName Name, | |||
843 | TemplateParameterList *Params, NamedDecl *Decl) | |||
844 | : RedeclarableTemplateDecl(nullptr, DK, C, DC, L, Name, Params, Decl) {} | |||
845 | ||||
846 | public: | |||
847 | friend class ASTDeclReader; | |||
848 | friend class ASTDeclWriter; | |||
849 | friend class ASTReader; | |||
850 | template <class decl_type> friend class RedeclarableTemplate; | |||
851 | ||||
852 | /// \brief Retrieves the canonical declaration of this template. | |||
853 | RedeclarableTemplateDecl *getCanonicalDecl() override { | |||
854 | return getFirstDecl(); | |||
855 | } | |||
856 | const RedeclarableTemplateDecl *getCanonicalDecl() const { | |||
857 | return getFirstDecl(); | |||
858 | } | |||
859 | ||||
860 | /// \brief Determines whether this template was a specialization of a | |||
861 | /// member template. | |||
862 | /// | |||
863 | /// In the following example, the function template \c X<int>::f and the | |||
864 | /// member template \c X<int>::Inner are member specializations. | |||
865 | /// | |||
866 | /// \code | |||
867 | /// template<typename T> | |||
868 | /// struct X { | |||
869 | /// template<typename U> void f(T, U); | |||
870 | /// template<typename U> struct Inner; | |||
871 | /// }; | |||
872 | /// | |||
873 | /// template<> template<typename T> | |||
874 | /// void X<int>::f(int, T); | |||
875 | /// template<> template<typename T> | |||
876 | /// struct X<int>::Inner { /* ... */ }; | |||
877 | /// \endcode | |||
878 | bool isMemberSpecialization() const { | |||
879 | return getCommonPtr()->InstantiatedFromMember.getInt(); | |||
880 | } | |||
881 | ||||
882 | /// \brief Note that this member template is a specialization. | |||
883 | void setMemberSpecialization() { | |||
884 | assert(getCommonPtr()->InstantiatedFromMember.getPointer() &&(static_cast <bool> (getCommonPtr()->InstantiatedFromMember .getPointer() && "Only member templates can be member template specializations" ) ? void (0) : __assert_fail ("getCommonPtr()->InstantiatedFromMember.getPointer() && \"Only member templates can be member template specializations\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 885, __extension__ __PRETTY_FUNCTION__)) | |||
885 | "Only member templates can be member template specializations")(static_cast <bool> (getCommonPtr()->InstantiatedFromMember .getPointer() && "Only member templates can be member template specializations" ) ? void (0) : __assert_fail ("getCommonPtr()->InstantiatedFromMember.getPointer() && \"Only member templates can be member template specializations\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 885, __extension__ __PRETTY_FUNCTION__)); | |||
886 | getCommonPtr()->InstantiatedFromMember.setInt(true); | |||
887 | } | |||
888 | ||||
889 | /// \brief Retrieve the member template from which this template was | |||
890 | /// instantiated, or nullptr if this template was not instantiated from a | |||
891 | /// member template. | |||
892 | /// | |||
893 | /// A template is instantiated from a member template when the member | |||
894 | /// template itself is part of a class template (or member thereof). For | |||
895 | /// example, given | |||
896 | /// | |||
897 | /// \code | |||
898 | /// template<typename T> | |||
899 | /// struct X { | |||
900 | /// template<typename U> void f(T, U); | |||
901 | /// }; | |||
902 | /// | |||
903 | /// void test(X<int> x) { | |||
904 | /// x.f(1, 'a'); | |||
905 | /// }; | |||
906 | /// \endcode | |||
907 | /// | |||
908 | /// \c X<int>::f is a FunctionTemplateDecl that describes the function | |||
909 | /// template | |||
910 | /// | |||
911 | /// \code | |||
912 | /// template<typename U> void X<int>::f(int, U); | |||
913 | /// \endcode | |||
914 | /// | |||
915 | /// which was itself created during the instantiation of \c X<int>. Calling | |||
916 | /// getInstantiatedFromMemberTemplate() on this FunctionTemplateDecl will | |||
917 | /// retrieve the FunctionTemplateDecl for the original template \c f within | |||
918 | /// the class template \c X<T>, i.e., | |||
919 | /// | |||
920 | /// \code | |||
921 | /// template<typename T> | |||
922 | /// template<typename U> | |||
923 | /// void X<T>::f(T, U); | |||
924 | /// \endcode | |||
925 | RedeclarableTemplateDecl *getInstantiatedFromMemberTemplate() const { | |||
926 | return getCommonPtr()->InstantiatedFromMember.getPointer(); | |||
927 | } | |||
928 | ||||
929 | void setInstantiatedFromMemberTemplate(RedeclarableTemplateDecl *TD) { | |||
930 | assert(!getCommonPtr()->InstantiatedFromMember.getPointer())(static_cast <bool> (!getCommonPtr()->InstantiatedFromMember .getPointer()) ? void (0) : __assert_fail ("!getCommonPtr()->InstantiatedFromMember.getPointer()" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 930, __extension__ __PRETTY_FUNCTION__)); | |||
931 | getCommonPtr()->InstantiatedFromMember.setPointer(TD); | |||
932 | } | |||
933 | ||||
934 | using redecl_range = redeclarable_base::redecl_range; | |||
935 | using redecl_iterator = redeclarable_base::redecl_iterator; | |||
936 | ||||
937 | using redeclarable_base::redecls_begin; | |||
938 | using redeclarable_base::redecls_end; | |||
939 | using redeclarable_base::redecls; | |||
940 | using redeclarable_base::getPreviousDecl; | |||
941 | using redeclarable_base::getMostRecentDecl; | |||
942 | using redeclarable_base::isFirstDecl; | |||
943 | ||||
944 | // Implement isa/cast/dyncast/etc. | |||
945 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } | |||
946 | ||||
947 | static bool classofKind(Kind K) { | |||
948 | return K >= firstRedeclarableTemplate && K <= lastRedeclarableTemplate; | |||
949 | } | |||
950 | }; | |||
951 | ||||
952 | template <> struct RedeclarableTemplateDecl:: | |||
953 | SpecEntryTraits<FunctionTemplateSpecializationInfo> { | |||
954 | using DeclType = FunctionDecl; | |||
955 | ||||
956 | static DeclType *getDecl(FunctionTemplateSpecializationInfo *I) { | |||
957 | return I->Function; | |||
958 | } | |||
959 | ||||
960 | static ArrayRef<TemplateArgument> | |||
961 | getTemplateArgs(FunctionTemplateSpecializationInfo *I) { | |||
962 | return I->TemplateArguments->asArray(); | |||
963 | } | |||
964 | }; | |||
965 | ||||
966 | /// Declaration of a template function. | |||
967 | class FunctionTemplateDecl : public RedeclarableTemplateDecl { | |||
968 | protected: | |||
969 | friend class FunctionDecl; | |||
970 | ||||
971 | /// \brief Data that is common to all of the declarations of a given | |||
972 | /// function template. | |||
973 | struct Common : CommonBase { | |||
974 | /// \brief The function template specializations for this function | |||
975 | /// template, including explicit specializations and instantiations. | |||
976 | llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> Specializations; | |||
977 | ||||
978 | /// \brief The set of "injected" template arguments used within this | |||
979 | /// function template. | |||
980 | /// | |||
981 | /// This pointer refers to the template arguments (there are as | |||
982 | /// many template arguments as template parameaters) for the function | |||
983 | /// template, and is allocated lazily, since most function templates do not | |||
984 | /// require the use of this information. | |||
985 | TemplateArgument *InjectedArgs = nullptr; | |||
986 | ||||
987 | Common() = default; | |||
988 | }; | |||
989 | ||||
990 | FunctionTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L, | |||
991 | DeclarationName Name, TemplateParameterList *Params, | |||
992 | NamedDecl *Decl) | |||
993 | : RedeclarableTemplateDecl(FunctionTemplate, C, DC, L, Name, Params, | |||
994 | Decl) {} | |||
995 | ||||
996 | CommonBase *newCommon(ASTContext &C) const override; | |||
997 | ||||
998 | Common *getCommonPtr() const { | |||
999 | return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr()); | |||
1000 | } | |||
1001 | ||||
1002 | /// \brief Retrieve the set of function template specializations of this | |||
1003 | /// function template. | |||
1004 | llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> & | |||
1005 | getSpecializations() const; | |||
1006 | ||||
1007 | /// \brief Add a specialization of this function template. | |||
1008 | /// | |||
1009 | /// \param InsertPos Insert position in the FoldingSetVector, must have been | |||
1010 | /// retrieved by an earlier call to findSpecialization(). | |||
1011 | void addSpecialization(FunctionTemplateSpecializationInfo* Info, | |||
1012 | void *InsertPos); | |||
1013 | ||||
1014 | public: | |||
1015 | friend class ASTDeclReader; | |||
1016 | friend class ASTDeclWriter; | |||
1017 | ||||
1018 | /// \brief Load any lazily-loaded specializations from the external source. | |||
1019 | void LoadLazySpecializations() const; | |||
1020 | ||||
1021 | /// Get the underlying function declaration of the template. | |||
1022 | FunctionDecl *getTemplatedDecl() const { | |||
1023 | return static_cast<FunctionDecl *>(TemplatedDecl); | |||
1024 | } | |||
1025 | ||||
1026 | /// Returns whether this template declaration defines the primary | |||
1027 | /// pattern. | |||
1028 | bool isThisDeclarationADefinition() const { | |||
1029 | return getTemplatedDecl()->isThisDeclarationADefinition(); | |||
1030 | } | |||
1031 | ||||
1032 | /// \brief Return the specialization with the provided arguments if it exists, | |||
1033 | /// otherwise return the insertion point. | |||
1034 | FunctionDecl *findSpecialization(ArrayRef<TemplateArgument> Args, | |||
1035 | void *&InsertPos); | |||
1036 | ||||
1037 | FunctionTemplateDecl *getCanonicalDecl() override { | |||
1038 | return cast<FunctionTemplateDecl>( | |||
1039 | RedeclarableTemplateDecl::getCanonicalDecl()); | |||
1040 | } | |||
1041 | const FunctionTemplateDecl *getCanonicalDecl() const { | |||
1042 | return cast<FunctionTemplateDecl>( | |||
1043 | RedeclarableTemplateDecl::getCanonicalDecl()); | |||
1044 | } | |||
1045 | ||||
1046 | /// \brief Retrieve the previous declaration of this function template, or | |||
1047 | /// nullptr if no such declaration exists. | |||
1048 | FunctionTemplateDecl *getPreviousDecl() { | |||
1049 | return cast_or_null<FunctionTemplateDecl>( | |||
1050 | static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl()); | |||
1051 | } | |||
1052 | const FunctionTemplateDecl *getPreviousDecl() const { | |||
1053 | return cast_or_null<FunctionTemplateDecl>( | |||
1054 | static_cast<const RedeclarableTemplateDecl *>(this)->getPreviousDecl()); | |||
1055 | } | |||
1056 | ||||
1057 | FunctionTemplateDecl *getMostRecentDecl() { | |||
1058 | return cast<FunctionTemplateDecl>( | |||
1059 | static_cast<RedeclarableTemplateDecl *>(this) | |||
1060 | ->getMostRecentDecl()); | |||
1061 | } | |||
1062 | const FunctionTemplateDecl *getMostRecentDecl() const { | |||
1063 | return const_cast<FunctionTemplateDecl*>(this)->getMostRecentDecl(); | |||
1064 | } | |||
1065 | ||||
1066 | FunctionTemplateDecl *getInstantiatedFromMemberTemplate() const { | |||
1067 | return cast_or_null<FunctionTemplateDecl>( | |||
1068 | RedeclarableTemplateDecl::getInstantiatedFromMemberTemplate()); | |||
1069 | } | |||
1070 | ||||
1071 | using spec_iterator = SpecIterator<FunctionTemplateSpecializationInfo>; | |||
1072 | using spec_range = llvm::iterator_range<spec_iterator>; | |||
1073 | ||||
1074 | spec_range specializations() const { | |||
1075 | return spec_range(spec_begin(), spec_end()); | |||
1076 | } | |||
1077 | ||||
1078 | spec_iterator spec_begin() const { | |||
1079 | return makeSpecIterator(getSpecializations(), false); | |||
1080 | } | |||
1081 | ||||
1082 | spec_iterator spec_end() const { | |||
1083 | return makeSpecIterator(getSpecializations(), true); | |||
1084 | } | |||
1085 | ||||
1086 | /// \brief Retrieve the "injected" template arguments that correspond to the | |||
1087 | /// template parameters of this function template. | |||
1088 | /// | |||
1089 | /// Although the C++ standard has no notion of the "injected" template | |||
1090 | /// arguments for a function template, the notion is convenient when | |||
1091 | /// we need to perform substitutions inside the definition of a function | |||
1092 | /// template. | |||
1093 | ArrayRef<TemplateArgument> getInjectedTemplateArgs(); | |||
1094 | ||||
1095 | /// \brief Create a function template node. | |||
1096 | static FunctionTemplateDecl *Create(ASTContext &C, DeclContext *DC, | |||
1097 | SourceLocation L, | |||
1098 | DeclarationName Name, | |||
1099 | TemplateParameterList *Params, | |||
1100 | NamedDecl *Decl); | |||
1101 | ||||
1102 | /// \brief Create an empty function template node. | |||
1103 | static FunctionTemplateDecl *CreateDeserialized(ASTContext &C, unsigned ID); | |||
1104 | ||||
1105 | // Implement isa/cast/dyncast support | |||
1106 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } | |||
1107 | static bool classofKind(Kind K) { return K == FunctionTemplate; } | |||
1108 | }; | |||
1109 | ||||
1110 | //===----------------------------------------------------------------------===// | |||
1111 | // Kinds of Template Parameters | |||
1112 | //===----------------------------------------------------------------------===// | |||
1113 | ||||
1114 | /// \brief Defines the position of a template parameter within a template | |||
1115 | /// parameter list. | |||
1116 | /// | |||
1117 | /// Because template parameter can be listed | |||
1118 | /// sequentially for out-of-line template members, each template parameter is | |||
1119 | /// given a Depth - the nesting of template parameter scopes - and a Position - | |||
1120 | /// the occurrence within the parameter list. | |||
1121 | /// This class is inheritedly privately by different kinds of template | |||
1122 | /// parameters and is not part of the Decl hierarchy. Just a facility. | |||
1123 | class TemplateParmPosition { | |||
1124 | protected: | |||
1125 | // FIXME: These probably don't need to be ints. int:5 for depth, int:8 for | |||
1126 | // position? Maybe? | |||
1127 | unsigned Depth; | |||
1128 | unsigned Position; | |||
1129 | ||||
1130 | TemplateParmPosition(unsigned D, unsigned P) : Depth(D), Position(P) {} | |||
1131 | ||||
1132 | public: | |||
1133 | TemplateParmPosition() = delete; | |||
1134 | ||||
1135 | /// Get the nesting depth of the template parameter. | |||
1136 | unsigned getDepth() const { return Depth; } | |||
1137 | void setDepth(unsigned D) { Depth = D; } | |||
1138 | ||||
1139 | /// Get the position of the template parameter within its parameter list. | |||
1140 | unsigned getPosition() const { return Position; } | |||
1141 | void setPosition(unsigned P) { Position = P; } | |||
1142 | ||||
1143 | /// Get the index of the template parameter within its parameter list. | |||
1144 | unsigned getIndex() const { return Position; } | |||
1145 | }; | |||
1146 | ||||
1147 | /// \brief Declaration of a template type parameter. | |||
1148 | /// | |||
1149 | /// For example, "T" in | |||
1150 | /// \code | |||
1151 | /// template<typename T> class vector; | |||
1152 | /// \endcode | |||
1153 | class TemplateTypeParmDecl : public TypeDecl { | |||
1154 | /// Sema creates these on the stack during auto type deduction. | |||
1155 | friend class Sema; | |||
1156 | ||||
1157 | /// \brief Whether this template type parameter was declaration with | |||
1158 | /// the 'typename' keyword. | |||
1159 | /// | |||
1160 | /// If false, it was declared with the 'class' keyword. | |||
1161 | bool Typename : 1; | |||
1162 | ||||
1163 | /// \brief The default template argument, if any. | |||
1164 | using DefArgStorage = | |||
1165 | DefaultArgStorage<TemplateTypeParmDecl, TypeSourceInfo *>; | |||
1166 | DefArgStorage DefaultArgument; | |||
1167 | ||||
1168 | TemplateTypeParmDecl(DeclContext *DC, SourceLocation KeyLoc, | |||
1169 | SourceLocation IdLoc, IdentifierInfo *Id, | |||
1170 | bool Typename) | |||
1171 | : TypeDecl(TemplateTypeParm, DC, IdLoc, Id, KeyLoc), Typename(Typename) {} | |||
1172 | ||||
1173 | public: | |||
1174 | static TemplateTypeParmDecl *Create(const ASTContext &C, DeclContext *DC, | |||
1175 | SourceLocation KeyLoc, | |||
1176 | SourceLocation NameLoc, | |||
1177 | unsigned D, unsigned P, | |||
1178 | IdentifierInfo *Id, bool Typename, | |||
1179 | bool ParameterPack); | |||
1180 | static TemplateTypeParmDecl *CreateDeserialized(const ASTContext &C, | |||
1181 | unsigned ID); | |||
1182 | ||||
1183 | /// \brief Whether this template type parameter was declared with | |||
1184 | /// the 'typename' keyword. | |||
1185 | /// | |||
1186 | /// If not, it was declared with the 'class' keyword. | |||
1187 | bool wasDeclaredWithTypename() const { return Typename; } | |||
1188 | ||||
1189 | const DefArgStorage &getDefaultArgStorage() const { return DefaultArgument; } | |||
1190 | ||||
1191 | /// \brief Determine whether this template parameter has a default | |||
1192 | /// argument. | |||
1193 | bool hasDefaultArgument() const { return DefaultArgument.isSet(); } | |||
1194 | ||||
1195 | /// \brief Retrieve the default argument, if any. | |||
1196 | QualType getDefaultArgument() const { | |||
1197 | return DefaultArgument.get()->getType(); | |||
1198 | } | |||
1199 | ||||
1200 | /// \brief Retrieves the default argument's source information, if any. | |||
1201 | TypeSourceInfo *getDefaultArgumentInfo() const { | |||
1202 | return DefaultArgument.get(); | |||
1203 | } | |||
1204 | ||||
1205 | /// \brief Retrieves the location of the default argument declaration. | |||
1206 | SourceLocation getDefaultArgumentLoc() const; | |||
1207 | ||||
1208 | /// \brief Determines whether the default argument was inherited | |||
1209 | /// from a previous declaration of this template. | |||
1210 | bool defaultArgumentWasInherited() const { | |||
1211 | return DefaultArgument.isInherited(); | |||
1212 | } | |||
1213 | ||||
1214 | /// \brief Set the default argument for this template parameter. | |||
1215 | void setDefaultArgument(TypeSourceInfo *DefArg) { | |||
1216 | DefaultArgument.set(DefArg); | |||
1217 | } | |||
1218 | ||||
1219 | /// \brief Set that this default argument was inherited from another | |||
1220 | /// parameter. | |||
1221 | void setInheritedDefaultArgument(const ASTContext &C, | |||
1222 | TemplateTypeParmDecl *Prev) { | |||
1223 | DefaultArgument.setInherited(C, Prev); | |||
1224 | } | |||
1225 | ||||
1226 | /// \brief Removes the default argument of this template parameter. | |||
1227 | void removeDefaultArgument() { | |||
1228 | DefaultArgument.clear(); | |||
1229 | } | |||
1230 | ||||
1231 | /// \brief Set whether this template type parameter was declared with | |||
1232 | /// the 'typename' or 'class' keyword. | |||
1233 | void setDeclaredWithTypename(bool withTypename) { Typename = withTypename; } | |||
1234 | ||||
1235 | /// \brief Retrieve the depth of the template parameter. | |||
1236 | unsigned getDepth() const; | |||
1237 | ||||
1238 | /// \brief Retrieve the index of the template parameter. | |||
1239 | unsigned getIndex() const; | |||
1240 | ||||
1241 | /// \brief Returns whether this is a parameter pack. | |||
1242 | bool isParameterPack() const; | |||
1243 | ||||
1244 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)); | |||
1245 | ||||
1246 | // Implement isa/cast/dyncast/etc. | |||
1247 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } | |||
1248 | static bool classofKind(Kind K) { return K == TemplateTypeParm; } | |||
1249 | }; | |||
1250 | ||||
1251 | /// NonTypeTemplateParmDecl - Declares a non-type template parameter, | |||
1252 | /// e.g., "Size" in | |||
1253 | /// @code | |||
1254 | /// template<int Size> class array { }; | |||
1255 | /// @endcode | |||
1256 | class NonTypeTemplateParmDecl final | |||
1257 | : public DeclaratorDecl, | |||
1258 | protected TemplateParmPosition, | |||
1259 | private llvm::TrailingObjects<NonTypeTemplateParmDecl, | |||
1260 | std::pair<QualType, TypeSourceInfo *>> { | |||
1261 | friend class ASTDeclReader; | |||
1262 | friend TrailingObjects; | |||
1263 | ||||
1264 | /// \brief The default template argument, if any, and whether or not | |||
1265 | /// it was inherited. | |||
1266 | using DefArgStorage = DefaultArgStorage<NonTypeTemplateParmDecl, Expr *>; | |||
1267 | DefArgStorage DefaultArgument; | |||
1268 | ||||
1269 | // FIXME: Collapse this into TemplateParamPosition; or, just move depth/index | |||
1270 | // down here to save memory. | |||
1271 | ||||
1272 | /// \brief Whether this non-type template parameter is a parameter pack. | |||
1273 | bool ParameterPack; | |||
1274 | ||||
1275 | /// \brief Whether this non-type template parameter is an "expanded" | |||
1276 | /// parameter pack, meaning that its type is a pack expansion and we | |||
1277 | /// already know the set of types that expansion expands to. | |||
1278 | bool ExpandedParameterPack = false; | |||
1279 | ||||
1280 | /// \brief The number of types in an expanded parameter pack. | |||
1281 | unsigned NumExpandedTypes = 0; | |||
1282 | ||||
1283 | size_t numTrailingObjects( | |||
1284 | OverloadToken<std::pair<QualType, TypeSourceInfo *>>) const { | |||
1285 | return NumExpandedTypes; | |||
1286 | } | |||
1287 | ||||
1288 | NonTypeTemplateParmDecl(DeclContext *DC, SourceLocation StartLoc, | |||
1289 | SourceLocation IdLoc, unsigned D, unsigned P, | |||
1290 | IdentifierInfo *Id, QualType T, | |||
1291 | bool ParameterPack, TypeSourceInfo *TInfo) | |||
1292 | : DeclaratorDecl(NonTypeTemplateParm, DC, IdLoc, Id, T, TInfo, StartLoc), | |||
1293 | TemplateParmPosition(D, P), ParameterPack(ParameterPack) {} | |||
1294 | ||||
1295 | NonTypeTemplateParmDecl(DeclContext *DC, SourceLocation StartLoc, | |||
1296 | SourceLocation IdLoc, unsigned D, unsigned P, | |||
1297 | IdentifierInfo *Id, QualType T, | |||
1298 | TypeSourceInfo *TInfo, | |||
1299 | ArrayRef<QualType> ExpandedTypes, | |||
1300 | ArrayRef<TypeSourceInfo *> ExpandedTInfos); | |||
1301 | ||||
1302 | public: | |||
1303 | static NonTypeTemplateParmDecl * | |||
1304 | Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, | |||
1305 | SourceLocation IdLoc, unsigned D, unsigned P, IdentifierInfo *Id, | |||
1306 | QualType T, bool ParameterPack, TypeSourceInfo *TInfo); | |||
1307 | ||||
1308 | static NonTypeTemplateParmDecl * | |||
1309 | Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, | |||
1310 | SourceLocation IdLoc, unsigned D, unsigned P, IdentifierInfo *Id, | |||
1311 | QualType T, TypeSourceInfo *TInfo, ArrayRef<QualType> ExpandedTypes, | |||
1312 | ArrayRef<TypeSourceInfo *> ExpandedTInfos); | |||
1313 | ||||
1314 | static NonTypeTemplateParmDecl *CreateDeserialized(ASTContext &C, | |||
1315 | unsigned ID); | |||
1316 | static NonTypeTemplateParmDecl *CreateDeserialized(ASTContext &C, | |||
1317 | unsigned ID, | |||
1318 | unsigned NumExpandedTypes); | |||
1319 | ||||
1320 | using TemplateParmPosition::getDepth; | |||
1321 | using TemplateParmPosition::setDepth; | |||
1322 | using TemplateParmPosition::getPosition; | |||
1323 | using TemplateParmPosition::setPosition; | |||
1324 | using TemplateParmPosition::getIndex; | |||
1325 | ||||
1326 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)); | |||
1327 | ||||
1328 | const DefArgStorage &getDefaultArgStorage() const { return DefaultArgument; } | |||
1329 | ||||
1330 | /// \brief Determine whether this template parameter has a default | |||
1331 | /// argument. | |||
1332 | bool hasDefaultArgument() const { return DefaultArgument.isSet(); } | |||
1333 | ||||
1334 | /// \brief Retrieve the default argument, if any. | |||
1335 | Expr *getDefaultArgument() const { return DefaultArgument.get(); } | |||
1336 | ||||
1337 | /// \brief Retrieve the location of the default argument, if any. | |||
1338 | SourceLocation getDefaultArgumentLoc() const; | |||
1339 | ||||
1340 | /// \brief Determines whether the default argument was inherited | |||
1341 | /// from a previous declaration of this template. | |||
1342 | bool defaultArgumentWasInherited() const { | |||
1343 | return DefaultArgument.isInherited(); | |||
1344 | } | |||
1345 | ||||
1346 | /// \brief Set the default argument for this template parameter, and | |||
1347 | /// whether that default argument was inherited from another | |||
1348 | /// declaration. | |||
1349 | void setDefaultArgument(Expr *DefArg) { DefaultArgument.set(DefArg); } | |||
1350 | void setInheritedDefaultArgument(const ASTContext &C, | |||
1351 | NonTypeTemplateParmDecl *Parm) { | |||
1352 | DefaultArgument.setInherited(C, Parm); | |||
1353 | } | |||
1354 | ||||
1355 | /// \brief Removes the default argument of this template parameter. | |||
1356 | void removeDefaultArgument() { DefaultArgument.clear(); } | |||
1357 | ||||
1358 | /// \brief Whether this parameter is a non-type template parameter pack. | |||
1359 | /// | |||
1360 | /// If the parameter is a parameter pack, the type may be a | |||
1361 | /// \c PackExpansionType. In the following example, the \c Dims parameter | |||
1362 | /// is a parameter pack (whose type is 'unsigned'). | |||
1363 | /// | |||
1364 | /// \code | |||
1365 | /// template<typename T, unsigned ...Dims> struct multi_array; | |||
1366 | /// \endcode | |||
1367 | bool isParameterPack() const { return ParameterPack; } | |||
1368 | ||||
1369 | /// \brief Whether this parameter pack is a pack expansion. | |||
1370 | /// | |||
1371 | /// A non-type template parameter pack is a pack expansion if its type | |||
1372 | /// contains an unexpanded parameter pack. In this case, we will have | |||
1373 | /// built a PackExpansionType wrapping the type. | |||
1374 | bool isPackExpansion() const { | |||
1375 | return ParameterPack && getType()->getAs<PackExpansionType>(); | |||
1376 | } | |||
1377 | ||||
1378 | /// \brief Whether this parameter is a non-type template parameter pack | |||
1379 | /// that has a known list of different types at different positions. | |||
1380 | /// | |||
1381 | /// A parameter pack is an expanded parameter pack when the original | |||
1382 | /// parameter pack's type was itself a pack expansion, and that expansion | |||
1383 | /// has already been expanded. For example, given: | |||
1384 | /// | |||
1385 | /// \code | |||
1386 | /// template<typename ...Types> | |||
1387 | /// struct X { | |||
1388 | /// template<Types ...Values> | |||
1389 | /// struct Y { /* ... */ }; | |||
1390 | /// }; | |||
1391 | /// \endcode | |||
1392 | /// | |||
1393 | /// The parameter pack \c Values has a \c PackExpansionType as its type, | |||
1394 | /// which expands \c Types. When \c Types is supplied with template arguments | |||
1395 | /// by instantiating \c X, the instantiation of \c Values becomes an | |||
1396 | /// expanded parameter pack. For example, instantiating | |||
1397 | /// \c X<int, unsigned int> results in \c Values being an expanded parameter | |||
1398 | /// pack with expansion types \c int and \c unsigned int. | |||
1399 | /// | |||
1400 | /// The \c getExpansionType() and \c getExpansionTypeSourceInfo() functions | |||
1401 | /// return the expansion types. | |||
1402 | bool isExpandedParameterPack() const { return ExpandedParameterPack; } | |||
1403 | ||||
1404 | /// \brief Retrieves the number of expansion types in an expanded parameter | |||
1405 | /// pack. | |||
1406 | unsigned getNumExpansionTypes() const { | |||
1407 | assert(ExpandedParameterPack && "Not an expansion parameter pack")(static_cast <bool> (ExpandedParameterPack && "Not an expansion parameter pack" ) ? void (0) : __assert_fail ("ExpandedParameterPack && \"Not an expansion parameter pack\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 1407, __extension__ __PRETTY_FUNCTION__)); | |||
1408 | return NumExpandedTypes; | |||
1409 | } | |||
1410 | ||||
1411 | /// \brief Retrieve a particular expansion type within an expanded parameter | |||
1412 | /// pack. | |||
1413 | QualType getExpansionType(unsigned I) const { | |||
1414 | assert(I < NumExpandedTypes && "Out-of-range expansion type index")(static_cast <bool> (I < NumExpandedTypes && "Out-of-range expansion type index") ? void (0) : __assert_fail ("I < NumExpandedTypes && \"Out-of-range expansion type index\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 1414, __extension__ __PRETTY_FUNCTION__)); | |||
1415 | auto TypesAndInfos = | |||
1416 | getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>(); | |||
1417 | return TypesAndInfos[I].first; | |||
1418 | } | |||
1419 | ||||
1420 | /// \brief Retrieve a particular expansion type source info within an | |||
1421 | /// expanded parameter pack. | |||
1422 | TypeSourceInfo *getExpansionTypeSourceInfo(unsigned I) const { | |||
1423 | assert(I < NumExpandedTypes && "Out-of-range expansion type index")(static_cast <bool> (I < NumExpandedTypes && "Out-of-range expansion type index") ? void (0) : __assert_fail ("I < NumExpandedTypes && \"Out-of-range expansion type index\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 1423, __extension__ __PRETTY_FUNCTION__)); | |||
1424 | auto TypesAndInfos = | |||
1425 | getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>(); | |||
1426 | return TypesAndInfos[I].second; | |||
1427 | } | |||
1428 | ||||
1429 | // Implement isa/cast/dyncast/etc. | |||
1430 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } | |||
1431 | static bool classofKind(Kind K) { return K == NonTypeTemplateParm; } | |||
1432 | }; | |||
1433 | ||||
1434 | /// TemplateTemplateParmDecl - Declares a template template parameter, | |||
1435 | /// e.g., "T" in | |||
1436 | /// @code | |||
1437 | /// template <template <typename> class T> class container { }; | |||
1438 | /// @endcode | |||
1439 | /// A template template parameter is a TemplateDecl because it defines the | |||
1440 | /// name of a template and the template parameters allowable for substitution. | |||
1441 | class TemplateTemplateParmDecl final | |||
1442 | : public TemplateDecl, | |||
1443 | protected TemplateParmPosition, | |||
1444 | private llvm::TrailingObjects<TemplateTemplateParmDecl, | |||
1445 | TemplateParameterList *> { | |||
1446 | /// \brief The default template argument, if any. | |||
1447 | using DefArgStorage = | |||
1448 | DefaultArgStorage<TemplateTemplateParmDecl, TemplateArgumentLoc *>; | |||
1449 | DefArgStorage DefaultArgument; | |||
1450 | ||||
1451 | /// \brief Whether this parameter is a parameter pack. | |||
1452 | bool ParameterPack; | |||
1453 | ||||
1454 | /// \brief Whether this template template parameter is an "expanded" | |||
1455 | /// parameter pack, meaning that it is a pack expansion and we | |||
1456 | /// already know the set of template parameters that expansion expands to. | |||
1457 | bool ExpandedParameterPack = false; | |||
1458 | ||||
1459 | /// \brief The number of parameters in an expanded parameter pack. | |||
1460 | unsigned NumExpandedParams = 0; | |||
1461 | ||||
1462 | TemplateTemplateParmDecl(DeclContext *DC, SourceLocation L, | |||
1463 | unsigned D, unsigned P, bool ParameterPack, | |||
1464 | IdentifierInfo *Id, TemplateParameterList *Params) | |||
1465 | : TemplateDecl(TemplateTemplateParm, DC, L, Id, Params), | |||
1466 | TemplateParmPosition(D, P), ParameterPack(ParameterPack) {} | |||
1467 | ||||
1468 | TemplateTemplateParmDecl(DeclContext *DC, SourceLocation L, | |||
1469 | unsigned D, unsigned P, | |||
1470 | IdentifierInfo *Id, TemplateParameterList *Params, | |||
1471 | ArrayRef<TemplateParameterList *> Expansions); | |||
1472 | ||||
1473 | void anchor() override; | |||
1474 | ||||
1475 | public: | |||
1476 | friend class ASTDeclReader; | |||
1477 | friend class ASTDeclWriter; | |||
1478 | friend TrailingObjects; | |||
1479 | ||||
1480 | static TemplateTemplateParmDecl *Create(const ASTContext &C, DeclContext *DC, | |||
1481 | SourceLocation L, unsigned D, | |||
1482 | unsigned P, bool ParameterPack, | |||
1483 | IdentifierInfo *Id, | |||
1484 | TemplateParameterList *Params); | |||
1485 | static TemplateTemplateParmDecl *Create(const ASTContext &C, DeclContext *DC, | |||
1486 | SourceLocation L, unsigned D, | |||
1487 | unsigned P, | |||
1488 | IdentifierInfo *Id, | |||
1489 | TemplateParameterList *Params, | |||
1490 | ArrayRef<TemplateParameterList *> Expansions); | |||
1491 | ||||
1492 | static TemplateTemplateParmDecl *CreateDeserialized(ASTContext &C, | |||
1493 | unsigned ID); | |||
1494 | static TemplateTemplateParmDecl *CreateDeserialized(ASTContext &C, | |||
1495 | unsigned ID, | |||
1496 | unsigned NumExpansions); | |||
1497 | ||||
1498 | using TemplateParmPosition::getDepth; | |||
1499 | using TemplateParmPosition::setDepth; | |||
1500 | using TemplateParmPosition::getPosition; | |||
1501 | using TemplateParmPosition::setPosition; | |||
1502 | using TemplateParmPosition::getIndex; | |||
1503 | ||||
1504 | /// \brief Whether this template template parameter is a template | |||
1505 | /// parameter pack. | |||
1506 | /// | |||
1507 | /// \code | |||
1508 | /// template<template <class T> ...MetaFunctions> struct Apply; | |||
1509 | /// \endcode | |||
1510 | bool isParameterPack() const { return ParameterPack; } | |||
1511 | ||||
1512 | /// \brief Whether this parameter pack is a pack expansion. | |||
1513 | /// | |||
1514 | /// A template template parameter pack is a pack expansion if its template | |||
1515 | /// parameter list contains an unexpanded parameter pack. | |||
1516 | bool isPackExpansion() const { | |||
1517 | return ParameterPack && | |||
1518 | getTemplateParameters()->containsUnexpandedParameterPack(); | |||
1519 | } | |||
1520 | ||||
1521 | /// \brief Whether this parameter is a template template parameter pack that | |||
1522 | /// has a known list of different template parameter lists at different | |||
1523 | /// positions. | |||
1524 | /// | |||
1525 | /// A parameter pack is an expanded parameter pack when the original parameter | |||
1526 | /// pack's template parameter list was itself a pack expansion, and that | |||
1527 | /// expansion has already been expanded. For exampe, given: | |||
1528 | /// | |||
1529 | /// \code | |||
1530 | /// template<typename...Types> struct Outer { | |||
1531 | /// template<template<Types> class...Templates> struct Inner; | |||
1532 | /// }; | |||
1533 | /// \endcode | |||
1534 | /// | |||
1535 | /// The parameter pack \c Templates is a pack expansion, which expands the | |||
1536 | /// pack \c Types. When \c Types is supplied with template arguments by | |||
1537 | /// instantiating \c Outer, the instantiation of \c Templates is an expanded | |||
1538 | /// parameter pack. | |||
1539 | bool isExpandedParameterPack() const { return ExpandedParameterPack; } | |||
1540 | ||||
1541 | /// \brief Retrieves the number of expansion template parameters in | |||
1542 | /// an expanded parameter pack. | |||
1543 | unsigned getNumExpansionTemplateParameters() const { | |||
1544 | assert(ExpandedParameterPack && "Not an expansion parameter pack")(static_cast <bool> (ExpandedParameterPack && "Not an expansion parameter pack" ) ? void (0) : __assert_fail ("ExpandedParameterPack && \"Not an expansion parameter pack\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 1544, __extension__ __PRETTY_FUNCTION__)); | |||
1545 | return NumExpandedParams; | |||
1546 | } | |||
1547 | ||||
1548 | /// \brief Retrieve a particular expansion type within an expanded parameter | |||
1549 | /// pack. | |||
1550 | TemplateParameterList *getExpansionTemplateParameters(unsigned I) const { | |||
1551 | assert(I < NumExpandedParams && "Out-of-range expansion type index")(static_cast <bool> (I < NumExpandedParams && "Out-of-range expansion type index") ? void (0) : __assert_fail ("I < NumExpandedParams && \"Out-of-range expansion type index\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 1551, __extension__ __PRETTY_FUNCTION__)); | |||
1552 | return getTrailingObjects<TemplateParameterList *>()[I]; | |||
1553 | } | |||
1554 | ||||
1555 | const DefArgStorage &getDefaultArgStorage() const { return DefaultArgument; } | |||
1556 | ||||
1557 | /// \brief Determine whether this template parameter has a default | |||
1558 | /// argument. | |||
1559 | bool hasDefaultArgument() const { return DefaultArgument.isSet(); } | |||
1560 | ||||
1561 | /// \brief Retrieve the default argument, if any. | |||
1562 | const TemplateArgumentLoc &getDefaultArgument() const { | |||
1563 | static const TemplateArgumentLoc None; | |||
1564 | return DefaultArgument.isSet() ? *DefaultArgument.get() : None; | |||
1565 | } | |||
1566 | ||||
1567 | /// \brief Retrieve the location of the default argument, if any. | |||
1568 | SourceLocation getDefaultArgumentLoc() const; | |||
1569 | ||||
1570 | /// \brief Determines whether the default argument was inherited | |||
1571 | /// from a previous declaration of this template. | |||
1572 | bool defaultArgumentWasInherited() const { | |||
1573 | return DefaultArgument.isInherited(); | |||
1574 | } | |||
1575 | ||||
1576 | /// \brief Set the default argument for this template parameter, and | |||
1577 | /// whether that default argument was inherited from another | |||
1578 | /// declaration. | |||
1579 | void setDefaultArgument(const ASTContext &C, | |||
1580 | const TemplateArgumentLoc &DefArg); | |||
1581 | void setInheritedDefaultArgument(const ASTContext &C, | |||
1582 | TemplateTemplateParmDecl *Prev) { | |||
1583 | DefaultArgument.setInherited(C, Prev); | |||
1584 | } | |||
1585 | ||||
1586 | /// \brief Removes the default argument of this template parameter. | |||
1587 | void removeDefaultArgument() { DefaultArgument.clear(); } | |||
1588 | ||||
1589 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)) { | |||
1590 | SourceLocation End = getLocation(); | |||
1591 | if (hasDefaultArgument() && !defaultArgumentWasInherited()) | |||
1592 | End = getDefaultArgument().getSourceRange().getEnd(); | |||
1593 | return SourceRange(getTemplateParameters()->getTemplateLoc(), End); | |||
1594 | } | |||
1595 | ||||
1596 | // Implement isa/cast/dyncast/etc. | |||
1597 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } | |||
1598 | static bool classofKind(Kind K) { return K == TemplateTemplateParm; } | |||
1599 | }; | |||
1600 | ||||
1601 | /// \brief Represents the builtin template declaration which is used to | |||
1602 | /// implement __make_integer_seq and other builtin templates. It serves | |||
1603 | /// no real purpose beyond existing as a place to hold template parameters. | |||
1604 | class BuiltinTemplateDecl : public TemplateDecl { | |||
1605 | BuiltinTemplateKind BTK; | |||
1606 | ||||
1607 | BuiltinTemplateDecl(const ASTContext &C, DeclContext *DC, | |||
1608 | DeclarationName Name, BuiltinTemplateKind BTK); | |||
1609 | ||||
1610 | void anchor() override; | |||
1611 | ||||
1612 | public: | |||
1613 | // Implement isa/cast/dyncast support | |||
1614 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } | |||
1615 | static bool classofKind(Kind K) { return K == BuiltinTemplate; } | |||
1616 | ||||
1617 | static BuiltinTemplateDecl *Create(const ASTContext &C, DeclContext *DC, | |||
1618 | DeclarationName Name, | |||
1619 | BuiltinTemplateKind BTK) { | |||
1620 | return new (C, DC) BuiltinTemplateDecl(C, DC, Name, BTK); | |||
1621 | } | |||
1622 | ||||
1623 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)) { | |||
1624 | return SourceRange(); | |||
1625 | } | |||
1626 | ||||
1627 | BuiltinTemplateKind getBuiltinTemplateKind() const { return BTK; } | |||
1628 | }; | |||
1629 | ||||
1630 | /// \brief Represents a class template specialization, which refers to | |||
1631 | /// a class template with a given set of template arguments. | |||
1632 | /// | |||
1633 | /// Class template specializations represent both explicit | |||
1634 | /// specialization of class templates, as in the example below, and | |||
1635 | /// implicit instantiations of class templates. | |||
1636 | /// | |||
1637 | /// \code | |||
1638 | /// template<typename T> class array; | |||
1639 | /// | |||
1640 | /// template<> | |||
1641 | /// class array<bool> { }; // class template specialization array<bool> | |||
1642 | /// \endcode | |||
1643 | class ClassTemplateSpecializationDecl | |||
1644 | : public CXXRecordDecl, public llvm::FoldingSetNode { | |||
1645 | /// \brief Structure that stores information about a class template | |||
1646 | /// specialization that was instantiated from a class template partial | |||
1647 | /// specialization. | |||
1648 | struct SpecializedPartialSpecialization { | |||
1649 | /// \brief The class template partial specialization from which this | |||
1650 | /// class template specialization was instantiated. | |||
1651 | ClassTemplatePartialSpecializationDecl *PartialSpecialization; | |||
1652 | ||||
1653 | /// \brief The template argument list deduced for the class template | |||
1654 | /// partial specialization itself. | |||
1655 | const TemplateArgumentList *TemplateArgs; | |||
1656 | }; | |||
1657 | ||||
1658 | /// \brief The template that this specialization specializes | |||
1659 | llvm::PointerUnion<ClassTemplateDecl *, SpecializedPartialSpecialization *> | |||
1660 | SpecializedTemplate; | |||
1661 | ||||
1662 | /// \brief Further info for explicit template specialization/instantiation. | |||
1663 | struct ExplicitSpecializationInfo { | |||
1664 | /// \brief The type-as-written. | |||
1665 | TypeSourceInfo *TypeAsWritten = nullptr; | |||
1666 | ||||
1667 | /// \brief The location of the extern keyword. | |||
1668 | SourceLocation ExternLoc; | |||
1669 | ||||
1670 | /// \brief The location of the template keyword. | |||
1671 | SourceLocation TemplateKeywordLoc; | |||
1672 | ||||
1673 | ExplicitSpecializationInfo() = default; | |||
1674 | }; | |||
1675 | ||||
1676 | /// \brief Further info for explicit template specialization/instantiation. | |||
1677 | /// Does not apply to implicit specializations. | |||
1678 | ExplicitSpecializationInfo *ExplicitInfo = nullptr; | |||
1679 | ||||
1680 | /// \brief The template arguments used to describe this specialization. | |||
1681 | const TemplateArgumentList *TemplateArgs; | |||
1682 | ||||
1683 | /// \brief The point where this template was instantiated (if any) | |||
1684 | SourceLocation PointOfInstantiation; | |||
1685 | ||||
1686 | /// \brief The kind of specialization this declaration refers to. | |||
1687 | /// Really a value of type TemplateSpecializationKind. | |||
1688 | unsigned SpecializationKind : 3; | |||
1689 | ||||
1690 | protected: | |||
1691 | ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK, | |||
1692 | DeclContext *DC, SourceLocation StartLoc, | |||
1693 | SourceLocation IdLoc, | |||
1694 | ClassTemplateDecl *SpecializedTemplate, | |||
1695 | ArrayRef<TemplateArgument> Args, | |||
1696 | ClassTemplateSpecializationDecl *PrevDecl); | |||
1697 | ||||
1698 | explicit ClassTemplateSpecializationDecl(ASTContext &C, Kind DK); | |||
1699 | ||||
1700 | public: | |||
1701 | friend class ASTDeclReader; | |||
1702 | friend class ASTDeclWriter; | |||
1703 | ||||
1704 | static ClassTemplateSpecializationDecl * | |||
1705 | Create(ASTContext &Context, TagKind TK, DeclContext *DC, | |||
1706 | SourceLocation StartLoc, SourceLocation IdLoc, | |||
1707 | ClassTemplateDecl *SpecializedTemplate, | |||
1708 | ArrayRef<TemplateArgument> Args, | |||
1709 | ClassTemplateSpecializationDecl *PrevDecl); | |||
1710 | static ClassTemplateSpecializationDecl * | |||
1711 | CreateDeserialized(ASTContext &C, unsigned ID); | |||
1712 | ||||
1713 | void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, | |||
1714 | bool Qualified) const override; | |||
1715 | ||||
1716 | // FIXME: This is broken. CXXRecordDecl::getMostRecentDecl() returns a | |||
1717 | // different "most recent" declaration from this function for the same | |||
1718 | // declaration, because we don't override getMostRecentDeclImpl(). But | |||
1719 | // it's not clear that we should override that, because the most recent | |||
1720 | // declaration as a CXXRecordDecl sometimes is the injected-class-name. | |||
1721 | ClassTemplateSpecializationDecl *getMostRecentDecl() { | |||
1722 | CXXRecordDecl *Recent = static_cast<CXXRecordDecl *>( | |||
1723 | this)->getMostRecentDecl(); | |||
1724 | while (!isa<ClassTemplateSpecializationDecl>(Recent)) { | |||
1725 | // FIXME: Does injected class name need to be in the redeclarations chain? | |||
1726 | assert(Recent->isInjectedClassName() && Recent->getPreviousDecl())(static_cast <bool> (Recent->isInjectedClassName() && Recent->getPreviousDecl()) ? void (0) : __assert_fail ("Recent->isInjectedClassName() && Recent->getPreviousDecl()" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 1726, __extension__ __PRETTY_FUNCTION__)); | |||
1727 | Recent = Recent->getPreviousDecl(); | |||
1728 | } | |||
1729 | return cast<ClassTemplateSpecializationDecl>(Recent); | |||
1730 | } | |||
1731 | ||||
1732 | /// \brief Retrieve the template that this specialization specializes. | |||
1733 | ClassTemplateDecl *getSpecializedTemplate() const; | |||
1734 | ||||
1735 | /// \brief Retrieve the template arguments of the class template | |||
1736 | /// specialization. | |||
1737 | const TemplateArgumentList &getTemplateArgs() const { | |||
1738 | return *TemplateArgs; | |||
1739 | } | |||
1740 | ||||
1741 | /// \brief Determine the kind of specialization that this | |||
1742 | /// declaration represents. | |||
1743 | TemplateSpecializationKind getSpecializationKind() const { | |||
1744 | return static_cast<TemplateSpecializationKind>(SpecializationKind); | |||
1745 | } | |||
1746 | ||||
1747 | bool isExplicitSpecialization() const { | |||
1748 | return getSpecializationKind() == TSK_ExplicitSpecialization; | |||
1749 | } | |||
1750 | ||||
1751 | /// \brief True if this declaration is an explicit specialization, | |||
1752 | /// explicit instantiation declaration, or explicit instantiation | |||
1753 | /// definition. | |||
1754 | bool isExplicitInstantiationOrSpecialization() const { | |||
1755 | return isTemplateExplicitInstantiationOrSpecialization( | |||
1756 | getTemplateSpecializationKind()); | |||
1757 | } | |||
1758 | ||||
1759 | void setSpecializationKind(TemplateSpecializationKind TSK) { | |||
1760 | SpecializationKind = TSK; | |||
1761 | } | |||
1762 | ||||
1763 | /// \brief Get the point of instantiation (if any), or null if none. | |||
1764 | SourceLocation getPointOfInstantiation() const { | |||
1765 | return PointOfInstantiation; | |||
1766 | } | |||
1767 | ||||
1768 | void setPointOfInstantiation(SourceLocation Loc) { | |||
1769 | assert(Loc.isValid() && "point of instantiation must be valid!")(static_cast <bool> (Loc.isValid() && "point of instantiation must be valid!" ) ? void (0) : __assert_fail ("Loc.isValid() && \"point of instantiation must be valid!\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 1769, __extension__ __PRETTY_FUNCTION__)); | |||
1770 | PointOfInstantiation = Loc; | |||
1771 | } | |||
1772 | ||||
1773 | /// \brief If this class template specialization is an instantiation of | |||
1774 | /// a template (rather than an explicit specialization), return the | |||
1775 | /// class template or class template partial specialization from which it | |||
1776 | /// was instantiated. | |||
1777 | llvm::PointerUnion<ClassTemplateDecl *, | |||
1778 | ClassTemplatePartialSpecializationDecl *> | |||
1779 | getInstantiatedFrom() const { | |||
1780 | if (!isTemplateInstantiation(getSpecializationKind())) | |||
1781 | return llvm::PointerUnion<ClassTemplateDecl *, | |||
1782 | ClassTemplatePartialSpecializationDecl *>(); | |||
1783 | ||||
1784 | return getSpecializedTemplateOrPartial(); | |||
1785 | } | |||
1786 | ||||
1787 | /// \brief Retrieve the class template or class template partial | |||
1788 | /// specialization which was specialized by this. | |||
1789 | llvm::PointerUnion<ClassTemplateDecl *, | |||
1790 | ClassTemplatePartialSpecializationDecl *> | |||
1791 | getSpecializedTemplateOrPartial() const { | |||
1792 | if (SpecializedPartialSpecialization *PartialSpec | |||
1793 | = SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>()) | |||
1794 | return PartialSpec->PartialSpecialization; | |||
1795 | ||||
1796 | return SpecializedTemplate.get<ClassTemplateDecl*>(); | |||
1797 | } | |||
1798 | ||||
1799 | /// \brief Retrieve the set of template arguments that should be used | |||
1800 | /// to instantiate members of the class template or class template partial | |||
1801 | /// specialization from which this class template specialization was | |||
1802 | /// instantiated. | |||
1803 | /// | |||
1804 | /// \returns For a class template specialization instantiated from the primary | |||
1805 | /// template, this function will return the same template arguments as | |||
1806 | /// getTemplateArgs(). For a class template specialization instantiated from | |||
1807 | /// a class template partial specialization, this function will return the | |||
1808 | /// deduced template arguments for the class template partial specialization | |||
1809 | /// itself. | |||
1810 | const TemplateArgumentList &getTemplateInstantiationArgs() const { | |||
1811 | if (SpecializedPartialSpecialization *PartialSpec | |||
1812 | = SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>()) | |||
1813 | return *PartialSpec->TemplateArgs; | |||
1814 | ||||
1815 | return getTemplateArgs(); | |||
1816 | } | |||
1817 | ||||
1818 | /// \brief Note that this class template specialization is actually an | |||
1819 | /// instantiation of the given class template partial specialization whose | |||
1820 | /// template arguments have been deduced. | |||
1821 | void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec, | |||
1822 | const TemplateArgumentList *TemplateArgs) { | |||
1823 | assert(!SpecializedTemplate.is<SpecializedPartialSpecialization*>() &&(static_cast <bool> (!SpecializedTemplate.is<SpecializedPartialSpecialization *>() && "Already set to a class template partial specialization!" ) ? void (0) : __assert_fail ("!SpecializedTemplate.is<SpecializedPartialSpecialization*>() && \"Already set to a class template partial specialization!\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 1824, __extension__ __PRETTY_FUNCTION__)) | |||
1824 | "Already set to a class template partial specialization!")(static_cast <bool> (!SpecializedTemplate.is<SpecializedPartialSpecialization *>() && "Already set to a class template partial specialization!" ) ? void (0) : __assert_fail ("!SpecializedTemplate.is<SpecializedPartialSpecialization*>() && \"Already set to a class template partial specialization!\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 1824, __extension__ __PRETTY_FUNCTION__)); | |||
1825 | SpecializedPartialSpecialization *PS | |||
1826 | = new (getASTContext()) SpecializedPartialSpecialization(); | |||
1827 | PS->PartialSpecialization = PartialSpec; | |||
| ||||
1828 | PS->TemplateArgs = TemplateArgs; | |||
1829 | SpecializedTemplate = PS; | |||
1830 | } | |||
1831 | ||||
1832 | /// \brief Note that this class template specialization is an instantiation | |||
1833 | /// of the given class template. | |||
1834 | void setInstantiationOf(ClassTemplateDecl *TemplDecl) { | |||
1835 | assert(!SpecializedTemplate.is<SpecializedPartialSpecialization*>() &&(static_cast <bool> (!SpecializedTemplate.is<SpecializedPartialSpecialization *>() && "Previously set to a class template partial specialization!" ) ? void (0) : __assert_fail ("!SpecializedTemplate.is<SpecializedPartialSpecialization*>() && \"Previously set to a class template partial specialization!\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 1836, __extension__ __PRETTY_FUNCTION__)) | |||
1836 | "Previously set to a class template partial specialization!")(static_cast <bool> (!SpecializedTemplate.is<SpecializedPartialSpecialization *>() && "Previously set to a class template partial specialization!" ) ? void (0) : __assert_fail ("!SpecializedTemplate.is<SpecializedPartialSpecialization*>() && \"Previously set to a class template partial specialization!\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 1836, __extension__ __PRETTY_FUNCTION__)); | |||
1837 | SpecializedTemplate = TemplDecl; | |||
1838 | } | |||
1839 | ||||
1840 | /// \brief Sets the type of this specialization as it was written by | |||
1841 | /// the user. This will be a class template specialization type. | |||
1842 | void setTypeAsWritten(TypeSourceInfo *T) { | |||
1843 | if (!ExplicitInfo) | |||
1844 | ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo; | |||
1845 | ExplicitInfo->TypeAsWritten = T; | |||
1846 | } | |||
1847 | ||||
1848 | /// \brief Gets the type of this specialization as it was written by | |||
1849 | /// the user, if it was so written. | |||
1850 | TypeSourceInfo *getTypeAsWritten() const { | |||
1851 | return ExplicitInfo ? ExplicitInfo->TypeAsWritten : nullptr; | |||
1852 | } | |||
1853 | ||||
1854 | /// \brief Gets the location of the extern keyword, if present. | |||
1855 | SourceLocation getExternLoc() const { | |||
1856 | return ExplicitInfo ? ExplicitInfo->ExternLoc : SourceLocation(); | |||
1857 | } | |||
1858 | ||||
1859 | /// \brief Sets the location of the extern keyword. | |||
1860 | void setExternLoc(SourceLocation Loc) { | |||
1861 | if (!ExplicitInfo) | |||
1862 | ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo; | |||
1863 | ExplicitInfo->ExternLoc = Loc; | |||
1864 | } | |||
1865 | ||||
1866 | /// \brief Sets the location of the template keyword. | |||
1867 | void setTemplateKeywordLoc(SourceLocation Loc) { | |||
1868 | if (!ExplicitInfo) | |||
1869 | ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo; | |||
1870 | ExplicitInfo->TemplateKeywordLoc = Loc; | |||
1871 | } | |||
1872 | ||||
1873 | /// \brief Gets the location of the template keyword, if present. | |||
1874 | SourceLocation getTemplateKeywordLoc() const { | |||
1875 | return ExplicitInfo ? ExplicitInfo->TemplateKeywordLoc : SourceLocation(); | |||
1876 | } | |||
1877 | ||||
1878 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)); | |||
1879 | ||||
1880 | void Profile(llvm::FoldingSetNodeID &ID) const { | |||
1881 | Profile(ID, TemplateArgs->asArray(), getASTContext()); | |||
1882 | } | |||
1883 | ||||
1884 | static void | |||
1885 | Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs, | |||
1886 | ASTContext &Context) { | |||
1887 | ID.AddInteger(TemplateArgs.size()); | |||
1888 | for (const TemplateArgument &TemplateArg : TemplateArgs) | |||
1889 | TemplateArg.Profile(ID, Context); | |||
1890 | } | |||
1891 | ||||
1892 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } | |||
1893 | ||||
1894 | static bool classofKind(Kind K) { | |||
1895 | return K >= firstClassTemplateSpecialization && | |||
1896 | K <= lastClassTemplateSpecialization; | |||
1897 | } | |||
1898 | }; | |||
1899 | ||||
1900 | class ClassTemplatePartialSpecializationDecl | |||
1901 | : public ClassTemplateSpecializationDecl { | |||
1902 | /// \brief The list of template parameters | |||
1903 | TemplateParameterList* TemplateParams = nullptr; | |||
1904 | ||||
1905 | /// \brief The source info for the template arguments as written. | |||
1906 | /// FIXME: redundant with TypeAsWritten? | |||
1907 | const ASTTemplateArgumentListInfo *ArgsAsWritten = nullptr; | |||
1908 | ||||
1909 | /// \brief The class template partial specialization from which this | |||
1910 | /// class template partial specialization was instantiated. | |||
1911 | /// | |||
1912 | /// The boolean value will be true to indicate that this class template | |||
1913 | /// partial specialization was specialized at this level. | |||
1914 | llvm::PointerIntPair<ClassTemplatePartialSpecializationDecl *, 1, bool> | |||
1915 | InstantiatedFromMember; | |||
1916 | ||||
1917 | ClassTemplatePartialSpecializationDecl(ASTContext &Context, TagKind TK, | |||
1918 | DeclContext *DC, | |||
1919 | SourceLocation StartLoc, | |||
1920 | SourceLocation IdLoc, | |||
1921 | TemplateParameterList *Params, | |||
1922 | ClassTemplateDecl *SpecializedTemplate, | |||
1923 | ArrayRef<TemplateArgument> Args, | |||
1924 | const ASTTemplateArgumentListInfo *ArgsAsWritten, | |||
1925 | ClassTemplatePartialSpecializationDecl *PrevDecl); | |||
1926 | ||||
1927 | ClassTemplatePartialSpecializationDecl(ASTContext &C) | |||
1928 | : ClassTemplateSpecializationDecl(C, ClassTemplatePartialSpecialization), | |||
1929 | InstantiatedFromMember(nullptr, false) {} | |||
1930 | ||||
1931 | void anchor() override; | |||
1932 | ||||
1933 | public: | |||
1934 | friend class ASTDeclReader; | |||
1935 | friend class ASTDeclWriter; | |||
1936 | ||||
1937 | static ClassTemplatePartialSpecializationDecl * | |||
1938 | Create(ASTContext &Context, TagKind TK, DeclContext *DC, | |||
1939 | SourceLocation StartLoc, SourceLocation IdLoc, | |||
1940 | TemplateParameterList *Params, | |||
1941 | ClassTemplateDecl *SpecializedTemplate, | |||
1942 | ArrayRef<TemplateArgument> Args, | |||
1943 | const TemplateArgumentListInfo &ArgInfos, | |||
1944 | QualType CanonInjectedType, | |||
1945 | ClassTemplatePartialSpecializationDecl *PrevDecl); | |||
1946 | ||||
1947 | static ClassTemplatePartialSpecializationDecl * | |||
1948 | CreateDeserialized(ASTContext &C, unsigned ID); | |||
1949 | ||||
1950 | ClassTemplatePartialSpecializationDecl *getMostRecentDecl() { | |||
1951 | return cast<ClassTemplatePartialSpecializationDecl>( | |||
1952 | static_cast<ClassTemplateSpecializationDecl *>( | |||
1953 | this)->getMostRecentDecl()); | |||
1954 | } | |||
1955 | ||||
1956 | /// Get the list of template parameters | |||
1957 | TemplateParameterList *getTemplateParameters() const { | |||
1958 | return TemplateParams; | |||
1959 | } | |||
1960 | ||||
1961 | /// Get the template arguments as written. | |||
1962 | const ASTTemplateArgumentListInfo *getTemplateArgsAsWritten() const { | |||
1963 | return ArgsAsWritten; | |||
1964 | } | |||
1965 | ||||
1966 | /// \brief Retrieve the member class template partial specialization from | |||
1967 | /// which this particular class template partial specialization was | |||
1968 | /// instantiated. | |||
1969 | /// | |||
1970 | /// \code | |||
1971 | /// template<typename T> | |||
1972 | /// struct Outer { | |||
1973 | /// template<typename U> struct Inner; | |||
1974 | /// template<typename U> struct Inner<U*> { }; // #1 | |||
1975 | /// }; | |||
1976 | /// | |||
1977 | /// Outer<float>::Inner<int*> ii; | |||
1978 | /// \endcode | |||
1979 | /// | |||
1980 | /// In this example, the instantiation of \c Outer<float>::Inner<int*> will | |||
1981 | /// end up instantiating the partial specialization | |||
1982 | /// \c Outer<float>::Inner<U*>, which itself was instantiated from the class | |||
1983 | /// template partial specialization \c Outer<T>::Inner<U*>. Given | |||
1984 | /// \c Outer<float>::Inner<U*>, this function would return | |||
1985 | /// \c Outer<T>::Inner<U*>. | |||
1986 | ClassTemplatePartialSpecializationDecl *getInstantiatedFromMember() const { | |||
1987 | const ClassTemplatePartialSpecializationDecl *First = | |||
1988 | cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl()); | |||
1989 | return First->InstantiatedFromMember.getPointer(); | |||
1990 | } | |||
1991 | ClassTemplatePartialSpecializationDecl * | |||
1992 | getInstantiatedFromMemberTemplate() const { | |||
1993 | return getInstantiatedFromMember(); | |||
1994 | } | |||
1995 | ||||
1996 | void setInstantiatedFromMember( | |||
1997 | ClassTemplatePartialSpecializationDecl *PartialSpec) { | |||
1998 | ClassTemplatePartialSpecializationDecl *First = | |||
1999 | cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl()); | |||
2000 | First->InstantiatedFromMember.setPointer(PartialSpec); | |||
2001 | } | |||
2002 | ||||
2003 | /// \brief Determines whether this class template partial specialization | |||
2004 | /// template was a specialization of a member partial specialization. | |||
2005 | /// | |||
2006 | /// In the following example, the member template partial specialization | |||
2007 | /// \c X<int>::Inner<T*> is a member specialization. | |||
2008 | /// | |||
2009 | /// \code | |||
2010 | /// template<typename T> | |||
2011 | /// struct X { | |||
2012 | /// template<typename U> struct Inner; | |||
2013 | /// template<typename U> struct Inner<U*>; | |||
2014 | /// }; | |||
2015 | /// | |||
2016 | /// template<> template<typename T> | |||
2017 | /// struct X<int>::Inner<T*> { /* ... */ }; | |||
2018 | /// \endcode | |||
2019 | bool isMemberSpecialization() { | |||
2020 | ClassTemplatePartialSpecializationDecl *First = | |||
2021 | cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl()); | |||
2022 | return First->InstantiatedFromMember.getInt(); | |||
2023 | } | |||
2024 | ||||
2025 | /// \brief Note that this member template is a specialization. | |||
2026 | void setMemberSpecialization() { | |||
2027 | ClassTemplatePartialSpecializationDecl *First = | |||
2028 | cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl()); | |||
2029 | assert(First->InstantiatedFromMember.getPointer() &&(static_cast <bool> (First->InstantiatedFromMember.getPointer () && "Only member templates can be member template specializations" ) ? void (0) : __assert_fail ("First->InstantiatedFromMember.getPointer() && \"Only member templates can be member template specializations\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 2030, __extension__ __PRETTY_FUNCTION__)) | |||
2030 | "Only member templates can be member template specializations")(static_cast <bool> (First->InstantiatedFromMember.getPointer () && "Only member templates can be member template specializations" ) ? void (0) : __assert_fail ("First->InstantiatedFromMember.getPointer() && \"Only member templates can be member template specializations\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 2030, __extension__ __PRETTY_FUNCTION__)); | |||
2031 | return First->InstantiatedFromMember.setInt(true); | |||
2032 | } | |||
2033 | ||||
2034 | /// Retrieves the injected specialization type for this partial | |||
2035 | /// specialization. This is not the same as the type-decl-type for | |||
2036 | /// this partial specialization, which is an InjectedClassNameType. | |||
2037 | QualType getInjectedSpecializationType() const { | |||
2038 | assert(getTypeForDecl() && "partial specialization has no type set!")(static_cast <bool> (getTypeForDecl() && "partial specialization has no type set!" ) ? void (0) : __assert_fail ("getTypeForDecl() && \"partial specialization has no type set!\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 2038, __extension__ __PRETTY_FUNCTION__)); | |||
2039 | return cast<InjectedClassNameType>(getTypeForDecl()) | |||
2040 | ->getInjectedSpecializationType(); | |||
2041 | } | |||
2042 | ||||
2043 | // FIXME: Add Profile support! | |||
2044 | ||||
2045 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } | |||
2046 | ||||
2047 | static bool classofKind(Kind K) { | |||
2048 | return K == ClassTemplatePartialSpecialization; | |||
2049 | } | |||
2050 | }; | |||
2051 | ||||
2052 | /// Declaration of a class template. | |||
2053 | class ClassTemplateDecl : public RedeclarableTemplateDecl { | |||
2054 | protected: | |||
2055 | /// \brief Data that is common to all of the declarations of a given | |||
2056 | /// class template. | |||
2057 | struct Common : CommonBase { | |||
2058 | /// \brief The class template specializations for this class | |||
2059 | /// template, including explicit specializations and instantiations. | |||
2060 | llvm::FoldingSetVector<ClassTemplateSpecializationDecl> Specializations; | |||
2061 | ||||
2062 | /// \brief The class template partial specializations for this class | |||
2063 | /// template. | |||
2064 | llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> | |||
2065 | PartialSpecializations; | |||
2066 | ||||
2067 | /// \brief The injected-class-name type for this class template. | |||
2068 | QualType InjectedClassNameType; | |||
2069 | ||||
2070 | Common() = default; | |||
2071 | }; | |||
2072 | ||||
2073 | /// \brief Retrieve the set of specializations of this class template. | |||
2074 | llvm::FoldingSetVector<ClassTemplateSpecializationDecl> & | |||
2075 | getSpecializations() const; | |||
2076 | ||||
2077 | /// \brief Retrieve the set of partial specializations of this class | |||
2078 | /// template. | |||
2079 | llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> & | |||
2080 | getPartialSpecializations(); | |||
2081 | ||||
2082 | ClassTemplateDecl(ConstrainedTemplateDeclInfo *CTDI, ASTContext &C, | |||
2083 | DeclContext *DC, SourceLocation L, DeclarationName Name, | |||
2084 | TemplateParameterList *Params, NamedDecl *Decl) | |||
2085 | : RedeclarableTemplateDecl(CTDI, ClassTemplate, C, DC, L, Name, Params, | |||
2086 | Decl) {} | |||
2087 | ||||
2088 | ClassTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L, | |||
2089 | DeclarationName Name, TemplateParameterList *Params, | |||
2090 | NamedDecl *Decl) | |||
2091 | : ClassTemplateDecl(nullptr, C, DC, L, Name, Params, Decl) {} | |||
2092 | ||||
2093 | CommonBase *newCommon(ASTContext &C) const override; | |||
2094 | ||||
2095 | Common *getCommonPtr() const { | |||
2096 | return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr()); | |||
2097 | } | |||
2098 | ||||
2099 | public: | |||
2100 | friend class ASTDeclReader; | |||
2101 | friend class ASTDeclWriter; | |||
2102 | ||||
2103 | /// \brief Load any lazily-loaded specializations from the external source. | |||
2104 | void LoadLazySpecializations() const; | |||
2105 | ||||
2106 | /// \brief Get the underlying class declarations of the template. | |||
2107 | CXXRecordDecl *getTemplatedDecl() const { | |||
2108 | return static_cast<CXXRecordDecl *>(TemplatedDecl); | |||
2109 | } | |||
2110 | ||||
2111 | /// \brief Returns whether this template declaration defines the primary | |||
2112 | /// class pattern. | |||
2113 | bool isThisDeclarationADefinition() const { | |||
2114 | return getTemplatedDecl()->isThisDeclarationADefinition(); | |||
2115 | } | |||
2116 | ||||
2117 | // FIXME: remove default argument for AssociatedConstraints | |||
2118 | /// \brief Create a class template node. | |||
2119 | static ClassTemplateDecl *Create(ASTContext &C, DeclContext *DC, | |||
2120 | SourceLocation L, | |||
2121 | DeclarationName Name, | |||
2122 | TemplateParameterList *Params, | |||
2123 | NamedDecl *Decl, | |||
2124 | Expr *AssociatedConstraints = nullptr); | |||
2125 | ||||
2126 | /// \brief Create an empty class template node. | |||
2127 | static ClassTemplateDecl *CreateDeserialized(ASTContext &C, unsigned ID); | |||
2128 | ||||
2129 | /// \brief Return the specialization with the provided arguments if it exists, | |||
2130 | /// otherwise return the insertion point. | |||
2131 | ClassTemplateSpecializationDecl * | |||
2132 | findSpecialization(ArrayRef<TemplateArgument> Args, void *&InsertPos); | |||
2133 | ||||
2134 | /// \brief Insert the specified specialization knowing that it is not already | |||
2135 | /// in. InsertPos must be obtained from findSpecialization. | |||
2136 | void AddSpecialization(ClassTemplateSpecializationDecl *D, void *InsertPos); | |||
2137 | ||||
2138 | ClassTemplateDecl *getCanonicalDecl() override { | |||
2139 | return cast<ClassTemplateDecl>( | |||
2140 | RedeclarableTemplateDecl::getCanonicalDecl()); | |||
2141 | } | |||
2142 | const ClassTemplateDecl *getCanonicalDecl() const { | |||
2143 | return cast<ClassTemplateDecl>( | |||
2144 | RedeclarableTemplateDecl::getCanonicalDecl()); | |||
2145 | } | |||
2146 | ||||
2147 | /// \brief Retrieve the previous declaration of this class template, or | |||
2148 | /// nullptr if no such declaration exists. | |||
2149 | ClassTemplateDecl *getPreviousDecl() { | |||
2150 | return cast_or_null<ClassTemplateDecl>( | |||
2151 | static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl()); | |||
2152 | } | |||
2153 | const ClassTemplateDecl *getPreviousDecl() const { | |||
2154 | return cast_or_null<ClassTemplateDecl>( | |||
2155 | static_cast<const RedeclarableTemplateDecl *>( | |||
2156 | this)->getPreviousDecl()); | |||
2157 | } | |||
2158 | ||||
2159 | ClassTemplateDecl *getMostRecentDecl() { | |||
2160 | return cast<ClassTemplateDecl>( | |||
2161 | static_cast<RedeclarableTemplateDecl *>(this)->getMostRecentDecl()); | |||
2162 | } | |||
2163 | const ClassTemplateDecl *getMostRecentDecl() const { | |||
2164 | return const_cast<ClassTemplateDecl*>(this)->getMostRecentDecl(); | |||
2165 | } | |||
2166 | ||||
2167 | ClassTemplateDecl *getInstantiatedFromMemberTemplate() const { | |||
2168 | return cast_or_null<ClassTemplateDecl>( | |||
2169 | RedeclarableTemplateDecl::getInstantiatedFromMemberTemplate()); | |||
2170 | } | |||
2171 | ||||
2172 | /// \brief Return the partial specialization with the provided arguments if it | |||
2173 | /// exists, otherwise return the insertion point. | |||
2174 | ClassTemplatePartialSpecializationDecl * | |||
2175 | findPartialSpecialization(ArrayRef<TemplateArgument> Args, void *&InsertPos); | |||
2176 | ||||
2177 | /// \brief Insert the specified partial specialization knowing that it is not | |||
2178 | /// already in. InsertPos must be obtained from findPartialSpecialization. | |||
2179 | void AddPartialSpecialization(ClassTemplatePartialSpecializationDecl *D, | |||
2180 | void *InsertPos); | |||
2181 | ||||
2182 | /// \brief Retrieve the partial specializations as an ordered list. | |||
2183 | void getPartialSpecializations( | |||
2184 | SmallVectorImpl<ClassTemplatePartialSpecializationDecl *> &PS); | |||
2185 | ||||
2186 | /// \brief Find a class template partial specialization with the given | |||
2187 | /// type T. | |||
2188 | /// | |||
2189 | /// \param T a dependent type that names a specialization of this class | |||
2190 | /// template. | |||
2191 | /// | |||
2192 | /// \returns the class template partial specialization that exactly matches | |||
2193 | /// the type \p T, or nullptr if no such partial specialization exists. | |||
2194 | ClassTemplatePartialSpecializationDecl *findPartialSpecialization(QualType T); | |||
2195 | ||||
2196 | /// \brief Find a class template partial specialization which was instantiated | |||
2197 | /// from the given member partial specialization. | |||
2198 | /// | |||
2199 | /// \param D a member class template partial specialization. | |||
2200 | /// | |||
2201 | /// \returns the class template partial specialization which was instantiated | |||
2202 | /// from the given member partial specialization, or nullptr if no such | |||
2203 | /// partial specialization exists. | |||
2204 | ClassTemplatePartialSpecializationDecl * | |||
2205 | findPartialSpecInstantiatedFromMember( | |||
2206 | ClassTemplatePartialSpecializationDecl *D); | |||
2207 | ||||
2208 | /// \brief Retrieve the template specialization type of the | |||
2209 | /// injected-class-name for this class template. | |||
2210 | /// | |||
2211 | /// The injected-class-name for a class template \c X is \c | |||
2212 | /// X<template-args>, where \c template-args is formed from the | |||
2213 | /// template arguments that correspond to the template parameters of | |||
2214 | /// \c X. For example: | |||
2215 | /// | |||
2216 | /// \code | |||
2217 | /// template<typename T, int N> | |||
2218 | /// struct array { | |||
2219 | /// typedef array this_type; // "array" is equivalent to "array<T, N>" | |||
2220 | /// }; | |||
2221 | /// \endcode | |||
2222 | QualType getInjectedClassNameSpecialization(); | |||
2223 | ||||
2224 | using spec_iterator = SpecIterator<ClassTemplateSpecializationDecl>; | |||
2225 | using spec_range = llvm::iterator_range<spec_iterator>; | |||
2226 | ||||
2227 | spec_range specializations() const { | |||
2228 | return spec_range(spec_begin(), spec_end()); | |||
2229 | } | |||
2230 | ||||
2231 | spec_iterator spec_begin() const { | |||
2232 | return makeSpecIterator(getSpecializations(), false); | |||
2233 | } | |||
2234 | ||||
2235 | spec_iterator spec_end() const { | |||
2236 | return makeSpecIterator(getSpecializations(), true); | |||
2237 | } | |||
2238 | ||||
2239 | // Implement isa/cast/dyncast support | |||
2240 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } | |||
2241 | static bool classofKind(Kind K) { return K == ClassTemplate; } | |||
2242 | }; | |||
2243 | ||||
2244 | /// \brief Declaration of a friend template. | |||
2245 | /// | |||
2246 | /// For example: | |||
2247 | /// \code | |||
2248 | /// template \<typename T> class A { | |||
2249 | /// friend class MyVector<T>; // not a friend template | |||
2250 | /// template \<typename U> friend class B; // not a friend template | |||
2251 | /// template \<typename U> friend class Foo<T>::Nested; // friend template | |||
2252 | /// }; | |||
2253 | /// \endcode | |||
2254 | /// | |||
2255 | /// \note This class is not currently in use. All of the above | |||
2256 | /// will yield a FriendDecl, not a FriendTemplateDecl. | |||
2257 | class FriendTemplateDecl : public Decl { | |||
2258 | virtual void anchor(); | |||
2259 | ||||
2260 | public: | |||
2261 | using FriendUnion = llvm::PointerUnion<NamedDecl *,TypeSourceInfo *>; | |||
2262 | ||||
2263 | private: | |||
2264 | // The number of template parameters; always non-zero. | |||
2265 | unsigned NumParams = 0; | |||
2266 | ||||
2267 | // The parameter list. | |||
2268 | TemplateParameterList **Params = nullptr; | |||
2269 | ||||
2270 | // The declaration that's a friend of this class. | |||
2271 | FriendUnion Friend; | |||
2272 | ||||
2273 | // Location of the 'friend' specifier. | |||
2274 | SourceLocation FriendLoc; | |||
2275 | ||||
2276 | FriendTemplateDecl(DeclContext *DC, SourceLocation Loc, | |||
2277 | MutableArrayRef<TemplateParameterList *> Params, | |||
2278 | FriendUnion Friend, SourceLocation FriendLoc) | |||
2279 | : Decl(Decl::FriendTemplate, DC, Loc), NumParams(Params.size()), | |||
2280 | Params(Params.data()), Friend(Friend), FriendLoc(FriendLoc) {} | |||
2281 | ||||
2282 | FriendTemplateDecl(EmptyShell Empty) : Decl(Decl::FriendTemplate, Empty) {} | |||
2283 | ||||
2284 | public: | |||
2285 | friend class ASTDeclReader; | |||
2286 | ||||
2287 | static FriendTemplateDecl * | |||
2288 | Create(ASTContext &Context, DeclContext *DC, SourceLocation Loc, | |||
2289 | MutableArrayRef<TemplateParameterList *> Params, FriendUnion Friend, | |||
2290 | SourceLocation FriendLoc); | |||
2291 | ||||
2292 | static FriendTemplateDecl *CreateDeserialized(ASTContext &C, unsigned ID); | |||
2293 | ||||
2294 | /// If this friend declaration names a templated type (or | |||
2295 | /// a dependent member type of a templated type), return that | |||
2296 | /// type; otherwise return null. | |||
2297 | TypeSourceInfo *getFriendType() const { | |||
2298 | return Friend.dyn_cast<TypeSourceInfo*>(); | |||
2299 | } | |||
2300 | ||||
2301 | /// If this friend declaration names a templated function (or | |||
2302 | /// a member function of a templated type), return that type; | |||
2303 | /// otherwise return null. | |||
2304 | NamedDecl *getFriendDecl() const { | |||
2305 | return Friend.dyn_cast<NamedDecl*>(); | |||
2306 | } | |||
2307 | ||||
2308 | /// \brief Retrieves the location of the 'friend' keyword. | |||
2309 | SourceLocation getFriendLoc() const { | |||
2310 | return FriendLoc; | |||
2311 | } | |||
2312 | ||||
2313 | TemplateParameterList *getTemplateParameterList(unsigned i) const { | |||
2314 | assert(i <= NumParams)(static_cast <bool> (i <= NumParams) ? void (0) : __assert_fail ("i <= NumParams", "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 2314, __extension__ __PRETTY_FUNCTION__)); | |||
2315 | return Params[i]; | |||
2316 | } | |||
2317 | ||||
2318 | unsigned getNumTemplateParameters() const { | |||
2319 | return NumParams; | |||
2320 | } | |||
2321 | ||||
2322 | // Implement isa/cast/dyncast/etc. | |||
2323 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } | |||
2324 | static bool classofKind(Kind K) { return K == Decl::FriendTemplate; } | |||
2325 | }; | |||
2326 | ||||
2327 | /// \brief Declaration of an alias template. | |||
2328 | /// | |||
2329 | /// For example: | |||
2330 | /// \code | |||
2331 | /// template \<typename T> using V = std::map<T*, int, MyCompare<T>>; | |||
2332 | /// \endcode | |||
2333 | class TypeAliasTemplateDecl : public RedeclarableTemplateDecl { | |||
2334 | protected: | |||
2335 | using Common = CommonBase; | |||
2336 | ||||
2337 | TypeAliasTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L, | |||
2338 | DeclarationName Name, TemplateParameterList *Params, | |||
2339 | NamedDecl *Decl) | |||
2340 | : RedeclarableTemplateDecl(TypeAliasTemplate, C, DC, L, Name, Params, | |||
2341 | Decl) {} | |||
2342 | ||||
2343 | CommonBase *newCommon(ASTContext &C) const override; | |||
2344 | ||||
2345 | Common *getCommonPtr() { | |||
2346 | return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr()); | |||
2347 | } | |||
2348 | ||||
2349 | public: | |||
2350 | friend class ASTDeclReader; | |||
2351 | friend class ASTDeclWriter; | |||
2352 | ||||
2353 | /// Get the underlying function declaration of the template. | |||
2354 | TypeAliasDecl *getTemplatedDecl() const { | |||
2355 | return static_cast<TypeAliasDecl *>(TemplatedDecl); | |||
2356 | } | |||
2357 | ||||
2358 | ||||
2359 | TypeAliasTemplateDecl *getCanonicalDecl() override { | |||
2360 | return cast<TypeAliasTemplateDecl>( | |||
2361 | RedeclarableTemplateDecl::getCanonicalDecl()); | |||
2362 | } | |||
2363 | const TypeAliasTemplateDecl *getCanonicalDecl() const { | |||
2364 | return cast<TypeAliasTemplateDecl>( | |||
2365 | RedeclarableTemplateDecl::getCanonicalDecl()); | |||
2366 | } | |||
2367 | ||||
2368 | /// \brief Retrieve the previous declaration of this function template, or | |||
2369 | /// nullptr if no such declaration exists. | |||
2370 | TypeAliasTemplateDecl *getPreviousDecl() { | |||
2371 | return cast_or_null<TypeAliasTemplateDecl>( | |||
2372 | static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl()); | |||
2373 | } | |||
2374 | const TypeAliasTemplateDecl *getPreviousDecl() const { | |||
2375 | return cast_or_null<TypeAliasTemplateDecl>( | |||
2376 | static_cast<const RedeclarableTemplateDecl *>( | |||
2377 | this)->getPreviousDecl()); | |||
2378 | } | |||
2379 | ||||
2380 | TypeAliasTemplateDecl *getInstantiatedFromMemberTemplate() const { | |||
2381 | return cast_or_null<TypeAliasTemplateDecl>( | |||
2382 | RedeclarableTemplateDecl::getInstantiatedFromMemberTemplate()); | |||
2383 | } | |||
2384 | ||||
2385 | /// \brief Create a function template node. | |||
2386 | static TypeAliasTemplateDecl *Create(ASTContext &C, DeclContext *DC, | |||
2387 | SourceLocation L, | |||
2388 | DeclarationName Name, | |||
2389 | TemplateParameterList *Params, | |||
2390 | NamedDecl *Decl); | |||
2391 | ||||
2392 | /// \brief Create an empty alias template node. | |||
2393 | static TypeAliasTemplateDecl *CreateDeserialized(ASTContext &C, unsigned ID); | |||
2394 | ||||
2395 | // Implement isa/cast/dyncast support | |||
2396 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } | |||
2397 | static bool classofKind(Kind K) { return K == TypeAliasTemplate; } | |||
2398 | }; | |||
2399 | ||||
2400 | /// \brief Declaration of a function specialization at template class scope. | |||
2401 | /// | |||
2402 | /// This is a non-standard extension needed to support MSVC. | |||
2403 | /// | |||
2404 | /// For example: | |||
2405 | /// \code | |||
2406 | /// template <class T> | |||
2407 | /// class A { | |||
2408 | /// template <class U> void foo(U a) { } | |||
2409 | /// template<> void foo(int a) { } | |||
2410 | /// } | |||
2411 | /// \endcode | |||
2412 | /// | |||
2413 | /// "template<> foo(int a)" will be saved in Specialization as a normal | |||
2414 | /// CXXMethodDecl. Then during an instantiation of class A, it will be | |||
2415 | /// transformed into an actual function specialization. | |||
2416 | class ClassScopeFunctionSpecializationDecl : public Decl { | |||
2417 | CXXMethodDecl *Specialization; | |||
2418 | bool HasExplicitTemplateArgs; | |||
2419 | TemplateArgumentListInfo TemplateArgs; | |||
2420 | ||||
2421 | ClassScopeFunctionSpecializationDecl(DeclContext *DC, SourceLocation Loc, | |||
2422 | CXXMethodDecl *FD, bool Args, | |||
2423 | TemplateArgumentListInfo TemplArgs) | |||
2424 | : Decl(Decl::ClassScopeFunctionSpecialization, DC, Loc), | |||
2425 | Specialization(FD), HasExplicitTemplateArgs(Args), | |||
2426 | TemplateArgs(std::move(TemplArgs)) {} | |||
2427 | ||||
2428 | ClassScopeFunctionSpecializationDecl(EmptyShell Empty) | |||
2429 | : Decl(Decl::ClassScopeFunctionSpecialization, Empty) {} | |||
2430 | ||||
2431 | virtual void anchor(); | |||
2432 | ||||
2433 | public: | |||
2434 | friend class ASTDeclReader; | |||
2435 | friend class ASTDeclWriter; | |||
2436 | ||||
2437 | CXXMethodDecl *getSpecialization() const { return Specialization; } | |||
2438 | bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; } | |||
2439 | const TemplateArgumentListInfo& templateArgs() const { return TemplateArgs; } | |||
2440 | ||||
2441 | static ClassScopeFunctionSpecializationDecl *Create(ASTContext &C, | |||
2442 | DeclContext *DC, | |||
2443 | SourceLocation Loc, | |||
2444 | CXXMethodDecl *FD, | |||
2445 | bool HasExplicitTemplateArgs, | |||
2446 | TemplateArgumentListInfo TemplateArgs) { | |||
2447 | return new (C, DC) ClassScopeFunctionSpecializationDecl( | |||
2448 | DC, Loc, FD, HasExplicitTemplateArgs, std::move(TemplateArgs)); | |||
2449 | } | |||
2450 | ||||
2451 | static ClassScopeFunctionSpecializationDecl * | |||
2452 | CreateDeserialized(ASTContext &Context, unsigned ID); | |||
2453 | ||||
2454 | // Implement isa/cast/dyncast/etc. | |||
2455 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } | |||
2456 | ||||
2457 | static bool classofKind(Kind K) { | |||
2458 | return K == Decl::ClassScopeFunctionSpecialization; | |||
2459 | } | |||
2460 | }; | |||
2461 | ||||
2462 | /// Implementation of inline functions that require the template declarations | |||
2463 | inline AnyFunctionDecl::AnyFunctionDecl(FunctionTemplateDecl *FTD) | |||
2464 | : Function(FTD) {} | |||
2465 | ||||
2466 | /// \brief Represents a variable template specialization, which refers to | |||
2467 | /// a variable template with a given set of template arguments. | |||
2468 | /// | |||
2469 | /// Variable template specializations represent both explicit | |||
2470 | /// specializations of variable templates, as in the example below, and | |||
2471 | /// implicit instantiations of variable templates. | |||
2472 | /// | |||
2473 | /// \code | |||
2474 | /// template<typename T> constexpr T pi = T(3.1415926535897932385); | |||
2475 | /// | |||
2476 | /// template<> | |||
2477 | /// constexpr float pi<float>; // variable template specialization pi<float> | |||
2478 | /// \endcode | |||
2479 | class VarTemplateSpecializationDecl : public VarDecl, | |||
2480 | public llvm::FoldingSetNode { | |||
2481 | ||||
2482 | /// \brief Structure that stores information about a variable template | |||
2483 | /// specialization that was instantiated from a variable template partial | |||
2484 | /// specialization. | |||
2485 | struct SpecializedPartialSpecialization { | |||
2486 | /// \brief The variable template partial specialization from which this | |||
2487 | /// variable template specialization was instantiated. | |||
2488 | VarTemplatePartialSpecializationDecl *PartialSpecialization; | |||
2489 | ||||
2490 | /// \brief The template argument list deduced for the variable template | |||
2491 | /// partial specialization itself. | |||
2492 | const TemplateArgumentList *TemplateArgs; | |||
2493 | }; | |||
2494 | ||||
2495 | /// \brief The template that this specialization specializes. | |||
2496 | llvm::PointerUnion<VarTemplateDecl *, SpecializedPartialSpecialization *> | |||
2497 | SpecializedTemplate; | |||
2498 | ||||
2499 | /// \brief Further info for explicit template specialization/instantiation. | |||
2500 | struct ExplicitSpecializationInfo { | |||
2501 | /// \brief The type-as-written. | |||
2502 | TypeSourceInfo *TypeAsWritten = nullptr; | |||
2503 | ||||
2504 | /// \brief The location of the extern keyword. | |||
2505 | SourceLocation ExternLoc; | |||
2506 | ||||
2507 | /// \brief The location of the template keyword. | |||
2508 | SourceLocation TemplateKeywordLoc; | |||
2509 | ||||
2510 | ExplicitSpecializationInfo() = default; | |||
2511 | }; | |||
2512 | ||||
2513 | /// \brief Further info for explicit template specialization/instantiation. | |||
2514 | /// Does not apply to implicit specializations. | |||
2515 | ExplicitSpecializationInfo *ExplicitInfo = nullptr; | |||
2516 | ||||
2517 | /// \brief The template arguments used to describe this specialization. | |||
2518 | const TemplateArgumentList *TemplateArgs; | |||
2519 | TemplateArgumentListInfo TemplateArgsInfo; | |||
2520 | ||||
2521 | /// \brief The point where this template was instantiated (if any). | |||
2522 | SourceLocation PointOfInstantiation; | |||
2523 | ||||
2524 | /// \brief The kind of specialization this declaration refers to. | |||
2525 | /// Really a value of type TemplateSpecializationKind. | |||
2526 | unsigned SpecializationKind : 3; | |||
2527 | ||||
2528 | /// \brief Whether this declaration is a complete definition of the | |||
2529 | /// variable template specialization. We can't otherwise tell apart | |||
2530 | /// an instantiated declaration from an instantiated definition with | |||
2531 | /// no initializer. | |||
2532 | unsigned IsCompleteDefinition : 1; | |||
2533 | ||||
2534 | protected: | |||
2535 | VarTemplateSpecializationDecl(Kind DK, ASTContext &Context, DeclContext *DC, | |||
2536 | SourceLocation StartLoc, SourceLocation IdLoc, | |||
2537 | VarTemplateDecl *SpecializedTemplate, | |||
2538 | QualType T, TypeSourceInfo *TInfo, | |||
2539 | StorageClass S, | |||
2540 | ArrayRef<TemplateArgument> Args); | |||
2541 | ||||
2542 | explicit VarTemplateSpecializationDecl(Kind DK, ASTContext &Context); | |||
2543 | ||||
2544 | public: | |||
2545 | friend class ASTDeclReader; | |||
2546 | friend class ASTDeclWriter; | |||
2547 | friend class VarDecl; | |||
2548 | ||||
2549 | static VarTemplateSpecializationDecl * | |||
2550 | Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, | |||
2551 | SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T, | |||
2552 | TypeSourceInfo *TInfo, StorageClass S, | |||
2553 | ArrayRef<TemplateArgument> Args); | |||
2554 | static VarTemplateSpecializationDecl *CreateDeserialized(ASTContext &C, | |||
2555 | unsigned ID); | |||
2556 | ||||
2557 | void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, | |||
2558 | bool Qualified) const override; | |||
2559 | ||||
2560 | VarTemplateSpecializationDecl *getMostRecentDecl() { | |||
2561 | VarDecl *Recent = static_cast<VarDecl *>(this)->getMostRecentDecl(); | |||
2562 | return cast<VarTemplateSpecializationDecl>(Recent); | |||
2563 | } | |||
2564 | ||||
2565 | /// \brief Retrieve the template that this specialization specializes. | |||
2566 | VarTemplateDecl *getSpecializedTemplate() const; | |||
2567 | ||||
2568 | /// \brief Retrieve the template arguments of the variable template | |||
2569 | /// specialization. | |||
2570 | const TemplateArgumentList &getTemplateArgs() const { return *TemplateArgs; } | |||
2571 | ||||
2572 | // TODO: Always set this when creating the new specialization? | |||
2573 | void setTemplateArgsInfo(const TemplateArgumentListInfo &ArgsInfo); | |||
2574 | ||||
2575 | const TemplateArgumentListInfo &getTemplateArgsInfo() const { | |||
2576 | return TemplateArgsInfo; | |||
2577 | } | |||
2578 | ||||
2579 | /// \brief Determine the kind of specialization that this | |||
2580 | /// declaration represents. | |||
2581 | TemplateSpecializationKind getSpecializationKind() const { | |||
2582 | return static_cast<TemplateSpecializationKind>(SpecializationKind); | |||
2583 | } | |||
2584 | ||||
2585 | bool isExplicitSpecialization() const { | |||
2586 | return getSpecializationKind() == TSK_ExplicitSpecialization; | |||
2587 | } | |||
2588 | ||||
2589 | /// \brief True if this declaration is an explicit specialization, | |||
2590 | /// explicit instantiation declaration, or explicit instantiation | |||
2591 | /// definition. | |||
2592 | bool isExplicitInstantiationOrSpecialization() const { | |||
2593 | return isTemplateExplicitInstantiationOrSpecialization( | |||
2594 | getTemplateSpecializationKind()); | |||
2595 | } | |||
2596 | ||||
2597 | void setSpecializationKind(TemplateSpecializationKind TSK) { | |||
2598 | SpecializationKind = TSK; | |||
2599 | } | |||
2600 | ||||
2601 | /// \brief Get the point of instantiation (if any), or null if none. | |||
2602 | SourceLocation getPointOfInstantiation() const { | |||
2603 | return PointOfInstantiation; | |||
2604 | } | |||
2605 | ||||
2606 | void setPointOfInstantiation(SourceLocation Loc) { | |||
2607 | assert(Loc.isValid() && "point of instantiation must be valid!")(static_cast <bool> (Loc.isValid() && "point of instantiation must be valid!" ) ? void (0) : __assert_fail ("Loc.isValid() && \"point of instantiation must be valid!\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 2607, __extension__ __PRETTY_FUNCTION__)); | |||
2608 | PointOfInstantiation = Loc; | |||
2609 | } | |||
2610 | ||||
2611 | void setCompleteDefinition() { IsCompleteDefinition = true; } | |||
2612 | ||||
2613 | /// \brief If this variable template specialization is an instantiation of | |||
2614 | /// a template (rather than an explicit specialization), return the | |||
2615 | /// variable template or variable template partial specialization from which | |||
2616 | /// it was instantiated. | |||
2617 | llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *> | |||
2618 | getInstantiatedFrom() const { | |||
2619 | if (!isTemplateInstantiation(getSpecializationKind())) | |||
2620 | return llvm::PointerUnion<VarTemplateDecl *, | |||
2621 | VarTemplatePartialSpecializationDecl *>(); | |||
2622 | ||||
2623 | return getSpecializedTemplateOrPartial(); | |||
2624 | } | |||
2625 | ||||
2626 | /// \brief Retrieve the variable template or variable template partial | |||
2627 | /// specialization which was specialized by this. | |||
2628 | llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *> | |||
2629 | getSpecializedTemplateOrPartial() const { | |||
2630 | if (SpecializedPartialSpecialization *PartialSpec = | |||
2631 | SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>()) | |||
2632 | return PartialSpec->PartialSpecialization; | |||
2633 | ||||
2634 | return SpecializedTemplate.get<VarTemplateDecl *>(); | |||
2635 | } | |||
2636 | ||||
2637 | /// \brief Retrieve the set of template arguments that should be used | |||
2638 | /// to instantiate the initializer of the variable template or variable | |||
2639 | /// template partial specialization from which this variable template | |||
2640 | /// specialization was instantiated. | |||
2641 | /// | |||
2642 | /// \returns For a variable template specialization instantiated from the | |||
2643 | /// primary template, this function will return the same template arguments | |||
2644 | /// as getTemplateArgs(). For a variable template specialization instantiated | |||
2645 | /// from a variable template partial specialization, this function will the | |||
2646 | /// return deduced template arguments for the variable template partial | |||
2647 | /// specialization itself. | |||
2648 | const TemplateArgumentList &getTemplateInstantiationArgs() const { | |||
2649 | if (SpecializedPartialSpecialization *PartialSpec = | |||
2650 | SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>()) | |||
2651 | return *PartialSpec->TemplateArgs; | |||
2652 | ||||
2653 | return getTemplateArgs(); | |||
2654 | } | |||
2655 | ||||
2656 | /// \brief Note that this variable template specialization is actually an | |||
2657 | /// instantiation of the given variable template partial specialization whose | |||
2658 | /// template arguments have been deduced. | |||
2659 | void setInstantiationOf(VarTemplatePartialSpecializationDecl *PartialSpec, | |||
2660 | const TemplateArgumentList *TemplateArgs) { | |||
2661 | assert(!SpecializedTemplate.is<SpecializedPartialSpecialization *>() &&(static_cast <bool> (!SpecializedTemplate.is<SpecializedPartialSpecialization *>() && "Already set to a variable template partial specialization!" ) ? void (0) : __assert_fail ("!SpecializedTemplate.is<SpecializedPartialSpecialization *>() && \"Already set to a variable template partial specialization!\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 2662, __extension__ __PRETTY_FUNCTION__)) | |||
2662 | "Already set to a variable template partial specialization!")(static_cast <bool> (!SpecializedTemplate.is<SpecializedPartialSpecialization *>() && "Already set to a variable template partial specialization!" ) ? void (0) : __assert_fail ("!SpecializedTemplate.is<SpecializedPartialSpecialization *>() && \"Already set to a variable template partial specialization!\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 2662, __extension__ __PRETTY_FUNCTION__)); | |||
2663 | SpecializedPartialSpecialization *PS = | |||
2664 | new (getASTContext()) SpecializedPartialSpecialization(); | |||
2665 | PS->PartialSpecialization = PartialSpec; | |||
2666 | PS->TemplateArgs = TemplateArgs; | |||
2667 | SpecializedTemplate = PS; | |||
2668 | } | |||
2669 | ||||
2670 | /// \brief Note that this variable template specialization is an instantiation | |||
2671 | /// of the given variable template. | |||
2672 | void setInstantiationOf(VarTemplateDecl *TemplDecl) { | |||
2673 | assert(!SpecializedTemplate.is<SpecializedPartialSpecialization *>() &&(static_cast <bool> (!SpecializedTemplate.is<SpecializedPartialSpecialization *>() && "Previously set to a variable template partial specialization!" ) ? void (0) : __assert_fail ("!SpecializedTemplate.is<SpecializedPartialSpecialization *>() && \"Previously set to a variable template partial specialization!\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 2674, __extension__ __PRETTY_FUNCTION__)) | |||
2674 | "Previously set to a variable template partial specialization!")(static_cast <bool> (!SpecializedTemplate.is<SpecializedPartialSpecialization *>() && "Previously set to a variable template partial specialization!" ) ? void (0) : __assert_fail ("!SpecializedTemplate.is<SpecializedPartialSpecialization *>() && \"Previously set to a variable template partial specialization!\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 2674, __extension__ __PRETTY_FUNCTION__)); | |||
2675 | SpecializedTemplate = TemplDecl; | |||
2676 | } | |||
2677 | ||||
2678 | /// \brief Sets the type of this specialization as it was written by | |||
2679 | /// the user. | |||
2680 | void setTypeAsWritten(TypeSourceInfo *T) { | |||
2681 | if (!ExplicitInfo) | |||
2682 | ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo; | |||
2683 | ExplicitInfo->TypeAsWritten = T; | |||
2684 | } | |||
2685 | ||||
2686 | /// \brief Gets the type of this specialization as it was written by | |||
2687 | /// the user, if it was so written. | |||
2688 | TypeSourceInfo *getTypeAsWritten() const { | |||
2689 | return ExplicitInfo ? ExplicitInfo->TypeAsWritten : nullptr; | |||
2690 | } | |||
2691 | ||||
2692 | /// \brief Gets the location of the extern keyword, if present. | |||
2693 | SourceLocation getExternLoc() const { | |||
2694 | return ExplicitInfo ? ExplicitInfo->ExternLoc : SourceLocation(); | |||
2695 | } | |||
2696 | ||||
2697 | /// \brief Sets the location of the extern keyword. | |||
2698 | void setExternLoc(SourceLocation Loc) { | |||
2699 | if (!ExplicitInfo) | |||
2700 | ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo; | |||
2701 | ExplicitInfo->ExternLoc = Loc; | |||
2702 | } | |||
2703 | ||||
2704 | /// \brief Sets the location of the template keyword. | |||
2705 | void setTemplateKeywordLoc(SourceLocation Loc) { | |||
2706 | if (!ExplicitInfo) | |||
2707 | ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo; | |||
2708 | ExplicitInfo->TemplateKeywordLoc = Loc; | |||
2709 | } | |||
2710 | ||||
2711 | /// \brief Gets the location of the template keyword, if present. | |||
2712 | SourceLocation getTemplateKeywordLoc() const { | |||
2713 | return ExplicitInfo ? ExplicitInfo->TemplateKeywordLoc : SourceLocation(); | |||
2714 | } | |||
2715 | ||||
2716 | void Profile(llvm::FoldingSetNodeID &ID) const { | |||
2717 | Profile(ID, TemplateArgs->asArray(), getASTContext()); | |||
2718 | } | |||
2719 | ||||
2720 | static void Profile(llvm::FoldingSetNodeID &ID, | |||
2721 | ArrayRef<TemplateArgument> TemplateArgs, | |||
2722 | ASTContext &Context) { | |||
2723 | ID.AddInteger(TemplateArgs.size()); | |||
2724 | for (const TemplateArgument &TemplateArg : TemplateArgs) | |||
2725 | TemplateArg.Profile(ID, Context); | |||
2726 | } | |||
2727 | ||||
2728 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } | |||
2729 | ||||
2730 | static bool classofKind(Kind K) { | |||
2731 | return K >= firstVarTemplateSpecialization && | |||
2732 | K <= lastVarTemplateSpecialization; | |||
2733 | } | |||
2734 | }; | |||
2735 | ||||
2736 | class VarTemplatePartialSpecializationDecl | |||
2737 | : public VarTemplateSpecializationDecl { | |||
2738 | /// \brief The list of template parameters | |||
2739 | TemplateParameterList *TemplateParams = nullptr; | |||
2740 | ||||
2741 | /// \brief The source info for the template arguments as written. | |||
2742 | /// FIXME: redundant with TypeAsWritten? | |||
2743 | const ASTTemplateArgumentListInfo *ArgsAsWritten = nullptr; | |||
2744 | ||||
2745 | /// \brief The variable template partial specialization from which this | |||
2746 | /// variable template partial specialization was instantiated. | |||
2747 | /// | |||
2748 | /// The boolean value will be true to indicate that this variable template | |||
2749 | /// partial specialization was specialized at this level. | |||
2750 | llvm::PointerIntPair<VarTemplatePartialSpecializationDecl *, 1, bool> | |||
2751 | InstantiatedFromMember; | |||
2752 | ||||
2753 | VarTemplatePartialSpecializationDecl( | |||
2754 | ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, | |||
2755 | SourceLocation IdLoc, TemplateParameterList *Params, | |||
2756 | VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo, | |||
2757 | StorageClass S, ArrayRef<TemplateArgument> Args, | |||
2758 | const ASTTemplateArgumentListInfo *ArgInfos); | |||
2759 | ||||
2760 | VarTemplatePartialSpecializationDecl(ASTContext &Context) | |||
2761 | : VarTemplateSpecializationDecl(VarTemplatePartialSpecialization, | |||
2762 | Context), | |||
2763 | InstantiatedFromMember(nullptr, false) {} | |||
2764 | ||||
2765 | void anchor() override; | |||
2766 | ||||
2767 | public: | |||
2768 | friend class ASTDeclReader; | |||
2769 | friend class ASTDeclWriter; | |||
2770 | ||||
2771 | static VarTemplatePartialSpecializationDecl * | |||
2772 | Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, | |||
2773 | SourceLocation IdLoc, TemplateParameterList *Params, | |||
2774 | VarTemplateDecl *SpecializedTemplate, QualType T, | |||
2775 | TypeSourceInfo *TInfo, StorageClass S, ArrayRef<TemplateArgument> Args, | |||
2776 | const TemplateArgumentListInfo &ArgInfos); | |||
2777 | ||||
2778 | static VarTemplatePartialSpecializationDecl *CreateDeserialized(ASTContext &C, | |||
2779 | unsigned ID); | |||
2780 | ||||
2781 | VarTemplatePartialSpecializationDecl *getMostRecentDecl() { | |||
2782 | return cast<VarTemplatePartialSpecializationDecl>( | |||
2783 | static_cast<VarTemplateSpecializationDecl *>( | |||
2784 | this)->getMostRecentDecl()); | |||
2785 | } | |||
2786 | ||||
2787 | /// Get the list of template parameters | |||
2788 | TemplateParameterList *getTemplateParameters() const { | |||
2789 | return TemplateParams; | |||
2790 | } | |||
2791 | ||||
2792 | /// Get the template arguments as written. | |||
2793 | const ASTTemplateArgumentListInfo *getTemplateArgsAsWritten() const { | |||
2794 | return ArgsAsWritten; | |||
2795 | } | |||
2796 | ||||
2797 | /// \brief Retrieve the member variable template partial specialization from | |||
2798 | /// which this particular variable template partial specialization was | |||
2799 | /// instantiated. | |||
2800 | /// | |||
2801 | /// \code | |||
2802 | /// template<typename T> | |||
2803 | /// struct Outer { | |||
2804 | /// template<typename U> U Inner; | |||
2805 | /// template<typename U> U* Inner<U*> = (U*)(0); // #1 | |||
2806 | /// }; | |||
2807 | /// | |||
2808 | /// template int* Outer<float>::Inner<int*>; | |||
2809 | /// \endcode | |||
2810 | /// | |||
2811 | /// In this example, the instantiation of \c Outer<float>::Inner<int*> will | |||
2812 | /// end up instantiating the partial specialization | |||
2813 | /// \c Outer<float>::Inner<U*>, which itself was instantiated from the | |||
2814 | /// variable template partial specialization \c Outer<T>::Inner<U*>. Given | |||
2815 | /// \c Outer<float>::Inner<U*>, this function would return | |||
2816 | /// \c Outer<T>::Inner<U*>. | |||
2817 | VarTemplatePartialSpecializationDecl *getInstantiatedFromMember() const { | |||
2818 | const VarTemplatePartialSpecializationDecl *First = | |||
2819 | cast<VarTemplatePartialSpecializationDecl>(getFirstDecl()); | |||
2820 | return First->InstantiatedFromMember.getPointer(); | |||
2821 | } | |||
2822 | ||||
2823 | void | |||
2824 | setInstantiatedFromMember(VarTemplatePartialSpecializationDecl *PartialSpec) { | |||
2825 | VarTemplatePartialSpecializationDecl *First = | |||
2826 | cast<VarTemplatePartialSpecializationDecl>(getFirstDecl()); | |||
2827 | First->InstantiatedFromMember.setPointer(PartialSpec); | |||
2828 | } | |||
2829 | ||||
2830 | /// \brief Determines whether this variable template partial specialization | |||
2831 | /// was a specialization of a member partial specialization. | |||
2832 | /// | |||
2833 | /// In the following example, the member template partial specialization | |||
2834 | /// \c X<int>::Inner<T*> is a member specialization. | |||
2835 | /// | |||
2836 | /// \code | |||
2837 | /// template<typename T> | |||
2838 | /// struct X { | |||
2839 | /// template<typename U> U Inner; | |||
2840 | /// template<typename U> U* Inner<U*> = (U*)(0); | |||
2841 | /// }; | |||
2842 | /// | |||
2843 | /// template<> template<typename T> | |||
2844 | /// U* X<int>::Inner<T*> = (T*)(0) + 1; | |||
2845 | /// \endcode | |||
2846 | bool isMemberSpecialization() { | |||
2847 | VarTemplatePartialSpecializationDecl *First = | |||
2848 | cast<VarTemplatePartialSpecializationDecl>(getFirstDecl()); | |||
2849 | return First->InstantiatedFromMember.getInt(); | |||
2850 | } | |||
2851 | ||||
2852 | /// \brief Note that this member template is a specialization. | |||
2853 | void setMemberSpecialization() { | |||
2854 | VarTemplatePartialSpecializationDecl *First = | |||
2855 | cast<VarTemplatePartialSpecializationDecl>(getFirstDecl()); | |||
2856 | assert(First->InstantiatedFromMember.getPointer() &&(static_cast <bool> (First->InstantiatedFromMember.getPointer () && "Only member templates can be member template specializations" ) ? void (0) : __assert_fail ("First->InstantiatedFromMember.getPointer() && \"Only member templates can be member template specializations\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 2857, __extension__ __PRETTY_FUNCTION__)) | |||
2857 | "Only member templates can be member template specializations")(static_cast <bool> (First->InstantiatedFromMember.getPointer () && "Only member templates can be member template specializations" ) ? void (0) : __assert_fail ("First->InstantiatedFromMember.getPointer() && \"Only member templates can be member template specializations\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/AST/DeclTemplate.h" , 2857, __extension__ __PRETTY_FUNCTION__)); | |||
2858 | return First->InstantiatedFromMember.setInt(true); | |||
2859 | } | |||
2860 | ||||
2861 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } | |||
2862 | ||||
2863 | static bool classofKind(Kind K) { | |||
2864 | return K == VarTemplatePartialSpecialization; | |||
2865 | } | |||
2866 | }; | |||
2867 | ||||
2868 | /// Declaration of a variable template. | |||
2869 | class VarTemplateDecl : public RedeclarableTemplateDecl { | |||
2870 | protected: | |||
2871 | /// \brief Data that is common to all of the declarations of a given | |||
2872 | /// variable template. | |||
2873 | struct Common : CommonBase { | |||
2874 | /// \brief The variable template specializations for this variable | |||
2875 | /// template, including explicit specializations and instantiations. | |||
2876 | llvm::FoldingSetVector<VarTemplateSpecializationDecl> Specializations; | |||
2877 | ||||
2878 | /// \brief The variable template partial specializations for this variable | |||
2879 | /// template. | |||
2880 | llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> | |||
2881 | PartialSpecializations; | |||
2882 | ||||
2883 | Common() = default; | |||
2884 | }; | |||
2885 | ||||
2886 | /// \brief Retrieve the set of specializations of this variable template. | |||
2887 | llvm::FoldingSetVector<VarTemplateSpecializationDecl> & | |||
2888 | getSpecializations() const; | |||
2889 | ||||
2890 | /// \brief Retrieve the set of partial specializations of this class | |||
2891 | /// template. | |||
2892 | llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> & | |||
2893 | getPartialSpecializations(); | |||
2894 | ||||
2895 | VarTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L, | |||
2896 | DeclarationName Name, TemplateParameterList *Params, | |||
2897 | NamedDecl *Decl) | |||
2898 | : RedeclarableTemplateDecl(VarTemplate, C, DC, L, Name, Params, Decl) {} | |||
2899 | ||||
2900 | CommonBase *newCommon(ASTContext &C) const override; | |||
2901 | ||||
2902 | Common *getCommonPtr() const { | |||
2903 | return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr()); | |||
2904 | } | |||
2905 | ||||
2906 | public: | |||
2907 | friend class ASTDeclReader; | |||
2908 | friend class ASTDeclWriter; | |||
2909 | ||||
2910 | /// \brief Load any lazily-loaded specializations from the external source. | |||
2911 | void LoadLazySpecializations() const; | |||
2912 | ||||
2913 | /// \brief Get the underlying variable declarations of the template. | |||
2914 | VarDecl *getTemplatedDecl() const { | |||
2915 | return static_cast<VarDecl *>(TemplatedDecl); | |||
2916 | } | |||
2917 | ||||
2918 | /// \brief Returns whether this template declaration defines the primary | |||
2919 | /// variable pattern. | |||
2920 | bool isThisDeclarationADefinition() const { | |||
2921 | return getTemplatedDecl()->isThisDeclarationADefinition(); | |||
2922 | } | |||
2923 | ||||
2924 | VarTemplateDecl *getDefinition(); | |||
2925 | ||||
2926 | /// \brief Create a variable template node. | |||
2927 | static VarTemplateDecl *Create(ASTContext &C, DeclContext *DC, | |||
2928 | SourceLocation L, DeclarationName Name, | |||
2929 | TemplateParameterList *Params, | |||
2930 | VarDecl *Decl); | |||
2931 | ||||
2932 | /// \brief Create an empty variable template node. | |||
2933 | static VarTemplateDecl *CreateDeserialized(ASTContext &C, unsigned ID); | |||
2934 | ||||
2935 | /// \brief Return the specialization with the provided arguments if it exists, | |||
2936 | /// otherwise return the insertion point. | |||
2937 | VarTemplateSpecializationDecl * | |||
2938 | findSpecialization(ArrayRef<TemplateArgument> Args, void *&InsertPos); | |||
2939 | ||||
2940 | /// \brief Insert the specified specialization knowing that it is not already | |||
2941 | /// in. InsertPos must be obtained from findSpecialization. | |||
2942 | void AddSpecialization(VarTemplateSpecializationDecl *D, void *InsertPos); | |||
2943 | ||||
2944 | VarTemplateDecl *getCanonicalDecl() override { | |||
2945 | return cast<VarTemplateDecl>(RedeclarableTemplateDecl::getCanonicalDecl()); | |||
2946 | } | |||
2947 | const VarTemplateDecl *getCanonicalDecl() const { | |||
2948 | return cast<VarTemplateDecl>(RedeclarableTemplateDecl::getCanonicalDecl()); | |||
2949 | } | |||
2950 | ||||
2951 | /// \brief Retrieve the previous declaration of this variable template, or | |||
2952 | /// nullptr if no such declaration exists. | |||
2953 | VarTemplateDecl *getPreviousDecl() { | |||
2954 | return cast_or_null<VarTemplateDecl>( | |||
2955 | static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl()); | |||
2956 | } | |||
2957 | const VarTemplateDecl *getPreviousDecl() const { | |||
2958 | return cast_or_null<VarTemplateDecl>( | |||
2959 | static_cast<const RedeclarableTemplateDecl *>( | |||
2960 | this)->getPreviousDecl()); | |||
2961 | } | |||
2962 | ||||
2963 | VarTemplateDecl *getMostRecentDecl() { | |||
2964 | return cast<VarTemplateDecl>( | |||
2965 | static_cast<RedeclarableTemplateDecl *>(this)->getMostRecentDecl()); | |||
2966 | } | |||
2967 | const VarTemplateDecl *getMostRecentDecl() const { | |||
2968 | return const_cast<VarTemplateDecl *>(this)->getMostRecentDecl(); | |||
2969 | } | |||
2970 | ||||
2971 | VarTemplateDecl *getInstantiatedFromMemberTemplate() const { | |||
2972 | return cast_or_null<VarTemplateDecl>( | |||
2973 | RedeclarableTemplateDecl::getInstantiatedFromMemberTemplate()); | |||
2974 | } | |||
2975 | ||||
2976 | /// \brief Return the partial specialization with the provided arguments if it | |||
2977 | /// exists, otherwise return the insertion point. | |||
2978 | VarTemplatePartialSpecializationDecl * | |||
2979 | findPartialSpecialization(ArrayRef<TemplateArgument> Args, void *&InsertPos); | |||
2980 | ||||
2981 | /// \brief Insert the specified partial specialization knowing that it is not | |||
2982 | /// already in. InsertPos must be obtained from findPartialSpecialization. | |||
2983 | void AddPartialSpecialization(VarTemplatePartialSpecializationDecl *D, | |||
2984 | void *InsertPos); | |||
2985 | ||||
2986 | /// \brief Retrieve the partial specializations as an ordered list. | |||
2987 | void getPartialSpecializations( | |||
2988 | SmallVectorImpl<VarTemplatePartialSpecializationDecl *> &PS); | |||
2989 | ||||
2990 | /// \brief Find a variable template partial specialization which was | |||
2991 | /// instantiated | |||
2992 | /// from the given member partial specialization. | |||
2993 | /// | |||
2994 | /// \param D a member variable template partial specialization. | |||
2995 | /// | |||
2996 | /// \returns the variable template partial specialization which was | |||
2997 | /// instantiated | |||
2998 | /// from the given member partial specialization, or nullptr if no such | |||
2999 | /// partial specialization exists. | |||
3000 | VarTemplatePartialSpecializationDecl *findPartialSpecInstantiatedFromMember( | |||
3001 | VarTemplatePartialSpecializationDecl *D); | |||
3002 | ||||
3003 | using spec_iterator = SpecIterator<VarTemplateSpecializationDecl>; | |||
3004 | using spec_range = llvm::iterator_range<spec_iterator>; | |||
3005 | ||||
3006 | spec_range specializations() const { | |||
3007 | return spec_range(spec_begin(), spec_end()); | |||
3008 | } | |||
3009 | ||||
3010 | spec_iterator spec_begin() const { | |||
3011 | return makeSpecIterator(getSpecializations(), false); | |||
3012 | } | |||
3013 | ||||
3014 | spec_iterator spec_end() const { | |||
3015 | return makeSpecIterator(getSpecializations(), true); | |||
3016 | } | |||
3017 | ||||
3018 | // Implement isa/cast/dyncast support | |||
3019 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } | |||
3020 | static bool classofKind(Kind K) { return K == VarTemplate; } | |||
3021 | }; | |||
3022 | ||||
3023 | inline NamedDecl *getAsNamedDecl(TemplateParameter P) { | |||
3024 | if (auto *PD = P.dyn_cast<TemplateTypeParmDecl*>()) | |||
3025 | return PD; | |||
3026 | if (auto *PD = P.dyn_cast<NonTypeTemplateParmDecl*>()) | |||
3027 | return PD; | |||
3028 | return P.get<TemplateTemplateParmDecl*>(); | |||
3029 | } | |||
3030 | ||||
3031 | inline TemplateDecl *getAsTypeTemplateDecl(Decl *D) { | |||
3032 | auto *TD = dyn_cast<TemplateDecl>(D); | |||
3033 | return TD && (isa<ClassTemplateDecl>(TD) || | |||
3034 | isa<ClassTemplatePartialSpecializationDecl>(TD) || | |||
3035 | isa<TypeAliasTemplateDecl>(TD) || | |||
3036 | isa<TemplateTemplateParmDecl>(TD)) | |||
3037 | ? TD | |||
3038 | : nullptr; | |||
3039 | } | |||
3040 | ||||
3041 | } // namespace clang | |||
3042 | ||||
3043 | #endif // LLVM_CLANG_AST_DECLTEMPLATE_H |