clang: lib/AST/DeclBase.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
37#include "llvm/ADT/PointerIntPair.h"
38#include "llvm/ADT/StringRef.h"
39#include "llvm/Support/ErrorHandling.h"
40#include "llvm/Support/MathExtras.h"
41#include "llvm/Support/VersionTuple.h"
42#include "llvm/Support/raw_ostream.h"
43#include
44#include
45#include
46#include
47#include
48#include
49
50using namespace clang;
51
52
53
54
55
56#define DECL(DERIVED, BASE) static int n##DERIVED##s = 0;
57#define ABSTRACT_DECL(DECL)
58#include "clang/AST/DeclNodes.inc"
59
62}
63
64#define DECL(DERIVED, BASE) \
65 static_assert(alignof(Decl) >= alignof(DERIVED##Decl), \
66 "Alignment sufficient after objects prepended to " #DERIVED);
67#define ABSTRACT_DECL(DECL)
68#include "clang/AST/DeclNodes.inc"
69
70void *Decl::operator new(std::size_t Size, const ASTContext &Context,
72
73
74 static_assert(sizeof(uint64_t) >= alignof(Decl), "Decl won't be misaligned");
75 void *Start = Context.Allocate(Size + Extra + 8);
76 void *Result = (char*)Start + 8;
77
78 uint64_t *PrefixPtr = (uint64_t *)Result - 1;
79
80 *PrefixPtr = ID.getRawValue();
81
82
83
84 assert(*PrefixPtr < llvm::maskTrailingOnes<uint64_t>(48));
85
87}
88
89void *Decl::operator new(std::size_t Size, const ASTContext &Ctx,
91 assert( || &Parent->getParentASTContext() == &Ctx);
92
93
94
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 uint64_t *IDAddress = (uint64_t *)this - 1;
129 *IDAddress &= llvm::maskTrailingOnes<uint64_t>(48);
130 *IDAddress |= (uint64_t)ID << 48;
131}
132
137
138 return nullptr;
139}
140
141Module *Decl::getOwningModuleSlow() const {
144}
145
148}
149
151 switch (DeclKind) {
152 default: llvm_unreachable("Declaration not in DeclNodes.inc!");
153#define DECL(DERIVED, BASE) case DERIVED: return #DERIVED;
154#define ABSTRACT_DECL(DECL)
155#include "clang/AST/DeclNodes.inc"
156 }
157}
158
161 assert(!isa(this) || !cast(this)->isCompleteDefinition());
163 return;
164 }
165
166 if (!isa(this)) {
167
168
169
171 }
172
173
174
175 if (auto *DD = dyn_cast(this)) {
176 for (auto *Binding : DD->bindings()) {
177 Binding->setInvalidDecl();
178 }
179 }
180}
181
184#define DECL(DERIVED, BASE) case Decl::DERIVED: return true;
185#define ABSTRACT_DECL(DECL)
186#include "clang/AST/DeclNodes.inc"
187 }
188 return false;
189}
190
193#define DECL(DERIVED, BASE) case Decl::DERIVED: return #DERIVED;
194#define ABSTRACT_DECL(DECL)
195#include "clang/AST/DeclNodes.inc"
196 }
197 llvm_unreachable("Declaration context not in DeclNodes.inc!");
198}
199
200bool Decl::StatisticsEnabled = false;
202 StatisticsEnabled = true;
203}
204
206 llvm::errs() << "\n*** Decl Stats:\n";
207
208 int totalDecls = 0;
209#define DECL(DERIVED, BASE) totalDecls += n##DERIVED##s;
210#define ABSTRACT_DECL(DECL)
211#include "clang/AST/DeclNodes.inc"
212 llvm::errs() << " " << totalDecls << " decls total.\n";
213
214 int totalBytes = 0;
215#define DECL(DERIVED, BASE) \
216 if (n##DERIVED##s > 0) { \
217 totalBytes += (int)(n##DERIVED##s * sizeof(DERIVED##Decl)); \
218 llvm::errs() << " " << n##DERIVED##s << " " #DERIVED " decls, " \
219 << sizeof(DERIVED##Decl) << " each (" \
220 << n##DERIVED##s * sizeof(DERIVED##Decl) \
221 << " bytes)\n"; \
222 }
223#define ABSTRACT_DECL(DECL)
224#include "clang/AST/DeclNodes.inc"
225
226 llvm::errs() << "Total bytes = " << totalBytes << "\n";
227}
228
230 switch (k) {
231#define DECL(DERIVED, BASE) case DERIVED: ++n##DERIVED##s; break;
232#define ABSTRACT_DECL(DECL)
233#include "clang/AST/DeclNodes.inc"
234 }
235}
236
238 if (const auto *TTP = dyn_cast(this))
239 return TTP->isParameterPack();
240 if (const auto *NTTP = dyn_cast(this))
241 return NTTP->isParameterPack();
242 if (const auto *TTP = dyn_cast(this))
243 return TTP->isParameterPack();
244 return false;
245}
246
248 if (const auto *Var = dyn_cast(this))
249 return Var->isParameterPack();
250
252}
253
255 if (auto *FD = dyn_cast(this))
256 return FD;
257 if (const auto *FTD = dyn_cast(this))
258 return FTD->getTemplatedDecl();
259 return nullptr;
260}
261
263 return isa(this);
264}
265
267 if (auto *FD = dyn_cast(this))
268 return FD->getDescribedFunctionTemplate();
269 if (auto *RD = dyn_cast(this))
270 return RD->getDescribedClassTemplate();
271 if (auto *VD = dyn_cast(this))
272 return VD->getDescribedVarTemplate();
273 if (auto *AD = dyn_cast(this))
274 return AD->getDescribedAliasTemplate();
275
276 return nullptr;
277}
278
281 return TD->getTemplateParameters();
282 if (auto *CTPSD = dyn_cast(this))
283 return CTPSD->getTemplateParameters();
284 if (auto *VTPSD = dyn_cast(this))
285 return VTPSD->getTemplateParameters();
286 return nullptr;
287}
288
290
291
292
293 if (auto *AsDC = dyn_cast(this))
294 return AsDC->isDependentContext();
297 return DC->isDependentContext() || isTemplateDecl() ||
299}
300
302 if (auto *DC = dyn_cast(this))
303 if (DC->isFileContext())
304 return 0;
305
307 return TPL->getDepth() + 1;
308
309
310
311
312 auto *RD = dyn_cast(this);
313 if (RD && RD->isDependentLambda())
314 if (Decl *Context = RD->getLambdaContextDecl())
315 return Context->getTemplateDepth();
316
319 return cast(DC)->getTemplateDepth();
320}
321
325 DC && !DC->isFileContext(); DC = DC->getParent())
326 if (DC->isFunctionOrMethod())
327 return DC;
328
329 return nullptr;
330}
331
332
333
334
335
338 if (TheLoc.isInvalid() && TheDecl)
340
342 TheLoc.print(OS, SM);
343 OS << ": ";
344 }
345
346 OS << Message;
347
348 if (const auto *DN = dyn_cast_or_null(TheDecl)) {
349 OS << " '";
350 DN->printQualifiedName(OS);
351 OS << '\'';
352 }
353 OS << '\n';
354}
355
356
357
358
359
360
362
364 DeclCtx = DC;
365}
366
369 return;
370
371 if (isInSemaDC()) {
373 } else {
374 getMultipleDC()->LexicalDC = DC;
375 }
376
377
378
383 }
384
385 assert(
388 "hidden declaration has no owning module");
389}
390
393 if (SemaDC == LexicalDC) {
394 DeclCtx = SemaDC;
395 } else {
396 auto *MDC = new (Ctx) Decl::MultipleDC();
397 MDC->SemanticDC = SemaDC;
398 MDC->LexicalDC = LexicalDC;
399 DeclCtx = MDC;
400 }
401}
402
406 return false;
407 while (true) {
409 return true;
410 if (!isa(LDC))
411 return false;
412 if (const auto *CRD = dyn_cast(LDC))
413 if (CRD->isLambda())
414 return true;
416 }
417 return false;
418}
419
422 if (const auto *ND = dyn_cast(DC))
423 if (ND->isAnonymousNamespace())
424 return true;
425 }
426
427 return false;
428}
429
433}
434
436 const auto *DC = dyn_cast(this);
437 return DC && DC->isFileContext();
438}
439
443 bool IgnoreTemplateOrMacroSubstitution) {
444
445
447 if (CAT) {
449
450 llvm::APInt Size = CAT->getSize();
451 if (StrictFlexArraysLevel == FAMKind::IncompleteOnly)
452 return false;
453
454
455 if (Size.isZero())
456 return true;
457
458 if (StrictFlexArraysLevel == FAMKind::ZeroOrIncomplete && Size.uge(1))
459 return false;
460
461 if (StrictFlexArraysLevel == FAMKind::OneZeroOrIncomplete && Size.uge(2))
462 return false;
464 return false;
465 }
466
467 if (const auto *OID = dyn_cast_if_present(D))
468 return OID->getNextIvar() == nullptr;
469
470 const auto *FD = dyn_cast_if_present(D);
471 if (!FD)
472 return false;
473
474 if (CAT) {
475
476
477 llvm::APInt Size = CAT->getSize();
478 if (FD->getParent()->isUnion() && (Size.isZero() || Size.isOne()))
479 return true;
480 }
481
482
483
484 if (IgnoreTemplateOrMacroSubstitution) {
486 while (TInfo) {
488
489
493 continue;
494 }
495
497 if (const Expr *SizeExpr =
498 dyn_cast_if_present(CTL.getSizeExpr());
500 return false;
501 }
502
503 break;
504 }
505 }
506
507
510 return ++FI == FD->getParent()->field_end();
511}
512
514 if (auto *TUD = dyn_cast(this))
515 return TUD;
516
518 assert(DC && "This decl is not contained in a translation unit!");
519
522 assert(DC && "This decl is not contained in a translation unit!");
523 }
524
525 return cast(DC);
526}
527
530}
531
532
533
536}
537
540}
541
544 return 0;
545
546 unsigned Align = 0;
550 for (; I != E; ++I) {
551 if (!I->isAlignmentErrorDependent())
552 Align = std::max(Align, I->getAlignment(Ctx));
553 }
554 return Align;
555}
556
559 if (CanonD->Used)
560 return true;
561
562
563
565 return true;
566
567
568
570}
571
574 return;
575
576 if (C.getASTMutationListener())
577 C.getASTMutationListener()->DeclarationMarkedUsed(this);
578
580}
581
583 if (Referenced)
584 return true;
585
586
587 for (const auto *I : redecls())
588 if (I->Referenced)
589 return true;
590
591 return false;
592}
593
596 if (auto *ID = dyn_cast(this)) {
598 } else if (auto *PD = dyn_cast(this)) {
600 } else if (auto *TD = dyn_cast(this)) {
602 }
605
606 if (auto *attr = Definition->getAttr())
609 return dcd->getAttr();
610 }
611
612 return nullptr;
613}
614
616 return hasAttr() || hasAttr() ||
617 hasAttr();
618}
619
621 if (auto *AA = getAttr())
622 return AA;
623 if (auto *IFA = getAttr())
624 return IFA;
625 if (auto *NZA = getAttr())
626 return NZA;
627 return nullptr;
628}
629
632
633
634 StringRef RealizedPlatform = A->getPlatform()->getName();
636 return RealizedPlatform;
637 size_t suffix = RealizedPlatform.rfind("_app_extension");
638 if (suffix != StringRef::npos)
639 return RealizedPlatform.slice(0, suffix);
640 return RealizedPlatform;
641}
642
643
644
645
646
647
648
649
650
651
653 const AvailabilityAttr *A,
654 std::string *Message,
655 VersionTuple EnclosingVersion) {
656 if (EnclosingVersion.empty())
658
659 if (EnclosingVersion.empty())
661
662 StringRef ActualPlatform = A->getPlatform()->getName();
664
665
668
669 StringRef PrettyPlatformName
670 = AvailabilityAttr::getPrettyPlatformName(ActualPlatform);
671
672 if (PrettyPlatformName.empty())
673 PrettyPlatformName = ActualPlatform;
674
675 std::string HintMessage;
676 if (!A->getMessage().empty()) {
677 HintMessage = " - ";
678 HintMessage += A->getMessage();
679 }
680
681
682 if (A->getUnavailable()) {
683 if (Message) {
684 Message->clear();
685 llvm::raw_string_ostream Out(*Message);
686 Out << "not available on " << PrettyPlatformName
687 << HintMessage;
688 }
689
691 }
692
693
694 if (!A->getIntroduced().empty() &&
695 EnclosingVersion < A->getIntroduced()) {
697 StringRef TargetEnv =
699 StringRef EnvName = llvm::Triple::getEnvironmentTypeName(
701
702 if (!IIEnv || (!TargetEnv.empty() && IIEnv->getName() == TargetEnv)) {
703 if (Message) {
704 Message->clear();
705 llvm::raw_string_ostream Out(*Message);
706 VersionTuple VTI(A->getIntroduced());
707 Out << "introduced in " << PrettyPlatformName << " " << VTI << " "
708 << EnvName << HintMessage;
709 }
710 }
711
712 else {
713 if (Message) {
714 Message->clear();
715 llvm::raw_string_ostream Out(*Message);
716 Out << "not available on " << PrettyPlatformName << " " << EnvName
717 << HintMessage;
718 }
719 }
720
722 }
723
724
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
735 }
736
737
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
748 }
749
751}
752
754 VersionTuple EnclosingVersion,
755 StringRef *RealizedPlatform) const {
756 if (auto *FTD = dyn_cast(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(A)) {
766 continue;
767
768 if (Message)
769 ResultMessage = std::string(Deprecated->getMessage());
770
772 continue;
773 }
774
775 if (const auto *Unavailable = dyn_cast(A)) {
776 if (Message)
777 *Message = std::string(Unavailable->getMessage());
779 }
780
781 if (const auto *Availability = dyn_cast(A)) {
783 Message, EnclosingVersion);
784
786 if (RealizedPlatform)
787 *RealizedPlatform = Availability->getPlatform()->getName();
789 }
790
793 if (Message)
794 ResultMessage.swap(*Message);
795 }
796 continue;
797 }
798 }
799
800 if (Message)
801 Message->swap(ResultMessage);
803}
804
808 for (const auto *A : attrs()) {
809 if (const auto *Availability = dyn_cast(A)) {
811 continue;
812 if (!Availability->getIntroduced().empty())
813 return Availability->getIntroduced();
814 }
815 }
816 return {};
817}
818
820 IsDefinition = false;
821
822
823 if (const auto *Var = dyn_cast(this)) {
824 if (Var->isThisDeclarationADefinition()) {
825 IsDefinition = true;
826 return false;
827 }
828 return true;
829 }
830
831 if (const auto *FD = dyn_cast(this)) {
832 if (FD->hasBody()) {
833 IsDefinition = true;
834 return false;
835 }
836 return true;
837
838 }
839
840 if (isa(this) &&
842 return true;
843 }
844
845 return false;
846}
847
849 bool IsDefinition;
851 return false;
852
854 if (isa(A))
855 return true;
856
857 if (const auto *Availability = dyn_cast(A)) {
860 return true;
861 }
862 }
863
864 return false;
865}
866
868 switch (DeclKind) {
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:
887
888 case Binding:
889 case NonTypeTemplateParm:
890 case VarTemplate:
891 case Concept:
892
893
895
896 case ObjCCompatibleAlias:
897 case ObjCInterface:
899
900 case Typedef:
901 case TypeAlias:
902 case TemplateTypeParm:
903 case ObjCTypeParam:
905
906 case UnresolvedUsingTypename:
908
909 case UsingShadow:
910 return 0;
911
912 case UnresolvedUsingValue:
914
915 case Using:
916 case UsingPack:
917 case UsingEnum:
919
920 case ObjCProtocol:
922
923 case Field:
924 case IndirectField:
925 case ObjCAtDefsField:
926 case ObjCIvar:
928
930 case CXXRecord:
933
934 case Namespace:
935 case NamespaceAlias:
937
938 case FunctionTemplate:
940
941 case ClassTemplate:
942 case TemplateTemplateParm:
943 case TypeAliasTemplate:
945
946 case UnresolvedUsingIfExists:
948
949 case OMPDeclareReduction:
951
952 case OMPDeclareMapper:
954
955
957 case FriendTemplate:
958 case AccessSpec:
959 case LinkageSpec:
960 case Export:
961 case FileScopeAsm:
962 case TopLevelStmt:
963 case StaticAssert:
964 case ObjCPropertyImpl:
965 case PragmaComment:
966 case PragmaDetectMismatch:
968 case Captured:
969 case TranslationUnit:
970 case ExternCContext:
971 case Decomposition:
972 case MSGuid:
973 case UnnamedGlobalConstant:
974 case TemplateParamObject:
975
976 case UsingDirective:
977 case BuiltinTemplate:
978 case ClassTemplateSpecialization:
979 case ClassTemplatePartialSpecialization:
980 case VarTemplateSpecialization:
981 case VarTemplatePartialSpecialization:
982 case ObjCImplementation:
983 case ObjCCategory:
984 case ObjCCategoryImpl:
985 case Import:
986 case OMPThreadPrivate:
987 case OMPAllocate:
988 case OMPRequires:
989 case OMPCapturedExpr:
991 case LifetimeExtendedTemporary:
992 case RequiresExprBody:
993 case ImplicitConceptSpecialization:
994
995 return 0;
996 }
997
998 llvm_unreachable("Invalid DeclKind!");
999}
1000
1002 assert(!HasAttrs && "Decl already contains attrs.");
1003
1005 assert(AttrBlank.empty() && "HasAttrs was wrong?");
1006
1007 AttrBlank = attrs;
1008 HasAttrs = true;
1009}
1010
1012 if (!HasAttrs) return;
1013
1014 HasAttrs = false;
1016}
1017
1021 return;
1022 }
1023
1026 Attrs.push_back(A);
1027 return;
1028 }
1029
1030
1031
1032
1033 auto I = Attrs.begin(), E = Attrs.end();
1034 for (; I != E; ++I) {
1035 if (!(*I)->isInherited())
1036 break;
1037 }
1038 Attrs.insert(I, A);
1039}
1040
1042 assert(HasAttrs && "No attrs to get!");
1044}
1045
1048 switch (DK) {
1049#define DECL(NAME, BASE)
1050#define DECL_CONTEXT(NAME) \
1051 case Decl::NAME: \
1052 return static_cast<NAME##Decl *>(const_cast<DeclContext *>(D));
1053#include "clang/AST/DeclNodes.inc"
1054 default:
1055 llvm_unreachable("a decl that inherits DeclContext isn't handled");
1056 }
1057}
1058
1061 switch(DK) {
1062#define DECL(NAME, BASE)
1063#define DECL_CONTEXT(NAME) \
1064 case Decl::NAME: \
1065 return static_cast<NAME##Decl *>(const_cast<Decl *>(D));
1066#include "clang/AST/DeclNodes.inc"
1067 default:
1068 llvm_unreachable("a decl that inherits DeclContext isn't handled");
1069 }
1070}
1071
1073
1074
1075 if (const auto *FD = dyn_cast(this)) {
1078 return Definition->getSourceRange().getEnd();
1079 return {};
1080 }
1081
1083 return Body->getSourceRange().getEnd();
1084
1085 return {};
1086}
1087
1088bool Decl::AccessDeclContextCheck() const {
1089#ifndef NDEBUG
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099 if (isa(this) || isa(this) ||
1100 isa(this) || () ||
1102 isa(this) || isa(this) ||
1103
1104
1105 isa(this) ||
1106
1107
1108 isa(this) || isa(this))
1109 return true;
1110
1112 "Access specifier is AS_none inside a record decl");
1113#endif
1114 return true;
1115}
1116
1119
1120 while (DC && !isa(DC))
1122
1123 return isa_and_nonnull(DC);
1124}
1125
1128
1129 if (!M)
1130 return false;
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140 M = M->getTopLevelModule();
1141 if (!M->isNamedModule())
1142 return false;
1143
1145}
1146
1149
1150 if (!M || !M->isNamedModule())
1151 return false;
1152
1154}
1155
1158 if (!Source)
1159 return false;
1160
1162}
1163
1166}
1167
1170}
1171
1174}
1175
1178}
1179
1182
1185}
1186
1189 if (const auto *D = dyn_cast(this))
1190 Ty = D->getType();
1191 else if (const auto *D = dyn_cast(this))
1192 Ty = D->getUnderlyingType();
1193 else
1194 return nullptr;
1195
1197
1198
1199 assert(isa(this));
1200 return nullptr;
1201 }
1202
1209
1211}
1212
1215 if (const auto *D = dyn_cast(this))
1216 Ty = D->getType();
1217 else if (const auto *D = dyn_cast(this))
1218 Ty = D->getUnderlyingType();
1219 else
1220 return false;
1221
1223}
1224
1228}
1229
1230
1231
1233 if (getKind(D) == Decl::CXXMethod) {
1234 auto *MD = cast(D);
1235 if (MD->getOverloadedOperator() == OO_Call &&
1236 MD->getParent()->isLambda())
1238 return MD;
1239 }
1240 if (auto *FD = dyn_cast(D))
1241 return FD;
1242 if (auto *MD = dyn_cast(D))
1243 return MD;
1244 if (auto *BD = dyn_cast(D))
1246 if (auto *CD = dyn_cast(D))
1248 return nullptr;
1249}
1250
1252 return ::getNonClosureContext(this);
1253}
1254
1256 return ::getNonClosureContext(this);
1257}
1258
1259
1260
1261
1262
1267 setNeedToReconcileExternalVisibleStorage(false);
1268 setHasLazyLocalLexicalLookups(false);
1269 setHasLazyExternalLexicalLookups(false);
1271}
1272
1275 switch (DK) {
1276#define DECL(NAME, BASE)
1277#define DECL_CONTEXT(NAME) case Decl::NAME:
1278#include "clang/AST/DeclNodes.inc"
1279 return true;
1280 default:
1281 return false;
1282 }
1283}
1284
1286
1287
1288
1289
1290
1291
1292
1294
1295 if (isa(this))
1299
1300
1301
1302
1305
1307}
1308
1311
1312 do {
1313 if (Ctx->isClosure())
1314 return cast(Ctx);
1315 Ctx = Ctx->getParent();
1316 } while (Ctx);
1317
1318 return nullptr;
1319}
1320
1323 cast(this)->isInline();
1324}
1325
1328 return false;
1329
1330 const auto *ND = cast(this);
1331 if (ND->isInline()) {
1332 return ND->getParent()->isStdNamespace();
1333 }
1334
1336 return false;
1337
1339 return II && II->isStr("std");
1340}
1341
1344 return false;
1345
1346 if (isa(this))
1347 return true;
1348
1349 if (const auto *Record = dyn_cast(this)) {
1350 if (Record->getDescribedClassTemplate())
1351 return true;
1352
1353 if (Record->isDependentLambda())
1354 return true;
1355 if (Record->isNeverDependentLambda())
1356 return false;
1357 }
1358
1359 if (const auto *Function = dyn_cast(this)) {
1360 if (Function->getDescribedFunctionTemplate())
1361 return true;
1362
1363
1364
1365 if (cast(this)->getFriendObjectKind())
1367 }
1368
1369
1370
1371
1372
1374}
1375
1378 return !cast(this)->isScoped();
1379
1380 return isa<LinkageSpecDecl, ExportDecl, HLSLBufferDecl>(this);
1381}
1382
1385 while (DC->getDeclKind() != Decl::TranslationUnit) {
1386 if (DC->getDeclKind() == Decl::LinkageSpec)
1387 return cast(DC)->getLanguage() == ID;
1389 }
1390 return false;
1391}
1392
1395}
1396
1399 while (DC->getDeclKind() != Decl::TranslationUnit) {
1400 if (DC->getDeclKind() == Decl::LinkageSpec &&
1402 return cast(DC);
1404 }
1405 return nullptr;
1406}
1407
1410}
1411
1415
1416 for (; DC; DC = DC->getParent())
1417 if (!isa(DC) && !isa(DC) &&
1419 return true;
1420 return false;
1421}
1422
1427 assert(DC && "All transparent contexts should have a parent!");
1428 }
1429 return DC;
1430}
1431
1434 case Decl::ExternCContext:
1435 case Decl::LinkageSpec:
1436 case Decl::Export:
1437 case Decl::TopLevelStmt:
1438 case Decl::Block:
1439 case Decl::Captured:
1440 case Decl::OMPDeclareReduction:
1441 case Decl::OMPDeclareMapper:
1442 case Decl::RequiresExprBody:
1443
1444 return this;
1445
1446 case Decl::HLSLBuffer:
1447
1448
1449
1450
1451
1452
1453 return this;
1454
1455 case Decl::TranslationUnit:
1457 case Decl::Namespace:
1458 return static_cast<NamespaceDecl *>(this)->getFirstDecl();
1459
1460 case Decl::ObjCMethod:
1461 return this;
1462
1463 case Decl::ObjCInterface:
1464 if (auto *OID = dyn_cast(this))
1465 if (auto *Def = OID->getDefinition())
1466 return Def;
1467 return this;
1468
1469 case Decl::ObjCProtocol:
1470 if (auto *OPD = dyn_cast(this))
1471 if (auto *Def = OPD->getDefinition())
1472 return Def;
1473 return this;
1474
1475 case Decl::ObjCCategory:
1476 return this;
1477
1478 case Decl::ObjCImplementation:
1479 case Decl::ObjCCategoryImpl:
1480 return this;
1481
1482 default:
1484
1485
1486 auto *Tag = cast(this);
1487
1488 if (TagDecl *Def = Tag->getDefinition())
1489 return Def;
1490
1491 if (const auto *TagTy = dyn_cast(Tag->getTypeForDecl())) {
1492
1493 TagDecl *PossiblePartialDef = TagTy->getDecl();
1495 return PossiblePartialDef;
1496 } else {
1497 assert(isa(Tag->getTypeForDecl()));
1498 }
1499
1500 return Tag;
1501 }
1502
1503 assert(getDeclKind() >= Decl::firstFunction &&
1505 "Unknown DeclContext kind");
1506 return this;
1507 }
1508}
1509
1510template
1514 Contexts.push_back(D);
1515
1516 std::reverse(Contexts.begin(), Contexts.end());
1517}
1518
1520 Contexts.clear();
1521
1523
1524 if (Kind == Decl::TranslationUnit)
1526 else if (Kind == Decl::Namespace)
1528 else
1529 Contexts.push_back(this);
1530}
1531
1532std::pair<Decl *, Decl *>
1534 bool FieldsAlreadyLoaded) {
1535
1536 Decl *FirstNewDecl = nullptr;
1537 Decl *PrevDecl = nullptr;
1538 for (auto *D : Decls) {
1539 if (FieldsAlreadyLoaded && isa(D))
1540 continue;
1541
1542 if (PrevDecl)
1544 else
1545 FirstNewDecl = D;
1546
1547 PrevDecl = D;
1548 }
1549
1550 return std::make_pair(FirstNewDecl, PrevDecl);
1551}
1552
1553
1554
1555
1556void DeclContext::reconcileExternalVisibleStorage() const {
1557 assert(hasNeedToReconcileExternalVisibleStorage() && LookupPtr);
1558 setNeedToReconcileExternalVisibleStorage(false);
1559
1561 Lookup.second.setHasExternalDecls();
1562}
1563
1564
1565
1566
1567bool
1568DeclContext::LoadLexicalDeclsFromExternalStorage() const {
1571
1572
1574
1575
1579
1580 if (Decls.empty())
1581 return false;
1582
1583
1584
1585 bool FieldsAlreadyLoaded = false;
1586 if (const auto *RD = dyn_cast(this))
1587 FieldsAlreadyLoaded = RD->hasLoadedFieldsFromExternalStorage();
1588
1589
1590
1591 Decl *ExternalFirst, *ExternalLast;
1592 std::tie(ExternalFirst, ExternalLast) =
1598 return true;
1599}
1600
1607 Map = DC->CreateStoredDeclsMap(Context);
1608 if (DC->hasNeedToReconcileExternalVisibleStorage())
1609 DC->reconcileExternalVisibleStorage();
1610
1611 (*Map)[Name].removeExternalDecls();
1612
1614}
1615
1623 Map = DC->CreateStoredDeclsMap(Context);
1624 if (DC->hasNeedToReconcileExternalVisibleStorage())
1625 DC->reconcileExternalVisibleStorage();
1626
1628 List.replaceExternalDecls(Decls);
1629 return List.getLookupResult();
1630}
1631
1634 LoadLexicalDeclsFromExternalStorage();
1636}
1637
1640 LoadLexicalDeclsFromExternalStorage();
1641
1643}
1644
1648}
1649
1652 LoadLexicalDeclsFromExternalStorage();
1654}
1655
1656
1657
1659
1660 if (->getDeclName())
1661 return true;
1662
1663
1664
1667 return true;
1668
1669
1670
1673 return true;
1674
1675
1676
1677
1678
1679 if (isa(D))
1680 return true;
1681 if (auto *FD = dyn_cast(D))
1682 if (FD->isFunctionTemplateSpecialization())
1683 return true;
1684
1685
1686
1687
1688
1690 return true;
1691
1692 return false;
1693}
1694
1697 "decl being removed from non-lexical context");
1699 "decl is not in decls list");
1700
1701
1705 else
1707 } else {
1709 assert(I && "decl not found in linked list");
1710 if (I->NextInContextAndBits.getPointer() == D) {
1713 break;
1714 }
1715 }
1716 }
1717
1718
1720
1721
1722 if (isa(D)) {
1723 auto *ND = cast(D);
1724
1725
1726
1728 return;
1729
1730
1731 if (!ND->getDeclName())
1732 return;
1733
1735 do {
1736 StoredDeclsMap *Map = DC->getPrimaryContext()->LookupPtr;
1737 if (Map) {
1738 StoredDeclsMap::iterator Pos = Map->find(ND->getDeclName());
1739 assert(Pos != Map->end() && "no lookup entry for decl");
1741 List.remove(ND);
1742
1743 if (List.isNull())
1744 Map->erase(Pos);
1745 }
1746 } while (DC->isTransparentContext() && (DC = DC->getParent()));
1747 }
1748}
1749
1752 "Decl inserted into wrong lexical context");
1754 "Decl already inserted into a DeclContext");
1755
1759 } else {
1761 }
1762
1763
1764
1765 if (auto *Record = dyn_cast(this))
1767
1768
1769
1771 if (auto *Import = dyn_cast(D))
1773 }
1774}
1775
1778
1779 if (auto *ND = dyn_cast(D))
1780 ND->getDeclContext()->getPrimaryContext()->
1781 makeDeclVisibleInContextWithFlags(ND, false, true);
1782}
1783
1786
1787 if (auto *ND = dyn_cast(D))
1788 ND->getDeclContext()->getPrimaryContext()->
1789 makeDeclVisibleInContextWithFlags(ND, true, true);
1790}
1791
1792
1793
1794
1795
1796
1797
1798
1800 assert(this == getPrimaryContext() && "buildLookup called on non-primary DC");
1801
1802 if (!hasLazyLocalLexicalLookups() &&
1803 !hasLazyExternalLexicalLookups())
1805
1808
1809 if (hasLazyExternalLexicalLookups()) {
1810 setHasLazyExternalLexicalLookups(false);
1811 for (auto *DC : Contexts) {
1812 if (DC->hasExternalLexicalStorage()) {
1813 bool LoadedDecls = DC->LoadLexicalDeclsFromExternalStorage();
1814 setHasLazyLocalLexicalLookups(
1815 hasLazyLocalLexicalLookups() | LoadedDecls );
1816 }
1817 }
1818
1819 if (!hasLazyLocalLexicalLookups())
1821 }
1822
1823 for (auto *DC : Contexts)
1825
1826
1827 setHasLazyLocalLexicalLookups(false);
1829}
1830
1831
1832
1833
1834
1837
1838
1839
1840
1841
1842
1843
1844
1845 if (auto *ND = dyn_cast(D))
1846 if (ND->getDeclContext() == DCtx && (ND) &&
1847 (!ND->isFromASTFile() ||
1850 makeDeclVisibleInContextImpl(ND, Internal);
1851
1852
1853
1854
1855 if (auto *InnerCtx = dyn_cast(D))
1856 if (InnerCtx->isTransparentContext() || InnerCtx->isInlineNamespace())
1857 buildLookupImpl(InnerCtx, Internal);
1858 }
1859}
1860
1863
1866
1868}
1869
1872 const DeclContext *OriginalLookupDC) const {
1874 "lookupImpl should only be called with primary DC!");
1876 "We shouldn't lookup in transparent DC.");
1877
1878
1879
1880
1882 if (Source)
1883 (void)cast(this)->getMostRecentDecl();
1884
1886 assert(Source && "external visible storage but no external source?");
1887
1888 if (hasNeedToReconcileExternalVisibleStorage())
1889 reconcileExternalVisibleStorage();
1890
1892
1893 if (hasLazyLocalLexicalLookups() ||
1894 hasLazyExternalLexicalLookups())
1895
1897
1898 if (!Map)
1900
1901
1902 std::pair<StoredDeclsMap::iterator, bool> R =
1904 if (!R.second && !R.first->second.hasExternalDecls())
1905 return R.first->second.getLookupResult();
1906
1908 !R.second) {
1910 StoredDeclsMap::iterator I = Map->find(Name);
1911 if (I != Map->end())
1912 return I->second.getLookupResult();
1913 }
1914 }
1915
1916 return {};
1917 }
1918
1920 if (hasLazyLocalLexicalLookups() ||
1921 hasLazyExternalLexicalLookups())
1923
1924 if (!Map)
1925 return {};
1926
1927 StoredDeclsMap::iterator I = Map->find(Name);
1928 if (I == Map->end())
1929 return {};
1930
1931 return I->second.getLookupResult();
1932}
1933
1936
1939
1941 if (PrimaryContext != this)
1943
1944 loadLazyLocalLexicalLookups();
1946 if (!Map)
1947 return {};
1948
1949 StoredDeclsMap::iterator I = Map->find(Name);
1950 return I != Map->end() ? I->second.getLookupResult()
1952}
1953
1954
1955
1956
1957void DeclContext::loadLazyLocalLexicalLookups() {
1958 if (hasLazyLocalLexicalLookups()) {
1961 for (auto *Context : Contexts)
1963 setHasLazyLocalLexicalLookups(false);
1964 }
1965}
1966
1969 Results.clear();
1970
1971
1972
1975 Results.insert(Results.end(), LookupResults.begin(), LookupResults.end());
1976 if (!Results.empty())
1977 return;
1978 }
1979
1980
1981
1982 if (Name && !hasLazyLocalLexicalLookups() &&
1983 !hasLazyExternalLexicalLookups()) {
1985 StoredDeclsMap::iterator Pos = Map->find(Name);
1986 if (Pos != Map->end()) {
1987 Results.insert(Results.end(),
1988 Pos->second.getLookupResult().begin(),
1989 Pos->second.getLookupResult().end());
1990 return;
1991 }
1992 }
1993 }
1994
1995
1996
1997
1998
2000 if (auto *ND = dyn_cast(D))
2001 if (ND->getDeclName() == Name)
2002 Results.push_back(ND);
2003 }
2004}
2005
2008
2009
2010
2011
2012
2013
2014 bool SkipRecords = getDeclKind() == Decl::Kind::Enum &&
2016
2017
2018
2019 while ((SkipRecords && Ctx->isRecord()) || Ctx->isTransparentContext())
2020 Ctx = Ctx->getParent();
2021 return Ctx;
2022}
2023
2026
2027 while (!Ctx->isFileContext())
2028 Ctx = Ctx->getParent();
2029 return Ctx->getPrimaryContext();
2030}
2031
2033
2037 OutermostRD = cast(DC);
2039 }
2040 return OutermostRD;
2041}
2042
2044
2046 return O->Equals(this);
2047
2048 do {
2049 if (O->Equals(this))
2050 return true;
2051
2052 const auto *NS = dyn_cast(O);
2053 if (!NS || !NS->isInline())
2054 break;
2056 } while (O);
2057
2058 return false;
2059}
2060
2064
2065
2066 PrimaryDC->makeDeclVisibleInContextWithFlags(D, false, PrimaryDC == DeclDC);
2067}
2068
2069void DeclContext::makeDeclVisibleInContextWithFlags(NamedDecl *D, bool Internal,
2070 bool Recoverable) {
2072
2076 ->makeDeclVisibleInContextWithFlags(D, Internal, Recoverable);
2077 return;
2078 }
2079
2080
2082 return;
2083
2084
2085
2086
2087
2088
2089
2090
2091
2096
2097
2098
2100 makeDeclVisibleInContextImpl(D, Internal);
2101 } else {
2102 setHasLazyLocalLexicalLookups(true);
2103 }
2104
2105
2106
2109 makeDeclVisibleInContextWithFlags(D, Internal, Recoverable);
2110
2111 auto *DCAsDecl = cast(this);
2112
2113 if (!(isa(DCAsDecl) && cast(DCAsDecl)->isBeingDefined()))
2115 L->AddedVisibleDecl(this, D);
2116}
2117
2118void DeclContext::makeDeclVisibleInContextImpl(NamedDecl *D, bool Internal) {
2119
2121 if (!Map) {
2123 Map = CreateStoredDeclsMap(*C);
2124 }
2125
2126
2127
2128
2129
2133 Map->find(D->getDeclName()) == Map->end())
2136
2137
2138 StoredDeclsList &DeclNameEntries = (*Map)[D->getDeclName()];
2139
2141
2142
2143
2144
2147 return;
2148 }
2149
2151}
2152
2154 return cast(*I);
2155}
2156
2157
2158
2160
2161
2164}
2165
2166
2167
2168
2169
2171 assert( && "context already has a decls map");
2173 "creating decls map on non-primary context");
2174
2179 else
2181 M->Previous = C.LastSDM;
2182 C.LastSDM = llvm::PointerIntPair<StoredDeclsMap*,1>(M, Dependent);
2184 return M;
2185}
2186
2187void ASTContext::ReleaseDeclContextMaps() {
2188
2189
2190
2192 LastSDM.setPointer(nullptr);
2193}
2194
2196 while (Map) {
2197
2198 llvm::PointerIntPair<StoredDeclsMap*,1> Next = Map->Previous;
2199
2202 else
2203 delete Map;
2204
2205 Map = Next.getPointer();
2207 }
2208}
2209
2213 assert(Parent->isDependentContext()
2214 && "cannot iterate dependent diagnostics of non-dependent context");
2216 if (->LookupPtr)
2217 Parent->CreateStoredDeclsMap(C);
2218
2220
2221
2222
2226
2228
2229
2230 DD->NextDiagnostic = Map->FirstDiagnostic;
2231 Map->FirstDiagnostic = DD;
2232
2233 return DD;
2234}
2235
2237 return ID & llvm::maskTrailingOnes(32);
2238}
Defines the clang::ASTContext interface.
This file provides some common utility functions for processing Lambda related AST Constructs.
static bool shouldBeHidden(NamedDecl *D)
shouldBeHidden - Determine whether a declaration which was declared within its semantic context shoul...
static void collectAllContextsImpl(T *Self, SmallVectorImpl< DeclContext * > &Contexts)
static bool isLinkageSpecContext(const DeclContext *DC, LinkageSpecLanguageIDs ID)
static Decl::Kind getKind(const Decl *D)
static Decl * getNonClosureContext(T *D)
Starting at a given context (a Decl or DeclContext), look for a code context that is not a closure (a...
static AvailabilityResult CheckAvailability(ASTContext &Context, const AvailabilityAttr *A, std::string *Message, VersionTuple EnclosingVersion)
Determine the availability of the given declaration based on the target platform.
static StringRef getRealizedPlatform(const AvailabilityAttr *A, const ASTContext &Context)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
This file defines OpenMP nodes for declarative directives.
Defines the C++ template declaration subclasses.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
llvm::MachO::Record Record
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...
void * Allocate(size_t Size, unsigned Align=8) const
const TargetInfo & getTargetInfo() const
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.
The results of name lookup within a DeclContext.
decl_iterator - Iterates through the declarations stored within this context.
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext,...
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.
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.
DeclContextLookupResult lookup_result
static std::pair< Decl *, Decl * > BuildDeclChain(ArrayRef< Decl * > Decls, bool FieldsAlreadyLoaded)
Build up a chain of declarations.
bool isTransparentContext() const
isTransparentContext - Determines whether this context is a "transparent" context,...
Decl * getNonClosureAncestor()
Find the nearest non-closure ancestor of this context, i.e.
ASTContext & getParentASTContext() const
bool isExternCXXContext() const
Determines whether this context or some of its ancestors is a linkage specification context that spec...
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
bool InEnclosingNamespaceSetOf(const DeclContext *NS) const
Test if this context is part of the enclosing namespace set of the context NS, as defined in C++0x [n...
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.
bool isLookupContext() const
Test whether the context supports looking up names.
const BlockDecl * getInnermostBlockDecl() const
Return this DeclContext if it is a BlockDecl.
bool hasExternalVisibleStorage() const
Whether this DeclContext has external storage containing additional declarations that are visible in ...
const char * getDeclKindName() const
bool isTranslationUnit() const
void collectAllContexts(SmallVectorImpl< DeclContext * > &Contexts)
Collects all of the declaration contexts that are semantically connected to this declaration context.
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
llvm::iterator_range< udir_iterator > udir_range
Decl * FirstDecl
FirstDecl - The first declaration stored within this declaration context.
DeclContext(Decl::Kind K)
void addDeclInternal(Decl *D)
Add the declaration D into this context, but suppress searches for external declarations with the sam...
bool containsDeclAndLoad(Decl *D) const
Checks whether a declaration is in this context.
void removeDecl(Decl *D)
Removes a declaration from this context.
void addDecl(Decl *D)
Add the declaration D into this context.
StoredDeclsMap * buildLookup()
Ensure the lookup structure is fully-built and return it.
bool hasValidDeclKind() const
bool isStdNamespace() const
lookup_result noload_lookup(DeclarationName Name)
Find the declarations with the given name that are visible within this context; don't attempt to retr...
static bool classof(const Decl *D)
bool containsDecl(Decl *D) const
Checks whether a declaration is in this context.
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
void setUseQualifiedLookup(bool use=true) const
DeclContext * getEnclosingNamespaceContext()
Retrieve the nearest enclosing namespace context.
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...
RecordDecl * getOuterLexicalRecordContext()
Retrieve the outermost lexically enclosing record context.
bool isInlineNamespace() const
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.
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...
const LinkageSpecDecl * getExternCContext() const
Retrieve the nearest enclosing C linkage specification context.
bool Encloses(const DeclContext *DC) const
Determine whether this declaration context encloses the declaration context DC.
void addHiddenDecl(Decl *D)
Add the declaration D to this context without modifying any lookup tables.
void localUncachedLookup(DeclarationName Name, SmallVectorImpl< NamedDecl * > &Results)
A simplistic name lookup mechanism that performs name lookup into this declaration context without co...
Decl::Kind getDeclKind() const
DeclContext * getNonTransparentContext()
decl_iterator decls_begin() const
unsigned getLocalDeclIndex() const
Decl - This represents one declaration (or definition), e.g.
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration,...
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,...
bool isInStdNamespace() const
bool isInCurrentModuleUnit() const
Whether this declaration comes from the same module unit being compiled.
TemplateDecl * getDescribedTemplate() const
If this is a declaration that describes some template, this method returns that template declaration.
bool isTemplateDecl() const
returns true if this declaration is a template
Module * getTopLevelOwningNamedModule() const
Get the top level owning named module that owns this declaration if any.
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
bool isFromGlobalModule() const
Whether this declaration comes from global module.
ASTContext & getASTContext() const LLVM_READONLY
void setOwningModuleID(unsigned ID)
Set the owning module ID.
void setAttrs(const AttrVec &Attrs)
bool hasLocalOwningModuleStorage() const
bool isFunctionPointerType() const
bool isInNamedModule() const
Whether this declaration comes from a named module.
ExternalSourceSymbolAttr * getExternalSourceSymbolAttr() const
Looks on this and related declarations for an applicable external source symbol attribute.
bool isWeakImported() const
Determine whether this is a weak-imported symbol.
ModuleOwnershipKind getModuleOwnershipKind() const
Get the kind of module ownership for this declaration.
bool isParameterPack() const
Whether this declaration is a parameter pack.
ASTMutationListener * getASTMutationListener() const
unsigned getMaxAlignment() const
getMaxAlignment - return the maximum alignment specified by attributes on this decl,...
AvailabilityResult getAvailability(std::string *Message=nullptr, VersionTuple EnclosingVersion=VersionTuple(), StringRef *RealizedPlatform=nullptr) const
Determine the availability of the given declaration.
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
Kind
Lists the kind of concrete classes of Decl.
static unsigned getIdentifierNamespaceForKind(Kind DK)
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.
bool isFileContextDecl() const
static Decl * castFromDeclContext(const DeclContext *)
Decl * getNextDeclInContext()
bool isTemplated() const
Determine whether this declaration is a templated entity (whether it is.
bool isInExportDeclContext() const
Whether this declaration was exported in a lexical context.
SourceLocation getBodyRBrace() const
getBodyRBrace - Gets the right brace of the body, if a body exists.
bool isReferenced() const
Whether any declaration of this entity was referenced.
const FunctionType * getFunctionType(bool BlocksToo=true) const
Looks through the Decl's underlying type to extract a FunctionType when possible.
bool isInAnotherModuleUnit() const
Whether this declaration comes from another module unit.
llvm::PointerIntPair< Decl *, 3, ModuleOwnershipKind > NextInContextAndBits
The next declaration within the same lexical DeclContext.
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.
bool isFromExplicitGlobalModule() const
Whether this declaration comes from explicit global module.
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
bool canBeWeakImported(bool &IsDefinition) const
Determines whether this symbol can be weak-imported, e.g., whether it would be well-formed to add the...
static DeclContext * castToDeclContext(const Decl *)
const TemplateParameterList * getDescribedTemplateParams() const
If this is a declaration that describes some template or partial specialization, this returns the cor...
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...
const Attr * getDefiningAttr() const
Return this declaration's defining attribute if it has one.
bool isTemplateParameter() const
isTemplateParameter - Determines whether this declaration is a template parameter.
DeclContext * getNonTransparentDeclContext()
Return the non transparent context.
Decl * getNonClosureContext()
Find the innermost non-closure ancestor of this declaration, walking up through blocks,...
bool isInvalidDecl() const
unsigned getIdentifierNamespace() const
bool hasDefiningAttr() const
Return true if this declaration has an attribute which acts as definition of the entity,...
bool isLocalExternDecl() const
Determine whether this is a block-scope declaration with linkage.
void setAccess(AccessSpecifier AS)
SourceLocation getLocation() const
const char * getDeclKindName() const
@ 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.
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.
DeclContext * getDeclContext()
bool isInAnonymousNamespace() const
static void EnableStatistics()
TranslationUnitDecl * getTranslationUnitDecl()
VersionTuple getVersionIntroduced() const
Retrieve the version of the target platform in which this declaration was introduced.
bool hasOwningModule() const
Is this declaration owned by some module?
bool isFromHeaderUnit() const
Whether this declaration comes from a header unit.
void updateOutOfDate(IdentifierInfo &II) const
Update a potentially out-of-date declaration.
static bool isFlexibleArrayMemberLike(ASTContext &Context, const Decl *D, QualType Ty, LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel, bool IgnoreTemplateOrMacroSubstitution)
Whether it resembles a flexible array member.
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
void setLexicalDeclContext(DeclContext *DC)
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.
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.
GlobalDeclID getGlobalID() const
Retrieve the global declaration ID associated with this declaration, which specifies where this Decl ...
unsigned getOwningModuleID() const
Retrieve the global ID of the module that owns this particular declaration.
bool shouldEmitInExternalSource() const
Whether the definition of the declaration should be emitted in external sources.
The name of a declaration.
A dependently-generated diagnostic.
static DependentDiagnostic * Create(ASTContext &Context, DeclContext *Parent, AccessNonce _, SourceLocation Loc, bool IsMemberAccess, AccessSpecifier AS, NamedDecl *TargetDecl, CXXRecordDecl *NamingClass, QualType BaseObjectType, const PartialDiagnostic &PDiag)
This represents one expression.
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)
static DeclContextLookupResult SetNoExternalVisibleDeclsForName(const DeclContext *DC, DeclarationName Name)
virtual Module * getModule(unsigned ID)
Retrieve the module that corresponds to the given module ID.
virtual bool FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name, const DeclContext *OriginalDC)
Find all declarations with the given name in the given context, and add them to the context by callin...
virtual void updateOutOfDateIdentifier(const IdentifierInfo &II)
Update an out-of-date identifier.
virtual void FindExternalLexicalDecls(const DeclContext *DC, llvm::function_ref< bool(Decl::Kind)> IsKindWeWant, SmallVectorImpl< Decl * > &Result)
Finds all declarations lexically contained within the given DeclContext, after applying an optional f...
Represents a member of a struct/union/class.
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.
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.
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
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.
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.
static void DestroyAll(StoredDeclsMap *Map, bool Dependent)
Represents the declaration of a struct/union/class/enum.
bool isBeingDefined() const
Return true if this decl is currently being defined.
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
StringRef getPlatformName() const
Retrieve the name of the platform as it is used in the availability attribute.
VersionTuple getPlatformMinVersion() const
Retrieve the minimum desired version of the platform, to which the program should be compiled.
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.
const T * getAs() const
Member-template getAs'.
Base class for declarations which introduce a typedef-name.
TypeSourceInfo * getTypeSourceInfo() const
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.
const internal::VariadicAllOfMatcher< Attr > attr
Matches attributes.
The JSON file list parser is used to communicate input to InstallAPI.
SmallVector< Attr *, 4 > AttrVec
AttrVec - A vector of Attr, which is how they are stored on the AST.
LinkageSpecLanguageIDs
Represents the language in a linkage specification.
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
@ Internal
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
bool isLambdaCallOperator(const CXXMethodDecl *MD)
@ Result
The result type of a method or function.
AvailabilityResult
Captures the result of checking the availability of a declaration.
const FunctionProtoType * T
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
UsingDirectiveDecl * operator*() const