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