24 #include "llvm/ADT/StringRef.h"
27 using namespace clang;
31 const AvailabilityAttr *AA) {
34 if (!IIEnvironment || Environment == llvm::Triple::UnknownEnvironment)
37 llvm::Triple::EnvironmentType ET =
38 AvailabilityAttr::getEnvironmentType(IIEnvironment->
getName());
39 return Environment == ET;
44 AvailabilityAttr
const *PartialMatch =
nullptr;
48 for (
const auto *A : D->
attrs()) {
49 if (
const auto *Avail = dyn_cast<AvailabilityAttr>(A)) {
55 StringRef ActualPlatform = Avail->getPlatform()->getName();
56 StringRef RealizedPlatform = ActualPlatform;
58 size_t suffix = RealizedPlatform.rfind(
"_app_extension");
59 if (suffix != StringRef::npos)
60 RealizedPlatform = RealizedPlatform.slice(0, suffix);
66 if (RealizedPlatform == TargetPlatform) {
85 static std::pair<AvailabilityResult, const NamedDecl *>
93 while (
const auto *TD = dyn_cast<TypedefNameDecl>(D)) {
95 if (
const auto *TT = TD->getUnderlyingType()->getAs<
TagType>()) {
105 if (
const auto *IDecl = dyn_cast<ObjCInterfaceDecl>(D)) {
106 if (IDecl->getDefinition()) {
107 D = IDecl->getDefinition();
112 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D))
115 if (
const auto *TheEnumDecl = dyn_cast<EnumDecl>(DC)) {
122 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
126 if (Init && Result ==
AR_Available && MD->isClassMethod() &&
127 MD->getSelector() == S.
ObjC().
NSAPIObj->getNewSelector() &&
129 Result = Init->getAvailability(Message);
145 assert(K !=
AR_Available &&
"Expected an unavailable declaration here!");
150 if (DeclLoc.isMacroID() && S.
getLangOpts().CPlusPlus &&
151 isa<TypedefDecl>(OffendingDecl)) {
153 if (MacroName ==
"CF_OPTIONS" || MacroName ==
"OBJC_OPTIONS" ||
154 MacroName ==
"SWIFT_OPTIONS" || MacroName ==
"NS_OPTIONS") {
160 auto CheckContext = [&](
const Decl *C) {
163 if (AA->getIntroduced() >= DeclVersion &&
164 AA->getEnvironment() == DeclEnv)
167 if (C->isDeprecated())
173 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(OffendingDecl)) {
174 if (
const auto *Impl = dyn_cast<ObjCImplDecl>(C)) {
175 if (MD->getClassInterface() == Impl->getClassInterface())
181 if (C->isUnavailable())
187 if (CheckContext(Ctx))
192 if (
const auto *MethodD = dyn_cast<ObjCMethodDecl>(Ctx))
193 if (MethodD->isClassMethod() &&
194 MethodD->getSelector().getAsString() ==
"load")
197 if (
const auto *CatOrImpl = dyn_cast<ObjCImplDecl>(Ctx)) {
203 else if (
const auto *CatD = dyn_cast<ObjCCategoryDecl>(Ctx))
214 const VersionTuple &DeploymentVersion,
215 const VersionTuple &DeclVersion) {
217 VersionTuple ForceAvailabilityFromVersion;
218 switch (Triple.getOS()) {
219 case llvm::Triple::IOS:
220 case llvm::Triple::TvOS:
221 ForceAvailabilityFromVersion = VersionTuple(11);
223 case llvm::Triple::WatchOS:
224 ForceAvailabilityFromVersion = VersionTuple(4);
226 case llvm::Triple::Darwin:
227 case llvm::Triple::MacOSX:
228 ForceAvailabilityFromVersion = VersionTuple(10, 13);
230 case llvm::Triple::ShaderModel:
235 return Triple.getVendor() == llvm::Triple::Apple;
237 return DeploymentVersion >= ForceAvailabilityFromVersion ||
238 DeclVersion >= ForceAvailabilityFromVersion;
242 for (
Decl *Ctx = OrigCtx; Ctx;
243 Ctx = cast_or_null<Decl>(Ctx->getDeclContext())) {
244 if (isa<TagDecl>(Ctx) || isa<FunctionDecl>(Ctx) || isa<ObjCMethodDecl>(Ctx))
245 return cast<NamedDecl>(Ctx);
246 if (
auto *CD = dyn_cast<ObjCContainerDecl>(Ctx)) {
247 if (
auto *Imp = dyn_cast<ObjCImplDecl>(Ctx))
248 return Imp->getClassInterface();
253 return dyn_cast<NamedDecl>(OrigCtx);
258 struct AttributeInsertion {
263 static AttributeInsertion createInsertionAfter(
const NamedDecl *D) {
267 return {
" ",
Loc,
""};
269 static AttributeInsertion createInsertionBefore(
const NamedDecl *D) {
284 static std::optional<unsigned>
288 if (!Name.empty() && (Name.front() ==
'-' || Name.front() ==
'+'))
289 Name = Name.drop_front(1);
292 Name.split(SlotNames,
':');
294 if (Name.back() ==
':') {
296 SlotNames.pop_back();
297 NumParams = SlotNames.size();
299 if (SlotNames.size() != 1)
305 bool AllowDollar = LangOpts.DollarIdents;
306 for (StringRef S : SlotNames) {
317 static std::optional<AttributeInsertion>
320 if (isa<ObjCPropertyDecl>(D))
321 return AttributeInsertion::createInsertionAfter(D);
322 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
325 return AttributeInsertion::createInsertionAfter(D);
327 if (
const auto *TD = dyn_cast<TagDecl>(D)) {
333 return AttributeInsertion::createInsertionAfter(
Loc);
335 return AttributeInsertion::createInsertionBefore(D);
355 bool ObjCPropertyAccess) {
357 unsigned diag, diag_message, diag_fwdclass_message;
358 unsigned diag_available_here = diag::note_availability_specified_here;
362 unsigned property_note_select;
365 unsigned available_here_select_kind;
367 VersionTuple DeclVersion;
371 DeclVersion = AA->getIntroduced();
372 IIEnv = AA->getEnvironment();
383 if (AA && AA->isInherited()) {
386 const AvailabilityAttr *AForRedecl =
388 if (AForRedecl && !AForRedecl->isInherited()) {
391 NoteLocation = Redecl->getLocation();
403 assert(AA !=
nullptr &&
"expecting valid availability attribute");
404 VersionTuple Introduced = AA->getIntroduced();
405 bool EnvironmentMatchesOrNone =
409 std::string PlatformName(
411 llvm::StringRef TargetEnvironment(AvailabilityAttr::getPrettyEnviromentName(
413 llvm::StringRef AttrEnvironment =
414 AA->getEnvironment() ? AvailabilityAttr::getPrettyEnviromentName(
415 AA->getEnvironment()->getName())
417 bool UseEnvironment =
418 (!AttrEnvironment.empty() && !TargetEnvironment.empty());
425 EnvironmentMatchesOrNone
426 ? (UseNewWarning ? diag::warn_unguarded_availability_new
427 : diag::warn_unguarded_availability)
428 : (UseNewWarning ? diag::warn_unguarded_availability_unavailable_new
429 : diag::warn_unguarded_availability_unavailable);
431 S.
Diag(
Loc, DiagKind) << OffendingDecl << PlatformName
432 << Introduced.getAsString() << UseEnvironment
433 << TargetEnvironment;
436 diag::note_partial_availability_specified_here)
437 << OffendingDecl << PlatformName << Introduced.getAsString()
439 << UseEnvironment << AttrEnvironment << TargetEnvironment;
442 if (
const auto *TD = dyn_cast<TagDecl>(Enclosing))
443 if (TD->getDeclName().isEmpty()) {
444 S.
Diag(TD->getLocation(),
445 diag::note_decl_unguarded_availability_silence)
446 << 1 << TD->getKindName();
450 S.
Diag(Enclosing->getLocation(),
451 diag::note_decl_unguarded_availability_silence)
454 if (Enclosing->hasAttr<AvailabilityAttr>())
462 std::string PlatformName =
463 AvailabilityAttr::getPlatformNameSourceSpelling(
466 std::string Introduced =
470 (llvm::Twine(Insertion->Prefix) +
"API_AVAILABLE(" + PlatformName +
471 "(" + Introduced +
"))" + Insertion->Suffix)
477 diag = !ObjCPropertyAccess ? diag::warn_deprecated
478 : diag::warn_property_method_deprecated;
479 diag_message = diag::warn_deprecated_message;
480 diag_fwdclass_message = diag::warn_deprecated_fwdclass_message;
481 property_note_select = 0;
482 available_here_select_kind = 2;
483 if (
const auto *AL = OffendingDecl->
getAttr<DeprecatedAttr>())
484 NoteLocation = AL->getLocation();
488 diag = !ObjCPropertyAccess ? diag::err_unavailable
489 : diag::err_property_method_unavailable;
490 diag_message = diag::err_unavailable_message;
491 diag_fwdclass_message = diag::warn_unavailable_fwdclass_message;
492 property_note_select = 1;
493 available_here_select_kind = 0;
495 if (
auto AL = OffendingDecl->
getAttr<UnavailableAttr>()) {
496 if (AL->isImplicit() && AL->getImplicitReason()) {
499 auto flagARCError = [&] {
503 diag = diag::err_unavailable_in_arc;
506 switch (AL->getImplicitReason()) {
507 case UnavailableAttr::IR_None:
break;
509 case UnavailableAttr::IR_ARCForbiddenType:
511 diag_available_here = diag::note_arc_forbidden_type;
514 case UnavailableAttr::IR_ForbiddenWeak:
516 diag_available_here = diag::note_arc_weak_disabled;
518 diag_available_here = diag::note_arc_weak_no_runtime;
521 case UnavailableAttr::IR_ARCForbiddenConversion:
523 diag_available_here = diag::note_performs_forbidden_arc_conversion;
526 case UnavailableAttr::IR_ARCInitReturnsUnrelated:
528 diag_available_here = diag::note_arc_init_returns_unrelated;
531 case UnavailableAttr::IR_ARCFieldWithOwnership:
533 diag_available_here = diag::note_arc_field_with_ownership;
541 llvm_unreachable(
"Warning for availability of available declaration?");
546 StringRef Replacement;
547 if (
auto AL = OffendingDecl->
getAttr<DeprecatedAttr>())
548 Replacement = AL->getReplacement();
550 Replacement = AL->getReplacement();
553 if (!Replacement.empty())
557 if (
const auto *MethodDecl = dyn_cast<ObjCMethodDecl>(ReferringDecl)) {
558 Selector Sel = MethodDecl->getSelector();
562 if (NumParams && *NumParams == Sel.
getNumArgs()) {
563 assert(SelectorSlotNames.size() == Locs.size());
564 for (
unsigned I = 0; I < Locs.size(); ++I) {
569 NameRange, SelectorSlotNames[I]));
587 bool ShouldAllowWarningInSystemHeader =
588 InstantiationLoc !=
Loc &&
591 struct AllowWarningInSystemHeaders {
593 bool AllowWarningInSystemHeaders)
597 ~AllowWarningInSystemHeaders() { Engine.setSuppressSystemWarnings(Prev); }
603 ShouldAllowWarningInSystemHeader);
605 if (!Message.empty()) {
606 S.
Diag(
Loc, diag_message) << ReferringDecl << Message << FixIts;
609 << ObjCProperty->
getDeclName() << property_note_select;
610 }
else if (!UnknownObjCClass) {
611 S.
Diag(
Loc, diag) << ReferringDecl << FixIts;
614 << ObjCProperty->
getDeclName() << property_note_select;
616 S.
Diag(
Loc, diag_fwdclass_message) << ReferringDecl << FixIts;
620 S.
Diag(NoteLocation, diag_available_here)
621 << OffendingDecl << available_here_select_kind;
626 "Expected an availability diagnostic here");
643 bool ObjCPropertyAccess) {
648 AR, Locs, ReferringDecl, OffendingDecl, UnknownObjCClass,
649 ObjCProperty, Message, ObjCPropertyAccess));
655 Message, Locs, UnknownObjCClass, ObjCProperty,
663 switch (
Parent->getStmtClass()) {
664 case Stmt::IfStmtClass:
665 return cast<IfStmt>(
Parent)->getThen() == S ||
666 cast<IfStmt>(
Parent)->getElse() == S;
667 case Stmt::WhileStmtClass:
668 return cast<WhileStmt>(
Parent)->getBody() == S;
669 case Stmt::DoStmtClass:
670 return cast<DoStmt>(
Parent)->getBody() == S;
671 case Stmt::ForStmtClass:
672 return cast<ForStmt>(
Parent)->getBody() == S;
673 case Stmt::CXXForRangeStmtClass:
674 return cast<CXXForRangeStmt>(
Parent)->getBody() == S;
675 case Stmt::ObjCForCollectionStmtClass:
676 return cast<ObjCForCollectionStmt>(
Parent)->getBody() == S;
677 case Stmt::CaseStmtClass:
678 case Stmt::DefaultStmtClass:
679 return cast<SwitchCase>(
Parent)->getSubStmt() == S;
689 bool VisitStmt(
Stmt *S) {
return S !=
Target; }
693 StmtUSEFinder Visitor;
695 return !Visitor.TraverseDecl(
const_cast<Decl *
>(D));
711 static const Stmt *findLastStmtThatUsesDecl(
const Decl *D,
713 LastDeclUSEFinder Visitor;
715 for (
const Stmt *S : llvm::reverse(
Scope->body())) {
716 if (!Visitor.TraverseStmt(
const_cast<Stmt *
>(S)))
729 class DiagnoseUnguardedAvailability
744 DiagnoseUnguardedAvailability(
Sema &SemaRef,
Decl *Ctx)
745 : SemaRef(SemaRef), Ctx(Ctx) {
746 AvailabilityStack.push_back(
750 bool TraverseStmt(
Stmt *S) {
753 StmtStack.push_back(S);
754 bool Result = Base::TraverseStmt(S);
755 StmtStack.pop_back();
759 void IssueDiagnostics(
Stmt *S) { TraverseStmt(S); }
761 bool TraverseIfStmt(
IfStmt *If);
776 DiagnoseDeclAvailability(
783 DiagnoseDeclAvailability(DRE->
getDecl(),
803 void DiagnoseUnguardedAvailability::DiagnoseDeclAvailability(
807 std::tie(Result, OffendingDecl) =
815 const AvailabilityAttr *AA =
817 bool EnvironmentMatchesOrNone =
819 VersionTuple Introduced = AA->getIntroduced();
821 if (EnvironmentMatchesOrNone && AvailabilityStack.back() >= Introduced)
827 AA->getEnvironment(), Ctx,
840 std::string PlatformName(
842 llvm::StringRef TargetEnvironment(AvailabilityAttr::getPrettyEnviromentName(
844 llvm::StringRef AttrEnvironment =
845 AA->getEnvironment() ? AvailabilityAttr::getPrettyEnviromentName(
846 AA->getEnvironment()->getName())
848 bool UseEnvironment =
849 (!AttrEnvironment.empty() && !TargetEnvironment.empty());
852 EnvironmentMatchesOrNone
853 ? (UseNewDiagKind ? diag::warn_unguarded_availability_new
854 : diag::warn_unguarded_availability)
856 ? diag::warn_unguarded_availability_unavailable_new
857 : diag::warn_unguarded_availability_unavailable);
860 <<
Range << D << PlatformName << Introduced.getAsString()
861 << UseEnvironment << TargetEnvironment;
864 diag::note_partial_availability_specified_here)
865 << OffendingDecl << PlatformName << Introduced.getAsString()
867 << UseEnvironment << AttrEnvironment << TargetEnvironment;
876 if (StmtStack.empty())
878 const Stmt *StmtOfUse = StmtStack.back();
880 for (
const Stmt *S : llvm::reverse(StmtStack)) {
881 if (
const auto *CS = dyn_cast<CompoundStmt>(S)) {
885 if (isBodyLikeChildStmt(StmtOfUse, S)) {
893 const Stmt *LastStmtOfUse =
nullptr;
894 if (isa<DeclStmt>(StmtOfUse) &&
Scope) {
895 for (
const Decl *D : cast<DeclStmt>(StmtOfUse)->decls()) {
896 if (StmtUSEFinder::isContained(StmtStack.back(), D)) {
897 LastStmtOfUse = LastDeclUSEFinder::findLastStmtThatUsesDecl(D,
Scope);
907 SM.getExpansionRange(
908 (LastStmtOfUse ? LastStmtOfUse : StmtOfUse)->getEndLoc())
910 if (
SM.getFileID(IfInsertionLoc) !=
SM.getFileID(StmtEndLoc))
914 const char *ExtraIndentation =
" ";
915 std::string FixItString;
916 llvm::raw_string_ostream FixItOS(FixItString);
917 FixItOS <<
"if (" << (SemaRef.
getLangOpts().ObjC ?
"@available"
918 :
"__builtin_available")
920 << AvailabilityAttr::getPlatformNameSourceSpelling(
922 <<
" " << Introduced.getAsString() <<
", *)) {\n"
923 << Indentation << ExtraIndentation;
931 FixItOS.str().clear();
933 << Indentation <<
"} else {\n"
934 << Indentation << ExtraIndentation
935 <<
"// Fallback on earlier versions\n"
936 << Indentation <<
"}";
941 bool DiagnoseUnguardedAvailability::VisitTypeLoc(
TypeLoc Ty) {
948 if (
const auto *TT = dyn_cast<TagType>(TyPtr)) {
950 DiagnoseDeclAvailability(TD, Range);
952 }
else if (
const auto *TD = dyn_cast<TypedefType>(TyPtr)) {
954 DiagnoseDeclAvailability(D, Range);
956 }
else if (
const auto *ObjCO = dyn_cast<ObjCObjectType>(TyPtr)) {
957 if (
NamedDecl *D = ObjCO->getInterface())
958 DiagnoseDeclAvailability(D, Range);
964 bool DiagnoseUnguardedAvailability::TraverseIfStmt(
IfStmt *If) {
965 VersionTuple CondVersion;
966 if (
auto *E = dyn_cast<ObjCAvailabilityCheckExpr>(
If->getCond())) {
971 if (CondVersion.empty() || CondVersion <= AvailabilityStack.back())
972 return TraverseStmt(
If->getThen()) && TraverseStmt(
If->getElse());
975 return Base::TraverseIfStmt(If);
978 AvailabilityStack.push_back(CondVersion);
979 bool ShouldContinue = TraverseStmt(
If->getThen());
980 AvailabilityStack.pop_back();
982 return ShouldContinue && TraverseStmt(
If->getElse());
988 Stmt *Body =
nullptr;
991 Body = FD->getBody();
993 if (
auto *CD = dyn_cast<CXXConstructorDecl>(FD))
995 DiagnoseUnguardedAvailability(*
this, D).IssueDiagnostics(CI->getInit());
997 }
else if (
auto *MD = dyn_cast<ObjCMethodDecl>(D))
998 Body = MD->getBody();
999 else if (
auto *BD = dyn_cast<BlockDecl>(D))
1000 Body = BD->getBody();
1002 assert(Body &&
"Need a body here!");
1004 DiagnoseUnguardedAvailability(*
this, D).IssueDiagnostics(Body);
1008 if (FunctionScopes.empty())
1015 return FunctionScopes.front();
1021 bool ObjCPropertyAccess,
1022 bool AvoidPartialAvailabilityChecks,
1024 std::string Message;
1028 std::tie(Result, OffendingDecl) =
1034 if (AvoidPartialAvailabilityChecks)
1041 Context->HasPotentialAvailabilityViolations =
true;
1047 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
1050 if (PDeclResult == Result)
1056 UnknownObjCClass, ObjCPDecl, ObjCPropertyAccess);
Defines the classes clang::DelayedDiagnostic and clang::AccessedEntity.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
llvm::MachO::Target Target
Defines the clang::Preprocessor interface.
static bool hasMatchingEnvironmentOrNone(const ASTContext &Context, const AvailabilityAttr *AA)
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 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 shouldDiagnoseAvailabilityByDefault(const ASTContext &Context, const VersionTuple &DeploymentVersion, const VersionTuple &DeclVersion)
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 NamedDecl * findEnclosingDeclToAnnotate(Decl *OrigCtx)
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 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.
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.
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.
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration,...
SourceLocation getLocation() const
SourceLocation getBeginLoc() const LLVM_READONLY
VersionTuple getVersionIntroduced() const
Retrieve the version of the target platform in which this declaration was introduced.
DeclContext * getDeclContext()
Concrete class used by the front-end to report problems and issues.
void setSuppressSystemWarnings(bool Val)
When set to true mask warnings that come from system headers.
bool getSuppressSystemWarnings() const
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.
SourceLocation getBeginLoc() const
VersionTuple getVersion() const
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.
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
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.
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
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.
class clang::Sema::DelayedDiagnostics DelayedDiagnostics
Preprocessor & getPreprocessor() 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
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.
ASTContext & getASTContext() const
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)
DeclContext * getCurLexicalContext() const
DiagnosticsEngine & getDiagnostics() const
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.
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.
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Base wrapper for a particular "section" of type source info.
const Type * getTypePtr() const
SourceLocation getEndLoc() const
Get the end source location.
SourceLocation getBeginLoc() const
Get the begin source location.
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 ObjCPropertyDecl * getObjCProperty() const
ArrayRef< SourceLocation > getAvailabilitySelectorLocs() const
const NamedDecl * getAvailabilityOffendingDecl() const
const NamedDecl * getAvailabilityReferringDecl() const
StringRef getAvailabilityMessage() const
AvailabilityResult getAvailabilityResult() const
const ObjCInterfaceDecl * getUnknownObjCClass() 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.
AvailabilityResult
Captures the result of checking the availability of a declaration.
@ Interface
The "__interface" keyword introduces the elaborated-type-specifier.