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.
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
145}
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())
379 setLocalOwningModule(cast<Decl>(DC)->getOwningModule());
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
526}
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
536}
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
612 return hasAttr<AliasAttr>() || hasAttr<IFuncAttr>() ||
613 hasAttr<LoaderUninitializedAttr>();
614}
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 OMPAllocate:
990 case OMPRequires:
991 case OMPCapturedExpr:
992 case Empty:
993 case LifetimeExtendedTemporary:
994 case RequiresExprBody:
995 case ImplicitConceptSpecialization:
996 case OpenACCDeclare:
997 case OpenACCRoutine:
998 // Never looked up by name.
999 return 0;
1000 }
1001
1002 llvm_unreachable("Invalid DeclKind!");
1003}
1004
1005void Decl::setAttrsImpl(const AttrVec &attrs, ASTContext &Ctx) {
1006 assert(!HasAttrs && "Decl already contains attrs.");
1007
1008 AttrVec &AttrBlank = Ctx.getDeclAttrs(this);
1009 assert(AttrBlank.empty() && "HasAttrs was wrong?");
1010
1011 AttrBlank = attrs;
1012 HasAttrs = true;
1013}
1014
1016 if (!HasAttrs) return;
1017
1018 HasAttrs = false;
1020}
1021
1023 if (!hasAttrs()) {
1024 setAttrs(AttrVec(1, A));
1025 return;
1026 }
1027
1028 AttrVec &Attrs = getAttrs();
1029 if (!A->isInherited()) {
1030 Attrs.push_back(A);
1031 return;
1032 }
1033
1034 // Attribute inheritance is processed after attribute parsing. To keep the
1035 // order as in the source code, add inherited attributes before non-inherited
1036 // ones.
1037 auto I = Attrs.begin(), E = Attrs.end();
1038 for (; I != E; ++I) {
1039 if (!(*I)->isInherited())
1040 break;
1041 }
1042 Attrs.insert(I, A);
1043}
1044
1045const AttrVec &Decl::getAttrs() const {
1046 assert(HasAttrs && "No attrs to get!");
1047 return getASTContext().getDeclAttrs(this);
1048}
1049
1051 Decl::Kind DK = D->getDeclKind();
1052 switch (DK) {
1053#define DECL(NAME, BASE)
1054#define DECL_CONTEXT(NAME) \
1055 case Decl::NAME: \
1056 return static_cast<NAME##Decl *>(const_cast<DeclContext *>(D));
1057#include "clang/AST/DeclNodes.inc"
1058 default:
1059 llvm_unreachable("a decl that inherits DeclContext isn't handled");
1060 }
1061}
1062
1064 Decl::Kind DK = D->getKind();
1065 switch(DK) {
1066#define DECL(NAME, BASE)
1067#define DECL_CONTEXT(NAME) \
1068 case Decl::NAME: \
1069 return static_cast<NAME##Decl *>(const_cast<Decl *>(D));
1070#include "clang/AST/DeclNodes.inc"
1071 default:
1072 llvm_unreachable("a decl that inherits DeclContext isn't handled");
1073 }
1074}
1075
1077 // Special handling of FunctionDecl to avoid de-serializing the body from PCH.
1078 // FunctionDecl stores EndRangeLoc for this purpose.
1079 if (const auto *FD = dyn_cast<FunctionDecl>(this)) {
1080 const FunctionDecl *Definition;
1081 if (FD->hasBody(Definition))
1082 return Definition->getSourceRange().getEnd();
1083 return {};
1084 }
1085
1086 if (Stmt *Body = getBody())
1087 return Body->getSourceRange().getEnd();
1088
1089 return {};
1090}
1091
1092bool Decl::AccessDeclContextCheck() const {
1093#ifndef NDEBUG
1094 // Suppress this check if any of the following hold:
1095 // 1. this is the translation unit (and thus has no parent)
1096 // 2. this is a template parameter (and thus doesn't belong to its context)
1097 // 3. this is a non-type template parameter
1098 // 4. the context is not a record
1099 // 5. it's invalid
1100 // 6. it's a C++0x static_assert.
1101 // 7. it's a block literal declaration
1102 // 8. it's a temporary with lifetime extended due to being default value.
1103 if (isa<TranslationUnitDecl>(this) || isa<TemplateTypeParmDecl>(this) ||
1104 isa<NonTypeTemplateParmDecl>(this) || !getDeclContext() ||
1105 !isa<CXXRecordDecl>(getDeclContext()) || isInvalidDecl() ||
1106 isa<StaticAssertDecl>(this) || isa<BlockDecl>(this) ||
1107 // FIXME: a ParmVarDecl can have ClassTemplateSpecialization
1108 // as DeclContext (?).
1109 isa<ParmVarDecl>(this) ||
1110 // FIXME: a ClassTemplateSpecialization or CXXRecordDecl can have
1111 // AS_none as access specifier.
1112 isa<CXXRecordDecl>(this) || isa<LifetimeExtendedTemporaryDecl>(this))
1113 return true;
1114
1115 assert(Access != AS_none &&
1116 "Access specifier is AS_none inside a record decl");
1117#endif
1118 return true;
1119}
1120
1122 const DeclContext *DC = getLexicalDeclContext();
1123
1124 while (DC && !isa<ExportDecl>(DC))
1125 DC = DC->getLexicalParent();
1126
1127 return isa_and_nonnull<ExportDecl>(DC);
1128}
1129
1131 if (isa<NamespaceDecl, TranslationUnitDecl>(this))
1132 return false;
1133 auto *M = getOwningModule();
1134 return M && M->isNamedModule() &&
1136}
1137
1139 auto *M = getOwningModule();
1140
1141 if (!M)
1142 return false;
1143
1144 // FIXME or NOTE: maybe we need to be clear about the semantics
1145 // of clang header modules. e.g., if this lives in a clang header
1146 // module included by the current unit, should we return false
1147 // here?
1148 //
1149 // This is clear for header units as the specification says the
1150 // header units live in a synthesised translation unit. So we
1151 // can return false here.
1152 M = M->getTopLevelModule();
1153 if (!M->isNamedModule())
1154 return false;
1155
1156 return M != getASTContext().getCurrentNamedModule();
1157}
1158
1160 auto *M = getOwningModule();
1161
1162 if (!M || !M->isNamedModule())
1163 return false;
1164
1165 return M == getASTContext().getCurrentNamedModule();
1166}
1167
1170 if (!Source)
1171 return false;
1172
1174}
1175
1178}
1179
1182}
1183
1186}
1187
1190}
1191
1192static Decl::Kind getKind(const Decl *D) { return D->getKind(); }
1193static Decl::Kind getKind(const DeclContext *DC) { return DC->getDeclKind(); }
1194
1195int64_t Decl::getID() const {
1196 return getASTContext().getAllocator().identifyKnownAlignedObject<Decl>(this);
1197}
1198
1199const FunctionType *Decl::getFunctionType(bool BlocksToo) const {
1200 QualType Ty;
1201 if (const auto *D = dyn_cast<ValueDecl>(this))
1202 Ty = D->getType();
1203 else if (const auto *D = dyn_cast<TypedefNameDecl>(this))
1204 Ty = D->getUnderlyingType();
1205 else
1206 return nullptr;
1207
1208 if (Ty.isNull()) {
1209 // BindingDecls do not have types during parsing, so return nullptr. This is
1210 // the only known case where `Ty` is null.
1211 assert(isa<BindingDecl>(this));
1212 return nullptr;
1213 }
1214
1215 if (Ty->isFunctionPointerType())
1216 Ty = Ty->castAs<PointerType>()->getPointeeType();
1217 else if (Ty->isMemberFunctionPointerType())
1219 else if (Ty->isFunctionReferenceType())
1220 Ty = Ty->castAs<ReferenceType>()->getPointeeType();
1221 else if (BlocksToo && Ty->isBlockPointerType())
1222 Ty = Ty->castAs<BlockPointerType>()->getPointeeType();
1223
1224 return Ty->getAs<FunctionType>();
1225}
1226
1228 QualType Ty;
1229 if (const auto *D = dyn_cast<ValueDecl>(this))
1230 Ty = D->getType();
1231 else if (const auto *D = dyn_cast<TypedefNameDecl>(this))
1232 Ty = D->getUnderlyingType();
1233 else
1234 return false;
1235
1237}
1238
1240 assert(getDeclContext());
1242}
1243
1244/// Starting at a given context (a Decl or DeclContext), look for a
1245/// code context that is not a closure (a lambda, block, etc.).
1246template <class T> static Decl *getNonClosureContext(T *D) {
1247 if (getKind(D) == Decl::CXXMethod) {
1248 auto *MD = cast<CXXMethodDecl>(D);
1249 if (MD->getOverloadedOperator() == OO_Call &&
1250 MD->getParent()->isLambda())
1251 return getNonClosureContext(MD->getParent()->getParent());
1252 return MD;
1253 }
1254 if (auto *FD = dyn_cast<FunctionDecl>(D))
1255 return FD;
1256 if (auto *MD = dyn_cast<ObjCMethodDecl>(D))
1257 return MD;
1258 if (auto *BD = dyn_cast<BlockDecl>(D))
1259 return getNonClosureContext(BD->getParent());
1260 if (auto *CD = dyn_cast<CapturedDecl>(D))
1261 return getNonClosureContext(CD->getParent());
1262 if (auto *OFD = dyn_cast<OutlinedFunctionDecl>(D))
1263 return getNonClosureContext(OFD->getParent());
1264 return nullptr;
1265}
1266
1268 return ::getNonClosureContext(this);
1269}
1270
1272 return ::getNonClosureContext(this);
1273}
1274
1275//===----------------------------------------------------------------------===//
1276// DeclContext Implementation
1277//===----------------------------------------------------------------------===//
1278
1280 DeclContextBits.DeclKind = K;
1283 setNeedToReconcileExternalVisibleStorage(false);
1284 setHasLazyLocalLexicalLookups(false);
1285 setHasLazyExternalLexicalLookups(false);
1286 setUseQualifiedLookup(false);
1287}
1288
1290 Decl::Kind DK = D->getKind();
1291 switch (DK) {
1292#define DECL(NAME, BASE)
1293#define DECL_CONTEXT(NAME) case Decl::NAME:
1294#include "clang/AST/DeclNodes.inc"
1295 return true;
1296 default:
1297 return false;
1298 }
1299}
1300
1301DeclContext::~DeclContext() = default;
1302
1303/// Find the parent context of this context that will be
1304/// used for unqualified name lookup.
1305///
1306/// Generally, the parent lookup context is the semantic context. However, for
1307/// a friend function the parent lookup context is the lexical context, which
1308/// is the class in which the friend is declared.
1310 // FIXME: Find a better way to identify friends.
1311 if (isa<FunctionDecl>(this))
1314 return getLexicalParent();
1315
1316 // A lookup within the call operator of a lambda never looks in the lambda
1317 // class; instead, skip to the context in which that closure type is
1318 // declared.
1319 if (isLambdaCallOperator(this))
1320 return getParent()->getParent();
1321
1322 return getParent();
1323}
1324
1326 const DeclContext *Ctx = this;
1327
1328 do {
1329 if (Ctx->isClosure())
1330 return cast<BlockDecl>(Ctx);
1331 Ctx = Ctx->getParent();
1332 } while (Ctx);
1333
1334 return nullptr;
1335}
1336
1338 return isNamespace() &&
1339 cast<NamespaceDecl>(this)->isInline();
1340}
1341
1343 if (!isNamespace())
1344 return false;
1345
1346 const auto *ND = cast<NamespaceDecl>(this);
1347 if (ND->isInline()) {
1348 return ND->getParent()->isStdNamespace();
1349 }
1350
1352 return false;
1353
1354 const IdentifierInfo *II = ND->getIdentifier();
1355 return II && II->isStr("std");
1356}
1357
1359 if (isFileContext())
1360 return false;
1361
1362 if (isa<ClassTemplatePartialSpecializationDecl>(this))
1363 return true;
1364
1365 if (const auto *Record = dyn_cast<CXXRecordDecl>(this)) {
1366 if (Record->getDescribedClassTemplate())
1367 return true;
1368
1369 if (Record->isDependentLambda())
1370 return true;
1371 if (Record->isNeverDependentLambda())
1372 return false;
1373 }
1374
1375 if (const auto *Function = dyn_cast<FunctionDecl>(this)) {
1376 if (Function->getDescribedFunctionTemplate())
1377 return true;
1378
1379 // Friend function declarations are dependent if their *lexical*
1380 // context is dependent.
1381 if (cast<Decl>(this)->getFriendObjectKind())
1383 }
1384
1385 // FIXME: A variable template is a dependent context, but is not a
1386 // DeclContext. A context within it (such as a lambda-expression)
1387 // should be considered dependent.
1388
1389 return getParent() && getParent()->isDependentContext();
1390}
1391
1393 if (getDeclKind() == Decl::Enum)
1394 return !cast<EnumDecl>(this)->isScoped();
1395
1396 return isa<LinkageSpecDecl, ExportDecl, HLSLBufferDecl>(this);
1397}
1398
1399static bool isLinkageSpecContext(const DeclContext *DC,
1401 while (DC->getDeclKind() != Decl::TranslationUnit) {
1402 if (DC->getDeclKind() == Decl::LinkageSpec)
1403 return cast<LinkageSpecDecl>(DC)->getLanguage() == ID;
1404 DC = DC->getLexicalParent();
1405 }
1406 return false;
1407}
1408
1411}
1412
1414 const DeclContext *DC = this;
1415 while (DC->getDeclKind() != Decl::TranslationUnit) {
1416 if (DC->getDeclKind() == Decl::LinkageSpec &&
1417 cast<LinkageSpecDecl>(DC)->getLanguage() == LinkageSpecLanguageIDs::C)
1418 return cast<LinkageSpecDecl>(DC);
1419 DC = DC->getLexicalParent();
1420 }
1421 return nullptr;
1422}
1423
1426}
1427
1428bool DeclContext::Encloses(const DeclContext *DC) const {
1429 if (getPrimaryContext() != this)
1430 return getPrimaryContext()->Encloses(DC);
1431
1432 for (; DC; DC = DC->getParent())
1433 if (!isa<LinkageSpecDecl, ExportDecl>(DC) &&
1434 DC->getPrimaryContext() == this)
1435 return true;
1436 return false;
1437}
1438
1440 if (getPrimaryContext() != this)
1442
1443 for (; DC; DC = DC->getLexicalParent())
1444 if (!isa<LinkageSpecDecl, ExportDecl>(DC) &&
1445 DC->getPrimaryContext() == this)
1446 return true;
1447 return false;
1448}
1449
1451 DeclContext *DC = this;
1452 while (DC->isTransparentContext()) {
1453 DC = DC->getParent();
1454 assert(DC && "All transparent contexts should have a parent!");
1455 }
1456 return DC;
1457}
1458
1460 switch (getDeclKind()) {
1461 case Decl::ExternCContext:
1462 case Decl::LinkageSpec:
1463 case Decl::Export:
1464 case Decl::TopLevelStmt:
1465 case Decl::Block:
1466 case Decl::Captured:
1467 case Decl::OutlinedFunction:
1468 case Decl::OMPDeclareReduction:
1469 case Decl::OMPDeclareMapper:
1470 case Decl::RequiresExprBody:
1471 // There is only one DeclContext for these entities.
1472 return this;
1473
1474 case Decl::HLSLBuffer:
1475 // Each buffer, even with the same name, is a distinct construct.
1476 // Multiple buffers with the same name are allowed for backward
1477 // compatibility.
1478 // As long as buffers have unique resource bindings the names don't matter.
1479 // The names get exposed via the CPU-side reflection API which
1480 // supports querying bindings, so we cannot remove them.
1481 return this;
1482
1483 case Decl::TranslationUnit:
1484 return static_cast<TranslationUnitDecl *>(this)->getFirstDecl();
1485 case Decl::Namespace:
1486 return static_cast<NamespaceDecl *>(this)->getFirstDecl();
1487
1488 case Decl::ObjCMethod:
1489 return this;
1490
1491 case Decl::ObjCInterface:
1492 if (auto *OID = dyn_cast<ObjCInterfaceDecl>(this))
1493 if (auto *Def = OID->getDefinition())
1494 return Def;
1495 return this;
1496
1497 case Decl::ObjCProtocol:
1498 if (auto *OPD = dyn_cast<ObjCProtocolDecl>(this))
1499 if (auto *Def = OPD->getDefinition())
1500 return Def;
1501 return this;
1502
1503 case Decl::ObjCCategory:
1504 return this;
1505
1506 case Decl::ObjCImplementation:
1507 case Decl::ObjCCategoryImpl:
1508 return this;
1509
1510 // If this is a tag type that has a definition or is currently
1511 // being defined, that definition is our primary context.
1512 case Decl::ClassTemplatePartialSpecialization:
1513 case Decl::ClassTemplateSpecialization:
1514 case Decl::CXXRecord:
1515 return cast<CXXRecordDecl>(this)->getDefinitionOrSelf();
1516 case Decl::Record:
1517 case Decl::Enum:
1518 return cast<TagDecl>(this)->getDefinitionOrSelf();
1519
1520 default:
1521 assert(getDeclKind() >= Decl::firstFunction &&
1522 getDeclKind() <= Decl::lastFunction && "Unknown DeclContext kind");
1523 return this;
1524 }
1525}
1526
1527template <typename T>
1530 for (T *D = Self->getMostRecentDecl(); D; D = D->getPreviousDecl())
1531 Contexts.push_back(D);
1532
1533 std::reverse(Contexts.begin(), Contexts.end());
1534}
1535
1537 Contexts.clear();
1538
1539 Decl::Kind Kind = getDeclKind();
1540
1541 if (Kind == Decl::TranslationUnit)
1542 collectAllContextsImpl(static_cast<TranslationUnitDecl *>(this), Contexts);
1543 else if (Kind == Decl::Namespace)
1544 collectAllContextsImpl(static_cast<NamespaceDecl *>(this), Contexts);
1545 else
1546 Contexts.push_back(this);
1547}
1548
1549std::pair<Decl *, Decl *>
1551 bool FieldsAlreadyLoaded) {
1552 // Build up a chain of declarations via the Decl::NextInContextAndBits field.
1553 Decl *FirstNewDecl = nullptr;
1554 Decl *PrevDecl = nullptr;
1555 for (auto *D : Decls) {
1556 if (FieldsAlreadyLoaded && isa<FieldDecl>(D))
1557 continue;
1558
1559 if (PrevDecl)
1560 PrevDecl->NextInContextAndBits.setPointer(D);
1561 else
1562 FirstNewDecl = D;
1563
1564 PrevDecl = D;
1565 }
1566
1567 return std::make_pair(FirstNewDecl, PrevDecl);
1568}
1569
1570/// We have just acquired external visible storage, and we already have
1571/// built a lookup map. For every name in the map, pull in the new names from
1572/// the external storage.
1573void DeclContext::reconcileExternalVisibleStorage() const {
1574 assert(hasNeedToReconcileExternalVisibleStorage() && LookupPtr);
1575 setNeedToReconcileExternalVisibleStorage(false);
1576
1577 for (auto &Lookup : *LookupPtr)
1578 Lookup.second.setHasExternalDecls();
1579}
1580
1581/// Load the declarations within this lexical storage from an
1582/// external source.
1583/// \return \c true if any declarations were added.
1584bool
1585DeclContext::LoadLexicalDeclsFromExternalStorage() const {
1587 assert(hasExternalLexicalStorage() && Source && "No external storage?");
1588
1589 // Notify that we have a DeclContext that is initializing.
1590 ExternalASTSource::Deserializing ADeclContext(Source);
1591
1592 // Load the external declarations, if any.
1595 Source->FindExternalLexicalDecls(this, Decls);
1596
1597 if (Decls.empty())
1598 return false;
1599
1600 // We may have already loaded just the fields of this record, in which case
1601 // we need to ignore them.
1602 bool FieldsAlreadyLoaded = false;
1603 if (const auto *RD = dyn_cast<RecordDecl>(this))
1604 FieldsAlreadyLoaded = RD->hasLoadedFieldsFromExternalStorage();
1605
1606 // Splice the newly-read declarations into the beginning of the list
1607 // of declarations.
1608 Decl *ExternalFirst, *ExternalLast;
1609 std::tie(ExternalFirst, ExternalLast) =
1610 BuildDeclChain(Decls, FieldsAlreadyLoaded);
1611 ExternalLast->NextInContextAndBits.setPointer(FirstDecl);
1612 FirstDecl = ExternalFirst;
1613 if (!LastDecl)
1614 LastDecl = ExternalLast;
1615 return true;
1616}
1617
1620 DeclarationName Name) {
1621 ASTContext &Context = DC->getParentASTContext();
1622 StoredDeclsMap *Map;
1623 if (!(Map = DC->LookupPtr))
1624 Map = DC->CreateStoredDeclsMap(Context);
1625 if (DC->hasNeedToReconcileExternalVisibleStorage())
1626 DC->reconcileExternalVisibleStorage();
1627
1628 (*Map)[Name].removeExternalDecls();
1629
1631}
1632
1635 DeclarationName Name,
1636 ArrayRef<NamedDecl*> Decls) {
1637 ASTContext &Context = DC->getParentASTContext();
1638 StoredDeclsMap *Map;
1639 if (!(Map = DC->LookupPtr))
1640 Map = DC->CreateStoredDeclsMap(Context);
1641 if (DC->hasNeedToReconcileExternalVisibleStorage())
1642 DC->reconcileExternalVisibleStorage();
1643
1644 StoredDeclsList &List = (*Map)[Name];
1645 List.replaceExternalDecls(Decls);
1646 return List.getLookupResult();
1647}
1648
1651 LoadLexicalDeclsFromExternalStorage();
1652 return decl_iterator(FirstDecl);
1653}
1654
1657 LoadLexicalDeclsFromExternalStorage();
1658
1659 return !FirstDecl;
1660}
1661
1663 return (D->getLexicalDeclContext() == this &&
1664 (D->NextInContextAndBits.getPointer() || D == LastDecl));
1665}
1666
1669 LoadLexicalDeclsFromExternalStorage();
1670 return containsDecl(D);
1671}
1672
1673/// shouldBeHidden - Determine whether a declaration which was declared
1674/// within its semantic context should be invisible to qualified name lookup.
1676 // Skip unnamed declarations.
1677 if (!D->getDeclName())
1678 return true;
1679
1680 // Skip entities that can't be found by name lookup into a particular
1681 // context.
1682 if ((D->getIdentifierNamespace() == 0 && !isa<UsingDirectiveDecl>(D)) ||
1684 return true;
1685
1686 // Skip friends and local extern declarations unless they're the first
1687 // declaration of the entity.
1688 if ((D->isLocalExternDecl() || D->getFriendObjectKind()) &&
1689 D != D->getCanonicalDecl())
1690 return true;
1691
1692 // Skip template specializations.
1693 // FIXME: This feels like a hack. Should DeclarationName support
1694 // template-ids, or is there a better way to keep specializations
1695 // from being visible?
1696 if (isa<ClassTemplateSpecializationDecl>(D))
1697 return true;
1698 if (auto *FD = dyn_cast<FunctionDecl>(D))
1699 if (FD->isFunctionTemplateSpecialization())
1700 return true;
1701
1702 // Hide destructors that are invalid. There should always be one destructor,
1703 // but if it is an invalid decl, another one is created. We need to hide the
1704 // invalid one from places that expect exactly one destructor, like the
1705 // serialization code.
1706 if (isa<CXXDestructorDecl>(D) && D->isInvalidDecl())
1707 return true;
1708
1709 return false;
1710}
1711
1713 assert(D->getLexicalDeclContext() == this &&
1714 "decl being removed from non-lexical context");
1715 assert((D->NextInContextAndBits.getPointer() || D == LastDecl) &&
1716 "decl is not in decls list");
1717
1718 // Remove D from the decl chain. This is O(n) but hopefully rare.
1719 if (D == FirstDecl) {
1720 if (D == LastDecl)
1721 FirstDecl = LastDecl = nullptr;
1722 else
1723 FirstDecl = D->NextInContextAndBits.getPointer();
1724 } else {
1725 for (Decl *I = FirstDecl; true; I = I->NextInContextAndBits.getPointer()) {
1726 assert(I && "decl not found in linked list");
1727 if (I->NextInContextAndBits.getPointer() == D) {
1728 I->NextInContextAndBits.setPointer(D->NextInContextAndBits.getPointer());
1729 if (D == LastDecl) LastDecl = I;
1730 break;
1731 }
1732 }
1733 }
1734
1735 // Mark that D is no longer in the decl chain.
1736 D->NextInContextAndBits.setPointer(nullptr);
1737
1738 // Remove D from the lookup table if necessary.
1739 if (isa<NamedDecl>(D)) {
1740 auto *ND = cast<NamedDecl>(D);
1741
1742 // Do not try to remove the declaration if that is invisible to qualified
1743 // lookup. E.g. template specializations are skipped.
1744 if (shouldBeHidden(ND))
1745 return;
1746
1747 // Remove only decls that have a name
1748 if (!ND->getDeclName())
1749 return;
1750
1751 auto *DC = D->getDeclContext();
1752 do {
1753 StoredDeclsMap *Map = DC->getPrimaryContext()->LookupPtr;
1754 if (Map) {
1755 StoredDeclsMap::iterator Pos = Map->find(ND->getDeclName());
1756 assert(Pos != Map->end() && "no lookup entry for decl");
1757 StoredDeclsList &List = Pos->second;
1758 List.remove(ND);
1759 // Clean up the entry if there are no more decls.
1760 if (List.isNull())
1761 Map->erase(Pos);
1762 }
1763 } while (DC->isTransparentContext() && (DC = DC->getParent()));
1764 }
1765}
1766
1768 assert(D->getLexicalDeclContext() == this &&
1769 "Decl inserted into wrong lexical context");
1770 assert(!D->getNextDeclInContext() && D != LastDecl &&
1771 "Decl already inserted into a DeclContext");
1772
1773 if (FirstDecl) {
1774 LastDecl->NextInContextAndBits.setPointer(D);
1775 LastDecl = D;
1776 } else {
1777 FirstDecl = LastDecl = D;
1778 }
1779
1780 // Notify a C++ record declaration that we've added a member, so it can
1781 // update its class-specific state.
1782 if (auto *Record = dyn_cast<CXXRecordDecl>(this))
1783 Record->addedMember(D);
1784
1785 // If this is a newly-created (not de-serialized) import declaration, wire
1786 // it in to the list of local import declarations.
1787 if (!D->isFromASTFile()) {
1788 if (auto *Import = dyn_cast<ImportDecl>(D))
1790 }
1791}
1792
1795
1796 if (auto *ND = dyn_cast<NamedDecl>(D))
1797 ND->getDeclContext()->getPrimaryContext()->
1798 makeDeclVisibleInContextWithFlags(ND, false, true);
1799}
1800
1803
1804 if (auto *ND = dyn_cast<NamedDecl>(D))
1805 ND->getDeclContext()->getPrimaryContext()->
1806 makeDeclVisibleInContextWithFlags(ND, true, true);
1807}
1808
1809/// buildLookup - Build the lookup data structure with all of the
1810/// declarations in this DeclContext (and any other contexts linked
1811/// to it or transparent contexts nested within it) and return it.
1812///
1813/// Note that the produced map may miss out declarations from an
1814/// external source. If it does, those entries will be marked with
1815/// the 'hasExternalDecls' flag.
1817 assert(this == getPrimaryContext() && "buildLookup called on non-primary DC");
1818
1819 if (!hasLazyLocalLexicalLookups() &&
1820 !hasLazyExternalLexicalLookups())
1821 return LookupPtr;
1822
1824 collectAllContexts(Contexts);
1825
1826 if (hasLazyExternalLexicalLookups()) {
1827 setHasLazyExternalLexicalLookups(false);
1828 for (auto *DC : Contexts) {
1829 if (DC->hasExternalLexicalStorage()) {
1830 bool LoadedDecls = DC->LoadLexicalDeclsFromExternalStorage();
1831 setHasLazyLocalLexicalLookups(
1832 hasLazyLocalLexicalLookups() | LoadedDecls );
1833 }
1834 }
1835
1836 if (!hasLazyLocalLexicalLookups())
1837 return LookupPtr;
1838 }
1839
1840 for (auto *DC : Contexts)
1841 buildLookupImpl(DC, hasExternalVisibleStorage());
1842
1843 // We no longer have any lazy decls.
1844 setHasLazyLocalLexicalLookups(false);
1845 return LookupPtr;
1846}
1847
1848/// buildLookupImpl - Build part of the lookup data structure for the
1849/// declarations contained within DCtx, which will either be this
1850/// DeclContext, a DeclContext linked to it, or a transparent context
1851/// nested within it.
1852void DeclContext::buildLookupImpl(DeclContext *DCtx, bool Internal) {
1853 for (auto *D : DCtx->noload_decls()) {
1854 // Insert this declaration into the lookup structure, but only if
1855 // it's semantically within its decl context. Any other decls which
1856 // should be found in this context are added eagerly.
1857 //
1858 // If it's from an AST file, don't add it now. It'll get handled by
1859 // FindExternalVisibleDeclsByName if needed. Exception: if we're not
1860 // in C++, we do not track external visible decls for the TU, so in
1861 // that case we need to collect them all here.
1862 if (auto *ND = dyn_cast<NamedDecl>(D))
1863 if (ND->getDeclContext() == DCtx && !shouldBeHidden(ND) &&
1864 (!ND->isFromASTFile() ||
1865 (isTranslationUnit() &&
1866 !getParentASTContext().getLangOpts().CPlusPlus)))
1867 makeDeclVisibleInContextImpl(ND, Internal);
1868
1869 // If this declaration is itself a transparent declaration context
1870 // or inline namespace, add the members of this declaration of that
1871 // context (recursively).
1872 if (auto *InnerCtx = dyn_cast<DeclContext>(D))
1873 if (InnerCtx->isTransparentContext() || InnerCtx->isInlineNamespace())
1874 buildLookupImpl(InnerCtx, Internal);
1875 }
1876}
1877
1880 // For transparent DeclContext, we should lookup in their enclosing context.
1881 if (getDeclKind() == Decl::LinkageSpec || getDeclKind() == Decl::Export)
1882 return getParent()->lookup(Name);
1883
1884 return getPrimaryContext()->lookupImpl(Name, this);
1885}
1886
1888DeclContext::lookupImpl(DeclarationName Name,
1889 const DeclContext *OriginalLookupDC) const {
1890 assert(this == getPrimaryContext() &&
1891 "lookupImpl should only be called with primary DC!");
1892 assert(getDeclKind() != Decl::LinkageSpec && getDeclKind() != Decl::Export &&
1893 "We shouldn't lookup in transparent DC.");
1894
1895 // If we have an external source, ensure that any later redeclarations of this
1896 // context have been loaded, since they may add names to the result of this
1897 // lookup (or add external visible storage).
1899 if (Source)
1900 (void)cast<Decl>(this)->getMostRecentDecl();
1901
1903 assert(Source && "external visible storage but no external source?");
1904
1905 if (hasNeedToReconcileExternalVisibleStorage())
1906 reconcileExternalVisibleStorage();
1907
1909
1910 if (hasLazyLocalLexicalLookups() ||
1911 hasLazyExternalLexicalLookups())
1912 // FIXME: Make buildLookup const?
1913 Map = const_cast<DeclContext*>(this)->buildLookup();
1914
1915 if (!Map)
1916 Map = CreateStoredDeclsMap(getParentASTContext());
1917
1918 // If we have a lookup result with no external decls, we are done.
1919 std::pair<StoredDeclsMap::iterator, bool> R = Map->try_emplace(Name);
1920 if (!R.second && !R.first->second.hasExternalDecls())
1921 return R.first->second.getLookupResult();
1922
1923 if (Source->FindExternalVisibleDeclsByName(this, Name, OriginalLookupDC) ||
1924 !R.second) {
1925 if (StoredDeclsMap *Map = LookupPtr) {
1926 StoredDeclsMap::iterator I = Map->find(Name);
1927 if (I != Map->end())
1928 return I->second.getLookupResult();
1929 }
1930 }
1931
1932 return {};
1933 }
1934
1936 if (hasLazyLocalLexicalLookups() ||
1937 hasLazyExternalLexicalLookups())
1938 Map = const_cast<DeclContext*>(this)->buildLookup();
1939
1940 if (!Map)
1941 return {};
1942
1943 StoredDeclsMap::iterator I = Map->find(Name);
1944 if (I == Map->end())
1945 return {};
1946
1947 return I->second.getLookupResult();
1948}
1949
1952 // For transparent DeclContext, we should lookup in their enclosing context.
1953 if (getDeclKind() == Decl::LinkageSpec || getDeclKind() == Decl::Export)
1954 return getParent()->noload_lookup(Name);
1955
1956 DeclContext *PrimaryContext = getPrimaryContext();
1957 if (PrimaryContext != this)
1958 return PrimaryContext->noload_lookup(Name);
1959
1960 loadLazyLocalLexicalLookups();
1962 if (!Map)
1963 return {};
1964
1965 StoredDeclsMap::iterator I = Map->find(Name);
1966 return I != Map->end() ? I->second.getLookupResult()
1967 : lookup_result();
1968}
1969
1970// If we have any lazy lexical declarations not in our lookup map, add them
1971// now. Don't import any external declarations, not even if we know we have
1972// some missing from the external visible lookups.
1973void DeclContext::loadLazyLocalLexicalLookups() {
1974 if (hasLazyLocalLexicalLookups()) {
1976 collectAllContexts(Contexts);
1977 for (auto *Context : Contexts)
1978 buildLookupImpl(Context, hasExternalVisibleStorage());
1979 setHasLazyLocalLexicalLookups(false);
1980 }
1981}
1982
1985 Results.clear();
1986
1987 // If there's no external storage, just perform a normal lookup and copy
1988 // the results.
1990 lookup_result LookupResults = lookup(Name);
1991 llvm::append_range(Results, LookupResults);
1992 if (!Results.empty())
1993 return;
1994 }
1995
1996 // If we have a lookup table, check there first. Maybe we'll get lucky.
1997 // FIXME: Should we be checking these flags on the primary context?
1998 if (Name && !hasLazyLocalLexicalLookups() &&
1999 !hasLazyExternalLexicalLookups()) {
2000 if (StoredDeclsMap *Map = LookupPtr) {
2001 StoredDeclsMap::iterator Pos = Map->find(Name);
2002 if (Pos != Map->end()) {
2003 Results.insert(Results.end(),
2004 Pos->second.getLookupResult().begin(),
2005 Pos->second.getLookupResult().end());
2006 return;
2007 }
2008 }
2009 }
2010
2011 // Slow case: grovel through the declarations in our chain looking for
2012 // matches.
2013 // FIXME: If we have lazy external declarations, this will not find them!
2014 // FIXME: Should we CollectAllContexts and walk them all here?
2015 for (Decl *D = FirstDecl; D; D = D->getNextDeclInContext()) {
2016 if (auto *ND = dyn_cast<NamedDecl>(D))
2017 if (ND->getDeclName() == Name)
2018 Results.push_back(ND);
2019 }
2020}
2021
2023 DeclContext *Ctx = this;
2024
2025 // In C, a record type is the redeclaration context for its fields only. If
2026 // we arrive at a record context after skipping anything else, we should skip
2027 // the record as well. Currently, this means skipping enumerations because
2028 // they're the only transparent context that can exist within a struct or
2029 // union.
2030 bool SkipRecords = getDeclKind() == Decl::Kind::Enum &&
2031 !getParentASTContext().getLangOpts().CPlusPlus;
2032
2033 // Skip through contexts to get to the redeclaration context. Transparent
2034 // contexts are always skipped.
2035 while ((SkipRecords && Ctx->isRecord()) || Ctx->isTransparentContext())
2036 Ctx = Ctx->getParent();
2037 return Ctx;
2038}
2039
2041 DeclContext *Ctx = this;
2042 // Skip through non-namespace, non-translation-unit contexts.
2043 while (!Ctx->isFileContext())
2044 Ctx = Ctx->getParent();
2045 return Ctx->getPrimaryContext();
2046}
2047
2049 // Loop until we find a non-record context.
2050 RecordDecl *OutermostRD = nullptr;
2051 DeclContext *DC = this;
2052 while (DC->isRecord()) {
2053 OutermostRD = cast<RecordDecl>(DC);
2054 DC = DC->getLexicalParent();
2055 }
2056 return OutermostRD;
2057}
2058
2060 // For non-file contexts, this is equivalent to Equals.
2061 if (!isFileContext())
2062 return O->Equals(this);
2063
2064 do {
2065 if (O->Equals(this))
2066 return true;
2067
2068 const auto *NS = dyn_cast<NamespaceDecl>(O);
2069 if (!NS || !NS->isInline())
2070 break;
2071 O = NS->getParent();
2072 } while (O);
2073
2074 return false;
2075}
2076
2078 DeclContext *PrimaryDC = this->getPrimaryContext();
2080 // If the decl is being added outside of its semantic decl context, we
2081 // need to ensure that we eagerly build the lookup information for it.
2082 PrimaryDC->makeDeclVisibleInContextWithFlags(D, false, PrimaryDC == DeclDC);
2083}
2084
2085void DeclContext::makeDeclVisibleInContextWithFlags(NamedDecl *D, bool Internal,
2086 bool Recoverable) {
2087 assert(this == getPrimaryContext() && "expected a primary DC");
2088
2089 if (!isLookupContext()) {
2092 ->makeDeclVisibleInContextWithFlags(D, Internal, Recoverable);
2093 return;
2094 }
2095
2096 // Skip declarations which should be invisible to name lookup.
2097 if (shouldBeHidden(D))
2098 return;
2099
2100 // If we already have a lookup data structure, perform the insertion into
2101 // it. If we might have externally-stored decls with this name, look them
2102 // up and perform the insertion. If this decl was declared outside its
2103 // semantic context, buildLookup won't add it, so add it now.
2104 //
2105 // FIXME: As a performance hack, don't add such decls into the translation
2106 // unit unless we're in C++, since qualified lookup into the TU is never
2107 // performed.
2109 ((!Recoverable || D->getDeclContext() != D->getLexicalDeclContext()) &&
2110 (getParentASTContext().getLangOpts().CPlusPlus ||
2111 !isTranslationUnit()))) {
2112 // If we have lazily omitted any decls, they might have the same name as
2113 // the decl which we are adding, so build a full lookup table before adding
2114 // this decl.
2115 buildLookup();
2116 makeDeclVisibleInContextImpl(D, Internal);
2117 } else {
2118 setHasLazyLocalLexicalLookups(true);
2119 }
2120
2121 // If we are a transparent context or inline namespace, insert into our
2122 // parent context, too. This operation is recursive.
2125 makeDeclVisibleInContextWithFlags(D, Internal, Recoverable);
2126
2127 auto *DCAsDecl = cast<Decl>(this);
2128 // Notify that a decl was made visible unless we are a Tag being defined.
2129 if (!(isa<TagDecl>(DCAsDecl) && cast<TagDecl>(DCAsDecl)->isBeingDefined()))
2130 if (ASTMutationListener *L = DCAsDecl->getASTMutationListener())
2131 L->AddedVisibleDecl(this, D);
2132}
2133
2134void DeclContext::makeDeclVisibleInContextImpl(NamedDecl *D, bool Internal) {
2135 // Find or create the stored declaration map.
2137 if (!Map) {
2139 Map = CreateStoredDeclsMap(*C);
2140 }
2141
2142 // If there is an external AST source, load any declarations it knows about
2143 // with this declaration's name.
2144 // If the lookup table contains an entry about this name it means that we
2145 // have already checked the external source.
2146 if (!Internal)
2147 if (ExternalASTSource *Source = getParentASTContext().getExternalSource())
2148 if (hasExternalVisibleStorage() && !Map->contains(D->getDeclName()))
2149 Source->FindExternalVisibleDeclsByName(this, D->getDeclName(),
2150 D->getDeclContext());
2151
2152 // Insert this declaration into the map.
2153 StoredDeclsList &DeclNameEntries = (*Map)[D->getDeclName()];
2154
2155 if (Internal) {
2156 // If this is being added as part of loading an external declaration,
2157 // this may not be the only external declaration with this name.
2158 // In this case, we never try to replace an existing declaration; we'll
2159 // handle that when we finalize the list of declarations for this name.
2160 DeclNameEntries.setHasExternalDecls();
2161 DeclNameEntries.prependDeclNoReplace(D);
2162 return;
2163 }
2164
2165 DeclNameEntries.addOrReplaceDecl(D);
2166}
2167
2169 return cast<UsingDirectiveDecl>(*I);
2170}
2171
2172/// Returns iterator range [First, Last) of UsingDirectiveDecls stored within
2173/// this context.
2175 // FIXME: Use something more efficient than normal lookup for using
2176 // directives. In C++, using directives are looked up more than anything else.
2177 lookup_result Result = lookup(UsingDirectiveDecl::getName());
2178 return udir_range(Result.begin(), Result.end());
2179}
2180
2181//===----------------------------------------------------------------------===//
2182// Creation and Destruction of StoredDeclsMaps. //
2183//===----------------------------------------------------------------------===//
2184
2185StoredDeclsMap *DeclContext::CreateStoredDeclsMap(ASTContext &C) const {
2186 assert(!LookupPtr && "context already has a decls map");
2187 assert(getPrimaryContext() == this &&
2188 "creating decls map on non-primary context");
2189
2190 StoredDeclsMap *M;
2192 if (Dependent)
2193 M = new DependentStoredDeclsMap();
2194 else
2195 M = new StoredDeclsMap();
2196 M->Previous = C.LastSDM;
2197 C.LastSDM = llvm::PointerIntPair<StoredDeclsMap*,1>(M, Dependent);
2198 LookupPtr = M;
2199 return M;
2200}
2201
2202void ASTContext::ReleaseDeclContextMaps() {
2203 // It's okay to delete DependentStoredDeclsMaps via a StoredDeclsMap
2204 // pointer because the subclass doesn't add anything that needs to
2205 // be deleted.
2206 StoredDeclsMap::DestroyAll(LastSDM.getPointer(), LastSDM.getInt());
2207 LastSDM.setPointer(nullptr);
2208}
2209
2211 while (Map) {
2212 // Advance the iteration before we invalidate memory.
2213 llvm::PointerIntPair<StoredDeclsMap*,1> Next = Map->Previous;
2214
2215 if (Dependent)
2216 delete static_cast<DependentStoredDeclsMap*>(Map);
2217 else
2218 delete Map;
2219
2220 Map = Next.getPointer();
2221 Dependent = Next.getInt();
2222 }
2223}
2224
2227 const PartialDiagnostic &PDiag) {
2228 assert(Parent->isDependentContext()
2229 && "cannot iterate dependent diagnostics of non-dependent context");
2230 Parent = Parent->getPrimaryContext();
2231 if (!Parent->LookupPtr)
2232 Parent->CreateStoredDeclsMap(C);
2233
2234 auto *Map = static_cast<DependentStoredDeclsMap *>(Parent->LookupPtr);
2235
2236 // Allocate the copy of the PartialDiagnostic via the ASTContext's
2237 // BumpPtrAllocator, rather than the ASTContext itself.
2238 DiagnosticStorage *DiagStorage = nullptr;
2239 if (PDiag.hasStorage())
2240 DiagStorage = new (C) DiagnosticStorage;
2241
2242 auto *DD = new (C) DependentDiagnostic(PDiag, DiagStorage);
2243
2244 // TODO: Maybe we shouldn't reverse the order during insertion.
2245 DD->NextDiagnostic = Map->FirstDiagnostic;
2246 Map->FirstDiagnostic = DD;
2247
2248 return DD;
2249}
2250
2252 return ID & llvm::maskTrailingOnes<DeclID>(32);
2253}
Defines the clang::ASTContext interface.
#define V(N, I)
Definition: ASTContext.h:3597
#define BuiltinTemplate(BTName)
Definition: ASTContext.h:2199
NodeId Parent
Definition: ASTDiff.cpp:191
This file provides some common utility functions for processing Lambda related AST Constructs.
const Decl * D
Expr * E
static bool shouldBeHidden(NamedDecl *D)
shouldBeHidden - Determine whether a declaration which was declared within its semantic context shoul...
Definition: DeclBase.cpp:1675
static void collectAllContextsImpl(T *Self, SmallVectorImpl< DeclContext * > &Contexts)
Definition: DeclBase.cpp:1528
static bool isLinkageSpecContext(const DeclContext *DC, LinkageSpecLanguageIDs ID)
Definition: DeclBase.cpp:1399
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:1192
static Decl * getNonClosureContext(T *D)
Starting at a given context (a Decl or DeclContext), look for a code context that is not a closure (a...
Definition: DeclBase.cpp:1246
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.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
llvm::MachO::Record Record
Definition: MachO.h:31
Defines the clang::Module class, which describes a module in the source code.
Defines types useful for describing an Objective-C runtime.
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream.
Defines the clang::SourceLocation class and associated facilities.
static QualType getPointeeType(const MemRegion *R)
C Language Family Type Representation.
std::string Label
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:188
const ConstantArrayType * getAsConstantArrayType(QualType T) const
Definition: ASTContext.h:3056
ASTMutationListener * getASTMutationListener() const
Retrieve a pointer to the AST mutation listener associated with this AST context, if any.
Definition: ASTContext.h:1360
const IncompleteArrayType * getAsIncompleteArrayType(QualType T) const
Definition: ASTContext.h:3062
const LangOptions & getLangOpts() const
Definition: ASTContext.h:894
llvm::BumpPtrAllocator & getAllocator() const
Definition: ASTContext.h:810
void eraseDeclAttrs(const Decl *D)
Erase the attributes corresponding to the given declaration.
void addedLocalImportDecl(ImportDecl *Import)
Notify the AST context that a new import declaration has been parsed or implicitly created within thi...
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:814
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:859
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
Definition: ASTContext.h:1339
Module * getCurrentNamedModule() const
Get module under construction, nullptr if this is not a C++20 module.
Definition: ASTContext.h:1193
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:4630
Pointer to a block type.
Definition: TypeBase.h:3558
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1382
decl_iterator - Iterates through the declarations stored within this context.
Definition: DeclBase.h:2330
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext,...
Definition: DeclBase.h:2393
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.
Definition: DeclBase.cpp:2174
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.
Definition: DeclBase.cpp:2077
DeclContextLookupResult lookup_result
Definition: DeclBase.h:2577
static std::pair< Decl *, Decl * > BuildDeclChain(ArrayRef< Decl * > Decls, bool FieldsAlreadyLoaded)
Build up a chain of declarations.
Definition: DeclBase.cpp:1550
bool isTransparentContext() const
isTransparentContext - Determines whether this context is a "transparent" context,...
Definition: DeclBase.cpp:1392
Decl * getNonClosureAncestor()
Find the nearest non-closure ancestor of this context, i.e.
Definition: DeclBase.cpp:1271
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...
Definition: DeclBase.cpp:1424
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:1358
bool InEnclosingNamespaceSetOf(const DeclContext *NS) const
Test if this context is part of the enclosing namespace set of the context NS, as defined in C++0x [n...
Definition: DeclBase.cpp:2059
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.
Definition: DeclBase.cpp:1879
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.
Definition: DeclBase.cpp:1325
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.
Definition: DeclBase.cpp:1536
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:2022
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)
Definition: DeclBase.cpp:1279
void addDeclInternal(Decl *D)
Add the declaration D into this context, but suppress searches for external declarations with the sam...
Definition: DeclBase.cpp:1801
bool containsDeclAndLoad(Decl *D) const
Checks whether a declaration is in this context.
Definition: DeclBase.cpp:1667
void removeDecl(Decl *D)
Removes a declaration from this context.
Definition: DeclBase.cpp:1712
void addDecl(Decl *D)
Add the declaration D into this context.
Definition: DeclBase.cpp:1793
StoredDeclsMap * buildLookup()
Ensure the lookup structure is fully-built and return it.
Definition: DeclBase.cpp:1816
bool hasValidDeclKind() const
Definition: DeclBase.cpp:179
bool isStdNamespace() const
Definition: DeclBase.cpp:1342
lookup_result noload_lookup(DeclarationName Name)
Find the declarations with the given name that are visible within this context; don't attempt to retr...
Definition: DeclBase.cpp:1951
static bool classof(const Decl *D)
Definition: DeclBase.cpp:1289
bool containsDecl(Decl *D) const
Checks whether a declaration is in this context.
Definition: DeclBase.cpp:1662
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.
Definition: DeclBase.cpp:2040
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...
Definition: DeclBase.cpp:1459
RecordDecl * getOuterLexicalRecordContext()
Retrieve the outermost lexically enclosing record context.
Definition: DeclBase.cpp:2048
bool decls_empty() const
Definition: DeclBase.cpp:1655
bool isInlineNamespace() const
Definition: DeclBase.cpp:1337
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.
Definition: DeclBase.cpp:1309
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...
Definition: DeclBase.cpp:1409
const LinkageSpecDecl * getExternCContext() const
Retrieve the nearest enclosing C linkage specification context.
Definition: DeclBase.cpp:1413
bool Encloses(const DeclContext *DC) const
Determine whether this declaration context semantically encloses the declaration context DC.
Definition: DeclBase.cpp:1428
void addHiddenDecl(Decl *D)
Add the declaration D to this context without modifying any lookup tables.
Definition: DeclBase.cpp:1767
void localUncachedLookup(DeclarationName Name, SmallVectorImpl< NamedDecl * > &Results)
A simplistic name lookup mechanism that performs name lookup into this declaration context without co...
Definition: DeclBase.cpp:1983
Decl::Kind getDeclKind() const
Definition: DeclBase.h:2102
DeclContext * getNonTransparentContext()
Definition: DeclBase.cpp:1450
decl_iterator decls_begin() const
Definition: DeclBase.cpp:1649
bool LexicallyEncloses(const DeclContext *DC) const
Determine whether this declaration context lexically encloses the declaration context DC.
Definition: DeclBase.cpp:1439
unsigned getLocalDeclIndex() const
Definition: DeclBase.cpp:2251
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration,...
Definition: DeclBase.h:1061
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.
Definition: DeclBase.cpp:1159
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.
Definition: DeclBase.cpp:1130
bool isFromGlobalModule() const
Whether this declaration comes from global module.
Definition: DeclBase.cpp:1180
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)
Definition: DeclBase.cpp:1022
void setAttrs(const AttrVec &Attrs)
Definition: DeclBase.h:520
bool hasLocalOwningModuleStorage() const
Definition: DeclBase.cpp:143
bool isFunctionPointerType() const
Definition: DeclBase.cpp:1227
bool isInNamedModule() const
Whether this declaration comes from a named module.
Definition: DeclBase.cpp:1184
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 *)
Definition: DeclBase.cpp:1050
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.
Definition: DeclBase.cpp:1121
SourceLocation getBodyRBrace() const
getBodyRBrace - Gets the right brace of the body, if a body exists.
Definition: DeclBase.cpp:1076
int64_t getID() const
Definition: DeclBase.cpp:1195
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.
Definition: DeclBase.cpp:1199
bool isInAnotherModuleUnit() const
Whether this declaration comes from another module unit.
Definition: DeclBase.cpp:1138
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.
Definition: DeclBase.cpp:1176
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()
Definition: DeclBase.cpp:1015
static DeclContext * castToDeclContext(const Decl *)
Definition: DeclBase.cpp:1063
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.
Definition: DeclBase.cpp:1239
Decl * getNonClosureContext()
Find the innermost non-closure ancestor of this declaration, walking up through blocks,...
Definition: DeclBase.cpp:1267
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
SourceLocation getLocation() const
Definition: DeclBase.h:439
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.
Definition: DeclBase.cpp:1188
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
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.
@ ReachableWhenImported
This declaration has an owning module, and is visible to lookups that occurs within that module.
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.
Definition: DeclBase.cpp:1168
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)
Definition: DeclBase.cpp:1634
static DeclContextLookupResult SetNoExternalVisibleDeclsForName(const DeclContext *DC, DeclarationName Name)
Definition: DeclBase.cpp:1619
virtual Module * getModule(unsigned ID)
Retrieve the module that corresponds to the given module ID.
virtual bool FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name, const DeclContext *OriginalDC)
Find all declarations with the given name in the given context, and add them to the context by callin...
virtual void FindExternalLexicalDecls(const DeclContext *DC, llvm::function_ref< bool(Decl::Kind)> IsKindWeWant, SmallVectorImpl< Decl * > &Result)
Finds all declarations lexically contained within the given DeclContext, after applying an optional f...
Represents a member of a struct/union/class.
Definition: Decl.h:3153
Represents a function declaration or definition.
Definition: Decl.h:1999
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: TypeBase.h:4478
One of these records is kept for each identifier that is lexed.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
StringRef getName() const
Return the actual identifier string.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:434
bool trackLocalOwningModule() const
Do we need to track the owning module for a local declaration?
Definition: LangOptions.h:606
Represents a linkage specification.
Definition: DeclCXX.h:3009
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: TypeBase.h:3669
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
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?
Definition: ObjCRuntime.h:378
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: TypeBase.h:3346
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:8395
Represents a struct/union/class.
Definition: Decl.h:4305
Base for LValueReferenceType and RValueReferenceType.
Definition: TypeBase.h:3589
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.
static void DestroyAll(StoredDeclsMap *Map, bool Dependent)
Definition: DeclBase.cpp:2210
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:1288
StringRef getPlatformName() const
Retrieve the name of the platform as it is used in the availability attribute.
Definition: TargetInfo.h:1699
VersionTuple getPlatformMinVersion() const
Retrieve the minimum desired version of the platform, to which the program should be compiled.
Definition: TargetInfo.h:1703
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:396
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:74
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:2843
A container of type source information.
Definition: TypeBase.h:8314
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:272
bool isBlockPointerType() const
Definition: TypeBase.h:8600
bool isFunctionReferenceType() const
Definition: TypeBase.h:8654
bool isFunctionPointerType() const
Definition: TypeBase.h:8647
const T * castAs() const
Member-template castAs<specific type>.
Definition: TypeBase.h:9226
bool isMemberFunctionPointerType() const
Definition: TypeBase.h:8665
const T * getAs() const
Member-template getAs<specific type>'.
Definition: TypeBase.h:9159
Wrapper for source info for typedefs.
Definition: TypeLoc.h:782
Represents C++ using-directive.
Definition: DeclCXX.h:3090
specific_attr_iterator - Iterates over a subrange of an AttrVec, only providing attributes that are o...
Definition: AttrIterator.h:36
Defines the clang::TargetInfo interface.
const internal::VariadicAllOfMatcher< Attr > attr
Matches attributes.
The JSON file list parser is used to communicate input to InstallAPI.
@ CPlusPlus
Definition: LangStandard.h:55
SmallVector< Attr *, 4 > AttrVec
AttrVec - A vector of Attr, which is how they are stored on the AST.
Definition: AttrIterator.h:31
LinkageSpecLanguageIDs
Represents the language in a linkage specification.
Definition: DeclCXX.h:3001
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
@ AS_public
Definition: Specifiers.h:124
@ AS_none
Definition: Specifiers.h:127
@ Dependent
Parse the block as a dependent block, which may be used in some template instantiations but not other...
@ Internal
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
bool isLambdaCallOperator(const CXXMethodDecl *MD)
Definition: ASTLambda.h:28
@ Result
The result type of a method or function.
@ FunctionTemplate
The name was classified as a function template name.
@ Concept
The name was classified as a concept name.
@ VarTemplate
The name was classified as a variable template name.
AvailabilityResult
Captures the result of checking the availability of a declaration.
Definition: DeclBase.h:72
@ AR_NotYetIntroduced
Definition: DeclBase.h:74
@ AR_Available
Definition: DeclBase.h:73
@ AR_Deprecated
Definition: DeclBase.h:75
@ AR_Unavailable
Definition: DeclBase.h:76
const FunctionProtoType * T
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
UsingDirectiveDecl * operator*() const
Definition: DeclBase.cpp:2168