clang 20.0.0git
Functions
SemaAvailability.cpp File Reference
#include "clang/AST/Attr.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Basic/DiagnosticSema.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Sema/DelayedDiagnostic.h"
#include "clang/Sema/ScopeInfo.h"
#include "clang/Sema/Sema.h"
#include "clang/Sema/SemaObjC.h"
#include "llvm/ADT/StringRef.h"
#include <optional>

Go to the source code of this file.

Functions

static bool hasMatchingEnvironmentOrNone (const ASTContext &Context, const AvailabilityAttr *AA)
 
static const AvailabilityAttr * getAttrForPlatform (ASTContext &Context, const Decl *D)
 
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 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.
 
static unsigned getAvailabilityDiagnosticKind (const ASTContext &Context, const VersionTuple &DeploymentVersion, const VersionTuple &DeclVersion, bool HasMatchingEnv)
 
static NamedDeclfindEnclosingDeclToAnnotate (Decl *OrigCtx)
 
static std::optional< unsignedtryParseObjCMethodName (StringRef Name, SmallVectorImpl< StringRef > &SlotNames, const LangOptions &LangOpts)
 Tries to parse a string as ObjC method name.
 
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 declaration \D.
 
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 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)
 

Function Documentation

◆ createAttributeInsertion()

static std::optional< AttributeInsertion > createAttributeInsertion ( const NamedDecl D,
const SourceManager SM,
const LangOptions LangOpts 
)
static

Returns a source location in which it's appropriate to insert a new attribute for the given declaration \D.

Definition at line 358 of file SemaAvailability.cpp.

References D, clang::Lexer::getLocForEndOfToken(), clang::SourceLocation::isInvalid(), Loc, and SM.

Referenced by DoEmitAvailabilityWarning().

◆ DoEmitAvailabilityWarning()

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 
)
static

Actually emit an availability diagnostic for a reference to an unavailable decl.

Parameters
CtxThe context that the reference occurred in
ReferringDeclThe exact declaration that was referenced.
OffendingDeclA related decl to ReferringDecl that has an availability attribute corresponding to K attached to it. Note that this may not be the same as ReferringDecl, i.e. if an EnumDecl is annotated and we refer to a member EnumConstantDecl, ReferringDecl is the EnumConstantDecl and OffendingDecl is the EnumDecl.

Definition at line 388 of file SemaAvailability.cpp.

References clang::AR_Available, clang::AR_Deprecated, clang::AR_NotYetIntroduced, clang::AR_Unavailable, clang::Sema::Context, createAttributeInsertion(), clang::FixItHint::CreateInsertion(), clang::FixItHint::CreateReplacement(), clang::SemaBase::Diag(), E, findEnclosingDeclToAnnotate(), clang::Sema::getASTContext(), clang::Decl::getAttr(), getAttrForPlatform(), getAvailabilityDiagnosticKind(), clang::CharSourceRange::getCharRange(), clang::NamedDecl::getDeclName(), clang::Sema::getDiagnostics(), clang::Sema::getLangOpts(), clang::Decl::getLocation(), clang::Sema::getLocForEndOfToken(), clang::NamedDecl::getMostRecentDecl(), clang::Selector::getNameForSlot(), clang::Selector::getNumArgs(), clang::TargetInfo::getPlatformMinVersion(), clang::TargetInfo::getPlatformName(), clang::Sema::getPreprocessor(), clang::Decl::getPreviousDecl(), clang::Sema::getSourceManager(), clang::ASTContext::getTargetInfo(), clang::Sema::getTopMostPointOfInstantiation(), clang::TargetInfo::getTriple(), clang::Decl::getVersionIntroduced(), hasMatchingEnvironmentOrNone(), clang::SourceManager::isInSystemHeader(), clang::Preprocessor::isMacroDefined(), clang::CharSourceRange::isValid(), Loc, ShouldDiagnoseAvailabilityInContext(), and tryParseObjCMethodName().

Referenced by EmitAvailabilityWarning(), and clang::Sema::handleDelayedAvailabilityCheck().

◆ EmitAvailabilityWarning()

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

◆ findEnclosingDeclToAnnotate()

static NamedDecl * findEnclosingDeclToAnnotate ( Decl OrigCtx)
static

Definition at line 281 of file SemaAvailability.cpp.

Referenced by DoEmitAvailabilityWarning().

◆ getAttrForPlatform()

static const AvailabilityAttr * getAttrForPlatform ( ASTContext Context,
const Decl D 
)
static

◆ getAvailabilityDiagnosticKind()

static unsigned getAvailabilityDiagnosticKind ( const ASTContext Context,
const VersionTuple &  DeploymentVersion,
const VersionTuple &  DeclVersion,
bool  HasMatchingEnv 
)
static

◆ hasMatchingEnvironmentOrNone()

static bool hasMatchingEnvironmentOrNone ( const ASTContext Context,
const AvailabilityAttr *  AA 
)
static

◆ ShouldDiagnoseAvailabilityInContext()

static bool ShouldDiagnoseAvailabilityInContext ( Sema S,
AvailabilityResult  K,
VersionTuple  DeclVersion,
const IdentifierInfo DeclEnv,
Decl Ctx,
const NamedDecl OffendingDecl 
)
static

◆ ShouldDiagnoseAvailabilityOfDecl()

static std::pair< AvailabilityResult, const NamedDecl * > ShouldDiagnoseAvailabilityOfDecl ( Sema S,
const NamedDecl D,
std::string *  Message,
ObjCInterfaceDecl ClassReceiver 
)
static

The diagnostic we should emit for D, and the declaration that originated it, or AR_Available.

Parameters
DThe declaration to check.
MessageIf non-null, this will be populated with the message from the availability attribute that is selected.
ClassReceiverIf we're checking the method of a class message send, the class. Otherwise nullptr.

Definition at line 92 of file SemaAvailability.cpp.

References clang::AR_Available, D, clang::Sema::getASTContext(), clang::Decl::getAvailability(), clang::Init, clang::ObjCInterfaceDecl::lookupInstanceMethod(), clang::SemaObjC::NSAPIObj, and clang::Sema::ObjC().

Referenced by clang::Sema::DiagnoseAvailabilityOfDecl().

◆ tryParseObjCMethodName()

static std::optional< unsigned > tryParseObjCMethodName ( StringRef  Name,
SmallVectorImpl< StringRef > &  SlotNames,
const LangOptions LangOpts 
)
static

Tries to parse a string as ObjC method name.

Parameters
NameThe string to parse. Expected to originate from availability attribute argument.
SlotNamesThe vector that will be populated with slot names. In case of unsuccessful parsing can contain invalid data.
Returns
A number of method parameters if parsing was successful, std::nullopt otherwise.

Definition at line 325 of file SemaAvailability.cpp.

References clang::isValidAsciiIdentifier().

Referenced by DoEmitAvailabilityWarning().