clang 24.0.0git
DeclBase.cpp
Go to the documentation of this file.
1//===- DeclBase.cpp - Declaration AST Node Implementation -----------------===//
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 Decl and DeclContext classes.
10//
11//===----------------------------------------------------------------------===//
12
13#include "clang/AST/DeclBase.h"
15#include "clang/AST/ASTLambda.h"
17#include "clang/AST/Attr.h"
19#include "clang/AST/Decl.h"
20#include "clang/AST/DeclCXX.h"
23#include "clang/AST/DeclObjC.h"
29#include "clang/AST/Stmt.h"
30#include "clang/AST/Type.h"
32#include "clang/Basic/LLVM.h"
33#include "clang/Basic/Module.h"
38#include "llvm/ADT/PointerIntPair.h"
39#include "llvm/ADT/StringRef.h"
40#include "llvm/Support/ErrorHandling.h"
41#include "llvm/Support/MathExtras.h"
42#include "llvm/Support/VersionTuple.h"
43#include "llvm/Support/raw_ostream.h"
44#include <algorithm>
45#include <cassert>
46#include <cstddef>
47#include <string>
48#include <tuple>
49#include <utility>
50
51using namespace clang;
52
53//===----------------------------------------------------------------------===//
54// Statistics
55//===----------------------------------------------------------------------===//
56
57#define DECL(DERIVED, BASE) static int n##DERIVED##s = 0;
58#define ABSTRACT_DECL(DECL)
59#include "clang/AST/DeclNodes.inc"
60
61#define DECL(DERIVED, BASE) \
62 static_assert(alignof(Decl) >= alignof(DERIVED##Decl), \
63 "Alignment sufficient after objects prepended to " #DERIVED);
64#define ABSTRACT_DECL(DECL)
65#include "clang/AST/DeclNodes.inc"
66
67void *Decl::operator new(std::size_t Size, const ASTContext &Context,
68 GlobalDeclID ID, std::size_t Extra) {
69 // Allocate an extra 8 bytes worth of storage, which ensures that the
70 // resulting pointer will still be 8-byte aligned.
71 static_assert(sizeof(uint64_t) >= alignof(Decl), "Decl won't be misaligned");
72 void *Start = Context.Allocate(Size + Extra + 8);
73 void *Result = (char*)Start + 8;
74
75 uint64_t *PrefixPtr = (uint64_t *)Result - 1;
76
77 *PrefixPtr = ID.getRawValue();
78
79 // We leave the upper 16 bits to store the module IDs. 48 bits should be
80 // sufficient to store a declaration ID. See the comments in setOwningModuleID
81 // for details.
82 assert((*PrefixPtr < llvm::maskTrailingOnes<uint64_t>(48)) &&
83 "Current Implementation limits the number of module files to not "
84 "exceed 2^16. Contact Clang Developers to remove the limitation.");
85
86 return Result;
87}
88
89void *Decl::operator new(std::size_t Size, const ASTContext &Ctx,
90 DeclContext *Parent, std::size_t Extra) {
91 assert(!Parent || &Parent->getParentASTContext() == &Ctx);
92 // With local visibility enabled, we track the owning module even for local
93 // declarations. We create the TU decl early and may not yet know what the
94 // LangOpts are, so conservatively allocate the storage.
95 if (Ctx.getLangOpts().trackLocalOwningModule() || !Parent) {
96 // Ensure required alignment of the resulting object by adding extra
97 // padding at the start if required.
98 size_t ExtraAlign =
99 llvm::offsetToAlignment(sizeof(Module *), llvm::Align(alignof(Decl)));
100 auto *Buffer = reinterpret_cast<char *>(
101 ::operator new(ExtraAlign + sizeof(Module *) + Size + Extra, Ctx));
102 Buffer += ExtraAlign;
103 auto *ParentModule =
104 Parent ? cast<Decl>(Parent)->getOwningModule() : nullptr;
105 return new (Buffer) Module*(ParentModule) + 1;
106 }
107 return ::operator new(Size + Extra, Ctx);
108}
109
111 if (!isFromASTFile())
112 return GlobalDeclID();
113 // See the comments in `Decl::operator new` for details.
114 uint64_t ID = *((const uint64_t *)this - 1);
115 return GlobalDeclID(ID & llvm::maskTrailingOnes<uint64_t>(48));
116}
117
118unsigned Decl::getOwningModuleID() const {
119 if (!isFromASTFile())
120 return 0;
121
122 uint64_t ID = *((const uint64_t *)this - 1);
123 return ID >> 48;
124}
125
126void Decl::setOwningModuleID(unsigned ID) {
127 assert(isFromASTFile() && "Only works on a deserialized declaration");
128 // Currently, we use 64 bits to store the GlobalDeclID and the module ID
129 // to save the space. See `Decl::operator new` for details. To make it,
130 // we split the higher 32 bits to 2 16bits for the module file index of
131 // GlobalDeclID and the module ID. This introduces a limitation that the
132 // number of modules can't exceed 2^16. (The number of module files should be
133 // less than the number of modules).
134 //
135 // It is counter-intuitive to store both the module file index and the
136 // module ID as it seems redundant. However, this is not true.
137 // The module ID may be different from the module file where it is serialized
138 // from for implicit template instantiations. See
139 // https://github.com/llvm/llvm-project/issues/101939
140 //
141 // If we reach the limitation, we have to remove the limitation by asking
142 // every deserialized declaration to pay for yet another 32 bits, or we have
143 // to review the above issue to decide what we should do for it.
144 assert((ID < llvm::maskTrailingOnes<unsigned>(16)) &&
145 "Current Implementation limits the number of modules to not exceed "
146 "2^16. Contact Clang Developers to remove the limitation.");
147 uint64_t *IDAddress = (uint64_t *)this - 1;
148 *IDAddress &= llvm::maskTrailingOnes<uint64_t>(48);
149 *IDAddress |= (uint64_t)ID << 48;
150}
151
153 if (getOwningModule() &&
154 getOwningModule()->getTopLevelModule()->isNamedModule())
156
157 return nullptr;
158}
159
160Module *Decl::getOwningModuleSlow() const {
161 assert(isFromASTFile() && "Not from AST file?");
163}
164
168
169const char *Decl::getDeclKindName() const {
170 switch (DeclKind) {
171 default: llvm_unreachable("Declaration not in DeclNodes.inc!");
172#define DECL(DERIVED, BASE) case DERIVED: return #DERIVED;
173#define ABSTRACT_DECL(DECL)
174#include "clang/AST/DeclNodes.inc"
175 }
176}
177
179 InvalidDecl = Invalid;
180 assert(!isa<TagDecl>(this) || !cast<TagDecl>(this)->isCompleteDefinition());
181 if (!Invalid) {
182 return;
183 }
184
185 if (!isa<ParmVarDecl>(this)) {
186 // Defensive maneuver for ill-formed code: we're likely not to make it to
187 // a point where we set the access specifier, so default it to "public"
188 // to avoid triggering asserts elsewhere in the front end.
190 }
191
192 // Marking a DecompositionDecl as invalid implies all the child BindingDecl's
193 // are invalid too.
194 if (auto *DD = dyn_cast<DecompositionDecl>(this)) {
195 for (auto *Binding : DD->bindings()) {
196 Binding->setInvalidDecl();
197 }
198 }
199}
200
202 switch (getDeclKind()) {
203#define DECL(DERIVED, BASE) case Decl::DERIVED: return true;
204#define ABSTRACT_DECL(DECL)
205#include "clang/AST/DeclNodes.inc"
206 }
207 return false;
208}
209
210const char *DeclContext::getDeclKindName() const {
211 switch (getDeclKind()) {
212#define DECL(DERIVED, BASE) case Decl::DERIVED: return #DERIVED;
213#define ABSTRACT_DECL(DECL)
214#include "clang/AST/DeclNodes.inc"
215 }
216 llvm_unreachable("Declaration context not in DeclNodes.inc!");
217}
218
219bool Decl::StatisticsEnabled = false;
221 StatisticsEnabled = true;
222}
223
225 llvm::errs() << "\n*** Decl Stats:\n";
226
227 int totalDecls = 0;
228#define DECL(DERIVED, BASE) totalDecls += n##DERIVED##s;
229#define ABSTRACT_DECL(DECL)
230#include "clang/AST/DeclNodes.inc"
231 llvm::errs() << " " << totalDecls << " decls total.\n";
232
233 int totalBytes = 0;
234#define DECL(DERIVED, BASE) \
235 if (n##DERIVED##s > 0) { \
236 totalBytes += (int)(n##DERIVED##s * sizeof(DERIVED##Decl)); \
237 llvm::errs() << " " << n##DERIVED##s << " " #DERIVED " decls, " \
238 << sizeof(DERIVED##Decl) << " each (" \
239 << n##DERIVED##s * sizeof(DERIVED##Decl) \
240 << " bytes)\n"; \
241 }
242#define ABSTRACT_DECL(DECL)
243#include "clang/AST/DeclNodes.inc"
244
245 llvm::errs() << "Total bytes = " << totalBytes << "\n";
246}
247
249 switch (k) {
250#define DECL(DERIVED, BASE) case DERIVED: ++n##DERIVED##s; break;
251#define ABSTRACT_DECL(DECL)
252#include "clang/AST/DeclNodes.inc"
253 }
254}
255
257 if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(this))
258 return TTP->isParameterPack();
259 if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(this))
260 return NTTP->isParameterPack();
261 if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(this))
262 return TTP->isParameterPack();
263 return false;
264}
265
267 if (const auto *Var = dyn_cast<ValueDecl>(this))
268 return Var->isParameterPack();
269
271}
272
274 if (auto *FD = dyn_cast<FunctionDecl>(this))
275 return FD;
276 if (const auto *FTD = dyn_cast<FunctionTemplateDecl>(this))
277 return FTD->getTemplatedDecl();
278 return nullptr;
279}
280
282 return isa<TemplateDecl>(this);
283}
284
286 if (auto *FD = dyn_cast<FunctionDecl>(this))
287 return FD->getDescribedFunctionTemplate();
288 if (auto *RD = dyn_cast<CXXRecordDecl>(this))
289 return RD->getDescribedClassTemplate();
290 if (auto *VD = dyn_cast<VarDecl>(this))
291 return VD->getDescribedVarTemplate();
292 if (auto *AD = dyn_cast<TypeAliasDecl>(this))
293 return AD->getDescribedAliasTemplate();
294
295 return nullptr;
296}
297
299 if (auto *TD = getDescribedTemplate())
300 return TD->getTemplateParameters();
301 if (auto *CTPSD = dyn_cast<ClassTemplatePartialSpecializationDecl>(this))
302 return CTPSD->getTemplateParameters();
303 if (auto *VTPSD = dyn_cast<VarTemplatePartialSpecializationDecl>(this))
304 return VTPSD->getTemplateParameters();
305 return nullptr;
306}
307
308bool Decl::isTemplated() const {
309 // A declaration is templated if it is a template or a template pattern, or
310 // is within (lexcially for a friend or local function declaration,
311 // semantically otherwise) a dependent context.
312 if (auto *AsDC = dyn_cast<DeclContext>(this))
313 return AsDC->isDependentContext();
314 auto *DC = getFriendObjectKind() || isLocalExternDecl()
316 return DC->isDependentContext() || isTemplateDecl() ||
318}
319
320unsigned Decl::getTemplateDepth() const {
321 if (auto *DC = dyn_cast<DeclContext>(this))
322 if (DC->isFileContext())
323 return 0;
324
325 if (auto *TPL = getDescribedTemplateParams())
326 return TPL->getDepth() + 1;
327
328 if (auto *ESD = dyn_cast<CXXExpansionStmtDecl>(this))
329 return ESD->getIndexTemplateParm()->getDepth() + 1;
330
331 // If this is a dependent lambda, there might be an enclosing variable
332 // template. In this case, the next step is not the parent DeclContext (or
333 // even a DeclContext at all).
334 auto *RD = dyn_cast<CXXRecordDecl>(this);
335 if (RD && RD->isDependentLambda())
336 if (Decl *Context = RD->getLambdaContextDecl())
337 return Context->getTemplateDepth();
338
339 const DeclContext *DC =
341 return cast<Decl>(DC)->getTemplateDepth();
342}
343
344const DeclContext *Decl::getParentFunctionOrMethod(bool LexicalParent) const {
345 for (const DeclContext *DC = LexicalParent ? getLexicalDeclContext()
346 : getDeclContext();
347 DC && !DC->isFileContext(); DC = DC->getParent())
348 if (DC->isFunctionOrMethod())
349 return DC;
350
351 return nullptr;
352}
353
354//===----------------------------------------------------------------------===//
355// PrettyStackTraceDecl Implementation
356//===----------------------------------------------------------------------===//
357
358void PrettyStackTraceDecl::print(raw_ostream &OS) const {
359 SourceLocation TheLoc = Loc;
360 if (TheLoc.isInvalid() && TheDecl)
361 TheLoc = TheDecl->getLocation();
362
363 if (TheLoc.isValid()) {
364 TheLoc.print(OS, SM);
365 OS << ": ";
366 }
367
368 OS << Message;
369
370 if (const auto *DN = dyn_cast_or_null<NamedDecl>(TheDecl)) {
371 OS << " '";
372 DN->printQualifiedName(OS);
373 OS << '\'';
374 }
375 OS << '\n';
376}
377
378//===----------------------------------------------------------------------===//
379// Decl Implementation
380//===----------------------------------------------------------------------===//
381
382// Out-of-line virtual method providing a home for Decl.
383Decl::~Decl() = default;
384
386 DeclCtx = DC;
387}
388
390 if (DC == getLexicalDeclContext())
391 return;
392
393 if (isInSemaDC()) {
394 setDeclContextsImpl(getDeclContext(), DC, getASTContext());
395 } else {
396 getMultipleDC()->LexicalDC = DC;
397 }
398
399 // FIXME: We shouldn't be changing the lexical context of declarations
400 // imported from AST files.
401 if (!isFromASTFile()) {
402 setModuleOwnershipKind(getModuleOwnershipKindForChildOf(DC));
403 if (hasOwningModule())
405 }
406
407 assert(
410 getOwningModule()) &&
411 "hidden declaration has no owning module");
412}
413
414void Decl::setDeclContextsImpl(DeclContext *SemaDC, DeclContext *LexicalDC,
415 ASTContext &Ctx) {
416 if (SemaDC == LexicalDC) {
417 DeclCtx = SemaDC;
418 } else {
419 auto *MDC = new (Ctx) Decl::MultipleDC();
420 MDC->SemanticDC = SemaDC;
421 MDC->LexicalDC = LexicalDC;
422 DeclCtx = MDC;
423 }
424}
425
427 const DeclContext *LDC = getLexicalDeclContext();
428 if (!LDC->isDependentContext())
429 return false;
430 while (true) {
431 if (LDC->isFunctionOrMethod())
432 return true;
433 if (!isa<TagDecl>(LDC))
434 return false;
435 if (const auto *CRD = dyn_cast<CXXRecordDecl>(LDC))
436 if (CRD->isLambda())
437 return true;
438 LDC = LDC->getLexicalParent();
439 }
440 return false;
441}
442
444 for (const DeclContext *DC = getDeclContext(); DC; DC = DC->getParent()) {
445 if (const auto *ND = dyn_cast<NamespaceDecl>(DC))
446 if (ND->isAnonymousNamespace())
447 return true;
448 }
449
450 return false;
451}
452
454 const DeclContext *DC = getDeclContext();
455 return DC && DC->getNonTransparentContext()->isStdNamespace();
456}
457
459 const auto *DC = dyn_cast<DeclContext>(this);
460 return DC && DC->isFileContext();
461}
462
464 const ASTContext &Ctx, const Decl *D, QualType Ty,
465 LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel,
466 bool IgnoreTemplateOrMacroSubstitution) {
467 // For compatibility with existing code, we treat arrays of length 0 or
468 // 1 as flexible array members.
469 const auto *CAT = Ctx.getAsConstantArrayType(Ty);
470 if (CAT) {
472
473 llvm::APInt Size = CAT->getSize();
474 if (StrictFlexArraysLevel == FAMKind::IncompleteOnly)
475 return false;
476
477 // GCC extension, only allowed to represent a FAM.
478 if (Size.isZero())
479 return true;
480
481 if (StrictFlexArraysLevel == FAMKind::ZeroOrIncomplete && Size.uge(1))
482 return false;
483
484 if (StrictFlexArraysLevel == FAMKind::OneZeroOrIncomplete && Size.uge(2))
485 return false;
486 } else if (!Ctx.getAsIncompleteArrayType(Ty)) {
487 return false;
488 }
489
490 if (const auto *OID = dyn_cast_if_present<ObjCIvarDecl>(D))
491 return OID->getNextIvar() == nullptr;
492
493 const auto *FD = dyn_cast_if_present<FieldDecl>(D);
494 if (!FD)
495 return false;
496
497 if (CAT) {
498 // GCC treats an array memeber of a union as an FAM if the size is one or
499 // zero.
500 llvm::APInt Size = CAT->getSize();
501 if (FD->getParent()->isUnion() && (Size.isZero() || Size.isOne()))
502 return true;
503 }
504
505 // Don't consider sizes resulting from macro expansions or template argument
506 // substitution to form C89 tail-padded arrays.
507 if (IgnoreTemplateOrMacroSubstitution) {
508 TypeSourceInfo *TInfo = FD->getTypeSourceInfo();
509 while (TInfo) {
510 TypeLoc TL = TInfo->getTypeLoc();
511
512 // Look through typedefs.
514 TInfo = TTL.getDecl()->getTypeSourceInfo();
515 continue;
516 }
517
518 if (auto CTL = TL.getAs<ConstantArrayTypeLoc>()) {
519 if (const Expr *SizeExpr =
520 dyn_cast_if_present<IntegerLiteral>(CTL.getSizeExpr());
521 !SizeExpr || SizeExpr->getExprLoc().isMacroID())
522 return false;
523 }
524
525 break;
526 }
527 }
528
529 // Test that the field is the last in the structure.
531 DeclContext::decl_iterator(const_cast<FieldDecl *>(FD)));
532 return ++FI == FD->getParent()->field_end();
533}
534
536 if (auto *TUD = dyn_cast<TranslationUnitDecl>(this))
537 return TUD;
538
540 assert(DC && "This decl is not contained in a translation unit!");
541
542 while (!DC->isTranslationUnit()) {
543 DC = DC->getParent();
544 assert(DC && "This decl is not contained in a translation unit!");
545 }
546
547 return cast<TranslationUnitDecl>(DC);
548}
549
553
554/// Helper to get the language options from the ASTContext.
555/// Defined out of line to avoid depending on ASTContext.h.
557 return getASTContext().getLangOpts();
558}
559
563
564unsigned Decl::getMaxAlignment() const {
565 if (!hasAttrs())
566 return 0;
567
568 unsigned Align = 0;
569 const AttrVec &V = getAttrs();
570 ASTContext &Ctx = getASTContext();
571 specific_attr_iterator<AlignedAttr> I(V.begin()), E(V.end());
572 for (; I != E; ++I) {
573 if (!I->isAlignmentErrorDependent())
574 Align = std::max(Align, I->getAlignment(Ctx));
575 }
576 return Align;
577}
578
579bool Decl::isUsed(bool CheckUsedAttr) const {
580 const Decl *CanonD = getCanonicalDecl();
581 if (CanonD->Used)
582 return true;
583
584 // Check for used attribute.
585 // Ask the most recent decl, since attributes accumulate in the redecl chain.
586 if (CheckUsedAttr && getMostRecentDecl()->hasAttr<UsedAttr>())
587 return true;
588
589 // The information may have not been deserialized yet. Force deserialization
590 // to complete the needed information.
591 return getMostRecentDecl()->getCanonicalDecl()->Used;
592}
593
595 if (isUsed(false))
596 return;
597
598 if (C.getASTMutationListener())
599 C.getASTMutationListener()->DeclarationMarkedUsed(this);
600
601 setIsUsed();
602}
603
604bool Decl::isReferenced() const {
605 if (Referenced)
606 return true;
607
608 // Check redeclarations.
609 for (const auto *I : redecls())
610 if (I->Referenced)
611 return true;
612
613 return false;
614}
615
616ExternalSourceSymbolAttr *Decl::getExternalSourceSymbolAttr() const {
617 const Decl *Definition = nullptr;
618 if (auto *ID = dyn_cast<ObjCInterfaceDecl>(this)) {
619 Definition = ID->getDefinition();
620 } else if (auto *PD = dyn_cast<ObjCProtocolDecl>(this)) {
621 Definition = PD->getDefinition();
622 } else if (auto *TD = dyn_cast<TagDecl>(this)) {
623 Definition = TD->getDefinition();
624 }
625 if (!Definition)
626 Definition = this;
627
628 if (auto *attr = Definition->getAttr<ExternalSourceSymbolAttr>())
629 return attr;
630 if (auto *dcd = dyn_cast<Decl>(getDeclContext())) {
631 return dcd->getAttr<ExternalSourceSymbolAttr>();
632 }
633
634 return nullptr;
635}
636
641
643 if (auto *AA = getAttr<AliasAttr>())
644 return AA;
645 if (auto *IFA = getAttr<IFuncAttr>())
646 return IFA;
647 if (auto *NZA = getAttr<LoaderUninitializedAttr>())
648 return NZA;
649 return nullptr;
650}
651
652static StringRef getRealizedPlatform(const AvailabilityAttr *A,
653 const ASTContext &Context) {
654 // Check if this is an App Extension "platform", and if so chop off
655 // the suffix for matching with the actual platform.
656 StringRef RealizedPlatform = A->getPlatform()->getName();
657 if (!Context.getLangOpts().AppExt)
658 return RealizedPlatform;
659 size_t suffix = RealizedPlatform.rfind("_app_extension");
660 if (suffix != StringRef::npos)
661 return RealizedPlatform.slice(0, suffix);
662 return RealizedPlatform;
663}
664
665/// Determine the availability of the given declaration based on
666/// the target platform.
667///
668/// When it returns an availability result other than \c AR_Available,
669/// if the \p Message parameter is non-NULL, it will be set to a
670/// string describing why the entity is unavailable.
671///
672/// FIXME: Make these strings localizable, since they end up in
673/// diagnostics.
675 const AvailabilityAttr *A,
676 std::string *Message,
677 VersionTuple EnclosingVersion) {
678 if (EnclosingVersion.empty())
679 EnclosingVersion = Context.getTargetInfo().getPlatformMinVersion();
680
681 if (EnclosingVersion.empty())
682 return AR_Available;
683
684 StringRef ActualPlatform = A->getPlatform()->getName();
685 StringRef TargetPlatform = Context.getTargetInfo().getPlatformName();
686
687 // Match the platform name.
688 if (getRealizedPlatform(A, Context) != TargetPlatform)
689 return AR_Available;
690
691 StringRef PrettyPlatformName
692 = AvailabilityAttr::getPrettyPlatformName(ActualPlatform);
693
694 if (PrettyPlatformName.empty())
695 PrettyPlatformName = ActualPlatform;
696
697 std::string HintMessage;
698 if (!A->getMessage().empty()) {
699 HintMessage = " - ";
700 HintMessage += A->getMessage();
701 }
702
703 // Make sure that this declaration has not been marked 'unavailable'.
704 if (A->getUnavailable()) {
705 if (Message) {
706 Message->clear();
707 llvm::raw_string_ostream Out(*Message);
708 Out << "not available on " << PrettyPlatformName
709 << HintMessage;
710 }
711
712 return AR_Unavailable;
713 }
714
715 // Make sure that this declaration has already been introduced.
716 if (!A->getIntroduced().empty() &&
717 EnclosingVersion < A->getIntroduced()) {
718 const IdentifierInfo *IIEnv = A->getEnvironment();
719 auto &Triple = Context.getTargetInfo().getTriple();
720 StringRef TargetEnv = Triple.getEnvironmentName();
721 StringRef EnvName =
722 llvm::Triple::getEnvironmentTypeName(Triple.getEnvironment());
723 // Matching environment or no environment on attribute.
724 if (!IIEnv || (Triple.hasEnvironment() && IIEnv->getName() == TargetEnv)) {
725 if (Message) {
726 Message->clear();
727 llvm::raw_string_ostream Out(*Message);
728 VersionTuple VTI(A->getIntroduced());
729 Out << "introduced in " << PrettyPlatformName << " " << VTI;
730 if (Triple.hasEnvironment())
731 Out << " " << EnvName;
732 Out << HintMessage;
733 }
734 }
735 // Non-matching environment or no environment on target.
736 else {
737 if (Message) {
738 Message->clear();
739 llvm::raw_string_ostream Out(*Message);
740 Out << "not available on " << PrettyPlatformName;
741 if (Triple.hasEnvironment())
742 Out << " " << EnvName;
743 Out << HintMessage;
744 }
745 }
746
747 return A->getStrict() ? AR_Unavailable : AR_NotYetIntroduced;
748 }
749
750 // Make sure that this declaration hasn't been obsoleted.
751 if (!A->getObsoleted().empty() && EnclosingVersion >= A->getObsoleted()) {
752 if (Message) {
753 Message->clear();
754 llvm::raw_string_ostream Out(*Message);
755 VersionTuple VTO(A->getObsoleted());
756 Out << "obsoleted in " << PrettyPlatformName << ' '
757 << VTO << HintMessage;
758 }
759
760 return AR_Unavailable;
761 }
762
763 // Make sure that this declaration hasn't been deprecated.
764 if (!A->getDeprecated().empty() && EnclosingVersion >= A->getDeprecated()) {
765 if (Message) {
766 Message->clear();
767 llvm::raw_string_ostream Out(*Message);
768 VersionTuple VTD(A->getDeprecated());
769 Out << "first deprecated in " << PrettyPlatformName << ' '
770 << VTD << HintMessage;
771 }
772
773 return AR_Deprecated;
774 }
775
776 return AR_Available;
777}
778
780 VersionTuple EnclosingVersion,
781 StringRef *RealizedPlatform) const {
782 if (auto *FTD = dyn_cast<FunctionTemplateDecl>(this))
783 return FTD->getTemplatedDecl()->getAvailability(Message, EnclosingVersion,
784 RealizedPlatform);
785
787 std::string ResultMessage;
788
789 for (const auto *A : attrs()) {
790 if (const auto *Deprecated = dyn_cast<DeprecatedAttr>(A)) {
791 if (Result >= AR_Deprecated)
792 continue;
793
794 if (Message)
795 ResultMessage = std::string(Deprecated->getMessage());
796
798 continue;
799 }
800
801 if (const auto *Unavailable = dyn_cast<UnavailableAttr>(A)) {
802 if (Message)
803 *Message = std::string(Unavailable->getMessage());
804 return AR_Unavailable;
805 }
806
807 if (const auto *Availability = dyn_cast<AvailabilityAttr>(A)) {
808 Availability = Availability->getEffectiveAttr();
810 Message, EnclosingVersion);
811
812 if (AR == AR_Unavailable) {
813 if (RealizedPlatform)
814 *RealizedPlatform = Availability->getPlatform()->getName();
815 return AR_Unavailable;
816 }
817
818 if (AR > Result) {
819 Result = AR;
820 if (Message)
821 ResultMessage.swap(*Message);
822 }
823 continue;
824 }
825 }
826
827 if (Message)
828 Message->swap(ResultMessage);
829 return Result;
830}
831
832VersionTuple Decl::getVersionIntroduced() const {
833 const ASTContext &Context = getASTContext();
834 StringRef TargetPlatform = Context.getTargetInfo().getPlatformName();
835 for (const auto *A : attrs()) {
836 if (const auto *Availability = dyn_cast<AvailabilityAttr>(A)) {
837 Availability = Availability->getEffectiveAttr();
838 if (getRealizedPlatform(Availability, Context) == TargetPlatform) {
839 if (!Availability->getIntroduced().empty())
840 return Availability->getIntroduced();
841 }
842 }
843 }
844 return {};
845}
846
847bool Decl::canBeWeakImported(bool &IsDefinition) const {
848 IsDefinition = false;
849
850 // Variables, if they aren't definitions.
851 if (const auto *Var = dyn_cast<VarDecl>(this)) {
852 if (Var->isThisDeclarationADefinition()) {
853 IsDefinition = true;
854 return false;
855 }
856 return true;
857 }
858 // Functions, if they aren't definitions.
859 if (const auto *FD = dyn_cast<FunctionDecl>(this)) {
860 if (FD->hasBody()) {
861 IsDefinition = true;
862 return false;
863 }
864 return true;
865
866 }
867 // Objective-C classes, if this is the non-fragile runtime.
868 if (isa<ObjCInterfaceDecl>(this) &&
870 return true;
871 }
872 // Nothing else.
873 return false;
874}
875
877 bool IsDefinition;
878 if (!canBeWeakImported(IsDefinition))
879 return false;
880
881 for (const auto *A : getMostRecentDecl()->attrs()) {
882 if (isa<WeakImportAttr>(A))
883 return true;
884
885 if (const auto *Availability = dyn_cast<AvailabilityAttr>(A)) {
886 Availability = Availability->getEffectiveAttr();
887 if (CheckAvailability(getASTContext(), Availability, nullptr,
888 VersionTuple()) == AR_NotYetIntroduced)
889 return true;
890 }
891 }
892
893 return false;
894}
895
897 switch (DeclKind) {
898 case Function:
899 case CXXDeductionGuide:
900 case CXXMethod:
901 case CXXConstructor:
902 case ConstructorUsingShadow:
903 case CXXDestructor:
904 case CXXConversion:
905 case EnumConstant:
906 case Var:
907 case ImplicitParam:
908 case ParmVar:
909 case ObjCMethod:
910 case ObjCProperty:
911 case MSProperty:
912 case HLSLBuffer:
913 case HLSLRootSignature:
914 return IDNS_Ordinary;
915 case Label:
916 return IDNS_Label;
917
918 case Binding:
919 case NonTypeTemplateParm:
920 case VarTemplate:
921 case Concept:
922 // These (C++-only) declarations are found by redeclaration lookup for
923 // tag types, so we include them in the tag namespace.
924 return IDNS_Ordinary | IDNS_Tag;
925
926 case ObjCCompatibleAlias:
927 case ObjCInterface:
928 return IDNS_Ordinary | IDNS_Type;
929
930 case Typedef:
931 case TypeAlias:
932 case TemplateTypeParm:
933 case ObjCTypeParam:
934 return IDNS_Ordinary | IDNS_Type;
935
936 case UnresolvedUsingTypename:
938
939 case UsingShadow:
940 return 0; // we'll actually overwrite this later
941
942 case UnresolvedUsingValue:
943 return IDNS_Ordinary | IDNS_Using;
944
945 case Using:
946 case UsingPack:
947 case UsingEnum:
948 return IDNS_Using;
949
950 case ObjCProtocol:
951 return IDNS_ObjCProtocol;
952
953 case Field:
954 case IndirectField:
955 case ObjCAtDefsField:
956 case ObjCIvar:
957 return IDNS_Member;
958
959 case Record:
960 case CXXRecord:
961 case Enum:
962 return IDNS_Tag | IDNS_Type;
963
964 case Namespace:
965 case NamespaceAlias:
966 return IDNS_Namespace;
967
968 case FunctionTemplate:
969 return IDNS_Ordinary;
970
971 case ClassTemplate:
972 case TemplateTemplateParm:
975
976 case UnresolvedUsingIfExists:
977 return IDNS_Type | IDNS_Ordinary;
978
979 case OMPDeclareReduction:
980 return IDNS_OMPReduction;
981
982 case OMPDeclareMapper:
983 return IDNS_OMPMapper;
984
985 // Never have names.
986 case Friend:
987 case FriendTemplate:
988 case AccessSpec:
989 case LinkageSpec:
990 case Export:
991 case FileScopeAsm:
992 case TopLevelStmt:
993 case StaticAssert:
994 case ObjCPropertyImpl:
995 case PragmaComment:
996 case PragmaDetectMismatch:
997 case Block:
998 case Captured:
999 case OutlinedFunction:
1000 case TranslationUnit:
1001 case ExternCContext:
1002 case Decomposition:
1003 case MSGuid:
1004 case UnnamedGlobalConstant:
1005 case TemplateParamObject:
1006
1007 case UsingDirective:
1008 case BuiltinTemplate:
1009 case ClassTemplateSpecialization:
1010 case ClassTemplatePartialSpecialization:
1011 case VarTemplateSpecialization:
1012 case VarTemplatePartialSpecialization:
1013 case ObjCImplementation:
1014 case ObjCCategory:
1015 case ObjCCategoryImpl:
1016 case Import:
1017 case OMPThreadPrivate:
1018 case OMPGroupPrivate:
1019 case OMPAllocate:
1020 case OMPRequires:
1021 case OMPCapturedExpr:
1022 case Empty:
1023 case LifetimeExtendedTemporary:
1024 case RequiresExprBody:
1025 case ImplicitConceptSpecialization:
1026 case OpenACCDeclare:
1027 case OpenACCRoutine:
1029 case CXXExpansionStmt:
1030 // Never looked up by name.
1031 return 0;
1032 }
1033
1034 llvm_unreachable("Invalid DeclKind!");
1035}
1036
1037void Decl::setAttrsImpl(const AttrVec &attrs, ASTContext &Ctx) {
1038 assert(!HasAttrs && "Decl already contains attrs.");
1039
1040 AttrVec &AttrBlank = Ctx.getDeclAttrs(this);
1041 assert(AttrBlank.empty() && "HasAttrs was wrong?");
1042
1043 AttrBlank = attrs;
1044 HasAttrs = true;
1045}
1046
1048 if (!HasAttrs) return;
1049
1050 HasAttrs = false;
1052}
1053
1055 if (!hasAttrs()) {
1056 setAttrs(AttrVec(1, A));
1057 return;
1058 }
1059
1060 AttrVec &Attrs = getAttrs();
1061 if (!A->isInherited()) {
1062 Attrs.push_back(A);
1063 return;
1064 }
1065
1066 // Attribute inheritance is processed after attribute parsing. To keep the
1067 // order as in the source code, add inherited attributes before non-inherited
1068 // ones.
1069 auto I = Attrs.begin(), E = Attrs.end();
1070 for (; I != E; ++I) {
1071 if (!(*I)->isInherited())
1072 break;
1073 }
1074 Attrs.insert(I, A);
1075}
1076
1077const AttrVec &Decl::getAttrs() const {
1078 assert(HasAttrs && "No attrs to get!");
1079 return getASTContext().getDeclAttrs(this);
1080}
1081
1083 Decl::Kind DK = D->getDeclKind();
1084 switch (DK) {
1085#define DECL(NAME, BASE)
1086#define DECL_CONTEXT(NAME) \
1087 case Decl::NAME: \
1088 return static_cast<NAME##Decl *>(const_cast<DeclContext *>(D));
1089#include "clang/AST/DeclNodes.inc"
1090 default:
1091 llvm_unreachable("a decl that inherits DeclContext isn't handled");
1092 }
1093}
1094
1096 Decl::Kind DK = D->getKind();
1097 switch(DK) {
1098#define DECL(NAME, BASE)
1099#define DECL_CONTEXT(NAME) \
1100 case Decl::NAME: \
1101 return static_cast<NAME##Decl *>(const_cast<Decl *>(D));
1102#include "clang/AST/DeclNodes.inc"
1103 default:
1104 llvm_unreachable("a decl that inherits DeclContext isn't handled");
1105 }
1106}
1107
1109 // Special handling of FunctionDecl to avoid de-serializing the body from PCH.
1110 // FunctionDecl stores EndRangeLoc for this purpose.
1111 if (const auto *FD = dyn_cast<FunctionDecl>(this)) {
1112 const FunctionDecl *Definition;
1113 if (FD->hasBody(Definition))
1114 return Definition->getSourceRange().getEnd();
1115 return {};
1116 }
1117
1118 if (Stmt *Body = getBody())
1119 return Body->getSourceRange().getEnd();
1120
1121 return {};
1122}
1123
1124bool Decl::AccessDeclContextCheck() const {
1125#ifndef NDEBUG
1126 // Suppress this check if any of the following hold:
1127 // 1. this is the translation unit (and thus has no parent)
1128 // 2. this is a template parameter (and thus doesn't belong to its context)
1129 // 3. this is a non-type template parameter
1130 // 4. the context is not a record
1131 // 5. it's invalid
1132 // 6. it's a C++0x static_assert.
1133 // 7. it's a block literal declaration
1134 // 8. it's a temporary with lifetime extended due to being default value.
1138 isa<StaticAssertDecl>(this) || isa<BlockDecl>(this) ||
1139 // FIXME: a ParmVarDecl can have ClassTemplateSpecialization
1140 // as DeclContext (?).
1141 isa<ParmVarDecl>(this) ||
1142 // FIXME: a ClassTemplateSpecialization or CXXRecordDecl can have
1143 // AS_none as access specifier.
1145 return true;
1146
1147 assert(Access != AS_none &&
1148 "Access specifier is AS_none inside a record decl");
1149#endif
1150 return true;
1151}
1152
1154 const DeclContext *DC = getLexicalDeclContext();
1155
1156 while (DC && !isa<ExportDecl>(DC))
1157 DC = DC->getLexicalParent();
1158
1159 return isa_and_nonnull<ExportDecl>(DC);
1160}
1161
1164 return false;
1165 auto *M = getOwningModule();
1166 return M && M->isNamedModule() &&
1168}
1169
1171 auto *M = getOwningModule();
1172
1173 if (!M)
1174 return false;
1175
1176 // FIXME or NOTE: maybe we need to be clear about the semantics
1177 // of clang header modules. e.g., if this lives in a clang header
1178 // module included by the current unit, should we return false
1179 // here?
1180 //
1181 // This is clear for header units as the specification says the
1182 // header units live in a synthesised translation unit. So we
1183 // can return false here.
1184 M = M->getTopLevelModule();
1185 if (!M->isNamedModule())
1186 return false;
1187
1188 return M != getASTContext().getCurrentNamedModule();
1189}
1190
1192 auto *M = getOwningModule();
1193
1194 if (!M || !M->isNamedModule())
1195 return false;
1196
1197 return M == getASTContext().getCurrentNamedModule();
1198}
1199
1202 if (!Source)
1203 return false;
1204
1206}
1207
1211
1215
1218}
1219
1222}
1223
1224static Decl::Kind getKind(const Decl *D) { return D->getKind(); }
1225static Decl::Kind getKind(const DeclContext *DC) { return DC->getDeclKind(); }
1226
1227int64_t Decl::getID() const {
1228 return getASTContext().getAllocator().identifyKnownAlignedObject<Decl>(this);
1229}
1230
1231const FunctionType *Decl::getFunctionType(bool BlocksToo) const {
1232 QualType Ty;
1233 if (const auto *D = dyn_cast<ValueDecl>(this))
1234 Ty = D->getType();
1235 else if (const auto *D = dyn_cast<TypedefNameDecl>(this))
1236 Ty = D->getUnderlyingType();
1237 else
1238 return nullptr;
1239
1240 if (Ty.isNull()) {
1241 // BindingDecls do not have types during parsing, so return nullptr. This is
1242 // the only known case where `Ty` is null.
1243 assert(isa<BindingDecl>(this));
1244 return nullptr;
1245 }
1246
1247 if (Ty->isFunctionPointerType())
1248 Ty = Ty->castAs<PointerType>()->getPointeeType();
1249 else if (Ty->isMemberFunctionPointerType())
1251 else if (Ty->isFunctionReferenceType())
1252 Ty = Ty->castAs<ReferenceType>()->getPointeeType();
1253 else if (BlocksToo && Ty->isBlockPointerType())
1254 Ty = Ty->castAs<BlockPointerType>()->getPointeeType();
1255
1256 return Ty->getAs<FunctionType>();
1257}
1258
1260 QualType Ty;
1261 if (const auto *D = dyn_cast<ValueDecl>(this))
1262 Ty = D->getType();
1263 else if (const auto *D = dyn_cast<TypedefNameDecl>(this))
1264 Ty = D->getUnderlyingType();
1265 else
1266 return false;
1267
1269}
1270
1275
1276/// Starting at a given context (a Decl or DeclContext), look for a
1277/// code context that is not a closure (a lambda, block, etc.).
1278template <class T> static Decl *getNonClosureContext(T *D) {
1279 if (getKind(D) == Decl::CXXMethod) {
1280 auto *MD = cast<CXXMethodDecl>(D);
1281 if (MD->getOverloadedOperator() == OO_Call &&
1282 MD->getParent()->isLambda())
1283 return getNonClosureContext(MD->getParent()->getParent());
1284 return MD;
1285 }
1286 if (auto *FD = dyn_cast<FunctionDecl>(D))
1287 return FD;
1288 if (auto *MD = dyn_cast<ObjCMethodDecl>(D))
1289 return MD;
1290 if (auto *BD = dyn_cast<BlockDecl>(D))
1291 return getNonClosureContext(BD->getParent());
1292 if (auto *CD = dyn_cast<CapturedDecl>(D))
1293 return getNonClosureContext(CD->getParent());
1294 if (auto *OFD = dyn_cast<OutlinedFunctionDecl>(D))
1295 return getNonClosureContext(OFD->getParent());
1296 return nullptr;
1297}
1298
1300 return ::getNonClosureContext(this);
1301}
1302
1304 return ::getNonClosureContext(this);
1305}
1306
1307//===----------------------------------------------------------------------===//
1308// DeclContext Implementation
1309//===----------------------------------------------------------------------===//
1310
1312 DeclContextBits.DeclKind = K;
1315 setNeedToReconcileExternalVisibleStorage(false);
1316 setHasLazyLocalLexicalLookups(false);
1317 setHasLazyExternalLexicalLookups(false);
1318}
1319
1321 Decl::Kind DK = D->getKind();
1322 switch (DK) {
1323#define DECL(NAME, BASE)
1324#define DECL_CONTEXT(NAME) case Decl::NAME:
1325#include "clang/AST/DeclNodes.inc"
1326 return true;
1327 default:
1328 return false;
1329 }
1330}
1331
1332DeclContext::~DeclContext() = default;
1333
1334/// Find the parent context of this context that will be
1335/// used for unqualified name lookup.
1336///
1337/// Generally, the parent lookup context is the semantic context. However, for
1338/// a friend function the parent lookup context is the lexical context, which
1339/// is the class in which the friend is declared.
1341 // FIXME: Find a better way to identify friends.
1342 if (isa<FunctionDecl>(this))
1345 return getLexicalParent();
1346
1347 // A lookup within the call operator of a lambda never looks in the lambda
1348 // class; instead, skip to the context in which that closure type is
1349 // declared.
1350 if (isLambdaCallOperator(this))
1351 return getParent()->getParent();
1352
1353 return getParent();
1354}
1355
1357 const DeclContext *Ctx = this;
1358
1359 do {
1360 if (Ctx->isClosure())
1361 return cast<BlockDecl>(Ctx);
1362 Ctx = Ctx->getParent();
1363 } while (Ctx);
1364
1365 return nullptr;
1366}
1367
1369 return isNamespace() &&
1370 cast<NamespaceDecl>(this)->isInline();
1371}
1372
1374 if (!isNamespace())
1375 return false;
1376
1377 const auto *ND = cast<NamespaceDecl>(this);
1378 if (ND->isInline()) {
1379 return ND->getParent()->isStdNamespace();
1380 }
1381
1383 return false;
1384
1385 const IdentifierInfo *II = ND->getIdentifier();
1386 return II && II->isStr("std");
1387}
1388
1390 if (isFileContext())
1391 return false;
1392
1394 return true;
1395
1396 if (const auto *Record = dyn_cast<CXXRecordDecl>(this)) {
1397 if (Record->getDescribedClassTemplate())
1398 return true;
1399
1400 if (Record->isDependentLambda())
1401 return true;
1402 if (Record->isNeverDependentLambda())
1403 return false;
1404 }
1405
1406 if (const auto *Function = dyn_cast<FunctionDecl>(this)) {
1407 if (Function->getDescribedFunctionTemplate())
1408 return true;
1409
1410 // Friend function declarations are dependent if their *lexical*
1411 // context is dependent.
1412 if (cast<Decl>(this)->getFriendObjectKind())
1414 }
1415
1416 // FIXME: A variable template is a dependent context, but is not a
1417 // DeclContext. A context within it (such as a lambda-expression)
1418 // should be considered dependent.
1419
1420 return getParent() && getParent()->isDependentContext();
1421}
1422
1424 if (getDeclKind() == Decl::Enum)
1425 return !cast<EnumDecl>(this)->isScoped();
1426
1428}
1429
1430static bool isLinkageSpecContext(const DeclContext *DC,
1432 while (DC->getDeclKind() != Decl::TranslationUnit) {
1433 if (DC->getDeclKind() == Decl::LinkageSpec)
1434 return cast<LinkageSpecDecl>(DC)->getLanguage() == ID;
1435 DC = DC->getLexicalParent();
1436 }
1437 return false;
1438}
1439
1443
1445 const DeclContext *DC = this;
1446 while (DC->getDeclKind() != Decl::TranslationUnit) {
1447 if (DC->getDeclKind() == Decl::LinkageSpec &&
1449 return cast<LinkageSpecDecl>(DC);
1450 DC = DC->getLexicalParent();
1451 }
1452 return nullptr;
1453}
1454
1458
1459bool DeclContext::Encloses(const DeclContext *DC) const {
1460 if (getPrimaryContext() != this)
1461 return getPrimaryContext()->Encloses(DC);
1462
1463 for (; DC; DC = DC->getParent())
1465 DC->getPrimaryContext() == this)
1466 return true;
1467 return false;
1468}
1469
1471 if (getPrimaryContext() != this)
1473
1474 for (; DC; DC = DC->getLexicalParent())
1476 DC->getPrimaryContext() == this)
1477 return true;
1478 return false;
1479}
1480
1482 DeclContext *DC = this;
1483 while (DC->isTransparentContext()) {
1484 DC = DC->getParent();
1485 assert(DC && "All transparent contexts should have a parent!");
1486 }
1487 return DC;
1488}
1489
1491 switch (getDeclKind()) {
1492 case Decl::ExternCContext:
1493 case Decl::LinkageSpec:
1494 case Decl::Export:
1495 case Decl::TopLevelStmt:
1496 case Decl::Block:
1497 case Decl::Captured:
1498 case Decl::OutlinedFunction:
1499 case Decl::OMPDeclareReduction:
1500 case Decl::OMPDeclareMapper:
1501 case Decl::RequiresExprBody:
1502 case Decl::CXXExpansionStmt:
1503 // There is only one DeclContext for these entities.
1504 return this;
1505
1506 case Decl::HLSLBuffer:
1507 // Each buffer, even with the same name, is a distinct construct.
1508 // Multiple buffers with the same name are allowed for backward
1509 // compatibility.
1510 // As long as buffers have unique resource bindings the names don't matter.
1511 // The names get exposed via the CPU-side reflection API which
1512 // supports querying bindings, so we cannot remove them.
1513 return this;
1514
1515 case Decl::TranslationUnit:
1516 return static_cast<TranslationUnitDecl *>(this)->getFirstDecl();
1517 case Decl::Namespace:
1518 return static_cast<NamespaceDecl *>(this)->getFirstDecl();
1519
1520 case Decl::ObjCMethod:
1521 return this;
1522
1523 case Decl::ObjCInterface:
1524 if (auto *OID = dyn_cast<ObjCInterfaceDecl>(this))
1525 if (auto *Def = OID->getDefinition())
1526 return Def;
1527 return this;
1528
1529 case Decl::ObjCProtocol:
1530 if (auto *OPD = dyn_cast<ObjCProtocolDecl>(this))
1531 if (auto *Def = OPD->getDefinition())
1532 return Def;
1533 return this;
1534
1535 case Decl::ObjCCategory:
1536 return this;
1537
1538 case Decl::ObjCImplementation:
1539 case Decl::ObjCCategoryImpl:
1540 return this;
1541
1542 // If this is a tag type that has a definition or is currently
1543 // being defined, that definition is our primary context.
1544 case Decl::ClassTemplatePartialSpecialization:
1545 case Decl::ClassTemplateSpecialization:
1546 case Decl::CXXRecord:
1547 return cast<CXXRecordDecl>(this)->getDefinitionOrSelf();
1548 case Decl::Record:
1549 case Decl::Enum:
1550 return cast<TagDecl>(this)->getDefinitionOrSelf();
1551
1552 default:
1553 assert(getDeclKind() >= Decl::firstFunction &&
1554 getDeclKind() <= Decl::lastFunction && "Unknown DeclContext kind");
1555 return this;
1556 }
1557}
1558
1559template <typename T>
1562 for (T *D = Self->getMostRecentDecl(); D; D = D->getPreviousDecl())
1563 Contexts.push_back(D);
1564
1565 std::reverse(Contexts.begin(), Contexts.end());
1566}
1567
1569 Contexts.clear();
1570
1571 Decl::Kind Kind = getDeclKind();
1572
1573 if (Kind == Decl::TranslationUnit)
1574 collectAllContextsImpl(static_cast<TranslationUnitDecl *>(this), Contexts);
1575 else if (Kind == Decl::Namespace)
1576 collectAllContextsImpl(static_cast<NamespaceDecl *>(this), Contexts);
1577 else
1578 Contexts.push_back(this);
1579}
1580
1581std::pair<Decl *, Decl *>
1583 bool FieldsAlreadyLoaded) {
1584 // Build up a chain of declarations via the Decl::NextInContextAndBits field.
1585 Decl *FirstNewDecl = nullptr;
1586 Decl *PrevDecl = nullptr;
1587 for (auto *D : Decls) {
1588 if (FieldsAlreadyLoaded && isa<FieldDecl>(D))
1589 continue;
1590
1591 if (PrevDecl)
1592 PrevDecl->NextInContextAndBits.setPointer(D);
1593 else
1594 FirstNewDecl = D;
1595
1596 PrevDecl = D;
1597 }
1598
1599 return std::make_pair(FirstNewDecl, PrevDecl);
1600}
1601
1602/// We have just acquired external visible storage, and we already have
1603/// built a lookup map. For every name in the map, pull in the new names from
1604/// the external storage.
1605void DeclContext::reconcileExternalVisibleStorage() const {
1606 assert(hasNeedToReconcileExternalVisibleStorage() && LookupPtr);
1607 setNeedToReconcileExternalVisibleStorage(false);
1608
1609 for (auto &Lookup : *LookupPtr)
1610 Lookup.second.setHasExternalDecls();
1611}
1612
1613/// Load the declarations within this lexical storage from an
1614/// external source.
1615/// \return \c true if any declarations were added.
1616bool
1617DeclContext::LoadLexicalDeclsFromExternalStorage() const {
1619 assert(hasExternalLexicalStorage() && Source && "No external storage?");
1620
1621 // Notify that we have a DeclContext that is initializing.
1622 ExternalASTSource::Deserializing ADeclContext(Source);
1623
1624 // Load the external declarations, if any.
1627 Source->FindExternalLexicalDecls(this, Decls);
1628
1629 if (Decls.empty())
1630 return false;
1631
1632 // We may have already loaded just the fields of this record, in which case
1633 // we need to ignore them.
1634 bool FieldsAlreadyLoaded = false;
1635 if (const auto *RD = dyn_cast<RecordDecl>(this))
1636 FieldsAlreadyLoaded = RD->hasLoadedFieldsFromExternalStorage();
1637
1638 // Splice the newly-read declarations into the beginning of the list
1639 // of declarations.
1640 Decl *ExternalFirst, *ExternalLast;
1641 std::tie(ExternalFirst, ExternalLast) =
1642 BuildDeclChain(Decls, FieldsAlreadyLoaded);
1643 ExternalLast->NextInContextAndBits.setPointer(FirstDecl);
1644 FirstDecl = ExternalFirst;
1645 if (!LastDecl)
1646 LastDecl = ExternalLast;
1647 return true;
1648}
1649
1652 DeclarationName Name) {
1653 ASTContext &Context = DC->getParentASTContext();
1654 StoredDeclsMap *Map;
1655 if (!(Map = DC->LookupPtr))
1656 Map = DC->CreateStoredDeclsMap(Context);
1657 if (DC->hasNeedToReconcileExternalVisibleStorage())
1658 DC->reconcileExternalVisibleStorage();
1659
1660 (*Map)[Name].removeExternalDecls();
1661
1663}
1664
1667 DeclarationName Name,
1668 ArrayRef<NamedDecl*> Decls) {
1669 ASTContext &Context = DC->getParentASTContext();
1670 StoredDeclsMap *Map;
1671 if (!(Map = DC->LookupPtr))
1672 Map = DC->CreateStoredDeclsMap(Context);
1673 if (DC->hasNeedToReconcileExternalVisibleStorage())
1674 DC->reconcileExternalVisibleStorage();
1675
1676 StoredDeclsList &List = (*Map)[Name];
1677 List.replaceExternalDecls(Decls);
1678 return List.getLookupResult();
1679}
1680
1683 LoadLexicalDeclsFromExternalStorage();
1684 return decl_iterator(FirstDecl);
1685}
1686
1689 LoadLexicalDeclsFromExternalStorage();
1690
1691 return !FirstDecl;
1692}
1693
1695 return (D->getLexicalDeclContext() == this &&
1696 (D->NextInContextAndBits.getPointer() || D == LastDecl));
1697}
1698
1701 LoadLexicalDeclsFromExternalStorage();
1702 return containsDecl(D);
1703}
1704
1705/// shouldBeHidden - Determine whether a declaration which was declared
1706/// within its semantic context should be invisible to qualified name lookup.
1707static bool shouldBeHidden(NamedDecl *D) {
1708 // Skip unnamed declarations.
1709 if (!D->getDeclName())
1710 return true;
1711
1712 // Skip entities that can't be found by name lookup into a particular
1713 // context.
1714 if ((D->getIdentifierNamespace() == 0 && !isa<UsingDirectiveDecl>(D)) ||
1716 return true;
1717
1718 // Skip friends and local extern declarations unless they're the first
1719 // declaration of the entity.
1720 if ((D->isLocalExternDecl() || D->getFriendObjectKind()) &&
1721 D != D->getCanonicalDecl())
1722 return true;
1723
1724 // Skip template specializations.
1725 // FIXME: This feels like a hack. Should DeclarationName support
1726 // template-ids, or is there a better way to keep specializations
1727 // from being visible?
1729 return true;
1730 if (auto *FD = dyn_cast<FunctionDecl>(D))
1731 if (FD->isFunctionTemplateSpecialization())
1732 return true;
1733
1734 // Hide destructors that are invalid. There should always be one destructor,
1735 // but if it is an invalid decl, another one is created. We need to hide the
1736 // invalid one from places that expect exactly one destructor, like the
1737 // serialization code.
1739 return true;
1740
1741 return false;
1742}
1743
1745 assert(D->getLexicalDeclContext() == this &&
1746 "decl being removed from non-lexical context");
1747 assert((D->NextInContextAndBits.getPointer() || D == LastDecl) &&
1748 "decl is not in decls list");
1749
1750 // Remove D from the decl chain. This is O(n) but hopefully rare.
1751 if (D == FirstDecl) {
1752 if (D == LastDecl)
1753 FirstDecl = LastDecl = nullptr;
1754 else
1755 FirstDecl = D->NextInContextAndBits.getPointer();
1756 } else {
1757 for (Decl *I = FirstDecl; true; I = I->NextInContextAndBits.getPointer()) {
1758 assert(I && "decl not found in linked list");
1759 if (I->NextInContextAndBits.getPointer() == D) {
1760 I->NextInContextAndBits.setPointer(D->NextInContextAndBits.getPointer());
1761 if (D == LastDecl) LastDecl = I;
1762 break;
1763 }
1764 }
1765 }
1766
1767 // Mark that D is no longer in the decl chain.
1768 D->NextInContextAndBits.setPointer(nullptr);
1769
1770 // Remove D from the lookup table if necessary.
1771 if (isa<NamedDecl>(D)) {
1772 auto *ND = cast<NamedDecl>(D);
1773
1774 // Do not try to remove the declaration if that is invisible to qualified
1775 // lookup. E.g. template specializations are skipped.
1776 if (shouldBeHidden(ND))
1777 return;
1778
1779 // Remove only decls that have a name
1780 if (!ND->getDeclName())
1781 return;
1782
1783 auto *DC = D->getDeclContext();
1784 do {
1785 StoredDeclsMap *Map = DC->getPrimaryContext()->LookupPtr;
1786 if (Map) {
1787 StoredDeclsMap::iterator Pos = Map->find(ND->getDeclName());
1788 assert(Pos != Map->end() && "no lookup entry for decl");
1789 StoredDeclsList &List = Pos->second;
1790 List.remove(ND);
1791 // Clean up the entry if there are no more decls.
1792 if (List.isNull())
1793 Map->erase(Pos);
1794 }
1795 } while (DC->isTransparentContext() && (DC = DC->getParent()));
1796 }
1797}
1798
1800 assert(D->getLexicalDeclContext() == this &&
1801 "Decl inserted into wrong lexical context");
1802 assert(!D->getNextDeclInContext() && D != LastDecl &&
1803 "Decl already inserted into a DeclContext");
1804
1805 if (FirstDecl) {
1806 LastDecl->NextInContextAndBits.setPointer(D);
1807 LastDecl = D;
1808 } else {
1809 FirstDecl = LastDecl = D;
1810 }
1811
1812 // Notify a C++ record declaration that we've added a member, so it can
1813 // update its class-specific state.
1814 if (auto *Record = dyn_cast<CXXRecordDecl>(this))
1815 Record->addedMember(D);
1816
1817 // If this is a newly-created (not de-serialized) import declaration, wire
1818 // it in to the list of local import declarations.
1819 if (!D->isFromASTFile()) {
1820 if (auto *Import = dyn_cast<ImportDecl>(D))
1822 }
1823}
1824
1826 addHiddenDecl(D);
1827
1828 if (auto *ND = dyn_cast<NamedDecl>(D))
1829 ND->getDeclContext()->getPrimaryContext()->
1830 makeDeclVisibleInContextWithFlags(ND, false, true);
1831}
1832
1834 addHiddenDecl(D);
1835
1836 if (auto *ND = dyn_cast<NamedDecl>(D))
1837 ND->getDeclContext()->getPrimaryContext()->
1838 makeDeclVisibleInContextWithFlags(ND, true, true);
1839}
1840
1841/// buildLookup - Build the lookup data structure with all of the
1842/// declarations in this DeclContext (and any other contexts linked
1843/// to it or transparent contexts nested within it) and return it.
1844///
1845/// Note that the produced map may miss out declarations from an
1846/// external source. If it does, those entries will be marked with
1847/// the 'hasExternalDecls' flag.
1849 assert(this == getPrimaryContext() && "buildLookup called on non-primary DC");
1850
1851 if (!hasLazyLocalLexicalLookups() &&
1852 !hasLazyExternalLexicalLookups())
1853 return LookupPtr;
1854
1856 collectAllContexts(Contexts);
1857
1858 if (hasLazyExternalLexicalLookups()) {
1859 setHasLazyExternalLexicalLookups(false);
1860 for (auto *DC : Contexts) {
1861 if (DC->hasExternalLexicalStorage()) {
1862 bool LoadedDecls = DC->LoadLexicalDeclsFromExternalStorage();
1863 setHasLazyLocalLexicalLookups(
1864 hasLazyLocalLexicalLookups() | LoadedDecls );
1865 }
1866 }
1867
1868 if (!hasLazyLocalLexicalLookups())
1869 return LookupPtr;
1870 }
1871
1872 for (auto *DC : Contexts)
1873 buildLookupImpl(DC, hasExternalVisibleStorage());
1874
1875 // We no longer have any lazy decls.
1876 setHasLazyLocalLexicalLookups(false);
1877 return LookupPtr;
1878}
1879
1880/// buildLookupImpl - Build part of the lookup data structure for the
1881/// declarations contained within DCtx, which will either be this
1882/// DeclContext, a DeclContext linked to it, or a transparent context
1883/// nested within it.
1884void DeclContext::buildLookupImpl(DeclContext *DCtx, bool Internal) {
1885 for (auto *D : DCtx->noload_decls()) {
1886 // Insert this declaration into the lookup structure, but only if
1887 // it's semantically within its decl context. Any other decls which
1888 // should be found in this context are added eagerly.
1889 //
1890 // If it's from an AST file, don't add it now. It'll get handled by
1891 // FindExternalVisibleDeclsByName if needed. Exception: if we're not
1892 // in C++, we do not track external visible decls for the TU, so in
1893 // that case we need to collect them all here.
1894 if (auto *ND = dyn_cast<NamedDecl>(D))
1895 if (ND->getDeclContext() == DCtx && !shouldBeHidden(ND) &&
1896 (!ND->isFromASTFile() ||
1897 (isTranslationUnit() &&
1898 !getParentASTContext().getLangOpts().CPlusPlus)))
1899 makeDeclVisibleInContextImpl(ND, Internal);
1900
1901 // If this declaration is itself a transparent declaration context
1902 // or inline namespace, add the members of this declaration of that
1903 // context (recursively).
1904 if (auto *InnerCtx = dyn_cast<DeclContext>(D))
1905 if (InnerCtx->isTransparentContext() || InnerCtx->isInlineNamespace())
1906 buildLookupImpl(InnerCtx, Internal);
1907 }
1908}
1909
1912 // For transparent DeclContext, we should lookup in their enclosing context.
1913 if (getDeclKind() == Decl::LinkageSpec || getDeclKind() == Decl::Export)
1914 return getParent()->lookup(Name);
1915
1916 return getPrimaryContext()->lookupImpl(Name, this);
1917}
1918
1920DeclContext::lookupImpl(DeclarationName Name,
1921 const DeclContext *OriginalLookupDC) const {
1922 assert(this == getPrimaryContext() &&
1923 "lookupImpl should only be called with primary DC!");
1924 assert(getDeclKind() != Decl::LinkageSpec && getDeclKind() != Decl::Export &&
1925 "We shouldn't lookup in transparent DC.");
1926
1927 // If we have an external source, ensure that any later redeclarations of this
1928 // context have been loaded, since they may add names to the result of this
1929 // lookup (or add external visible storage).
1931 if (Source)
1932 (void)cast<Decl>(this)->getMostRecentDecl();
1933
1935 assert(Source && "external visible storage but no external source?");
1936
1937 if (hasNeedToReconcileExternalVisibleStorage())
1938 reconcileExternalVisibleStorage();
1939
1941
1942 if (hasLazyLocalLexicalLookups() ||
1943 hasLazyExternalLexicalLookups())
1944 // FIXME: Make buildLookup const?
1945 Map = const_cast<DeclContext*>(this)->buildLookup();
1946
1947 if (!Map)
1948 Map = CreateStoredDeclsMap(getParentASTContext());
1949
1950 // If we have a lookup result with no external decls, we are done.
1951 std::pair<StoredDeclsMap::iterator, bool> R = Map->try_emplace(Name);
1952 if (!R.second && !R.first->second.hasExternalDecls())
1953 return R.first->second.getLookupResult();
1954
1955 if (Source->FindExternalVisibleDeclsByName(this, Name, OriginalLookupDC) ||
1956 !R.second) {
1957 if (StoredDeclsMap *Map = LookupPtr) {
1958 StoredDeclsMap::iterator I = Map->find(Name);
1959 if (I != Map->end())
1960 return I->second.getLookupResult();
1961 }
1962 }
1963
1964 return {};
1965 }
1966
1967 StoredDeclsMap *Map = LookupPtr;
1968 if (hasLazyLocalLexicalLookups() ||
1969 hasLazyExternalLexicalLookups())
1970 Map = const_cast<DeclContext*>(this)->buildLookup();
1971
1972 if (!Map)
1973 return {};
1974
1975 StoredDeclsMap::iterator I = Map->find(Name);
1976 if (I == Map->end())
1977 return {};
1978
1979 return I->second.getLookupResult();
1980}
1981
1984 // For transparent DeclContext, we should lookup in their enclosing context.
1985 if (getDeclKind() == Decl::LinkageSpec || getDeclKind() == Decl::Export)
1986 return getParent()->noload_lookup(Name);
1987
1988 DeclContext *PrimaryContext = getPrimaryContext();
1989 if (PrimaryContext != this)
1990 return PrimaryContext->noload_lookup(Name);
1991
1992 loadLazyLocalLexicalLookups();
1994 if (!Map)
1995 return {};
1996
1997 StoredDeclsMap::iterator I = Map->find(Name);
1998 return I != Map->end() ? I->second.getLookupResult()
1999 : lookup_result();
2000}
2001
2002// If we have any lazy lexical declarations not in our lookup map, add them
2003// now. Don't import any external declarations, not even if we know we have
2004// some missing from the external visible lookups.
2005void DeclContext::loadLazyLocalLexicalLookups() {
2006 if (hasLazyLocalLexicalLookups()) {
2008 collectAllContexts(Contexts);
2009 for (auto *Context : Contexts)
2010 buildLookupImpl(Context, hasExternalVisibleStorage());
2011 setHasLazyLocalLexicalLookups(false);
2012 }
2013}
2014
2017 Results.clear();
2018
2019 // If there's no external storage, just perform a normal lookup and copy
2020 // the results.
2022 lookup_result LookupResults = lookup(Name);
2023 llvm::append_range(Results, LookupResults);
2024 if (!Results.empty())
2025 return;
2026 }
2027
2028 // If we have a lookup table, check there first. Maybe we'll get lucky.
2029 // FIXME: Should we be checking these flags on the primary context?
2030 if (Name && !hasLazyLocalLexicalLookups() &&
2031 !hasLazyExternalLexicalLookups()) {
2032 if (StoredDeclsMap *Map = LookupPtr) {
2033 StoredDeclsMap::iterator Pos = Map->find(Name);
2034 if (Pos != Map->end()) {
2035 Results.insert(Results.end(),
2036 Pos->second.getLookupResult().begin(),
2037 Pos->second.getLookupResult().end());
2038 return;
2039 }
2040 }
2041 }
2042
2043 // Slow case: grovel through the declarations in our chain looking for
2044 // matches.
2045 // FIXME: If we have lazy external declarations, this will not find them!
2046 // FIXME: Should we CollectAllContexts and walk them all here?
2047 for (Decl *D = FirstDecl; D; D = D->getNextDeclInContext()) {
2048 if (auto *ND = dyn_cast<NamedDecl>(D))
2049 if (ND->getDeclName() == Name)
2050 Results.push_back(ND);
2051 }
2052}
2053
2055 DeclContext *Ctx = this;
2056
2057 // In C, a record type is the redeclaration context for its fields only. If
2058 // we arrive at a record context after skipping anything else, we should skip
2059 // the record as well. Currently, this means skipping enumerations because
2060 // they're the only transparent context that can exist within a struct or
2061 // union.
2062 bool SkipRecords = getDeclKind() == Decl::Kind::Enum &&
2063 !getParentASTContext().getLangOpts().CPlusPlus;
2064
2065 // Skip through contexts to get to the redeclaration context. Transparent
2066 // contexts are always skipped.
2067 while ((SkipRecords && Ctx->isRecord()) || Ctx->isTransparentContext())
2068 Ctx = Ctx->getParent();
2069 return Ctx;
2070}
2071
2073 DeclContext *Ctx = this;
2074 // Skip through non-namespace, non-translation-unit contexts.
2075 while (!Ctx->isFileContext())
2076 Ctx = Ctx->getParent();
2077 return Ctx->getPrimaryContext();
2078}
2079
2081 // Loop until we find a non-record context.
2082 RecordDecl *OutermostRD = nullptr;
2083 DeclContext *DC = this;
2084 while (DC->isRecord()) {
2085 OutermostRD = cast<RecordDecl>(DC);
2086 DC = DC->getLexicalParent();
2087 }
2088 return OutermostRD;
2089}
2090
2092 DeclContext *DC = this;
2093 while (isa<CXXExpansionStmtDecl>(DC))
2094 DC = DC->getParent();
2095 return DC;
2096}
2097
2101
2105
2107 // For non-file contexts, this is equivalent to Equals.
2108 if (!isFileContext())
2109 return O->Equals(this);
2110
2111 do {
2112 if (O->Equals(this))
2113 return true;
2114
2115 const auto *NS = dyn_cast<NamespaceDecl>(O);
2116 if (!NS || !NS->isInline())
2117 break;
2118 O = NS->getParent();
2119 } while (O);
2120
2121 return false;
2122}
2123
2125 DeclContext *PrimaryDC = this->getPrimaryContext();
2127 // If the decl is being added outside of its semantic decl context, we
2128 // need to ensure that we eagerly build the lookup information for it.
2129 PrimaryDC->makeDeclVisibleInContextWithFlags(D, false, PrimaryDC == DeclDC);
2130}
2131
2132void DeclContext::makeDeclVisibleInContextWithFlags(NamedDecl *D, bool Internal,
2133 bool Recoverable) {
2134 assert(this == getPrimaryContext() && "expected a primary DC");
2135
2136 if (!isLookupContext()) {
2139 ->makeDeclVisibleInContextWithFlags(D, Internal, Recoverable);
2140 return;
2141 }
2142
2143 // Skip declarations which should be invisible to name lookup.
2144 if (shouldBeHidden(D))
2145 return;
2146
2147 // If we already have a lookup data structure, perform the insertion into
2148 // it. If we might have externally-stored decls with this name, look them
2149 // up and perform the insertion. If this decl was declared outside its
2150 // semantic context, buildLookup won't add it, so add it now.
2151 //
2152 // FIXME: As a performance hack, don't add such decls into the translation
2153 // unit unless we're in C++, since qualified lookup into the TU is never
2154 // performed.
2156 ((!Recoverable || D->getDeclContext() != D->getLexicalDeclContext()) &&
2157 (getParentASTContext().getLangOpts().CPlusPlus ||
2158 !isTranslationUnit()))) {
2159 // If we have lazily omitted any decls, they might have the same name as
2160 // the decl which we are adding, so build a full lookup table before adding
2161 // this decl.
2162 buildLookup();
2163 makeDeclVisibleInContextImpl(D, Internal);
2164 } else {
2165 setHasLazyLocalLexicalLookups(true);
2166 }
2167
2168 // If we are a transparent context or inline namespace, insert into our
2169 // parent context, too. This operation is recursive.
2172 makeDeclVisibleInContextWithFlags(D, Internal, Recoverable);
2173
2174 auto *DCAsDecl = cast<Decl>(this);
2175 // Notify that a decl was made visible unless we are a Tag being defined.
2176 if (!(isa<TagDecl>(DCAsDecl) && cast<TagDecl>(DCAsDecl)->isBeingDefined()))
2177 if (ASTMutationListener *L = DCAsDecl->getASTMutationListener())
2178 L->AddedVisibleDecl(this, D);
2179}
2180
2181void DeclContext::makeDeclVisibleInContextImpl(NamedDecl *D, bool Internal) {
2182 // Find or create the stored declaration map.
2183 StoredDeclsMap *Map = LookupPtr;
2184 if (!Map) {
2185 ASTContext *C = &getParentASTContext();
2186 Map = CreateStoredDeclsMap(*C);
2187 }
2188
2189 // If there is an external AST source, load any declarations it knows about
2190 // with this declaration's name.
2191 // If the lookup table contains an entry about this name it means that we
2192 // have already checked the external source.
2193 if (!Internal)
2194 if (ExternalASTSource *Source = getParentASTContext().getExternalSource())
2195 if (hasExternalVisibleStorage() && !Map->contains(D->getDeclName()))
2197 D->getDeclContext());
2198
2199 // Insert this declaration into the map.
2200 StoredDeclsList &DeclNameEntries = (*Map)[D->getDeclName()];
2201
2202 if (Internal) {
2203 // If this is being added as part of loading an external declaration,
2204 // this may not be the only external declaration with this name.
2205 // In this case, we never try to replace an existing declaration; we'll
2206 // handle that when we finalize the list of declarations for this name.
2207 DeclNameEntries.setHasExternalDecls();
2208 DeclNameEntries.prependDeclNoReplace(D);
2209 return;
2210 }
2211
2212 DeclNameEntries.addOrReplaceDecl(D);
2213}
2214
2218
2219/// Returns iterator range [First, Last) of UsingDirectiveDecls stored within
2220/// this context.
2222 // FIXME: Use something more efficient than normal lookup for using
2223 // directives. In C++, using directives are looked up more than anything else.
2224 lookup_result Result = lookup(UsingDirectiveDecl::getName());
2225 return udir_range(Result.begin(), Result.end());
2226}
2227
2228//===----------------------------------------------------------------------===//
2229// Creation and Destruction of StoredDeclsMaps. //
2230//===----------------------------------------------------------------------===//
2231
2232StoredDeclsMap *DeclContext::CreateStoredDeclsMap(ASTContext &C) const {
2233 assert(!LookupPtr && "context already has a decls map");
2234 assert(getPrimaryContext() == this &&
2235 "creating decls map on non-primary context");
2236
2237 StoredDeclsMap *M;
2239 if (Dependent)
2240 M = new DependentStoredDeclsMap();
2241 else
2242 M = new StoredDeclsMap();
2243 M->Previous = C.LastSDM;
2244 C.LastSDM = llvm::PointerIntPair<StoredDeclsMap*,1>(M, Dependent);
2245 LookupPtr = M;
2246 return M;
2247}
2248
2249void ASTContext::ReleaseDeclContextMaps() {
2250 // It's okay to delete DependentStoredDeclsMaps via a StoredDeclsMap
2251 // pointer because the subclass doesn't add anything that needs to
2252 // be deleted.
2253 StoredDeclsMap::DestroyAll(LastSDM.getPointer(), LastSDM.getInt());
2254 LastSDM.setPointer(nullptr);
2255}
2256
2258 while (Map) {
2259 // Advance the iteration before we invalidate memory.
2260 llvm::PointerIntPair<StoredDeclsMap*,1> Next = Map->Previous;
2261
2262 if (Dependent)
2263 delete static_cast<DependentStoredDeclsMap*>(Map);
2264 else
2265 delete Map;
2266
2267 Map = Next.getPointer();
2268 Dependent = Next.getInt();
2269 }
2270}
2271
2273 DeclContext *Parent,
2274 const PartialDiagnostic &PDiag) {
2275 assert(Parent->isDependentContext()
2276 && "cannot iterate dependent diagnostics of non-dependent context");
2277 Parent = Parent->getPrimaryContext();
2278 if (!Parent->LookupPtr)
2279 Parent->CreateStoredDeclsMap(C);
2280
2281 auto *Map = static_cast<DependentStoredDeclsMap *>(Parent->LookupPtr);
2282
2283 // Allocate the copy of the PartialDiagnostic via the ASTContext's
2284 // BumpPtrAllocator, rather than the ASTContext itself.
2285 DiagnosticStorage *DiagStorage = nullptr;
2286 if (PDiag.hasStorage())
2287 DiagStorage = new (C) DiagnosticStorage;
2288
2289 auto *DD = new (C) DependentDiagnostic(PDiag, DiagStorage);
2290
2291 // TODO: Maybe we shouldn't reverse the order during insertion.
2292 DD->NextDiagnostic = Map->FirstDiagnostic;
2293 Map->FirstDiagnostic = DD;
2294
2295 return DD;
2296}
2297
2299 return ID & llvm::maskTrailingOnes<DeclID>(32);
2300}
Defines the clang::ASTContext interface.
#define V(N, I)
#define BuiltinTemplate(BTName)
Definition ASTContext.h:504
This file provides some common utility functions for processing Lambda related AST Constructs.
static bool shouldBeHidden(NamedDecl *D)
shouldBeHidden - Determine whether a declaration which was declared within its semantic context shoul...
static void collectAllContextsImpl(T *Self, SmallVectorImpl< DeclContext * > &Contexts)
static bool isLinkageSpecContext(const DeclContext *DC, LinkageSpecLanguageIDs ID)
static Decl::Kind getKind(const Decl *D)
static Decl * getNonClosureContext(T *D)
Starting at a given context (a Decl or DeclContext), look for a code context that is not a closure (a...
static AvailabilityResult CheckAvailability(ASTContext &Context, const AvailabilityAttr *A, std::string *Message, VersionTuple EnclosingVersion)
Determine the availability of the given declaration based on the target platform.
Definition DeclBase.cpp:674
static StringRef getRealizedPlatform(const AvailabilityAttr *A, const ASTContext &Context)
Definition DeclBase.cpp:652
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
This file defines OpenACC nodes for declarative directives.
This file defines OpenMP nodes for declarative directives.
Defines the C++ template declaration subclasses.
FormatToken * Next
The next token in the unwrapped line.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
llvm::MachO::Record Record
Definition MachO.h:31
Defines the clang::Module class, which describes a module in the source code.
Defines types useful for describing an Objective-C runtime.
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream.
Defines the clang::SourceLocation class and associated facilities.
static QualType getPointeeType(const MemRegion *R)
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:245
const ConstantArrayType * getAsConstantArrayType(QualType T) const
ASTMutationListener * getASTMutationListener() const
Retrieve a pointer to the AST mutation listener associated with this AST context, if any.
const IncompleteArrayType * getAsIncompleteArrayType(QualType T) const
const LangOptions & getLangOpts() const
llvm::BumpPtrAllocator & getAllocator() const
Definition ASTContext.h:926
void eraseDeclAttrs(const Decl *D)
Erase the attributes corresponding to the given declaration.
void addedLocalImportDecl(ImportDecl *Import)
Notify the AST context that a new import declaration has been parsed or implicitly created within thi...
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
Module * getCurrentNamedModule() const
Get module under construction, nullptr if this is not a C++20 module.
AttrVec & getDeclAttrs(const Decl *D)
Retrieve the attributes for the given declaration.
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
Attr - This represents one attribute.
Definition Attr.h:46
bool isInherited() const
Definition Attr.h:101
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition Decl.h:4814
Pointer to a block type.
Definition TypeBase.h:3653
decl_iterator - Iterates through the declarations stored within this context.
Definition DeclBase.h:2374
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition DeclBase.h:1466
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition DeclBase.h:2120
udir_range using_directives() const
Returns iterator range [First, Last) of UsingDirectiveDecls stored within this context.
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC.
Definition DeclBase.h:2273
bool isFileContext() const
Definition DeclBase.h:2211
void setHasExternalVisibleStorage(bool ES=true) const
State whether this DeclContext has external storage for declarations visible in this context.
Definition DeclBase.h:2750
void makeDeclVisibleInContext(NamedDecl *D)
Makes a declaration visible within this context.
DeclContextLookupResult lookup_result
Definition DeclBase.h:2621
static std::pair< Decl *, Decl * > BuildDeclChain(ArrayRef< Decl * > Decls, bool FieldsAlreadyLoaded)
Build up a chain of declarations.
bool isTransparentContext() const
isTransparentContext - Determines whether this context is a "transparent" context,...
Decl * getNonClosureAncestor()
Find the nearest non-closure ancestor of this context, i.e.
ASTContext & getParentASTContext() const
Definition DeclBase.h:2149
bool isExternCXXContext() const
Determines whether this context or some of its ancestors is a linkage specification context that spec...
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
bool InEnclosingNamespaceSetOf(const DeclContext *NS) const
Test if this context is part of the enclosing namespace set of the context NS, as defined in C++0x [n...
bool isClosure() const
Definition DeclBase.h:2153
DeclContext * getLexicalParent()
getLexicalParent - Returns the containing lexical DeclContext.
Definition DeclBase.h:2136
bool isNamespace() const
Definition DeclBase.h:2233
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
bool isLookupContext() const
Test whether the context supports looking up names.
Definition DeclBase.h:2206
const BlockDecl * getInnermostBlockDecl() const
Return this DeclContext if it is a BlockDecl.
bool hasExternalVisibleStorage() const
Whether this DeclContext has external storage containing additional declarations that are visible in ...
Definition DeclBase.h:2744
const char * getDeclKindName() const
Definition DeclBase.cpp:210
bool isTranslationUnit() const
Definition DeclBase.h:2216
bool isRecord() const
Definition DeclBase.h:2220
void collectAllContexts(SmallVectorImpl< DeclContext * > &Contexts)
Collects all of the declaration contexts that are semantically connected to this declaration context.
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
llvm::iterator_range< udir_iterator > udir_range
Definition DeclBase.h:2698
Decl * FirstDecl
FirstDecl - The first declaration stored within this declaration context.
Definition DeclBase.h:2090
DeclContext(Decl::Kind K)
void addDeclInternal(Decl *D)
Add the declaration D into this context, but suppress searches for external declarations with the sam...
bool containsDeclAndLoad(Decl *D) const
Checks whether a declaration is in this context.
void removeDecl(Decl *D)
Removes a declaration from this context.
void addDecl(Decl *D)
Add the declaration D into this context.
StoredDeclsMap * buildLookup()
Ensure the lookup structure is fully-built and return it.
bool hasValidDeclKind() const
Definition DeclBase.cpp:201
bool isStdNamespace() const
lookup_result noload_lookup(DeclarationName Name)
Find the declarations with the given name that are visible within this context; don't attempt to retr...
static bool classof(const Decl *D)
bool containsDecl(Decl *D) const
Checks whether a declaration is in this context.
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
Definition DeclBase.h:2732
DeclContext * getEnclosingNamespaceContext()
Retrieve the nearest enclosing namespace context.
friend class ExternalASTSource
For reconcileExternalVisibleStorage, CreateStoredDeclsMap, hasNeedToReconcileExternalVisibleStorage.
Definition DeclBase.h:1473
Decl * LastDecl
LastDecl - The last declaration stored within this declaration context.
Definition DeclBase.h:2096
FunctionDecl * getEnclosingFunction()
Cast this to a FunctionDecl if it is one, ignoring any intervening expansion statements.
decl_range noload_decls() const
noload_decls_begin/end - Iterate over the declarations stored in this context that are currently load...
Definition DeclBase.h:2425
FunctionDecl * castEnclosingFunction()
friend class DependentDiagnostic
For CreateStoredDeclsMap.
Definition DeclBase.h:1475
DeclContext * getPrimaryContext()
getPrimaryContext - There may be many different declarations of the same entity (including forward de...
RecordDecl * getOuterLexicalRecordContext()
Retrieve the outermost lexically enclosing record context.
bool decls_empty() const
bool isInlineNamespace() const
DeclContextBitfields DeclContextBits
Definition DeclBase.h:2049
bool isFunctionOrMethod() const
Returns true if this DeclContext is a function, Objective-C method, or block, or a DeclContext that c...
Definition DeclBase.h:2175
void setHasExternalLexicalStorage(bool ES=true) const
State whether this DeclContext has external storage for declarations lexically in this context.
Definition DeclBase.h:2738
DeclContext * getLookupParent()
Find the parent context of this context that will be used for unqualified name lookup.
StoredDeclsMap * LookupPtr
Pointer to the data structure used to lookup declarations within this context (or a DependentStoredDe...
Definition DeclBase.h:2037
bool isExternCContext() const
Determines whether this context or some of its ancestors is a linkage specification context that spec...
const LinkageSpecDecl * getExternCContext() const
Retrieve the nearest enclosing C linkage specification context.
bool Encloses(const DeclContext *DC) const
Determine whether this declaration context semantically encloses the declaration context DC.
void addHiddenDecl(Decl *D)
Add the declaration D to this context without modifying any lookup tables.
void localUncachedLookup(DeclarationName Name, SmallVectorImpl< NamedDecl * > &Results)
A simplistic name lookup mechanism that performs name lookup into this declaration context without co...
Decl::Kind getDeclKind() const
Definition DeclBase.h:2113
DeclContext * getNonTransparentContext()
decl_iterator decls_begin() const
bool LexicallyEncloses(const DeclContext *DC) const
Determine whether this declaration context lexically encloses the declaration context DC.
DeclContext * getEnclosingNonExpansionStatementContext()
Retrieve the innermost enclosing context that doesn't belong to an expansion statement.
unsigned getLocalDeclIndex() const
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
Decl()=delete
Decl * getMostRecentDecl()
Retrieve the most recent declaration that declares the same entity as this declaration (which may be ...
Definition DeclBase.h:1093
const DeclContext * getParentFunctionOrMethod(bool LexicalParent=false) const
If this decl is defined inside a function/method/block it returns the corresponding DeclContext,...
Definition DeclBase.cpp:344
bool isInStdNamespace() const
Definition DeclBase.cpp:453
bool isInCurrentModuleUnit() const
Whether this declaration comes from the same module unit being compiled.
TemplateDecl * getDescribedTemplate() const
If this is a declaration that describes some template, this method returns that template declaration.
Definition DeclBase.cpp:285
bool isTemplateDecl() const
returns true if this declaration is a template
Definition DeclBase.cpp:281
static void add(Kind k)
Definition DeclBase.cpp:248
Module * getTopLevelOwningNamedModule() const
Get the top level owning named module that owns this declaration if any.
Definition DeclBase.cpp:152
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
Definition DeclBase.h:1243
bool isModuleLocal() const
Whether this declaration was a local declaration to a C++20 named module.
bool isFromGlobalModule() const
Whether this declaration comes from global module.
T * getAttr() const
Definition DeclBase.h:581
static bool isFlexibleArrayMemberLike(const ASTContext &Context, const Decl *D, QualType Ty, LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel, bool IgnoreTemplateOrMacroSubstitution)
Whether it resembles a flexible array member.
Definition DeclBase.cpp:463
bool hasAttrs() const
Definition DeclBase.h:526
ASTContext & getASTContext() const LLVM_READONLY
Definition DeclBase.cpp:550
void setOwningModuleID(unsigned ID)
Set the owning module ID.
Definition DeclBase.cpp:126
void addAttr(Attr *A)
void setAttrs(const AttrVec &Attrs)
Definition DeclBase.h:528
bool hasLocalOwningModuleStorage() const
Definition DeclBase.cpp:165
bool isFunctionPointerType() const
bool isInNamedModule() const
Whether this declaration comes from a named module.
virtual ~Decl()
ExternalSourceSymbolAttr * getExternalSourceSymbolAttr() const
Looks on this and related declarations for an applicable external source symbol attribute.
Definition DeclBase.cpp:616
bool isWeakImported() const
Determine whether this is a weak-imported symbol.
Definition DeclBase.cpp:876
ModuleOwnershipKind getModuleOwnershipKind() const
Get the kind of module ownership for this declaration.
Definition DeclBase.h:893
bool isParameterPack() const
Whether this declaration is a parameter pack.
Definition DeclBase.cpp:266
ASTMutationListener * getASTMutationListener() const
Definition DeclBase.cpp:560
unsigned getMaxAlignment() const
getMaxAlignment - return the maximum alignment specified by attributes on this decl,...
Definition DeclBase.cpp:564
AvailabilityResult getAvailability(std::string *Message=nullptr, VersionTuple EnclosingVersion=VersionTuple(), StringRef *RealizedPlatform=nullptr) const
Determine the availability of the given declaration.
Definition DeclBase.cpp:779
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
Definition DeclBase.cpp:178
Kind
Lists the kind of concrete classes of Decl.
Definition DeclBase.h:89
static unsigned getIdentifierNamespaceForKind(Kind DK)
Definition DeclBase.cpp:896
virtual Stmt * getBody() const
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
Definition DeclBase.h:1104
void markUsed(ASTContext &C)
Mark the declaration used, in the sense of odr-use.
Definition DeclBase.cpp:594
bool isFileContextDecl() const
Definition DeclBase.cpp:458
static Decl * castFromDeclContext(const DeclContext *)
Decl * getNextDeclInContext()
Definition DeclBase.h:453
bool isTemplated() const
Determine whether this declaration is a templated entity (whether it is.
Definition DeclBase.cpp:308
bool isInExportDeclContext() const
Whether this declaration was exported in a lexical context.
SourceLocation getBodyRBrace() const
getBodyRBrace - Gets the right brace of the body, if a body exists.
int64_t getID() const
bool isReferenced() const
Whether any declaration of this entity was referenced.
Definition DeclBase.cpp:604
const FunctionType * getFunctionType(bool BlocksToo=true) const
Looks through the Decl's underlying type to extract a FunctionType when possible.
bool isInAnotherModuleUnit() const
Whether this declaration comes from another module unit.
llvm::PointerIntPair< Decl *, 3, ModuleOwnershipKind > NextInContextAndBits
The next declaration within the same lexical DeclContext.
Definition DeclBase.h:257
Module * getOwningModule() const
Get the module that owns this declaration (for visibility purposes).
Definition DeclBase.h:854
unsigned getTemplateDepth() const
Determine the number of levels of template parameter surrounding this declaration.
Definition DeclBase.cpp:320
bool isFromExplicitGlobalModule() const
Whether this declaration comes from explicit global module.
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
Definition DeclBase.cpp:273
bool canBeWeakImported(bool &IsDefinition) const
Determines whether this symbol can be weak-imported, e.g., whether it would be well-formed to add the...
Definition DeclBase.cpp:847
void dropAttrs()
static DeclContext * castToDeclContext(const Decl *)
const TemplateParameterList * getDescribedTemplateParams() const
If this is a declaration that describes some template or partial specialization, this returns the cor...
Definition DeclBase.cpp:298
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
Definition DeclBase.h:805
bool isInLocalScopeForInstantiation() const
Determine whether a substitution into this declaration would occur as part of a substitution into a d...
Definition DeclBase.cpp:426
const Attr * getDefiningAttr() const
Return this declaration's defining attribute if it has one.
Definition DeclBase.cpp:642
bool isTemplateParameter() const
isTemplateParameter - Determines whether this declaration is a template parameter.
Definition DeclBase.h:2829
DeclContext * getNonTransparentDeclContext()
Return the non transparent context.
Decl * getNonClosureContext()
Find the innermost non-closure ancestor of this declaration, walking up through blocks,...
bool isInvalidDecl() const
Definition DeclBase.h:596
unsigned getIdentifierNamespace() const
Definition DeclBase.h:906
bool hasDefiningAttr() const
Return true if this declaration has an attribute which acts as definition of the entity,...
Definition DeclBase.cpp:637
bool isLocalExternDecl() const
Determine whether this is a block-scope declaration with linkage.
Definition DeclBase.h:1186
void setAccess(AccessSpecifier AS)
Definition DeclBase.h:510
const char * getDeclKindName() const
Definition DeclBase.cpp:169
@ IDNS_Ordinary
Ordinary names.
Definition DeclBase.h:144
@ IDNS_Type
Types, declared with 'struct foo', typedefs, etc.
Definition DeclBase.h:130
@ IDNS_OMPReduction
This declaration is an OpenMP user defined reduction construction.
Definition DeclBase.h:178
@ IDNS_Label
Labels, declared with 'x:' and referenced with 'goto x'.
Definition DeclBase.h:117
@ IDNS_Member
Members, declared with object declarations within tag definitions.
Definition DeclBase.h:136
@ IDNS_OMPMapper
This declaration is an OpenMP user defined mapper.
Definition DeclBase.h:181
@ IDNS_ObjCProtocol
Objective C @protocol.
Definition DeclBase.h:147
@ IDNS_Namespace
Namespaces, declared with 'namespace foo {}'.
Definition DeclBase.h:140
@ IDNS_Using
This declaration is a using declaration.
Definition DeclBase.h:163
@ IDNS_Tag
Tags, declared with 'struct foo;' and referenced with 'struct foo'.
Definition DeclBase.h:125
bool isTemplateParameterPack() const
isTemplateParameter - Determines whether this declaration is a template parameter pack.
Definition DeclBase.cpp:256
void setLocalOwningModule(Module *M)
Definition DeclBase.h:841
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition DeclBase.h:1066
void setIsUsed()
Set whether the declaration is used, in the sense of odr-use.
Definition DeclBase.h:616
unsigned Access
Access - Used by C++ decls for the access specifier.
Definition DeclBase.h:344
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
Definition DeclBase.cpp:579
DeclContext * getDeclContext()
Definition DeclBase.h:456
attr_range attrs() const
Definition DeclBase.h:543
bool isInAnonymousNamespace() const
Definition DeclBase.cpp:443
static void EnableStatistics()
Definition DeclBase.cpp:220
TranslationUnitDecl * getTranslationUnitDecl()
Definition DeclBase.cpp:535
VersionTuple getVersionIntroduced() const
Retrieve the version of the target platform in which this declaration was introduced.
Definition DeclBase.cpp:832
bool hasOwningModule() const
Is this declaration owned by some module?
Definition DeclBase.h:849
bool isFromHeaderUnit() const
Whether this declaration comes from a header unit.
static void PrintStats()
Definition DeclBase.cpp:224
AttrVec & getAttrs()
Definition DeclBase.h:532
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
Definition DeclBase.cpp:385
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition DeclBase.h:935
bool hasAttr() const
Definition DeclBase.h:585
friend class DeclContext
Definition DeclBase.h:260
void setLexicalDeclContext(DeclContext *DC)
Definition DeclBase.cpp:389
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition DeclBase.h:995
@ VisiblePromoted
This declaration has an owning module, and is not visible to the current TU but we promoted it to be ...
Definition DeclBase.h:237
@ VisibleWhenImported
This declaration has an owning module, and is visible when that module is imported.
Definition DeclBase.h:229
@ ReachableWhenImported
This declaration has an owning module, and is visible to lookups that occurs within that module.
Definition DeclBase.h:242
Kind getKind() const
Definition DeclBase.h:450
void setModuleOwnershipKind(ModuleOwnershipKind MOK)
Set whether this declaration is hidden from name lookup.
Definition DeclBase.h:898
const LangOptions & getLangOpts() const LLVM_READONLY
Helper to get the language options from the ASTContext.
Definition DeclBase.cpp:556
GlobalDeclID getGlobalID() const
Retrieve the global declaration ID associated with this declaration, which specifies where this Decl ...
Definition DeclBase.cpp:110
unsigned getOwningModuleID() const
Retrieve the global ID of the module that owns this particular declaration.
Definition DeclBase.cpp:118
bool shouldEmitInExternalSource() const
Whether the definition of the declaration should be emitted in external sources.
The name of a declaration.
A dependently-generated diagnostic.
static DependentDiagnostic * Create(ASTContext &Context, DeclContext *Parent, AccessNonce _, SourceLocation Loc, bool IsMemberAccess, AccessSpecifier AS, NamedDecl *TargetDecl, CXXRecordDecl *NamingClass, QualType BaseObjectType, const PartialDiagnostic &PDiag)
This represents one expression.
Definition Expr.h:113
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition Expr.cpp:283
RAII class for safely pairing a StartedDeserializing call with FinishedDeserializing.
Abstract interface for external sources of AST nodes.
virtual ExtKind hasExternalDefinitions(const Decl *D)
static DeclContextLookupResult SetExternalVisibleDeclsForName(const DeclContext *DC, DeclarationName Name, ArrayRef< NamedDecl * > Decls)
static DeclContextLookupResult SetNoExternalVisibleDeclsForName(const DeclContext *DC, DeclarationName Name)
virtual Module * getModule(unsigned ID)
Retrieve the module that corresponds to the given module ID.
virtual bool FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name, const DeclContext *OriginalDC)
Find all declarations with the given name in the given context, and add them to the context by callin...
Represents a member of a struct/union/class.
Definition Decl.h:3299
Represents a function declaration or definition.
Definition Decl.h:2059
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition TypeBase.h:4612
One of these records is kept for each identifier that is lexed.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
StringRef getName() const
Return the actual identifier string.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
bool trackLocalOwningModule() const
Do we need to track the owning module for a local declaration?
Represents a linkage specification.
Definition DeclCXX.h:3045
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition TypeBase.h:3751
Describes a module or submodule.
Definition Module.h:340
bool isExplicitGlobalModule() const
Definition Module.h:444
bool isGlobalModule() const
Does this Module scope describe a fragment of the global module within some C++ module.
Definition Module.h:441
bool isHeaderUnit() const
Is this module a header unit.
Definition Module.h:890
bool isNamedModule() const
Does this Module is a named module of a standard named module?
Definition Module.h:426
Module * getTopLevelModule()
Retrieve the top-level module for this (sub)module, which may be this module.
Definition Module.h:943
This represents a decl that may have a name.
Definition Decl.h:275
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition Decl.h:341
Represent a C++ namespace.
Definition Decl.h:593
The basic abstraction for the target Objective-C runtime.
Definition ObjCRuntime.h:28
bool hasWeakClassImport() const
Does this runtime support weakly importing classes?
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition TypeBase.h:3403
void print(raw_ostream &OS) const override
Definition DeclBase.cpp:358
A (possibly-)qualified type.
Definition TypeBase.h:938
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition TypeBase.h:1005
QualType getCanonicalType() const
Definition TypeBase.h:8498
Represents a struct/union/class.
Definition Decl.h:4464
specific_decl_iterator< FieldDecl > field_iterator
Definition Decl.h:4664
Base for LValueReferenceType and RValueReferenceType.
Definition TypeBase.h:3678
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
void print(raw_ostream &OS, const SourceManager &SM) const
Stmt - This represents one statement.
Definition Stmt.h:85
An array of decls optimized for the common case of only containing one entry.
void addOrReplaceDecl(NamedDecl *D)
If this is a redeclaration of an existing decl, replace the old one with D.
void prependDeclNoReplace(NamedDecl *D)
Add a declaration to the list without checking if it replaces anything.
void replaceExternalDecls(ArrayRef< NamedDecl * > Decls)
DeclContext::lookup_result getLookupResult() const
Return the list of all the decls.
static void DestroyAll(StoredDeclsMap *Map, bool Dependent)
The base class of all kinds of template declarations (e.g., class, function, etc.).
Stores a list of template parameters for a TemplateDecl and its derived classes.
The top declaration context.
Definition Decl.h:106
ASTContext & getASTContext() const
Definition Decl.h:142
Base wrapper for a particular "section" of type source info.
Definition TypeLoc.h:59
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Definition TypeLoc.h:89
T getAsAdjusted() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Definition TypeLoc.h:2766
A container of type source information.
Definition TypeBase.h:8417
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition TypeLoc.h:267
bool isBlockPointerType() const
Definition TypeBase.h:8703
bool isFunctionReferenceType() const
Definition TypeBase.h:8757
bool isFunctionPointerType() const
Definition TypeBase.h:8750
const T * castAs() const
Member-template castAs<specific type>.
Definition TypeBase.h:9366
bool isMemberFunctionPointerType() const
Definition TypeBase.h:8768
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9299
Wrapper for source info for typedefs.
Definition TypeLoc.h:777
Represents C++ using-directive.
Definition DeclCXX.h:3126
specific_attr_iterator - Iterates over a subrange of an AttrVec, only providing attributes that are o...
Defines the clang::TargetInfo interface.
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
Definition Address.h:330
@ CPlusPlus
LinkageSpecLanguageIDs
Represents the language in a linkage specification.
Definition DeclCXX.h:3037
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
@ AS_public
Definition Specifiers.h:128
@ AS_none
Definition Specifiers.h:131
SmallVector< Attr *, 4 > AttrVec
AttrVec - A vector of Attr, which is how they are stored on the AST.
@ Dependent
Parse the block as a dependent block, which may be used in some template instantiations but not other...
Definition Parser.h:142
@ Internal
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
Definition Linkage.h:35
bool isLambdaCallOperator(const CXXMethodDecl *MD)
Definition ASTLambda.h:28
@ Result
The result type of a method or function.
Definition TypeBase.h:906
const FunctionProtoType * T
@ ExplicitInstantiation
We are parsing an explicit instantiation.
Definition Parser.h:85
@ FunctionTemplate
The name was classified as a function template name.
Definition Sema.h:581
@ Concept
The name was classified as a concept name.
Definition Sema.h:585
@ VarTemplate
The name was classified as a variable template name.
Definition Sema.h:579
AvailabilityResult
Captures the result of checking the availability of a declaration.
Definition DeclBase.h:72
@ AR_NotYetIntroduced
Definition DeclBase.h:74
@ AR_Available
Definition DeclBase.h:73
@ AR_Deprecated
Definition DeclBase.h:75
@ AR_Unavailable
Definition DeclBase.h:76
U cast(CodeGen::Address addr)
Definition Address.h:327
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:6028
UsingDirectiveDecl * operator*() const