clang 20.0.0git
|
#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/SemaObjC.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. | |
static NSAPI::NSClassIdKindKind | ClassKindFromLiteralKind (SemaObjC::ObjCLiteralKind LiteralKind) |
Maps ObjCLiteralKind to NSClassIdKindKind. | |
static bool | ValidateObjCLiteralInterfaceDecl (Sema &S, ObjCInterfaceDecl *Decl, SourceLocation Loc, SemaObjC::ObjCLiteralKind LiteralKind) |
Validates ObjCInterfaceDecl availability. | |
enum | ARCConversionTypeClass { ACTC_none , ACTC_retainable , ACTC_indirectRetainable , ACTC_voidPtr , ACTC_coreFoundation } |
static ObjCInterfaceDecl * | LookupObjCInterfaceDeclForLiteral (Sema &S, SourceLocation Loc, SemaObjC::ObjCLiteralKind LiteralKind) |
Looks up ObjCInterfaceDecl of a given NSClassIdKindKind. | |
static ObjCMethodDecl * | getNSNumberFactoryMethod (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. | |
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. | |
static void | CheckObjCDictionaryLiteralDuplicateKeys (Sema &S, ObjCDictionaryLiteral *Literal) |
Check for duplicate keys in an ObjC dictionary literal. | |
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 ObjCMethodDecl * | LookupDirectMethodInMethodList (Sema &S, Selector Sel, ObjCMethodList &MethList, bool &onlyDirect, bool &anyDirect) |
static ObjCMethodDecl * | LookupDirectMethodInGlobalPool (Sema &S, Selector Sel, bool &onlyDirect, bool &anyDirect) |
static ObjCMethodDecl * | findMethodInCurrentClass (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. | |
static const ObjCMethodDecl * | findExplicitInstancetypeDeclarer (const ObjCMethodDecl *MD, QualType instancetype) |
Look for an ObjC method whose result type exactly matches the given type. | |
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. | |
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 Expr * | maybeUndoReclaimObject (Expr *e) |
Look for an ObjCReclaimReturnedObject cast and destroy it. | |
Definition at line 3442 of file SemaExprObjC.cpp.
|
static |
Definition at line 3748 of file SemaExprObjC.cpp.
References clang::ast_matchers::castExpr, clang::FixItHint::CreateInsertion(), clang::FixItHint::CreateReplacement(), clang::CStyleCast, clang::ForBuiltinOverloadedOp, clang::FunctionalCast, clang::QualType::getAsString(), clang::Sema::getLangOpts(), clang::Sema::getLocForEndOfToken(), clang::Sema::getSourceManager(), clang::Stmt::getSourceRange(), clang::Expr::IgnoreImpCasts(), clang::Implicit, clang::Lexer::isAsciiIdentifierContinueChar(), clang::OtherCast, Range, and SM.
Referenced by diagnoseObjCARCConversion().
|
static |
Definition at line 2449 of file SemaExprObjC.cpp.
References clang::edit::Commit::Act_Insert, clang::edit::Commit::Act_InsertFromRange, clang::edit::Commit::Act_Remove, clang::edit::Commit::Edit::BeforePrev, clang::FixItHint::CreateInsertion(), clang::FixItHint::CreateInsertionFromRange(), clang::FixItHint::CreateRemoval(), clang::SemaBase::Diag(), clang::Sema::Diags, E, clang::edit::Commit::edit_begin(), clang::edit::Commit::edit_end(), clang::Expr::getExprLoc(), clang::edit::Commit::Edit::getFileRange(), clang::edit::Commit::Edit::getInsertFromRange(), clang::ObjCMessageExpr::getSelector(), clang::Stmt::getSourceRange(), clang::edit::Commit::isCommitable(), clang::DiagnosticsEngine::isIgnored(), clang::edit::Commit::Edit::Kind, clang::Sema::LangOpts, clang::SemaObjC::NSAPIObj, clang::Sema::ObjC(), clang::edit::Commit::Edit::OrigLoc, SM, clang::Sema::SourceMgr, and clang::edit::Commit::Edit::Text.
Referenced by checkCocoaAPI().
|
static |
Definition at line 2488 of file SemaExprObjC.cpp.
References applyCocoaAPICheck(), and clang::edit::rewriteObjCRedundantCallWithLiteral().
Referenced by clang::SemaObjC::BuildClassMessage(), and clang::SemaObjC::BuildInstanceMessage().
|
static |
Definition at line 2493 of file SemaExprObjC.cpp.
References clang::SemaBase::Diag(), clang::Type::getAs(), clang::ObjCMethodDecl::getBeginLoc(), clang::Selector::getMethodFamily(), clang::ObjCMethodDecl::getReturnType(), clang::ObjCMethodDecl::getSelector(), Loc, and clang::OMF_performSelector.
Referenced by clang::SemaObjC::BuildClassMessage(), and clang::SemaObjC::BuildInstanceMessage().
|
static |
Definition at line 4066 of file SemaExprObjC.cpp.
References clang::ast_matchers::castExpr, clang::Sema::Context, clang::SemaBase::Diag(), clang::Type::getAs(), clang::TypeDecl::getBeginLoc(), clang::LookupResult::getFoundDecl(), clang::TypedefNameDecl::getUnderlyingType(), clang::ObjCInterfaceDecl::isSuperClassOf(), clang::Sema::LookupName(), clang::Sema::LookupOrdinaryName, clang::ASTContext::QIdProtocolsAdoptObjCObjectProtocols(), clang::T, and clang::Sema::TUScope.
|
static |
Definition at line 4003 of file SemaExprObjC.cpp.
References clang::ast_matchers::castExpr, clang::Sema::Context, clang::SemaBase::Diag(), clang::Type::getAs(), clang::Type::getAsObjCInterfacePointerType(), clang::TypeDecl::getBeginLoc(), clang::LookupResult::getFoundDecl(), clang::Type::getPointeeType(), clang::TypedefNameDecl::getUnderlyingType(), clang::Type::isObjCIdType(), clang::ObjCInterfaceDecl::isSuperClassOf(), clang::Sema::LookupName(), clang::Sema::LookupOrdinaryName, clang::ASTContext::ObjCObjectAdoptsQTypeProtocols(), clang::T, and clang::Sema::TUScope.
|
static |
Check that the given expression is a valid element of an Objective-C collection literal.
Definition at line 392 of file SemaExprObjC.cpp.
References clang::SemaObjC::BuildObjCNumericLiteral(), clang::SemaObjC::BuildObjCStringLiteral(), clang::Sema::CheckPlaceholderExpr(), clang::Sema::Context, clang::InitializationKind::CreateCopy(), clang::FixItHint::CreateInsertion(), clang::Sema::DefaultLvalueConversion(), clang::SemaBase::Diag(), clang::ExprError(), clang::Stmt::getBeginLoc(), clang::Sema::getLangOpts(), clang::Stmt::getSourceRange(), clang::StringLiteral::getString(), clang::Expr::getType(), clang::InitializedEntity::InitializeParameter(), clang::SemaObjC::NSAPIObj, clang::Sema::ObjC(), clang::Sema::PerformCopyInitialization(), clang::Result, clang::Seq, and clang::T.
Referenced by clang::SemaObjC::BuildObjCArrayLiteral().
|
static |
Check for duplicate keys in an ObjC dictionary literal.
For instance: NSDictionary *nd = "foo" : @"bar", @"foo" : @"baz" };
Definition at line 903 of file SemaExprObjC.cpp.
References clang::SemaBase::Diag(), clang::Expr::EvaluateAsInt(), clang::Sema::getASTContext(), clang::Expr::IgnoreParenImpCasts(), Loc, clang::Result, and clang::Expr::SE_AllowSideEffects.
|
static |
Definition at line 3471 of file SemaExprObjC.cpp.
References ACTC_coreFoundation, ACTC_indirectRetainable, ACTC_none, ACTC_retainable, ACTC_voidPtr, and clang::ast_matchers::type.
Referenced by clang::SemaObjC::CheckObjCBridgeRelatedCast(), clang::SemaObjC::CheckObjCBridgeRelatedConversions(), clang::SemaObjC::CheckObjCConversion(), clang::SemaObjC::CheckTollFreeBridgeCast(), clang::SemaObjC::CheckTollFreeBridgeStaticCast(), and clang::SemaObjC::diagnoseARCUnbridgedCast().
|
static |
Maps ObjCLiteralKind to NSClassIdKindKind.
Definition at line 176 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::SemaObjC::LK_Array, clang::SemaObjC::LK_Block, clang::SemaObjC::LK_Boxed, clang::SemaObjC::LK_Dictionary, clang::SemaObjC::LK_None, clang::SemaObjC::LK_Numeric, and clang::SemaObjC::LK_String.
Referenced by LookupObjCInterfaceDeclForLiteral(), and ValidateObjCLiteralInterfaceDecl().
|
static |
Diagnose use of s directive in an NSString which is being passed as formatting string to formatting method.
Definition at line 2542 of file SemaExprObjC.cpp.
References clang::SemaBase::Diag(), clang::Sema::FormatStringHasSArg(), clang::NamedDecl::getDeclName(), clang::Expr::getExprLoc(), clang::SemaObjC::GetFormatNSStringIdx(), clang::Decl::getLocation(), clang::StringLiteral::getString(), clang::Selector::getStringFormatFamily(), clang::Expr::IgnoreParenImpCasts(), clang::Sema::ObjC(), clang::SFF_NSString, and clang::Decl::specific_attrs().
Referenced by clang::SemaObjC::BuildClassMessage(), and clang::SemaObjC::BuildInstanceMessage().
|
static |
Definition at line 1209 of file SemaExprObjC.cpp.
References b, clang::Sema::Diags, HelperToDiagnoseMismatchedMethodsInGlobalPool(), clang::DiagnosticsEngine::isIgnored(), clang::SemaObjC::MethodPool, and clang::Sema::ObjC().
Referenced by clang::SemaObjC::ParseObjCSelectorExpression().
|
static |
Definition at line 3870 of file SemaExprObjC.cpp.
References ACTC_coreFoundation, ACTC_indirectRetainable, ACTC_none, ACTC_retainable, ACTC_voidPtr, addFixitForObjCARCConversion(), clang::ast_matchers::castExpr, clang::Sema::Context, clang::SemaBase::Diag(), clang::SourceRange::getBegin(), clang::Sema::getLocForEndOfToken(), isAnyRetainable(), clang::Type::isBlockPointerType(), clang::Sema::isCast(), clang::SemaObjC::isKnownName(), clang::Type::isPointerType(), clang::SourceLocation::isValid(), clang::SourceRange::isValid(), clang::Sema::makeUnavailableInSystemHeader(), clang::Sema::ObjC(), ObjCBridgeRelatedAttrFromType(), and clang::OtherCast.
Referenced by clang::SemaObjC::CheckObjCConversion(), and clang::SemaObjC::diagnoseARCUnbridgedCast().
|
static |
Look for an ObjC method whose result type exactly matches the given type.
Definition at line 1623 of file SemaExprObjC.cpp.
References findExplicitInstancetypeDeclarer(), clang::Decl::getDeclContext(), clang::ObjCContainerDecl::getMethod(), clang::ObjCMethodDecl::getOverriddenMethods(), clang::ObjCMethodDecl::getReturnType(), clang::ObjCMethodDecl::getSelector(), and clang::ObjCMethodDecl::isInstanceMethod().
Referenced by clang::SemaObjC::EmitRelatedResultTypeNoteForReturn(), and findExplicitInstancetypeDeclarer().
|
static |
Definition at line 1276 of file SemaExprObjC.cpp.
References clang::Sema::getCurMethodDecl(), clang::ObjCInterfaceDecl::lookupMethod(), and clang::ObjCInterfaceDecl::lookupPrivateMethod().
Referenced by clang::SemaObjC::ParseObjCSelectorExpression().
|
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 1460 of file SemaExprObjC.cpp.
References clang::Class, clang::Sema::Context, clang::Type::getAsObjCInterfaceType(), clang::ASTContext::getAttributedType(), clang::Sema::getCurMethodDecl(), clang::Type::getNullability(), clang::ASTContext::getObjCInterfaceType(), clang::ASTContext::getObjCObjectPointerType(), clang::ObjCMethodDecl::getSendResultType(), clang::ObjCMethodDecl::hasRelatedResultType(), clang::ObjCMethodDecl::isInstanceMethod(), clang::Type::isObjCClassType(), clang::Type::isObjCQualifiedClassType(), stripObjCInstanceType(), clang::AttributedType::stripOuterNullability(), and clang::ast_matchers::type.
Referenced by clang::SemaObjC::getMessageSendResultType().
|
static |
Retrieve the NSNumber factory method that should be used to create an Objective-C literal for the given type.
Definition at line 248 of file SemaExprObjC.cpp.
References clang::Sema::Context, clang::ParmVarDecl::Create(), clang::ObjCMethodDecl::Create(), clang::SemaBase::Diag(), clang::IdentifierTable::get(), clang::Sema::getLangOpts(), clang::ASTContext::getObjCInterfaceType(), clang::ASTContext::getObjCObjectPointerType(), clang::ASTContext::Idents, clang::SemaObjC::LK_Numeric, Loc, LookupObjCInterfaceDeclForLiteral(), clang::Required, clang::SC_None, clang::SemaBase::SemaRef, clang::ObjCMethodDecl::setMethodParams(), and validateBoxingMethod().
Referenced by clang::SemaObjC::BuildObjCBoxedExpr(), and clang::SemaObjC::BuildObjCNumericLiteral().
|
inlinestatic |
Definition at line 3843 of file SemaExprObjC.cpp.
References clang::ast_matchers::attr, clang::Type::getAs(), clang::TypedefType::getDecl(), clang::Type::getPointeeType(), clang::TypedefNameDecl::getUnderlyingType(), clang::Type::isPointerType(), and clang::T.
|
static |
Definition at line 1178 of file SemaExprObjC.cpp.
References clang::FixItHint::CreateInsertion(), clang::SemaBase::Diag(), clang::Decl::getDeclContext(), clang::NamedDecl::getDeclName(), clang::Decl::getLocation(), clang::ObjCMethodList::getMethod(), clang::ObjCMethodList::getNext(), clang::ObjCMethodDecl::getSelector(), clang::SemaObjC::MatchTwoMethodDeclarations(), clang::SemaObjC::MMS_loose, and clang::Sema::ObjC().
Referenced by DiagnoseMismatchedSelectors().
|
static |
Definition at line 3465 of file SemaExprObjC.cpp.
References ACTC_coreFoundation, ACTC_none, and ACTC_voidPtr.
Referenced by clang::SemaObjC::CheckObjCConversion().
|
static |
Definition at line 3459 of file SemaExprObjC.cpp.
References ACTC_coreFoundation, ACTC_retainable, and ACTC_voidPtr.
Referenced by clang::SemaObjC::CheckObjCConversion(), and diagnoseObjCARCConversion().
|
static |
Definition at line 2784 of file SemaExprObjC.cpp.
References clang::NSAPI::ClassId_NSObject, clang::Decl::getDeclContext(), clang::Sema::LookupOrdinaryName, clang::Sema::LookupSingleName(), clang::SemaObjC::NSAPIObj, clang::Sema::ObjC(), P, and clang::Sema::TUScope.
Referenced by clang::SemaObjC::BuildInstanceMessage().
|
static |
Definition at line 1261 of file SemaExprObjC.cpp.
References Iter, LookupDirectMethodInMethodList(), clang::SemaObjC::MethodPool, and clang::Sema::ObjC().
Referenced by clang::SemaObjC::ParseObjCSelectorExpression().
|
static |
Definition at line 1235 of file SemaExprObjC.cpp.
References clang::ObjCMethodList::getMethod(), clang::ObjCMethodList::getNext(), clang::ObjCMethodDecl::getSelector(), and clang::ObjCMethodDecl::isDirectMethod().
Referenced by LookupDirectMethodInGlobalPool().
|
static |
Looks up ObjCInterfaceDecl of a given NSClassIdKindKind.
Used to create ObjC literals, such as NSDictionary (}), NSArray (@[]) and Boxed Expressions (@())
Definition at line 225 of file SemaExprObjC.cpp.
References ClassKindFromLiteralKind(), clang::Sema::Context, clang::ObjCInterfaceDecl::Create(), clang::Sema::getLangOpts(), clang::ASTContext::getTranslationUnitDecl(), Loc, clang::Sema::LookupOrdinaryName, clang::Sema::LookupSingleName(), clang::SemaObjC::NSAPIObj, clang::Sema::ObjC(), clang::Sema::TUScope, and ValidateObjCLiteralInterfaceDecl().
Referenced by clang::SemaObjC::BuildObjCArrayLiteral(), clang::SemaObjC::BuildObjCBoxedExpr(), clang::SemaObjC::BuildObjCDictionaryLiteral(), and getNSNumberFactoryMethod().
Look for an ObjCReclaimReturnedObject cast and destroy it.
Definition at line 4604 of file SemaExprObjC.cpp.
Referenced by clang::SemaObjC::BuildObjCBridgedCast().
|
static |
Definition at line 3858 of file SemaExprObjC.cpp.
References clang::Type::getAs(), clang::TypedefNameDecl::getUnderlyingType(), and clang::T.
Referenced by clang::SemaObjC::checkObjCBridgeRelatedComponents(), and diagnoseObjCARCConversion().
Definition at line 3398 of file SemaExprObjC.cpp.
References clang::Expr::IgnoreParenCasts(), and Loc.
Referenced by clang::SemaObjC::ActOnInstanceMessage().
|
static |
Definition at line 1438 of file SemaExprObjC.cpp.
References clang::ASTContext::getAttributedType(), clang::ASTContext::getObjCIdType(), clang::ASTContext::getObjCInstanceType(), clang::AttributedType::stripOuterNullability(), and clang::T.
Referenced by getBaseMessageSendResultType().
|
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 152 of file SemaExprObjC.cpp.
References clang::Class, clang::SemaBase::Diag(), clang::Decl::getLocation(), clang::ObjCMethodDecl::getReturnType(), clang::Type::isObjCObjectPointerType(), and Loc.
Referenced by clang::SemaObjC::BuildObjCArrayLiteral(), clang::SemaObjC::BuildObjCBoxedExpr(), clang::SemaObjC::BuildObjCDictionaryLiteral(), and getNSNumberFactoryMethod().
|
static |
Validates ObjCInterfaceDecl availability.
ObjCInterfaceDecl, used to create ObjC literals, should be defined if clang not in a debugger mode.
Definition at line 202 of file SemaExprObjC.cpp.
References ClassKindFromLiteralKind(), clang::SemaBase::Diag(), clang::Sema::getLangOpts(), clang::Decl::getLocation(), clang::IdentifierInfo::getName(), Loc, clang::SemaObjC::NSAPIObj, and clang::Sema::ObjC().
Referenced by LookupObjCInterfaceDeclForLiteral().