Thanks to visit codestin.com
Credit goes to clang.llvm.org

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