26#include "llvm/ADT/StringRef.h"
33 const AvailabilityAttr *AA) {
36 if (!IIEnvironment || Environment == llvm::Triple::UnknownEnvironment)
39 llvm::Triple::EnvironmentType ET =
40 AvailabilityAttr::getEnvironmentType(IIEnvironment->
getName());
41 return Environment == ET;
46 AvailabilityAttr
const *PartialMatch =
nullptr;
52 if (
const auto *FTD = dyn_cast<FunctionTemplateDecl>(
D))
53 D = FTD->getTemplatedDecl();
54 for (
const auto *A :
D->
attrs()) {
55 if (
const auto *Avail = dyn_cast<AvailabilityAttr>(A)) {
61 StringRef ActualPlatform = Avail->getPlatform()->getName();
62 StringRef RealizedPlatform = ActualPlatform;
64 size_t suffix = RealizedPlatform.rfind(
"_app_extension");
65 if (suffix != StringRef::npos)
66 RealizedPlatform = RealizedPlatform.slice(0, suffix);
72 if (RealizedPlatform == TargetPlatform) {
91static std::pair<AvailabilityResult, const NamedDecl *>
99 while (
const auto *TD = dyn_cast<TypedefNameDecl>(
D)) {
101 if (
const auto *TT = TD->getUnderlyingType()->getAs<
TagType>()) {
111 if (
const auto *ADecl = dyn_cast<TypeAliasTemplateDecl>(
D)) {
112 D = ADecl->getTemplatedDecl();
117 if (
const auto *IDecl = dyn_cast<ObjCInterfaceDecl>(
D)) {
118 if (IDecl->getDefinition()) {
119 D = IDecl->getDefinition();
124 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(
D))
127 if (
const auto *TheEnumDecl = dyn_cast<EnumDecl>(DC)) {
134 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(
D)) {
139 MD->getSelector() == S.
ObjC().
NSAPIObj->getNewSelector() &&
141 Result =
Init->getAvailability(Message);
157 assert(K !=
AR_Available &&
"Expected an unavailable declaration here!");
162 if (DeclLoc.isMacroID() && S.
getLangOpts().CPlusPlus &&
163 isa<TypedefDecl>(OffendingDecl)) {
165 if (MacroName ==
"CF_OPTIONS" || MacroName ==
"OBJC_OPTIONS" ||
166 MacroName ==
"SWIFT_OPTIONS" || MacroName ==
"NS_OPTIONS") {
179 (DeclEnv !=
nullptr &&
181 llvm::Triple::EnvironmentType::Library))
186 auto CheckContext = [&](
const Decl *
C) {
189 if (AA->getIntroduced() >= DeclVersion &&
190 AA->getEnvironment() == DeclEnv)
193 if (
C->isDeprecated())
199 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(OffendingDecl)) {
200 if (
const auto *Impl = dyn_cast<ObjCImplDecl>(
C)) {
201 if (MD->getClassInterface() == Impl->getClassInterface())
207 if (
C->isUnavailable())
213 if (CheckContext(Ctx))
218 if (
const auto *MethodD = dyn_cast<ObjCMethodDecl>(Ctx))
219 if (MethodD->isClassMethod() &&
220 MethodD->getSelector().getAsString() ==
"load")
223 if (
const auto *CatOrImpl = dyn_cast<ObjCImplDecl>(Ctx)) {
229 else if (
const auto *CatD = dyn_cast<ObjCCategoryDecl>(Ctx))
239 const ASTContext &Context,
const VersionTuple &DeploymentVersion,
240 const VersionTuple &DeclVersion,
bool HasMatchingEnv) {
242 VersionTuple ForceAvailabilityFromVersion;
243 switch (Triple.getOS()) {
248 case llvm::Triple::IOS:
249 case llvm::Triple::TvOS:
250 ForceAvailabilityFromVersion = VersionTuple(11);
252 case llvm::Triple::WatchOS:
253 ForceAvailabilityFromVersion = VersionTuple(4);
255 case llvm::Triple::Darwin:
256 case llvm::Triple::MacOSX:
257 ForceAvailabilityFromVersion = VersionTuple(10, 13);
263 case llvm::Triple::ShaderModel:
264 return HasMatchingEnv ? diag::warn_hlsl_availability
265 : diag::warn_hlsl_availability_unavailable;
268 ForceAvailabilityFromVersion =
269 (Triple.getVendor() == llvm::Triple::Apple)
271 : VersionTuple((
unsigned)-1, (
unsigned)-1);
273 if (DeploymentVersion >= ForceAvailabilityFromVersion ||
274 DeclVersion >= ForceAvailabilityFromVersion)
275 return HasMatchingEnv ? diag::warn_unguarded_availability_new
276 : diag::warn_unguarded_availability_unavailable_new;
277 return HasMatchingEnv ? diag::warn_unguarded_availability
278 : diag::warn_unguarded_availability_unavailable;
282 for (
Decl *Ctx = OrigCtx; Ctx;
283 Ctx = cast_or_null<Decl>(Ctx->getDeclContext())) {
284 if (isa<TagDecl>(Ctx) || isa<FunctionDecl>(Ctx) || isa<ObjCMethodDecl>(Ctx))
285 return cast<NamedDecl>(Ctx);
286 if (
auto *CD = dyn_cast<ObjCContainerDecl>(Ctx)) {
287 if (
auto *Imp = dyn_cast<ObjCImplDecl>(Ctx))
288 return Imp->getClassInterface();
293 return dyn_cast<NamedDecl>(OrigCtx);
298struct AttributeInsertion {
303 static AttributeInsertion createInsertionAfter(
const NamedDecl *
D) {
306 static AttributeInsertion createInsertionAfter(
SourceLocation Loc) {
307 return {
" ",
Loc,
""};
309 static AttributeInsertion createInsertionBefore(
const NamedDecl *
D) {
324static std::optional<unsigned>
328 if (!Name.empty() && (Name.front() ==
'-' || Name.front() ==
'+'))
329 Name = Name.drop_front(1);
332 Name.split(SlotNames,
':');
334 if (Name.back() ==
':') {
336 SlotNames.pop_back();
337 NumParams = SlotNames.size();
339 if (SlotNames.size() != 1)
345 bool AllowDollar = LangOpts.DollarIdents;
346 for (StringRef S : SlotNames) {
357static std::optional<AttributeInsertion>
360 if (isa<ObjCPropertyDecl>(
D))
361 return AttributeInsertion::createInsertionAfter(
D);
362 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(
D)) {
365 return AttributeInsertion::createInsertionAfter(
D);
367 if (
const auto *TD = dyn_cast<TagDecl>(
D)) {
373 return AttributeInsertion::createInsertionAfter(
Loc);
375 return AttributeInsertion::createInsertionBefore(
D);
395 bool ObjCPropertyAccess) {
397 unsigned diag, diag_message, diag_fwdclass_message;
398 unsigned diag_available_here = diag::note_availability_specified_here;
402 unsigned property_note_select;
405 unsigned available_here_select_kind;
407 VersionTuple DeclVersion;
411 DeclVersion = AA->getIntroduced();
412 IIEnv = AA->getEnvironment();
423 if (AA && AA->isInherited()) {
426 const AvailabilityAttr *AForRedecl =
428 if (AForRedecl && !AForRedecl->isInherited()) {
431 NoteLocation = Redecl->getLocation();
443 assert(AA !=
nullptr &&
"expecting valid availability attribute");
444 VersionTuple Introduced = AA->getIntroduced();
445 bool EnvironmentMatchesOrNone =
449 std::string PlatformName(
451 llvm::StringRef TargetEnvironment(
452 llvm::Triple::getEnvironmentTypeName(TI.
getTriple().getEnvironment()));
453 llvm::StringRef AttrEnvironment =
454 AA->getEnvironment() ? AA->getEnvironment()->getName() :
"";
455 bool UseEnvironment =
456 (!AttrEnvironment.empty() && !TargetEnvironment.empty());
460 Introduced, EnvironmentMatchesOrNone);
462 S.
Diag(
Loc, DiagKind) << OffendingDecl << PlatformName
463 << Introduced.getAsString() << UseEnvironment
464 << TargetEnvironment;
467 diag::note_partial_availability_specified_here)
468 << OffendingDecl << PlatformName << Introduced.getAsString()
470 << UseEnvironment << AttrEnvironment << TargetEnvironment;
477 if (
const auto *TD = dyn_cast<TagDecl>(Enclosing))
478 if (TD->getDeclName().isEmpty()) {
479 S.
Diag(TD->getLocation(),
480 diag::note_decl_unguarded_availability_silence)
481 << 1 << TD->getKindName();
485 S.
Diag(Enclosing->getLocation(),
486 diag::note_decl_unguarded_availability_silence)
489 if (Enclosing->hasAttr<AvailabilityAttr>())
497 std::string PlatformName =
498 AvailabilityAttr::getPlatformNameSourceSpelling(
501 std::string Introduced =
505 (llvm::Twine(Insertion->Prefix) +
"API_AVAILABLE(" + PlatformName +
506 "(" + Introduced +
"))" + Insertion->Suffix)
512 diag = !ObjCPropertyAccess ? diag::warn_deprecated
513 : diag::warn_property_method_deprecated;
514 diag_message = diag::warn_deprecated_message;
515 diag_fwdclass_message = diag::warn_deprecated_fwdclass_message;
516 property_note_select = 0;
517 available_here_select_kind = 2;
518 if (
const auto *AL = OffendingDecl->
getAttr<DeprecatedAttr>())
519 NoteLocation = AL->getLocation();
523 diag = !ObjCPropertyAccess ? diag::err_unavailable
524 : diag::err_property_method_unavailable;
525 diag_message = diag::err_unavailable_message;
526 diag_fwdclass_message = diag::warn_unavailable_fwdclass_message;
527 property_note_select = 1;
528 available_here_select_kind = 0;
530 if (
auto AL = OffendingDecl->
getAttr<UnavailableAttr>()) {
531 if (AL->isImplicit() && AL->getImplicitReason()) {
534 auto flagARCError = [&] {
538 diag = diag::err_unavailable_in_arc;
541 switch (AL->getImplicitReason()) {
542 case UnavailableAttr::IR_None:
break;
544 case UnavailableAttr::IR_ARCForbiddenType:
546 diag_available_here = diag::note_arc_forbidden_type;
549 case UnavailableAttr::IR_ForbiddenWeak:
551 diag_available_here = diag::note_arc_weak_disabled;
553 diag_available_here = diag::note_arc_weak_no_runtime;
556 case UnavailableAttr::IR_ARCForbiddenConversion:
558 diag_available_here = diag::note_performs_forbidden_arc_conversion;
561 case UnavailableAttr::IR_ARCInitReturnsUnrelated:
563 diag_available_here = diag::note_arc_init_returns_unrelated;
566 case UnavailableAttr::IR_ARCFieldWithOwnership:
568 diag_available_here = diag::note_arc_field_with_ownership;
576 llvm_unreachable(
"Warning for availability of available declaration?");
581 StringRef Replacement;
582 if (
auto AL = OffendingDecl->
getAttr<DeprecatedAttr>())
583 Replacement = AL->getReplacement();
585 Replacement = AL->getReplacement();
588 if (!Replacement.empty())
592 if (
const auto *MethodDecl = dyn_cast<ObjCMethodDecl>(ReferringDecl)) {
593 Selector Sel = MethodDecl->getSelector();
597 if (NumParams && *NumParams == Sel.
getNumArgs()) {
598 assert(SelectorSlotNames.size() == Locs.size());
599 for (
unsigned I = 0; I < Locs.size(); ++I) {
604 NameRange, SelectorSlotNames[I]));
622 bool ShouldAllowWarningInSystemHeader =
623 InstantiationLoc !=
Loc &&
625 struct AllowWarningInSystemHeaders {
627 bool AllowWarningInSystemHeaders)
628 : Engine(
E), Prev(
E.getSuppressSystemWarnings()) {
629 E.setSuppressSystemWarnings(!AllowWarningInSystemHeaders);
631 ~AllowWarningInSystemHeaders() { Engine.setSuppressSystemWarnings(Prev); }
637 ShouldAllowWarningInSystemHeader);
639 if (!Message.empty()) {
640 S.
Diag(
Loc, diag_message) << ReferringDecl << Message << FixIts;
643 << ObjCProperty->
getDeclName() << property_note_select;
644 }
else if (!UnknownObjCClass) {
645 S.
Diag(
Loc, diag) << ReferringDecl << FixIts;
648 << ObjCProperty->
getDeclName() << property_note_select;
650 S.
Diag(
Loc, diag_fwdclass_message) << ReferringDecl << FixIts;
654 S.
Diag(NoteLocation, diag_available_here)
655 << OffendingDecl << available_here_select_kind;
660 "Expected an availability diagnostic here");
677 bool ObjCPropertyAccess) {
682 AR, Locs, ReferringDecl, OffendingDecl, UnknownObjCClass,
683 ObjCProperty, Message, ObjCPropertyAccess));
689 Message, Locs, UnknownObjCClass, ObjCProperty,
697 switch (
Parent->getStmtClass()) {
698 case Stmt::IfStmtClass:
699 return cast<IfStmt>(
Parent)->getThen() == S ||
700 cast<IfStmt>(
Parent)->getElse() == S;
701 case Stmt::WhileStmtClass:
702 return cast<WhileStmt>(
Parent)->getBody() == S;
703 case Stmt::DoStmtClass:
704 return cast<DoStmt>(
Parent)->getBody() == S;
705 case Stmt::ForStmtClass:
706 return cast<ForStmt>(
Parent)->getBody() == S;
707 case Stmt::CXXForRangeStmtClass:
708 return cast<CXXForRangeStmt>(
Parent)->getBody() == S;
709 case Stmt::ObjCForCollectionStmtClass:
710 return cast<ObjCForCollectionStmt>(
Parent)->getBody() == S;
711 case Stmt::CaseStmtClass:
712 case Stmt::DefaultStmtClass:
713 return cast<SwitchCase>(
Parent)->getSubStmt() == S;
723 bool VisitStmt(
Stmt *S) {
return S !=
Target; }
727 StmtUSEFinder Visitor;
729 return !Visitor.TraverseDecl(
const_cast<Decl *
>(
D));
745 static const Stmt *findLastStmtThatUsesDecl(
const Decl *
D,
747 LastDeclUSEFinder Visitor;
749 for (
const Stmt *S : llvm::reverse(
Scope->body())) {
750 if (!Visitor.TraverseStmt(
const_cast<Stmt *
>(S)))
763class DiagnoseUnguardedAvailability
778 DiagnoseUnguardedAvailability(
Sema &SemaRef,
Decl *Ctx)
779 : SemaRef(SemaRef), Ctx(Ctx) {
780 AvailabilityStack.push_back(
784 bool TraverseStmt(
Stmt *S) {
787 StmtStack.push_back(S);
788 bool Result = Base::TraverseStmt(S);
789 StmtStack.pop_back();
793 void IssueDiagnostics(
Stmt *S) { TraverseStmt(S); }
810 DiagnoseDeclAvailability(
817 DiagnoseDeclAvailability(DRE->
getDecl(),
837void DiagnoseUnguardedAvailability::DiagnoseDeclAvailability(
841 std::tie(
Result, OffendingDecl) =
849 const AvailabilityAttr *AA =
851 assert(AA !=
nullptr &&
"expecting valid availability attribute");
852 bool EnvironmentMatchesOrNone =
854 VersionTuple Introduced = AA->getIntroduced();
856 if (EnvironmentMatchesOrNone && AvailabilityStack.back() >= Introduced)
862 AA->getEnvironment(), Ctx,
867 std::string PlatformName(
869 llvm::StringRef TargetEnvironment(TI.
getTriple().getEnvironmentName());
870 llvm::StringRef AttrEnvironment =
871 AA->getEnvironment() ? AA->getEnvironment()->getName() :
"";
872 bool UseEnvironment =
873 (!AttrEnvironment.empty() && !TargetEnvironment.empty());
878 EnvironmentMatchesOrNone);
881 <<
Range <<
D << PlatformName << Introduced.getAsString()
882 << UseEnvironment << TargetEnvironment;
885 diag::note_partial_availability_specified_here)
886 << OffendingDecl << PlatformName << Introduced.getAsString()
888 << UseEnvironment << AttrEnvironment << TargetEnvironment;
901 if (StmtStack.empty())
903 const Stmt *StmtOfUse = StmtStack.back();
905 for (
const Stmt *S : llvm::reverse(StmtStack)) {
906 if (
const auto *CS = dyn_cast<CompoundStmt>(S)) {
910 if (isBodyLikeChildStmt(StmtOfUse, S)) {
918 const Stmt *LastStmtOfUse =
nullptr;
919 if (isa<DeclStmt>(StmtOfUse) &&
Scope) {
920 for (
const Decl *
D : cast<DeclStmt>(StmtOfUse)->decls()) {
921 if (StmtUSEFinder::isContained(StmtStack.back(),
D)) {
922 LastStmtOfUse = LastDeclUSEFinder::findLastStmtThatUsesDecl(
D,
Scope);
932 SM.getExpansionRange(
933 (LastStmtOfUse ? LastStmtOfUse : StmtOfUse)->getEndLoc())
935 if (
SM.getFileID(IfInsertionLoc) !=
SM.getFileID(StmtEndLoc))
939 const char *ExtraIndentation =
" ";
940 std::string FixItString;
941 llvm::raw_string_ostream FixItOS(FixItString);
942 FixItOS <<
"if (" << (SemaRef.
getLangOpts().ObjC ?
"@available"
943 :
"__builtin_available")
945 << AvailabilityAttr::getPlatformNameSourceSpelling(
947 <<
" " << Introduced.getAsString() <<
", *)) {\n"
948 << Indentation << ExtraIndentation;
956 FixItOS.str().clear();
958 << Indentation <<
"} else {\n"
959 << Indentation << ExtraIndentation
960 <<
"// Fallback on earlier versions\n"
961 << Indentation <<
"}";
966bool DiagnoseUnguardedAvailability::VisitTypeLoc(
TypeLoc Ty) {
973 if (
const auto *TT = dyn_cast<TagType>(TyPtr)) {
975 DiagnoseDeclAvailability(TD,
Range);
977 }
else if (
const auto *TD = dyn_cast<TypedefType>(TyPtr)) {
979 DiagnoseDeclAvailability(
D,
Range);
981 }
else if (
const auto *ObjCO = dyn_cast<ObjCObjectType>(TyPtr)) {
983 DiagnoseDeclAvailability(
D,
Range);
989bool DiagnoseUnguardedAvailability::TraverseIfStmt(
IfStmt *
If) {
990 VersionTuple CondVersion;
991 if (
auto *
E = dyn_cast<ObjCAvailabilityCheckExpr>(
If->getCond())) {
992 CondVersion =
E->getVersion();
996 if (CondVersion.empty() || CondVersion <= AvailabilityStack.back())
997 return TraverseStmt(
If->getThen()) && TraverseStmt(
If->getElse());
1000 return Base::TraverseIfStmt(
If);
1003 AvailabilityStack.push_back(CondVersion);
1004 bool ShouldContinue = TraverseStmt(
If->getThen());
1005 AvailabilityStack.pop_back();
1007 return ShouldContinue && TraverseStmt(
If->getElse());
1013 Stmt *Body =
nullptr;
1016 Body = FD->getBody();
1018 if (
auto *CD = dyn_cast<CXXConstructorDecl>(FD))
1020 DiagnoseUnguardedAvailability(*
this,
D).IssueDiagnostics(CI->getInit());
1022 }
else if (
auto *MD = dyn_cast<ObjCMethodDecl>(
D))
1023 Body = MD->getBody();
1024 else if (
auto *BD = dyn_cast<BlockDecl>(
D))
1025 Body = BD->getBody();
1027 assert(Body &&
"Need a body here!");
1029 DiagnoseUnguardedAvailability(*
this,
D).IssueDiagnostics(Body);
1046 bool ObjCPropertyAccess,
1047 bool AvoidPartialAvailabilityChecks,
1049 std::string Message;
1053 std::tie(
Result, OffendingDecl) =
1059 if (AvoidPartialAvailabilityChecks)
1066 Context->HasPotentialAvailabilityViolations =
true;
1072 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(
D)) {
1075 if (PDeclResult ==
Result)
1081 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.
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.
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.
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.
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.