clang API Documentation
#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"
Go to the source code of this file.
Enumerations | |
enum | ARCConversionTypeClass { ACTC_none, ACTC_retainable, ACTC_indirectRetainable, ACTC_voidPtr, ACTC_coreFoundation } |
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. | |
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. | |
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 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 const ObjCMethodDecl * | findExplicitInstancetypeDeclarer (const ObjCMethodDecl *MD, QualType instancetype) |
Look for an ObjC method whose result type exactly matches the given type. | |
static void | DiagnoseARCUseOfWeakReceiver (Sema &S, Expr *Receiver) |
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 | 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 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. |
enum ACCResult |
A result from the cast checker.
Definition at line 2915 of file SemaExprObjC.cpp.
Definition at line 2847 of file SemaExprObjC.cpp.
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 3146 of file SemaExprObjC.cpp.
References clang::DiagnosticBuilder::AddFixItHint(), clang::ast_matchers::castExpr, clang::Sema::CCK_CStyleCast, 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::Preprocessor::getLocForEndOfToken(), clang::SourceLocation::getLocWithOffset(), clang::Sema::getSourceManager(), clang::Stmt::getSourceRange(), clang::Expr::IgnoreImpCasts(), clang::Lexer::isIdentifierBodyChar(), clang::Sema::PP, and SM.
Referenced by diagnoseObjCARCConversion().
static void applyCocoaAPICheck | ( | Sema & | S, |
const ObjCMessageExpr * | Msg, | ||
unsigned | DiagID, | ||
bool(*)(const ObjCMessageExpr *, const NSAPI &, edit::Commit &) | refactor | ||
) | [static] |
Definition at line 2022 of file SemaExprObjC.cpp.
References clang::edit::Commit::Act_Insert, clang::edit::Commit::Act_InsertFromRange, clang::edit::Commit::Act_Remove, clang::DiagnosticBuilder::AddFixItHint(), clang::edit::Commit::Edit::BeforePrev, Builder, clang::FixItHint::CreateInsertion(), clang::FixItHint::CreateInsertionFromRange(), clang::FixItHint::CreateRemoval(), clang::Sema::Diag(), clang::Sema::Diags, 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::Sema::NSAPIObj, clang::edit::Commit::Edit::OrigLoc, SM, clang::Sema::SourceMgr, and clang::edit::Commit::Edit::Text.
Referenced by checkCocoaAPI().
static void checkCocoaAPI | ( | Sema & | S, |
const ObjCMessageExpr * | Msg | ||
) | [static] |
Definition at line 2061 of file SemaExprObjC.cpp.
References applyCocoaAPICheck(), and clang::edit::rewriteObjCRedundantCallWithLiteral().
Referenced by clang::Sema::BuildClassMessage(), and clang::Sema::BuildInstanceMessage().
static bool CheckObjCBridgeCFCast | ( | Sema & | S, |
QualType | castType, | ||
Expr * | castExpr, | ||
bool & | HadTheAttribute, | ||
bool | warn | ||
) | [static] |
Definition at line 3459 of file SemaExprObjC.cpp.
References clang::Sema::Context, clang::Sema::Diag(), clang::Type::getAsObjCInterfacePointerType(), clang::LookupResult::getFoundDecl(), clang::Decl::getLocStart(), clang::Stmt::getLocStart(), clang::TypeDecl::getLocStart(), 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(), and clang::Sema::TUScope.
static bool CheckObjCBridgeNSCast | ( | Sema & | S, |
QualType | castType, | ||
Expr * | castExpr, | ||
bool & | HadTheAttribute, | ||
bool | warn | ||
) | [static] |
Definition at line 3398 of file SemaExprObjC.cpp.
References clang::Sema::Context, clang::Sema::Diag(), clang::Type::getAsObjCInterfacePointerType(), clang::LookupResult::getFoundDecl(), clang::Decl::getLocStart(), clang::Stmt::getLocStart(), clang::TypeDecl::getLocStart(), 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(), and clang::Sema::TUScope.
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 329 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::Sema::getLangOpts(), clang::Stmt::getLocStart(), 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().
Referenced by clang::Sema::BuildObjCArrayLiteral(), and clang::Sema::BuildObjCDictionaryLiteral().
static ARCConversionTypeClass classifyTypeForARCConversion | ( | QualType | type | ) | [static] |
Definition at line 2874 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::CheckObjCARCConversion(), clang::Sema::CheckObjCBridgeRelatedCast(), clang::Sema::CheckObjCBridgeRelatedConversions(), clang::Sema::CheckTollFreeBridgeCast(), clang::Sema::CheckTollFreeBridgeStaticCast(), and clang::Sema::diagnoseARCUnbridgedCast().
static void DiagnoseARCUseOfWeakReceiver | ( | Sema & | S, |
Expr * | Receiver | ||
) | [static] |
Definition at line 1510 of file SemaExprObjC.cpp.
References clang::Sema::Diag(), clang::ObjCMethodDecl::findPropertyDecl(), clang::Decl::getLocation(), clang::Stmt::getLocStart(), clang::Selector::getNumArgs(), clang::QualType::getObjCLifetime(), clang::ObjCPropertyDecl::getPropertyAttributes(), clang::ObjCMethodDecl::getReturnType(), clang::ObjCMethodDecl::getSelector(), clang::Expr::getType(), clang::ObjCPropertyDecl::getType(), clang::Expr::IgnoreParenImpCasts(), clang::ObjCPropertyDecl::OBJC_PR_weak, and clang::Qualifiers::OCL_Weak.
Referenced by clang::Sema::BuildInstanceMessage().
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 2069 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().
Referenced by clang::Sema::BuildClassMessage(), and clang::Sema::BuildInstanceMessage().
static void DiagnoseMismatchedSelectors | ( | Sema & | S, |
SourceLocation | AtLoc, | ||
ObjCMethodDecl * | Method, | ||
SourceLocation | LParenLoc, | ||
SourceLocation | RParenLoc, | ||
bool | WarnMultipleSelectors | ||
) | [static] |
Definition at line 1012 of file SemaExprObjC.cpp.
References clang::Sema::Diags, HelperToDiagnoseMismatchedMethodsInGlobalPool(), clang::DiagnosticsEngine::isIgnored(), and clang::Sema::MethodPool.
Referenced by clang::Sema::ParseObjCSelectorExpression().
static void diagnoseObjCARCConversion | ( | Sema & | S, |
SourceRange | castRange, | ||
QualType | castType, | ||
ARCConversionTypeClass | castACTC, | ||
Expr * | castExpr, | ||
Expr * | realCast, | ||
ARCConversionTypeClass | exprACTC, | ||
Sema::CheckedConversionKind | CCK | ||
) | [static] |
Definition at line 3270 of file SemaExprObjC.cpp.
References ACTC_coreFoundation, ACTC_indirectRetainable, ACTC_none, ACTC_retainable, ACTC_voidPtr, addFixitForObjCARCConversion(), clang::Sema::CCK_ImplicitConversion, clang::Sema::CCK_OtherCast, clang::Sema::Context, clang::Sema::Diag(), clang::SourceRange::getBegin(), clang::Expr::getExprLoc(), clang::Preprocessor::getLocForEndOfToken(), clang::Stmt::getSourceRange(), clang::Expr::getType(), isAnyRetainable(), clang::Type::isBlockPointerType(), clang::Sema::isKnownName(), clang::Type::isPointerType(), clang::SourceLocation::isValid(), clang::SourceRange::isValid(), clang::Sema::makeUnavailableInSystemHeader(), ObjCBridgeRelatedAttrFromType(), and clang::Sema::PP.
Referenced by clang::Sema::CheckObjCARCConversion(), and clang::Sema::diagnoseARCUnbridgedCast().
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 1187 of file SemaExprObjC.cpp.
References clang::Decl::getDeclContext(), clang::ObjCContainerDecl::getMethod(), clang::ObjCMethodDecl::getOverriddenMethods(), clang::ObjCMethodDecl::getReturnType(), clang::ObjCMethodDecl::getSelector(), and clang::ObjCMethodDecl::isInstanceMethod().
Referenced by clang::Sema::EmitRelatedResultTypeNoteForReturn().
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 173 of file SemaExprObjC.cpp.
References clang::NSAPI::ClassId_NSNumber, clang::Sema::Context, clang::ObjCMethodDecl::Create(), clang::ObjCInterfaceDecl::Create(), clang::ParmVarDecl::Create(), clang::Sema::Diag(), clang::IdentifierTable::get(), clang::Sema::getLangOpts(), clang::ASTContext::getObjCInterfaceType(), clang::ASTContext::getObjCObjectPointerType(), clang::ASTContext::getTranslationUnitDecl(), clang::ObjCInterfaceDecl::hasDefinition(), clang::ASTContext::Idents, clang::tok::isLiteral(), clang::ObjCInterfaceDecl::lookupClassMethod(), clang::Sema::LookupOrdinaryName, clang::Sema::LookupSingleName(), clang::Sema::NSAPIObj, clang::Sema::NSNumberDecl, clang::Sema::NSNumberLiteralMethods, clang::Sema::NSNumberPointer, clang::ObjCMethodDecl::Required, clang::SC_None, clang::ObjCMethodDecl::setMethodParams(), clang::Sema::TUScope, and validateBoxingMethod().
Referenced by clang::Sema::BuildObjCBoxedExpr(), and clang::Sema::BuildObjCNumericLiteral().
static T* getObjCBridgeAttr | ( | const TypedefType * | TD | ) | [inline, static] |
Definition at line 3245 of file SemaExprObjC.cpp.
References clang::Type::getAs(), clang::TypedefType::getDecl(), clang::RecordDecl::getMostRecentDecl(), clang::Type::getPointeeType(), clang::TypedefNameDecl::getUnderlyingType(), and clang::Type::isPointerType().
static bool HelperToDiagnoseMismatchedMethodsInGlobalPool | ( | Sema & | S, |
SourceLocation | AtLoc, | ||
SourceLocation | LParenLoc, | ||
SourceLocation | RParenLoc, | ||
ObjCMethodDecl * | Method, | ||
ObjCMethodList & | MethList | ||
) | [static] |
Definition at line 981 of file SemaExprObjC.cpp.
References clang::FixItHint::CreateInsertion(), clang::Sema::Diag(), clang::Decl::getDeclContext(), clang::NamedDecl::getDeclName(), clang::Decl::getLocation(), clang::ObjCMethodList::getNext(), clang::ObjCMethodDecl::getSelector(), clang::Sema::MatchTwoMethodDeclarations(), clang::ObjCMethodList::Method, and clang::Sema::MMS_loose.
Referenced by DiagnoseMismatchedSelectors().
static bool isAnyCLike | ( | ARCConversionTypeClass | ACTC | ) | [static] |
Definition at line 2868 of file SemaExprObjC.cpp.
References ACTC_coreFoundation, ACTC_none, and ACTC_voidPtr.
Referenced by clang::Sema::CheckObjCARCConversion().
static bool isAnyRetainable | ( | ARCConversionTypeClass | ACTC | ) | [static] |
Definition at line 2863 of file SemaExprObjC.cpp.
References ACTC_coreFoundation, ACTC_retainable, and ACTC_voidPtr.
Referenced by clang::Sema::CheckObjCARCConversion(), and diagnoseObjCARCConversion().
static Expr* maybeUndoReclaimObject | ( | Expr * | e | ) | [static] |
Look for an ObjCReclaimReturnedObject cast and destroy it.
Definition at line 3961 of file SemaExprObjC.cpp.
References clang::CK_ARCReclaimReturnedObject.
Referenced by clang::Sema::BuildObjCBridgedCast().
static ObjCBridgeRelatedAttr* ObjCBridgeRelatedAttrFromType | ( | QualType | T, |
TypedefNameDecl *& | TDNDecl | ||
) | [static] |
Definition at line 3257 of file SemaExprObjC.cpp.
References clang::QualType::getTypePtr(), and clang::TypedefNameDecl::getUnderlyingType().
Referenced by clang::Sema::checkObjCBridgeRelatedComponents(), and diagnoseObjCARCConversion().
static void RemoveSelectorFromWarningCache | ( | Sema & | S, |
Expr * | Arg | ||
) | [static] |
Definition at line 2802 of file SemaExprObjC.cpp.
References clang::Expr::IgnoreParenCasts(), and clang::Sema::ReferencedSelectors.
Referenced by clang::Sema::ActOnInstanceMessage().
static QualType stripObjCInstanceType | ( | ASTContext & | Context, |
QualType | T | ||
) | [static] |
Definition at line 1139 of file SemaExprObjC.cpp.
References clang::ASTContext::getObjCIdType(), and clang::ASTContext::getObjCInstanceType().
Referenced by clang::Sema::getMessageSendResultType().
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 149 of file SemaExprObjC.cpp.
References clang::Sema::Diag(), clang::Decl::getLocation(), clang::NamedDecl::getName(), clang::ObjCMethodDecl::getReturnType(), and clang::Type::isObjCObjectPointerType().
Referenced by clang::Sema::BuildObjCArrayLiteral(), clang::Sema::BuildObjCBoxedExpr(), clang::Sema::BuildObjCDictionaryLiteral(), and getNSNumberFactoryMethod().