Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:37:04

0001 //===----- SemaObjC.h ------ Semantic Analysis for Objective-C ------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 /// \file
0009 /// This file declares semantic analysis for Objective-C.
0010 ///
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_CLANG_SEMA_SEMAOBJC_H
0014 #define LLVM_CLANG_SEMA_SEMAOBJC_H
0015 
0016 #include "clang/AST/ASTFwd.h"
0017 #include "clang/AST/DeclObjC.h"
0018 #include "clang/AST/NSAPI.h"
0019 #include "clang/AST/OperationKinds.h"
0020 #include "clang/AST/Type.h"
0021 #include "clang/Basic/IdentifierTable.h"
0022 #include "clang/Basic/LLVM.h"
0023 #include "clang/Basic/SourceLocation.h"
0024 #include "clang/Basic/Specifiers.h"
0025 #include "clang/Basic/TokenKinds.h"
0026 #include "clang/Sema/DeclSpec.h"
0027 #include "clang/Sema/ObjCMethodList.h"
0028 #include "clang/Sema/Ownership.h"
0029 #include "clang/Sema/Redeclaration.h"
0030 #include "clang/Sema/Sema.h"
0031 #include "clang/Sema/SemaBase.h"
0032 #include "llvm/ADT/DenseMap.h"
0033 #include "llvm/ADT/MapVector.h"
0034 #include "llvm/ADT/SmallPtrSet.h"
0035 #include <memory>
0036 #include <optional>
0037 #include <utility>
0038 
0039 namespace clang {
0040 
0041 class AttributeCommonInfo;
0042 class AvailabilitySpec;
0043 enum class CheckedConversionKind;
0044 class DeclGroupRef;
0045 class LookupResult;
0046 struct ObjCDictionaryElement;
0047 class ParsedAttr;
0048 class ParsedAttributesView;
0049 class Scope;
0050 struct SkipBodyInfo;
0051 
0052 class SemaObjC : public SemaBase {
0053 public:
0054   SemaObjC(Sema &S);
0055 
0056   ExprResult CheckObjCForCollectionOperand(SourceLocation forLoc,
0057                                            Expr *collection);
0058   StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, Stmt *First,
0059                                         Expr *collection,
0060                                         SourceLocation RParenLoc);
0061   /// FinishObjCForCollectionStmt - Attach the body to a objective-C foreach
0062   /// statement.
0063   StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body);
0064 
0065   StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen,
0066                                   Decl *Parm, Stmt *Body);
0067 
0068   StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body);
0069 
0070   StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try,
0071                                 MultiStmtArg Catch, Stmt *Finally);
0072 
0073   StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw);
0074   StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw,
0075                                   Scope *CurScope);
0076   ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc,
0077                                             Expr *operand);
0078   StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, Expr *SynchExpr,
0079                                          Stmt *SynchBody);
0080 
0081   StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body);
0082 
0083   /// Build a an Objective-C protocol-qualified 'id' type where no
0084   /// base type was specified.
0085   TypeResult actOnObjCProtocolQualifierType(
0086       SourceLocation lAngleLoc, ArrayRef<Decl *> protocols,
0087       ArrayRef<SourceLocation> protocolLocs, SourceLocation rAngleLoc);
0088 
0089   /// Build a specialized and/or protocol-qualified Objective-C type.
0090   TypeResult actOnObjCTypeArgsAndProtocolQualifiers(
0091       Scope *S, SourceLocation Loc, ParsedType BaseType,
0092       SourceLocation TypeArgsLAngleLoc, ArrayRef<ParsedType> TypeArgs,
0093       SourceLocation TypeArgsRAngleLoc, SourceLocation ProtocolLAngleLoc,
0094       ArrayRef<Decl *> Protocols, ArrayRef<SourceLocation> ProtocolLocs,
0095       SourceLocation ProtocolRAngleLoc);
0096 
0097   /// Build an Objective-C type parameter type.
0098   QualType BuildObjCTypeParamType(const ObjCTypeParamDecl *Decl,
0099                                   SourceLocation ProtocolLAngleLoc,
0100                                   ArrayRef<ObjCProtocolDecl *> Protocols,
0101                                   ArrayRef<SourceLocation> ProtocolLocs,
0102                                   SourceLocation ProtocolRAngleLoc,
0103                                   bool FailOnError = false);
0104 
0105   /// Build an Objective-C object pointer type.
0106   QualType BuildObjCObjectType(
0107       QualType BaseType, SourceLocation Loc, SourceLocation TypeArgsLAngleLoc,
0108       ArrayRef<TypeSourceInfo *> TypeArgs, SourceLocation TypeArgsRAngleLoc,
0109       SourceLocation ProtocolLAngleLoc, ArrayRef<ObjCProtocolDecl *> Protocols,
0110       ArrayRef<SourceLocation> ProtocolLocs, SourceLocation ProtocolRAngleLoc,
0111       bool FailOnError, bool Rebuilding);
0112 
0113   /// The parser has parsed the context-sensitive type 'instancetype'
0114   /// in an Objective-C message declaration. Return the appropriate type.
0115   ParsedType ActOnObjCInstanceType(SourceLocation Loc);
0116 
0117   /// checkRetainCycles - Check whether an Objective-C message send
0118   /// might create an obvious retain cycle.
0119   void checkRetainCycles(ObjCMessageExpr *msg);
0120   void checkRetainCycles(Expr *receiver, Expr *argument);
0121   void checkRetainCycles(VarDecl *Var, Expr *Init);
0122 
0123   bool CheckObjCString(Expr *Arg);
0124   bool CheckObjCMethodCall(ObjCMethodDecl *Method, SourceLocation loc,
0125                            ArrayRef<const Expr *> Args);
0126   /// Check whether receiver is mutable ObjC container which
0127   /// attempts to add itself into the container
0128   void CheckObjCCircularContainer(ObjCMessageExpr *Message);
0129 
0130   void ActOnObjCContainerStartDefinition(ObjCContainerDecl *IDecl);
0131   void ActOnObjCContainerFinishDefinition();
0132 
0133   /// Invoked when we must temporarily exit the objective-c container
0134   /// scope for parsing/looking-up C constructs.
0135   ///
0136   /// Must be followed by a call to \see ActOnObjCReenterContainerContext
0137   void ActOnObjCTemporaryExitContainerContext(ObjCContainerDecl *ObjCCtx);
0138   void ActOnObjCReenterContainerContext(ObjCContainerDecl *ObjCCtx);
0139 
0140   const DeclContext *getCurObjCLexicalContext() const;
0141 
0142   ObjCProtocolDecl *LookupProtocol(
0143       IdentifierInfo *II, SourceLocation IdLoc,
0144       RedeclarationKind Redecl = RedeclarationKind::NotForRedeclaration);
0145 
0146   bool isObjCWritebackConversion(QualType FromType, QualType ToType,
0147                                  QualType &ConvertedType);
0148 
0149   enum ObjCSubscriptKind { OS_Array, OS_Dictionary, OS_Error };
0150   ObjCSubscriptKind CheckSubscriptingKind(Expr *FromE);
0151 
0152   /// AddCFAuditedAttribute - Check whether we're currently within
0153   /// '\#pragma clang arc_cf_code_audited' and, if so, consider adding
0154   /// the appropriate attribute.
0155   void AddCFAuditedAttribute(Decl *D);
0156 
0157   /// The struct behind the CFErrorRef pointer.
0158   RecordDecl *CFError = nullptr;
0159   bool isCFError(RecordDecl *D);
0160 
0161   IdentifierInfo *getNSErrorIdent();
0162 
0163   bool GetFormatNSStringIdx(const FormatAttr *Format, unsigned &Idx);
0164 
0165   /// Diagnose use of %s directive in an NSString which is being passed
0166   /// as formatting string to formatting method.
0167   void DiagnoseCStringFormatDirectiveInCFAPI(const NamedDecl *FDecl,
0168                                              Expr **Args, unsigned NumArgs);
0169 
0170   bool isSignedCharBool(QualType Ty);
0171 
0172   void adornBoolConversionDiagWithTernaryFixit(
0173       Expr *SourceExpr, const Sema::SemaDiagnosticBuilder &Builder);
0174 
0175   /// Check an Objective-C dictionary literal being converted to the given
0176   /// target type.
0177   void checkDictionaryLiteral(QualType TargetType,
0178                               ObjCDictionaryLiteral *DictionaryLiteral);
0179 
0180   /// Check an Objective-C array literal being converted to the given
0181   /// target type.
0182   void checkArrayLiteral(QualType TargetType, ObjCArrayLiteral *ArrayLiteral);
0183 
0184 private:
0185   IdentifierInfo *Ident_NSError = nullptr;
0186 
0187   //
0188   //
0189   // -------------------------------------------------------------------------
0190   //
0191   //
0192 
0193   /// \name ObjC Declarations
0194   /// Implementations are in SemaDeclObjC.cpp
0195   ///@{
0196 
0197 public:
0198   enum ObjCSpecialMethodKind {
0199     OSMK_None,
0200     OSMK_Alloc,
0201     OSMK_New,
0202     OSMK_Copy,
0203     OSMK_RetainingInit,
0204     OSMK_NonRetainingInit
0205   };
0206 
0207   /// Method selectors used in a \@selector expression. Used for implementation
0208   /// of -Wselector.
0209   llvm::MapVector<Selector, SourceLocation> ReferencedSelectors;
0210 
0211   using GlobalMethodPool =
0212       llvm::DenseMap<Selector, std::pair<ObjCMethodList, ObjCMethodList>>;
0213 
0214   /// Method Pool - allows efficient lookup when typechecking messages to "id".
0215   /// We need to maintain a list, since selectors can have differing signatures
0216   /// across classes. In Cocoa, this happens to be extremely uncommon (only 1%
0217   /// of selectors are "overloaded").
0218   /// At the head of the list it is recorded whether there were 0, 1, or >= 2
0219   /// methods inside categories with a particular selector.
0220   GlobalMethodPool MethodPool;
0221 
0222   typedef llvm::SmallPtrSet<Selector, 8> SelectorSet;
0223 
0224   enum MethodMatchStrategy { MMS_loose, MMS_strict };
0225 
0226   enum ObjCContainerKind {
0227     OCK_None = -1,
0228     OCK_Interface = 0,
0229     OCK_Protocol,
0230     OCK_Category,
0231     OCK_ClassExtension,
0232     OCK_Implementation,
0233     OCK_CategoryImplementation
0234   };
0235   ObjCContainerKind getObjCContainerKind() const;
0236 
0237   DeclResult actOnObjCTypeParam(Scope *S, ObjCTypeParamVariance variance,
0238                                 SourceLocation varianceLoc, unsigned index,
0239                                 IdentifierInfo *paramName,
0240                                 SourceLocation paramLoc,
0241                                 SourceLocation colonLoc, ParsedType typeBound);
0242 
0243   ObjCTypeParamList *actOnObjCTypeParamList(Scope *S, SourceLocation lAngleLoc,
0244                                             ArrayRef<Decl *> typeParams,
0245                                             SourceLocation rAngleLoc);
0246   void popObjCTypeParamList(Scope *S, ObjCTypeParamList *typeParamList);
0247 
0248   ObjCInterfaceDecl *ActOnStartClassInterface(
0249       Scope *S, SourceLocation AtInterfaceLoc, IdentifierInfo *ClassName,
0250       SourceLocation ClassLoc, ObjCTypeParamList *typeParamList,
0251       IdentifierInfo *SuperName, SourceLocation SuperLoc,
0252       ArrayRef<ParsedType> SuperTypeArgs, SourceRange SuperTypeArgsRange,
0253       Decl *const *ProtoRefs, unsigned NumProtoRefs,
0254       const SourceLocation *ProtoLocs, SourceLocation EndProtoLoc,
0255       const ParsedAttributesView &AttrList, SkipBodyInfo *SkipBody);
0256 
0257   void ActOnSuperClassOfClassInterface(
0258       Scope *S, SourceLocation AtInterfaceLoc, ObjCInterfaceDecl *IDecl,
0259       IdentifierInfo *ClassName, SourceLocation ClassLoc,
0260       IdentifierInfo *SuperName, SourceLocation SuperLoc,
0261       ArrayRef<ParsedType> SuperTypeArgs, SourceRange SuperTypeArgsRange);
0262 
0263   void ActOnTypedefedProtocols(SmallVectorImpl<Decl *> &ProtocolRefs,
0264                                SmallVectorImpl<SourceLocation> &ProtocolLocs,
0265                                IdentifierInfo *SuperName,
0266                                SourceLocation SuperLoc);
0267 
0268   Decl *ActOnCompatibilityAlias(SourceLocation AtCompatibilityAliasLoc,
0269                                 IdentifierInfo *AliasName,
0270                                 SourceLocation AliasLocation,
0271                                 IdentifierInfo *ClassName,
0272                                 SourceLocation ClassLocation);
0273 
0274   bool CheckForwardProtocolDeclarationForCircularDependency(
0275       IdentifierInfo *PName, SourceLocation &PLoc, SourceLocation PrevLoc,
0276       const ObjCList<ObjCProtocolDecl> &PList);
0277 
0278   ObjCProtocolDecl *ActOnStartProtocolInterface(
0279       SourceLocation AtProtoInterfaceLoc, IdentifierInfo *ProtocolName,
0280       SourceLocation ProtocolLoc, Decl *const *ProtoRefNames,
0281       unsigned NumProtoRefs, const SourceLocation *ProtoLocs,
0282       SourceLocation EndProtoLoc, const ParsedAttributesView &AttrList,
0283       SkipBodyInfo *SkipBody);
0284 
0285   ObjCCategoryDecl *ActOnStartCategoryInterface(
0286       SourceLocation AtInterfaceLoc, const IdentifierInfo *ClassName,
0287       SourceLocation ClassLoc, ObjCTypeParamList *typeParamList,
0288       const IdentifierInfo *CategoryName, SourceLocation CategoryLoc,
0289       Decl *const *ProtoRefs, unsigned NumProtoRefs,
0290       const SourceLocation *ProtoLocs, SourceLocation EndProtoLoc,
0291       const ParsedAttributesView &AttrList);
0292 
0293   ObjCImplementationDecl *ActOnStartClassImplementation(
0294       SourceLocation AtClassImplLoc, const IdentifierInfo *ClassName,
0295       SourceLocation ClassLoc, const IdentifierInfo *SuperClassname,
0296       SourceLocation SuperClassLoc, const ParsedAttributesView &AttrList);
0297 
0298   ObjCCategoryImplDecl *ActOnStartCategoryImplementation(
0299       SourceLocation AtCatImplLoc, const IdentifierInfo *ClassName,
0300       SourceLocation ClassLoc, const IdentifierInfo *CatName,
0301       SourceLocation CatLoc, const ParsedAttributesView &AttrList);
0302 
0303   using DeclGroupPtrTy = OpaquePtr<DeclGroupRef>;
0304 
0305   DeclGroupPtrTy ActOnFinishObjCImplementation(Decl *ObjCImpDecl,
0306                                                ArrayRef<Decl *> Decls);
0307 
0308   DeclGroupPtrTy
0309   ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc,
0310                                   ArrayRef<IdentifierLocPair> IdentList,
0311                                   const ParsedAttributesView &attrList);
0312 
0313   void FindProtocolDeclaration(bool WarnOnDeclarations, bool ForObjCContainer,
0314                                ArrayRef<IdentifierLocPair> ProtocolId,
0315                                SmallVectorImpl<Decl *> &Protocols);
0316 
0317   void DiagnoseTypeArgsAndProtocols(IdentifierInfo *ProtocolId,
0318                                     SourceLocation ProtocolLoc,
0319                                     IdentifierInfo *TypeArgId,
0320                                     SourceLocation TypeArgLoc,
0321                                     bool SelectProtocolFirst = false);
0322 
0323   /// Given a list of identifiers (and their locations), resolve the
0324   /// names to either Objective-C protocol qualifiers or type
0325   /// arguments, as appropriate.
0326   void actOnObjCTypeArgsOrProtocolQualifiers(
0327       Scope *S, ParsedType baseType, SourceLocation lAngleLoc,
0328       ArrayRef<IdentifierInfo *> identifiers,
0329       ArrayRef<SourceLocation> identifierLocs, SourceLocation rAngleLoc,
0330       SourceLocation &typeArgsLAngleLoc, SmallVectorImpl<ParsedType> &typeArgs,
0331       SourceLocation &typeArgsRAngleLoc, SourceLocation &protocolLAngleLoc,
0332       SmallVectorImpl<Decl *> &protocols, SourceLocation &protocolRAngleLoc,
0333       bool warnOnIncompleteProtocols);
0334 
0335   void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT,
0336                                         ObjCInterfaceDecl *ID);
0337 
0338   Decl *ActOnAtEnd(Scope *S, SourceRange AtEnd,
0339                    ArrayRef<Decl *> allMethods = {},
0340                    ArrayRef<DeclGroupPtrTy> allTUVars = {});
0341 
0342   struct ObjCArgInfo {
0343     IdentifierInfo *Name;
0344     SourceLocation NameLoc;
0345     // The Type is null if no type was specified, and the DeclSpec is invalid
0346     // in this case.
0347     ParsedType Type;
0348     ObjCDeclSpec DeclSpec;
0349 
0350     /// ArgAttrs - Attribute list for this argument.
0351     ParsedAttributesView ArgAttrs;
0352   };
0353 
0354   ParmVarDecl *ActOnMethodParmDeclaration(Scope *S, ObjCArgInfo &ArgInfo,
0355                                           int ParamIndex,
0356                                           bool MethodDefinition);
0357 
0358   Decl *ActOnMethodDeclaration(
0359       Scope *S,
0360       SourceLocation BeginLoc, // location of the + or -.
0361       SourceLocation EndLoc,   // location of the ; or {.
0362       tok::TokenKind MethodType, ObjCDeclSpec &ReturnQT, ParsedType ReturnType,
0363       ArrayRef<SourceLocation> SelectorLocs, Selector Sel,
0364       // optional arguments. The number of types/arguments is obtained
0365       // from the Sel.getNumArgs().
0366       ParmVarDecl **ArgInfo, DeclaratorChunk::ParamInfo *CParamInfo,
0367       unsigned CNumArgs, // c-style args
0368       const ParsedAttributesView &AttrList, tok::ObjCKeywordKind MethodImplKind,
0369       bool isVariadic, bool MethodDefinition);
0370 
0371   bool CheckARCMethodDecl(ObjCMethodDecl *method);
0372 
0373   bool checkInitMethod(ObjCMethodDecl *method, QualType receiverTypeIfCall);
0374 
0375   /// Check whether the given new method is a valid override of the
0376   /// given overridden method, and set any properties that should be inherited.
0377   void CheckObjCMethodOverride(ObjCMethodDecl *NewMethod,
0378                                const ObjCMethodDecl *Overridden);
0379 
0380   /// Describes the compatibility of a result type with its method.
0381   enum ResultTypeCompatibilityKind {
0382     RTC_Compatible,
0383     RTC_Incompatible,
0384     RTC_Unknown
0385   };
0386 
0387   void CheckObjCMethodDirectOverrides(ObjCMethodDecl *method,
0388                                       ObjCMethodDecl *overridden);
0389 
0390   void CheckObjCMethodOverrides(ObjCMethodDecl *ObjCMethod,
0391                                 ObjCInterfaceDecl *CurrentClass,
0392                                 ResultTypeCompatibilityKind RTC);
0393 
0394   /// AddAnyMethodToGlobalPool - Add any method, instance or factory to global
0395   /// pool.
0396   void AddAnyMethodToGlobalPool(Decl *D);
0397 
0398   void ActOnStartOfObjCMethodDef(Scope *S, Decl *D);
0399   bool isObjCMethodDecl(Decl *D) { return isa_and_nonnull<ObjCMethodDecl>(D); }
0400 
0401   /// CheckImplementationIvars - This routine checks if the instance variables
0402   /// listed in the implelementation match those listed in the interface.
0403   void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
0404                                 ObjCIvarDecl **Fields, unsigned nIvars,
0405                                 SourceLocation Loc);
0406 
0407   void WarnConflictingTypedMethods(ObjCMethodDecl *Method,
0408                                    ObjCMethodDecl *MethodDecl,
0409                                    bool IsProtocolMethodDecl);
0410 
0411   void CheckConflictingOverridingMethod(ObjCMethodDecl *Method,
0412                                         ObjCMethodDecl *Overridden,
0413                                         bool IsProtocolMethodDecl);
0414 
0415   /// WarnExactTypedMethods - This routine issues a warning if method
0416   /// implementation declaration matches exactly that of its declaration.
0417   void WarnExactTypedMethods(ObjCMethodDecl *Method, ObjCMethodDecl *MethodDecl,
0418                              bool IsProtocolMethodDecl);
0419 
0420   /// MatchAllMethodDeclarations - Check methods declaraed in interface or
0421   /// or protocol against those declared in their implementations.
0422   void MatchAllMethodDeclarations(
0423       const SelectorSet &InsMap, const SelectorSet &ClsMap,
0424       SelectorSet &InsMapSeen, SelectorSet &ClsMapSeen, ObjCImplDecl *IMPDecl,
0425       ObjCContainerDecl *IDecl, bool &IncompleteImpl, bool ImmediateClass,
0426       bool WarnCategoryMethodImpl = false);
0427 
0428   /// CheckCategoryVsClassMethodMatches - Checks that methods implemented in
0429   /// category matches with those implemented in its primary class and
0430   /// warns each time an exact match is found.
0431   void CheckCategoryVsClassMethodMatches(ObjCCategoryImplDecl *CatIMP);
0432 
0433   /// ImplMethodsVsClassMethods - This is main routine to warn if any method
0434   /// remains unimplemented in the class or category \@implementation.
0435   void ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl *IMPDecl,
0436                                  ObjCContainerDecl *IDecl,
0437                                  bool IncompleteImpl = false);
0438 
0439   DeclGroupPtrTy ActOnForwardClassDeclaration(
0440       SourceLocation Loc, IdentifierInfo **IdentList, SourceLocation *IdentLocs,
0441       ArrayRef<ObjCTypeParamList *> TypeParamLists, unsigned NumElts);
0442 
0443   /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns
0444   /// true, or false, accordingly.
0445   bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
0446                                   const ObjCMethodDecl *PrevMethod,
0447                                   MethodMatchStrategy strategy = MMS_strict);
0448 
0449   /// Add the given method to the list of globally-known methods.
0450   void addMethodToGlobalList(ObjCMethodList *List, ObjCMethodDecl *Method);
0451 
0452   void ReadMethodPool(Selector Sel);
0453   void updateOutOfDateSelector(Selector Sel);
0454 
0455   /// - Returns instance or factory methods in global method pool for
0456   /// given selector. It checks the desired kind first, if none is found, and
0457   /// parameter checkTheOther is set, it then checks the other kind. If no such
0458   /// method or only one method is found, function returns false; otherwise, it
0459   /// returns true.
0460   bool
0461   CollectMultipleMethodsInGlobalPool(Selector Sel,
0462                                      SmallVectorImpl<ObjCMethodDecl *> &Methods,
0463                                      bool InstanceFirst, bool CheckTheOther,
0464                                      const ObjCObjectType *TypeBound = nullptr);
0465 
0466   bool
0467   AreMultipleMethodsInGlobalPool(Selector Sel, ObjCMethodDecl *BestMethod,
0468                                  SourceRange R, bool receiverIdOrClass,
0469                                  SmallVectorImpl<ObjCMethodDecl *> &Methods);
0470 
0471   void
0472   DiagnoseMultipleMethodInGlobalPool(SmallVectorImpl<ObjCMethodDecl *> &Methods,
0473                                      Selector Sel, SourceRange R,
0474                                      bool receiverIdOrClass);
0475 
0476   const ObjCMethodDecl *
0477   SelectorsForTypoCorrection(Selector Sel, QualType ObjectType = QualType());
0478   /// LookupImplementedMethodInGlobalPool - Returns the method which has an
0479   /// implementation.
0480   ObjCMethodDecl *LookupImplementedMethodInGlobalPool(Selector Sel);
0481 
0482   void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID);
0483 
0484   /// Checks that the Objective-C declaration is declared in the global scope.
0485   /// Emits an error and marks the declaration as invalid if it's not declared
0486   /// in the global scope.
0487   bool CheckObjCDeclScope(Decl *D);
0488 
0489   void ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart,
0490                  const IdentifierInfo *ClassName,
0491                  SmallVectorImpl<Decl *> &Decls);
0492 
0493   VarDecl *BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType,
0494                                   SourceLocation StartLoc, SourceLocation IdLoc,
0495                                   const IdentifierInfo *Id,
0496                                   bool Invalid = false);
0497 
0498   Decl *ActOnObjCExceptionDecl(Scope *S, Declarator &D);
0499 
0500   /// CollectIvarsToConstructOrDestruct - Collect those ivars which require
0501   /// initialization.
0502   void
0503   CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI,
0504                                     SmallVectorImpl<ObjCIvarDecl *> &Ivars);
0505 
0506   void DiagnoseUseOfUnimplementedSelectors();
0507 
0508   /// DiagnoseUnusedBackingIvarInAccessor - Issue an 'unused' warning if ivar
0509   /// which backs the property is not used in the property's accessor.
0510   void DiagnoseUnusedBackingIvarInAccessor(Scope *S,
0511                                            const ObjCImplementationDecl *ImplD);
0512 
0513   /// GetIvarBackingPropertyAccessor - If method is a property setter/getter and
0514   /// it property has a backing ivar, returns this ivar; otherwise, returns
0515   /// NULL. It also returns ivar's property on success.
0516   ObjCIvarDecl *
0517   GetIvarBackingPropertyAccessor(const ObjCMethodDecl *Method,
0518                                  const ObjCPropertyDecl *&PDecl) const;
0519 
0520   /// AddInstanceMethodToGlobalPool - All instance methods in a translation
0521   /// unit are added to a global pool. This allows us to efficiently associate
0522   /// a selector with a method declaraation for purposes of typechecking
0523   /// messages sent to "id" (where the class of the object is unknown).
0524   void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method,
0525                                      bool impl = false) {
0526     AddMethodToGlobalPool(Method, impl, /*instance*/ true);
0527   }
0528 
0529   /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
0530   void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl = false) {
0531     AddMethodToGlobalPool(Method, impl, /*instance*/ false);
0532   }
0533 
0534   QualType AdjustParameterTypeForObjCAutoRefCount(QualType T,
0535                                                   SourceLocation NameLoc,
0536                                                   TypeSourceInfo *TSInfo);
0537 
0538   /// Look for an Objective-C class in the translation unit.
0539   ///
0540   /// \param Id The name of the Objective-C class we're looking for. If
0541   /// typo-correction fixes this name, the Id will be updated
0542   /// to the fixed name.
0543   ///
0544   /// \param IdLoc The location of the name in the translation unit.
0545   ///
0546   /// \param DoTypoCorrection If true, this routine will attempt typo correction
0547   /// if there is no class with the given name.
0548   ///
0549   /// \returns The declaration of the named Objective-C class, or NULL if the
0550   /// class could not be found.
0551   ObjCInterfaceDecl *getObjCInterfaceDecl(const IdentifierInfo *&Id,
0552                                           SourceLocation IdLoc,
0553                                           bool TypoCorrection = false);
0554 
0555   bool inferObjCARCLifetime(ValueDecl *decl);
0556 
0557   /// SetIvarInitializers - This routine builds initialization ASTs for the
0558   /// Objective-C implementation whose ivars need be initialized.
0559   void SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation);
0560 
0561   Decl *ActOnIvar(Scope *S, SourceLocation DeclStart, Declarator &D,
0562                   Expr *BitWidth, tok::ObjCKeywordKind visibility);
0563 
0564   ObjCContainerDecl *getObjCDeclContext() const;
0565 
0566 private:
0567   /// AddMethodToGlobalPool - Add an instance or factory method to the global
0568   /// pool. See descriptoin of AddInstanceMethodToGlobalPool.
0569   void AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance);
0570 
0571   /// LookupMethodInGlobalPool - Returns the instance or factory method and
0572   /// optionally warns if there are multiple signatures.
0573   ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R,
0574                                            bool receiverIdOrClass,
0575                                            bool instance);
0576 
0577   ///@}
0578 
0579   //
0580   //
0581   // -------------------------------------------------------------------------
0582   //
0583   //
0584 
0585   /// \name ObjC Expressions
0586   /// Implementations are in SemaExprObjC.cpp
0587   ///@{
0588 
0589 public:
0590   /// Caches identifiers/selectors for NSFoundation APIs.
0591   std::unique_ptr<NSAPI> NSAPIObj;
0592 
0593   /// The declaration of the Objective-C NSNumber class.
0594   ObjCInterfaceDecl *NSNumberDecl;
0595 
0596   /// The declaration of the Objective-C NSValue class.
0597   ObjCInterfaceDecl *NSValueDecl;
0598 
0599   /// Pointer to NSNumber type (NSNumber *).
0600   QualType NSNumberPointer;
0601 
0602   /// Pointer to NSValue type (NSValue *).
0603   QualType NSValuePointer;
0604 
0605   /// The Objective-C NSNumber methods used to create NSNumber literals.
0606   ObjCMethodDecl *NSNumberLiteralMethods[NSAPI::NumNSNumberLiteralMethods];
0607 
0608   /// The declaration of the Objective-C NSString class.
0609   ObjCInterfaceDecl *NSStringDecl;
0610 
0611   /// Pointer to NSString type (NSString *).
0612   QualType NSStringPointer;
0613 
0614   /// The declaration of the stringWithUTF8String: method.
0615   ObjCMethodDecl *StringWithUTF8StringMethod;
0616 
0617   /// The declaration of the valueWithBytes:objCType: method.
0618   ObjCMethodDecl *ValueWithBytesObjCTypeMethod;
0619 
0620   /// The declaration of the Objective-C NSArray class.
0621   ObjCInterfaceDecl *NSArrayDecl;
0622 
0623   /// The declaration of the arrayWithObjects:count: method.
0624   ObjCMethodDecl *ArrayWithObjectsMethod;
0625 
0626   /// The declaration of the Objective-C NSDictionary class.
0627   ObjCInterfaceDecl *NSDictionaryDecl;
0628 
0629   /// The declaration of the dictionaryWithObjects:forKeys:count: method.
0630   ObjCMethodDecl *DictionaryWithObjectsMethod;
0631 
0632   /// id<NSCopying> type.
0633   QualType QIDNSCopying;
0634 
0635   /// will hold 'respondsToSelector:'
0636   Selector RespondsToSelectorSel;
0637 
0638   ExprResult HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,
0639                                        Expr *BaseExpr, SourceLocation OpLoc,
0640                                        DeclarationName MemberName,
0641                                        SourceLocation MemberLoc,
0642                                        SourceLocation SuperLoc,
0643                                        QualType SuperType, bool Super);
0644 
0645   ExprResult ActOnClassPropertyRefExpr(const IdentifierInfo &receiverName,
0646                                        const IdentifierInfo &propertyName,
0647                                        SourceLocation receiverNameLoc,
0648                                        SourceLocation propertyNameLoc);
0649 
0650   // ParseObjCStringLiteral - Parse Objective-C string literals.
0651   ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
0652                                     ArrayRef<Expr *> Strings);
0653 
0654   ExprResult BuildObjCStringLiteral(SourceLocation AtLoc, StringLiteral *S);
0655 
0656   /// BuildObjCNumericLiteral - builds an ObjCBoxedExpr AST node for the
0657   /// numeric literal expression. Type of the expression will be "NSNumber *"
0658   /// or "id" if NSNumber is unavailable.
0659   ExprResult BuildObjCNumericLiteral(SourceLocation AtLoc, Expr *Number);
0660   ExprResult ActOnObjCBoolLiteral(SourceLocation AtLoc, SourceLocation ValueLoc,
0661                                   bool Value);
0662   ExprResult BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements);
0663 
0664   /// BuildObjCBoxedExpr - builds an ObjCBoxedExpr AST node for the
0665   /// '@' prefixed parenthesized expression. The type of the expression will
0666   /// either be "NSNumber *", "NSString *" or "NSValue *" depending on the type
0667   /// of ValueType, which is allowed to be a built-in numeric type, "char *",
0668   /// "const char *" or C structure with attribute 'objc_boxable'.
0669   ExprResult BuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr);
0670 
0671   ExprResult BuildObjCSubscriptExpression(SourceLocation RB, Expr *BaseExpr,
0672                                           Expr *IndexExpr,
0673                                           ObjCMethodDecl *getterMethod,
0674                                           ObjCMethodDecl *setterMethod);
0675 
0676   ExprResult
0677   BuildObjCDictionaryLiteral(SourceRange SR,
0678                              MutableArrayRef<ObjCDictionaryElement> Elements);
0679 
0680   ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc,
0681                                        TypeSourceInfo *EncodedTypeInfo,
0682                                        SourceLocation RParenLoc);
0683 
0684   ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
0685                                        SourceLocation EncodeLoc,
0686                                        SourceLocation LParenLoc, ParsedType Ty,
0687                                        SourceLocation RParenLoc);
0688 
0689   /// ParseObjCSelectorExpression - Build selector expression for \@selector
0690   ExprResult ParseObjCSelectorExpression(Selector Sel, SourceLocation AtLoc,
0691                                          SourceLocation SelLoc,
0692                                          SourceLocation LParenLoc,
0693                                          SourceLocation RParenLoc,
0694                                          bool WarnMultipleSelectors);
0695 
0696   /// ParseObjCProtocolExpression - Build protocol expression for \@protocol
0697   ExprResult ParseObjCProtocolExpression(IdentifierInfo *ProtocolName,
0698                                          SourceLocation AtLoc,
0699                                          SourceLocation ProtoLoc,
0700                                          SourceLocation LParenLoc,
0701                                          SourceLocation ProtoIdLoc,
0702                                          SourceLocation RParenLoc);
0703 
0704   ObjCMethodDecl *tryCaptureObjCSelf(SourceLocation Loc);
0705 
0706   /// Describes the kind of message expression indicated by a message
0707   /// send that starts with an identifier.
0708   enum ObjCMessageKind {
0709     /// The message is sent to 'super'.
0710     ObjCSuperMessage,
0711     /// The message is an instance message.
0712     ObjCInstanceMessage,
0713     /// The message is a class message, and the identifier is a type
0714     /// name.
0715     ObjCClassMessage
0716   };
0717 
0718   ObjCMessageKind getObjCMessageKind(Scope *S, IdentifierInfo *Name,
0719                                      SourceLocation NameLoc, bool IsSuper,
0720                                      bool HasTrailingDot,
0721                                      ParsedType &ReceiverType);
0722 
0723   ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc, Selector Sel,
0724                                SourceLocation LBracLoc,
0725                                ArrayRef<SourceLocation> SelectorLocs,
0726                                SourceLocation RBracLoc, MultiExprArg Args);
0727 
0728   ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo,
0729                                QualType ReceiverType, SourceLocation SuperLoc,
0730                                Selector Sel, ObjCMethodDecl *Method,
0731                                SourceLocation LBracLoc,
0732                                ArrayRef<SourceLocation> SelectorLocs,
0733                                SourceLocation RBracLoc, MultiExprArg Args,
0734                                bool isImplicit = false);
0735 
0736   ExprResult BuildClassMessageImplicit(QualType ReceiverType,
0737                                        bool isSuperReceiver, SourceLocation Loc,
0738                                        Selector Sel, ObjCMethodDecl *Method,
0739                                        MultiExprArg Args);
0740 
0741   ExprResult ActOnClassMessage(Scope *S, ParsedType Receiver, Selector Sel,
0742                                SourceLocation LBracLoc,
0743                                ArrayRef<SourceLocation> SelectorLocs,
0744                                SourceLocation RBracLoc, MultiExprArg Args);
0745 
0746   ExprResult BuildInstanceMessage(Expr *Receiver, QualType ReceiverType,
0747                                   SourceLocation SuperLoc, Selector Sel,
0748                                   ObjCMethodDecl *Method,
0749                                   SourceLocation LBracLoc,
0750                                   ArrayRef<SourceLocation> SelectorLocs,
0751                                   SourceLocation RBracLoc, MultiExprArg Args,
0752                                   bool isImplicit = false);
0753 
0754   ExprResult BuildInstanceMessageImplicit(Expr *Receiver, QualType ReceiverType,
0755                                           SourceLocation Loc, Selector Sel,
0756                                           ObjCMethodDecl *Method,
0757                                           MultiExprArg Args);
0758 
0759   ExprResult ActOnInstanceMessage(Scope *S, Expr *Receiver, Selector Sel,
0760                                   SourceLocation LBracLoc,
0761                                   ArrayRef<SourceLocation> SelectorLocs,
0762                                   SourceLocation RBracLoc, MultiExprArg Args);
0763 
0764   ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc,
0765                                   ObjCBridgeCastKind Kind,
0766                                   SourceLocation BridgeKeywordLoc,
0767                                   TypeSourceInfo *TSInfo, Expr *SubExpr);
0768 
0769   ExprResult ActOnObjCBridgedCast(Scope *S, SourceLocation LParenLoc,
0770                                   ObjCBridgeCastKind Kind,
0771                                   SourceLocation BridgeKeywordLoc,
0772                                   ParsedType Type, SourceLocation RParenLoc,
0773                                   Expr *SubExpr);
0774 
0775   void CheckTollFreeBridgeCast(QualType castType, Expr *castExpr);
0776 
0777   void CheckObjCBridgeRelatedCast(QualType castType, Expr *castExpr);
0778 
0779   bool CheckTollFreeBridgeStaticCast(QualType castType, Expr *castExpr,
0780                                      CastKind &Kind);
0781 
0782   bool checkObjCBridgeRelatedComponents(SourceLocation Loc, QualType DestType,
0783                                         QualType SrcType,
0784                                         ObjCInterfaceDecl *&RelatedClass,
0785                                         ObjCMethodDecl *&ClassMethod,
0786                                         ObjCMethodDecl *&InstanceMethod,
0787                                         TypedefNameDecl *&TDNDecl, bool CfToNs,
0788                                         bool Diagnose = true);
0789 
0790   bool CheckObjCBridgeRelatedConversions(SourceLocation Loc, QualType DestType,
0791                                          QualType SrcType, Expr *&SrcExpr,
0792                                          bool Diagnose = true);
0793 
0794   /// Private Helper predicate to check for 'self'.
0795   bool isSelfExpr(Expr *RExpr);
0796   bool isSelfExpr(Expr *RExpr, const ObjCMethodDecl *Method);
0797 
0798   ObjCMethodDecl *LookupMethodInQualifiedType(Selector Sel,
0799                                               const ObjCObjectPointerType *OPT,
0800                                               bool IsInstance);
0801   ObjCMethodDecl *LookupMethodInObjectType(Selector Sel, QualType Ty,
0802                                            bool IsInstance);
0803 
0804   bool isKnownName(StringRef name);
0805 
0806   enum ARCConversionResult { ACR_okay, ACR_unbridged, ACR_error };
0807 
0808   /// Checks for invalid conversions and casts between
0809   /// retainable pointers and other pointer kinds for ARC and Weak.
0810   ARCConversionResult CheckObjCConversion(SourceRange castRange,
0811                                           QualType castType, Expr *&op,
0812                                           CheckedConversionKind CCK,
0813                                           bool Diagnose = true,
0814                                           bool DiagnoseCFAudited = false,
0815                                           BinaryOperatorKind Opc = BO_PtrMemD);
0816 
0817   Expr *stripARCUnbridgedCast(Expr *e);
0818   void diagnoseARCUnbridgedCast(Expr *e);
0819 
0820   bool CheckObjCARCUnavailableWeakConversion(QualType castType,
0821                                              QualType ExprType);
0822 
0823   /// CheckMessageArgumentTypes - Check types in an Obj-C message send.
0824   /// \param Method - May be null.
0825   /// \param [out] ReturnType - The return type of the send.
0826   /// \return true iff there were any incompatible types.
0827   bool CheckMessageArgumentTypes(const Expr *Receiver, QualType ReceiverType,
0828                                  MultiExprArg Args, Selector Sel,
0829                                  ArrayRef<SourceLocation> SelectorLocs,
0830                                  ObjCMethodDecl *Method, bool isClassMessage,
0831                                  bool isSuperMessage, SourceLocation lbrac,
0832                                  SourceLocation rbrac, SourceRange RecRange,
0833                                  QualType &ReturnType, ExprValueKind &VK);
0834 
0835   /// Determine the result of a message send expression based on
0836   /// the type of the receiver, the method expected to receive the message,
0837   /// and the form of the message send.
0838   QualType getMessageSendResultType(const Expr *Receiver, QualType ReceiverType,
0839                                     ObjCMethodDecl *Method, bool isClassMessage,
0840                                     bool isSuperMessage);
0841 
0842   /// If the given expression involves a message send to a method
0843   /// with a related result type, emit a note describing what happened.
0844   void EmitRelatedResultTypeNote(const Expr *E);
0845 
0846   /// Given that we had incompatible pointer types in a return
0847   /// statement, check whether we're in a method with a related result
0848   /// type, and if so, emit a note describing what happened.
0849   void EmitRelatedResultTypeNoteForReturn(QualType destType);
0850 
0851   /// LookupInstanceMethodInGlobalPool - Returns the method and warns if
0852   /// there are multiple signatures.
0853   ObjCMethodDecl *
0854   LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R,
0855                                    bool receiverIdOrClass = false) {
0856     return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass,
0857                                     /*instance*/ true);
0858   }
0859 
0860   /// LookupFactoryMethodInGlobalPool - Returns the method and warns if
0861   /// there are multiple signatures.
0862   ObjCMethodDecl *
0863   LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R,
0864                                   bool receiverIdOrClass = false) {
0865     return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass,
0866                                     /*instance*/ false);
0867   }
0868 
0869   /// The parser has read a name in, and Sema has detected that we're currently
0870   /// inside an ObjC method. Perform some additional checks and determine if we
0871   /// should form a reference to an ivar.
0872   ///
0873   /// Ideally, most of this would be done by lookup, but there's
0874   /// actually quite a lot of extra work involved.
0875   DeclResult LookupIvarInObjCMethod(LookupResult &Lookup, Scope *S,
0876                                     IdentifierInfo *II);
0877 
0878   /// The parser has read a name in, and Sema has detected that we're currently
0879   /// inside an ObjC method. Perform some additional checks and determine if we
0880   /// should form a reference to an ivar. If so, build an expression referencing
0881   /// that ivar.
0882   ExprResult LookupInObjCMethod(LookupResult &LookUp, Scope *S,
0883                                 IdentifierInfo *II,
0884                                 bool AllowBuiltinCreation = false);
0885 
0886   ExprResult BuildIvarRefExpr(Scope *S, SourceLocation Loc, ObjCIvarDecl *IV);
0887 
0888   /// FindCompositeObjCPointerType - Helper method to find composite type of
0889   /// two objective-c pointer types of the two input expressions.
0890   QualType FindCompositeObjCPointerType(ExprResult &LHS, ExprResult &RHS,
0891                                         SourceLocation QuestionLoc);
0892 
0893   bool CheckConversionToObjCLiteral(QualType DstType, Expr *&SrcExpr,
0894                                     bool Diagnose = true);
0895 
0896   /// ActOnObjCBoolLiteral - Parse {__objc_yes,__objc_no} literals.
0897   ExprResult ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind);
0898 
0899   ExprResult
0900   ActOnObjCAvailabilityCheckExpr(llvm::ArrayRef<AvailabilitySpec> AvailSpecs,
0901                                  SourceLocation AtLoc, SourceLocation RParen);
0902 
0903   /// Prepare a conversion of the given expression to an ObjC object
0904   /// pointer type.
0905   CastKind PrepareCastToObjCObjectPointer(ExprResult &E);
0906 
0907   // Note that LK_String is intentionally after the other literals, as
0908   // this is used for diagnostics logic.
0909   enum ObjCLiteralKind {
0910     LK_Array,
0911     LK_Dictionary,
0912     LK_Numeric,
0913     LK_Boxed,
0914     LK_String,
0915     LK_Block,
0916     LK_None
0917   };
0918   ObjCLiteralKind CheckLiteralKind(Expr *FromE);
0919 
0920   ///@}
0921 
0922   //
0923   //
0924   // -------------------------------------------------------------------------
0925   //
0926   //
0927 
0928   /// \name ObjC @property and @synthesize
0929   /// Implementations are in SemaObjCProperty.cpp
0930   ///@{
0931 
0932 public:
0933   /// Ensure attributes are consistent with type.
0934   /// \param [in, out] Attributes The attributes to check; they will
0935   /// be modified to be consistent with \p PropertyTy.
0936   void CheckObjCPropertyAttributes(Decl *PropertyPtrTy, SourceLocation Loc,
0937                                    unsigned &Attributes,
0938                                    bool propertyInPrimaryClass);
0939 
0940   /// Process the specified property declaration and create decls for the
0941   /// setters and getters as needed.
0942   /// \param property The property declaration being processed
0943   void ProcessPropertyDecl(ObjCPropertyDecl *property);
0944 
0945   Decl *ActOnProperty(Scope *S, SourceLocation AtLoc, SourceLocation LParenLoc,
0946                       FieldDeclarator &FD, ObjCDeclSpec &ODS,
0947                       Selector GetterSel, Selector SetterSel,
0948                       tok::ObjCKeywordKind MethodImplKind,
0949                       DeclContext *lexicalDC = nullptr);
0950 
0951   Decl *ActOnPropertyImplDecl(Scope *S, SourceLocation AtLoc,
0952                               SourceLocation PropertyLoc, bool ImplKind,
0953                               IdentifierInfo *PropertyId,
0954                               IdentifierInfo *PropertyIvar,
0955                               SourceLocation PropertyIvarLoc,
0956                               ObjCPropertyQueryKind QueryKind);
0957 
0958   /// Called by ActOnProperty to handle \@property declarations in
0959   /// class extensions.
0960   ObjCPropertyDecl *HandlePropertyInClassExtension(
0961       Scope *S, SourceLocation AtLoc, SourceLocation LParenLoc,
0962       FieldDeclarator &FD, Selector GetterSel, SourceLocation GetterNameLoc,
0963       Selector SetterSel, SourceLocation SetterNameLoc, const bool isReadWrite,
0964       unsigned &Attributes, const unsigned AttributesAsWritten, QualType T,
0965       TypeSourceInfo *TSI, tok::ObjCKeywordKind MethodImplKind);
0966 
0967   /// Called by ActOnProperty and HandlePropertyInClassExtension to
0968   /// handle creating the ObjcPropertyDecl for a category or \@interface.
0969   ObjCPropertyDecl *
0970   CreatePropertyDecl(Scope *S, ObjCContainerDecl *CDecl, SourceLocation AtLoc,
0971                      SourceLocation LParenLoc, FieldDeclarator &FD,
0972                      Selector GetterSel, SourceLocation GetterNameLoc,
0973                      Selector SetterSel, SourceLocation SetterNameLoc,
0974                      const bool isReadWrite, const unsigned Attributes,
0975                      const unsigned AttributesAsWritten, QualType T,
0976                      TypeSourceInfo *TSI, tok::ObjCKeywordKind MethodImplKind,
0977                      DeclContext *lexicalDC = nullptr);
0978 
0979   void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
0980                                 ObjCPropertyDecl *SuperProperty,
0981                                 const IdentifierInfo *Name,
0982                                 bool OverridingProtocolProperty);
0983 
0984   bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD,
0985                                         ObjCMethodDecl *Getter,
0986                                         SourceLocation Loc);
0987 
0988   /// DiagnoseUnimplementedProperties - This routine warns on those properties
0989   /// which must be implemented by this implementation.
0990   void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl *IMPDecl,
0991                                        ObjCContainerDecl *CDecl,
0992                                        bool SynthesizeProperties);
0993 
0994   /// Diagnose any null-resettable synthesized setters.
0995   void diagnoseNullResettableSynthesizedSetters(const ObjCImplDecl *impDecl);
0996 
0997   /// DefaultSynthesizeProperties - This routine default synthesizes all
0998   /// properties which must be synthesized in the class's \@implementation.
0999   void DefaultSynthesizeProperties(Scope *S, ObjCImplDecl *IMPDecl,
1000                                    ObjCInterfaceDecl *IDecl,
1001                                    SourceLocation AtEnd);
1002   void DefaultSynthesizeProperties(Scope *S, Decl *D, SourceLocation AtEnd);
1003 
1004   /// IvarBacksCurrentMethodAccessor - This routine returns 'true' if 'IV' is
1005   /// an ivar synthesized for 'Method' and 'Method' is a property accessor
1006   /// declared in class 'IFace'.
1007   bool IvarBacksCurrentMethodAccessor(ObjCInterfaceDecl *IFace,
1008                                       ObjCMethodDecl *Method, ObjCIvarDecl *IV);
1009 
1010   void DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D);
1011 
1012   void
1013   DiagnoseMissingDesignatedInitOverrides(const ObjCImplementationDecl *ImplD,
1014                                          const ObjCInterfaceDecl *IFD);
1015 
1016   /// AtomicPropertySetterGetterRules - This routine enforces the rule (via
1017   /// warning) when atomic property has one but not the other user-declared
1018   /// setter or getter.
1019   void AtomicPropertySetterGetterRules(ObjCImplDecl *IMPDecl,
1020                                        ObjCInterfaceDecl *IDecl);
1021 
1022   ///@}
1023 
1024   //
1025   //
1026   // -------------------------------------------------------------------------
1027   //
1028   //
1029 
1030   /// \name ObjC Attributes
1031   /// Implementations are in SemaObjC.cpp
1032   ///@{
1033 
1034   bool isNSStringType(QualType T, bool AllowNSAttributedString = false);
1035   bool isCFStringType(QualType T);
1036 
1037   void handleIBOutlet(Decl *D, const ParsedAttr &AL);
1038   void handleIBOutletCollection(Decl *D, const ParsedAttr &AL);
1039 
1040   void handleSuppresProtocolAttr(Decl *D, const ParsedAttr &AL);
1041   void handleDirectAttr(Decl *D, const ParsedAttr &AL);
1042   void handleDirectMembersAttr(Decl *D, const ParsedAttr &AL);
1043   void handleMethodFamilyAttr(Decl *D, const ParsedAttr &AL);
1044   void handleNSObject(Decl *D, const ParsedAttr &AL);
1045   void handleIndependentClass(Decl *D, const ParsedAttr &AL);
1046   void handleBlocksAttr(Decl *D, const ParsedAttr &AL);
1047   void handleReturnsInnerPointerAttr(Decl *D, const ParsedAttr &Attrs);
1048   void handleXReturnsXRetainedAttr(Decl *D, const ParsedAttr &AL);
1049   void handleRequiresSuperAttr(Decl *D, const ParsedAttr &Attrs);
1050   void handleNSErrorDomain(Decl *D, const ParsedAttr &Attr);
1051   void handleBridgeAttr(Decl *D, const ParsedAttr &AL);
1052   void handleBridgeMutableAttr(Decl *D, const ParsedAttr &AL);
1053   void handleBridgeRelatedAttr(Decl *D, const ParsedAttr &AL);
1054   void handleDesignatedInitializer(Decl *D, const ParsedAttr &AL);
1055   void handleRuntimeName(Decl *D, const ParsedAttr &AL);
1056   void handleBoxable(Decl *D, const ParsedAttr &AL);
1057   void handleOwnershipAttr(Decl *D, const ParsedAttr &AL);
1058   void handlePreciseLifetimeAttr(Decl *D, const ParsedAttr &AL);
1059   void handleExternallyRetainedAttr(Decl *D, const ParsedAttr &AL);
1060 
1061   void AddXConsumedAttr(Decl *D, const AttributeCommonInfo &CI,
1062                         Sema::RetainOwnershipKind K,
1063                         bool IsTemplateInstantiation);
1064 
1065   /// \return whether the parameter is a pointer to OSObject pointer.
1066   bool isValidOSObjectOutParameter(const Decl *D);
1067   bool checkNSReturnsRetainedReturnType(SourceLocation loc, QualType type);
1068 
1069   Sema::RetainOwnershipKind
1070   parsedAttrToRetainOwnershipKind(const ParsedAttr &AL);
1071 
1072   ///@}
1073 };
1074 
1075 } // namespace clang
1076 
1077 #endif // LLVM_CLANG_SEMA_SEMAOBJC_H