clang  6.0.0svn
Macros | Typedefs | Enumerations | Functions
SemaDeclObjC.cpp File Reference
#include "TypeLocBuilder.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTMutationListener.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprObjC.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Sema/DeclSpec.h"
#include "clang/Sema/Lookup.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/ScopeInfo.h"
#include "clang/Sema/SemaInternal.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "clang/AST/DeclNodes.inc"
Include dependency graph for SemaDeclObjC.cpp:

Go to the source code of this file.

Macros

#define OBJCCONTAINER(type, base)
 
#define ABSTRACT_DECL(expansion)
 
#define DECL(type, base)   case Decl::type:
 

Typedefs

typedef llvm::DenseSet< IdentifierInfo * > ProtocolNameSet
 FIXME: Type hierarchies in Objective-C can be deep. More...
 
typedef std::unique_ptr< ProtocolNameSetLazyProtocolNameSet
 

Enumerations

enum  TypeParamListContext
 The context in which an Objective-C type parameter list occurs, for use in diagnostics. More...
 

Functions

static void DiagnoseObjCImplementedDeprecations (Sema &S, const NamedDecl *ND, SourceLocation ImplLoc)
 
static bool HasExplicitOwnershipAttr (Sema &S, ParmVarDecl *Param)
 HasExplicitOwnershipAttr - returns true when pointer to ObjC pointer has explicit ownership attribute; false otherwise. More...
 
static void diagnoseUseOfProtocols (Sema &TheSema, ObjCContainerDecl *CD, ObjCProtocolDecl *const *ProtoRefs, unsigned NumProtoRefs, const SourceLocation *ProtoLocs)
 
static bool checkTypeParamListConsistency (Sema &S, ObjCTypeParamList *prevTypeParams, ObjCTypeParamList *newTypeParams, TypeParamListContext newContext)
 Check consistency between two Objective-C type parameter lists, e.g., between a category/extension and an @interface or between an @class and an @interface. More...
 
static bool NestedProtocolHasNoDefinition (ObjCProtocolDecl *PDecl, ObjCProtocolDecl *&UndefinedProtocol)
 
static void WarnUndefinedMethod (Sema &S, SourceLocation ImpLoc, ObjCMethodDecl *method, bool &IncompleteImpl, unsigned DiagID, NamedDecl *NeededFor=nullptr)
 
static bool isObjCTypeSubstitutable (ASTContext &Context, const ObjCObjectPointerType *A, const ObjCObjectPointerType *B, bool rejectId)
 Determines if type B can be substituted for type A. More...
 
static SourceRange getTypeRange (TypeSourceInfo *TSI)
 
static bool objcModifiersConflict (Decl::ObjCDeclQualifier x, Decl::ObjCDeclQualifier y)
 Determine whether two set of Objective-C declaration qualifiers conflict. More...
 
static bool CheckMethodOverrideReturn (Sema &S, ObjCMethodDecl *MethodImpl, ObjCMethodDecl *MethodDecl, bool IsProtocolMethodDecl, bool IsOverridingMode, bool Warn)
 
static bool CheckMethodOverrideParam (Sema &S, ObjCMethodDecl *MethodImpl, ObjCMethodDecl *MethodDecl, ParmVarDecl *ImplVar, ParmVarDecl *IfaceVar, bool IsProtocolMethodDecl, bool IsOverridingMode, bool Warn)
 
static bool checkMethodFamilyMismatch (Sema &S, ObjCMethodDecl *impl, ObjCMethodDecl *decl)
 In ARC, check whether the conventional meanings of the two methods match. More...
 
static void findProtocolsWithExplicitImpls (const ObjCProtocolDecl *PDecl, ProtocolNameSet &PNS)
 
static void findProtocolsWithExplicitImpls (const ObjCInterfaceDecl *Super, ProtocolNameSet &PNS)
 Recursively populates a set with all conformed protocols in a class hierarchy that have the 'objc_protocol_requires_explicit_implementation' attribute. More...
 
static void CheckProtocolMethodDefs (Sema &S, SourceLocation ImpLoc, ObjCProtocolDecl *PDecl, bool &IncompleteImpl, const Sema::SelectorSet &InsMap, const Sema::SelectorSet &ClsMap, ObjCContainerDecl *CDecl, LazyProtocolNameSet &ProtocolsExplictImpl)
 CheckProtocolMethodDefs - This routine checks unimplemented methods Declared in protocol, and those referenced by it. More...
 
static bool tryMatchRecordTypes (ASTContext &Context, Sema::MethodMatchStrategy strategy, const Type *left, const Type *right)
 
static bool matchTypes (ASTContext &Context, Sema::MethodMatchStrategy strategy, QualType leftQT, QualType rightQT)
 
static bool isMethodContextSameForKindofLookup (ObjCMethodDecl *Method, ObjCMethodDecl *MethodInList)
 
static bool isAcceptableMethodMismatch (ObjCMethodDecl *chosen, ObjCMethodDecl *other)
 Determines if this is an "acceptable" loose mismatch in the global method pool. More...
 
static bool FilterMethodsByTypeBound (ObjCMethodDecl *Method, const ObjCObjectType *TypeBound)
 Return true if the given method is wthin the type bound. More...
 
static void HelperSelectorsForTypoCorrection (SmallVectorImpl< const ObjCMethodDecl *> &BestMethod, StringRef Typo, const ObjCMethodDecl *Method)
 
static bool HelperIsMethodInObjCType (Sema &S, Selector Sel, QualType ObjectType)
 
static void DiagnoseWeakIvars (Sema &S, ObjCImplementationDecl *ID)
 Diagnose attempts to define ARC-__weak ivars when __weak is disabled. More...
 
static void DiagnoseRetainableFlexibleArrayMember (Sema &S, ObjCInterfaceDecl *ID)
 Diagnose attempts to use flexible array member with retainable object type. More...
 
static bool IsVariableSizedType (QualType T)
 
static void DiagnoseVariableSizedIvars (Sema &S, ObjCContainerDecl *OCD)
 
static Decl::ObjCDeclQualifier CvtQTToAstBitMask (ObjCDeclSpec::ObjCDeclQualifier PQTVal)
 CvtQTToAstBitMask - utility routine to produce an AST bitmask for objective-c's type qualifier from the parser version of the same info. More...
 
static Sema::ResultTypeCompatibilityKind CheckRelatedResultTypeCompatibility (Sema &S, ObjCMethodDecl *Method, ObjCInterfaceDecl *CurrentClass)
 Check whether the declared result type of the given Objective-C method declaration is compatible with the method's class. More...
 
static QualType mergeTypeNullabilityForRedecl (Sema &S, SourceLocation loc, QualType type, bool usesCSKeyword, SourceLocation prevLoc, QualType prevType, bool prevUsesCSKeyword)
 Merge type nullability from for a redeclaration of the same entity, producing the updated type of the redeclared entity. More...
 
static void mergeInterfaceMethodToImpl (Sema &S, ObjCMethodDecl *method, ObjCMethodDecl *prevMethod)
 Merge information from the declaration of a method in the @interface (or a category/extension) into the corresponding method in the (for a class or category). More...
 
static void checkObjCMethodX86VectorTypes (Sema &SemaRef, const ObjCMethodDecl *Method)
 Verify that the method parameters/return value have types that are supported by the x86 target. More...
 

Macro Definition Documentation

◆ ABSTRACT_DECL

#define ABSTRACT_DECL (   expansion)

◆ DECL

#define DECL (   type,
  base 
)    case Decl::type:

◆ OBJCCONTAINER

#define OBJCCONTAINER (   type,
  base 
)
Value:
case Decl::type: \
searchFrom(cast<type##Decl>(container)); \
break;
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.

Typedef Documentation

◆ LazyProtocolNameSet

typedef std::unique_ptr<ProtocolNameSet> LazyProtocolNameSet

Definition at line 2610 of file SemaDeclObjC.cpp.

◆ ProtocolNameSet

FIXME: Type hierarchies in Objective-C can be deep.

We could most likely improve the efficiency of selector lookups and type checking by associating with each protocol / interface / category the flattened instance tables. If we used an immutable set to keep the table then it wouldn't add significant memory cost and it would be handy for lookups.

Definition at line 2609 of file SemaDeclObjC.cpp.

Enumeration Type Documentation

◆ TypeParamListContext

enum TypeParamListContext
strong

The context in which an Objective-C type parameter list occurs, for use in diagnostics.

Definition at line 774 of file SemaDeclObjC.cpp.

Function Documentation

◆ checkMethodFamilyMismatch()

static bool checkMethodFamilyMismatch ( Sema S,
ObjCMethodDecl impl,
ObjCMethodDecl decl 
)
static

In ARC, check whether the conventional meanings of the two methods match.

If they don't, it's a hard error.

Definition at line 2441 of file SemaDeclObjC.cpp.

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

◆ CheckMethodOverrideParam()

static bool CheckMethodOverrideParam ( Sema S,
ObjCMethodDecl MethodImpl,
ObjCMethodDecl MethodDecl,
ParmVarDecl ImplVar,
ParmVarDecl IfaceVar,
bool  IsProtocolMethodDecl,
bool  IsOverridingMode,
bool  Warn 
)
static

◆ CheckMethodOverrideReturn()

static bool CheckMethodOverrideReturn ( Sema S,
ObjCMethodDecl MethodImpl,
ObjCMethodDecl MethodDecl,
bool  IsProtocolMethodDecl,
bool  IsOverridingMode,
bool  Warn 
)
static

◆ checkObjCMethodX86VectorTypes()

static void checkObjCMethodX86VectorTypes ( Sema SemaRef,
const ObjCMethodDecl Method 
)
static

◆ CheckProtocolMethodDefs()

static void CheckProtocolMethodDefs ( Sema S,
SourceLocation  ImpLoc,
ObjCProtocolDecl PDecl,
bool IncompleteImpl,
const Sema::SelectorSet InsMap,
const Sema::SelectorSet ClsMap,
ObjCContainerDecl CDecl,
LazyProtocolNameSet ProtocolsExplictImpl 
)
static

CheckProtocolMethodDefs - This routine checks unimplemented methods Declared in protocol, and those referenced by it.

Definition at line 2636 of file SemaDeclObjC.cpp.

◆ CheckRelatedResultTypeCompatibility()

static Sema::ResultTypeCompatibilityKind CheckRelatedResultTypeCompatibility ( Sema S,
ObjCMethodDecl Method,
ObjCInterfaceDecl CurrentClass 
)
static

Check whether the declared result type of the given Objective-C method declaration is compatible with the method's class.

Definition at line 4091 of file SemaDeclObjC.cpp.

◆ checkTypeParamListConsistency()

static bool checkTypeParamListConsistency ( Sema S,
ObjCTypeParamList prevTypeParams,
ObjCTypeParamList newTypeParams,
TypeParamListContext  newContext 
)
static

Check consistency between two Objective-C type parameter lists, e.g., between a category/extension and an @interface or between an @class and an @interface.

Definition at line 785 of file SemaDeclObjC.cpp.

Referenced by clang::Sema::ActOnForwardClassDeclaration(), and clang::Sema::ActOnStartCategoryInterface().

◆ CvtQTToAstBitMask()

static Decl::ObjCDeclQualifier CvtQTToAstBitMask ( ObjCDeclSpec::ObjCDeclQualifier  PQTVal)
static

CvtQTToAstBitMask - utility routine to produce an AST bitmask for objective-c's type qualifier from the parser version of the same info.

Definition at line 4083 of file SemaDeclObjC.cpp.

◆ DiagnoseObjCImplementedDeprecations()

static void DiagnoseObjCImplementedDeprecations ( Sema S,
const NamedDecl ND,
SourceLocation  ImplLoc 
)
static

◆ DiagnoseRetainableFlexibleArrayMember()

static void DiagnoseRetainableFlexibleArrayMember ( Sema S,
ObjCInterfaceDecl ID 
)
static

Diagnose attempts to use flexible array member with retainable object type.

Definition at line 3725 of file SemaDeclObjC.cpp.

◆ diagnoseUseOfProtocols()

static void diagnoseUseOfProtocols ( Sema TheSema,
ObjCContainerDecl CD,
ObjCProtocolDecl *const *  ProtoRefs,
unsigned  NumProtoRefs,
const SourceLocation ProtoLocs 
)
static

◆ DiagnoseVariableSizedIvars()

static void DiagnoseVariableSizedIvars ( Sema S,
ObjCContainerDecl OCD 
)
static

Definition at line 3771 of file SemaDeclObjC.cpp.

◆ DiagnoseWeakIvars()

static void DiagnoseWeakIvars ( Sema S,
ObjCImplementationDecl ID 
)
static

Diagnose attempts to define ARC-__weak ivars when __weak is disabled.

Definition at line 3708 of file SemaDeclObjC.cpp.

◆ FilterMethodsByTypeBound()

static bool FilterMethodsByTypeBound ( ObjCMethodDecl Method,
const ObjCObjectType TypeBound 
)
static

◆ findProtocolsWithExplicitImpls() [1/2]

static void findProtocolsWithExplicitImpls ( const ObjCProtocolDecl PDecl,
ProtocolNameSet PNS 
)
static

◆ findProtocolsWithExplicitImpls() [2/2]

static void findProtocolsWithExplicitImpls ( const ObjCInterfaceDecl Super,
ProtocolNameSet PNS 
)
static

Recursively populates a set with all conformed protocols in a class hierarchy that have the 'objc_protocol_requires_explicit_implementation' attribute.

Definition at line 2623 of file SemaDeclObjC.cpp.

◆ getTypeRange()

static SourceRange getTypeRange ( TypeSourceInfo TSI)
static

◆ HasExplicitOwnershipAttr()

static bool HasExplicitOwnershipAttr ( Sema S,
ParmVarDecl Param 
)
static

HasExplicitOwnershipAttr - returns true when pointer to ObjC pointer has explicit ownership attribute; false otherwise.

Definition at line 315 of file SemaDeclObjC.cpp.

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

◆ HelperIsMethodInObjCType()

static bool HelperIsMethodInObjCType ( Sema S,
Selector  Sel,
QualType  ObjectType 
)
static

Definition at line 3618 of file SemaDeclObjC.cpp.

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

◆ HelperSelectorsForTypoCorrection()

static void HelperSelectorsForTypoCorrection ( SmallVectorImpl< const ObjCMethodDecl *> &  BestMethod,
StringRef  Typo,
const ObjCMethodDecl Method 
)
static

Definition at line 3596 of file SemaDeclObjC.cpp.

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

◆ isAcceptableMethodMismatch()

static bool isAcceptableMethodMismatch ( ObjCMethodDecl chosen,
ObjCMethodDecl other 
)
static

Determines if this is an "acceptable" loose mismatch in the global method pool.

This exists mostly as a hack to get around certain global mismatches which we can't afford to make warnings / errors. Really, what we want is a way to take a method out of the global method pool.

Definition at line 3386 of file SemaDeclObjC.cpp.

References clang::Selector::getNameForSlot(), clang::ObjCMethodDecl::getReturnType(), clang::ObjCMethodDecl::getSelector(), clang::ObjCMethodDecl::isInstanceMethod(), clang::Type::isIntegerType(), and clang::Selector::isUnarySelector().

◆ isMethodContextSameForKindofLookup()

static bool isMethodContextSameForKindofLookup ( ObjCMethodDecl Method,
ObjCMethodDecl MethodInList 
)
static

◆ isObjCTypeSubstitutable()

static bool isObjCTypeSubstitutable ( ASTContext Context,
const ObjCObjectPointerType A,
const ObjCObjectPointerType B,
bool  rejectId 
)
static

Determines if type B can be substituted for type A.

Returns true if we can guarantee that anything that the user will do to an object of type A can also be done to an object of type B. This is trivially true if the two types are the same, or if B is a subclass of A. It becomes more complex in cases where protocols are involved.

Object types in Objective-C describe the minimum requirements for an object, rather than providing a complete description of a type. For example, if A is a subclass of B, then B* may refer to an instance of A. The principle of substitutability means that we may use an instance of A anywhere that we may use an instance of B - it will implement all of the ivars of B and all of the methods of B.

This substitutability is important when type checking methods, because the implementation may have stricter type definitions than the interface. The interface specifies minimum requirements, but the implementation may have more accurate ones. For example, a method may privately accept instances of B, but only publish that it accepts instances of A. Any object passed to it will be type checked against B, and so will implicitly by a valid A*. Similarly, a method may return a subclass of the class that it is declared as returning.

This is most important when considering subclassing. A method in a subclass must accept any object as an argument that its superclass's implementation accepts. It may, however, accept a more general type without breaking substitutability (i.e. you can still use the subclass anywhere that you can use the superclass, but not vice versa). The converse requirement applies to return types: the return type for a subclass method must be a valid object of the kind that the superclass advertises, but it may be specified more accurately. This avoids the need for explicit down-casting by callers.

Note: This is a stricter requirement than for assignment.

Definition at line 2227 of file SemaDeclObjC.cpp.

References clang::ASTContext::canAssignObjCInterfaces(), clang::ObjCObjectPointerType::isObjCIdType(), clang::ObjCObjectPointerType::isObjCQualifiedIdType(), and clang::ASTContext::ObjCQualifiedIdTypesAreCompatible().

◆ IsVariableSizedType()

static bool IsVariableSizedType ( QualType  T)
static

◆ matchTypes()

static bool matchTypes ( ASTContext Context,
Sema::MethodMatchStrategy  strategy,
QualType  leftQT,
QualType  rightQT 
)
static

◆ mergeInterfaceMethodToImpl()

static void mergeInterfaceMethodToImpl ( Sema S,
ObjCMethodDecl method,
ObjCMethodDecl prevMethod 
)
static

Merge information from the declaration of a method in the @interface (or a category/extension) into the corresponding method in the (for a class or category).

Definition at line 4420 of file SemaDeclObjC.cpp.

◆ mergeTypeNullabilityForRedecl()

static QualType mergeTypeNullabilityForRedecl ( Sema S,
SourceLocation  loc,
QualType  type,
bool  usesCSKeyword,
SourceLocation  prevLoc,
QualType  prevType,
bool  prevUsesCSKeyword 
)
static

Merge type nullability from for a redeclaration of the same entity, producing the updated type of the redeclared entity.

Definition at line 4380 of file SemaDeclObjC.cpp.

◆ NestedProtocolHasNoDefinition()

static bool NestedProtocolHasNoDefinition ( ObjCProtocolDecl PDecl,
ObjCProtocolDecl *&  UndefinedProtocol 
)
static

◆ objcModifiersConflict()

static bool objcModifiersConflict ( Decl::ObjCDeclQualifier  x,
Decl::ObjCDeclQualifier  y 
)
static

Determine whether two set of Objective-C declaration qualifiers conflict.

Definition at line 2266 of file SemaDeclObjC.cpp.

References clang::Decl::OBJC_TQ_CSNullability.

◆ tryMatchRecordTypes()

static bool tryMatchRecordTypes ( ASTContext Context,
Sema::MethodMatchStrategy  strategy,
const Type left,
const Type right 
)
static

◆ WarnUndefinedMethod()

static void WarnUndefinedMethod ( Sema S,
SourceLocation  ImpLoc,
ObjCMethodDecl method,
bool IncompleteImpl,
unsigned  DiagID,
NamedDecl NeededFor = nullptr 
)
static

Definition at line 2159 of file SemaDeclObjC.cpp.