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