clang  20.0.0git
Functions
SemaExprObjC.cpp File Reference
#include "clang/AST/ASTContext.h"
#include "clang/AST/Availability.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/ExprObjC.h"
#include "clang/AST/StmtVisitor.h"
#include "clang/AST/TypeLoc.h"
#include "clang/Analysis/DomainSpecific/CocoaConventions.h"
#include "clang/Basic/Builtins.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Edit/Commit.h"
#include "clang/Edit/Rewriters.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Sema/Initialization.h"
#include "clang/Sema/Lookup.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/ScopeInfo.h"
#include "clang/Sema/SemaInternal.h"
#include "clang/Sema/SemaObjC.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/ConvertUTF.h"
#include <optional>

Go to the source code of this file.

Functions

static bool validateBoxingMethod (Sema &S, SourceLocation Loc, const ObjCInterfaceDecl *Class, Selector Sel, const ObjCMethodDecl *Method)
 Emits an error if the given method does not exist, or if the return type is not an Objective-C object. More...
 
static NSAPI::NSClassIdKindKind ClassKindFromLiteralKind (SemaObjC::ObjCLiteralKind LiteralKind)
 Maps ObjCLiteralKind to NSClassIdKindKind. More...
 
static bool ValidateObjCLiteralInterfaceDecl (Sema &S, ObjCInterfaceDecl *Decl, SourceLocation Loc, SemaObjC::ObjCLiteralKind LiteralKind)
 Validates ObjCInterfaceDecl availability. More...
 
enum  ARCConversionTypeClass {
  ACTC_none , ACTC_retainable , ACTC_indirectRetainable , ACTC_voidPtr ,
  ACTC_coreFoundation
}
 
static ObjCInterfaceDeclLookupObjCInterfaceDeclForLiteral (Sema &S, SourceLocation Loc, SemaObjC::ObjCLiteralKind LiteralKind)
 Looks up ObjCInterfaceDecl of a given NSClassIdKindKind. More...
 
static ObjCMethodDeclgetNSNumberFactoryMethod (SemaObjC &S, SourceLocation Loc, QualType NumberType, bool isLiteral=false, SourceRange R=SourceRange())
 Retrieve the NSNumber factory method that should be used to create an Objective-C literal for the given type. More...
 
static ExprResult CheckObjCCollectionLiteralElement (Sema &S, Expr *Element, QualType T, bool ArrayLiteral=false)
 Check that the given expression is a valid element of an Objective-C collection literal. More...
 
static void CheckObjCDictionaryLiteralDuplicateKeys (Sema &S, ObjCDictionaryLiteral *Literal)
 Check for duplicate keys in an ObjC dictionary literal. More...
 
static bool HelperToDiagnoseMismatchedMethodsInGlobalPool (Sema &S, SourceLocation AtLoc, SourceLocation LParenLoc, SourceLocation RParenLoc, ObjCMethodDecl *Method, ObjCMethodList &MethList)
 
static void DiagnoseMismatchedSelectors (Sema &S, SourceLocation AtLoc, ObjCMethodDecl *Method, SourceLocation LParenLoc, SourceLocation RParenLoc, bool WarnMultipleSelectors)
 
static ObjCMethodDeclLookupDirectMethodInMethodList (Sema &S, Selector Sel, ObjCMethodList &MethList, bool &onlyDirect, bool &anyDirect)
 
static ObjCMethodDeclLookupDirectMethodInGlobalPool (Sema &S, Selector Sel, bool &onlyDirect, bool &anyDirect)
 
static ObjCMethodDeclfindMethodInCurrentClass (Sema &S, Selector Sel)
 
static QualType stripObjCInstanceType (ASTContext &Context, QualType T)
 
static QualType getBaseMessageSendResultType (Sema &S, QualType ReceiverType, ObjCMethodDecl *Method, bool isClassMessage, bool isSuperMessage)
 Determine the result type of a message send based on the receiver type, method, and the kind of message send. More...
 
static const ObjCMethodDeclfindExplicitInstancetypeDeclarer (const ObjCMethodDecl *MD, QualType instancetype)
 Look for an ObjC method whose result type exactly matches the given type. More...
 
static void applyCocoaAPICheck (Sema &S, const ObjCMessageExpr *Msg, unsigned DiagID, bool(*refactor)(const ObjCMessageExpr *, const NSAPI &, edit::Commit &))
 
static void checkCocoaAPI (Sema &S, const ObjCMessageExpr *Msg)
 
static void checkFoundationAPI (Sema &S, SourceLocation Loc, const ObjCMethodDecl *Method, ArrayRef< Expr * > Args, QualType ReceiverType, bool IsClassObjectCall)
 
static void DiagnoseCStringFormatDirectiveInObjCAPI (Sema &S, ObjCMethodDecl *Method, Selector Sel, Expr **Args, unsigned NumArgs)
 Diagnose use of s directive in an NSString which is being passed as formatting string to formatting method. More...
 
static bool isMethodDeclaredInRootProtocol (Sema &S, const ObjCMethodDecl *M)
 
static void RemoveSelectorFromWarningCache (SemaObjC &S, Expr *Arg)
 
static bool isAnyRetainable (ARCConversionTypeClass ACTC)
 
static bool isAnyCLike (ARCConversionTypeClass ACTC)
 
static ARCConversionTypeClass classifyTypeForARCConversion (QualType type)
 
template<typename DiagBuilderT >
static void addFixitForObjCARCConversion (Sema &S, DiagBuilderT &DiagB, CheckedConversionKind CCK, SourceLocation afterLParen, QualType castType, Expr *castExpr, Expr *realCast, const char *bridgeKeyword, const char *CFBridgeName)
 
template<typename T >
static T * getObjCBridgeAttr (const TypedefType *TD)
 
static ObjCBridgeRelatedAttr * ObjCBridgeRelatedAttrFromType (QualType T, TypedefNameDecl *&TDNDecl)
 
static void diagnoseObjCARCConversion (Sema &S, SourceRange castRange, QualType castType, ARCConversionTypeClass castACTC, Expr *castExpr, Expr *realCast, ARCConversionTypeClass exprACTC, CheckedConversionKind CCK)
 
template<typename TB >
static bool CheckObjCBridgeNSCast (Sema &S, QualType castType, Expr *castExpr, bool &HadTheAttribute, bool warn)
 
template<typename TB >
static bool CheckObjCBridgeCFCast (Sema &S, QualType castType, Expr *castExpr, bool &HadTheAttribute, bool warn)
 
static ExprmaybeUndoReclaimObject (Expr *e)
 Look for an ObjCReclaimReturnedObject cast and destroy it. More...
 

Enumeration Type Documentation

◆ ARCConversionTypeClass

Enumerator
ACTC_none 

int, void, struct A

ACTC_retainable 

id, void (^)()

ACTC_indirectRetainable 

id*, id***, void (^*)(),

ACTC_voidPtr 

void* might be a normal C type, or it might a CF type.

ACTC_coreFoundation 

struct A*

Definition at line 3455 of file SemaExprObjC.cpp.

Function Documentation

◆ addFixitForObjCARCConversion()

template<typename DiagBuilderT >
static void addFixitForObjCARCConversion ( Sema S,
DiagBuilderT &  DiagB,
CheckedConversionKind  CCK,
SourceLocation  afterLParen,
QualType  castType,
Expr castExpr,
Expr realCast,
const char *  bridgeKeyword,
const char *  CFBridgeName 
)
static

Definition at line 3761 of file SemaExprObjC.cpp.

◆ applyCocoaAPICheck()

static void applyCocoaAPICheck ( Sema S,
const ObjCMessageExpr Msg,
unsigned  DiagID,
bool(*)(const ObjCMessageExpr *, const NSAPI &, edit::Commit &)  refactor 
)
static

Definition at line 2462 of file SemaExprObjC.cpp.

◆ checkCocoaAPI()

static void checkCocoaAPI ( Sema S,
const ObjCMessageExpr Msg 
)
static

Definition at line 2501 of file SemaExprObjC.cpp.

◆ checkFoundationAPI()

static void checkFoundationAPI ( Sema S,
SourceLocation  Loc,
const ObjCMethodDecl Method,
ArrayRef< Expr * >  Args,
QualType  ReceiverType,
bool  IsClassObjectCall 
)
static

Definition at line 2506 of file SemaExprObjC.cpp.

◆ CheckObjCBridgeCFCast()

template<typename TB >
static bool CheckObjCBridgeCFCast ( Sema S,
QualType  castType,
Expr castExpr,
bool HadTheAttribute,
bool  warn 
)
static

Definition at line 4079 of file SemaExprObjC.cpp.

◆ CheckObjCBridgeNSCast()

template<typename TB >
static bool CheckObjCBridgeNSCast ( Sema S,
QualType  castType,
Expr castExpr,
bool HadTheAttribute,
bool  warn 
)
static

Definition at line 4016 of file SemaExprObjC.cpp.

◆ CheckObjCCollectionLiteralElement()

static ExprResult CheckObjCCollectionLiteralElement ( Sema S,
Expr Element,
QualType  T,
bool  ArrayLiteral = false 
)
static

Check that the given expression is a valid element of an Objective-C collection literal.

Definition at line 394 of file SemaExprObjC.cpp.

◆ CheckObjCDictionaryLiteralDuplicateKeys()

static void CheckObjCDictionaryLiteralDuplicateKeys ( Sema S,
ObjCDictionaryLiteral Literal 
)
static

Check for duplicate keys in an ObjC dictionary literal.

For instance: NSDictionary *nd = "foo" : @"bar", @"foo" : @"baz" };

Definition at line 908 of file SemaExprObjC.cpp.

◆ classifyTypeForARCConversion()

static ARCConversionTypeClass classifyTypeForARCConversion ( QualType  type)
static

◆ ClassKindFromLiteralKind()

static NSAPI::NSClassIdKindKind ClassKindFromLiteralKind ( SemaObjC::ObjCLiteralKind  LiteralKind)
static

◆ DiagnoseCStringFormatDirectiveInObjCAPI()

static void DiagnoseCStringFormatDirectiveInObjCAPI ( Sema S,
ObjCMethodDecl Method,
Selector  Sel,
Expr **  Args,
unsigned  NumArgs 
)
static

Diagnose use of s directive in an NSString which is being passed as formatting string to formatting method.

Definition at line 2555 of file SemaExprObjC.cpp.

◆ DiagnoseMismatchedSelectors()

static void DiagnoseMismatchedSelectors ( Sema S,
SourceLocation  AtLoc,
ObjCMethodDecl Method,
SourceLocation  LParenLoc,
SourceLocation  RParenLoc,
bool  WarnMultipleSelectors 
)
static

Definition at line 1214 of file SemaExprObjC.cpp.

◆ diagnoseObjCARCConversion()

static void diagnoseObjCARCConversion ( Sema S,
SourceRange  castRange,
QualType  castType,
ARCConversionTypeClass  castACTC,
Expr castExpr,
Expr realCast,
ARCConversionTypeClass  exprACTC,
CheckedConversionKind  CCK 
)
static

Definition at line 3883 of file SemaExprObjC.cpp.

Referenced by clang::SemaObjC::diagnoseARCUnbridgedCast().

◆ findExplicitInstancetypeDeclarer()

static const ObjCMethodDecl* findExplicitInstancetypeDeclarer ( const ObjCMethodDecl MD,
QualType  instancetype 
)
static

◆ findMethodInCurrentClass()

static ObjCMethodDecl* findMethodInCurrentClass ( Sema S,
Selector  Sel 
)
static

Definition at line 1281 of file SemaExprObjC.cpp.

◆ getBaseMessageSendResultType()

static QualType getBaseMessageSendResultType ( Sema S,
QualType  ReceiverType,
ObjCMethodDecl Method,
bool  isClassMessage,
bool  isSuperMessage 
)
static

Determine the result type of a message send based on the receiver type, method, and the kind of message send.

This is the "base" result type, which will still need to be adjusted to account for nullability.

Definition at line 1467 of file SemaExprObjC.cpp.

◆ getNSNumberFactoryMethod()

static ObjCMethodDecl* getNSNumberFactoryMethod ( SemaObjC S,
SourceLocation  Loc,
QualType  NumberType,
bool  isLiteral = false,
SourceRange  R = SourceRange() 
)
static

Retrieve the NSNumber factory method that should be used to create an Objective-C literal for the given type.

Definition at line 250 of file SemaExprObjC.cpp.

◆ getObjCBridgeAttr()

template<typename T >
static T* getObjCBridgeAttr ( const TypedefType TD)
inlinestatic

◆ HelperToDiagnoseMismatchedMethodsInGlobalPool()

static bool HelperToDiagnoseMismatchedMethodsInGlobalPool ( Sema S,
SourceLocation  AtLoc,
SourceLocation  LParenLoc,
SourceLocation  RParenLoc,
ObjCMethodDecl Method,
ObjCMethodList MethList 
)
static

Definition at line 1183 of file SemaExprObjC.cpp.

◆ isAnyCLike()

static bool isAnyCLike ( ARCConversionTypeClass  ACTC)
static

Definition at line 3478 of file SemaExprObjC.cpp.

References ACTC_coreFoundation, ACTC_none, and ACTC_voidPtr.

◆ isAnyRetainable()

static bool isAnyRetainable ( ARCConversionTypeClass  ACTC)
static

Definition at line 3472 of file SemaExprObjC.cpp.

References ACTC_coreFoundation, ACTC_retainable, and ACTC_voidPtr.

◆ isMethodDeclaredInRootProtocol()

static bool isMethodDeclaredInRootProtocol ( Sema S,
const ObjCMethodDecl M 
)
static

Definition at line 2797 of file SemaExprObjC.cpp.

◆ LookupDirectMethodInGlobalPool()

static ObjCMethodDecl* LookupDirectMethodInGlobalPool ( Sema S,
Selector  Sel,
bool onlyDirect,
bool anyDirect 
)
static

Definition at line 1266 of file SemaExprObjC.cpp.

◆ LookupDirectMethodInMethodList()

static ObjCMethodDecl* LookupDirectMethodInMethodList ( Sema S,
Selector  Sel,
ObjCMethodList MethList,
bool onlyDirect,
bool anyDirect 
)
static

Definition at line 1240 of file SemaExprObjC.cpp.

◆ LookupObjCInterfaceDeclForLiteral()

static ObjCInterfaceDecl* LookupObjCInterfaceDeclForLiteral ( Sema S,
SourceLocation  Loc,
SemaObjC::ObjCLiteralKind  LiteralKind 
)
static

Looks up ObjCInterfaceDecl of a given NSClassIdKindKind.

Used to create ObjC literals, such as NSDictionary (}), NSArray (@[]) and Boxed Expressions (@())

Definition at line 227 of file SemaExprObjC.cpp.

◆ maybeUndoReclaimObject()

static Expr* maybeUndoReclaimObject ( Expr e)
static

Look for an ObjCReclaimReturnedObject cast and destroy it.

Definition at line 4617 of file SemaExprObjC.cpp.

◆ ObjCBridgeRelatedAttrFromType()

static ObjCBridgeRelatedAttr* ObjCBridgeRelatedAttrFromType ( QualType  T,
TypedefNameDecl *&  TDNDecl 
)
static

◆ RemoveSelectorFromWarningCache()

static void RemoveSelectorFromWarningCache ( SemaObjC S,
Expr Arg 
)
static

Definition at line 3411 of file SemaExprObjC.cpp.

◆ stripObjCInstanceType()

static QualType stripObjCInstanceType ( ASTContext Context,
QualType  T 
)
static

Definition at line 1443 of file SemaExprObjC.cpp.

◆ validateBoxingMethod()

static bool validateBoxingMethod ( Sema S,
SourceLocation  Loc,
const ObjCInterfaceDecl Class,
Selector  Sel,
const ObjCMethodDecl Method 
)
static

Emits an error if the given method does not exist, or if the return type is not an Objective-C object.

Definition at line 154 of file SemaExprObjC.cpp.

◆ ValidateObjCLiteralInterfaceDecl()

static bool ValidateObjCLiteralInterfaceDecl ( Sema S,
ObjCInterfaceDecl Decl,
SourceLocation  Loc,
SemaObjC::ObjCLiteralKind  LiteralKind 
)
static

Validates ObjCInterfaceDecl availability.

ObjCInterfaceDecl, used to create ObjC literals, should be defined if clang not in a debugger mode.

Definition at line 204 of file SemaExprObjC.cpp.