28#include "llvm/ADT/StringRef.h"
35 const AvailabilityAttr *AA) {
38 if (!IIEnvironment || Environment == llvm::Triple::UnknownEnvironment)
41 llvm::Triple::EnvironmentType ET =
42 AvailabilityAttr::getEnvironmentType(IIEnvironment->
getName());
43 return Environment == ET;
48 AvailabilityAttr
const *PartialMatch =
nullptr;
54 if (
const auto *FTD = dyn_cast<FunctionTemplateDecl>(
D))
55 D = FTD->getTemplatedDecl();
56 for (
const auto *A :
D->
attrs()) {
57 if (
const auto *Avail = dyn_cast<AvailabilityAttr>(A)) {
63 StringRef ActualPlatform = Avail->getPlatform()->getName();
64 StringRef RealizedPlatform = ActualPlatform;
66 size_t suffix = RealizedPlatform.rfind(
"_app_extension");
67 if (suffix != StringRef::npos)
68 RealizedPlatform = RealizedPlatform.slice(0, suffix);
74 if (RealizedPlatform == TargetPlatform) {
93static std::pair<AvailabilityResult, const NamedDecl *>
101 while (
const auto *TD = dyn_cast<TypedefNameDecl>(
D)) {
103 if (
const auto *TT = TD->getUnderlyingType()->getAs<
TagType>()) {
113 if (
const auto *ADecl = dyn_cast<TypeAliasTemplateDecl>(
D)) {
114 D = ADecl->getTemplatedDecl();
119 if (
const auto *IDecl = dyn_cast<ObjCInterfaceDecl>(
D)) {
120 if (IDecl->getDefinition()) {
121 D = IDecl->getDefinition();
126 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(
D))
129 if (
const auto *TheEnumDecl = dyn_cast<EnumDecl>(DC)) {
136 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(
D)) {
141 MD->getSelector() == S.
ObjC().
NSAPIObj->getNewSelector() &&
143 Result =
Init->getAvailability(Message);
159 assert(K !=
AR_Available &&
"Expected an unavailable declaration here!");
164 if (DeclLoc.isMacroID() && S.
getLangOpts().CPlusPlus &&
165 isa<TypedefDecl>(OffendingDecl)) {
167 if (MacroName ==
"CF_OPTIONS" || MacroName ==
"OBJC_OPTIONS" ||
168 MacroName ==
"SWIFT_OPTIONS" || MacroName ==
"NS_OPTIONS") {
181 (DeclEnv !=
nullptr &&
183 llvm::Triple::EnvironmentType::Library))
188 if (
const auto *VD = dyn_cast<VarDecl>(OffendingDecl))
189 if (VD->isLocalVarDeclOrParm() && VD->isDeprecated())
194 auto CheckContext = [&](
const Decl *
C) {
197 if (AA->getIntroduced() >= DeclVersion &&
198 AA->getEnvironment() == DeclEnv)
201 if (
C->isDeprecated())
207 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(OffendingDecl)) {
208 if (
const auto *Impl = dyn_cast<ObjCImplDecl>(
C)) {
209 if (MD->getClassInterface() == Impl->getClassInterface())
215 if (
C->isUnavailable())
221 if (CheckContext(Ctx))
226 if (
const auto *MethodD = dyn_cast<ObjCMethodDecl>(Ctx))
227 if (MethodD->isClassMethod() &&
228 MethodD->getSelector().getAsString() ==
"load")
231 if (
const auto *CatOrImpl = dyn_cast<ObjCImplDecl>(Ctx)) {
237 else if (
const auto *CatD = dyn_cast<ObjCCategoryDecl>(Ctx))
247 const ASTContext &Context,
const VersionTuple &DeploymentVersion,
248 const VersionTuple &DeclVersion,
bool HasMatchingEnv) {
250 VersionTuple ForceAvailabilityFromVersion;
251 switch (Triple.getOS()) {
256 case llvm::Triple::IOS:
257 case llvm::Triple::TvOS:
258 ForceAvailabilityFromVersion = VersionTuple(11);
260 case llvm::Triple::WatchOS:
261 ForceAvailabilityFromVersion = VersionTuple(4);
263 case llvm::Triple::Darwin:
264 case llvm::Triple::MacOSX:
265 ForceAvailabilityFromVersion = VersionTuple(10, 13);
271 case llvm::Triple::ShaderModel:
272 return HasMatchingEnv ? diag::warn_hlsl_availability
273 : diag::warn_hlsl_availability_unavailable;
276 ForceAvailabilityFromVersion =
277 (Triple.getVendor() == llvm::Triple::Apple)
279 : VersionTuple((
unsigned)-1, (
unsigned)-1);
281 if (DeploymentVersion >= ForceAvailabilityFromVersion ||
282 DeclVersion >= ForceAvailabilityFromVersion)
283 return HasMatchingEnv ? diag::warn_unguarded_availability_new
284 : diag::warn_unguarded_availability_unavailable_new;
285 return HasMatchingEnv ? diag::warn_unguarded_availability
286 : diag::warn_unguarded_availability_unavailable;
290 for (
Decl *Ctx = OrigCtx; Ctx;
291 Ctx = cast_or_null<Decl>(Ctx->getDeclContext())) {
292 if (isa<TagDecl>(Ctx) || isa<FunctionDecl>(Ctx) || isa<ObjCMethodDecl>(Ctx))
293 return cast<NamedDecl>(Ctx);
294 if (
auto *CD = dyn_cast<ObjCContainerDecl>(Ctx)) {
295 if (
auto *Imp = dyn_cast<ObjCImplDecl>(Ctx))
296 return Imp->getClassInterface();
301 return dyn_cast<NamedDecl>(OrigCtx);
306struct AttributeInsertion {
311 static AttributeInsertion createInsertionAfter(
const NamedDecl *
D) {
314 static AttributeInsertion createInsertionAfter(
SourceLocation Loc) {
315 return {
" ",
Loc,
""};
317 static AttributeInsertion createInsertionBefore(
const NamedDecl *
D) {
332static std::optional<unsigned>
336 if (!Name.empty() && (Name.front() ==
'-' || Name.front() ==
'+'))
337 Name = Name.drop_front(1);
340 Name.split(SlotNames,
':');
342 if (Name.back() ==
':') {
344 SlotNames.pop_back();
345 NumParams = SlotNames.size();
347 if (SlotNames.size() != 1)
353 bool AllowDollar = LangOpts.DollarIdents;
354 for (StringRef S : SlotNames) {
365static std::optional<AttributeInsertion>
368 if (isa<ObjCPropertyDecl>(
D))
369 return AttributeInsertion::createInsertionAfter(
D);
370 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(
D)) {
373 return AttributeInsertion::createInsertionAfter(
D);
375 if (
const auto *TD = dyn_cast<TagDecl>(
D)) {
381 return AttributeInsertion::createInsertionAfter(
Loc);
383 return AttributeInsertion::createInsertionBefore(
D);
403 bool ObjCPropertyAccess) {
405 unsigned diag, diag_message, diag_fwdclass_message;
406 unsigned diag_available_here = diag::note_availability_specified_here;
410 unsigned property_note_select;
413 unsigned available_here_select_kind;
415 VersionTuple DeclVersion;
419 DeclVersion = AA->getIntroduced();
420 IIEnv = AA->getEnvironment();
431 if (AA && AA->isInherited()) {
434 const AvailabilityAttr *AForRedecl =
436 if (AForRedecl && !AForRedecl->isInherited()) {
439 NoteLocation = Redecl->getLocation();
451 assert(AA !=
nullptr &&
"expecting valid availability attribute");
452 VersionTuple Introduced = AA->getIntroduced();
453 bool EnvironmentMatchesOrNone =
457 std::string PlatformName(
459 llvm::StringRef TargetEnvironment(
460 llvm::Triple::getEnvironmentTypeName(TI.
getTriple().getEnvironment()));
461 llvm::StringRef AttrEnvironment =
462 AA->getEnvironment() ? AA->getEnvironment()->getName() :
"";
463 bool UseEnvironment =
464 (!AttrEnvironment.empty() && !TargetEnvironment.empty());
468 Introduced, EnvironmentMatchesOrNone);
470 S.
Diag(
Loc, DiagKind) << OffendingDecl << PlatformName
471 << Introduced.getAsString() << UseEnvironment
472 << TargetEnvironment;
475 diag::note_partial_availability_specified_here)
476 << OffendingDecl << PlatformName << Introduced.getAsString()
478 << UseEnvironment << AttrEnvironment << TargetEnvironment;
485 if (
const auto *TD = dyn_cast<TagDecl>(Enclosing))
486 if (TD->getDeclName().isEmpty()) {
487 S.
Diag(TD->getLocation(),
488 diag::note_decl_unguarded_availability_silence)
489 << 1 << TD->getKindName();
493 S.
Diag(Enclosing->getLocation(),
494 diag::note_decl_unguarded_availability_silence)
497 if (Enclosing->hasAttr<AvailabilityAttr>())
506 StringRef PlatformName =
519 std::vector<StringRef> EquivalentPlatforms =
520 AvailabilityAttr::equivalentPlatformNames(PlatformName);
521 llvm::Twine MacroPrefix =
"__API_AVAILABLE_PLATFORM_";
522 auto AvailablePlatform =
523 llvm::find_if(EquivalentPlatforms, [&](StringRef EquivalentPlatform) {
524 return PP.
isMacroDefined((MacroPrefix + EquivalentPlatform).str());
526 if (AvailablePlatform == EquivalentPlatforms.end())
528 std::string Introduced =
532 (llvm::Twine(Insertion->Prefix) +
"API_AVAILABLE(" +
533 *AvailablePlatform +
"(" + Introduced +
"))" + Insertion->Suffix)
539 diag = !ObjCPropertyAccess ? diag::warn_deprecated
540 : diag::warn_property_method_deprecated;
541 diag_message = diag::warn_deprecated_message;
542 diag_fwdclass_message = diag::warn_deprecated_fwdclass_message;
543 property_note_select = 0;
544 available_here_select_kind = 2;
545 if (
const auto *AL = OffendingDecl->
getAttr<DeprecatedAttr>())
546 NoteLocation = AL->getLocation();
550 diag = !ObjCPropertyAccess ? diag::err_unavailable
551 : diag::err_property_method_unavailable;
552 diag_message = diag::err_unavailable_message;
553 diag_fwdclass_message = diag::warn_unavailable_fwdclass_message;
554 property_note_select = 1;
555 available_here_select_kind = 0;
557 if (
auto AL = OffendingDecl->
getAttr<UnavailableAttr>()) {
558 if (AL->isImplicit() && AL->getImplicitReason()) {
561 auto flagARCError = [&] {
565 diag = diag::err_unavailable_in_arc;
568 switch (AL->getImplicitReason()) {
569 case UnavailableAttr::IR_None:
break;
571 case UnavailableAttr::IR_ARCForbiddenType:
573 diag_available_here = diag::note_arc_forbidden_type;
576 case UnavailableAttr::IR_ForbiddenWeak:
578 diag_available_here = diag::note_arc_weak_disabled;
580 diag_available_here = diag::note_arc_weak_no_runtime;
583 case UnavailableAttr::IR_ARCForbiddenConversion:
585 diag_available_here = diag::note_performs_forbidden_arc_conversion;
588 case UnavailableAttr::IR_ARCInitReturnsUnrelated:
590 diag_available_here = diag::note_arc_init_returns_unrelated;
593 case UnavailableAttr::IR_ARCFieldWithOwnership:
595 diag_available_here = diag::note_arc_field_with_ownership;
603 llvm_unreachable(
"Warning for availability of available declaration?");
608 StringRef Replacement;
609 if (
auto AL = OffendingDecl->
getAttr<DeprecatedAttr>())
610 Replacement = AL->getReplacement();
612 Replacement = AL->getReplacement();
615 if (!Replacement.empty())
619 if (
const auto *MethodDecl = dyn_cast<ObjCMethodDecl>(ReferringDecl)) {
620 Selector Sel = MethodDecl->getSelector();
624 if (NumParams && *NumParams == Sel.
getNumArgs()) {
625 assert(SelectorSlotNames.size() == Locs.size());
626 for (
unsigned I = 0; I < Locs.size(); ++I) {
631 NameRange, SelectorSlotNames[I]));
649 bool ShouldAllowWarningInSystemHeader =
650 InstantiationLoc !=
Loc &&
652 struct AllowWarningInSystemHeaders {
654 bool AllowWarningInSystemHeaders)
655 : Engine(
E), Prev(
E.getSuppressSystemWarnings()) {
656 E.setSuppressSystemWarnings(!AllowWarningInSystemHeaders);
658 ~AllowWarningInSystemHeaders() { Engine.setSuppressSystemWarnings(Prev); }
664 ShouldAllowWarningInSystemHeader);
666 if (!Message.empty()) {
667 S.
Diag(
Loc, diag_message) << ReferringDecl << Message << FixIts;
670 << ObjCProperty->
getDeclName() << property_note_select;
671 }
else if (!UnknownObjCClass) {
672 S.
Diag(
Loc, diag) << ReferringDecl << FixIts;
675 << ObjCProperty->
getDeclName() << property_note_select;
677 S.
Diag(
Loc, diag_fwdclass_message) << ReferringDecl << FixIts;
681 S.
Diag(NoteLocation, diag_available_here)
682 << OffendingDecl << available_here_select_kind;
687 "Expected an availability diagnostic here");
704 bool ObjCPropertyAccess) {
709 AR, Locs, ReferringDecl, OffendingDecl, UnknownObjCClass,
710 ObjCProperty, Message, ObjCPropertyAccess));
716 Message, Locs, UnknownObjCClass, ObjCProperty,
724 switch (
Parent->getStmtClass()) {
725 case Stmt::IfStmtClass:
726 return cast<IfStmt>(
Parent)->getThen() == S ||
727 cast<IfStmt>(
Parent)->getElse() == S;
728 case Stmt::WhileStmtClass:
729 return cast<WhileStmt>(
Parent)->getBody() == S;
730 case Stmt::DoStmtClass:
731 return cast<DoStmt>(
Parent)->getBody() == S;
732 case Stmt::ForStmtClass:
733 return cast<ForStmt>(
Parent)->getBody() == S;
734 case Stmt::CXXForRangeStmtClass:
735 return cast<CXXForRangeStmt>(
Parent)->getBody() == S;
736 case Stmt::ObjCForCollectionStmtClass:
737 return cast<ObjCForCollectionStmt>(
Parent)->getBody() == S;
738 case Stmt::CaseStmtClass:
739 case Stmt::DefaultStmtClass:
740 return cast<SwitchCase>(
Parent)->getSubStmt() == S;
750 bool VisitStmt(
Stmt *S)
override {
return S !=
Target; }
754 StmtUSEFinder Visitor;
756 return !Visitor.TraverseDecl(
const_cast<Decl *
>(
D));
772 static const Stmt *findLastStmtThatUsesDecl(
const Decl *
D,
774 LastDeclUSEFinder Visitor;
776 for (
const Stmt *S : llvm::reverse(
Scope->body())) {
777 if (!Visitor.TraverseStmt(
const_cast<Stmt *
>(S)))
802 DiagnoseUnguardedAvailability(
Sema &SemaRef,
Decl *Ctx)
803 : SemaRef(SemaRef), Ctx(Ctx) {
804 AvailabilityStack.push_back(
808 bool TraverseStmt(
Stmt *S)
override {
811 StmtStack.push_back(S);
813 StmtStack.pop_back();
817 void IssueDiagnostics(
Stmt *S) { TraverseStmt(S); }
819 bool TraverseIfStmt(
IfStmt *
If)
override;
823 bool TraverseCaseStmt(
CaseStmt *CS)
override {
834 DiagnoseDeclAvailability(
841 DiagnoseDeclAvailability(DRE->
getDecl(),
846 bool VisitMemberExpr(
MemberExpr *ME)
override {
858 bool VisitTypeLoc(
TypeLoc Ty)
override;
861void DiagnoseUnguardedAvailability::DiagnoseDeclAvailability(
865 std::tie(
Result, OffendingDecl) =
873 const AvailabilityAttr *AA =
875 assert(AA !=
nullptr &&
"expecting valid availability attribute");
876 bool EnvironmentMatchesOrNone =
878 VersionTuple Introduced = AA->getIntroduced();
880 if (EnvironmentMatchesOrNone && AvailabilityStack.back() >= Introduced)
886 AA->getEnvironment(), Ctx,
891 std::string PlatformName(
893 llvm::StringRef TargetEnvironment(TI.
getTriple().getEnvironmentName());
894 llvm::StringRef AttrEnvironment =
895 AA->getEnvironment() ? AA->getEnvironment()->getName() :
"";
896 bool UseEnvironment =
897 (!AttrEnvironment.empty() && !TargetEnvironment.empty());
902 EnvironmentMatchesOrNone);
905 <<
Range <<
D << PlatformName << Introduced.getAsString()
906 << UseEnvironment << TargetEnvironment;
909 diag::note_partial_availability_specified_here)
910 << OffendingDecl << PlatformName << Introduced.getAsString()
912 << UseEnvironment << AttrEnvironment << TargetEnvironment;
925 if (StmtStack.empty())
927 const Stmt *StmtOfUse = StmtStack.back();
929 for (
const Stmt *S : llvm::reverse(StmtStack)) {
930 if (
const auto *CS = dyn_cast<CompoundStmt>(S)) {
934 if (isBodyLikeChildStmt(StmtOfUse, S)) {
942 const Stmt *LastStmtOfUse =
nullptr;
943 if (isa<DeclStmt>(StmtOfUse) &&
Scope) {
944 for (
const Decl *
D : cast<DeclStmt>(StmtOfUse)->decls()) {
945 if (StmtUSEFinder::isContained(StmtStack.back(),
D)) {
946 LastStmtOfUse = LastDeclUSEFinder::findLastStmtThatUsesDecl(
D,
Scope);
956 SM.getExpansionRange(
957 (LastStmtOfUse ? LastStmtOfUse : StmtOfUse)->getEndLoc())
959 if (
SM.getFileID(IfInsertionLoc) !=
SM.getFileID(StmtEndLoc))
963 const char *ExtraIndentation =
" ";
964 std::string FixItString;
965 llvm::raw_string_ostream FixItOS(FixItString);
966 FixItOS <<
"if (" << (SemaRef.
getLangOpts().ObjC ?
"@available"
967 :
"__builtin_available")
969 << AvailabilityAttr::getPlatformNameSourceSpelling(
971 <<
" " << Introduced.getAsString() <<
", *)) {\n"
972 << Indentation << ExtraIndentation;
980 FixItOS.str().clear();
982 << Indentation <<
"} else {\n"
983 << Indentation << ExtraIndentation
984 <<
"// Fallback on earlier versions\n"
985 << Indentation <<
"}";
990bool DiagnoseUnguardedAvailability::VisitTypeLoc(
TypeLoc Ty) {
997 if (
const auto *TT = dyn_cast<TagType>(TyPtr)) {
999 DiagnoseDeclAvailability(TD,
Range);
1001 }
else if (
const auto *TD = dyn_cast<TypedefType>(TyPtr)) {
1003 DiagnoseDeclAvailability(
D,
Range);
1005 }
else if (
const auto *ObjCO = dyn_cast<ObjCObjectType>(TyPtr)) {
1007 DiagnoseDeclAvailability(
D,
Range);
1013struct ExtractedAvailabilityExpr {
1015 bool isNegated =
false;
1018ExtractedAvailabilityExpr extractAvailabilityExpr(
const Expr *IfCond) {
1019 const auto *
E = IfCond;
1020 bool IsNegated =
false;
1023 if (
const auto *AE = dyn_cast<ObjCAvailabilityCheckExpr>(
E)) {
1024 return ExtractedAvailabilityExpr{AE, IsNegated};
1027 const auto *UO = dyn_cast<UnaryOperator>(
E);
1028 if (!UO || UO->getOpcode() != UO_LNot) {
1029 return ExtractedAvailabilityExpr{};
1031 E = UO->getSubExpr();
1032 IsNegated = !IsNegated;
1036bool DiagnoseUnguardedAvailability::TraverseIfStmt(
IfStmt *
If) {
1037 ExtractedAvailabilityExpr IfCond = extractAvailabilityExpr(
If->getCond());
1040 return DynamicRecursiveASTVisitor::TraverseIfStmt(
If);
1043 VersionTuple CondVersion = IfCond.E->getVersion();
1046 if (CondVersion.empty() || CondVersion <= AvailabilityStack.back()) {
1047 return TraverseStmt(
If->getThen()) && TraverseStmt(
If->getElse());
1050 auto *Guarded =
If->getThen();
1051 auto *Unguarded =
If->getElse();
1052 if (IfCond.isNegated) {
1053 std::swap(Guarded, Unguarded);
1056 AvailabilityStack.push_back(CondVersion);
1057 bool ShouldContinue = TraverseStmt(Guarded);
1058 AvailabilityStack.pop_back();
1060 return ShouldContinue && TraverseStmt(Unguarded);
1066 Stmt *Body =
nullptr;
1069 Body = FD->getBody();
1071 if (
auto *CD = dyn_cast<CXXConstructorDecl>(FD))
1073 DiagnoseUnguardedAvailability(*
this,
D).IssueDiagnostics(CI->getInit());
1075 }
else if (
auto *MD = dyn_cast<ObjCMethodDecl>(
D))
1076 Body = MD->getBody();
1077 else if (
auto *BD = dyn_cast<BlockDecl>(
D))
1078 Body = BD->getBody();
1080 assert(Body &&
"Need a body here!");
1082 DiagnoseUnguardedAvailability(*
this,
D).IssueDiagnostics(Body);
1099 bool ObjCPropertyAccess,
1100 bool AvoidPartialAvailabilityChecks,
1102 std::string Message;
1106 std::tie(
Result, OffendingDecl) =
1112 if (AvoidPartialAvailabilityChecks)
1119 Context->HasPotentialAvailabilityViolations =
true;
1125 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(
D)) {
1128 if (PDeclResult ==
Result)
1134 UnknownObjCClass, ObjCPDecl, ObjCPropertyAccess);
Defines the C++ template declaration subclasses.
Defines the classes clang::DelayedDiagnostic and clang::AccessedEntity.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Defines the clang::LangOptions interface.
llvm::MachO::Target Target
Defines the clang::Preprocessor interface.
static unsigned getAvailabilityDiagnosticKind(const ASTContext &Context, const VersionTuple &DeploymentVersion, const VersionTuple &DeclVersion, bool HasMatchingEnv)
static std::pair< AvailabilityResult, const NamedDecl * > ShouldDiagnoseAvailabilityOfDecl(Sema &S, const NamedDecl *D, std::string *Message, ObjCInterfaceDecl *ClassReceiver)
The diagnostic we should emit for D, and the declaration that originated it, or AR_Available.
static bool hasMatchingEnvironmentOrNone(const ASTContext &Context, const AvailabilityAttr *AA)
static std::optional< AttributeInsertion > createAttributeInsertion(const NamedDecl *D, const SourceManager &SM, const LangOptions &LangOpts)
Returns a source location in which it's appropriate to insert a new attribute for the given declarati...
static void EmitAvailabilityWarning(Sema &S, AvailabilityResult AR, const NamedDecl *ReferringDecl, const NamedDecl *OffendingDecl, StringRef Message, ArrayRef< SourceLocation > Locs, const ObjCInterfaceDecl *UnknownObjCClass, const ObjCPropertyDecl *ObjCProperty, bool ObjCPropertyAccess)
static void DoEmitAvailabilityWarning(Sema &S, AvailabilityResult K, Decl *Ctx, const NamedDecl *ReferringDecl, const NamedDecl *OffendingDecl, StringRef Message, ArrayRef< SourceLocation > Locs, const ObjCInterfaceDecl *UnknownObjCClass, const ObjCPropertyDecl *ObjCProperty, bool ObjCPropertyAccess)
Actually emit an availability diagnostic for a reference to an unavailable decl.
static NamedDecl * findEnclosingDeclToAnnotate(Decl *OrigCtx)
static std::optional< unsigned > tryParseObjCMethodName(StringRef Name, SmallVectorImpl< StringRef > &SlotNames, const LangOptions &LangOpts)
Tries to parse a string as ObjC method name.
static const AvailabilityAttr * getAttrForPlatform(ASTContext &Context, const Decl *D)
static bool ShouldDiagnoseAvailabilityInContext(Sema &S, AvailabilityResult K, VersionTuple DeclVersion, const IdentifierInfo *DeclEnv, Decl *Ctx, const NamedDecl *OffendingDecl)
whether we should emit a diagnostic for K and DeclVersion in the context of Ctx.
This file declares semantic analysis for Objective-C.
Defines the Objective-C statement AST node classes.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const LangOptions & getLangOpts() const
const TargetInfo & getTargetInfo() const
Represents a C++ base or member initializer.
CaseStmt - Represent a case statement.
Represents a character-granular source range.
static CharSourceRange getCharRange(SourceRange R)
CompoundStmt - This represents a group of statements like { stmt stmt }.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
A reference to a declared variable, function, enum, etc.
SourceLocation getBeginLoc() const LLVM_READONLY
SourceLocation getEndLoc() const LLVM_READONLY
Decl - This represents one declaration (or definition), e.g.
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration,...
SourceLocation getEndLoc() const LLVM_READONLY
AvailabilityResult getAvailability(std::string *Message=nullptr, VersionTuple EnclosingVersion=VersionTuple(), StringRef *RealizedPlatform=nullptr) const
Determine the availability of the given declaration.
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
SourceLocation getLocation() const
DeclContext * getDeclContext()
SourceLocation getBeginLoc() const LLVM_READONLY
VersionTuple getVersionIntroduced() const
Retrieve the version of the target platform in which this declaration was introduced.
Concrete class used by the front-end to report problems and issues.
Recursive AST visitor that supports extension via dynamic dispatch.
virtual bool TraverseStmt(Stmt *S)
Recursively visit a statement or expression, by dispatching to Traverse*() based on the argument's dy...
This represents one expression.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
IfStmt - This represents an if/then/else.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
static SourceLocation findLocationAfterToken(SourceLocation loc, tok::TokenKind TKind, const SourceManager &SM, const LangOptions &LangOpts, bool SkipTrailingWhitespaceAndNewLine)
Checks that the given token is the first token that occurs after the given location (this excludes co...
static StringRef getIndentationForLine(SourceLocation Loc, const SourceManager &SM)
Returns the leading whitespace for line that corresponds to the given location Loc.
static SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset, const SourceManager &SM, const LangOptions &LangOpts)
Computes the source location just past the end of the token at this source location.
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
SourceLocation getEndLoc() const LLVM_READONLY
SourceLocation getBeginLoc() const LLVM_READONLY
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.
NamedDecl * getMostRecentDecl()
A runtime availability query.
Represents an ObjC class declaration.
ObjCMethodDecl * lookupInstanceMethod(Selector Sel) const
Lookup an instance method for a given selector.
An expression that sends a message to the given Objective-C object or class.
QualType getClassReceiver() const
Returns the type of a class message send, or NULL if the message is not a class message.
const ObjCMethodDecl * getMethodDecl() const
SourceLocation getEndLoc() const LLVM_READONLY
SourceLocation getSelectorStartLoc() const
ObjCMethodDecl - Represents an instance or class method declaration.
ObjCInterfaceDecl * getInterface() const
Gets the interface declaration for this object type, if the base type really is an interface.
Represents one property declaration in an Objective-C interface.
static ObjCPropertyDecl * findPropertyDecl(const DeclContext *DC, const IdentifierInfo *propertyID, ObjCPropertyQueryKind queryKind)
Lookup a property by name in the specified DeclContext.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
bool isMacroDefined(StringRef Id)
StringRef getImmediateMacroName(SourceLocation Loc)
Retrieve the name of the immediate macro expansion.
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Scope - A scope is a transient data structure that is used while parsing the program.
Smart pointer class that efficiently represents Objective-C method names.
StringRef getNameForSlot(unsigned argIndex) const
Retrieve the name at a given position in the selector.
unsigned getNumArgs() const
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
std::unique_ptr< NSAPI > NSAPIObj
Caches identifiers/selectors for NSFoundation APIs.
bool shouldDelayDiagnostics()
Determines whether diagnostics should be delayed.
void add(const sema::DelayedDiagnostic &diag)
Adds a delayed diagnostic.
Sema - This implements semantic analysis and AST building for C.
SmallVector< sema::FunctionScopeInfo *, 4 > FunctionScopes
Stack containing information about each of the nested function, block, and method scopes that are cur...
Preprocessor & getPreprocessor() const
class clang::Sema::DelayedDiagnostics DelayedDiagnostics
DiagnosticsEngine & getDiagnostics() const
ASTContext & getASTContext() const
void DiagnoseUnguardedAvailabilityViolations(Decl *FD)
Issue any -Wunguarded-availability warnings in FD.
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
const LangOptions & getLangOpts() const
DeclContext * getCurLexicalContext() const
SourceManager & getSourceManager() const
sema::FunctionScopeInfo * getCurFunctionAvailabilityContext()
Retrieve the current function, if any, that should be analyzed for potential availability violations.
SourceLocation getTopMostPointOfInstantiation(const NamedDecl *) const
Returns the top most location responsible for the definition of N.
void DiagnoseAvailabilityOfDecl(NamedDecl *D, ArrayRef< SourceLocation > Locs, const ObjCInterfaceDecl *UnknownObjCClass, bool ObjCPropertyAccess, bool AvoidPartialAvailabilityChecks=false, ObjCInterfaceDecl *ClassReceiver=nullptr)
void handleDelayedAvailabilityCheck(sema::DelayedDiagnostic &DD, Decl *Ctx)
Encodes a location in the source.
This class handles loading and caching of source files into memory.
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
A trivial tuple used to represent a source range.
SourceLocation getBegin() const
Stmt - This represents one statement.
SourceLocation getBeginLoc() const LLVM_READONLY
Represents the declaration of a struct/union/class/enum.
Exposes information about the current target.
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.
Base wrapper for a particular "section" of type source info.
SourceLocation getEndLoc() const
Get the end source location.
SourceLocation getBeginLoc() const
Get the begin source location.
const Type * getTypePtr() const
The base class of the type hierarchy.
const ObjCObjectType * getAsObjCInterfaceType() const
Base class for declarations which introduce a typedef-name.
A diagnostic message which has been conditionally emitted pending the complete parsing of the current...
static DelayedDiagnostic makeAvailability(AvailabilityResult AR, ArrayRef< SourceLocation > Locs, const NamedDecl *ReferringDecl, const NamedDecl *OffendingDecl, const ObjCInterfaceDecl *UnknownObjCClass, const ObjCPropertyDecl *ObjCProperty, StringRef Msg, bool ObjCPropertyAccess)
const ObjCInterfaceDecl * getUnknownObjCClass() const
const NamedDecl * getAvailabilityOffendingDecl() const
const ObjCPropertyDecl * getObjCProperty() const
StringRef getAvailabilityMessage() const
ArrayRef< SourceLocation > getAvailabilitySelectorLocs() const
AvailabilityResult getAvailabilityResult() const
const NamedDecl * getAvailabilityReferringDecl() const
Retains information about a function, method, or block that is currently being parsed.
Defines the clang::TargetInfo interface.
The JSON file list parser is used to communicate input to InstallAPI.
@ If
'if' clause, allowed on all the Compute Constructs, Data Constructs, Executable Constructs,...
LLVM_READONLY bool isValidAsciiIdentifier(StringRef S, bool AllowDollar=false)
Return true if this is a valid ASCII identifier.
@ Result
The result type of a method or function.
AvailabilityResult
Captures the result of checking the availability of a declaration.
@ Interface
The "__interface" keyword introduces the elaborated-type-specifier.