clang 8.0.0

Enumerations | Functions
SemaExprObjC.cpp File Reference
`#include "clang/Sema/SemaInternal.h"`
`#include "clang/AST/ASTContext.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/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 "llvm/ADT/SmallString.h"`
Include dependency graph for SemaExprObjC.cpp:

Go to the source code of this file.

## Enumerations
enum | ACCResult
| A result from the cast checker. More...

## 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 (Sema::ObjCLiteralKind LiteralKind)
| Maps ObjCLiteralKind to NSClassIdKindKind. More...
static bool | ValidateObjCLiteralInterfaceDecl (Sema &S, ObjCInterfaceDecl *Decl, SourceLocation Loc, Sema::ObjCLiteralKind LiteralKind)
| Validates ObjCInterfaceDecl availability. More...
enum | ARCConversionTypeClass { ACTC_none, ACTC_retainable, ACTC_indirectRetainable, ACTC_voidPtr, ACTC_coreFoundation }
static ObjCInterfaceDecl * | LookupObjCInterfaceDeclForLiteral (Sema &S, SourceLocation Loc, Sema::ObjCLiteralKind LiteralKind)
| Looks up ObjCInterfaceDecl of a given NSClassIdKindKind. More...
static ObjCMethodDecl * | getNSNumberFactoryMethod (Sema &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 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 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 ObjCMethodDecl * | findExplicitInstancetypeDeclarer (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 (Sema &S, Expr *Arg)
static bool | isAnyRetainable (ARCConversionTypeClass ACTC)
static bool | isAnyCLike (ARCConversionTypeClass ACTC)
static ARCConversionTypeClass | classifyTypeForARCConversion (QualType type)
static void | addFixitForObjCARCConversion (Sema &S, DiagnosticBuilder &DiagB, Sema::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, Sema::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 Expr * | maybeUndoReclaimObject (Expr *e)
| Look for an ObjCReclaimReturnedObject cast and destroy it. More...

## Enumeration Type Documentation

## ◆ ACCResult

enum ACCResult

A result from the cast checker.

Definition at line 3290 of file SemaExprObjC.cpp.

## ◆ ARCConversionTypeClass

enum 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 3220 of file SemaExprObjC.cpp.

## Function Documentation

## ◆ addFixitForObjCARCConversion()

static void addFixitForObjCARCConversion | ( | Sema & | S,
|  | DiagnosticBuilder & | DiagB,
|  | Sema::CheckedConversionKind | CCK,
|  | SourceLocation | afterLParen,
|  | QualType | castType,
|  | Expr * | castExpr,
|  | Expr * | realCast,
|  | const char * | bridgeKeyword,
|  | const char * | CFBridgeName
| ) |  |
| static

Definition at line 3524 of file SemaExprObjC.cpp.

References clang::DiagnosticBuilder::AddFixItHint(), clang::ast_matchers::castExpr, clang::Sema::CCK_CStyleCast, clang::Sema::CCK_ForBuiltinOverloadedOp, clang::Sema::CCK_FunctionalCast, clang::Sema::CCK_ImplicitConversion, clang::Sema::CCK_OtherCast, clang::FixItHint::CreateInsertion(), clang::FixItHint::CreateReplacement(), clang::QualType::getAsString(), clang::SourceRange::getBegin(), clang::SourceManager::getCharacterData(), clang::SourceRange::getEnd(), clang::Sema::getLangOpts(), clang::Sema::getLocForEndOfToken(), clang::SourceLocation::getLocWithOffset(), clang::Sema::getSourceManager(), clang::Stmt::getSourceRange(), clang::Expr::IgnoreImpCasts(), clang::Lexer::isIdentifierBodyChar(), and SM.

Referenced by diagnoseObjCARCConversion().

## ◆ applyCocoaAPICheck()

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

Definition at line 2267 of file SemaExprObjC.cpp.

Referenced by checkCocoaAPI().

## ◆ checkCocoaAPI()

static void checkCocoaAPI | ( | Sema & | S,
|  | const ObjCMessageExpr * | Msg
| ) |  |
| static

Definition at line 2306 of file SemaExprObjC.cpp.

References applyCocoaAPICheck(), and clang::edit::rewriteObjCRedundantCallWithLiteral().

## ◆ checkFoundationAPI()

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

Definition at line 2311 of file SemaExprObjC.cpp.

References clang::Sema::Diag(), clang::Type::getAs(), clang::ObjCMethodDecl::getBeginLoc(), clang::Selector::getMethodFamily(), clang::ObjCMethodDecl::getReturnType(), clang::ObjCMethodDecl::getSelector(), clang::Type::isExtVectorType(), clang::Type::isRecordType(), clang::Type::isUnionType(), clang::Type::isVectorType(), and clang::OMF_performSelector.

## ◆ CheckObjCBridgeCFCast()

template<typename TB >

static bool CheckObjCBridgeCFCast | ( | Sema & | S,
|  | QualType | castType,
|  | Expr * | castExpr,
|  | bool & | HadTheAttribute,
|  | bool | warn
| ) |  |
| static

Definition at line 3847 of file SemaExprObjC.cpp.

References clang::Sema::Context, clang::Sema::Diag(), clang::Type::getAsObjCInterfacePointerType(), clang::Decl::getBeginLoc(), clang::Stmt::getBeginLoc(), clang::TypeDecl::getBeginLoc(), clang::LookupResult::getFoundDecl(), clang::Type::getPointeeType(), clang::Expr::getType(), clang::QualType::getTypePtr(), clang::TypedefNameDecl::getUnderlyingType(), clang::Type::isObjCIdType(), clang::ObjCInterfaceDecl::isSuperClassOf(), clang::Sema::LookupName(), clang::Sema::LookupOrdinaryName, clang::ASTContext::QIdProtocolsAdoptObjCObjectProtocols(), clang::Target, and clang::Sema::TUScope.

## ◆ CheckObjCBridgeNSCast()

template<typename TB >

static bool CheckObjCBridgeNSCast | ( | Sema & | S,
|  | QualType | castType,
|  | Expr * | castExpr,
|  | bool & | HadTheAttribute,
|  | bool | warn
| ) |  |
| static

Definition at line 3781 of file SemaExprObjC.cpp.

References clang::Sema::Context, clang::Sema::Diag(), clang::Type::getAsObjCInterfacePointerType(), clang::Decl::getBeginLoc(), clang::Stmt::getBeginLoc(), clang::TypeDecl::getBeginLoc(), clang::LookupResult::getFoundDecl(), clang::NamedDecl::getName(), clang::Type::getPointeeType(), clang::Expr::getType(), clang::QualType::getTypePtr(), clang::TypedefNameDecl::getUnderlyingType(), clang::Type::isObjCIdType(), clang::ObjCInterfaceDecl::isSuperClassOf(), clang::Sema::LookupName(), clang::Sema::LookupOrdinaryName, clang::ASTContext::ObjCObjectAdoptsQTypeProtocols(), clang::Target, and clang::Sema::TUScope.

## ◆ 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 384 of file SemaExprObjC.cpp.

References clang::Sema::BuildObjCNumericLiteral(), clang::Sema::BuildObjCStringLiteral(), clang::Sema::CheckPlaceholderExpr(), clang::Sema::Context, clang::InitializationKind::CreateCopy(), clang::FixItHint::CreateInsertion(), clang::Sema::DefaultLvalueConversion(), clang::Sema::Diag(), clang::ExprError(), clang::ActionResult< PtrTy, CompressInvalid >::get(), clang::Stmt::getBeginLoc(), clang::Sema::getLangOpts(), clang::Stmt::getSourceRange(), clang::StringLiteral::getString(), clang::Expr::getType(), clang::InitializedEntity::InitializeParameter(), clang::Type::isBlockPointerType(), clang::ActionResult< PtrTy, CompressInvalid >::isInvalid(), clang::Type::isObjCObjectPointerType(), clang::Type::isRecordType(), clang::Expr::isTypeDependent(), clang::Sema::NSAPIObj, and clang::Sema::PerformCopyInitialization().

## ◆ classifyTypeForARCConversion()

static ARCConversionTypeClass classifyTypeForARCConversion | ( | QualType | type | ) |
| static

Definition at line 3249 of file SemaExprObjC.cpp.

References ACTC_coreFoundation, ACTC_indirectRetainable, ACTC_none, ACTC_retainable, ACTC_voidPtr, clang::Type::getAs(), clang::Type::getAsArrayTypeUnsafe(), clang::Type::getPointeeType(), clang::Type::isObjCARCBridgableType(), clang::Type::isRecordType(), and clang::Type::isVoidType().

Referenced by clang::Sema::CheckObjCBridgeRelatedCast(), clang::Sema::CheckObjCBridgeRelatedConversions(), clang::Sema::CheckObjCConversion(), clang::Sema::CheckTollFreeBridgeCast(), clang::Sema::CheckTollFreeBridgeStaticCast(), and clang::Sema::diagnoseARCUnbridgedCast().

## ◆ ClassKindFromLiteralKind()

static NSAPI::NSClassIdKindKind ClassKindFromLiteralKind | ( | Sema::ObjCLiteralKind | LiteralKind | ) |
| static

Maps ObjCLiteralKind to NSClassIdKindKind.

Definition at line 169 of file SemaExprObjC.cpp.

References clang::NSAPI::ClassId_NSArray, clang::NSAPI::ClassId_NSDictionary, clang::NSAPI::ClassId_NSNumber, clang::NSAPI::ClassId_NSString, clang::NSAPI::ClassId_NSValue, clang::Sema::LK_Array, clang::Sema::LK_Block, clang::Sema::LK_Boxed, clang::Sema::LK_Dictionary, clang::Sema::LK_None, clang::Sema::LK_Numeric, and clang::Sema::LK_String.

## ◆ 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 2361 of file SemaExprObjC.cpp.

References clang::Sema::Diag(), clang::Sema::FormatStringHasSArg(), clang::NamedDecl::getDeclName(), clang::Expr::getExprLoc(), clang::Sema::GetFormatNSStringIdx(), clang::Decl::getLocation(), clang::StringLiteral::getString(), clang::Selector::getStringFormatFamily(), clang::Expr::IgnoreParenImpCasts(), clang::SFF_NSString, and clang::Decl::specific_attrs().

## ◆ DiagnoseMismatchedSelectors()

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

Definition at line 1133 of file SemaExprObjC.cpp.

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

## ◆ diagnoseObjCARCConversion()

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

Definition at line 3649 of file SemaExprObjC.cpp.

References ACTC_coreFoundation, ACTC_indirectRetainable, ACTC_none, ACTC_retainable, ACTC_voidPtr, addFixitForObjCARCConversion(), clang::Sema::CCK_OtherCast, clang::Sema::Context, clang::Sema::Diag(), clang::SourceRange::getBegin(), clang::Expr::getExprLoc(), clang::Sema::getLocForEndOfToken(), clang::Stmt::getSourceRange(), clang::Expr::getType(), isAnyRetainable(), clang::Type::isBlockPointerType(), clang::Sema::isCast(), clang::Sema::isKnownName(), clang::Type::isPointerType(), clang::SourceLocation::isValid(), clang::SourceRange::isValid(), clang::Sema::makeUnavailableInSystemHeader(), and ObjCBridgeRelatedAttrFromType().

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

## ◆ findExplicitInstancetypeDeclarer()

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

Look for an ObjC method whose result type exactly matches the given type.

Definition at line 1446 of file SemaExprObjC.cpp.

References clang::Decl::getDeclContext(), clang::ObjCContainerDecl::getMethod(), clang::ObjCMethodDecl::getOverriddenMethods(), clang::ObjCMethodDecl::getReturnType(), clang::ObjCMethodDecl::getSelector(), and clang::ObjCMethodDecl::isInstanceMethod().

## ◆ 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 1284 of file SemaExprObjC.cpp.

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

## ◆ getNSNumberFactoryMethod()

static ObjCMethodDecl* getNSNumberFactoryMethod | ( | Sema & | 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 241 of file SemaExprObjC.cpp.

## ◆ getObjCBridgeAttr()

template<typename T >

static T* getObjCBridgeAttr | ( | const TypedefType * | TD | ) |
| inline static

Definition at line 3624 of file SemaExprObjC.cpp.

References clang::Type::getAs(), clang::TypedefType::getDecl(), clang::RecordDecl::getMostRecentDecl(), clang::Type::getPointeeType(), clang::TypedefNameDecl::getUnderlyingType(), and clang::Type::isPointerType().

## ◆ HelperToDiagnoseMismatchedMethodsInGlobalPool()

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

Definition at line 1102 of file SemaExprObjC.cpp.

## ◆ isAnyCLike()

static bool isAnyCLike | ( | ARCConversionTypeClass | ACTC | ) |
| static

Definition at line 3243 of file SemaExprObjC.cpp.

References ACTC_coreFoundation, ACTC_none, and ACTC_voidPtr.

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

## ◆ isAnyRetainable()

static bool isAnyRetainable | ( | ARCConversionTypeClass | ACTC | ) |
| static

Definition at line 3237 of file SemaExprObjC.cpp.

References ACTC_coreFoundation, ACTC_retainable, and ACTC_voidPtr.

Referenced by diagnoseObjCARCConversion().

## ◆ isMethodDeclaredInRootProtocol()

static bool isMethodDeclaredInRootProtocol | ( | Sema & | S,
|  | const ObjCMethodDecl * | M
| ) |  |
| static

Definition at line 2602 of file SemaExprObjC.cpp.

References clang::NSAPI::ClassId_NSObject, clang::Decl::getDeclContext(), clang::Sema::LookupOrdinaryName, clang::Sema::LookupSingleName(), clang::Sema::NSAPIObj, P, and clang::Sema::TUScope.

## ◆ LookupObjCInterfaceDeclForLiteral()

static ObjCInterfaceDecl* LookupObjCInterfaceDeclForLiteral | ( | Sema & | S,
|  | SourceLocation | Loc,
|  | Sema::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 217 of file SemaExprObjC.cpp.

Referenced by clang::Sema::BuildObjCArrayLiteral(), and clang::Sema::BuildObjCDictionaryLiteral().

## ◆ maybeUndoReclaimObject()

static Expr* maybeUndoReclaimObject | ( | Expr * | e | ) |
| static

Look for an ObjCReclaimReturnedObject cast and destroy it.

Definition at line 4377 of file SemaExprObjC.cpp.

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

## ◆ ObjCBridgeRelatedAttrFromType()

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

Definition at line 3636 of file SemaExprObjC.cpp.

References clang::QualType::getTypePtr(), and clang::TypedefNameDecl::getUnderlyingType().

Referenced by clang::Sema::checkObjCBridgeRelatedComponents(), and diagnoseObjCARCConversion().

## ◆ RemoveSelectorFromWarningCache()

static void RemoveSelectorFromWarningCache | ( | Sema & | S,
|  | Expr * | Arg
| ) |  |
| static

Definition at line 3176 of file SemaExprObjC.cpp.

References clang::Expr::IgnoreParenCasts(), and clang::Sema::ReferencedSelectors.

## ◆ stripObjCInstanceType()

static QualType stripObjCInstanceType | ( | ASTContext & | Context,
|  | QualType | T
| ) |  |
| static

Definition at line 1260 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 146 of file SemaExprObjC.cpp.

## ◆ ValidateObjCLiteralInterfaceDecl()

static bool ValidateObjCLiteralInterfaceDecl | ( | Sema & | S,
|  | ObjCInterfaceDecl * | Decl,
|  | SourceLocation | Loc,
|  | Sema::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 195 of file SemaExprObjC.cpp.