clang: lib/AST/DeclBase.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
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
45#include
46#include
47#include
48#include
49#include
50
51using namespace clang;
52
53
54
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,
69
70
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
80
81
82 assert((*PrefixPtr < llvm::maskTrailingOnes<uint64_t>(48)) &&
83 "Current Implementation limits the number of module files to not "
84 "exceed 2^16. Contact Clang Developers to remove the limitation.");
85
87}
88
89void *Decl::operator new(std::size_t Size, const ASTContext &Ctx,
91 assert(!Parent || &Parent->getParentASTContext() == &Ctx);
92
93
94
95 if (Ctx.getLangOpts().trackLocalOwningModule() || !Parent) {
96
97
98 size_t ExtraAlign =
99 llvm::offsetToAlignment(sizeof(Module *), llvm::Align(alignof(Decl)));
100 auto *Buffer = reinterpret_cast<char *>(
101 ::operator new(ExtraAlign + sizeof(Module *) + Size + Extra, Ctx));
102 Buffer += ExtraAlign;
103 auto *ParentModule =
104 Parent ? cast(Parent)->getOwningModule() : nullptr;
105 return new (Buffer) Module*(ParentModule) + 1;
106 }
107 return ::operator new(Size + Extra, Ctx);
108}
109
113
114 uint64_t ID = *((const uint64_t *)this - 1);
115 return GlobalDeclID(ID & llvm::maskTrailingOnes<uint64_t>(48));
116}
117
120 return 0;
121
122 uint64_t ID = *((const uint64_t *)this - 1);
123 return ID >> 48;
124}
125
127 assert(isFromASTFile() && "Only works on a deserialized declaration");
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144 assert((ID < llvm::maskTrailingOnes(16)) &&
145 "Current Implementation limits the number of modules to not exceed "
146 "2^16. Contact Clang Developers to remove the limitation.");
147 uint64_t *IDAddress = (uint64_t *)this - 1;
148 *IDAddress &= llvm::maskTrailingOnes<uint64_t>(48);
149 *IDAddress |= (uint64_t)ID << 48;
150}
151
156
157 return nullptr;
158}
159
160Module *Decl::getOwningModuleSlow() const {
163}
164
168
170 switch (DeclKind) {
171 default: llvm_unreachable("Declaration not in DeclNodes.inc!");
172#define DECL(DERIVED, BASE) case DERIVED: return #DERIVED;
173#define ABSTRACT_DECL(DECL)
174#include "clang/AST/DeclNodes.inc"
175 }
176}
177
182 return;
183 }
184
186
187
188
190 }
191
192
193
194 if (auto *DD = dyn_cast(this)) {
195 for (auto *Binding : DD->bindings()) {
196 Binding->setInvalidDecl();
197 }
198 }
199}
200
203#define DECL(DERIVED, BASE) case Decl::DERIVED: return true;
204#define ABSTRACT_DECL(DECL)
205#include "clang/AST/DeclNodes.inc"
206 }
207 return false;
208}
209
212#define DECL(DERIVED, BASE) case Decl::DERIVED: return #DERIVED;
213#define ABSTRACT_DECL(DECL)
214#include "clang/AST/DeclNodes.inc"
215 }
216 llvm_unreachable("Declaration context not in DeclNodes.inc!");
217}
218
219bool Decl::StatisticsEnabled = false;
221 StatisticsEnabled = true;
222}
223
225 llvm::errs() << "\n*** Decl Stats:\n";
226
227 int totalDecls = 0;
228#define DECL(DERIVED, BASE) totalDecls += n##DERIVED##s;
229#define ABSTRACT_DECL(DECL)
230#include "clang/AST/DeclNodes.inc"
231 llvm::errs() << " " << totalDecls << " decls total.\n";
232
233 int totalBytes = 0;
234#define DECL(DERIVED, BASE) \
235 if (n##DERIVED##s > 0) { \
236 totalBytes += (int)(n##DERIVED##s * sizeof(DERIVED##Decl)); \
237 llvm::errs() << " " << n##DERIVED##s << " " #DERIVED " decls, " \
238 << sizeof(DERIVED##Decl) << " each (" \
239 << n##DERIVED##s * sizeof(DERIVED##Decl) \
240 << " bytes)\n"; \
241 }
242#define ABSTRACT_DECL(DECL)
243#include "clang/AST/DeclNodes.inc"
244
245 llvm::errs() << "Total bytes = " << totalBytes << "\n";
246}
247
249 switch (k) {
250#define DECL(DERIVED, BASE) case DERIVED: ++n##DERIVED##s; break;
251#define ABSTRACT_DECL(DECL)
252#include "clang/AST/DeclNodes.inc"
253 }
254}
255
257 if (const auto *TTP = dyn_cast(this))
258 return TTP->isParameterPack();
259 if (const auto *NTTP = dyn_cast(this))
260 return NTTP->isParameterPack();
261 if (const auto *TTP = dyn_cast(this))
262 return TTP->isParameterPack();
263 return false;
264}
265
267 if (const auto *Var = dyn_cast(this))
268 return Var->isParameterPack();
269
271}
272
274 if (auto *FD = dyn_cast(this))
275 return FD;
276 if (const auto *FTD = dyn_cast(this))
277 return FTD->getTemplatedDecl();
278 return nullptr;
279}
280
284
286 if (auto *FD = dyn_cast(this))
287 return FD->getDescribedFunctionTemplate();
288 if (auto *RD = dyn_cast(this))
289 return RD->getDescribedClassTemplate();
290 if (auto *VD = dyn_cast(this))
291 return VD->getDescribedVarTemplate();
292 if (auto *AD = dyn_cast(this))
293 return AD->getDescribedAliasTemplate();
294
295 return nullptr;
296}
297
300 return TD->getTemplateParameters();
301 if (auto *CTPSD = dyn_cast(this))
302 return CTPSD->getTemplateParameters();
303 if (auto *VTPSD = dyn_cast(this))
304 return VTPSD->getTemplateParameters();
305 return nullptr;
306}
307
309
310
311
312 if (auto *AsDC = dyn_cast(this))
313 return AsDC->isDependentContext();
316 return DC->isDependentContext() || isTemplateDecl() ||
318}
319
321 if (auto *DC = dyn_cast(this))
322 if (DC->isFileContext())
323 return 0;
324
326 return TPL->getDepth() + 1;
327
328
329
330
331 auto *RD = dyn_cast(this);
332 if (RD && RD->isDependentLambda())
333 if (Decl *Context = RD->getLambdaContextDecl())
334 return Context->getTemplateDepth();
335
338 return cast(DC)->getTemplateDepth();
339}
340
344 DC && !DC->isFileContext(); DC = DC->getParent())
345 if (DC->isFunctionOrMethod())
346 return DC;
347
348 return nullptr;
349}
350
351
352
353
354
357 if (TheLoc.isInvalid() && TheDecl)
358 TheLoc = TheDecl->getLocation();
359
361 TheLoc.print(OS, SM);
362 OS << ": ";
363 }
364
365 OS << Message;
366
367 if (const auto *DN = dyn_cast_or_null(TheDecl)) {
368 OS << " '";
369 DN->printQualifiedName(OS);
370 OS << '\'';
371 }
372 OS << '\n';
373}
374
375
376
377
378
379
381
385
388 return;
389
390 if (isInSemaDC()) {
392 } else {
393 getMultipleDC()->LexicalDC = DC;
394 }
395
396
397
402 }
403
404 assert(
407 "hidden declaration has no owning module");
408}
409
412 if (SemaDC == LexicalDC) {
413 DeclCtx = SemaDC;
414 } else {
415 auto *MDC = new (Ctx) Decl::MultipleDC();
416 MDC->SemanticDC = SemaDC;
417 MDC->LexicalDC = LexicalDC;
418 DeclCtx = MDC;
419 }
420}
421
425 return false;
426 while (true) {
428 return true;
430 return false;
431 if (const auto *CRD = dyn_cast(LDC))
432 if (CRD->isLambda())
433 return true;
435 }
436 return false;
437}
438
441 if (const auto *ND = dyn_cast(DC))
442 if (ND->isAnonymousNamespace())
443 return true;
444 }
445
446 return false;
447}
448
453
455 const auto *DC = dyn_cast(this);
456 return DC && DC->isFileContext();
457}
458
462 bool IgnoreTemplateOrMacroSubstitution) {
463
464
466 if (CAT) {
468
469 llvm::APInt Size = CAT->getSize();
470 if (StrictFlexArraysLevel == FAMKind::IncompleteOnly)
471 return false;
472
473
474 if (Size.isZero())
475 return true;
476
477 if (StrictFlexArraysLevel == FAMKind::ZeroOrIncomplete && Size.uge(1))
478 return false;
479
480 if (StrictFlexArraysLevel == FAMKind::OneZeroOrIncomplete && Size.uge(2))
481 return false;
483 return false;
484 }
485
486 if (const auto *OID = dyn_cast_if_present(D))
487 return OID->getNextIvar() == nullptr;
488
489 const auto *FD = dyn_cast_if_present(D);
490 if (!FD)
491 return false;
492
493 if (CAT) {
494
495
496 llvm::APInt Size = CAT->getSize();
497 if (FD->getParent()->isUnion() && (Size.isZero() || Size.isOne()))
498 return true;
499 }
500
501
502
503 if (IgnoreTemplateOrMacroSubstitution) {
505 while (TInfo) {
507
508
510 TInfo = TTL.getDecl()->getTypeSourceInfo();
511 continue;
512 }
513
515 if (const Expr *SizeExpr =
516 dyn_cast_if_present(CTL.getSizeExpr());
518 return false;
519 }
520
521 break;
522 }
523 }
524
525
528 return ++FI == FD->getParent()->field_end();
529}
530
532 if (auto *TUD = dyn_cast(this))
533 return TUD;
534
536 assert(DC && "This decl is not contained in a translation unit!");
537
540 assert(DC && "This decl is not contained in a translation unit!");
541 }
542
544}
545
549
550
551
555
559
562 return 0;
563
564 unsigned Align = 0;
568 for (; I != E; ++I) {
569 if (!I->isAlignmentErrorDependent())
570 Align = std::max(Align, I->getAlignment(Ctx));
571 }
572 return Align;
573}
574
577 if (CanonD->Used)
578 return true;
579
580
581
583 return true;
584
585
586
588}
589
592 return;
593
594 if (C.getASTMutationListener())
595 C.getASTMutationListener()->DeclarationMarkedUsed(this);
596
598}
599
601 if (Referenced)
602 return true;
603
604
605 for (const auto *I : redecls())
606 if (I->Referenced)
607 return true;
608
609 return false;
610}
611
614 if (auto *ID = dyn_cast(this)) {
616 } else if (auto *PD = dyn_cast(this)) {
618 } else if (auto *TD = dyn_cast(this)) {
620 }
623
624 if (auto *attr = Definition->getAttr())
627 return dcd->getAttr();
628 }
629
630 return nullptr;
631}
632
637
640 return AA;
642 return IFA;
644 return NZA;
645 return nullptr;
646}
647
650
651
652 StringRef RealizedPlatform = A->getPlatform()->getName();
653 if (!Context.getLangOpts().AppExt)
654 return RealizedPlatform;
655 size_t suffix = RealizedPlatform.rfind("_app_extension");
656 if (suffix != StringRef::npos)
657 return RealizedPlatform.slice(0, suffix);
658 return RealizedPlatform;
659}
660
661
662
663
664
665
666
667
668
669
671 const AvailabilityAttr *A,
672 std::string *Message,
673 VersionTuple EnclosingVersion) {
674 if (EnclosingVersion.empty())
675 EnclosingVersion = Context.getTargetInfo().getPlatformMinVersion();
676
677 if (EnclosingVersion.empty())
679
680 StringRef ActualPlatform = A->getPlatform()->getName();
681 StringRef TargetPlatform = Context.getTargetInfo().getPlatformName();
682
683
686
687 StringRef PrettyPlatformName
688 = AvailabilityAttr::getPrettyPlatformName(ActualPlatform);
689
690 if (PrettyPlatformName.empty())
691 PrettyPlatformName = ActualPlatform;
692
693 std::string HintMessage;
694 if (!A->getMessage().empty()) {
695 HintMessage = " - ";
696 HintMessage += A->getMessage();
697 }
698
699
700 if (A->getUnavailable()) {
701 if (Message) {
702 Message->clear();
703 llvm::raw_string_ostream Out(*Message);
704 Out << "not available on " << PrettyPlatformName
705 << HintMessage;
706 }
707
709 }
710
711
712 if (!A->getIntroduced().empty() &&
713 EnclosingVersion < A->getIntroduced()) {
715 auto &Triple = Context.getTargetInfo().getTriple();
716 StringRef TargetEnv = Triple.getEnvironmentName();
717 StringRef EnvName =
718 llvm::Triple::getEnvironmentTypeName(Triple.getEnvironment());
719
720 if (!IIEnv || (Triple.hasEnvironment() && IIEnv->getName() == TargetEnv)) {
721 if (Message) {
722 Message->clear();
723 llvm::raw_string_ostream Out(*Message);
724 VersionTuple VTI(A->getIntroduced());
725 Out << "introduced in " << PrettyPlatformName << " " << VTI;
726 if (Triple.hasEnvironment())
727 Out << " " << EnvName;
728 Out << HintMessage;
729 }
730 }
731
732 else {
733 if (Message) {
734 Message->clear();
735 llvm::raw_string_ostream Out(*Message);
736 Out << "not available on " << PrettyPlatformName;
737 if (Triple.hasEnvironment())
738 Out << " " << EnvName;
739 Out << HintMessage;
740 }
741 }
742
744 }
745
746
747 if (!A->getObsoleted().empty() && EnclosingVersion >= A->getObsoleted()) {
748 if (Message) {
749 Message->clear();
750 llvm::raw_string_ostream Out(*Message);
751 VersionTuple VTO(A->getObsoleted());
752 Out << "obsoleted in " << PrettyPlatformName << ' '
753 << VTO << HintMessage;
754 }
755
757 }
758
759
760 if (!A->getDeprecated().empty() && EnclosingVersion >= A->getDeprecated()) {
761 if (Message) {
762 Message->clear();
763 llvm::raw_string_ostream Out(*Message);
764 VersionTuple VTD(A->getDeprecated());
765 Out << "first deprecated in " << PrettyPlatformName << ' '
766 << VTD << HintMessage;
767 }
768
770 }
771
773}
774
776 VersionTuple EnclosingVersion,
777 StringRef *RealizedPlatform) const {
778 if (auto *FTD = dyn_cast(this))
779 return FTD->getTemplatedDecl()->getAvailability(Message, EnclosingVersion,
780 RealizedPlatform);
781
783 std::string ResultMessage;
784
785 for (const auto *A : attrs()) {
786 if (const auto *Deprecated = dyn_cast(A)) {
788 continue;
789
790 if (Message)
791 ResultMessage = std::string(Deprecated->getMessage());
792
794 continue;
795 }
796
797 if (const auto *Unavailable = dyn_cast(A)) {
798 if (Message)
799 *Message = std::string(Unavailable->getMessage());
801 }
802
803 if (const auto *Availability = dyn_cast(A)) {
805 Message, EnclosingVersion);
806
808 if (RealizedPlatform)
809 *RealizedPlatform = Availability->getPlatform()->getName();
811 }
812
815 if (Message)
816 ResultMessage.swap(*Message);
817 }
818 continue;
819 }
820 }
821
822 if (Message)
823 Message->swap(ResultMessage);
825}
826
829 StringRef TargetPlatform = Context.getTargetInfo().getPlatformName();
830 for (const auto *A : attrs()) {
831 if (const auto *Availability = dyn_cast(A)) {
833 continue;
834 if (!Availability->getIntroduced().empty())
835 return Availability->getIntroduced();
836 }
837 }
838 return {};
839}
840
842 IsDefinition = false;
843
844
845 if (const auto *Var = dyn_cast(this)) {
846 if (Var->isThisDeclarationADefinition()) {
847 IsDefinition = true;
848 return false;
849 }
850 return true;
851 }
852
853 if (const auto *FD = dyn_cast(this)) {
854 if (FD->hasBody()) {
855 IsDefinition = true;
856 return false;
857 }
858 return true;
859
860 }
861
864 return true;
865 }
866
867 return false;
868}
869
871 bool IsDefinition;
873 return false;
874
877 return true;
878
879 if (const auto *Availability = dyn_cast(A)) {
882 return true;
883 }
884 }
885
886 return false;
887}
888
890 switch (DeclKind) {
892 case CXXDeductionGuide:
893 case CXXMethod:
894 case CXXConstructor:
895 case ConstructorUsingShadow:
896 case CXXDestructor:
897 case CXXConversion:
898 case EnumConstant:
899 case Var:
900 case ImplicitParam:
901 case ParmVar:
902 case ObjCMethod:
903 case ObjCProperty:
904 case MSProperty:
905 case HLSLBuffer:
906 case HLSLRootSignature:
908 case Label:
910
911 case Binding:
912 case NonTypeTemplateParm:
915
916
918
919 case ObjCCompatibleAlias:
920 case ObjCInterface:
922
925 case TemplateTypeParm:
926 case ObjCTypeParam:
928
929 case UnresolvedUsingTypename:
931
932 case UsingShadow:
933 return 0;
934
935 case UnresolvedUsingValue:
937
938 case Using:
939 case UsingPack:
940 case UsingEnum:
942
943 case ObjCProtocol:
945
946 case Field:
947 case IndirectField:
948 case ObjCAtDefsField:
949 case ObjCIvar:
951
953 case CXXRecord:
956
957 case Namespace:
958 case NamespaceAlias:
960
963
964 case ClassTemplate:
965 case TemplateTemplateParm:
968
969 case UnresolvedUsingIfExists:
971
972 case OMPDeclareReduction:
974
975 case OMPDeclareMapper:
977
978
980 case FriendTemplate:
981 case AccessSpec:
982 case LinkageSpec:
983 case Export:
984 case FileScopeAsm:
985 case TopLevelStmt:
986 case StaticAssert:
987 case ObjCPropertyImpl:
988 case PragmaComment:
989 case PragmaDetectMismatch:
991 case Captured:
992 case OutlinedFunction:
993 case TranslationUnit:
994 case ExternCContext:
995 case Decomposition:
996 case MSGuid:
997 case UnnamedGlobalConstant:
998 case TemplateParamObject:
999
1000 case UsingDirective:
1002 case ClassTemplateSpecialization:
1003 case ClassTemplatePartialSpecialization:
1004 case VarTemplateSpecialization:
1005 case VarTemplatePartialSpecialization:
1006 case ObjCImplementation:
1007 case ObjCCategory:
1008 case ObjCCategoryImpl:
1009 case Import:
1010 case OMPThreadPrivate:
1011 case OMPGroupPrivate:
1012 case OMPAllocate:
1013 case OMPRequires:
1014 case OMPCapturedExpr:
1016 case LifetimeExtendedTemporary:
1017 case RequiresExprBody:
1018 case ImplicitConceptSpecialization:
1019 case OpenACCDeclare:
1020 case OpenACCRoutine:
1021
1022 return 0;
1023 }
1024
1025 llvm_unreachable("Invalid DeclKind!");
1026}
1027
1029 assert(!HasAttrs && "Decl already contains attrs.");
1030
1032 assert(AttrBlank.empty() && "HasAttrs was wrong?");
1033
1034 AttrBlank = attrs;
1035 HasAttrs = true;
1036}
1037
1039 if (!HasAttrs) return;
1040
1041 HasAttrs = false;
1043}
1044
1048 return;
1049 }
1050
1053 Attrs.push_back(A);
1054 return;
1055 }
1056
1057
1058
1059
1060 auto I = Attrs.begin(), E = Attrs.end();
1061 for (; I != E; ++I) {
1062 if (!(*I)->isInherited())
1063 break;
1064 }
1065 Attrs.insert(I, A);
1066}
1067
1069 assert(HasAttrs && "No attrs to get!");
1071}
1072
1075 switch (DK) {
1076#define DECL(NAME, BASE)
1077#define DECL_CONTEXT(NAME) \
1078 case Decl::NAME: \
1079 return static_cast<NAME##Decl *>(const_cast<DeclContext *>(D));
1080#include "clang/AST/DeclNodes.inc"
1081 default:
1082 llvm_unreachable("a decl that inherits DeclContext isn't handled");
1083 }
1084}
1085
1088 switch(DK) {
1089#define DECL(NAME, BASE)
1090#define DECL_CONTEXT(NAME) \
1091 case Decl::NAME: \
1092 return static_cast<NAME##Decl *>(const_cast<Decl *>(D));
1093#include "clang/AST/DeclNodes.inc"
1094 default:
1095 llvm_unreachable("a decl that inherits DeclContext isn't handled");
1096 }
1097}
1098
1100
1101
1102 if (const auto *FD = dyn_cast(this)) {
1105 return Definition->getSourceRange().getEnd();
1106 return {};
1107 }
1108
1110 return Body->getSourceRange().getEnd();
1111
1112 return {};
1113}
1114
1115bool Decl::AccessDeclContextCheck() const {
1116#ifndef NDEBUG
1117
1118
1119
1120
1121
1122
1123
1124
1125
1130
1131
1133
1134
1136 return true;
1137
1139 "Access specifier is AS_none inside a record decl");
1140#endif
1141 return true;
1142}
1143
1146
1149
1150 return isa_and_nonnull(DC);
1151}
1152
1155 return false;
1157 return M && M->isNamedModule() &&
1159}
1160
1163
1164 if (!M)
1165 return false;
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175 M = M->getTopLevelModule();
1176 if (!M->isNamedModule())
1177 return false;
1178
1180}
1181
1184
1185 if (!M || !M->isNamedModule())
1186 return false;
1187
1189}
1190
1193 if (!Source)
1194 return false;
1195
1197}
1198
1202
1206
1210
1214
1217
1221
1224 if (const auto *D = dyn_cast(this))
1225 Ty = D->getType();
1226 else if (const auto *D = dyn_cast(this))
1227 Ty = D->getUnderlyingType();
1228 else
1229 return nullptr;
1230
1232
1233
1235 return nullptr;
1236 }
1237
1246
1248}
1249
1252 if (const auto *D = dyn_cast(this))
1253 Ty = D->getType();
1254 else if (const auto *D = dyn_cast(this))
1255 Ty = D->getUnderlyingType();
1256 else
1257 return false;
1258
1260}
1261
1266
1267
1268
1270 if (getKind(D) == Decl::CXXMethod) {
1272 if (MD->getOverloadedOperator() == OO_Call &&
1273 MD->getParent()->isLambda())
1275 return MD;
1276 }
1277 if (auto *FD = dyn_cast(D))
1278 return FD;
1279 if (auto *MD = dyn_cast(D))
1280 return MD;
1281 if (auto *BD = dyn_cast(D))
1283 if (auto *CD = dyn_cast(D))
1285 if (auto *OFD = dyn_cast(D))
1287 return nullptr;
1288}
1289
1291 return ::getNonClosureContext(this);
1292}
1293
1295 return ::getNonClosureContext(this);
1296}
1297
1298
1299
1300
1301
1306 setNeedToReconcileExternalVisibleStorage(false);
1307 setHasLazyLocalLexicalLookups(false);
1308 setHasLazyExternalLexicalLookups(false);
1310}
1311
1314 switch (DK) {
1315#define DECL(NAME, BASE)
1316#define DECL_CONTEXT(NAME) case Decl::NAME:
1317#include "clang/AST/DeclNodes.inc"
1318 return true;
1319 default:
1320 return false;
1321 }
1322}
1323
1325
1326
1327
1328
1329
1330
1331
1333
1338
1339
1340
1341
1344
1346}
1347
1350
1351 do {
1355 } while (Ctx);
1356
1357 return nullptr;
1358}
1359
1364
1367 return false;
1368
1370 if (ND->isInline()) {
1371 return ND->getParent()->isStdNamespace();
1372 }
1373
1375 return false;
1376
1378 return II && II->isStr("std");
1379}
1380
1383 return false;
1384
1386 return true;
1387
1388 if (const auto *Record = dyn_cast(this)) {
1389 if (Record->getDescribedClassTemplate())
1390 return true;
1391
1392 if (Record->isDependentLambda())
1393 return true;
1394 if (Record->isNeverDependentLambda())
1395 return false;
1396 }
1397
1398 if (const auto *Function = dyn_cast(this)) {
1399 if (Function->getDescribedFunctionTemplate())
1400 return true;
1401
1402
1403
1404 if (cast(this)->getFriendObjectKind())
1406 }
1407
1408
1409
1410
1411
1413}
1414
1421
1424 while (DC->getDeclKind() != Decl::TranslationUnit) {
1425 if (DC->getDeclKind() == Decl::LinkageSpec)
1428 }
1429 return false;
1430}
1431
1435
1438 while (DC->getDeclKind() != Decl::TranslationUnit) {
1439 if (DC->getDeclKind() == Decl::LinkageSpec &&
1443 }
1444 return nullptr;
1445}
1446
1450
1454
1455 for (; DC; DC = DC->getParent())
1458 return true;
1459 return false;
1460}
1461
1465
1469 return true;
1470 return false;
1471}
1472
1477 assert(DC && "All transparent contexts should have a parent!");
1478 }
1479 return DC;
1480}
1481
1484 case Decl::ExternCContext:
1485 case Decl::LinkageSpec:
1486 case Decl::Export:
1487 case Decl::TopLevelStmt:
1488 case Decl::Block:
1489 case Decl::Captured:
1490 case Decl::OutlinedFunction:
1491 case Decl::OMPDeclareReduction:
1492 case Decl::OMPDeclareMapper:
1493 case Decl::RequiresExprBody:
1494
1495 return this;
1496
1497 case Decl::HLSLBuffer:
1498
1499
1500
1501
1502
1503
1504 return this;
1505
1506 case Decl::TranslationUnit:
1508 case Decl::Namespace:
1509 return static_cast<NamespaceDecl *>(this)->getFirstDecl();
1510
1511 case Decl::ObjCMethod:
1512 return this;
1513
1514 case Decl::ObjCInterface:
1515 if (auto *OID = dyn_cast(this))
1516 if (auto *Def = OID->getDefinition())
1517 return Def;
1518 return this;
1519
1520 case Decl::ObjCProtocol:
1521 if (auto *OPD = dyn_cast(this))
1522 if (auto *Def = OPD->getDefinition())
1523 return Def;
1524 return this;
1525
1526 case Decl::ObjCCategory:
1527 return this;
1528
1529 case Decl::ObjCImplementation:
1530 case Decl::ObjCCategoryImpl:
1531 return this;
1532
1533
1534
1535 case Decl::ClassTemplatePartialSpecialization:
1536 case Decl::ClassTemplateSpecialization:
1537 case Decl::CXXRecord:
1539 case Decl::Record:
1540 case Decl::Enum:
1541 return cast(this)->getDefinitionOrSelf();
1542
1543 default:
1544 assert(getDeclKind() >= Decl::firstFunction &&
1545 getDeclKind() <= Decl::lastFunction && "Unknown DeclContext kind");
1546 return this;
1547 }
1548}
1549
1550template
1553 for (T *D = Self->getMostRecentDecl(); D; D = D->getPreviousDecl())
1554 Contexts.push_back(D);
1555
1556 std::reverse(Contexts.begin(), Contexts.end());
1557}
1558
1560 Contexts.clear();
1561
1563
1564 if (Kind == Decl::TranslationUnit)
1566 else if (Kind == Decl::Namespace)
1568 else
1569 Contexts.push_back(this);
1570}
1571
1572std::pair<Decl *, Decl *>
1574 bool FieldsAlreadyLoaded) {
1575
1576 Decl *FirstNewDecl = nullptr;
1577 Decl *PrevDecl = nullptr;
1578 for (auto *D : Decls) {
1580 continue;
1581
1582 if (PrevDecl)
1584 else
1585 FirstNewDecl = D;
1586
1587 PrevDecl = D;
1588 }
1589
1590 return std::make_pair(FirstNewDecl, PrevDecl);
1591}
1592
1593
1594
1595
1596void DeclContext::reconcileExternalVisibleStorage() const {
1597 assert(hasNeedToReconcileExternalVisibleStorage() && LookupPtr);
1598 setNeedToReconcileExternalVisibleStorage(false);
1599
1601 Lookup.second.setHasExternalDecls();
1602}
1603
1604
1605
1606
1607bool
1608DeclContext::LoadLexicalDeclsFromExternalStorage() const {
1611
1612
1614
1615
1618 Source->FindExternalLexicalDecls(this, Decls);
1619
1620 if (Decls.empty())
1621 return false;
1622
1623
1624
1625 bool FieldsAlreadyLoaded = false;
1626 if (const auto *RD = dyn_cast(this))
1627 FieldsAlreadyLoaded = RD->hasLoadedFieldsFromExternalStorage();
1628
1629
1630
1631 Decl *ExternalFirst, *ExternalLast;
1632 std::tie(ExternalFirst, ExternalLast) =
1638 return true;
1639}
1640
1647 Map = DC->CreateStoredDeclsMap(Context);
1648 if (DC->hasNeedToReconcileExternalVisibleStorage())
1649 DC->reconcileExternalVisibleStorage();
1650
1651 (*Map)[Name].removeExternalDecls();
1652
1654}
1655
1663 Map = DC->CreateStoredDeclsMap(Context);
1664 if (DC->hasNeedToReconcileExternalVisibleStorage())
1665 DC->reconcileExternalVisibleStorage();
1666
1670}
1671
1674 LoadLexicalDeclsFromExternalStorage();
1676}
1677
1680 LoadLexicalDeclsFromExternalStorage();
1681
1683}
1684
1689
1692 LoadLexicalDeclsFromExternalStorage();
1694}
1695
1696
1697
1699
1701 return true;
1702
1703
1704
1707 return true;
1708
1709
1710
1713 return true;
1714
1715
1716
1717
1718
1720 return true;
1721 if (auto *FD = dyn_cast(D))
1722 if (FD->isFunctionTemplateSpecialization())
1723 return true;
1724
1725
1726
1727
1728
1730 return true;
1731
1732 return false;
1733}
1734
1737 "decl being removed from non-lexical context");
1739 "decl is not in decls list");
1740
1741
1745 else
1747 } else {
1748 for (Decl *I = FirstDecl; true; I = I->NextInContextAndBits.getPointer()) {
1749 assert(I && "decl not found in linked list");
1750 if (I->NextInContextAndBits.getPointer() == D) {
1753 break;
1754 }
1755 }
1756 }
1757
1758
1760
1761
1764
1765
1766
1768 return;
1769
1770
1771 if (!ND->getDeclName())
1772 return;
1773
1775 do {
1776 StoredDeclsMap *Map = DC->getPrimaryContext()->LookupPtr;
1777 if (Map) {
1778 StoredDeclsMap::iterator Pos = Map->find(ND->getDeclName());
1779 assert(Pos != Map->end() && "no lookup entry for decl");
1782
1784 Map->erase(Pos);
1785 }
1786 } while (DC->isTransparentContext() && (DC = DC->getParent()));
1787 }
1788}
1789
1792 "Decl inserted into wrong lexical context");
1794 "Decl already inserted into a DeclContext");
1795
1797 LastDecl->NextInContextAndBits.setPointer(D);
1799 } else {
1801 }
1802
1803
1804
1805 if (auto *Record = dyn_cast(this))
1806 Record->addedMember(D);
1807
1808
1809
1811 if (auto *Import = dyn_cast(D))
1813 }
1814}
1815
1818
1819 if (auto *ND = dyn_cast(D))
1820 ND->getDeclContext()->getPrimaryContext()->
1821 makeDeclVisibleInContextWithFlags(ND, false, true);
1822}
1823
1826
1827 if (auto *ND = dyn_cast(D))
1828 ND->getDeclContext()->getPrimaryContext()->
1829 makeDeclVisibleInContextWithFlags(ND, true, true);
1830}
1831
1832
1833
1834
1835
1836
1837
1838
1840 assert(this == getPrimaryContext() && "buildLookup called on non-primary DC");
1841
1842 if (!hasLazyLocalLexicalLookups() &&
1843 !hasLazyExternalLexicalLookups())
1845
1848
1849 if (hasLazyExternalLexicalLookups()) {
1850 setHasLazyExternalLexicalLookups(false);
1851 for (auto *DC : Contexts) {
1852 if (DC->hasExternalLexicalStorage()) {
1853 bool LoadedDecls = DC->LoadLexicalDeclsFromExternalStorage();
1854 setHasLazyLocalLexicalLookups(
1855 hasLazyLocalLexicalLookups() | LoadedDecls );
1856 }
1857 }
1858
1859 if (!hasLazyLocalLexicalLookups())
1861 }
1862
1863 for (auto *DC : Contexts)
1865
1866
1867 setHasLazyLocalLexicalLookups(false);
1869}
1870
1871
1872
1873
1874
1877
1878
1879
1880
1881
1882
1883
1884
1885 if (auto *ND = dyn_cast(D))
1886 if (ND->getDeclContext() == DCtx && (ND) &&
1887 (!ND->isFromASTFile() ||
1890 makeDeclVisibleInContextImpl(ND, Internal);
1891
1892
1893
1894
1895 if (auto *InnerCtx = dyn_cast(D))
1896 if (InnerCtx->isTransparentContext() || InnerCtx->isInlineNamespace())
1897 buildLookupImpl(InnerCtx, Internal);
1898 }
1899}
1900
1909
1912 const DeclContext *OriginalLookupDC) const {
1914 "lookupImpl should only be called with primary DC!");
1916 "We shouldn't lookup in transparent DC.");
1917
1918
1919
1920
1922 if (Source)
1923 (void)cast(this)->getMostRecentDecl();
1924
1926 assert(Source && "external visible storage but no external source?");
1927
1928 if (hasNeedToReconcileExternalVisibleStorage())
1929 reconcileExternalVisibleStorage();
1930
1932
1933 if (hasLazyLocalLexicalLookups() ||
1934 hasLazyExternalLexicalLookups())
1935
1937
1938 if (!Map)
1940
1941
1942 std::pair<StoredDeclsMap::iterator, bool> R = Map->try_emplace(Name);
1943 if (!R.second && !R.first->second.hasExternalDecls())
1944 return R.first->second.getLookupResult();
1945
1946 if (Source->FindExternalVisibleDeclsByName(this, Name, OriginalLookupDC) ||
1947 !R.second) {
1949 StoredDeclsMap::iterator I = Map->find(Name);
1950 if (I != Map->end())
1951 return I->second.getLookupResult();
1952 }
1953 }
1954
1955 return {};
1956 }
1957
1958 StoredDeclsMap *Map = LookupPtr;
1959 if (hasLazyLocalLexicalLookups() ||
1960 hasLazyExternalLexicalLookups())
1962
1963 if (!Map)
1964 return {};
1965
1966 StoredDeclsMap::iterator I = Map->find(Name);
1967 if (I == Map->end())
1968 return {};
1969
1970 return I->second.getLookupResult();
1971}
1972
1975
1978
1980 if (PrimaryContext != this)
1982
1983 loadLazyLocalLexicalLookups();
1985 if (!Map)
1986 return {};
1987
1988 StoredDeclsMap::iterator I = Map->find(Name);
1989 return I != Map->end() ? I->second.getLookupResult()
1991}
1992
1993
1994
1995
1996void DeclContext::loadLazyLocalLexicalLookups() {
1997 if (hasLazyLocalLexicalLookups()) {
2000 for (auto *Context : Contexts)
2002 setHasLazyLocalLexicalLookups(false);
2003 }
2004}
2005
2008 Results.clear();
2009
2010
2011
2014 llvm::append_range(Results, LookupResults);
2015 if (!Results.empty())
2016 return;
2017 }
2018
2019
2020
2021 if (Name && !hasLazyLocalLexicalLookups() &&
2022 !hasLazyExternalLexicalLookups()) {
2024 StoredDeclsMap::iterator Pos = Map->find(Name);
2025 if (Pos != Map->end()) {
2026 Results.insert(Results.end(),
2027 Pos->second.getLookupResult().begin(),
2028 Pos->second.getLookupResult().end());
2029 return;
2030 }
2031 }
2032 }
2033
2034
2035
2036
2037
2038 for (Decl *D = FirstDecl; D; D = D->getNextDeclInContext()) {
2039 if (auto *ND = dyn_cast(D))
2040 if (ND->getDeclName() == Name)
2041 Results.push_back(ND);
2042 }
2043}
2044
2047
2048
2049
2050
2051
2052
2053 bool SkipRecords = getDeclKind() == Decl::Kind::Enum &&
2055
2056
2057
2060 return Ctx;
2061}
2062
2070
2072
2078 }
2079 return OutermostRD;
2080}
2081
2083
2085 return O->Equals(this);
2086
2087 do {
2088 if (O->Equals(this))
2089 return true;
2090
2091 const auto *NS = dyn_cast(O);
2092 if (!NS || !NS->isInline())
2093 break;
2095 } while (O);
2096
2097 return false;
2098}
2099
2103
2104
2105 PrimaryDC->makeDeclVisibleInContextWithFlags(D, false, PrimaryDC == DeclDC);
2106}
2107
2108void DeclContext::makeDeclVisibleInContextWithFlags(NamedDecl *D, bool Internal,
2109 bool Recoverable) {
2111
2115 ->makeDeclVisibleInContextWithFlags(D, Internal, Recoverable);
2116 return;
2117 }
2118
2119
2121 return;
2122
2123
2124
2125
2126
2127
2128
2129
2130
2135
2136
2137
2139 makeDeclVisibleInContextImpl(D, Internal);
2140 } else {
2141 setHasLazyLocalLexicalLookups(true);
2142 }
2143
2144
2145
2148 makeDeclVisibleInContextWithFlags(D, Internal, Recoverable);
2149
2151
2153 if (ASTMutationListener *L = DCAsDecl->getASTMutationListener())
2154 L->AddedVisibleDecl(this, D);
2155}
2156
2157void DeclContext::makeDeclVisibleInContextImpl(NamedDecl *D, bool Internal) {
2158
2159 StoredDeclsMap *Map = LookupPtr;
2160 if (!Map) {
2162 Map = CreateStoredDeclsMap(*C);
2163 }
2164
2165
2166
2167
2168
2174
2175
2176 StoredDeclsList &DeclNameEntries = (*Map)[D->getDeclName()];
2177
2179
2180
2181
2182
2185 return;
2186 }
2187
2189}
2190
2194
2195
2196
2203
2204
2205
2206
2207
2209 assert( && "context already has a decls map");
2211 "creating decls map on non-primary context");
2212
2217 else
2219 M->Previous = C.LastSDM;
2220 C.LastSDM = llvm::PointerIntPair<StoredDeclsMap*,1>(M, Dependent);
2222 return M;
2223}
2224
2225void ASTContext::ReleaseDeclContextMaps() {
2226
2227
2228
2230 LastSDM.setPointer(nullptr);
2231}
2232
2234 while (Map) {
2235
2236 llvm::PointerIntPair<StoredDeclsMap*,1> Next = Map->Previous;
2237
2240 else
2241 delete Map;
2242
2243 Map = Next.getPointer();
2245 }
2246}
2247
2252 && "cannot iterate dependent diagnostics of non-dependent context");
2255 Parent->CreateStoredDeclsMap(C);
2256
2258
2259
2260
2264
2266
2267
2268 DD->NextDiagnostic = Map->FirstDiagnostic;
2269 Map->FirstDiagnostic = DD;
2270
2271 return DD;
2272}
2273
2275 return ID & llvm::maskTrailingOnes(32);
2276}
Defines the clang::ASTContext interface.
#define BuiltinTemplate(BTName)
This file provides some common utility functions for processing Lambda related AST Constructs.
static bool shouldBeHidden(NamedDecl *D)
shouldBeHidden - Determine whether a declaration which was declared within its semantic context shoul...
Definition DeclBase.cpp:1698
static void collectAllContextsImpl(T *Self, SmallVectorImpl< DeclContext * > &Contexts)
Definition DeclBase.cpp:1551
static bool isLinkageSpecContext(const DeclContext *DC, LinkageSpecLanguageIDs ID)
Definition DeclBase.cpp:1422
static Decl::Kind getKind(const Decl *D)
Definition DeclBase.cpp:1215
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:1269
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:670
static StringRef getRealizedPlatform(const AvailabilityAttr *A, const ASTContext &Context)
Definition DeclBase.cpp:648
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
This file defines OpenACC nodes for declarative directives.
This file defines OpenMP nodes for declarative directives.
Defines the C++ template declaration subclasses.
FormatToken * Next
The next token in the unwrapped line.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
llvm::MachO::Record Record
Defines the clang::Module class, which describes a module in the source code.
Defines types useful for describing an Objective-C runtime.
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream.
Defines the clang::SourceLocation class and associated facilities.
static QualType getPointeeType(const MemRegion *R)
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const ConstantArrayType * getAsConstantArrayType(QualType T) const
ASTMutationListener * getASTMutationListener() const
Retrieve a pointer to the AST mutation listener associated with this AST context, if any.
const IncompleteArrayType * getAsIncompleteArrayType(QualType T) const
const LangOptions & getLangOpts() const
llvm::BumpPtrAllocator & getAllocator() const
void eraseDeclAttrs(const Decl *D)
Erase the attributes corresponding to the given declaration.
void addedLocalImportDecl(ImportDecl *Import)
Notify the AST context that a new import declaration has been parsed or implicitly created within thi...
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
Module * getCurrentNamedModule() const
Get module under construction, nullptr if this is not a C++20 module.
AttrVec & getDeclAttrs(const Decl *D)
Retrieve the attributes for the given declaration.
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
Attr - This represents one attribute.
Represents a block literal declaration, which is like an unnamed FunctionDecl.
decl_iterator - Iterates through the declarations stored within this context.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
udir_range using_directives() const
Returns iterator range [First, Last) of UsingDirectiveDecls stored within this context.
Definition DeclBase.cpp:2197
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC.
bool isFileContext() const
void setHasExternalVisibleStorage(bool ES=true) const
State whether this DeclContext has external storage for declarations visible in this context.
void makeDeclVisibleInContext(NamedDecl *D)
Makes a declaration visible within this context.
Definition DeclBase.cpp:2100
DeclContextLookupResult lookup_result
static std::pair< Decl *, Decl * > BuildDeclChain(ArrayRef< Decl * > Decls, bool FieldsAlreadyLoaded)
Build up a chain of declarations.
Definition DeclBase.cpp:1573
bool isTransparentContext() const
isTransparentContext - Determines whether this context is a "transparent" context,...
Definition DeclBase.cpp:1415
Decl * getNonClosureAncestor()
Find the nearest non-closure ancestor of this context, i.e.
Definition DeclBase.cpp:1294
ASTContext & getParentASTContext() const
bool isExternCXXContext() const
Determines whether this context or some of its ancestors is a linkage specification context that spec...
Definition DeclBase.cpp:1447
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition DeclBase.cpp:1381
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:2082
DeclContext * getLexicalParent()
getLexicalParent - Returns the containing lexical DeclContext.
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition DeclBase.cpp:1902
bool isLookupContext() const
Test whether the context supports looking up names.
const BlockDecl * getInnermostBlockDecl() const
Return this DeclContext if it is a BlockDecl.
Definition DeclBase.cpp:1348
bool hasExternalVisibleStorage() const
Whether this DeclContext has external storage containing additional declarations that are visible in ...
const char * getDeclKindName() const
Definition DeclBase.cpp:210
bool isTranslationUnit() const
void collectAllContexts(SmallVectorImpl< DeclContext * > &Contexts)
Collects all of the declaration contexts that are semantically connected to this declaration context.
Definition DeclBase.cpp:1559
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition DeclBase.cpp:2045
llvm::iterator_range< udir_iterator > udir_range
Decl * FirstDecl
FirstDecl - The first declaration stored within this declaration context.
DeclContext(Decl::Kind K)
Definition DeclBase.cpp:1302
void addDeclInternal(Decl *D)
Add the declaration D into this context, but suppress searches for external declarations with the sam...
Definition DeclBase.cpp:1824
bool containsDeclAndLoad(Decl *D) const
Checks whether a declaration is in this context.
Definition DeclBase.cpp:1690
void removeDecl(Decl *D)
Removes a declaration from this context.
Definition DeclBase.cpp:1735
void addDecl(Decl *D)
Add the declaration D into this context.
Definition DeclBase.cpp:1816
StoredDeclsMap * buildLookup()
Ensure the lookup structure is fully-built and return it.
Definition DeclBase.cpp:1839
bool hasValidDeclKind() const
Definition DeclBase.cpp:201
bool isStdNamespace() const
Definition DeclBase.cpp:1365
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:1974
static bool classof(const Decl *D)
Definition DeclBase.cpp:1312
bool containsDecl(Decl *D) const
Checks whether a declaration is in this context.
Definition DeclBase.cpp:1685
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
void setUseQualifiedLookup(bool use=true) const
DeclContext * getEnclosingNamespaceContext()
Retrieve the nearest enclosing namespace context.
Definition DeclBase.cpp:2063
friend class ExternalASTSource
For reconcileExternalVisibleStorage, CreateStoredDeclsMap, hasNeedToReconcileExternalVisibleStorage.
Decl * LastDecl
LastDecl - The last declaration stored within this declaration context.
decl_range noload_decls() const
noload_decls_begin/end - Iterate over the declarations stored in this context that are currently load...
friend class DependentDiagnostic
For CreateStoredDeclsMap.
DeclContext * getPrimaryContext()
getPrimaryContext - There may be many different declarations of the same entity (including forward de...
Definition DeclBase.cpp:1482
RecordDecl * getOuterLexicalRecordContext()
Retrieve the outermost lexically enclosing record context.
Definition DeclBase.cpp:2071
bool decls_empty() const
Definition DeclBase.cpp:1678
bool isInlineNamespace() const
Definition DeclBase.cpp:1360
DeclContextBitfields DeclContextBits
bool isFunctionOrMethod() const
void setHasExternalLexicalStorage(bool ES=true) const
State whether this DeclContext has external storage for declarations lexically in this context.
DeclContext * getLookupParent()
Find the parent context of this context that will be used for unqualified name lookup.
Definition DeclBase.cpp:1332
StoredDeclsMap * LookupPtr
Pointer to the data structure used to lookup declarations within this context (or a DependentStoredDe...
bool isExternCContext() const
Determines whether this context or some of its ancestors is a linkage specification context that spec...
Definition DeclBase.cpp:1432
const LinkageSpecDecl * getExternCContext() const
Retrieve the nearest enclosing C linkage specification context.
Definition DeclBase.cpp:1436
bool Encloses(const DeclContext *DC) const
Determine whether this declaration context semantically encloses the declaration context DC.
Definition DeclBase.cpp:1451
void addHiddenDecl(Decl *D)
Add the declaration D to this context without modifying any lookup tables.
Definition DeclBase.cpp:1790
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:2006
Decl::Kind getDeclKind() const
DeclContext * getNonTransparentContext()
Definition DeclBase.cpp:1473
decl_iterator decls_begin() const
Definition DeclBase.cpp:1672
bool LexicallyEncloses(const DeclContext *DC) const
Determine whether this declaration context lexically encloses the declaration context DC.
Definition DeclBase.cpp:1462
unsigned getLocalDeclIndex() const
Definition DeclBase.cpp:2274
Decl - This represents one declaration (or definition), e.g.
Decl * getMostRecentDecl()
Retrieve the most recent declaration that declares the same entity as this declaration (which may be ...
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:341
bool isInStdNamespace() const
Definition DeclBase.cpp:449
bool isInCurrentModuleUnit() const
Whether this declaration comes from the same module unit being compiled.
Definition DeclBase.cpp:1182
TemplateDecl * getDescribedTemplate() const
If this is a declaration that describes some template, this method returns that template declaration.
Definition DeclBase.cpp:285
bool isTemplateDecl() const
returns true if this declaration is a template
Definition DeclBase.cpp:281
static void add(Kind k)
Definition DeclBase.cpp:248
Module * getTopLevelOwningNamedModule() const
Get the top level owning named module that owns this declaration if any.
Definition DeclBase.cpp:152
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
bool isModuleLocal() const
Whether this declaration was a local declaration to a C++20 named module.
Definition DeclBase.cpp:1153
bool isFromGlobalModule() const
Whether this declaration comes from global module.
Definition DeclBase.cpp:1203
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:459
ASTContext & getASTContext() const LLVM_READONLY
Definition DeclBase.cpp:546
void setOwningModuleID(unsigned ID)
Set the owning module ID.
Definition DeclBase.cpp:126
void addAttr(Attr *A)
Definition DeclBase.cpp:1045
void setAttrs(const AttrVec &Attrs)
bool hasLocalOwningModuleStorage() const
Definition DeclBase.cpp:165
bool isFunctionPointerType() const
Definition DeclBase.cpp:1250
bool isInNamedModule() const
Whether this declaration comes from a named module.
Definition DeclBase.cpp:1207
ExternalSourceSymbolAttr * getExternalSourceSymbolAttr() const
Looks on this and related declarations for an applicable external source symbol attribute.
Definition DeclBase.cpp:612
bool isWeakImported() const
Determine whether this is a weak-imported symbol.
Definition DeclBase.cpp:870
ModuleOwnershipKind getModuleOwnershipKind() const
Get the kind of module ownership for this declaration.
bool isParameterPack() const
Whether this declaration is a parameter pack.
Definition DeclBase.cpp:266
ASTMutationListener * getASTMutationListener() const
Definition DeclBase.cpp:556
unsigned getMaxAlignment() const
getMaxAlignment - return the maximum alignment specified by attributes on this decl,...
Definition DeclBase.cpp:560
AvailabilityResult getAvailability(std::string *Message=nullptr, VersionTuple EnclosingVersion=VersionTuple(), StringRef *RealizedPlatform=nullptr) const
Determine the availability of the given declaration.
Definition DeclBase.cpp:775
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
Definition DeclBase.cpp:178
Kind
Lists the kind of concrete classes of Decl.
static unsigned getIdentifierNamespaceForKind(Kind DK)
Definition DeclBase.cpp:889
virtual Stmt * getBody() const
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
void markUsed(ASTContext &C)
Mark the declaration used, in the sense of odr-use.
Definition DeclBase.cpp:590
bool isFileContextDecl() const
Definition DeclBase.cpp:454
static Decl * castFromDeclContext(const DeclContext *)
Definition DeclBase.cpp:1073
Decl * getNextDeclInContext()
bool isTemplated() const
Determine whether this declaration is a templated entity (whether it is.
Definition DeclBase.cpp:308
bool isInExportDeclContext() const
Whether this declaration was exported in a lexical context.
Definition DeclBase.cpp:1144
SourceLocation getBodyRBrace() const
getBodyRBrace - Gets the right brace of the body, if a body exists.
Definition DeclBase.cpp:1099
int64_t getID() const
Definition DeclBase.cpp:1218
bool isReferenced() const
Whether any declaration of this entity was referenced.
Definition DeclBase.cpp:600
const FunctionType * getFunctionType(bool BlocksToo=true) const
Looks through the Decl's underlying type to extract a FunctionType when possible.
Definition DeclBase.cpp:1222
bool isInAnotherModuleUnit() const
Whether this declaration comes from another module unit.
Definition DeclBase.cpp:1161
llvm::PointerIntPair< Decl *, 3, ModuleOwnershipKind > NextInContextAndBits
The next declaration within the same lexical DeclContext.
Module * getOwningModule() const
Get the module that owns this declaration (for visibility purposes).
unsigned getTemplateDepth() const
Determine the number of levels of template parameter surrounding this declaration.
Definition DeclBase.cpp:320
bool isFromExplicitGlobalModule() const
Whether this declaration comes from explicit global module.
Definition DeclBase.cpp:1199
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
Definition DeclBase.cpp:273
bool canBeWeakImported(bool &IsDefinition) const
Determines whether this symbol can be weak-imported, e.g., whether it would be well-formed to add the...
Definition DeclBase.cpp:841
void dropAttrs()
Definition DeclBase.cpp:1038
static DeclContext * castToDeclContext(const Decl *)
Definition DeclBase.cpp:1086
const TemplateParameterList * getDescribedTemplateParams() const
If this is a declaration that describes some template or partial specialization, this returns the cor...
Definition DeclBase.cpp:298
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
bool isInLocalScopeForInstantiation() const
Determine whether a substitution into this declaration would occur as part of a substitution into a d...
Definition DeclBase.cpp:422
const Attr * getDefiningAttr() const
Return this declaration's defining attribute if it has one.
Definition DeclBase.cpp:638
bool isTemplateParameter() const
isTemplateParameter - Determines whether this declaration is a template parameter.
DeclContext * getNonTransparentDeclContext()
Return the non transparent context.
Definition DeclBase.cpp:1262
Decl * getNonClosureContext()
Find the innermost non-closure ancestor of this declaration, walking up through blocks,...
Definition DeclBase.cpp:1290
bool isInvalidDecl() const
unsigned getIdentifierNamespace() const
bool hasDefiningAttr() const
Return true if this declaration has an attribute which acts as definition of the entity,...
Definition DeclBase.cpp:633
bool isLocalExternDecl() const
Determine whether this is a block-scope declaration with linkage.
void setAccess(AccessSpecifier AS)
const char * getDeclKindName() const
Definition DeclBase.cpp:169
@ IDNS_Ordinary
Ordinary names.
@ IDNS_Type
Types, declared with 'struct foo', typedefs, etc.
@ IDNS_OMPReduction
This declaration is an OpenMP user defined reduction construction.
@ IDNS_Label
Labels, declared with 'x:' and referenced with 'goto x'.
@ IDNS_Member
Members, declared with object declarations within tag definitions.
@ IDNS_OMPMapper
This declaration is an OpenMP user defined mapper.
@ IDNS_ObjCProtocol
Objective C @protocol.
@ IDNS_Namespace
Namespaces, declared with 'namespace foo {}'.
@ IDNS_Using
This declaration is a using declaration.
@ IDNS_Tag
Tags, declared with 'struct foo;' and referenced with 'struct foo'.
bool isTemplateParameterPack() const
isTemplateParameter - Determines whether this declaration is a template parameter pack.
Definition DeclBase.cpp:256
void setLocalOwningModule(Module *M)
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
void setIsUsed()
Set whether the declaration is used, in the sense of odr-use.
unsigned Access
Access - Used by C++ decls for the access specifier.
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
Definition DeclBase.cpp:575
DeclContext * getDeclContext()
bool isInAnonymousNamespace() const
Definition DeclBase.cpp:439
static void EnableStatistics()
Definition DeclBase.cpp:220
TranslationUnitDecl * getTranslationUnitDecl()
Definition DeclBase.cpp:531
VersionTuple getVersionIntroduced() const
Retrieve the version of the target platform in which this declaration was introduced.
Definition DeclBase.cpp:827
bool hasOwningModule() const
Is this declaration owned by some module?
bool isFromHeaderUnit() const
Whether this declaration comes from a header unit.
Definition DeclBase.cpp:1211
static void PrintStats()
Definition DeclBase.cpp:224
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
Definition DeclBase.cpp:382
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
void setLexicalDeclContext(DeclContext *DC)
Definition DeclBase.cpp:386
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
@ 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.
void setModuleOwnershipKind(ModuleOwnershipKind MOK)
Set whether this declaration is hidden from name lookup.
const LangOptions & getLangOpts() const LLVM_READONLY
Helper to get the language options from the ASTContext.
Definition DeclBase.cpp:552
GlobalDeclID getGlobalID() const
Retrieve the global declaration ID associated with this declaration, which specifies where this Decl ...
Definition DeclBase.cpp:110
unsigned getOwningModuleID() const
Retrieve the global ID of the module that owns this particular declaration.
Definition DeclBase.cpp:118
bool shouldEmitInExternalSource() const
Whether the definition of the declaration should be emitted in external sources.
Definition DeclBase.cpp:1191
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.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
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:1657
static DeclContextLookupResult SetNoExternalVisibleDeclsForName(const DeclContext *DC, DeclarationName Name)
Definition DeclBase.cpp:1642
virtual Module * getModule(unsigned ID)
Retrieve the module that corresponds to the given module ID.
virtual bool FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name, const DeclContext *OriginalDC)
Find all declarations with the given name in the given context, and add them to the context by callin...
Represents a member of a struct/union/class.
Represents a function declaration or definition.
FunctionType - C99 6.7.5.3 - Function Declarators.
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.
StrictFlexArraysLevelKind
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
bool trackLocalOwningModule() const
Do we need to track the owning module for a local declaration?
Represents a linkage specification.
A pointer to member type per C++ 8.3.3 - Pointers to members.
Describes a module or submodule.
bool isExplicitGlobalModule() const
bool isGlobalModule() const
Does this Module scope describe a fragment of the global module within some C++ module.
bool isHeaderUnit() const
Is this module a header unit.
bool isNamedModule() const
Does this Module is a named module of a standard named module?
Module * getTopLevelModule()
Retrieve the top-level module for this (sub)module, which may be this module.
This represents a decl that may have a name.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Represent a C++ namespace.
The basic abstraction for the target Objective-C runtime.
bool hasWeakClassImport() const
Does this runtime support weakly importing classes?
PointerType - C99 6.7.5.1 - Pointer Declarators.
void print(raw_ostream &OS) const override
Definition DeclBase.cpp:355
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
QualType getCanonicalType() const
Represents a struct/union/class.
specific_decl_iterator< FieldDecl > field_iterator
Base for LValueReferenceType and RValueReferenceType.
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.
An array of decls optimized for the common case of only containing one entry.
void setHasExternalDecls()
void addOrReplaceDecl(NamedDecl *D)
If this is a redeclaration of an existing decl, replace the old one with D.
void prependDeclNoReplace(NamedDecl *D)
Add a declaration to the list without checking if it replaces anything.
void replaceExternalDecls(ArrayRef< NamedDecl * > Decls)
void remove(NamedDecl *D)
DeclContext::lookup_result getLookupResult() const
Return the list of all the decls.
static void DestroyAll(StoredDeclsMap *Map, bool Dependent)
Definition DeclBase.cpp:2233
The base class of all kinds of template declarations (e.g., class, function, etc.).
Stores a list of template parameters for a TemplateDecl and its derived classes.
The top declaration context.
ASTContext & getASTContext() const
Base wrapper for a particular "section" of type source info.
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
T getAsAdjusted() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
A container of type source information.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
bool isBlockPointerType() const
bool isFunctionReferenceType() const
bool isFunctionPointerType() const
const T * castAs() const
Member-template castAs.
bool isMemberFunctionPointerType() const
const T * getAs() const
Member-template getAs'.
Wrapper for source info for typedefs.
Represents C++ using-directive.
specific_attr_iterator - Iterates over a subrange of an AttrVec, only providing attributes that are o...
Defines the clang::TargetInfo interface.
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
LinkageSpecLanguageIDs
Represents the language in a linkage specification.
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
SmallVector< Attr *, 4 > AttrVec
AttrVec - A vector of Attr, which is how they are stored on the AST.
@ Dependent
Parse the block as a dependent block, which may be used in some template instantiations but not other...
@ Internal
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
bool isLambdaCallOperator(const CXXMethodDecl *MD)
@ Result
The result type of a method or function.
const FunctionProtoType * T
@ 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.
U cast(CodeGen::Address addr)
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
UsingDirectiveDecl * operator*() const
Definition DeclBase.cpp:2191