clang API Documentation
#include "clang/Sema/SemaInternal.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTMutationListener.h"
#include "clang/AST/DataRecursiveASTVisitor.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprObjC.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Sema/DeclSpec.h"
#include "clang/Sema/ExternalSemaSource.h"
#include "clang/Sema/Lookup.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/ScopeInfo.h"
#include "llvm/ADT/DenseSet.h"
#include "clang/AST/DeclNodes.inc"
Go to the source code of this file.
#define ABSTRACT_DECL | ( | expansion | ) |
#define DECL | ( | type, | |
base | |||
) | case Decl::type: |
#define OBJCCONTAINER | ( | type, | |
base | |||
) |
case Decl::type: \ searchFrom(cast<type##Decl>(container)); \ break;
typedef std::unique_ptr<ProtocolNameSet> LazyProtocolNameSet |
Definition at line 1648 of file SemaDeclObjC.cpp.
typedef llvm::DenseSet<IdentifierInfo*> 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 1647 of file SemaDeclObjC.cpp.
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 1479 of file SemaDeclObjC.cpp.
References clang::ast_matchers::decl, clang::Sema::Diag(), clang::Decl::getLocation(), clang::ObjCMethodDecl::getMethodFamily(), clang::ObjCMethodDecl::getReturnType(), clang::Decl::isInvalidDecl(), clang::Type::isObjCObjectPointerType(), clang::OMF_alloc, clang::OMF_autorelease, clang::OMF_copy, clang::OMF_dealloc, clang::OMF_finalize, clang::OMF_init, clang::OMF_initialize, clang::OMF_mutableCopy, clang::OMF_new, clang::OMF_None, clang::OMF_performSelector, clang::OMF_release, clang::OMF_retain, clang::OMF_retainCount, and clang::OMF_self.
Referenced by clang::Sema::WarnConflictingTypedMethods().
static bool CheckMethodOverrideParam | ( | Sema & | S, |
ObjCMethodDecl * | MethodImpl, | ||
ObjCMethodDecl * | MethodDecl, | ||
ParmVarDecl * | ImplVar, | ||
ParmVarDecl * | IfaceVar, | ||
bool | IsProtocolMethodDecl, | ||
bool | IsOverridingMode, | ||
bool | Warn | ||
) | [static] |
Definition at line 1408 of file SemaDeclObjC.cpp.
References clang::Sema::Context, clang::Sema::Diag(), clang::Type::getAs(), clang::NamedDecl::getDeclName(), clang::Decl::getLocation(), clang::ParmVarDecl::getObjCDeclQualifier(), clang::ValueDecl::getType(), getTypeRange(), clang::DeclaratorDecl::getTypeSourceInfo(), clang::ASTContext::hasSameUnqualifiedType(), and isObjCTypeSubstitutable().
Referenced by clang::Sema::CheckConflictingOverridingMethod(), clang::Sema::WarnConflictingTypedMethods(), and clang::Sema::WarnExactTypedMethods().
static bool CheckMethodOverrideReturn | ( | Sema & | S, |
ObjCMethodDecl * | MethodImpl, | ||
ObjCMethodDecl * | MethodDecl, | ||
bool | IsProtocolMethodDecl, | ||
bool | IsOverridingMode, | ||
bool | Warn | ||
) | [static] |
Definition at line 1345 of file SemaDeclObjC.cpp.
References clang::Sema::Context, clang::Sema::Diag(), clang::Type::getAs(), clang::NamedDecl::getDeclName(), clang::Decl::getLocation(), clang::ObjCMethodDecl::getObjCDeclQualifier(), clang::ObjCMethodDecl::getReturnType(), clang::ObjCMethodDecl::getReturnTypeSourceRange(), clang::ASTContext::hasSameUnqualifiedType(), and isObjCTypeSubstitutable().
Referenced by clang::Sema::CheckConflictingOverridingMethod(), clang::Sema::WarnConflictingTypedMethods(), and clang::Sema::WarnExactTypedMethods().
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 1674 of file SemaDeclObjC.cpp.
References AttributeLangSupport::C, clang::ObjCContainerDecl::class_methods(), clang::Sema::Context, DIAG, clang::Sema::Diags, findProtocolsWithExplicitImpls(), clang::IdentifierTable::get(), clang::ObjCCategoryDecl::getClassInterface(), clang::ObjCProtocolDecl::getDefinition(), clang::NamedDecl::getIdentifier(), clang::Sema::getLangOpts(), clang::SelectorTable::getSelector(), clang::ObjCInterfaceDecl::getSuperClass(), clang::Decl::hasAttr(), clang::ASTContext::Idents, clang::ObjCContainerDecl::instance_methods(), clang::DiagnosticsEngine::isIgnored(), clang::ObjCRuntime::isNeXTFamily(), clang::ObjCProtocolDecl::isThisDeclarationADefinition(), clang::ObjCInterfaceDecl::lookupInheritedClass(), clang::ObjCInterfaceDecl::lookupMethod(), clang::LangOptions::ObjCRuntime, clang::ObjCMethodDecl::Optional, clang::ObjCProtocolDecl::protocols(), clang::ASTContext::Selectors, and WarnUndefinedMethod().
Referenced by clang::Sema::ImplMethodsVsClassMethods().
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 2796 of file SemaDeclObjC.cpp.
References clang::declaresSameEntity(), clang::Type::getAs(), clang::ObjCMethodDecl::getReturnType(), clang::Sema::RTC_Compatible, clang::Sema::RTC_Incompatible, and clang::Sema::RTC_Unknown.
Referenced by clang::Sema::ActOnMethodDeclaration().
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 2788 of file SemaDeclObjC.cpp.
Referenced by clang::Sema::ActOnMethodDeclaration().
static void DiagnoseObjCImplementedDeprecations | ( | Sema & | S, |
NamedDecl * | ND, | ||
SourceLocation | ImplLoc, | ||
int | select | ||
) | [static] |
Definition at line 251 of file SemaDeclObjC.cpp.
References clang::Sema::Diag(), clang::NamedDecl::getDeclName(), clang::Decl::getLocation(), and clang::Decl::isDeprecated().
Referenced by clang::Sema::ActOnStartCategoryImplementation(), clang::Sema::ActOnStartClassImplementation(), and clang::Sema::ActOnStartOfObjCMethodDef().
static void findProtocolsWithExplicitImpls | ( | const ObjCProtocolDecl * | PDecl, |
ProtocolNameSet & | PNS | ||
) | [static] |
Definition at line 1650 of file SemaDeclObjC.cpp.
References clang::NamedDecl::getIdentifier(), clang::Decl::hasAttr(), and clang::ObjCProtocolDecl::protocols().
Referenced by CheckProtocolMethodDefs(), and findProtocolsWithExplicitImpls().
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 1661 of file SemaDeclObjC.cpp.
References clang::ObjCInterfaceDecl::all_referenced_protocols(), findProtocolsWithExplicitImpls(), and clang::ObjCInterfaceDecl::getSuperClass().
static SourceRange getTypeRange | ( | TypeSourceInfo * | TSI | ) | [static] |
Definition at line 1341 of file SemaDeclObjC.cpp.
References clang::TypeLoc::getSourceRange(), and clang::TypeSourceInfo::getTypeLoc().
Referenced by CheckMethodOverrideParam().
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 282 of file SemaDeclObjC.cpp.
References clang::Type::getAs(), clang::QualType::getLocalQualifiers(), clang::Type::getPointeeType(), clang::ValueDecl::getType(), and clang::Qualifiers::hasObjCLifetime().
Referenced by clang::Sema::ActOnStartOfObjCMethodDef().
static bool HelperIsMethodInObjCType | ( | Sema & | S, |
Selector | Sel, | ||
QualType | ObjectType | ||
) | [static] |
Definition at line 2474 of file SemaDeclObjC.cpp.
References clang::QualType::isNull(), and clang::Sema::LookupMethodInObjectType().
Referenced by clang::Sema::SelectorsForTypoCorrection().
static void HelperSelectorsForTypoCorrection | ( | SmallVectorImpl< const ObjCMethodDecl * > & | BestMethod, |
StringRef | Typo, | ||
const ObjCMethodDecl * | Method | ||
) | [static] |
Definition at line 2452 of file SemaDeclObjC.cpp.
References BestEditDistance, clang::Selector::getAsString(), clang::ObjCMethodDecl::getSelector(), and MaxEditDistance.
Referenced by clang::Sema::SelectorsForTypoCorrection().
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 2309 of file SemaDeclObjC.cpp.
References clang::Selector::getNameForSlot(), clang::ObjCMethodDecl::getReturnType(), clang::ObjCMethodDecl::getSelector(), clang::ObjCMethodDecl::isInstanceMethod(), clang::Type::isIntegerType(), and clang::Selector::isUnarySelector().
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 1307 of file SemaDeclObjC.cpp.
References clang::ASTContext::canAssignObjCInterfaces(), clang::ObjCObjectPointerType::isObjCIdType(), clang::ObjCObjectPointerType::isObjCQualifiedIdType(), and clang::ASTContext::ObjCQualifiedIdTypesAreCompatible().
Referenced by CheckMethodOverrideParam(), and CheckMethodOverrideReturn().
static bool matchTypes | ( | ASTContext & | Context, |
Sema::MethodMatchStrategy | strategy, | ||
QualType | leftQT, | ||
QualType | rightQT | ||
) | [static] |
Definition at line 2088 of file SemaDeclObjC.cpp.
References clang::TypeInfo::Align, clang::ASTContext::getCanonicalType(), clang::Type::getScalarTypeKind(), clang::ASTContext::getTypeInfo(), clang::CanQual< T >::getTypePtr(), clang::CanQual< T >::getUnqualifiedType(), clang::Type::isIncompleteType(), clang::Type::isScalarType(), clang::Sema::MMS_strict, clang::Type::STK_BlockPointer, clang::Type::STK_Bool, clang::Type::STK_CPointer, clang::Type::STK_Integral, clang::Type::STK_ObjCObjectPointer, tryMatchRecordTypes(), and clang::TypeInfo::Width.
Referenced by clang::Sema::MatchTwoMethodDeclarations(), and tryMatchRecordTypes().
static bool NestedProtocolHasNoDefinition | ( | ObjCProtocolDecl * | PDecl, |
ObjCProtocolDecl *& | UndefinedProtocol | ||
) | [static] |
Definition at line 763 of file SemaDeclObjC.cpp.
References clang::ObjCProtocolDecl::getDefinition(), clang::ObjCProtocolDecl::hasDefinition(), clang::NamedDecl::isHidden(), and clang::ObjCProtocolDecl::protocols().
Referenced by clang::Sema::FindProtocolDeclaration().
static bool tryMatchRecordTypes | ( | ASTContext & | Context, |
Sema::MethodMatchStrategy | strategy, | ||
const Type * | left, | ||
const Type * | right | ||
) | [static] |
Definition at line 2145 of file SemaDeclObjC.cpp.
References clang::TypeInfo::Align, clang::ASTContext::getTypeInfo(), clang::TagDecl::isUnion(), matchTypes(), and clang::TypeInfo::Width.
Referenced by matchTypes().
static void WarnUndefinedMethod | ( | Sema & | S, |
SourceLocation | ImpLoc, | ||
ObjCMethodDecl * | method, | ||
bool & | IncompleteImpl, | ||
unsigned | DiagID, | ||
NamedDecl * | NeededFor = nullptr |
||
) | [static] |
Definition at line 1239 of file SemaDeclObjC.cpp.
References clang::AR_Available, clang::AR_Deprecated, clang::AR_NotYetIntroduced, clang::AR_Unavailable, clang::Sema::Diag(), clang::Decl::getAvailability(), clang::ObjCMethodDecl::getLocStart(), and clang::SourceLocation::isValid().
Referenced by CheckProtocolMethodDefs(), and clang::Sema::MatchAllMethodDeclarations().