clang 20.0.0git
ExternalASTMerger.cpp
Go to the documentation of this file.
1//===- ExternalASTMerger.cpp - Merging External AST Interface ---*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the ExternalASTMerger, which vends a combination of
10// ASTs from several different ASTContext/FileManager pairs
11//
12//===----------------------------------------------------------------------===//
13
15#include "clang/AST/Decl.h"
16#include "clang/AST/DeclCXX.h"
17#include "clang/AST/DeclObjC.h"
20
21using namespace clang;
22
23namespace {
24
25template <typename T> struct Source {
26 T t;
27 Source(T t) : t(t) {}
28 operator T() { return t; }
29 template <typename U = T> U &get() { return t; }
30 template <typename U = T> const U &get() const { return t; }
31 template <typename U> operator Source<U>() { return Source<U>(t); }
32};
33
34typedef std::pair<Source<NamedDecl *>, ASTImporter *> Candidate;
35
36/// For the given DC, return the DC that is safe to perform lookups on. This is
37/// the DC we actually want to work with most of the time.
38const DeclContext *CanonicalizeDC(const DeclContext *DC) {
39 if (isa<LinkageSpecDecl>(DC))
40 return DC->getRedeclContext();
41 return DC;
42}
43
44Source<const DeclContext *>
45LookupSameContext(Source<TranslationUnitDecl *> SourceTU, const DeclContext *DC,
46 ASTImporter &ReverseImporter) {
47 DC = CanonicalizeDC(DC);
48 if (DC->isTranslationUnit()) {
49 return SourceTU;
50 }
51 Source<const DeclContext *> SourceParentDC =
52 LookupSameContext(SourceTU, DC->getParent(), ReverseImporter);
53 if (!SourceParentDC) {
54 // If we couldn't find the parent DC in this TranslationUnit, give up.
55 return nullptr;
56 }
57 auto *ND = cast<NamedDecl>(DC);
58 DeclarationName Name = ND->getDeclName();
59 auto SourceNameOrErr = ReverseImporter.Import(Name);
60 if (!SourceNameOrErr) {
61 llvm::consumeError(SourceNameOrErr.takeError());
62 return nullptr;
63 }
64 Source<DeclarationName> SourceName = *SourceNameOrErr;
65 DeclContext::lookup_result SearchResult =
66 SourceParentDC.get()->lookup(SourceName.get());
67
68 // There are two cases here. First, we might not find the name.
69 // We might also find multiple copies, in which case we have no
70 // guarantee that the one we wanted is the one we pick. (E.g.,
71 // if we have two specializations of the same template it is
72 // very hard to determine which is the one you want.)
73 //
74 // The Origins map fixes this problem by allowing the origin to be
75 // explicitly recorded, so we trigger that recording by returning
76 // nothing (rather than a possibly-inaccurate guess) here.
77 if (SearchResult.isSingleResult()) {
78 NamedDecl *SearchResultDecl = SearchResult.front();
79 if (isa<DeclContext>(SearchResultDecl) &&
80 SearchResultDecl->getKind() == DC->getDeclKind())
81 return cast<DeclContext>(SearchResultDecl)->getPrimaryContext();
82 return nullptr; // This type of lookup is unsupported
83 } else {
84 return nullptr;
85 }
86}
87
88/// A custom implementation of ASTImporter, for ExternalASTMerger's purposes.
89///
90/// There are several modifications:
91///
92/// - It enables lazy lookup (via the HasExternalLexicalStorage flag and a few
93/// others), which instructs Clang to refer to ExternalASTMerger. Also, it
94/// forces MinimalImport to true, which is necessary to make this work.
95/// - It maintains a reverse importer for use with names. This allows lookup of
96/// arbitrary names in the source context.
97/// - It updates the ExternalASTMerger's origin map as needed whenever a
98/// it sees a DeclContext.
99class LazyASTImporter : public ASTImporter {
100private:
102 ASTImporter Reverse;
103 const ExternalASTMerger::OriginMap &FromOrigins;
104 /// @see ExternalASTMerger::ImporterSource::Temporary
105 bool TemporarySource;
106 /// Map of imported declarations back to the declarations they originated
107 /// from.
108 llvm::DenseMap<Decl *, Decl *> ToOrigin;
109 /// @see ExternalASTMerger::ImporterSource::Merger
110 ExternalASTMerger *SourceMerger;
111 llvm::raw_ostream &logs() { return Parent.logs(); }
112public:
113 LazyASTImporter(ExternalASTMerger &_Parent, ASTContext &ToContext,
114 FileManager &ToFileManager,
116 std::shared_ptr<ASTImporterSharedState> SharedState)
117 : ASTImporter(ToContext, ToFileManager, S.getASTContext(),
118 S.getFileManager(),
119 /*MinimalImport=*/true, SharedState),
120 Parent(_Parent),
121 Reverse(S.getASTContext(), S.getFileManager(), ToContext, ToFileManager,
122 /*MinimalImport=*/true),
123 FromOrigins(S.getOriginMap()), TemporarySource(S.isTemporary()),
124 SourceMerger(S.getMerger()) {}
125
126 llvm::Expected<Decl *> ImportImpl(Decl *FromD) override {
127 if (!TemporarySource || !SourceMerger)
128 return ASTImporter::ImportImpl(FromD);
129
130 // If we get here, then this source is importing from a temporary ASTContext
131 // that also has another ExternalASTMerger attached. It could be
132 // possible that the current ExternalASTMerger and the temporary ASTContext
133 // share a common ImporterSource, which means that the temporary
134 // AST could contain declarations that were imported from a source
135 // that this ExternalASTMerger can access directly. Instead of importing
136 // such declarations from the temporary ASTContext, they should instead
137 // be directly imported by this ExternalASTMerger from the original
138 // source. This way the ExternalASTMerger can safely do a minimal import
139 // without creating incomplete declarations originated from a temporary
140 // ASTContext. If we would try to complete such declarations later on, we
141 // would fail to do so as their temporary AST could be deleted (which means
142 // that the missing parts of the minimally imported declaration in that
143 // ASTContext were also deleted).
144 //
145 // The following code tracks back any declaration that needs to be
146 // imported from the temporary ASTContext to a persistent ASTContext.
147 // Then the ExternalASTMerger tries to import from the persistent
148 // ASTContext directly by using the associated ASTImporter. If that
149 // succeeds, this ASTImporter just maps the declarations imported by
150 // the other (persistent) ASTImporter to this (temporary) ASTImporter.
151 // The steps can be visualized like this:
152 //
153 // Target AST <--- 3. Indirect import --- Persistent AST
154 // ^ of persistent decl ^
155 // | |
156 // 1. Current import 2. Tracking back to persistent decl
157 // 4. Map persistent decl |
158 // & pretend we imported. |
159 // | |
160 // Temporary AST -------------------------------'
161
162 // First, ask the ExternalASTMerger of the source where the temporary
163 // declaration originated from.
164 Decl *Persistent = SourceMerger->FindOriginalDecl(FromD);
165 // FromD isn't from a persistent AST, so just do a normal import.
166 if (!Persistent)
167 return ASTImporter::ImportImpl(FromD);
168 // Now ask the current ExternalASTMerger to try import the persistent
169 // declaration into the target.
170 ASTContext &PersistentCtx = Persistent->getASTContext();
171 ASTImporter &OtherImporter = Parent.ImporterForOrigin(PersistentCtx);
172 // Check that we never end up in the current Importer again.
173 assert((&PersistentCtx != &getFromContext()) && (&OtherImporter != this) &&
174 "Delegated to same Importer?");
175 auto DeclOrErr = OtherImporter.Import(Persistent);
176 // Errors when importing the persistent decl are treated as if we
177 // had errors with importing the temporary decl.
178 if (!DeclOrErr)
179 return DeclOrErr.takeError();
180 Decl *D = *DeclOrErr;
181 // Tell the current ASTImporter that this has already been imported
182 // to prevent any further queries for the temporary decl.
183 MapImported(FromD, D);
184 return D;
185 }
186
187 /// Implements the ASTImporter interface for tracking back a declaration
188 /// to its original declaration it came from.
189 Decl *GetOriginalDecl(Decl *To) override {
190 return ToOrigin.lookup(To);
191 }
192
193 /// Whenever a DeclContext is imported, ensure that ExternalASTSource's origin
194 /// map is kept up to date. Also set the appropriate flags.
195 void Imported(Decl *From, Decl *To) override {
196 ToOrigin[To] = From;
197
198 if (auto *ToDC = dyn_cast<DeclContext>(To)) {
199 const bool LoggingEnabled = Parent.LoggingEnabled();
200 if (LoggingEnabled)
201 logs() << "(ExternalASTMerger*)" << (void*)&Parent
202 << " imported (DeclContext*)" << (void*)ToDC
203 << ", (ASTContext*)" << (void*)&getToContext()
204 << " from (DeclContext*)" << (void*)llvm::cast<DeclContext>(From)
205 << ", (ASTContext*)" << (void*)&getFromContext()
206 << "\n";
207 Source<DeclContext *> FromDC(
208 cast<DeclContext>(From)->getPrimaryContext());
209 if (FromOrigins.count(FromDC) &&
210 Parent.HasImporterForOrigin(*FromOrigins.at(FromDC).AST)) {
211 if (LoggingEnabled)
212 logs() << "(ExternalASTMerger*)" << (void*)&Parent
213 << " forced origin (DeclContext*)"
214 << (void*)FromOrigins.at(FromDC).DC
215 << ", (ASTContext*)"
216 << (void*)FromOrigins.at(FromDC).AST
217 << "\n";
218 Parent.ForceRecordOrigin(ToDC, FromOrigins.at(FromDC));
219 } else {
220 if (LoggingEnabled)
221 logs() << "(ExternalASTMerger*)" << (void*)&Parent
222 << " maybe recording origin (DeclContext*)" << (void*)FromDC
223 << ", (ASTContext*)" << (void*)&getFromContext()
224 << "\n";
225 Parent.MaybeRecordOrigin(ToDC, {FromDC, &getFromContext()});
226 }
227 }
228 if (auto *ToTag = dyn_cast<TagDecl>(To)) {
229 ToTag->setHasExternalLexicalStorage();
230 ToTag->getPrimaryContext()->setMustBuildLookupTable();
231 assert(Parent.CanComplete(ToTag));
232 } else if (auto *ToNamespace = dyn_cast<NamespaceDecl>(To)) {
233 ToNamespace->setHasExternalVisibleStorage();
234 assert(Parent.CanComplete(ToNamespace));
235 } else if (auto *ToContainer = dyn_cast<ObjCContainerDecl>(To)) {
236 ToContainer->setHasExternalLexicalStorage();
237 ToContainer->getPrimaryContext()->setMustBuildLookupTable();
238 assert(Parent.CanComplete(ToContainer));
239 }
240 }
241 ASTImporter &GetReverse() { return Reverse; }
242};
243
244bool HasDeclOfSameType(llvm::ArrayRef<Candidate> Decls, const Candidate &C) {
245 if (isa<FunctionDecl>(C.first.get()))
246 return false;
247 return llvm::any_of(Decls, [&](const Candidate &D) {
248 return C.first.get()->getKind() == D.first.get()->getKind();
249 });
250}
251
252} // end namespace
253
255 for (const std::unique_ptr<ASTImporter> &I : Importers)
256 if (&I->getFromContext() == &OriginContext)
257 return *I;
258 llvm_unreachable("We should have an importer for this origin!");
259}
260
261namespace {
262LazyASTImporter &LazyImporterForOrigin(ExternalASTMerger &Merger,
263 ASTContext &OriginContext) {
264 return static_cast<LazyASTImporter &>(
265 Merger.ImporterForOrigin(OriginContext));
266}
267}
268
270 for (const std::unique_ptr<ASTImporter> &I : Importers)
271 if (&I->getFromContext() == &OriginContext)
272 return true;
273 return false;
274}
275
276template <typename CallbackType>
277void ExternalASTMerger::ForEachMatchingDC(const DeclContext *DC,
278 CallbackType Callback) {
279 if (Origins.count(DC)) {
280 ExternalASTMerger::DCOrigin Origin = Origins[DC];
281 LazyASTImporter &Importer = LazyImporterForOrigin(*this, *Origin.AST);
282 Callback(Importer, Importer.GetReverse(), Origin.DC);
283 } else {
284 bool DidCallback = false;
285 for (const std::unique_ptr<ASTImporter> &Importer : Importers) {
286 Source<TranslationUnitDecl *> SourceTU =
287 Importer->getFromContext().getTranslationUnitDecl();
288 ASTImporter &Reverse =
289 static_cast<LazyASTImporter *>(Importer.get())->GetReverse();
290 if (auto SourceDC = LookupSameContext(SourceTU, DC, Reverse)) {
291 DidCallback = true;
292 if (Callback(*Importer, Reverse, SourceDC))
293 break;
294 }
295 }
296 if (!DidCallback && LoggingEnabled())
297 logs() << "(ExternalASTMerger*)" << (void*)this
298 << " asserting for (DeclContext*)" << (const void*)DC
299 << ", (ASTContext*)" << (void*)&Target.AST
300 << "\n";
301 assert(DidCallback && "Couldn't find a source context matching our DC");
302 }
303}
304
306 assert(Tag->hasExternalLexicalStorage());
307 ForEachMatchingDC(Tag, [&](ASTImporter &Forward, ASTImporter &Reverse,
308 Source<const DeclContext *> SourceDC) -> bool {
309 auto *SourceTag = const_cast<TagDecl *>(cast<TagDecl>(SourceDC.get()));
310 if (SourceTag->hasExternalLexicalStorage())
311 SourceTag->getASTContext().getExternalSource()->CompleteType(SourceTag);
312 if (!SourceTag->getDefinition())
313 return false;
314 Forward.MapImported(SourceTag, Tag);
315 if (llvm::Error Err = Forward.ImportDefinition(SourceTag))
316 llvm::consumeError(std::move(Err));
317 Tag->setCompleteDefinition(SourceTag->isCompleteDefinition());
318 return true;
319 });
320}
321
323 assert(Interface->hasExternalLexicalStorage());
324 ForEachMatchingDC(
325 Interface, [&](ASTImporter &Forward, ASTImporter &Reverse,
326 Source<const DeclContext *> SourceDC) -> bool {
327 auto *SourceInterface = const_cast<ObjCInterfaceDecl *>(
328 cast<ObjCInterfaceDecl>(SourceDC.get()));
329 if (SourceInterface->hasExternalLexicalStorage())
330 SourceInterface->getASTContext().getExternalSource()->CompleteType(
331 SourceInterface);
332 if (!SourceInterface->getDefinition())
333 return false;
334 Forward.MapImported(SourceInterface, Interface);
335 if (llvm::Error Err = Forward.ImportDefinition(SourceInterface))
336 llvm::consumeError(std::move(Err));
337 return true;
338 });
339}
340
342 assert(Interface->hasExternalLexicalStorage() ||
343 Interface->hasExternalVisibleStorage());
344 bool FoundMatchingDC = false;
345 ForEachMatchingDC(Interface,
346 [&](ASTImporter &Forward, ASTImporter &Reverse,
347 Source<const DeclContext *> SourceDC) -> bool {
348 FoundMatchingDC = true;
349 return true;
350 });
351 return FoundMatchingDC;
352}
353
354namespace {
355bool IsSameDC(const DeclContext *D1, const DeclContext *D2) {
356 if (isa<ObjCContainerDecl>(D1) && isa<ObjCContainerDecl>(D2))
357 return true; // There are many cases where Objective-C is ambiguous.
358 if (auto *T1 = dyn_cast<TagDecl>(D1))
359 if (auto *T2 = dyn_cast<TagDecl>(D2))
360 if (T1->getFirstDecl() == T2->getFirstDecl())
361 return true;
362 return D1 == D2 || D1 == CanonicalizeDC(D2);
363}
364}
365
367 DCOrigin Origin) {
368 LazyASTImporter &Importer = LazyImporterForOrigin(*this, *Origin.AST);
369 ASTImporter &Reverse = Importer.GetReverse();
370 Source<const DeclContext *> FoundFromDC =
371 LookupSameContext(Origin.AST->getTranslationUnitDecl(), ToDC, Reverse);
372 const bool DoRecord = !FoundFromDC || !IsSameDC(FoundFromDC.get(), Origin.DC);
373 if (DoRecord)
374 RecordOriginImpl(ToDC, Origin, Importer);
375 if (LoggingEnabled())
376 logs() << "(ExternalASTMerger*)" << (void*)this
377 << (DoRecord ? " decided " : " decided NOT")
378 << " to record origin (DeclContext*)" << (void*)Origin.DC
379 << ", (ASTContext*)" << (void*)&Origin.AST
380 << "\n";
381}
382
384 DCOrigin Origin) {
385 RecordOriginImpl(ToDC, Origin, ImporterForOrigin(*Origin.AST));
386}
387
388void ExternalASTMerger::RecordOriginImpl(const DeclContext *ToDC, DCOrigin Origin,
389 ASTImporter &Importer) {
390 Origins[ToDC] = Origin;
391 Importer.ASTImporter::MapImported(cast<Decl>(Origin.DC), const_cast<Decl*>(cast<Decl>(ToDC)));
392}
393
395 llvm::ArrayRef<ImporterSource> Sources) : LogStream(&llvm::nulls()), Target(Target) {
396 SharedState = std::make_shared<ASTImporterSharedState>(
397 *Target.AST.getTranslationUnitDecl());
398 AddSources(Sources);
399}
400
402 assert(&D->getASTContext() == &Target.AST);
403 for (const auto &I : Importers)
404 if (auto Result = I->GetOriginalDecl(D))
405 return Result;
406 return nullptr;
407}
408
410 for (const ImporterSource &S : Sources) {
411 assert(&S.getASTContext() != &Target.AST);
412 // Check that the associated merger actually imports into the source AST.
413 assert(!S.getMerger() || &S.getMerger()->Target.AST == &S.getASTContext());
414 Importers.push_back(std::make_unique<LazyASTImporter>(
415 *this, Target.AST, Target.FM, S, SharedState));
416 }
417}
418
420 if (LoggingEnabled())
421 for (const ImporterSource &S : Sources)
422 logs() << "(ExternalASTMerger*)" << (void *)this
423 << " removing source (ASTContext*)" << (void *)&S.getASTContext()
424 << "\n";
425 llvm::erase_if(Importers,
426 [&Sources](std::unique_ptr<ASTImporter> &Importer) -> bool {
427 for (const ImporterSource &S : Sources) {
428 if (&Importer->getFromContext() == &S.getASTContext())
429 return true;
430 }
431 return false;
432 });
433 for (OriginMap::iterator OI = Origins.begin(), OE = Origins.end(); OI != OE; ) {
434 std::pair<const DeclContext *, DCOrigin> Origin = *OI;
435 bool Erase = false;
436 for (const ImporterSource &S : Sources) {
437 if (&S.getASTContext() == Origin.second.AST) {
438 Erase = true;
439 break;
440 }
441 }
442 if (Erase)
443 OI = Origins.erase(OI);
444 else
445 ++OI;
446 }
447}
448
449template <typename DeclTy>
450static bool importSpecializations(DeclTy *D, ASTImporter *Importer) {
451 for (auto *Spec : D->specializations()) {
452 auto ImportedSpecOrError = Importer->Import(Spec);
453 if (!ImportedSpecOrError) {
454 llvm::consumeError(ImportedSpecOrError.takeError());
455 return true;
456 }
457 }
458 return false;
459}
460
461/// Imports specializations from template declarations that can be specialized.
463 if (!isa<TemplateDecl>(D))
464 return false;
465 if (auto *FunctionTD = dyn_cast<FunctionTemplateDecl>(D))
466 return importSpecializations(FunctionTD, Importer);
467 else if (auto *ClassTD = dyn_cast<ClassTemplateDecl>(D))
468 return importSpecializations(ClassTD, Importer);
469 else if (auto *VarTD = dyn_cast<VarTemplateDecl>(D))
470 return importSpecializations(VarTD, Importer);
471 return false;
472}
473
475 DeclarationName Name) {
478
479 auto FilterFoundDecl = [&Candidates](const Candidate &C) {
480 if (!HasDeclOfSameType(Candidates, C))
481 Candidates.push_back(C);
482 };
483
484 ForEachMatchingDC(DC,
485 [&](ASTImporter &Forward, ASTImporter &Reverse,
486 Source<const DeclContext *> SourceDC) -> bool {
487 auto FromNameOrErr = Reverse.Import(Name);
488 if (!FromNameOrErr) {
489 llvm::consumeError(FromNameOrErr.takeError());
490 return false;
491 }
493 SourceDC.get()->lookup(*FromNameOrErr);
494 for (NamedDecl *FromD : Result) {
495 FilterFoundDecl(std::make_pair(FromD, &Forward));
496 }
497 return false;
498 });
499
500 if (Candidates.empty())
501 return false;
502
503 Decls.reserve(Candidates.size());
504 for (const Candidate &C : Candidates) {
505 Decl *LookupRes = C.first.get();
506 ASTImporter *Importer = C.second;
507 auto NDOrErr = Importer->Import(LookupRes);
508 NamedDecl *ND = cast<NamedDecl>(llvm::cantFail(std::move(NDOrErr)));
509 assert(ND);
510 // If we don't import specialization, they are not available via lookup
511 // because the lookup result is imported TemplateDecl and it does not
512 // reference its specializations until they are imported explicitly.
513 bool IsSpecImportFailed =
514 importSpecializationsIfNeeded(LookupRes, Importer);
515 assert(!IsSpecImportFailed);
516 (void)IsSpecImportFailed;
517 Decls.push_back(ND);
518 }
519 SetExternalVisibleDeclsForName(DC, Name, Decls);
520 return true;
521}
522
524 const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
526 ForEachMatchingDC(DC, [&](ASTImporter &Forward, ASTImporter &Reverse,
527 Source<const DeclContext *> SourceDC) -> bool {
528 for (const Decl *SourceDecl : SourceDC.get()->decls()) {
529 if (IsKindWeWant(SourceDecl->getKind())) {
530 auto ImportedDeclOrErr = Forward.Import(SourceDecl);
531 if (ImportedDeclOrErr)
532 assert(!(*ImportedDeclOrErr) ||
533 IsSameDC((*ImportedDeclOrErr)->getDeclContext(), DC));
534 else
535 llvm::consumeError(ImportedDeclOrErr.takeError());
536 }
537 }
538 return false;
539 });
540}
Defines the clang::ASTContext interface.
NodeId Parent
Definition: ASTDiff.cpp:191
const Decl * D
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:1171
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
static bool importSpecializations(DeclTy *D, ASTImporter *Importer)
static bool importSpecializationsIfNeeded(Decl *D, ASTImporter *Importer)
Imports specializations from template declarations that can be specialized.
llvm::MachO::Target Target
Definition: MachO.h:51
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:187
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1101
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
Definition: ASTContext.h:1227
Imports selected nodes from one AST context into another context, merging AST nodes where appropriate...
Definition: ASTImporter.h:62
ASTContext & getFromContext() const
Retrieve the context that AST nodes are being imported from.
Definition: ASTImporter.h:522
ASTContext & getToContext() const
Retrieve the context that AST nodes are being imported into.
Definition: ASTImporter.h:519
Decl * MapImported(Decl *From, Decl *To)
Store and assign the imported declaration to its counterpart.
llvm::Error ImportDefinition(Decl *From)
Import the definition of the given declaration, including all of the declarations it contains.
virtual Decl * GetOriginalDecl(Decl *To)
Called by StructuralEquivalenceContext.
Definition: ASTImporter.h:562
virtual void Imported(Decl *From, Decl *To)
Subclasses can override this function to observe all of the From -> To declaration mappings as they a...
Definition: ASTImporter.h:547
virtual Expected< Decl * > ImportImpl(Decl *From)
Can be overwritten by subclasses to implement their own import logic.
llvm::Expected< ExprWithCleanups::CleanupObject > Import(ExprWithCleanups::CleanupObject From)
Import cleanup objects owned by ExprWithCleanup.
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1369
reference front() const
Definition: DeclBase.h:1392
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1436
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:2090
bool isTranslationUnit() const
Definition: DeclBase.h:2166
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:1988
Decl::Kind getDeclKind() const
Definition: DeclBase.h:2083
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:523
Kind
Lists the kind of concrete classes of Decl.
Definition: DeclBase.h:89
Kind getKind() const
Definition: DeclBase.h:449
The name of a declaration.
A source for an ExternalASTMerger.
ExternalASTSource implementation that merges information from several ASTContexts.
llvm::raw_ostream & logs()
Log something if there is a logging callback installed.
void AddSources(llvm::ArrayRef< ImporterSource > Sources)
Add a set of ASTContexts as possible origins.
bool FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name) override
Implementation of the ExternalASTSource API.
ASTImporter & ImporterForOrigin(ASTContext &OriginContext)
Returns a reference to the ASTImporter from Importers whose origin is OriginContext.
Decl * FindOriginalDecl(Decl *D)
Asks all connected ASTImporters if any of them imported the given declaration.
void CompleteType(TagDecl *Tag) override
Implementation of the ExternalASTSource API.
void MaybeRecordOrigin(const DeclContext *ToDC, DCOrigin Origin)
Records an origin in Origins only if name lookup would find something different or nothing at all.
void RemoveSources(llvm::ArrayRef< ImporterSource > Sources)
Remove a set of ASTContexts as possible origins.
std::map< const DeclContext *, DCOrigin > OriginMap
void ForceRecordOrigin(const DeclContext *ToDC, DCOrigin Origin)
Regardless of any checks, override the Origin for a DeclContext.
ExternalASTMerger(const ImporterTarget &Target, llvm::ArrayRef< ImporterSource > Sources)
bool CanComplete(DeclContext *DC)
Returns true if DC can be found in any source AST context.
bool LoggingEnabled()
True if the log stream is not llvm::nulls();.
bool HasImporterForOrigin(ASTContext &OriginContext)
Returns true if Importers contains an ASTImporter whose source is OriginContext.
void FindExternalLexicalDecls(const DeclContext *DC, llvm::function_ref< bool(Decl::Kind)> IsKindWeWant, SmallVectorImpl< Decl * > &Result) override
Implementation of the ExternalASTSource API.
static DeclContextLookupResult SetExternalVisibleDeclsForName(const DeclContext *DC, DeclarationName Name, ArrayRef< NamedDecl * > Decls)
Definition: DeclBase.cpp:1607
virtual void CompleteType(TagDecl *Tag)
Gives the external AST source an opportunity to complete an incomplete type.
Implements support for file system lookup, file system caching, and directory search management.
Definition: FileManager.h:53
This represents a decl that may have a name.
Definition: Decl.h:249
Represents an ObjC class declaration.
Definition: DeclObjC.h:1153
ASTContext & getASTContext() const
Definition: Sema.h:602
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3561
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
const FunctionProtoType * T
@ Interface
The "__interface" keyword introduces the elaborated-type-specifier.
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30
#define true
Definition: stdbool.h:25
A single origin for a DeclContext.
The target for an ExternalASTMerger.